console: scripted witnesses for replace first
The default bundle, and team's, each lose one of the five while their key is live, and the switch-off's mint for that bundle fails (the team failure aimed at team's user through the hooked provisioner). Seed numbers do not survive a code change, so seed 5063's shape is scripted. Mutation-checked: without the kept key in Enable, or in EnableEnvironment, its step fails.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 file changed,
+55
−0
internal/console/submission_sim_test.go+55 −0
diff --git a/internal/console/submission_sim_test.go b/internal/console/submission_sim_test.go| index 4a4dc3dfa..d5b54e053 100644 |
| --- a/internal/console/submission_sim_test.go |
| +++ b/internal/console/submission_sim_test.go |
| @@ -267,6 +267,15 @@ var simProvisionerFaults = []string{"EnsureUser", "MintKey", "ReapKeys", "Delete |
| type simHookedProvisioner struct { |
| *mail.MemProvisioner |
| beforeReapKeys atomic.Pointer[func(user string)] |
| + failMintFor atomic.Pointer[string] // the next MintKey for this user fails |
| +} |
| + |
| +func (p *simHookedProvisioner) MintKey(ctx context.Context, user string) (string, string, error) { |
| + if u := p.failMintFor.Load(); u != nil && *u == user { |
| + p.failMintFor.Store(nil) |
| + return "", "", errors.New("simulated AWS failure") |
| + } |
| + return p.MemProvisioner.MintKey(ctx, user) |
| } |
| func (p *simHookedProvisioner) ReapKeys(ctx context.Context, user string, keep []string) error { |
| @@ -1046,6 +1055,52 @@ func (sim *channelSim) keysChecked() { |
| if st/100 == 2 || !sim.switched() { |
| sim.t.Fatalf("a switch-off that could not read a key's state answered %d (switched %v), want a refusal with the switch still on\nsteps:\n %s", st, sim.switched(), strings.Join(sim.steps, "\n ")) |
| } |
| + // Replace first (ruled by Paul, 2026-11-14; seed 5063 before the fix): |
| + // the default bundle's five name a live key, but one of them is gone |
| + // (seed 5063 had a stale From), so the switch-off's Enable walk must |
| + // mint. The mint fails. The key the bundle names must still be there: |
| + // a walk that reaped it before minting left a still-switched app's |
| + // bundle naming a deleted key. |
| + sim.do("switch off", false, sim.switchOff) |
| + sim.switchOnLeavingTheFive() |
| + sim.do("the default bundle loses TITO_SMTP_PORT", false, func() string { |
| + if _, err := appconfig.Apply(ctx, sim.w.fx.rel, "bab", "titogo", nil, []string{"TITO_SMTP_PORT"}); err != nil { |
| + return "setup: " + err.Error() |
| + } |
| + return "ok" |
| + }) |
| + sim.prov.FailNext = map[string]error{"MintKey": errors.New("simulated AWS failure")} |
| + sim.do("switch off, the replacement key's mint failing", false, sim.switchOff) |
| + if !sim.switched() { |
| + sim.t.Fatalf("a switch-off whose mint failed turned the switch off\nsteps:\n %s", strings.Join(sim.steps, "\n ")) |
| + } |
| + // The same for an owned environment's walk: a switch-on that stops at |
| + // team's first reap write leaves team's five naming its live key; one |
| + // of them goes; the switch-off's EnableEnvironment must mint, and the |
| + // mint fails. |
| + sim.do("switch off", false, sim.switchOff) |
| + sim.ready() |
| + sim.faults.armMatching("environments/team.json", 2) |
| + sim.do("switch on, team's reap write failing", false, sim.switchOn) |
| + if !sim.switched() || sim.bundleVars("team")["TITO_SMTP_HOST"].Value == "" { |
| + sim.t.Fatalf("the switch-on did not stop with the five in team's bundle, so the steps after it prove nothing\nsteps:\n %s", strings.Join(sim.steps, "\n ")) |
| + } |
| + sim.do("team's bundle loses TITO_SMTP_PORT", false, func() string { |
| + if _, err := appconfig.ApplyEnvironment(ctx, sim.w.fx.rel, "bab", "titogo", "team", nil, []string{"TITO_SMTP_PORT"}); err != nil { |
| + return "setup: " + err.Error() |
| + } |
| + return "ok" |
| + }) |
| + teamUser := mail.EnvironmentUserName("bab", "titogo", "team") |
| + sim.hooked.failMintFor.Store(&teamUser) |
| + sim.do("switch off, team's replacement key's mint failing", false, sim.switchOff) |
| + if sim.hooked.failMintFor.Load() != nil { |
| + sim.hooked.failMintFor.Store(nil) |
| + sim.t.Fatalf("the switch-off never minted for team, so the step proved nothing\nsteps:\n %s", strings.Join(sim.steps, "\n ")) |
| + } |
| + if !sim.switched() { |
| + sim.t.Fatalf("a switch-off whose mint failed turned the switch off\nsteps:\n %s", strings.Join(sim.steps, "\n ")) |
| + } |
| sim.do("switch off", false, sim.switchOff) |
| } |