@@ -12,6 +12,7 @@ import (
1212 "time"
1313
1414 "github.com/codag-megalith/codag-cli/internal/api"
15+ "github.com/codag-megalith/codag-cli/internal/config"
1516)
1617
1718func TestValidateLogCommand_AllowsKnownLogShapes (t * testing.T ) {
@@ -223,7 +224,7 @@ func TestCompactRawTextPassesTinyInputThroughWithoutAPI(t *testing.T) {
223224 t .Setenv ("CODAG_SERVER" , srv .URL )
224225
225226 raw := "error 42\n INFO recovered\n "
226- got , err := compactRawText (context .Background (), raw , "info" , "api" , "" , "pasted" )
227+ got , err := compactRawText (context .Background (), raw , "info" , "api" , "" , "pasted" , false )
227228 if err != nil {
228229 t .Fatalf ("compactRawText: %v" , err )
229230 }
@@ -272,7 +273,7 @@ func TestCompactRawTextUsesPlanAwareCompactWithAnonymousFallback(t *testing.T) {
272273 t .Setenv ("CODAG_SERVER" , srv .URL )
273274
274275 raw := strings .Repeat ("error 42 database connection timeout active=20 waiting=30 service=api tenant=acme route=/api/orders request_id=abcdef\n " , 12 )
275- got , err := compactRawText (context .Background (), raw , "info" , "api" , "" , "railway" )
276+ got , err := compactRawText (context .Background (), raw , "info" , "api" , "" , "railway" , false )
276277 if err != nil {
277278 t .Fatalf ("compactRawText: %v" , err )
278279 }
@@ -290,7 +291,7 @@ func TestCompactRawTextUsesPlanAwareCompactWithAnonymousFallback(t *testing.T) {
290291func TestRunChildAndCompactAppendsExitStatusNote (t * testing.T ) {
291292 t .Setenv ("XDG_CONFIG_HOME" , t .TempDir ())
292293 got , err := runChildAndCompact (context .Background (), "sh" ,
293- []string {"-c" , "echo boom; exit 7" }, "info" , "" , "" )
294+ []string {"-c" , "echo boom; exit 7" }, "info" , "" , "" , false )
294295 if err != nil {
295296 t .Fatalf ("runChildAndCompact: %v" , err )
296297 }
@@ -302,6 +303,74 @@ func TestRunChildAndCompactAppendsExitStatusNote(t *testing.T) {
302303 }
303304}
304305
306+ func TestCompactToolsSendEngineWhenDeterministic (t * testing.T ) {
307+ t .Setenv ("XDG_CONFIG_HOME" , t .TempDir ())
308+ if err := config .Save (& config.Config {
309+ AccessToken : "AT-test" ,
310+ ExpiresAt : time .Now ().Add (time .Hour ).Unix (),
311+ }); err != nil {
312+ t .Fatalf ("save config: %v" , err )
313+ }
314+
315+ var lastEngine atomic.Value
316+ srv := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
317+ var body struct {
318+ Engine string `json:"engine"`
319+ }
320+ _ = json .NewDecoder (r .Body ).Decode (& body )
321+ lastEngine .Store (body .Engine )
322+ _ = json .NewEncoder (w ).Encode (map [string ]any {
323+ "text" : "summary" ,
324+ "stats" : map [string ]any {"elapsed_ms" : 1 },
325+ })
326+ }))
327+ defer srv .Close ()
328+ t .Setenv ("CODAG_SERVER" , srv .URL )
329+
330+ // Enough lines to beat the tiny-input passthrough.
331+ raw := strings .Repeat ("error 42 database connection timeout active=20 waiting=30 service=api tenant=acme route=/api/orders request_id=abcdef\n " , 12 )
332+
333+ if _ , err := compactRawText (context .Background (), raw , "info" , "api" , "" , "railway" , true ); err != nil {
334+ t .Fatalf ("compactRawText deterministic: %v" , err )
335+ }
336+ if got , _ := lastEngine .Load ().(string ); got != "deterministic" {
337+ t .Fatalf ("compactRawText engine = %q, want deterministic" , got )
338+ }
339+
340+ script := `i=0; while [ $i -lt 12 ]; do echo "error 42 database connection timeout active=20 waiting=30 service=api tenant=acme route=/api/orders request_id=abcdef$i"; i=$((i+1)); done`
341+ if _ , err := runChildAndCompact (context .Background (), "sh" , []string {"-c" , script }, "info" , "" , "" , true ); err != nil {
342+ t .Fatalf ("runChildAndCompact deterministic: %v" , err )
343+ }
344+ if got , _ := lastEngine .Load ().(string ); got != "deterministic" {
345+ t .Fatalf ("runChildAndCompact engine = %q, want deterministic" , got )
346+ }
347+
348+ if _ , err := compactRawText (context .Background (), raw , "info" , "api" , "" , "railway" , false ); err != nil {
349+ t .Fatalf ("compactRawText default: %v" , err )
350+ }
351+ if got , _ := lastEngine .Load ().(string ); got != "" {
352+ t .Fatalf ("default engine = %q, want empty" , got )
353+ }
354+ }
355+
356+ func TestBoolArgToleratesAgentShapes (t * testing.T ) {
357+ cases := []struct {
358+ val any
359+ want bool
360+ }{
361+ {true , true }, {false , false }, {"true" , true }, {"1" , true },
362+ {"false" , false }, {"yes" , false }, {nil , false }, {42 , false },
363+ }
364+ for _ , c := range cases {
365+ if got := boolArg (map [string ]any {"k" : c .val }, "k" ); got != c .want {
366+ t .Errorf ("boolArg(%v) = %v, want %v" , c .val , got , c .want )
367+ }
368+ }
369+ if boolArg (map [string ]any {}, "missing" ) {
370+ t .Error ("boolArg on missing key = true, want false" )
371+ }
372+ }
373+
305374func TestWithNotes (t * testing.T ) {
306375 if got := withNotes ("summary" , nil ); got != "summary" {
307376 t .Fatalf ("no notes = %q" , got )
0 commit comments