Skip to content

Commit 5689e51

Browse files
test(server): cover the mode reapply with one v1 replay transcript
The replay transcript already rejects any unexpected outbound frame, so a third turn proves an unchanged mode is not re-sent. That makes the mock agent self-switch test and its environment flag redundant. AI-assisted; verified with the tests and tools listed above.
1 parent acac83a commit 5689e51

2 files changed

Lines changed: 3 additions & 102 deletions

File tree

‎apps/server/scripts/acp-mock-agent.ts‎

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ const compactionPromptOrdinals = new Set(
7777
(process.env.T3_ACP_COMPACTION_PROMPT_ORDINALS ?? "").split(",").map(Number),
7878
);
7979
const failSetModeConfigOption = process.env.T3_ACP_FAIL_SET_MODE_CONFIG_OPTION === "1";
80-
const selfSwitchModeOnFirstPrompt = process.env.T3_ACP_SELF_SWITCH_MODE_ON_FIRST_PROMPT;
8180
const emitEmptyDefaultAgentOption = process.env.T3_ACP_EMIT_EMPTY_DEFAULT_AGENT_OPTION === "1";
8281
const promptResponseText = process.env.T3_ACP_PROMPT_RESPONSE_TEXT;
8382
const promptDelayMs = Number(process.env.T3_ACP_PROMPT_DELAY_MS ?? "0");
@@ -1348,18 +1347,6 @@ const program = Effect.gen(function* () {
13481347
}
13491348
}
13501349

1351-
if (selfSwitchModeOnFirstPrompt !== undefined && promptCount === 1) {
1352-
currentModeId = selfSwitchModeOnFirstPrompt;
1353-
yield* agent.client.sessionUpdate({
1354-
sessionId: requestedSessionId,
1355-
update: { sessionUpdate: "current_mode_update", currentModeId },
1356-
});
1357-
yield* agent.client.sessionUpdate({
1358-
sessionId: requestedSessionId,
1359-
update: { sessionUpdate: "config_option_update", configOptions: configOptions() },
1360-
});
1361-
}
1362-
13631350
if (failPrompt || promptCount === failPromptOrdinal) {
13641351
return yield* AcpError.AcpRequestError.internalError("Mock prompt failure");
13651352
}

‎apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts‎

Lines changed: 3 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -2415,94 +2415,6 @@ describe("AcpAdapterV2", () => {
24152415
}).pipe(Effect.provide(layerTest), Effect.scoped),
24162416
);
24172417

2418-
// regression: #27646 an agent leaving its native mode on its own must not keep the next turn there
2419-
it.live("reapplies the selected native mode after the agent switches mode itself", () =>
2420-
Effect.gen(function* () {
2421-
const childProcessSpawner = yield* ChildProcessSpawner.ChildProcessSpawner;
2422-
const path = yield* Path.Path;
2423-
const mockAgentPath = yield* path.fromFileUrl(
2424-
new URL("../../../scripts/acp-mock-agent.ts", import.meta.url),
2425-
);
2426-
const protocolEvents = yield* Queue.unbounded<EffectAcpProtocol.AcpProtocolLogEvent>();
2427-
const instanceId = ProviderInstanceId.make("acp-test-agent-mode-drift");
2428-
const threadId = ThreadId.make("thread-acp-agent-mode-drift");
2429-
const adapter = yield* makeAcpAdapterV2({
2430-
instanceId,
2431-
flavor: {
2432-
driver: ACP_TEST_DRIVER,
2433-
capabilities: AcpProviderCapabilitiesV2,
2434-
makeRuntime: makeMockRuntime({
2435-
childProcessSpawner,
2436-
mockAgentPath,
2437-
protocolEvents,
2438-
environment: { T3_ACP_SELF_SWITCH_MODE_ON_FIRST_PROMPT: "ask" },
2439-
}),
2440-
},
2441-
selfInvocation: yield* resolveSelfInvocation(),
2442-
});
2443-
const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({
2444-
runtimeMode: "full-access",
2445-
interactionMode: "default",
2446-
cwd: process.cwd(),
2447-
});
2448-
const modelSelection = {
2449-
instanceId,
2450-
model: "default",
2451-
options: [{ id: "mode", value: "architect" }],
2452-
} as const;
2453-
const runtime = yield* adapter.openSession({
2454-
threadId,
2455-
providerSessionId: ProviderSessionId.make("provider-session-acp-agent-mode-drift"),
2456-
modelSelection,
2457-
runtimePolicy,
2458-
});
2459-
const providerThread = yield* runtime.ensureThread({
2460-
threadId,
2461-
modelSelection,
2462-
runtimePolicy,
2463-
});
2464-
const now = yield* DateTime.now;
2465-
const runTurn = Effect.fnUntraced(function* (ordinal: number) {
2466-
yield* runtime.startTurn(
2467-
makeTurnInput({
2468-
threadId,
2469-
providerThread,
2470-
instanceId,
2471-
runtimePolicy,
2472-
now,
2473-
ordinal,
2474-
modelSelection,
2475-
}),
2476-
);
2477-
yield* runtime.events.pipe(
2478-
Stream.takeUntil((event) => event.type === "turn.terminal"),
2479-
Stream.runDrain,
2480-
);
2481-
const modeSetsBeforePrompt: Array<unknown> = [];
2482-
while (true) {
2483-
const event = yield* Queue.take(protocolEvents);
2484-
if (event.direction !== "outgoing") continue;
2485-
const method = rawProtocolMethod(event);
2486-
if (method === "session/prompt") return modeSetsBeforePrompt;
2487-
if (
2488-
method === "session/set_config_option" &&
2489-
rawProtocolRequestParam(event, "configId") === "mode"
2490-
) {
2491-
modeSetsBeforePrompt.push(rawProtocolRequestParam(event, "value"));
2492-
}
2493-
}
2494-
});
2495-
2496-
assert.deepEqual(yield* runTurn(1), ["architect"]);
2497-
assert.deepEqual(
2498-
yield* runTurn(2),
2499-
["architect"],
2500-
"the agent left architect mode during turn 1, so turn 2 must set it back before prompting",
2501-
);
2502-
assert.deepEqual(yield* runTurn(3), [], "an unchanged mode is not re-sent");
2503-
}).pipe(Effect.provide(layerTest), Effect.scoped),
2504-
);
2505-
25062418
// regression: #27646 an ACP v1 agent can report a mode switch without a config option update
25072419
it.live("reapplies the selected native mode after a mode-only update from a v1 agent", () =>
25082420
Effect.gen(function* () {
@@ -2589,6 +2501,7 @@ describe("AcpAdapterV2", () => {
25892501
...prompt([{ sessionUpdate: "current_mode_update", currentModeId: "ask" }]),
25902502
...setArchitect,
25912503
...prompt([]),
2504+
...prompt([]),
25922505
],
25932506
},
25942507
ACP_TEST_DRIVER,
@@ -2634,7 +2547,8 @@ describe("AcpAdapterV2", () => {
26342547
runtimePolicy,
26352548
});
26362549
const now = yield* DateTime.now;
2637-
for (const ordinal of [1, 2]) {
2550+
// Turn 2 must set architect back before prompting; turn 3 must not re-send it.
2551+
for (const ordinal of [1, 2, 3]) {
26382552
yield* runtime.startTurn(
26392553
makeTurnInput({
26402554
threadId,

0 commit comments

Comments
 (0)