From 55663b5cf6c20898d0778ce2c7b842c1e4b7d7ce Mon Sep 17 00:00:00 2001 From: YeonGyu-Kim Date: Fri, 29 May 2026 17:37:19 +0900 Subject: [PATCH] test(atlas): model safe idle messages in hook mocks Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus --- src/hooks/atlas/index.test.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/hooks/atlas/index.test.ts b/src/hooks/atlas/index.test.ts index 4004f6383..8c109687b 100644 --- a/src/hooks/atlas/index.test.ts +++ b/src/hooks/atlas/index.test.ts @@ -31,6 +31,7 @@ describe("atlas hook", () => { function createMockPluginInput(overrides?: { promptMock?: ReturnType sessionGetMock?: ReturnType + sessionMessagesMock?: ReturnType }): MockAtlasInput { const promptMock = overrides?.promptMock ?? mock(() => Promise.resolve()) const sessionGetMock = overrides?.sessionGetMock ?? mock(async ({ path }: { path: { id: string } }) => ({ @@ -39,8 +40,12 @@ describe("atlas hook", () => { parentID: path.id.startsWith("ses_") ? "session-1" : "main-session-123", }, })) + const sessionMessagesMock = overrides?.sessionMessagesMock ?? mock(async () => ({ + data: [{ info: { role: "assistant", finish: "unknown", time: { completed: 1 } }, parts: [{ type: "text", text: "idle" }] }], + })) const client = createOpencodeClient({ baseUrl: "http://localhost" }) Reflect.set(client.session, "get", sessionGetMock) + Reflect.set(client.session, "messages", sessionMessagesMock) Reflect.set(client.session, "prompt", promptMock) Reflect.set(client.session, "promptAsync", promptMock) @@ -51,6 +56,7 @@ describe("atlas hook", () => { serverUrl: new URL("http://localhost"), $: {} as Parameters[0]["$"], client, + experimental_workspace: { register: () => {} }, _promptMock: promptMock, _sessionGetMock: sessionGetMock, } @@ -2677,15 +2683,15 @@ session_id: ses_untrusted_999 }) as typeof setTimeout globalThis.clearTimeout = ((id?: ReturnType) => { - const timerEntry = id ? capturedTimers.get(id) : undefined + if (id === undefined) return + + const timerEntry = capturedTimers.get(id) if (timerEntry) { timerEntry.cleared = true capturedTimers.delete(id) return } - if (id !== undefined) { - originalClearTimeout(id) - } + originalClearTimeout(id) }) as typeof clearTimeout })