Skip to content

Commit 47cc9a5

Browse files
committed
test(kiro): cover the real upstream shape that omits tokenUsage
CodeWhisperer does not report per-turn cache detail. Proven statically without credentials: parseTokenUsage reads totalTokens as required, so a parsed authoritative frame always yields usage.totalTokens, and no recent Kiro usage row carries it (or any cache field) in a 5691-row live sample. The 4736 rows that DO carry a large usage.totalTokens all fall in a 06-30..07-01 window, from when 7374c3a wrote contextUsagePercentage x contextWindow straight into totalTokens. That figure later moved to the dedicated contextTotalTokens field, which persistence dropped — which is why the large numbers disappeared from Logs. This test pins the live shape: contextUsagePercentage present, tokenUsage absent. The turn stays estimated, invents no cache split, and still reports a contextTotalTokens checkpoint larger than the per-turn total. The cache read/write parser stays in place, so if upstream ever starts reporting the split it surfaces with no further code change.
1 parent d24c523 commit 47cc9a5

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

tests/kiro-stream.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,6 +1242,27 @@ describe("kiro adapter — parseStream", () => {
12421242
expect(done.estimated).toBe(true);
12431243
});
12441244

1245+
test("a real-shaped Kiro turn without tokenUsage still reports a cumulative context checkpoint", async () => {
1246+
// This is the shape live CodeWhisperer actually sends: contextUsagePercentage but NO
1247+
// tokenUsage (proven statically — parseTokenUsage reads totalTokens as required, and no
1248+
// recent kiro usage row carries usage.totalTokens or any cache field). The per-turn
1249+
// numbers therefore stay small estimates, and contextTotalTokens is the ONLY signal of
1250+
// real context occupancy. It must be present so Logs can show cumulative growth.
1251+
const adapter = createKiroAdapter(provider);
1252+
await adapter.buildRequest(parsedWith([{ role: "user", content: "x".repeat(4_000) }]));
1253+
const done = await doneUsage(
1254+
adapter,
1255+
eventFrame({ content: "answer" }),
1256+
eventFrame({ contextUsagePercentage: 42 }, "metadataEvent"),
1257+
);
1258+
expect(done.estimated).toBe(true);
1259+
// No fabricated cache detail when upstream reports none.
1260+
expect("cacheReadInputTokens" in done).toBe(false);
1261+
expect("cacheCreationInputTokens" in done).toBe(false);
1262+
// The checkpoint exceeds the small per-turn total, which is the whole point.
1263+
expect(done.contextTotalTokens).toBeGreaterThan(done.inputTokens + done.outputTokens);
1264+
});
1265+
12451266
test("authoritative metadata token usage overrides estimates and preserves cache splits", async () => {
12461267
const adapter = createKiroAdapter(provider);
12471268
await adapter.buildRequest(parsedWith([{ role: "user", content: "x".repeat(700) }]));

0 commit comments

Comments
 (0)