@@ -3,6 +3,7 @@ package testcases
33import (
44 "bytes"
55 "context"
6+ "embed"
67 "encoding/json"
78 "fmt"
89 "io"
@@ -13,6 +14,9 @@ import (
1314 "k8s.io/client-go/kubernetes"
1415)
1516
17+ //go:embed testdata/plugin_chain_cases.json
18+ var pluginChainTestData embed.FS
19+
1620func init () {
1721 pkgtestcases .Register ("plugin-chain-execution" , pkgtestcases.TestCase {
1822 Description : "Test plugin chain execution order and blocking behavior" ,
@@ -23,14 +27,29 @@ func init() {
2327
2428// PluginChainCase represents a test case for plugin chain execution
2529type PluginChainCase struct {
30+ Description string `json:"description"`
2631 Query string `json:"query"`
2732 ExpectPIIBlock bool `json:"expect_pii_block"`
2833 ExpectCacheUsed bool `json:"expect_cache_used"`
2934 ExpectPromptApplied bool `json:"expect_prompt_applied"`
30- Description string `json:"description"`
3135 PIITypes []string `json:"pii_types"` // Expected PII types detected
3236}
3337
38+ // loadPluginChainCases loads test cases from the embedded JSON file
39+ func loadPluginChainCases () ([]PluginChainCase , error ) {
40+ data , err := pluginChainTestData .ReadFile ("testdata/plugin_chain_cases.json" )
41+ if err != nil {
42+ return nil , fmt .Errorf ("failed to read plugin chain cases: %w" , err )
43+ }
44+
45+ var cases []PluginChainCase
46+ if err := json .Unmarshal (data , & cases ); err != nil {
47+ return nil , fmt .Errorf ("failed to parse plugin chain cases: %w" , err )
48+ }
49+
50+ return cases , nil
51+ }
52+
3453// PluginChainResult tracks the result of a single plugin chain test
3554type PluginChainResult struct {
3655 Query string
@@ -58,38 +77,14 @@ func testPluginChainExecution(ctx context.Context, client *kubernetes.Clientset,
5877 }
5978 defer stopPortForward ()
6079
61- // Define test cases
62- testCases := []PluginChainCase {
63- {
64- Query : "My social security number is 123-45-6789" ,
65- ExpectPIIBlock : true ,
66- ExpectCacheUsed : false , // PII blocks before cache
67- ExpectPromptApplied : false , // PII blocks before prompt
68- Description : "PII (SSN) should block entire plugin chain" ,
69- PIITypes : []string {"US_SSN" },
70- },
71- {
72- Query :
"Contact me at [email protected] " ,
73- ExpectPIIBlock : true ,
74- ExpectCacheUsed : false ,
75- ExpectPromptApplied : false ,
76- Description : "PII (EMAIL) should block entire plugin chain" ,
77- PIITypes : []string {"EMAIL" },
78- },
79- {
80- Query : "What is 5 + 7?" ,
81- ExpectPIIBlock : false ,
82- ExpectCacheUsed : false , // First request, cache miss
83- ExpectPromptApplied : true , // Should apply math expert prompt
84- Description : "Clean query should pass PII and apply prompt" ,
85- },
86- {
87- Query : "Tell me about photosynthesis" ,
88- ExpectPIIBlock : false ,
89- ExpectCacheUsed : false ,
90- ExpectPromptApplied : true ,
91- Description : "Biology query should pass PII plugin" ,
92- },
80+ // Load test cases from JSON file
81+ testCases , err := loadPluginChainCases ()
82+ if err != nil {
83+ return fmt .Errorf ("failed to load test cases: %w" , err )
84+ }
85+
86+ if opts .Verbose {
87+ fmt .Printf ("[Test] Loaded %d test cases from testdata/plugin_chain_cases.json\n " , len (testCases ))
9388 }
9489
9590 // Run plugin chain tests
@@ -181,7 +176,12 @@ func testSinglePluginChain(ctx context.Context, testCase PluginChainCase, localP
181176
182177 // Extract plugin execution headers
183178 piiViolationHeader := resp .Header .Get ("x-vsr-pii-violation" )
184- result .PIIDetected = piiViolationHeader // Store for display purposes
179+ piiTypesHeader := resp .Header .Get ("x-vsr-pii-types" )
180+ if piiTypesHeader != "" {
181+ result .PIIDetected = piiTypesHeader // Store detected PII types for display
182+ } else {
183+ result .PIIDetected = piiViolationHeader // Fallback to boolean
184+ }
185185 result .PIIBlocked = (resp .StatusCode == http .StatusForbidden || piiViolationHeader == "true" )
186186
187187 // Check cache headers (x-vsr-cache-hit or similar)
0 commit comments