carlos / platform Public

durability 3a: one publish classifier and the file inventory (pubclass)

Plan 3a Task 1. A new leaf package, internal/layout/pubclass, holds the
per-host names internal/layout owned (FileBases, ShadowName,
FixedSuffixes, FixedShapeHost, NestedPlatformNames, IsNestedPlatformName,
SeedMarkerSuffix, FilesMarkerName) and the one classifier of what a files
publication may carry (spec §5.3): Of gives every path relative to the
inventory root one class (app, sealed, regenerated, replicated, never) by
the eight rules in order, every platform-name rule before the nested app
fallback. It is a leaf (imports only controlname, instancectl,
instancekey) because layout imports the activator, which must call it.

Around Of: FilesDirSkip (a hostfiles skip for a sync rooted at <host>/),
SealedRel/SealedPath/SealedRels (the sealed trio and their item names;
SealedPath is the only way to make a SealedRel), ErrSecretPath, and
IsRawSecretItem(ItemContext, name) for the step 7 copier. Of is by name
only, so a directory at a reserved name is refused like a file; an
unclean rel or unknown layout is never; IsRawSecretItem reads entry names
as path.Clean would and refuses every name in a zero context.

layout.Inventory lists a host's inventory root (nested: the instance
directory; flat: dataDir by the longest-host rule) with each entry's
class. flatFiles/nestedFiles build from pubclass.FileBases (PlanFor's
paths and NestedPlatformNames are byte-identical before and after, the
journal's on-disk contract); NestedPlatformNames and IsNestedPlatformName
stay as one-line wrappers; activator.SeedMarkerSuffix is pubclass's.
A guard test fails if artifactNames or FixedSuffixes gains a name that is
not listed, or any artifact, fixed shape or nested platform name is app.

Census: new Inventory (one ReadDir) and quiet NestedPlatformNames, overlay
durability-3a-escrow; record-write re-pin of layout nestedFiles (same
"instances" literal, key-site).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by claude agent, operated by paul@keymail.dev d97e9687c19664c15ec4ed23c1ce1ac0813f1159 parent b4d8db8
18 files changed, +964 −175
  • docs/superpowers/notes/census-durability-3a-escrow-claims.md +6 −0
  • docs/superpowers/notes/census-proposal-durability-3a-escrow.md +16 −0
  • internal/activator/seedplace.go +3 −1
  • internal/layout/extras.go +2 −36
  • internal/layout/extras_test.go +0 −23
  • internal/layout/hostsused.go +2 −1
  • internal/layout/inventory.go +62 −0
  • internal/layout/inventory_test.go +90 −0
  • internal/layout/pass_linux_test.go +5 −4
  • internal/layout/plan.go +27 −109
  • internal/layout/pubclass/names.go +140 −0
  • internal/layout/pubclass/pubclass.go +282 −0
  • internal/layout/pubclass/pubclass_test.go +234 −0
  • internal/layout/pubclass_guard_test.go +47 −0
  • internal/provision/durability_3a_escrow_census_test.go +36 −0
  • internal/provision/plan9_b8_census_test.go +1 −1
  • internal/provision/testdata/plan14-root-reads-chain.tsv +1 −0
  • internal/provision/testdata/plan14-root-reads-durability-3a-escrow.tsv +10 −0

Intent

Attributed to this commit: 13.7 g CO₂e (1,765,470 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on durability-3a-escrow, never backward from it. A turn that produced more than one commit books all of its tokens to the last one, and a concurrent session on this branch can add to the same figure. Some of it was priced using the shared default rate, because no model-specific factor row exists yet for at least one model involved. The Carbon view has the repo total, which is never derived from this attribution.

diff --git a/docs/superpowers/notes/census-durability-3a-escrow-claims.md b/docs/superpowers/notes/census-durability-3a-escrow-claims.md
new file mode 100644
index 000000000..beebf7f51
--- /dev/null
+++ b/docs/superpowers/notes/census-durability-3a-escrow-claims.md
@@ -0,0 +1,6 @@
+# CLAIMS for the root-read census, branch durability-3a-escrow (durability plan 3a: escrow, fence, restore).
+# Format (AGENTS.md "The census"): <file>:<unit><TAB><what changed>. Lines starting with # are ignored.
+# Appended task by task; census-propose is re-run with the whole file.
+
+internal/layout/inventory.go:Inventory durability 3a Task 1: new. One os.ReadDir of the host's inventory root, provision.InstanceDir(dataDir, host) nested or dataDir flat, after refusing a host that fails controlname.ValidHostShape and a layout that is neither flat nor nested; reads only the listing's names and types (DirEntry.IsDir), opens and follows nothing; flat ownership is the extras scan's own (hostEntries over knownHosts); each top-level name is classified by pubclass.Of, a pure function of the name. A missing directory is an empty inventory. No caller in this task; later tasks call it from the publisher.
+internal/layout/plan.go:NestedPlatformNames durability 3a Task 1: now a one-line wrapper for pubclass.NestedPlatformNames, which builds the same set (byte-identical, checked before and after) from pubclass.FileBases and the same instancectl/instancekey names, without nestedFiles or rawInstanceDir; it never read anything, and reads nothing now
diff --git a/docs/superpowers/notes/census-proposal-durability-3a-escrow.md b/docs/superpowers/notes/census-proposal-durability-3a-escrow.md
new file mode 100644
index 000000000..439d18249
--- /dev/null
+++ b/docs/superpowers/notes/census-proposal-durability-3a-escrow.md
@@ -0,0 +1,16 @@
+# Census approval: durability-3a-escrow
+
+Ruling `census-ruling-durability-3a-escrow`. The independent reviewer approves or rejects every change below, 2 with a new disposition; nothing goes to the census owner (Paul, #280, 2026-10-26).
+
+Envelopes re-pinned: `internal/activator`, `internal/layout`, `internal/layout/pubclass`.
+
+Review: a model from the other family than the author reads the branch's diff against main on the amadan.net remote (`origin` or `amadan`, whichever points at amadan.net) and gives a verdict for every unit and every re-pinned envelope above. For a unit, compare the change with its recorded disposition and basis below; for an envelope, read every changed function in the package and what it reaches. Reject if the change lets root open, run, query or follow anything it did not before from a path or input a tenant, an app or a box agent can create, write or name; if it weakens a check, refusal, validation, argument or environment the basis relies on; or if the diff cannot settle either. Otherwise approve. Record each verdict on #280 with the tip. A rejected unit goes back to the author to correct; nothing escalates to the census owner.
+
+New dispositions, which census-propose wrote and the reviewer checks against the unit's reads and the diff:
+
+- new `internal/layout/inventory.go:Inventory`: reads +file:ReadDir; written legacy, accepted-legacy, frozen
+- quiet `internal/layout/plan.go:NestedPlatformNames`: reads nothing now; retired while it reads nothing (or its row keeps no sites)
+
+Seal: `eaeb153ab7a7a849edc9c6e92f2ac5c709c6e39044a647971cf1fa5ebcb660c8` → `d1cf6e6d51e2b3451a4f3343b6d1ab66374c4dcde6c6f9bb21b52ccb1cf98350`.
+
+Overlay: `internal/provision/testdata/plan14-root-reads-durability-3a-escrow.tsv`, appended to `internal/provision/testdata/plan14-root-reads-chain.tsv`.
diff --git a/internal/activator/seedplace.go b/internal/activator/seedplace.go
index 26f2494ad..db6fa1c78 100644
--- a/internal/activator/seedplace.go
+++ b/internal/activator/seedplace.go
@@ -14,6 +14,7 @@ import (
"strings"
"github.com/carlosframework/platform/internal/instancefs"
+ "github.com/carlosframework/platform/internal/layout/pubclass"
"github.com/carlosframework/platform/internal/lease"
"github.com/carlosframework/platform/internal/registry"
"github.com/carlosframework/platform/internal/seeds"
@@ -27,7 +28,8 @@ type SeedObjects interface {
// SeedMarkerSuffix names the installation evidence beside a placed
// database: <db>.seed holds the seed's id (spec §3.4 step 3, codex R2-1).
-const SeedMarkerSuffix = ".seed"
+// The name is pubclass's, which classifies it as a platform name.
+const SeedMarkerSuffix = pubclass.SeedMarkerSuffix
// seedMarkerMax bounds the marker read: it holds a 29-byte id and a newline,
// and it sits in tenant-writable ground.
diff --git a/internal/layout/extras.go b/internal/layout/extras.go
index 329fdf930..e57ac220b 100644
--- a/internal/layout/extras.go
+++ b/internal/layout/extras.go
@@ -8,7 +8,7 @@ import (
"sort"
"strings"
- "github.com/carlosframework/platform/internal/controlname"
+ "github.com/carlosframework/platform/internal/layout/pubclass"
)
// The entries an app makes for itself (discussion #256).
@@ -90,40 +90,6 @@ func fixedNames(p *Plan) map[string]bool {
return names
}
-// fixedSuffixes are the platform's per-host file shapes under the flat
-// layout, X plus suffix (flatFiles), longest first so ".db.corrupt" is
-// read before ".db" and ".config.env" before ".env".
-var fixedSuffixes = []string{".db.corrupt", ".config.env", "-sidecar.env", ".db-wal", ".db-shm", ".db", ".env"}
-
-// fixedShapeHost reads the host X out of a name that has one of the
-// platform's fixed per-host shapes (X.db, X.env, X.config.env,
-// X-sidecar.env, X.db-wal, X.db-shm, X.db.corrupt, .activator-X.*), and
-// reports whether it has one. X must be a valid host shape with a dot in
-// it (every host the platform serves has one; registry.db and
-// litestream.env are the box's, not a host's); a name that is not
-// host-shaped under any suffix is nobody's platform file.
-func fixedShapeHost(name string) (string, bool) {
- hostLike := func(x string) bool { return strings.Contains(x, ".") && controlname.ValidHostShape(x) }
- if rest, ok := strings.CutPrefix(name, ".activator-"); ok {
- if x, ok := fixedShapeHost(rest); ok {
- return x, true
- }
- if i := strings.Index(rest, ".db-"); i > 0 && hostLike(rest[:i]) {
- return rest[:i], true
- }
- return "", false
- }
- for _, suffix := range fixedSuffixes {
- if x, ok := strings.CutSuffix(name, suffix); ok && x != "" {
- if hostLike(x) {
- return x, true
- }
- return "", false
- }
- }
- return "", false
-}
-
// knownHosts is every host an entry can belong to: the box's rows, and
// every host the directory's own platform-named files are evidence of. A
// host deleted from the box, or moved away, leaves X.env (its admin
@@ -142,7 +108,7 @@ func knownHosts(entries []os.DirEntry, rows []string) []string {
}
}
for _, e := range entries {
- if x, ok := fixedShapeHost(e.Name()); ok && !seen[x] {
+ if x, ok := pubclass.FixedShapeHost(e.Name()); ok && !seen[x] {
seen[x] = true
hosts = append(hosts, x)
}
diff --git a/internal/layout/extras_test.go b/internal/layout/extras_test.go
index 4737ca688..dbd02bc4c 100644
--- a/internal/layout/extras_test.go
+++ b/internal/layout/extras_test.go
@@ -169,26 +169,3 @@ func TestScanExtrasLeavesAnotherHostsPlatformFilesAlone(t *testing.T) {
t.Errorf("a host with a row is reported wrongly:\n%s", j)
}
}
-
-func TestFixedShapeHostReadsEveryPlatformShape(t *testing.T) {
- for name, want := range map[string]string{
- "a.example.com.env": "a.example.com",
- "a.example.com.db": "a.example.com",
- "a.example.com.db-wal": "a.example.com",
- "a.example.com.db-shm": "a.example.com",
- "a.example.com.config.env": "a.example.com",
- "a.example.com-sidecar.env": "a.example.com",
- "a.example.com.db.corrupt": "a.example.com",
- ".activator-a.example.com.db-litestream": "a.example.com",
- "a.example.com": "",
- "a.example.com-blobs": "",
- "litestream.env": "",
- "registry.db": "",
- ".env": "",
- } {
- got, ok := fixedShapeHost(name)
- if got != want || ok != (want != "") {
- t.Errorf("fixedShapeHost(%q) = %q %v, want %q", name, got, ok, want)
- }
- }
-}
diff --git a/internal/layout/hostsused.go b/internal/layout/hostsused.go
index 034635933..2df039df5 100644
--- a/internal/layout/hostsused.go
+++ b/internal/layout/hostsused.go
@@ -6,6 +6,7 @@ import (
"github.com/carlosframework/platform/internal/controlname"
"github.com/carlosframework/platform/internal/instancectl"
+ "github.com/carlosframework/platform/internal/layout/pubclass"
"github.com/carlosframework/platform/internal/provision"
)
@@ -132,7 +133,7 @@ func listingHostLike(x string) bool { return strings.Contains(x, ".") && control
func flatNameHosts(name string) (hosts []string, malformed bool) {
name = strings.TrimPrefix(name, ".activator-")
stem, fixed := name, false
- for _, suffix := range fixedSuffixes {
+ for _, suffix := range pubclass.FixedSuffixes {
if x, ok := strings.CutSuffix(name, suffix); ok && x != "" {
if strings.Contains(x, ".") && !listingHostLike(x) {
return nil, true
diff --git a/internal/layout/inventory.go b/internal/layout/inventory.go
new file mode 100644
index 000000000..53438f279
--- /dev/null
+++ b/internal/layout/inventory.go
@@ -0,0 +1,62 @@
+package layout
+
+import (
+ "errors"
+ "fmt"
+ "os"
+ "sort"
+
+ "github.com/carlosframework/platform/internal/controlname"
+ "github.com/carlosframework/platform/internal/layout/pubclass"
+ "github.com/carlosframework/platform/internal/provision"
+)
+
+// InventoryEntry is one top-level entry of a host's inventory root and the
+// classifier's verdict on it.
+type InventoryEntry struct {
+ Rel string
+ Dir bool
+ Class pubclass.Class
+}
+
+// Inventory is §5.3's file inventory: every top-level entry of the host's
+// inventory root it owns (nested: every entry of the instance directory;
+// flat: every entry of dataDir the longest-host rule gives it), sorted by
+// Rel. Flat ownership is the extras scan's own (hostEntries over
+// knownHosts), with hosts the box's rows; the host itself is always one.
+// A missing directory is an empty inventory. Nothing is opened or
+// followed: the listing's own names and types are all it reads.
+func Inventory(dataDir, host string, l pubclass.Layout, hosts []string) ([]InventoryEntry, error) {
+ if !controlname.ValidHostShape(host) {
+ return nil, fmt.Errorf("layout: %q is not a hostname", host)
+ }
+ if l != pubclass.Flat && l != pubclass.Nested {
+ return nil, fmt.Errorf("layout: %s: layout %v is not flat or nested", host, l)
+ }
+ root := dataDir
+ if l == pubclass.Nested {
+ root = provision.InstanceDir(dataDir, host)
+ }
+ entries, err := os.ReadDir(root)
+ if errors.Is(err, os.ErrNotExist) {
+ return nil, nil
+ }
+ if err != nil {
+ return nil, fmt.Errorf("layout: %s: list %s: %w", host, root, err)
+ }
+ isDir := make(map[string]bool, len(entries))
+ var names []string
+ for _, e := range entries {
+ isDir[e.Name()] = e.IsDir()
+ names = append(names, e.Name())
+ }
+ if l == pubclass.Flat {
+ names, _ = hostEntries(entries, host, knownHosts(entries, append([]string{host}, hosts...)), nil)
+ }
+ sort.Strings(names)
+ out := make([]InventoryEntry, 0, len(names))
+ for _, name := range names {
+ out = append(out, InventoryEntry{Rel: name, Dir: isDir[name], Class: pubclass.Of(l, host, name, isDir[name])})
+ }
+ return out, nil
+}
diff --git a/internal/layout/inventory_test.go b/internal/layout/inventory_test.go
new file mode 100644
index 000000000..0a3c863ea
--- /dev/null
+++ b/internal/layout/inventory_test.go
@@ -0,0 +1,90 @@
+package layout
+
+import (
+ "os"
+ "path/filepath"
+ "slices"
+ "testing"
+
+ "github.com/carlosframework/platform/internal/layout/pubclass"
+ "github.com/carlosframework/platform/internal/provision"
+)
+
+func makeEntries(t *testing.T, dir string, names ...string) {
+ t.Helper()
+ if err := os.MkdirAll(dir, 0o755); err != nil {
+ t.Fatal(err)
+ }
+ for _, n := range names {
+ p := filepath.Join(dir, n)
+ var err error
+ if n[len(n)-1] == '/' {
+ err = os.Mkdir(p, 0o755)
+ } else {
+ err = os.WriteFile(p, []byte("x"), 0o600)
+ }
+ if err != nil {
+ t.Fatal(err)
+ }
+ }
+}
+
+func TestInventoryFlatGivesEachNameToTheLongestHost(t *testing.T) {
+ dd := t.TempDir()
+ const h = "a.b.example.com"
+ makeEntries(t, dd, h+".env", h+"-x.env", h+"/", h+"-blobs/", "blobs/", "registry.db")
+ got, err := Inventory(dd, h, pubclass.Flat, []string{h, h + "-x"})
+ if err != nil {
+ t.Fatal(err)
+ }
+ want := []InventoryEntry{
+ {Rel: h, Dir: true, Class: pubclass.App},
+ {Rel: h + "-blobs", Dir: true, Class: pubclass.App},
+ {Rel: h + ".env", Class: pubclass.Sealed},
+ }
+ if !slices.Equal(got, want) {
+ t.Errorf("Inventory = %+v, want %+v", got, want)
+ }
+}
+
+func TestInventoryNestedListsTheWholeInstanceDirectory(t *testing.T) {
+ dd := t.TempDir()
+ const h = "shop.example.com"
+ makeEntries(t, provision.InstanceDir(dd, h), h+"/", h+".env", h+".config.env", h+".db", ".files-gen", "launch.run.json", "notes.txt")
+ got, err := Inventory(dd, h, pubclass.Nested, nil)
+ if err != nil {
+ t.Fatal(err)
+ }
+ want := []InventoryEntry{
+ {Rel: ".files-gen", Class: pubclass.Never},
+ {Rel: "launch.run.json", Class: pubclass.Never},
+ {Rel: "notes.txt", Class: pubclass.App},
+ {Rel: h, Dir: true, Class: pubclass.App},
+ {Rel: h + ".config.env", Class: pubclass.Regenerated},
+ {Rel: h + ".db", Class: pubclass.Replicated},
+ {Rel: h + ".env", Class: pubclass.Sealed},
+ }
+ if !slices.Equal(got, want) {
+ t.Errorf("Inventory = %+v, want %+v", got, want)
+ }
+}
+
+func TestInventoryOfAMissingDirectoryIsEmpty(t *testing.T) {
+ dd := filepath.Join(t.TempDir(), "absent")
+ for _, l := range []pubclass.Layout{pubclass.Flat, pubclass.Nested} {
+ got, err := Inventory(dd, "shop.example.com", l, nil)
+ if err != nil || len(got) != 0 {
+ t.Errorf("%v: %+v %v, want empty", l, got, err)
+ }
+ }
+}
+
+func TestInventoryRefusesABadHostOrLayout(t *testing.T) {
+ dd := t.TempDir()
+ if _, err := Inventory(dd, "../x", pubclass.Nested, nil); err == nil {
+ t.Error("a bad host was listed")
+ }
+ if _, err := Inventory(dd, "shop.example.com", pubclass.Layout(0), nil); err == nil {
+ t.Error("an unknown layout was listed")
+ }
+}
diff --git a/internal/layout/pass_linux_test.go b/internal/layout/pass_linux_test.go
index e9a22a2e5..ffc3a0946 100644
--- a/internal/layout/pass_linux_test.go
+++ b/internal/layout/pass_linux_test.go
@@ -16,6 +16,7 @@ import (
"time"
"github.com/carlosframework/platform/internal/activator"
+ "github.com/carlosframework/platform/internal/layout/pubclass"
"github.com/carlosframework/platform/internal/provision"
"github.com/carlosframework/platform/internal/registry"
)
@@ -94,7 +95,7 @@ func seedFlat(t *testing.T, dd, h string) {
db: "db " + h,
db + "-wal": "wal",
filepath.Join(dd, h+".env"): "CARLOS_ADMIN_TOKEN=t\n",
- filepath.Join(dd, shadowName(h), "generation"): "g",
+ filepath.Join(dd, pubclass.ShadowName(h), "generation"): "g",
}
if h == host {
files[db+".corrupt"] = "quarantined"
@@ -211,7 +212,7 @@ func TestConvergeNestedMovesFilesFlipsTheRowAndRemovesTheJournal(t *testing.T) {
t.Fatalf("%s row = %+v, want %+v", h, got, want)
}
raw := rawInstanceDir(p.DataDir, h)
- for _, name := range []string{h + ".db", h + ".db-wal", h + ".env", filepath.Join(shadowName(h), "generation")} {
+ for _, name := range []string{h + ".db", h + ".db-wal", h + ".env", filepath.Join(pubclass.ShadowName(h), "generation")} {
if _, err := os.Stat(filepath.Join(raw, name)); err != nil {
t.Errorf("%s not at the raw destination: %v", name, err)
}
@@ -250,7 +251,7 @@ func TestConvergeNestedMovesFilesFlipsTheRowAndRemovesTheJournal(t *testing.T) {
t.Fatalf("revert %s = %+v", h, res[h])
}
assertFlatUntouched(t, p, h)
- if _, err := os.Stat(filepath.Join(p.DataDir, shadowName(h), "generation")); err != nil {
+ if _, err := os.Stat(filepath.Join(p.DataDir, pubclass.ShadowName(h), "generation")); err != nil {
t.Errorf("%s shadow not back: %v", h, err)
}
}
@@ -1103,7 +1104,7 @@ func TestRecoverDoesNotReleaseANestedHostFlatOverAForgedRevert(t *testing.T) {
if res := byHost(t, p.Converge(context.Background(), ModeNested)); res[host].Outcome != "migrated" {
t.Fatalf("setup: %+v", res)
}
- shadow := filepath.Join(rawInstanceDir(p.DataDir, host), shadowName(host))
+ shadow := filepath.Join(rawInstanceDir(p.DataDir, host), pubclass.ShadowName(host))
if _, err := os.Stat(shadow); err != nil {
t.Fatalf("setup: %v", err)
}
diff --git a/internal/layout/plan.go b/internal/layout/plan.go
index 83222615d..0e0dfad8d 100644
--- a/internal/layout/plan.go
+++ b/internal/layout/plan.go
@@ -10,13 +10,9 @@ package layout
import (
"fmt"
"path/filepath"
- "strconv"
- "strings"
- "github.com/carlosframework/platform/internal/activator"
"github.com/carlosframework/platform/internal/controlname"
- "github.com/carlosframework/platform/internal/instancectl"
- "github.com/carlosframework/platform/internal/instancekey"
+ "github.com/carlosframework/platform/internal/layout/pubclass"
"github.com/carlosframework/platform/internal/provision"
"github.com/carlosframework/platform/internal/release"
)
@@ -118,124 +114,46 @@ func rawRunDir(socketDir, host string) string {
return filepath.Join(socketDir, ".instances", provision.InstanceID(host))
}
-// shadowName is the litestream shadow directory's file name for host,
-// derived exactly as internal/lease/lease.go's newStore does for a
-// database path whose base name is "<host>.db". That derivation is on an
-// unexported helper in internal/lease, so it is repeated here rather than
-// imported: this package has no other reason to depend on litestream's
-// setup, and a two-line string format is cheaper to keep in step by hand
-// than a new cross-package dependency is to justify.
-func shadowName(host string) string {
- return ".activator-" + host + ".db-litestream"
-}
-
// flatFiles and nestedFiles are the nine artifact paths under each layout,
-// in artifactNames order. The nested set is expressed through the raw
-// directories, except for the socket, which the pass never renames and so
-// is expressed through the mount-visible ("instances", not ".instances")
-// path the row itself will carry.
+// in artifactNames order, built from pubclass.FileBases. The nested set is
+// expressed through the raw directories, except for the socket, which the
+// pass never renames and so is expressed through the mount-visible
+// ("instances", not ".instances") path the row itself will carry.
func flatFiles(dataDir, socketDir, host string) []string {
- db := provision.DefaultDBPath(dataDir, host)
- return []string{
- db,
- db + "-wal",
- db + "-shm",
- filepath.Join(dataDir, host+".env"),
- filepath.Join(dataDir, host+"-sidecar.env"),
- filepath.Join(dataDir, host+".config.env"),
- filepath.Join(socketDir, host+".sock"),
- filepath.Join(dataDir, shadowName(host)),
- db + ".corrupt",
- }
+ return artifactPaths(dataDir, filepath.Join(socketDir, host+".sock"), host)
}
func nestedFiles(dataDir, socketDir, host string) []string {
- d := rawInstanceDir(dataDir, host)
- db := filepath.Join(d, host+".db")
- return []string{
- db,
- filepath.Join(d, host+".db-wal"),
- filepath.Join(d, host+".db-shm"),
- filepath.Join(d, host+".env"),
- filepath.Join(d, host+"-sidecar.env"),
- filepath.Join(d, host+".config.env"),
- filepath.Join(socketDir, "instances", provision.InstanceID(host), "app.sock"),
- filepath.Join(d, shadowName(host)),
- db + ".corrupt",
- }
+ return artifactPaths(rawInstanceDir(dataDir, host), filepath.Join(socketDir, "instances", provision.InstanceID(host), "app.sock"), host)
}
-// filesMarkerName is the files directory's generation marker
-// (archive.MarkerName, hostfiles' marker), named here rather than imported:
-// the archive package depends on hostfiles and appconfig, which this
-// package has no other reason to.
-const filesMarkerName = ".files-gen"
+// artifactPaths is every artifact in artifactNames order: the socket at
+// socket, every other one at its pubclass.FileBases name under dir.
+func artifactPaths(dir, socket, host string) []string {
+ bases := pubclass.FileBases(host)
+ out := make([]string, 0, len(artifactNames))
+ for _, name := range artifactNames {
+ if name == "socket" {
+ out = append(out, socket)
+ continue
+ }
+ out = append(out, filepath.Join(dir, bases[name]))
+ }
+ return out
+}
-// NestedPlatformNames is every name in a nested host's instance directory
-// that is the platform's, not the app's: the names nestedFiles puts in the
-// raw instance directory (the database, its WAL, SHM and quarantine, the
-// own and sidecar env files, the rendered configuration, the activator's
-// litestream shadow; the socket is in the run directory and is not here),
-// the database's generation marker (<db>.gen), litestream's stock meta
-// directory (<db>-litestream), the files generation marker (.files-gen) and
-// the instance-key adoption record, the seed marker a seeded database
-// keeps beside it for its life (<db>.seed, activator.SeedMarkerSuffix,
-// written by ExecBackend.seededRestore in activator/seedplace.go), and the
-// unit launch descriptors written into the instance directory:
-// launch.<role>.json for every instancectl role
-// (instancectl.LaunchFileName; written by ExecBackend.writeLaunchFor in
-// activator/prepare.go, and launch.run.json also by root's role launch in
-// activator/rolelaunch_root_linux.go). A
-// generation's descriptor, launch.gen.<n>.json (instancectl.
-// GenLaunchFileName, written by writeLaunchFor), has no fixed name:
-// IsNestedPlatformName answers for it. Everything else in the directory is
-// the app's: its files directory <host> and anything it keeps beside it.
-//
+// NestedPlatformNames is pubclass.NestedPlatformNames: every name in a
+// nested host's instance directory that is the platform's, not the app's.
// The offline move's sealer uses these to find what the app keeps beside
// its files directory, which the move cannot carry. It archives the files
// directory alone (archive.Build over <instance dir>/<host>), so none of
// these is ever carried; the source's retire parks every entry of the
// instance directory, these included.
-func NestedPlatformNames(host string) map[string]bool {
- const dataDir, socketDir = "/data", "/run/carlos"
- raw := rawInstanceDir(dataDir, host)
- out := map[string]bool{}
- for _, p := range nestedFiles(dataDir, socketDir, host) {
- if filepath.Dir(p) == raw {
- out[filepath.Base(p)] = true
- }
- }
- db := host + ".db"
- out[db+".gen"] = true
- out[db+"-litestream"] = true
- out[db+activator.SeedMarkerSuffix] = true
- out[filesMarkerName] = true
- out[host+instancekey.AdoptionSuffix] = true
- for _, role := range []instancectl.Role{instancectl.RoleRun, instancectl.RoleSeed, instancectl.RoleSidecar, instancectl.RoleCmd} {
- out[instancectl.LaunchFileName(role)] = true
- }
- return out
-}
+func NestedPlatformNames(host string) map[string]bool { return pubclass.NestedPlatformNames(host) }
-// IsNestedPlatformName reports whether name, an entry of host's instance
-// directory, is the platform's: one of NestedPlatformNames, or a
-// generation's launch descriptor, exactly launch.gen.<n>.json with n a
-// decimal number as instancectl.GenLaunchFileName writes it.
-func IsNestedPlatformName(host, name string) bool {
- if NestedPlatformNames(host)[name] {
- return true
- }
- n, ok := strings.CutPrefix(name, "launch.gen.")
- if !ok {
- return false
- }
- n, ok = strings.CutSuffix(n, ".json")
- if !ok || n == "" {
- return false
- }
- gen, err := strconv.ParseUint(n, 10, 64)
- return err == nil && instancectl.GenLaunchFileName(gen) == name
-}
+// IsNestedPlatformName is pubclass.IsNestedPlatformName: one of
+// NestedPlatformNames, or a generation's launch descriptor.
+func IsNestedPlatformName(host, name string) bool { return pubclass.IsNestedPlatformName(host, name) }
// PlanFor derives the plan for host in the given direction from the host
// name alone (design §8.2 step 3). The endpoints are the row values the
diff --git a/internal/layout/pubclass/names.go b/internal/layout/pubclass/names.go
new file mode 100644
index 000000000..a12c45bee
--- /dev/null
+++ b/internal/layout/pubclass/names.go
@@ -0,0 +1,140 @@
+package pubclass
+
+import (
+ "strconv"
+ "strings"
+
+ "github.com/carlosframework/platform/internal/controlname"
+ "github.com/carlosframework/platform/internal/instancectl"
+ "github.com/carlosframework/platform/internal/instancekey"
+)
+
+// The per-host names the platform gives a host's files. They lived in
+// internal/layout (plan.go, extras.go), which imports internal/activator,
+// so the classifier could not sit there and be called from the activator.
+// They are here, in a package that imports only name helpers, and layout
+// builds its plans from them.
+
+// SeedMarkerSuffix names the installation evidence beside a placed
+// database: <db>.seed holds the seed's id (activator.SeedMarkerSuffix,
+// written by ExecBackend.seededRestore in activator/seedplace.go).
+const SeedMarkerSuffix = ".seed"
+
+// FilesMarkerName is the files directory's generation marker
+// (archive.MarkerName, hostfiles' marker).
+const FilesMarkerName = ".files-gen"
+
+// ShadowName is the activator's litestream shadow directory's file name for
+// host, derived exactly as internal/lease/lease.go's newStore does for a
+// database path whose base name is "<host>.db". That derivation is on an
+// unexported helper in internal/lease, so it is repeated here rather than
+// imported.
+func ShadowName(host string) string {
+ return ".activator-" + host + ".db-litestream"
+}
+
+// FileBases is the base name of every artifact the layout pass tracks for
+// host (layout's artifactNames) that is a file or directory beside the
+// database, keyed by artifact name. The base names are the same under both
+// layouts. The socket is left out: it lives in the run directory and has a
+// different name nested.
+func FileBases(host string) map[string]string {
+ db := host + ".db"
+ return map[string]string{
+ "db": db,
+ "db-wal": db + "-wal",
+ "db-shm": db + "-shm",
+ "env": host + ".env",
+ "sidecar-env": host + "-sidecar.env",
+ "config-env": host + ".config.env",
+ "litestream-shadow": ShadowName(host),
+ "corrupt": db + ".corrupt",
+ }
+}
+
+// NestedPlatformNames is every name in a nested host's instance directory
+// that is the platform's, not the app's: the FileBases names (the
+// database, its WAL, SHM and quarantine, the own and sidecar env files,
+// the rendered configuration, the activator's litestream shadow), the
+// database's generation marker (<db>.gen), litestream's stock meta
+// directory (<db>-litestream), the files generation marker (.files-gen),
+// the instance-key adoption record, the seed marker a seeded database
+// keeps beside it for its life (<db>.seed), and the unit launch
+// descriptors written into the instance directory: launch.<role>.json for
+// every instancectl role (instancectl.LaunchFileName; written by
+// ExecBackend.writeLaunchFor in activator/prepare.go, and launch.run.json
+// also by root's role launch in activator/rolelaunch_root_linux.go). A
+// generation's descriptor, launch.gen.<n>.json (instancectl.
+// GenLaunchFileName), has no fixed name: IsNestedPlatformName answers for
+// it. Everything else in the directory is the app's: its files directory
+// <host> and anything it keeps beside it.
+func NestedPlatformNames(host string) map[string]bool {
+ out := map[string]bool{}
+ for _, base := range FileBases(host) {
+ out[base] = true
+ }
+ db := host + ".db"
+ out[db+".gen"] = true
+ out[db+"-litestream"] = true
+ out[db+SeedMarkerSuffix] = true
+ out[FilesMarkerName] = true
+ out[host+instancekey.AdoptionSuffix] = true
+ for _, role := range []instancectl.Role{instancectl.RoleRun, instancectl.RoleSeed, instancectl.RoleSidecar, instancectl.RoleCmd} {
+ out[instancectl.LaunchFileName(role)] = true
+ }
+ return out
+}
+
+// IsNestedPlatformName reports whether name, an entry of host's instance
+// directory, is the platform's: one of NestedPlatformNames, or a
+// generation's launch descriptor, exactly launch.gen.<n>.json with n a
+// decimal number as instancectl.GenLaunchFileName writes it.
+func IsNestedPlatformName(host, name string) bool {
+ if NestedPlatformNames(host)[name] {
+ return true
+ }
+ n, ok := strings.CutPrefix(name, "launch.gen.")
+ if !ok {
+ return false
+ }
+ n, ok = strings.CutSuffix(n, ".json")
+ if !ok || n == "" {
+ return false
+ }
+ gen, err := strconv.ParseUint(n, 10, 64)
+ return err == nil && instancectl.GenLaunchFileName(gen) == name
+}
+
+// FixedSuffixes are the platform's per-host file shapes under the flat
+// layout, X plus suffix, longest first so ".db.corrupt" is read before
+// ".db" and ".config.env" before ".env".
+var FixedSuffixes = []string{".db.corrupt", ".config.env", "-sidecar.env", ".db-wal", ".db-shm", ".db", ".env"}
+
+// FixedShapeHost reads the host X out of a name that has one of the
+// platform's fixed per-host shapes (X.db, X.env, X.config.env,
+// X-sidecar.env, X.db-wal, X.db-shm, X.db.corrupt, .activator-X.*), and
+// reports whether it has one. X must be a valid host shape with a dot in
+// it (every host the platform serves has one; registry.db and
+// litestream.env are the box's, not a host's); a name that is not
+// host-shaped under any suffix is nobody's platform file.
+func FixedShapeHost(name string) (string, bool) {
+ hostLike := func(x string) bool { return strings.Contains(x, ".") && controlname.ValidHostShape(x) }
+ if rest, ok := strings.CutPrefix(name, ".activator-"); ok {
+ if x, ok := FixedShapeHost(rest); ok {
+ return x, true
+ }
+ if i := strings.Index(rest, ".db-"); i > 0 && hostLike(rest[:i]) {
+ return rest[:i], true
+ }
+ return "", false
+ }
+ for _, suffix := range FixedSuffixes {
+ if x, ok := strings.CutSuffix(name, suffix); ok && x != "" {
+ if hostLike(x) {
+ return x, true
+ }
+ return "", false
+ }
+ }
+ return "", false
+}
diff --git a/internal/layout/pubclass/pubclass.go b/internal/layout/pubclass/pubclass.go
new file mode 100644
index 000000000..70a4fef16
--- /dev/null
+++ b/internal/layout/pubclass/pubclass.go
@@ -0,0 +1,282 @@
+// Package pubclass is the one classification of what a files publication
+// may carry (durability spec §5.3, §3.1 item 16). Every publication's walk
+// asks Of for every path before staging it: only App is published as bytes;
+// the sealed trio goes only as sealed platform items (§5.4); the rendered
+// env files are never published; the databases are Litestream's; and
+// everything else the platform names is never published.
+//
+// It is a leaf: it imports only name helpers, so hostfiles and the
+// activator can call it, and internal/layout builds its plans from the
+// names it holds (names.go).
+package pubclass
+
+import (
+ "errors"
+ "path"
+ "strconv"
+ "strings"
+)
+
+// Class is what a publication may do with a path.
+type Class uint8
+
+const (
+ // App is published as bytes: an entry the app made.
+ App Class = iota + 1
+ // Sealed is <host>.env, instance.key or report.token: never published
+ // raw, only as a sealed platform item.
+ Sealed
+ // Regenerated is <host>.config.env or <host>-sidecar.env: never
+ // published; every box renders them from sealed configuration.
+ Regenerated
+ // Replicated is a database with its WAL, SHM, quarantine and
+ // Litestream directories: Litestream's, never files'.
+ Replicated
+ // Never is everything else the platform names, and anything the
+ // inventory does not give the host.
+ Never
+)
+
+func (c Class) String() string {
+ switch c {
+ case App:
+ return "app"
+ case Sealed:
+ return "sealed"
+ case Regenerated:
+ return "regenerated"
+ case Replicated:
+ return "replicated"
+ case Never:
+ return "never"
+ }
+ return "class(" + strconv.Itoa(int(c)) + ")"
+}
+
+// Layout is where the host's inventory root is.
+type Layout uint8
+
+const (
+ // Flat: the inventory root is the data directory.
+ Flat Layout = iota + 1
+ // Nested: the inventory root is the host's instance directory.
+ Nested
+)
+
+func (l Layout) String() string {
+ switch l {
+ case Flat:
+ return "flat"
+ case Nested:
+ return "nested"
+ }
+ return "layout(" + strconv.Itoa(int(l)) + ")"
+}
+
+// ErrSecretPath is a refusal to publish a path whose class is Sealed,
+// Regenerated or Never.
+var ErrSecretPath = errors.New("pubclass: a secret or platform path would be published")
+
+// The trio's names inside the files directory, and the raw platform item
+// an older publisher wrote the env under (hostfiles.EnvItem; a hostfiles
+// test pins the two equal).
+const (
+ instanceKeyName = "instance.key"
+ reportTokenName = "report.token"
+ rawEnvItem = "host.env"
+)
+
+// clean reports whether rel is a clean, relative slash path naming
+// something below the root: not empty, not ".", not absolute, no "..",
+// no empty or "." element.
+func clean(rel string) bool {
+ return rel != "" && rel != "." && path.Clean(rel) == rel && !path.IsAbs(rel) &&
+ rel != ".." && !strings.HasPrefix(rel, "../")
+}
+
+// Of classifies rel, a clean slash path relative to the host's inventory
+// root: the instance directory (Nested) or the data directory (Flat). The
+// first rule that matches decides (spec §5.3), and every platform-name rule
+// comes before the nested App fallback:
+//
+// 1. a first element with a platform fixed per-host shape of another host
+// (FixedShapeHost): Never;
+// 2. <host>.env, <host>/instance.key, <host>/report.token (the trio only at
+// the files directory's root): Sealed;
+// 3. <host>.config.env, <host>-sidecar.env: Regenerated;
+// 4. <host>.db, <host>.db-wal, <host>.db-shm, <host>.db.corrupt,
+// ShadowName(host) and <host>.db-litestream, with everything beneath:
+// Replicated;
+// 5. nested only: a first element IsNestedPlatformName names (the launch
+// descriptors carry Env): Never;
+// 6. any other first element beginning <host>. or .activator-<host>, and
+// any other dot name at the root: Never;
+// 7. <host> and everything beneath it, and <host>-<x> with x not
+// sidecar.env: App;
+// 8. anything else: Never in Flat (the inventory never gives it to this
+// host); App in Nested (the app's own entry in its instance directory).
+//
+// Names are classified by where they sit, never by extension: an app's
+// Gemfile.lock or config/production.env under <host>/ is App. Every rule
+// is by name, so isDir changes no class: a directory at a reserved name is
+// refused exactly as a file there would be. Sockets and other non-regular
+// files are the walker's to skip. A rel that is not clean, and a layout
+// that is neither Flat nor Nested, is Never: a path is only trusted to be
+// what its first element says when it cannot climb out of it.
+func Of(l Layout, host, rel string, isDir bool) Class {
+ if (l != Flat && l != Nested) || !clean(rel) {
+ return Never
+ }
+ first, _, _ := strings.Cut(rel, "/")
+ db := host + ".db"
+
+ // 1. Another host's fixed platform shape.
+ if x, ok := FixedShapeHost(first); ok && x != host {
+ return Never
+ }
+ // 2. The sealed trio.
+ switch rel {
+ case host + ".env", host + "/" + instanceKeyName, host + "/" + reportTokenName:
+ return Sealed
+ }
+ // 3. The rendered env files.
+ switch rel {
+ case host + ".config.env", host + "-sidecar.env":
+ return Regenerated
+ }
+ // 4. The databases and Litestream's directories, with everything beneath.
+ switch first {
+ case db, db + "-wal", db + "-shm", db + ".corrupt", ShadowName(host), db + "-litestream":
+ return Replicated
+ }
+ // 5. The nested platform names.
+ if l == Nested && IsNestedPlatformName(host, first) {
+ return Never
+ }
+ // 6. Every other platform-shaped or dot name at the root (the
+ // .activator-<host> forms are dot names).
+ if strings.HasPrefix(first, host+".") || strings.HasPrefix(first, ".") {
+ return Never
+ }
+ // 7. The files directory and the app's sibling trees.
+ if first == host {
+ return App
+ }
+ if x, ok := strings.CutPrefix(first, host+"-"); ok && x != "" && x != "sidecar.env" {
+ return App
+ }
+ // 8. The fallback.
+ if l == Nested {
+ return App
+ }
+ return Never
+}
+
+// FilesDirSkip is a hostfiles skip for a sync rooted at <root>/<host>:
+// true for every path whose class as host+"/"+rel is not App.
+func FilesDirSkip(l Layout, host string) func(rel string, isDir bool) bool {
+ return func(rel string, isDir bool) bool {
+ return Of(l, host, host+"/"+rel, isDir) != App
+ }
+}
+
+// SealedRel is a path Of classified Sealed, with its hostfiles item name.
+// Its fields are unexported: SealedPath is the only way to make one, so
+// hostfiles.StageSealed can only be handed a classifier verdict.
+type SealedRel struct{ rel, item string }
+
+// Rel is the path relative to the inventory root.
+func (r SealedRel) Rel() string { return r.rel }
+
+// Item is the sealed platform item's name: "env.sealed",
+// "instance.key.sealed" or "report.token.sealed".
+func (r SealedRel) Item() string { return r.item }
+
+// SealedPath is rel as a SealedRel, ok only when Of classifies it Sealed.
+func SealedPath(l Layout, host, rel string) (SealedRel, bool) {
+ if Of(l, host, rel, false) != Sealed {
+ return SealedRel{}, false
+ }
+ switch rel {
+ case host + ".env":
+ return SealedRel{rel: rel, item: "env.sealed"}, true
+ case host + "/" + instanceKeyName:
+ return SealedRel{rel: rel, item: instanceKeyName + ".sealed"}, true
+ case host + "/" + reportTokenName:
+ return SealedRel{rel: rel, item: reportTokenName + ".sealed"}, true
+ }
+ return SealedRel{}, false
+}
+
+// SealedRels is the three sealed paths: <host>.env, <host>/instance.key,
+// <host>/report.token, relative to the inventory root (the same in both
+// layouts), in that order. A layout Of does not know gives none.
+func SealedRels(l Layout, host string) []SealedRel {
+ var out []SealedRel
+ for _, rel := range []string{host + ".env", host + "/" + instanceKeyName, host + "/" + reportTokenName} {
+ if r, ok := SealedPath(l, host, rel); ok {
+ out = append(out, r)
+ }
+ }
+ return out
+}
+
+type itemKind uint8
+
+const (
+ platformItems itemKind = iota + 1
+ filesDirEntries
+ inventoryEntries
+)
+
+// ItemContext says where a name sits in a publication, so the predicate
+// follows the classifier's reserved locations and never an app's filename.
+// The zero ItemContext is no context: IsRawSecretItem refuses every name in
+// it.
+type ItemContext struct {
+ kind itemKind
+ layout Layout
+ host string
+}
+
+// PlatformItems is a manifest's Platform map.
+func PlatformItems() ItemContext { return ItemContext{kind: platformItems} }
+
+// FilesDirEntries is the Entries of a publication rooted at <host>/.
+func FilesDirEntries() ItemContext { return ItemContext{kind: filesDirEntries} }
+
+// InventoryEntries is the Entries of a publication rooted at the inventory
+// root (step 6's box-level sets).
+func InventoryEntries(l Layout, host string) ItemContext {
+ return ItemContext{kind: inventoryEntries, layout: l, host: host}
+}
+
+// IsRawSecretItem reports whether name, in context c, would carry a secret
+// raw. Platform items: only "host.env" (hostfiles.EnvItem). Files-directory
+// entries: only "instance.key" and "report.token" at the root (Of's rule
+// 2). Inventory entries: a path Of classifies Sealed or Regenerated. Paul's
+// ruling: the step 7 copier refuses every object such an item names.
+//
+// An entry name is read as path.Clean would restore it, so a name that
+// climbs back onto a secret's place ("sub/../instance.key") is that
+// secret. A context nobody made with one of the three constructors answers
+// true: a caller that forgot to say where a name sits is refused.
+func IsRawSecretItem(c ItemContext, name string) bool {
+ switch c.kind {
+ case platformItems:
+ return name == rawEnvItem
+ case filesDirEntries:
+ switch strings.TrimPrefix(path.Clean("/"+name), "/") {
+ case instanceKeyName, reportTokenName:
+ return true
+ }
+ return false
+ case inventoryEntries:
+ switch Of(c.layout, c.host, strings.TrimPrefix(path.Clean("/"+name), "/"), false) {
+ case Sealed, Regenerated:
+ return true
+ }
+ return false
+ }
+ return true
+}
diff --git a/internal/layout/pubclass/pubclass_test.go b/internal/layout/pubclass/pubclass_test.go
new file mode 100644
index 000000000..db3acf5ec
--- /dev/null
+++ b/internal/layout/pubclass/pubclass_test.go
@@ -0,0 +1,234 @@
+package pubclass
+
+import (
+ "testing"
+
+ "github.com/carlosframework/platform/internal/instancekey"
+)
+
+func TestOfClassifiesEveryPlatformName(t *testing.T) {
+ const h = "shop.example.com"
+ for _, l := range []Layout{Flat, Nested} {
+ for rel, want := range map[string]Class{
+ h + ".env": Sealed, h + "/instance.key": Sealed, h + "/report.token": Sealed,
+ h + ".config.env": Regenerated, h + "-sidecar.env": Regenerated,
+ h + ".db": Replicated, h + ".db-wal": Replicated, h + ".db-shm": Replicated,
+ h + ".db.corrupt": Replicated, ".activator-" + h + ".db-litestream/0001": Replicated,
+ h + ".db-litestream/x": Replicated,
+ h + ".db.gen": Never, h + ".db.seed": Never, h + ".db.release.files.json": Never,
+ h + ".restore/a": Never, h + ".anything": Never,
+ h + "/a.txt": App, h + "/sub/instance.key": App, h + "/Gemfile.lock": App,
+ h + "-blobs/x/y": App,
+ "other.example.com.env": Never,
+ } {
+ if got := Of(l, h, rel, false); got != want {
+ t.Errorf("%v %s: %v, want %v", l, rel, got, want)
+ }
+ }
+ }
+ // Astra R1 P1-6: these reach rule 5 before the nested fallback.
+ for _, rel := range []string{".files-gen", "launch.run.json", "launch.seed.json", "launch.gen.7.json", h + instancekey.AdoptionSuffix} {
+ if got := Of(Nested, h, rel, false); got != Never {
+ t.Errorf("nested %s: %v, want never", rel, got)
+ }
+ }
+ if got := Of(Nested, h, "notes.txt", false); got != App {
+ t.Errorf("nested notes.txt: %v, want app", got)
+ }
+ if got := Of(Flat, h, "blobs/x", false); got != Never {
+ t.Errorf("flat blobs/x: %v, want never (not the host's)", got)
+ }
+}
+
+// A directory at a reserved name is refused like a file there, the files
+// directory itself is the app's, and a path that is not clean is never
+// trusted to be what its first element says.
+func TestOfJudgesByNameAndRefusesUncleanPaths(t *testing.T) {
+ const h = "shop.example.com"
+ for _, l := range []Layout{Flat, Nested} {
+ for rel, want := range map[string]Class{
+ h: App,
+ h + "/instance.key": Sealed,
+ h + ".env": Sealed,
+ h + ".config.env": Regenerated,
+ ShadowName(h): Replicated,
+ h + "-sidecar.env/x": Never,
+ ".instances": Never,
+ } {
+ if got := Of(l, h, rel, true); got != want {
+ t.Errorf("%v dir %s: %v, want %v", l, rel, got, want)
+ }
+ }
+ for _, rel := range []string{"", ".", "/" + h + "/a", h + "/../" + h + ".env", h + "/./a", h + "//a", h + "/", "../x", h + "/a/.."} {
+ if got := Of(l, h, rel, false); got != Never {
+ t.Errorf("%v unclean %q: %v, want never", l, rel, got)
+ }
+ }
+ }
+ if got := Of(Layout(0), h, h+"/a.txt", false); got != Never {
+ t.Errorf("unknown layout: %v, want never", got)
+ }
+}
+
+func TestClassAndLayoutStrings(t *testing.T) {
+ for c, want := range map[Class]string{App: "app", Sealed: "sealed", Regenerated: "regenerated", Replicated: "replicated", Never: "never"} {
+ if c.String() != want {
+ t.Errorf("%d: %q, want %q", c, c.String(), want)
+ }
+ }
+}
+
+func TestSealedPathIsTheOnlyWayToASealedRel(t *testing.T) {
+ const h = "shop.example.com"
+ if r, ok := SealedPath(Nested, h, h+".env"); !ok || r.Item() != "env.sealed" || r.Rel() != h+".env" {
+ t.Fatalf("env: %+v %v", r, ok)
+ }
+ for _, rel := range []string{h + ".config.env", h + "/a.txt", "launch.run.json"} {
+ if _, ok := SealedPath(Nested, h, rel); ok {
+ t.Errorf("%s made a SealedRel", rel)
+ }
+ }
+}
+
+func TestSealedRelsAreTheTrioInBothLayouts(t *testing.T) {
+ const h = "shop.example.com"
+ want := [][2]string{
+ {h + ".env", "env.sealed"},
+ {h + "/instance.key", "instance.key.sealed"},
+ {h + "/report.token", "report.token.sealed"},
+ }
+ for _, l := range []Layout{Flat, Nested} {
+ got := SealedRels(l, h)
+ if len(got) != len(want) {
+ t.Fatalf("%v: %d sealed rels, want %d", l, len(got), len(want))
+ }
+ for i, r := range got {
+ if r.Rel() != want[i][0] || r.Item() != want[i][1] {
+ t.Errorf("%v %d: %s %s, want %s %s", l, i, r.Rel(), r.Item(), want[i][0], want[i][1])
+ }
+ if Of(l, h, r.Rel(), false) != Sealed {
+ t.Errorf("%v %s: not sealed", l, r.Rel())
+ }
+ if again, ok := SealedPath(l, h, r.Rel()); !ok || again != r {
+ t.Errorf("%v %s: SealedPath gives %+v %v", l, r.Rel(), again, ok)
+ }
+ }
+ }
+}
+
+func TestFilesDirSkipLeavesOnlyAppFiles(t *testing.T) {
+ const h = "shop.example.com"
+ for _, l := range []Layout{Flat, Nested} {
+ skip := FilesDirSkip(l, h)
+ for _, tc := range []struct {
+ rel string
+ isDir bool
+ want bool
+ }{
+ {"instance.key", false, true},
+ {"report.token", false, true},
+ {"a.txt", false, false},
+ {"sub/instance.key", false, false},
+ {"sub", true, false},
+ {"Gemfile.lock", false, false},
+ {"config/production.env", false, false},
+ {"../" + h + ".env", false, true},
+ } {
+ if got := skip(tc.rel, tc.isDir); got != tc.want {
+ t.Errorf("%v skip(%q, %v) = %v, want %v", l, tc.rel, tc.isDir, got, tc.want)
+ }
+ }
+ }
+}
+
+func TestIsRawSecretItem(t *testing.T) {
+ const h = "shop.example.com"
+ for _, tc := range []struct {
+ ctx string
+ c ItemContext
+ name string
+ want bool
+ }{
+ {"platform", PlatformItems(), "host.env", true},
+ {"platform", PlatformItems(), "env.sealed", false},
+ {"platform", PlatformItems(), "instance.key.sealed", false},
+ {"platform", PlatformItems(), "report.token.sealed", false},
+ {"platform", PlatformItems(), "wake.json", false},
+ {"platform", PlatformItems(), "sealed.cutover", false},
+
+ {"files", FilesDirEntries(), "instance.key", true},
+ {"files", FilesDirEntries(), "report.token", true},
+ {"files", FilesDirEntries(), "./instance.key", true},
+ {"files", FilesDirEntries(), "sub/../report.token", true},
+ {"files", FilesDirEntries(), "sub/instance.key", false},
+ {"files", FilesDirEntries(), "host.env", false},
+ {"files", FilesDirEntries(), "shop.example.com.env", false},
+ {"files", FilesDirEntries(), "config/production.env", false},
+
+ {"inventory", InventoryEntries(Nested, h), h + ".env", true},
+ {"inventory", InventoryEntries(Nested, h), h + "/instance.key", true},
+ {"inventory", InventoryEntries(Nested, h), h + "/report.token", true},
+ {"inventory", InventoryEntries(Nested, h), h + ".config.env", true},
+ {"inventory", InventoryEntries(Nested, h), h + "-sidecar.env", true},
+ {"inventory", InventoryEntries(Nested, h), h + "/x/../instance.key", true},
+ {"inventory", InventoryEntries(Nested, h), h + "/x.env", false},
+ {"inventory", InventoryEntries(Nested, h), h + "-blobs/a.env", false},
+ {"inventory", InventoryEntries(Nested, h), "notes.env", false},
+ {"inventory", InventoryEntries(Nested, h), h + ".db", false},
+ {"inventory", InventoryEntries(Flat, h), h + ".env", true},
+ {"inventory", InventoryEntries(Flat, h), h + "-sidecar.env", true},
+ {"inventory", InventoryEntries(Flat, h), h + "/a.env", false},
+
+ // A context nobody made answers true: a caller that forgot to say
+ // where a name sits is refused, not waved through.
+ {"zero", ItemContext{}, "a.txt", true},
+ } {
+ if got := IsRawSecretItem(tc.c, tc.name); got != tc.want {
+ t.Errorf("%s %q: %v, want %v", tc.ctx, tc.name, got, tc.want)
+ }
+ }
+}
+
+func TestFileBasesAreTheEightNonSocketArtifacts(t *testing.T) {
+ const h = "shop.example.com"
+ want := map[string]string{
+ "db": h + ".db", "db-wal": h + ".db-wal", "db-shm": h + ".db-shm",
+ "env": h + ".env", "sidecar-env": h + "-sidecar.env", "config-env": h + ".config.env",
+ "litestream-shadow": ".activator-" + h + ".db-litestream", "corrupt": h + ".db.corrupt",
+ }
+ got := FileBases(h)
+ if len(got) != len(want) {
+ t.Fatalf("FileBases: %v, want %v", got, want)
+ }
+ for k, v := range want {
+ if got[k] != v {
+ t.Errorf("FileBases[%s] = %q, want %q", k, got[k], v)
+ }
+ }
+ if ShadowName(h) != want["litestream-shadow"] {
+ t.Errorf("ShadowName: %q", ShadowName(h))
+ }
+}
+
+func TestFixedShapeHostReadsEveryPlatformShape(t *testing.T) {
+ for name, want := range map[string]string{
+ "a.example.com.env": "a.example.com",
+ "a.example.com.db": "a.example.com",
+ "a.example.com.db-wal": "a.example.com",
+ "a.example.com.db-shm": "a.example.com",
+ "a.example.com.config.env": "a.example.com",
+ "a.example.com-sidecar.env": "a.example.com",
+ "a.example.com.db.corrupt": "a.example.com",
+ ".activator-a.example.com.db-litestream": "a.example.com",
+ "a.example.com": "",
+ "a.example.com-blobs": "",
+ "litestream.env": "",
+ "registry.db": "",
+ ".env": "",
+ } {
+ got, ok := FixedShapeHost(name)
+ if got != want || ok != (want != "") {
+ t.Errorf("FixedShapeHost(%q) = %q %v, want %q", name, got, ok, want)
+ }
+ }
+}
diff --git a/internal/layout/pubclass_guard_test.go b/internal/layout/pubclass_guard_test.go
new file mode 100644
index 000000000..573bb7a47
--- /dev/null
+++ b/internal/layout/pubclass_guard_test.go
@@ -0,0 +1,47 @@
+package layout
+
+import (
+ "slices"
+ "testing"
+
+ "github.com/carlosframework/platform/internal/layout/pubclass"
+)
+
+// Exhaustiveness (durability spec §5.3, guard tests): every name the
+// layout pass tracks for a host, under both layouts, is sealed,
+// regenerated, replicated or never, and a new artifact or fixed shape
+// fails here until it is classified and listed.
+func TestEveryArtifactAndFixedShapeIsNotApp(t *testing.T) {
+ wantArtifacts := []string{"db", "db-wal", "db-shm", "env", "sidecar-env", "config-env", "socket", "litestream-shadow", "corrupt"}
+ wantSuffixes := []string{".db.corrupt", ".config.env", "-sidecar.env", ".db-wal", ".db-shm", ".db", ".env"}
+ if !slices.Equal(artifactNames, wantArtifacts) || !slices.Equal(pubclass.FixedSuffixes, wantSuffixes) {
+ t.Fatalf("artifactNames %q or FixedSuffixes %q changed: classify the new name in pubclass, then list it here", artifactNames, pubclass.FixedSuffixes)
+ }
+ const h = "shop.example.com"
+ bases := pubclass.FileBases(h)
+ for _, name := range artifactNames {
+ if _, ok := bases[name]; ok == (name == "socket") {
+ t.Errorf("FileBases and artifactNames disagree on %s", name)
+ }
+ }
+ if len(bases) != len(artifactNames)-1 {
+ t.Errorf("FileBases has %d names, want %d", len(bases), len(artifactNames)-1)
+ }
+ for _, l := range []pubclass.Layout{pubclass.Flat, pubclass.Nested} {
+ for name, base := range bases {
+ if c := pubclass.Of(l, h, base, name == "litestream-shadow"); c == pubclass.App {
+ t.Errorf("%v: artifact %s (%s) is app", l, name, base)
+ }
+ }
+ for _, s := range pubclass.FixedSuffixes {
+ if c := pubclass.Of(l, h, h+s, false); c == pubclass.App {
+ t.Errorf("%v: %s%s is app", l, h, s)
+ }
+ }
+ }
+ for name := range NestedPlatformNames(h) {
+ if c := pubclass.Of(pubclass.Nested, h, name, false); c == pubclass.App {
+ t.Errorf("nested platform name %s is app", name)
+ }
+ }
+}
diff --git a/internal/provision/durability_3a_escrow_census_test.go b/internal/provision/durability_3a_escrow_census_test.go
new file mode 100644
index 000000000..76e17e940
--- /dev/null
+++ b/internal/provision/durability_3a_escrow_census_test.go
@@ -0,0 +1,36 @@
+package provision
+
+// Record-write census entries for durability plan 3a (branch
+// durability-3a-escrow; plan
+// docs/superpowers/plans/2026-10-30-durability-step3-escrow-fence-restore.md),
+// layered on consoleProtectionTabWriteCensusInventory (main's newest at
+// b4d8db83). Reviewed by the branch author against the source; the census
+// approval is recorded on #280 with the root-read card
+// (docs/superpowers/notes/census-proposal-durability-3a-escrow.md). No
+// record write is added, moved or reclassified:
+// - internal/layout/plan.go nestedFiles (key-site), re-pinned (Task 1):
+// it builds the same nine paths, byte for byte, through artifactPaths
+// from pubclass.FileBases instead of listing them. The same "instances"
+// literal, the socket's mount-visible run directory (a directory name,
+// not a record): still key-site.
+func durability3aEscrowWriteCensusInventory() []censusEntry {
+ entries := append([]censusEntry(nil), consoleProtectionTabWriteCensusInventory()...)
+ repins := []censusEntry{
+ {"internal/layout/plan.go", "nestedFiles", "key-site", "lit:instances", "39ac6611151b89527e86ed0ae7a61dc400ad33f6c7d5c7627119548d4353f1ef"},
+ }
+ for _, r := range repins {
+ found := false
+ for i, e := range entries {
+ if e.File == r.File && e.Unit == r.Unit {
+ if e.Class != r.Class || e.Kinds != r.Kinds {
+ panic("durability-3a-escrow re-pin changes the class or kinds of " + r.File + ":" + r.Unit)
+ }
+ entries[i], found = r, true
+ }
+ }
+ if !found {
+ panic("durability-3a-escrow re-pin of an unlisted unit " + r.File + ":" + r.Unit)
+ }
+ }
+ return entries
+}
diff --git a/internal/provision/plan9_b8_census_test.go b/internal/provision/plan9_b8_census_test.go
index ad61affab..81b0fb881 100644
--- a/internal/provision/plan9_b8_census_test.go
+++ b/internal/provision/plan9_b8_census_test.go
@@ -366,7 +366,7 @@ func TestPlan9B8RecordWriteCensus(t *testing.T) {
if len(got) < 100 {
t.Fatalf("census found only %d units under %s; the walk is broken", len(got), root)
}
- inventory := consoleProtectionTabWriteCensusInventory()
+ inventory := durability3aEscrowWriteCensusInventory()
problems := append(censusDiff(inventory, got), censusPolicy(inventory)...)
if len(problems) > 0 {
t.Fatalf("record-write census rejected %d site(s); update the explicit inventory only after reviewing the source:\n %s", len(problems), strings.Join(problems, "\n "))
diff --git a/internal/provision/testdata/plan14-root-reads-chain.tsv b/internal/provision/testdata/plan14-root-reads-chain.tsv
index 895b2be6e..db6918f1a 100644
--- a/internal/provision/testdata/plan14-root-reads-chain.tsv
+++ b/internal/provision/testdata/plan14-root-reads-chain.tsv
@@ -45,3 +45,4 @@ plan14-root-reads-fleet-public-routes.tsv bca6ef741a96b72767b1747789cd01b3111d61
plan14-root-reads-fleet-routes-followups.tsv 1379d066c8dd2335d95d5f6e9c7bce65ff57f00b2b287a308d9b3f47911ae5e7
plan14-root-reads-tunnel-websockets.tsv 949bc734a293366e6b2700244af5110dd6e84b5432023e991c09e806afd62483
plan14-root-reads-console-protection-tab.tsv eaeb153ab7a7a849edc9c6e92f2ac5c709c6e39044a647971cf1fa5ebcb660c8
+plan14-root-reads-durability-3a-escrow.tsv d1cf6e6d51e2b3451a4f3343b6d1ab66374c4dcde6c6f9bb21b52ccb1cf98350
diff --git a/internal/provision/testdata/plan14-root-reads-durability-3a-escrow.tsv b/internal/provision/testdata/plan14-root-reads-durability-3a-escrow.tsv
new file mode 100644
index 000000000..0b81f4e37
--- /dev/null
+++ b/internal/provision/testdata/plan14-root-reads-durability-3a-escrow.tsv
@@ -0,0 +1,10 @@
+# Census overlay durability-3a-escrow, written by census-propose (#369). census-ruling-durability-3a-escrow, approved on #280 before the merge; the approval card is docs/superpowers/notes/census-proposal-durability-3a-escrow.md.
+# 0 body, 0 sites, 3 envelope: each changed unit re-frozen at its existing disposition with its claim appended.
+# 2 new dispositions: 0 reads re-frozen at their disposition with the claim, 1 new units frozen accepted-legacy, 1 quiet units retired while they read nothing, 0 other.
+@legacy 7520abf7fe01442d3fcca5cc9c46cd22346ae2ad193162ed8df7ba9371914028 internal/layout/inventory.go Inventory legacy accepted-legacy accepted-legacy;rev3=census-ruling-durability-3a-escrow;basis=durability 3a Task 1: new. One os.ReadDir of the host's inventory root, provision.InstanceDir(dataDir, host) nested or dataDir flat, after refusing a host that fails controlname.ValidHostShape and a layout that is neither flat nor nested; reads only the listing's names and types (DirEntry.IsDir), opens and follows nothing; flat ownership is the extras scan's own (hostEntries over knownHosts); each top-level name is classified by pubclass.Of, a pure function of the name. A missing directory is an empty inventory. No caller in this task; later tasks call it from the publisher. file:ReadDir@449 9662e465abb7f9c60e908952740384479009c9987c8a6ae65d98fb19cb3d4d7e
+internal/layout/inventory.go Inventory legacy accepted-legacy accepted-legacy;rev3=census-ruling-durability-3a-escrow;basis=durability 3a Task 1: new. One os.ReadDir of the host's inventory root, provision.InstanceDir(dataDir, host) nested or dataDir flat, after refusing a host that fails controlname.ValidHostShape and a layout that is neither flat nor nested; reads only the listing's names and types (DirEntry.IsDir), opens and follows nothing; flat ownership is the extras scan's own (hostEntries over knownHosts); each top-level name is classified by pubclass.Of, a pure function of the name. A missing directory is an empty inventory. No caller in this task; later tasks call it from the publisher. file:ReadDir@449 9662e465abb7f9c60e908952740384479009c9987c8a6ae65d98fb19cb3d4d7e
+@remove internal/layout/plan.go NestedPlatformNames
+@removed internal/layout/plan.go NestedPlatformNames H3 census-ruling-durability-3a-escrow;basis=durability 3a Task 1: now a one-line wrapper for pubclass.NestedPlatformNames, which builds the same set (byte-identical, checked before and after) from pubclass.FileBases and the same instancectl/instancekey names, without nestedFiles or rawInstanceDir; it never read anything, and reads nothing now
+@coverage internal/activator a9f6de4b8b6267b13a954ab27ceaa93ae811da0f88c1ea9d8ed817b64b1f51a8
+@coverage internal/layout 5d8b1d3bcd0b247e8088e4fb32bc26378ece37f41dc40f1d999e23913eccc9d0
+@coverage internal/layout/pubclass bd3938f002a5dca044378b71670e904736653d4914a8b1e06275e2b4dc79ed67