Skip to content

Commit a9078b0

Browse files
only21milclaude
andcommitted
test(server): a pinned parent's subagent child settles through both projection stores
The existing test checks the child thread object and calls isAutoSettlementCandidate on a hand-built candidate. This one writes a pinned parent and its subagent child into the SQL and the in-memory ProjectionStore, then asks each store for settlement candidates. Only the child comes back, unpinned, and resolveAutoSettlementAt settles it once it has been idle past the auto-settle window. Without the fix the child keeps the parent's pinnedAt and both stores skip it. Refs #19657 Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent aa45f0a commit a9078b0

1 file changed

Lines changed: 55 additions & 3 deletions

File tree

‎apps/server/src/orchestration-v2/SubagentProjection.test.ts‎

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
} from "@t3tools/contracts";
1717
import * as DateTime from "effect/DateTime";
1818
import * as Effect from "effect/Effect";
19+
import * as Layer from "effect/Layer";
1920

2021
import {
2122
makeSubagentChildThread,
@@ -26,8 +27,9 @@ import {
2627
endRunlessRootTurns,
2728
} from "@t3tools/provider-core/server/subagentProjection";
2829

29-
import { emptyProjection } from "./ProjectionStore.ts";
30-
import { isAutoSettlementCandidate } from "./ThreadSettlementService.ts";
30+
import * as SqlitePersistence from "../persistence/Sqlite.ts";
31+
import * as ProjectionStore from "./ProjectionStore.ts";
32+
import { isAutoSettlementCandidate, resolveAutoSettlementAt } from "./ThreadSettlementService.ts";
3133

3234
const parentThreadId = ThreadId.make("thread:subagent-snoozed-parent");
3335
const childThreadId = ThreadId.make("thread:subagent-awake-child");
@@ -160,8 +162,58 @@ it("creates a pinned parent's subagent child unpinned so it can settle", () => {
160162
}
161163
});
162164

165+
it.effect.each([
166+
["sql", ProjectionStore.layer.pipe(Layer.provideMerge(SqlitePersistence.layerMemory))],
167+
["memory", ProjectionStore.layerMemory],
168+
] as const)(
169+
"%s: a pinned parent's subagent child is born unpinned and settles once idle",
170+
([, testLayer]) =>
171+
Effect.gen(function* () {
172+
const store = yield* ProjectionStore.ProjectionStoreV2;
173+
const parentThread = { ...makeParentThread(), pinnedAt: parentCreatedAt, pinOrderKey: "a0" };
174+
const childThread = makeSubagentChildThread({
175+
parentThread,
176+
childThreadId,
177+
parentNodeId: NodeId.make("node:subagent-parent"),
178+
activeProviderThreadId: null,
179+
providerInstanceId: childProviderInstanceId,
180+
modelSelection: childModelSelection,
181+
title: "Child",
182+
now: childCreatedAt,
183+
createdBy: "agent",
184+
creationSource: "provider",
185+
});
186+
187+
assert.isNull(childThread.pinnedAt);
188+
assert.isNull(childThread.pinOrderKey);
189+
190+
for (const thread of [parentThread, childThread]) {
191+
yield* store.apply({
192+
id: EventId.make(`event:${thread.id}`),
193+
type: "thread.created",
194+
threadId: thread.id,
195+
occurredAt: thread.createdAt,
196+
payload: thread,
197+
});
198+
}
199+
const candidates = yield* store.getSettlementCandidates();
200+
assert.deepEqual(
201+
candidates.map((candidate) => candidate.id),
202+
[childThreadId],
203+
);
204+
const settledAt = resolveAutoSettlementAt({
205+
thread: candidates[0]!,
206+
pullRequest: null,
207+
nowMs: DateTime.toEpochMillis(DateTime.add(childCreatedAt, { days: 4 })),
208+
autoSettleAfterDays: 3,
209+
autoSettleOnMerge: false,
210+
});
211+
assert.equal(settledAt && DateTime.formatIso(settledAt), DateTime.formatIso(childCreatedAt));
212+
}).pipe(Effect.provide(testLayer)),
213+
);
214+
163215
function taskFixture() {
164-
const projection = emptyProjection({
216+
const projection = ProjectionStore.emptyProjection({
165217
type: "thread.created",
166218
id: EventId.make("task-fixture"),
167219
threadId: parentThreadId,

0 commit comments

Comments
 (0)