radroots_sdk_boundary.test.mjs (1746B)
1 import assert from "node:assert/strict"; 2 import { readFileSync, readdirSync } from "node:fs"; 3 import { dirname, join, relative, resolve } from "node:path"; 4 import { fileURLToPath } from "node:url"; 5 import test from "node:test"; 6 7 const root = resolve(dirname(fileURLToPath(import.meta.url)), ".."); 8 9 function rustSources(path, found = []) { 10 for (const entry of readdirSync(path, { withFileTypes: true })) { 11 const child = join(path, entry.name); 12 if (entry.isDirectory()) { 13 rustSources(child, found); 14 } else if (entry.isFile() && entry.name.endsWith(".rs")) { 15 found.push(relative(root, child)); 16 } 17 } 18 return found.sort(); 19 } 20 21 test("the Rust workspace is an exact zero-logic source-lock capsule", () => { 22 assert.deepEqual(rustSources(join(root, "crates")), [ 23 "crates/source_lock/src/lib.rs", 24 ]); 25 assert.equal( 26 readFileSync(join(root, "crates/source_lock/src/lib.rs"), "utf8"), 27 "#![no_std]\n", 28 ); 29 assert.deepEqual(rustSources(join(root, "tools")), []); 30 const workspace = readFileSync(join(root, "Cargo.toml"), "utf8"); 31 const capsule = readFileSync(join(root, "crates/source_lock/Cargo.toml"), "utf8"); 32 assert.match(workspace, /^members = \["crates\/source_lock"\]$/m); 33 assert.match(capsule, /^publish = false$/m); 34 assert.doesNotMatch(workspace, /path\s*=/); 35 assert.doesNotMatch(capsule, /path\s*=/); 36 }); 37 38 test("the source-lock dependency is immutable and exact", () => { 39 const workspace = readFileSync(join(root, "Cargo.toml"), "utf8"); 40 assert.match(workspace, /git = "https:\/\/github\.com\/radrootslabs\/lib"/); 41 assert.match(workspace, /rev = "[0-9a-f]{40}"/); 42 assert.match(workspace, /version = "=0\.1\.0-alpha"/); 43 assert.doesNotMatch(workspace, /branch\s*=|tag\s*=/); 44 });