Apply remaining changes

This commit is contained in:
Chris Scott committed 2026-11-17 15:07:59 -05:00
1 parent edd083e417
commit f737511ba3
2 files changed
+37 -25

No files matched your search

@@ -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<void> {
@@ -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 })
+24 -17
View File
@@ -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)
})
})