Skip to content
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
3 changes: 2 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const config = {
testEnvironment: 'node',
silent: true,
forceExit: true,
maxWorkers: 1,
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
extensionsToTreatAsEsm: ['.ts'],
testMatch: ['**/__tests__/**/*.+(ts|tsx|js)', '**/?(*.)+(spec|test).+(ts|tsx|js)'],
Expand Down Expand Up @@ -38,4 +39,4 @@ const config = {
],
};

export default config;
export default config;
85 changes: 85 additions & 0 deletions tests/config.integration.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import { jest } from "@jest/globals";
import path from "path";
import { mkdtempSync, readFileSync, writeFileSync, mkdirSync } from "node:fs";
import os from "os";
import { ConfigChatType, ConfigType } from "../src/types.ts";

// mock external modules to keep memory usage low
jest.unstable_mockModule("../src/helpers/readGoogleSheet", () => ({
readGoogleSheet: jest.fn(),
}));
jest.unstable_mockModule(
"google-auth-library/build/src/auth/oauth2client",
() => ({ OAuth2Client: class {} }),
);
jest.unstable_mockModule("google-auth-library", () => ({
GoogleAuth: class {},
}));

const config = await import("../src/config.ts");
const {
readConfig,
writeConfig,
generateConfig,
convertChatConfig,
setConfigPath,
} = config;
const yaml = await import("js-yaml");

describe("config integration", () => {
it("loads chats from files and updates chat file", () => {
const tmp = mkdtempSync(path.join(os.tmpdir(), "cfg-"));
const chatsDir = path.join(tmp, "data", "chats");
mkdirSync(chatsDir, { recursive: true });
writeFileSync(path.join(chatsDir, "a.yml"), "name: a\n");
writeFileSync(path.join(chatsDir, "b.yml"), "name: b\n");
const cfg = generateConfig();
cfg.useChatsDir = true;
cfg.chatsDir = chatsDir;
cfg.chats = [];
const configPath = path.join(tmp, "config.yml");
writeConfig(configPath, cfg);
const loaded = readConfig(configPath);
expect(loaded.chats.map((c) => c.name)).toEqual(["a", "b"]);
const chatFile = path.join(chatsDir, "a.yml");
const before = readFileSync(chatFile, "utf8");
loaded.chats[0].description = "updated";
writeConfig(configPath, loaded);
const after = readFileSync(chatFile, "utf8");
expect(after).not.toBe(before);
expect(after).toMatch(/description: updated/);
});

it("splits and merges config using convertChatConfig", () => {
const tmp = mkdtempSync(path.join(os.tmpdir(), "cfg-"));
const configPath = path.join(tmp, "config.yml");
const chatsDir = path.join(tmp, "data", "chats");
const cfg = generateConfig();
cfg.useChatsDir = false;
cfg.chatsDir = chatsDir;
cfg.chats = [
{
name: "chat1",
agent_name: "chat1",
completionParams: {},
chatParams: {},
toolParams: {},
} as ConfigChatType,
];
writeConfig(configPath, cfg);
setConfigPath(configPath);

convertChatConfig("split");
const splitCfg = yaml.load(readFileSync(configPath, "utf8")) as ConfigType;
expect(splitCfg.useChatsDir).toBe(true);
expect(splitCfg.chats).toBeUndefined();
const chatFile = path.join(chatsDir, "chat1.yml");
const saved = yaml.load(readFileSync(chatFile, "utf8")) as ConfigChatType;
expect(saved.name).toBe("chat1");

convertChatConfig("merge");
const mergedCfg = yaml.load(readFileSync(configPath, "utf8")) as ConfigType;
expect(mergedCfg.useChatsDir).toBe(false);
expect(mergedCfg.chats[0].name).toBe("chat1");
});
});
2 changes: 1 addition & 1 deletion tests/configChatsDir.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ describe("chats dir mode", () => {
...mod.useConfig().chats[0],
buttonsSync: { sheetId: "id", sheetName: "name" },
} as ConfigChatType;
await mod.syncButtons(chat, {} as any);
await mod.syncButtons(chat, {} as unknown as Record<string, unknown>);
const afterCfg = yaml.load(readFileSync(configPath, "utf8")) as Record<
string,
unknown
Expand Down