11package encrypt_test
22
33import (
4+ "encoding/json"
45 "errors"
56 "os"
67 "os/exec"
78 "path/filepath"
9+ "regexp"
10+ "slices"
811 "strings"
912 "testing"
13+
14+ "github.com/cipherstash/stack/languages/golang/encrypt"
1015)
1116
17+ // All conformance runners use the same missing-guest policy. Other errors
18+ // remain failures in the caller, including errors wrapping neither sentinel.
19+ func skipMissingConformanceGuest (t * testing.T , err error ) {
20+ t .Helper ()
21+ if (errors .Is (err , encrypt .ErrGuestNotBuilt ) || errors .Is (err , encrypt .ErrDeterministicGuestNotBuilt )) && os .Getenv ("STACK_CONFORMANCE_REQUIRED" ) != "1" {
22+ t .Skip (err )
23+ }
24+ }
25+
1226// Exercise the real fixture entry points in an isolated tree with their frozen
13- // inputs but no guest. A missing guest must never make required conformance green.
27+ // inputs but no guest. Check every indexed test's outcome, so a missing compiled
28+ // test also fails this guard. A missing guest must never make conformance green.
1429func TestFixtureConformanceRequiresGuest (t * testing.T ) {
1530 binary , err := os .Executable ()
1631 if err != nil {
@@ -24,20 +39,56 @@ func TestFixtureConformanceRequiresGuest(t *testing.T) {
2439 t .Fatal (err )
2540 }
2641 }
27- for _ , name := range []string {"value_kinds.json" , "query_operators.json" } {
28- data , err := os .ReadFile (filepath .Join (".." , ".." , ".." , fixtures , name ))
42+ var index struct {
43+ Profiles []struct {
44+ Fixture string `json:"fixture"`
45+ Requirements []struct {
46+ GoTests []string `json:"go_tests"`
47+ } `json:"requirements"`
48+ } `json:"profiles"`
49+ }
50+ data , err := os .ReadFile (filepath .Join (".." , ".." , ".." , "conformance" , "stack-encrypt" , "v1" , "fixture-profiles.json" ))
51+ if err != nil {
52+ t .Fatal (err )
53+ }
54+ if err := json .Unmarshal (data , & index ); err != nil {
55+ t .Fatal (err )
56+ }
57+ names := make (map [string ]bool )
58+ for _ , profile := range index .Profiles {
59+ data , err := os .ReadFile (filepath .Join (".." , ".." , ".." , profile .Fixture ))
2960 if err != nil {
3061 t .Fatal (err )
3162 }
32- if err := os .WriteFile (filepath .Join (root , fixtures , name ), data , 0o600 ); err != nil {
63+ if err := os .WriteFile (filepath .Join (root , profile . Fixture ), data , 0o600 ); err != nil {
3364 t .Fatal (err )
3465 }
66+ for _ , requirement := range profile .Requirements {
67+ for _ , name := range requirement .GoTests {
68+ names [name ] = true
69+ }
70+ }
71+ }
72+ if len (names ) == 0 {
73+ t .Fatal ("fixture index selects no Go tests" )
74+ }
75+ // These full-suite tests also share queryFixtureClient's required-mode policy;
76+ // they remain outside the shared fixture requirements and aggregate selection.
77+ names ["TestAQueryTheFieldDoesNotAnswerIsRefused" ] = true
78+ names ["TestAMatchesQueryNeverPrintsItsText" ] = true
79+ tests := make ([]string , 0 , len (names ))
80+ for name := range names {
81+ tests = append (tests , name )
82+ }
83+ slices .Sort (tests )
84+ patterns := make ([]string , len (tests ))
85+ for i , name := range tests {
86+ patterns [i ] = regexp .QuoteMeta (name )
3587 }
36- tests := []string {"TestGeneratedCodeOpensTheRustValueKindsFixture" , "TestQueryTermsAreTheRustFixtures" }
3788 for _ , required := range []string {"0" , "1" } {
3889 t .Run ("required=" + required , func (t * testing.T ) {
3990 t .Setenv ("STACK_CONFORMANCE_REQUIRED" , required )
40- cmd := exec .CommandContext (t .Context (), binary , "-test.v" , "-test.timeout=30s" , "-test.run=^(" + strings .Join (tests , "|" )+ ")$" )
91+ cmd := exec .CommandContext (t .Context (), binary , "-test.v" , "-test.timeout=30s" , "-test.run=^(" + strings .Join (patterns , "|" )+ ")$" )
4192 cmd .Dir = workdir
4293 out , err := cmd .CombinedOutput ()
4394 marker := "--- SKIP: "
0 commit comments