Compare commits

..
Author SHA1 Message Date
Quixos Subtree Publisher 27af7af6c5 Publish quixos-protocol from 473886a58fdacf15f2c873b77da96faf3be7fa65 2026-10-31 14:55:33 +00:00
Quixos Development Agent 01f26965-84fa-4a79-8069-725682c13065 7545f7392d Preserve authorized cold-load browser refusals and private aggregate metadata usage (#641) 2026-10-31 14:50:06 +00:00
Quixos Development Agent 01f26965-84fa-4a79-8069-725682c13065 94ddc8bedf Expose bounded post-build Source Check failures to authors (#641) 2026-10-31 14:48:20 +00:00
Quixos Subtree Publisher c56948ebd0 Publish quixos-protocol from e8df5e3396060619b33ab3cf9458231ef220ccc7 2026-10-31 14:19:06 +00:00
Quixos Development Agent 01f26965-84fa-4a79-8069-725682c13065 6f5b5265b6 Exercise alias pin discovery and refresh in always-run Nix fixtures (#713) 2026-10-31 14:15:38 +00:00
Quixos Development Agent 01f26965-84fa-4a79-8069-725682c13065 31d155fd88 Keep managed source paths canonical across outer workbench aliases (#713) 2026-10-31 14:09:51 +00:00
Quixos Subtree Publisher a025525f47 Publish quixos-protocol from 806b0430d952b5a9aab5b2a63496c272aced8e50 2026-10-29 14:36:45 +00:00
Timothy J. Aveni e13fde36fb Resolve managed resource aliases within the canonical workbench (#588) 2026-10-29 07:36:45 -07:00
Quixos Subtree Publisher d829d584af Publish quixos-protocol from ca5b05584b89e90cb259b4596b1bc01d3d692136 2026-10-25 21:28:36 +00:00
Quixos Development Agent 5ffdc2ce-2936-4c70-8208-3a9da53f4aa9 ee84025322 Use explicit navigation projections for React presentation readiness (#339) 2026-10-24 06:39:33 +00:00
Timothy J. Aveni bc9a7ef2cf Integrate Kubernetes compute, scoped Agent placement and observable releases (#195) 2026-10-18 19:52:45 -07:00
Quixos Subtree Publisher badad181de Publish quixos-protocol from 6b91014ff1d6c9c54d0782f586935e694f9ee72f 2026-10-13 12:37:58 +00:00
Timothy J. Aveni 85163b6e67 Reduce repeated compiler startup in monorepo QX formatting 2026-10-13 05:37:58 -07:00
Quixos Subtree Publisher e8373a4cd1 Publish quixos-protocol from e4393946ba63cfef75580f6aa6ba840035e7d43c 2026-10-13 10:19:49 +00:00
Timothy J. Aveni e92b08025c Avoid rehashing validated Graph execution metadata during Candidate loading 2026-10-13 02:58:29 -07:00
Timothy J. Aveni 62a09605cf Reuse verified immutable plans and streamline cooperative hashing
Continue final hosted development reliability qualification.
2026-10-12 20:16:56 -07:00
Timothy J. Aveni 47b316180d Keep checked execution groups and public catalog preparation cooperative 2026-10-12 19:21:34 -07:00
Timothy J. Aveni a4ba6169a6 Reuse checked reflection inputs before acquiring controller ownership 2026-10-12 18:30:07 -07:00
Timothy J. Aveni a48fccc328 Keep cold Candidate verification cooperative with controller renewals 2026-10-12 18:24:38 -07:00
Timothy J. Aveni 755c008a88 Repair concurrent Graph recovery, Source Job residency and developer source provisioning 2026-10-12 15:39:34 -07:00
Timothy J. Aveni bbf9056dfa Unify scoped development with ordinary Workspace authoring commands 2026-10-12 13:09:47 -07:00
Timothy J. Aveni ecf97173b4 Retain private platform source while resolving its context-free Nix flake reference 2026-10-11 16:41:18 -07:00
Timothy J. Aveni 0f41b12ca0 Supply exact private platform source to sealed checks without private evaluator egress 2026-10-11 16:07:52 -07:00
Timothy J. Aveni fa698dd306 Protect active development Graphs from rejected launcher cleanup 2026-10-11 03:42:32 -07:00
41 changed files with 980 additions and 365 deletions
+3 -3
View File
@@ -1,8 +1,8 @@
{ {
"version": 1, "version": 1,
"sourceRepo": "https://gitea-external.egads.tutti.syntaxblitz.net/quixos/quixos", "sourceRepo": "https://gitea.internal.quixos.org/quixos/quixos.git",
"sourceCommit": "8014b4ba717313e1b494c59a8e2781df58bf9a85", "sourceCommit": "473886a58fdacf15f2c873b77da96faf3be7fa65",
"sourcePath": "quixos-protocol", "sourcePath": "quixos-protocol",
"exportName": "quixos-protocol", "exportName": "quixos-protocol",
"mirrorRemote": "https://gitea-external.egads.tutti.syntaxblitz.net/quixos/quixos-protocol.git" "mirrorRemote": "https://repos.quixos.org/quixos-toolchain/quixos-protocol.git"
} }
+29 -9
View File
@@ -7,6 +7,7 @@
generator, generator,
contractOnly ? false, contractOnly ? false,
workspaceId ? null, workspaceId ? null,
platformSourceJSON ? null,
system ? builtins.currentSystem, system ? builtins.currentSystem,
}: }:
let let
@@ -71,9 +72,21 @@ let
else else
{ }; { };
execution = (configuration.backend or "typescript") == "execution"; execution = (configuration.backend or "typescript") == "execution";
runtime = builtins.getFlake ( platformSource = if platformSourceJSON == null then null else builtins.fromJSON platformSourceJSON;
"git+${root.lock.quixos.repository}?rev=${root.lock.quixos.commit}&ref=refs/tags/quixos-reachability/${root.lock.quixos.commit}" runtime =
); if platformSource == null then
builtins.getFlake (
"git+${root.lock.quixos.repository}?rev=${root.lock.quixos.commit}&ref=refs/tags/quixos-reachability/${root.lock.quixos.commit}"
)
else
assert platformSource.repository == root.lock.quixos.repository;
assert platformSource.commit == root.lock.quixos.commit;
# getFlake accepts a context-free flake reference. storePath first checks
# presence; the resulting flake retains its immutable source as an input.
# Dropping string context here does not permit an authored mutable path.
builtins.getFlake (
builtins.unsafeDiscardStringContext "path:${builtins.storePath platformSource.directory}"
);
runtimePackages = runtime.packages.${system}; runtimePackages = runtime.packages.${system};
resourceClosure = resourceClosure =
includeBuild: node: includeBuild: node:
@@ -394,12 +407,19 @@ pkgs.runCommand (if contractOnly then "qx-contract" else "qx-checked-candidate")
${pkgs.nodejs_24}/bin/node ${./check-execution.mjs} \ ${pkgs.nodejs_24}/bin/node ${./check-execution.mjs} \
${protocol}/libexec/quixos-protocol/execution-world.mjs \ ${protocol}/libexec/quixos-protocol/execution-world.mjs \
"$out/execution-plan.json" "$out/checks.json" "$out" "$out/execution-plan.json" "$out/checks.json" "$out"
mkdir -p "$out/bin" # The optional development host is acquired only when explicitly run.
cat > "$out/bin/run-isolated" <<EOF # Embedding its executable here made every source check build Web Studio
#!${pkgs.runtimeShell} # and a full host even when only checked Package outputs were consumed.
exec ${runtimePackages.camino-isolated-workspace}/bin/camino-isolated-workspace "$out" "\$@" cp ${
EOF pkgs.writeText "qx-isolated-runtime.json" (
chmod +x "$out/bin/run-isolated" builtins.toJSON {
codec = "quixos-isolated-runtime/1";
source = {
inherit (root.lock.quixos) repository commit;
};
}
)
} "$out/isolated-runtime.json"
''} ''}
''} ''}
${pkgs.lib.optionalString ( ${pkgs.lib.optionalString (
+27 -22
View File
@@ -41,15 +41,19 @@ export function presentationQueries(pkg: PackageRevision, interfaces: readonly I
]; ];
}); });
const stem = `PresentationNavigation${createHash("sha256").update(id).digest("hex").slice(0, 12)}`; const stem = `PresentationNavigation${createHash("sha256").update(id).digest("hex").slice(0, 12)}`;
const inputs = `presentation:navigation:${id}:inputs`; // Retain full state for operations and hidden occurrences, independently
for (const local of [false, true]) { // from the identity projection used to prepare a rendering occurrence.
const name = `${stem}${local ? "View" : "Inputs"}`; for (const identity of [false, true]) {
const document = `generated/${name}.graphql`; const prefix = `presentation:navigation:${id}:${identity ? "identity-" : ""}`;
documents.set( const inputs = prefix + "inputs";
document, for (const local of [false, true]) {
`query ${name}($presentationMount: QxRef_PresentationMount!) { const name = `${stem}${identity ? "Identity" : ""}${local ? "View" : "Inputs"}`;
const document = `generated/${name}.graphql`;
documents.set(
document,
`query ${name}($presentationMount: QxRef_PresentationMount!) {
root { ${local ? "availableObjects" : "objects"}(all:512, where:{_camino:{as:{PresentationState:{presentationMount:{eq:$presentationMount}}}}}) { root { ${local ? "availableObjects" : "objects"}(all:512, where:{_camino:{as:{PresentationState:{presentationMount:{eq:$presentationMount}}}}}) {
entries { node { ${fields.join("\n")} entries { node { ${identity ? "" : fields.join("\n")}
... on PresentationState { ... on PresentationState {
_presentationOccurrence: occurrence _presentationOccurrence: occurrence
_presentationSource: source {_camino {ref}} _presentationSource: source {_camino {ref}}
@@ -59,20 +63,21 @@ export function presentationQueries(pkg: PackageRevision, interfaces: readonly I
} } } }
} } } }
}`, }`,
); );
generated.push({ generated.push({
id: local ? `presentation:navigation:${id}:view` : inputs, id: local ? prefix + "view" : inputs,
displayName: name, displayName: name,
root: { kind: "workspace-interface", interface: contract.revisionId }, root: { kind: "workspace-interface", interface: contract.revisionId },
document, document,
operation: name, operation: name,
fragments: [], fragments: [],
views: [], views: [],
allowances: [], allowances: [],
budgets: { ...defaultQueryBudgets, rows: 5000, candidates: 5000, resultBytes: 8388608 }, budgets: { ...defaultQueryBudgets, rows: 5000, candidates: 5000, resultBytes: 8388608 },
watch: local, watch: local,
placement: local ? { kind: "local", sourceQueryId: inputs } : { kind: "replica" }, placement: local ? { kind: "local", sourceQueryId: inputs } : { kind: "replica" },
}); });
}
} }
} }
for (const query of generated) for (const query of generated)
+58 -15
View File
@@ -21,6 +21,8 @@ export async function authoringContext(start: string) {
} }
if (text !== undefined) { if (text !== undefined) {
const graph = JSON.parse(text) as { resources: AuthoringResource[]; workspaceId?: string }; const graph = JSON.parse(text) as { resources: AuthoringResource[]; workspaceId?: string };
if (!graph || typeof graph !== "object" || Array.isArray(graph))
throw new Error("Managed resource inventory is malformed");
if ( if (
graph.workspaceId !== undefined && graph.workspaceId !== undefined &&
(typeof graph.workspaceId !== "string" || !/^[a-zA-Z0-9][a-zA-Z0-9:._-]{0,255}$/.test(graph.workspaceId)) (typeof graph.workspaceId !== "string" || !/^[a-zA-Z0-9][a-zA-Z0-9:._-]{0,255}$/.test(graph.workspaceId))
@@ -30,27 +32,68 @@ export async function authoringContext(start: string) {
const resources: AuthoringResource[] = [{ kind: "workspace", directory: "root" }]; const resources: AuthoringResource[] = [{ kind: "workspace", directory: "root" }];
const identities = new Set<string>(), const identities = new Set<string>(),
directories = new Set<string>(["root"]); directories = new Set<string>(["root"]);
for (const entry of graph.resources) { for (const [index, entry] of graph.resources.entries()) {
// Compiler graphs carry resolved paths; the authoring API presents const invalid = (reason: string): never => {
// stable workbench-relative names and validates containment here. throw new Error(`Invalid managed resource registration at entry ${index + 1}: ${reason}`);
if (typeof entry.directory === "string" && path.isAbsolute(entry.directory)) };
entry.directory = path.relative(workbench, entry.directory);
if ( if (
!["interface", "package", "build"].includes(entry.kind) || !entry ||
!entry.source || typeof entry !== "object" ||
!/^resources\/[A-Za-z0-9][A-Za-z0-9._-]*$/.test(entry.directory) Array.isArray(entry) ||
) { !["interface", "package", "build"].includes(entry.kind)
throw new Error("Invalid managed resource registration"); )
invalid("unsupported resource kind");
if (
entry.resourceId !== undefined &&
(typeof entry.resourceId !== "string" ||
entry.resourceId.length < 1 ||
entry.resourceId.length > 256 ||
entry.resourceId.includes("\0"))
)
invalid("resource identity must be a bounded nonempty identifier");
const source = entry.source;
if (
!source ||
typeof source !== "object" ||
Array.isArray(source) ||
source.resolver !== "git" ||
typeof source.repository !== "string" ||
!source.repository ||
source.repository.length > 4096 ||
source.repository.includes("\0") ||
typeof source.commit !== "string" ||
!/^([0-9a-f]{40}|[0-9a-f]{64})$/.test(source.commit)
)
invalid("expected an immutable Git source");
// Git transport policy belongs to the source resolver, including its
// maintained local/file fixtures; registration validates only its shape.
if (
typeof entry.directory !== "string" ||
!entry.directory ||
entry.directory.length > 4096 ||
entry.directory.includes("\0")
)
invalid("directory must be a bounded path");
// Bootstrap intentionally records stable aliases for native histories.
// Compare physical paths on BOTH sides, then expose the same canonical
// workbench-relative selection for alias and physical working dirs.
let directory: string;
try {
directory = path.relative(workbench, await realpath(path.resolve(workbench, entry.directory)));
} catch {
invalid("registered directory is unavailable");
} }
const identity = `${entry.kind}\0${entry.resourceId ?? entry.source.repository}`; if (!/^resources\/[A-Za-z0-9][A-Za-z0-9._-]*$/.test(directory!))
if (identities.has(identity) || directories.has(entry.directory)) { invalid("registered directory must resolve beneath workbench resources");
throw new Error(`Multiple editable selections for ${entry.resourceId ?? entry.source.repository}`); const identity = `${entry.kind}\0${entry.resourceId ?? source!.repository}`;
if (identities.has(identity) || directories.has(directory!)) {
throw new Error(`Multiple editable selections for ${directory!}`);
} }
identities.add(identity); identities.add(identity);
directories.add(entry.directory); directories.add(directory!);
resources.push({ resources.push({
kind: entry.kind, kind: entry.kind,
directory: entry.directory, directory: directory!,
resourceId: entry.resourceId, resourceId: entry.resourceId,
source: entry.source, source: entry.source,
}); });
@@ -4,6 +4,7 @@ import { execFile as callback } from "node:child_process";
import { promisify } from "node:util"; import { promisify } from "node:util";
import { randomUUID } from "node:crypto"; import { randomUUID } from "node:crypto";
import { authoringContext } from "./authoring-context.js"; import { authoringContext } from "./authoring-context.js";
import { managedResourcePath } from "./managed-source-path.js";
import { snapshotCommit } from "./checked-build.js"; import { snapshotCommit } from "./checked-build.js";
import { profile } from "./profile.js"; import { profile } from "./profile.js";
import { import {
@@ -85,6 +86,11 @@ export async function convergeAuthoring(start: string, target = "root") {
const context = await authoringContext(start); const context = await authoringContext(start);
const graphFile = path.join(context.workbench, ".quixos/resource-graph.json"); const graphFile = path.join(context.workbench, ".quixos/resource-graph.json");
const graphBefore = await readFile(graphFile, "utf8"); const graphBefore = await readFile(graphFile, "utf8");
const graph = JSON.parse(graphBefore);
// Discovery resolves outer guest aliases. Persist those same physical
// selections, without accepting symlinks within the managed workbench.
for (const resource of graph.resources)
resource.directory = await managedResourcePath(context.workbench, resource.directory);
const blockers: AuthoringBlocker[] = []; const blockers: AuthoringBlocker[] = [];
const nodes = new Map<string, { directory: string; kind: string; source: GitSource; dependencies: string[] }>(); const nodes = new Map<string, { directory: string; kind: string; source: GitSource; dependencies: string[] }>();
const selected = new Map<string, string>(); const selected = new Map<string, string>();
@@ -247,9 +253,6 @@ export async function convergeAuthoring(start: string, target = "root") {
profile("capture-recheck", recheckStarted, { repositories: complete.size }); profile("capture-recheck", recheckStarted, { repositories: complete.size });
// Persist successful selections even if another repository is still broken. // Persist successful selections even if another repository is still broken.
// Recovery must not depend on all parents succeeding in the same invocation. // Recovery must not depend on all parents succeeding in the same invocation.
const graph = JSON.parse(graphBefore);
for (const resource of graph.resources)
resource.directory = path.relative(context.workbench, path.resolve(context.workbench, resource.directory));
const replacements = new Map<string, string>(); const replacements = new Map<string, string>();
for (const resource of graph.resources) { for (const resource of graph.resources) {
const source = complete.get(resource.directory); const source = complete.get(resource.directory);
+9
View File
@@ -113,6 +113,7 @@ export async function buildImmutableCandidate(
contractOnly = false, contractOnly = false,
observe?: (phase: "nixEvaluationMs" | "nixBuildMs", ms: number) => void, observe?: (phase: "nixEvaluationMs" | "nixBuildMs", ms: number) => void,
workspaceId?: string, workspaceId?: string,
platformSource?: { repository: string; commit: string; directory: string },
): Promise<string> { ): Promise<string> {
if (workspaceId !== undefined && (kind !== "workspace" || !/^[a-zA-Z0-9][a-zA-Z0-9:._-]{0,255}$/.test(workspaceId))) if (workspaceId !== undefined && (kind !== "workspace" || !/^[a-zA-Z0-9][a-zA-Z0-9:._-]{0,255}$/.test(workspaceId)))
throw new Error("Instance binding requires a valid Workspace identity and a Workspace root"); throw new Error("Instance binding requires a valid Workspace identity and a Workspace root");
@@ -121,6 +122,13 @@ export async function buildImmutableCandidate(
const url = new URL(source.repository); const url = new URL(source.repository);
if (url.protocol !== "https:" || url.username || url.password || url.search || url.hash) if (url.protocol !== "https:" || url.username || url.password || url.search || url.hash)
throw new Error("Candidate origin must be credential-free HTTPS"); throw new Error("Candidate origin must be credential-free HTTPS");
if (
platformSource &&
(Object.keys(platformSource).sort().join(",") !== "commit,directory,repository" ||
!/^[a-f0-9]{40}$/.test(platformSource.commit) ||
!/^\/nix\/store\/[a-z0-9]{32}-[^/\s]+$/.test(platformSource.directory))
)
throw Error("Invalid immutable platform source input");
const generator = const generator =
process.env.QUIXOS_CHECK_GENERATOR ?? path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../.."); process.env.QUIXOS_CHECK_GENERATOR ?? path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../..");
if (!/^\/nix\/store\/[^/]+$/.test(generator)) throw new Error("Use the installed Quixos checker"); if (!/^\/nix\/store\/[^/]+$/.test(generator)) throw new Error("Use the installed Quixos checker");
@@ -204,6 +212,7 @@ export async function buildImmutableCandidate(
"contractOnly", "contractOnly",
contractOnly ? "true" : "false", contractOnly ? "true" : "false",
...(workspaceId === undefined ? [] : ["--argstr", "workspaceId", workspaceId]), ...(workspaceId === undefined ? [] : ["--argstr", "workspaceId", workspaceId]),
...(platformSource ? ["--argstr", "platformSourceJSON", JSON.stringify(platformSource)] : []),
"--add-root", "--add-root",
gcRoot, gcRoot,
"--indirect", "--indirect",
@@ -16,8 +16,11 @@ export async function prepareDevelopmentSources(options: {
directory: string; directory: string;
cacheDirectory: string; cacheDirectory: string;
locations?: Record<string, string>; locations?: Record<string, string>;
workspaceId?: string;
}) { }) {
const source = workspaceSourcePin(options.source); const source = workspaceSourcePin(options.source);
if (options.workspaceId !== undefined && !/^[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/.test(options.workspaceId))
throw Error("Development source binding requires a Workspace UUID");
const destination = path.resolve(options.directory); const destination = path.resolve(options.directory);
const cache = path.resolve(options.cacheDirectory); const cache = path.resolve(options.cacheDirectory);
if (cache === destination || cache.startsWith(destination + path.sep)) if (cache === destination || cache.startsWith(destination + path.sep))
@@ -43,7 +46,8 @@ export async function prepareDevelopmentSources(options: {
const parent = path.dirname(destination); const parent = path.dirname(destination);
await mkdir(parent, { recursive: true }); await mkdir(parent, { recursive: true });
const staging = await mkdtemp(path.join(parent, ".development-sources-")); const staging = await mkdtemp(path.join(parent, ".development-sources-"));
const workspaceId = randomUUID(); // This local association does not create or grant access to a hosted Graph.
const workspaceId = options.workspaceId ?? randomUUID();
try { try {
const resources = []; const resources = [];
for (const entry of closure.resources) { for (const entry of closure.resources) {
+18 -11
View File
@@ -1,14 +1,19 @@
import { spawn } from "node:child_process"; import { spawn } from "node:child_process";
export class FileLockBusyError extends Error {}
/** Kernel-owned lock: a crashed coordinator cannot leave a stale ownership file. /** Kernel-owned lock: a crashed coordinator cannot leave a stale ownership file.
* The persistent file is just an inode; EOF releases the helper's lock. */ * The persistent file is just an inode; EOF releases the helper's lock. */
export async function withFileLock<T>(filename: string, work: () => Promise<T>): Promise<T> { export async function withFileLock<T>(
filename: string,
work: () => Promise<T>,
{ nonblocking = false }: { nonblocking?: boolean } = {},
): Promise<T> {
const child = spawn( const child = spawn(
"flock", "flock",
[ [
"--exclusive", "--exclusive",
"--timeout", ...(nonblocking ? ["--nonblock"] : ["--timeout", "120"]),
"120",
"--conflict-exit-code", "--conflict-exit-code",
"75", "75",
filename, filename,
@@ -32,15 +37,17 @@ export async function withFileLock<T>(filename: string, work: () => Promise<T>):
await new Promise<void>((resolve, reject) => { await new Promise<void>((resolve, reject) => {
let output = ""; let output = "";
child.once("error", reject); child.once("error", reject);
child.once("exit", (code) => child.once("exit", (code) => {
reject( reject(
new Error( code === 75
code === 75 ? new FileLockBusyError(
? "Timed out after 120 seconds waiting for another authoring command; inspect that command before retrying" nonblocking
: `Cannot acquire authoring lock: ${diagnostics}`, ? "Another process owns this lock"
), : "Timed out after 120 seconds waiting for another authoring command; inspect that command before retrying",
), )
); : new Error(`Cannot acquire authoring lock: ${diagnostics}`),
);
});
child.stdout.on("data", (chunk) => { child.stdout.on("data", (chunk) => {
output += chunk; output += chunk;
if (output.includes("locked\n")) resolve(); if (output.includes("locked\n")) resolve();
@@ -0,0 +1,19 @@
import { realpath } from "node:fs/promises";
import path from "node:path";
/** Registration may name the workbench through its guest alias. Only that
* outer alias is permitted: resources and each checkout remain physical,
* directly contained directories. Persist the resulting root-relative path.
*/
export async function managedResourcePath(workbench: string, directory: string): Promise<string> {
const root = await realpath(workbench);
const selected = path.resolve(root, directory);
const name = path.basename(selected);
const resources = path.dirname(selected);
if (path.basename(resources) !== "resources" || !/^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(name))
throw new Error(`Repository is outside the managed workbench: ${directory}`);
const relative = `resources/${name}`;
if ((await realpath(path.dirname(resources))) !== root || (await realpath(selected)) !== path.join(root, relative))
throw new Error(`Managed repository path crosses a symlink or escapes the workbench: ${directory}`);
return relative;
}
+13 -10
View File
@@ -22,6 +22,7 @@ import {
type EvolutionReview, type EvolutionReview,
} from "../capability-model/index.js"; } from "../capability-model/index.js";
import { withFileLock } from "./file-lock.js"; import { withFileLock } from "./file-lock.js";
import { managedResourcePath } from "./managed-source-path.js";
const execFile = promisify(callback); const execFile = promisify(callback);
type Source = { repository: string; commit: string }; type Source = { repository: string; commit: string };
export type UpgradeNode = { kind: "workspace" | "package" | "interface" | "build"; directory: string; source: Source }; export type UpgradeNode = { kind: "workspace" | "package" | "interface" | "build"; directory: string; source: Source };
@@ -98,7 +99,8 @@ const writeJournal = async (filename: string, journal: unknown) => {
} }
}; };
export const discoverUpgradeSpec = async (workbench: string): Promise<UpgradeSpec> => { export const discoverUpgradeSpec = async (workbenchPath: string): Promise<UpgradeSpec> => {
const workbench = await fs.realpath(workbenchPath);
const graph = JSON.parse(await fs.readFile(path.join(workbench, ".quixos/resource-graph.json"), "utf8")); const graph = JSON.parse(await fs.readFile(path.join(workbench, ".quixos/resource-graph.json"), "utf8"));
const root = await location(workbench, "root"); const root = await location(workbench, "root");
const nodes: UpgradeNode[] = [ const nodes: UpgradeNode[] = [
@@ -110,11 +112,15 @@ export const discoverUpgradeSpec = async (workbench: string): Promise<UpgradeSpe
commit: await command(root, "jj", ["--ignore-working-copy", "log", "--no-graph", "-r", "@", "-T", "commit_id"]), commit: await command(root, "jj", ["--ignore-working-copy", "log", "--no-graph", "-r", "@", "-T", "commit_id"]),
}, },
}, },
...graph.resources.map((entry: { kind: "interface" | "package" | "build"; directory: string; source: Source }) => ({ ...(await Promise.all(
kind: entry.kind, graph.resources.map(
source: entry.source, async (entry: { kind: "interface" | "package" | "build"; directory: string; source: Source }) => ({
directory: path.relative(workbench, path.resolve(workbench, entry.directory)), kind: entry.kind,
})), source: entry.source,
directory: await managedResourcePath(workbench, entry.directory),
}),
),
)),
]; ];
let baseline: string | undefined; let baseline: string | undefined;
try { try {
@@ -406,10 +412,7 @@ export const applyPinUpgrades = async (
previous.resources.map(async (entry: { kind: string; source: Source; directory: string }) => ({ previous.resources.map(async (entry: { kind: string; source: Source; directory: string }) => ({
kind: entry.kind, kind: entry.kind,
...entry.source, ...entry.source,
directory: await location( directory: await location(plan.workbench, await managedResourcePath(plan.workbench, entry.directory)),
plan.workbench,
path.relative(plan.workbench, path.resolve(plan.workbench, entry.directory)),
),
})), })),
); );
for (const node of plan.nodes.filter((entry) => entry.kind !== "workspace")) { for (const node of plan.nodes.filter((entry) => entry.kind !== "workspace")) {
@@ -6,5 +6,13 @@ const [repository, commit, log, workspaceId] = process.argv.slice(2);
if (!repository || !commit || !log || !workspaceId || process.argv.length !== 6) if (!repository || !commit || !log || !workspaceId || process.argv.length !== 6)
throw Error("source-check-driver REPOSITORY COMMIT LOG WORKSPACE_ID"); throw Error("source-check-driver REPOSITORY COMMIT LOG WORKSPACE_ID");
process.stdout.write( process.stdout.write(
(await buildImmutableCandidate({ repository, commit }, "workspace", log, false, undefined, workspaceId)) + "\n", (await buildImmutableCandidate(
{ repository, commit },
"workspace",
log,
false,
undefined,
workspaceId,
process.env.QUIXOS_CHECK_PLATFORM_SOURCE ? JSON.parse(process.env.QUIXOS_CHECK_PLATFORM_SOURCE) : undefined,
)) + "\n",
); );
+30 -2
View File
@@ -73,7 +73,7 @@ const main = async () => {
"--dir", "--dir",
...(args[1] !== "restore" ? ["--locations"] : []), ...(args[1] !== "restore" ? ["--locations"] : []),
...(args[1] === "checkout" ? ["--repository-prefix"] : []), ...(args[1] === "checkout" ? ["--repository-prefix"] : []),
...(args[1] === "develop" ? ["--cache"] : []), ...(args[1] === "develop" ? ["--cache", "--workspace-id"] : []),
...(args[1] === "backup" ? ["--output"] : []), ...(args[1] === "backup" ? ["--output"] : []),
].includes(args[i]) || ].includes(args[i]) ||
!args[i + 1] || !args[i + 1] ||
@@ -100,7 +100,11 @@ const main = async () => {
if (args[1] === "develop") { if (args[1] === "develop") {
if (!flags.get("--cache")) throw Error("source develop requires --cache DIRECTORY"); if (!flags.get("--cache")) throw Error("source develop requires --cache DIRECTORY");
const { prepareDevelopmentSources } = await import("./development-sources.js"); const { prepareDevelopmentSources } = await import("./development-sources.js");
result = await prepareDevelopmentSources({ ...options, cacheDirectory: path.resolve(flags.get("--cache")!) }); result = await prepareDevelopmentSources({
...options,
cacheDirectory: path.resolve(flags.get("--cache")!),
...(flags.has("--workspace-id") ? { workspaceId: flags.get("--workspace-id")! } : {}),
});
} else if (args[1] === "backup") { } else if (args[1] === "backup") {
if (!flags.get("--output")) throw Error("source backup requires --output DIRECTORY"); if (!flags.get("--output")) throw Error("source backup requires --output DIRECTORY");
const { backupWorkspaceSources } = await import("./source-backup.js"); const { backupWorkspaceSources } = await import("./source-backup.js");
@@ -591,6 +595,30 @@ const main = async () => {
process.stdout.write(`${JSON.stringify(plan, null, 2)}\n`); process.stdout.write(`${JSON.stringify(plan, null, 2)}\n`);
return; return;
} }
if (command === "format" && (args[0] === "--check" || args[0] === "--write")) {
const check = args[0] === "--check",
files = args.slice(1);
if (!files.length || files.some((file) => file.startsWith("-")))
throw new Error("usage: quixos-qx format --check|--write FILE...");
for (const file of files) {
try {
const source = await readFile(file, "utf8"),
formatted = formatQx(source);
if (formatted === source) continue;
if (check) {
console.error(`Needs formatting: ${file}`);
process.exitCode = 1;
} else {
await writeFile(file, formatted);
console.log(`Formatted ${file}`);
}
} catch (error) {
console.error(`${file}: ${error instanceof Error ? error.message : error}`);
process.exitCode = 1;
}
}
return;
}
const [file, flag, ...rest] = args; const [file, flag, ...rest] = args;
if ( if (
!file || !file ||
+84
View File
@@ -1,4 +1,5 @@
import { createHash } from "node:crypto"; import { createHash } from "node:crypto";
import { setImmediate } from "node:timers/promises";
import type { Binding, Conformance, DependencyBinding, PersistentAttachment, WorkspaceRevision } from "./types.js"; import type { Binding, Conformance, DependencyBinding, PersistentAttachment, WorkspaceRevision } from "./types.js";
import { validateWorkspaceRevision } from "./validation.js"; import { validateWorkspaceRevision } from "./validation.js";
@@ -21,6 +22,89 @@ export const canonicalJson = (value: unknown): string => {
}; };
export const contentDigest = (value: unknown) => export const contentDigest = (value: unknown) =>
`sha256:${createHash("sha256").update(canonicalJson(value)).digest("hex")}`; `sha256:${createHash("sha256").update(canonicalJson(value)).digest("hex")}`;
/** Same canonical bytes as contentDigest, without monopolizing a live host's
* event loop while verifying large immutable metadata. No validation is skipped.
* This is for asynchronous loading, not a different build/wire identity. */
export async function contentDigestAsync(value: unknown): Promise<string> {
// An explicit stack visits each node once; recursive generator delegation
// otherwise forwards every token through every ancestor of a deep plan.
type Frame = { kind: "value" | "array" | "object"; value: unknown; index?: number; keys?: string[]; wrote?: boolean };
const hash = createHash("sha256"),
stack: Frame[] = [{ kind: "value", value }],
active = new WeakSet<object>();
let buffer = "",
sliceStarted = performance.now(),
steps = 0;
const append = (part: string) => {
buffer += part;
if (buffer.length >= 65536) {
hash.update(buffer);
buffer = "";
}
};
while (stack.length) {
const frame = stack[stack.length - 1]!;
if (frame.kind === "value") {
const value = frame.value;
if (value !== null && typeof value === "object") {
if (active.has(value)) throw new Error("Cannot hash cyclic JSON values");
active.add(value);
frame.index = 0;
if (Array.isArray(value)) {
frame.kind = "array";
append("[");
} else {
if (Object.getPrototypeOf(value) !== Object.prototype && Object.getPrototypeOf(value) !== null)
throw new Error("Expected a plain JSON object");
frame.kind = "object";
frame.keys = Object.keys(value).sort(compareText);
frame.wrote = false;
append("{");
}
} else {
append(canonicalJson(value));
stack.pop();
}
} else if (frame.kind === "array") {
const array = frame.value as unknown[];
if (frame.index === array.length) {
append("]");
active.delete(array);
stack.pop();
} else {
const index = frame.index!;
frame.index = index + 1;
if (index) append(",");
// Match canonicalJson's Array.map behavior for sparse arrays too.
if (index in array) stack.push({ kind: "value", value: array[index] });
}
} else {
const object = frame.value as Record<string, unknown>;
if (frame.index === frame.keys!.length) {
append("}");
active.delete(object);
stack.pop();
} else {
const index = frame.index!;
frame.index = index + 1;
const key = frame.keys![index]!,
entry = object[key];
if (entry !== undefined) {
if (frame.wrote) append(",");
frame.wrote = true;
append(JSON.stringify(key) + ":");
stack.push({ kind: "value", value: entry });
}
}
}
if (++steps % 512 === 0 && performance.now() - sliceStarted >= 8) {
await setImmediate();
sliceStarted = performance.now();
}
}
hash.update(buffer);
return `sha256:${hash.digest("hex")}`;
}
const semantic = (value: unknown): unknown => { const semantic = (value: unknown): unknown => {
if (Array.isArray(value)) return value.map(semantic); if (Array.isArray(value)) return value.map(semantic);
if (value && typeof value === "object") if (value && typeof value === "object")
+9 -2
View File
@@ -1,6 +1,13 @@
import {
executionPlanDigestAsync,
type ExecutionPlan,
type PlanPackage,
ExecutionPlanError,
hexDigest,
executionVersions,
} from "./plan.js";
import { createHash } from "node:crypto"; import { createHash } from "node:crypto";
import { canonicalJson } from "../capability-model/evolution.js"; import { canonicalJson } from "../capability-model/evolution.js";
import { type ExecutionPlan, type PlanPackage, ExecutionPlanError, hexDigest, executionVersions } from "./plan.js";
export interface ArtifactFile { export interface ArtifactFile {
path: string; path: string;
@@ -359,7 +366,7 @@ export async function checkExecutionWorld(
): Promise<CheckedWorld> { ): Promise<CheckedWorld> {
if (canonicalJson(plan.definition.versions) !== canonicalJson(executionVersions)) if (canonicalJson(plan.definition.versions) !== canonicalJson(executionVersions))
fail("world", "Unsupported plan codec versions"); fail("world", "Unsupported plan codec versions");
if (hexDigest(plan.definition) !== plan.digest) fail("plan", "Plan digest mismatch"); if ((await executionPlanDigestAsync(plan)) !== plan.digest) fail("plan", "Plan digest mismatch");
const manifests = inputs.map(parsePackageArtifacts); const manifests = inputs.map(parsePackageArtifacts);
unique( unique(
manifests.map((m) => m.packageRevisionId), manifests.map((m) => m.packageRevisionId),
+15 -9
View File
@@ -1,7 +1,7 @@
import { graphExecutionRepresentation } from "./graph-execution.js"; import { graphExecutionRepresentation } from "./graph-execution.js";
import { lstat } from "node:fs/promises"; import { lstat } from "node:fs/promises";
import { join } from "node:path"; import { join } from "node:path";
import { hexDigest, ExecutionPlanError, type ExecutionPlan } from "./plan.js"; import { hexDigest, hexDigestAsync, sealExecutionPlan, ExecutionPlanError, type ExecutionPlan } from "./plan.js";
import { import {
loadExecutionInstallation, loadExecutionInstallation,
createClientContractCatalog, createClientContractCatalog,
@@ -50,7 +50,7 @@ export async function loadCheckedInstallationCandidate(
const input = await readJson(root, "candidate.json", scope); const input = await readJson(root, "candidate.json", scope);
try { try {
const { executionContracts: _legacyContracts, ...workspace } = input.value; const { executionContracts: _legacyContracts, ...workspace } = input.value;
return hexDigest(workspace); return await hexDigestAsync(workspace);
} finally { } finally {
input.releaseTree(); input.releaseTree();
} }
@@ -72,8 +72,8 @@ export async function loadCheckedInstallationCandidate(
const [plan, artifacts, source, entryRequest, kernel, queries] = values; const [plan, artifacts, source, entryRequest, kernel, queries] = values;
if ( if (
plan?.definition?.codec !== "camino-execution-plan-v1" || plan?.definition?.codec !== "camino-execution-plan-v1" ||
hexDigest(plan.definition) !== plan.digest || !(await sealExecutionPlan(plan)) ||
workspaceDigest !== hexDigest(plan.definition.workspace) workspaceDigest !== (await hexDigestAsync(plan.definition.workspace))
) )
throw new ExecutionPlanError( throw new ExecutionPlanError(
"CANDIDATE_PLAN_MISMATCH", "CANDIDATE_PLAN_MISMATCH",
@@ -117,7 +117,11 @@ export async function loadCheckedInstallationCandidate(
["kernel", kernel, "camino-kernel-program-v1"], ["kernel", kernel, "camino-kernel-program-v1"],
["queries", queries, "camino-query-program-v1"], ["queries", queries, "camino-query-program-v1"],
] as const) ] as const)
if (program?.codec !== codec || program.plan !== kernel.plan || hexDigest(program) !== artifacts.programs?.[name]) if (
program?.codec !== codec ||
program.plan !== kernel.plan ||
(await hexDigestAsync(program)) !== artifacts.programs?.[name]
)
throw new ExecutionPlanError( throw new ExecutionPlanError(
"CANDIDATE_PROGRAM_MISMATCH", "CANDIDATE_PROGRAM_MISMATCH",
name, name,
@@ -126,16 +130,17 @@ export async function loadCheckedInstallationCandidate(
const expectedGraph = graphExecutionRepresentation(plan, installation, kernel, queries); const expectedGraph = graphExecutionRepresentation(plan, installation, kernel, queries);
// The stored graph embeds the same kernel/query programs. Validate it in a // The stored graph embeds the same kernel/query programs. Validate it in a
// short-lived scope and retain the representation that shares those trees. // short-lived scope and retain the representation that shares those trees.
await (async () => { const graphDigest = await (async () => {
const input = await readJson(root, "graph-execution.json", scope); const input = await readJson(root, "graph-execution.json", scope);
try { try {
const digest = hexDigest(input.value); const digest = await hexDigestAsync(input.value);
if (digest !== hexDigest(expectedGraph) || artifacts.execution !== digest) if (digest !== (await hexDigestAsync(expectedGraph)) || artifacts.execution !== digest)
throw new ExecutionPlanError( throw new ExecutionPlanError(
"CANDIDATE_EXECUTION_MISMATCH", "CANDIDATE_EXECUTION_MISMATCH",
root, root,
"Stored graph execution differs from checked inputs", "Stored graph execution differs from checked inputs",
); );
return digest;
} finally { } finally {
input.releaseTree(); input.releaseTree();
} }
@@ -164,7 +169,8 @@ export async function loadCheckedInstallationCandidate(
return { return {
reference, reference,
workspace: plan.definition.workspace.workspaceId, workspace: plan.definition.workspace.workspaceId,
world: hexDigest(expectedGraph), // The checked representation was already compared with this digest.
world: graphDigest,
plan: kernel.plan as string, plan: kernel.plan as string,
graphExecution: expectedGraph, graphExecution: expectedGraph,
provenance, provenance,
+5 -14
View File
@@ -1,3 +1,4 @@
import { executionPlanDigest, type ExecutionPlan, resolvePlannedOperation, ExecutionPlanError } from "./plan.js";
import type { import type {
InterfaceRevision, InterfaceRevision,
InterfaceOperation, InterfaceOperation,
@@ -6,7 +7,7 @@ import type {
} from "../capability-model/types.js"; } from "../capability-model/types.js";
import { canonicalJson } from "../capability-model/evolution.js"; import { canonicalJson } from "../capability-model/evolution.js";
import { portableValueSchema, tsType } from "../bindings/portable.js"; import { portableValueSchema, tsType } from "../bindings/portable.js";
import { type ExecutionPlan, resolvePlannedOperation, hexDigest, ExecutionPlanError } from "./plan.js";
import type { BindingSchema } from "../bindings/index.js"; import type { BindingSchema } from "../bindings/index.js";
import type { PackageBuildContract } from "./build-contract.js"; import type { PackageBuildContract } from "./build-contract.js";
import { preparationArtifact, type ReactPreparationArtifact } from "../react-build/declarations.js"; import { preparationArtifact, type ReactPreparationArtifact } from "../react-build/declarations.js";
@@ -55,7 +56,7 @@ export function publicOperationContract(
} }
/** Resolve a public contract to internal dispatch. This does not authorize the receiver. */ /** Resolve a public contract to internal dispatch. This does not authorize the receiver. */
export function linkInterfaceOperation(plan: ExecutionPlan, atom: string, contract: PublicOperationContract) { export function linkInterfaceOperation(plan: ExecutionPlan, atom: string, contract: PublicOperationContract) {
if (hexDigest(plan.definition) !== plan.digest) if (executionPlanDigest(plan) !== plan.digest)
throw new ExecutionPlanError("INVALID_PLAN", atom, "Invalid execution plan digest"); throw new ExecutionPlanError("INVALID_PLAN", atom, "Invalid execution plan digest");
const iface = plan.definition.workspace.interfaceImports.find((i) => i.revisionId === contract.interface); const iface = plan.definition.workspace.interfaceImports.find((i) => i.revisionId === contract.interface);
const operation = iface?.members.flatMap((m) => m.operations).find((o) => o.id === contract.operation); const operation = iface?.members.flatMap((m) => m.operations).find((o) => o.id === contract.operation);
@@ -97,7 +98,7 @@ export function publicQueryContract(pkg: PackageRevision, queryId: string): Publ
}; };
} }
export function linkPackageQuery(plan: ExecutionPlan, contract: PublicQueryContract) { export function linkPackageQuery(plan: ExecutionPlan, contract: PublicQueryContract) {
if (hexDigest(plan.definition) !== plan.digest) if (executionPlanDigest(plan) !== plan.digest)
throw new ExecutionPlanError("INVALID_PLAN", contract.query, "Invalid execution plan digest"); throw new ExecutionPlanError("INVALID_PLAN", contract.query, "Invalid execution plan digest");
const pkg = plan.definition.workspace.packageImports.find((p) => p.revisionId === contract.package); const pkg = plan.definition.workspace.packageImports.find((p) => p.revisionId === contract.package);
if (!pkg || canonicalJson(publicQueryContract(pkg, contract.query)) !== canonicalJson(contract)) if (!pkg || canonicalJson(publicQueryContract(pkg, contract.query)) !== canonicalJson(contract))
@@ -257,17 +258,7 @@ export function generatePackageComponentBindings(
target.kind === "atom" target.kind === "atom"
? `ManagedReference<"atom", ${JSON.stringify(target.atomId)}>` ? `ManagedReference<"atom", ${JSON.stringify(target.atomId)}>`
: `ManagedReference<"interface", ${JSON.stringify(target.interfaceRevisionId)}>`; : `ManagedReference<"interface", ${JSON.stringify(target.interfaceRevisionId)}>`;
const fields = return `{readonly reference: ${reference}}`;
target.kind === "interface"
? find(target.interfaceRevisionId).members.flatMap((member) => {
if ((member.kind !== "value" && member.kind !== "relationship") || !member.queryRead) return [];
const getter = member.operations.find(
(operation) => operation.displayName === (member.kind === "value" ? "get" : "resolve"),
);
return getter ? [`readonly ${JSON.stringify(member.displayName)}: ${tsType(getter.outputType)}`] : [];
})
: [];
return `{readonly reference: ${reference}; readonly values: {${fields.join(";")}}}`;
}) })
.join(",")}]`; .join(",")}]`;
const interfaces = generateInterfaceClientBindings(imports, "@quixos/camino-react", props); const interfaces = generateInterfaceClientBindings(imports, "@quixos/camino-react", props);
+172 -175
View File
@@ -1,3 +1,4 @@
import { executionPlanDigestAsync, type ExecutionPlan, hexDigest, hexDigestAsync, ExecutionPlanError } from "./plan.js";
import { portableReflectionValue } from "./reflection.js"; import { portableReflectionValue } from "./reflection.js";
import type { import type {
BoundDependency, BoundDependency,
@@ -6,7 +7,6 @@ import type {
PersistentAttachment, PersistentAttachment,
} from "../capability-model/types.js"; } from "../capability-model/types.js";
import { type ExecutionInstallation, type ExecutionGroupIdentity } from "./installation.js"; import { type ExecutionInstallation, type ExecutionGroupIdentity } from "./installation.js";
import { type ExecutionPlan, hexDigest, ExecutionPlanError } from "./plan.js";
export interface ExecutionEnvironment { export interface ExecutionEnvironment {
/** Explicit host placement. Merely including an optional module does not select it. */ /** Explicit host placement. Merely including an optional module does not select it. */
@@ -23,12 +23,12 @@ export interface InstalledExecutionGroup extends ExecutionGroupIdentity {
} }
/** Conservative outbound closure. Runtime graph values, reverse callers, source /** Conservative outbound closure. Runtime graph values, reverse callers, source
* provenance and the workspace epoch are deliberately absent from this identity. */ * provenance and the workspace epoch are deliberately absent from this identity. */
export function compileExecutionGroups( export async function compileExecutionGroups(
plan: ExecutionPlan, plan: ExecutionPlan,
installation: ExecutionInstallation, installation: ExecutionInstallation,
environments: Readonly<Record<string, ExecutionEnvironment>>, environments: Readonly<Record<string, ExecutionEnvironment>>,
): InstalledExecutionGroup[] { ): Promise<InstalledExecutionGroup[]> {
if (installation.plan !== plan.digest || hexDigest(plan.definition) !== plan.digest) if (installation.plan !== plan.digest || (await executionPlanDigestAsync(plan)) !== plan.digest)
throw new ExecutionPlanError("GROUP_PLAN_MISMATCH", plan.digest, "Expected one checked installation"); throw new ExecutionPlanError("GROUP_PLAN_MISMATCH", plan.digest, "Expected one checked installation");
const workspace = plan.definition.workspace; const workspace = plan.definition.workspace;
const packages = new Map(workspace.packageImports.map((p) => [p.revisionId as string, p])); const packages = new Map(workspace.packageImports.map((p) => [p.revisionId as string, p]));
@@ -82,178 +82,175 @@ export function compileExecutionGroups(
}; };
const bindingContract = (value: DependencyBinding) => const bindingContract = (value: DependencyBinding) =>
value.kind === "query" ? { ...value, packageRevisionId: logical(value.packageRevisionId) } : value; value.kind === "query" ? { ...value, packageRevisionId: logical(value.packageRevisionId) } : value;
return installation.packages const groups: InstalledExecutionGroup[] = [];
.filter((p) => !!implementations.get(p.revision)) for (const root of installation.packages.filter((p) => !!implementations.get(p.revision))) {
.map((root) => { const consumed = new Map<string, unknown>(),
const consumed = new Map<string, unknown>(), visited = new Set<string>(),
visited = new Set<string>(), visitedQueries = new Set<string>(),
visitedQueries = new Set<string>(), consumedPackages = new Set<string>();
consumedPackages = new Set<string>(); const remember = (key: string, value: unknown) => consumed.set(key, value);
const remember = (key: string, value: unknown) => consumed.set(key, value); const storage = (id: string) => {
const storage = (id: string) => { const value = attachments.get(id);
const value = attachments.get(id); if (!value) throw new ExecutionPlanError("GROUP_STORAGE_MISSING", id, "Uninstalled consumed storage");
if (!value) throw new ExecutionPlanError("GROUP_STORAGE_MISSING", id, "Uninstalled consumed storage"); remember(`storage:${id}`, attachmentContract(value));
remember(`storage:${id}`, attachmentContract(value)); };
}; // Deletion may visit related objects and their owned state. Conservatively
// Deletion may visit related objects and their owned state. Conservatively // include the connected schema component, including possible future edges.
// include the connected schema component, including possible future edges. const lifecycle = (atom: string) => {
const lifecycle = (atom: string) => { const visited = new Set<string>(),
const visited = new Set<string>(), pending = [atom];
pending = [atom]; const atoms = (constraint: Extract<PersistentAttachment, { kind: "edge" }>["endpoints"][number]["constraint"]) =>
const atoms = ( constraint.kind === "atom"
constraint: Extract<PersistentAttachment, { kind: "edge" }>["endpoints"][number]["constraint"], ? [constraint.atomId as string]
) =>
constraint.kind === "atom"
? [constraint.atomId as string]
: workspace.conformances
.filter((c) => c.interfaceRevisionId === constraint.interfaceRevisionId)
.map((c) => c.atomId as string);
while (pending.length) {
const current = pending.pop()!;
if (visited.has(current)) continue;
visited.add(current);
for (const owner of workspace.conformances.filter((c) => c.atomId === current))
for (const attachment of owner.privateAttachments) storage(attachment.id);
for (const attachment of attachments.values())
if (attachment.kind === "edge" && attachment.endpoints.some((e) => atoms(e.constraint).includes(current))) {
storage(attachment.id);
pending.push(...attachment.endpoints.flatMap((e) => atoms(e.constraint)));
}
}
};
const targets = (binding: DependencyBinding, atom: string): string[] => {
if (binding.kind === "interface" && binding.receiver === "input")
return workspace.conformances
.filter((c) => c.interfaceRevisionId === binding.interfaceRevisionId)
.map((c) => c.atomId);
if (!("via" in binding) || !binding.via) return [atom];
storage(binding.via.edgeTypeId);
const edge = attachments.get(binding.via.edgeTypeId);
if (!edge || edge.kind !== "edge")
throw new ExecutionPlanError("GROUP_EDGE_MISSING", atom, "Missing traversal edge");
const endpoint = edge.endpoints.find((e) => e.projectionId !== binding.via!.projectionId)!;
const constraint = endpoint.constraint;
return constraint.kind === "atom"
? [constraint.atomId]
: workspace.conformances : workspace.conformances
.filter((c) => c.interfaceRevisionId === constraint.interfaceRevisionId) .filter((c) => c.interfaceRevisionId === constraint.interfaceRevisionId)
.map((c) => c.atomId); .map((c) => c.atomId as string);
}; while (pending.length) {
const query = (revision: string, id: string) => { const current = pending.pop()!;
const key = JSON.stringify([revision, id]); if (visited.has(current)) continue;
if (visitedQueries.has(key)) return; visited.add(current);
visitedQueries.add(key); for (const owner of workspace.conformances.filter((c) => c.atomId === current))
const value = plan.definition.queries.find((q) => q.id === key); for (const attachment of owner.privateAttachments) storage(attachment.id);
if (!value) throw new ExecutionPlanError("GROUP_QUERY_MISSING", key, "Missing consumed query"); for (const attachment of attachments.values())
remember(`query:${JSON.stringify([logical(revision), id])}`, value.query.checked.definitionDigest); if (attachment.kind === "edge" && attachment.endpoints.some((e) => atoms(e.constraint).includes(current))) {
for (const operation of value.operations) visit(operation); storage(attachment.id);
}; pending.push(...attachment.endpoints.flatMap((e) => atoms(e.constraint)));
const dependencies = (entry: PackageExport, bindings: readonly BoundDependency[], atom: string) => { }
for (const bound of bindings) { }
const target = bound.binding, };
port = entry.dependencyPorts.find((p) => p.id === bound.portId)!; const targets = (binding: DependencyBinding, atom: string): string[] => {
if ("via" in target && target.via) storage(target.via.edgeTypeId); if (binding.kind === "interface" && binding.receiver === "input")
if (target.kind === "reflection") { return workspace.conformances
for (const selector of target.selectors) .filter((c) => c.interfaceRevisionId === binding.interfaceRevisionId)
remember("reflection:" + selector, portableReflectionValue(workspace, selector)); .map((c) => c.atomId);
} else if (target.kind === "state") storage(target.slotId); if (!("via" in binding) || !binding.via) return [atom];
else if (target.kind === "edge") storage(target.edgeTypeId); storage(binding.via.edgeTypeId);
else if (target.kind === "query") query(target.packageRevisionId, target.queryId); const edge = attachments.get(binding.via.edgeTypeId);
else if (target.kind === "interface" && port.requirement.kind === "interface") { if (!edge || edge.kind !== "edge")
const iface = workspace.interfaceImports.find((i) => i.revisionId === target.interfaceRevisionId)!; throw new ExecutionPlanError("GROUP_EDGE_MISSING", atom, "Missing traversal edge");
for (const targetAtom of targets(target, atom)) const endpoint = edge.endpoints.find((e) => e.projectionId !== binding.via!.projectionId)!;
for (const op of port.requirement.operations ?? const constraint = endpoint.constraint;
iface.members.flatMap((m) => m.operations.map((o) => o.id))) return constraint.kind === "atom"
visit(JSON.stringify([targetAtom, target.interfaceRevisionId, op])); ? [constraint.atomId]
} else if (target.kind === "creation") { : workspace.conformances
for (const seed of target.owners) { .filter((c) => c.interfaceRevisionId === constraint.interfaceRevisionId)
const owner = workspace.conformances.find( .map((c) => c.atomId);
(c) => c.atomId === target.atomId && c.interfaceRevisionId === seed.interfaceRevisionId, };
)!; const query = (revision: string, id: string) => {
remember(`birth:${owner.id}`, { const key = JSON.stringify([revision, id]);
id: owner.id, if (visitedQueries.has(key)) return;
atom: owner.atomId, visitedQueries.add(key);
interface: owner.interfaceRevisionId, const value = plan.definition.queries.find((q) => q.id === key);
initialization: owner.initialization ?? [], if (!value) throw new ExecutionPlanError("GROUP_QUERY_MISSING", key, "Missing consumed query");
}); remember(`query:${JSON.stringify([logical(revision), id])}`, value.query.checked.definitionDigest);
for (const attachment of owner.privateAttachments) storage(attachment.id); for (const operation of value.operations) visit(operation);
} };
} else const dependencies = (entry: PackageExport, bindings: readonly BoundDependency[], atom: string) => {
throw new ExecutionPlanError( for (const bound of bindings) {
"GROUP_DEPENDENCY_UNSUPPORTED", const target = bound.binding,
bound.portId, port = entry.dependencyPorts.find((p) => p.id === bound.portId)!;
"Cannot establish execution reuse for this dependency", if ("via" in target && target.via) storage(target.via.edgeTypeId);
); if (target.kind === "reflection") {
} for (const selector of target.selectors)
}; remember("reflection:" + selector, portableReflectionValue(workspace, selector));
const visit = (key: string) => { } else if (target.kind === "state") storage(target.slotId);
if (visited.has(key)) return; else if (target.kind === "edge") storage(target.edgeTypeId);
visited.add(key); else if (target.kind === "query") query(target.packageRevisionId, target.queryId);
const operation = operations.get(key); else if (target.kind === "interface" && port.requirement.kind === "interface") {
if (!operation) throw new ExecutionPlanError("GROUP_OPERATION_MISSING", key, "Missing consumed operation"); const iface = workspace.interfaceImports.find((i) => i.revisionId === target.interfaceRevisionId)!;
const binding = operation.binding; for (const targetAtom of targets(target, atom))
if (binding.kind === "package") { for (const op of port.requirement.operations ?? iface.members.flatMap((m) => m.operations.map((o) => o.id)))
const pkg = packages.get(binding.packageRevisionId)!; visit(JSON.stringify([targetAtom, target.interfaceRevisionId, op]));
const implementation = implementations.get(pkg.revisionId); } else if (target.kind === "creation") {
if (!implementation) for (const seed of target.owners) {
throw new ExecutionPlanError( const owner = workspace.conformances.find(
"GROUP_IMPLEMENTATION_MISSING", (c) => c.atomId === target.atomId && c.interfaceRevisionId === seed.interfaceRevisionId,
pkg.revisionId, )!;
"Consumed package has no selected server implementation", remember(`birth:${owner.id}`, {
); id: owner.id,
consumedPackages.add(pkg.packageId); atom: owner.atomId,
remember(`implementation:${pkg.packageId}`, { interface: owner.interfaceRevisionId,
digest: implementation.contentDigest, initialization: owner.initialization ?? [],
environment: environment(pkg.revisionId), });
}); for (const attachment of owner.privateAttachments) storage(attachment.id);
const entry = pkg.exports.find((e) => e.id === binding.exportId)!; }
const bindings = binding.dependencies.map((d) => ({ portId: d.portId, binding: bindingContract(d.binding) })); } else
const acceptance = (binding.acceptanceDependencies ?? []).map((d) => ({ throw new ExecutionPlanError(
portId: d.portId, "GROUP_DEPENDENCY_UNSUPPORTED",
binding: bindingContract(d.binding), bound.portId,
})); "Cannot establish execution reuse for this dependency",
const contract = { );
input: operation.input, }
output: operation.output, };
execution: operation.execution, const visit = (key: string) => {
scope: operation.scope, if (visited.has(key)) return;
binding: { visited.add(key);
package: pkg.packageId, const operation = operations.get(key);
export: binding.exportId, if (!operation) throw new ExecutionPlanError("GROUP_OPERATION_MISSING", key, "Missing consumed operation");
dependencies: bindings, const binding = operation.binding;
acceptanceDependencies: acceptance, if (binding.kind === "package") {
}, const pkg = packages.get(binding.packageRevisionId)!;
}; const implementation = implementations.get(pkg.revisionId);
// Deduplicate aliases of the same bound export, rather than keying its owner by reverse callers. if (!implementation)
remember(`binding:${hexDigest(contract)}`, contract); throw new ExecutionPlanError(
dependencies(entry, binding.dependencies, operation.atomId); "GROUP_IMPLEMENTATION_MISSING",
if (entry.acceptanceExportId) pkg.revisionId,
dependencies( "Consumed package has no selected server implementation",
pkg.exports.find((e) => e.id === entry.acceptanceExportId)!, );
binding.acceptanceDependencies ?? [], consumedPackages.add(pkg.packageId);
operation.atomId, remember(`implementation:${pkg.packageId}`, {
); digest: implementation.contentDigest,
} else { environment: environment(pkg.revisionId),
remember(`operation:${key}`, operation); });
if (binding.kind === "state") storage(binding.slotId); const entry = pkg.exports.find((e) => e.id === binding.exportId)!;
if (binding.kind === "edge") storage(binding.edgeTypeId); const bindings = binding.dependencies.map((d) => ({ portId: d.portId, binding: bindingContract(d.binding) }));
if (binding.kind === "lifecycle") lifecycle(operation.atomId); const acceptance = (binding.acceptanceDependencies ?? []).map((d) => ({
} portId: d.portId,
}; binding: bindingContract(d.binding),
for (const operation of plan.definition.operations) }));
if (operation.binding.kind === "package" && operation.binding.packageRevisionId === root.revision) const contract = {
visit(operation.key); input: operation.input,
const own = implementations.get(root.revision)!; output: operation.output,
const exports = packages.get(root.revision)!.exports.map(({ displayName: _name, dependencyPorts, ...entry }) => ({ execution: operation.execution,
...entry, scope: operation.scope,
dependencyPorts: dependencyPorts.map(({ displayName: _name, ...port }) => port), binding: {
})); package: pkg.packageId,
const entries = [...consumed].sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)); export: binding.exportId,
return { dependencies: bindings,
logicalId: logical(root.revision), acceptanceDependencies: acceptance,
packageRevision: root.revision, },
executionDigest: `sha256:${hexDigest({ implementation: own.contentDigest, exports, environment: environment(root.revision), versions: plan.definition.versions, consumed: entries })}`, };
consumedPackages: [...consumedPackages].sort(), // Deduplicate aliases of the same bound export, rather than keying its owner by reverse callers.
}; remember(`binding:${hexDigest(contract)}`, contract);
dependencies(entry, binding.dependencies, operation.atomId);
if (entry.acceptanceExportId)
dependencies(
pkg.exports.find((e) => e.id === entry.acceptanceExportId)!,
binding.acceptanceDependencies ?? [],
operation.atomId,
);
} else {
remember(`operation:${key}`, operation);
if (binding.kind === "state") storage(binding.slotId);
if (binding.kind === "edge") storage(binding.edgeTypeId);
if (binding.kind === "lifecycle") lifecycle(operation.atomId);
}
};
for (const operation of plan.definition.operations)
if (operation.binding.kind === "package" && operation.binding.packageRevisionId === root.revision)
visit(operation.key);
const own = implementations.get(root.revision)!;
const exports = packages.get(root.revision)!.exports.map(({ displayName: _name, dependencyPorts, ...entry }) => ({
...entry,
dependencyPorts: dependencyPorts.map(({ displayName: _name, ...port }) => port),
}));
const entries = [...consumed].sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0));
groups.push({
logicalId: logical(root.revision),
packageRevision: root.revision,
executionDigest: `sha256:${await hexDigestAsync({ implementation: own.contentDigest, exports, environment: environment(root.revision), versions: plan.definition.versions, consumed: entries })}`,
consumedPackages: [...consumedPackages].sort(),
}); });
}
return groups;
} }
+3 -2
View File
@@ -1,4 +1,5 @@
import { ExecutionPlanError, hexDigest, type ExecutionPlan } from "./plan.js"; import { executionPlanDigest, ExecutionPlanError, hexDigest, type ExecutionPlan } from "./plan.js";
import type { ExecutionInstallation } from "./installation.js"; import type { ExecutionInstallation } from "./installation.js";
/** Execution inputs, not build evidence. Nominal revision IDs remain dispatch /** Execution inputs, not build evidence. Nominal revision IDs remain dispatch
@@ -10,7 +11,7 @@ export function graphExecutionRepresentation(
kernel: unknown, kernel: unknown,
queries: unknown, queries: unknown,
) { ) {
if (installation.plan !== plan.digest || hexDigest(plan.definition) !== plan.digest) if (installation.plan !== plan.digest || executionPlanDigest(plan) !== plan.digest)
throw new ExecutionPlanError("GRAPH_PLAN_MISMATCH", "graph", "Expected one checked installation"); throw new ExecutionPlanError("GRAPH_PLAN_MISMATCH", "graph", "Expected one checked installation");
if ( if (
!kernel || !kernel ||
+29 -20
View File
@@ -1,9 +1,10 @@
import { executionPlanDigestAsync, ExecutionPlanError, type ExecutionPlan } from "./plan.js";
import { compileInspectionTemplates, type InspectionTemplate, type InspectionKernel } from "./inspection.js"; import { compileInspectionTemplates, type InspectionTemplate, type InspectionKernel } from "./inspection.js";
import path from "node:path"; import path from "node:path";
import { loadCheckedArtifactWorld } from "./receipts.js"; import { loadCheckedArtifactWorld } from "./receipts.js";
import { contentArtifactUrl, loadArtifactWorld, type LoadedArtifactWorld } from "./files.js"; import { contentArtifactUrl, loadArtifactWorld, type LoadedArtifactWorld } from "./files.js";
import { selectArtifactImplementation, type ArtifactImplementation, type ComponentArtifact } from "./artifacts.js"; import { selectArtifactImplementation, type ArtifactImplementation, type ComponentArtifact } from "./artifacts.js";
import { ExecutionPlanError, hexDigest, type ExecutionPlan } from "./plan.js";
import { import {
publicOperationContract, publicOperationContract,
publicQueryContract, publicQueryContract,
@@ -41,13 +42,13 @@ export interface ClientContractCatalog {
}[]; }[];
} }
/** Explicit projection prevents accidental spreading of filesystem roots or private bindings. */ /** Explicit projection prevents accidental spreading of filesystem roots or private bindings. */
export function clientContractCatalog( export async function clientContractCatalog(
plan: ExecutionPlan, plan: ExecutionPlan,
installation: ExecutionInstallation, installation: ExecutionInstallation,
requestedPackages: readonly string[], requestedPackages: readonly string[],
checkedKernel?: InspectionKernel, checkedKernel?: InspectionKernel,
): ClientContractCatalog { ): Promise<ClientContractCatalog> {
if (installation.plan !== plan.digest || hexDigest(plan.definition) !== plan.digest) if (installation.plan !== plan.digest || (await executionPlanDigestAsync(plan)) !== plan.digest)
throw new ExecutionPlanError( throw new ExecutionPlanError(
"CATALOG_PLAN_MISMATCH", "CATALOG_PLAN_MISMATCH",
plan.digest, plan.digest,
@@ -112,6 +113,7 @@ export function createClientContractCatalog(
const revisions = plan.definition.workspace.packageImports.map((pkg) => pkg.revisionId); const revisions = plan.definition.workspace.packageImports.map((pkg) => pkg.revisionId);
const installed = new Set<string>(revisions); const installed = new Set<string>(revisions);
let catalog: ClientContractCatalog | undefined; let catalog: ClientContractCatalog | undefined;
let preparing: Promise<void> | undefined;
let release: (() => void) | undefined; let release: (() => void) | undefined;
let closed = false; let closed = false;
const freeze = (value: unknown, seen = new WeakSet<object>()) => { const freeze = (value: unknown, seen = new WeakSet<object>()) => {
@@ -121,7 +123,7 @@ export function createClientContractCatalog(
Object.freeze(value); Object.freeze(value);
}; };
return { return {
select(requestedPackages: readonly string[]): ClientContractCatalog { async select(requestedPackages: readonly string[]): Promise<ClientContractCatalog> {
if (closed) throw Error("CANDIDATE_METADATA_CLOSED"); if (closed) throw Error("CANDIDATE_METADATA_CLOSED");
for (const revision of requestedPackages) for (const revision of requestedPackages)
if (!installed.has(revision)) if (!installed.has(revision))
@@ -129,22 +131,29 @@ export function createClientContractCatalog(
if (!catalog) { if (!catalog) {
// Like other candidate admission charges, this is an allocation estimate, // Like other candidate admission charges, this is an allocation estimate,
// not a V8 heap limit. The process/cgroup ceiling bounds transient work. // not a V8 heap limit. The process/cgroup ceiling bounds transient work.
const reservation = metadata.reserve(32 * 1024 * 1024); preparing ??= (async () => {
try { const reservation = metadata.reserve(32 * 1024 * 1024);
const compiled = clientContractCatalog(plan, installation, revisions, checkedKernel); try {
const bytes = Buffer.byteLength(JSON.stringify(compiled)); const compiled = await clientContractCatalog(plan, installation, revisions, checkedKernel);
if (bytes > 8 * 1024 * 1024) throw Error("CANDIDATE_CATALOG_LIMIT"); if (closed) throw Error("CANDIDATE_METADATA_CLOSED");
freeze(compiled); const bytes = Buffer.byteLength(JSON.stringify(compiled));
// No await between reservations: replacing the transient upper bound if (bytes > 8 * 1024 * 1024) throw Error("CANDIDATE_CATALOG_LIMIT");
// with a smaller retained estimate cannot race another admission. freeze(compiled);
reservation(); // No await between reservations: replacing the transient upper bound
release = metadata.reserve(Math.max(64 * 1024, bytes * 4)); // with a smaller retained estimate cannot race another admission.
catalog = compiled; reservation();
} catch (error) { release = metadata.reserve(Math.max(64 * 1024, bytes * 4));
reservation(); catalog = compiled;
throw error; } catch (error) {
} reservation();
throw error;
}
})().finally(() => {
preparing = undefined;
});
await preparing;
} }
if (closed || !catalog) throw Error("CANDIDATE_METADATA_CLOSED");
const requested = new Set(requestedPackages); const requested = new Set(requestedPackages);
return { return {
inspections: catalog.inspections, inspections: catalog.inspections,
+3 -2
View File
@@ -1,3 +1,4 @@
import { executionPlanDigest, type ExecutionPlan, ExecutionPlanError, hexDigest } from "./plan.js";
import { portableReflectionType, portableReflectionValue } from "./reflection.js"; import { portableReflectionType, portableReflectionValue } from "./reflection.js";
import type { import type {
ValueType, ValueType,
@@ -7,7 +8,7 @@ import type {
BoundDependency, BoundDependency,
PackageExport, PackageExport,
} from "../capability-model/types.js"; } from "../capability-model/types.js";
import { type ExecutionPlan, ExecutionPlanError, hexDigest } from "./plan.js";
import { portableValueSchema } from "../bindings/portable.js"; import { portableValueSchema } from "../bindings/portable.js";
import { subscriptionContract } from "../capability-model/journals.js"; import { subscriptionContract } from "../capability-model/journals.js";
type PreparedStep = string | null | { case: string; id: string }; type PreparedStep = string | null | { case: string; id: string };
@@ -25,7 +26,7 @@ function preparedInputPaths(type: ValueType, path: PreparedStep[] = []): Prepare
} }
/** Small data-only interpreter input; no compiler, parser, Node module or SQL dependency reaches the browser. */ /** Small data-only interpreter input; no compiler, parser, Node module or SQL dependency reaches the browser. */
export function compileKernelProgram(plan: ExecutionPlan): unknown { export function compileKernelProgram(plan: ExecutionPlan): unknown {
if (hexDigest(plan.definition) !== plan.digest) if (executionPlanDigest(plan) !== plan.digest)
throw new ExecutionPlanError("INVALID_PLAN", "kernel", "Plan digest mismatch"); throw new ExecutionPlanError("INVALID_PLAN", "kernel", "Plan digest mismatch");
const workspace = plan.definition.workspace; const workspace = plan.definition.workspace;
if (workspace.sharedAttachments.some((attachment) => attachment.kind !== "edge")) if (workspace.sharedAttachments.some((attachment) => attachment.kind !== "edge"))
+8 -2
View File
@@ -1,6 +1,9 @@
import { constants } from "node:fs"; import { constants } from "node:fs";
import { open } from "node:fs/promises"; import { open } from "node:fs/promises";
const admissionFailure = (code: string, kind: "file-bytes", measured: number, limit: number) =>
Object.assign(Error(code), { metadataAdmission: { kind, measured, limit } });
/** Admission estimates, not a hard V8 heap limit. A process/cgroup ceiling is /** Admission estimates, not a hard V8 heap limit. A process/cgroup ceiling is
* still required. Charge input, parse trees and derived indexes before reading * still required. Charge input, parse trees and derived indexes before reading
* or parsing. Each live candidate retains its reservation until explicit close. */ * or parsing. Each live candidate retains its reservation until explicit close. */
@@ -22,6 +25,9 @@ export class CandidateMetadataBudget {
snapshot() { snapshot() {
return { bytes: this.bytes, candidates: this.scopes, owners: this.owners.size, limits: this.limits }; return { bytes: this.bytes, candidates: this.scopes, owners: this.owners.size, limits: this.limits };
} }
ownedBytes(owner: string) {
return this.owners.get(owner) ?? 0;
}
acquire(owner: string) { acquire(owner: string) {
if (!owner || owner.length > 4096) throw Error("INVALID_CANDIDATE_METADATA_OWNER"); if (!owner || owner.length > 4096) throw Error("INVALID_CANDIDATE_METADATA_OWNER");
if (this.scopes >= this.limits.candidates) throw Error("CANDIDATE_METADATA_LIMIT"); if (this.scopes >= this.limits.candidates) throw Error("CANDIDATE_METADATA_LIMIT");
@@ -113,8 +119,8 @@ export async function readCandidateMetadata(
let releaseInput: (() => void) | undefined; let releaseInput: (() => void) | undefined;
try { try {
const stat = await handle.stat(); const stat = await handle.stat();
if (!stat.isFile() || !Number.isSafeInteger(stat.size) || stat.size > limit) if (!stat.isFile() || !Number.isSafeInteger(stat.size)) throw Error("CANDIDATE_METADATA_FILE_LIMIT");
throw Error("CANDIDATE_METADATA_FILE_LIMIT"); if (stat.size > limit) throw admissionFailure("CANDIDATE_METADATA_FILE_LIMIT", "file-bytes", stat.size, limit);
// Reserve the input buffer and UTF-16 decoding before allocating either. // Reserve the input buffer and UTF-16 decoding before allocating either.
releaseInput = scope.reserve((stat.size + 1) * 3); releaseInput = scope.reserve((stat.size + 1) * 3);
const bytes = Buffer.alloc(stat.size + 1); const bytes = Buffer.alloc(stat.size + 1);
+3 -2
View File
@@ -1,6 +1,7 @@
import { executionPlanDigest, ExecutionPlanError, hexDigest, type ExecutionPlan } from "./plan.js";
import { parse } from "@babel/parser"; import { parse } from "@babel/parser";
import { builtinModules } from "node:module"; import { builtinModules } from "node:module";
import { ExecutionPlanError, hexDigest, type ExecutionPlan } from "./plan.js";
import type { ExecutionInstallation } from "./installation.js"; import type { ExecutionInstallation } from "./installation.js";
import type { ArtifactImplementation, ArtifactReader } from "./artifacts.js"; import type { ArtifactImplementation, ArtifactReader } from "./artifacts.js";
@@ -212,7 +213,7 @@ export async function reportExecutionPlacement(
installation: ExecutionInstallation, installation: ExecutionInstallation,
read: ArtifactReader, read: ArtifactReader,
) { ) {
if (installation.plan !== plan.digest || hexDigest(plan.definition) !== plan.digest) if (installation.plan !== plan.digest || executionPlanDigest(plan) !== plan.digest)
throw new ExecutionPlanError( throw new ExecutionPlanError(
"PLACEMENT_PLAN_MISMATCH", "PLACEMENT_PLAN_MISMATCH",
plan.digest, plan.digest,
+52 -1
View File
@@ -11,12 +11,13 @@ import type {
OperationId, OperationId,
} from "../capability-model/types.js"; } from "../capability-model/types.js";
import { validateWorkspaceRevision } from "../capability-model/validation.js"; import { validateWorkspaceRevision } from "../capability-model/validation.js";
import { canonicalJson, contentDigest } from "../capability-model/evolution.js"; import { canonicalJson, contentDigest, contentDigestAsync } from "../capability-model/evolution.js";
import { resolveForwardedBinding } from "../capability-model/forwarding.js"; import { resolveForwardedBinding } from "../capability-model/forwarding.js";
import { linkQueries, type LinkedQuery } from "../query/link.js"; import { linkQueries, type LinkedQuery } from "../query/link.js";
import { type BindingSchema } from "../bindings/index.js"; import { type BindingSchema } from "../bindings/index.js";
import { unsupportedQueryOperator } from "./query-operators.js"; import { unsupportedQueryOperator } from "./query-operators.js";
import { packageBuildContexts } from "./build-contract.js"; import { packageBuildContexts } from "./build-contract.js";
import { setImmediate } from "node:timers/promises";
export class ExecutionPlanError extends Error { export class ExecutionPlanError extends Error {
constructor( constructor(
@@ -29,6 +30,56 @@ export class ExecutionPlanError extends Error {
} }
} }
export const hexDigest = (value: unknown): string => contentDigest(value).slice("sha256:".length); export const hexDigest = (value: unknown): string => contentDigest(value).slice("sha256:".length);
export const hexDigestAsync = async (value: unknown): Promise<string> =>
(await contentDigestAsync(value)).slice("sha256:".length);
// Checked runtime metadata is owned JSON, not live Graph data. Reuse its proof
// only after every reachable record is immutable. Weak keys retain neither old
// Candidates nor an application cache; unsealed compiler inputs are rehashed.
const sealedPlanDigests = new WeakMap<ExecutionPlan, string>();
export const executionPlanDigest = (plan: ExecutionPlan): string =>
sealedPlanDigests.get(plan) ?? hexDigest(plan.definition);
export const executionPlanDigestAsync = async (plan: ExecutionPlan): Promise<string> =>
sealedPlanDigests.get(plan) ?? (await hexDigestAsync(plan.definition));
/** Transfers owned parsed JSON into immutable runtime metadata. Freeze before
* yielding to hashing so concurrent mutation cannot invalidate the proof. */
export async function sealExecutionPlan(plan: ExecutionPlan): Promise<boolean> {
if (sealedPlanDigests.has(plan)) return true;
if (!Object.hasOwn(plan, "definition") || !Object.hasOwn(plan, "digest")) return false;
const pending: object[] = [plan],
seen = new WeakSet<object>();
let sliceStarted = performance.now(),
count = 0;
while (pending.length) {
const value = pending.pop()!;
if (seen.has(value)) continue;
if (
!Array.isArray(value) &&
Object.getPrototypeOf(value) !== Object.prototype &&
Object.getPrototypeOf(value) !== null
)
throw new ExecutionPlanError("INVALID_PLAN_JSON", "plan", "Expected owned JSON records");
for (const key of Reflect.ownKeys(value)) {
const descriptor = Object.getOwnPropertyDescriptor(value, key)!;
if (typeof key !== "string" || !Object.hasOwn(descriptor, "value"))
throw new ExecutionPlanError(
"INVALID_PLAN_JSON",
"plan",
"Runtime metadata cannot contain accessors or symbols",
);
if (descriptor.value !== null && typeof descriptor.value === "object") pending.push(descriptor.value);
}
Object.freeze(value);
seen.add(value);
if (++count % 1024 === 0 && performance.now() - sliceStarted >= 8) {
await setImmediate();
sliceStarted = performance.now();
}
}
const digest = await hexDigestAsync(plan.definition);
if (digest !== plan.digest) return false;
sealedPlanDigests.set(plan, digest);
return true;
}
const sorted = <T>(values: readonly T[], key: (value: T) => string): T[] => const sorted = <T>(values: readonly T[], key: (value: T) => string): T[] =>
[...values].sort((a, b) => (key(a) < key(b) ? -1 : key(a) > key(b) ? 1 : 0)); [...values].sort((a, b) => (key(a) < key(b) ? -1 : key(a) > key(b) ? 1 : 0));
export const publicOperationKey = (atom: string, iface: string, operation: string): string => export const publicOperationKey = (atom: string, iface: string, operation: string): string =>
+3 -2
View File
@@ -1,4 +1,5 @@
import { ExecutionPlanError, hexDigest, type ExecutionPlan, type PlannedQuery } from "./plan.js"; import { executionPlanDigest, ExecutionPlanError, type ExecutionPlan, type PlannedQuery } from "./plan.js";
/** Contracts promised by a direct result. Interface dependencies are explicit; accidental /** Contracts promised by a direct result. Interface dependencies are explicit; accidental
* overlap among today's implementations does not silently widen an exported interface contract. */ * overlap among today's implementations does not silently widen an exported interface contract. */
export function resultInterfaces(plan: ExecutionPlan, operationKey: string): string[] { export function resultInterfaces(plan: ExecutionPlan, operationKey: string): string[] {
@@ -23,7 +24,7 @@ export function resultInterfaces(plan: ExecutionPlan, operationKey: string): str
} }
/** Compile-time observeResult compatibility. Observation does not grant read or mutation authority. */ /** Compile-time observeResult compatibility. Observation does not grant read or mutation authority. */
export function checkResultProjection(plan: ExecutionPlan, operationKey: string, queryId: string): PlannedQuery { export function checkResultProjection(plan: ExecutionPlan, operationKey: string, queryId: string): PlannedQuery {
if (hexDigest(plan.definition) !== plan.digest) if (executionPlanDigest(plan) !== plan.digest)
throw new ExecutionPlanError("INVALID_PLAN", "projection", "Plan digest mismatch"); throw new ExecutionPlanError("INVALID_PLAN", "projection", "Plan digest mismatch");
const query = plan.definition.queries.find((q) => q.id === queryId); const query = plan.definition.queries.find((q) => q.id === queryId);
if (!query) throw new ExecutionPlanError("UNKNOWN_PROJECTION", queryId, "No installed query"); if (!query) throw new ExecutionPlanError("UNKNOWN_PROJECTION", queryId, "No installed query");
+13 -23
View File
@@ -1,27 +1,17 @@
import { compileInspectionTemplates } from "./inspection.js"; import { compileInspectionTemplates, type InspectionKernel } from "./inspection.js";
import { compileKernelProgram } from "./kernel.js"; import { hexDigestAsync, type ExecutionPlan } from "./plan.js";
import { hexDigest, type ExecutionPlan } from "./plan.js"; import type { ClientContractCatalog } from "./installation.js";
import { clientContractCatalog, type ExecutionInstallation } from "./installation.js";
import { publicOperationContract, publicQueryContract } from "./client-contracts.js"; import { publicOperationContract, publicQueryContract } from "./client-contracts.js";
/** Explicit public projection. Never serialize conformance storage or package ports. */ /** Explicit public projection of checked inputs. Never serialize conformance
export function publicDefinitionSnapshot(plan: ExecutionPlan, installation: ExecutionInstallation) { * storage or package ports, or recompile a historical Candidate at runtime.
* The caller supplies that Candidate's checked, cached public catalog. */
export async function publicDefinitionSnapshot(
plan: ExecutionPlan,
kernel: InspectionKernel,
catalog: ClientContractCatalog,
) {
const workspace = plan.definition.workspace; const workspace = plan.definition.workspace;
const kernel = compileKernelProgram(plan) as {
operations: {
atom: string;
interface: string;
operation: string;
unsupported: string | null;
effect: string;
targets: string[];
}[];
};
const catalog = clientContractCatalog(
plan,
installation,
installation.packages.map((pkg) => pkg.revision),
);
const rows = { const rows = {
atoms: workspace.atoms.map((atom) => ({ id: atom.id, name: atom.displayName, documentation: atom.documentation })), atoms: workspace.atoms.map((atom) => ({ id: atom.id, name: atom.displayName, documentation: atom.documentation })),
interfaces: workspace.interfaceImports.map((iface) => ({ interfaces: workspace.interfaceImports.map((iface) => ({
@@ -68,7 +58,7 @@ export function publicDefinitionSnapshot(plan: ExecutionPlan, installation: Exec
), ),
})), })),
queries: [ queries: [
...compileInspectionTemplates(plan).contracts.map((descriptor) => ({ ...compileInspectionTemplates(plan, kernel).contracts.map((descriptor) => ({
id: JSON.stringify([descriptor.package, descriptor.query]), id: JSON.stringify([descriptor.package, descriptor.query]),
name: "Public inspection", name: "Public inspection",
package: descriptor.package, package: descriptor.package,
@@ -100,5 +90,5 @@ export function publicDefinitionSnapshot(plan: ExecutionPlan, installation: Exec
{ id: string; [key: string]: unknown }[] { id: string; [key: string]: unknown }[]
>; >;
for (const entries of Object.values(publicRows)) entries.sort((a, b) => (a.id < b.id ? -1 : a.id > b.id ? 1 : 0)); for (const entries of Object.values(publicRows)) entries.sort((a, b) => (a.id < b.id ? -1 : a.id > b.id ? 1 : 0));
return { codec: "camino-definitions-v1" as const, id: hexDigest(publicRows), rows: publicRows }; return { codec: "camino-definitions-v1" as const, id: await hexDigestAsync(publicRows), rows: publicRows };
} }
+3 -2
View File
@@ -1,7 +1,8 @@
import { executionPlanDigest, ExecutionPlanError, type ExecutionPlan } from "./plan.js";
import { compileKernelProgram } from "./kernel.js"; import { compileKernelProgram } from "./kernel.js";
import { compileInspectionTemplates } from "./inspection.js"; import { compileInspectionTemplates } from "./inspection.js";
import { portableValueSchema } from "../bindings/portable.js"; import { portableValueSchema } from "../bindings/portable.js";
import { ExecutionPlanError, hexDigest, type ExecutionPlan } from "./plan.js";
import type { ValueType } from "../capability-model/types.js"; import type { ValueType } from "../capability-model/types.js";
import { compileQueryComposition } from "../query/composition.js"; import { compileQueryComposition } from "../query/composition.js";
import { queryTreeBlueprint } from "./query-trees.js"; import { queryTreeBlueprint } from "./query-trees.js";
@@ -24,7 +25,7 @@ const lowerTypes = (value: unknown): unknown =>
/** Checked query IR and installed getter identities, without GraphQL schemas/parsers or SQL adapters. /** Checked query IR and installed getter identities, without GraphQL schemas/parsers or SQL adapters.
* Keep authored selection names only for output paths; field access uses resolved interface/member IDs. */ * Keep authored selection names only for output paths; field access uses resolved interface/member IDs. */
export function compileQueryProgram(plan: ExecutionPlan): unknown { export function compileQueryProgram(plan: ExecutionPlan): unknown {
if (hexDigest(plan.definition) !== plan.digest) if (executionPlanDigest(plan) !== plan.digest)
throw new ExecutionPlanError("INVALID_PLAN", "queries", "Plan digest mismatch"); throw new ExecutionPlanError("INVALID_PLAN", "queries", "Plan digest mismatch");
const allQueries = new Map(plan.definition.queries.map(({ id, query }) => [id, query.checked])); const allQueries = new Map(plan.definition.queries.map(({ id, query }) => [id, query.checked]));
const compositions = plan.definition.workspace.packageImports.flatMap((pkg) => const compositions = plan.definition.workspace.packageImports.flatMap((pkg) =>
+3 -2
View File
@@ -1,8 +1,9 @@
import { executionPlanDigest, hexDigest, type ExecutionPlan, type PlannedQuery } from "./plan.js";
import { compileQuery } from "../query/compile.js"; import { compileQuery } from "../query/compile.js";
import { linkQueries } from "../query/link.js"; import { linkQueries } from "../query/link.js";
import { capabilityId } from "../capability-model/types.js"; import { capabilityId } from "../capability-model/types.js";
import { portableValueSchema } from "../bindings/portable.js"; import { portableValueSchema } from "../bindings/portable.js";
import { hexDigest, type ExecutionPlan, type PlannedQuery } from "./plan.js";
import { compileKernelProgram } from "./kernel.js"; import { compileKernelProgram } from "./kernel.js";
import { queryProgramEntry } from "./queries.js"; import { queryProgramEntry } from "./queries.js";
import { unsupportedQueryOperator } from "./query-operators.js"; import { unsupportedQueryOperator } from "./query-operators.js";
@@ -17,7 +18,7 @@ export interface QueryDocument {
/** Runtime query documents use the same language, nominal contracts, linking /** Runtime query documents use the same language, nominal contracts, linking
* and interpreter as packaged queries. They introduce no resources or code. */ * and interpreter as packaged queries. They introduce no resources or code. */
export async function compilePublicQuery(plan: ExecutionPlan, request: QueryDocument) { export async function compilePublicQuery(plan: ExecutionPlan, request: QueryDocument) {
if (hexDigest(plan.definition) !== plan.digest) throw Error("INVALID_PLAN"); if (executionPlanDigest(plan) !== plan.digest) throw Error("INVALID_PLAN");
if ( if (
typeof request.document !== "string" || typeof request.document !== "string" ||
Buffer.byteLength(request.document) > 32768 || Buffer.byteLength(request.document) > 32768 ||
+27 -5
View File
@@ -113,6 +113,13 @@ export function lowerQueryTree(
if (!root || selection.some((field) => field !== root)) if (!root || selection.some((field) => field !== root))
throw new QueryCompileError("QUERY_TREE_ROOT", "A Query Tree requires one unaliased root selection"); throw new QueryCompileError("QUERY_TREE_ROOT", "A Query Tree requires one unaliased root selection");
const plan: QueryTreePlan = { root: "root", nodes: [], projections: [], maxOccurrences: 0 }; const plan: QueryTreePlan = { root: "root", nodes: [], projections: [], maxOccurrences: 0 };
const collectionBound = (field: QuerySelection): number | undefined => {
const limit = field.arguments.first ?? field.arguments.all;
// Checked GraphQL Int literals retain their decimal spelling in the IR.
if (limit?.kind !== "literal" || !["string", "number"].includes(typeof limit.value)) return;
const value = Number(limit.value);
return Number.isSafeInteger(value) && value > 0 ? Math.min(value, declaration.budgets.rows) : undefined;
};
const project = (id: string, subject: InterfaceRevisionId, fields: QuerySelection[], shape: ValueType) => { const project = (id: string, subject: InterfaceRevisionId, fields: QuerySelection[], shape: ValueType) => {
if (plan.projections.length >= 256) if (plan.projections.length >= 256)
throw new QueryCompileError("QUERY_TREE_LIMIT", "Query Tree exceeds 256 projections"); throw new QueryCompileError("QUERY_TREE_LIMIT", "Query Tree exceeds 256 projections");
@@ -153,9 +160,15 @@ export function lowerQueryTree(
for (const field of fields) { for (const field of fields) {
if (field.boundary || !containsBoundary(field.selection)) continue; if (field.boundary || !containsBoundary(field.selection)) continue;
const targets: { path: string[]; node: string }[] = []; const targets: { path: string[]; node: string }[] = [];
const prune = (fields: QuerySelection[], shape: ValueType, path: string[], bound: number): QuerySelection[] => { const prune = (
if (shape.kind === "optional") return prune(fields, shape.value, path, bound); fields: QuerySelection[],
if (shape.kind === "list") return prune(fields, shape.value, [...path, "[]"], bound * declaration.budgets.rows); shape: ValueType,
path: string[],
bound: number,
listLimit = declaration.budgets.rows,
): QuerySelection[] => {
if (shape.kind === "optional") return prune(fields, shape.value, path, bound, listLimit);
if (shape.kind === "list") return prune(fields, shape.value, [...path, "[]"], bound * listLimit);
const target = objectInterface(fields); const target = objectInterface(fields);
if (target) { if (target) {
targets.push({ targets.push({
@@ -168,7 +181,13 @@ export function lowerQueryTree(
.filter((field) => containsBoundary(field.selection)) .filter((field) => containsBoundary(field.selection))
.map((field) => ({ .map((field) => ({
...field, ...field,
selection: prune(field.selection, fieldType(shape, field.key), [...path, field.key], bound), selection: prune(
field.selection,
fieldType(shape, field.key),
[...path, field.key],
bound,
collectionBound(field) ?? listLimit,
),
})); }));
// Relationship occurrence identity is its entry key, including duplicate // Relationship occurrence identity is its entry key, including duplicate
// target Objects. Never substitute list position or Object identity. // target Objects. Never substitute list position or Object identity.
@@ -177,7 +196,10 @@ export function lowerQueryTree(
return minimal; return minimal;
}; };
const type = fieldType(shape, field.key); const type = fieldType(shape, field.key);
const minimal = { ...field, selection: prune(field.selection, type, [field.key], occurrences) }; const minimal = {
...field,
selection: prune(field.selection, type, [field.key], occurrences, collectionBound(field)),
};
const selected = [...identity(fields), minimal]; const selected = [...identity(fields), minimal];
current.bindings.push({ current.bindings.push({
name: field.key, name: field.key,
+3
View File
@@ -364,6 +364,9 @@ export async function expandPresentationQueries(workspace: WorkspaceRevision): P
for (const pkg of workspace.packageImports) { for (const pkg of workspace.packageImports) {
for (const original of [...(pkg.checkedQueries ?? [])]) { for (const original of [...(pkg.checkedQueries ?? [])]) {
if (!original.declaration.id.startsWith("presentation:navigation:")) continue; if (!original.declaration.id.startsWith("presentation:navigation:")) continue;
// Identity must remain independent of every occurrence's data projection.
// Full retained acquisition may include those requirements together.
if (/:identity-(inputs|view)$/.test(original.declaration.id)) continue;
const inputs = (stateInputs.get(original.declaration.root.interface) ?? []).map((input) => ({ const inputs = (stateInputs.get(original.declaration.root.interface) ?? []).map((input) => ({
...input, ...input,
query: query:
+15
View File
@@ -1,5 +1,20 @@
#!/usr/bin/env node #!/usr/bin/env node
import { loadQuixosLock } from "./loader.js"; import { loadQuixosLock } from "./loader.js";
import { parseQuixosLockDocument } from "./parser.js";
import { readFile, stat } from "node:fs/promises";
// A trusted fetcher can inspect the root's declared platform pin without
// following authored import paths or evaluating Nix. The input is a fetched
// Git blob, not a filesystem tree provided by an author.
if (process.argv[2] === "--platform-only") {
const filename = process.argv[3];
if (process.argv.length !== 4 || !filename || (await stat(filename)).size > 1024 * 1024)
throw Error("INVALID_PLATFORM_SOURCE_LOCK");
const result = parseQuixosLockDocument(await readFile(filename, "utf8"));
if (!result.ok || result.document.kind !== "root") throw Error("INVALID_PLATFORM_SOURCE_LOCK");
console.log(JSON.stringify({ repository: result.document.quixos.repository, commit: result.document.quixos.commit }));
process.exit(0);
}
const fileName = process.argv[2]; const fileName = process.argv[2];
if (!fileName || process.argv.length !== 3) { if (!fileName || process.argv.length !== 3) {
+3
View File
@@ -5,6 +5,7 @@ import { join } from "node:path";
import { tmpdir } from "node:os"; import { tmpdir } from "node:os";
import { CandidateMetadataBudget, readCandidateMetadata } from "../src/execution-world/metadata.js"; import { CandidateMetadataBudget, readCandidateMetadata } from "../src/execution-world/metadata.js";
import { loadCheckedInstallationCandidate } from "../src/execution-world/candidate.js"; import { loadCheckedInstallationCandidate } from "../src/execution-world/candidate.js";
import { hexDigestAsync } from "../src/execution-world/plan.js";
test( test(
"a real checked application can stage its replacement within the default metadata budget", "a real checked application can stage its replacement within the default metadata budget",
@@ -21,6 +22,8 @@ test(
try { try {
assert.equal(budget.snapshot().bytes, retained * 2); assert.equal(budget.snapshot().bytes, retained * 2);
assert.deepEqual(second.reference, first.reference, "Compaction preserves exact checked identity"); assert.deepEqual(second.reference, first.reference, "Compaction preserves exact checked identity");
assert.equal(first.world, await hexDigestAsync(first.graphExecution));
assert.equal(second.world, first.world, "Replacement retains the checked execution identity");
assert.equal(second.graphExecution.kernel, second.kernel, "Graph representation shares the validated program"); assert.equal(second.graphExecution.kernel, second.kernel, "Graph representation shares the validated program");
assert.equal(second.graphExecution.queries, second.queries); assert.equal(second.graphExecution.queries, second.queries);
// A deliberately tighter pool admits the serving installation but must // A deliberately tighter pool admits the serving installation but must
+34
View File
@@ -3,6 +3,7 @@ import { test } from "node:test";
import { capabilityId as id, valueType, validateWorkspaceRevision } from "../src/capability-model/index.js"; import { capabilityId as id, valueType, validateWorkspaceRevision } from "../src/capability-model/index.js";
import { import {
contentDigest, contentDigest,
contentDigestAsync,
planEvolution, planEvolution,
reviewSemanticMajors, reviewSemanticMajors,
runtimeContracts, runtimeContracts,
@@ -51,6 +52,39 @@ test("hashing is canonical and rejects values outside the persisted JSON contrac
assert.throws(() => contentDigest(new Date())); assert.throws(() => contentDigest(new Date()));
}); });
test("cooperative hashing preserves canonical identities and services the event loop", async () => {
const sparse = [1, 2, 3];
delete sparse[1];
const values: unknown[] = [
null,
false,
-0,
"中\\n\ud800",
sparse,
{ z: 1, a: { omitted: undefined, b: [false, 1e100] } },
];
const shared = { text: "中😀".repeat(22000) };
values.push({ first: shared, second: shared });
for (const value of values) assert.equal(await contentDigestAsync(value), contentDigest(value));
for (const value of [undefined, NaN, Infinity, new Date(), [undefined]])
await assert.rejects(contentDigestAsync(value));
const cyclic: { next?: unknown } = {};
cyclic.next = cyclic;
await assert.rejects(contentDigestAsync(cyclic), /cyclic JSON/);
const large = Array.from({ length: 50000 }, (_, index) => ({ z: "definition".repeat(8), a: index }));
const expected = contentDigest(large);
let serviced = false;
const timer = setTimeout(() => {
serviced = true;
}, 0);
try {
assert.equal(await contentDigestAsync(large), expected);
assert.equal(serviced, true, "large verification must let host renewals and RPCs run");
} finally {
clearTimeout(timer);
}
});
test("a workspace root change and display names do not restart package runtimes", () => { test("a workspace root change and display names do not restart package runtimes", () => {
const before = makeValidCapabilityWorkspace(); const before = makeValidCapabilityWorkspace();
const after = structuredClone(before); const after = structuredClone(before);
+8 -8
View File
@@ -45,7 +45,7 @@ const prepare = async (workspace: WorkspaceRevision) => {
test("execution reuse ignores world/source/display changes and unrelated packages", async () => { test("execution reuse ignores world/source/display changes and unrelated packages", async () => {
const workspace = await loadReaderWorkspace(), const workspace = await loadReaderWorkspace(),
original = await prepare(workspace); original = await prepare(workspace);
const before = original.groups()[0]!.executionDigest; const before = (await original.groups())[0]!.executionDigest;
workspace.sourceRootCommit = "f".repeat(40); workspace.sourceRootCommit = "f".repeat(40);
workspace.packageImports[0]!.displayName = "Renamed"; workspace.packageImports[0]!.displayName = "Renamed";
workspace.packageImports[0]!.source.commit = "e".repeat(40); workspace.packageImports[0]!.source.commit = "e".repeat(40);
@@ -59,13 +59,13 @@ test("execution reuse ignores world/source/display changes and unrelated package
const after = await prepare(workspace); const after = await prepare(workspace);
assert.notEqual(after.plan.digest, original.plan.digest); assert.notEqual(after.plan.digest, original.plan.digest);
assert.equal( assert.equal(
after.groups().find((g) => g.logicalId === workspace.packageImports[0]!.packageId)!.executionDigest, (await after.groups()).find((g) => g.logicalId === workspace.packageImports[0]!.packageId)!.executionDigest,
before, before,
); );
original.environments[workspace.packageImports[0]!.revisionId]!.credentialGeneration = "config:2"; original.environments[workspace.packageImports[0]!.revisionId]!.credentialGeneration = "config:2";
assert.notEqual(original.groups()[0]!.executionDigest, before); assert.notEqual((await original.groups())[0]!.executionDigest, before);
original.environments[workspace.packageImports[0]!.revisionId]!.placement = "module"; original.environments[workspace.packageImports[0]!.revisionId]!.placement = "module";
assert.notEqual(original.groups()[0]!.executionDigest, before); assert.notEqual((await original.groups())[0]!.executionDigest, before);
}); });
test("outbound provider changes invalidate consumers while caller changes preserve providers", async () => { test("outbound provider changes invalidate consumers while caller changes preserve providers", async () => {
@@ -108,15 +108,15 @@ test("outbound provider changes invalidate consumers while caller changes preser
dependencies: [{ portId, binding: { kind: "state", slotId: id.slot("slot:document:content") } }], dependencies: [{ portId, binding: { kind: "state", slotId: id.slot("slot:document:content") } }],
}; };
const prepared = await prepare(workspace); const prepared = await prepare(workspace);
const values = () => new Map(prepared.groups().map((g) => [g.logicalId, g.executionDigest])); const values = async () => new Map((await prepared.groups()).map((g) => [g.logicalId, g.executionDigest]));
const before = values(); const before = await values();
prepared.installation.packages.find((p) => p.revision === "package:reader-runtime@1")!.service!.contentDigest = prepared.installation.packages.find((p) => p.revision === "package:reader-runtime@1")!.service!.contentDigest =
"c".repeat(64); "c".repeat(64);
const callerChanged = values(); const callerChanged = await values();
assert.equal(callerChanged.get("provider"), before.get("provider")); assert.equal(callerChanged.get("provider"), before.get("provider"));
assert.notEqual(callerChanged.get("package:reader-runtime"), before.get("package:reader-runtime")); assert.notEqual(callerChanged.get("package:reader-runtime"), before.get("package:reader-runtime"));
prepared.installation.packages.find((p) => p.revision === revision)!.service!.contentDigest = "d".repeat(64); prepared.installation.packages.find((p) => p.revision === revision)!.service!.contentDigest = "d".repeat(64);
const providerChanged = values(); const providerChanged = await values();
assert.notEqual(providerChanged.get("provider"), callerChanged.get("provider")); assert.notEqual(providerChanged.get("provider"), callerChanged.get("provider"));
assert.notEqual(providerChanged.get("package:reader-runtime"), callerChanged.get("package:reader-runtime")); assert.notEqual(providerChanged.get("package:reader-runtime"), callerChanged.get("package:reader-runtime"));
}); });
+75 -2
View File
@@ -7,7 +7,11 @@ import {
checkExecutionWorld, checkExecutionWorld,
checkedWorldDigest, checkedWorldDigest,
implementationDigest, implementationDigest,
clientContractCatalog,
hexDigest, hexDigest,
executionPlanDigest,
executionPlanDigestAsync,
sealExecutionPlan,
parsePackageArtifacts, parsePackageArtifacts,
artifactPath, artifactPath,
type PackageArtifacts, type PackageArtifacts,
@@ -20,6 +24,54 @@ import { compileKernelProgram } from "../src/execution-world/kernel.js";
import { loadCompositeWorkspace } from "./composite-fixture.js"; import { loadCompositeWorkspace } from "./composite-fixture.js";
import { standardNativeBackends } from "../src/execution-world/native-backends.js"; import { standardNativeBackends } from "../src/execution-world/native-backends.js";
test("sealed runtime plans reuse verified integrity while mutable copies are rechecked", async () => {
const workspace = await loadReaderWorkspace();
const compiled = compileExecutionPlan(workspace);
const plan: ExecutionPlan = JSON.parse(JSON.stringify(compiled));
assert.equal(await sealExecutionPlan(plan), true);
assert.equal(executionPlanDigest(plan), compiled.digest);
assert.equal(await executionPlanDigestAsync(plan), compiled.digest);
assert.throws(() => {
plan.definition.workspace.sourceRootCommit = "f".repeat(40);
}, TypeError);
assert.throws(() => {
plan.digest = "0".repeat(64);
}, TypeError);
const stringify = JSON.stringify;
JSON.stringify = () => {
throw Error("Repeated serialization of sealed metadata");
};
try {
assert.equal(executionPlanDigest(plan), compiled.digest);
assert.equal(await executionPlanDigestAsync(plan), compiled.digest);
} finally {
JSON.stringify = stringify;
}
const changed: ExecutionPlan = structuredClone(plan);
changed.definition.workspace.sourceRootCommit = "f".repeat(40);
Object.freeze(changed);
assert.notEqual(executionPlanDigest(changed), plan.digest);
assert.notEqual(await executionPlanDigestAsync(changed), plan.digest);
assert.equal(await sealExecutionPlan(changed), false, "shallow freezing is not an integrity proof");
const resigned: ExecutionPlan = structuredClone(plan);
resigned.definition.workspace.sourceRootCommit = "e".repeat(40);
resigned.digest = executionPlanDigest(resigned);
assert.equal(await sealExecutionPlan(resigned), true);
assert.notEqual(executionPlanDigest(resigned), plan.digest);
workspace.sourceRootCommit = "d".repeat(40);
assert.equal(workspace.sourceRootCommit, "d".repeat(40), "sealing owned JSON leaves compiler inputs editable");
});
test("runtime plan sealing rejects accessor-backed metadata", async () => {
const plan: ExecutionPlan = compileExecutionPlan(await loadReaderWorkspace());
assert.equal(await sealExecutionPlan(Object.create(plan)), false, "inherited integrity fields cannot be sealed");
Object.defineProperty(plan.definition, "codec", { get: () => "camino-execution-plan-v1", enumerable: true });
await assert.rejects(sealExecutionPlan(plan), /INVALID_PLAN_JSON/);
});
test("optional targets close over calls into another package", async () => { test("optional targets close over calls into another package", async () => {
const workspace = await loadCompositeWorkspace(); const workspace = await loadCompositeWorkspace();
const before = compileExecutionPlan(workspace).definition.operations.find( const before = compileExecutionPlan(workspace).definition.operations.find(
@@ -385,7 +437,14 @@ test("public reflection contains nominal contracts and callable descriptors with
components: [], components: [],
routes: {}, routes: {},
}; };
const snapshot = publicDefinitionSnapshot(plan, installation); const kernel = compileKernelProgram(plan) as import("../src/execution-world/inspection.js").InspectionKernel;
const catalog = await clientContractCatalog(
plan,
installation,
installation.packages.map((pkg) => pkg.revision),
kernel,
);
const snapshot = await publicDefinitionSnapshot(plan, kernel, catalog);
assert.ok(snapshot.rows.interfaces.length); assert.ok(snapshot.rows.interfaces.length);
assert.ok(snapshot.rows.queries.length); assert.ok(snapshot.rows.queries.length);
assert.ok(snapshot.rows.conformances.length); assert.ok(snapshot.rows.conformances.length);
@@ -400,5 +459,19 @@ test("public reflection contains nominal contracts and callable descriptors with
assert.ok(!publicText.includes('"' + privateKey + '"'), privateKey); assert.ok(!publicText.includes('"' + privateKey + '"'), privateKey);
assert.ok(publicText.includes('"descriptor"')); assert.ok(publicText.includes('"descriptor"'));
assert.ok(publicText.includes('"scope":"class"')); assert.ok(publicText.includes('"scope":"class"'));
assert.equal(snapshot.id, publicDefinitionSnapshot(plan, installation).id); assert.equal(snapshot.id, (await publicDefinitionSnapshot(plan, kernel, catalog)).id);
// Historical checked availability must survive a newer host compiler. If
// reflection silently regenerates the Kernel, this evidence disappears.
const historical = structuredClone(kernel);
const installed = historical.operations.find((operation) => !operation.unsupported)!;
assert.ok(installed);
installed.unsupported = "CHECKED_HISTORICAL_UNSUPPORTED";
const historicalCatalog = await clientContractCatalog(
plan,
installation,
installation.packages.map((pkg) => pkg.revision),
historical,
);
const historicalSnapshot = await publicDefinitionSnapshot(plan, historical, historicalCatalog);
assert.match(JSON.stringify(historicalSnapshot.rows.conformances), /CHECKED_HISTORICAL_UNSUPPORTED/);
}); });
+32
View File
@@ -0,0 +1,32 @@
import test from "node:test";
import assert from "node:assert/strict";
import fs from "node:fs/promises";
import os from "node:os";
import path from "node:path";
import { managedResourcePath } from "../src/capability-language/managed-source-path.js";
test("source registration permits an outer workbench alias, never nested checkout or resources symlinks", async (t) => {
const scratch = await fs.mkdtemp(path.join(os.tmpdir(), "qx-managed-source-path-"));
t.after(() => fs.rm(scratch, { recursive: true, force: true }));
const root = path.join(scratch, "retained/workbench"),
alias = path.join(scratch, "guest"),
outside = path.join(scratch, "outside");
await fs.mkdir(path.join(root, "resources/Package"), { recursive: true });
await fs.mkdir(outside);
await fs.symlink(root, alias);
for (const registered of [
"resources/Package",
path.join(alias, "resources/Package"),
path.relative(root, path.join(alias, "resources/Package")),
])
assert.equal(await managedResourcePath(alias, registered), "resources/Package");
await fs.symlink(path.join(root, "resources/Package"), path.join(root, "resources/Alias"));
await assert.rejects(managedResourcePath(root, "resources/Alias"), /crosses a symlink/);
await fs.symlink(outside, path.join(root, "resources/Escape"));
await assert.rejects(managedResourcePath(root, "resources/Escape"), /escapes the workbench/);
await fs.mkdir(path.join(outside, "resources/Package"), { recursive: true });
await assert.rejects(managedResourcePath(root, path.join(outside, "resources/Package")), /escapes the workbench/);
await fs.rename(path.join(root, "resources"), path.join(root, "relocated-resources"));
await fs.symlink(path.join(root, "relocated-resources"), path.join(root, "resources"));
await assert.rejects(managedResourcePath(root, "resources/Package"), /crosses a symlink/);
});
+13 -1
View File
@@ -176,6 +176,9 @@ for (const dependencyKind of ["interface", "build"] as const)
test(`${dependencyKind} pin upgrades publish children before parent locks and resume without republishing completed nodes`, async (context) => { test(`${dependencyKind} pin upgrades publish children before parent locks and resume without republishing completed nodes`, async (context) => {
const workbench = await fs.mkdtemp(path.join(os.tmpdir(), "qx-upgrade-test-")); const workbench = await fs.mkdtemp(path.join(os.tmpdir(), "qx-upgrade-test-"));
context.after(() => fs.rm(workbench, { recursive: true, force: true })); context.after(() => fs.rm(workbench, { recursive: true, force: true }));
const alias = `${workbench}-guest-alias`;
await fs.symlink(workbench, alias);
context.after(() => fs.unlink(alias));
const from = "a".repeat(40), const from = "a".repeat(40),
to = "b".repeat(40), to = "b".repeat(40),
framework = "c".repeat(40); framework = "c".repeat(40);
@@ -244,7 +247,15 @@ for (const dependencyKind of ["interface", "build"] as const)
await fs.mkdir(path.join(workbench, ".quixos"), { recursive: true }); await fs.mkdir(path.join(workbench, ".quixos"), { recursive: true });
await fs.writeFile( await fs.writeFile(
path.join(workbench, ".quixos/resource-graph.json"), path.join(workbench, ".quixos/resource-graph.json"),
JSON.stringify({ resources: [{ ...sources[1], source: { resolver: "git", ...sources[1].source } }] }), JSON.stringify({
resources: [
{
...sources[1],
directory: path.join(alias, sources[1].directory),
source: { resolver: "git", ...sources[1].source },
},
],
}),
); );
assert.deepEqual( assert.deepEqual(
plan.nodes.map((node) => node.directory), plan.nodes.map((node) => node.directory),
@@ -275,6 +286,7 @@ for (const dependencyKind of ["interface", "build"] as const)
assert.deepEqual(published, ["resources/Named", "root"]); assert.deepEqual(published, ["resources/Named", "root"]);
const graph = JSON.parse(await fs.readFile(path.join(workbench, ".quixos/resource-graph.json"), "utf8")); const graph = JSON.parse(await fs.readFile(path.join(workbench, ".quixos/resource-graph.json"), "utf8"));
assert.equal(graph.resources.length, 1); assert.equal(graph.resources.length, 1);
assert.equal(graph.resources[0].directory, "resources/Named");
assert.equal(graph.resources[0].source.commit, to); assert.equal(graph.resources[0].source.commit, to);
const next = await planPinUpgrades(workbench, { const next = await planPinUpgrades(workbench, {
nodes: [sources[0], { ...sources[1], source: graph.resources[0].source }], nodes: [sources[0], { ...sources[1], source: graph.resources[0].source }],
+12 -10
View File
@@ -249,13 +249,13 @@ test("checked component-only artifacts install without a service and reject miss
assert.ok(installation.routes[installation.components[0]!.url]); assert.ok(installation.routes[installation.components[0]!.url]);
assert.equal(JSON.stringify(installation.components).includes(root), false); assert.equal(JSON.stringify(installation.components).includes(root), false);
assert.equal(JSON.stringify(installation.components).includes("slot:"), false); assert.equal(JSON.stringify(installation.components).includes("slot:"), false);
const catalog = clientContractCatalog(plan, installation, [pkg.revision]); const catalog = await clientContractCatalog(plan, installation, [pkg.revision]);
assert.equal(catalog.presentations[0]!.component, "component:card"); assert.equal(catalog.presentations[0]!.component, "component:card");
assert.equal(catalog.components[0]!.subject, "interface:Data@1"); assert.equal(catalog.components[0]!.subject, "interface:Data@1");
assert.equal(JSON.stringify(catalog).includes(root), false); assert.equal(JSON.stringify(catalog).includes(root), false);
assert.equal(JSON.stringify(catalog).includes("bindingSchema"), false); assert.equal(JSON.stringify(catalog).includes("bindingSchema"), false);
assert.throws(() => clientContractCatalog(plan, installation, ["absent"]), /UNINSTALLED_PACKAGE/); await assert.rejects(() => clientContractCatalog(plan, installation, ["absent"]), /UNINSTALLED_PACKAGE/);
assert.throws( await assert.rejects(
() => clientContractCatalog(plan, { ...installation, plan: "bad" }, [pkg.revision]), () => clientContractCatalog(plan, { ...installation, plan: "bad" }, [pkg.revision]),
/CATALOG_PLAN_MISMATCH/, /CATALOG_PLAN_MISMATCH/,
); );
@@ -268,14 +268,16 @@ test("checked component-only artifacts install without a service and reject miss
compileKernelProgram(plan) as InspectionKernel, compileKernelProgram(plan) as InspectionKernel,
); );
try { try {
assert.throws(() => prepared.select(["absent"]), /UNINSTALLED_PACKAGE/); await assert.rejects(() => prepared.select(["absent"]), /UNINSTALLED_PACKAGE/);
assert.equal(scope.bytes, 0, "Unknown requests do not allocate compiler metadata"); assert.equal(scope.bytes, 0, "Unknown requests do not allocate compiler metadata");
assert.deepEqual(prepared.select([pkg.revision]), catalog); const [first, coalesced] = await Promise.all([prepared.select([pkg.revision]), prepared.select([pkg.revision])]);
assert.deepEqual(first, catalog);
assert.equal(first.operations, coalesced.operations, "Concurrent preparation shares one metadata reservation");
const retained = scope.bytes; const retained = scope.bytes;
assert.ok(retained > 0); assert.ok(retained > 0);
assert.ok(retained < 32 * 1024 * 1024, "Small catalogs retain a proportional metadata charge"); assert.ok(retained < 32 * 1024 * 1024, "Small catalogs retain a proportional metadata charge");
const full = prepared.select([pkg.revision]); const full = await prepared.select([pkg.revision]);
const empty = prepared.select([]); const empty = await prepared.select([]);
assert.deepEqual(empty.components, []); assert.deepEqual(empty.components, []);
assert.deepEqual(empty.presentations, []); assert.deepEqual(empty.presentations, []);
assert.deepEqual(empty.moduleBindings, []); assert.deepEqual(empty.moduleBindings, []);
@@ -290,14 +292,14 @@ test("checked component-only artifacts install without a service and reject miss
}, },
}); });
try { try {
assert.deepEqual(prepared.select([pkg.revision]), full); assert.deepEqual(await prepared.select([pkg.revision]), full);
assert.equal(scope.bytes, retained, "Package projections do not accumulate cache entries"); assert.equal(scope.bytes, retained, "Package projections do not accumulate cache entries");
} finally { } finally {
Object.defineProperty(plan, "definition", { configurable: true, value: definition }); Object.defineProperty(plan, "definition", { configurable: true, value: definition });
} }
prepared.close(); prepared.close();
assert.equal(scope.bytes, 0); assert.equal(scope.bytes, 0);
assert.throws(() => prepared.select([pkg.revision]), /CANDIDATE_METADATA_CLOSED/); await assert.rejects(() => prepared.select([pkg.revision]), /CANDIDATE_METADATA_CLOSED/);
} finally { } finally {
prepared.close(); prepared.close();
scope.release(); scope.release();
@@ -305,7 +307,7 @@ test("checked component-only artifacts install without a service and reject miss
const tight = new CandidateMetadataBudget({ bytes: 1000, ownerBytes: 1000, candidates: 1 }); const tight = new CandidateMetadataBudget({ bytes: 1000, ownerBytes: 1000, candidates: 1 });
const tightScope = tight.acquire("catalog-test"); const tightScope = tight.acquire("catalog-test");
const refused = createClientContractCatalog(plan, installation, tightScope); const refused = createClientContractCatalog(plan, installation, tightScope);
assert.throws(() => refused.select([pkg.revision]), /CANDIDATE_METADATA_LIMIT/); await assert.rejects(() => refused.select([pkg.revision]), /CANDIDATE_METADATA_LIMIT/);
assert.equal(tightScope.bytes, 0); assert.equal(tightScope.bytes, 0);
refused.close(); refused.close();
tightScope.release(); tightScope.release();
+8 -2
View File
@@ -520,7 +520,7 @@ test("React tooling generates checked owner queries from imported closed navigat
if (parsed.resource.kind !== "package") throw Error("package required"); if (parsed.resource.kind !== "package") throw Error("package required");
const contracts = [...dependencies, ...(parsed.resource.specializations ?? [])]; const contracts = [...dependencies, ...(parsed.resource.specializations ?? [])];
const documents = presentationQueries(parsed.resource.revision, contracts); const documents = presentationQueries(parsed.resource.revision, contracts);
assert.equal(documents.size, 2); assert.equal(documents.size, 4);
const checked = await Promise.all( const checked = await Promise.all(
parsed.resource.revision.queries!.map((query) => parsed.resource.revision.queries!.map((query) =>
compileQuery(query, contracts, async (name) => documents.get(name)!), compileQuery(query, contracts, async (name) => documents.get(name)!),
@@ -528,10 +528,16 @@ test("React tooling generates checked owner queries from imported closed navigat
); );
assert.deepEqual( assert.deepEqual(
checked.map((query) => query.declaration.placement?.kind), checked.map((query) => query.declaration.placement?.kind),
["replica", "local"], ["replica", "local", "replica", "local"],
); );
assert.match(JSON.stringify(checked[0]!.output), /"custom":\{"kind":"record","fields":\{"label"/); assert.match(JSON.stringify(checked[0]!.output), /"custom":\{"kind":"record","fields":\{"label"/);
assert.match(JSON.stringify(checked[0]!.selection), /"kind":"as"/); assert.match(JSON.stringify(checked[0]!.selection), /"kind":"as"/);
for (const identity of checked.slice(2)) {
assert.match(identity.declaration.id, /:identity-(inputs|view)$/);
assert.doesNotMatch(JSON.stringify(identity.output), /"custom"/);
assert.match(JSON.stringify(identity.output), /_presentationOccurrence/);
assert.match(JSON.stringify(identity.output), /_presentationSource/);
}
assert( assert(
checked.every((query) => checked.every((query) =>
query.effects.some((effect) => effect.memberId === "mount" && effect.uses.includes("predicate")), query.effects.some((effect) => effect.memberId === "mount" && effect.uses.includes("predicate")),
+43 -2
View File
@@ -29,12 +29,15 @@ const navigation = iface(
}`, }`,
[item], [item],
); );
function declaration(root: InterfaceRevision = item) { function declaration(root: InterfaceRevision = item, dependencies: InterfaceRevision[] = []) {
const result = compileCapabilityResourceSource( const result = compileCapabilityResourceSource(
`import interface ${root.displayName}; package Views id "views" revision "views@1" { `import interface ${root.displayName}; package Views id "views" revision "views@1" {
query Open id "open" root ${root.displayName} document "open.graphql" operation "Open" {replica; max rows 10;} query Open id "open" root ${root.displayName} document "open.graphql" operation "Open" {replica; max rows 10;}
}`, }`,
{ source, environment: { interfaces: new Map([[root.displayName, root]]), interfaceClosure: [root, item] } }, {
source,
environment: { interfaces: new Map([[root.displayName, root]]), interfaceClosure: [root, item, ...dependencies] },
},
); );
assert.ok(result.ok, JSON.stringify(result.diagnostics)); assert.ok(result.ok, JSON.stringify(result.diagnostics));
if (result.resource.kind !== "package") throw Error("Expected Package"); if (result.resource.kind !== "package") throw Error("Expected Package");
@@ -103,6 +106,44 @@ test("bounded list bindings preserve entry identity without requesting details",
assert(!JSON.stringify(projection.selection).includes('"name":"body"')); assert(!JSON.stringify(projection.selection).includes('"name":"body"'));
assert(tree.maxOccurrences <= 256); assert(tree.maxOccurrences <= 256);
}); });
test("literal collection windows bound handles independently of detail row budgets", async () => {
const source = { ...declaration(navigation), budgets: { ...declaration(navigation).budgets, rows: 20000 } };
const query = (limit: string, variables = "") => `query Open${variables} {root {
items(first: ${limit}) {entries {node {...Body @boundary(name:"body")}}}
}} fragment Body on Item {body}`;
const checked = await compileQuery(source, [item, navigation], async () => query("3"));
assert.equal(checked.tree!.maxOccurrences, 7);
await assert.rejects(
compileQuery(source, [item, navigation], async () => query("200")),
/QUERY_TREE_LIMIT/,
);
await assert.rejects(
compileQuery(source, [item, navigation], async () => query("$first", "($first:Int!)")),
/QUERY_TREE_LIMIT/,
);
const group = iface(
`import interface Item; interface Group id "group" revision "group@1" {
queryable relation items id "group:items" : many interface Item ordered {resolve id "group:items:resolve" execution snapshot;}
}`,
[item],
);
const groups = iface(
`import interface Group; interface Groups id "groups" revision "groups@1" {
queryable relation groups id "groups:groups" : many interface Group ordered {resolve id "groups:groups:resolve" execution snapshot;}
}`,
[item, group],
);
const nested = { ...declaration(groups, [group]), budgets: source.budgets };
const nestedQuery = (outer: number, inner: number) => `query Open {root {
groups(first:${outer}) {entries {node {items(first:${inner}) {entries {node {...Body @boundary(name:"body")}}}}}}
}} fragment Body on Item {body}`;
const bounded = await compileQuery(nested, [item, group, groups], async () => nestedQuery(2, 3));
assert.equal(bounded.tree!.maxOccurrences, 15, "Nested windows multiply instead of reusing the outer bound");
await assert.rejects(
compileQuery(nested, [item, group, groups], async () => nestedQuery(20, 20)),
/QUERY_TREE_LIMIT/,
);
});
test("guards control boundary participation and invalid syntax fails checking", async () => { test("guards control boundary participation and invalid syntax fails checking", async () => {
const checked = await compileQuery( const checked = await compileQuery(
declaration(), declaration(),
+55
View File
@@ -0,0 +1,55 @@
import assert from "node:assert/strict";
import { spawnSync } from "node:child_process";
import { mkdtempSync, readFileSync, writeFileSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import { join, resolve } from "node:path";
import test from "node:test";
import { formatQx } from "../src/capability-language/source.js";
const cli = resolve(process.cwd(), "dist/src/capability-language/tool-cli.js");
const run = (...args: string[]) => spawnSync(process.execPath, [cli, "format", ...args], { encoding: "utf8" });
const source = `workspace Test id "w" revision "w@1" commit "${"1".repeat(40)}" {\n// 雪 🦊 comment preserved\n}\n`;
test("QX batch checks are read-only; writes match single-file formatting and remain idempotent", (t) => {
const root = mkdtempSync(join(tmpdir(), "qx-format-"));
t.after(() => rmSync(root, { recursive: true, force: true }));
const files = [join(root, "one.qx"), join(root, "two 雪.qx")];
for (const file of files) writeFileSync(file, source);
const check = run("--check", ...files);
assert.notEqual(check.status, 0, check.stderr);
for (const file of files) {
assert(check.stderr.includes(file));
assert.equal(readFileSync(file, "utf8"), source);
}
const single = run(files[0]!);
assert.equal(single.status, 0, single.stderr);
assert.equal(single.stdout, formatQx(source));
const write = run("--write", ...files);
assert.equal(write.status, 0, write.stderr);
for (const file of files) assert.equal(readFileSync(file, "utf8"), single.stdout);
assert.equal(run("--check", ...files).status, 0);
assert.equal(run("--write", ...files).stdout, "");
writeFileSync(files[0]!, source);
assert.equal(run(files[0]!, "--write").status, 0);
assert.equal(readFileSync(files[0]!, "utf8"), single.stdout);
});
test("QX batch errors report every failure and do not truncate valid work", (t) => {
const root = mkdtempSync(join(tmpdir(), "qx-format-errors-"));
t.after(() => rmSync(root, { recursive: true, force: true }));
const broken = join(root, "broken.qx"),
missing = join(root, "missing.qx"),
valid = join(root, "valid.qx");
writeFileSync(broken, "workspace { invalid");
writeFileSync(valid, source);
const result = run("--write", broken, missing, valid);
assert.notEqual(result.status, 0);
assert(result.stderr.includes(broken));
assert(result.stderr.includes(missing));
assert.equal(readFileSync(broken, "utf8"), "workspace { invalid");
assert.equal(readFileSync(valid, "utf8"), formatQx(source));
writeFileSync(valid, source);
assert.notEqual(run("--write", valid, "--unknown").status, 0);
assert.equal(readFileSync(valid, "utf8"), source, "Validate arguments before writing any file");
assert.notEqual(run("--check").status, 0);
});
+21
View File
@@ -172,6 +172,27 @@ test("exact source closure recovers through explicitly selected bundles, preserv
directory: path.join(temporary, "b"), directory: path.join(temporary, "b"),
}); });
assert.notEqual(a.workspaceId, b.workspaceId); assert.notEqual(a.workspaceId, b.workspaceId);
const assigned = "f8f2f8a3-328c-45a2-847a-31869ad28ce7";
const c = await prepareDevelopmentSources({
source: root,
cacheDirectory: directory,
directory: path.join(temporary, "assigned"),
workspaceId: assigned,
});
assert.equal(c.workspaceId, assigned);
assert.equal(
JSON.parse(await readFile(path.join(c.directory, ".quixos/resource-graph.json"), "utf8")).workspaceId,
assigned,
);
await assert.rejects(
prepareDevelopmentSources({
source: root,
cacheDirectory: directory,
directory: path.join(temporary, "invalid"),
workspaceId: "not-a-workspace",
}),
/Workspace UUID/,
);
const aRoot = path.join(a.directory, "root"), const aRoot = path.join(a.directory, "root"),
bRoot = path.join(b.directory, "root"); bRoot = path.join(b.directory, "root");
assert.equal((await exec("git", ["remote", "get-url", "origin"], { cwd: aRoot })).stdout.trim(), root.repository); assert.equal((await exec("git", ["remote", "get-url", "origin"], { cwd: aRoot })).stdout.trim(), root.repository);