|
| 1 | +import { PullRequestProviderError } from "@t3tools/source-control-core/server/PullRequestProvider"; |
1 | 2 | import { SourceControlProviderKind } from "@t3tools/contracts"; |
2 | 3 | import { limitRecoveryCommand } from "./UsageLimitRecoveryWorker.ts"; |
3 | 4 | import * as McpProviderSessions from "@t3tools/provider-core/server/McpProviderSessions"; |
@@ -3172,63 +3173,155 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => { |
3172 | 3173 | }), |
3173 | 3174 | ); |
3174 | 3175 |
|
3175 | | - it.effect("ends a watch it cannot read, and tells the agent", () => |
3176 | | - Effect.gen(function* () { |
3177 | | - const orchestrator = yield* Orchestrator.OrchestratorV2; |
3178 | | - const threadId = ThreadId.make("runtime-pull-request-watch-unreadable"); |
3179 | | - const projectId = ProjectId.make("pr-watch-unreadable-project"); |
3180 | | - yield* seedProject({ |
3181 | | - projectId, |
3182 | | - title: "Watch unreadable", |
3183 | | - workspaceRoot: "/workspace/watch-unreadable", |
3184 | | - defaultModelSelection: null, |
3185 | | - createdAt: "2026-10-01T00:00:00.000Z", |
3186 | | - }); |
3187 | | - yield* orchestrator.dispatch({ |
3188 | | - type: "thread.create", |
3189 | | - createdBy: "user", |
3190 | | - creationSource: "web", |
3191 | | - commandId: CommandId.make("pr-watch-unreadable-create"), |
3192 | | - threadId, |
3193 | | - projectId, |
3194 | | - title: "Watch unreadable", |
3195 | | - modelSelection, |
3196 | | - runtimeMode: "full-access", |
3197 | | - interactionMode: "default", |
3198 | | - branch: null, |
3199 | | - worktreePath: null, |
3200 | | - }); |
3201 | | - yield* orchestrator.dispatch({ |
3202 | | - type: "thread.pull-request.watch", |
3203 | | - commandId: CommandId.make("pr-watch-unreadable-start"), |
3204 | | - threadId, |
3205 | | - host: "github.com", |
3206 | | - repository: "pingdotgg/t3code", |
3207 | | - number: 8, |
3208 | | - watching: true, |
3209 | | - link: { url: "https://github.com/pingdotgg/t3code/pull/8", source: "agent" }, |
3210 | | - }); |
3211 | | - const reactor = yield* PullRequestWatchReactor.make.pipe( |
3212 | | - Effect.provide( |
3213 | | - Layer.mergeAll( |
3214 | | - NodeServices.layer, |
3215 | | - Layer.mock(PullRequestService.PullRequestService)({ |
3216 | | - detail: () => Effect.die("host unreachable"), |
3217 | | - activity: () => Effect.die("host unreachable"), |
| 3176 | + it.effect.each([ |
| 3177 | + { reason: "failed", activityFails: false }, |
| 3178 | + { reason: "not-found", activityFails: false }, |
| 3179 | + { reason: "failed", activityFails: true }, |
| 3180 | + { reason: "not-found", activityFails: true }, |
| 3181 | + { reason: "forbidden", activityFails: true }, |
| 3182 | + ] as const)( |
| 3183 | + "handles repeated host read failures: $reason (activity fails: $activityFails)", |
| 3184 | + ({ reason, activityFails }) => |
| 3185 | + Effect.gen(function* () { |
| 3186 | + const orchestrator = yield* Orchestrator.OrchestratorV2; |
| 3187 | + const threadId = ThreadId.make( |
| 3188 | + `runtime-pull-request-watch-unreadable-${reason}-${activityFails}`, |
| 3189 | + ); |
| 3190 | + const projectId = ProjectId.make(`pr-watch-unreadable-project-${reason}-${activityFails}`); |
| 3191 | + yield* seedProject({ |
| 3192 | + projectId, |
| 3193 | + title: "Watch unreadable", |
| 3194 | + workspaceRoot: "/workspace/watch-unreadable", |
| 3195 | + defaultModelSelection: null, |
| 3196 | + createdAt: "2026-10-01T00:00:00.000Z", |
| 3197 | + }); |
| 3198 | + yield* orchestrator.dispatch({ |
| 3199 | + type: "thread.create", |
| 3200 | + createdBy: "user", |
| 3201 | + creationSource: "web", |
| 3202 | + commandId: CommandId.make(`pr-watch-unreadable-create-${reason}-${activityFails}`), |
| 3203 | + threadId, |
| 3204 | + projectId, |
| 3205 | + title: "Watch unreadable", |
| 3206 | + modelSelection, |
| 3207 | + runtimeMode: "full-access", |
| 3208 | + interactionMode: "default", |
| 3209 | + branch: null, |
| 3210 | + worktreePath: null, |
| 3211 | + }); |
| 3212 | + yield* orchestrator.dispatch({ |
| 3213 | + type: "thread.pull-request.watch", |
| 3214 | + commandId: CommandId.make(`pr-watch-unreadable-start-${reason}-${activityFails}`), |
| 3215 | + threadId, |
| 3216 | + host: "github.com", |
| 3217 | + repository: "pingdotgg/t3code", |
| 3218 | + number: 8, |
| 3219 | + watching: true, |
| 3220 | + link: { url: "https://github.com/pingdotgg/t3code/pull/8", source: "agent" }, |
| 3221 | + }); |
| 3222 | + let disconnected = false; |
| 3223 | + let passed = false; |
| 3224 | + let genericFailure = false; |
| 3225 | + const activityFailures = yield* Queue.unbounded<void>(); |
| 3226 | + const readFailure = (operation: string, failure: "failed" | "not-found" | "forbidden") => |
| 3227 | + new PullRequestOperationError({ |
| 3228 | + operation, |
| 3229 | + detail: "host read failed", |
| 3230 | + cause: new PullRequestProviderError({ |
| 3231 | + provider: SourceControlProviderKind.make("github"), |
| 3232 | + operation, |
| 3233 | + reason: failure, |
| 3234 | + detail: "host read failed", |
3218 | 3235 | }), |
| 3236 | + }); |
| 3237 | + const reactor = yield* PullRequestWatchReactor.make.pipe( |
| 3238 | + Effect.provide( |
| 3239 | + Layer.mergeAll( |
| 3240 | + NodeServices.layer, |
| 3241 | + Layer.mock(PullRequestService.PullRequestService)({ |
| 3242 | + watchFingerprint: () => Effect.succeed(null), |
| 3243 | + detail: () => |
| 3244 | + genericFailure |
| 3245 | + ? Effect.die("host read failed") |
| 3246 | + : disconnected |
| 3247 | + ? (activityFails ? Queue.take(activityFailures) : Effect.void).pipe( |
| 3248 | + Effect.andThen(Effect.fail(readFailure("detail", reason))), |
| 3249 | + ) |
| 3250 | + : Effect.succeed({ |
| 3251 | + ...watchedPullRequestDetail({ |
| 3252 | + projectId, |
| 3253 | + number: 8, |
| 3254 | + at: "2026-10-02T12:00:00.000Z", |
| 3255 | + }), |
| 3256 | + headSha: "abc1234def", |
| 3257 | + checks: [ |
| 3258 | + { |
| 3259 | + name: "test", |
| 3260 | + status: passed ? ("success" as const) : ("pending" as const), |
| 3261 | + description: null, |
| 3262 | + url: null, |
| 3263 | + required: true, |
| 3264 | + }, |
| 3265 | + ], |
| 3266 | + }), |
| 3267 | + activity: () => |
| 3268 | + disconnected && activityFails |
| 3269 | + ? Queue.offer(activityFailures, undefined).pipe( |
| 3270 | + Effect.andThen(Effect.fail(readFailure("activity", "failed"))), |
| 3271 | + ) |
| 3272 | + : Effect.succeed({ |
| 3273 | + comments: [], |
| 3274 | + commentCount: 0, |
| 3275 | + commentsTruncated: false, |
| 3276 | + reviewThreads: [], |
| 3277 | + commits: [], |
| 3278 | + }), |
| 3279 | + }), |
| 3280 | + ), |
3219 | 3281 | ), |
3220 | | - ), |
3221 | | - ); |
3222 | | - for (let pass = 0; pass < 15; pass += 1) yield* reactor.sweep; |
| 3282 | + ); |
| 3283 | + const worker = yield* EffectWorker.OrchestrationEffectWorkerV2; |
| 3284 | + const sweep = reactor.sweep.pipe(Effect.andThen(worker.drain())); |
| 3285 | + const summaries = Effect.map( |
| 3286 | + orchestrator.getThreadRecords(threadId, ["messages"]), |
| 3287 | + ({ messages }) => messages.flatMap((message) => message.notification?.summary ?? []), |
| 3288 | + ); |
| 3289 | + yield* sweep; |
| 3290 | + assert.deepEqual(yield* summaries, []); |
| 3291 | + disconnected = true; |
| 3292 | + for (let pass = 0; pass < 15; pass += 1) { |
| 3293 | + genericFailure = reason === "failed" && (pass === 0 || (pass >= 2 && pass <= 8)); |
| 3294 | + yield* TestClock.adjust("2 minutes"); |
| 3295 | + yield* sweep; |
| 3296 | + } |
3223 | 3297 |
|
3224 | | - const thread = yield* orchestrator.getThreadShell(threadId); |
3225 | | - assert.isUndefined(thread?.pullRequests?.[0]?.watch); |
3226 | | - const { messages } = yield* orchestrator.getThreadRecords(threadId, ["messages"]); |
3227 | | - assert.deepEqual( |
3228 | | - messages.flatMap((message) => message.notification?.summary ?? []), |
3229 | | - ["#8: stopped watching, could not read it"], |
3230 | | - ); |
3231 | | - }), |
| 3298 | + const thread = yield* orchestrator.getThreadShell(threadId); |
| 3299 | + if (reason !== "failed") { |
| 3300 | + assert.isUndefined(thread?.pullRequests?.[0]?.watch); |
| 3301 | + assert.deepEqual(yield* summaries, ["#8: stopped watching, could not read it"]); |
| 3302 | + return; |
| 3303 | + } |
| 3304 | + assert.isDefined(thread?.pullRequests?.[0]?.watch); |
| 3305 | + assert.deepEqual(yield* summaries, []); |
| 3306 | + disconnected = false; |
| 3307 | + genericFailure = false; |
| 3308 | + passed = true; |
| 3309 | + yield* sweep; |
| 3310 | + assert.deepEqual(yield* summaries, ["#8: checks passed"]); |
| 3311 | + yield* TestClock.adjust("10 minutes"); |
| 3312 | + yield* sweep; |
| 3313 | + assert.deepEqual(yield* summaries, ["#8: checks passed"]); |
| 3314 | + yield* orchestrator.dispatch({ |
| 3315 | + type: "thread.pull-request.watch", |
| 3316 | + commandId: CommandId.make(`pr-watch-unreadable-stop-${reason}-${activityFails}`), |
| 3317 | + threadId, |
| 3318 | + host: "github.com", |
| 3319 | + repository: "pingdotgg/t3code", |
| 3320 | + number: 8, |
| 3321 | + watching: false, |
| 3322 | + }); |
| 3323 | + yield* worker.drain(); |
| 3324 | + }), |
3232 | 3325 | ); |
3233 | 3326 |
|
3234 | 3327 | it.effect("wakes once for a state it reported, across a restart and a new watch", () => |
|
0 commit comments