Browse Source

test(token-meter): preserve shadow-price mismatch rejection coverage

The breakdown refactor correctly stopped consuming scalar shadow claims, but its old negative test was the only coverage of the pressure fold rejection path. Exercise the remaining real pressure consumer with mismatched start and end claims, preserving the runtime invariant rather than deleting or ignoring its guard.

Validation: Linux and Windows CI reported the two uncovered locations in surface-projection.ts. All118 token-meter tests pass and the exact pressure fold file now has100% statement, branch, function and line coverage.
Tianyi Cui 1 month ago
parent
commit
af87e576da
1 changed files with 16 additions and 0 deletions
  1. 16 0
      packages/llm/token-meter/tests/token-usage-projection.spec.ts

+ 16 - 0
packages/llm/token-meter/tests/token-usage-projection.spec.ts

@@ -486,6 +486,22 @@ describe('contextPressure session projection', () => {
     expect(compacted.projectedTokens).toBeLessThan(beforeCompaction!)
     expect(compacted.projectedTokens).toBeLessThan(beforeCompaction!)
   })
   })
 
 
+  it.each(['start', 'end'] as const)('rejects a shadow claim with a mismatched %s endpoint', async (endpoint) => {
+    const { ctx, session } = await harness()
+    try {
+      const first = appendUser(session, 'first')
+      const last = appendUser(session, 'last')
+      appendSummaryMeter(ctx, session, first, last)
+      const target = endpoint === 'start' ? last : first
+      session.append('user/message', createUserMessage({
+        content: [{ type: 'text', text: 'summary' }], source: { kind: 'plugin', plugin: 'test' },
+      }), { surfaceOp: { op: 'replace', start: target, end: target }, sourceEventSeqs: [target] })
+      expect(() => pressure(ctx, session)).toThrow('has no adjacent shadow price')
+    } finally {
+      await ctx.fiber.dispose()
+    }
+  })
+
   it('folds a replacement without a claim at zero', async () => {
   it('folds a replacement without a claim at zero', async () => {
     const { ctx, session } = await harness()
     const { ctx, session } = await harness()
     const question = appendUser(session, 'a question from an unmetered log')
     const question = appendUser(session, 'a question from an unmetered log')