region HA P1a Task 4: beginExecutableChange drops its region-HA arm
P0: system apply no longer reads CARLOS_REGION_HA for claim participation. With no root participation required, beginExecutableChange returns nil and writes no marker; otherwise it takes WithParticipation (BeginUpdate), and the floor-armed branch is unchanged. The systemApplier.regionHA field is gone. Settling a legacy update-begun marker left by an older build stays. The environment read moved into systemApplier.readEnvironment (claims and gate wait), which RunSystemApply calls with os.Getenv, so the new test builds the applier's settings the way production does (ruling S4). Tests: - Added TestBeginExecutableChangeIgnoresRegionHA (required and not required, CARLOS_REGION_HA=1 through readEnvironment): red before (the legacy marker was written), green after. - Deleted (subject region-HA only: .hostexec refusal or the legacy marker): TestApplyRefusesWhileThisBoxTakesPartInAClaimOperation, TestApplyRefusesWhenItCannotTellWhetherThisBoxTakesPart, TestApplyRefusesWhenItCannotListTheControllerDirectory, TestApplyHoldsTheUpdateBegunMarkerAcrossTheInstall. - TestTheMarkerStaysWhileAJournalIsOpen: field line dropped (recover run, never reached the guard). - TestApplyDeferredForParticipationAppliesOnceItEnds: participation via a pending ledger record on the fixture's disk, not a .hostexec file. - sharedGuardFixture: field line dropped; the fixture's census already requires participation, so the armed-floor branch is reached. Tests renamed TestSystemGuardParticipationPreservesReservationThroughRecovery and TestSystemGuardParticipationKeepsFailedCompletionEvidence. - TestSystemGuardUnpublishedKeepsRegionHAParticipation became TestSystemGuardUnpublishedKeepsParticipation: a pending ledger record defers; with it gone the ledger holds the reservation and no legacy marker is written; settlement ends the reservation. - TestPlan14ParticipationFlagOffUpdate: region-on dimension removed. - TestPlan9AUnchangedTransactionRecordsNoCompletion late-participation and TestPlan14ExecutionSystemUpdateExclusion: field line dropped (fixture disk already requires participation). - TestDecidePrevWritesTheSidecarAndVerdictBeforeTheJournal (r3.6): a pending participation record defers at the update-begun step; ordering witness and every assertion unchanged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
8 files changed,
+133
−217
internal/host/guardparticipation_test.go+19 −17internal/host/participation_flagoff_test.go+27 −32internal/host/plan9_a_guard_test.go+3 −3internal/host/rootexecution_update_test.go+0 −1internal/host/systemapply.go+22 −20internal/host/systemapply_test.go+7 −4internal/host/systemparticipation.go+20 −38internal/host/systemparticipation_test.go+35 −102
diff --git a/internal/host/guardparticipation_test.go b/internal/host/guardparticipation_test.go| index 13746e1b9..2651eda80 100644 |
| --- a/internal/host/guardparticipation_test.go |
| +++ b/internal/host/guardparticipation_test.go |
| @@ -19,11 +19,10 @@ func sharedGuardFixture(t *testing.T) (*applyFixture, string) { |
| t.Fatal(err) |
| } |
| f.a.floor.Dir = dir |
| - f.a.regionHA = true |
| return f, id |
| } |
| -func TestSystemGuardRegionHAPreservesReservationThroughRecovery(t *testing.T) { |
| +func TestSystemGuardParticipationPreservesReservationThroughRecovery(t *testing.T) { |
| f, id := sharedGuardFixture(t) |
| a := f.a |
| if err := a.floor.Begin(t.Context(), id, a.dataDir); err != nil { |
| @@ -39,7 +38,7 @@ func TestSystemGuardRegionHAPreservesReservationThroughRecovery(t *testing.T) { |
| a.settleUpdateBegun(t.Context()) |
| after, err := os.ReadFile(updateBegunPath(a.optDir)) |
| if err != nil || string(after) != string(before) { |
| - t.Fatalf("region HA changed the floor reservation: %s, %v", after, err) |
| + t.Fatalf("participation changed the floor reservation: %s, %v", after, err) |
| } |
| if err := a.journal(systemJournal{Phase: systemPhaseBackingUp, Target: "new-build", PrevBuild: "old-build", StartedAt: f.now}); err != nil { |
| t.Fatal(err) |
| @@ -56,7 +55,7 @@ func TestSystemGuardRegionHAPreservesReservationThroughRecovery(t *testing.T) { |
| } |
| } |
| -func TestSystemGuardRegionHAKeepsFailedCompletionEvidence(t *testing.T) { |
| +func TestSystemGuardParticipationKeepsFailedCompletionEvidence(t *testing.T) { |
| for _, failure := range []string{"completion", "controller", "marker"} { |
| t.Run(failure, func(t *testing.T) { |
| f, id := sharedGuardFixture(t) |
| @@ -104,10 +103,12 @@ func TestSystemGuardRegionHAKeepsFailedCompletionEvidence(t *testing.T) { |
| } |
| } |
| -func TestSystemGuardUnpublishedKeepsRegionHAParticipation(t *testing.T) { |
| +// An unpublished floor is not armed, so root participation decides alone: |
| +// a pending ledger record defers, and with it gone the update begins. |
| +// Region HA P1a: no legacy update-begun marker is written either way. |
| +func TestSystemGuardUnpublishedKeepsParticipation(t *testing.T) { |
| f, _ := applyHappy(t) |
| a := f.a |
| - a.regionHA = true |
| a.floor = &hostfloor.Disk{Dir: systemGuardDir(a.optDir), Bucket: "bucket", PublicKey: f.pub, Participation: a.participation} |
| if err := os.MkdirAll(a.floor.Dir, 0755); err != nil { |
| t.Fatal(err) |
| @@ -116,29 +117,30 @@ func TestSystemGuardUnpublishedKeepsRegionHAParticipation(t *testing.T) { |
| if err := hostfloor.Durable(filepath.Join(a.floor.Dir, "policy.json"), raw, 0644); err != nil { |
| t.Fatal(err) |
| } |
| - if err := os.WriteFile(filepath.Join(hostexec(t, f), "pending.json"), []byte(`{}`), 0600); err != nil { |
| + if err := a.participation.State.Write("shop.example.json", []byte(`{"Schema":1,"Status":"pending"}`)); err != nil { |
| t.Fatal(err) |
| } |
| - if err := a.beginExecutableChange(t.Context(), "v2", f.now); !errors.Is(err, errSystemDeferred) { |
| - t.Fatalf("unpublished floor bypassed participation: %v", err) |
| + if err := a.beginExecutableChange(t.Context(), "v2", f.now); err == nil { |
| + t.Fatal("unpublished floor bypassed participation") |
| } |
| if _, err := os.Stat(updateBegunPath(a.optDir)); !os.IsNotExist(err) { |
| - t.Fatalf("refused unarmed update retained marker: %v", err) |
| + t.Fatalf("refused unarmed update wrote a marker: %v", err) |
| } |
| - if err := os.Remove(filepath.Join(a.dataDir, hostexecDir, "pending.json")); err != nil { |
| + if err := a.participation.State.Remove("shop.example.json"); err != nil { |
| t.Fatal(err) |
| } |
| if err := a.beginExecutableChange(t.Context(), "v2", f.now); err != nil { |
| t.Fatal(err) |
| } |
| - raw, err := os.ReadFile(updateBegunPath(a.optDir)) |
| - var begun updateBegun |
| - if err != nil || json.Unmarshal(raw, &begun) != nil || begun.Target != "v2" { |
| - t.Fatalf("unpublished marker = %s, %v", raw, err) |
| + if _, err := a.participation.UpdateID(); err != nil { |
| + t.Fatalf("unarmed update began no root reservation: %v", err) |
| } |
| - a.settleUpdateBegun(t.Context()) |
| if _, err := os.Stat(updateBegunPath(a.optDir)); !os.IsNotExist(err) { |
| - t.Fatalf("completed unarmed update retained marker: %v", err) |
| + t.Fatalf("unarmed update wrote a legacy marker: %v", err) |
| + } |
| + a.settleUpdateBegun(t.Context()) |
| + if _, err := a.participation.UpdateID(); !os.IsNotExist(err) { |
| + t.Fatalf("completed unarmed update retained its reservation: %v", err) |
| } |
| if err := os.MkdirAll(a.stagingDir(), 0755); err != nil { |
| t.Fatal(err) |
diff --git a/internal/host/participation_flagoff_test.go b/internal/host/participation_flagoff_test.go| index e178f7e37..64a5059d7 100644 |
| --- a/internal/host/participation_flagoff_test.go |
| +++ b/internal/host/participation_flagoff_test.go |
| @@ -9,42 +9,37 @@ import ( |
| func TestPlan14ParticipationFlagOffUpdate(t *testing.T) { |
| t.Setenv("CARLOS_HOST_CLAIM", "") |
| - for _, region := range []bool{false, true} { |
| - for _, mirror := range []string{"absent", "empty", "pending", "symlink"} { |
| - t.Run(map[bool]string{false: "region-off", true: "region-on"}[region]+"/"+mirror, func(t *testing.T) { |
| - f, _ := applyHappy(t) |
| - f.a.regionHA = region |
| - if err := f.a.participation.State.Remove("census.json"); err != nil { |
| + for _, mirror := range []string{"absent", "empty", "pending", "symlink"} { |
| + t.Run(mirror, func(t *testing.T) { |
| + f, _ := applyHappy(t) |
| + if err := f.a.participation.State.Remove("census.json"); err != nil { |
| + t.Fatal(err) |
| + } |
| + f.a.participation.VerifyLaunches = nil |
| + switch mirror { |
| + case "empty": |
| + hostexec(t, f) |
| + case "pending": |
| + if err := os.WriteFile(filepath.Join(hostexec(t, f), "pending.json"), []byte(`{}`), 0600); err != nil { |
| t.Fatal(err) |
| } |
| - f.a.participation.VerifyLaunches = nil |
| - switch mirror { |
| - case "empty": |
| - hostexec(t, f) |
| - case "pending": |
| - if err := os.WriteFile(filepath.Join(hostexec(t, f), "pending.json"), []byte(`{}`), 0600); err != nil { |
| - t.Fatal(err) |
| - } |
| - case "symlink": |
| - if err := os.Symlink(t.TempDir(), filepath.Join(f.a.dataDir, hostexecDir)); err != nil { |
| - t.Fatal(err) |
| - } |
| - } |
| - if err := f.a.Run(t.Context(), false); err != nil { |
| + case "symlink": |
| + if err := os.Symlink(t.TempDir(), filepath.Join(f.a.dataDir, hostexecDir)); err != nil { |
| t.Fatal(err) |
| } |
| - want := systemOutcomeApplied |
| - if region && (mirror == "pending" || mirror == "symlink") { |
| - want = systemOutcomeDeferred |
| - } |
| - if got := f.result(); got == nil || got.Outcome != want { |
| - t.Fatalf("result=%+v want=%s", got, want) |
| - } |
| - if _, err := f.a.participation.UpdateID(); !os.IsNotExist(err) { |
| - t.Fatalf("legacy update created root reservation: %v", err) |
| - } |
| - }) |
| - } |
| + } |
| + if err := f.a.Run(t.Context(), false); err != nil { |
| + t.Fatal(err) |
| + } |
| + // Region HA P1a: no .hostexec mirror defers an update. |
| + want := systemOutcomeApplied |
| + if got := f.result(); got == nil || got.Outcome != want { |
| + t.Fatalf("result=%+v want=%s", got, want) |
| + } |
| + if _, err := f.a.participation.UpdateID(); !os.IsNotExist(err) { |
| + t.Fatalf("legacy update created root reservation: %v", err) |
| + } |
| + }) |
| } |
| } |
diff --git a/internal/host/plan9_a_guard_test.go b/internal/host/plan9_a_guard_test.go| index d18294dc1..7b841dcbf 100644 |
| --- a/internal/host/plan9_a_guard_test.go |
| +++ b/internal/host/plan9_a_guard_test.go |
| @@ -94,9 +94,9 @@ func TestPlan9AUnchangedTransactionRecordsNoCompletion(t *testing.T) { |
| } |
| switch state { |
| case "late-participation": |
| - // The late re-check before the first destructive step runs |
| - // under CARLOS_REGION_HA (systemparticipation.go). |
| - a.regionHA = true |
| + // The late re-check before the first destructive step: |
| + // root participation is required (the fixture's census), |
| + // so the armed floor checks controllers are idle. |
| if err := os.WriteFile(record, []byte(`{"state":"pending"}`), 0600); err != nil { |
| t.Fatal(err) |
| } |
diff --git a/internal/host/rootexecution_update_test.go b/internal/host/rootexecution_update_test.go| index 049a4b16f..9a425addf 100644 |
| --- a/internal/host/rootexecution_update_test.go |
| +++ b/internal/host/rootexecution_update_test.go |
| @@ -23,7 +23,6 @@ func TestPlan14ExecutionSystemUpdateExclusion(t *testing.T) { |
| for _, pending := range []bool{false, true} { |
| t.Run(map[bool]string{true: "participating", false: "empty"}[pending], func(t *testing.T) { |
| f := newApplyFixture(t, "stable", "old") |
| - f.a.regionHA = true |
| f.a.participation = updateParticipationFixture(t) |
| if pending { |
| if err := f.a.participation.State.Write("shop.example.json", []byte("{\"Schema\":1,\"Status\":\"pending\"}")); err != nil { |
diff --git a/internal/host/systemapply.go b/internal/host/systemapply.go| index da966c116..c2dc55ac7 100644 |
| --- a/internal/host/systemapply.go |
| +++ b/internal/host/systemapply.go |
| @@ -126,13 +126,12 @@ func RunSystemApply(args []string) { |
| if invalidChannel != "" { |
| log.Printf("system apply: %s=%q is not a channel; this box follows %s", systemChannelEnv, invalidChannel, channel) |
| } |
| - claims, gateWait := systemApplyGate(os.Getenv) |
| a := &systemApplier{ |
| rootMoves: rootMovesFloorIdentity, ops: productionSysOps(), openStore: openSystemStore, channel: channel, |
| optDir: release.OptDir(), dataDir: dataDir(), etcDir: "/etc", build: version.Build, |
| - platform: runtime.GOOS + "-" + runtime.GOARCH, gateWait: gateWait, soak: systemGateSoak, |
| - regionHA: regionHAEnabled(os.Getenv), claims: claims, |
| + platform: runtime.GOOS + "-" + runtime.GOARCH, soak: systemGateSoak, |
| } |
| + a.readEnvironment(os.Getenv) |
| a.floorHook = installFloorHook // decided under the apply lock, in Run |
| runErr := a.runWithRelease(ctx, *recover) |
| if runErr != nil { |
| @@ -256,10 +255,6 @@ type systemApplier struct { |
| build string // version.Build of THIS process |
| platform string // "<goos>-<goarch>"; the caller sets it from runtime |
| gateWait, soak time.Duration |
| - // regionHA is CARLOS_REGION_HA: root writes its update-begun marker and |
| - // refuses an update while this box takes part in a claim operation |
| - // (region HA spec 1 §5.10; systemparticipation.go). |
| - regionHA bool |
| // claims is CARLOS_HOST_CLAIM, read with hostwrite.Enabled from the |
| // unit's environment (carlos-system-update.service and |
| // carlos-system-recover.service both load host.env). It changes only the |
| @@ -534,12 +529,12 @@ func (a *systemApplier) install(ctx context.Context, req systemRequest, p *relea |
| if err != nil { |
| return a.record(req, fmt.Errorf("%w: carlos.prev bootstrap: %v", errSystemRefused, err)) |
| } |
| - // Region HA (spec 1 §5.10): the marker, then the participation check, |
| - // before the first step that changes the box. Either failing defers the |
| - // update, which the agent retries; the box is left exactly as it was. |
| + // Root participation, before the first step that changes the box. A |
| + // refusal defers the update, which the agent retries; the box is left |
| + // exactly as it was. |
| if err := a.beginExecutableChange(ctx, target, req.PromotedAt); err != nil { |
| if !errors.Is(err, errSystemDeferred) { |
| - err = fmt.Errorf("%w: update-begun marker: %v", errSystemDeferred, err) |
| + err = fmt.Errorf("%w: update not begun: %v", errSystemDeferred, err) |
| } |
| return a.record(req, err) |
| } |
| @@ -958,15 +953,14 @@ func (a *systemApplier) armFloor(ctx context.Context) error { |
| // put in place, so the step that puts it there runs under activationGuard, |
| // which applies the same rule again with its inputs held still. |
| // |
| -// How the hold half relates to systemparticipation.go (region HA H14): that |
| -// guard defers any executable change, up or down, while this box takes |
| -// part in a claim operation (.hostexec), and only under CARLOS_REGION_HA, |
| -// and only on the install path. This one refuses only a downgrade, while a |
| -// moves hold_op row exists, once a floor is armed, and on every activating |
| -// path, rollback and recovery included. They overlap on a downgrade |
| -// install during a move that also runs a claim operation; there both run |
| -// (this check before staging, H14's marker just before the journal) and |
| -// either refusal stands. Neither reads or relaxes the other. |
| +// How the hold half relates to systemparticipation.go: that guard defers |
| +// any executable change, up or down, while root participation refuses the |
| +// update, and only on the install path. This one refuses only a downgrade, |
| +// while a moves hold_op row exists, once a floor is armed, and on every |
| +// activating path, rollback and recovery included. They overlap on a |
| +// downgrade install while root participation also refuses; there both run |
| +// (this check before staging, the participation check just before the |
| +// journal) and either refusal stands. Neither reads or relaxes the other. |
| func (a *systemApplier) activationAllowed(ctx context.Context, version string) error { |
| return a.activationRule(version, func() string { return a.onDiskBuild(ctx) }) |
| } |
| @@ -1564,6 +1558,14 @@ func systemApplyGate(getenv func(string) string) (bool, time.Duration) { |
| return claims, systemGateWaitFor(claims) |
| } |
| +// readEnvironment sets what the unit's environment decides about this run. |
| +// RunSystemApply calls it with os.Getenv; tests call it to build an applier |
| +// the way production does. CARLOS_REGION_HA is not read here (region HA |
| +// P1a): it no longer changes how an update begins. |
| +func (a *systemApplier) readEnvironment(getenv func(string) string) { |
| + a.claims, a.gateWait = systemApplyGate(getenv) |
| +} |
| + |
| // systemGateWaitFor is the gate's window: systemClaimsGateWait with |
| // CARLOS_HOST_CLAIM on, systemGateWait without. The install's gate and the |
| // rollback's gate both use it, so a claims-on box can roll back to a |
diff --git a/internal/host/systemapply_test.go b/internal/host/systemapply_test.go| index ee79416d8..3df36d191 100644 |
| --- a/internal/host/systemapply_test.go |
| +++ b/internal/host/systemapply_test.go |
| @@ -1840,8 +1840,9 @@ func TestBootRecoveryUsesTheArmedFloorOffline(t *testing.T) { |
| } |
| // decidePrev learns carlos.prev's version and judges it before the journal |
| -// is written. The proof of "before": region HA defers this install at the |
| -// step just ahead of the journal, and the two files are already there. |
| +// is written. The proof of "before": a pending root participation record |
| +// defers this install at the step just ahead of the journal (the ledger |
| +// refuses the update begun there), and the two files are already there. |
| func TestDecidePrevWritesTheSidecarAndVerdictBeforeTheJournal(t *testing.T) { |
| t.Parallel() |
| for _, tc := range []struct { |
| @@ -1860,8 +1861,10 @@ func TestDecidePrevWritesTheSidecarAndVerdictBeforeTheJournal(t *testing.T) { |
| } |
| // A verdict from an earlier judgement must not outlive this one. |
| writeFileDurable(filepath.Join(f.a.optDir, moves.PrevAllowedFile), []byte("v0.30.0\n"), 0o644) |
| - f.a.regionHA = true |
| - os.MkdirAll(filepath.Join(f.a.dataDir, hostexecDir, "op-9"), 0o755) |
| + f.a.participation = updateParticipationFixture(t) |
| + if err := f.a.participation.State.Write("shop.example.json", []byte("{\"Schema\":1,\"Status\":\"pending\"}")); err != nil { |
| + t.Fatal(err) |
| + } |
| if err := f.a.Run(context.Background(), false); err != nil { |
| t.Fatal(err) |
| } |
diff --git a/internal/host/systemparticipation.go b/internal/host/systemparticipation.go| index a067c70ae..9a288973a 100644 |
| --- a/internal/host/systemparticipation.go |
| +++ b/internal/host/systemparticipation.go |
| @@ -36,20 +36,26 @@ type updateBegun struct { |
| At time.Time `json:"at"` |
| } |
| -// beginExecutableChange is §5.10's root side, run under the apply lock |
| -// just before the first box-changing step: write the marker durably, then |
| -// look for participation. On a refusal the marker is removed again and the |
| -// error, wrapping errSystemDeferred, says why. The caller records it as |
| -// "deferred", never "refused": a refusal is terminal for that promote, and |
| -// this one must be retried once the operation ends (spec §5.10: the |
| -// update is refused and retried later). The agent's leg re-requests a |
| -// deferred apply on its backoff ladder, at most every five minutes. |
| +// beginExecutableChange is root's participation check, run under the apply |
| +// lock just before the first box-changing step. With no root participation |
| +// required it allows and writes nothing. Otherwise root's ledger begins the |
| +// update; a refusal there (a controller record pending, say) comes back and |
| +// the caller records it as "deferred", never "refused": a refusal is |
| +// terminal for that promote, and this one must be retried once the |
| +// operation ends. The agent's leg re-requests a deferred apply on its |
| +// backoff ladder, at most every five minutes. On a floor-armed box the |
| +// reservation beginGuard persisted is checked instead, and kept until |
| +// authenticated completion. |
| +// |
| +// Region HA P1a removed the CARLOS_REGION_HA arm: root no longer writes the |
| +// legacy update-begun marker here. clearUpdateBegun and settleUpdateBegun |
| +// still remove one left by an older build. |
| func (a *systemApplier) beginExecutableChange(ctx context.Context, target string, promotedAt time.Time) error { |
| required, err := a.participationDisk().ParticipationRequired(ctx) |
| if err != nil { |
| return err |
| } |
| - if !required && !a.regionHA { |
| + if !required { |
| return nil |
| } |
| active, err := a.activeFloor() |
| @@ -78,33 +84,9 @@ func (a *systemApplier) beginExecutableChange(ctx context.Context, target string |
| } |
| return nil |
| } |
| - if !a.regionHA { |
| - return a.participationDisk().WithParticipation(ctx, func(ctx context.Context, l rootparticipation.Ledger) error { |
| - return l.BeginUpdate(ctx, "system-"+target) |
| - }, func() error { return nil }) |
| - } |
| - writeMarker := func() error { |
| - if err := os.MkdirAll(systemGuardDir(a.optDir), 0o755); err != nil { |
| - return err |
| - } |
| - return writeJSONDurable(updateBegunPath(a.optDir), updateBegun{Target: target, PromotedAt: promotedAt, At: a.ops.now().UTC()}, 0o644) |
| - } |
| - err = a.participationDisk().BeginParticipation(ctx, "system-"+target, a.dataDir, writeMarker, func() error { |
| - if err := writeMarker(); err != nil { |
| - return err |
| - } |
| - if reason := a.participationDisk().CheckParticipation(ctx, a.dataDir, false); reason != nil { |
| - if err := a.clearLegacyUpdateBegun(); err != nil { |
| - a.ops.logf("system apply: %v", err) |
| - } |
| - return reason |
| - } |
| - return nil |
| - }) |
| - if err != nil { |
| - return fmt.Errorf("%w: %v", errSystemDeferred, err) |
| - } |
| - return nil |
| + return a.participationDisk().WithParticipation(ctx, func(ctx context.Context, l rootparticipation.Ledger) error { |
| + return l.BeginUpdate(ctx, "system-"+target) |
| + }, func() error { return nil }) |
| } |
| // clearUpdateBegun removes both markers only after positive root settlement. |
| @@ -144,8 +126,8 @@ func (a *systemApplier) clearLegacyUpdateBegun() error { |
| // settleUpdateBegun clears the marker once no update is in progress: no |
| // journal means the update finished, rolled back, was recovered, or never |
| // got past its first step. A kept journal (a rollback that could not |
| -// finish) keeps the marker with it. Run with or without CARLOS_REGION_HA, |
| -// so a marker left behind after the flag is turned off still goes. |
| +// finish) keeps the marker with it. No build since region HA P1a writes |
| +// the legacy marker; this still clears one an older build left behind. |
| // |
| // On a census box the settlement goes through settleWithoutJournal (Astra |
| // round 3): a legacy marker with no update record and no journal has |
diff --git a/internal/host/systemparticipation_test.go b/internal/host/systemparticipation_test.go| index ecdd03b7d..c12614a42 100644 |
| --- a/internal/host/systemparticipation_test.go |
| +++ b/internal/host/systemparticipation_test.go |
| @@ -4,7 +4,6 @@ import ( |
| "context" |
| "os" |
| "path/filepath" |
| - "runtime" |
| "strings" |
| "testing" |
| ) |
| @@ -41,99 +40,6 @@ func assertNotUpdated(t *testing.T, f *applyFixture, why string) { |
| } |
| } |
| -// Spec §5.10: any controller record, in any state, refuses the update. |
| -func TestApplyRefusesWhileThisBoxTakesPartInAClaimOperation(t *testing.T) { |
| - t.Parallel() |
| - for _, state := range []string{"pending", "active", "lost"} { |
| - t.Run(state, func(t *testing.T) { |
| - f, _ := applyHappy(t) |
| - f.a.regionHA = true |
| - os.WriteFile(filepath.Join(hostexec(t, f), "shop.bab.test.json"), []byte(`{"state":"`+state+`"}`), 0o600) |
| - if err := f.a.Run(context.Background(), false); err != nil { |
| - t.Fatal(err) |
| - } |
| - assertNotUpdated(t, f, "takes part in a running claim operation") |
| - }) |
| - } |
| -} |
| - |
| -// Review Focus 4: what root cannot read is a refusal, never a pass. |
| -func TestApplyRefusesWhenItCannotTellWhetherThisBoxTakesPart(t *testing.T) { |
| - t.Parallel() |
| - cases := map[string]func(t *testing.T, f *applyFixture){ |
| - "a temporary file": func(t *testing.T, f *applyFixture) { |
| - os.WriteFile(filepath.Join(hostexec(t, f), ".shop.bab.test.json.tmp"), nil, 0o600) |
| - }, |
| - "garbage": func(t *testing.T, f *applyFixture) { |
| - os.WriteFile(filepath.Join(hostexec(t, f), "shop.bab.test.json"), []byte("{half"), 0o600) |
| - }, |
| - "a symlink in place of the directory": func(t *testing.T, f *applyFixture) { |
| - elsewhere := t.TempDir() |
| - if err := os.Symlink(elsewhere, filepath.Join(f.a.dataDir, hostexecDir)); err != nil { |
| - t.Skip("no symlinks here:", err) |
| - } |
| - }, |
| - "a file in place of the directory": func(t *testing.T, f *applyFixture) { |
| - os.WriteFile(filepath.Join(f.a.dataDir, hostexecDir), nil, 0o600) |
| - }, |
| - } |
| - for name, setup := range cases { |
| - t.Run(name, func(t *testing.T) { |
| - f, _ := applyHappy(t) |
| - f.a.regionHA = true |
| - setup(t, f) |
| - if err := f.a.Run(context.Background(), false); err != nil { |
| - t.Fatal(err) |
| - } |
| - assertNotUpdated(t, f, "hostexec") |
| - }) |
| - } |
| -} |
| - |
| -func TestApplyRefusesWhenItCannotListTheControllerDirectory(t *testing.T) { |
| - if runtime.GOOS == "windows" || os.Geteuid() == 0 { |
| - t.Skip("permission bits do not stop this user") |
| - } |
| - f, _ := applyHappy(t) |
| - f.a.regionHA = true |
| - dir := hostexec(t, f) |
| - os.Chmod(dir, 0) |
| - t.Cleanup(func() { os.Chmod(dir, 0o755) }) |
| - if err := f.a.Run(context.Background(), false); err != nil { |
| - t.Fatal(err) |
| - } |
| - assertNotUpdated(t, f, "cannot be listed") |
| -} |
| - |
| -// The marker is written before the box changes and is gone once the |
| -// update is done; an empty controller directory is no participation. |
| -func TestApplyHoldsTheUpdateBegunMarkerAcrossTheInstall(t *testing.T) { |
| - f, req := applyHappy(t) |
| - f.a.regionHA = true |
| - hostexec(t, f) // present and empty |
| - seen := false |
| - orig := f.a.ops.systemctl |
| - f.a.ops.systemctl = func(args ...string) (string, error) { |
| - if args[0] == "restart" && args[len(args)-1] == systemEdgeUnit { |
| - _, err := os.Stat(updateBegunPath(f.a.optDir)) |
| - seen = err == nil |
| - } |
| - return orig(args...) |
| - } |
| - if err := f.a.Run(context.Background(), false); err != nil { |
| - t.Fatal(err) |
| - } |
| - if r := f.result(); r == nil || r.Outcome != systemOutcomeApplied || !r.matches("stable", "v2", req.PromotedAt) { |
| - t.Fatalf("result = %+v", r) |
| - } |
| - if !seen { |
| - t.Fatal("no update-begun marker while the edge restarted onto the new binary") |
| - } |
| - if _, err := os.Stat(updateBegunPath(f.a.optDir)); !os.IsNotExist(err) { |
| - t.Fatalf("marker left after the update finished: %v", err) |
| - } |
| -} |
| - |
| func TestApplyWithoutRegionHAWritesNoMarkerAndIgnoresControllerRecords(t *testing.T) { |
| f, _ := applyHappy(t) |
| os.WriteFile(filepath.Join(hostexec(t, f), "shop.bab.test.json"), []byte(`{}`), 0o600) |
| @@ -166,7 +72,6 @@ func TestAStaleUpdateBegunMarkerIsClearedByTheNextRun(t *testing.T) { |
| // the marker with it: the update is not over. |
| func TestTheMarkerStaysWhileAJournalIsOpen(t *testing.T) { |
| f := newApplyFixture(t, "stable", "v1") |
| - f.a.regionHA = true |
| os.MkdirAll(systemGuardDir(f.a.optDir), 0o755) |
| os.WriteFile(updateBegunPath(f.a.optDir), []byte(`{"target":"v2"}`), 0o644) |
| // A journal recovery cannot act on: no carlos.prev to restore. |
| @@ -185,19 +90,21 @@ func TestTheMarkerStaysWhileAJournalIsOpen(t *testing.T) { |
| // Astra plan R1-3: participation defers, it does not refuse. Once the |
| // operation ends and its record is cleared, the same promote applies. The |
| // agent's side, re-requesting a deferred apply, is |
| -// TestSystemLegReusesAVerifiedCacheOnARetry. |
| +// TestSystemLegReusesAVerifiedCacheOnARetry. The record is root's own |
| +// participation ledger's (region HA P1a: no longer a .hostexec file read |
| +// under CARLOS_REGION_HA). |
| func TestApplyDeferredForParticipationAppliesOnceItEnds(t *testing.T) { |
| f, req := applyHappy(t) |
| - f.a.regionHA = true |
| - rec := filepath.Join(hostexec(t, f), "shop.bab.test.json") |
| - os.WriteFile(rec, []byte(`{"state":"active"}`), 0o600) |
| + if err := f.a.participation.State.Write("shop.example.json", []byte(`{"Schema":1,"Status":"pending"}`)); err != nil { |
| + t.Fatal(err) |
| + } |
| if err := f.a.Run(context.Background(), false); err != nil { |
| t.Fatal(err) |
| } |
| - if r := f.result(); r == nil || r.Outcome != systemOutcomeDeferred || r.terminal() { |
| - t.Fatalf("result = %+v, want deferred, which the agent retries", r) |
| + assertNotUpdated(t, f, "root participation unavailable") |
| + if err := f.a.participation.State.Remove("shop.example.json"); err != nil { |
| + t.Fatal(err) |
| } |
| - os.Remove(rec) |
| if err := f.a.Run(context.Background(), false); err != nil { |
| t.Fatal(err) |
| } |
| @@ -205,3 +112,29 @@ func TestApplyDeferredForParticipationAppliesOnceItEnds(t *testing.T) { |
| t.Fatalf("result after the operation ended = %+v, want applied", r) |
| } |
| } |
| + |
| +// Region HA P1a Task 4: CARLOS_REGION_HA no longer reaches the update |
| +// guard. With the flag on, as root reads it from the unit's environment, an |
| +// update begins exactly as it does with it off: no deferral and no legacy |
| +// update-begun marker, whether or not root participation is required. |
| +func TestBeginExecutableChangeIgnoresRegionHA(t *testing.T) { |
| + for _, required := range []bool{false, true} { |
| + t.Run(map[bool]string{false: "not-required", true: "required"}[required], func(t *testing.T) { |
| + t.Setenv("CARLOS_REGION_HA", "1") |
| + f := newApplyFixture(t, "stable", "v1") |
| + f.a.readEnvironment(os.Getenv) |
| + if !required { |
| + if err := f.a.participation.State.Remove("census.json"); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + hostexec(t, f) // present and empty |
| + if err := f.a.beginExecutableChange(context.Background(), "v2", f.now); err != nil { |
| + t.Fatalf("deferred: %v", err) |
| + } |
| + if _, err := os.Stat(updateBegunPath(f.a.optDir)); !os.IsNotExist(err) { |
| + t.Fatalf("legacy marker written: %v", err) |
| + } |
| + }) |
| + } |
| +} |