Host persistent Camino services and authenticated workspace bootstrap (WI-06)
This commit is contained in:
@@ -2,7 +2,7 @@ import { open, lstat } from "node:fs/promises";
|
||||
import { constants } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import type { WorkspaceRevision } from "../capability-model/types.js";
|
||||
import { compileExecutionPlan, hexDigest, ExecutionPlanError } from "./plan.js";
|
||||
import { compileExecutionPlan, hexDigest, ExecutionPlanError, type ExecutionPlan } from "./plan.js";
|
||||
import { loadExecutionInstallation, type PackageInstallationSelection } from "./installation.js";
|
||||
import { compileKernelProgram } from "./kernel.js";
|
||||
import { compileQueryProgram } from "./queries.js";
|
||||
@@ -26,11 +26,12 @@ export async function loadCheckedInstallationCandidate(
|
||||
) {
|
||||
if (!rootPattern.test(root) || !(await lstat(root)).isDirectory())
|
||||
throw Error("Candidate must be an immutable Nix output directory");
|
||||
const [candidate, recordedPlan, artifacts, source] = await Promise.all([
|
||||
const [candidate, recordedPlan, artifacts, source, entryRequest] = await Promise.all([
|
||||
readJson(root, "candidate.json"),
|
||||
readJson(root, "execution-plan.json"),
|
||||
readJson(root, "execution-artifacts.json"),
|
||||
readJson(root, "source.json"),
|
||||
readJson(root, "entry.json"),
|
||||
]);
|
||||
const { executionContracts: _legacyContracts, ...workspace } = candidate;
|
||||
const plan = compileExecutionPlan(workspace as WorkspaceRevision);
|
||||
@@ -70,6 +71,7 @@ export async function loadCheckedInstallationCandidate(
|
||||
"Package artifacts must be immutable Nix roots",
|
||||
);
|
||||
const installation = await loadExecutionInstallation(plan, artifacts.roots, generator, selections);
|
||||
const entry = compileWorkspaceEntry(plan, entryRequest);
|
||||
const kernel = compileKernelProgram(plan),
|
||||
queries = compileQueryProgram(plan);
|
||||
// The isolated runner and managed host consume the same compiled programs.
|
||||
@@ -91,7 +93,7 @@ export async function loadCheckedInstallationCandidate(
|
||||
};
|
||||
const reference = {
|
||||
root,
|
||||
digest: hexDigest({ plan: plan.digest, world: installation.world, provenance, roots: artifacts.roots }),
|
||||
digest: hexDigest({ plan: plan.digest, world: installation.world, provenance, roots: artifacts.roots, entry }),
|
||||
};
|
||||
return {
|
||||
reference,
|
||||
@@ -99,9 +101,47 @@ export async function loadCheckedInstallationCandidate(
|
||||
world: installation.world,
|
||||
plan: plan.digest,
|
||||
provenance,
|
||||
entry,
|
||||
kernel,
|
||||
queries,
|
||||
installation,
|
||||
executionPlan: plan,
|
||||
};
|
||||
}
|
||||
|
||||
export function compileWorkspaceEntry(plan: ExecutionPlan, entryRequest: unknown): { operation: string } | null {
|
||||
let entry: { operation: string } | null = null;
|
||||
if (entryRequest !== null) {
|
||||
if (
|
||||
typeof entryRequest !== "object" ||
|
||||
Array.isArray(entryRequest) ||
|
||||
Object.keys(entryRequest).sort().join(",") !== "atom,interface,operation"
|
||||
)
|
||||
throw new ExecutionPlanError(
|
||||
"INVALID_ENTRY_FACTORY",
|
||||
"entry",
|
||||
"Entry declaration must name atom, interface and operation identities",
|
||||
);
|
||||
const operation = plan.definition.operations.find(
|
||||
(op) =>
|
||||
op.atomId === (entryRequest as Record<string, unknown>).atom &&
|
||||
op.interfaceRevisionId === (entryRequest as Record<string, unknown>).interface &&
|
||||
op.operationId === (entryRequest as Record<string, unknown>).operation,
|
||||
);
|
||||
if (
|
||||
!operation ||
|
||||
operation.scope !== "class" ||
|
||||
operation.execution.kind !== "transaction" ||
|
||||
operation.input.kind !== "builtin" ||
|
||||
operation.input.name !== "unit" ||
|
||||
operation.output.kind !== "object-ref"
|
||||
)
|
||||
throw new ExecutionPlanError(
|
||||
"INVALID_ENTRY_FACTORY",
|
||||
"entry",
|
||||
"Entry must be a checked unit-input class transaction returning one object reference",
|
||||
);
|
||||
entry = { operation: operation.key };
|
||||
}
|
||||
return entry;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user