


























@@ -83,6 +83,15 @@ function requireString(value: string | undefined, label: string): string {
8383return value;
8484}
858586+function expectFields(value: unknown, expected: Record<string, unknown>): void {
87+expect(value).toBeTypeOf("object");
88+expect(value).not.toBeNull();
89+const record = value as Record<string, unknown>;
90+for (const [key, expectedValue] of Object.entries(expected)) {
91+expect(record[key], key).toEqual(expectedValue);
92+}
93+}
94+8695describe("gateway session utils", () => {
8796afterEach(() => {
8897resetConfigRuntimeState();
@@ -198,21 +207,22 @@ describe("gateway session utils", () => {
198207createModelDefaultsConfig({ primary: "openai-codex/gpt-5.5" }),
199208);
200209201-expect(defaults).toMatchObject({
210+expectFields(defaults, {
202211modelProvider: "openai-codex",
203212model: "gpt-5.5",
204213thinkingDefault: "adaptive",
205214});
206-expect(defaults.thinkingLevels).toEqual(
207-expect.arrayContaining([
208-{ id: "adaptive", label: "adaptive" },
209-{ id: "xhigh", label: "xhigh" },
210-{ id: "max", label: "maximum" },
211-]),
212-);
213-expect(defaults.thinkingOptions).toEqual(
214-expect.arrayContaining(["adaptive", "xhigh", "maximum"]),
215+const levelLabels = Object.fromEntries(
216+defaults.thinkingLevels?.map((level) => [level.id, level.label]) ?? [],
215217);
218+expectFields(levelLabels, {
219+adaptive: "adaptive",
220+xhigh: "xhigh",
221+max: "maximum",
222+});
223+expect(defaults.thinkingOptions).toContain("adaptive");
224+expect(defaults.thinkingOptions).toContain("xhigh");
225+expect(defaults.thinkingOptions).toContain("maximum");
216226});
217227218228test("session defaults and rows use catalog reasoning metadata for provider thinking options", () => {
@@ -421,7 +431,7 @@ describe("gateway session utils", () => {
421431},
422432} as OpenClawConfig);
423433424-expect(defaults).toMatchObject({
434+expectFields(defaults, {
425435modelProvider: "openai-codex",
426436model: "gpt-5.5",
427437thinkingDefault: "high",
@@ -457,7 +467,7 @@ describe("gateway session utils", () => {
457467key: "agent:alpha:main",
458468});
459469460-expect(row).toMatchObject({
470+expectFields(row, {
461471modelProvider: "openai-codex",
462472model: "gpt-5.5",
463473thinkingDefault: "high",
@@ -486,7 +496,7 @@ describe("gateway session utils", () => {
486496key: "main",
487497});
488498489-expect(row).toMatchObject({
499+expectFields(row, {
490500modelProvider: "openai-codex",
491501model: "gpt-5.5",
492502thinkingDefault: "max",
@@ -612,7 +622,8 @@ describe("gateway session utils", () => {
612622} as OpenClawConfig;
613623const target = resolveGatewaySessionStoreTarget({ cfg, key: "main" });
614624expect(target.canonicalKey).toBe("agent:ops:main");
615-expect(target.storeKeys).toEqual(expect.arrayContaining(["agent:ops:main", "main"]));
625+expect(target.storeKeys).toContain("agent:ops:main");
626+expect(target.storeKeys).toContain("main");
616627expect(target.storePath).toBe(path.resolve(storeTemplate.replace("{agentId}", "ops")));
617628});
618629@@ -630,9 +641,8 @@ describe("gateway session utils", () => {
630641} as OpenClawConfig;
631642const target = resolveGatewaySessionStoreTarget({ cfg, key: "agent:ops:mysession" });
632643expect(target.canonicalKey).toBe("agent:ops:mysession");
633-expect(target.storeKeys).toEqual(
634-expect.arrayContaining(["agent:ops:mysession", "agent:ops:MySession"]),
635-);
644+expect(target.storeKeys).toContain("agent:ops:mysession");
645+expect(target.storeKeys).toContain("agent:ops:MySession");
636646const store = JSON.parse(fs.readFileSync(storePath, "utf8"));
637647const found = target.storeKeys.some((k) => Boolean(store[k]));
638648expect(found).toBe(true);
@@ -654,9 +664,8 @@ describe("gateway session utils", () => {
654664agents: { list: [{ id: "ops", default: true }] },
655665} as OpenClawConfig;
656666const target = resolveGatewaySessionStoreTarget({ cfg, key: "agent:ops:mysession" });
657-expect(target.storeKeys).toEqual(
658-expect.arrayContaining(["agent:ops:mysession", "agent:ops:MySession"]),
659-);
667+expect(target.storeKeys).toContain("agent:ops:mysession");
668+expect(target.storeKeys).toContain("agent:ops:MySession");
660669});
661670662671test("resolveGatewaySessionStoreTarget finds legacy main alias key when mainKey is customized", () => {
@@ -673,7 +682,7 @@ describe("gateway session utils", () => {
673682} as OpenClawConfig;
674683const target = resolveGatewaySessionStoreTarget({ cfg, key: "agent:ops:main" });
675684expect(target.canonicalKey).toBe("agent:ops:work");
676-expect(target.storeKeys).toEqual(expect.arrayContaining(["agent:ops:MAIN"]));
685+expect(target.storeKeys).toContain("agent:ops:MAIN");
677686});
678687679688test("resolveGatewaySessionStoreTarget preserves discovered store paths for non-round-tripping agent dirs", async () => {
@@ -1062,17 +1071,17 @@ describe("gateway session utils", () => {
10621071} as OpenClawConfig;
1063107210641073const result = listAgentsForGateway(cfg);
1065-expect(result.agents[0]).toMatchObject({
1074+expectFields(result.agents[0], {
10661075id: "main",
10671076workspace: "/tmp/default-workspace",
1068- model: {
1069- primary: "openai/gpt-5.4",
1070- fallbacks: ["openai-codex/gpt-5.4"],
1071-},
1072- agentRuntime: {
1073- id: "codex",
1074- source: "implicit",
1075-},
1077+});
1078+expect(result.agents[0]?.model).toEqual({
1079+primary: "openai/gpt-5.4",
1080+fallbacks: ["openai-codex/gpt-5.4"],
1081+});
1082+expect(result.agents[0]?.agentRuntime).toEqual({
1083+id: "codex",
1084+source: "implicit",
10761085});
10771086});
10781087@@ -1097,12 +1106,12 @@ describe("gateway session utils", () => {
10971106} as OpenClawConfig;
1098110710991108const result = listAgentsForGateway(cfg);
1100-expect(result.agents[0]).toMatchObject({
1109+expectFields(result.agents[0], {
11011110id: "main",
1102- agentRuntime: {
1103- id: "codex",
1104- source: "provider",
1105-},
1111+});
1112+expect(result.agents[0]?.agentRuntime).toEqual({
1113+id: "codex",
1114+source: "provider",
11061115});
11071116});
11081117@@ -1320,13 +1329,11 @@ describe("listSessionsFromStore selected model display", () => {
13201329expect(listed.count).toBe(expected.count);
13211330expect(listed.defaults).toEqual(expected.defaults);
13221331expect(listed.sessions).toHaveLength(expected.sessions.length);
1323-expect(listed.sessions[0]).toEqual(
1324-expect.objectContaining({
1325-key: "agent:main:sess-yield-0",
1326-derivedTitle: "title 0",
1327-lastMessagePreview: "last 0",
1328-}),
1329-);
1332+expectFields(listed.sessions[0], {
1333+key: "agent:main:sess-yield-0",
1334+derivedTitle: "title 0",
1335+lastMessagePreview: "last 0",
1336+});
13301337expect(listed.sessions[0]?.agentRuntime).toEqual({ id: "codex", source: "implicit" });
13311338expect(listed.sessions[0]?.thinkingLevel).toBeUndefined();
13321339expect(listed.sessions[0]?.thinkingLevels?.length).toBeGreaterThan(0);
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。