Skip to content
Open
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
231 changes: 231 additions & 0 deletions axilo-cli/tests/config.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,234 @@ test("loads user instructions + project doc when axilo.md is present", () => {
userInstr + "\n\n--- project-doc ---\n\n" + projectDoc,
);
});


test("saves config with only model when memory and fullAutoErrorMode are undefined", () => {
const testConfig = {
model: "gpt-4",
instructions: "test instructions",
};
saveConfig(testConfig, testConfigPath, testInstructionsPath);

expect(memfs[testConfigPath]).toContain('"model": "gpt-4"');
expect(memfs[testConfigPath]).not.toContain('"memory"');
expect(memfs[testConfigPath]).not.toContain('"fullAutoErrorMode"');
expect(memfs[testInstructionsPath]).toBe("test instructions");
});

test("saves config with memory when memory is truthy", () => {
const testConfig = {
model: "gpt-4",
memory: { enabled: true },
instructions: "test instructions",
};
saveConfig(testConfig, testConfigPath, testInstructionsPath);

expect(memfs[testConfigPath]).toContain('"model": "gpt-4"');
expect(memfs[testConfigPath]).toContain('"memory"');
expect(memfs[testConfigPath]).toContain('"enabled": true');
});

test("saves config with fullAutoErrorMode when fullAutoErrorMode is truthy", () => {
const testConfig = {
model: "gpt-4",
fullAutoErrorMode: "always",
instructions: "test instructions",
};
saveConfig(testConfig, testConfigPath, testInstructionsPath);

expect(memfs[testConfigPath]).toContain('"model": "gpt-4"');
expect(memfs[testConfigPath]).toContain('"fullAutoErrorMode"');
expect(memfs[testConfigPath]).toContain('"always"');
});

test("saves config with both memory and fullAutoErrorMode when both are truthy", () => {
const testConfig = {
model: "gpt-4",
memory: { enabled: true },
fullAutoErrorMode: "always",
instructions: "test instructions",
};
saveConfig(testConfig, testConfigPath, testInstructionsPath);

expect(memfs[testConfigPath]).toContain('"model": "gpt-4"');
expect(memfs[testConfigPath]).toContain('"memory"');
expect(memfs[testConfigPath]).toContain('"enabled": true');
expect(memfs[testConfigPath]).toContain('"fullAutoErrorMode"');
expect(memfs[testConfigPath]).toContain('"always"');
});

test("does not save memory when memory is falsy", () => {
const testConfig = {
model: "gpt-4",
memory: undefined,
instructions: "test instructions",
};
saveConfig(testConfig, testConfigPath, testInstructionsPath);

expect(memfs[testConfigPath]).toContain('"model": "gpt-4"');
expect(memfs[testConfigPath]).not.toContain('"memory"');
});

test("does not save fullAutoErrorMode when fullAutoErrorMode is falsy", () => {
const testConfig = {
model: "gpt-4",
fullAutoErrorMode: undefined,
instructions: "test instructions",
};
saveConfig(testConfig, testConfigPath, testInstructionsPath);

expect(memfs[testConfigPath]).toContain('"model": "gpt-4"');
expect(memfs[testConfigPath]).not.toContain('"fullAutoErrorMode"');
});

test("saves and loads config with memory correctly", () => {
const testConfig = {
model: "test-model",
memory: { enabled: true },
instructions: "test instructions",
};
saveConfig(testConfig, testConfigPath, testInstructionsPath);

const loadedConfig = loadConfig(testConfigPath, testInstructionsPath, {
disableProjectDoc: true,
});
expect(loadedConfig.model).toBe("test-model");
expect(loadedConfig.memory).toEqual({ enabled: true });
expect(loadedConfig.instructions).toBe("test instructions");
});

test("saves and loads config with fullAutoErrorMode correctly", () => {
const testConfig = {
model: "test-model",
fullAutoErrorMode: "always",
instructions: "test instructions",
};
saveConfig(testConfig, testConfigPath, testInstructionsPath);

const loadedConfig = loadConfig(testConfigPath, testInstructionsPath, {
disableProjectDoc: true,
});
expect(loadedConfig.model).toBe("test-model");
expect(loadedConfig.fullAutoErrorMode).toBe("always");
expect(loadedConfig.instructions).toBe("test instructions");
});

test("saves and loads config with all optional fields correctly", () => {
const testConfig = {
model: "test-model",
memory: { enabled: true },
fullAutoErrorMode: "prompt",
instructions: "test instructions",
};
saveConfig(testConfig, testConfigPath, testInstructionsPath);

const loadedConfig = loadConfig(testConfigPath, testInstructionsPath, {
disableProjectDoc: true,
});
expect(loadedConfig.model).toBe("test-model");
expect(loadedConfig.memory).toEqual({ enabled: true });
expect(loadedConfig.fullAutoErrorMode).toBe("prompt");
expect(loadedConfig.instructions).toBe("test instructions");
});

test("saves config to YAML format with optional fields", () => {
const yamlConfigPath = join(testDir, "config.yml");
const testConfig = {
model: "gpt-4",
memory: { enabled: true },
fullAutoErrorMode: "always",
instructions: "test instructions",
};
saveConfig(testConfig, yamlConfigPath, testInstructionsPath);

expect(memfs[yamlConfigPath]).toContain("model: gpt-4");
expect(memfs[yamlConfigPath]).toContain("memory:");
expect(memfs[yamlConfigPath]).toContain("enabled: true");
expect(memfs[yamlConfigPath]).toContain("fullAutoErrorMode: always");
});

test("saves config to YAML format without optional fields when undefined", () => {
const yamlConfigPath = join(testDir, "config.yml");
const testConfig = {
model: "gpt-4",
instructions: "test instructions",
};
saveConfig(testConfig, yamlConfigPath, testInstructionsPath);

expect(memfs[yamlConfigPath]).toContain("model: gpt-4");
expect(memfs[yamlConfigPath]).not.toContain("memory:");
expect(memfs[yamlConfigPath]).not.toContain("fullAutoErrorMode:");
});

test("handles edge case with memory enabled false", () => {
const testConfig = {
model: "gpt-4",
memory: { enabled: false },
instructions: "test instructions",
};
saveConfig(testConfig, testConfigPath, testInstructionsPath);

expect(memfs[testConfigPath]).toContain('"model": "gpt-4"');
expect(memfs[testConfigPath]).toContain('"memory"');
expect(memfs[testConfigPath]).toContain('"enabled": false');

const loadedConfig = loadConfig(testConfigPath, testInstructionsPath, {
disableProjectDoc: true,
});
expect(loadedConfig.memory).toEqual({ enabled: false });
});

test("preserves backward compatibility when loading old config without optional fields", () => {
memfs[testConfigPath] = JSON.stringify({ model: "old-model" }, null, 2);
memfs[testInstructionsPath] = "old instructions";

const loadedConfig = loadConfig(testConfigPath, testInstructionsPath, {
disableProjectDoc: true,
});

expect(loadedConfig.model).toBe("old-model");
expect(loadedConfig.memory).toBeUndefined();
expect(loadedConfig.fullAutoErrorMode).toBeUndefined();
expect(loadedConfig.instructions).toBe("old instructions");
});

test("handles config with only fullAutoErrorMode", () => {
const testConfig = {
model: "gpt-4",
fullAutoErrorMode: "never",
instructions: "test instructions",
};
saveConfig(testConfig, testConfigPath, testInstructionsPath);

expect(memfs[testConfigPath]).toContain('"model": "gpt-4"');
expect(memfs[testConfigPath]).toContain('"fullAutoErrorMode": "never"');
expect(memfs[testConfigPath]).not.toContain('"memory"');

const loadedConfig = loadConfig(testConfigPath, testInstructionsPath, {
disableProjectDoc: true,
});
expect(loadedConfig.model).toBe("gpt-4");
expect(loadedConfig.fullAutoErrorMode).toBe("never");
expect(loadedConfig.memory).toBeUndefined();
});

test("handles config with only memory", () => {
const testConfig = {
model: "gpt-4",
memory: { enabled: true },
instructions: "test instructions",
};
saveConfig(testConfig, testConfigPath, testInstructionsPath);

expect(memfs[testConfigPath]).toContain('"model": "gpt-4"');
expect(memfs[testConfigPath]).toContain('"memory"');
expect(memfs[testConfigPath]).not.toContain('"fullAutoErrorMode"');

const loadedConfig = loadConfig(testConfigPath, testInstructionsPath, {
disableProjectDoc: true,
});
expect(loadedConfig.model).toBe("gpt-4");
expect(loadedConfig.memory).toEqual({ enabled: true });
expect(loadedConfig.fullAutoErrorMode).toBeUndefined();
});
Loading