Skip to content

Commit 6cf266d

Browse files
committed
test(server): cover archived preparation through the launcher
1 parent e770f7a commit 6cf266d

2 files changed

Lines changed: 71 additions & 23 deletions

File tree

‎apps/server/src/orchestration-v2/Orchestrator.control-reads.test.ts‎

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -104,29 +104,6 @@ for (const terminalCommand of ["thread.archive", "thread.delete"] as const) {
104104
assert.equal(error.cause, `Thread ${threadId} is not active.`);
105105
assert.deepEqual(yield* projections.getThreadProjection(threadId), before);
106106
assert.deepEqual(yield* outbox.listByCommandId(commandId), []);
107-
if (terminalCommand === "thread.archive") {
108-
yield* orchestrator.dispatch({
109-
type: "thread.unarchive",
110-
commandId: CommandId.make("unarchive-terminal-preparation"),
111-
threadId,
112-
});
113-
const resumedCommandId = CommandId.make("release-unarchived-preparation");
114-
yield* orchestrator.dispatch({
115-
type: "prepared-run.release",
116-
commandId: resumedCommandId,
117-
threadId,
118-
runId,
119-
});
120-
assert.equal(
121-
(yield* projections.getThreadProjection(threadId)).runs[0]!.status,
122-
"starting",
123-
);
124-
assert.isTrue(
125-
(yield* outbox.listByCommandId(resumedCommandId)).some(
126-
(effect) => effect.request.type === "provider-turn.start",
127-
),
128-
);
129-
}
130107
}).pipe(Effect.provide(testLayer)),
131108
);
132109
}

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

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1959,6 +1959,77 @@ it.effect("shared intake preserves durable attachment bytes after a lost launch
19591959
}).pipe(Effect.provide(Layer.mergeAll(harness.layer, files)));
19601960
});
19611961

1962+
it.effect("fails preparation completed while archived and accepts a new send after unarchive", () =>
1963+
Effect.gen(function* () {
1964+
const setupEntered = yield* Deferred.make<void>();
1965+
const allowSetup = yield* Deferred.make<void>();
1966+
const harness = makeHarness({
1967+
runSetup: () =>
1968+
Deferred.succeed(setupEntered, undefined).pipe(
1969+
Effect.andThen(Deferred.await(allowSetup)),
1970+
Effect.as({ status: "no-script" as const }),
1971+
),
1972+
});
1973+
yield* Effect.gen(function* () {
1974+
const launches = yield* ThreadLaunch.ThreadLaunchService;
1975+
const threads = yield* ThreadManagement.ThreadManagementService;
1976+
const outbox = yield* EffectOutbox.EffectOutboxV2;
1977+
const input = launchInput({
1978+
command: "launch:archive-during-setup",
1979+
thread: "thread:archive-during-setup",
1980+
message: "Start",
1981+
});
1982+
const launched = yield* launches.launch(input);
1983+
yield* Deferred.await(setupEntered);
1984+
yield* threads.dispatch({
1985+
type: "thread.archive",
1986+
commandId: CommandId.make("archive:during-setup"),
1987+
threadId: launched.threadId,
1988+
});
1989+
yield* Deferred.succeed(allowSetup, undefined);
1990+
yield* threads.streamStoredEventsFrom({ threadId: launched.threadId }).pipe(
1991+
Stream.filter(
1992+
(stored) =>
1993+
(stored.commandId === CommandId.make(`${input.commandId}:fail`) ||
1994+
stored.commandId === CommandId.make(`${input.commandId}:release`)) &&
1995+
stored.event.type === "run.updated",
1996+
),
1997+
Stream.runHead,
1998+
);
1999+
const failed = yield* threads.getThreadProjection(launched.threadId);
2000+
assert.equal(failed.runs[0]?.status, "failed");
2001+
assert.isEmpty(failed.providerTurns);
2002+
assert.isEmpty(failed.checkpointScopes);
2003+
assert.isEmpty(yield* outbox.listByCommandId(CommandId.make(`${input.commandId}:release`)));
2004+
2005+
yield* threads.dispatch({
2006+
type: "thread.unarchive",
2007+
commandId: CommandId.make("unarchive:after-setup"),
2008+
threadId: launched.threadId,
2009+
});
2010+
const next = yield* threads.sendToThread({
2011+
projectId,
2012+
commandId: CommandId.make("send:after-unarchive"),
2013+
threadId: launched.threadId,
2014+
messageId: MessageId.make("message:after-unarchive"),
2015+
text: "Try again",
2016+
attachments: [],
2017+
mode: "auto",
2018+
createdBy: "user",
2019+
creationSource: "web",
2020+
});
2021+
assert.equal(next.delivery, "started");
2022+
assert.equal(next.run.status, "starting");
2023+
assert.notEqual(next.run.id, failed.runs[0]?.id);
2024+
assert.isTrue(
2025+
(yield* outbox.listByCommandId(CommandId.make("send:after-unarchive"))).some(
2026+
(entry) => entry.request.type === "provider-turn.start",
2027+
),
2028+
);
2029+
}).pipe(Effect.provide(harness.layer));
2030+
}),
2031+
);
2032+
19622033
it.effect("cancels tracked setup before provider work is released", () =>
19632034
Effect.gen(function* () {
19642035
const entered = yield* Deferred.make<void>();

0 commit comments

Comments
 (0)