@@ -31,6 +31,57 @@ describe("request log token-estimate context-window cap (codex-router PR #140)",
3131 expect ( attempt . usage ?. inputTokens ) . toBe ( 100_000 ) ;
3232 } ) ;
3333
34+ test ( "capping adapter-estimated input recomputes an explicit total" , ( ) => {
35+ const attempt = beginRequestAttempt ( 1 , "kiro" , "deepseek-3.2" , "kiro" ) ;
36+ finishRequestAttempt ( attempt , 200 , 10 , {
37+ inputTokens : 200_000 ,
38+ outputTokens : 4 ,
39+ totalTokens : 200_004 ,
40+ estimated : true ,
41+ } ) ;
42+ expect ( attempt . usage ) . toEqual ( {
43+ inputTokens : DEEPSEEK_WINDOW ,
44+ outputTokens : 4 ,
45+ totalTokens : DEEPSEEK_WINDOW + 4 ,
46+ estimated : true ,
47+ } ) ;
48+ expect ( attempt . totalTokens ) . toBe ( DEEPSEEK_WINDOW + 4 ) ;
49+ } ) ;
50+
51+ test ( "combining a local estimate recomputes the nested and outer totals" , ( ) => {
52+ const attempt = beginRequestAttempt ( 1 , "kiro" , "deepseek-3.2" , "kiro" ) ;
53+ noteAttemptSend ( attempt , 200_000 ) ;
54+ finishRequestAttempt ( attempt , 200 , 10 , {
55+ inputTokens : 50 ,
56+ outputTokens : 4 ,
57+ totalTokens : 54 ,
58+ } ) ;
59+ expect ( attempt . usage ) . toEqual ( {
60+ inputTokens : DEEPSEEK_WINDOW ,
61+ outputTokens : 4 ,
62+ totalTokens : DEEPSEEK_WINDOW + 4 ,
63+ estimated : true ,
64+ } ) ;
65+ expect ( attempt . totalTokens ) . toBe ( DEEPSEEK_WINDOW + 4 ) ;
66+ } ) ;
67+
68+ test ( "caps an estimated Cursor checkpoint without double-adding output" , ( ) => {
69+ const attempt = beginRequestAttempt ( 1 , "cursor" , "claude-4.6-opus-high" , "cursor" ) ;
70+ finishRequestAttempt ( attempt , 200 , 10 , {
71+ inputTokens : 499_994 ,
72+ outputTokens : 6 ,
73+ totalTokens : 500_000 ,
74+ estimated : true ,
75+ } ) ;
76+ expect ( attempt . usage ) . toEqual ( {
77+ inputTokens : CURSOR_CLAUDE_WINDOW ,
78+ outputTokens : 6 ,
79+ totalTokens : CURSOR_CLAUDE_WINDOW + 6 ,
80+ estimated : true ,
81+ } ) ;
82+ expect ( attempt . totalTokens ) . toBe ( CURSOR_CLAUDE_WINDOW + 6 ) ;
83+ } ) ;
84+
3485 test ( "a positive provider-reported input count is never reduced by the cap" , ( ) => {
3586 const attempt = beginRequestAttempt ( 1 , "kiro" , "deepseek-3.2" , "kiro" ) ;
3687 noteAttemptSend ( attempt , 200_000 ) ; // estimate would exceed the window
0 commit comments