Skip to content
4 changes: 2 additions & 2 deletions src/lib/onboard/managed-bootstrap/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ work completes exact restore and cleanup; and shared-state-committed work
completes exact backup cleanup and commit. Recovery persists an identity-bound
finalization receipt before removing the active journal, is idempotent across
another interruption, and returns normalized, provider-owned receipts in stable
identity order. Mutable OpenShell names are read only to detect ownership reuse,
and unsafe name-only deletion returns a typed retention error. Multi-process
identity order. The code reads mutable OpenShell names only to detect ownership
reuse, and unsafe name-only deletion returns a typed retention error. Multi-process
lease/arbitration remains an explicit production-activation gate. Activation
must also inject the selected gateway's canonical state root.

Expand Down
43 changes: 43 additions & 0 deletions src/lib/onboard/managed-bootstrap/adapter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
type ManagedBootstrapAuthorityStore,
type ManagedBootstrapCompletionReceipt,
type ManagedBootstrapCreateReceipt,
type ManagedBootstrapDurablePreparationReceipt,
type ManagedBootstrapFinalizationReceipt,
type ManagedBootstrapHeldWorkloadHandle,
type ManagedBootstrapObservedSnapshot,
Expand All @@ -27,7 +28,10 @@ import {
prepareManagedBootstrapSequence,
recoverManagedBootstrapTransactions,
renderManagedBootstrapHeldCommand,
sameManagedBootstrapCompletionReceipt,
sameManagedBootstrapDurablePreparationReceipt,
} from "./adapter";
import { reverseKeys } from "./managed-bootstrap-test-fixture";

const IDENTITY = "1".repeat(64);
const CONFIG_ID = `sha256:${"2".repeat(64)}`;
Expand Down Expand Up @@ -354,6 +358,45 @@ async function captureFailure<T>(promise: Promise<T>) {
}

describe("managed bootstrap adapter contract", () => {
it("compares provider-neutral durable receipts by canonical value", () => {
const handle = handleFor(requestFor("hermes"));
const preparation: ManagedBootstrapDurablePreparationReceipt = {
schemaVersion: MANAGED_BOOTSTRAP_SCHEMA_VERSION,
sandbox: handle.sandbox,
bootstrapIdentity: handle.bootstrapIdentity,
authorityFingerprint: "a".repeat(64),
recordId: "mxc-durable-authority",
recordedAt: "2026-07-29T12:00:30.000Z",
};
const reorderedPreparation = reverseKeys({
...preparation,
sandbox: reverseKeys({ ...preparation.sandbox }),
});
expect(sameManagedBootstrapDurablePreparationReceipt(preparation, reorderedPreparation)).toBe(
true,
);
expect(
sameManagedBootstrapDurablePreparationReceipt(preparation, {
...reorderedPreparation,
recordId: "changed-authority",
}),
).toBe(false);

const completion = completionFor(requestFor("hermes"), handle);
const reorderedCompletion = reverseKeys({
...completion,
image: reverseKeys({ ...completion.image }),
sandbox: reverseKeys({ ...completion.sandbox }),
});
expect(sameManagedBootstrapCompletionReceipt(completion, reorderedCompletion)).toBe(true);
expect(
sameManagedBootstrapCompletionReceipt(completion, {
...reorderedCompletion,
transactionPending: false,
}),
).toBe(false);
});

it.each(
MANAGED_STARTUP_AGENTS,
)("prepares, durably records, and only then activates %s through a provider-neutral adapter", async (agent) => {
Expand Down
16 changes: 16 additions & 0 deletions src/lib/onboard/managed-bootstrap/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,22 @@ function canonicalJson(value: unknown): string {
.join(",")}}`;
}

/** Compare durable provider receipts by canonical value, independent of object key order. */
export function sameManagedBootstrapDurablePreparationReceipt(
left: ManagedBootstrapDurablePreparationReceipt,
right: ManagedBootstrapDurablePreparationReceipt,
): boolean {
return canonicalJson(left) === canonicalJson(right);
}

/** Compare completion receipts by canonical value, independent of object key order. */
export function sameManagedBootstrapCompletionReceipt(
left: ManagedBootstrapCompletionReceipt,
right: ManagedBootstrapCompletionReceipt,
): boolean {
return canonicalJson(left) === canonicalJson(right);
}

export function assertManagedBootstrapIdentity(value: string): void {
if (!SHA256_RE.test(value)) {
protocolFail("identity must be 32 random bytes encoded as lowercase hex");
Expand Down
Loading
Loading