@@ -7,41 +7,41 @@ export {} // This makes the file a proper TypeScript module
77describe ( "ContextWindowProgress Logic" , ( ) => {
88 // Using the shared utility function from model-utils.ts instead of reimplementing it
99
10- test ( "calculates correct token distribution with default 20% reservation" , ( ) => {
11- const contextWindow = 4000
10+ test ( "calculates correct token distribution with default 8192 reservation" , ( ) => {
11+ const contextWindow = 10000
1212 const contextTokens = 1000
1313
1414 const result = calculateTokenDistribution ( contextWindow , contextTokens )
1515
1616 // Expected calculations:
17- // reservedForOutput = 0.2 * 4000 = 800
18- // availableSize = 4000 - 1000 - 800 = 2200
19- // total = 1000 + 800 + 2200 = 4000
20- expect ( result . reservedForOutput ) . toBe ( 800 )
21- expect ( result . availableSize ) . toBe ( 2200 )
17+ // reservedForOutput = 8192 (ANTHROPIC_DEFAULT_MAX_TOKENS)
18+ // availableSize = 10000 - 1000 - 8192 = 808
19+ // total = 1000 + 8192 + 808 = 10000
20+ expect ( result . reservedForOutput ) . toBe ( 8192 )
21+ expect ( result . availableSize ) . toBe ( 808 )
2222
2323 // Check percentages
24- expect ( result . currentPercent ) . toBeCloseTo ( 25 ) // 1000/4000 * 100 = 25 %
25- expect ( result . reservedPercent ) . toBeCloseTo ( 20 ) // 800/4000 * 100 = 20 %
26- expect ( result . availablePercent ) . toBeCloseTo ( 55 ) // 2200/4000 * 100 = 55 %
24+ expect ( result . currentPercent ) . toBeCloseTo ( 10 ) // 1000/10000 * 100 = 10 %
25+ expect ( result . reservedPercent ) . toBeCloseTo ( 81.92 ) // 8192/10000 * 100 = 81.92 %
26+ expect ( result . availablePercent ) . toBeCloseTo ( 8.08 ) // 808/10000 * 100 = 8.08 %
2727
2828 // Verify percentages sum to 100%
2929 expect ( result . currentPercent + result . reservedPercent + result . availablePercent ) . toBeCloseTo ( 100 )
3030 } )
3131
3232 test ( "uses provided maxTokens when available instead of default calculation" , ( ) => {
33- const contextWindow = 4000
33+ const contextWindow = 10000
3434 const contextTokens = 1000
3535
36- // First calculate with default 20% reservation (no maxTokens provided)
36+ // First calculate with default 8192 reservation (no maxTokens provided)
3737 const defaultResult = calculateTokenDistribution ( contextWindow , contextTokens )
3838
3939 // Then calculate with custom maxTokens value
40- const customMaxTokens = 1500 // Custom maxTokens instead of default 20%
40+ const customMaxTokens = 1500 // Custom maxTokens instead of default 8192
4141 const customResult = calculateTokenDistribution ( contextWindow , contextTokens , customMaxTokens )
4242
43- // VERIFY MAXTOKEN PROP EFFECT: Custom maxTokens should be used directly instead of 20% calculation
44- const defaultReserved = Math . ceil ( contextWindow * 0.2 ) // 800 tokens (20% of 4000)
43+ // VERIFY MAXTOKEN PROP EFFECT: Custom maxTokens should be used directly instead of 8192 calculation
44+ const defaultReserved = 8192 // ANTHROPIC_DEFAULT_MAX_TOKENS
4545 expect ( defaultResult . reservedForOutput ) . toBe ( defaultReserved )
4646 expect ( customResult . reservedForOutput ) . toBe ( customMaxTokens ) // Should use exact provided value
4747
@@ -51,13 +51,13 @@ describe("ContextWindowProgress Logic", () => {
5151 expect ( defaultTooltip ) . not . toBe ( customTooltip )
5252
5353 // Verify the effect on available space
54- expect ( customResult . availableSize ) . toBe ( 4000 - 1000 - 1500 ) // 1500 tokens available
55- expect ( defaultResult . availableSize ) . toBe ( 4000 - 1000 - 800 ) // 2200 tokens available
54+ expect ( customResult . availableSize ) . toBe ( 10000 - 1000 - 1500 ) // 7500 tokens available
55+ expect ( defaultResult . availableSize ) . toBe ( 10000 - 1000 - 8192 ) // 808 tokens available
5656
5757 // Verify the effect on percentages
58- // With custom maxTokens (1500), the reserved percentage should be higher
59- expect ( defaultResult . reservedPercent ) . toBeCloseTo ( 20 ) // 800/4000 * 100 = 20 %
60- expect ( customResult . reservedPercent ) . toBeCloseTo ( 37.5 ) // 1500/4000 * 100 = 37.5 %
58+ // With custom maxTokens (1500), the reserved percentage should be lower than default
59+ expect ( defaultResult . reservedPercent ) . toBeCloseTo ( 81.92 ) // 8192/10000 * 100 = 81.92 %
60+ expect ( customResult . reservedPercent ) . toBeCloseTo ( 15 ) // 1500/10000 * 100 = 15 %
6161
6262 // Verify percentages still sum to 100%
6363 expect ( customResult . currentPercent + customResult . reservedPercent + customResult . availablePercent ) . toBeCloseTo (
@@ -66,19 +66,19 @@ describe("ContextWindowProgress Logic", () => {
6666 } )
6767
6868 test ( "handles negative input values" , ( ) => {
69- const contextWindow = 4000
69+ const contextWindow = 10000
7070 const contextTokens = - 500 // Negative tokens should be handled gracefully
7171
7272 const result = calculateTokenDistribution ( contextWindow , contextTokens )
7373
7474 // Expected calculations:
7575 // safeContextTokens = Math.max(0, -500) = 0
76- // reservedForOutput = 0.2 * 4000 = 800
77- // availableSize = 4000 - 0 - 800 = 3200
78- // total = 0 + 800 + 3200 = 4000
79- expect ( result . currentPercent ) . toBeCloseTo ( 0 ) // 0/4000 * 100 = 0%
80- expect ( result . reservedPercent ) . toBeCloseTo ( 20 ) // 800/4000 * 100 = 20 %
81- expect ( result . availablePercent ) . toBeCloseTo ( 80 ) // 3200/4000 * 100 = 80 %
76+ // reservedForOutput = 8192 (ANTHROPIC_DEFAULT_MAX_TOKENS)
77+ // availableSize = 10000 - 0 - 8192 = 1808
78+ // total = 0 + 8192 + 1808 = 10000
79+ expect ( result . currentPercent ) . toBeCloseTo ( 0 ) // 0/10000 * 100 = 0%
80+ expect ( result . reservedPercent ) . toBeCloseTo ( 81.92 ) // 8192/10000 * 100 = 81.92 %
81+ expect ( result . availablePercent ) . toBeCloseTo ( 18.08 ) // 1808/10000 * 100 = 18.08 %
8282 } )
8383
8484 test ( "handles zero context window gracefully" , ( ) => {
@@ -87,9 +87,9 @@ describe("ContextWindowProgress Logic", () => {
8787
8888 const result = calculateTokenDistribution ( contextWindow , contextTokens )
8989
90- // With zero context window, everything should be zero
91- expect ( result . reservedForOutput ) . toBe ( 0 )
92- expect ( result . availableSize ) . toBe ( 0 )
90+ // With zero context window, the function uses ANTHROPIC_DEFAULT_MAX_TOKENS but available size becomes 0
91+ expect ( result . reservedForOutput ) . toBe ( 8192 ) // ANTHROPIC_DEFAULT_MAX_TOKENS
92+ expect ( result . availableSize ) . toBe ( 0 ) // max(0, 0 - 1000 - 8192) = 0
9393
9494 // The percentages maintain total of 100% even with zero context window
9595 // due to how the division handles this edge case
@@ -98,20 +98,20 @@ describe("ContextWindowProgress Logic", () => {
9898 } )
9999
100100 test ( "handles case where tokens exceed context window" , ( ) => {
101- const contextWindow = 4000
102- const contextTokens = 5000 // More tokens than the window size
101+ const contextWindow = 10000
102+ const contextTokens = 12000 // More tokens than the window size
103103
104104 const result = calculateTokenDistribution ( contextWindow , contextTokens )
105105
106106 // Expected calculations:
107- // reservedForOutput = 0.2 * 4000 = 800
108- // availableSize = Math.max(0, 4000 - 5000 - 800 ) = 0
109- expect ( result . reservedForOutput ) . toBe ( 800 )
107+ // reservedForOutput = 8192 (ANTHROPIC_DEFAULT_MAX_TOKENS)
108+ // availableSize = Math.max(0, 10000 - 12000 - 8192 ) = 0
109+ expect ( result . reservedForOutput ) . toBe ( 8192 )
110110 expect ( result . availableSize ) . toBe ( 0 )
111111
112- // Percentages should be calculated based on total (5000 + 800 + 0 = 5800 )
113- expect ( result . currentPercent ) . toBeCloseTo ( ( 5000 / 5800 ) * 100 )
114- expect ( result . reservedPercent ) . toBeCloseTo ( ( 800 / 5800 ) * 100 )
112+ // Percentages should be calculated based on total (12000 + 8192 + 0 = 20192 )
113+ expect ( result . currentPercent ) . toBeCloseTo ( ( 12000 / 20192 ) * 100 )
114+ expect ( result . reservedPercent ) . toBeCloseTo ( ( 8192 / 20192 ) * 100 )
115115 expect ( result . availablePercent ) . toBeCloseTo ( 0 )
116116
117117 // Verify percentages sum to 100%
0 commit comments