483bc68a94
Enable evolution by default for source-backed workspaces. Add stable conformance ownership, semantic-major review, candidate typechecking, and durable fenced cutover with explicit migrations and forward recovery. Independently supervise package runtimes so unchanged resource owners keep their processes and connections across cutover. Add scoped invocation authority, resource sessions, and typed callback rebinding. Wire opaque object references through generated bindings and RPCs. Add canonical relationship sets, keyed maps, and ordered lists with scoped transactional mutations, revision checks, and inverse consistency. Support planned cascade deletion, protection, tombstones, and lifecycle foundations. Add journaled structural edits, package/function/migration scaffolding, managed repository creation, and resumable bottom-up dependency pin publication. Document lifetime boundaries, revision pinning, prototype compatibility policy, commands, and deferred work. Validate with 210 tests, user-systemd process/connection continuity, generated-package TypeScript checks, and Nix host/protocol checks. TTL handoff, physical reclamation, general multi-step migrations, and root-systemd migration isolation acceptance remain deferred.
279 lines
10 KiB
TypeScript
279 lines
10 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import { test } from "node:test";
|
|
import {
|
|
compileWorkspaceRevision,
|
|
computeCapabilityClosure,
|
|
resolveOperationPlan,
|
|
validateWorkspaceRevision,
|
|
valueType,
|
|
type CapabilityValidationIssueCode,
|
|
type WorkspaceRevision,
|
|
} from "../src/capability-model/index.js";
|
|
import {
|
|
fixtureId,
|
|
makeValidCapabilityWorkspace,
|
|
} from "./fixtures/capability-model.js";
|
|
|
|
test("ordinary state rejects managed references even under list/optional wrappers", () => {
|
|
const workspace = makeValidCapabilityWorkspace();
|
|
const state = [...workspace.sharedAttachments, ...workspace.conformances.flatMap((entry) => entry.privateAttachments)].find((entry) => entry.kind === "state")!;
|
|
if (state.kind !== "state") throw new Error("fixture missing state");
|
|
state.valueType = {kind: "list", value: {kind: "optional", value: {kind: "object-ref", expectation: {kind: "atom", atomId: state.attachedTo}}}};
|
|
assert.ok(validateWorkspaceRevision(workspace).some((entry) => entry.message.includes("graph relationships")));
|
|
});
|
|
|
|
const expectIssue = (
|
|
workspace: WorkspaceRevision,
|
|
code: CapabilityValidationIssueCode,
|
|
) => {
|
|
const issues = validateWorkspaceRevision(workspace);
|
|
assert.ok(
|
|
issues.some((entry) => entry.code === code),
|
|
`Expected ${code}, got:\n${issues
|
|
.map((entry) => `${entry.code} ${entry.path}: ${entry.message}`)
|
|
.join("\n")}`,
|
|
);
|
|
assert.equal(compileWorkspaceRevision(workspace).ok, false);
|
|
};
|
|
|
|
test("constructor dependency input contracts match the selected constructor", () => {
|
|
const workspace = makeValidCapabilityWorkspace();
|
|
const port = workspace.packageImports.flatMap((pkg) => pkg.exports).flatMap((entry) => entry.dependencyPorts)
|
|
.find((port) => port.requirement.kind === "constructor")!;
|
|
assert.equal(port.requirement.kind, "constructor");
|
|
if (port.requirement.kind !== "constructor") return;
|
|
port.requirement.inputType = valueType.unit;
|
|
assert.deepEqual(validateWorkspaceRevision(workspace), []);
|
|
port.requirement.inputType = valueType.string;
|
|
expectIssue(workspace, "invalid-dependency-binding");
|
|
});
|
|
|
|
const conformance = (
|
|
workspace: WorkspaceRevision,
|
|
identity: Pick<(typeof workspace.conformances)[number], "atomId" | "interfaceRevisionId">,
|
|
) => {
|
|
const result = workspace.conformances.find((entry) =>
|
|
entry.atomId === identity.atomId &&
|
|
entry.interfaceRevisionId === identity.interfaceRevisionId
|
|
);
|
|
assert.ok(
|
|
result,
|
|
`Missing fixture conformance ${identity.atomId} as ${identity.interfaceRevisionId}`,
|
|
);
|
|
return result;
|
|
};
|
|
|
|
test("the representative v1 workspace compiles to native and package plans", () => {
|
|
const workspace = makeValidCapabilityWorkspace();
|
|
assert.deepEqual(validateWorkspaceRevision(workspace), []);
|
|
const compiled = compileWorkspaceRevision(workspace);
|
|
assert.equal(compiled.ok, true);
|
|
if (!compiled.ok) return;
|
|
|
|
const title = resolveOperationPlan(
|
|
compiled.plan,
|
|
fixtureId.project,
|
|
fixtureId.namedV1,
|
|
fixtureId.namedGet,
|
|
);
|
|
assert.equal(title?.kind, "state");
|
|
if (title?.kind === "state") {
|
|
assert.equal(title.binding.slotId, fixtureId.projectTitle);
|
|
assert.equal(title.binding.primitive, "read");
|
|
assert.deepEqual(title.attachment.owner, { kind: "workspace" });
|
|
}
|
|
|
|
const owner = resolveOperationPlan(
|
|
compiled.plan,
|
|
fixtureId.project,
|
|
fixtureId.ownedV1,
|
|
fixtureId.ownerResolve,
|
|
);
|
|
assert.equal(owner?.kind, "edge");
|
|
if (owner?.kind === "edge") {
|
|
assert.equal(owner.binding.edgeTypeId, fixtureId.projectOwner);
|
|
assert.deepEqual(owner.attachment.owner, {
|
|
kind: "conformance",
|
|
...fixtureId.projectOwnedConformance,
|
|
});
|
|
}
|
|
|
|
const summary = resolveOperationPlan(
|
|
compiled.plan,
|
|
fixtureId.project,
|
|
fixtureId.summaryV1,
|
|
fixtureId.summaryGet,
|
|
);
|
|
assert.equal(summary?.kind, "package");
|
|
if (summary?.kind === "package") {
|
|
assert.equal(summary.packageRevision.revisionId, fixtureId.todoRuntimeV1);
|
|
assert.equal(summary.packageExport.id, fixtureId.summaryGetExport);
|
|
assert.deepEqual(
|
|
summary.dependencies.map((entry) => [entry.port.id, entry.binding.kind]),
|
|
[
|
|
[fixtureId.titlePort, "state"],
|
|
[fixtureId.namedPort, "interface"],
|
|
[fixtureId.personPort, "constructor"],
|
|
],
|
|
);
|
|
}
|
|
});
|
|
|
|
test("the closure is an exact tree-shaking boundary", () => {
|
|
const result = compileWorkspaceRevision(makeValidCapabilityWorkspace());
|
|
assert.equal(result.ok, true);
|
|
if (!result.ok) return;
|
|
const closure = computeCapabilityClosure(result.plan, [
|
|
{ atomId: fixtureId.project, interfaceRevisionId: fixtureId.summaryV1 },
|
|
]);
|
|
assert.deepEqual(closure.conformances, [
|
|
fixtureId.projectNamedConformance,
|
|
fixtureId.projectSummaryConformance,
|
|
]);
|
|
assert.deepEqual(closure.packageRevisionIds, [fixtureId.todoRuntimeV1]);
|
|
assert.deepEqual(closure.attachmentIds, [fixtureId.projectTitle]);
|
|
assert.deepEqual(closure.constructorAtomIds, [fixtureId.person]);
|
|
});
|
|
|
|
test("compiled plans are snapshots, not mutable authoring state", () => {
|
|
const workspace = makeValidCapabilityWorkspace();
|
|
const result = compileWorkspaceRevision(workspace);
|
|
assert.equal(result.ok, true);
|
|
if (!result.ok) return;
|
|
conformance(workspace, fixtureId.projectNamedConformance)
|
|
.operationBindings[0]!.binding = {
|
|
kind: "state",
|
|
slotId: fixtureId.personName,
|
|
primitive: "read",
|
|
};
|
|
const resolved = resolveOperationPlan(
|
|
result.plan,
|
|
fixtureId.project,
|
|
fixtureId.namedV1,
|
|
fixtureId.namedGet,
|
|
);
|
|
assert.equal(resolved?.kind, "state");
|
|
if (resolved?.kind === "state") {
|
|
assert.equal(resolved.binding.slotId, fixtureId.projectTitle);
|
|
}
|
|
});
|
|
|
|
test("a conformance binds every operation exactly once", () => {
|
|
const missing = makeValidCapabilityWorkspace();
|
|
conformance(missing, fixtureId.projectNamedConformance).operationBindings.pop();
|
|
expectIssue(missing, "missing-operation-binding");
|
|
|
|
const duplicate = makeValidCapabilityWorkspace();
|
|
const bindings = conformance(
|
|
duplicate,
|
|
fixtureId.projectNamedConformance,
|
|
).operationBindings;
|
|
bindings.push(structuredClone(bindings[0]!));
|
|
expectIssue(duplicate, "duplicate-operation-binding");
|
|
});
|
|
|
|
test("private attachments are visible only to their owning conformance", () => {
|
|
const workspace = makeValidCapabilityWorkspace();
|
|
const binding = conformance(
|
|
workspace,
|
|
fixtureId.projectNamedConformance,
|
|
).operationBindings[0]!.binding;
|
|
assert.equal(binding.kind, "state");
|
|
if (binding.kind !== "state") return;
|
|
binding.slotId = fixtureId.personName;
|
|
expectIssue(workspace, "private-attachment-access");
|
|
});
|
|
|
|
test("related-object dependency views cannot traverse another conformance's private edge", () => {
|
|
const workspace = makeValidCapabilityWorkspace();
|
|
const packageBinding = conformance(
|
|
workspace,
|
|
fixtureId.projectSummaryConformance,
|
|
).operationBindings[0]!.binding;
|
|
assert.equal(packageBinding.kind, "package");
|
|
if (packageBinding.kind !== "package") return;
|
|
const named = packageBinding.dependencies.find(
|
|
(dependency) => dependency.portId === fixtureId.namedPort,
|
|
);
|
|
assert.ok(named && named.binding.kind === "interface");
|
|
named.binding.via = {
|
|
edgeTypeId: fixtureId.projectOwner,
|
|
projectionId: fixtureId.projectOwnerProjection,
|
|
};
|
|
expectIssue(workspace, "private-attachment-access");
|
|
const owner = conformance(workspace, fixtureId.projectOwnedConformance);
|
|
const edge = owner.privateAttachments.find((entry) => entry.kind === "edge" && entry.id === fixtureId.projectOwner);
|
|
assert.ok(edge?.kind === "edge");
|
|
edge.endpoints.find((endpoint) => endpoint.projectionId === fixtureId.projectOwnerProjection)!.publicTraversal = true;
|
|
assert.equal(validateWorkspaceRevision(workspace).some((entry) => entry.code === "private-attachment-access"), false, "Only an explicitly exported read-only traversal crosses ownership");
|
|
});
|
|
|
|
test("native state and edge providers must match operation shape", () => {
|
|
const stateWorkspace = makeValidCapabilityWorkspace();
|
|
const state = conformance(
|
|
stateWorkspace,
|
|
fixtureId.projectNamedConformance,
|
|
).operationBindings[0]!.binding;
|
|
assert.equal(state.kind, "state");
|
|
if (state.kind === "state") state.primitive = "write";
|
|
expectIssue(stateWorkspace, "invalid-state-binding");
|
|
|
|
const edgeWorkspace = makeValidCapabilityWorkspace();
|
|
const edge = conformance(
|
|
edgeWorkspace,
|
|
fixtureId.projectOwnedConformance,
|
|
).operationBindings[0]!.binding;
|
|
assert.equal(edge.kind, "edge");
|
|
if (edge.kind === "edge") edge.primitive = "connect";
|
|
expectIssue(edgeWorkspace, "invalid-edge-binding");
|
|
});
|
|
|
|
test("package dependencies are complete, exact, and explicitly injected", () => {
|
|
const missing = makeValidCapabilityWorkspace();
|
|
const packageBinding = conformance(
|
|
missing,
|
|
fixtureId.projectSummaryConformance,
|
|
).operationBindings[0]!.binding;
|
|
assert.equal(packageBinding.kind, "package");
|
|
if (packageBinding.kind === "package") packageBinding.dependencies.pop();
|
|
expectIssue(missing, "invalid-dependency-binding");
|
|
|
|
const wrongType = makeValidCapabilityWorkspace();
|
|
const summaryExport = wrongType.packageImports[0]!.exports.find(
|
|
(entry) => entry.id === fixtureId.summaryGetExport,
|
|
);
|
|
assert.ok(summaryExport);
|
|
summaryExport.dependencyPorts[0]!.requirement = {
|
|
kind: "state",
|
|
valueType: valueType.int32,
|
|
primitives: ["read"],
|
|
};
|
|
expectIssue(wrongType, "invalid-dependency-binding");
|
|
});
|
|
|
|
test("package receiver requirements cannot depend on themselves", () => {
|
|
const workspace = makeValidCapabilityWorkspace();
|
|
const summaryExport = workspace.packageImports[0]!.exports.find(
|
|
(entry) => entry.id === fixtureId.summaryGetExport,
|
|
);
|
|
assert.ok(summaryExport && summaryExport.kind === "operation");
|
|
summaryExport.receiverRequirement = {
|
|
kind: "all-interfaces",
|
|
interfaceRevisionIds: [fixtureId.summaryV1],
|
|
};
|
|
summaryExport.dependencyPorts = [];
|
|
const packageBinding = conformance(
|
|
workspace,
|
|
fixtureId.projectSummaryConformance,
|
|
).operationBindings[0]!.binding;
|
|
assert.equal(packageBinding.kind, "package");
|
|
if (packageBinding.kind === "package") packageBinding.dependencies = [];
|
|
expectIssue(workspace, "cyclic-conformance-requirement");
|
|
});
|
|
|
|
test("constructors are statically checked", () => {
|
|
const badConstructor = makeValidCapabilityWorkspace();
|
|
badConstructor.constructors[0]!.exportId = fixtureId.summaryGetExport;
|
|
expectIssue(badConstructor, "invalid-constructor");
|
|
});
|