test: tighten config session assertions · openclaw/openclaw@2858afd
steipete
·
2026-05-11
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -293,8 +293,7 @@ describe("resolveToolsBySender", () => {
|
293 | 293 | |
294 | 294 | expect(warningSpy).toHaveBeenCalledTimes(1); |
295 | 295 | expect(String(warningSpy.mock.calls[0]?.[0])).toContain(`toolsBySender key "${legacyKey}"`); |
296 | | -expect(warningSpy.mock.calls[0]?.[1]).toMatchObject({ |
297 | | -code: "OPENCLAW_TOOLS_BY_SENDER_UNTYPED_KEY", |
298 | | -}); |
| 296 | +const warningMeta = warningSpy.mock.calls[0]?.[1] as { code?: unknown } | undefined; |
| 297 | +expect(warningMeta?.code).toBe("OPENCLAW_TOOLS_BY_SENDER_UNTYPED_KEY"); |
299 | 298 | }); |
300 | 299 | }); |
| Original file line number | Diff line number | Diff line change |
|---|
@@ -211,7 +211,9 @@ describe("resolveConfigIncludes", () => {
|
211 | 211 | } catch (err) { |
212 | 212 | expect(err).toBeInstanceOf(CircularIncludeError); |
213 | 213 | const circular = err as CircularIncludeError; |
214 | | -expect(circular.chain).toEqual(expect.arrayContaining([DEFAULT_BASE_PATH, aPath, bPath])); |
| 214 | +expect(circular.chain).toContain(DEFAULT_BASE_PATH); |
| 215 | +expect(circular.chain).toContain(aPath); |
| 216 | +expect(circular.chain).toContain(bPath); |
215 | 217 | expect(circular.message).toMatch(/Circular include detected/); |
216 | 218 | expect(circular.message).toContain("a.json"); |
217 | 219 | expect(circular.message).toContain("b.json"); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -632,9 +632,7 @@ describe("config io write prepare", () => {
|
632 | 632 | auth: { mode: "token" }, |
633 | 633 | }); |
634 | 634 | const channels = persisted.channels as Record<string, Record<string, unknown>> | undefined; |
635 | | -expect(channels?.imessage).toMatchObject({ |
636 | | -cliPath: "/usr/local/bin/imsg", |
637 | | -}); |
| 635 | +expect(channels?.imessage?.cliPath).toBe("/usr/local/bin/imsg"); |
638 | 636 | expect(channels?.imessage).not.toHaveProperty("runtimeOnlyDefault"); |
639 | 637 | }); |
640 | 638 | |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -365,8 +365,6 @@ describe("Session Store Cache", () => {
|
365 | 365 | |
366 | 366 | // The cache should detect the size change and reload from disk |
367 | 367 | const loaded2 = loadSessionStore(storePath); |
368 | | -expect(loaded2).toMatchObject({ |
369 | | -"session:2": { displayName: "Added" }, |
370 | | -}); |
| 368 | +expect(loaded2["session:2"]?.displayName).toBe("Added"); |
371 | 369 | }); |
372 | 370 | }); |
| Original file line number | Diff line number | Diff line change |
|---|
@@ -105,7 +105,13 @@ describe("sessions", () => {
|
105 | 105 | } |
106 | 106 | |
107 | 107 | async function expectPathMissing(targetPath: string): Promise<void> { |
108 | | -await expect(fs.stat(targetPath)).rejects.toMatchObject({ code: "ENOENT" }); |
| 108 | +let error: { code?: unknown } | undefined; |
| 109 | +try { |
| 110 | +await fs.stat(targetPath); |
| 111 | +} catch (err) { |
| 112 | +error = err as { code?: unknown }; |
| 113 | +} |
| 114 | +expect(error?.code).toBe("ENOENT"); |
109 | 115 | } |
110 | 116 | |
111 | 117 | const deriveSessionKeyCases = [ |
@@ -493,7 +499,8 @@ describe("sessions", () => {
|
493 | 499 | sessionKey, |
494 | 500 | update: async () => null, |
495 | 501 | }); |
496 | | -expect(result).toEqual(expect.objectContaining({ sessionId: "sess-1", thinkingLevel: "low" })); |
| 502 | +expect(result?.sessionId).toBe("sess-1"); |
| 503 | +expect(result?.thinkingLevel).toBe("low"); |
497 | 504 | |
498 | 505 | const store = loadSessionStore(storePath); |
499 | 506 | expect(store[sessionKey]?.thinkingLevel).toBe("low"); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -13,12 +13,9 @@ describe("readSessionStoreReadOnly", () => {
|
13 | 13 | expect(readSessionStoreReadOnly(storePath)).toStrictEqual({}); |
14 | 14 | |
15 | 15 | await fs.writeFile(storePath, '{"session-1":{"sessionId":"s1","updatedAt":1}}\n', "utf8"); |
16 | | -expect(readSessionStoreReadOnly(storePath)).toMatchObject({ |
17 | | -"session-1": { |
18 | | -sessionId: "s1", |
19 | | -updatedAt: 1, |
20 | | -}, |
21 | | -}); |
| 16 | +const store = readSessionStoreReadOnly(storePath); |
| 17 | +expect(store["session-1"]?.sessionId).toBe("s1"); |
| 18 | +expect(store["session-1"]?.updatedAt).toBe(1); |
22 | 19 | }); |
23 | 20 | }); |
24 | 21 | }); |
| Original file line number | Diff line number | Diff line change |
|---|
@@ -203,10 +203,12 @@ describe("appendAssistantMessageToSessionTranscript", () => {
|
203 | 203 | message: { role: "user", content: "x".repeat(5 * 1024 * 1024) }, |
204 | 204 | }); |
205 | 205 | |
206 | | -await expect(readLatestAssistantTextFromSessionTranscript(sessionFile)).resolves.toMatchObject({ |
207 | | -id: exactResult.messageId, |
208 | | -text: "Hello before the large user entry", |
209 | | -}); |
| 206 | +const latestAssistantText = await readLatestAssistantTextFromSessionTranscript(sessionFile); |
| 207 | +if (!latestAssistantText) { |
| 208 | +throw new Error("expected latest assistant text"); |
| 209 | +} |
| 210 | +expect(latestAssistantText.id).toBe(exactResult.messageId); |
| 211 | +expect(latestAssistantText.text).toBe("Hello before the large user entry"); |
210 | 212 | |
211 | 213 | const mirrorResult = await appendAssistantMessageToSessionTranscript({ |
212 | 214 | sessionKey, |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -4,12 +4,10 @@ import { SessionSchema } from "./zod-schema.session.js";
|
4 | 4 | |
5 | 5 | describe("typing mode schema reuse", () => { |
6 | 6 | it("accepts supported typingMode values for session and agent defaults", () => { |
7 | | -expect(SessionSchema.parse({ typingMode: "thinking" })).toMatchObject({ |
8 | | -typingMode: "thinking", |
9 | | -}); |
10 | | -expect(AgentDefaultsSchema.parse({ typingMode: "message" })).toMatchObject({ |
11 | | -typingMode: "message", |
12 | | -}); |
| 7 | +const session = SessionSchema.parse({ typingMode: "thinking" }); |
| 8 | +const agentDefaults = AgentDefaultsSchema.parse({ typingMode: "message" }); |
| 9 | +expect(session?.typingMode).toBe("thinking"); |
| 10 | +expect(agentDefaults?.typingMode).toBe("message"); |
13 | 11 | }); |
14 | 12 | |
15 | 13 | it("rejects unsupported typingMode values for session and agent defaults", () => { |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。