CI / verify (pull_request) Successful in 58s
CI / infrastructure-smoke (pull_request) Successful in 35s
CI / migration-smoke (pull_request) Successful in 1m53s
CI / image-build (pull_request) Successful in 30s
CI / deploy-smoke (same-origin) (pull_request) Successful in 50s
CI / deploy-smoke (split) (pull_request) Successful in 1m32s
Every Module Package v1 now declares the module's license and carries its text. packageFormat stays 1; pre-ADR-0051 metadata fails closed. - Contracts: ekklesia.package.json requires an SPDX `license` expression, validated with spdx-expression-parse, with UNLICENSED and non-expressions refused. The `files` list must hold exactly one non-empty root LICENSE. The package contracts move to the @ekklesia/contracts/module-package subpath, so the SPDX parser and its data (spdx-exceptions and spdx-license-ids ship no licence files) never reach a module bundle through the SDK's re-export of the contracts root. - Packager: reads the source package.json's string SPDX declaration and never invents one. It requires an explicit --license-file (a non-empty regular file, no symlink, no parent search, no download) and copies its bytes unchanged to LICENSE, listed with size and SHA-256 and covered by the archive digest. THIRD_PARTY_NOTICES stays third-party only, and bundled Ekklesia code stays in `incorporates`. - Verifier: rejects missing or invalid license metadata, and a missing, unlisted, duplicated, or corrupted LICENSE, through the schema and the existing strict inventory. - Template: packaged as AGPL-3.0-or-later with the repository's canonical LICENSE, passed explicitly (Dockerfile, smoke, docs). Packing it twice gives byte-identical archives. Started by Codex; reviewed and completed in Claude Code (empty license-text refusal, schema non-empty LICENSE, symlink and empty-file tests). ADR 0051 is Accepted. Co-Authored-By: Claude Opus 5.5 <[email protected]>
226 lines
7.9 KiB
TypeScript
226 lines
7.9 KiB
TypeScript
import { mkdir, mkdtemp, realpath, rm, symlink, writeFile } from "node:fs/promises";
|
|
import { tmpdir } from "node:os";
|
|
import path from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
|
|
/**
|
|
* Generated module fixtures for the packager's tests: a built module directory in a temporary
|
|
* location, whose `node_modules` links to the real Module SDK and Drizzle this package depends on.
|
|
* Everything a development module directory holds is there, including what must never ship
|
|
* (`src/`, `tests/`, declarations, source maps, `workspace:` ranges), so a test can prove the
|
|
* packager leaves it out.
|
|
*/
|
|
|
|
const packageRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..", "..");
|
|
|
|
export interface FakePackage {
|
|
readonly name: string;
|
|
readonly version?: string;
|
|
readonly packageJson?: Record<string, unknown>;
|
|
/** Files relative to the fake package's root. */
|
|
readonly files?: Record<string, string | Uint8Array>;
|
|
}
|
|
|
|
export interface FixtureModuleOptions {
|
|
readonly databaseAbi?: 1;
|
|
readonly id?: string;
|
|
readonly license?: unknown;
|
|
readonly licenseText?: string | Uint8Array;
|
|
readonly version?: string;
|
|
readonly serverSource?: string;
|
|
readonly withModuleDatabase?: boolean;
|
|
readonly withSchema?: boolean;
|
|
readonly fakePackages?: readonly FakePackage[];
|
|
readonly manifest?: (manifest: Record<string, unknown>) => Record<string, unknown>;
|
|
}
|
|
|
|
const temporaryDirectories: string[] = [];
|
|
|
|
export async function cleanupFixtures(): Promise<void> {
|
|
await Promise.all(
|
|
temporaryDirectories
|
|
.splice(0)
|
|
.map((directory) => rm(directory, { force: true, recursive: true })),
|
|
);
|
|
}
|
|
|
|
export async function scratchDirectory(prefix = "ekklesia-pack-"): Promise<string> {
|
|
const directory = await realpath(await mkdtemp(path.join(tmpdir(), prefix)));
|
|
temporaryDirectories.push(directory);
|
|
return directory;
|
|
}
|
|
|
|
async function write(file: string, contents: string | Uint8Array): Promise<void> {
|
|
await mkdir(path.dirname(file), { recursive: true });
|
|
await writeFile(file, contents);
|
|
}
|
|
|
|
const defaultServer = (
|
|
id: string,
|
|
version: string,
|
|
databaseAbi?: 1,
|
|
) => `import { defineModuleRuntime } from "@ekklesia/module-sdk";
|
|
export default defineModuleRuntime({ ${databaseAbi === 1 ? "database: { abi: 1 }, " : ""}id: ${JSON.stringify(id)}, version: ${JSON.stringify(version)}, register() {} });
|
|
`;
|
|
|
|
const schemaSource = (id: string, databaseAbi?: 1) => `${
|
|
databaseAbi === 1
|
|
? 'import { moduleDrizzleSchemaMetadata } from "@ekklesia/module-database/drizzle";'
|
|
: 'import { defineModuleSchema } from "@ekklesia/module-sdk";'
|
|
}
|
|
import { createModuleTable } from "@ekklesia/module-sdk";
|
|
import { text, uuid } from "drizzle-orm/pg-core";
|
|
export const records = createModuleTable(${JSON.stringify(id)})("records", {
|
|
id: uuid("id").primaryKey(),
|
|
value: text("value").notNull(),
|
|
});
|
|
export default ${
|
|
databaseAbi === 1
|
|
? `moduleDrizzleSchemaMetadata(${JSON.stringify(id)}, { records })`
|
|
: `defineModuleSchema({ moduleId: ${JSON.stringify(id)}, tables: { records } })`
|
|
};
|
|
`;
|
|
|
|
export async function fixtureModule(options: FixtureModuleOptions = {}): Promise<string> {
|
|
const id = options.id ?? "example";
|
|
const version = options.version ?? "0.1.0";
|
|
const root = await scratchDirectory("ekklesia-pack-fixture-");
|
|
const moduleDirectory = path.join(root, id);
|
|
const tableName = `${id.replaceAll("-", "_")}_records`;
|
|
const usesModuleDatabase = options.withModuleDatabase || options.databaseAbi === 1;
|
|
|
|
const baseManifest: Record<string, unknown> = {
|
|
manifestVersion: 8,
|
|
id,
|
|
name: `${id} module`,
|
|
version,
|
|
compatibility: { platform: "^0.1.0", moduleSdk: "^0.1.0" },
|
|
...(options.databaseAbi === 1 ? { database: { abi: 1 } } : {}),
|
|
capabilities: [],
|
|
permissions: [],
|
|
entrypoints: {
|
|
server: "./dist/server/index.js",
|
|
...(options.withSchema ? { schema: "./dist/schema/index.js" } : {}),
|
|
migrations: "./drizzle",
|
|
},
|
|
};
|
|
const manifest = options.manifest ? options.manifest(baseManifest) : baseManifest;
|
|
|
|
await write(
|
|
path.join(moduleDirectory, "ekklesia.module.json"),
|
|
`${JSON.stringify(manifest, null, 2)}\n`,
|
|
);
|
|
await write(
|
|
path.join(moduleDirectory, "package.json"),
|
|
`${JSON.stringify(
|
|
{
|
|
name: `@test/module-${id}`,
|
|
version,
|
|
license: Object.hasOwn(options, "license") ? options.license : "MIT",
|
|
private: true,
|
|
type: "module",
|
|
scripts: { build: "tsc" },
|
|
dependencies: {
|
|
"@ekklesia/module-sdk": "workspace:*",
|
|
...(usesModuleDatabase ? { "@ekklesia/module-database": "workspace:*" } : {}),
|
|
"drizzle-orm": "0.45.2",
|
|
},
|
|
devDependencies: { typescript: "7.0.2" },
|
|
exports: { ".": "./dist/server/index.js" },
|
|
ekklesia: { layer: "module" },
|
|
},
|
|
null,
|
|
2,
|
|
)}\n`,
|
|
);
|
|
await write(
|
|
path.join(moduleDirectory, "LICENSE"),
|
|
options.licenseText ?? "MIT License\n\nCopyright (c) 2026 Example Module\n",
|
|
);
|
|
await write(
|
|
path.join(moduleDirectory, "dist/server/index.js"),
|
|
options.serverSource ?? defaultServer(id, version, options.databaseAbi),
|
|
);
|
|
await write(path.join(moduleDirectory, "dist/server/index.js.map"), '{"version":3}\n');
|
|
await write(path.join(moduleDirectory, "dist/server/index.d.ts"), "export {};\n");
|
|
if (options.withSchema) {
|
|
await write(
|
|
path.join(moduleDirectory, "dist/schema/index.js"),
|
|
schemaSource(id, options.databaseAbi),
|
|
);
|
|
}
|
|
await write(path.join(moduleDirectory, "src/server/index.ts"), "export {};\n");
|
|
await write(path.join(moduleDirectory, "tests/server.test.ts"), "export {};\n");
|
|
await write(path.join(moduleDirectory, "README.md"), "# Development notes\n");
|
|
|
|
await write(
|
|
path.join(moduleDirectory, "drizzle/0000_initial.sql"),
|
|
`CREATE TABLE "${tableName}" ("id" uuid PRIMARY KEY NOT NULL, "value" text NOT NULL);\n`,
|
|
);
|
|
await write(
|
|
path.join(moduleDirectory, "drizzle/meta/_journal.json"),
|
|
JSON.stringify({
|
|
version: "7",
|
|
dialect: "postgresql",
|
|
entries: [
|
|
{ idx: 0, version: "7", when: 1_700_000_000_000, tag: "0000_initial", breakpoints: true },
|
|
],
|
|
}),
|
|
);
|
|
await write(
|
|
path.join(moduleDirectory, "drizzle/meta/_ekklesia.json"),
|
|
JSON.stringify({
|
|
version: 1,
|
|
moduleId: id,
|
|
entries: [{ tag: "0000_initial", destructive: { mode: "none" } }],
|
|
}),
|
|
);
|
|
await write(
|
|
path.join(moduleDirectory, "drizzle/meta/0000_snapshot.json"),
|
|
JSON.stringify({
|
|
version: "7",
|
|
dialect: "postgresql",
|
|
id: "10000000-0000-4000-8000-000000000001",
|
|
prevId: "00000000-0000-0000-0000-000000000000",
|
|
}),
|
|
);
|
|
|
|
// The module's dependencies, as a workspace links them: the real packages this package depends on.
|
|
const modules = path.join(moduleDirectory, "node_modules");
|
|
await mkdir(path.join(modules, "@ekklesia"), { recursive: true });
|
|
await symlink(
|
|
await realpath(path.join(packageRoot, "node_modules", "@ekklesia", "module-sdk")),
|
|
path.join(modules, "@ekklesia", "module-sdk"),
|
|
);
|
|
if (usesModuleDatabase) {
|
|
await symlink(
|
|
await realpath(path.join(packageRoot, "node_modules", "@ekklesia", "module-database")),
|
|
path.join(modules, "@ekklesia", "module-database"),
|
|
);
|
|
}
|
|
await symlink(
|
|
await realpath(path.join(packageRoot, "node_modules", "drizzle-orm")),
|
|
path.join(modules, "drizzle-orm"),
|
|
);
|
|
for (const fake of options.fakePackages ?? []) {
|
|
const fakeRoot = path.join(modules, ...fake.name.split("/"));
|
|
await write(
|
|
path.join(fakeRoot, "package.json"),
|
|
JSON.stringify({
|
|
name: fake.name,
|
|
version: fake.version ?? "1.0.0",
|
|
type: "module",
|
|
main: "index.js",
|
|
license: "MIT",
|
|
...fake.packageJson,
|
|
}),
|
|
);
|
|
for (const [relative, contents] of Object.entries(fake.files ?? {})) {
|
|
await write(path.join(fakeRoot, relative), contents);
|
|
}
|
|
}
|
|
return moduleDirectory;
|
|
}
|
|
|
|
export const SOURCE_REVISION = "86ae907f59458508e3277666cdd214f5bd7c1078";
|