fix(team-mode): preserve member context on retry
This commit is contained in:
@@ -2,7 +2,7 @@ import { afterAll, beforeEach, describe, expect, mock, test } from "bun:test"
|
||||
|
||||
const sharedLogMock = mock(() => {})
|
||||
const readConnectedProvidersCacheMock = mock(() => null)
|
||||
const readProviderModelsCacheMock = mock(() => null)
|
||||
const readProviderModelsCacheMock = mock((): { connected: string[] } | null => null)
|
||||
const shouldRetryErrorMock = mock(() => true)
|
||||
const getNextFallbackMock = mock((chain: Array<{ model: string }>, attempt: number) => chain[attempt])
|
||||
const hasMoreFallbacksMock = mock((chain: Array<{ model: string }>, attempt: number) => attempt < chain.length)
|
||||
@@ -88,7 +88,7 @@ function createMockConcurrencyManager(): ConcurrencyManager {
|
||||
acquire: mock(async () => {}),
|
||||
getQueueLength: mock(() => 0),
|
||||
getActiveCount: mock(() => 0),
|
||||
} as unknown as ConcurrencyManager
|
||||
} as never
|
||||
}
|
||||
|
||||
function createMockClient(): {
|
||||
@@ -101,7 +101,7 @@ function createMockClient(): {
|
||||
session: {
|
||||
abort: abortMock,
|
||||
},
|
||||
} as unknown as OpencodeClient,
|
||||
} as never,
|
||||
abortMock,
|
||||
}
|
||||
}
|
||||
@@ -133,9 +133,9 @@ describe("tryFallbackRetry", () => {
|
||||
})
|
||||
|
||||
beforeEach(() => {
|
||||
;(shouldRetryError as any).mockImplementation(() => true)
|
||||
;(selectFallbackProvider as any).mockImplementation((providers: string[]) => providers[0])
|
||||
;(readProviderModelsCache as any).mockReturnValue(null)
|
||||
shouldRetryError.mockImplementation(() => true)
|
||||
selectFallbackProvider.mockImplementation((providers: string[]) => providers[0])
|
||||
readProviderModelsCache.mockReturnValue(null)
|
||||
})
|
||||
|
||||
describe("#given retryable error with fallback chain", () => {
|
||||
@@ -260,6 +260,21 @@ describe("tryFallbackRetry", () => {
|
||||
expect(args.processKey).toHaveBeenCalledWith(key)
|
||||
})
|
||||
|
||||
test("preserves team identity and session callback in retry input", async () => {
|
||||
const onSessionCreated = mock(async () => {})
|
||||
const args = createDefaultArgs({
|
||||
teamRunId: "team-run-1",
|
||||
onSessionCreated,
|
||||
})
|
||||
|
||||
await tryFallbackRetry(args)
|
||||
|
||||
const key = `${args.task.model!.providerID}/${args.task.model!.modelID}`
|
||||
const retryInput = args.queuesByKey.get(key)?.[0]?.input
|
||||
expect(retryInput?.teamRunId).toBe("team-run-1")
|
||||
expect(retryInput?.onSessionCreated).toBe(onSessionCreated)
|
||||
})
|
||||
|
||||
test("finalizes the failed attempt, creates a new pending attempt, and enqueues its explicit attemptID", async () => {
|
||||
const args = createDefaultArgs({
|
||||
status: "running",
|
||||
@@ -308,13 +323,16 @@ describe("tryFallbackRetry", () => {
|
||||
const key = `${args.task.model!.providerID}/${args.task.model!.modelID}`
|
||||
const queue = args.queuesByKey.get(key)
|
||||
expect(queue).toBeDefined()
|
||||
expect((queue?.[0] as QueueItem & { attemptID?: string })?.attemptID).toBe(nextAttempt?.attemptId)
|
||||
const queuedAttemptID = queue?.[0]?.attemptID
|
||||
expect(queuedAttemptID).toBeDefined()
|
||||
expect(nextAttempt?.attemptId).toBeDefined()
|
||||
expect(queuedAttemptID).toBe(nextAttempt?.attemptId ?? "")
|
||||
})
|
||||
})
|
||||
|
||||
describe("#given non-retryable error", () => {
|
||||
test("returns false when shouldRetryError returns false", async () => {
|
||||
;(shouldRetryError as any).mockImplementation(() => false)
|
||||
shouldRetryError.mockImplementation(() => false)
|
||||
const args = createDefaultArgs()
|
||||
|
||||
const result = await tryFallbackRetry(args)
|
||||
@@ -415,8 +433,8 @@ describe("tryFallbackRetry", () => {
|
||||
|
||||
describe("#given disconnected fallback providers with connected preferred provider", () => {
|
||||
test("keeps fallback entry and selects connected preferred provider", async () => {
|
||||
;(readProviderModelsCache as any).mockReturnValueOnce({ connected: ["provider-a"] })
|
||||
;(selectFallbackProvider as any).mockImplementationOnce(
|
||||
readProviderModelsCache.mockReturnValueOnce({ connected: ["provider-a"] })
|
||||
selectFallbackProvider.mockImplementationOnce(
|
||||
(_providers: string[], preferredProviderID?: string) => preferredProviderID ?? "provider-b",
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user