Skip to content
This repository was archived by the owner on Jul 14, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 65 additions & 7 deletions tests/cli.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
import { program } from "commander";
import { buildCmd } from "../src/cli";
import { executeTests } from "../src/tools";
import { runDebugtopus } from "../src/debugtopus";
import { loadConfig } from "../src/config";

jest.mock("../src/tools");
jest.mock("../src/debugtopus");
jest.mock("../src/config", () => ({
...jest.requireActual("../src/config"),
loadConfig: jest.fn(),
}));

beforeAll(() => {
buildCmd();
program.exitOverride((err) => {
throw err;
});
});

describe("CLI Commands parsing options", () => {
const stdArgs = [
Expand All @@ -15,13 +29,6 @@ describe("CLI Commands parsing options", () => {
"test-target-123",
];

beforeAll(() => {
buildCmd();
program.exitOverride((err) => {
throw err;
});
});

beforeEach(() => {
jest.clearAllMocks();
});
Expand Down Expand Up @@ -75,3 +82,54 @@ describe("CLI Commands parsing options", () => {
);
});
});

describe("config overwrite behaviour", () => {
beforeEach(() => {
jest.clearAllMocks();
});

it("should resolve testTargetId from parameter when provided", async () => {
const providedTestTargetId = "provided-test-target-123";

await program.parseAsync([
"node",
"cli.js",
"debug",
"--url",
"https://example.com",
"--testTargetId",
providedTestTargetId,
]);

expect(runDebugtopus).toHaveBeenCalledWith(
expect.objectContaining({
url: "https://example.com",
testTargetId: providedTestTargetId,
}),
);
});

it("should resolve testTargetId from config when not provided as parameter", async () => {
const mockResolvedId = "config-test-target-456";
const mockConfig = {
apiKey: "test-api-key",
testTargetId: mockResolvedId,
};
(loadConfig as jest.Mock).mockResolvedValue(mockConfig);

await program.parseAsync([
"node",
"cli.js",
"debug",
"--url",
"https://example.com",
]);

expect(runDebugtopus).toHaveBeenCalledWith(
expect.objectContaining({
url: "https://example.com",
testTargetId: mockResolvedId,
}),
);
});
});
50 changes: 50 additions & 0 deletions tests/config.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import fs from "fs/promises";
import path from "path";
import { loadConfig, Config } from "../src/config";

jest.mock("fs/promises");
const mockedFs = fs as jest.Mocked<typeof fs>;

const originalConsoleError = console.error;

describe("Config", () => {
beforeEach(() => {
console.error = jest.fn();
});

afterEach(() => {
console.error = originalConsoleError;
});

describe("loadConfig", () => {
it("should load and parse a valid config file", async () => {
const mockConfig: Config = {
apiKey: "test-api-key-12345",
testTargetId: "test-target-id-67890",
};

mockedFs.readFile.mockResolvedValue(JSON.stringify(mockConfig));

const result = await loadConfig();

expect(result).toEqual(mockConfig);
expect(mockedFs.readFile).toHaveBeenCalledWith(
path.join(process.cwd(), "octomind.config.json"),
"utf8",
);
});

it("should error when config file does not exist", async () => {
const fileNotFoundError = new Error(
"ENOENT: no such file or directory",
) as Error & { code?: string };
fileNotFoundError.code = "ENOENT";

mockedFs.readFile.mockRejectedValue(fileNotFoundError);

await loadConfig();

expect(console.error).toHaveBeenCalled();
});
});
});
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"strict": true,
"noImplicitAny": true,
"esModuleInterop": true,
"resolveJsonModule": true
"resolveJsonModule": true,
"isolatedModules": true
},
"exclude": [
"node_modules",
Expand Down