feat: Ekklesia Module Package v1, the canonical packager and verifier (ADR 0049)
CI / verify (pull_request) Successful in 57s
CI / infrastructure-smoke (pull_request) Successful in 35s
CI / migration-smoke (pull_request) Successful in 1m42s
CI / image-build (pull_request) Successful in 29s
CI / deploy-smoke (same-origin) (pull_request) Successful in 51s
CI / deploy-smoke (split) (pull_request) Failing after 54s
CI / verify (pull_request) Successful in 57s
CI / infrastructure-smoke (pull_request) Successful in 35s
CI / migration-smoke (pull_request) Successful in 1m42s
CI / image-build (pull_request) Successful in 29s
CI / deploy-smoke (same-origin) (pull_request) Successful in 51s
CI / deploy-smoke (split) (pull_request) Failing after 54s
A separately versioned module is now distributed as one deterministic .tar.gz and its SHA-256, produced by an Ekklesia-owned packager and checked by Core before anything is installed. This slice implements the portable `any` target, with the module template as the end-to-end proof. ADR 0049 is accepted. @ekklesia/contracts: the Module Package v1 contract. The strict ekklesia.package.json schema (packageFormat 1, identity, target, runtime, provenance, incorporated Ekklesia packages, strict transitional facts, an exact byte-wise-sorted file list with size and SHA-256), target names, and the generated runtime package.json. @ekklesia/module-pack (new, tooling): `ekklesia-pack-module --module <dir> --target any --out <dir> --source-revision <commit>`. - Bundles server, schema, and jobs with esbuild, SDK, contracts, and Drizzle included; only Node built-ins remain imports. Any warning, unresolved import, external dependency, or native or platform-specific package fails. - Copies browser artifacts as built, after proving them current, and the migrations; generates package.json and ekklesia.package.json; never ships src, tests, declarations, source maps, or workspace ranges. - THIRD_PARTY_NOTICES: every third-party package traced from the bundles' own inputs, credited once with its declared licence and every licence, copying, copyright, and notice file it ships. A missing licence fails; a missing text fails unless its standard text is complete without copyright lines (Apache-2.0, vendored, needed by drizzle-orm). - Deterministic ustar and gzip: sorted paths, uid/gid 0, empty names, mtime 0, 0755/0644, no links. Byte-identical across runs and machines. - Writes only the archive and its .sha256; never deploys, links, or installs, so the workspace's install state is untouched. Core: verifyModulePackage and `verify-module-package.js <archive> [--sha256 | --sha256-file] [--extract-to <new dir>]`. Reads the archive in memory and refuses links, special entries, setuid/setgid/sticky modes, unsafe or escaping paths, and a second top-level directory; checks metadata, every file, identity, target, Node.js range, SDK, and the transitional Drizzle agreement; runs the platform's module and migration discovery; loads the backend once in a forked process with an empty environment; only then extracts, with normalized modes, into a new directory. Errors are sanitized. @ekklesia/module-ui-build: analyzeModuleUi reports each artifact's inputs and whether the built file is current. The nested stylesheet build now works from the module directory, so artifacts no longer depend on the caller's working directory. The split deploy smoke builds the package with the canonical packager (scripts/lib/build-module-package.Dockerfile replaces the test-only pnpm deploy packaging), verifies it with the same generic image, installs the verified tree, removes it, and reinstalls the exact same archive. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
45d6506c10
commit
35ef31df9f
@@ -0,0 +1,89 @@
|
||||
// The isolated, short-lived validation process of Module Package v1 verification (ADR 0049).
|
||||
//
|
||||
// The verifier forks this file with an empty environment and one JSON argument naming a candidate
|
||||
// module's backend entrypoints. It imports each one, so a package whose code cannot load, or whose
|
||||
// bundle still reaches for a dependency it does not contain, is refused before it is ever installed.
|
||||
// Whatever the module's top-level code does happens here, in a process with no database URL, no
|
||||
// secret, and no platform state, and that is discarded as soon as it reports.
|
||||
//
|
||||
// The result travels over the IPC channel, never stdout, so nothing a module prints can forge it.
|
||||
// It carries fixed role and reason names only: never an error message, a path, or module output.
|
||||
//
|
||||
// Written as erasable TypeScript with no relative imports, so Node can run the source file directly
|
||||
// in tests as well as the compiled file in the image.
|
||||
import { pathToFileURL } from "node:url";
|
||||
import { parseModuleRuntimeDefinition, parseModuleSchemaDefinition } from "@ekklesia/contracts";
|
||||
|
||||
interface ProbeRequest {
|
||||
readonly moduleId: string;
|
||||
readonly version: string;
|
||||
readonly entrypoints: Readonly<Record<string, string>>;
|
||||
}
|
||||
|
||||
interface ProbeFailure {
|
||||
readonly role: string;
|
||||
readonly reason: "export" | "identity" | "load";
|
||||
}
|
||||
|
||||
function defaultExport(namespace: unknown): unknown {
|
||||
return typeof namespace === "object" && namespace !== null && "default" in namespace
|
||||
? (namespace as { default: unknown }).default
|
||||
: undefined;
|
||||
}
|
||||
|
||||
async function probe(request: ProbeRequest): Promise<readonly ProbeFailure[]> {
|
||||
const failures: ProbeFailure[] = [];
|
||||
for (const role of Object.keys(request.entrypoints).sort()) {
|
||||
const entrypoint = request.entrypoints[role];
|
||||
if (entrypoint === undefined) {
|
||||
continue;
|
||||
}
|
||||
let namespace: unknown;
|
||||
try {
|
||||
namespace = await import(pathToFileURL(entrypoint).href);
|
||||
} catch {
|
||||
failures.push({ reason: "load", role });
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
if (role === "server") {
|
||||
const definition = parseModuleRuntimeDefinition(defaultExport(namespace));
|
||||
if (definition.id !== request.moduleId || definition.version !== request.version) {
|
||||
failures.push({ reason: "identity", role });
|
||||
}
|
||||
} else if (role === "schema") {
|
||||
const definition = parseModuleSchemaDefinition(defaultExport(namespace));
|
||||
if (definition.moduleId !== request.moduleId) {
|
||||
failures.push({ reason: "identity", role });
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
failures.push({ reason: "export", role });
|
||||
}
|
||||
}
|
||||
return failures;
|
||||
}
|
||||
|
||||
function report(message: unknown): void {
|
||||
if (typeof process.send !== "function") {
|
||||
process.exitCode = 2;
|
||||
return;
|
||||
}
|
||||
process.send(message, () => {
|
||||
// A module may leave timers or handles behind; the probe's work is done either way.
|
||||
process.exit(0);
|
||||
});
|
||||
}
|
||||
|
||||
let request: ProbeRequest | undefined;
|
||||
try {
|
||||
request = JSON.parse(process.argv[2] ?? "") as ProbeRequest;
|
||||
} catch {
|
||||
report({ failures: [{ reason: "load", role: "request" }] });
|
||||
}
|
||||
if (request !== undefined) {
|
||||
probe(request).then(
|
||||
(failures) => report({ failures }),
|
||||
() => report({ failures: [{ reason: "load", role: "probe" }] }),
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user