Skip to content

Beautiful, AI-native markdown IDE and LLM wiki

Keep OK validation and root-guard verdicts tied to work that ran (#6081)

Nick Gomez5d4403ee9352
diff --git a/packages/app/tests/integration/dev-gate-allowlist.ts b/packages/app/tests/integration/dev-gate-allowlist.ts
index 4f66d2be6..10bc9eec9 100644
--- a/packages/app/tests/integration/dev-gate-allowlist.ts
+++ b/packages/app/tests/integration/dev-gate-allowlist.ts
@@ -1,7 +1,13 @@
-export const DEV_GATED_WINDOW_WRITERS: ReadonlyArray<string> = [
- 'packages/app/src/components/GraphView.tsx',
- 'packages/app/src/components/SystemDocSubscriber.tsx',
- 'packages/app/src/editor/DocumentContext.tsx',
- 'packages/app/src/editor/TiptapEditor.tsx',
- 'packages/app/src/lib/acp/dev-thread-harness.ts',
-];
+export const DEV_GATED_WINDOW_WRITERS: Readonly<Record<string, readonly string[]>> = {
+ 'packages/app/src/components/GraphView.tsx': ['__graphHarness'],
+ 'packages/app/src/editor/DocumentContext.tsx': [
+ '__activeEditor',
+ '__activeProvider',
+ '__providerPool',
+ '__test_armPendingRejection',
+ '__test_closeActiveWebSocket',
+ '__test_rejectSyncPromise',
+ ],
+ 'packages/app/src/editor/TiptapEditor.tsx': ['__agentFlashState'],
+ 'packages/app/src/lib/acp/dev-thread-harness.ts': ['__acpThreadHarness'],
+};
diff --git a/packages/app/tests/integration/e2e-stop-rules.test.ts b/packages/app/tests/integration/e2e-stop-rules.test.ts
index 290a7275d..c031f8274 100644
--- a/packages/app/tests/integration/e2e-stop-rules.test.ts
+++ b/packages/app/tests/integration/e2e-stop-rules.test.ts
@@ -505,6 +505,86 @@ function collectMatches(
return violations;
}
+type DevGateFinding =
+ | { kind: 'unlisted-write'; path: string; line: number; global: string; excerpt: string }
+ | { kind: 'stale-entry'; path: string; global: string }
+ | { kind: 'empty-entry'; path: string };
+
+interface DevGateScan {
+ scannedFiles: number;
+ writerFiles: number;
+ writes: number;
+ findings: DevGateFinding[];
+}
+
+const ASSIGNED_WINDOW_GLOBAL = /(?<=window\.)__[A-Za-z_][A-Za-z0-9_]*(?=\s*=)/g;
+const COMPARED_WINDOW_GLOBAL = /window\.__[A-Za-z_][A-Za-z0-9_]*\s*===?/;
+const DEFINED_WINDOW_GLOBAL =
+ /(?<=Object\.defineProperty\s*\(\s*window\s*,\s*['"])__[A-Za-z_][A-Za-z0-9_]*(?=['"])/g;
+
+function windowGlobalsWrittenOn(line: string): string[] {
+ const assigned = COMPARED_WINDOW_GLOBAL.test(line)
+ ? []
+ : (line.match(ASSIGNED_WINDOW_GLOBAL) ?? []);
+ return [...assigned, ...(line.match(DEFINED_WINDOW_GLOBAL) ?? [])];
+}
+
+function scanDevGatedWrites(
+ files: ReadonlyArray<Pick<FileLines, 'path' | 'lines'>>,
+ allowlist: Readonly<Record<string, readonly string[]>>,
+): DevGateScan {
+ const listed = new Map(
+ Object.entries(allowlist).map(([path, globals]) => [path, new Set(globals)]),
+ );
+ const written = new Map<string, Set<string>>();
+ const findings: DevGateFinding[] = [];
+ let writes = 0;
+ for (const file of files) {
+ file.lines.forEach((line, index) => {
+ for (const global of windowGlobalsWrittenOn(line)) {
+ writes += 1;
+ const globalsWritten = written.get(file.path) ?? new Set<string>();
+ globalsWritten.add(global);
+ written.set(file.path, globalsWritten);
+ if (listed.get(file.path)?.has(global) === true) continue;
+ findings.push({
+ kind: 'unlisted-write',
+ path: file.path,
+ line: index + 1,
+ global,
+ excerpt: line.trim(),
+ });
+ }
+ });
+ }
+ for (const [path, globals] of listed) {
+ if (globals.size === 0) findings.push({ kind: 'empty-entry', path });
+ for (const global of globals) {
+ if (written.get(path)?.has(global) !== true) {
+ findings.push({ kind: 'stale-entry', path, global });
+ }
+ }
+ }
+ return { scannedFiles: files.length, writerFiles: written.size, writes, findings };
+}
+
+function assertNeverDevGateFinding(finding: never): never {
+ throw new Error(`Unhandled DevGateFinding kind: ${JSON.stringify(finding)}`);
+}
+
+function describeDevGateFinding(finding: DevGateFinding): string {
+ switch (finding.kind) {
+ case 'unlisted-write':
+ return ` ${finding.path}:${finding.line} ${finding.global} is not listed for this file ${finding.excerpt}`;
+ case 'stale-entry':
+ return ` ${finding.path} lists ${finding.global}, which this file does not write`;
+ case 'empty-entry':
+ return ` ${finding.path} lists no global`;
+ default:
+ return assertNeverDevGateFinding(finding);
+ }
+}
+
describe('E2E STOP rule — zero allowlist', () => {
const e2eTsFiles = listE2eTsFiles();
const e2eFiles = e2eTsFiles.filter((file) => isTestOnlySourceFile(file.path, 'playwright'));
@@ -592,30 +672,106 @@ describe('E2E STOP rule — zero allowlist', () => {
).toEqual([]);
});
- test('no ungated window.__ writes outside dev-gate allowlist (US-006/US-026)', () => {
- const srcFiles = listAppSrcTsFiles();
- const writePattern = /window\.__[A-Za-z_][A-Za-z0-9_]*\s*=/;
- const equalityPattern = /window\.__[A-Za-z_][A-Za-z0-9_]*\s*===?/;
- const definePropertyPattern =
- /Object\.defineProperty\s*\(\s*window\s*,\s*['"]__[A-Za-z_][A-Za-z0-9_]*['"]/;
+ test('every window.__ write in app source is listed for its own file, and every listed global is written', () => {
+ const scan = scanDevGatedWrites(listAppSrcTsFiles(), DEV_GATED_WINDOW_WRITERS);
+ console.info(
+ `dev-gate allowlist: ${scan.writes} window.__ writes in ${scan.writerFiles} files, ${scan.findings.length} findings, ${scan.scannedFiles} source files scanned`,
+ );
- const violations: string[] = [];
- for (const file of srcFiles) {
- if (DEV_GATED_WINDOW_WRITERS.includes(file.path)) continue;
- for (let i = 0; i < file.lines.length; i++) {
- const line = file.lines[i] ?? '';
- const isAssignWrite = writePattern.test(line) && !equalityPattern.test(line);
- const isDefinePropertyWrite = definePropertyPattern.test(line);
- if (!isAssignWrite && !isDefinePropertyWrite) continue;
- violations.push(` ${file.path}:${i + 1} ${line.trim()}`);
- }
- }
+ expect(scan.scannedFiles).toBeGreaterThan(0);
expect(
- violations,
- `Ungated window.__ write outside the dev-gate allowlist — wrap in if (import.meta.env.DEV) and add to dev-gate-allowlist.ts:\n${violations.join('\n')}`,
+ scan.findings,
+ `window.__ writes disagree with dev-gate-allowlist.ts — wrap a new write in if (import.meta.env.DEV) and list its global under its file; delete an entry whose write is gone:\n${scan.findings.map(describeDevGateFinding).join('\n')}`,
).toEqual([]);
});
+ test('dev-gate rule reports a global its file is not listed for, and not the adjacent negatives', () => {
+ const listed = 'packages/app/src/editor/Listed.tsx';
+ const unlisted = 'packages/app/src/components/Unlisted.tsx';
+ const scan = scanDevGatedWrites(
+ [
+ {
+ path: listed,
+ lines: [
+ 'if (import.meta.env.DEV) {',
+ ' window.__listedHook = hook;',
+ " Object.defineProperty(window, '__listedGetter', { get: () => hook });",
+ ' window.__unlistedHook = other;',
+ ' Object.defineProperty(window, "__unlistedGetter", { get: () => other });',
+ ' window.__listedHook = window.__chainedHook = both;',
+ '}',
+ ],
+ },
+ {
+ path: unlisted,
+ lines: [
+ 'window.__strayHook = hook;',
+ 'if (window.__strayHook === hook) cleanup();',
+ 'delete window.__strayHook;',
+ 'const read = window.__readHook;',
+ 'window.okDesktop = bridge;',
+ "Object.defineProperty(window, 'okDesktop', { value: bridge });",
+ ],
+ },
+ ],
+ { [listed]: ['__listedGetter', '__listedHook'] },
+ );
+
+ expect(scan.findings).toEqual([
+ {
+ kind: 'unlisted-write',
+ path: listed,
+ line: 4,
+ global: '__unlistedHook',
+ excerpt: 'window.__unlistedHook = other;',
+ },
+ {
+ kind: 'unlisted-write',
+ path: listed,
+ line: 5,
+ global: '__unlistedGetter',
+ excerpt: 'Object.defineProperty(window, "__unlistedGetter", { get: () => other });',
+ },
+ {
+ kind: 'unlisted-write',
+ path: listed,
+ line: 6,
+ global: '__chainedHook',
+ excerpt: 'window.__listedHook = window.__chainedHook = both;',
+ },
+ {
+ kind: 'unlisted-write',
+ path: unlisted,
+ line: 1,
+ global: '__strayHook',
+ excerpt: 'window.__strayHook = hook;',
+ },
+ ]);
+ expect({ writes: scan.writes, writerFiles: scan.writerFiles }).toEqual({
+ writes: 7,
+ writerFiles: 2,
+ });
+ });
+
+ test('dev-gate rule reports an allowlist entry that matches no write', () => {
+ const writer = 'packages/app/src/editor/Writer.tsx';
+ const quiet = 'packages/app/src/components/Quiet.tsx';
+ const writerFile = { path: writer, lines: [' window.__keptHook = hook;'] };
+
+ expect(
+ scanDevGatedWrites([writerFile, { path: quiet, lines: [' render(window.__keptHook);'] }], {
+ [writer]: ['__keptHook', '__removedHook'],
+ [quiet]: [],
+ 'packages/app/src/lib/Deleted.ts': ['__goneHook'],
+ }).findings,
+ ).toEqual([
+ { kind: 'stale-entry', path: writer, global: '__removedHook' },
+ { kind: 'empty-entry', path: quiet },
+ { kind: 'stale-entry', path: 'packages/app/src/lib/Deleted.ts', global: '__goneHook' },
+ ]);
+ expect(scanDevGatedWrites([writerFile], { [writer]: ['__keptHook'] }).findings).toEqual([]);
+ });
+
test('no static value import of the DEV ACP thread harness', () => {
const violations = collectMatches(listAppSrcTsFiles(), (line) =>
isStaticDevHarnessImport(line),
diff --git a/scripts/check-override-floors.test.mjs b/scripts/check-override-floors.test.mjs
index d6f7bd97f..ef2ccf02e 100644
--- a/scripts/check-override-floors.test.mjs
+++ b/scripts/check-override-floors.test.mjs
@@ -135,9 +135,12 @@ describe('parsePackagePatterns / expandPackagePattern', () => {
const listedEntries = afterHeader
.slice(0, blockEnd === -1 ? afterHeader.length : blockEnd)
.filter((line) => line.trim().startsWith('-'));
+ const nestedMembersOnDisk = ['packages/md-conformance/md-audit'].filter((member) =>
+ fs.existsSync(path.join(root, member, 'package.json')),
+ );
expect(unparsed).toEqual([]);
- expect(patterns).toEqual(['packages/*', 'docs', 'packages/md-conformance/md-audit']);
+ expect(patterns).toEqual(['packages/*', 'docs', ...nestedMembersOnDisk]);
expect(patterns).toHaveLength(listedEntries.length);
expect(expandPackagePattern(root, 'packages/*')?.length).toBe(
fs.readdirSync(path.join(root, 'packages')).length,
diff --git a/scripts/check-typescript-resolution.test.mjs b/scripts/check-typescript-resolution.test.mjs
index 873528e79..3d52d518d 100644
--- a/scripts/check-typescript-resolution.test.mjs
+++ b/scripts/check-typescript-resolution.test.mjs
@@ -320,11 +320,11 @@ describe('collectViolations', () => {
describe('memberDirs', () => {
const root = path.resolve(import.meta.dirname, '..');
- const collect = (yaml) => {
+ const collect = (yaml, walkRoot = root) => {
const unparsed = [];
const empty = [];
const dirs = memberDirs(
- root,
+ walkRoot,
yaml,
(line) => unparsed.push(line),
(pattern) => empty.push(pattern),
@@ -339,21 +339,31 @@ describe('memberDirs', () => {
expect(unparsed).toEqual([]);
expect(empty).toEqual([]);
const names = dirs.map((dir) => path.relative(root, dir));
+ const nestedMembersOnDisk = [path.join('packages', 'md-conformance', 'md-audit')].filter(
+ (member) => fs.existsSync(path.join(root, member, 'package.json')),
+ );
expect(names).toContain('docs');
- expect(names).toContain(path.join('packages', 'md-conformance', 'md-audit'));
+ expect(names).toEqual(expect.arrayContaining(nestedMembersOnDisk));
expect(names).toContain(path.join('packages', 'core'));
expect(dirs.length).toBeGreaterThanOrEqual(8);
});
it('keeps enumerating past a comment interleaved in the packages list', () => {
- const withComment = collect(
- "packages:\n - 'docs'\n # a nested package needs its own entry\n\n - 'packages/md-conformance/md-audit'\n",
- );
- const withoutComment = collect(
- "packages:\n - 'docs'\n - 'packages/md-conformance/md-audit'\n",
+ withTree(
+ { 'docs/package.json': {}, 'packages/md-conformance/md-audit/package.json': {} },
+ (fixture) => {
+ const withComment = collect(
+ "packages:\n - 'docs'\n # a nested package needs its own entry\n\n - 'packages/md-conformance/md-audit'\n",
+ fixture,
+ );
+ const withoutComment = collect(
+ "packages:\n - 'docs'\n - 'packages/md-conformance/md-audit'\n",
+ fixture,
+ );
+ expect(withComment.dirs).toEqual(withoutComment.dirs);
+ expect(withComment.dirs).toHaveLength(2);
+ },
);
- expect(withComment.dirs).toEqual(withoutComment.dirs);
- expect(withComment.dirs).toHaveLength(2);
});
it('stops at the next top-level key instead of swallowing a later list', () => {
diff --git a/test-support/setup-files-contract.test.ts b/test-support/setup-files-contract.test.ts
index 16edeac32..e3c6190a6 100644
--- a/test-support/setup-files-contract.test.ts
+++ b/test-support/setup-files-contract.test.ts
@@ -27,16 +27,19 @@ const KNOWN_TEST_PROJECTS = [
'packages/cli/vitest.e2e.config.ts',
'packages/core/vitest.config.ts',
'packages/desktop/vitest.config.ts',
- 'packages/md-conformance/md-audit/vitest.config.ts',
- 'packages/md-conformance/vitest.config.ts',
'packages/server/vitest.config.ts',
'packages/server/vitest.network.config.ts',
'test-support/fixtures/no-net-connect/vitest.no-net-connect-fixture.config.ts',
- 'vitest.config.ts',
'vitest.scripts.config.ts',
'vitest.uncached.config.ts',
];
+const TEST_PROJECTS_OUTSIDE_THE_PUBLIC_TREE = [
+ 'packages/md-conformance/md-audit/vitest.config.ts',
+ 'packages/md-conformance/vitest.config.ts',
+ 'vitest.config.ts',
+];
+
const KNOWN_BUILD_CONFIGS = [
'packages/app/vite.config.ts',
'packages/desktop/electron.vite.config.ts',
@@ -55,21 +58,28 @@ const isBrowserProject = (relPath: string): boolean =>
const isTestConfig = (relPath: string): boolean => TEST_CONFIG_FILENAME.test(basename(relPath));
-function findConfigs(): string[] {
- return execFileSync(
- 'git',
- ['ls-files', '-z', '--', '*.config.ts', '*.config.mts', '*.config.js', '*.config.mjs'],
- {
- cwd: REPO_ROOT,
- env: gitCleanEnv(),
- encoding: 'utf8',
- },
- )
+function trackedFiles(pathspecs: readonly string[]): string[] {
+ return execFileSync('git', ['ls-files', '-z', '--', ...pathspecs], {
+ cwd: REPO_ROOT,
+ env: gitCleanEnv(),
+ encoding: 'utf8',
+ })
.split('\0')
- .filter((relPath) => relPath !== '' && CONFIG_FILENAME.test(basename(relPath)))
+ .filter((relPath) => relPath !== '');
+}
+
+function findConfigs(): string[] {
+ return trackedFiles(['*.config.ts', '*.config.mts', '*.config.js', '*.config.mjs'])
+ .filter((relPath) => CONFIG_FILENAME.test(basename(relPath)))
.sort();
}
+const tracksFilesThePublicTreeOmits = trackedFiles(['*.private.*']).length > 0;
+
+const EXPECTED_TEST_PROJECTS = tracksFilesThePublicTreeOmits
+ ? [...KNOWN_TEST_PROJECTS, ...TEST_PROJECTS_OUTSIDE_THE_PUBLIC_TREE]
+ : KNOWN_TEST_PROJECTS;
+
type TestOptions = { name?: unknown; setupFiles?: unknown; projects?: unknown };
function setupFileList(setupFiles: unknown): string[] {
@@ -125,7 +135,7 @@ describe('vitest setupFiles contract', () => {
configs.filter(isTestConfig).sort(),
'A vitest project appeared or disappeared. Confirm the new one is covered, then update ' +
'this list; a lower bound would have let a disappearing project pass silently.',
- ).toEqual([...KNOWN_TEST_PROJECTS].sort());
+ ).toEqual([...EXPECTED_TEST_PROJECTS].sort());
});
test('every non-vitest config in the sweep is a known build config', () => {