test: one-box witness reaches the instance start boundary after admission
Task 6 fix round 2 (Astra R2 P2-3, P3). TestManaged2B2OneBox configures the agent's ExecBackend as on a fleet box (served pools, the fleet bucket from host.env, the lease through a fake S3) and makes the same start attempt for the route Reconcile mints: refused with ErrTenantAdmission and no fleet-bucket request while joining, then the instance lease is taken after root admits the box. The console fixture sets CARLOS_SECRETS_PUBKEY.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 file changed,
+64
−6
internal/host/managed2b2_onebox_linux_test.go+64 −6
diff --git a/internal/host/managed2b2_onebox_linux_test.go b/internal/host/managed2b2_onebox_linux_test.go| index b00df7b05..8b93b54ff 100644 |
| --- a/internal/host/managed2b2_onebox_linux_test.go |
| +++ b/internal/host/managed2b2_onebox_linux_test.go |
| @@ -19,9 +19,11 @@ import ( |
| "bufio" |
| "bytes" |
| "context" |
| + "crypto/ecdh" |
| "crypto/ed25519" |
| "crypto/rand" |
| "crypto/sha256" |
| + "encoding/base64" |
| "encoding/hex" |
| "encoding/json" |
| "errors" |
| @@ -43,6 +45,7 @@ import ( |
| "github.com/carlosframework/platform/internal/console" |
| "github.com/carlosframework/platform/internal/edge" |
| "github.com/carlosframework/platform/internal/edgeproof" |
| + "github.com/carlosframework/platform/internal/edgesfile" |
| "github.com/carlosframework/platform/internal/fleetstore" |
| "github.com/carlosframework/platform/internal/managedboot" |
| "github.com/carlosframework/platform/internal/managedboot/boottest" |
| @@ -173,7 +176,8 @@ func newOneBoxWorld(t *testing.T) *oneBoxWorld { |
| w.cloud = &obCloud{Fake: compute.NewFake()} |
| cfg := console.Config{Origin: w.ts.URL, Keymail: "https://keymail.example", Releases: w.store, Registry: filepath.Join(dir, "registry.db"), |
| AlertSealKeyPath: filepath.Join(dir, "seal"), Key: priv, ReleasePub: pub, TunnelHost: mbtTunnelHost, |
| - ManagedCompute: w.cloud, ManagedStorage: &obStorage{Fake: fleetstore.NewFake()}, ManagedDeployment: "test"} |
| + ManagedCompute: w.cloud, ManagedStorage: &obStorage{Fake: fleetstore.NewFake()}, ManagedDeployment: "test", |
| + SecretsPub: obSecretsPub(t)} |
| if _, err = provision.WriteHostsState(ctx, w.store, provision.HostsState{Mode: provision.HostsModeIncomplete}, ""); err != nil { |
| t.Fatal(err) |
| } |
| @@ -233,10 +237,27 @@ func newOneBoxWorld(t *testing.T) *oneBoxWorld { |
| s3srv := httptest.NewServer(w.s3) |
| t.Cleanup(s3srv.Close) |
| t.Setenv("CARLOS_S3_ENDPOINT", s3srv.URL) |
| + // The instance lease's default-chain client: dummy keys, no files, no |
| + // metadata service; every request goes to the fake S3 above. |
| + none := filepath.Join(t.TempDir(), "none") |
| + for k, v := range map[string]string{"AWS_ACCESS_KEY_ID": "AKIDEXAMPLE", "AWS_SECRET_ACCESS_KEY": "example-secret", "AWS_SESSION_TOKEN": "", |
| + "AWS_PROFILE": "", "AWS_DEFAULT_PROFILE": "", "AWS_CONFIG_FILE": none, "AWS_SHARED_CREDENTIALS_FILE": none, "AWS_EC2_METADATA_DISABLED": "true"} { |
| + t.Setenv(k, v) |
| + } |
| w.bucket = release.NewDirStore(t.TempDir()) |
| return w |
| } |
| +// obSecretsPub is a deployment secrets public key (CARLOS_SECRETS_PUBKEY). |
| +func obSecretsPub(t *testing.T) string { |
| + t.Helper() |
| + k, err := ecdh.P256().GenerateKey(rand.Reader) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + return base64.StdEncoding.EncodeToString(k.PublicKey().Bytes()) |
| +} |
| + |
| // api calls a console CLI route as the member. |
| func (w *oneBoxWorld) api(method, path, body string) (int, []byte) { |
| w.t.Helper() |
| @@ -390,7 +411,13 @@ func (w *oneBoxWorld) agent() { |
| p.getenv = func(k string) string { return env[k] } |
| p.readCreds = func() ([]byte, error) { return os.ReadFile(w.box.path(managedboot.CredentialsPath)) } |
| w.reg = openTestRegistry(t) |
| - w.eb = &activator.ExecBackend{} |
| + // The production start path's backend as the agent configures it on a |
| + // fleet box: the pools this box serves and the fleet bucket the |
| + // instance lease lives in (host.env), reached through the fake S3. |
| + w.eb = &activator.ExecBackend{ |
| + ServedPools: func() edgesfile.PoolEvidence { return edgesfile.PoolEvidence(`["shop"]`) }, |
| + Cfg: activator.Config{Bucket: env["CARLOS_HIBERNATE_BUCKET"], Region: env["CARLOS_HIBERNATE_REGION"], Prefix: env["CARLOS_HIBERNATE_PREFIX"]}, |
| + } |
| w.svc = activator.New(activator.Config{}, w.eb, w.reg) |
| if w.edge, err = edge.New(w.reg, w.svc); err != nil { |
| t.Fatal(err) |
| @@ -512,15 +539,15 @@ func TestManaged2B2OneBox(t *testing.T) { |
| w.agent() |
| rec := w.shopRecord() |
| - rt := registry.Route{Host: rec.Host, Kind: "instance", App: "shop", Account: obAccount, Status: "ready", Hibernate: true, Socket: "/run/carlos/" + rec.Host + ".sock"} |
| + // The route Reconcile mints for the record (provision.RouteFor, its one |
| + // definition): the start attempt made before and after admission. |
| + rt := provision.RouteFor(rec, "/data", "", false, nil) |
| // Joining: nothing placed, nothing may start. |
| w.reconcile() |
| if got, _ := w.reg.Get(rec.Host); got != nil { |
| t.Fatal("placed before root's record") |
| } |
| - if _, err := w.eb.Acquire(w.ctx, rt); !errors.Is(err, activator.ErrTenantAdmission) { |
| - t.Fatalf("start allowed while joining: %v", err) |
| - } |
| + w.startRefused(rt) |
| // A minute of joining: heartbeat and probe from the box itself. |
| at := w.now.Add(time.Minute) |
| @@ -546,6 +573,7 @@ func TestManaged2B2OneBox(t *testing.T) { |
| if got, _ := w.reg.Get(rec.Host); got != nil || !w.join.Joining() { |
| t.Fatal("placed before root's record") |
| } |
| + w.startRefused(rt) |
| // The agent's ready leg: one read through the store door, relayed to |
| // root, which verifies and commits. |
| @@ -566,6 +594,36 @@ func TestManaged2B2OneBox(t *testing.T) { |
| if !w.svc.TenantAdmitted() || !w.eb.TenantStartAllowed(*got) { |
| t.Fatal("start still refused after admission") |
| } |
| + if got.Host != rt.Host || got.Pool != rt.Pool || got.Provisioned != rt.Provisioned || got.Kind != rt.Kind { |
| + t.Fatalf("minted route %+v differs from the attempted one %+v", got, rt) |
| + } |
| + // The same start attempt now reaches the start boundary and succeeds: |
| + // the instance's single-writer lease is taken in the fleet bucket. |
| + w.s3.take() |
| + l, err := w.eb.Acquire(w.ctx, *got) |
| + if err != nil || l == nil { |
| + t.Fatalf("start after admission: %v", err) |
| + } |
| + if calls := w.s3.take(); len(calls) == 0 { |
| + t.Fatal("the start path never reached the lease") |
| + } |
| + if err = l.Release(w.ctx); err != nil { |
| + t.Fatal(err) |
| + } |
| +} |
| + |
| +// startRefused is the workload-start invariant on a joining box: the start |
| +// attempt is refused with ErrTenantAdmission and never reaches the lease |
| +// (no fleet-bucket request), so no instance can start before root's record. |
| +func (w *oneBoxWorld) startRefused(rt registry.Route) { |
| + w.t.Helper() |
| + w.s3.take() |
| + if l, err := w.eb.Acquire(w.ctx, rt); l != nil || !errors.Is(err, activator.ErrTenantAdmission) { |
| + w.t.Fatalf("start allowed while joining: %v", err) |
| + } |
| + if calls := w.s3.take(); len(calls) != 0 { |
| + w.t.Fatalf("a joining box reached the start boundary: %v", calls) |
| + } |
| } |
| // TestManaged2B2KeyFailureStatus: the fleet bucket already holds a malformed |