|
8 | 8 | ProviderInstanceId, |
9 | 9 | RunId, |
10 | 10 | ThreadId, |
| 11 | + TurnItemId, |
11 | 12 | type OrchestrationProjectShell, |
12 | 13 | type OrchestrationV2AppThread, |
13 | 14 | type OrchestrationV2Command, |
@@ -598,9 +599,12 @@ const makeHarness = Effect.fn("makeThreadSettlementHarness")(function* (options: |
598 | 599 | return next; |
599 | 600 | }); |
600 | 601 |
|
601 | | - const branchPullRequest: GitManager.GitManager["Service"]["branchPullRequest"] = (input) => |
| 602 | + const branchPullRequest: GitManager.GitManager["Service"]["branchPullRequest"] = ( |
| 603 | + input, |
| 604 | + lookupOptions, |
| 605 | + ) => |
602 | 606 | Ref.update(branchCalls, (calls) => [...calls, input]).pipe( |
603 | | - Effect.andThen(options.branchPullRequest?.(input) ?? Effect.succeed(null)), |
| 607 | + Effect.andThen(options.branchPullRequest?.(input, lookupOptions) ?? Effect.succeed(null)), |
604 | 608 | ); |
605 | 609 | const pullRequestSummary: PullRequestService.PullRequestService["Service"]["summary"] = ( |
606 | 610 | input, |
@@ -1051,6 +1055,75 @@ describe("ThreadSettlementServiceV2 worker", () => { |
1051 | 1055 | ), |
1052 | 1056 | ); |
1053 | 1057 |
|
| 1058 | + it.effect("settles an unlinked branch thread its agent merged from a shell, past the cache", () => |
| 1059 | + Effect.scoped( |
| 1060 | + Effect.gen(function* () { |
| 1061 | + yield* TestClock.setTime(Date.parse(NOW)); |
| 1062 | + const settled = yield* Deferred.make<void>(); |
| 1063 | + const thread = makeThread("shell-merged", { |
| 1064 | + branch: "saved-feature", |
| 1065 | + latestUserMessageAt: DateTime.makeUnsafe("2026-08-27T00:00:00.000Z"), |
| 1066 | + }); |
| 1067 | + const fixture = yield* makeHarness({ |
| 1068 | + snapshot: makeSnapshot([thread]), |
| 1069 | + // The host already merged it; only a fresh read sees that past the cached open lookup. |
| 1070 | + branchPullRequest: (_input, lookupOptions) => |
| 1071 | + Effect.succeed(makeBranchPullRequest(lookupOptions?.refresh ? "merged" : "open")), |
| 1072 | + onDispatch: () => Deferred.succeed(settled, undefined), |
| 1073 | + }); |
| 1074 | + const at = DateTime.makeUnsafe(NOW); |
| 1075 | + const runId = RunId.make("run:shell-merged"); |
| 1076 | + const runEnded: OrchestrationV2DomainEvent = { |
| 1077 | + type: "run.background-work-cancelled", |
| 1078 | + id: EventId.make("event:shell-merged:run-ended"), |
| 1079 | + threadId: thread.id, |
| 1080 | + occurredAt: at, |
| 1081 | + payload: { runId, restartCancelledBackgroundWork: [] }, |
| 1082 | + }; |
| 1083 | + |
| 1084 | + yield* Effect.gen(function* () { |
| 1085 | + const reactor = yield* ThreadSettlementService.ThreadSettlementServiceV2; |
| 1086 | + yield* startHarness(reactor, fixture.activation, fixture.snapshotReads); |
| 1087 | + yield* fixture.publishEvent(runEnded); |
| 1088 | + yield* Queue.take(fixture.snapshotReads); |
| 1089 | + yield* reactor.drain; |
| 1090 | + assert.deepStrictEqual(yield* Ref.get(fixture.commands), []); |
| 1091 | + |
| 1092 | + yield* fixture.publishEvent({ |
| 1093 | + type: "turn-item.updated", |
| 1094 | + id: EventId.make("event:shell-merged:command"), |
| 1095 | + threadId: thread.id, |
| 1096 | + runId, |
| 1097 | + occurredAt: at, |
| 1098 | + payload: { |
| 1099 | + id: TurnItemId.make("item:shell-merged:command"), |
| 1100 | + threadId: thread.id, |
| 1101 | + runId, |
| 1102 | + nodeId: null, |
| 1103 | + providerThreadId: null, |
| 1104 | + providerTurnId: null, |
| 1105 | + nativeItemRef: null, |
| 1106 | + parentItemId: null, |
| 1107 | + ordinal: 1, |
| 1108 | + status: "completed", |
| 1109 | + title: null, |
| 1110 | + startedAt: at, |
| 1111 | + completedAt: at, |
| 1112 | + updatedAt: at, |
| 1113 | + type: "command_execution", |
| 1114 | + input: "gh pr merge 42 --squash", |
| 1115 | + }, |
| 1116 | + }); |
| 1117 | + yield* Deferred.await(settled); |
| 1118 | + assert.deepStrictEqual( |
| 1119 | + (yield* Ref.get(fixture.commands)).map((command) => command.threadId), |
| 1120 | + [thread.id], |
| 1121 | + ); |
| 1122 | + }).pipe(Effect.provide(fixture.layer)); |
| 1123 | + }), |
| 1124 | + ), |
| 1125 | + ); |
| 1126 | + |
1054 | 1127 | it.effect( |
1055 | 1128 | "settles branch threads on a pull request merge without waiting for the next sweep", |
1056 | 1129 | () => |
|
0 commit comments