@@ -43,7 +43,7 @@ func TestInjectTools_CacheBreakpoints(t *testing.T) {
4343 require .Equal (t , constant .ValueOf [constant.Ephemeral ](), i .req .Tools [0 ].OfTool .CacheControl .Type )
4444 })
4545
46- t .Run ("cache control breakpoint is preserved and moved to final tool " , func (t * testing.T ) {
46+ t .Run ("cache control breakpoint is preserved by prepending injected tools " , func (t * testing.T ) {
4747 t .Parallel ()
4848
4949 // Request has existing tool with cache control.
@@ -72,16 +72,16 @@ func TestInjectTools_CacheBreakpoints(t *testing.T) {
7272 i .injectTools ()
7373
7474 require .Len (t , i .req .Tools , 2 )
75- // Original tool's cache control should be cleared .
76- require .Equal (t , "existing_tool " , i .req .Tools [0 ].OfTool .Name )
75+ // Injected tools are prepended .
76+ require .Equal (t , "injected_tool " , i .req .Tools [0 ].OfTool .Name )
7777 require .Zero (t , i .req .Tools [0 ].OfTool .CacheControl )
78- // Cache control breakpoint should be moved to the final tool .
79- require .Equal (t , "injected_tool " , i .req .Tools [1 ].OfTool .Name )
78+ // Original tool's cache control should be preserved at the end .
79+ require .Equal (t , "existing_tool " , i .req .Tools [1 ].OfTool .Name )
8080 require .Equal (t , constant .ValueOf [constant.Ephemeral ](), i .req .Tools [1 ].OfTool .CacheControl .Type )
8181 })
8282
83- // Multiple breakpoints should not be set , but if they are we should only move the first one to the end .
84- t .Run ("only first cache control breakpoint is moved when multiple exist " , func (t * testing.T ) {
83+ // The cache breakpoint SHOULD be on the final tool , but may not be; we must preserve that intention .
84+ t .Run ("cache control breakpoint in non-standard location is preserved " , func (t * testing.T ) {
8585 t .Parallel ()
8686
8787 // Request has multiple tools with cache control breakpoints.
@@ -100,9 +100,6 @@ func TestInjectTools_CacheBreakpoints(t *testing.T) {
100100 {
101101 OfTool : & anthropic.ToolParam {
102102 Name : "tool_with_cache_2" ,
103- CacheControl : anthropic.CacheControlEphemeralParam {
104- Type : constant .ValueOf [constant.Ephemeral ](),
105- },
106103 },
107104 },
108105 },
@@ -118,15 +115,14 @@ func TestInjectTools_CacheBreakpoints(t *testing.T) {
118115 i .injectTools ()
119116
120117 require .Len (t , i .req .Tools , 3 )
121- // First tool's cache control should be cleared (it was captured) .
122- require .Equal (t , "tool_with_cache_1 " , i .req .Tools [0 ].OfTool .Name )
118+ // Injected tool is prepended without cache control .
119+ require .Equal (t , "injected_tool " , i .req .Tools [0 ].OfTool .Name )
123120 require .Zero (t , i .req .Tools [0 ].OfTool .CacheControl )
124- // Second tool's cache control should remain (loop breaks after first match) .
125- require .Equal (t , "tool_with_cache_2 " , i .req .Tools [1 ].OfTool .Name )
121+ // Both original tools' cache controls should remain.
122+ require .Equal (t , "tool_with_cache_1 " , i .req .Tools [1 ].OfTool .Name )
126123 require .Equal (t , constant .ValueOf [constant.Ephemeral ](), i .req .Tools [1 ].OfTool .CacheControl .Type )
127- // Only the first breakpoint is moved to the final tool.
128- require .Equal (t , "injected_tool" , i .req .Tools [2 ].OfTool .Name )
129- require .Equal (t , constant .ValueOf [constant.Ephemeral ](), i .req .Tools [2 ].OfTool .CacheControl .Type )
124+ require .Equal (t , "tool_with_cache_2" , i .req .Tools [2 ].OfTool .Name )
125+ require .Zero (t , i .req .Tools [2 ].OfTool .CacheControl )
130126 })
131127
132128 t .Run ("no cache control added when none originally set" , func (t * testing.T ) {
@@ -155,10 +151,11 @@ func TestInjectTools_CacheBreakpoints(t *testing.T) {
155151 i .injectTools ()
156152
157153 require .Len (t , i .req .Tools , 2 )
158- // Neither tool should have cache control.
159- require .Equal (t , "existing_tool_no_cache " , i .req .Tools [0 ].OfTool .Name )
154+ // Injected tool is prepended without cache control.
155+ require .Equal (t , "injected_tool " , i .req .Tools [0 ].OfTool .Name )
160156 require .Zero (t , i .req .Tools [0 ].OfTool .CacheControl )
161- require .Equal (t , "injected_tool" , i .req .Tools [1 ].OfTool .Name )
157+ // Original tool remains at the end without cache control.
158+ require .Equal (t , "existing_tool_no_cache" , i .req .Tools [1 ].OfTool .Name )
162159 require .Zero (t , i .req .Tools [1 ].OfTool .CacheControl )
163160 })
164161}
0 commit comments