66 formatForBudget ,
77 applyTokenBudget
88} from '../src/core/token-budget' ;
9- import type { Skill } from '../src/core/types' ;
9+ import type { Doc } from '../src/core/types' ;
1010
1111describe ( 'token-budget' , ( ) => {
1212 describe ( 'estimateTokens' , ( ) => {
@@ -34,7 +34,8 @@ describe('token-budget', () => {
3434
3535 describe ( 'extractCodeBlocks' , ( ) => {
3636 it ( 'should extract fenced code blocks from markdown' , ( ) => {
37- const content = 'Some text\n```js\nconst x = 1;\n```\nMore text\n```ts\nconst y = 2;\n```' ;
37+ const content =
38+ 'Some text\n```js\nconst x = 1;\n```\nMore text\n```ts\nconst y = 2;\n```' ;
3839 const blocks = extractCodeBlocks ( content ) ;
3940 expect ( blocks ) . toHaveLength ( 2 ) ;
4041 expect ( blocks [ 0 ] ) . toContain ( 'const x = 1' ) ;
@@ -70,10 +71,9 @@ describe('token-budget', () => {
7071 } ) ;
7172
7273 describe ( 'formatForBudget' , ( ) => {
73- const baseSkill : Skill = {
74- id : 'test-skill' ,
75- title : 'Test Skill' ,
76- title_en : 'Test Skill' ,
74+ const baseDoc : Doc = {
75+ id : 'test-doc' ,
76+ title : 'Test Doc' ,
7777 description : 'A test description' ,
7878 library : 'g2' ,
7979 version : '5.x' ,
@@ -83,47 +83,47 @@ describe('token-budget', () => {
8383 use_cases : [ ] ,
8484 anti_patterns : [ ] ,
8585 related : [ ] ,
86- content : '## Intro\nSome text\n```js\nconst x = 1;\n```\nMore details here.'
86+ content :
87+ '## Intro\nSome text\n```js\nconst x = 1;\n```\nMore details here.'
8788 } ;
8889
8990 it ( 'level 0: should return full content' , ( ) => {
90- const result = formatForBudget ( baseSkill , 0 , 500 ) ;
91- expect ( result ) . toContain ( 'Test Skill ' ) ;
91+ const result = formatForBudget ( baseDoc , 0 , 500 ) ;
92+ expect ( result ) . toContain ( 'Test Doc ' ) ;
9293 expect ( result ) . toContain ( 'Some text' ) ;
9394 expect ( result ) . toContain ( 'const x = 1' ) ;
9495 expect ( result ) . toContain ( 'More details' ) ;
9596 } ) ;
9697
9798 it ( 'level 1: should return summary + code blocks only' , ( ) => {
98- const result = formatForBudget ( baseSkill , 1 , 500 ) ;
99- expect ( result ) . toContain ( 'Test Skill ' ) ;
99+ const result = formatForBudget ( baseDoc , 1 , 500 ) ;
100+ expect ( result ) . toContain ( 'Test Doc ' ) ;
100101 expect ( result ) . toContain ( 'A test description' ) ;
101102 expect ( result ) . toContain ( 'const x = 1' ) ;
102103 // Should NOT contain the prose "More details" (it's not in a code block)
103104 expect ( result ) . not . toContain ( 'More details' ) ;
104105 } ) ;
105106
106107 it ( 'level 2: should return summary only' , ( ) => {
107- const result = formatForBudget ( baseSkill , 2 , 500 ) ;
108- expect ( result ) . toContain ( 'Test Skill ' ) ;
108+ const result = formatForBudget ( baseDoc , 2 , 500 ) ;
109+ expect ( result ) . toContain ( 'Test Doc ' ) ;
109110 expect ( result ) . toContain ( 'A test description' ) ;
110111 // Should NOT contain any body content
111112 expect ( result ) . not . toContain ( 'Some text' ) ;
112113 expect ( result ) . not . toContain ( 'const x = 1' ) ;
113114 } ) ;
114115
115116 it ( 'should truncate when budget is too small for code blocks' , ( ) => {
116- const result = formatForBudget ( baseSkill , 1 , 5 ) ;
117+ const result = formatForBudget ( baseDoc , 1 , 5 ) ;
117118 // Very small budget — should fallback to truncateContent
118119 expect ( result . length ) . toBeGreaterThan ( 0 ) ;
119120 } ) ;
120121 } ) ;
121122
122123 describe ( 'applyTokenBudget' , ( ) => {
123- const makeSkill = ( id : string , content : string ) : Skill => ( {
124+ const makeDoc = ( id : string , content : string ) : Doc => ( {
124125 id,
125- title : `Skill ${ id } ` ,
126- title_en : `Skill ${ id } ` ,
126+ title : `Doc ${ id } ` ,
127127 description : '' ,
128128 library : 'g2' ,
129129 version : '' ,
@@ -136,44 +136,45 @@ describe('token-budget', () => {
136136 content
137137 } ) ;
138138
139- it ( 'should give full budget to __info__ and trim remaining skills ' , ( ) => {
140- const skills : Skill [ ] = [
139+ it ( 'should give full budget to __info__ and trim remaining docs ' , ( ) => {
140+ const docs : Doc [ ] = [
141141 {
142- ...makeSkill ( '__info__g2' , 'Core constraints text that is important' ) ,
142+ ...makeDoc ( '__info__g2' , 'Core constraints text that is important' ) ,
143143 category : '__info__'
144144 } ,
145- makeSkill ( 'skill -1', 'Content for skill one' ) ,
146- makeSkill ( 'skill -2', 'Content for skill two' ) ,
145+ makeDoc ( 'doc -1', 'Content for doc one' ) ,
146+ makeDoc ( 'doc -2', 'Content for doc two' )
147147 ] ;
148148
149- const result = applyTokenBudget ( skills , 20 , 1 ) ;
149+ const result = applyTokenBudget ( docs , 20 , 1 ) ;
150150 // __info__ should keep its content
151151 expect ( result [ 0 ] . content ) . toBeDefined ( ) ;
152152 } ) ;
153153
154154 it ( 'should set content to undefined when budget exhausted' , ( ) => {
155- const skills : Skill [ ] = [
155+ const docs : Doc [ ] = [
156156 {
157- ...makeSkill ( '__info__g2' , 'Very long constraints content eating all budget' ) ,
157+ ...makeDoc (
158+ '__info__g2' ,
159+ 'Very long constraints content eating all budget'
160+ ) ,
158161 category : '__info__'
159162 } ,
160- makeSkill ( 'skill -1', 'Short content' ) ,
161- makeSkill ( 'skill -2', 'Another content' ) ,
163+ makeDoc ( 'doc -1', 'Short content' ) ,
164+ makeDoc ( 'doc -2', 'Another content' )
162165 ] ;
163166
164167 // Very small budget — info consumes it all
165- const result = applyTokenBudget ( skills , 5 , 1 ) ;
166- // Skills after info should have no content
168+ const result = applyTokenBudget ( docs , 5 , 1 ) ;
169+ // Docs after info should have no content
167170 expect ( result [ 1 ] . content ) . toBeUndefined ( ) ;
168171 expect ( result [ 2 ] . content ) . toBeUndefined ( ) ;
169172 } ) ;
170173
171- it ( 'should handle no __info__ skill gracefully' , ( ) => {
172- const skills : Skill [ ] = [
173- makeSkill ( 'skill-1' , 'Content for skill one' ) ,
174- ] ;
174+ it ( 'should handle no __info__ doc gracefully' , ( ) => {
175+ const docs : Doc [ ] = [ makeDoc ( 'doc-1' , 'Content for doc one' ) ] ;
175176
176- const result = applyTokenBudget ( skills , 50 , 0 ) ;
177+ const result = applyTokenBudget ( docs , 50 , 0 ) ;
177178 expect ( result [ 0 ] . content ) . toBeDefined ( ) ;
178179 } ) ;
179180 } ) ;
0 commit comments