Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

feat(ci): walk engine dependency closure in check-storage-owner gate

Steven Enamakelad1b36c307c9
diff --git a/scripts/ci/__tests__/check-storage-owner.test.mjs b/scripts/ci/__tests__/check-storage-owner.test.mjs
new file mode 100644
index 0000000000..193837cb4d
--- /dev/null
+++ b/scripts/ci/__tests__/check-storage-owner.test.mjs
@@ -0,0 +1,268 @@
+/**
+ * Fixture-based self-tests for check-storage-owner.mjs
+ *
+ * Run with: node --test scripts/ci/__tests__/check-storage-owner.test.mjs
+ *
+ * Cargo metadata dep_kinds format:
+ * - Normal dep: { kind: "normal" } or absent (treated as normal by cargo)
+ * - Build dep: { kind: "build" }
+ * - Dev dep: { kind: "dev" }
+ */
+
+import { checkMetadata } from '../check-storage-owner.mjs';
+
+const ROOT = '/fake/repo';
+const TSD_MANIFEST = `${ROOT}/vendor/tinystoragedrivers/crates/tinystoragedrivers-sqlite/Cargo.toml`;
+const REGISTRY = 'registry+https://github.com/rust-lang/crates.io-index';
+const tsd_git = (tag) => `git+https://github.com/tinyhumansai/tinystoragedrivers?tag=${tag}#`;
+
+// ---------------------------------------------------------------------------
+// Helper builders
+// ---------------------------------------------------------------------------
+
+/** Path crate (first-party, source = null). */
+const pathPkg = (name, version, manifest, deps = []) => ({
+ id: `${name} ${version}`,
+ name,
+ version,
+ manifest_path: manifest,
+ source: null,
+ dependencies: deps,
+});
+
+/** Registry crate. */
+const regPkg = (name, version, manifest, deps = []) => ({
+ id: `${name} ${version} ${REGISTRY}`,
+ name,
+ version,
+ manifest_path: manifest,
+ source: REGISTRY,
+ dependencies: deps,
+});
+
+/** Normal dep_kinds entry. */
+const NORMAL = [{ kind: 'normal' }];
+
+/** Resolve node for a path crate. */
+const pathNode = (name, version, deps) => ({
+ id: `${name} ${version}`,
+ deps: deps.map(([dep_name, dep_ver, dep_source]) => ({
+ name: dep_name,
+ pkg: dep_source ? `${dep_name} ${dep_ver} ${dep_source}` : `${dep_name} ${dep_ver}`,
+ dep_kinds: NORMAL,
+ })),
+});
+
+/** Resolve node for a registry crate. */
+const regNode = (name, version, deps) => ({
+ id: `${name} ${version} ${REGISTRY}`,
+ deps: deps.map(([dep_name, dep_ver, dep_source]) => ({
+ name: dep_name,
+ pkg: dep_source ? `${dep_name} ${dep_ver} ${dep_source}` : `${dep_name} ${dep_ver}`,
+ dep_kinds: NORMAL,
+ })),
+});
+
+// ---------------------------------------------------------------------------
+// Fixture: transitive engine through tsd crate → must FAIL
+// tinyagents-session (path) -> tinystoragedrivers-sqlite (path) -> rusqlite (registry)
+// ---------------------------------------------------------------------------
+
+const transitive_engine_fixture = {
+ packages: [
+ pathPkg('tinystoragedrivers-sqlite', '1.0.0', TSD_MANIFEST, [
+ { name: 'rusqlite', pkg: `rusqlite 0.32.1 ${REGISTRY}` },
+ ]),
+ regPkg('rusqlite', '0.32.1', `${ROOT}/.cargo/registry/src/foo/rusqlite-0.32.1/Cargo.toml`),
+ pathPkg('tinyagents-session', '0.1.0', `${ROOT}/crates/tinyagents-session/Cargo.toml`, [
+ { name: 'tinystoragedrivers-sqlite', pkg: 'tinystoragedrivers-sqlite 1.0.0' },
+ ]),
+ ],
+ resolve: {
+ nodes: [
+ pathNode('tinyagents-session', '0.1.0', [['tinystoragedrivers-sqlite', '1.0.0', null]]),
+ pathNode('tinystoragedrivers-sqlite', '1.0.0', [['rusqlite', '0.32.1', REGISTRY]]),
+ regNode('rusqlite', '0.32.1', []),
+ ],
+ },
+};
+
+// ---------------------------------------------------------------------------
+// Fixture: tsd tag mismatch → must FAIL
+// some-odd-crate (path) depends on tinystoragedrivers-core with git tag "99.0.0"
+// but vendored version is "1.0.0".
+// Note: dep.source must be set for the mismatch check to read the tag.
+// ---------------------------------------------------------------------------
+
+const tsd_tag_mismatch_fixture = {
+ packages: [
+ pathPkg('tinystoragedrivers-core', '1.0.0',
+ `${ROOT}/vendor/tinystoragedrivers/crates/tinystoragedrivers-core/Cargo.toml`),
+ // some-odd-crate depends on tinystoragedrivers-core with an explicit git source
+ // whose tag differs from the vendored version.
+ {
+ id: `some-odd-crate 0.1.0`,
+ name: 'some-odd-crate',
+ version: '0.1.0',
+ manifest_path: `${ROOT}/crates/some-odd-crate/Cargo.toml`,
+ source: null,
+ dependencies: [
+ {
+ name: 'tinystoragedrivers-core',
+ pkg: `tinystoragedrivers-core 1.0.0 ${tsd_git('99.0.0')}`,
+ source: tsd_git('99.0.0'), // <-- must be set for tag mismatch check
+ },
+ ],
+ },
+ ],
+ resolve: {
+ nodes: [
+ pathNode('some-odd-crate', '0.1.0', [['tinystoragedrivers-core', '1.0.0', tsd_git('99.0.0')]]),
+ pathNode('tinystoragedrivers-core', '1.0.0', []),
+ ],
+ },
+};
+
+// ---------------------------------------------------------------------------
+// Fixture: allowlisted root reaches engine → must PASS
+// openhuman (allowlisted) -> rusqlite
+// ---------------------------------------------------------------------------
+
+const allowlisted_root_fixture = {
+ packages: [
+ pathPkg('openhuman', '0.1.0', `${ROOT}/crates/openhuman/Cargo.toml`, [
+ { name: 'rusqlite', pkg: `rusqlite 0.32.1 ${REGISTRY}` },
+ ]),
+ regPkg('rusqlite', '0.32.1', '/fake/.cargo/registry/src/foo/rusqlite-0.32.1/Cargo.toml'),
+ ],
+ resolve: {
+ nodes: [
+ pathNode('openhuman', '0.1.0', [['rusqlite', '0.32.1', REGISTRY]]),
+ regNode('rusqlite', '0.32.1', []),
+ ],
+ },
+};
+
+// ---------------------------------------------------------------------------
+// Fixture: crate naming violation → must FAIL
+// Name ends with "-sqlite" → forbidden pattern.
+// ---------------------------------------------------------------------------
+
+const naming_violation_fixture = {
+ packages: [
+ pathPkg('tinyagents-sqlite', '0.1.0', `${ROOT}/crates/tinyagents-sqlite/Cargo.toml`),
+ ],
+ resolve: {
+ nodes: [
+ pathNode('tinyagents-sqlite', '0.1.0', []),
+ ],
+ },
+};
+
+// ---------------------------------------------------------------------------
+// Fixture: all tsd crates vendored → must PASS
+// ---------------------------------------------------------------------------
+
+const vendored_ok_fixture = {
+ packages: [
+ pathPkg('tinystoragedrivers-core', '1.0.0',
+ `${ROOT}/vendor/tinystoragedrivers/crates/tinystoragedrivers-core/Cargo.toml`),
+ pathPkg('tinystoragedrivers-sqlite', '1.0.0', TSD_MANIFEST),
+ pathPkg('openhuman-embed', '0.1.0', `${ROOT}/crates/openhuman-embed/Cargo.toml`, [
+ { name: 'tinystoragedrivers-core', pkg: 'tinystoragedrivers-core 1.0.0' },
+ ]),
+ ],
+ resolve: {
+ nodes: [
+ pathNode('tinystoragedrivers-core', '1.0.0', []),
+ pathNode('tinystoragedrivers-sqlite', '1.0.0', []),
+ pathNode('openhuman-embed', '0.1.0', [['tinystoragedrivers-core', '1.0.0', null]]),
+ ],
+ },
+};
+
+// ---------------------------------------------------------------------------
+// Fixture: aws-sdk-s3 reached directly from non-allowlisted crate → must FAIL
+// openhuman-core (NOT allowlisted) -> aws-sdk-s3 (registry)
+// ---------------------------------------------------------------------------
+
+const aws_s3_fixture = {
+ packages: [
+ pathPkg('openhuman-core', '0.1.0', `${ROOT}/crates/openhuman-core/Cargo.toml`, [
+ { name: 'aws-sdk-s3', pkg: `aws-sdk-s3 1.0.0 ${REGISTRY}` },
+ ]),
+ regPkg('aws-sdk-s3', '1.0.0', '/fake/.cargo/registry/src/aws/aws-sdk-s3-1.0.0/Cargo.toml'),
+ ],
+ resolve: {
+ nodes: [
+ pathNode('openhuman-core', '0.1.0', [['aws-sdk-s3', '1.0.0', REGISTRY]]),
+ regNode('aws-sdk-s3', '1.0.0', []),
+ ],
+ },
+};
+
+// ---------------------------------------------------------------------------
+// Tests
+// ---------------------------------------------------------------------------
+
+const { test, describe } = await import('node:test');
+
+describe('transitive engine through tsd crate → must FAIL', () => {
+ test('produces at least one engine-reach violation', () => {
+ const violations = checkMetadata(transitive_engine_fixture, ROOT);
+ const engineViolations = violations.filter(v => v.kind === 'engine-reach');
+ if (engineViolations.length === 0) {
+ throw new Error(`Expected engine-reach violation, got: ${JSON.stringify(violations)}`);
+ }
+ });
+});
+
+describe('tsd tag mismatch → must FAIL', () => {
+ test('produces a tsd-tag-mismatch violation', () => {
+ const violations = checkMetadata(tsd_tag_mismatch_fixture, ROOT);
+ const mismatch = violations.filter(v => v.kind === 'tsd-tag-mismatch');
+ if (mismatch.length === 0) {
+ throw new Error(`Expected tsd-tag-mismatch violation, got: ${JSON.stringify(violations)}`);
+ }
+ });
+});
+
+describe('allowlisted root reaches engine → must PASS', () => {
+ test('produces no violations', () => {
+ const violations = checkMetadata(allowlisted_root_fixture, ROOT);
+ if (violations.length > 0) {
+ throw new Error(`Expected no violations for allowlisted root, got: ${JSON.stringify(violations)}`);
+ }
+ });
+});
+
+describe('crate naming violation → must FAIL', () => {
+ test('produces a crate-name violation', () => {
+ const violations = checkMetadata(naming_violation_fixture, ROOT);
+ const naming = violations.filter(v => v.kind === 'crate-name');
+ if (naming.length === 0) {
+ throw new Error(`Expected crate-name violation, got: ${JSON.stringify(violations)}`);
+ }
+ });
+});
+
+describe('all tsd crates vendored → must PASS', () => {
+ test('produces no violations', () => {
+ const violations = checkMetadata(vendored_ok_fixture, ROOT);
+ if (violations.length > 0) {
+ throw new Error(`Expected no violations for vendored-clean tree, got: ${JSON.stringify(violations)}`);
+ }
+ });
+});
+
+describe('aws-sdk-s3 reached directly → must FAIL', () => {
+ test('produces an engine-reach violation for aws-sdk-s3', () => {
+ const violations = checkMetadata(aws_s3_fixture, ROOT);
+ const engineViolations = violations.filter(v =>
+ v.kind === 'engine-reach' && v.engine === 'aws-sdk-s3'
+ );
+ if (engineViolations.length === 0) {
+ throw new Error(`Expected engine-reach violation for aws-sdk-s3, got: ${JSON.stringify(violations)}`);
+ }
+ });
+});
diff --git a/scripts/ci/check-storage-owner.mjs b/scripts/ci/check-storage-owner.mjs
index 6827d2599d..243d95cd86 100644
--- a/scripts/ci/check-storage-owner.mjs
+++ b/scripts/ci/check-storage-owner.mjs
@@ -1,28 +1,25 @@
#!/usr/bin/env node
-// Storage-owner gate (tinyhumansai/openhuman#7642, part of #7522).
+// Storage-engine gate — tinyhumansai/openhuman#8131, part of #442.
//
// tinystoragedrivers is the only crate family allowed to own a storage
-// backend. This check reads `cargo metadata` for the root workspace and for
-// `crates/openhuman-app` and fails when
-// 1. a first-party package (path or git source, i.e. not a crates.io
-// dependency) outside `tinystoragedrivers*` declares a dependency on one
-// of FORBIDDEN_DEPS (any kind, optional or not), or
-// 2. a first-party package outside `tinystoragedrivers*` is named
-// `*-sqlite`, `*-mongodb` or `*-file`.
-// 3. a `tinystoragedrivers*` package in the resolved graph is not built from
-// a path under `vendor/tinystoragedrivers/` (a registry or git source
-// means some manifest escaped the root `[patch]` onto the vendored copy,
-// for example a module that bumped its tag past the vendored commit),
-// anchored to THIS repository's root, and
-// 4. a dependency naming tinystoragedrivers by a git tag that differs from
-// the vendored checkout's version (a tag-only bump still resolves to the
-// patched path, so rule 3 alone cannot see it).
-// Third-party registry crates are ignored (they are the backends' own deps,
-// e.g. `rusqlite -> libsqlite3-sys`).
+// backend. This check reads `cargo metadata --all-features` for the root
+// workspace and for `crates/openhuman-app` and fails when
+//
+// Rule 1: a first-party package (path or git source, not a registry dep)
+// that is NOT a tsd crate and NOT a composition root reaches a
+// forbidden engine crate through any normal or build dependency.
+//
+// Rule 2: a first-party package not in tsd is named `*-sqlite`,
+// `*-mongodb` or `*-file`.
+//
+// Rule 3: a tinystoragedrivers* package in the resolved graph is not a
+// path under `vendor/tinystoragedrivers/` (anchored to this repo).
+//
+// Rule 4: a dependency names tinystoragedrivers by a git tag that differs
+// from the vendored checkout's version.
//
// Read-only readers of external databases are not storage and are listed in
-// ALLOWLIST with a reason. A temporary entry names the open issue that
-// removes it.
+// ALLOWLIST with a reason.
//
// Usage: check-storage-owner.mjs [repo-root] [--metadata <file.json>]...
// With --metadata the given `cargo metadata` JSON files are checked instead of
@@ -34,39 +31,100 @@ import { readFileSync } from 'node:fs';
import { dirname, resolve } from 'node:path';
import { fileURLToPath, pathToFileURL } from 'node:url';
+// ---------------------------------------------------------------------------
+// Configuration
+// ---------------------------------------------------------------------------
+
+/** Engine crates no non-root first-party package may reach. */
export const FORBIDDEN_DEPS = [
'rusqlite',
'libsqlite3-sys',
'mongodb',
+ 'bson',
+ 'aws-sdk-s3',
+ 'lapin', // AMQP client (RabbitMQ)
+ 'amq-protocol', // AMQP wire protocol
'object_store',
'sqlx',
'redb',
'sled',
'rocksdb',
+ 'fs2', // advisory file locking
];
-export const FORBIDDEN_CRATE_NAME = /-(sqlite|mongodb|file)$/;
+/** Patterns matched as a prefix against the normalised crate name. */
+export const FORBIDDEN_PREFIXES = ['aws-smithy-'];
-/** Package name -> why it may keep a forbidden dependency. */
+/** Engine crates in the tinystoragedrivers family. */
+export const FORBIDDEN_TSD_ENGINES = [
+ 'tinystoragedrivers-sqlite',
+ 'tinystoragedrivers-mongodb',
+ 'tinystoragedrivers-file',
+ 'tinystoragedrivers-s3',
+ 'tinystoragedrivers-rabbitmq',
+ 'tinystoragedrivers-document',
+ 'tinystoragedrivers-kv',
+ 'tinystoragedrivers-blob',
+ 'tinystoragedrivers-queue',
+ 'tinystoragedrivers-secrets',
+ 'tinystoragedrivers-connect',
+];
+
+/** Packages allowed to transitively reach a forbidden engine, with a reason. */
export const ALLOWLIST = {
- tinychannels: 'iMessage chat.db reader: reads an external SQLite database read-only, not storage',
- 'openhuman-app': 'imessage scanner: reads chat.db directly and read-only, not storage',
- 'tinymemory-integrations': 'legacy-import: reads legacy SQLite files read-only for one-time import',
+ // Core storage domain — owns all engine initialisation.
+ openhuman: 'core storage domain',
+ // Hosts — own keyring access through rusqlite (keyring backend).
+ 'openhuman-app': 'keyring secrets via rusqlite',
+ 'openhuman-cli': 'keyring secrets via rusqlite',
+ 'openhuman-tui': 'keyring secrets via rusqlite',
+ 'openhuman-rpc': 'keyring secrets via rusqlite',
+ // iMessage scanner — reads chat.db directly, read-only.
+ tinychannels: 'iMessage chat.db reader: read-only SQLite access',
+ // CLI tools that bundle their own engine.
+ 'tinybox-cli': 'bin target, bundles engine',
+ tinyjuice: 'bin target, bundles engine',
};
+export const FORBIDDEN_CRATE_NAME = /-(sqlite|mongodb|file)$/;
+
export const MANIFESTS = ['Cargo.toml', 'crates/openhuman-app/Cargo.toml'];
+export const VENDORED_TSD_DIR = 'vendor/tinystoragedrivers/';
+export const REPO_ROOT = resolve(dirname(fileURLToPath(import.meta.url)), '../..');
+
+// ---------------------------------------------------------------------------
+// Helpers
+// ---------------------------------------------------------------------------
+
+const norm = s => String(s ?? '').replaceAll('\\', '/').replace(/\/+$/, '');
+
const isOwner = name => name.startsWith('tinystoragedrivers');
-/** First-party = built from a path or a git source, not from a registry. */
-const isFirstParty = pkg => !pkg.source || pkg.source.startsWith('git+');
+const normalisedName = name => name.replace(/_/g, '-');
-export const VENDORED_TSD_DIR = 'vendor/tinystoragedrivers/';
-export const REPO_ROOT = resolve(dirname(fileURLToPath(import.meta.url)), '../..');
+const isForbiddenDep = name => {
+ const n = normalisedName(name);
+ if (FORBIDDEN_DEPS.includes(n)) return true;
+ if (FORBIDDEN_PREFIXES.some(p => n.startsWith(p))) return true;
+ return false;
+};
-const norm = p => String(p ?? '').replaceAll('\\', '/').replace(/\/+$/, '');
+const isForbiddenTsdEngine = name => {
+ const n = normalisedName(name);
+ return FORBIDDEN_TSD_ENGINES.includes(n) || n === 'tinystoragedrivers';
+};
+
+/**
+ * First-party = built from a path or a git source, not from a registry.
+ * `null` source means path-based (same repo); a git source means git-based.
+ * A registry source (starts with "registry+") is third-party.
+ */
+const isFirstParty = pkg => {
+ if (pkg.source === null || pkg.source === undefined) return true;
+ return pkg.source.startsWith('git+');
+};
-/** True when `manifest` lies under `<root>/vendor/tinystoragedrivers/` (this checkout only). */
export function isUnderVendoredTsd(manifest, root) {
const prefix = `${norm(root)}/${VENDORED_TSD_DIR}`;
return norm(manifest).startsWith(prefix);
@@ -74,17 +132,126 @@ export function isUnderVendoredTsd(manifest, root) {
const TSD_GIT = /^git\+https?:\/\/[^?#]*\/tinystoragedrivers(?:\.git)?\?tag=([^#&]+)/;
+// ---------------------------------------------------------------------------
+// Dependency-closure walk
+// ---------------------------------------------------------------------------
+
/**
- * Rule 3: every tinystoragedrivers* package must be a path under this
- * repository's `<root>/vendor/tinystoragedrivers/`.
- * Rule 4: a dependency that names tinystoragedrivers by git tag must name the
- * tag matching the vendored checkout's version; a bare tag bump stays
- * semver-compatible, so the `[patch]` would otherwise apply silently.
+ * Walk the resolved normal+build dependency graph starting from `roots`
+ * (composition roots — always allowed) and report every first-party non-root
+ * package that reaches a forbidden engine.
+ *
+ * @param {object} metadata - cargo metadata document
+ * @param {string[]} roots - package names that are composition roots
+ * @returns {{ package: string, kind: string, engine: string, path: string[], detail: string }[]}
*/
+export function checkEngineClosure(metadata, roots) {
+ const packages = Object.fromEntries(
+ (metadata.packages ?? []).map(p => [p.id, p])
+ );
+ const nodes = Object.fromEntries(
+ (metadata.resolve?.nodes ?? []).map(n => [n.id, n])
+ );
+
+ // Set of package IDs that are composition roots (always allowed to reach engines)
+ const rootIds = new Set(
+ (metadata.packages ?? [])
+ .filter(p => roots.includes(p.name))
+ .map(p => p.id)
+ );
+
+ const violations = [];
+
+ for (const pkg of metadata.packages ?? []) {
+ if (!isFirstParty(pkg) || isOwner(pkg.name)) continue;
+ if (pkg.name in ALLOWLIST) continue;
+
+ const pkg_id = pkg.id;
+ if (!nodes[pkg_id]) continue;
+
+ // BFS from this package
+ // Each entry: [current_id, current_name, path_names]
+ const queue = [[pkg_id, pkg.name, [pkg.name]]];
+ const seen = new Set([pkg_id]);
+
+ while (queue.length) {
+ const [current_id, current_name, path] = queue.shift();
+ const node = nodes[current_id];
+ if (!node) continue;
+
+ for (const dep of node.deps ?? []) {
+ // Only normal and build edges count.
+ // dep_kinds may be absent (defaults to normal per cargo convention).
+ const dep_kinds = dep.dep_kinds ?? [{ kind: null }];
+ const has_normal_or_build = dep_kinds.some(
+ dk => dk.kind === undefined || dk.kind === 'normal' || dk.kind === 'build'
+ );
+ if (!has_normal_or_build) continue;
+
+ const dep_id = dep.pkg;
+ if (seen.has(dep_id)) continue;
+ seen.add(dep_id);
+
+ const dep_pkg = packages[dep_id];
+ if (!dep_pkg) continue;
+
+ const dep_name = dep_pkg.name;
+ const new_path = [...path, dep_name];
+
+ // Forbidden engine found — report it.
+ if (isForbiddenDep(dep_name) || isForbiddenTsdEngine(dep_name)) {
+ violations.push({
+ package: pkg.name,
+ kind: 'engine-reach',
+ engine: dep_name,
+ path: new_path,
+ detail: `reaches ${dep_name} via ${path.slice(1).join(' -> ')}`,
+ });
+ // Don't continue through forbidden crates — path to engine is captured.
+ continue;
+ }
+
+ // Continue the walk through this dep, regardless of whether it's
+ // first-party, owner-owned, or a registry crate. The BFS always
+ // continues so that we can trace a path all the way to a forbidden
+ // crate even when it passes through tsd engine crates.
+ queue.push([dep_id, dep_name, new_path]);
+ }
+ }
+ }
+
+ return violations;
+}
+
+// ---------------------------------------------------------------------------
+// Rule 2: crate naming
+// ---------------------------------------------------------------------------
+
+export function checkCrateNaming(metadata) {
+ const out = [];
+ for (const pkg of metadata.packages ?? []) {
+ if (!isFirstParty(pkg) || isOwner(pkg.name)) continue;
+ if (FORBIDDEN_CRATE_NAME.test(pkg.name)) {
+ out.push({
+ package: pkg.name,
+ kind: 'crate-name',
+ detail: `crate name matches ${FORBIDDEN_CRATE_NAME}`,
+ });
+ }
+ }
+ return out;
+}
+
+// ---------------------------------------------------------------------------
+// Rules 3 & 4: vendored TSD ownership and tag match
+// ---------------------------------------------------------------------------
+
export function checkVendoredOwner(metadata, root = REPO_ROOT) {
const out = [];
const packages = metadata.packages ?? [];
let vendoredVersion = null;
+
+ // Rule 3: every tsd* package must be a vendored path
for (const pkg of packages) {
if (!isOwner(pkg.name)) continue;
const manifest = norm(pkg.manifest_path);
@@ -99,6 +266,7 @@ export function checkVendoredOwner(metadata, root = REPO_ROOT) {
.map(p => p.name)
),
].sort();
+
out.push({
package: pkg.name,
kind: 'tsd-not-vendored',
@@ -108,13 +276,19 @@ export function checkVendoredOwner(metadata, root = REPO_ROOT) {
'; bump vendor/tinystoragedrivers or the module\'s tinystoragedrivers tag so they agree',
});
}
+
+ // Rule 4: git-tag mismatch
if (vendoredVersion) {
const seen = new Set();
for (const p of packages) {
if (isOwner(p.name)) continue;
for (const d of p.dependencies ?? []) {
- const tag = isOwner(d.name) ? TSD_GIT.exec(d.source ?? '')?.[1] : null;
- if (!tag || tag.replace(/^v/, '') === vendoredVersion) continue;
+ if (!isOwner(d.name)) continue;
+ // Check the dependency's declared source (what the consumer wrote in Cargo.toml)
+ const tag = d.source ? TSD_GIT.exec(d.source)?.[1] : null;
+ if (!tag) continue;
+ const normalisedTag = tag.replace(/^v/, '');
+ if (normalisedTag === vendoredVersion) continue;
const key = `${p.name}|${tag}`;
if (seen.has(key)) continue;
seen.add(key);
@@ -128,43 +302,58 @@ export function checkVendoredOwner(metadata, root = REPO_ROOT) {
}
}
}
+
return out;
}
-/** Returns `[{ package, kind, detail }]` violations for one metadata document. */
-export function checkMetadata(metadata, allowlist = ALLOWLIST, root = REPO_ROOT) {
- const out = [];
- for (const pkg of metadata.packages ?? []) {
- if (!isFirstParty(pkg) || isOwner(pkg.name)) continue;
- if (FORBIDDEN_CRATE_NAME.test(pkg.name)) {
- out.push({ package: pkg.name, kind: 'crate-name', detail: `crate name matches ${FORBIDDEN_CRATE_NAME}` });
- }
- if (Object.hasOwn(allowlist, pkg.name)) continue;
- const seen = new Set();
- for (const dep of pkg.dependencies ?? []) {
- if (FORBIDDEN_DEPS.includes(dep.name) && !seen.has(dep.name)) {
- seen.add(dep.name);
- out.push({ package: pkg.name, kind: 'dependency', detail: `depends on ${dep.name}` });
- }
- }
- }
- return [...out, ...checkVendoredOwner(metadata, root)];
+// ---------------------------------------------------------------------------
+// Top-level check
+// ---------------------------------------------------------------------------
+
+export function checkMetadata(metadata, root = REPO_ROOT) {
+ const allowlistKeys = Object.keys(ALLOWLIST);
+
+ // Rule 1: engine closure
+ const closureViolations = checkEngineClosure(metadata, allowlistKeys);
+
+ // Rule 2: crate naming
+ const namingViolations = checkCrateNaming(metadata);
+
+ // Rules 3 & 4
+ const vendoredViolations = checkVendoredOwner(metadata, root);
+
+ return [...closureViolations, ...namingViolations, ...vendoredViolations];
}
export function formatReport(violations) {
- if (violations.length === 0) return 'storage-owner: ok (no storage backend outside tinystoragedrivers*)';
- const lines = violations.map(v => ` - ${v.package}: ${v.detail}`);
+ if (violations.length === 0) {
+ return 'storage-owner: ok (no storage backend outside tinystoragedrivers* reached from non-root crates)';
+ }
+ const lines = violations.map(v => {
+ if (v.kind === 'engine-reach') {
+ return ` - ${v.package}: reaches ${v.engine} via ${v.path.slice(1, -1).join(' -> ')}`;
+ }
+ return ` - ${v.package}: ${v.detail}`;
+ });
return [
- 'storage-owner: FAILED. tinystoragedrivers* owns every storage backend.',
+ 'storage-owner: FAILED. No non-root first-party package may reach a storage engine.',
...lines,
- 'Use the tinystoragedrivers ports instead, or add a read-only external-database reader to ALLOWLIST in scripts/ci/check-storage-owner.mjs with a reason.',
+ '',
+ 'Allowlist entries (composition roots only):',
+ ...Object.entries(ALLOWLIST).map(([k, v]) => ` ${k}: ${v}`),
+ '',
+ 'Add a read-only external-database reader to ALLOWLIST with a reason, or use the tinystoragedrivers ports.',
].join('\n');
}
+// ---------------------------------------------------------------------------
+// CLI
+// ---------------------------------------------------------------------------
+
function loadMetadata(root, manifest) {
const r = spawnSync(
'cargo',
- ['metadata', '--format-version', '1', '--manifest-path', resolve(root, manifest)],
+ ['metadata', '--format-version', '1', '--manifest-path', resolve(root, manifest), '--all-features'],
{ cwd: root, encoding: 'utf8', maxBuffer: 1 << 30 }
);
if (r.status !== 0) throw new Error(`cargo metadata failed for ${manifest}: ${r.stderr}`);
@@ -178,6 +367,7 @@ export function main(argv) {
if (argv[i] === '--metadata') files.push(argv[++i]);
else root = resolve(argv[i]);
}
+
let docs;
try {
docs = files.length
@@ -187,10 +377,15 @@ export function main(argv) {
console.error(`storage-owner: cannot read inputs: ${err.message}`);
return 2;
}
+
const seen = new Set();
const violations = docs
- .flatMap(d => checkMetadata(d, ALLOWLIST, root))
- .filter(v => !seen.has(`${v.package}|${v.detail}`) && seen.add(`${v.package}|${v.detail}`));
+ .flatMap(d => checkMetadata(d, root))
+ .filter(v => {
+ const key = `${v.package}|${v.kind}|${v.detail}`;
+ return !seen.has(key) && seen.add(key);
+ });
+
console.log(formatReport(violations));
return violations.length ? 1 : 0;
}