Skip to content

Beautiful, AI-native markdown IDE and LLM wiki

Gate 36 environment-dependent tests on declared capabilities (#5243)

Nick Gomez27b67c0f2e3a
diff --git a/knip.config.ts b/knip.config.ts
index be41ab16c..37d9ce912 100644
--- a/knip.config.ts
+++ b/knip.config.ts
@@ -145,11 +145,15 @@ export default {
'packages/server': {
entry: ['src/**/*.test.ts', 'src/parse-worker.ts'],
project: 'src/**',
- ignoreDependencies: ['@types/shell-quote'],
+ ignoreDependencies: [
+ '@types/shell-quote',
+ ],
},
'packages/cli': {
entry: ['src/**/*.test.ts', 'scripts/*.ts', 'tests/**/*.ts', 'src/parse-worker.ts'],
- ignoreDependencies: ['yjs'],
+ ignoreDependencies: [
+ 'yjs',
+ ],
},
'packages/desktop': {
entry: [
diff --git a/packages/app/tests/integration/bug3-source-mode-writeback.test.ts b/packages/app/tests/integration/bug3-source-mode-writeback.test.ts
index 8a60e5826..a28cc2b18 100644
--- a/packages/app/tests/integration/bug3-source-mode-writeback.test.ts
+++ b/packages/app/tests/integration/bug3-source-mode-writeback.test.ts
@@ -1,3 +1,4 @@
+
import { readFileSync } from 'node:fs';
import { join } from 'node:path';
import { setTimeout as wait } from 'node:timers/promises';
diff --git a/packages/app/tests/integration/indented-jsx-byte-sacred.test.ts b/packages/app/tests/integration/indented-jsx-byte-sacred.test.ts
index 6fcdc23f2..4fc2c11f9 100644
--- a/packages/app/tests/integration/indented-jsx-byte-sacred.test.ts
+++ b/packages/app/tests/integration/indented-jsx-byte-sacred.test.ts
@@ -1,3 +1,4 @@
+
import { setTimeout as wait } from 'node:timers/promises';
import { normalizeBridge } from '@inkeep/open-knowledge-core';
import { updateYFragment } from '@tiptap/y-tiptap';
diff --git a/packages/app/tests/integration/interior-edit-freshness.test.ts b/packages/app/tests/integration/interior-edit-freshness.test.ts
index 40b5cdfd6..9f2f6feb6 100644
--- a/packages/app/tests/integration/interior-edit-freshness.test.ts
+++ b/packages/app/tests/integration/interior-edit-freshness.test.ts
@@ -1,3 +1,4 @@
+
import { setTimeout as wait } from 'node:timers/promises';
import { updateYFragment, yXmlFragmentToProseMirrorRootNode } from '@tiptap/y-tiptap';
import { afterAll, beforeAll, describe, expect, test } from 'vitest';
diff --git a/packages/app/tests/integration/keystroke-cadence-danger-space.test.ts b/packages/app/tests/integration/keystroke-cadence-danger-space.test.ts
index 93666af70..2a085742b 100644
--- a/packages/app/tests/integration/keystroke-cadence-danger-space.test.ts
+++ b/packages/app/tests/integration/keystroke-cadence-danger-space.test.ts
@@ -1,3 +1,4 @@
+
import { setTimeout as wait } from 'node:timers/promises';
import { updateYFragment, yXmlFragmentToProseMirrorRootNode } from '@tiptap/y-tiptap';
import { afterAll, beforeAll, describe, expect, test } from 'vitest';
diff --git a/packages/app/tests/integration/kill-gracefully-tree.test.ts b/packages/app/tests/integration/kill-gracefully-tree.test.ts
index 0d678315e..871221a98 100644
--- a/packages/app/tests/integration/kill-gracefully-tree.test.ts
+++ b/packages/app/tests/integration/kill-gracefully-tree.test.ts
@@ -2,6 +2,7 @@ import { type ChildProcess, spawn, spawnSync } from 'node:child_process';
import { once } from 'node:events';
import { setTimeout as wait } from 'node:timers/promises';
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest';
+import { pid1Reaps } from '../../../../test-support/capabilities.test-helper.ts';
import {
installSignalBoundary,
type SignalBoundary,
@@ -178,7 +179,8 @@ describe('killGracefully signals only a tree whose leader it still holds', () =>
}).toEqual({ refused: [], leaderExited: true, descendantReapedOrReported: true });
});
- test('escalates to SIGKILL while the leader is still held when the tree ignores SIGTERM', async () => {
+ test('escalates to SIGKILL while the leader is still held when the tree ignores SIGTERM', async (ctx) => {
+ ctx.skip(!pid1Reaps, 'PID 1 must reap the orphans this test waits on');
const tree = spawnLifelineTree('trap "" TERM; echo READY; while :; do sleep 1; done');
const leaderPid = pidOf(tree.proc);
await awaitOutput(tree, /READY/);
@@ -212,7 +214,8 @@ describe('killGracefully signals only a tree whose leader it still holds', () =>
expect(boundary.refused).toEqual([]);
});
- test('reports no survivor when the leader exits on SIGTERM and its group drains', async () => {
+ test('reports no survivor when the leader exits on SIGTERM and its group drains', async (ctx) => {
+ ctx.skip(!pid1Reaps, 'PID 1 must reap the orphans this test waits on');
const tree = spawnLifelineTree(`${DESCENDANT} & wait`);
const leaderPid = pidOf(tree.proc);
const descendantPid = await reportedDescendant(tree);
diff --git a/packages/app/tests/integration/producer-guard-wiring.test.ts b/packages/app/tests/integration/producer-guard-wiring.test.ts
index 867598d34..878d5196b 100644
--- a/packages/app/tests/integration/producer-guard-wiring.test.ts
+++ b/packages/app/tests/integration/producer-guard-wiring.test.ts
@@ -1,3 +1,4 @@
+
import { setTimeout as wait } from 'node:timers/promises';
import { updateYFragment, yXmlFragmentToProseMirrorRootNode } from '@tiptap/y-tiptap';
import { afterAll, beforeAll, describe, expect, test } from 'vitest';
diff --git a/packages/app/tests/integration/qa-039-reconciliation-counters-http.test.ts b/packages/app/tests/integration/qa-039-reconciliation-counters-http.test.ts
index 0970ac12f..4ada3cf26 100644
--- a/packages/app/tests/integration/qa-039-reconciliation-counters-http.test.ts
+++ b/packages/app/tests/integration/qa-039-reconciliation-counters-http.test.ts
@@ -1,3 +1,4 @@
+
import { randomUUID } from 'node:crypto';
import { afterEach, describe, expect, test } from 'vitest';
import { agentWriteMd, createTestServer, type TestServer } from './test-harness';
diff --git a/packages/app/tests/integration/qa-045-restore-after-gc.test.ts b/packages/app/tests/integration/qa-045-restore-after-gc.test.ts
index b632185e1..cbe2b705f 100644
--- a/packages/app/tests/integration/qa-045-restore-after-gc.test.ts
+++ b/packages/app/tests/integration/qa-045-restore-after-gc.test.ts
@@ -1,3 +1,4 @@
+
import { execFileSync } from 'node:child_process';
import { randomUUID } from 'node:crypto';
import { join } from 'node:path';
diff --git a/packages/app/tests/integration/qa-050-rollback-undo-shipped-path.test.ts b/packages/app/tests/integration/qa-050-rollback-undo-shipped-path.test.ts
index c530ce4ba..89bc9b4d9 100644
--- a/packages/app/tests/integration/qa-050-rollback-undo-shipped-path.test.ts
+++ b/packages/app/tests/integration/qa-050-rollback-undo-shipped-path.test.ts
@@ -1,3 +1,4 @@
+
import { randomUUID } from 'node:crypto';
import { afterAll, afterEach, beforeAll, describe, expect, test } from 'vitest';
import type * as Y from 'yjs';
diff --git a/packages/app/tests/integration/skill-import-bulk.test.ts b/packages/app/tests/integration/skill-import-bulk.test.ts
index a97b2e902..bc6931884 100644
--- a/packages/app/tests/integration/skill-import-bulk.test.ts
+++ b/packages/app/tests/integration/skill-import-bulk.test.ts
@@ -11,6 +11,7 @@ import {
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, test } from 'vitest';
+import { runningAsRoot } from '../../../../test-support/capabilities.test-helper.ts';
import { createTestServer, HARNESS_BOOT_TIMEOUT_MS, type TestServer } from './test-harness.ts';
let srcRoot: string;
@@ -125,7 +126,8 @@ describe('POST /api/skills/import-bulk', () => {
expect(await listedNames()).toContain('alpha-skill');
});
- test('an unreadable bundle fails only itself, not the selection', async () => {
+ test('an unreadable bundle fails only itself, not the selection', async (ctx) => {
+ ctx.skip(runningAsRoot, 'root bypasses the chmod refusal this test induces');
const locked = join(srcRoot, 'bundle', 'locked-skill');
writeSkillDir(locked, 'locked-skill', 'Cannot be read');
chmodSync(locked, 0o000);
diff --git a/packages/app/tests/integration/undo-after-rollback.test.ts b/packages/app/tests/integration/undo-after-rollback.test.ts
index d3767adc9..a78aeb0e4 100644
--- a/packages/app/tests/integration/undo-after-rollback.test.ts
+++ b/packages/app/tests/integration/undo-after-rollback.test.ts
@@ -1,3 +1,4 @@
+
import { ROLLBACK_ORIGIN } from '@inkeep/open-knowledge-server';
import { afterAll, beforeAll, describe, expect, test } from 'vitest';
import * as Y from 'yjs';
diff --git a/packages/app/tests/integration/undo-recycle-reset.test.ts b/packages/app/tests/integration/undo-recycle-reset.test.ts
index b076f955c..e7cc69c3f 100644
--- a/packages/app/tests/integration/undo-recycle-reset.test.ts
+++ b/packages/app/tests/integration/undo-recycle-reset.test.ts
@@ -1,3 +1,4 @@
+
import { writeFileSync } from 'node:fs';
import { join } from 'node:path';
import { setTimeout as wait } from 'node:timers/promises';
diff --git a/packages/app/tests/integration/undo-rederive-survival.test.ts b/packages/app/tests/integration/undo-rederive-survival.test.ts
index 7935e35f8..9ddcd0730 100644
--- a/packages/app/tests/integration/undo-rederive-survival.test.ts
+++ b/packages/app/tests/integration/undo-rederive-survival.test.ts
@@ -1,3 +1,4 @@
+
import { prependFrontmatter } from '@inkeep/open-knowledge-core';
import { Plugin, PluginKey } from '@tiptap/pm/state';
import { updateYFragment, yXmlFragmentToProseMirrorRootNode } from '@tiptap/y-tiptap';
diff --git a/packages/app/tests/meta/copy-excalidraw-assets-concurrency.test.ts b/packages/app/tests/meta/copy-excalidraw-assets-concurrency.test.ts
index d16c1a32e..f8e37672e 100644
--- a/packages/app/tests/meta/copy-excalidraw-assets-concurrency.test.ts
+++ b/packages/app/tests/meta/copy-excalidraw-assets-concurrency.test.ts
@@ -19,6 +19,7 @@ import { setTimeout as wait } from 'node:timers/promises';
import { fileURLToPath, pathToFileURL } from 'node:url';
import { promisify } from 'node:util';
import { afterEach, beforeEach, describe, expect, test } from 'vitest';
+import { runningAsRoot } from '../../../../test-support/capabilities.test-helper.ts';
const execFileAsync = promisify(execFile);
@@ -345,7 +346,8 @@ describe('copy-excalidraw-assets predev step', () => {
expect(strayRootEntries(root)).toEqual([]);
});
- test('a displaced tree that cannot be removed still publishes, and says so', async () => {
+ test('a displaced tree that cannot be removed still publishes, and says so', async (ctx) => {
+ ctx.skip(runningAsRoot, 'root bypasses the chmod refusal this test induces');
seedStaleVendoredDir(root);
chmodSync(join(vendoredDir(root), 'fonts'), 0o500);
diff --git a/packages/cli/src/commands/pi-acp-bridge.test.ts b/packages/cli/src/commands/pi-acp-bridge.test.ts
index 0031c60a2..b6caa12fa 100644
--- a/packages/cli/src/commands/pi-acp-bridge.test.ts
+++ b/packages/cli/src/commands/pi-acp-bridge.test.ts
@@ -20,6 +20,7 @@ import { tmpdir } from 'node:os';
import { dirname, join } from 'node:path';
import lockfile from 'proper-lockfile';
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest';
+import { runningAsRoot } from '../../../../test-support/capabilities.test-helper.ts';
import { buildPiExtensionSource, isOwnPiExtensionSource } from '../integrations/pi-extension.ts';
import { EDITOR_TARGETS, PI_EXTENSION_OWNERSHIP_MARKER } from './editors.ts';
import { removeOwnMcpEntry } from './mcp-config-removal.ts';
@@ -1915,7 +1916,8 @@ describe('folder-scoped trust', () => {
expect(probeReadyPiBridgeState(cwd, home).trust).toBe('trusted');
});
- test('an unreadable extensions folder is kept, not treated as verified empty', async () => {
+ test('an unreadable extensions folder is kept, not treated as verified empty', async (ctx) => {
+ ctx.skip(runningAsRoot, 'root bypasses the chmod refusal this test induces');
const cwd = tmp();
const home = tmp();
await ensurePiBridge(cwd, { mode: 'published' }, home);
diff --git a/packages/cli/src/commands/removal-host-uncertainty.test.ts b/packages/cli/src/commands/removal-host-uncertainty.test.ts
index dea3d204d..d0c4be096 100644
--- a/packages/cli/src/commands/removal-host-uncertainty.test.ts
+++ b/packages/cli/src/commands/removal-host-uncertainty.test.ts
@@ -21,6 +21,7 @@ import { dirname, join } from 'node:path';
import { Readable } from 'node:stream';
import { isProcessAlive } from '@inkeep/open-knowledge-server';
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest';
+import { hasLsof } from '../../../../test-support/capabilities.test-helper.ts';
import { startDefunctProcess } from './defunct-process.test-helper.ts';
import { buildDeinitPlan, runRemoval } from './removal-plan.ts';
import { stopServerForRemoval } from './stop-for-removal.ts';
@@ -278,7 +279,8 @@ describe.skipIf(process.platform === 'win32')(
expect(readFileSync(join(project, 'notes.md'), 'utf8')).toBe('# Keep');
});
- test('refuses removal while a live server is attributable to this project', async () => {
+ test('refuses removal while a live server is attributable to this project', async (ctx) => {
+ ctx.skip(!hasLsof, 'the product inspects processes with lsof');
const server = await startLiveProcess(project);
expect(isProcessAlive(server)).toBe(true);
installHost({ processes: [{ pid: server, command: 'open-knowledge-server notes' }] });
@@ -292,7 +294,8 @@ describe.skipIf(process.platform === 'win32')(
expect(readFileSync(join(project, 'notes.md'), 'utf8')).toBe('# Keep');
});
- test('reports an unreadable process state once per run, not once per probing caller', async () => {
+ test('reports an unreadable process state once per run, not once per probing caller', async (ctx) => {
+ ctx.skip(!hasLsof, 'the product inspects processes with lsof');
const server = await startLiveProcess(project);
installHost({ processes: [{ pid: server, command: 'open-knowledge-server notes' }] });
const binDir = installFailingPsProbe();
diff --git a/packages/cli/src/commands/uninstall-lock-recovery.test.ts b/packages/cli/src/commands/uninstall-lock-recovery.test.ts
index e082b3c63..f055ddf3a 100644
--- a/packages/cli/src/commands/uninstall-lock-recovery.test.ts
+++ b/packages/cli/src/commands/uninstall-lock-recovery.test.ts
@@ -17,6 +17,7 @@ import {
scanLockProcesses,
} from '@inkeep/open-knowledge-server';
import { afterEach, beforeEach, describe, expect, test } from 'vitest';
+import { hasLsof } from '../../../../test-support/capabilities.test-helper.ts';
import {
buildDeinitPlan,
buildUninstallPlan,
@@ -252,14 +253,15 @@ describe.skipIf(process.platform === 'win32')('uninstall lock recovery in an iso
expect(readFileSync(join(project, 'notes.md'), 'utf8')).toBe('# Keep');
});
- test.each([
+ test.for([
{ associated: false, unrecorded: false },
{ associated: true, unrecorded: false },
{ associated: false, unrecorded: true },
{ associated: true, unrecorded: true },
])(
'retains a live foreign or unverified lock (associated=$associated, unrecorded=$unrecorded)',
- async ({ associated, unrecorded }) => {
+ async ({ associated, unrecorded }, ctx) => {
+ ctx.skip(!hasLsof, 'the product inspects processes with lsof');
const home = join(root, 'home');
const settings = join(home, '.ok', 'config.yml');
const project = join(root, 'foreign-project');
diff --git a/packages/cli/src/mcp/keepalive-orphan-reaping.test.ts b/packages/cli/src/mcp/keepalive-orphan-reaping.test.ts
index b33332f18..17e8e1f70 100644
--- a/packages/cli/src/mcp/keepalive-orphan-reaping.test.ts
+++ b/packages/cli/src/mcp/keepalive-orphan-reaping.test.ts
@@ -5,6 +5,7 @@ import { dirname, join } from 'node:path';
import { setTimeout as wait } from 'node:timers/promises';
import { fileURLToPath } from 'node:url';
import { afterEach, describe, expect, test } from 'vitest';
+import { pid1Reaps } from '../../../../test-support/capabilities.test-helper.ts';
const HERE = dirname(fileURLToPath(import.meta.url));
const CLI_ENTRY = join(HERE, '..', '..', 'dist', 'cli.mjs');
@@ -63,7 +64,8 @@ describe('ok mcp orphan reaping (PRD-6917)', () => {
}
});
- test('ok mcp exits when its launching parent dies even if stdin never EOFs (no orphan to launchd)', async () => {
+ test('ok mcp exits when its launching parent dies even if stdin never EOFs (no orphan to launchd)', async (ctx) => {
+ ctx.skip(!pid1Reaps, 'PID 1 must reap the orphans this test waits on');
const dir = mkdtempSync(join(tmpdir(), 'ok-orphan-reaping-'));
cleanups.push(() => rmSync(dir, { recursive: true, force: true }));
diff --git a/packages/core/src/bridge/compose.ts b/packages/core/src/bridge/compose.ts
index f4cc8a286..2a597ec3d 100644
--- a/packages/core/src/bridge/compose.ts
+++ b/packages/core/src/bridge/compose.ts
@@ -1,3 +1,4 @@
+
import { prependFrontmatter, stripFrontmatter } from '../extensions/frontmatter.ts';
export type ComposeAdjustment = 'none' | 'body' | 'frontmatter' | 'unresolved';
diff --git a/packages/core/src/bridge/doc-boundary-space.ts b/packages/core/src/bridge/doc-boundary-space.ts
index 8fb428b90..01ef76a9f 100644
--- a/packages/core/src/bridge/doc-boundary-space.ts
+++ b/packages/core/src/bridge/doc-boundary-space.ts
@@ -1,3 +1,4 @@
+
import { FRONTMATTER_RE, stripFrontmatter } from '../extensions/frontmatter.ts';
import { carriedEdgeEmpties, type DocEdgeEmpties } from '../markdown/doc-edge-blank-runs.ts';
diff --git a/packages/core/src/markdown/comment-promoter.ts b/packages/core/src/markdown/comment-promoter.ts
index fc267cbea..fb0ba5a7c 100644
--- a/packages/core/src/markdown/comment-promoter.ts
+++ b/packages/core/src/markdown/comment-promoter.ts
@@ -1,3 +1,4 @@
+
import type { Nodes, Paragraph, PhrasingContent, Root, RootContent, Text } from 'mdast';
import { SKIP, visit } from 'unist-util-visit';
import type { VFile } from 'vfile';
diff --git a/packages/core/src/markdown/merged-walker.ts b/packages/core/src/markdown/merged-walker.ts
index bfd7e3109..fa3cfcd86 100644
--- a/packages/core/src/markdown/merged-walker.ts
+++ b/packages/core/src/markdown/merged-walker.ts
@@ -1,3 +1,4 @@
+
import type { Nodes, Parent, Root } from 'mdast';
import { SKIP, visit } from 'unist-util-visit';
import type { VFile } from 'vfile';
diff --git a/packages/core/src/markdown/safe-url.ts b/packages/core/src/markdown/safe-url.ts
index 4d3250d3a..8be632ba4 100644
--- a/packages/core/src/markdown/safe-url.ts
+++ b/packages/core/src/markdown/safe-url.ts
@@ -1,3 +1,4 @@
+
export const SAFE_URL_SCHEMES = ['https', 'http', 'mailto', 'tel', 'ftp', 'sms'] as const;
const SCHEME_ALT = SAFE_URL_SCHEMES.map((s) => `${s}:`).join('|');
diff --git a/packages/core/src/shadow-repo-layout.test.ts b/packages/core/src/shadow-repo-layout.test.ts
index c6e32b776..10340bd44 100644
--- a/packages/core/src/shadow-repo-layout.test.ts
+++ b/packages/core/src/shadow-repo-layout.test.ts
@@ -3,6 +3,7 @@ import { mkdtemp, rm } from 'node:fs/promises';
import { tmpdir } from 'node:os';
import { resolve } from 'node:path';
import { afterEach, beforeEach, describe, expect, test } from 'vitest';
+import { runningAsRoot } from '../../../test-support/capabilities.test-helper.ts';
import {
COMMIT_SUBJECT_MAX_LEN,
composeCommitSubject,
@@ -403,7 +404,8 @@ describe('resolveShadowDir', () => {
expect(e.message).toContain('git worktree prune');
});
- test('threads the underlying readFileSync error as `cause` when the .git pointer is unreadable', () => {
+ test('threads the underlying readFileSync error as `cause` when the .git pointer is unreadable', (ctx) => {
+ ctx.skip(runningAsRoot, 'root bypasses the chmod refusal this test induces');
const project = resolve(tmp, 'unreadable');
mkdirSync(project, { recursive: true });
const gitPath = resolve(project, '.git');
@@ -433,7 +435,8 @@ describe('resolveShadowDir', () => {
expect(['EACCES', 'EPERM']).toContain(causeCode);
});
- test('throws GitDirAccessError (not MalformedGitPointerError) when statSync fails with non-ENOENT', () => {
+ test('throws GitDirAccessError (not MalformedGitPointerError) when statSync fails with non-ENOENT', (ctx) => {
+ ctx.skip(runningAsRoot, 'root bypasses the chmod refusal this test induces');
const project = resolve(tmp, 'unstattable');
mkdirSync(project, { recursive: true });
writeFileSync(resolve(project, '.git'), 'gitdir: /tmp/whatever\n');
@@ -605,7 +608,8 @@ describe('getShadowRepoPath', () => {
expect(getShadowRepoPath(project)).toBe(null);
});
- test('swallows GitDirAccessError, returns null — preserves string|null contract on EACCES', () => {
+ test('swallows GitDirAccessError, returns null — preserves string|null contract on EACCES', (ctx) => {
+ ctx.skip(runningAsRoot, 'root bypasses the chmod refusal this test induces');
const project = resolve(tmp, 'eaccess-probe');
mkdirSync(project, { recursive: true });
writeFileSync(resolve(project, '.git'), 'gitdir: /tmp/whatever\n');
diff --git a/packages/desktop/src/main/create-new-project.test.ts b/packages/desktop/src/main/create-new-project.test.ts
index 0787f995d..1fabf6542 100644
--- a/packages/desktop/src/main/create-new-project.test.ts
+++ b/packages/desktop/src/main/create-new-project.test.ts
@@ -13,6 +13,7 @@ import { tmpdir } from 'node:os';
import { join, resolve } from 'node:path';
import { ALL_EDITOR_IDS } from '@inkeep/open-knowledge-core';
import { afterEach, beforeEach, describe, expect, test } from 'vitest';
+import { runningAsRoot } from '../../../../test-support/capabilities.test-helper.ts';
import {
CreateNewProjectError,
folderState,
@@ -516,7 +517,8 @@ describe('runCreateNew — defense-in-depth rejections', () => {
expect(result.target).toBe(join(tmpRoot, 'escape'));
});
- test('surfaces mkdir-failed when the parent is not writable', async () => {
+ test('surfaces mkdir-failed when the parent is not writable', async (ctx) => {
+ ctx.skip(runningAsRoot, 'root bypasses the chmod refusal this test induces');
const parent = join(tmpRoot, 'readonly');
mkdirSync(parent);
chmodSync(parent, 0o555);
diff --git a/packages/desktop/src/main/read-git-dir-kind.test.ts b/packages/desktop/src/main/read-git-dir-kind.test.ts
index a037a2b6a..18c0da66e 100644
--- a/packages/desktop/src/main/read-git-dir-kind.test.ts
+++ b/packages/desktop/src/main/read-git-dir-kind.test.ts
@@ -12,6 +12,7 @@ import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { promisify } from 'node:util';
import { afterEach, describe, expect, test } from 'vitest';
+import { runningAsRoot } from '../../../../test-support/capabilities.test-helper.ts';
import { readGitDirKind } from './read-git-dir-kind.ts';
const execFileAsync = promisify(execFile);
@@ -80,7 +81,8 @@ describe('readGitDirKind', () => {
expect(readGitDirKind(sub)).toBe('absent');
});
- test('returns "inaccessible" for a real checkout whose gitdir cannot be traversed', () => {
+ test('returns "inaccessible" for a real checkout whose gitdir cannot be traversed', (ctx) => {
+ ctx.skip(runningAsRoot, 'root bypasses the chmod refusal this test induces');
testRoot = realpathSync(mkdtempSync(join(tmpdir(), 'gitdir-kind-')));
const gitDir = join(testRoot, '.git');
mkdirSync(gitDir, { recursive: true });
diff --git a/packages/desktop/tests/utility/pty-host-reap.test.ts b/packages/desktop/tests/utility/pty-host-reap.test.ts
index 6515bbf71..29e42e10e 100644
--- a/packages/desktop/tests/utility/pty-host-reap.test.ts
+++ b/packages/desktop/tests/utility/pty-host-reap.test.ts
@@ -3,6 +3,7 @@ import { once } from 'node:events';
import { Readable } from 'node:stream';
import { isProcessAlive } from '@inkeep/open-knowledge-server';
import { describe, expect, test } from 'vitest';
+import { pid1Reaps } from '../../../../test-support/capabilities.test-helper.ts';
const HARNESS = new URL('./pty-host.reap-harness.ts', import.meta.url).pathname;
@@ -64,7 +65,8 @@ describe.skipIf(process.platform === 'win32')(
await assertNoOrphan('SIGTERM');
}, 60_000);
- test('a SIGKILL to the host leaves no orphan shell (OS backstop, no handler runs)', async () => {
+ test('a SIGKILL to the host leaves no orphan shell (OS backstop, no handler runs)', async (ctx) => {
+ ctx.skip(!pid1Reaps, 'PID 1 must reap the orphans this test waits on');
await assertNoOrphan('SIGKILL');
}, 60_000);
},
diff --git a/packages/desktop/tests/utility/pty-host-support-file.test.ts b/packages/desktop/tests/utility/pty-host-support-file.test.ts
index 98f803040..a0569d8d0 100644
--- a/packages/desktop/tests/utility/pty-host-support-file.test.ts
+++ b/packages/desktop/tests/utility/pty-host-support-file.test.ts
@@ -13,6 +13,7 @@ import {
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { afterEach, beforeEach, describe, expect, test } from 'vitest';
+import { runningAsRoot } from '../../../../test-support/capabilities.test-helper.ts';
import {
type PtyHostOutgoingMessage,
type PtyProcessLike,
@@ -235,7 +236,8 @@ describe('production support-file writer', () => {
test.skipIf(process.platform === 'win32')(
'keeps a permission failure distinct from a containment refusal',
- () => {
+ (ctx) => {
+ ctx.skip(runningAsRoot, 'root bypasses the chmod refusal this test induces');
const locked = join(outside, 'locked');
const target = join(locked, 'target');
mkdirSync(target, { recursive: true });
diff --git a/packages/server/src/acp/acquisition-contract.test-helper.ts b/packages/server/src/acp/acquisition-contract.test-helper.ts
index c364af40c..d23dbb73b 100644
--- a/packages/server/src/acp/acquisition-contract.test-helper.ts
+++ b/packages/server/src/acp/acquisition-contract.test-helper.ts
@@ -17,7 +17,10 @@ import {
type AcquisitionFactory = (run: (home: string) => Promise<void>) => Promise<void>;
-export function acquisitionFailureContract(factory: AcquisitionFactory): void {
+export function acquisitionFailureContract(
+ factory: AcquisitionFactory,
+ { uvxOnAgentSpawnPath = true }: { uvxOnAgentSpawnPath?: boolean } = {},
+): void {
const log = getLogger('acquisition-contract');
describe('native acquisition contract', () => {
test('an admitted exact package keeps its pin', async () => {
@@ -33,7 +36,11 @@ export function acquisitionFailureContract(factory: AcquisitionFactory): void {
expect(launch.args).toEqual(['-y', '[email protected]', '--version']);
});
});
- test('uvx retains the native cutoff refusal', async () => {
+ test('uvx retains the native cutoff refusal', async (ctx) => {
+ ctx.skip(
+ !uvxOnAgentSpawnPath,
+ 'uvx must be available to exercise its native acquisition refusal',
+ );
await factory(async (home) => {
process.env.UV_EXCLUDE_NEWER = '1970-01-01';
const launch = await resolveRegistryLaunch(
diff --git a/packages/server/src/acp/launch-package-acquisition.test.ts b/packages/server/src/acp/launch-package-acquisition.test.ts
index 8783ce85b..67491dc53 100644
--- a/packages/server/src/acp/launch-package-acquisition.test.ts
+++ b/packages/server/src/acp/launch-package-acquisition.test.ts
@@ -3,12 +3,16 @@ import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
import { createServer } from 'node:http';
import { join } from 'node:path';
import { describe, expect, test } from 'vitest';
+import {
+ executableFacts,
+ findExecutable,
+} from '../../../../test-support/capabilities.test-helper.ts';
import { getLogger } from '../logger.ts';
import {
acquisitionFailureContract,
withLocalAcquisitionRegistry,
} from './acquisition-contract.test-helper.ts';
-import { AgentLaunchError, resolveRegistryLaunch } from './launch.ts';
+import { AgentLaunchError, agentSpawnPath, resolveRegistryLaunch } from './launch.ts';
import {
installNodeFixture,
npmNative,
@@ -21,7 +25,9 @@ import {
const log = getLogger('package-acquisition-test');
-acquisitionFailureContract(withLocalAcquisitionRegistry);
+acquisitionFailureContract(withLocalAcquisitionRegistry, {
+ uvxOnAgentSpawnPath: findExecutable('uvx', agentSpawnPath(), executableFacts),
+});
describe('hermetic package acquisition and native dispatch', () => {
test('the fixture latest tag is independent of release insertion order', async () => {
diff --git a/packages/server/src/acp/launch.test.ts b/packages/server/src/acp/launch.test.ts
index f6bb0bd5a..a4723e458 100644
--- a/packages/server/src/acp/launch.test.ts
+++ b/packages/server/src/acp/launch.test.ts
@@ -14,6 +14,7 @@ import { homedir, tmpdir } from 'node:os';
import { delimiter, join } from 'node:path';
import { OK_HOSTED_AGENT_ENV } from '@inkeep/open-knowledge-core';
import { afterEach, describe, expect, test, vi } from 'vitest';
+import { pid1Reaps } from '../../../../test-support/capabilities.test-helper.ts';
import { getLogger, type PinoLogger } from '../logger.ts';
import { withLocalAcquisitionRegistry } from './acquisition-contract.test-helper.ts';
import { createDiagnosticStderrCapture } from './diagnostics.ts';
@@ -1036,7 +1037,8 @@ describe.skipIf(process.platform === 'win32')('probeInterpreterHealth', () => {
expect(detail).not.toBeNull();
});
- test('a hung probe times out as healthy and does not leak the process', async () => {
+ test('a hung probe times out as healthy and does not leak the process', async (ctx) => {
+ ctx.skip(!pid1Reaps, 'PID 1 must reap the orphans this test waits on');
const dir = tmp();
const kidPidFile = join(dir, 'kid.pid');
writeFileSync(
diff --git a/packages/server/src/acp/thread-manager.integration.test.ts b/packages/server/src/acp/thread-manager.integration.test.ts
index 7502725df..b028e4233 100644
--- a/packages/server/src/acp/thread-manager.integration.test.ts
+++ b/packages/server/src/acp/thread-manager.integration.test.ts
@@ -20,6 +20,12 @@ import type {
import { THREAD_REOPEN_OP_TIMEOUT_MS } from '@inkeep/open-knowledge-core/acp/thread-protocol';
import { afterEach, describe, expect, test, vi } from 'vitest';
import * as Y from 'yjs';
+import {
+ executableFacts,
+ findExecutable,
+ hasUvx,
+ pid1Reaps,
+} from '../../../../test-support/capabilities.test-helper.ts';
import codexFixture from '../../../../test-support/fixtures/codex-legacy-warning-envelopes.json' with {
type: 'json',
};
@@ -31,6 +37,7 @@ import { isValidLockPid } from '../process-alive.ts';
import { RUNTIME_VERSION } from '../version-constants.ts';
import { withLocalAcquisitionRegistry } from './acquisition-contract.test-helper.ts';
import { isWithin } from './archive.ts';
+import { agentSpawnPath } from './launch.ts';
import {
installNodeFixture,
npmCli,
@@ -168,9 +175,14 @@ function stagedSkillNote(localDir: string): string {
}
describe('package acquisition failure projection', () => {
- test.each(['npx', 'uvx'] as const)(
+ test.for(['npx', 'uvx'] as const)(
'%s start and retry retain actionable native refusal and clean up',
- async (runtime) => {
+ { timeout: 90_000 },
+ async (runtime, ctx) => {
+ ctx.skip(
+ runtime === 'uvx' && !findExecutable('uvx', agentSpawnPath(), executableFacts),
+ 'uvx must be available to exercise its native acquisition refusal',
+ );
await withLocalAcquisitionRegistry(async (home) => {
process.env.npm_config_before = '1970-01-01';
process.env.UV_EXCLUDE_NEWER = '1970-01-01';
@@ -246,12 +258,16 @@ describe('package acquisition failure projection', () => {
}
});
},
- 90_000,
);
- test.each(['npx', 'uvx'] as const)(
+ test.for(['npx', 'uvx'] as const)(
'%s resume exposes typed install-failed after real native acquisition refusal',
- async (runtime) => {
+ { timeout: 90_000 },
+ async (runtime, ctx) => {
+ ctx.skip(
+ runtime === 'uvx' && !hasUvx,
+ 'uvx must be available to exercise its native acquisition refusal',
+ );
await withLocalAcquisitionRegistry(async (home) => {
const realNpx = npmCli('npx');
const realNpm = npmCli('npm');
@@ -331,10 +347,10 @@ describe('package acquisition failure projection', () => {
}
});
},
- 90_000,
);
- test('a ceiling-sized acquisition primary preserves its headline and a distinct stderr tail', async () => {
+ test('a ceiling-sized acquisition primary preserves its headline and a distinct stderr tail', async (ctx) => {
+ ctx.skip(!hasUvx, 'uvx must be available to exercise its native acquisition refusal');
await withLocalAcquisitionRegistry(async (home) => {
const localDir = tmp();
const bin = join(home, 'bin');
@@ -530,7 +546,8 @@ describe('AcpThreadManager (real subprocess)', () => {
expect(manager.listThreads()[0]?.archived).toBe(true);
}, 45_000);
- test('closeThread kills a SIGTERM-ignoring agent tree before resolving', async () => {
+ test('closeThread kills a SIGTERM-ignoring agent tree before resolving', async (ctx) => {
+ ctx.skip(!pid1Reaps, 'PID 1 must reap the orphans this test waits on');
const contentDir = tmp();
const localDir = tmp();
const kidPidFile = join(localDir, 'kid.pid');
diff --git a/packages/server/src/lint/frontmatter-schemas.test.ts b/packages/server/src/lint/frontmatter-schemas.test.ts
index 73a0f098d..f3d58d83e 100644
--- a/packages/server/src/lint/frontmatter-schemas.test.ts
+++ b/packages/server/src/lint/frontmatter-schemas.test.ts
@@ -17,6 +17,7 @@ import {
SUPPORTED_SCHEMA_DIALECTS,
} from '@inkeep/open-knowledge-core';
import { afterEach, beforeEach, describe, expect, test } from 'vitest';
+import { runningAsRoot } from '../../../../test-support/capabilities.test-helper.ts';
import {
listProjectSchemaFiles,
resolveFrontmatterSchemas,
@@ -218,7 +219,8 @@ describe('resolveFrontmatterSchemas — escape guards', () => {
expect(entries[0]?.key).toBe(realpathSync(join(projectDir, 'real/doc.schema.json')));
});
- test('an unreadable file is a cannot-read problem', () => {
+ test('an unreadable file is a cannot-read problem', (ctx) => {
+ ctx.skip(runningAsRoot, 'root bypasses the chmod refusal this test induces');
const abs = write('locked.json', GOOD_SCHEMA);
chmodSync(abs, 0o000);
const { problems } = resolveFrontmatterSchemas(projectDir, [{ file: 'locked.json' }]);
diff --git a/packages/server/src/server-factory.test.ts b/packages/server/src/server-factory.test.ts
index 2729487e4..093b81918 100644
--- a/packages/server/src/server-factory.test.ts
+++ b/packages/server/src/server-factory.test.ts
@@ -30,6 +30,7 @@ import simpleGit from 'simple-git';
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest';
import { stringify as stringifyYaml } from 'yaml';
import * as Y from 'yjs';
+import { runningAsRoot } from '../../../test-support/capabilities.test-helper.ts';
import { MAX_AGENT_SESSIONS } from './agent-sessions.ts';
import { BacklinkIndex } from './backlink-index.ts';
import { getBootTimings, resetBootTimingsForTest, startBootTimings } from './boot-timings.ts';
@@ -648,7 +649,8 @@ describe('createServer().destroy() — graceful shutdown flush', () => {
expect(rescueLogs[0].payload.docName).toBe('pathological-doc');
});
- test('destroy() deliberately rescues and unloads a refused-store doc instead of stranding it to the timeout', async () => {
+ test('destroy() deliberately rescues and unloads a refused-store doc instead of stranding it to the timeout', async (ctx) => {
+ ctx.skip(runningAsRoot, 'root bypasses the chmod refusal this test induces');
const projectDir = tmpDir;
const contentDir = join(tmpDir, 'content');
mkdirSync(contentDir, { recursive: true });
@@ -729,7 +731,8 @@ describe('createServer().destroy() — graceful shutdown flush', () => {
}
});
- test('destroy() rescues a doc refused before shutdown that the unload loop would otherwise destroy', async () => {
+ test('destroy() rescues a doc refused before shutdown that the unload loop would otherwise destroy', async (ctx) => {
+ ctx.skip(runningAsRoot, 'root bypasses the chmod refusal this test induces');
const projectDir = tmpDir;
const contentDir = join(tmpDir, 'content');
mkdirSync(contentDir, { recursive: true });
@@ -846,7 +849,8 @@ describe('createServer().destroy() — graceful shutdown flush', () => {
}
});
- test('a later refused store refreshes the runtime rescue buffer with the newest content', async () => {
+ test('a later refused store refreshes the runtime rescue buffer with the newest content', async (ctx) => {
+ ctx.skip(runningAsRoot, 'root bypasses the chmod refusal this test induces');
const projectDir = tmpDir;
const contentDir = join(tmpDir, 'content');
mkdirSync(contentDir, { recursive: true });
@@ -924,7 +928,8 @@ describe('createServer().destroy() — graceful shutdown flush', () => {
}
});
- test('destroy() leaves a refused-store doc loaded when its shutdown rescue cannot write and reports it lost', async () => {
+ test('destroy() leaves a refused-store doc loaded when its shutdown rescue cannot write and reports it lost', async (ctx) => {
+ ctx.skip(runningAsRoot, 'root bypasses the chmod refusal this test induces');
const projectDir = tmpDir;
const contentDir = join(tmpDir, 'content');
mkdirSync(contentDir, { recursive: true });
@@ -1029,7 +1034,8 @@ describe('createServer().destroy() — graceful shutdown flush', () => {
}
});
- test('destroy() leaves a refused-store doc to the flush timeout when its unload hangs past the deadline and reports the late completion', async () => {
+ test('destroy() leaves a refused-store doc to the flush timeout when its unload hangs past the deadline and reports the late completion', async (ctx) => {
+ ctx.skip(runningAsRoot, 'root bypasses the chmod refusal this test induces');
const projectDir = tmpDir;
const contentDir = join(tmpDir, 'content');
mkdirSync(contentDir, { recursive: true });
@@ -1124,7 +1130,8 @@ describe('createServer().destroy() — graceful shutdown flush', () => {
}
}, 30_000);
- test('destroy() does not hand a second refused-store doc a budget the first one already spent', async () => {
+ test('destroy() does not hand a second refused-store doc a budget the first one already spent', async (ctx) => {
+ ctx.skip(runningAsRoot, 'root bypasses the chmod refusal this test induces');
const projectDir = tmpDir;
const contentDir = join(tmpDir, 'content');
mkdirSync(contentDir, { recursive: true });
@@ -1212,7 +1219,8 @@ describe('createServer().destroy() — graceful shutdown flush', () => {
}
}, 40_000);
- test('a shadowless server logs and counts the rescue losses the flush timeout and skipped mints declare', async () => {
+ test('a shadowless server logs and counts the rescue losses the flush timeout and skipped mints declare', async (ctx) => {
+ ctx.skip(runningAsRoot, 'root bypasses the chmod refusal this test induces');
const projectDir = tmpDir;
const contentDir = join(tmpDir, 'content');
mkdirSync(contentDir, { recursive: true });
@@ -6515,7 +6523,8 @@ describe('createServer() — disk-event reconcile with an absent reconciled base
}
}, 30_000);
- test('an ingest whose rescue writes all fail is not reported as a clean ingest', async () => {
+ test('an ingest whose rescue writes all fail is not reported as a clean ingest', async (ctx) => {
+ ctx.skip(runningAsRoot, 'root bypasses the chmod refusal this test induces');
rig = await setupReconcileRig('ok-reconcile-rescue-write-failure-');
const docName = 'rescue-write-failure-target';
const initial =
@@ -6601,7 +6610,8 @@ describe('createServer() — disk-event reconcile with an absent reconciled base
}
}, 45_000);
- test('an ingest that loses its rescue and then fails to apply is not counted as an unrescued clean ingest', async () => {
+ test('an ingest that loses its rescue and then fails to apply is not counted as an unrescued clean ingest', async (ctx) => {
+ ctx.skip(runningAsRoot, 'root bypasses the chmod refusal this test induces');
rig = await setupReconcileRig('ok-reconcile-compound-ingest-failure-');
const docName = 'compound-ingest-failure-target';
const initial =
@@ -6693,7 +6703,8 @@ describe('createServer() — disk-event reconcile with an absent reconciled base
await server.destroy();
}
}, 45_000);
- test('an ingest that loses its rescue and then fails to apply after the live Y.Text is overwritten is reported as an unrescued loss', async () => {
+ test('an ingest that loses its rescue and then fails to apply after the live Y.Text is overwritten is reported as an unrescued loss', async (ctx) => {
+ ctx.skip(runningAsRoot, 'root bypasses the chmod refusal this test induces');
rig = await setupReconcileRig('ok-reconcile-post-write-ingest-failure-');
const docName = 'post-write-ingest-failure-target';
const initial =
diff --git a/scripts/check-known-reds.uncached.test.mjs b/scripts/check-known-reds.uncached.test.mjs
index cdf2215d8..88b464f8e 100644
--- a/scripts/check-known-reds.uncached.test.mjs
+++ b/scripts/check-known-reds.uncached.test.mjs
@@ -486,6 +486,34 @@ describe('known-reds feed: gate atoms and title chains', () => {
expect(atomsOf(source)).toEqual([atoms]);
});
+ test.each([
+ ['import { hasLsof } from "../test-support/capabilities.test-helper.ts";', 'hasLsof'],
+ [
+ 'import { hasLsof as present } from "../test-support/capabilities.test-helper.ts";',
+ 'present',
+ ],
+ ['import present from "../test-support/capabilities.test-helper.ts";', 'present'],
+ ['import * as present from "../test-support/capabilities.test-helper.ts";', 'present'],
+ ])('attributes a statically imported condition to its module: %s', (imported, condition) => {
+ const source = `${imported}\ntest('x', (ctx) => { ctx.skip(!${condition}, 'requires the tool'); });`;
+ expect(atomsOf(source)).toEqual([
+ [{ kind: 'import', name: '../test-support/capabilities.test-helper.ts', text: condition }],
+ ]);
+ });
+
+ test('a local binding shadows a statically imported capability', () => {
+ const source = [
+ 'import { hasLsof } from "../test-support/capabilities.test-helper.ts";',
+ "test('x', (ctx) => {",
+ ' const hasLsof = localProbe();',
+ " ctx.skip(!hasLsof, 'requires the local tool');",
+ '});',
+ ].join('\n');
+ expect(atomsOf(source)).toEqual([
+ [{ kind: 'runtime', name: 'localProbe()', text: 'localProbe()' }],
+ ]);
+ });
+
test('follows aliases to the facts they read', () => {
const source = [
"const ON_WINDOWS = process.platform === 'win32';",
@@ -1038,7 +1066,10 @@ describe('known-reds through its real invocation', () => {
write('packages/app/tests/stress/hide.e2e.ts', playwrightPin(''));
write(
'packages/app/src/helper.test-helper.ts',
- "test.skip(process.env.CI, 'not a test file');\n",
+ [
+ "import { hasLsof } from '../../../../test-support/capabilities.test-helper.ts';",
+ "test('helper contract', (ctx) => { ctx.skip(!hasLsof, 'the product inspects processes with lsof'); });",
+ ].join('\n'),
);
write('reports/spike/probe.test.ts', "test.skip(process.env.CI, 'evidence');\n");
write('specs/spike/probe.e2e.ts', "test.skip(process.env.CI, 'evidence');\n");
@@ -1050,15 +1081,40 @@ describe('known-reds through its real invocation', () => {
encoding: 'utf8',
});
- test('scans exactly the test files a runner could run', () => {
+ test('scans test files and helpers that can declare their tests', () => {
expect(init.status).toBe(0);
expect(listTestFiles(root)).toEqual([
+ 'packages/app/src/helper.test-helper.ts',
'packages/app/tests/stress/hide.e2e.ts',
'packages/server/src/planted-boot.test.ts',
'packages/server/src/spawn.test.ts',
]);
});
+ test('lists a reasoned environment gate declared in a helper file', () => {
+ const report = scanTree(root);
+ expect(report.envGates).toEqual([
+ {
+ path: 'packages/app/src/helper.test-helper.ts',
+ line: 2,
+ form: 'context-skip',
+ scope: 'test',
+ condition: '!hasLsof',
+ skipWhen: 'condition',
+ ci: null,
+ reason: 'the product inspects processes with lsof',
+ atoms: [
+ {
+ kind: 'import',
+ name: '../../../../test-support/capabilities.test-helper.ts',
+ text: 'hasLsof',
+ },
+ ],
+ titles: ['helper contract'],
+ },
+ ]);
+ });
+
test('finds every planted violation', () => {
const report = scanTree(root);
const violations = validate(report, { today: TODAY, allowlist: NO_ALLOWLIST });
@@ -1080,7 +1136,7 @@ describe('known-reds through its real invocation', () => {
expect(run.status).toBe(1);
const feed = JSON.parse(run.stdout);
expect(feed.schemaVersion).toBe(2);
- expect(feed.files).toBe(3);
+ expect(feed.files).toBe(4);
expect(feed.violations.map((violation) => violation.rule)).toEqual(
expect.arrayContaining(['pin-retries', 'ci-skip', 'early-return']),
);
@@ -1135,7 +1191,7 @@ describe('known-reds through its real invocation', () => {
});
expect(run.status).toBe(1);
expect(run.stdout).toContain('Known reds in open-knowledge on ');
- expect(run.stdout).toContain(': 3 test files scanned.');
+ expect(run.stdout).toContain(': 4 test files scanned.');
expect(run.stdout).toContain(
'packages/server/src/planted-boot.test.ts:2 file process.env.CI',
);
diff --git a/scripts/known-reds.mjs b/scripts/known-reds.mjs
index 799c95e17..47976cedc 100644
--- a/scripts/known-reds.mjs
+++ b/scripts/known-reds.mjs
@@ -21,7 +21,7 @@ export const CONVENTION_DOC = 'test-support/KNOWN-REDS.md';
export const MIN_SIGNATURE_LITERAL = 4;
export const EXPIRY_WARNING_DAYS = 14;
-const TEST_FILE = /\.test\.[cm]?[jt]sx?$|\.e2e\.tsx?$/;
+const TEST_FILE = /\.test\.[cm]?[jt]sx?$|\.e2e\.tsx?$|\.test-helper\.[cm]?[jt]sx?$/;
const PLAYWRIGHT_FILE = /\.e2e\.tsx?$/;
const ISSUE_URL =
/^https:\/\/(?:github\.com\/inkeep\/[\w.-]+\/issues\/\d+|linear\.app\/inkeep\/issue\/[A-Z]+-\d+(?:\/[\w-]*)?)$/;
@@ -744,6 +744,10 @@ function conditionAtoms(condition, context) {
}
if (ts.isIdentifier(node)) {
const binding = visibleBinding(node, node.text);
+ if (binding?.imported) {
+ add('import', binding.imported.module, textNode);
+ return;
+ }
const initializer = binding?.initializer ?? null;
if (initializer && !following.has(initializer)) {
const specifier = importSpecifier(initializer, sourceFile);
diff --git a/test-support/capabilities.test-helper.ts b/test-support/capabilities.test-helper.ts
new file mode 100644
index 000000000..7eed28f0c
--- /dev/null
+++ b/test-support/capabilities.test-helper.ts
@@ -0,0 +1,69 @@
+import { accessSync, constants, readFileSync, statSync } from 'node:fs';
+import { posix, win32 } from 'node:path';
+
+type ExecutableFacts = {
+ platform: NodeJS.Platform;
+ pathExt?: string;
+ isExecutableFile: (path: string) => boolean;
+};
+
+export function probeRunningAsRoot(uid: number | undefined): boolean {
+ return uid === 0;
+}
+
+export function findExecutable(
+ command: string,
+ path: string | undefined,
+ { platform, pathExt, isExecutableFile }: ExecutableFacts,
+): boolean {
+ if (platform === 'win32') {
+ const extensions = (pathExt ?? '.COM;.EXE;.BAT;.CMD')
+ .split(';')
+ .map((extension) => extension.trim())
+ .filter((extension) => extension !== '');
+ return (path ?? '')
+ .split(';')
+ .some(
+ (directory) =>
+ directory !== '' &&
+ extensions.some((extension) =>
+ isExecutableFile(win32.join(directory, command + extension)),
+ ),
+ );
+ }
+ return (path ?? '/usr/bin:/bin')
+ .split(':')
+ .some((directory) => isExecutableFile(posix.join(directory, command)));
+}
+
+export function probePid1Reaps(comm: string | undefined): boolean {
+ return comm?.trim() !== 'sleep';
+}
+
+function isExecutableFile(path: string): boolean {
+ try {
+ accessSync(path, constants.X_OK);
+ return statSync(path).isFile();
+ } catch {
+ return false;
+ }
+}
+
+function pid1Comm(): string | undefined {
+ try {
+ return readFileSync('/proc/1/comm', 'utf8');
+ } catch {
+ return undefined;
+ }
+}
+
+export const executableFacts: ExecutableFacts = {
+ platform: process.platform,
+ pathExt: process.env.PATHEXT,
+ isExecutableFile,
+};
+
+export const runningAsRoot = probeRunningAsRoot(process.getuid?.());
+export const hasLsof = findExecutable('lsof', process.env.PATH, executableFacts);
+export const hasUvx = findExecutable('uvx', process.env.PATH, executableFacts);
+export const pid1Reaps = probePid1Reaps(pid1Comm());
diff --git a/test-support/capabilities.test.ts b/test-support/capabilities.test.ts
new file mode 100644
index 000000000..ec09243a3
--- /dev/null
+++ b/test-support/capabilities.test.ts
@@ -0,0 +1,86 @@
+import { describe, expect, test } from 'vitest';
+import { findExecutable, probePid1Reaps, probeRunningAsRoot } from './capabilities.test-helper.ts';
+
+describe('environment capability probes', () => {
+ test.each([
+ { uid: 0, root: true },
+ { uid: 501, root: false },
+ { uid: undefined, root: false },
+ ])('identifies uid $uid as root=$root', ({ uid, root }) => {
+ expect(probeRunningAsRoot(uid)).toBe(root);
+ });
+
+ test.each(['lsof', 'uvx'] as const)('%s must be executable on PATH', (command) => {
+ const executable = `/tools/${command}`;
+ const input = {
+ path: '/empty:/tools',
+ platform: 'linux' as const,
+ isExecutableFile: (path: string) => path === executable,
+ };
+ expect(findExecutable(command, input.path, input)).toBe(true);
+ expect(findExecutable(command, '/empty', input)).toBe(false);
+ expect(findExecutable(command, input.path, { ...input, isExecutableFile: () => false })).toBe(
+ false,
+ );
+ });
+
+ test('a POSIX empty PATH entry searches the current directory', () => {
+ expect(
+ findExecutable('uvx', '/empty:', {
+ platform: 'darwin',
+ isExecutableFile: (path) => path === 'uvx',
+ }),
+ ).toBe(true);
+ });
+
+ test('an unset POSIX PATH uses the process spawn default', () => {
+ expect(
+ findExecutable('lsof', undefined, {
+ platform: 'linux',
+ isExecutableFile: (path) => path === '/usr/bin/lsof',
+ }),
+ ).toBe(true);
+ });
+
+ test('Windows uvx uses the product PATHEXT search', () => {
+ const input = {
+ path: 'C:\\empty;C:\\tools',
+ platform: 'win32' as const,
+ pathExt: '.COM; .EXE; ;.CMD',
+ isExecutableFile: (path: string) => path === 'C:\\tools\\uvx.EXE',
+ };
+ expect(findExecutable('uvx', input.path, input)).toBe(true);
+ expect(findExecutable('uvx', 'C:\\empty', input)).toBe(false);
+ });
+
+ test.each(['systemd', 'init', 'tini', 'docker-init', 'dumb-init', 'catatonit'])(
+ 'PID 1 %s is a recognized reaper',
+ (comm) => {
+ expect(probePid1Reaps(`${comm}\n`)).toBe(true);
+ },
+ );
+
+ test.each(['sleep', 'sleep\n'])('PID 1 %j is the observed non-reaper', (comm) => {
+ expect(probePid1Reaps(comm)).toBe(false);
+ });
+
+ test.each(['bash', 'node', 'launchd', 'runner-init', 'sleepy', ''])(
+ 'PID 1 %j has not been observed to leave orphans unreaped',
+ (comm) => {
+ expect(probePid1Reaps(comm)).toBe(true);
+ },
+ );
+
+ test('uses the supplied search path for an augmented uvx lookup', () => {
+ const facts = {
+ platform: 'darwin' as const,
+ isExecutableFile: (path: string) => path === '/opt/homebrew/bin/uvx',
+ };
+ expect(findExecutable('uvx', '/empty', facts)).toBe(false);
+ expect(findExecutable('uvx', '/empty:/opt/homebrew/bin', facts)).toBe(true);
+ });
+
+ test('an unreadable proc comm does not reject macOS or Windows', () => {
+ expect(probePid1Reaps(undefined)).toBe(true);
+ });
+});