Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

address review (codex): scope .ps1 BOM test to git-tracked files

[._.]/ Adam Eivy7f9e281a776d
diff --git a/scripts/ps1-bom.test.js b/scripts/ps1-bom.test.js
index 6ff5394b7a..e9fe324af7 100644
--- a/scripts/ps1-bom.test.js
+++ b/scripts/ps1-bom.test.js
@@ -1,6 +1,7 @@
import { describe, it, expect } from 'vitest';
-import { readdirSync, readFileSync, statSync } from 'fs';
-import { dirname, join, relative } from 'path';
+import { execFileSync } from 'child_process';
+import { readFileSync } from 'fs';
+import { dirname, join } from 'path';
import { fileURLToPath } from 'url';
// Regression guard for issue #1788: setup.ps1 failed to parse on Windows
@@ -13,35 +14,33 @@ import { fileURLToPath } from 'url';
//
// This test fails the moment any tracked .ps1 loses (or is added without) its
// BOM, so the bug can't silently return via an editor that strips it.
+//
+// We enumerate via `git ls-files` rather than walking the tree so the check
+// covers exactly the *tracked* scripts: gitignored runtime data (e.g. cloned
+// repos under data/repos/) and the lib/slashdo submodule's own files are
+// excluded for free — a BOM-less .ps1 a developer happens to clone locally
+// must not fail this suite.
const REPO_ROOT = join(dirname(fileURLToPath(import.meta.url)), '..');
-const SKIP_DIRS = new Set(['node_modules', '.git']);
const UTF8_BOM = Buffer.from([0xef, 0xbb, 0xbf]);
-function findPs1Files(dir, acc = []) {
- for (const entry of readdirSync(dir, { withFileTypes: true })) {
- // Skip the vendored slashdo submodule — it owns its own files.
- if (entry.isDirectory()) {
- if (SKIP_DIRS.has(entry.name)) continue;
- const full = join(dir, entry.name);
- if (relative(REPO_ROOT, full) === join('lib', 'slashdo')) continue;
- findPs1Files(full, acc);
- } else if (entry.isFile() && entry.name.toLowerCase().endsWith('.ps1')) {
- acc.push(join(dir, entry.name));
- }
- }
- return acc;
+function trackedPs1Files() {
+ const out = execFileSync('git', ['ls-files', '-z', '*.ps1'], {
+ cwd: REPO_ROOT,
+ encoding: 'utf8',
+ });
+ return out.split('\0').filter(Boolean);
}
describe('PowerShell scripts (.ps1) ship a UTF-8 BOM (issue #1788)', () => {
- const files = findPs1Files(REPO_ROOT);
+ const files = trackedPs1Files();
- it('finds the project .ps1 scripts to verify', () => {
- // Sanity: if the walk finds nothing the assertions below are vacuous.
+ it('finds the tracked .ps1 scripts to verify', () => {
+ // Sanity: if `git ls-files` found nothing the assertions below are vacuous.
expect(files.length).toBeGreaterThan(0);
});
- it.each(files.map((f) => relative(REPO_ROOT, f)))(
+ it.each(files)(
'%s starts with a UTF-8 BOM so Windows PowerShell 5.1 reads it as UTF-8',
(rel) => {
const head = readFileSync(join(REPO_ROOT, rel)).subarray(0, 3);