Skip to content
TypeScript

test(server): ACP adapter tests no longer race the prompt settle (#15330)

Theo Brownea21702d0e58a
diff --git a/apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts b/apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts
index 14692458676..b6cb0be45ac 100644
--- a/apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts
+++ b/apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts
@@ -4925,9 +4925,13 @@ describe("AcpAdapterV2", () => {
const mockAgentPath = yield* path.fromFileUrl(
new URL("../../../scripts/acp-mock-agent.ts", import.meta.url),
);
- const protocolEvents = yield* Queue.bounded<EffectAcpProtocol.AcpProtocolLogEvent>(256);
const instanceId = ProviderInstanceId.make("acp-test");
+ const promptSettled = yield* Deferred.make<void>();
const adapter = makeAcpAdapterV2({
+ testHooks: {
+ afterPromptSettledWithBackgroundWork: () =>
+ Deferred.succeed(promptSettled, undefined).pipe(Effect.asVoid),
+ },
crypto: yield* Crypto.Crypto,
instanceId,
flavor: {
@@ -4950,7 +4954,6 @@ describe("AcpAdapterV2", () => {
childProcessSpawner,
mockAgentPath,
environment: { T3_ACP_EMIT_GENERIC_TOOL_PLACEHOLDERS: "1" },
- protocolEvents,
}),
},
fileSystem,
@@ -4986,28 +4989,13 @@ describe("AcpAdapterV2", () => {
makeTurnInput({ threadId, providerThread, instanceId, runtimePolicy, now }),
);
// The still-running subagent defers finalize after session/prompt returns.
- yield* Stream.fromQueue(protocolEvents).pipe(
- Stream.filter(
- (event) =>
- event.direction === "incoming" &&
- event.stage === "raw" &&
- typeof event.payload === "string" &&
- event.payload.includes('"stopReason"'),
- ),
- Stream.runHead,
- );
- yield* Effect.yieldNow;
- yield* Effect.yieldNow;
+ yield* Deferred.await(promptSettled);
const providerTurnId = idAllocator.derive.providerTurn({
driver: ACP_TEST_DRIVER,
nativeTurnId: acpScopedNativeId(instanceId, "mock-session-1:turn:1"),
});
- const interruptFiber = yield* runtime
- .interruptTurn({ providerThread, providerTurnId })
- .pipe(Effect.forkScoped);
- yield* TestClock.adjust("10 seconds");
- yield* Fiber.join(interruptFiber);
+ yield* runtime.interruptTurn({ providerThread, providerTurnId });
let terminalStatus: string | null = null;
while (terminalStatus === null) {
@@ -5033,10 +5021,14 @@ describe("AcpAdapterV2", () => {
const mockAgentPath = yield* path.fromFileUrl(
new URL("../../../scripts/acp-mock-agent.ts", import.meta.url),
);
- const protocolEvents = yield* Queue.bounded<EffectAcpProtocol.AcpProtocolLogEvent>(256);
const instanceId = ProviderInstanceId.make("acp-test");
let subagentPhase: "spawn" | "complete" = "spawn";
+ const promptSettled = yield* Deferred.make<void>();
const adapter = makeAcpAdapterV2({
+ testHooks: {
+ afterPromptSettledWithBackgroundWork: () =>
+ Deferred.succeed(promptSettled, undefined).pipe(Effect.asVoid),
+ },
crypto: yield* Crypto.Crypto,
instanceId,
flavor: {
@@ -5072,7 +5064,6 @@ describe("AcpAdapterV2", () => {
childProcessSpawner,
mockAgentPath,
environment: { T3_ACP_EMIT_GENERIC_TOOL_PLACEHOLDERS: "1" },
- protocolEvents,
}),
},
fileSystem,
@@ -5107,28 +5098,13 @@ describe("AcpAdapterV2", () => {
yield* runtime.startTurn(
makeTurnInput({ threadId, providerThread, instanceId, runtimePolicy, now }),
);
- yield* Stream.fromQueue(protocolEvents).pipe(
- Stream.filter(
- (event) =>
- event.direction === "incoming" &&
- event.stage === "raw" &&
- typeof event.payload === "string" &&
- event.payload.includes('"stopReason"'),
- ),
- Stream.runHead,
- );
- yield* Effect.yieldNow;
- yield* Effect.yieldNow;
+ yield* Deferred.await(promptSettled);
const firstProviderTurnId = idAllocator.derive.providerTurn({
driver: ACP_TEST_DRIVER,
nativeTurnId: acpScopedNativeId(instanceId, "mock-session-1:turn:1"),
});
- const interruptFiber = yield* runtime
- .interruptTurn({ providerThread, providerTurnId: firstProviderTurnId })
- .pipe(Effect.forkScoped);
- yield* TestClock.adjust("10 seconds");
- yield* Fiber.join(interruptFiber);
+ yield* runtime.interruptTurn({ providerThread, providerTurnId: firstProviderTurnId });
let subagentTurnItemId: string | null = null;
let firstTerminalStatus: string | null = null;
@@ -5193,10 +5169,14 @@ describe("AcpAdapterV2", () => {
const mockAgentPath = yield* path.fromFileUrl(
new URL("../../../scripts/acp-mock-agent.ts", import.meta.url),
);
- const protocolEvents = yield* Queue.bounded<EffectAcpProtocol.AcpProtocolLogEvent>(256);
const instanceId = ProviderInstanceId.make("acp-test");
let subagentPhase: "spawn" | "complete" = "spawn";
+ const promptSettled = yield* Deferred.make<void>();
const adapter = makeAcpAdapterV2({
+ testHooks: {
+ afterPromptSettledWithBackgroundWork: () =>
+ Deferred.succeed(promptSettled, undefined).pipe(Effect.asVoid),
+ },
crypto: yield* Crypto.Crypto,
instanceId,
flavor: {
@@ -5230,7 +5210,6 @@ describe("AcpAdapterV2", () => {
childProcessSpawner,
mockAgentPath,
environment: { T3_ACP_EMIT_GENERIC_TOOL_PLACEHOLDERS: "1" },
- protocolEvents,
}),
},
fileSystem,
@@ -5272,28 +5251,13 @@ describe("AcpAdapterV2", () => {
yield* runtime.startTurn(
makeTurnInput({ threadId, providerThread, instanceId, runtimePolicy, now }),
);
- yield* Stream.fromQueue(protocolEvents).pipe(
- Stream.filter(
- (event) =>
- event.direction === "incoming" &&
- event.stage === "raw" &&
- typeof event.payload === "string" &&
- event.payload.includes('"stopReason"'),
- ),
- Stream.runHead,
- );
- yield* Effect.yieldNow;
- yield* Effect.yieldNow;
+ yield* Deferred.await(promptSettled);
const firstProviderTurnId = idAllocator.derive.providerTurn({
driver: ACP_TEST_DRIVER,
nativeTurnId: acpScopedNativeId(instanceId, "mock-session-1:turn:1"),
});
- const interruptFiber = yield* runtime
- .interruptTurn({ providerThread, providerTurnId: firstProviderTurnId })
- .pipe(Effect.forkScoped);
- yield* TestClock.adjust("10 seconds");
- yield* Fiber.join(interruptFiber);
+ yield* runtime.interruptTurn({ providerThread, providerTurnId: firstProviderTurnId });
let firstTerminalStatus: string | null = null;
while (firstTerminalStatus === null) {
@@ -5352,7 +5316,6 @@ describe("AcpAdapterV2", () => {
const mockAgentPath = yield* path.fromFileUrl(
new URL("../../../scripts/acp-mock-agent.ts", import.meta.url),
);
- const protocolEvents = yield* Queue.bounded<EffectAcpProtocol.AcpProtocolLogEvent>(256);
const secondPromptWireReturned = yield* Deferred.make<void>();
const releaseSecondPromptCompletion = yield* Deferred.make<void>();
const instanceId = ProviderInstanceId.make("acp-test");
@@ -5361,7 +5324,12 @@ describe("AcpAdapterV2", () => {
let subagentPhase: "spawn" | "complete" = "spawn";
type RuntimeService = AcpSessionRuntime.AcpSessionRuntime["Service"];
let sessionUpdateHandler: Parameters<RuntimeService["handleSessionUpdate"]>[0] | undefined;
+ const promptSettled = yield* Deferred.make<void>();
const adapter = makeAcpAdapterV2({
+ testHooks: {
+ afterPromptSettledWithBackgroundWork: () =>
+ Deferred.succeed(promptSettled, undefined).pipe(Effect.asVoid),
+ },
crypto: yield* Crypto.Crypto,
instanceId,
flavor: {
@@ -5395,7 +5363,6 @@ describe("AcpAdapterV2", () => {
childProcessSpawner,
mockAgentPath,
environment: { T3_ACP_EMIT_GENERIC_TOOL_PLACEHOLDERS: "1" },
- protocolEvents,
wrapRuntime: (runtime) => ({
...runtime,
handleSessionUpdate: (handler) =>
@@ -5456,28 +5423,13 @@ describe("AcpAdapterV2", () => {
yield* runtime.startTurn(
makeTurnInput({ threadId, providerThread, instanceId, runtimePolicy, now }),
);
- yield* Stream.fromQueue(protocolEvents).pipe(
- Stream.filter(
- (event) =>
- event.direction === "incoming" &&
- event.stage === "raw" &&
- typeof event.payload === "string" &&
- event.payload.includes('"stopReason"'),
- ),
- Stream.runHead,
- );
- yield* Effect.yieldNow;
- yield* Effect.yieldNow;
+ yield* Deferred.await(promptSettled);
const firstProviderTurnId = idAllocator.derive.providerTurn({
driver: ACP_TEST_DRIVER,
nativeTurnId: acpScopedNativeId(instanceId, "mock-session-1:turn:1"),
});
- const interruptFiber = yield* runtime
- .interruptTurn({ providerThread, providerTurnId: firstProviderTurnId })
- .pipe(Effect.forkScoped);
- yield* TestClock.adjust("10 seconds");
- yield* Fiber.join(interruptFiber);
+ yield* runtime.interruptTurn({ providerThread, providerTurnId: firstProviderTurnId });
let firstTerminalStatus: string | null = null;
while (firstTerminalStatus === null) {
@@ -5601,7 +5553,6 @@ describe("AcpAdapterV2", () => {
const mockAgentPath = yield* path.fromFileUrl(
new URL("../../../scripts/acp-mock-agent.ts", import.meta.url),
);
- const protocolEvents = yield* Queue.bounded<EffectAcpProtocol.AcpProtocolLogEvent>(256);
const baseClock = yield* Clock.Clock;
const finalizationClockRead = yield* Deferred.make<void>();
const releaseFinalizationClockRead = yield* Deferred.make<void>();
@@ -5629,7 +5580,12 @@ describe("AcpAdapterV2", () => {
let sessionUpdateHandler:
| Parameters<RuntimeService["handleSessionUpdate"]>[0]
| undefined;
+ const promptSettled = yield* Deferred.make<void>();
const adapter = makeAcpAdapterV2({
+ testHooks: {
+ afterPromptSettledWithBackgroundWork: () =>
+ Deferred.succeed(promptSettled, undefined).pipe(Effect.asVoid),
+ },
crypto: yield* Crypto.Crypto,
instanceId,
flavor: {
@@ -5668,7 +5624,6 @@ describe("AcpAdapterV2", () => {
childProcessSpawner,
mockAgentPath,
environment: { T3_ACP_EMIT_GENERIC_TOOL_PLACEHOLDERS: "1" },
- protocolEvents,
wrapRuntime: (runtime) => ({
...runtime,
handleSessionUpdate: (handler) =>
@@ -5719,18 +5674,7 @@ describe("AcpAdapterV2", () => {
yield* runtime.startTurn(
makeTurnInput({ threadId, providerThread, instanceId, runtimePolicy, now }),
);
- yield* Stream.fromQueue(protocolEvents).pipe(
- Stream.filter(
- (event) =>
- event.direction === "incoming" &&
- event.stage === "raw" &&
- typeof event.payload === "string" &&
- event.payload.includes('"stopReason"'),
- ),
- Stream.runHead,
- );
- yield* Effect.yieldNow;
- yield* Effect.yieldNow;
+ yield* Deferred.await(promptSettled);
yield* TestClock.adjust("1 second");
assert.isDefined(sessionUpdateHandler, "session update handler must be wired");
@@ -6451,14 +6395,18 @@ describe("AcpAdapterV2", () => {
const mockAgentPath = yield* path.fromFileUrl(
new URL("../../../scripts/acp-mock-agent.ts", import.meta.url),
);
- const protocolEvents = yield* Queue.bounded<EffectAcpProtocol.AcpProtocolLogEvent>(256);
const continuationRequests: Array<ProviderContinuationRequest> = [];
const bufferedAssistantText = "BUFFERED_WAKE_AFTER_USER_ATTACH";
const instanceId = ProviderInstanceId.make("acp-test");
let subagentPhase: "spawn" | "complete" = "spawn";
type RuntimeService = AcpSessionRuntime.AcpSessionRuntime["Service"];
let sessionUpdateHandler: Parameters<RuntimeService["handleSessionUpdate"]>[0] | undefined;
+ const promptSettled = yield* Deferred.make<void>();
const adapter = makeAcpAdapterV2({
+ testHooks: {
+ afterPromptSettledWithBackgroundWork: () =>
+ Deferred.succeed(promptSettled, undefined).pipe(Effect.asVoid),
+ },
crypto: yield* Crypto.Crypto,
instanceId,
flavor: {
@@ -6492,7 +6440,6 @@ describe("AcpAdapterV2", () => {
childProcessSpawner,
mockAgentPath,
environment: { T3_ACP_EMIT_GENERIC_TOOL_PLACEHOLDERS: "1" },
- protocolEvents,
wrapRuntime: (runtime) => ({
...runtime,
handleSessionUpdate: (handler) =>
@@ -6548,28 +6495,13 @@ describe("AcpAdapterV2", () => {
yield* runtime.startTurn(
makeTurnInput({ threadId, providerThread, instanceId, runtimePolicy, now }),
);
- yield* Stream.fromQueue(protocolEvents).pipe(
- Stream.filter(
- (event) =>
- event.direction === "incoming" &&
- event.stage === "raw" &&
- typeof event.payload === "string" &&
- event.payload.includes('"stopReason"'),
- ),
- Stream.runHead,
- );
- yield* Effect.yieldNow;
- yield* Effect.yieldNow;
+ yield* Deferred.await(promptSettled);
const firstProviderTurnId = idAllocator.derive.providerTurn({
driver: ACP_TEST_DRIVER,
nativeTurnId: acpScopedNativeId(instanceId, "mock-session-1:turn:1"),
});
- const interruptFiber = yield* runtime
- .interruptTurn({ providerThread, providerTurnId: firstProviderTurnId })
- .pipe(Effect.forkScoped);
- yield* TestClock.adjust("10 seconds");
- yield* Fiber.join(interruptFiber);
+ yield* runtime.interruptTurn({ providerThread, providerTurnId: firstProviderTurnId });
let firstTerminalStatus: string | null = null;
while (firstTerminalStatus === null) {
@@ -6752,14 +6684,18 @@ describe("AcpAdapterV2", () => {
new URL("../../../scripts/acp-mock-agent.ts", import.meta.url),
);
const continuationRequests: Array<ProviderContinuationRequest> = [];
- const protocolEvents = yield* Queue.bounded<EffectAcpProtocol.AcpProtocolLogEvent>(256);
const promptWireReturned = yield* Deferred.make<void>();
const releasePromptCompletion = yield* Deferred.make<void>();
const instanceId = ProviderInstanceId.make("acp-test");
let subagentPhase: "spawn" | "complete" = "spawn";
type RuntimeService = AcpSessionRuntime.AcpSessionRuntime["Service"];
let sessionUpdateHandler: Parameters<RuntimeService["handleSessionUpdate"]>[0] | undefined;
+ const promptSettled = yield* Deferred.make<void>();
const adapter = makeAcpAdapterV2({
+ testHooks: {
+ afterPromptSettledWithBackgroundWork: () =>
+ Deferred.succeed(promptSettled, undefined).pipe(Effect.asVoid),
+ },
crypto: yield* Crypto.Crypto,
instanceId,
flavor: {
@@ -6795,7 +6731,6 @@ describe("AcpAdapterV2", () => {
childProcessSpawner,
mockAgentPath,
environment: { T3_ACP_EMIT_GENERIC_TOOL_PLACEHOLDERS: "1" },
- protocolEvents,
wrapRuntime: (runtime) => ({
...runtime,
handleSessionUpdate: (handler) =>
@@ -6875,18 +6810,13 @@ describe("AcpAdapterV2", () => {
},
});
yield* Deferred.succeed(releasePromptCompletion, undefined);
- yield* Effect.yieldNow;
- yield* Effect.yieldNow;
+ yield* Deferred.await(promptSettled);
const firstProviderTurnId = idAllocator.derive.providerTurn({
driver: ACP_TEST_DRIVER,
nativeTurnId: acpScopedNativeId(instanceId, "mock-session-1:turn:1"),
});
- const interruptFiber = yield* runtime
- .interruptTurn({ providerThread, providerTurnId: firstProviderTurnId })
- .pipe(Effect.forkScoped);
- yield* TestClock.adjust("10 seconds");
- yield* Fiber.join(interruptFiber);
+ yield* runtime.interruptTurn({ providerThread, providerTurnId: firstProviderTurnId });
let firstTerminalStatus: string | null = null;
while (firstTerminalStatus === null) {
@@ -7223,7 +7153,6 @@ describe("AcpAdapterV2", () => {
const mockAgentPath = yield* path.fromFileUrl(
new URL("../../../scripts/acp-mock-agent.ts", import.meta.url),
);
- const protocolEvents = yield* Queue.bounded<EffectAcpProtocol.AcpProtocolLogEvent>(256);
const continuationRequests: Array<ProviderContinuationRequest> = [];
const instanceId = ProviderInstanceId.make("acp-test");
const childSessionId = "mock-child-session-pending-continuation";
@@ -7231,7 +7160,12 @@ describe("AcpAdapterV2", () => {
let subagentPhase: "spawn" | "complete" = "spawn";
type RuntimeService = AcpSessionRuntime.AcpSessionRuntime["Service"];
let sessionUpdateHandler: Parameters<RuntimeService["handleSessionUpdate"]>[0] | undefined;
+ const promptSettled = yield* Deferred.make<void>();
const adapter = makeAcpAdapterV2({
+ testHooks: {
+ afterPromptSettledWithBackgroundWork: () =>
+ Deferred.succeed(promptSettled, undefined).pipe(Effect.asVoid),
+ },
crypto: yield* Crypto.Crypto,
instanceId,
flavor: {
@@ -7265,7 +7199,6 @@ describe("AcpAdapterV2", () => {
childProcessSpawner,
mockAgentPath,
environment: { T3_ACP_EMIT_GENERIC_TOOL_PLACEHOLDERS: "1" },
- protocolEvents,
wrapRuntime: (runtime) => ({
...runtime,
handleSessionUpdate: (handler) =>
@@ -7321,28 +7254,13 @@ describe("AcpAdapterV2", () => {
yield* runtime.startTurn(
makeTurnInput({ threadId, providerThread, instanceId, runtimePolicy, now }),
);
- yield* Stream.fromQueue(protocolEvents).pipe(
- Stream.filter(
- (event) =>
- event.direction === "incoming" &&
- event.stage === "raw" &&
- typeof event.payload === "string" &&
- event.payload.includes('"stopReason"'),
- ),
- Stream.runHead,
- );
- yield* Effect.yieldNow;
- yield* Effect.yieldNow;
+ yield* Deferred.await(promptSettled);
const firstProviderTurnId = idAllocator.derive.providerTurn({
driver: ACP_TEST_DRIVER,
nativeTurnId: acpScopedNativeId(instanceId, "mock-session-1:turn:1"),
});
- const interruptFiber = yield* runtime
- .interruptTurn({ providerThread, providerTurnId: firstProviderTurnId })
- .pipe(Effect.forkScoped);
- yield* TestClock.adjust("10 seconds");
- yield* Fiber.join(interruptFiber);
+ yield* runtime.interruptTurn({ providerThread, providerTurnId: firstProviderTurnId });
let firstTerminalStatus: string | null = null;
while (firstTerminalStatus === null) {
@@ -7506,14 +7424,18 @@ describe("AcpAdapterV2", () => {
const mockAgentPath = yield* path.fromFileUrl(
new URL("../../../scripts/acp-mock-agent.ts", import.meta.url),
);
- const protocolEvents = yield* Queue.bounded<EffectAcpProtocol.AcpProtocolLogEvent>(256);
const continuationRequests: Array<ProviderContinuationRequest> = [];
const instanceId = ProviderInstanceId.make("acp-test");
const childSessionId = "mock-child-session-root-then-child";
let subagentPhase: "spawn" | "complete" = "spawn";
type RuntimeService = AcpSessionRuntime.AcpSessionRuntime["Service"];
let sessionUpdateHandler: Parameters<RuntimeService["handleSessionUpdate"]>[0] | undefined;
+ const promptSettled = yield* Deferred.make<void>();
const adapter = makeAcpAdapterV2({
+ testHooks: {
+ afterPromptSettledWithBackgroundWork: () =>
+ Deferred.succeed(promptSettled, undefined).pipe(Effect.asVoid),
+ },
crypto: yield* Crypto.Crypto,
instanceId,
flavor: {
@@ -7547,7 +7469,6 @@ describe("AcpAdapterV2", () => {
childProcessSpawner,
mockAgentPath,
environment: { T3_ACP_EMIT_GENERIC_TOOL_PLACEHOLDERS: "1" },
- protocolEvents,
wrapRuntime: (runtime) => ({
...runtime,
handleSessionUpdate: (handler) =>
@@ -7603,28 +7524,13 @@ describe("AcpAdapterV2", () => {
yield* runtime.startTurn(
makeTurnInput({ threadId, providerThread, instanceId, runtimePolicy, now }),
);
- yield* Stream.fromQueue(protocolEvents).pipe(
- Stream.filter(
- (event) =>
- event.direction === "incoming" &&
- event.stage === "raw" &&
- typeof event.payload === "string" &&
- event.payload.includes('"stopReason"'),
- ),
- Stream.runHead,
- );
- yield* Effect.yieldNow;
- yield* Effect.yieldNow;
+ yield* Deferred.await(promptSettled);
const firstProviderTurnId = idAllocator.derive.providerTurn({
driver: ACP_TEST_DRIVER,
nativeTurnId: acpScopedNativeId(instanceId, "mock-session-1:turn:1"),
});
- const interruptFiber = yield* runtime
- .interruptTurn({ providerThread, providerTurnId: firstProviderTurnId })
- .pipe(Effect.forkScoped);
- yield* TestClock.adjust("10 seconds");
- yield* Fiber.join(interruptFiber);
+ yield* runtime.interruptTurn({ providerThread, providerTurnId: firstProviderTurnId });
let firstTerminalStatus: string | null = null;
while (firstTerminalStatus === null) {
@@ -7760,12 +7666,16 @@ describe("AcpAdapterV2", () => {
const mockAgentPath = yield* path.fromFileUrl(
new URL("../../../scripts/acp-mock-agent.ts", import.meta.url),
);
- const protocolEvents = yield* Queue.bounded<EffectAcpProtocol.AcpProtocolLogEvent>(256);
const instanceId = ProviderInstanceId.make("acp-test");
let subagentPhase: "spawn" | "complete" = "spawn";
let cancelCalled = false;
let runtimeOrdinalSeen = 0;
+ const promptSettled = yield* Deferred.make<void>();
const adapter = makeAcpAdapterV2({
+ testHooks: {
+ afterPromptSettledWithBackgroundWork: () =>
+ Deferred.succeed(promptSettled, undefined).pipe(Effect.asVoid),
+ },
crypto: yield* Crypto.Crypto,
instanceId,
flavor: {
@@ -7812,7 +7722,6 @@ describe("AcpAdapterV2", () => {
runtimeOrdinalSeen = Math.max(runtimeOrdinalSeen, runtimeOrdinal);
return { T3_ACP_EMIT_GENERIC_TOOL_PLACEHOLDERS: "1" };
},
- protocolEvents,
wrapCancel: (cancel) =>
Effect.sync(() => {
cancelCalled = true;
@@ -7853,28 +7762,13 @@ describe("AcpAdapterV2", () => {
);
// The still-running subagent defers finalize after session/prompt returns,
// so the interrupt below hits a settled turn held open for background work.
- yield* Stream.fromQueue(protocolEvents).pipe(
- Stream.filter(
- (event) =>
- event.direction === "incoming" &&
- event.stage === "raw" &&
- typeof event.payload === "string" &&
- event.payload.includes('"stopReason"'),
- ),
- Stream.runHead,
- );
- yield* Effect.yieldNow;
- yield* Effect.yieldNow;
+ yield* Deferred.await(promptSettled);
const firstProviderTurnId = idAllocator.derive.providerTurn({
driver: ACP_TEST_DRIVER,
nativeTurnId: acpScopedNativeId(instanceId, "mock-session-1:turn:1"),
});
- const interruptFiber = yield* runtime
- .interruptTurn({ providerThread, providerTurnId: firstProviderTurnId })
- .pipe(Effect.forkScoped);
- yield* TestClock.adjust("10 seconds");
- yield* Fiber.join(interruptFiber);
+ yield* runtime.interruptTurn({ providerThread, providerTurnId: firstProviderTurnId });
assert.isFalse(
cancelCalled,
"settled soft steer must not send session/cancel (the real Grok CLI kills background subagents on cancel)",
@@ -13725,10 +13619,14 @@ describe("AcpAdapterV2", () => {
const mockAgentPath = yield* path.fromFileUrl(
new URL("../../../scripts/acp-mock-agent.ts", import.meta.url),
);
- const protocolEvents = yield* Queue.bounded<EffectAcpProtocol.AcpProtocolLogEvent>(256);
const instanceId = ProviderInstanceId.make("acp-test");
let subagentPhase: "spawn" | "complete" = "spawn";
+ const promptSettled = yield* Deferred.make<void>();
const adapter = makeAcpAdapterV2({
+ testHooks: {
+ afterPromptSettledWithBackgroundWork: () =>
+ Deferred.succeed(promptSettled, undefined).pipe(Effect.asVoid),
+ },
crypto: yield* Crypto.Crypto,
instanceId,
flavor: {
@@ -13762,7 +13660,6 @@ describe("AcpAdapterV2", () => {
childProcessSpawner,
mockAgentPath,
environment: { T3_ACP_EMIT_GENERIC_TOOL_PLACEHOLDERS: "1" },
- protocolEvents,
}),
},
fileSystem,
@@ -13799,32 +13696,17 @@ describe("AcpAdapterV2", () => {
yield* runtime.startTurn(
makeTurnInput({ threadId, providerThread, instanceId, runtimePolicy, now }),
);
- yield* Stream.fromQueue(protocolEvents).pipe(
- Stream.filter(
- (event) =>
- event.direction === "incoming" &&
- event.stage === "raw" &&
- typeof event.payload === "string" &&
- event.payload.includes('"stopReason"'),
- ),
- Stream.runHead,
- );
- yield* Effect.yieldNow;
- yield* Effect.yieldNow;
+ yield* Deferred.await(promptSettled);
const firstProviderTurnId = idAllocator.derive.providerTurn({
driver: ACP_TEST_DRIVER,
nativeTurnId: acpScopedNativeId(instanceId, "mock-session-1:turn:1"),
});
- const interruptFiber = yield* runtime
- .interruptTurn({
- providerThread,
- providerTurnId: firstProviderTurnId,
- requestRuntimeRestart: true,
- })
- .pipe(Effect.forkScoped);
- yield* TestClock.adjust("10 seconds");
- yield* Fiber.join(interruptFiber);
+ yield* runtime.interruptTurn({
+ providerThread,
+ providerTurnId: firstProviderTurnId,
+ requestRuntimeRestart: true,
+ });
let subagentStatus: string | null = null;
let firstTerminalStatus: string | null = null;