@@ -11,15 +11,13 @@ import (
1111 "github.com/stretchr/testify/require"
1212)
1313
14- // TestE2E_ProvisioningOverrideMigration exercises the full lifecycle:
14+ // TestE2E_ProvisioningOverride exercises the full lifecycle:
1515// 1. Sync platform defaults
16- // 2. Provision a new tenant (seeder creates platform_ref entries )
17- // 3. Verify platform fallback resolution works
16+ // 2. Provision a new tenant (seeder copies scripts directly into tenant schema )
17+ // 3. Verify scripts are resolved from tenant schema (no public fallback)
1818// 4. Override a saga with custom script
19- // 5. Verify override takes priority over platform default
20- // 6. Provision another tenant with old-style copies
21- // 7. Migrate old tenant to platform refs
22- func TestE2E_ProvisioningOverrideMigration (t * testing.T ) {
19+ // 5. Verify override takes priority over system default
20+ func TestE2E_ProvisioningOverride (t * testing.T ) {
2321 pool , cleanup := setupPlatformTestDB (t )
2422 defer cleanup ()
2523
@@ -30,7 +28,7 @@ func TestE2E_ProvisioningOverrideMigration(t *testing.T) {
3028 err := platformSync .SyncPlatformDefaults (ctx )
3129 require .NoError (t , err )
3230
33- // Step 2: Provision tenant alpha (new-style with platform_ref )
31+ // Step 2: Provision tenant alpha (scripts copied directly into tenant schema )
3432 alphaID := tenant .TenantID ("alpha_corp" )
3533 alphaSchema := alphaID .SchemaName ()
3634 setupTenantSchemaForSeeder (t , pool , ctx , alphaSchema )
@@ -40,16 +38,19 @@ func TestE2E_ProvisioningOverrideMigration(t *testing.T) {
4038 err = seeder .SeedTenant (ctx , alphaID )
4139 require .NoError (t , err )
4240
43- // Step 3: Verify platform fallback resolution
41+ // Step 3: Verify scripts are self-contained in tenant schema
4442 alphaCtx := tenant .WithTenant (ctx , alphaID )
4543 registry := NewPostgresRegistry (pool , nil )
4644
4745 activeDef , err := registry .GetActive (alphaCtx , "current_account_withdrawal" )
4846 require .NoError (t , err )
4947 assert .True (t , activeDef .IsSystem , "should resolve system saga" )
50- assert .True (t , activeDef .UsedPlatformFallback , "should use platform fallback" )
48+ assert .False (t , activeDef .UsedPlatformFallback ,
49+ "should not use platform fallback - scripts copied directly" )
5150 assert .NotEmpty (t , activeDef .ResolvedScript , "resolved script should not be empty" )
52- assert .NotNil (t , activeDef .PlatformRef , "platform_ref should be set" )
51+ assert .NotEmpty (t , activeDef .Script , "script should be copied directly into tenant" )
52+ assert .Nil (t , activeDef .PlatformRef ,
53+ "platform_ref should be nil - scripts are self-contained" )
5354
5455 // Step 4: Create tenant override
5556 overrideSvc := NewOverrideService (pool , registry )
@@ -95,55 +96,13 @@ def posting_rules(ctx):
9596 assert .Equal (t , "Alpha Corp requires UK compliance checks on all withdrawals" ,
9697 activeDef .OverrideReason )
9798
98- // Non-overridden sagas should still use platform fallback
99+ // Non-overridden sagas should resolve from tenant's own script copy
99100 depositDef , err := registry .GetActive (alphaCtx , "current_account_deposit" )
100101 require .NoError (t , err )
101102 assert .True (t , depositDef .IsSystem , "deposit should still use system saga" )
102- assert .True (t , depositDef .UsedPlatformFallback , "deposit should use platform fallback" )
103-
104- // Step 6: Provision tenant beta (old-style with script copies)
105- betaID := tenant .TenantID ("beta_corp" )
106- betaSchema := betaID .SchemaName ()
107- setupTenantSchemaForSeeder (t , pool , ctx , betaSchema )
108-
109- // Insert old-style script-copied sagas
110- scripts , err := GetEmbeddedScripts ()
111- require .NoError (t , err )
112-
113- e2eDefaults , e2eDefaultsErr := PlatformDefaults ()
114- require .NoError (t , e2eDefaultsErr )
115- for _ , meta := range e2eDefaults {
116- script , ok := scripts [meta .Filename + ".star" ]
117- require .True (t , ok , "expected embedded script %s.star" , meta .Filename )
118- require .NotEmpty (t , script )
119- _ , err := pool .Exec (ctx , `
120- INSERT INTO ` + betaSchema + `.saga_definition (
121- name, version, script, status, is_system,
122- display_name, description, created_at, updated_at, activated_at
123- ) VALUES ($1, 1, $2, 'ACTIVE', true, $3, $4, now(), now(), now())` ,
124- meta .Name , script , meta .DisplayName , meta .Description )
125- require .NoError (t , err )
126- }
127-
128- // Step 7: Migrate beta to platform refs
129- migrationResults , err := overrideSvc .MigrateToPlatformRef (ctx , betaID , false )
130- require .NoError (t , err )
131-
132- migratedCount := 0
133- for _ , r := range migrationResults {
134- if r .Action == "migrated" {
135- migratedCount ++
136- }
137- }
138- assert .Equal (t , 8 , migratedCount , "all 8 sagas should be migrated" )
139-
140- // Verify beta's sagas now use platform_ref
141- betaCtx := tenant .WithTenant (ctx , betaID )
142- betaWithdrawal , err := registry .GetActive (betaCtx , "current_account_withdrawal" )
143- require .NoError (t , err )
144- assert .True (t , betaWithdrawal .IsSystem )
145- assert .NotNil (t , betaWithdrawal .PlatformRef , "should now have platform_ref" )
146- assert .True (t , betaWithdrawal .UsedPlatformFallback , "should use platform fallback after migration" )
103+ assert .False (t , depositDef .UsedPlatformFallback ,
104+ "deposit should use copied script, not platform fallback" )
105+ assert .NotEmpty (t , depositDef .ResolvedScript , "deposit should have script content" )
147106}
148107
149108// TestE2E_SeededSagasAreActive verifies that seeded sagas are immediately ACTIVE.
@@ -165,18 +124,23 @@ func TestE2E_SeededSagasAreActive(t *testing.T) {
165124 err = seeder .SeedTenant (ctx , tenantID )
166125 require .NoError (t , err )
167126
168- // Verify all seeded sagas are ACTIVE
127+ // Verify all seeded sagas are ACTIVE with scripts copied directly
169128 rows , err := pool .Query (ctx ,
170- "SELECT name, status FROM " + schemaName + ".saga_definition WHERE is_system = true ORDER BY name" )
129+ "SELECT name, status, script FROM " + schemaName + ".saga_definition WHERE is_system = true ORDER BY name" )
171130 require .NoError (t , err )
172131 defer rows .Close ()
173132
174133 var count int
175134 for rows .Next () {
176135 var name , status string
177- err := rows .Scan (& name , & status )
136+ var script * string
137+ err := rows .Scan (& name , & status , & script )
178138 require .NoError (t , err )
179139 assert .Equal (t , "ACTIVE" , status , "seeded saga %s should be ACTIVE" , name )
140+ assert .NotNil (t , script , "seeded saga %s should have script content (not NULL)" , name )
141+ if script != nil {
142+ assert .NotEmpty (t , * script , "seeded saga %s should have non-empty script" , name )
143+ }
180144 count ++
181145 }
182146 require .NoError (t , rows .Err ())
0 commit comments