Skip to content

Commit a730237

Browse files
test(server): cover the resumed policy deciding a permission request during resume
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 539a056 commit a730237

1 file changed

Lines changed: 95 additions & 15 deletions

File tree

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

Lines changed: 95 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,26 @@ function rawProtocolRequest(
287287
return undefined;
288288
}
289289

290+
function rawProtocolOutgoingOutcomes(
291+
events: ReadonlyArray<EffectAcpProtocol.AcpProtocolLogEvent>,
292+
): Array<unknown> {
293+
const outcomes: Array<unknown> = [];
294+
for (const event of events) {
295+
if (event.stage !== "raw" || event.direction !== "outgoing") continue;
296+
if (typeof event.payload !== "string") continue;
297+
for (const line of event.payload.split("\n")) {
298+
const decoded = Option.getOrUndefined(decodeUnknownJson(line.trim()));
299+
if (typeof decoded !== "object" || decoded === null || "method" in decoded) continue;
300+
if ("error" in decoded) outcomes.push({ error: Reflect.get(decoded, "error") });
301+
const result = Reflect.get(decoded, "result");
302+
if (typeof result === "object" && result !== null && "outcome" in result) {
303+
outcomes.push(Reflect.get(result, "outcome"));
304+
}
305+
}
306+
}
307+
return outcomes;
308+
}
309+
290310
function rawProtocolRequestParam(
291311
event: EffectAcpProtocol.AcpProtocolLogEvent,
292312
key: string,
@@ -1231,29 +1251,89 @@ describe("AcpAdapterV2", () => {
12311251
}),
12321252
),
12331253
);
1234-
const permissionReplies: Array<unknown> = [];
1235-
for (const event of yield* Queue.takeAll(protocolEvents)) {
1236-
if (event.direction !== "outgoing" || typeof event.payload !== "string") continue;
1237-
for (const line of event.payload.split("\n")) {
1238-
const decoded = Option.getOrUndefined(decodeUnknownJson(line.trim()));
1239-
if (typeof decoded !== "object" || decoded === null || "method" in decoded) continue;
1240-
if ("error" in decoded)
1241-
permissionReplies.push({ error: Reflect.get(decoded, "error") });
1242-
const result = Reflect.get(decoded, "result");
1243-
if (typeof result === "object" && result !== null && "outcome" in result) {
1244-
permissionReplies.push(Reflect.get(result, "outcome"));
1245-
}
1246-
}
1247-
}
12481254
assert.deepEqual(
1249-
permissionReplies,
1255+
rawProtocolOutgoingOutcomes(Array.from(yield* Queue.takeAll(protocolEvents))),
12501256
[{ outcome: "selected", optionId }],
12511257
"a permission request before the turn is active must be answered from the runtime policy",
12521258
);
12531259
assert.isTrue(Exit.isSuccess(started), "the turn on the switched model must start");
12541260
}).pipe(Effect.provide(layerTest), Effect.scoped),
12551261
);
12561262

1263+
// regression: #26852 a resumed session decides permission requests with the resumed policy
1264+
it.live(
1265+
"answers a permission request during a resumed model switch from the resumed policy",
1266+
() =>
1267+
Effect.gen(function* () {
1268+
const childProcessSpawner = yield* ChildProcessSpawner.ChildProcessSpawner;
1269+
const path = yield* Path.Path;
1270+
const mockAgentPath = yield* path.fromFileUrl(
1271+
new URL("../../../scripts/acp-mock-agent.ts", import.meta.url),
1272+
);
1273+
const protocolEvents = yield* Queue.unbounded<EffectAcpProtocol.AcpProtocolLogEvent>();
1274+
const instanceId = ProviderInstanceId.make("acp-test-permission-during-resume");
1275+
const threadId = ThreadId.make("thread-acp-permission-during-resume");
1276+
const adapter = yield* makeAcpAdapterV2({
1277+
instanceId,
1278+
flavor: {
1279+
driver: ACP_TEST_DRIVER,
1280+
capabilities: AcpProviderCapabilitiesV2,
1281+
makeRuntime: makeMockRuntime({
1282+
childProcessSpawner,
1283+
mockAgentPath,
1284+
protocolEvents,
1285+
environment: { T3_ACP_REQUEST_PERMISSION_ON_SET_MODEL: "composer-2" },
1286+
}),
1287+
},
1288+
selfInvocation: yield* resolveSelfInvocation(),
1289+
});
1290+
const openedPolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({
1291+
runtimeMode: "full-access",
1292+
interactionMode: "default",
1293+
cwd: process.cwd(),
1294+
});
1295+
const resumedPolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({
1296+
runtimeMode: "approval-required",
1297+
interactionMode: "default",
1298+
cwd: process.cwd(),
1299+
});
1300+
const openedSelection = { instanceId, model: "default" } as const;
1301+
const runtime = yield* adapter.openSession({
1302+
threadId,
1303+
providerSessionId: ProviderSessionId.make("provider-session-acp-permission-resume"),
1304+
modelSelection: openedSelection,
1305+
runtimePolicy: openedPolicy,
1306+
});
1307+
const providerThread = yield* runtime.ensureThread({
1308+
threadId,
1309+
modelSelection: openedSelection,
1310+
runtimePolicy: openedPolicy,
1311+
});
1312+
yield* Queue.clear(protocolEvents);
1313+
1314+
const resumed = yield* Effect.exit(
1315+
runtime.resumeThread({
1316+
providerThread: {
1317+
...providerThread,
1318+
nativeThreadRef: {
1319+
driver: ACP_TEST_DRIVER,
1320+
nativeId: "persisted-session",
1321+
strength: "strong",
1322+
},
1323+
},
1324+
modelSelection: { instanceId, model: "composer-2" },
1325+
runtimePolicy: resumedPolicy,
1326+
}),
1327+
);
1328+
assert.deepEqual(
1329+
rawProtocolOutgoingOutcomes(Array.from(yield* Queue.takeAll(protocolEvents))),
1330+
[{ outcome: "selected", optionId: "reject-once" }],
1331+
"a permission request while resuming must be decided by the resumed policy",
1332+
);
1333+
assert.isTrue(Exit.isSuccess(resumed), "resuming on the switched model must succeed");
1334+
}).pipe(Effect.provide(layerTest), Effect.scoped),
1335+
);
1336+
12571337
// regression: #21499 turns blocked only on T3 thread waits must show as waiting
12581338
it.effect.each(["agent_message_chunk"] as const)(
12591339
"keeps named ACP %s open while deriving thread wait execution state",

0 commit comments

Comments
 (0)