Compare commits
18
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7f3fdfe64e | ||
|
|
0a7bdf7657 | ||
|
|
137dcaa101 | ||
|
|
a86de3fe5b | ||
|
|
165510341d | ||
|
|
b406738249 | ||
|
|
ffd728b061 | ||
|
|
e78b7adf28 | ||
|
|
a935273913 | ||
|
|
e162dc3013 | ||
|
|
e65ddad798 | ||
|
|
31a48e746d | ||
|
|
f9a8d64564 | ||
|
|
61534d3fb5 | ||
|
|
391f02f78a | ||
|
|
c8c56d8ea7 | ||
|
|
0443992dd4 | ||
|
|
9248332da6 |
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"version": 1,
|
"version": 1,
|
||||||
"sourceRepo": "https://gitea-external.egads.tutti.syntaxblitz.net/quixos/quixos",
|
"sourceRepo": "https://gitea-external.egads.tutti.syntaxblitz.net/quixos/quixos",
|
||||||
"sourceCommit": "dd7527da2714f3b0941ed908357fd82e98f45bc4",
|
"sourceCommit": "d1ab9c912133511cfd3de65550965e0e8806678f",
|
||||||
"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://gitea-external.egads.tutti.syntaxblitz.net/quixos/quixos-protocol.git"
|
||||||
|
|||||||
@@ -15,7 +15,12 @@ import {
|
|||||||
} from "./assembly.js";
|
} from "./assembly.js";
|
||||||
import { createGitCapabilityResolver } from "./git-resolver.js";
|
import { createGitCapabilityResolver } from "./git-resolver.js";
|
||||||
import { snapshotCommit, buildImmutableCandidate } from "./checked-build.js";
|
import { snapshotCommit, buildImmutableCandidate } from "./checked-build.js";
|
||||||
import { planEvolution, type WorkspaceRevision, type EvolutionReview } from "../capability-model/index.js";
|
import {
|
||||||
|
planEvolution,
|
||||||
|
reviewSemanticMajors,
|
||||||
|
type WorkspaceRevision,
|
||||||
|
type EvolutionReview,
|
||||||
|
} from "../capability-model/index.js";
|
||||||
import { withFileLock } from "./file-lock.js";
|
import { withFileLock } from "./file-lock.js";
|
||||||
const execFile = promisify(callback);
|
const execFile = promisify(callback);
|
||||||
type Source = { repository: string; commit: string };
|
type Source = { repository: string; commit: string };
|
||||||
@@ -187,6 +192,34 @@ export type UpgradeEffects = {
|
|||||||
snapshot(root: string): Promise<string>;
|
snapshot(root: string): Promise<string>;
|
||||||
publish(root: string, commit: string): Promise<void>;
|
publish(root: string, commit: string): Promise<void>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** Review a successfully built immutable candidate using the same boundary as
|
||||||
|
* ordinary authoring checks. Execution storage compatibility is checked against
|
||||||
|
* the current graph at activation; the legacy evolution model is not its schema.
|
||||||
|
*/
|
||||||
|
export async function reviewUpgradeCandidate({
|
||||||
|
artifact,
|
||||||
|
baseline,
|
||||||
|
candidate,
|
||||||
|
reviews = [],
|
||||||
|
}: {
|
||||||
|
artifact: string;
|
||||||
|
baseline: WorkspaceRevision | null;
|
||||||
|
candidate: WorkspaceRevision;
|
||||||
|
reviews?: EvolutionReview[];
|
||||||
|
}) {
|
||||||
|
let execution = false;
|
||||||
|
try {
|
||||||
|
await fs.access(path.join(artifact, "execution-plan.json"));
|
||||||
|
execution = true;
|
||||||
|
} catch (error) {
|
||||||
|
if ((error as NodeJS.ErrnoException).code !== "ENOENT") throw error;
|
||||||
|
}
|
||||||
|
return execution
|
||||||
|
? { filename: "semantic-review.json", review: reviewSemanticMajors(baseline, candidate, reviews) }
|
||||||
|
: { filename: "evolution.json", review: planEvolution(baseline, candidate, { reviews }) };
|
||||||
|
}
|
||||||
|
|
||||||
const effects: UpgradeEffects = {
|
const effects: UpgradeEffects = {
|
||||||
async check(node, root, output, spec) {
|
async check(node, root, output, spec) {
|
||||||
if (node.kind === "workspace" && !spec.baseline && !spec.bootstrap)
|
if (node.kind === "workspace" && !spec.baseline && !spec.bootstrap)
|
||||||
@@ -206,10 +239,15 @@ const effects: UpgradeEffects = {
|
|||||||
? (JSON.parse(await fs.readFile(spec.baseline, "utf8")) as WorkspaceRevision)
|
? (JSON.parse(await fs.readFile(spec.baseline, "utf8")) as WorkspaceRevision)
|
||||||
: null;
|
: null;
|
||||||
const reviews = spec.reviews ? (JSON.parse(await fs.readFile(spec.reviews, "utf8")) as EvolutionReview[]) : [];
|
const reviews = spec.reviews ? (JSON.parse(await fs.readFile(spec.reviews, "utf8")) as EvolutionReview[]) : [];
|
||||||
const evolution = planEvolution(baseline, JSON.parse(candidate), { reviews });
|
const { filename, review } = await reviewUpgradeCandidate({
|
||||||
await fs.writeFile(path.join(output, "evolution.json"), JSON.stringify(evolution, null, 2));
|
artifact,
|
||||||
if (evolution.blockers.length)
|
baseline,
|
||||||
throw new Error(`Refactor required in ${node.directory}: ${evolution.blockers.join("; ")}`);
|
candidate: JSON.parse(candidate),
|
||||||
|
reviews,
|
||||||
|
});
|
||||||
|
await fs.writeFile(path.join(output, filename), JSON.stringify(review, null, 2));
|
||||||
|
if (review.blockers.length)
|
||||||
|
throw new Error(`Refactor required in ${node.directory}: ${review.blockers.join("; ")}`);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async snapshot(root) {
|
async snapshot(root) {
|
||||||
@@ -443,13 +481,13 @@ export const applyPinUpgrades = async (
|
|||||||
quixos: compiled.lock.quixos,
|
quixos: compiled.lock.quixos,
|
||||||
directResources: [...compiled.directResources.entries()].map(([bindingKey, node]) => {
|
directResources: [...compiled.directResources.entries()].map(([bindingKey, node]) => {
|
||||||
const [kind, binding] = bindingKey.split("\0");
|
const [kind, binding] = bindingKey.split("\0");
|
||||||
return { kind, binding, resourceKey: node.key, directory: node.directory };
|
return { kind, binding, resourceKey: node.key, directory: path.relative(plan.workbench, node.directory) };
|
||||||
}),
|
}),
|
||||||
resources: [...resources.values()].map((node) => ({
|
resources: [...resources.values()].map((node) => ({
|
||||||
key: node.key,
|
key: node.key,
|
||||||
kind: node.kind,
|
kind: node.kind,
|
||||||
source: node.source,
|
source: node.source,
|
||||||
directory: node.directory,
|
directory: path.relative(plan.workbench, node.directory),
|
||||||
...(node.resource.kind === "build"
|
...(node.resource.kind === "build"
|
||||||
? {}
|
? {}
|
||||||
: {
|
: {
|
||||||
|
|||||||
@@ -1526,7 +1526,6 @@ const validateBoundDependencies = (
|
|||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
validateAttachmentAccess(issues, attachment, params.conformance, `${path}.binding.edgeTypeId`);
|
|
||||||
const projection = edgeProjection(attachment.attachment, edgeBinding.projectionId);
|
const projection = edgeProjection(attachment.attachment, edgeBinding.projectionId);
|
||||||
if (!projection) {
|
if (!projection) {
|
||||||
issue(
|
issue(
|
||||||
@@ -1537,6 +1536,12 @@ const validateBoundDependencies = (
|
|||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
// Exporting traversal never exports writes or subscription ownership.
|
||||||
|
const publicRead =
|
||||||
|
projection.endpoint.publicTraversal &&
|
||||||
|
requirement.primitives.length > 0 &&
|
||||||
|
requirement.primitives.every((primitive) => primitive === "resolve");
|
||||||
|
if (!publicRead) validateAttachmentAccess(issues, attachment, params.conformance, `${path}.binding.edgeTypeId`);
|
||||||
if (projection.target.keyType && requirement.primitives.includes("connect"))
|
if (projection.target.keyType && requirement.primitives.includes("connect"))
|
||||||
issue(
|
issue(
|
||||||
issues,
|
issues,
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ export interface ArtifactFile {
|
|||||||
export interface ArtifactImplementation {
|
export interface ArtifactImplementation {
|
||||||
id: string;
|
id: string;
|
||||||
target: string;
|
target: string;
|
||||||
compatibility: "quixos-service-v1" | "quixos-js-module-v1";
|
compatibility: "quixos-service-v1" | "quixos-js-module-v1" | "quixos-restricted-module-v1";
|
||||||
path: string;
|
path: string;
|
||||||
ports: "quixos-transaction-ports-v1";
|
ports: "quixos-transaction-ports-v1";
|
||||||
registryExport?: string;
|
registryExport?: string;
|
||||||
@@ -225,7 +225,11 @@ export function parseArtifactGroup(value: unknown): ArtifactGroup {
|
|||||||
["registryExport"],
|
["registryExport"],
|
||||||
path,
|
path,
|
||||||
);
|
);
|
||||||
if (entry.compatibility !== "quixos-service-v1" && entry.compatibility !== "quixos-js-module-v1")
|
if (
|
||||||
|
!["quixos-service-v1", "quixos-js-module-v1", "quixos-restricted-module-v1"].includes(
|
||||||
|
String(entry.compatibility),
|
||||||
|
)
|
||||||
|
)
|
||||||
fail(path, "Unsupported artifact ABI");
|
fail(path, "Unsupported artifact ABI");
|
||||||
if (entry.ports !== "quixos-transaction-ports-v1") fail(path, "Unsupported transaction port ABI");
|
if (entry.ports !== "quixos-transaction-ports-v1") fail(path, "Unsupported transaction port ABI");
|
||||||
if (
|
if (
|
||||||
@@ -233,7 +237,9 @@ export function parseArtifactGroup(value: unknown): ArtifactGroup {
|
|||||||
(entry.target !== "server" || entry.registryExport !== undefined)
|
(entry.target !== "server" || entry.registryExport !== undefined)
|
||||||
)
|
)
|
||||||
fail(path, "Service must target server and has no JS registry export");
|
fail(path, "Service must target server and has no JS registry export");
|
||||||
if (entry.compatibility === "quixos-js-module-v1") text(entry.registryExport, `${path}.registryExport`);
|
if (entry.compatibility !== "quixos-service-v1") text(entry.registryExport, `${path}.registryExport`);
|
||||||
|
if (entry.compatibility === "quixos-restricted-module-v1" && entry.target !== "server")
|
||||||
|
fail(path, "Restricted modules must target server");
|
||||||
const exports = array(entry.exports, `${path}.exports`).map((value) => text(value, `${path}.exports`));
|
const exports = array(entry.exports, `${path}.exports`).map((value) => text(value, `${path}.exports`));
|
||||||
unique(exports, `${path}.exports`);
|
unique(exports, `${path}.exports`);
|
||||||
const files = parseArtifactFiles(entry.files, `${path}.files`);
|
const files = parseArtifactFiles(entry.files, `${path}.files`);
|
||||||
@@ -300,6 +306,11 @@ export function checkPackageCoverage(
|
|||||||
for (const id of implementation.exports) {
|
for (const id of implementation.exports) {
|
||||||
const entry = expected.exports.find((e) => e.id === id);
|
const entry = expected.exports.find((e) => e.id === id);
|
||||||
if (!entry) fail(implementation.id, `Unknown export ${id}`);
|
if (!entry) fail(implementation.id, `Unknown export ${id}`);
|
||||||
|
if (
|
||||||
|
implementation.compatibility === "quixos-restricted-module-v1" &&
|
||||||
|
(entry!.execution.kind === "remote" || !entry!.execution.targets.includes("server"))
|
||||||
|
)
|
||||||
|
fail(implementation.id, `Export ${id} does not promise restricted server computation`);
|
||||||
if (
|
if (
|
||||||
implementation.target !== "server" &&
|
implementation.target !== "server" &&
|
||||||
(!entry?.execution ||
|
(!entry?.execution ||
|
||||||
|
|||||||
+153
-106
@@ -1,18 +1,27 @@
|
|||||||
import { graphExecutionRepresentation } from "./graph-execution.js";
|
import { graphExecutionRepresentation } from "./graph-execution.js";
|
||||||
import { open, lstat } from "node:fs/promises";
|
import { lstat } from "node:fs/promises";
|
||||||
import { constants } from "node:fs";
|
|
||||||
import { join } from "node:path";
|
import { join } from "node:path";
|
||||||
import { hexDigest, ExecutionPlanError, type ExecutionPlan } from "./plan.js";
|
import { hexDigest, ExecutionPlanError, type ExecutionPlan } from "./plan.js";
|
||||||
import { loadExecutionInstallation, type PackageInstallationSelection } from "./installation.js";
|
import { loadExecutionInstallation, type PackageInstallationSelection } from "./installation.js";
|
||||||
|
import {
|
||||||
|
candidateMetadataBudget,
|
||||||
|
readCandidateMetadata,
|
||||||
|
type CandidateMetadataBudget,
|
||||||
|
type CandidateMetadataScope,
|
||||||
|
} from "./metadata.js";
|
||||||
const rootPattern = /^\/nix\/store\/[a-z0-9]{32}-[^/\s]+$/;
|
const rootPattern = /^\/nix\/store\/[a-z0-9]{32}-[^/\s]+$/;
|
||||||
async function readJson(root: string, file: string): Promise<any> {
|
async function readJson(root: string, file: string, scope: CandidateMetadataScope) {
|
||||||
const handle = await open(join(root, file), constants.O_RDONLY | constants.O_NOFOLLOW);
|
const input = await readCandidateMetadata(join(root, file), scope, 32 * 1024 * 1024);
|
||||||
try {
|
try {
|
||||||
const metadata = await handle.stat();
|
return {
|
||||||
if (!metadata.isFile() || metadata.size > 32 * 1024 * 1024) throw Error(`Invalid checked candidate file: ${file}`);
|
value: JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(input.bytes)),
|
||||||
return JSON.parse(await handle.readFile("utf8"));
|
releaseTree: input.releaseTree,
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
input.releaseTree();
|
||||||
|
throw error;
|
||||||
} finally {
|
} finally {
|
||||||
await handle.close();
|
input.releaseInput();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/** Load the checked Nix output, preserving its original compilation and provenance.
|
/** Load the checked Nix output, preserving its original compilation and provenance.
|
||||||
@@ -22,113 +31,151 @@ async function readJson(root: string, file: string): Promise<any> {
|
|||||||
export async function loadCheckedInstallationCandidate(
|
export async function loadCheckedInstallationCandidate(
|
||||||
root: string,
|
root: string,
|
||||||
selections: Readonly<Record<string, PackageInstallationSelection>> = {},
|
selections: Readonly<Record<string, PackageInstallationSelection>> = {},
|
||||||
|
resources: { budget?: CandidateMetadataBudget; owner?: string } = {},
|
||||||
) {
|
) {
|
||||||
if (!rootPattern.test(root) || !(await lstat(root)).isDirectory())
|
if (!rootPattern.test(root) || !(await lstat(root)).isDirectory())
|
||||||
throw Error("Candidate must be an immutable Nix output directory");
|
throw Error("Candidate must be an immutable Nix output directory");
|
||||||
const [candidate, plan, artifacts, source, entryRequest, kernel, queries, graph] = await Promise.all([
|
const scope = (resources.budget ?? candidateMetadataBudget).acquire(resources.owner ?? root);
|
||||||
readJson(root, "candidate.json"),
|
try {
|
||||||
readJson(root, "execution-plan.json"),
|
// Validate the duplicated source contract by digest, then discard its tree
|
||||||
readJson(root, "execution-artifacts.json"),
|
// before allocating the substantially larger checked execution plan.
|
||||||
readJson(root, "source.json"),
|
const workspaceDigest = await (async () => {
|
||||||
readJson(root, "entry.json"),
|
const input = await readJson(root, "candidate.json", scope);
|
||||||
readJson(root, "kernel.json"),
|
try {
|
||||||
readJson(root, "queries.json"),
|
const { executionContracts: _legacyContracts, ...workspace } = input.value;
|
||||||
readJson(root, "graph-execution.json"),
|
return hexDigest(workspace);
|
||||||
]);
|
} finally {
|
||||||
const { executionContracts: _legacyContracts, ...workspace } = candidate;
|
input.releaseTree();
|
||||||
if (
|
}
|
||||||
plan?.definition?.codec !== "camino-execution-plan-v1" ||
|
})();
|
||||||
hexDigest(plan.definition) !== plan.digest ||
|
// Sequential reads avoid partially rejected Promise.all() work allocating
|
||||||
hexDigest(workspace) !== hexDigest(plan.definition.workspace)
|
// after the failed candidate's reservation has been released.
|
||||||
)
|
const values = [];
|
||||||
throw new ExecutionPlanError(
|
for (const file of [
|
||||||
"CANDIDATE_PLAN_MISMATCH",
|
"execution-plan.json",
|
||||||
root,
|
"execution-artifacts.json",
|
||||||
"Stored plan must match its digest and exact workspace source contract",
|
"source.json",
|
||||||
);
|
"entry.json",
|
||||||
if (
|
"kernel.json",
|
||||||
source.kind !== "workspace" ||
|
"queries.json",
|
||||||
source.commit !== plan.definition.workspace.sourceRootCommit ||
|
]) {
|
||||||
typeof source.repository !== "string"
|
const parsed = await readJson(root, file, scope);
|
||||||
)
|
values.push(parsed.value);
|
||||||
throw new ExecutionPlanError("CANDIDATE_SOURCE_MISMATCH", root, "Expected exact workspace source provenance");
|
}
|
||||||
const repository = new URL(source.repository);
|
const [plan, artifacts, source, entryRequest, kernel, queries] = values;
|
||||||
if (
|
if (
|
||||||
!["https:", "ssh:"].includes(repository.protocol) ||
|
plan?.definition?.codec !== "camino-execution-plan-v1" ||
|
||||||
repository.username ||
|
hexDigest(plan.definition) !== plan.digest ||
|
||||||
repository.password ||
|
workspaceDigest !== hexDigest(plan.definition.workspace)
|
||||||
repository.hash ||
|
)
|
||||||
repository.search
|
|
||||||
)
|
|
||||||
throw new ExecutionPlanError("CANDIDATE_SOURCE_INVALID", root, "Expected a source URL without credentials");
|
|
||||||
if (
|
|
||||||
artifacts.codec !== "camino-checked-execution-v2" ||
|
|
||||||
typeof artifacts.generator !== "string" ||
|
|
||||||
!/^[0-9a-f]{64}$/.test(artifacts.generator) ||
|
|
||||||
!artifacts.roots ||
|
|
||||||
typeof artifacts.roots !== "object" ||
|
|
||||||
Array.isArray(artifacts.roots)
|
|
||||||
)
|
|
||||||
throw new ExecutionPlanError("CANDIDATE_ARTIFACTS_INVALID", root, "Expected checked package roots");
|
|
||||||
for (const entry of Object.values(artifacts.roots))
|
|
||||||
if (typeof entry !== "string" || !rootPattern.test(entry))
|
|
||||||
throw new ExecutionPlanError(
|
throw new ExecutionPlanError(
|
||||||
"CANDIDATE_ARTIFACTS_INVALID",
|
"CANDIDATE_PLAN_MISMATCH",
|
||||||
root,
|
root,
|
||||||
"Package artifacts must be immutable Nix roots",
|
"Stored plan must match its digest and exact workspace source contract",
|
||||||
);
|
);
|
||||||
const installation = await loadExecutionInstallation(plan, artifacts.roots, selections);
|
if (
|
||||||
const entry = compileWorkspaceEntry(plan, entryRequest);
|
source.kind !== "workspace" ||
|
||||||
for (const [name, program, codec] of [
|
source.commit !== plan.definition.workspace.sourceRootCommit ||
|
||||||
["kernel", kernel, "camino-kernel-program-v1"],
|
typeof source.repository !== "string"
|
||||||
["queries", queries, "camino-query-program-v1"],
|
)
|
||||||
] as const)
|
throw new ExecutionPlanError("CANDIDATE_SOURCE_MISMATCH", root, "Expected exact workspace source provenance");
|
||||||
if (program?.codec !== codec || program.plan !== kernel.plan || hexDigest(program) !== artifacts.programs?.[name])
|
const repository = new URL(source.repository);
|
||||||
throw new ExecutionPlanError(
|
if (
|
||||||
"CANDIDATE_PROGRAM_MISMATCH",
|
!["https:", "ssh:"].includes(repository.protocol) ||
|
||||||
name,
|
repository.username ||
|
||||||
"Stored interpreter input must match the checked build and plan",
|
repository.password ||
|
||||||
);
|
repository.hash ||
|
||||||
const expectedGraph = graphExecutionRepresentation(plan, installation, kernel, queries);
|
repository.search
|
||||||
if (hexDigest(graph) !== hexDigest(expectedGraph) || artifacts.execution !== hexDigest(graph))
|
)
|
||||||
throw new ExecutionPlanError(
|
throw new ExecutionPlanError("CANDIDATE_SOURCE_INVALID", root, "Expected a source URL without credentials");
|
||||||
"CANDIDATE_EXECUTION_MISMATCH",
|
if (
|
||||||
|
artifacts.codec !== "camino-checked-execution-v2" ||
|
||||||
|
typeof artifacts.generator !== "string" ||
|
||||||
|
!/^[0-9a-f]{64}$/.test(artifacts.generator) ||
|
||||||
|
!artifacts.roots ||
|
||||||
|
typeof artifacts.roots !== "object" ||
|
||||||
|
Array.isArray(artifacts.roots)
|
||||||
|
)
|
||||||
|
throw new ExecutionPlanError("CANDIDATE_ARTIFACTS_INVALID", root, "Expected checked package roots");
|
||||||
|
for (const entry of Object.values(artifacts.roots))
|
||||||
|
if (typeof entry !== "string" || !rootPattern.test(entry))
|
||||||
|
throw new ExecutionPlanError(
|
||||||
|
"CANDIDATE_ARTIFACTS_INVALID",
|
||||||
|
root,
|
||||||
|
"Package artifacts must be immutable Nix roots",
|
||||||
|
);
|
||||||
|
const installation = await loadExecutionInstallation(plan, artifacts.roots, selections, scope);
|
||||||
|
const entry = compileWorkspaceEntry(plan, entryRequest);
|
||||||
|
for (const [name, program, codec] of [
|
||||||
|
["kernel", kernel, "camino-kernel-program-v1"],
|
||||||
|
["queries", queries, "camino-query-program-v1"],
|
||||||
|
] as const)
|
||||||
|
if (program?.codec !== codec || program.plan !== kernel.plan || hexDigest(program) !== artifacts.programs?.[name])
|
||||||
|
throw new ExecutionPlanError(
|
||||||
|
"CANDIDATE_PROGRAM_MISMATCH",
|
||||||
|
name,
|
||||||
|
"Stored interpreter input must match the checked build and plan",
|
||||||
|
);
|
||||||
|
const expectedGraph = graphExecutionRepresentation(plan, installation, kernel, queries);
|
||||||
|
// The stored graph embeds the same kernel/query programs. Validate it in a
|
||||||
|
// short-lived scope and retain the representation that shares those trees.
|
||||||
|
await (async () => {
|
||||||
|
const input = await readJson(root, "graph-execution.json", scope);
|
||||||
|
try {
|
||||||
|
const digest = hexDigest(input.value);
|
||||||
|
if (digest !== hexDigest(expectedGraph) || artifacts.execution !== digest)
|
||||||
|
throw new ExecutionPlanError(
|
||||||
|
"CANDIDATE_EXECUTION_MISMATCH",
|
||||||
|
root,
|
||||||
|
"Stored graph execution differs from checked inputs",
|
||||||
|
);
|
||||||
|
} finally {
|
||||||
|
input.releaseTree();
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
const provenance = {
|
||||||
|
workspaceRevision: plan.definition.workspace.id as string,
|
||||||
|
source: { repository: source.repository as string, commit: source.commit as string },
|
||||||
|
generator: artifacts.generator as string,
|
||||||
|
packages: (plan as ExecutionPlan).definition.packages.map((pkg) => ({
|
||||||
|
revision: pkg.revision,
|
||||||
|
source: pkg.source,
|
||||||
|
})),
|
||||||
|
};
|
||||||
|
const reference = {
|
||||||
root,
|
root,
|
||||||
"Stored graph execution differs from checked inputs",
|
digest: hexDigest({
|
||||||
);
|
plan: plan.digest,
|
||||||
const provenance = {
|
world: installation.world,
|
||||||
workspaceRevision: workspace.id as string,
|
provenance,
|
||||||
source: { repository: source.repository as string, commit: source.commit as string },
|
roots: artifacts.roots,
|
||||||
generator: artifacts.generator as string,
|
entry,
|
||||||
packages: (plan as ExecutionPlan).definition.packages.map((pkg) => ({
|
programs: artifacts.programs,
|
||||||
revision: pkg.revision,
|
}),
|
||||||
source: pkg.source,
|
};
|
||||||
})),
|
return {
|
||||||
};
|
reference,
|
||||||
const reference = {
|
workspace: plan.definition.workspace.workspaceId,
|
||||||
root,
|
world: hexDigest(expectedGraph),
|
||||||
digest: hexDigest({
|
plan: kernel.plan as string,
|
||||||
plan: plan.digest,
|
graphExecution: expectedGraph,
|
||||||
world: installation.world,
|
|
||||||
provenance,
|
provenance,
|
||||||
roots: artifacts.roots,
|
|
||||||
entry,
|
entry,
|
||||||
programs: artifacts.programs,
|
kernel,
|
||||||
}),
|
queries,
|
||||||
};
|
installation,
|
||||||
return {
|
executionPlan: plan as ExecutionPlan,
|
||||||
reference,
|
metadata: {
|
||||||
workspace: plan.definition.workspace.workspaceId,
|
get bytes() {
|
||||||
world: hexDigest(graph),
|
return scope.bytes;
|
||||||
plan: kernel.plan as string,
|
},
|
||||||
graphExecution: graph,
|
release: scope.release,
|
||||||
provenance,
|
},
|
||||||
entry,
|
};
|
||||||
kernel,
|
} catch (error) {
|
||||||
queries,
|
scope.release();
|
||||||
installation,
|
throw error;
|
||||||
executionPlan: plan as ExecutionPlan,
|
}
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function compileWorkspaceEntry(plan: ExecutionPlan, entryRequest: unknown): { operation: string } | null {
|
export function compileWorkspaceEntry(plan: ExecutionPlan, entryRequest: unknown): { operation: string } | null {
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import {
|
|||||||
type CheckedWorld,
|
type CheckedWorld,
|
||||||
} from "./artifacts.js";
|
} from "./artifacts.js";
|
||||||
import { type ExecutionPlan, ExecutionPlanError } from "./plan.js";
|
import { type ExecutionPlan, ExecutionPlanError } from "./plan.js";
|
||||||
|
import { readCandidateMetadata, type CandidateMetadataScope } from "./metadata.js";
|
||||||
|
|
||||||
const maxFileBytes = 256 * 1024 * 1024;
|
const maxFileBytes = 256 * 1024 * 1024;
|
||||||
const metadataLimit = 16 * 1024 * 1024;
|
const metadataLimit = 16 * 1024 * 1024;
|
||||||
@@ -21,6 +22,18 @@ const fail = (where: string, message: string): never => {
|
|||||||
};
|
};
|
||||||
/** Roots must be trusted immutable output directories. Refuse symlinks, including
|
/** Roots must be trusted immutable output directories. Refuse symlinks, including
|
||||||
* interior directory links. Hash verification is still required before serving bytes. */
|
* interior directory links. Hash verification is still required before serving bytes. */
|
||||||
|
async function artifactFile(root: string, relative: string): Promise<string> {
|
||||||
|
artifactPath(relative);
|
||||||
|
const components = relative.split("/");
|
||||||
|
let resolved = root;
|
||||||
|
for (let index = 0; index < components.length; index++) {
|
||||||
|
resolved = path.join(resolved, components[index]!);
|
||||||
|
const stat = await lstat(resolved);
|
||||||
|
if (stat.isSymbolicLink() || (index < components.length - 1 ? !stat.isDirectory() : !stat.isFile()))
|
||||||
|
fail(relative, "Only real directories and regular files are allowed");
|
||||||
|
}
|
||||||
|
return resolved;
|
||||||
|
}
|
||||||
export async function artifactFileReader(roots: Readonly<Record<string, string>>): Promise<ArtifactReader> {
|
export async function artifactFileReader(roots: Readonly<Record<string, string>>): Promise<ArtifactReader> {
|
||||||
const directories = new Map<string, string>();
|
const directories = new Map<string, string>();
|
||||||
for (const [revision, root] of Object.entries(roots)) {
|
for (const [revision, root] of Object.entries(roots)) {
|
||||||
@@ -33,16 +46,8 @@ export async function artifactFileReader(roots: Readonly<Record<string, string>>
|
|||||||
return async (revision, relative, limit) => {
|
return async (revision, relative, limit) => {
|
||||||
const root = directories.get(revision);
|
const root = directories.get(revision);
|
||||||
if (!root) fail(revision, "Unknown package output");
|
if (!root) fail(revision, "Unknown package output");
|
||||||
artifactPath(relative);
|
|
||||||
if (!Number.isSafeInteger(limit) || limit < 0 || limit > maxFileBytes) fail(relative, "Invalid file byte limit");
|
if (!Number.isSafeInteger(limit) || limit < 0 || limit > maxFileBytes) fail(relative, "Invalid file byte limit");
|
||||||
const components = relative.split("/");
|
const resolved = await artifactFile(root!, relative);
|
||||||
let resolved = root!;
|
|
||||||
for (let index = 0; index < components.length; index++) {
|
|
||||||
resolved = path.join(resolved, components[index]!);
|
|
||||||
const stat = await lstat(resolved);
|
|
||||||
if (stat.isSymbolicLink() || (index < components.length - 1 ? !stat.isDirectory() : !stat.isFile()))
|
|
||||||
fail(relative, "Only real directories and regular files are allowed");
|
|
||||||
}
|
|
||||||
const handle = await open(resolved, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
|
const handle = await open(resolved, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
|
||||||
try {
|
try {
|
||||||
const stat = await handle.stat();
|
const stat = await handle.stat();
|
||||||
@@ -72,6 +77,7 @@ export interface LoadedArtifactWorld {
|
|||||||
export async function loadArtifactWorld(
|
export async function loadArtifactWorld(
|
||||||
plan: ExecutionPlan,
|
plan: ExecutionPlan,
|
||||||
roots: Readonly<Record<string, string>>,
|
roots: Readonly<Record<string, string>>,
|
||||||
|
metadata?: CandidateMetadataScope,
|
||||||
): Promise<LoadedArtifactWorld> {
|
): Promise<LoadedArtifactWorld> {
|
||||||
const read = await artifactFileReader(roots),
|
const read = await artifactFileReader(roots),
|
||||||
manifests: PackageArtifacts[] = [];
|
manifests: PackageArtifacts[] = [];
|
||||||
@@ -79,8 +85,16 @@ export async function loadArtifactWorld(
|
|||||||
if (JSON.stringify(Object.keys(roots).sort()) !== JSON.stringify(expected))
|
if (JSON.stringify(Object.keys(roots).sort()) !== JSON.stringify(expected))
|
||||||
fail("world", "Output roots must exactly match the installed plan");
|
fail("world", "Output roots must exactly match the installed plan");
|
||||||
for (const revision of expected) {
|
for (const revision of expected) {
|
||||||
const bytes = await read(revision, "share/quixos/package-artifacts.json", metadataLimit);
|
const file = "share/quixos/package-artifacts.json";
|
||||||
const manifest = parsePackageArtifacts(JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(bytes)));
|
const input = metadata
|
||||||
|
? await readCandidateMetadata(await artifactFile(roots[revision]!, file), metadata, metadataLimit)
|
||||||
|
: { bytes: await read(revision, file, metadataLimit), releaseInput: () => {} };
|
||||||
|
let manifest: PackageArtifacts;
|
||||||
|
try {
|
||||||
|
manifest = parsePackageArtifacts(JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(input.bytes)));
|
||||||
|
} finally {
|
||||||
|
input.releaseInput();
|
||||||
|
}
|
||||||
if (manifest.packageRevisionId !== revision) fail(revision, "Output belongs to another package revision");
|
if (manifest.packageRevisionId !== revision) fail(revision, "Output belongs to another package revision");
|
||||||
manifests.push(manifest);
|
manifests.push(manifest);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ export * from "./queries.js";
|
|||||||
export * from "./query-document.js";
|
export * from "./query-document.js";
|
||||||
export { generatePortableClientBindings } from "../bindings/portable-client.js";
|
export { generatePortableClientBindings } from "../bindings/portable-client.js";
|
||||||
export * from "./candidate.js";
|
export * from "./candidate.js";
|
||||||
|
export * from "./metadata.js";
|
||||||
|
|
||||||
export { reviewSemanticMajors } from "../capability-model/evolution.js";
|
export { reviewSemanticMajors } from "../capability-model/evolution.js";
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import {
|
|||||||
type PublicQueryContract,
|
type PublicQueryContract,
|
||||||
} from "./client-contracts.js";
|
} from "./client-contracts.js";
|
||||||
import { resultInterfaces } from "./projections.js";
|
import { resultInterfaces } from "./projections.js";
|
||||||
|
import type { CandidateMetadataScope } from "./metadata.js";
|
||||||
|
|
||||||
/** Activation is assigned by graph authority, never by a package artifact. */
|
/** Activation is assigned by graph authority, never by a package artifact. */
|
||||||
export interface ActiveExecutionIdentity {
|
export interface ActiveExecutionIdentity {
|
||||||
@@ -112,6 +113,8 @@ export interface ExecutionInstallation {
|
|||||||
readonly root: string;
|
readonly root: string;
|
||||||
readonly service?: ArtifactImplementation;
|
readonly service?: ArtifactImplementation;
|
||||||
readonly module?: ArtifactImplementation;
|
readonly module?: ArtifactImplementation;
|
||||||
|
/** Checked candidate only; the qualified host verifies its import surface and SDK. */
|
||||||
|
readonly restricted?: ArtifactImplementation;
|
||||||
readonly browserImplementation?: ArtifactImplementation;
|
readonly browserImplementation?: ArtifactImplementation;
|
||||||
readonly browserURL?: string;
|
readonly browserURL?: string;
|
||||||
readonly browserRegistry?: string;
|
readonly browserRegistry?: string;
|
||||||
@@ -159,8 +162,9 @@ export async function loadExecutionInstallation(
|
|||||||
plan: ExecutionPlan,
|
plan: ExecutionPlan,
|
||||||
roots: Readonly<Record<string, string>>,
|
roots: Readonly<Record<string, string>>,
|
||||||
selections: Readonly<Record<string, PackageInstallationSelection>> = {},
|
selections: Readonly<Record<string, PackageInstallationSelection>> = {},
|
||||||
|
metadata?: CandidateMetadataScope,
|
||||||
): Promise<ExecutionInstallation> {
|
): Promise<ExecutionInstallation> {
|
||||||
return assembleExecutionInstallation(plan, roots, await loadArtifactWorld(plan, roots), selections);
|
return assembleExecutionInstallation(plan, roots, await loadArtifactWorld(plan, roots, metadata), selections);
|
||||||
}
|
}
|
||||||
function assembleExecutionInstallation(
|
function assembleExecutionInstallation(
|
||||||
plan: ExecutionPlan,
|
plan: ExecutionPlan,
|
||||||
@@ -249,6 +253,11 @@ function assembleExecutionInstallation(
|
|||||||
exports: exports.map((entry) => entry.id),
|
exports: exports.map((entry) => entry.id),
|
||||||
})
|
})
|
||||||
: undefined;
|
: undefined;
|
||||||
|
const restrictedCandidates = manifest.implementations.filter(
|
||||||
|
(entry) => entry.compatibility === "quixos-restricted-module-v1",
|
||||||
|
);
|
||||||
|
if (restrictedCandidates.length > 1) fail(revision, "Ambiguous restricted module candidates");
|
||||||
|
const restricted = restrictedCandidates[0];
|
||||||
const browserExports = exports.filter(
|
const browserExports = exports.filter(
|
||||||
(entry) =>
|
(entry) =>
|
||||||
entry.execution.kind !== "remote" &&
|
entry.execution.kind !== "remote" &&
|
||||||
@@ -256,7 +265,13 @@ function assembleExecutionInstallation(
|
|||||||
);
|
);
|
||||||
if (!browserExports.length) {
|
if (!browserExports.length) {
|
||||||
if (selection.browser) fail(revision, "Package has no browser exports to select");
|
if (selection.browser) fail(revision, "Package has no browser exports to select");
|
||||||
packages.push({ revision, root, ...(service ? { service } : {}), ...(module ? { module } : {}) });
|
packages.push({
|
||||||
|
revision,
|
||||||
|
root,
|
||||||
|
...(service ? { service } : {}),
|
||||||
|
...(module ? { module } : {}),
|
||||||
|
...(restricted ? { restricted } : {}),
|
||||||
|
});
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const browser = selectArtifactImplementation(manifest, {
|
const browser = selectArtifactImplementation(manifest, {
|
||||||
@@ -287,6 +302,7 @@ function assembleExecutionInstallation(
|
|||||||
root,
|
root,
|
||||||
...(service ? { service } : {}),
|
...(service ? { service } : {}),
|
||||||
...(module ? { module } : {}),
|
...(module ? { module } : {}),
|
||||||
|
...(restricted ? { restricted } : {}),
|
||||||
browserImplementation: browser,
|
browserImplementation: browser,
|
||||||
browserURL: contentArtifactUrl(entry),
|
browserURL: contentArtifactUrl(entry),
|
||||||
browserRegistry: browser.registryExport,
|
browserRegistry: browser.registryExport,
|
||||||
|
|||||||
@@ -0,0 +1,138 @@
|
|||||||
|
import { constants } from "node:fs";
|
||||||
|
import { open } from "node:fs/promises";
|
||||||
|
|
||||||
|
/** Admission estimates, not a hard V8 heap limit. A process/cgroup ceiling is
|
||||||
|
* still required. Charge input, parse trees and derived indexes before reading
|
||||||
|
* or parsing. Each live candidate retains its reservation until explicit close. */
|
||||||
|
export class CandidateMetadataBudget {
|
||||||
|
readonly limits: Readonly<{ bytes: number; ownerBytes: number; candidates: number }>;
|
||||||
|
private bytes = 0;
|
||||||
|
private scopes = 0;
|
||||||
|
private readonly owners = new Map<string, number>();
|
||||||
|
// A cutover holds both the serving and proposed installation plus transient
|
||||||
|
// parsing space. The 57-repository reader retains ~133 MiB per installation;
|
||||||
|
// a 256 MiB owner ceiling cannot admit its ordinary atomic replacement.
|
||||||
|
// Keep the aggregate ceiling independent and leave room for parsing overlap.
|
||||||
|
constructor(limits = { bytes: 512 * 1024 * 1024, ownerBytes: 384 * 1024 * 1024, candidates: 128 }) {
|
||||||
|
for (const value of Object.values(limits))
|
||||||
|
if (!Number.isSafeInteger(value) || value < 1) throw Error("INVALID_CANDIDATE_METADATA_BUDGET");
|
||||||
|
if (limits.ownerBytes > limits.bytes) throw Error("INVALID_CANDIDATE_METADATA_BUDGET");
|
||||||
|
this.limits = Object.freeze({ ...limits });
|
||||||
|
}
|
||||||
|
snapshot() {
|
||||||
|
return { bytes: this.bytes, candidates: this.scopes, owners: this.owners.size, limits: this.limits };
|
||||||
|
}
|
||||||
|
acquire(owner: string) {
|
||||||
|
if (!owner || owner.length > 4096) throw Error("INVALID_CANDIDATE_METADATA_OWNER");
|
||||||
|
if (this.scopes >= this.limits.candidates) throw Error("CANDIDATE_METADATA_LIMIT");
|
||||||
|
this.scopes++;
|
||||||
|
let bytes = 0,
|
||||||
|
closed = false;
|
||||||
|
const charge = (amount: number) => {
|
||||||
|
if (closed) throw Error("CANDIDATE_METADATA_CLOSED");
|
||||||
|
if (!Number.isSafeInteger(amount) || amount < 0) throw Error("INVALID_CANDIDATE_METADATA_CHARGE");
|
||||||
|
const owned = this.owners.get(owner) ?? 0;
|
||||||
|
if (this.bytes + amount > this.limits.bytes || owned + amount > this.limits.ownerBytes)
|
||||||
|
throw Error("CANDIDATE_METADATA_LIMIT");
|
||||||
|
bytes += amount;
|
||||||
|
this.bytes += amount;
|
||||||
|
this.owners.set(owner, owned + amount);
|
||||||
|
};
|
||||||
|
const subtract = (amount: number) => {
|
||||||
|
bytes -= amount;
|
||||||
|
this.bytes -= amount;
|
||||||
|
const remaining = (this.owners.get(owner) ?? 0) - amount;
|
||||||
|
if (remaining) this.owners.set(owner, remaining);
|
||||||
|
else this.owners.delete(owner);
|
||||||
|
};
|
||||||
|
return {
|
||||||
|
get bytes() {
|
||||||
|
return bytes;
|
||||||
|
},
|
||||||
|
charge,
|
||||||
|
/** Opaque, idempotent transient reservation; callers cannot subtract an
|
||||||
|
* arbitrary amount or release another candidate's charges. */
|
||||||
|
reserve: (amount: number) => {
|
||||||
|
charge(amount);
|
||||||
|
let released = false;
|
||||||
|
return () => {
|
||||||
|
if (closed || released) return;
|
||||||
|
released = true;
|
||||||
|
subtract(amount);
|
||||||
|
};
|
||||||
|
},
|
||||||
|
release: () => {
|
||||||
|
if (closed) return;
|
||||||
|
closed = true;
|
||||||
|
subtract(bytes);
|
||||||
|
this.scopes--;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
export type CandidateMetadataScope = ReturnType<CandidateMetadataBudget["acquire"]>;
|
||||||
|
export const candidateMetadataBudget = new CandidateMetadataBudget();
|
||||||
|
|
||||||
|
// Estimate JSON allocation without constructing its tree. Object/array headers,
|
||||||
|
// value slots and strings get explicit weights, with a multiplier for checked
|
||||||
|
// indexes/derived representations. Indentation must not multiply tree charges.
|
||||||
|
function jsonAllocation(bytes: Uint8Array): number {
|
||||||
|
let estimate = 0;
|
||||||
|
for (let i = 0; i < bytes.length; i++) {
|
||||||
|
const c = bytes[i]!;
|
||||||
|
if (c === 123) estimate += 64;
|
||||||
|
else if (c === 91) estimate += 32;
|
||||||
|
else if (c === 34) {
|
||||||
|
const start = ++i;
|
||||||
|
while (i < bytes.length && bytes[i] !== 34) {
|
||||||
|
if (bytes[i] === 92) i++;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
estimate += 32 + 2 * (i - start);
|
||||||
|
} else if (c === 45 || (c >= 48 && c <= 57) || c === 116 || c === 102 || c === 110) {
|
||||||
|
estimate += 16;
|
||||||
|
while (i + 1 < bytes.length) {
|
||||||
|
const next = bytes[i + 1]!;
|
||||||
|
if (next === 9 || next === 10 || next === 13 || next === 32 || next === 44 || next === 93 || next === 125)
|
||||||
|
break;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return estimate * 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Immutable regular files only. Fixed allocation plus an extra byte catches
|
||||||
|
* growth; readFile() would allocate before the admission check can intervene. */
|
||||||
|
export async function readCandidateMetadata(
|
||||||
|
path: string,
|
||||||
|
scope: CandidateMetadataScope,
|
||||||
|
limit: number,
|
||||||
|
): Promise<{ bytes: Uint8Array; releaseInput: () => void; releaseTree: () => void }> {
|
||||||
|
const handle = await open(path, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
|
||||||
|
let releaseInput: (() => void) | undefined;
|
||||||
|
try {
|
||||||
|
const stat = await handle.stat();
|
||||||
|
if (!stat.isFile() || !Number.isSafeInteger(stat.size) || stat.size > limit)
|
||||||
|
throw Error("CANDIDATE_METADATA_FILE_LIMIT");
|
||||||
|
// Reserve the input buffer and UTF-16 decoding before allocating either.
|
||||||
|
releaseInput = scope.reserve((stat.size + 1) * 3);
|
||||||
|
const bytes = Buffer.alloc(stat.size + 1);
|
||||||
|
let offset = 0;
|
||||||
|
while (offset < bytes.length) {
|
||||||
|
const read = await handle.read(bytes, offset, bytes.length - offset, offset);
|
||||||
|
if (!read.bytesRead) break;
|
||||||
|
offset += read.bytesRead;
|
||||||
|
}
|
||||||
|
if (offset !== stat.size) throw Error("CANDIDATE_METADATA_CHANGED");
|
||||||
|
const content = bytes.subarray(0, offset);
|
||||||
|
// No JSON.parse/decoded tree exists until its shape-based charge succeeds.
|
||||||
|
const releaseTree = scope.reserve(jsonAllocation(content));
|
||||||
|
return { bytes: content, releaseInput, releaseTree };
|
||||||
|
} catch (error) {
|
||||||
|
releaseInput?.();
|
||||||
|
throw error;
|
||||||
|
} finally {
|
||||||
|
await handle.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -23,6 +23,75 @@ export interface ImportFinding {
|
|||||||
readonly detail: string;
|
readonly detail: string;
|
||||||
readonly line: number | null;
|
readonly line: number | null;
|
||||||
}
|
}
|
||||||
|
export const restrictedSDKSpecifier = "quixos:restricted-sdk/v1";
|
||||||
|
export const restrictedSDKPath = "share/quixos/restricted/core.mjs";
|
||||||
|
|
||||||
|
/** Compare trusted SDK syntax without build-machine paths in source comments.
|
||||||
|
* Keep literal/directive spelling and every executable AST node. This is SDK
|
||||||
|
* compatibility only: artifact files and the executed host SDK still have exact
|
||||||
|
* byte digests, and authored SDK bytes are never loaded by the restricted host.
|
||||||
|
*/
|
||||||
|
export function restrictedSDKIdentity(source: string): string {
|
||||||
|
if (Buffer.byteLength(source) > 2 * 1024 * 1024) throw Error("RESTRICTED_SDK_ANALYSIS_LIMIT");
|
||||||
|
const syntax = parse(source, { sourceType: "module", attachComment: false });
|
||||||
|
const metadata = new Set([
|
||||||
|
"start",
|
||||||
|
"end",
|
||||||
|
"loc",
|
||||||
|
"comments",
|
||||||
|
"leadingComments",
|
||||||
|
"innerComments",
|
||||||
|
"trailingComments",
|
||||||
|
"parenStart",
|
||||||
|
]);
|
||||||
|
let nodes = 0;
|
||||||
|
const encoded = JSON.stringify(syntax, (key, value) => {
|
||||||
|
if (metadata.has(key)) return undefined;
|
||||||
|
if (value && typeof value === "object" && typeof value.type === "string" && ++nodes > 100000)
|
||||||
|
throw Error("RESTRICTED_SDK_ANALYSIS_LIMIT");
|
||||||
|
return value;
|
||||||
|
});
|
||||||
|
return hexDigest({ codec: "quixos-restricted-sdk-syntax-v1", syntax: JSON.parse(encoded) });
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Mechanical candidate checks, not authorization or an engine-safety proof.
|
||||||
|
* The caller must first verify the manifest and all declared file digests. */
|
||||||
|
export async function inspectRestrictedImplementation(
|
||||||
|
revision: string,
|
||||||
|
implementation: ArtifactImplementation,
|
||||||
|
read: ArtifactReader,
|
||||||
|
qualifiedSDKIdentity?: string,
|
||||||
|
): Promise<ImportFinding[]> {
|
||||||
|
const entry = implementation.files.find((file) => file.path === implementation.path);
|
||||||
|
const sdk = implementation.files.find((file) => file.path === restrictedSDKPath);
|
||||||
|
if (
|
||||||
|
implementation.compatibility !== "quixos-restricted-module-v1" ||
|
||||||
|
implementation.target !== "server" ||
|
||||||
|
implementation.files.length !== 2 ||
|
||||||
|
!entry ||
|
||||||
|
!sdk ||
|
||||||
|
entry === sdk ||
|
||||||
|
entry.mediaType !== "text/javascript" ||
|
||||||
|
sdk.mediaType !== "text/javascript" ||
|
||||||
|
!/^[$A-Z_a-z][$\w]*$/.test(implementation.registryExport ?? "")
|
||||||
|
)
|
||||||
|
return [{ code: "RESTRICTED_CLOSURE", detail: "Expected one closed module and the restricted SDK", line: null }];
|
||||||
|
if (entry.bytes > 1024 * 1024 || sdk.bytes > 2 * 1024 * 1024)
|
||||||
|
return [{ code: "ANALYSIS_LIMIT", detail: "Restricted closure exceeds the source budget", line: null }];
|
||||||
|
if (qualifiedSDKIdentity) {
|
||||||
|
const source = Buffer.from(await read(revision, sdk.path, sdk.bytes)).toString("utf8");
|
||||||
|
try {
|
||||||
|
if (restrictedSDKIdentity(source) !== qualifiedSDKIdentity) throw Error("SDK syntax differs");
|
||||||
|
} catch {
|
||||||
|
return [
|
||||||
|
{ code: "RESTRICTED_SDK_UNSUPPORTED", detail: "SDK differs from the qualified host profile", line: null },
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return inspectJavaScriptSurface(Buffer.from(await read(revision, entry.path, entry.bytes)).toString("utf8"), [
|
||||||
|
restrictedSDKSpecifier,
|
||||||
|
]);
|
||||||
|
}
|
||||||
const nativeImports = new Set(builtinModules.flatMap((name) => [name, name.replace(/^node:/, "")]));
|
const nativeImports = new Set(builtinModules.flatMap((name) => [name, name.replace(/^node:/, "")]));
|
||||||
const ambient = new Set([
|
const ambient = new Set([
|
||||||
"process",
|
"process",
|
||||||
@@ -136,9 +205,8 @@ export function inspectJavaScriptSurface(source: string, checkedSDKImports: read
|
|||||||
return findings;
|
return findings;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Derived metadata only. Browser/server portability and available targets say
|
/** Derived metadata only. A build report can describe a closed candidate but
|
||||||
* nothing about sandbox eligibility. No existing package artifact has a
|
* cannot qualify the host's engine, SDK, OS sandbox or resource controller. */
|
||||||
* qualified restricted runtime, so it conservatively requires its VM. */
|
|
||||||
export async function reportExecutionPlacement(
|
export async function reportExecutionPlacement(
|
||||||
plan: ExecutionPlan,
|
plan: ExecutionPlan,
|
||||||
installation: ExecutionInstallation,
|
installation: ExecutionInstallation,
|
||||||
@@ -155,11 +223,13 @@ export async function reportExecutionPlacement(
|
|||||||
const packages = await Promise.all(
|
const packages = await Promise.all(
|
||||||
installation.packages.map(async (pkg) => {
|
installation.packages.map(async (pkg) => {
|
||||||
const implementations: { id: string; digest: string; compatibility: string; findings: ImportFinding[] }[] = [];
|
const implementations: { id: string; digest: string; compatibility: string; findings: ImportFinding[] }[] = [];
|
||||||
for (const implementation of [pkg.service, pkg.module].filter(
|
for (const implementation of [pkg.service, pkg.module, pkg.restricted].filter(
|
||||||
(entry): entry is ArtifactImplementation => !!entry,
|
(entry): entry is ArtifactImplementation => !!entry,
|
||||||
)) {
|
)) {
|
||||||
let findings: ImportFinding[];
|
let findings: ImportFinding[];
|
||||||
if (implementation.compatibility === "quixos-js-module-v1") {
|
if (implementation.compatibility === "quixos-restricted-module-v1")
|
||||||
|
findings = await inspectRestrictedImplementation(pkg.revision, implementation, read);
|
||||||
|
else if (implementation.compatibility === "quixos-js-module-v1") {
|
||||||
const file = implementation.files.find((file) => file.path === implementation.path)!;
|
const file = implementation.files.find((file) => file.path === implementation.path)!;
|
||||||
if (!file || file.bytes > 1024 * 1024)
|
if (!file || file.bytes > 1024 * 1024)
|
||||||
findings = [
|
findings = [
|
||||||
@@ -191,7 +261,14 @@ export async function reportExecutionPlacement(
|
|||||||
revision: pkg.revision,
|
revision: pkg.revision,
|
||||||
requiresVM: implementations.length > 0,
|
requiresVM: implementations.length > 0,
|
||||||
restrictedEligible: false as const,
|
restrictedEligible: false as const,
|
||||||
reason: "NO_QUALIFIED_RESTRICTED_RUNTIME",
|
reason: pkg.restricted ? "HOST_PROFILE_QUALIFICATION_REQUIRED" : "NO_RESTRICTED_IMPLEMENTATION",
|
||||||
|
restrictedCandidate: pkg.restricted
|
||||||
|
? {
|
||||||
|
digest: pkg.restricted.contentDigest,
|
||||||
|
exports: pkg.restricted.exports,
|
||||||
|
compatible: implementations.find((entry) => entry.id === pkg.restricted!.id)!.findings.length === 0,
|
||||||
|
}
|
||||||
|
: null,
|
||||||
implementations,
|
implementations,
|
||||||
};
|
};
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -29,6 +29,8 @@ export interface PackageInvocation {
|
|||||||
/** Capability arguments/receiver use the versioned managed-reference codec. */
|
/** Capability arguments/receiver use the versioned managed-reference codec. */
|
||||||
input: unknown;
|
input: unknown;
|
||||||
receiver: unknown | null;
|
receiver: unknown | null;
|
||||||
|
/** Host-owned remaining root resources, separate from authored input. */
|
||||||
|
budget?: { root: string; depth: number; calls: number; deadlineMs: number };
|
||||||
}
|
}
|
||||||
export type InvocationReply =
|
export type InvocationReply =
|
||||||
| { abi: typeof transactionPortAbi; invocation: string; status: "returned"; output: unknown }
|
| { abi: typeof transactionPortAbi; invocation: string; status: "returned"; output: unknown }
|
||||||
|
|||||||
@@ -0,0 +1,160 @@
|
|||||||
|
import test from "node:test";
|
||||||
|
import assert from "node:assert/strict";
|
||||||
|
import { mkdtemp, writeFile, symlink, rm } from "node:fs/promises";
|
||||||
|
import { join } from "node:path";
|
||||||
|
import { tmpdir } from "node:os";
|
||||||
|
import { CandidateMetadataBudget, readCandidateMetadata } from "../src/execution-world/metadata.js";
|
||||||
|
import { loadCheckedInstallationCandidate } from "../src/execution-world/candidate.js";
|
||||||
|
|
||||||
|
test(
|
||||||
|
"a real checked application can stage its replacement within the default metadata budget",
|
||||||
|
{
|
||||||
|
skip: !process.env.QX_CHECKED_CANDIDATE,
|
||||||
|
},
|
||||||
|
async () => {
|
||||||
|
const root = process.env.QX_CHECKED_CANDIDATE!;
|
||||||
|
const budget = new CandidateMetadataBudget();
|
||||||
|
const first = await loadCheckedInstallationCandidate(root, {}, { budget, owner: "reader" });
|
||||||
|
try {
|
||||||
|
const retained = budget.snapshot().bytes;
|
||||||
|
const second = await loadCheckedInstallationCandidate(root, {}, { budget, owner: "reader" });
|
||||||
|
try {
|
||||||
|
assert.equal(budget.snapshot().bytes, retained * 2);
|
||||||
|
assert.deepEqual(second.reference, first.reference, "Compaction preserves exact checked identity");
|
||||||
|
assert.equal(second.graphExecution.kernel, second.kernel, "Graph representation shares the validated program");
|
||||||
|
assert.equal(second.graphExecution.queries, second.queries);
|
||||||
|
// A deliberately tighter pool admits the serving installation but must
|
||||||
|
// reject replacement parsing without leaking a candidate or tree lease.
|
||||||
|
const tight = new CandidateMetadataBudget({
|
||||||
|
bytes: retained + 1,
|
||||||
|
ownerBytes: retained + 1,
|
||||||
|
candidates: 2,
|
||||||
|
});
|
||||||
|
const blocker = tight.acquire("reader");
|
||||||
|
blocker.charge(retained);
|
||||||
|
try {
|
||||||
|
await assert.rejects(
|
||||||
|
loadCheckedInstallationCandidate(root, {}, { budget: tight, owner: "reader" }),
|
||||||
|
/CANDIDATE_METADATA_LIMIT/,
|
||||||
|
);
|
||||||
|
assert.equal(tight.snapshot().bytes, retained);
|
||||||
|
assert.equal(tight.snapshot().candidates, 1);
|
||||||
|
} finally {
|
||||||
|
blocker.release();
|
||||||
|
}
|
||||||
|
const other = budget.acquire("other");
|
||||||
|
try {
|
||||||
|
assert.throws(() => other.charge(budget.limits.bytes), /CANDIDATE_METADATA_LIMIT/);
|
||||||
|
assert.equal(budget.snapshot().bytes, retained * 2, "Rejected admission must not leak charges");
|
||||||
|
} finally {
|
||||||
|
other.release();
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
second.metadata.release();
|
||||||
|
}
|
||||||
|
assert.equal(budget.snapshot().bytes, retained, "The serving candidate survives failed or completed staging");
|
||||||
|
} finally {
|
||||||
|
first.metadata.release();
|
||||||
|
}
|
||||||
|
assert.equal(budget.snapshot().bytes, 0);
|
||||||
|
assert.equal(budget.snapshot().candidates, 0);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
test("concurrent candidate reservations enforce aggregate and owner limits and release exactly once", () => {
|
||||||
|
const budget = new CandidateMetadataBudget({ bytes: 1000, ownerBytes: 600, candidates: 3 });
|
||||||
|
const first = budget.acquire("a"),
|
||||||
|
second = budget.acquire("a"),
|
||||||
|
third = budget.acquire("b");
|
||||||
|
assert.throws(() => budget.acquire("c"), /CANDIDATE_METADATA_LIMIT/);
|
||||||
|
first.charge(400);
|
||||||
|
second.charge(200);
|
||||||
|
third.charge(400);
|
||||||
|
assert.throws(() => second.charge(1), /CANDIDATE_METADATA_LIMIT/);
|
||||||
|
assert.throws(() => third.charge(1), /CANDIDATE_METADATA_LIMIT/);
|
||||||
|
assert.equal(budget.snapshot().bytes, 1000);
|
||||||
|
second.release();
|
||||||
|
second.release();
|
||||||
|
assert.equal(budget.snapshot().bytes, 800);
|
||||||
|
assert.throws(() => second.charge(1), /CANDIDATE_METADATA_CLOSED/);
|
||||||
|
first.release();
|
||||||
|
third.release();
|
||||||
|
assert.deepEqual(budget.snapshot(), { bytes: 0, candidates: 0, owners: 0, limits: budget.limits });
|
||||||
|
});
|
||||||
|
|
||||||
|
test("metadata files reserve parse/index space before allocation and refuse oversized or linked inputs", async () => {
|
||||||
|
const root = await mkdtemp(join(tmpdir(), "qx-metadata-budget-"));
|
||||||
|
const budget = new CandidateMetadataBudget({ bytes: 450, ownerBytes: 450, candidates: 2 });
|
||||||
|
const scope = budget.acquire("workspace");
|
||||||
|
try {
|
||||||
|
const file = join(root, "metadata.json");
|
||||||
|
await writeFile(file, '{"ok":true}');
|
||||||
|
const input = await readCandidateMetadata(file, scope, 100);
|
||||||
|
assert.equal(new TextDecoder().decode(input.bytes), '{"ok":true}');
|
||||||
|
const withInput = scope.bytes;
|
||||||
|
input.releaseInput();
|
||||||
|
input.releaseInput();
|
||||||
|
const first = scope.bytes;
|
||||||
|
assert.equal(withInput - first, (Buffer.byteLength('{"ok":true}') + 1) * 3);
|
||||||
|
assert.ok(first > 12 * 3, "Decoded tree and derived metadata are reserved before parsing");
|
||||||
|
await assert.rejects(readCandidateMetadata(file, scope, 100), /CANDIDATE_METADATA_LIMIT/);
|
||||||
|
assert.equal(scope.bytes, first, "Rejected tree allocation releases its transient input buffer");
|
||||||
|
await assert.rejects(readCandidateMetadata(file, scope, 5), /CANDIDATE_METADATA_FILE_LIMIT/);
|
||||||
|
await symlink(file, join(root, "linked"));
|
||||||
|
await assert.rejects(readCandidateMetadata(join(root, "linked"), scope, 100), { code: "ELOOP" });
|
||||||
|
await assert.rejects(readCandidateMetadata(root, scope, 100), /CANDIDATE_METADATA_FILE_LIMIT/);
|
||||||
|
assert.equal(scope.bytes, first);
|
||||||
|
input.releaseTree();
|
||||||
|
input.releaseTree();
|
||||||
|
assert.equal(scope.bytes, 0, "Discarded validation trees can release independently of the candidate");
|
||||||
|
} finally {
|
||||||
|
scope.release();
|
||||||
|
await rm(root, { recursive: true, force: true });
|
||||||
|
}
|
||||||
|
assert.equal(budget.snapshot().bytes, 0);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("JSON structure accounting is independent of indentation and covers strings, values and dense nodes", async () => {
|
||||||
|
const root = await mkdtemp(join(tmpdir(), "qx-metadata-shape-"));
|
||||||
|
const budget = new CandidateMetadataBudget();
|
||||||
|
try {
|
||||||
|
for (const value of [{}, [null, true, false, 1, -3.5e8], { 'a"b': '雪\\"', nodes: [{}, {}, {}] }]) {
|
||||||
|
const measured = [];
|
||||||
|
for (const spaces of [0, 4]) {
|
||||||
|
const file = join(root, "metadata.json"),
|
||||||
|
text = JSON.stringify(value, null, spaces);
|
||||||
|
await writeFile(file, text);
|
||||||
|
const scope = budget.acquire("test");
|
||||||
|
try {
|
||||||
|
const input = await readCandidateMetadata(file, scope, 10000);
|
||||||
|
assert.deepEqual(JSON.parse(new TextDecoder().decode(input.bytes)), value);
|
||||||
|
input.releaseInput();
|
||||||
|
measured.push(scope.bytes);
|
||||||
|
} finally {
|
||||||
|
scope.release();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assert.equal(measured[0], measured[1], "Whitespace changes input storage, not the allocated JSON shape");
|
||||||
|
assert.ok(measured[0] >= 128);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
await rm(root, { recursive: true, force: true });
|
||||||
|
}
|
||||||
|
assert.equal(budget.snapshot().bytes, 0);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("transient leases release exactly once, including after their parent closes", () => {
|
||||||
|
const budget = new CandidateMetadataBudget({ bytes: 1000, ownerBytes: 600, candidates: 3 });
|
||||||
|
const scope = budget.acquire("a");
|
||||||
|
scope.charge(200);
|
||||||
|
const release = scope.reserve(300);
|
||||||
|
assert.throws(() => scope.reserve(101), /CANDIDATE_METADATA_LIMIT/);
|
||||||
|
release();
|
||||||
|
release();
|
||||||
|
assert.equal(scope.bytes, 200);
|
||||||
|
const afterClose = scope.reserve(100);
|
||||||
|
scope.release();
|
||||||
|
afterClose();
|
||||||
|
assert.equal(scope.bytes, 0);
|
||||||
|
assert.equal(budget.snapshot().bytes, 0);
|
||||||
|
});
|
||||||
@@ -2,6 +2,7 @@ import assert from "node:assert/strict";
|
|||||||
import { test } from "node:test";
|
import { test } from "node:test";
|
||||||
import {
|
import {
|
||||||
compileWorkspaceRevision,
|
compileWorkspaceRevision,
|
||||||
|
capabilityId,
|
||||||
computeCapabilityClosure,
|
computeCapabilityClosure,
|
||||||
resolveOperationPlan,
|
resolveOperationPlan,
|
||||||
validateWorkspaceRevision,
|
validateWorkspaceRevision,
|
||||||
@@ -197,6 +198,62 @@ test("public traversal permits a native inverse read without exporting mutation
|
|||||||
expectIssue(workspace, "private-attachment-access");
|
expectIssue(workspace, "private-attachment-access");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("public traversal exports only the selected read-only package edge port", () => {
|
||||||
|
const workspace = makeValidCapabilityWorkspace();
|
||||||
|
const exportDefinition = workspace.packageImports
|
||||||
|
.flatMap((pkg) => pkg.exports)
|
||||||
|
.find((entry) => entry.id === fixtureId.summaryGetExport)!;
|
||||||
|
const port = {
|
||||||
|
id: capabilityId.dependencyPort("port:summary:owner"),
|
||||||
|
displayName: "owner",
|
||||||
|
requirement: {
|
||||||
|
kind: "edge" as const,
|
||||||
|
target: { kind: "interface" as const, interfaceRevisionId: fixtureId.namedV1 },
|
||||||
|
cardinality: "exactly-one" as const,
|
||||||
|
primitives: ["resolve" as const],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
exportDefinition.dependencyPorts.push(port);
|
||||||
|
const binding = conformance(workspace, fixtureId.projectSummaryConformance).operationBindings[0].binding;
|
||||||
|
assert.ok(binding.kind === "package");
|
||||||
|
binding.dependencies.push({
|
||||||
|
portId: port.id,
|
||||||
|
binding: {
|
||||||
|
kind: "edge",
|
||||||
|
edgeTypeId: fixtureId.projectOwner,
|
||||||
|
projectionId: fixtureId.projectOwnerProjection,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const edge = conformance(workspace, fixtureId.projectOwnedConformance).privateAttachments.find(
|
||||||
|
(entry) => entry.id === fixtureId.projectOwner,
|
||||||
|
);
|
||||||
|
assert.ok(edge?.kind === "edge");
|
||||||
|
const endpoint = edge.endpoints.find((entry) => entry.projectionId === fixtureId.projectOwnerProjection)!;
|
||||||
|
expectIssue(workspace, "private-attachment-access");
|
||||||
|
|
||||||
|
// Publicity of the opposite projection does not grant this receiver access.
|
||||||
|
edge.endpoints.find((entry) => entry !== endpoint)!.publicTraversal = true;
|
||||||
|
expectIssue(workspace, "private-attachment-access");
|
||||||
|
endpoint.publicTraversal = true;
|
||||||
|
assert.deepEqual(validateWorkspaceRevision(workspace), []);
|
||||||
|
const compiled = compileWorkspaceRevision(workspace);
|
||||||
|
assert.ok(compiled.ok);
|
||||||
|
const plan = resolveOperationPlan(compiled.plan, fixtureId.project, fixtureId.summaryV1, fixtureId.summaryGet);
|
||||||
|
assert.ok(plan?.kind === "package");
|
||||||
|
assert.deepEqual(plan.dependencies.find((entry) => entry.port.id === port.id)?.port.requirement, port.requirement);
|
||||||
|
|
||||||
|
for (const primitive of ["connect", "disconnect", "watch-start", "watch-stop"] as const) {
|
||||||
|
const mutated = structuredClone(workspace);
|
||||||
|
const requirement = mutated.packageImports
|
||||||
|
.flatMap((pkg) => pkg.exports)
|
||||||
|
.find((entry) => entry.id === fixtureId.summaryGetExport)!
|
||||||
|
.dependencyPorts.find((entry) => entry.id === port.id)!.requirement;
|
||||||
|
assert.ok(requirement.kind === "edge");
|
||||||
|
requirement.primitives.push(primitive);
|
||||||
|
expectIssue(mutated, "private-attachment-access");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
test("native state and edge providers must match operation shape", () => {
|
test("native state and edge providers must match operation shape", () => {
|
||||||
const stateWorkspace = makeValidCapabilityWorkspace();
|
const stateWorkspace = makeValidCapabilityWorkspace();
|
||||||
const state = conformance(stateWorkspace, fixtureId.projectNamedConformance).operationBindings[0]!.binding;
|
const state = conformance(stateWorkspace, fixtureId.projectNamedConformance).operationBindings[0]!.binding;
|
||||||
|
|||||||
@@ -5,9 +5,90 @@ import os from "node:os";
|
|||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import { promisify } from "node:util";
|
import { promisify } from "node:util";
|
||||||
import { execFile as callback } from "node:child_process";
|
import { execFile as callback } from "node:child_process";
|
||||||
import { planPinUpgrades, applyPinUpgrades, type UpgradeEffects } from "../src/capability-language/pin-upgrades.js";
|
import {
|
||||||
|
planPinUpgrades,
|
||||||
|
applyPinUpgrades,
|
||||||
|
discoverUpgradeSpec,
|
||||||
|
reviewUpgradeCandidate,
|
||||||
|
type UpgradeEffects,
|
||||||
|
} from "../src/capability-language/pin-upgrades.js";
|
||||||
|
import { capabilityId } from "../src/capability-model/index.js";
|
||||||
|
import { makeValidCapabilityWorkspace } from "./fixtures/capability-model.js";
|
||||||
const execFile = promisify(callback);
|
const execFile = promisify(callback);
|
||||||
|
|
||||||
|
test("execution pin upgrades accept unchanged shared attachments without legacy migration planning", async (context) => {
|
||||||
|
const artifact = await fs.mkdtemp(path.join(os.tmpdir(), "qx-upgrade-execution-review-"));
|
||||||
|
context.after(() => fs.rm(artifact, { recursive: true, force: true }));
|
||||||
|
await fs.writeFile(path.join(artifact, "execution-plan.json"), "{}");
|
||||||
|
const baseline = makeValidCapabilityWorkspace();
|
||||||
|
assert.ok(baseline.sharedAttachments.length);
|
||||||
|
const candidate = structuredClone(baseline);
|
||||||
|
candidate.sourceRootCommit = "f".repeat(40);
|
||||||
|
const { filename, review } = await reviewUpgradeCandidate({ artifact, baseline, candidate });
|
||||||
|
assert.equal(filename, "semantic-review.json");
|
||||||
|
assert.equal(review.checkerVersion, "quixos-semantic-review-v1");
|
||||||
|
assert.deepEqual(review.blockers, []);
|
||||||
|
assert.equal("migrationRequired" in review, false);
|
||||||
|
assert.equal("runtimeActions" in review, false);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("execution pin upgrades require exact semantic-major receipts and reject foreign workspaces", async (context) => {
|
||||||
|
const artifact = await fs.mkdtemp(path.join(os.tmpdir(), "qx-upgrade-semantic-review-"));
|
||||||
|
context.after(() => fs.rm(artifact, { recursive: true, force: true }));
|
||||||
|
await fs.writeFile(path.join(artifact, "execution-plan.json"), "{}");
|
||||||
|
const baseline = makeValidCapabilityWorkspace();
|
||||||
|
baseline.conformances[0]!.id = capabilityId.conformance("conformance:project:named");
|
||||||
|
const candidate = structuredClone(baseline);
|
||||||
|
candidate.conformances[0]!.semanticMajor = 2;
|
||||||
|
const { review } = await reviewUpgradeCandidate({ artifact, baseline, candidate });
|
||||||
|
assert.equal(review.reviews.length, 1);
|
||||||
|
assert.equal(review.reviews[0]!.accepted, false);
|
||||||
|
assert.match(review.blockers[0]!, /Semantic-major review required/);
|
||||||
|
const receipt = {
|
||||||
|
requirementDigest: review.reviews[0]!.requirementDigest,
|
||||||
|
decision: "accepted-unchanged" as const,
|
||||||
|
rationale: "Reviewed the consumer against the provider's unchanged label behavior",
|
||||||
|
agentId: "upgrade-fixture-agent",
|
||||||
|
};
|
||||||
|
assert.deepEqual(
|
||||||
|
(await reviewUpgradeCandidate({ artifact, baseline, candidate, reviews: [receipt] })).review.blockers,
|
||||||
|
[],
|
||||||
|
);
|
||||||
|
candidate.packageImports[0]!.source.commit = "f".repeat(40);
|
||||||
|
assert.equal(
|
||||||
|
(await reviewUpgradeCandidate({ artifact, baseline, candidate, reviews: [receipt] })).review.reviews[0]!.accepted,
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
candidate.workspaceId = capabilityId.workspace("workspace:foreign");
|
||||||
|
await assert.rejects(() => reviewUpgradeCandidate({ artifact, baseline, candidate }), /different workspace/);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("nonexecution pin upgrades retain their evolution checks", async (context) => {
|
||||||
|
const artifact = await fs.mkdtemp(path.join(os.tmpdir(), "qx-upgrade-evolution-review-"));
|
||||||
|
context.after(() => fs.rm(artifact, { recursive: true, force: true }));
|
||||||
|
const baseline = makeValidCapabilityWorkspace();
|
||||||
|
const { filename, review } = await reviewUpgradeCandidate({
|
||||||
|
artifact,
|
||||||
|
baseline,
|
||||||
|
candidate: structuredClone(baseline),
|
||||||
|
});
|
||||||
|
assert.equal(filename, "evolution.json");
|
||||||
|
assert.equal(review.checkerVersion, "quixos-evolution-v1");
|
||||||
|
assert.ok(review.blockers.some((message) => message.includes("legacy workspace-shared attachments")));
|
||||||
|
assert.equal("migrationRequired" in review, true);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("unexpected artifact access failures do not select nonexecution checks", async (context) => {
|
||||||
|
const directory = await fs.mkdtemp(path.join(os.tmpdir(), "qx-upgrade-review-failure-"));
|
||||||
|
context.after(() => fs.rm(directory, { recursive: true, force: true }));
|
||||||
|
const artifact = path.join(directory, "not-a-directory");
|
||||||
|
await fs.writeFile(artifact, "not an artifact");
|
||||||
|
const candidate = makeValidCapabilityWorkspace();
|
||||||
|
await assert.rejects(() => reviewUpgradeCandidate({ artifact, baseline: candidate, candidate }), {
|
||||||
|
code: "ENOTDIR",
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
test(
|
test(
|
||||||
"real jj snapshots and immutable Git publication propagate a changed interface into the root",
|
"real jj snapshots and immutable Git publication propagate a changed interface into the root",
|
||||||
{ skip: !process.env.QX_CHECK_GENERATOR },
|
{ skip: !process.env.QX_CHECK_GENERATOR },
|
||||||
@@ -73,6 +154,21 @@ test(
|
|||||||
await run(workbench, "git", ["--git-dir", path.join(workbench, "remotes/named.git"), "show-ref"]),
|
await run(workbench, "git", ["--git-dir", path.join(workbench, "remotes/named.git"), "show-ref"]),
|
||||||
new RegExp(commit),
|
new RegExp(commit),
|
||||||
);
|
);
|
||||||
|
assert.equal(graph.resources[0].directory, "resources/Named");
|
||||||
|
assert.equal(graph.directResources[0].directory, "resources/Named");
|
||||||
|
// A retained workbench can move without keeping its original absolute path
|
||||||
|
// alive. Recovery journals remain bound to their original writer/root.
|
||||||
|
const relocated = `${workbench}-relocated`;
|
||||||
|
context.after(() => fs.rm(relocated, { recursive: true, force: true }));
|
||||||
|
await fs.cp(workbench, relocated, { recursive: true });
|
||||||
|
const discovered = await discoverUpgradeSpec(relocated);
|
||||||
|
assert.equal(discovered.nodes[1]!.directory, "resources/Named");
|
||||||
|
const relocatedPlan = await planPinUpgrades(relocated, { ...discovered, bootstrap: true });
|
||||||
|
assert.equal(relocatedPlan.workbench, relocated);
|
||||||
|
assert.deepEqual(
|
||||||
|
relocatedPlan.nodes.map((node) => node.directory),
|
||||||
|
["resources/Named", "root"],
|
||||||
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -6,10 +6,64 @@ import {
|
|||||||
compileExecutionPlan,
|
compileExecutionPlan,
|
||||||
hexDigest,
|
hexDigest,
|
||||||
inspectJavaScriptSurface,
|
inspectJavaScriptSurface,
|
||||||
|
inspectRestrictedImplementation,
|
||||||
|
restrictedSDKIdentity,
|
||||||
|
restrictedSDKPath,
|
||||||
|
type ArtifactImplementation,
|
||||||
reportExecutionPlacement,
|
reportExecutionPlacement,
|
||||||
type ExecutionInstallation,
|
type ExecutionInstallation,
|
||||||
} from "../src/execution-world/index.js";
|
} from "../src/execution-world/index.js";
|
||||||
|
|
||||||
|
test("restricted SDK identity ignores build comments and positions, preserving executable syntax", () => {
|
||||||
|
const source = 'export function value() { return ("hello"); }';
|
||||||
|
const x86 = "// /nix/store/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-core/dist/portable.js\n" + source;
|
||||||
|
const arm = "// /nix/store/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb-core/dist/portable.js\n\n" + source;
|
||||||
|
assert.equal(restrictedSDKIdentity(x86), restrictedSDKIdentity(arm));
|
||||||
|
for (const changed of [
|
||||||
|
'export function value() { return ("goodbye"); }',
|
||||||
|
'export function value() { return\n("hello"); }',
|
||||||
|
'export function value() { fetch("hello"); }',
|
||||||
|
'import x from "node:fs"; ' + source,
|
||||||
|
'export function value() { return "/nix/store/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-core"; }',
|
||||||
|
])
|
||||||
|
assert.notEqual(restrictedSDKIdentity(source), restrictedSDKIdentity(changed));
|
||||||
|
assert.notEqual(restrictedSDKIdentity('"use strict";'), restrictedSDKIdentity('"use\\x20strict";'));
|
||||||
|
assert.notEqual(restrictedSDKIdentity('const value="// comment";'), restrictedSDKIdentity('const value="";'));
|
||||||
|
assert.throws(() => restrictedSDKIdentity("const ???"));
|
||||||
|
assert.throws(() => restrictedSDKIdentity(" ".repeat(2 * 1024 * 1024 + 1)), /ANALYSIS_LIMIT/);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("restricted admission accepts the same SDK syntax and rejects changed SDK behavior", async () => {
|
||||||
|
const source = "export const registry = {};";
|
||||||
|
const sdk = 'export const value = "trusted";';
|
||||||
|
const implementation: ArtifactImplementation = {
|
||||||
|
id: "restricted",
|
||||||
|
target: "server",
|
||||||
|
compatibility: "quixos-restricted-module-v1",
|
||||||
|
path: "module.mjs",
|
||||||
|
ports: "quixos-transaction-ports-v1",
|
||||||
|
registryExport: "registry",
|
||||||
|
exports: ["value"],
|
||||||
|
contentDigest: "a".repeat(64),
|
||||||
|
files: [
|
||||||
|
{ path: "module.mjs", digest: "b".repeat(64), bytes: source.length, mediaType: "text/javascript" },
|
||||||
|
{ path: restrictedSDKPath, digest: "c".repeat(64), bytes: sdk.length, mediaType: "text/javascript" },
|
||||||
|
],
|
||||||
|
};
|
||||||
|
const check = (candidateSDK: string) => {
|
||||||
|
implementation.files[1]!.bytes = Buffer.byteLength(candidateSDK);
|
||||||
|
return inspectRestrictedImplementation(
|
||||||
|
"package:test@1",
|
||||||
|
implementation,
|
||||||
|
async (_revision, path) => Buffer.from(path === restrictedSDKPath ? candidateSDK : source),
|
||||||
|
restrictedSDKIdentity(sdk),
|
||||||
|
);
|
||||||
|
};
|
||||||
|
assert.deepEqual(await check("// a different build path\n" + sdk), []);
|
||||||
|
assert.equal((await check('export const value = "untrusted";'))[0]?.code, "RESTRICTED_SDK_UNSUPPORTED");
|
||||||
|
assert.equal((await check("export const ???"))[0]?.code, "RESTRICTED_SDK_UNSUPPORTED");
|
||||||
|
});
|
||||||
|
|
||||||
test("compiled-source inspection finds authority imports and ambient facilities without executing code", () => {
|
test("compiled-source inspection finds authority imports and ambient facilities without executing code", () => {
|
||||||
const surface = inspectJavaScriptSurface(
|
const surface = inspectJavaScriptSurface(
|
||||||
`
|
`
|
||||||
|
|||||||
Reference in New Issue
Block a user