@@ -121,7 +121,7 @@ const ACP_TEST_DRIVER = ProviderDriverKind.make("acp-test");
121121const decodeUnknownJson = Schema.decodeUnknownOption(Schema.fromJsonString(Schema.Unknown));
122122
123123describe("acpPerTurnPromptUsage", () => {
124- it("maps a per-turn sample straight through without any baseline ", () => {
124+ it("maps a per-turn sample straight onto TurnTokenUsage ", () => {
125125 assert.deepEqual(
126126 acpPerTurnPromptUsage(
127127 {
@@ -190,7 +190,7 @@ describe("acpPerTurnPromptUsage", () => {
190190 });
191191
192192 it("caps cache writes at the input left over after cache reads", () => {
193- // PR review case: each counter fits under input alone, but together they exceed it.
193+ // Each counter fits under input alone, but together they exceed it.
194194 assert.deepEqual(
195195 acpPerTurnPromptUsage(
196196 {
@@ -1073,8 +1073,7 @@ describe("AcpAdapterV2", () => {
10731073 (event) =>
10741074 event.type === "provider_turn.updated" && event.providerTurn.status === "completed",
10751075 );
1076- // Per-turn semantics map each response's own sample onto its turn:
1077- // turn 2 reports 2453 input tokens, not the 21-token delta.
1076+ // Per-turn: each response's own sample maps straight onto its turn.
10781077 assert.deepEqual(
10791078 completed?.type === "provider_turn.updated"
10801079 ? completed.providerTurn.turnTokenUsage
@@ -1251,77 +1250,75 @@ describe("AcpAdapterV2", () => {
12511250 }).pipe(Effect.provide(layerTest), Effect.scoped),
12521251 );
12531252
1254- it.live(
1255- "keeps usage unavailable for undeclared semantics even when the agent reports usage",
1256- () =>
1257- Effect.gen(function* () {
1258- const path = yield* Path.Path;
1259- const instanceId = ProviderInstanceId.make("acp-test-usage-undeclared");
1260- const threadId = ThreadId.make("thread-acp-usage-undeclared");
1261- const adapter = yield* makeAcpAdapterV2({
1262- instanceId,
1263- selfInvocation: yield* resolveSelfInvocation(),
1264- flavor: {
1265- driver: ACP_TEST_DRIVER,
1266- capabilities: AcpProviderCapabilitiesV2,
1267- makeRuntime: makeMockRuntime({
1268- childProcessSpawner: yield* ChildProcessSpawner.ChildProcessSpawner,
1269- mockAgentPath: yield* path.fromFileUrl(
1270- new URL("../../../scripts/acp-mock-agent.ts", import.meta.url),
1271- ),
1272- wrapRuntime: (runtime) => ({
1273- ...runtime,
1274- prompt: () =>
1275- Effect.succeed({
1276- stopReason: "end_turn" as const,
1277- usage: { inputTokens: 60, outputTokens: 15, totalTokens: 75 },
1278- }),
1279- }),
1280- }),
1281- },
1282- });
1283- const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({
1284- runtimeMode: "full-access",
1285- interactionMode: "default",
1286- cwd: process.cwd(),
1287- });
1288- const modelSelection = { instanceId, model: "default" } as const;
1289- const runtime = yield* adapter.openSession({
1290- threadId,
1291- providerSessionId: ProviderSessionId.make("provider-session-acp-usage-undeclared"),
1292- modelSelection,
1293- runtimePolicy,
1294- });
1295- const providerThread = yield* runtime.ensureThread({
1296- threadId,
1297- modelSelection,
1298- runtimePolicy,
1299- });
1300- const now = yield* DateTime.now;
1301- for (const ordinal of [1, 2]) {
1302- yield* runtime.startTurn(
1303- makeTurnInput({ threadId, providerThread, instanceId, runtimePolicy, now, ordinal }),
1304- );
1305- const events = Array.from(
1306- yield* runtime.events.pipe(
1307- Stream.takeUntil((event) => event.type === "turn.terminal"),
1308- Stream.runCollect,
1253+ it.live("keeps usage unavailable for undeclared agents even when they report usage", () =>
1254+ Effect.gen(function* () {
1255+ const path = yield* Path.Path;
1256+ const instanceId = ProviderInstanceId.make("acp-test-usage-undeclared");
1257+ const threadId = ThreadId.make("thread-acp-usage-undeclared");
1258+ const adapter = yield* makeAcpAdapterV2({
1259+ instanceId,
1260+ selfInvocation: yield* resolveSelfInvocation(),
1261+ flavor: {
1262+ driver: ACP_TEST_DRIVER,
1263+ capabilities: AcpProviderCapabilitiesV2,
1264+ makeRuntime: makeMockRuntime({
1265+ childProcessSpawner: yield* ChildProcessSpawner.ChildProcessSpawner,
1266+ mockAgentPath: yield* path.fromFileUrl(
1267+ new URL("../../../scripts/acp-mock-agent.ts", import.meta.url),
13091268 ),
1310- );
1311- const completed = events.find(
1312- (event) =>
1313- event.type === "provider_turn.updated" && event.providerTurn.status === "completed",
1314- );
1315- // Usage semantics are unverified for an undeclared agent, so its
1316- // counters are never trusted, on any turn.
1317- assert.deepEqual(
1318- completed?.type === "provider_turn.updated"
1319- ? completed.providerTurn.turnTokenUsage
1320- : null,
1321- { usageScope: "main_agent", usageStatus: "unavailable", hasSubagents: false },
1322- );
1323- }
1324- }).pipe(Effect.provide(layerTest), Effect.scoped),
1269+ wrapRuntime: (runtime) => ({
1270+ ...runtime,
1271+ prompt: () =>
1272+ Effect.succeed({
1273+ stopReason: "end_turn" as const,
1274+ usage: { inputTokens: 60, outputTokens: 15, totalTokens: 75 },
1275+ }),
1276+ }),
1277+ }),
1278+ },
1279+ });
1280+ const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({
1281+ runtimeMode: "full-access",
1282+ interactionMode: "default",
1283+ cwd: process.cwd(),
1284+ });
1285+ const modelSelection = { instanceId, model: "default" } as const;
1286+ const runtime = yield* adapter.openSession({
1287+ threadId,
1288+ providerSessionId: ProviderSessionId.make("provider-session-acp-usage-undeclared"),
1289+ modelSelection,
1290+ runtimePolicy,
1291+ });
1292+ const providerThread = yield* runtime.ensureThread({
1293+ threadId,
1294+ modelSelection,
1295+ runtimePolicy,
1296+ });
1297+ const now = yield* DateTime.now;
1298+ for (const ordinal of [1, 2]) {
1299+ yield* runtime.startTurn(
1300+ makeTurnInput({ threadId, providerThread, instanceId, runtimePolicy, now, ordinal }),
1301+ );
1302+ const events = Array.from(
1303+ yield* runtime.events.pipe(
1304+ Stream.takeUntil((event) => event.type === "turn.terminal"),
1305+ Stream.runCollect,
1306+ ),
1307+ );
1308+ const completed = events.find(
1309+ (event) =>
1310+ event.type === "provider_turn.updated" && event.providerTurn.status === "completed",
1311+ );
1312+ // Usage semantics are unverified for an undeclared agent, so its
1313+ // counters are never trusted, on any turn.
1314+ assert.deepEqual(
1315+ completed?.type === "provider_turn.updated"
1316+ ? completed.providerTurn.turnTokenUsage
1317+ : null,
1318+ { usageScope: "main_agent", usageStatus: "unavailable", hasSubagents: false },
1319+ );
1320+ }
1321+ }).pipe(Effect.provide(layerTest), Effect.scoped),
13251322 );
13261323
13271324 // Factory Droid 0.243.0 sends an optional text companion for every AskUser choice.
0 commit comments