| 1 | package provision |
| 2 | |
| 3 | import ( |
| 4 | "strings" |
| 5 | "testing" |
| 6 | ) |
| 7 | |
| 8 | func TestPlan14LegacyDeclarationCannotDisappear(t *testing.T) { |
| 9 | e := classifiedRootRead{rootReadEntry: rootReadEntry{File: "internal/host/agent.go", Unit: "systemctlStartUnit", Kinds: "file:Command@10", Digest: strings.Repeat("a", 64)}, Class: "legacy", Task: "accepted-legacy", Basis: "accepted-legacy;rev3=J1;basis=root-route"} |
| 10 | key := e.File + ":" + e.Unit |
| 11 | inv := rootReadInventory{Entries: map[string]classifiedRootRead{key: e}, Legacy: map[string]bool{rootReadLegacyFingerprint(e): true}, Frozen: map[string]classifiedRootRead{key: e}, Removed: map[string]string{}} |
| 12 | scan := rootReadScan{Declarations: map[string]string{key: e.Digest}} |
| 13 | if errs := checkRootReadDeclarations(scan, inv); len(errs) != 0 { |
| 14 | t.Fatal(errs) |
| 15 | } |
| 16 | delete(inv.Entries, key) |
| 17 | scan.Declarations[key] = strings.Repeat("b", 64) |
| 18 | if errs := checkRootReadDeclarations(scan, inv); len(errs) == 0 { |
| 19 | t.Fatal("changed declaration with no read sites and no TSV row escaped") |
| 20 | } |
| 21 | inv.Entries[key] = e |
| 22 | if errs := checkRootReadDeclarations(scan, inv); len(errs) == 0 { |
| 23 | t.Fatal("changed declaration body escaped frozen identity") |
| 24 | } |
| 25 | promoted := e |
| 26 | promoted.Class = "authority" |
| 27 | promoted.Task = "C" |
| 28 | promoted.Basis = "reviewed delegation" |
| 29 | promoted.Kinds = "" |
| 30 | promoted.Digest = scan.Declarations[key] |
| 31 | inv.Entries[key] = promoted |
| 32 | if errs := checkRootReadDeclarations(scan, inv); len(errs) != 0 { |
| 33 | t.Fatal(errs) |
| 34 | } |
| 35 | delete(scan.Declarations, key) |
| 36 | if errs := checkRootReadDeclarations(scan, inv); len(errs) == 0 { |
| 37 | t.Fatal("removed declaration needs explicit removal") |
| 38 | } |
| 39 | delete(inv.Entries, key) |
| 40 | inv.Removed[key] = "C; removed obsolete delegate after reviewed root authority conversion" |
| 41 | if errs := checkRootReadDeclarations(scan, inv); len(errs) != 0 { |
| 42 | t.Fatal(errs) |
| 43 | } |
| 44 | scan.Declarations[key] = e.Digest |
| 45 | if errs := checkRootReadDeclarations(scan, inv); len(errs) == 0 { |
| 46 | t.Fatal("removal disposition hid a surviving declaration") |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | func TestPlan14MovesOverlayPreservesLegacySeal(t *testing.T) { |
| 51 | root := censusRoot(t) |
| 52 | inv := rootReadInventory{Entries: map[string]classifiedRootRead{}, Coverage: map[string]string{}} |
| 53 | if err := loadRootReadInventory(root+"/internal/provision/testdata/plan14-root-reads.tsv", &inv, false); err != nil { |
| 54 | t.Fatal(err) |
| 55 | } |
| 56 | baseline := make(map[string]bool, len(inv.Legacy)) |
| 57 | for hash := range inv.Legacy { |
| 58 | baseline[hash] = true |
| 59 | } |
| 60 | if err := loadRootReadInventory(root+"/internal/provision/testdata/plan14-root-reads-moves.tsv", &inv, true); err != nil { |
| 61 | t.Fatal(err) |
| 62 | } |
| 63 | for hash := range baseline { |
| 64 | if !inv.Legacy[hash] { |
| 65 | t.Fatalf("overlay removed frozen identity %s", hash) |
| 66 | } |
| 67 | } |
| 68 | if got := rootReadLegacySeal(inv); got != "fddd1cfd0391db80770074c47156dca161c5618d0d92da08669aea2cc22dcf9e" { |
| 69 | t.Fatalf("overlay changed approved legacy set: %s", got) |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | func TestPlan14MergeOverlayPreservesLegacySeal(t *testing.T) { |
| 74 | root := censusRoot(t) |
| 75 | inv := rootReadInventory{Entries: map[string]classifiedRootRead{}, Coverage: map[string]string{}} |
| 76 | for i, name := range []string{"plan14-root-reads.tsv", "plan14-root-reads-moves.tsv"} { |
| 77 | if err := loadRootReadInventory(root+"/internal/provision/testdata/"+name, &inv, i > 0); err != nil { |
| 78 | t.Fatal(err) |
| 79 | } |
| 80 | } |
| 81 | original := make(map[string]bool, len(inv.Legacy)) |
| 82 | for hash := range inv.Legacy { |
| 83 | original[hash] = true |
| 84 | } |
| 85 | if err := loadRootReadInventory(root+"/internal/provision/testdata/plan14-root-reads-merge.tsv", &inv, true); err != nil { |
| 86 | t.Fatal(err) |
| 87 | } |
| 88 | for hash := range original { |
| 89 | if !inv.Legacy[hash] { |
| 90 | t.Fatalf("merge removed original freeze %s", hash) |
| 91 | } |
| 92 | } |
| 93 | const seal = "c88a37629c95dd397beeb95f5ef101438fa884ac04dc4435aa55387b897d393c" |
| 94 | if errs := checkRootReadLegacy(inv, seal); len(errs) != 0 { |
| 95 | t.Fatal(errs) |
| 96 | } |
| 97 | key := "internal/provision/reconcile.go:routeFor" |
| 98 | if inv.Removed[key] == "" { |
| 99 | t.Fatal("renamed declaration lost its explicit removal disposition") |
| 100 | } |
| 101 | if _, present := inv.Entries[key]; present { |
| 102 | t.Fatal("removed declaration still classified") |
| 103 | } |
| 104 | inv.Legacy[strings.Repeat("0", 64)] = true |
| 105 | if errs := checkRootReadLegacy(inv, seal); len(errs) == 0 { |
| 106 | t.Fatal("new freeze entry accepted without a ruling") |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | func TestPlan14Merge3OverlayPreservesLegacySeal(t *testing.T) { |
| 111 | root := censusRoot(t) |
| 112 | inv := rootReadInventory{Entries: map[string]classifiedRootRead{}, Coverage: map[string]string{}} |
| 113 | for i, name := range []string{"plan14-root-reads.tsv", "plan14-root-reads-moves.tsv", "plan14-root-reads-merge.tsv", "plan14-root-reads-fix1.tsv", "plan14-root-reads-fix2.tsv"} { |
| 114 | if err := loadRootReadInventory(root+"/internal/provision/testdata/"+name, &inv, i > 0); err != nil { |
| 115 | t.Fatal(err) |
| 116 | } |
| 117 | } |
| 118 | if errs := checkRootReadLegacy(inv, "c3351f27f6467fc33b319b36a7e64b75b2d992232f956d9c6243cc49e0c05396"); len(errs) != 0 { |
| 119 | t.Fatal(errs) |
| 120 | } |
| 121 | original := make(map[string]bool, len(inv.Legacy)) |
| 122 | for hash := range inv.Legacy { |
| 123 | original[hash] = true |
| 124 | } |
| 125 | if err := loadRootReadInventory(root+"/internal/provision/testdata/plan14-root-reads-merge3.tsv", &inv, true); err != nil { |
| 126 | t.Fatal(err) |
| 127 | } |
| 128 | for hash := range original { |
| 129 | if !inv.Legacy[hash] { |
| 130 | t.Fatalf("merge3 removed original freeze %s", hash) |
| 131 | } |
| 132 | } |
| 133 | if len(inv.Legacy) != len(original)+3 { |
| 134 | t.Fatal("merge ruling 3 permits exactly three new frozen declarations") |
| 135 | } |
| 136 | const seal = "65dba959f80cc47e9fd99be145ba8b24bb3b37ffaf77b47d1b9cc3e01da14b47" |
| 137 | if errs := checkRootReadLegacy(inv, seal); len(errs) != 0 { |
| 138 | t.Fatal(errs) |
| 139 | } |
| 140 | for _, key := range []string{"internal/host/instancekeys.go:backfillInstanceKeys", "internal/host/instancekeys.go:keyBackfillInSlot.BackfillInstanceKey", "internal/host/layoutleg.go:activatorStart.Run"} { |
| 141 | e := inv.Entries[key] |
| 142 | if e.Class != "legacy" || e.Task != "accepted-legacy" || !strings.HasPrefix(e.Basis, "accepted-legacy;rev3=merge-ruling-3;") { |
| 143 | t.Fatalf("wrong hotfix disposition: %+v", e) |
| 144 | } |
| 145 | } |
| 146 | if inv.Entries["internal/host/agent.go:runAgent"].Class != "authority" { |
| 147 | t.Fatal("runAgent lost kept authority") |
| 148 | } |
| 149 | inv.Legacy[strings.Repeat("0", 64)] = true |
| 150 | if errs := checkRootReadLegacy(inv, seal); len(errs) == 0 { |
| 151 | t.Fatal("unapproved legacy fingerprint accepted") |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | func TestPlan14Fix4OverlayPreservesLegacySeal(t *testing.T) { |
| 156 | root := censusRoot(t) |
| 157 | inv := rootReadInventory{Entries: map[string]classifiedRootRead{}, Coverage: map[string]string{}} |
| 158 | for i, name := range []string{"plan14-root-reads.tsv", "plan14-root-reads-moves.tsv", "plan14-root-reads-merge.tsv", "plan14-root-reads-fix1.tsv", "plan14-root-reads-fix2.tsv", "plan14-root-reads-merge3.tsv"} { |
| 159 | if err := loadRootReadInventory(root+"/internal/provision/testdata/"+name, &inv, i > 0); err != nil { |
| 160 | t.Fatal(err) |
| 161 | } |
| 162 | } |
| 163 | seal := rootReadLegacySeal(inv) |
| 164 | if err := loadRootReadInventory(root+"/internal/provision/testdata/plan14-root-reads-fix4.tsv", &inv, true); err != nil { |
| 165 | t.Fatal(err) |
| 166 | } |
| 167 | if errs := checkRootReadLegacy(inv, seal); len(errs) != 0 { |
| 168 | t.Fatal(errs) |
| 169 | } |
| 170 | if seal != "65dba959f80cc47e9fd99be145ba8b24bb3b37ffaf77b47d1b9cc3e01da14b47" { |
| 171 | t.Fatal("unexpected legacy seal", seal) |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | func TestPlan14Fix5OverlayPreservesLegacySeal(t *testing.T) { |
| 176 | root := censusRoot(t) |
| 177 | inv := rootReadInventory{Entries: map[string]classifiedRootRead{}, Coverage: map[string]string{}} |
| 178 | for i, name := range []string{"plan14-root-reads.tsv", "plan14-root-reads-moves.tsv", "plan14-root-reads-merge.tsv", "plan14-root-reads-fix1.tsv", "plan14-root-reads-fix2.tsv", "plan14-root-reads-merge3.tsv", "plan14-root-reads-fix4.tsv"} { |
| 179 | if err := loadRootReadInventory(root+"/internal/provision/testdata/"+name, &inv, i > 0); err != nil { |
| 180 | t.Fatal(err) |
| 181 | } |
| 182 | } |
| 183 | seal := rootReadLegacySeal(inv) |
| 184 | if err := loadRootReadInventory(root+"/internal/provision/testdata/plan14-root-reads-fix5.tsv", &inv, true); err != nil { |
| 185 | t.Fatal(err) |
| 186 | } |
| 187 | if err := loadRootReadInventory(root+"/internal/provision/testdata/plan14-root-reads-fix6.tsv", &inv, true); err != nil { |
| 188 | t.Fatal(err) |
| 189 | } |
| 190 | if errs := checkRootReadLegacy(inv, seal); len(errs) != 0 { |
| 191 | t.Fatal(errs) |
| 192 | } |
| 193 | if seal != "65dba959f80cc47e9fd99be145ba8b24bb3b37ffaf77b47d1b9cc3e01da14b47" { |
| 194 | t.Fatal("unexpected legacy seal", seal) |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | // Census ruling zddr3 (#272): the placement shim's overlay, loaded after fix6. |
| 199 | func TestPlan14Zddr3OverlayPreservesLegacySeal(t *testing.T) { |
| 200 | root := censusRoot(t) |
| 201 | inv := rootReadInventory{Entries: map[string]classifiedRootRead{}, Coverage: map[string]string{}} |
| 202 | for i, name := range []string{"plan14-root-reads.tsv", "plan14-root-reads-moves.tsv", "plan14-root-reads-merge.tsv", "plan14-root-reads-fix1.tsv", "plan14-root-reads-fix2.tsv", "plan14-root-reads-merge3.tsv", "plan14-root-reads-fix4.tsv", "plan14-root-reads-fix5.tsv", "plan14-root-reads-fix6.tsv"} { |
| 203 | if err := loadRootReadInventory(root+"/internal/provision/testdata/"+name, &inv, i > 0); err != nil { |
| 204 | t.Fatal(err) |
| 205 | } |
| 206 | } |
| 207 | if errs := checkRootReadLegacy(inv, "65dba959f80cc47e9fd99be145ba8b24bb3b37ffaf77b47d1b9cc3e01da14b47"); len(errs) != 0 { |
| 208 | t.Fatal(errs) |
| 209 | } |
| 210 | original := make(map[string]bool, len(inv.Legacy)) |
| 211 | for hash := range inv.Legacy { |
| 212 | original[hash] = true |
| 213 | } |
| 214 | if err := loadRootReadInventory(root+"/internal/provision/testdata/plan14-root-reads-zddr3.tsv", &inv, true); err != nil { |
| 215 | t.Fatal(err) |
| 216 | } |
| 217 | for hash := range original { |
| 218 | if !inv.Legacy[hash] { |
| 219 | t.Fatalf("zddr3 removed original freeze %s", hash) |
| 220 | } |
| 221 | } |
| 222 | if len(inv.Legacy) != len(original)+13 { |
| 223 | t.Fatal("census ruling zddr3 permits exactly thirteen new frozen declarations") |
| 224 | } |
| 225 | // Census ruling zddr3 seal: ten shim and VerifyPlacement rows plus three |
| 226 | // refreshed legacy rows (openCleanupAt, StartWorkerStaged, spawnChildFrom). |
| 227 | const seal = "c748e02bfe907a009ef42eb544b1a44fe813f4f7c13e454be3980aec4fade568" |
| 228 | if errs := checkRootReadLegacy(inv, seal); len(errs) != 0 { |
| 229 | t.Fatal(errs) |
| 230 | } |
| 231 | for key, e := range inv.Entries { |
| 232 | if strings.HasPrefix(key, "internal/cgroup/shim_linux.go:") || strings.HasPrefix(key, "internal/cgroup/verify_linux.go:") { |
| 233 | if e.Class != "legacy" || e.Task != "accepted-legacy" || !strings.HasPrefix(e.Basis, "accepted-legacy;rev3=census-ruling-zddr3;") { |
| 234 | t.Fatalf("wrong zddr3 disposition: %+v", e) |
| 235 | } |
| 236 | } |
| 237 | } |
| 238 | for _, key := range []string{"internal/cgroup/cgroup_linux.go:placementLive", "internal/cgroup/cgroup.go:Manager.startIn"} { |
| 239 | if !strings.HasPrefix(inv.Removed[key], "H3;census-ruling-zddr3: ") { |
| 240 | t.Fatalf("%s lost its census-ruling removal", key) |
| 241 | } |
| 242 | if _, present := inv.Entries[key]; present { |
| 243 | t.Fatalf("%s still classified", key) |
| 244 | } |
| 245 | } |
| 246 | inv.Legacy[strings.Repeat("0", 64)] = true |
| 247 | if errs := checkRootReadLegacy(inv, seal); len(errs) == 0 { |
| 248 | t.Fatal("unapproved legacy fingerprint accepted") |
| 249 | } |
| 250 | } |
| 251 | |
| 252 | // Census ruling zddr4 (zero-downtime deploys rev 19, Gate F, #272): the |
| 253 | // generation socket overlay, loaded after hotfix281. |
| 254 | func TestPlan14Zddr4OverlayPreservesLegacySeal(t *testing.T) { |
| 255 | root := censusRoot(t) |
| 256 | inv := rootReadInventory{Entries: map[string]classifiedRootRead{}, Coverage: map[string]string{}} |
| 257 | for i, name := range []string{"plan14-root-reads.tsv", "plan14-root-reads-moves.tsv", "plan14-root-reads-merge.tsv", "plan14-root-reads-fix1.tsv", "plan14-root-reads-fix2.tsv", "plan14-root-reads-merge3.tsv", "plan14-root-reads-fix4.tsv", "plan14-root-reads-fix5.tsv", "plan14-root-reads-fix6.tsv", "plan14-root-reads-zddr3.tsv", "plan14-root-reads-hotfix281.tsv"} { |
| 258 | if err := loadRootReadInventory(root+"/internal/provision/testdata/"+name, &inv, i > 0); err != nil { |
| 259 | t.Fatal(err) |
| 260 | } |
| 261 | } |
| 262 | if errs := checkRootReadLegacy(inv, "6da50872e15f7f396d23e5b1b2e044a73cd9e5c07d85c8e22252b0a1a5304bbd"); len(errs) != 0 { |
| 263 | t.Fatal(errs) |
| 264 | } |
| 265 | original := make(map[string]bool, len(inv.Legacy)) |
| 266 | for hash := range inv.Legacy { |
| 267 | original[hash] = true |
| 268 | } |
| 269 | if err := loadRootReadInventory(root+"/internal/provision/testdata/plan14-root-reads-zddr4.tsv", &inv, true); err != nil { |
| 270 | t.Fatal(err) |
| 271 | } |
| 272 | for hash := range original { |
| 273 | if !inv.Legacy[hash] { |
| 274 | t.Fatalf("zddr4 removed original freeze %s", hash) |
| 275 | } |
| 276 | } |
| 277 | if len(inv.Legacy) != len(original)+14 { |
| 278 | t.Fatal("census ruling zddr4 permits exactly fourteen new frozen declarations") |
| 279 | } |
| 280 | // Census ruling zddr4 seal: ten changed activator rows (startGenFrom, |
| 281 | // GenPaths, StartStaged, genTerminated, handlelessGenEmpty, |
| 282 | // failedWakeStopped, prepareAt, swapOverlap, foreignRow, |
| 283 | // holdAdmitLocked) plus four new ones (ExecBackend.GenLayout, |
| 284 | // SplitBackend.GenLayout, removeGenDir, swapLayout). |
| 285 | const seal = "e736a5e2652cc546db02c5a385ae7da9fa8a4313d3064f6b431642431974d65d" |
| 286 | if errs := checkRootReadLegacy(inv, seal); len(errs) != 0 { |
| 287 | t.Fatal(errs) |
| 288 | } |
| 289 | units := []string{ |
| 290 | "internal/activator/backend_exec.go:ExecBackend.startGenFrom", |
| 291 | "internal/activator/genbackend.go:ExecBackend.GenPaths", |
| 292 | "internal/activator/genbackend.go:ExecBackend.StartStaged", |
| 293 | "internal/activator/opset.go:Service.genTerminated", |
| 294 | "internal/activator/opset.go:Service.handlelessGenEmpty", |
| 295 | "internal/activator/opset.go:Service.failedWakeStopped", |
| 296 | "internal/activator/prepare.go:ExecBackend.prepareAt", |
| 297 | "internal/activator/swap.go:Service.swapOverlap", |
| 298 | "internal/activator/swaphold.go:Service.foreignRow", |
| 299 | "internal/activator/swaphold.go:Service.holdAdmitLocked", |
| 300 | "internal/activator/genbackend.go:ExecBackend.GenLayout", |
| 301 | "internal/activator/genbackend.go:SplitBackend.GenLayout", |
| 302 | "internal/activator/generations.go:removeGenDir", |
| 303 | "internal/activator/swaphold.go:Service.swapLayout", |
| 304 | } |
| 305 | const boundary = "Boundary: agent-side, running as carlos; generation socket directories under the agent's own /run/carlos tree; no root decision; no registry, /data, release or claim read beyond what the unit read before." |
| 306 | for _, key := range units { |
| 307 | e, ok := inv.Entries[key] |
| 308 | if !ok || e.Class != "legacy" || e.Task != "accepted-legacy" || !strings.HasPrefix(e.Basis, "accepted-legacy;rev3=census-ruling-zddr4;") || !strings.HasSuffix(e.Basis, boundary) { |
| 309 | t.Fatalf("wrong zddr4 disposition for %s: %+v", key, e) |
| 310 | } |
| 311 | if f, ok := inv.Frozen[key]; !ok || rootReadLegacyFingerprint(f) != rootReadLegacyFingerprint(e) { |
| 312 | t.Fatalf("%s is not frozen as classified", key) |
| 313 | } |
| 314 | } |
| 315 | inv.Legacy[strings.Repeat("0", 64)] = true |
| 316 | if errs := checkRootReadLegacy(inv, seal); len(errs) == 0 { |
| 317 | t.Fatal("unapproved legacy fingerprint accepted") |
| 318 | } |
| 319 | } |
| 320 | |
| 321 | // Census ruling 292 (amadan #292, platform-1e, extended): the edge-restart |
| 322 | // lease overlay, loaded after reserved285, the last overlay before it. |
| 323 | func TestPlan14Overlay292PreservesLegacySeal(t *testing.T) { |
| 324 | root := censusRoot(t) |
| 325 | inv := rootReadInventory{Entries: map[string]classifiedRootRead{}, Coverage: map[string]string{}} |
| 326 | for i, name := range []string{"plan14-root-reads.tsv", "plan14-root-reads-moves.tsv", "plan14-root-reads-merge.tsv", "plan14-root-reads-fix1.tsv", "plan14-root-reads-fix2.tsv", "plan14-root-reads-merge3.tsv", "plan14-root-reads-fix4.tsv", "plan14-root-reads-fix5.tsv", "plan14-root-reads-fix6.tsv", "plan14-root-reads-zddr3.tsv", "plan14-root-reads-hotfix281.tsv", "plan14-root-reads-zddr4.tsv", "plan14-root-reads-reserved285.tsv"} { |
| 327 | if err := loadRootReadInventory(root+"/internal/provision/testdata/"+name, &inv, i > 0); err != nil { |
| 328 | t.Fatal(err) |
| 329 | } |
| 330 | } |
| 331 | if errs := checkRootReadLegacy(inv, "e736a5e2652cc546db02c5a385ae7da9fa8a4313d3064f6b431642431974d65d"); len(errs) != 0 { |
| 332 | t.Fatal(errs) |
| 333 | } |
| 334 | original := make(map[string]bool, len(inv.Legacy)) |
| 335 | for hash := range inv.Legacy { |
| 336 | original[hash] = true |
| 337 | } |
| 338 | if err := loadRootReadInventory(root+"/internal/provision/testdata/plan14-root-reads-292.tsv", &inv, true); err != nil { |
| 339 | t.Fatal(err) |
| 340 | } |
| 341 | for hash := range original { |
| 342 | if !inv.Legacy[hash] { |
| 343 | t.Fatalf("292 removed original freeze %s", hash) |
| 344 | } |
| 345 | } |
| 346 | if len(inv.Legacy) != len(original)+12 { |
| 347 | t.Fatal("census ruling 292 permits exactly twelve new frozen declarations") |
| 348 | } |
| 349 | // Census ruling 292 seal: eight changed activator rows (begin, |
| 350 | // BeginSidecarRequest, doWake, sweepOnce, wake, spawnUnitFrom, |
| 351 | // cleanupFailedWake, reapUnprovenWake), three new proof units |
| 352 | // (ExecBackend.LegacyRunGone, SplitBackend.LegacyRunGone, |
| 353 | // legacyRunGone) and instance-control's Server declaration. |
| 354 | const seal = "3b2506dd2ab3986d0df0ceda7f596e5a46ea4d1dfbc17b1d0fd8d5f176e8038d" |
| 355 | if errs := checkRootReadLegacy(inv, seal); len(errs) != 0 { |
| 356 | t.Fatal(errs) |
| 357 | } |
| 358 | agent := []string{ |
| 359 | "internal/activator/activator.go:Service.BeginSidecarRequest", |
| 360 | "internal/activator/activator.go:Service.begin", |
| 361 | "internal/activator/activator.go:Service.doWake", |
| 362 | "internal/activator/activator.go:Service.sweepOnce", |
| 363 | "internal/activator/activator.go:Service.wake", |
| 364 | "internal/activator/backend_exec.go:ExecBackend.spawnUnitFrom", |
| 365 | "internal/activator/backend_exec.go:ExecBackend.LegacyRunGone", |
| 366 | "internal/activator/backend_unit.go:SplitBackend.LegacyRunGone", |
| 367 | "internal/activator/containment.go:Service.legacyRunGone", |
| 368 | "internal/activator/maintenance.go:Service.cleanupFailedWake", |
| 369 | "internal/activator/opset.go:Service.reapUnprovenWake", |
| 370 | } |
| 371 | const boundary = "Boundary: agent-side shutdown gates running as carlos; they refuse or stop new work once shutdown begins, and a cancelled wake releases its lease; no new read and no root decision; plus the legacy run unit's termination proof (systemctl show state and cgroup.events, as the exit observer reads), and a retried conditional lease delete of the same record." |
| 372 | const rootClause = "Boundary: root's legacy start/stop serialisation per host: a stop fences, cancels and joins that host's in-flight legacy starts before its systemd stop; stop-only direction, no new start, path or read." |
| 373 | check := func(key, rev3, suffix string) { |
| 374 | t.Helper() |
| 375 | e, ok := inv.Entries[key] |
| 376 | if !ok || e.Class != "legacy" || e.Task != "accepted-legacy" || !strings.HasPrefix(e.Basis, "accepted-legacy;rev3="+rev3+";") || !strings.HasSuffix(e.Basis, suffix) { |
| 377 | t.Fatalf("wrong 292 disposition for %s: %+v", key, e) |
| 378 | } |
| 379 | if f, ok := inv.Frozen[key]; !ok || rootReadLegacyFingerprint(f) != rootReadLegacyFingerprint(e) { |
| 380 | t.Fatalf("%s is not frozen as classified", key) |
| 381 | } |
| 382 | } |
| 383 | for _, key := range agent { |
| 384 | check(key, "census-ruling-292", boundary) |
| 385 | } |
| 386 | check("internal/instancectl/server.go:type Server", "census-ruling-292,J2,J4", rootClause) |
| 387 | for _, key := range []string{"internal/activator/activator.go:Service.begin", "internal/activator/activator.go:Service.wake"} { |
| 388 | if !strings.Contains(inv.Entries[key].Basis, "claim wakes are cancelled at shutdown with swaps off, matching the fence path; stop-only, and the lease is released.") { |
| 389 | t.Fatalf("%s lacks the claims note", key) |
| 390 | } |
| 391 | } |
| 392 | inv.Legacy[strings.Repeat("0", 64)] = true |
| 393 | if errs := checkRootReadLegacy(inv, seal); len(errs) == 0 { |
| 394 | t.Fatal("unapproved legacy fingerprint accepted") |
| 395 | } |
| 396 | } |
| 397 | |
| 398 | // Census ruling carlos-run (Plan 14 controller, 2026-10-14): the carlos-run |
| 399 | // branch's overlay (carlos run, #259), loaded last, after census ruling |
| 400 | // owed. It keeps every earlier freeze, adds exactly 59 frozen declarations |
| 401 | // (the 58 it was ruled with, and type Server as census ruling 292 classed |
| 402 | // it), and every row it writes names the ruling. The two units that still exist and no longer |
| 403 | // read are retired under the ruling's name, in the form zddr3 used. |
| 404 | func TestPlan14CarlosRunOverlayPreservesLegacySeal(t *testing.T) { |
| 405 | root := censusRoot(t) |
| 406 | inv := rootReadInventory{Entries: map[string]classifiedRootRead{}, Coverage: map[string]string{}} |
| 407 | for i, name := range []string{"plan14-root-reads.tsv", "plan14-root-reads-moves.tsv", "plan14-root-reads-merge.tsv", "plan14-root-reads-fix1.tsv", "plan14-root-reads-fix2.tsv", "plan14-root-reads-merge3.tsv", "plan14-root-reads-fix4.tsv", "plan14-root-reads-fix5.tsv", "plan14-root-reads-fix6.tsv", "plan14-root-reads-zddr3.tsv", "plan14-root-reads-hotfix281.tsv", "plan14-root-reads-zddr4.tsv", "plan14-root-reads-reserved285.tsv", "plan14-root-reads-292.tsv", "plan14-root-reads-census-ruling-275.tsv", "plan14-root-reads-census-ruling-owed.tsv"} { |
| 408 | if err := loadRootReadInventory(root+"/internal/provision/testdata/"+name, &inv, i > 0); err != nil { |
| 409 | t.Fatal(err) |
| 410 | } |
| 411 | } |
| 412 | if errs := checkRootReadLegacy(inv, "79db70c4c396457e563bf792027f98eeed7cef3dc54fff8abedb025e7db1dfbb"); len(errs) != 0 { |
| 413 | t.Fatal(errs) |
| 414 | } |
| 415 | original := make(map[string]bool, len(inv.Legacy)) |
| 416 | for hash := range inv.Legacy { |
| 417 | original[hash] = true |
| 418 | } |
| 419 | before := make(map[string]classifiedRootRead, len(inv.Entries)) |
| 420 | for key, e := range inv.Entries { |
| 421 | before[key] = e |
| 422 | } |
| 423 | if err := loadRootReadInventory(root+"/internal/provision/testdata/plan14-root-reads-carlos-run.tsv", &inv, true); err != nil { |
| 424 | t.Fatal(err) |
| 425 | } |
| 426 | for hash := range original { |
| 427 | if !inv.Legacy[hash] { |
| 428 | t.Fatalf("carlos-run removed original freeze %s", hash) |
| 429 | } |
| 430 | } |
| 431 | if len(inv.Legacy) != len(original)+59 { |
| 432 | t.Fatalf("census ruling carlos-run permits exactly 59 new frozen declarations, not %d", len(inv.Legacy)-len(original)) |
| 433 | } |
| 434 | // Census ruling carlos-run seal: 54 service-user and CLI rows, the four |
| 435 | // instance-control rows that extend the J4 seed pattern, and type |
| 436 | // Server re-digested as census ruling 292 classed it. |
| 437 | const seal = "96e521e60dfc0b55e2bc08adbb7a7682a607a30599a8cf66e7c5689d6cf7fe5a" |
| 438 | if errs := checkRootReadLegacy(inv, seal); len(errs) != 0 { |
| 439 | t.Fatal(errs) |
| 440 | } |
| 441 | written := 0 |
| 442 | for key, e := range inv.Entries { |
| 443 | if e == before[key] { |
| 444 | continue |
| 445 | } |
| 446 | written++ |
| 447 | if !strings.Contains(e.Basis, "rev3=census-ruling-carlos-run;") { |
| 448 | t.Fatalf("%s does not name the ruling: %+v", key, e) |
| 449 | } |
| 450 | if e.Class == "legacy" && (e.Task != "accepted-legacy" || !strings.HasPrefix(e.Basis, "accepted-legacy;rev3=census-ruling-carlos-run;")) { |
| 451 | t.Fatalf("wrong carlos-run disposition: %+v", e) |
| 452 | } |
| 453 | } |
| 454 | if written != 61 { |
| 455 | t.Fatalf("census ruling carlos-run writes 61 rows, not %d", written) |
| 456 | } |
| 457 | // Main's authority rows keep their class and family. |
| 458 | for key, task := range map[string]string{"internal/host/agent.go:runAgent": "B,C,D,F", "internal/host/agent.go:fastConvergeLoop": "B3"} { |
| 459 | if e := inv.Entries[key]; e.Class != "authority" || e.Task != task { |
| 460 | t.Fatalf("%s lost main's authority: %+v", key, e) |
| 461 | } |
| 462 | } |
| 463 | if e := inv.Entries["internal/instancectl/server.go:type Server"]; e.Class != "legacy" || e.Task != "accepted-legacy" { |
| 464 | t.Fatalf("type Server lost census ruling 292's disposition: %+v", e) |
| 465 | } |
| 466 | for _, key := range []string{"apimode.go:apiSession.getJSON", "internal/instancectl/hardening.go:ensureExe"} { |
| 467 | if !strings.HasPrefix(inv.Removed[key], "H3;census-ruling-carlos-run: ") { |
| 468 | t.Fatalf("%s lost its census-ruling removal", key) |
| 469 | } |
| 470 | if _, present := inv.Entries[key]; present { |
| 471 | t.Fatalf("%s still classified", key) |
| 472 | } |
| 473 | } |
| 474 | inv.Legacy[strings.Repeat("0", 64)] = true |
| 475 | if errs := checkRootReadLegacy(inv, seal); len(errs) == 0 { |
| 476 | t.Fatal("unapproved legacy fingerprint accepted") |
| 477 | } |
| 478 | } |
| 479 | |
| 480 | // Census ruling seeded-instances (Plan 14 controller, 2026-10-14). The |
| 481 | // overlay is loaded last, after carlos-run's. This pins what the ruling |
| 482 | // writes: 100 new frozen fingerprints, 115 rows, every basis naming the |
| 483 | // ruling, main's authority rows kept, the ruled classes, nothing removed. |
| 484 | // Three rows are the census ruling 292fix block (Plan 14 controller, |
| 485 | // 2026-10-15), an extension of census ruling 292 for the seeded pre-land |
| 486 | // review's P2: Service.doWake (moved there from the seeded rows) and |
| 487 | // #292's cleanupFailedWake and reapUnprovenWake. |
| 488 | func TestPlan14SeededInstancesOverlayPreservesLegacySeal(t *testing.T) { |
| 489 | root := censusRoot(t) |
| 490 | inv := rootReadInventory{Entries: map[string]classifiedRootRead{}, Coverage: map[string]string{}} |
| 491 | for i, name := range []string{"plan14-root-reads.tsv", "plan14-root-reads-moves.tsv", "plan14-root-reads-merge.tsv", "plan14-root-reads-fix1.tsv", "plan14-root-reads-fix2.tsv", "plan14-root-reads-merge3.tsv", "plan14-root-reads-fix4.tsv", "plan14-root-reads-fix5.tsv", "plan14-root-reads-fix6.tsv", "plan14-root-reads-zddr3.tsv", "plan14-root-reads-hotfix281.tsv", "plan14-root-reads-zddr4.tsv", "plan14-root-reads-reserved285.tsv", "plan14-root-reads-292.tsv", "plan14-root-reads-census-ruling-275.tsv", "plan14-root-reads-census-ruling-owed.tsv", "plan14-root-reads-carlos-run.tsv"} { |
| 492 | if err := loadRootReadInventory(root+"/internal/provision/testdata/"+name, &inv, i > 0); err != nil { |
| 493 | t.Fatal(err) |
| 494 | } |
| 495 | } |
| 496 | if errs := checkRootReadLegacy(inv, "96e521e60dfc0b55e2bc08adbb7a7682a607a30599a8cf66e7c5689d6cf7fe5a"); len(errs) != 0 { |
| 497 | t.Fatal(errs) |
| 498 | } |
| 499 | original := make(map[string]bool, len(inv.Legacy)) |
| 500 | for hash := range inv.Legacy { |
| 501 | original[hash] = true |
| 502 | } |
| 503 | before := make(map[string]classifiedRootRead, len(inv.Entries)) |
| 504 | for key, e := range inv.Entries { |
| 505 | before[key] = e |
| 506 | } |
| 507 | removed := len(inv.Removed) |
| 508 | if err := loadRootReadInventory(root+"/internal/provision/testdata/plan14-root-reads-seeded-instances.tsv", &inv, true); err != nil { |
| 509 | t.Fatal(err) |
| 510 | } |
| 511 | for hash := range original { |
| 512 | if !inv.Legacy[hash] { |
| 513 | t.Fatalf("seeded-instances removed original freeze %s", hash) |
| 514 | } |
| 515 | } |
| 516 | if len(inv.Legacy) != len(original)+100 { |
| 517 | t.Fatalf("the seeded-instances overlay adds exactly 100 frozen fingerprints, not %d", len(inv.Legacy)-len(original)) |
| 518 | } |
| 519 | // Census ruling seeded-instances seal: 96 service-user and CLI rows plus |
| 520 | // activationGuard and activationRule, accepted legacy (J1) as on main, |
| 521 | // less doWake, which moved to the 292fix block; and that block's |
| 522 | // three rows. |
| 523 | const seal = "10e024eccd584f40b64e959a105c551302585e3e14e55104fc250dae5960898a" |
| 524 | if errs := checkRootReadLegacy(inv, seal); len(errs) != 0 { |
| 525 | t.Fatal(errs) |
| 526 | } |
| 527 | proposed := map[string]bool{ |
| 528 | "internal/activator/activator.go:Service.doWake": true, |
| 529 | "internal/activator/maintenance.go:Service.cleanupFailedWake": true, |
| 530 | "internal/activator/opset.go:Service.reapUnprovenWake": true, |
| 531 | } |
| 532 | written := 0 |
| 533 | for key, e := range inv.Entries { |
| 534 | if e == before[key] { |
| 535 | continue |
| 536 | } |
| 537 | written++ |
| 538 | marker := "census-ruling-seeded-instances" |
| 539 | if proposed[key] { |
| 540 | // Main's rows, changed by the pre-land fix: their class is |
| 541 | // kept, under census ruling 292fix. |
| 542 | marker = "census-ruling-292fix" |
| 543 | if before[key].Class != "legacy" { |
| 544 | t.Fatalf("%s was %s on main; the fix's block keeps only legacy rows", key, before[key].Class) |
| 545 | } |
| 546 | } |
| 547 | if !strings.Contains(e.Basis, "rev3="+marker+";") { |
| 548 | t.Fatalf("%s does not name %s: %+v", key, marker, e) |
| 549 | } |
| 550 | if e.Class == "legacy" && (e.Task != "accepted-legacy" || !strings.HasPrefix(e.Basis, "accepted-legacy;rev3="+marker+";")) { |
| 551 | t.Fatalf("wrong seeded-instances disposition: %+v", e) |
| 552 | } |
| 553 | if strings.Contains(e.Basis, "NEEDS RULING") { |
| 554 | t.Fatalf("%s still waits for a ruling: %+v", key, e) |
| 555 | } |
| 556 | } |
| 557 | if written != 115 { |
| 558 | t.Fatalf("the seeded-instances overlay writes 115 rows, not %d", written) |
| 559 | } |
| 560 | // Main's authority rows keep their class and family. rootJudgeMovesPrev |
| 561 | // is the body of main's rootJudgePrev under a new name and carries its |
| 562 | // family; rootJudgePrev is still declared and reads nothing. The ruled |
| 563 | // rows: the seeds floor's root readers F,J4, the two deny-only |
| 564 | // activation inputs G, and Upsert's moved code E3. |
| 565 | for key, task := range map[string]string{ |
| 566 | "internal/host/agent.go:runAgent": "B,C,D,F", |
| 567 | "internal/host/movespass.go:armPhase1": "B2,C", |
| 568 | "internal/provision/reconcile.go:RouteFor": "C,E3", |
| 569 | "internal/registry/registry.go:Registry.Upsert": "E3", |
| 570 | "internal/host/units/carlos-system-recover.service:external": "F,J4", |
| 571 | "internal/host/units/carlos-system-update.service:external": "F,J4", |
| 572 | "internal/host/movesfloor.go:rootJudgeMovesPrev": "F,J4", |
| 573 | "internal/host/movesfloor.go:rootJudgePrev": "F,J4", |
| 574 | "internal/host/seedsfloor.go:readLocalSeedsFloor": "F,J4", |
| 575 | "internal/host/seedsfloor.go:judgeSeedsPrev": "F,J4", |
| 576 | "internal/host/seedsfloor.go:rootJudgeSeedsPrev": "F,J4", |
| 577 | "internal/hostops/backfill_seeds.go:CollectCensusSeeds": "G", |
| 578 | "internal/registry/importjournal.go:Registry.ImportJournalHosts": "G", |
| 579 | "internal/registry/registry.go:normalizeRoute": "E3", |
| 580 | "internal/registry/registry.go:routeArgs": "E3", |
| 581 | } { |
| 582 | if e := inv.Entries[key]; e.Class != "authority" || e.Task != task { |
| 583 | t.Fatalf("%s lost its authority: %+v", key, e) |
| 584 | } |
| 585 | } |
| 586 | for _, key := range []string{"internal/host/systemapply.go:systemApplier.activationGuard", "internal/host/systemapply.go:systemApplier.activationRule"} { |
| 587 | if e := inv.Entries[key]; e.Class != "legacy" || e.Task != "accepted-legacy" { |
| 588 | t.Fatalf("%s is not accepted legacy, as on main: %+v", key, e) |
| 589 | } |
| 590 | } |
| 591 | if e := inv.Entries["internal/host/movesfloor.go:rootJudgePrev"]; e.Kinds != "" { |
| 592 | t.Fatalf("rootJudgePrev is recorded with read sites: %+v", e) |
| 593 | } |
| 594 | if len(inv.Removed) != removed { |
| 595 | t.Fatalf("census ruling seeded-instances removes nothing, not %d declarations", len(inv.Removed)-removed) |
| 596 | } |
| 597 | inv.Legacy[strings.Repeat("0", 64)] = true |
| 598 | if errs := checkRootReadLegacy(inv, seal); len(errs) == 0 { |
| 599 | t.Fatal("unapproved legacy fingerprint accepted") |
| 600 | } |
| 601 | } |
| 602 | |
| 603 | func TestPlan14SeedOverlayPreservesLegacySeal(t *testing.T) { |
| 604 | root := censusRoot(t) |
| 605 | inv := rootReadInventory{Entries: map[string]classifiedRootRead{}, Coverage: map[string]string{}} |
| 606 | for i, name := range []string{"plan14-root-reads.tsv", "plan14-root-reads-moves.tsv", "plan14-root-reads-merge.tsv", "plan14-root-reads-fix1.tsv", "plan14-root-reads-fix2.tsv", "plan14-root-reads-merge3.tsv", "plan14-root-reads-fix4.tsv", "plan14-root-reads-fix5.tsv", "plan14-root-reads-fix6.tsv", "plan14-root-reads-zddr3.tsv", "plan14-root-reads-hotfix281.tsv", "plan14-root-reads-zddr4.tsv", "plan14-root-reads-reserved285.tsv", "plan14-root-reads-292.tsv", "plan14-root-reads-census-ruling-275.tsv", "plan14-root-reads-census-ruling-owed.tsv", "plan14-root-reads-carlos-run.tsv", "plan14-root-reads-seeded-instances.tsv", "plan14-root-reads-hostfiles-cap-236.tsv", "plan14-root-reads-moves-overcap-cut-236.tsv"} { |
| 607 | if err := loadRootReadInventory(root+"/internal/provision/testdata/"+name, &inv, i > 0); err != nil { |
| 608 | t.Fatal(err) |
| 609 | } |
| 610 | } |
| 611 | const seal = "fc38db001ebd8825709a8ca9c41cc0e8f165c1b1967e5967347dc9bd3556afec" |
| 612 | if errs := checkRootReadLegacy(inv, seal); len(errs) != 0 { |
| 613 | t.Fatal(errs) |
| 614 | } |
| 615 | before := len(inv.Legacy) |
| 616 | if err := loadRootReadInventory(root+"/internal/provision/testdata/plan14-root-reads-seed.tsv", &inv, true); err != nil { |
| 617 | t.Fatal(err) |
| 618 | } |
| 619 | if len(inv.Legacy) != before+7 { |
| 620 | t.Fatal("FS-R6, FS-R10 and FS-R11 preserve exactly seven additional legacy fingerprints") |
| 621 | } |
| 622 | if errs := checkRootReadLegacy(inv, "624e96c0f0fd397d09575e807f7347f86cbcb109b4b713eb8369f0b64622e483"); len(errs) != 0 { |
| 623 | t.Fatal(errs) |
| 624 | } |
| 625 | for _, key := range []string{"internal/activator/servingretry.go:ServingRetries.Wrap", "internal/activator/servingretry.go:ServingRetries.settle", "internal/park/local.go:Local.RetireSuperseded"} { |
| 626 | if e := inv.Entries[key]; e.Class != "legacy" || e.Task != "accepted-legacy" || !strings.Contains(e.Basis, "census-ruling-FS-R11") { |
| 627 | t.Fatalf("own-CAS threading changed legacy authority %s: %+v", key, e) |
| 628 | } |
| 629 | } |
| 630 | // FS-R6 keeps these existing legacy classes; the seed cannot promote them. |
| 631 | for _, key := range []string{"internal/activator/activator.go:Service.sweepOnce", "internal/activator/servingretry.go:ServingRetries.Wrap", "internal/host/relocationflush.go:ReleaseFlushFiles.Flush"} { |
| 632 | if e := inv.Entries[key]; e.Class != "legacy" || e.Task != "accepted-legacy" || !strings.Contains(e.Basis, "census-ruling-FS-R6") { |
| 633 | t.Fatalf("unruled legacy disposition %s: %+v", key, e) |
| 634 | } |
| 635 | } |
| 636 | if e := inv.Entries["internal/lease/leasetest/s3server.go:NewS3Server"]; e.Class != "legacy" || !strings.Contains(e.Basis, "census-ruling-FS-R10") { |
| 637 | t.Fatal("test S3 fixture lost its legacy ruling", e) |
| 638 | } |
| 639 | if e := inv.Entries["internal/host/claimwakeassembly.go:ClaimWakeAssembly.Build"]; e.Task != "C,G,J1,J4" { |
| 640 | t.Fatal("wake assembly lost its owners", e.Task) |
| 641 | } |
| 642 | for _, key := range []string{ |
| 643 | "internal/host/claimconstruction.go:OpenProductionClaimAssembly", |
| 644 | "internal/host/claimproduction.go:ProductionClaimOwnerProvider.OpenClaimOwners", |
| 645 | "internal/host/claimowners.go:checkClaimServingSources", |
| 646 | "internal/host/claimowners.go:claimServingOwners.serving", |
| 647 | "internal/host/claimwakeassembly.go:ClaimWakeAssembly.Build", |
| 648 | "internal/hostbox/restore.go:ColdRestore.Install", |
| 649 | "internal/hostbox/restore.go:ColdRestore.InstallEmpty", |
| 650 | "internal/hostguard/writerstop.go:Guard.CompletedServingStops", |
| 651 | } { |
| 652 | e, ok := inv.Entries[key] |
| 653 | if !ok || e.Class != "authority" || !strings.HasPrefix(e.Basis, "rev3=PROPOSED-seed;") || !rootReadKeptTask(e.Task) { |
| 654 | t.Fatalf("unproposed or unowned seed authority %s: %+v", key, e) |
| 655 | } |
| 656 | } |
| 657 | } |
| 658 | |