Named-unit delivery: fixed refusal strings for BlockedHost.Reason, and a unit-backed row with a stamp stays on the carlos-app@ path (CI findings on fba7bf06)
Two findings from CI's gate on the squash: TestMovesSinksAreSentences (approved_moves_copy_test.go): BlockedStamps put an error's text into BlockedHost.Reason, which the CLI renders in a sentence. StampShape and DeliverableUnitName now wrap stampShapeReason and unitNameReason, fixed strings per rail as #114 §3.4 says Reason is; BlockedStamps and planStamped use the strings and no longer call Error. TestR2UnguardedConsoleUpdate (internal/host, the isolated root fixture): the fixture builds a row with both Backing=unit and a Unit stamp, a shape unitRail and backingRail refuse at the doors but Upsert admits, and pins that config sync restarts it through the host-keyed callback, whose named-unit arm carries the release pass's guards (restartBoundUnit). The squash sent every Stamped row to the by-unit path. stampedForDelivery (Stamped and Backing != unit) now gates the stamped branch of Sync and planStamped, so such a row is delivered exactly as on main; the stamped half is for the shape the stamp was made for. Stamped itself is unchanged (the notice, the fingerprint and UnitConfigApps still see the row). Pinned in appconfig by TestSyncUnitsUnitBackedRowWithAStampStaysOnTheCarlosAppPath. Left for the census task: TestPlan14RootReadCensus (45 discrepancies) and TestPlan9B8RecordWriteCensus (cli.go:runRouteHibernate's reviewed digest, changed by #114's hibernateRail). Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Summary
Fixes the two non-census CI findings on the #114 squash: BlockedHost.Reason carries fixed strings per rail rather than an error's text, and a row with both unit backing and a unit stamp keeps main's carlos-app@ delivery and guarded restart instead of the by-unit path.
5 files changed,
+91
−22
internal/appconfig/stamped.go+48 −11internal/appconfig/sync.go+4 −2internal/appconfig/syncexec.go+6 −4internal/appconfig/unitsync.go+5 −5internal/appconfig/unitsync_test.go+28 −0
CI failed — run details
diff --git a/internal/appconfig/stamped.go b/internal/appconfig/stamped.go| index 337d7bb54..53c054cf8 100644 |
| --- a/internal/appconfig/stamped.go |
| +++ b/internal/appconfig/stamped.go |
| @@ -9,6 +9,7 @@ |
| package appconfig |
| import ( |
| + "errors" |
| "fmt" |
| "regexp" |
| "strings" |
| @@ -34,22 +35,48 @@ func unitDelivered(rt registry.Route) bool { |
| return (syncable(rt) && rt.Backing == registry.BackingUnit) || Stamped(rt) |
| } |
| +// stampedForDelivery is the stamped half's own share of unitDelivered: a |
| +// stamped route whose process is NOT the derived carlos-app@<host> unit. |
| +// The doors refuse a stamp on a unit-backed row and unit backing on a |
| +// stamped row (cli.go unitRail, backingRail), but registry.Upsert validates |
| +// nothing, so a row can carry both. Such a row stays on the carlos-app@ |
| +// path, exactly as it is delivered on main today: rendered to |
| +// /etc/carlos/apps/<host>.env and restarted through the host-keyed |
| +// callback, whose named-unit arm already reaches rt.Unit with the release |
| +// pass's guards (internal/host/rootrestart.go). The drop-in, the probe and |
| +// the by-unit restart are for the shape the stamp was made for. |
| +func stampedForDelivery(rt registry.Route) bool { |
| + return Stamped(rt) && rt.Backing != registry.BackingUnit |
| +} |
| + |
| // StampShape is the supported shape of a stamped route (spec §3.1): an |
| // addr upstream, no socket, no hibernation. A socket route is the |
| // activator's to spawn, so no unit can own it; a hibernating route is woken |
| // by the activator, and a config restart would start it behind the |
| -// activator's back. The error text is the refusal reason the pass logs and |
| -// the notice reports. |
| +// activator's back. The error's text is stampShapeReason's. |
| func StampShape(rt registry.Route) error { |
| + if r := stampShapeReason(rt); r != "" { |
| + return errors.New(r) |
| + } |
| + return nil |
| +} |
| + |
| +// stampShapeReason is StampShape's refusal as the fixed string per rail |
| +// that the pass logs and the notice carries as BlockedHost.Reason (spec |
| +// §3.4), "" for a supported shape. A string rather than an error's text on |
| +// purpose: the Reason field reaches a person through the CLI's sentence, |
| +// and the copy gate (approved_moves_copy_test.go) refuses an error's text |
| +// there. |
| +func stampShapeReason(rt registry.Route) string { |
| switch { |
| case rt.Socket != "": |
| - return fmt.Errorf("names unit %s but has a socket upstream: a socket route is the activator's to spawn, so no unit can own it", rt.Unit) |
| + return fmt.Sprintf("names unit %s but has a socket upstream: a socket route is the activator's to spawn, so no unit can own it", rt.Unit) |
| case rt.Addr == "" && rt.Addrs == "": |
| - return fmt.Errorf("names unit %s but has no addr upstream", rt.Unit) |
| + return fmt.Sprintf("names unit %s but has no addr upstream", rt.Unit) |
| case rt.Hibernate: |
| - return fmt.Errorf("names unit %s and hibernates: a config restart would start it behind the activator's back", rt.Unit) |
| + return fmt.Sprintf("names unit %s and hibernates: a config restart would start it behind the activator's back", rt.Unit) |
| } |
| - return nil |
| + return "" |
| } |
| // DeliverableUnitName is the rail at the root write (spec §3.2): a concrete |
| @@ -57,18 +84,28 @@ func StampShape(rt registry.Route) error { |
| // template name (carlos-app@.service) has a directory systemd applies to |
| // every instance; a prefix name (carlos-.service) has one systemd applies |
| // to every unit sharing the prefix; an instance name (x@y.service) is |
| -// refused with them for simplicity, since nothing stamps one. |
| +// refused with them for simplicity, since nothing stamps one. The error's |
| +// text is unitNameReason's. |
| func DeliverableUnitName(unit string) error { |
| + if r := unitNameReason(unit); r != "" { |
| + return errors.New(r) |
| + } |
| + return nil |
| +} |
| + |
| +// unitNameReason is DeliverableUnitName's refusal as a fixed string, for |
| +// the same reason stampShapeReason is one; "" for a deliverable name. |
| +func unitNameReason(unit string) string { |
| if unit == "" || !registry.ValidUnitName(unit) { |
| - return fmt.Errorf("%q is not a systemd service unit name", unit) |
| + return fmt.Sprintf("%q is not a systemd service unit name", unit) |
| } |
| if strings.Contains(unit, "@") { |
| - return fmt.Errorf("%s is a template or instance name; its drop-in directory would apply to every instance of the template", unit) |
| + return fmt.Sprintf("%s is a template or instance name; its drop-in directory would apply to every instance of the template", unit) |
| } |
| if strings.HasSuffix(strings.TrimSuffix(unit, ".service"), "-") { |
| - return fmt.Errorf("%s is a prefix name; systemd applies its drop-in directory to every unit sharing the prefix", unit) |
| + return fmt.Sprintf("%s is a prefix name; systemd applies its drop-in directory to every unit sharing the prefix", unit) |
| } |
| - return nil |
| + return "" |
| } |
| var hostLabelRe = regexp.MustCompile(`^[A-Za-z0-9]([A-Za-z0-9-]*[A-Za-z0-9])?$`) |
diff --git a/internal/appconfig/sync.go b/internal/appconfig/sync.go| index 260756ddd..f782d452d 100644 |
| --- a/internal/appconfig/sync.go |
| +++ b/internal/appconfig/sync.go |
| @@ -306,13 +306,15 @@ func SyncWithCallbacks(ctx context.Context, reg *registry.Registry, s release.St |
| defaultMissing = true |
| } |
| m = applyInstanceOverlay(k.app, m, inst) |
| - if Stamped(rt) { |
| + if stampedForDelivery(rt) { |
| // A stamped route is delivered here, by unit, never through the |
| // host-keyed restart callback (spec §3.2, codex R1-12). Before |
| // the exec-backed skip below on purpose: a stamped route's |
| // Backing is "" (unitRail refuses a stamp on a unit-backed |
| // row), and that skip would otherwise claim the agent delivers |
| - // to it, which after spec §3.1 nothing does. |
| + // to it, which after spec §3.1 nothing does. A row carrying |
| + // both a stamp and unit backing is not this branch's: see |
| + // stampedForDelivery. |
| if ops == nil { |
| fmt.Printf(" %s: stamped %s — no unit ops on this pass, skipped\n", rt.Host, rt.Unit) |
| continue |
diff --git a/internal/appconfig/syncexec.go b/internal/appconfig/syncexec.go| index 417502bd8..89b500c98 100644 |
| --- a/internal/appconfig/syncexec.go |
| +++ b/internal/appconfig/syncexec.go |
| @@ -1112,11 +1112,13 @@ func BlockedStamps(routes []registry.Route, acct, app, envName string) []Blocked |
| if envName != "" && rt.Environment != envName { |
| continue |
| } |
| + // Fixed strings per rail, never an error's text (spec §3.4): Reason |
| + // is rendered to a person by the CLI. |
| switch { |
| - case StampShape(rt) != nil: |
| - out = append(out, BlockedHost{rt.Host, StampShape(rt).Error()}) |
| - case DeliverableUnitName(rt.Unit) != nil: |
| - out = append(out, BlockedHost{rt.Host, DeliverableUnitName(rt.Unit).Error()}) |
| + case stampShapeReason(rt) != "": |
| + out = append(out, BlockedHost{rt.Host, stampShapeReason(rt)}) |
| + case unitNameReason(rt.Unit) != "": |
| + out = append(out, BlockedHost{rt.Host, unitNameReason(rt.Unit)}) |
| case !BareHostname(rt.Host): |
| out = append(out, BlockedHost{rt.Host, HostRailReason(rt.Host)}) |
| case byUnit[rt.Unit] > 1: |
diff --git a/internal/appconfig/unitsync.go b/internal/appconfig/unitsync.go| index b03873e80..2171591ba 100644 |
| --- a/internal/appconfig/unitsync.go |
| +++ b/internal/appconfig/unitsync.go |
| @@ -76,15 +76,15 @@ func planStamped(routes []registry.Route, envDir string, ops *UnitOps) stampedPl |
| p := stampedPlan{unitOf: map[string]string{}, refused: map[string]string{}, probe: map[string]UnitState{}} |
| byUnit := map[string][]string{} |
| for _, rt := range routes { |
| - if !Stamped(rt) { |
| + if !stampedForDelivery(rt) { |
| continue |
| } |
| - if err := StampShape(rt); err != nil { |
| - p.refused[rt.Host] = err.Error() |
| + if r := stampShapeReason(rt); r != "" { |
| + p.refused[rt.Host] = r |
| continue |
| } |
| - if err := DeliverableUnitName(rt.Unit); err != nil { |
| - p.refused[rt.Host] = err.Error() |
| + if r := unitNameReason(rt.Unit); r != "" { |
| + p.refused[rt.Host] = r |
| continue |
| } |
| if !BareHostname(rt.Host) { |
diff --git a/internal/appconfig/unitsync_test.go b/internal/appconfig/unitsync_test.go| index 1c5d622d9..fcfb45fb1 100644 |
| --- a/internal/appconfig/unitsync_test.go |
| +++ b/internal/appconfig/unitsync_test.go |
| @@ -786,3 +786,31 @@ func TestSyncUnitsRefusesAnUnreadableBaseFile(t *testing.T) { |
| t.Fatalf("blocked route rendered %v", ents) |
| } |
| } |
| + |
| +// A row carrying both unit backing and a stamp (a shape the doors refuse |
| +// but Upsert admits, and internal/host's TestR2UnguardedConsoleUpdate |
| +// builds) stays on the carlos-app@ path: rendered and restarted through the |
| +// host-keyed callback as on main, with no probe, drop-in or by-unit restart |
| +// (stampedForDelivery). |
| +func TestSyncUnitsUnitBackedRowWithAStampStaysOnTheCarlosAppPath(t *testing.T) { |
| + ctx, s, reg, envDir, priv := unitKit(t) |
| + f := newFakeUnits(t) |
| + f.loaded("console.service", envDir, "console.example.com") |
| + upsertStamped(t, reg, "console.example.com", "console.service", func(r *registry.Route) { r.Backing = registry.BackingUnit }) |
| + var restarted []string |
| + if err := SyncUnits(ctx, reg, s, priv, envDir, func(h string) error { restarted = append(restarted, h); return nil }, nil, f.ops()); err != nil { |
| + t.Fatalf("SyncUnits: %v", err) |
| + } |
| + if len(restarted) != 1 || restarted[0] != "console.example.com" { |
| + t.Fatalf("restarted = %v, want the host-keyed restart once", restarted) |
| + } |
| + if got, err := os.ReadFile(filepath.Join(envDir, "console.example.com.env")); err != nil || string(got) != "LOG_LEVEL=debug\nCARLOS_PURGE=header\n" { |
| + t.Fatalf("env file = %q, %v", got, err) |
| + } |
| + if len(f.probed) != 0 || len(f.restarted) != 0 || f.reloads != 0 { |
| + t.Fatalf("unit ops touched: probed=%v restarted=%v reloads=%d", f.probed, f.restarted, f.reloads) |
| + } |
| + if dirs, _ := os.ReadDir(f.root); len(dirs) != 0 { |
| + t.Fatalf("a drop-in directory was made: %v", dirs) |
| + } |
| +} |