carlos / platform Public

Named-unit delivery: the base layer and two rails from the console config design §4.1 (#453)

The drop-in a stamped unit reads its config through now lists two files
after the reset, the box's /etc/carlos/units/<unit>.base.env (root's,
written at provisioning, optional) and then /etc/carlos/apps/<host>.env,
and the post-reload verification and the drift check require exactly
those two paths in that order and nothing else (envFilesMatch). Two
rails, both refused loudly every pass through the root side's existing
blocked reporting, nothing written:

- the unmanaged-file guard: before a unit's first drop-in (no
  marker-bearing zz-carlos-env.conf yet), the batched probe's
  EnvironmentFiles list is the operator's, and any path in it that is not
  one of the two above blocks delivery for the route with the paths named
  (planStamped);
- the overlap rail: before a stamped unit's env file is written, the base
  file's variable names (names only, never a value) are compared with the
  rendered bundle's, and a name in both blocks the route with the names
  (prepareStamped). A base file that cannot be read blocks the route too.

UnitOps gains BaseEnvDir (DefaultUnitBaseDir in production, wired in
productionUnitOps). Tests run through the real SyncUnits with the faked
systemctl seam: the guard (blocked before any write, every pass, names the
path, admits a list made only of the two managed paths, converges once the
operator moves the values), the base layer (base line before the bundle,
a unit with no base file still delivered and restarted, the reversed order
refused after reload), the overlap rail (blocked every pass with the name
and no value, unblocked by removing the name from either layer) and an
unreadable base file; TestSyncUnitsVerificationMismatchBlocks becomes a
managed-unit scenario since a first delivery with a foreign path is now
the guard's refusal. The #114 spec gains §12 recording the three changes;
docs/site/cli.md's carlos route paragraph and AGENTS.md's #110 bullet say
two files, not one.

Not in this branch, per the brief: rollback and .prev files, the per-unit
lock, ack schema changes, the console sealing key, door and CLI changes.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

Summary

Adds the console config design's §4.1 to named-unit delivery: the drop-in lists the unit's base file before the bundle, the post-reload and drift checks want exactly those two paths in order, a unit loading any other environment file is refused before its first drop-in, and a variable name in both the base file and the bundle blocks the route.
claude agent, operated by paul@keymail.dev dbb1920363b0f9ca7709de5c90edf0da4ce79fb0 parent fba7bf0
12 files changed, +543 −47
  • AGENTS.md +6 −2
  • docs/site/cli.md +6 −2
  • docs/superpowers/specs/2026-09-07-named-unit-config-delivery-design.md +69 −0
  • internal/appconfig/baseenv.go +94 −0
  • internal/appconfig/baseenv_test.go +58 −0
  • internal/appconfig/dropin.go +9 −4
  • internal/appconfig/dropin_test.go +6 −5
  • internal/appconfig/sync.go +1 −1
  • internal/appconfig/unitsync.go +64 −17
  • internal/appconfig/unitsync_test.go +219 −16
  • internal/host/unitops.go +1 −0
  • internal/host/unitops_test.go +10 −0
diff --git a/AGENTS.md b/AGENTS.md
index d1d55de89..e9e56f148 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -550,8 +550,12 @@ unchanged.
A stamped route also receives its config from the root pass (spec
`docs/superpowers/specs/2026-09-07-named-unit-config-delivery-design.md`):
the drop-in it writes RESETS the unit's `EnvironmentFile=` list to the
- rendered bundle, so a hand-built unit's own `EnvironmentFile=` lines stop
- applying once it is stamped; `Environment=` lines are untouched.
+ box's `/etc/carlos/units/<unit>.base.env` (root's, written at
+ provisioning, optional) and then the rendered bundle (that spec's §12,
+ from the console config design §4.1). A unit loading any other
+ environment file is refused before its first drop-in, and a name in both
+ the base file and the bundle blocks the route; `Environment=` lines are
+ untouched.
- **`carlos restart -app X`** (#113, merged 916cd6b, live after the same
roll): member-facing process cycle with no version or config change —
console door touches `apps/<acct>/<app>/restart-gen.json` + bumps the
diff --git a/docs/site/cli.md b/docs/site/cli.md
index b0f503e54..52b4c2c86 100644
--- a/docs/site/cli.md
+++ b/docs/site/cli.md
@@ -2159,8 +2159,12 @@ this route's process — so the command will not let you write both.
Naming a unit also hands its config to the root pass: on every config
write the pass renders the route's bundle to `/etc/carlos/apps/<host>.env`,
-keeps a drop-in under `/etc/systemd/system/<unit>.d/` that makes that file
-the unit's only `EnvironmentFile=`, reloads systemd and restarts the unit.
+keeps a drop-in under `/etc/systemd/system/<unit>.d/` that makes the box's
+`/etc/carlos/units/<unit>.base.env` (if there is one) and that file the
+unit's only `EnvironmentFile=` sources, reloads systemd and restarts the
+unit. A unit that loads any other environment file, or a variable named in
+both the base file and the route's config, is refused and the reason is
+logged on the box until one of them is changed.
A stamp needs an addr upstream and no hibernation; `--unit` refuses a
socket or hibernating row, `--hibernate` refuses a stamped one, and
`--unit -` always clears.
diff --git a/docs/superpowers/specs/2026-09-07-named-unit-config-delivery-design.md b/docs/superpowers/specs/2026-09-07-named-unit-config-delivery-design.md
index fa5f40b62..b4fa82429 100644
--- a/docs/superpowers/specs/2026-09-07-named-unit-config-delivery-design.md
+++ b/docs/superpowers/specs/2026-09-07-named-unit-config-delivery-design.md
@@ -802,3 +802,72 @@ resolved). Disposition of the new findings:
| R3-4 | P2 | yes: drift is checked every pass from the batched probe for unmarked units, reported and never fought | §3.2 step 7 |
| R3-5 | P2 | yes: the doors validate the resulting row; clearing a stamp always allowed; `--hibernate` refused on a stamped row | §3.1, §6 |
| R3-6 | P3 | yes: one batched `systemctl show` per pass, the `adviseBackingMismatches` shape | §3.2 rail |
+
+## 12. Amendment: the base layer and two rails (2026-10-28)
+
+Applied when this spec was brought onto `main` (branch
+`named-unit-delivery-114`), from the console config design's §4.1
+(`docs/superpowers/specs/2026-10-28-console-config-design.md`, approved by
+Paul 2026-10-28), whose §3 says why: a console reads its bucket, its keys
+and its database path from environment files of its own, and §3.2's reset
+alone would start it without them. Three changes, nothing else of that
+design; its rollback, per-unit lock, ack changes, sealing key and door
+work are later plans.
+
+1. **The drop-in lists two files, the base file first.** §3.2's drop-in
+ becomes
+
+ ```
+ [Service]
+ EnvironmentFile=
+ EnvironmentFile=-/etc/carlos/units/<unit>.base.env
+ EnvironmentFile=-/etc/carlos/apps/<host>.env
+ ```
+
+ The base file holds what the process needs before it can serve or read
+ the bucket. Root writes it at provisioning; carlos never writes it, and
+ this pass reads it only for its variable names (change 3). The `-`
+ keeps it optional, so a stamped unit without one is unchanged. The
+ reset stays, for §3.2's reason. §3.2 step 4 (verification after
+ reload) and step 7 (drift) change from "exactly one file" to "exactly
+ these two paths, in this order, and nothing else"; a list holding only
+ one of them, both reversed, or a third path anywhere is a mismatch
+ (`envFilesMatch`, `unitsync.go`).
+
+2. **Never reset a file away silently (the unmanaged-file guard).** Before
+ the pass writes a drop-in for a unit for the first time, that is while
+ the unit has no marker-bearing `zz-carlos-env.conf`, the batched probe's
+ `EnvironmentFiles` answer is the operator's list. If any path in it is
+ not one of the two above, delivery for that route is refused in
+ `planStamped`, every pass, with the paths named, and nothing is
+ written, reloaded or restarted. The operator moves those values into
+ the base file or the bundle and removes the unit's own lines; the route
+ converges on the next pass. A list made only of the two managed paths
+ (a hand drop-in from the SSM era naming carlos's file, or no file at
+ all) is admitted. Once the drop-in exists the list is carlos's and step
+ 7 watches it.
+
+3. **One owner per variable (the overlap rail, Paul's ruling in the
+ console config design §12).** Before a stamped unit's env file is
+ written, `prepareStamped` reads the base file's names, never a value,
+ and compares them with the rendered bundle's. Any name in both blocks
+ delivery for that route, logged every pass with the names and nothing
+ else, and nothing is written. A base file that cannot be read blocks
+ the route too, since its names cannot be ruled out. Removing the name
+ from either layer unblocks the route on the next pass.
+
+Tests (console config design §11, first three bullets) run through the
+real `SyncUnits` with the faked `UnitOps`:
+`TestSyncUnitsRefusesToResetAnUnmanagedEnvFileAway`,
+`TestSyncUnitsGuardAdmitsAUnitLoadingOnlyManagedPaths`,
+`TestSyncUnitsDropInListsBaseBeforeBundle`,
+`TestSyncUnitsRefusesANameInBothLayers`,
+`TestSyncUnitsRefusesAnUnreadableBaseFile`, plus `TestEnvFilesMatch` for
+the full mismatch matrix.
+
+Consequence for §4 and §7: on today's fleet no stamped unit is known to
+carry an `EnvironmentFile=` line of its own; where one does, the first
+pass after the roll now refuses and names it instead of resetting it
+away, so §7 step 2's check before the roll is no longer load-bearing. The
+console config design's §10 says the console's own base file is written
+before this ships there.
diff --git a/internal/appconfig/baseenv.go b/internal/appconfig/baseenv.go
new file mode 100644
index 000000000..19aae2e4a
--- /dev/null
+++ b/internal/appconfig/baseenv.go
@@ -0,0 +1,94 @@
+// The base layer of a stamped unit's environment (console config design,
+// docs/superpowers/specs/2026-10-28-console-config-design.md §4.1): a file
+// root writes at provisioning and carlos never writes, loaded by the unit
+// before the rendered bundle. It holds what a process needs before it can
+// serve or read the bucket. Two rails keep the two layers apart: the pass
+// never resets a file away silently (unmanagedEnvFiles), and no variable
+// name may be stated by both layers (overlappingNames). Names only, here
+// and in every log line: a value in the base file is never read for
+// anything but its name.
+package appconfig
+
+import (
+ "os"
+ "path/filepath"
+ "sort"
+ "strings"
+)
+
+// DefaultUnitBaseDir is where a stamped unit's base file lives in
+// production: /etc/carlos/units/<unit>.base.env.
+const DefaultUnitBaseDir = "/etc/carlos/units"
+
+// baseEnvPath is the base file the drop-in lists for unit.
+func baseEnvPath(baseDir, unit string) string {
+ return filepath.Join(baseDir, unit+".base.env")
+}
+
+// unmanagedEnvFiles is the unmanaged-file guard (§4.1): the paths in got
+// that are neither the base file nor the bundle, in got's order. A unit
+// loading any such file before carlos writes its first drop-in would have
+// that file reset away by the drop-in's empty assignment; the operator
+// moves those values into the base file or the bundle first, so the pass
+// refuses and names them.
+func unmanagedEnvFiles(got []string, base, bundle string) []string {
+ var out []string
+ for _, p := range got {
+ if p != base && p != bundle {
+ out = append(out, p)
+ }
+ }
+ return out
+}
+
+// envFileNames reads the variable NAMES of an EnvironmentFile-format file
+// and nothing else: KEY=value per line, blank lines and lines starting
+// with # or ; skipped, as systemd reads them. A missing file has no names.
+// Any other read error is returned, because a base file the pass cannot
+// read is a base file whose names it cannot rule out.
+func envFileNames(path string) ([]string, error) {
+ raw, err := os.ReadFile(path)
+ if err != nil {
+ if os.IsNotExist(err) {
+ return nil, nil
+ }
+ return nil, err
+ }
+ var names []string
+ for _, line := range strings.Split(string(raw), "\n") {
+ s := strings.TrimSpace(line)
+ if s == "" || strings.HasPrefix(s, "#") || strings.HasPrefix(s, ";") {
+ continue
+ }
+ name, _, ok := strings.Cut(s, "=")
+ name = strings.TrimSpace(name)
+ if !ok || name == "" {
+ continue
+ }
+ names = append(names, name)
+ }
+ return names, nil
+}
+
+// overlappingNames is the overlap rail (§4.1, Paul's "one owner per
+// variable"): the names in both base and rendered, sorted. rendered is the
+// bundle as it would be written, so the comparison is against what the
+// unit would actually load, agent-owned names included.
+func overlappingNames(base []string, rendered []byte) []string {
+ inBase := make(map[string]bool, len(base))
+ for _, n := range base {
+ inBase[n] = true
+ }
+ seen := map[string]bool{}
+ var out []string
+ for _, line := range strings.Split(string(rendered), "\n") {
+ name, _, ok := strings.Cut(line, "=")
+ if !ok || !inBase[name] || seen[name] {
+ continue
+ }
+ seen[name] = true
+ out = append(out, name)
+ }
+ sort.Strings(out)
+ return out
+}
diff --git a/internal/appconfig/baseenv_test.go b/internal/appconfig/baseenv_test.go
new file mode 100644
index 000000000..7aebe22b3
--- /dev/null
+++ b/internal/appconfig/baseenv_test.go
@@ -0,0 +1,58 @@
+package appconfig
+
+import (
+ "os"
+ "path/filepath"
+ "strings"
+ "testing"
+)
+
+func TestEnvFileNamesReadsNamesOnly(t *testing.T) {
+ dir := t.TempDir()
+ path := baseEnvPath(dir, "console.service")
+ if names, err := envFileNames(path); err != nil || names != nil {
+ t.Fatalf("absent file: names=%v err=%v, want none and no error", names, err)
+ }
+ body := "# provisioned by root\n\nCONSOLE_DB=/data/console.db\n CARLOS_REGISTRY = /data/registry.db \n;comment\nnot a var\n=novalue\nEMPTY=\n"
+ if err := os.WriteFile(path, []byte(body), 0o600); err != nil {
+ t.Fatal(err)
+ }
+ names, err := envFileNames(path)
+ if err != nil || strings.Join(names, ",") != "CONSOLE_DB,CARLOS_REGISTRY,EMPTY" {
+ t.Fatalf("names = %v, %v", names, err)
+ }
+ if err := os.Mkdir(filepath.Join(dir, "dir.service.base.env"), 0o755); err != nil {
+ t.Fatal(err)
+ }
+ if _, err := envFileNames(baseEnvPath(dir, "dir.service")); err == nil {
+ t.Fatal("a base file that cannot be read must be an error, not an empty list")
+ }
+}
+
+func TestOverlappingNames(t *testing.T) {
+ rendered := []byte("LOG_LEVEL=debug\nTOKEN=x\nCARLOS_PURGE=header\n")
+ got := overlappingNames([]string{"TOKEN", "CONSOLE_DB", "LOG_LEVEL", "CARLOS_PURGE"}, rendered)
+ if strings.Join(got, ",") != "CARLOS_PURGE,LOG_LEVEL,TOKEN" {
+ t.Fatalf("overlap = %v", got)
+ }
+ if got := overlappingNames(nil, rendered); len(got) != 0 {
+ t.Fatalf("no base names, overlap = %v", got)
+ }
+ if got := overlappingNames([]string{"OTHER"}, rendered); len(got) != 0 {
+ t.Fatalf("disjoint, overlap = %v", got)
+ }
+}
+
+func TestUnmanagedEnvFiles(t *testing.T) {
+ base, bundle := "/etc/carlos/units/u.service.base.env", "/etc/carlos/apps/h.env"
+ if got := unmanagedEnvFiles([]string{base, bundle}, base, bundle); len(got) != 0 {
+ t.Fatalf("the two managed paths reported as foreign: %v", got)
+ }
+ if got := unmanagedEnvFiles(nil, base, bundle); len(got) != 0 {
+ t.Fatalf("an empty list reported as foreign: %v", got)
+ }
+ got := unmanagedEnvFiles([]string{"/etc/x.env", bundle, "/data/y.env"}, base, bundle)
+ if strings.Join(got, ",") != "/etc/x.env,/data/y.env" {
+ t.Fatalf("foreign = %v", got)
+ }
+}
diff --git a/internal/appconfig/dropin.go b/internal/appconfig/dropin.go
index 1a03a9fc3..1b5183cc2 100644
--- a/internal/appconfig/dropin.go
+++ b/internal/appconfig/dropin.go
@@ -1,6 +1,7 @@
// The drop-in a stamped route's unit reads its config through (spec §3.2):
// <root>/<unit>.d/zz-carlos-env.conf, marker-owned, carrying a reset and
-// ONE EnvironmentFile line; and beside it carlos-env.pending, the record
+// TWO EnvironmentFile lines, the base file then the rendered bundle
+// (console config design §4.1); and beside it carlos-env.pending, the record
// that the unit owes a daemon-reload and (while it is still owned) a
// restart. Everything here is a pure file operation with no systemd in it,
// so the pass's protocol (unitsync.go) is testable with a temp dir.
@@ -30,13 +31,17 @@ const (
func dropInDir(root, unit string) string { return filepath.Join(root, unit+".d") }
// renderDropIn: the reset line hands the unit's EnvironmentFile list to
-// carlos whole (spec §3.2, codex R2-8); the second line is the rendered
-// bundle, with the '-' prefix so an absent file is not a start failure.
-func renderDropIn(envDir, host string) []byte {
+// carlos whole (spec §3.2, codex R2-8); then the unit's base file (console
+// config design §4.1: root's at provisioning, never carlos's) and the
+// rendered bundle, in that order, each with the '-' prefix so an absent
+// file is not a start failure. A unit with no base file is unchanged by
+// the base line.
+func renderDropIn(envDir, baseDir, unit, host string) []byte {
return []byte(dropInMarker + "\n" +
"# Edit the route's config with `carlos env` / `carlos secrets`, not this file.\n" +
"[Service]\n" +
"EnvironmentFile=\n" +
+ "EnvironmentFile=-" + baseEnvPath(baseDir, unit) + "\n" +
"EnvironmentFile=-" + filepath.Join(envDir, host+".env") + "\n")
}
diff --git a/internal/appconfig/dropin_test.go b/internal/appconfig/dropin_test.go
index eb0f6060b..182c41579 100644
--- a/internal/appconfig/dropin_test.go
+++ b/internal/appconfig/dropin_test.go
@@ -8,11 +8,12 @@ import (
)
func TestRenderDropInHasMarkerResetAndFile(t *testing.T) {
- got := string(renderDropIn("/etc/carlos/apps", "relay.example.com"))
+ got := string(renderDropIn("/etc/carlos/apps", "/etc/carlos/units", "relay.service", "relay.example.com"))
want := dropInMarker + "\n" +
"# Edit the route's config with `carlos env` / `carlos secrets`, not this file.\n" +
"[Service]\n" +
"EnvironmentFile=\n" +
+ "EnvironmentFile=-/etc/carlos/units/relay.service.base.env\n" +
"EnvironmentFile=-/etc/carlos/apps/relay.example.com.env\n"
if got != want {
t.Fatalf("renderDropIn =\n%s\nwant\n%s", got, want)
@@ -27,7 +28,7 @@ func TestWriteReadAndMarkDropIn(t *testing.T) {
if _, exists, _, err := readDropIn(root, "relay.service"); err != nil || exists {
t.Fatalf("readDropIn before write: exists=%v err=%v", exists, err)
}
- body := renderDropIn("/etc/carlos/apps", "relay.example.com")
+ body := renderDropIn("/etc/carlos/apps", "/etc/carlos/units", "relay.service", "relay.example.com")
if err := writeDropIn(root, "relay.service", body); err != nil {
t.Fatalf("writeDropIn: %v", err)
}
@@ -100,10 +101,10 @@ func TestEnsureDropInDirRefusesSymlinkAndFile(t *testing.T) {
func TestListMarkedDropInsSkipsSymlinkedDirs(t *testing.T) {
root := t.TempDir()
elsewhere := t.TempDir()
- os.WriteFile(filepath.Join(elsewhere, DropInFile), renderDropIn("/e", "h"), 0o644)
+ os.WriteFile(filepath.Join(elsewhere, DropInFile), renderDropIn("/e", "/b", "x.service", "h"), 0o644)
os.Symlink(elsewhere, filepath.Join(root, "retired.service.d"))
os.MkdirAll(filepath.Join(root, "real.service.d"), 0o755)
- os.WriteFile(filepath.Join(root, "real.service.d", DropInFile), renderDropIn("/e", "h"), 0o644)
+ os.WriteFile(filepath.Join(root, "real.service.d", DropInFile), renderDropIn("/e", "/b", "x.service", "h"), 0o644)
units, skipped, unreadable := listMarkedDropIns(root)
if len(units) != 1 || units[0] != "real.service" {
t.Fatalf("units = %v, want [real.service]", units)
@@ -142,7 +143,7 @@ func TestListMarkedDropInsReportsAnUnreadableFile(t *testing.T) {
func TestRemoveDropIn(t *testing.T) {
root := t.TempDir()
ensureDropInDir(root, "relay.service")
- writeDropIn(root, "relay.service", renderDropIn("/e", "h"))
+ writeDropIn(root, "relay.service", renderDropIn("/e", "/b", "x.service", "h"))
if err := removeDropIn(root, "relay.service"); err != nil {
t.Fatalf("removeDropIn: %v", err)
}
diff --git a/internal/appconfig/sync.go b/internal/appconfig/sync.go
index 983a0d751..260756ddd 100644
--- a/internal/appconfig/sync.go
+++ b/internal/appconfig/sync.go
@@ -106,7 +106,7 @@ func SyncWithCallbacks(ctx context.Context, reg *registry.Registry, s release.St
// behind, for the reload/restart half after the loop.
var plan stampedPlan
if ops != nil {
- plan = planStamped(routes, ops)
+ plan = planStamped(routes, envDir, ops)
}
work := map[string]unitWork{} // by unit
type groupKey struct{ acct, app, env string }
diff --git a/internal/appconfig/unitsync.go b/internal/appconfig/unitsync.go
index 9dfbe6233..b03873e80 100644
--- a/internal/appconfig/unitsync.go
+++ b/internal/appconfig/unitsync.go
@@ -12,6 +12,7 @@ import (
"fmt"
"path/filepath"
"sort"
+ "strings"
"github.com/carlosframework/platform/internal/registry"
)
@@ -32,6 +33,11 @@ type UnitState struct {
type UnitOps struct {
// DropInRoot is /etc/systemd/system in production.
DropInRoot string
+ // BaseEnvDir is where a unit's base file lives (DefaultUnitBaseDir in
+ // production): the first of the two EnvironmentFile lines the drop-in
+ // carries (console config design §4.1). Root writes a base file at
+ // provisioning; this pass only ever reads one, for its names.
+ BaseEnvDir string
// Lock serialises config passes across processes (spec §3.2, codex
// R2-3). An error means another pass holds it: do nothing this pass.
Lock func() (unlock func(), err error)
@@ -62,9 +68,11 @@ type stampedPlan struct {
// planStamped applies the rail (spec §3.2) to every stamped route in
// routes, in this order: shape, unit name, hostname, one-route-per-unit,
// then the batched systemd probe (loaded, and the stamp is the canonical
-// name). Refusals are collected, never printed here: the route loop prints
-// them beside the route so a log reads in one place.
-func planStamped(routes []registry.Route, ops *UnitOps) stampedPlan {
+// name), then the unmanaged-file guard (console config design §4.1) for a
+// unit that has no carlos drop-in yet. Refusals are collected, never
+// printed here: the route loop prints them beside the route so a log reads
+// in one place.
+func planStamped(routes []registry.Route, envDir string, ops *UnitOps) stampedPlan {
p := stampedPlan{unitOf: map[string]string{}, refused: map[string]string{}, probe: map[string]UnitState{}}
byUnit := map[string][]string{}
for _, rt := range routes {
@@ -116,6 +124,28 @@ func planStamped(routes []registry.Route, ops *UnitOps) stampedPlan {
case st.ID != unit:
p.refused[host] = fmt.Sprintf("%s is an alias of %s; stamp the canonical unit name", unit, st.ID)
default:
+ // Never reset a file away silently (§4.1). Before the FIRST
+ // drop-in for this unit, its effective EnvironmentFile list is
+ // the operator's: every path in it must be one of the two the
+ // drop-in will list, or the reset would drop values the unit
+ // starts from. Once a marker-bearing drop-in exists the list is
+ // carlos's and the drift check (applyStamped) is the one that
+ // watches it; an unmarked file at the path is prepareStamped's
+ // refusal. A drop-in that cannot be read is refused here too:
+ // whether the list is ours is then unknown.
+ _, exists, marked, err := readDropIn(ops.DropInRoot, unit)
+ if err != nil {
+ p.refused[host] = fmt.Sprintf("read drop-in for %s: %v", unit, err)
+ continue
+ }
+ if !exists || !marked {
+ base, bundle := baseEnvPath(ops.BaseEnvDir, unit), filepath.Join(envDir, host+".env")
+ if foreign := unmanagedEnvFiles(st.EnvFiles, base, bundle); len(foreign) > 0 {
+ p.refused[host] = fmt.Sprintf("%s loads environment files carlos does not manage (%s); the first drop-in would reset them away. Move their values into %s or the route's config, remove them from the unit, and the route converges on the next pass",
+ unit, strings.Join(foreign, ", "), base)
+ continue
+ }
+ }
p.unitOf[host] = unit
p.probe[unit] = st
}
@@ -148,6 +178,20 @@ func prepareStamped(rt registry.Route, unit string, m *Manifest, defaultMissing
return w
}
path, rendered, cur, existed := hr.path, hr.rendered, hr.cur, hr.existed
+ // One owner per variable (§4.1): a name stated by both the base file
+ // and the bundle is refused, every pass, before anything is written.
+ // Names only; no value from either layer is read for this or printed.
+ base := baseEnvPath(ops.BaseEnvDir, unit)
+ baseNames, err := envFileNames(base)
+ if err != nil {
+ fmt.Printf(" %s: delivery blocked: read %s: %v; cannot rule out a name owned by both layers\n", rt.Host, base, err)
+ return w
+ }
+ if both := overlappingNames(baseNames, rendered); len(both) > 0 {
+ fmt.Printf(" %s: delivery blocked: %s and the route's config both set %s; one layer owns each variable. Remove the name from one of them and the route converges on the next pass\n",
+ rt.Host, base, strings.Join(both, ", "))
+ return w
+ }
if err := ensureDropInDir(ops.DropInRoot, unit); err != nil {
fmt.Printf(" %s: drop-in directory for %s: %v\n", rt.Host, unit, err)
return w
@@ -162,7 +206,7 @@ func prepareStamped(rt registry.Route, unit string, m *Manifest, defaultMissing
rt.Host, dropInDir(ops.DropInRoot, unit), DropInFile, errNotOurs)
return w
}
- wantDrop := renderDropIn(envDir, rt.Host)
+ wantDrop := renderDropIn(envDir, ops.BaseEnvDir, unit, rt.Host)
envChanged := !(existed && bytes.Equal(cur, rendered))
dropChanged := !(dropExists && bytes.Equal(curDrop, wantDrop))
if !envChanged && !dropChanged {
@@ -239,11 +283,14 @@ func reapDropIns(routes []registry.Route, ops *UnitOps) {
}
// envFilesMatch: the unit's effective EnvironmentFile list must be EXACTLY
-// carlos's one file (spec §3.2 step 4, codex R3-3). Presence or last
-// position is not enough: a later drop-in that resets the list and re-adds
-// a legacy file before carlos's would resurrect an unset key.
-func envFilesMatch(got []string, want string) bool {
- return len(got) == 1 && got[0] == want
+// the two paths the drop-in lists, the base file then the bundle, and
+// nothing else (spec §3.2 step 4 as amended by console config design §4.1;
+// codex R3-3). Presence or last position is not enough: a later drop-in
+// that resets the list and re-adds a legacy file before carlos's would
+// resurrect an unset key, and one that reorders the two would let the
+// bundle be overridden by the base file.
+func envFilesMatch(got []string, base, bundle string) bool {
+ return len(got) == 2 && got[0] == base && got[1] == bundle
}
// applyStamped is spec §3.2 steps 3 to 7: one reload if anything is
@@ -297,10 +344,10 @@ func applyStamped(envDir string, ops *UnitOps, plan stampedPlan, work map[string
fmt.Printf(" %s: %s is not loaded after reload (%s); restart still owed\n", w.host, unit, st.LoadState)
continue
}
- want := filepath.Join(envDir, w.host+".env")
- if !envFilesMatch(states[unit].EnvFiles, want) {
- fmt.Printf(" %s: delivery blocked: %s reads %v after reload, want exactly [%s]; a later drop-in owns the EnvironmentFile list\n",
- w.host, unit, states[unit].EnvFiles, want)
+ base, want := baseEnvPath(ops.BaseEnvDir, unit), filepath.Join(envDir, w.host+".env")
+ if !envFilesMatch(states[unit].EnvFiles, base, want) {
+ fmt.Printf(" %s: delivery blocked: %s reads %v after reload, want exactly [%s %s]; a later drop-in owns the EnvironmentFile list\n",
+ w.host, unit, states[unit].EnvFiles, base, want)
continue
}
if err := ops.Restart(unit); err != nil {
@@ -326,10 +373,10 @@ func applyStamped(envDir string, ops *UnitOps, plan stampedPlan, work map[string
if marked[unit] || !w.ok {
continue
}
- want := filepath.Join(envDir, w.host+".env")
- if st, ok := plan.probe[unit]; ok && !envFilesMatch(st.EnvFiles, want) {
- fmt.Printf(" %s: delivery blocked: %s reads %v, want exactly [%s]; a later drop-in owns the EnvironmentFile list\n",
- w.host, unit, st.EnvFiles, want)
+ base, want := baseEnvPath(ops.BaseEnvDir, unit), filepath.Join(envDir, w.host+".env")
+ if st, ok := plan.probe[unit]; ok && !envFilesMatch(st.EnvFiles, base, want) {
+ fmt.Printf(" %s: delivery blocked: %s reads %v, want exactly [%s %s]; a later drop-in owns the EnvironmentFile list\n",
+ w.host, unit, st.EnvFiles, base, want)
}
}
}
diff --git a/internal/appconfig/unitsync_test.go b/internal/appconfig/unitsync_test.go
index 4914f4e29..1c5d622d9 100644
--- a/internal/appconfig/unitsync_test.go
+++ b/internal/appconfig/unitsync_test.go
@@ -17,6 +17,7 @@ import (
// reloaded and restarted, and what the probe answers.
type fakeUnits struct {
root string
+ base string
states map[string]UnitState
probeErr error
reloadErr error
@@ -29,18 +30,28 @@ type fakeUnits struct {
func newFakeUnits(t *testing.T) *fakeUnits {
t.Helper()
- return &fakeUnits{root: t.TempDir(), states: map[string]UnitState{}, restartErr: map[string]error{}}
+ return &fakeUnits{root: t.TempDir(), base: t.TempDir(), states: map[string]UnitState{}, restartErr: map[string]error{}}
}
// loaded answers the probe for a healthy unit whose effective env list is
-// exactly carlos's file — the steady state after a successful pass.
+// exactly carlos's two files, the base file then the bundle — the steady
+// state after a successful pass (console config design §4.1).
func (f *fakeUnits) loaded(unit, envDir, host string) {
- f.states[unit] = UnitState{ID: unit, LoadState: "loaded", EnvFiles: []string{filepath.Join(envDir, host+".env")}}
+ f.states[unit] = UnitState{ID: unit, LoadState: "loaded", EnvFiles: []string{baseEnvPath(f.base, unit), filepath.Join(envDir, host+".env")}}
+}
+
+// writeBase writes the unit's base file as root would at provisioning.
+func (f *fakeUnits) writeBase(t *testing.T, unit, body string) {
+ t.Helper()
+ if err := os.WriteFile(baseEnvPath(f.base, unit), []byte(body), 0o600); err != nil {
+ t.Fatal(err)
+ }
}
func (f *fakeUnits) ops() *UnitOps {
return &UnitOps{
DropInRoot: f.root,
+ BaseEnvDir: f.base,
Lock: func() (func(), error) {
if f.lockErr != nil {
return nil, f.lockErr
@@ -125,7 +136,7 @@ func TestSyncUnitsPreparesAStampedRoute(t *testing.T) {
t.Fatalf("env file = %q, %v", got, err)
}
cur, exists, marked, _ := readDropIn(f.root, "relay.service")
- if !exists || !marked || string(cur) != string(renderDropIn(envDir, "relay.example.com")) {
+ if !exists || !marked || string(cur) != string(renderDropIn(envDir, f.base, "relay.service", "relay.example.com")) {
t.Fatalf("drop-in exists=%v marked=%v body=%q", exists, marked, cur)
}
if len(f.probed) < 1 || strings.Join(f.probed[0], ",") != "relay.service" {
@@ -383,11 +394,18 @@ func TestSyncUnitsRestartFailureKeepsMarkerAndRetries(t *testing.T) {
func TestSyncUnitsVerificationMismatchBlocks(t *testing.T) {
ctx, s, reg, envDir, priv := unitKit(t)
f := newFakeUnits(t)
- // Loaded, but the effective list has a legacy file first: a later
- // drop-in re-added it. "Ends with carlos's file" is not enough.
- f.states["relay.service"] = UnitState{ID: "relay.service", LoadState: "loaded",
- EnvFiles: []string{"/data/relay.example.com.config.env", filepath.Join(envDir, "relay.example.com.env")}}
+ f.loaded("relay.service", envDir, "relay.example.com")
upsertStamped(t, reg, "relay.example.com", "relay.service", nil)
+ syncOnce(t, ctx, reg, s, priv, envDir, f) // delivered, cleared: the unit is carlos's now
+ f.restarted = nil
+ // A config change marks the unit; after the reload the effective list
+ // has a legacy file first, which a later drop-in re-added. "Ends with
+ // carlos's files" is not enough.
+ f.states["relay.service"] = UnitState{ID: "relay.service", LoadState: "loaded",
+ EnvFiles: []string{"/data/relay.example.com.config.env", baseEnvPath(f.base, "relay.service"), filepath.Join(envDir, "relay.example.com.env")}}
+ if err := SetEnv(ctx, s, "bab", "relay", map[string]string{"LOG_LEVEL": "info"}); err != nil {
+ t.Fatal(err)
+ }
out := syncOnce(t, ctx, reg, s, priv, envDir, f)
if len(f.restarted) != 0 || !hasPending(f.root, "relay.service") {
t.Fatalf("mismatch: restarted=%v pending=%v", f.restarted, hasPending(f.root, "relay.service"))
@@ -512,7 +530,7 @@ func TestSyncUnitsReaperNeverRemovesUnmarkedOrSymlinked(t *testing.T) {
foreign := []byte("[Service]\nEnvironmentFile=/x\n")
os.WriteFile(filepath.Join(dropInDir(f.root, "foreign.service"), DropInFile), foreign, 0o644)
elsewhere := t.TempDir()
- os.WriteFile(filepath.Join(elsewhere, DropInFile), renderDropIn(envDir, "h"), 0o644)
+ os.WriteFile(filepath.Join(elsewhere, DropInFile), renderDropIn(envDir, f.base, "linked.service", "h"), 0o644)
os.Symlink(elsewhere, dropInDir(f.root, "linked.service"))
// One unrelated carlos-app@ route so the route list is not empty.
if err := reg.Upsert(registry.Route{Host: "km.example.com", Kind: "instance", App: "relay", Account: "bab",
@@ -537,7 +555,7 @@ func TestSyncUnitsEmptyRegistryReapsNoDropIns(t *testing.T) {
ctx, s, reg, envDir, priv := unitKit(t)
f := newFakeUnits(t)
ensureDropInDir(f.root, "relay.service")
- writeDropIn(f.root, "relay.service", renderDropIn(envDir, "relay.example.com"))
+ writeDropIn(f.root, "relay.service", renderDropIn(envDir, f.base, "relay.service", "relay.example.com"))
if err := SyncUnits(ctx, reg, s, priv, envDir, func(string) error { return nil }, nil, f.ops()); err != nil {
t.Fatal(err)
}
@@ -573,13 +591,198 @@ func TestSyncUnitsReStampMovesTheDropIn(t *testing.T) {
}
func TestEnvFilesMatch(t *testing.T) {
- want := "/etc/carlos/apps/h.env"
- if !envFilesMatch([]string{want}, want) {
- t.Fatal("exact single match must pass")
- }
- for _, bad := range [][]string{nil, {}, {"/x", want}, {want, "/x"}, {"/x"}} {
- if envFilesMatch(bad, want) {
+ base, want := "/etc/carlos/units/u.service.base.env", "/etc/carlos/apps/h.env"
+ if !envFilesMatch([]string{base, want}, base, want) {
+ t.Fatal("exactly the two paths in order must pass")
+ }
+ // One file alone, the two reversed, a third before, between or after,
+ // and nothing at all: none is the list the drop-in wrote (console
+ // config design §4.1: exactly these two paths, in this order).
+ for _, bad := range [][]string{nil, {}, {want}, {base}, {want, base}, {"/x", base, want}, {base, "/x", want}, {base, want, "/x"}, {"/x"}} {
+ if envFilesMatch(bad, base, want) {
t.Fatalf("%v must not match", bad)
}
}
}
+
+// TestSyncUnitsRefusesToResetAnUnmanagedEnvFileAway is the unmanaged-file
+// guard (console config design §4.1, §11): a unit loading an environment
+// file that is neither its base file nor the bundle is blocked BEFORE any
+// drop-in is written, the block names the path, and it is refused every
+// pass until the operator moves the values; nothing is written, reloaded
+// or restarted meanwhile.
+func TestSyncUnitsRefusesToResetAnUnmanagedEnvFileAway(t *testing.T) {
+ ctx, s, reg, envDir, priv := unitKit(t)
+ f := newFakeUnits(t)
+ // The console as provisioned by hand: a drop-in of its own naming two
+ // files, one of which is also carlos's bundle path.
+ f.states["console.service"] = UnitState{ID: "console.service", LoadState: "loaded",
+ EnvFiles: []string{"/etc/console/hand.env", filepath.Join(envDir, "console.example.com.env")}}
+ upsertStamped(t, reg, "console.example.com", "console.service", nil)
+ for pass := 1; pass <= 2; pass++ {
+ out := syncOnce(t, ctx, reg, s, priv, envDir, f)
+ if !strings.Contains(out, "console.example.com") || !strings.Contains(out, "blocked") || !strings.Contains(out, "/etc/console/hand.env") {
+ t.Fatalf("pass %d: expected a blocked line naming /etc/console/hand.env, got %q", pass, out)
+ }
+ if strings.Contains(out, "console.example.com.env)") || strings.Contains(out, "console.example.com.env,") {
+ t.Fatalf("pass %d: the bundle path is one of the two managed paths and must not be named as foreign: %q", pass, out)
+ }
+ if ents, _ := os.ReadDir(envDir); len(ents) != 0 {
+ t.Fatalf("pass %d: blocked route rendered %v", pass, ents)
+ }
+ if dirs, _ := os.ReadDir(f.root); len(dirs) != 0 {
+ t.Fatalf("pass %d: blocked route got a drop-in directory: %v", pass, dirs)
+ }
+ if f.reloads != 0 || len(f.restarted) != 0 {
+ t.Fatalf("pass %d: reloads=%d restarted=%v, want none", pass, f.reloads, f.restarted)
+ }
+ }
+ // The operator moved the values into the base file and removed the
+ // hand drop-in: the unit now loads exactly carlos's two paths and the
+ // route converges on the next pass.
+ f.writeBase(t, "console.service", "CONSOLE_DB=/data/console.db\n")
+ f.loaded("console.service", envDir, "console.example.com")
+ syncOnce(t, ctx, reg, s, priv, envDir, f)
+ if _, exists, marked, _ := readDropIn(f.root, "console.service"); !exists || !marked {
+ t.Fatal("drop-in not written once the unit loads only managed files")
+ }
+ if len(f.restarted) != 1 || f.restarted[0] != "console.service" || hasPending(f.root, "console.service") {
+ t.Fatalf("after the fix: restarted=%v pending=%v", f.restarted, hasPending(f.root, "console.service"))
+ }
+}
+
+// A unit whose only environment file is already carlos's bundle path (the
+// SSM-era hand drop-in #114 §1 describes) or none at all is not blocked by
+// the guard: both lists are made only of the two managed paths.
+func TestSyncUnitsGuardAdmitsAUnitLoadingOnlyManagedPaths(t *testing.T) {
+ ctx, s, reg, envDir, priv := unitKit(t)
+ f := newFakeUnits(t)
+ f.states["a.service"] = UnitState{ID: "a.service", LoadState: "loaded", EnvFiles: []string{filepath.Join(envDir, "a.example.com.env")}}
+ f.states["b.service"] = UnitState{ID: "b.service", LoadState: "loaded"}
+ upsertStamped(t, reg, "a.example.com", "a.service", nil)
+ upsertStamped(t, reg, "b.example.com", "b.service", nil)
+ syncOnce(t, ctx, reg, s, priv, envDir, f)
+ for _, unit := range []string{"a.service", "b.service"} {
+ if _, exists, marked, _ := readDropIn(f.root, unit); !exists || !marked {
+ t.Fatalf("%s: drop-in not written for a unit loading only managed paths", unit)
+ }
+ }
+}
+
+// TestSyncUnitsDropInListsBaseBeforeBundle is the base layer (console
+// config design §4.1, §11): the drop-in lists the base file before the
+// bundle; a unit with NO base file gets the same drop-in, is reloaded,
+// verified against exactly the two paths, restarted and cleared; and the
+// post-reload check refuses the two paths in the other order.
+func TestSyncUnitsDropInListsBaseBeforeBundle(t *testing.T) {
+ ctx, s, reg, envDir, priv := unitKit(t)
+ f := newFakeUnits(t)
+ f.loaded("relay.service", envDir, "relay.example.com")
+ upsertStamped(t, reg, "relay.example.com", "relay.service", nil)
+ if _, err := os.Stat(baseEnvPath(f.base, "relay.service")); !os.IsNotExist(err) {
+ t.Fatalf("precondition: no base file, stat err = %v", err)
+ }
+ syncOnce(t, ctx, reg, s, priv, envDir, f)
+ cur, exists, marked, _ := readDropIn(f.root, "relay.service")
+ if !exists || !marked {
+ t.Fatal("drop-in not written")
+ }
+ lines := strings.Split(strings.TrimSpace(string(cur)), "\n")
+ want := []string{
+ "[Service]",
+ "EnvironmentFile=",
+ "EnvironmentFile=-" + baseEnvPath(f.base, "relay.service"),
+ "EnvironmentFile=-" + filepath.Join(envDir, "relay.example.com.env"),
+ }
+ if got := lines[len(lines)-4:]; strings.Join(got, "|") != strings.Join(want, "|") {
+ t.Fatalf("drop-in tail = %q, want %q", got, want)
+ }
+ if len(f.restarted) != 1 || f.restarted[0] != "relay.service" || hasPending(f.root, "relay.service") {
+ t.Fatalf("a unit with no base file must still be restarted and cleared: restarted=%v pending=%v", f.restarted, hasPending(f.root, "relay.service"))
+ }
+ if got, err := os.ReadFile(filepath.Join(envDir, "relay.example.com.env")); err != nil || string(got) != "LOG_LEVEL=debug\nCARLOS_PURGE=header\n" {
+ t.Fatalf("env file = %q, %v", got, err)
+ }
+
+ // The two paths in the other order after a reload: blocked, not
+ // restarted, marker kept.
+ f.restarted = nil
+ f.states["relay.service"] = UnitState{ID: "relay.service", LoadState: "loaded",
+ EnvFiles: []string{filepath.Join(envDir, "relay.example.com.env"), baseEnvPath(f.base, "relay.service")}}
+ if err := SetEnv(ctx, s, "bab", "relay", map[string]string{"LOG_LEVEL": "info"}); err != nil {
+ t.Fatal(err)
+ }
+ out := syncOnce(t, ctx, reg, s, priv, envDir, f)
+ if len(f.restarted) != 0 || !hasPending(f.root, "relay.service") || !strings.Contains(out, "blocked") {
+ t.Fatalf("reversed order: restarted=%v pending=%v out=%q", f.restarted, hasPending(f.root, "relay.service"), out)
+ }
+}
+
+// TestSyncUnitsRefusesANameInBothLayers is the overlap rail (console
+// config design §4.1, §11): a name in both the base file and the rendered
+// bundle blocks delivery for the route, logged every pass with the name
+// and never a value, nothing written; removing it from either side
+// unblocks the route on the next pass.
+func TestSyncUnitsRefusesANameInBothLayers(t *testing.T) {
+ ctx, s, reg, envDir, priv := unitKit(t)
+ f := newFakeUnits(t)
+ f.loaded("relay.service", envDir, "relay.example.com")
+ upsertStamped(t, reg, "relay.example.com", "relay.service", nil)
+ f.writeBase(t, "relay.service", "# provisioned\nCARLOS_DEPLOYMENT_BUCKET=bkt-value\n LOG_LEVEL = base-value\n;x\n")
+ for pass := 1; pass <= 2; pass++ {
+ out := syncOnce(t, ctx, reg, s, priv, envDir, f)
+ if !strings.Contains(out, "relay.example.com") || !strings.Contains(out, "blocked") || !strings.Contains(out, "LOG_LEVEL") {
+ t.Fatalf("pass %d: expected a blocked line naming LOG_LEVEL, got %q", pass, out)
+ }
+ if strings.Contains(out, "base-value") || strings.Contains(out, "debug") || strings.Contains(out, "bkt-value") {
+ t.Fatalf("pass %d: a value was logged: %q", pass, out)
+ }
+ if strings.Contains(out, "CARLOS_DEPLOYMENT_BUCKET") {
+ t.Fatalf("pass %d: a name in one layer only was reported as overlapping: %q", pass, out)
+ }
+ if ents, _ := os.ReadDir(envDir); len(ents) != 0 {
+ t.Fatalf("pass %d: blocked route rendered %v", pass, ents)
+ }
+ if _, exists, _, _ := readDropIn(f.root, "relay.service"); exists || hasPending(f.root, "relay.service") {
+ t.Fatalf("pass %d: blocked route wrote a drop-in or a marker", pass)
+ }
+ if f.reloads != 0 || len(f.restarted) != 0 {
+ t.Fatalf("pass %d: reloads=%d restarted=%v", pass, f.reloads, f.restarted)
+ }
+ }
+ // Removed from the base file: delivered on the next pass.
+ f.writeBase(t, "relay.service", "CARLOS_DEPLOYMENT_BUCKET=bkt-value\n")
+ syncOnce(t, ctx, reg, s, priv, envDir, f)
+ if len(f.restarted) != 1 || hasPending(f.root, "relay.service") {
+ t.Fatalf("after removing the name from the base file: restarted=%v pending=%v", f.restarted, hasPending(f.root, "relay.service"))
+ }
+ // Back in the base file and gone from the bundle instead: delivered too.
+ f.restarted = nil
+ f.writeBase(t, "relay.service", "LOG_LEVEL=base-value\n")
+ if _, err := Unset(ctx, s, "bab", "relay", []string{"LOG_LEVEL"}); err != nil {
+ t.Fatal(err)
+ }
+ syncOnce(t, ctx, reg, s, priv, envDir, f)
+ if len(f.restarted) != 1 || hasPending(f.root, "relay.service") {
+ t.Fatalf("after removing the name from the bundle: restarted=%v pending=%v", f.restarted, hasPending(f.root, "relay.service"))
+ }
+}
+
+// A base file the pass cannot read is a base file whose names it cannot
+// rule out: blocked, not guessed.
+func TestSyncUnitsRefusesAnUnreadableBaseFile(t *testing.T) {
+ ctx, s, reg, envDir, priv := unitKit(t)
+ f := newFakeUnits(t)
+ f.loaded("relay.service", envDir, "relay.example.com")
+ upsertStamped(t, reg, "relay.example.com", "relay.service", nil)
+ if err := os.Mkdir(baseEnvPath(f.base, "relay.service"), 0o755); err != nil {
+ t.Fatal(err)
+ }
+ out := syncOnce(t, ctx, reg, s, priv, envDir, f)
+ if !strings.Contains(out, "blocked") || len(f.restarted) != 0 {
+ t.Fatalf("unreadable base file: restarted=%v out=%q", f.restarted, out)
+ }
+ if ents, _ := os.ReadDir(envDir); len(ents) != 0 {
+ t.Fatalf("blocked route rendered %v", ents)
+ }
+}
diff --git a/internal/host/unitops.go b/internal/host/unitops.go
index b8dafa26a..bb20dcfcf 100644
--- a/internal/host/unitops.go
+++ b/internal/host/unitops.go
@@ -22,6 +22,7 @@ const dropInRoot = "/etc/systemd/system"
func productionUnitOps(envDir string) *appconfig.UnitOps {
return &appconfig.UnitOps{
DropInRoot: dropInRoot,
+ BaseEnvDir: appconfig.DefaultUnitBaseDir,
Lock: func() (func(), error) { return lockConfigSync(envDir + "/.sync") },
Probe: probeUnits,
Reload: daemonReload,
diff --git a/internal/host/unitops_test.go b/internal/host/unitops_test.go
index 982dbc1f0..8c6afbb8c 100644
--- a/internal/host/unitops_test.go
+++ b/internal/host/unitops_test.go
@@ -46,3 +46,13 @@ func TestParseSystemctlShowSpaceSeparatedEnvFiles(t *testing.T) {
t.Fatalf("EnvFiles = %v", got["a.service"].EnvFiles)
}
}
+
+// The production ops carry the base layer's directory (console config
+// design §4.1): without it every drop-in would list a base file under the
+// empty path.
+func TestProductionUnitOpsNameTheBaseDir(t *testing.T) {
+ ops := productionUnitOps("/etc/carlos/apps")
+ if ops.BaseEnvDir != "/etc/carlos/units" || ops.DropInRoot != "/etc/systemd/system" {
+ t.Fatalf("BaseEnvDir=%q DropInRoot=%q", ops.BaseEnvDir, ops.DropInRoot)
+ }
+}