Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions skills/reverse-engineering-saas/scripts/check-kb.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// evidence tags, the change ledger and STATUS.md.
// Exit code 1 when there are errors, 2 on bad usage.
import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs';
import { dirname, join, relative, resolve } from 'node:path';
import { dirname, join, relative, resolve, sep } from 'node:path';

const USAGE = 'Usage: node check-kb.mjs <kb-dir> [--closing] [--next] [--help]';
const ID_PATTERN = /\b(FL|SRC|EV|BR|F|S|C|R|E|B|Q|L)-(\d{3})\b/g;
Expand Down Expand Up @@ -46,7 +46,7 @@ function walk(dir, root = dir) {
if (SKIP_DIRS.has(entry)) continue;
const full = join(dir, entry);
if (statSync(full).isDirectory()) files.push(...walk(full, root));
else files.push(relative(root, full));
else files.push(relative(root, full).split(sep).join('/'));
}
return files;
}
Expand Down
6 changes: 4 additions & 2 deletions tests/kb-scripts.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { fileURLToPath } from 'node:url';

const scripts = join(dirname(fileURLToPath(import.meta.url)), '..', 'skills', 'reverse-engineering-saas', 'scripts');
const run = (name, ...args) => spawnSync(process.execPath, [join(scripts, name), ...args], { encoding: 'utf8' });
// Windows installs Python as python, not python3.
const python = process.platform === 'win32' ? 'python' : 'python3';

let dir;
let kb;
Expand Down Expand Up @@ -218,7 +220,7 @@ test('init-kb defaults to ./re-<product-slug>', () => {
// Lists and verifies a zip with Python's zipfile, an independent implementation.
const readZip = (file) => {
const code = 'import json,sys,zipfile\nz=zipfile.ZipFile(sys.argv[1])\nprint(json.dumps({"bad": z.testzip(), "names": z.namelist(), "build": z.read([n for n in z.namelist() if n.endswith("/BUILD.md")][0]).decode()}))';
const result = spawnSync('python3', ['-c', code, file], { encoding: 'utf8' });
const result = spawnSync(python, ['-c', code, file], { encoding: 'utf8' });
assert.equal(result.status, 0, result.stderr);
return JSON.parse(result.stdout);
};
Expand Down Expand Up @@ -255,7 +257,7 @@ test('an unzipped handoff passes check-kb --closing; its ledger has no IDs, loca
assert.equal(packed.status, 0, packed.stdout + packed.stderr);
assert.match(packed.stdout, /Kept sandbox\/ledger\.csv without object IDs/);
const target = join(dir, 'unzipped');
const unzip = spawnSync('python3', ['-c', 'import sys,zipfile\nzipfile.ZipFile(sys.argv[1]).extractall(sys.argv[2])', out, target], { encoding: 'utf8' });
const unzip = spawnSync(python, ['-c', 'import sys,zipfile\nzipfile.ZipFile(sys.argv[1]).extractall(sys.argv[2])', out, target], { encoding: 'utf8' });
assert.equal(unzip.status, 0, unzip.stderr);

const ledger = readFileSync(join(target, 're-acme', 'sandbox', 'ledger.csv'), 'utf8');
Expand Down