From f737511ba31f74ab9a79438023afba361281783f Mon Sep 17 00:00:00 2001 From: Chris Scott <99081550+chriswritescode-dev@users.noreply.github.com> Date: Tue, 17 Nov 2026 15:07:59 -0500 Subject: [PATCH] Apply remaining changes --- .../goal-rpc-cold-location.test.ts | 21 ++++++---- frontend/src/hooks/useSessionGoals.test.tsx | 41 +++++++++++-------- 2 files changed, 37 insertions(+), 25 deletions(-) diff --git a/backend/test/integration/goal-rpc-cold-location.test.ts b/backend/test/integration/goal-rpc-cold-location.test.ts index 32f4f4d3..70d1ffee 100644 --- a/backend/test/integration/goal-rpc-cold-location.test.ts +++ b/backend/test/integration/goal-rpc-cold-location.test.ts @@ -66,8 +66,8 @@ describe.skipIf(BINARY === null)(`OpenCode ${VERSION ?? 'unknown'} cold-Location let recorded: RecordedEvent[] const controller = new AbortController() - function findPluginUpdated(directory: string): RecordedEvent | undefined { - return recorded.find((event) => event.type === 'plugin.updated' && event.directory === directory) + function findPluginUpdated(directory: string, fromIndex = 0): RecordedEvent | undefined { + return recorded.slice(fromIndex).find((event) => event.type === 'plugin.updated' && event.directory === directory) } async function startEventRecorder(): Promise { @@ -194,21 +194,26 @@ describe.skipIf(BINARY === null)(`OpenCode ${VERSION ?? 'unknown'} cold-Location } }, 120000) - it('restores the Goal read after a location reload', async () => { + it('reports the Goal unavailable after a location reload until plugin.updated names the directory', async () => { try { + const eventsBeforeReload = recorded.length await client.api.location.reload({ headers: { [OPENCODE_DIRECTORY_HEADER]: encodeURIComponent(coldDirectory) } }) const immediateStartedAt = Date.now() const immediate = await readSessionGoal(client.api, { sessionID: SESSION_ID, directory: coldDirectory }) const immediateDuration = Date.now() - immediateStartedAt if (RPC_SKIPS_ACTIVATION) { - const readable = await waitFor('the Goal to be readable after the location reload', async () => { - const read = await readSessionGoal(client.api, { sessionID: SESSION_ID, directory: coldDirectory }) - return read.supported ? read : undefined - }) - expect(readable).toEqual({ supported: true, goal: null }) + expect(immediate).toEqual({ supported: false }) + expect(immediateDuration).toBeLessThan(SLOW_PLUGIN_MS / 2) + await waitFor('a plugin.updated event for the cold Location after the reload', () => + findPluginUpdated(coldDirectory, eventsBeforeReload), + ) + expect(await readSessionGoal(client.api, { sessionID: SESSION_ID, directory: coldDirectory })).toEqual({ supported: true, goal: null }) } else { expect(immediate).toEqual({ supported: true, goal: null }) expect(immediateDuration).toBeGreaterThanOrEqual(SLOW_PLUGIN_MS - 500) + await waitFor('a plugin.updated event for the cold Location after the reload', () => + findPluginUpdated(coldDirectory, eventsBeforeReload), + ) } } catch (error) { throw new Error(`${error instanceof Error ? error.message : String(error)}\n${serve.readOutput()}`, { cause: error }) diff --git a/frontend/src/hooks/useSessionGoals.test.tsx b/frontend/src/hooks/useSessionGoals.test.tsx index dfdb58ca..9dce12f3 100644 --- a/frontend/src/hooks/useSessionGoals.test.tsx +++ b/frontend/src/hooks/useSessionGoals.test.tsx @@ -146,26 +146,27 @@ describe('invalidateSessionGoalsForLocation', () => { }) it('keeps an always-unavailable goal unsupported without retrying', async () => { - const { result, fetchFake, queryClient } = renderHookWithProviders(() => useSessionGoal('ses_1', '/repo'), { - ...hookProviders, - fetchRoutes: [goalRoute(() => ({ status: 400, json: unavailableGoalBody }))], - }) - - await waitFor(() => expect(result.current.data).toEqual({ supported: false })) - - await act(async () => { - await invalidateSessionGoalsForLocation(queryClient, LOCAL_OPENCODE_SERVER_ID, '/repo') - }) - - await waitFor(() => expect(fetchFake.findRequests('POST', goalReadPath)).toHaveLength(2)) - expect(result.current.data).toEqual({ supported: false }) - - vi.useFakeTimers() + vi.useFakeTimers({ shouldAdvanceTime: true }) try { + const { result, fetchFake, queryClient } = renderHookWithProviders(() => useSessionGoal('ses_1', '/repo'), { + ...hookProviders, + fetchRoutes: [goalRoute(() => ({ status: 400, json: unavailableGoalBody }))], + }) + + await waitFor(() => expect(result.current.data).toEqual({ supported: false })) + + await act(async () => { + await invalidateSessionGoalsForLocation(queryClient, LOCAL_OPENCODE_SERVER_ID, '/repo') + }) + + await waitFor(() => expect(fetchFake.findRequests('POST', goalReadPath)).toHaveLength(2)) + expect(result.current.data).toEqual({ supported: false }) + await act(async () => { await vi.advanceTimersByTimeAsync(10_000) }) expect(fetchFake.findRequests('POST', goalReadPath)).toHaveLength(2) + expect(result.current.data).toEqual({ supported: false }) } finally { vi.useRealTimers() } @@ -197,7 +198,7 @@ describe('invalidateSessionGoalsForLocation', () => { } }) - it('does not refetch or leak data for an inactive query after unmount', async () => { + it('does not refetch an inactive goal query or cache other locations after unmount', async () => { const pending = deferred() const { unmount, fetchFake, queryClient } = renderHookWithProviders(() => useSessionGoal('ses_1', '/repo'), { ...hookProviders, @@ -221,7 +222,13 @@ describe('invalidateSessionGoalsForLocation', () => { pending.resolve({ json: { output: goal } }) }) - expect(queryClient.getQueryData(['session-goal', 'ses_1', '/other'])).toBeUndefined() + await waitFor(() => + expect(queryClient.getQueryState(['session-goal', 'ses_1', '/repo'])?.fetchStatus).toBe('idle'), + ) + expect(queryClient.getQueryCache().findAll({ queryKey: ['session-goal'] }).map((query) => query.queryKey)).toEqual([ + ['session-goal', 'ses_1', '/repo'], + ]) + expect(fetchFake.findRequests('POST', goalReadPath)).toHaveLength(1) }) })