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

verify the direct-invocation drift detector instead of trusting it

[._.]/ Adam Eivy96d03d916254
diff --git a/scripts/direct-invocation-drift.test.js b/scripts/direct-invocation-drift.test.js
index 207963c353..b79dc678e6 100644
--- a/scripts/direct-invocation-drift.test.js
+++ b/scripts/direct-invocation-drift.test.js
@@ -25,13 +25,29 @@ const scriptFiles = SCRIPT_DIRS.flatMap((relativeDir) => {
.map((entry) => `${relativeDir}/${entry.name}`);
});
+/** True when `source` hand-rolls the argv[1] <-> import.meta.url comparison. */
+const handRollsCheck = (source) => (
+ /process\.argv\[1\][\s\S]{0,200}import\.meta\.url/.test(source)
+ || /import\.meta\.url[\s\S]{0,200}process\.argv\[1\]/.test(source)
+);
+
describe('direct-invocation checks have one owner (issue #4868)', () => {
+ // The scan below can only fail while the detector still fires and the file
+ // list is still populated, so both are verified rather than trusted — a
+ // broken regex or an empty glob would otherwise pass silently forever.
+ it('handRollsCheck flags hand-rolled guards and clears the shared helper', () => {
+ expect(handRollsCheck('const isMain = process.argv[1]\n && resolve(process.argv[1]) === resolve(fileURLToPath(import.meta.url));')).toBe(true);
+ expect(handRollsCheck('if (import.meta.url === pathToFileURL(process.argv[1]).href) main();')).toBe(true);
+ expect(handRollsCheck('if (import.meta.url === `file://${process.argv[1]}`) main();')).toBe(true);
+ expect(handRollsCheck('if (isDirectlyInvoked(import.meta.url)) main();')).toBe(false);
+ });
+
it('top-level JavaScript scripts do not compare argv[1] with import.meta.url themselves', () => {
- const offenders = scriptFiles.filter((relativePath) => {
- const source = readFileSync(join(REPO_ROOT, relativePath), 'utf8');
- return /process\.argv\[1\][\s\S]{0,200}import\.meta\.url/.test(source)
- || /import\.meta\.url[\s\S]{0,200}process\.argv\[1\]/.test(source);
- });
+ expect(scriptFiles.length).toBeGreaterThan(0);
+
+ const offenders = scriptFiles.filter((relativePath) => (
+ handRollsCheck(readFileSync(join(REPO_ROOT, relativePath), 'utf8'))
+ ));
expect(offenders).toEqual([]);
});