Skip to content

Commit 938574a

Browse files
authored
test: fix DifferentVarsCacheMiss test to use same filter with different varNames
The test previously used different filter strings to prove a cache miss. It now uses the same filter string with different varNames slices, which is the actual behavior being documented (composite cache key includes varNames).
1 parent e0e42fd commit 938574a

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

internal/middleware/jqschema_coverage_test.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -534,19 +534,22 @@ func TestCompileToolResponseFilterWithVars_CacheHit(t *testing.T) {
534534
}
535535

536536
// TestCompileToolResponseFilterWithVars_DifferentVarsCacheMiss verifies that
537-
// different variable name lists produce distinct cache entries.
537+
// the same filter string compiled with different variable name lists produces
538+
// distinct cache entries (different *gojq.Code pointers).
538539
func TestCompileToolResponseFilterWithVars_DifferentVarsCacheMiss(t *testing.T) {
539-
filter := ". | {id: $id}"
540-
code1, err := CompileToolResponseFilterWithVars(filter, []string{"$id"})
540+
// Use a filter that doesn't reference any specific variable so it compiles
541+
// successfully with any varNames list.
542+
filter := ". | {ok: true}"
543+
code1, err := CompileToolResponseFilterWithVars(filter, []string{"$a"})
541544
require.NoError(t, err)
542545
require.NotNil(t, code1)
543546

544-
// Same filter string but different variable name list → should be a distinct entry.
545-
code2, err := CompileToolResponseFilterWithVars(filter+" ", []string{"$id"})
547+
// Same filter string but a different variable name list → distinct cache key.
548+
code2, err := CompileToolResponseFilterWithVars(filter, []string{"$a", "$b"})
546549
require.NoError(t, err)
547550
require.NotNil(t, code2)
548551

549-
assert.NotSame(t, code1, code2, "CompileToolResponseFilterWithVars should use distinct cache entries for different filter strings")
552+
assert.NotSame(t, code1, code2, "CompileToolResponseFilterWithVars should use distinct cache entries for different varNames")
550553
}
551554

552555
// ---------------------------------------------------------------------------

0 commit comments

Comments
 (0)