Skip to content

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

test(scripts): run the storage-owner self-test against the current checker

M3gA-Mind611f031f81fc
diff --git a/scripts/__tests__/check-storage-owner.test.mjs b/scripts/__tests__/check-storage-owner.test.mjs
index 44e5d8c951..550f6620aa 100644
--- a/scripts/__tests__/check-storage-owner.test.mjs
+++ b/scripts/__tests__/check-storage-owner.test.mjs
@@ -1,155 +1,343 @@
-import assert from 'node:assert/strict';
-import { spawnSync } from 'node:child_process';
-import { mkdtempSync, rmSync, writeFileSync } from 'node:fs';
-import { tmpdir } from 'node:os';
-import { dirname, join, resolve } from 'node:path';
-import { test } from 'node:test';
-import { fileURLToPath } from 'node:url';
+/**
+ * Fixture-based self-tests for check-storage-owner.mjs
+ *
+ * Run with: node --test scripts/__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 { ALLOWLIST, checkMetadata as checkMetadataAt, formatReport } from '../ci/check-storage-owner.mjs';
+import { checkMetadata, formatReport } from '../ci/check-storage-owner.mjs';
-const CHECKER = resolve(dirname(fileURLToPath(import.meta.url)), '../ci/check-storage-owner.mjs');
-const pkg = (name, deps = [], source = null, manifest_path) => ({
+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,
- source,
- manifest_path:
- manifest_path ??
- (name.startsWith('tinystoragedrivers')
- ? `/repo/vendor/tinystoragedrivers/crates/${name}/Cargo.toml`
- : `/repo/vendor/${name}/Cargo.toml`),
- dependencies: deps.map(d => ({ name: d, kind: null, optional: false })),
+ version,
+ manifest_path: manifest,
+ source: null,
+ dependencies: deps,
});
-const checkMetadata = (m, root = '/repo') => checkMetadataAt(m, ALLOWLIST, root);
-const registry = 'registry+https://github.com/rust-lang/crates.io-index';
-test('a clean workspace passes', () => {
- assert.deepEqual(checkMetadata({ packages: [pkg('openhuman', ['serde']), pkg('tinyflows', ['tinystoragedrivers-core'])] }), []);
+/** Registry crate. */
+const regPkg = (name, version, manifest, deps = []) => ({
+ id: `${name} ${version} ${REGISTRY}`,
+ name,
+ version,
+ manifest_path: manifest,
+ source: REGISTRY,
+ dependencies: deps,
});
-test('every forbidden backend dependency is rejected', () => {
- for (const dep of ['rusqlite', 'libsqlite3-sys', 'mongodb', 'object_store', 'sqlx', 'redb', 'sled', 'rocksdb']) {
- const v = checkMetadata({ packages: [pkg('tinymcp', [dep])] });
- assert.equal(v.length, 1, dep);
- assert.equal(v[0].package, 'tinymcp');
- }
-});
+/** Normal dep_kinds entry. */
+const NORMAL = [{ kind: 'normal' }];
-test('tinystoragedrivers crates own the backends', () => {
- const v = checkMetadata({
- packages: [pkg('tinystoragedrivers-sqlite', ['rusqlite']), pkg('tinystoragedrivers-file')],
- });
- assert.deepEqual(v, []);
+/** 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,
+ })),
});
-test('backend-named crates outside tinystoragedrivers are rejected', () => {
- for (const name of ['tinyflows-sqlite', 'tinyflows-mongodb', 'thing-file']) {
- assert.equal(checkMetadata({ packages: [pkg(name)] })[0].kind, 'crate-name', name);
- }
+/** 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,
+ })),
});
-test('registry crates are ignored', () => {
- assert.deepEqual(
- checkMetadata({ packages: [pkg('rusqlite', ['libsqlite3-sys'], registry), pkg('same-file', [], registry)] }),
- []
- );
-});
+// ---------------------------------------------------------------------------
+// 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.
+// ---------------------------------------------------------------------------
-test('allowlisted read-only readers may depend on rusqlite, with a reason', () => {
- for (const [name, reason] of Object.entries(ALLOWLIST)) {
- assert.ok(reason.length > 10, `${name} needs a reason`);
- assert.deepEqual(checkMetadata({ packages: [pkg(name, ['rusqlite'])] }), []);
- }
- assert.equal(checkMetadata({ packages: [pkg('tinyskills', ['rusqlite'])] }).length, 1);
+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)}`);
+ }
+ });
});
-test('the report names the offender', () => {
- assert.match(formatReport(checkMetadata({ packages: [pkg('tinymcp', ['rusqlite'])] })), /tinymcp: depends on rusqlite/);
- assert.match(formatReport([]), /ok/);
+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)}`);
+ }
+ });
});
-test('CLI exits 1 on a violation, 0 when clean, 2 on unreadable input', () => {
- const dir = mkdtempSync(join(tmpdir(), 'storage-owner-'));
- try {
- const bad = join(dir, 'bad.json');
- const good = join(dir, 'good.json');
- writeFileSync(bad, JSON.stringify({ packages: [pkg('tinymcp', ['rusqlite'])] }));
- writeFileSync(good, JSON.stringify({ packages: [pkg('tinymcp')] }));
- assert.equal(spawnSync('node', [CHECKER, '--metadata', bad]).status, 1);
- assert.equal(spawnSync('node', [CHECKER, '--metadata', good]).status, 0);
- assert.equal(spawnSync('node', [CHECKER, '--metadata', join(dir, 'missing.json')]).status, 2);
- } finally {
- rmSync(dir, { recursive: true, force: true });
- }
+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)}`);
+ }
+ });
});
-test('tinystoragedrivers packages under vendor/tinystoragedrivers pass', () => {
- assert.deepEqual(
- checkMetadata({ packages: [pkg('tinyflows', ['tinystoragedrivers-core']), pkg('tinystoragedrivers-core')] }),
- []
- );
+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)}`);
+ }
+ });
});
-test('a git or registry tinystoragedrivers package fails and names its dependents', () => {
- const git = 'git+https://github.com/tinyhumansai/tinystoragedrivers?tag=v0.12.0#abc';
- const v = checkMetadata({
- packages: [
- pkg('tinyflows', ['tinystoragedrivers-core']),
- pkg('tinystoragedrivers-core', [], git, '/home/u/.cargo/git/checkouts/tsd/abc/Cargo.toml'),
- ],
+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)}`);
+ }
});
- assert.equal(v.length, 1);
- assert.equal(v[0].kind, 'tsd-not-vendored');
- assert.match(formatReport(v), /tinystoragedrivers-core: resolves to git\+.*required by tinyflows.*bump vendor\/tinystoragedrivers/);
- const reg = checkMetadata({ packages: [pkg('tinystoragedrivers-core', [], registry)] });
- assert.equal(reg[0].kind, 'tsd-not-vendored');
});
-test('the standalone storage types contract may come from a pinned git revision', () => {
- const rev = 'git+https://github.com/tinyhumansai/tinystoragedrivers?rev=05eaada962decbab33bafa4763d2bd1a67f6b456#05eaada';
- const v = checkMetadata({
- packages: [
- pkg('tinyjuice-bus', ['tinystoragedrivers-types']),
- pkg('tinystoragedrivers-types', [], rev, '/home/u/.cargo/git/checkouts/tsd/abc/crates/tinystoragedrivers-types/Cargo.toml'),
- ],
+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)}`);
+ }
});
- assert.deepEqual(v, []);
});
-test('a path tinystoragedrivers package outside the vendored checkout fails', () => {
- const v = checkMetadata({
- packages: [pkg('tinystoragedrivers-core', [], null, '/repo/vendor/tinyagents/vendor/tinystoragedrivers/crates/x/Cargo.toml')],
+// ---------------------------------------------------------------------------
+// Edge kinds, report text, root anchoring and the CLI
+// ---------------------------------------------------------------------------
+
+const assert = (await import('node:assert/strict')).default;
+const { spawnSync } = await import('node:child_process');
+const { mkdtempSync, rmSync, writeFileSync } = await import('node:fs');
+const { tmpdir } = await import('node:os');
+const { dirname, join, resolve } = await import('node:path');
+const { fileURLToPath } = await import('node:url');
+const CHECKER = resolve(dirname(fileURLToPath(import.meta.url)), '../ci/check-storage-owner.mjs');
+
+describe('a dev-only edge to an engine → must PASS', () => {
+ test('dev dependencies are not part of the closure', () => {
+ const fixture = {
+ packages: [
+ pathPkg('tinyflows', '0.1.0', `${ROOT}/vendor/tinyflows/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: [
+ {
+ id: 'tinyflows 0.1.0',
+ deps: [{ name: 'rusqlite', pkg: `rusqlite 0.32.1 ${REGISTRY}`, dep_kinds: [{ kind: 'dev' }] }],
+ },
+ regNode('rusqlite', '0.32.1', []),
+ ],
+ },
+ };
+ assert.deepEqual(checkMetadata(fixture, ROOT), []);
});
- assert.equal(v.length, 1);
});
-const tsd = (manifest_path, version = '0.11.0') => ({ ...pkg('tinystoragedrivers-core', [], null, manifest_path), version });
-const TAG = 'git+https://github.com/tinyhumansai/tinystoragedrivers?tag=';
-const dependsAt = (name, tag) => ({
- name,
- source: null,
- manifest_path: `/repo/vendor/${name}/Cargo.toml`,
- dependencies: [{ name: 'tinystoragedrivers-core', kind: null, optional: false, source: `${TAG}${tag}` }],
+describe('the report', () => {
+ test('names the offender and the engine', () => {
+ assert.match(formatReport(checkMetadata(aws_s3_fixture, ROOT)), /openhuman-core: reaches aws-sdk-s3/);
+ assert.match(formatReport([]), /ok/);
+ });
});
-test('vendored path is anchored to this repository root', () => {
- const ok = '/repo/vendor/tinystoragedrivers/crates/core/Cargo.toml';
- assert.deepEqual(checkMetadata({ packages: [tsd(ok)] }), []);
- // a checkout below an ancestor named vendor is still accepted
- assert.deepEqual(checkMetadata({ packages: [tsd('/home/me/vendor/oh/vendor/tinystoragedrivers/c/Cargo.toml')] }, '/home/me/vendor/oh'), []);
- for (const bad of [
- '/other/vendor/tinystoragedrivers/crates/core/Cargo.toml',
- '/repo/vendor/x/vendor/tinystoragedrivers/crates/core/Cargo.toml',
- '/repo/other/vendor/tinystoragedrivers/crates/core/Cargo.toml',
- ]) {
- assert.equal(checkMetadata({ packages: [tsd(bad)] })[0]?.kind, 'tsd-not-vendored', bad);
- }
+describe('the vendored tinystoragedrivers path is anchored to the repository root', () => {
+ test('only <root>/vendor/tinystoragedrivers/ counts as vendored', () => {
+ const tsdAt = manifest => ({
+ packages: [pathPkg('tinystoragedrivers-core', '1.0.0', manifest)],
+ resolve: { nodes: [pathNode('tinystoragedrivers-core', '1.0.0', [])] },
+ });
+ assert.deepEqual(checkMetadata(tsdAt(`${ROOT}/vendor/tinystoragedrivers/crates/core/Cargo.toml`), ROOT), []);
+ for (const bad of [
+ '/other/vendor/tinystoragedrivers/crates/core/Cargo.toml',
+ `${ROOT}/vendor/x/vendor/tinystoragedrivers/crates/core/Cargo.toml`,
+ ]) {
+ assert.equal(checkMetadata(tsdAt(bad), ROOT)[0]?.kind, 'tsd-not-vendored', bad);
+ }
+ });
});
-test('a module tag differing from the vendored version is rejected', () => {
- const vend = tsd('/repo/vendor/tinystoragedrivers/crates/core/Cargo.toml');
- assert.deepEqual(checkMetadata({ packages: [vend, dependsAt('tinyflows', 'v0.11.0')] }), []);
- const v = checkMetadata({ packages: [vend, dependsAt('tinyflows', 'v0.12.0')] });
- assert.equal(v.length, 1);
- assert.equal(v[0].kind, 'tsd-tag-mismatch');
- assert.match(v[0].detail, /v0\.12\.0.*0\.11\.0/);
+describe('the CLI', () => {
+ test('exits 1 on a violation, 0 when clean, 2 on unreadable input', () => {
+ const dir = mkdtempSync(join(tmpdir(), 'storage-owner-'));
+ try {
+ const bad = join(dir, 'bad.json');
+ const good = join(dir, 'good.json');
+ writeFileSync(bad, JSON.stringify(aws_s3_fixture));
+ writeFileSync(good, JSON.stringify(allowlisted_root_fixture));
+ assert.equal(spawnSync('node', [CHECKER, '--metadata', bad]).status, 1);
+ assert.equal(spawnSync('node', [CHECKER, '--metadata', good]).status, 0);
+ assert.equal(spawnSync('node', [CHECKER, '--metadata', join(dir, 'missing.json')]).status, 2);
+ } finally {
+ rmSync(dir, { recursive: true, force: true });
+ }
+ });
});
diff --git a/scripts/ci/__tests__/check-storage-owner.test.mjs b/scripts/ci/__tests__/check-storage-owner.test.mjs
deleted file mode 100644
index 193837cb4d..0000000000
--- a/scripts/ci/__tests__/check-storage-owner.test.mjs
+++ /dev/null
@@ -1,268 +0,0 @@
-/**
- * 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)}`);
- }
- });
-});