cultcache-ts 0.15.0; cultnet-ts and cultmesh-ts declare ^0.15.0; a check builds the tagged releases a declared range admits

cultnet-ts imports readSingleFileStore and cultmesh-ts imports schemaIdentityOf and SchemaConflictError, none of which cultcache-ts 0.14.0 exports. The new check builds each tagged release a declared range admits and requires every runtime name the dependent imports to be an export of it.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-10-03 01:28:48 +02:00
commit 4f76bb9391
9 changed files with 178 additions and 7 deletions

6
package-lock.json generated
View file

@ -1184,7 +1184,7 @@
},
"packages/cultcache-ts": {
"name": "@gamecult/cultcache-ts",
"version": "0.14.0",
"version": "0.15.0",
"license": "MIT",
"dependencies": {
"@msgpack/msgpack": "^3.1.3",
@ -1217,7 +1217,7 @@
"version": "0.1.1",
"license": "MIT",
"dependencies": {
"@gamecult/cultcache-ts": "^0.14.0",
"@gamecult/cultcache-ts": "^0.15.0",
"@msgpack/msgpack": "^3.1.2",
"cultnet-ts": "^0.2.0",
"koffi": "3.3.0"
@ -1235,7 +1235,7 @@
"version": "0.2.0",
"license": "MIT",
"dependencies": {
"@gamecult/cultcache-ts": "^0.14.0",
"@gamecult/cultcache-ts": "^0.15.0",
"@msgpack/msgpack": "^3.1.3",
"ajv": "^8.17.1"
},

View file

@ -10,7 +10,7 @@
"scripts": {
"build:ts": "node scripts/run-typescript-workspaces.mjs build",
"test:ts": "node scripts/run-typescript-workspaces.mjs test",
"test:pack:ts": "node scripts/test-typescript-package-closure.mjs",
"test:pack:ts": "node scripts/test-typescript-package-closure.mjs && node scripts/test-declared-dependency-ranges.mjs",
"test:eve-browser-network": "node scripts/verify-eve-browser-network.mjs"
},
"devDependencies": {

View file

@ -0,0 +1,14 @@
# Changelog
## 0.15.0
### Breaking
- A single-file store refuses a zero-byte file as `StoreUnreadableError`; only a path with nothing at it is an empty store. A header this runtime does not read is refused, and the refusal echoes the header only as `cultcache.store.v<digits>`.
- A dangling symbolic link at the store path is an I/O error with code `ENOENT`, not an empty store.
### Added
- `readSingleFileStore(path)`, the one synchronous reader of a single-file store, for consumers that must read a store file rather than decode it themselves. `pullAll`, `push`, `delete` and `pushAll` ask the same reader.
- `StoreUnreadableError` for a store file this runtime cannot read, `SchemaConflictError` for a write the catalog cannot describe, and `schemaIdentityOf`.
- A soft `pushAll` writes only where nothing is at the path, leaves a store it can read byte for byte, and refuses what the reader refuses.

View file

@ -1,6 +1,6 @@
{
"name": "@gamecult/cultcache-ts",
"version": "0.14.0",
"version": "0.15.0",
"description": "CultCache-style typed persistence for TypeScript with schema-backed polymorphic MessagePack storage.",
"main": "dist/index.js",
"types": "dist/index.d.ts",

View file

@ -0,0 +1,5 @@
# Changelog
## Unreleased
- Depends on `@gamecult/cultcache-ts ^0.15.0`: it imports `schemaIdentityOf` and `SchemaConflictError`, which 0.14.x does not export.

View file

@ -44,7 +44,7 @@
},
"dependencies": {
"@msgpack/msgpack": "^3.1.2",
"@gamecult/cultcache-ts": "^0.14.0",
"@gamecult/cultcache-ts": "^0.15.0",
"cultnet-ts": "^0.2.0",
"koffi": "3.3.0"
},

View file

@ -0,0 +1,5 @@
# Changelog
## Unreleased
- Depends on `@gamecult/cultcache-ts ^0.15.0`: the Idunn runtime authority reader calls `readSingleFileStore`, which 0.14.x does not export. An absent authority file is now a plain `Error` without a code.

View file

@ -63,7 +63,7 @@
"dependencies": {
"@msgpack/msgpack": "^3.1.3",
"ajv": "^8.17.1",
"@gamecult/cultcache-ts": "^0.14.0"
"@gamecult/cultcache-ts": "^0.15.0"
},
"devDependencies": {
"@types/node": "^24.0.0",

View file

@ -0,0 +1,147 @@
// Observes the dependency ranges the TypeScript workspace packages declare, not the workspace symlinks that satisfy them.
//
// Every workspace test resolves a sibling package through node_modules/<name> -> packages/<dir>, so a package that starts
// importing a new export from a sibling passes whatever range it declares. A consumer outside the workspace installs the
// newest published version the range admits. This check builds every tagged release (`<dir>-v<version>`) that a declared
// range admits and requires each runtime value the dependent imports from that package to be an export of it.
//
// node scripts/test-declared-dependency-ranges.mjs
//
// It needs the workspace installed (typescript at the repo root) and git with the release tags. A package whose range
// admits no tagged release other than the workspace's own passes, because nothing a consumer could install lacks the export.
// Namespace imports, default imports, type-only imports and subpath imports are not checked.
import assert from "node:assert/strict";
import { execFileSync } from "node:child_process";
import { existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync, symlinkSync } from "node:fs";
import { createRequire } from "node:module";
import { tmpdir } from "node:os";
import { dirname, join, resolve } from "node:path";
import { fileURLToPath } from "node:url";
const repoRoot = resolve(dirname(fileURLToPath(import.meta.url)), "..");
const rootRequire = createRequire(join(repoRoot, "package.json"));
const ts = rootRequire("typescript");
const semver = createRequire(join(npmRoot(), "package.json"))("semver");
function npmRoot() {
const cli = process.env.npm_execpath ?? join(dirname(process.execPath), "node_modules", "npm", "bin", "npm-cli.js");
return dirname(dirname(cli));
}
function readJson(path) {
return JSON.parse(readFileSync(path, "utf8"));
}
function git(...args) {
return execFileSync("git", args, { cwd: repoRoot, encoding: "utf8" });
}
// The runtime names `sourceText` imports from, or re-exports from, exactly `packageName`.
function importedNames(sourceText, packageName) {
const file = ts.createSourceFile("source.ts", sourceText, ts.ScriptTarget.Latest, true);
const names = new Set();
for (const statement of file.statements) {
const from = statement.moduleSpecifier;
if (!from || !ts.isStringLiteral(from) || from.text !== packageName) {
continue;
}
let clause;
if (ts.isImportDeclaration(statement) && statement.importClause && !statement.importClause.isTypeOnly) {
clause = statement.importClause.namedBindings;
} else if (ts.isExportDeclaration(statement) && !statement.isTypeOnly) {
clause = statement.exportClause;
}
if (clause && (ts.isNamedImports(clause) || ts.isNamedExports(clause))) {
for (const element of clause.elements) {
if (!element.isTypeOnly) {
names.add((element.propertyName ?? element.name).text);
}
}
}
}
return [...names].sort();
}
function sourceFiles(directory) {
return readdirSync(directory, { withFileTypes: true }).flatMap((entry) => {
const path = join(directory, entry.name);
if (entry.isDirectory()) {
return sourceFiles(path);
}
return entry.name.endsWith(".ts") && !entry.name.endsWith(".d.ts") ? [path] : [];
});
}
// Builds the package as the tag released it, in a scratch directory that borrows the workspace's node_modules.
function buildRelease(directory, tag, scratch) {
const archive = join(scratch, `${tag}.tar`);
git("archive", "--format=tar", "-o", archive, tag, `packages/${directory}`);
const extracted = join(scratch, tag);
mkdirSync(extracted);
execFileSync("tar", ["-xf", archive, "-C", extracted]);
symlinkSync(join(repoRoot, "node_modules"), join(extracted, "node_modules"), "junction");
const packageRoot = join(extracted, "packages", directory);
execFileSync(process.execPath, [rootRequire.resolve("typescript/bin/tsc"), "-p", "tsconfig.json"], { cwd: packageRoot, stdio: "inherit" });
return rootRequire(join(packageRoot, "dist", "index.js"));
}
const workspaces = readJson(join(repoRoot, "package.json")).workspaces.map((directory) => {
const manifest = readJson(join(repoRoot, directory, "package.json"));
return { directory: directory.replace(/^packages\//u, ""), root: join(repoRoot, directory), manifest };
});
const byName = new Map(workspaces.map((workspace) => [workspace.manifest.name, workspace]));
const tags = git("tag", "-l").split(/\r?\n/u).filter(Boolean);
const scratch = mkdtempSync(join(tmpdir(), "cultlib-declared-ranges-"));
const built = new Map();
let checked = 0;
try {
for (const dependent of workspaces) {
for (const [name, range] of Object.entries(dependent.manifest.dependencies ?? {})) {
const dependency = byName.get(name);
if (!dependency) {
continue;
}
assert.ok(
semver.satisfies(dependency.manifest.version, range),
`${dependent.manifest.name} declares ${name} ${range}, which excludes the workspace's own ${dependency.manifest.version}`,
);
const src = join(dependent.root, "src");
const imported = existsSync(src)
? [...new Set(sourceFiles(src).flatMap((file) => importedNames(readFileSync(file, "utf8"), name)))].sort()
: [];
const prefix = `${dependency.directory}-v`;
const admitted = tags.filter((tag) => {
const version = tag.startsWith(prefix) ? tag.slice(prefix.length) : undefined;
return version !== undefined && semver.valid(version) !== null && semver.satisfies(version, range) && version !== dependency.manifest.version;
});
for (const tag of admitted) {
if (!built.has(tag)) {
built.set(tag, buildRelease(dependency.directory, tag, scratch));
}
const exports = built.get(tag);
const missing = imported.filter((symbol) => !(symbol in exports));
assert.deepEqual(
missing,
[],
`${dependent.manifest.name} declares ${name} ${range}, which admits ${tag}, and ${tag} does not export ${missing.join(", ")}`,
);
}
checked += 1;
console.log(`${dependent.manifest.name} -> ${name} ${range}: ${imported.length} imported names, ${admitted.length} admitted tagged releases checked`);
}
}
assert.ok(checked > 0, "no workspace package declares a dependency on another workspace package");
console.log(`Declared dependency ranges: ${checked} checked`);
} finally {
rmSync(scratch, { recursive: true, force: true });
}