Skip to content

Commit a605029

Browse files
committed
chore(lint): forbid node:os in product tests
Add a no-restricted-imports override so a product *.test.ts that imports node:os is a lint error pointing at mkdtempForTest, mirroring the existing node:child_process ban. A follow-up override clears it for the handful of tests that mock production's os.tmpdir()/os.homedir() or assert a real /tmp socket.
1 parent 3d4cf20 commit a605029

13 files changed

Lines changed: 54 additions & 0 deletions

File tree

‎oxlint.config.ts‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
import nkzw from '@nkzw/oxlint-config';
22
import { defineConfig } from 'oxlint';
33

4+
// Product source trees, where unit tests get scratch from the package tmp-dir helpers.
5+
// scripts/, test/, and package test harnesses manage TMPDIR for child processes on purpose,
6+
// so keeping the roots explicit holds them out of scope that a bare `**` would sweep in.
7+
const PRODUCT_TEST_ROOTS = ['src', 'packages/*/src'];
8+
const PRODUCT_TEST_SHAPES = [
9+
'**/*.test.ts',
10+
'**/*.fixtures.ts',
11+
'**/__tests__/**/*.ts',
12+
'**/test-utils/**/*.ts',
13+
];
14+
const PRODUCT_TEST_FILES = PRODUCT_TEST_ROOTS.flatMap((root) =>
15+
PRODUCT_TEST_SHAPES.map((shape) => `${root}/${shape}`),
16+
);
17+
418
export default defineConfig({
519
env: {
620
builtin: true,
@@ -146,5 +160,33 @@ export default defineConfig({
146160
output: 'writable',
147161
},
148162
},
163+
{
164+
// Product tests get scratch from the package tmp-dir helpers, which honor the run's
165+
// redirected TMPDIR; reading node:os reuses a fixed path across the suite. A file with a
166+
// justified read (mocking production, a real socket path, or the TMPDIR mechanism itself)
167+
// oxlint-disables its one import line with a reason instead of widening this list.
168+
files: PRODUCT_TEST_FILES,
169+
rules: {
170+
'no-restricted-imports': [
171+
'error',
172+
{
173+
paths: [
174+
{
175+
name: 'node:os',
176+
message:
177+
'Create test scratch with mkdtempForTest()/mkdtempForTestSync() from the package tmp-dir helper instead of reading node:os.',
178+
},
179+
],
180+
},
181+
],
182+
},
183+
},
184+
{
185+
// The tmp-dir helper modules are the sanctioned os.tmpdir() readers.
186+
files: ['**/tmp-dir.ts', '**/tmp-dir.fixtures.ts'],
187+
rules: {
188+
'no-restricted-imports': ['error', { paths: [] }],
189+
},
190+
},
149191
],
150192
});

‎packages/host-kit/src/code-signature-cache.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import assert from 'node:assert/strict';
22
import fs from 'node:fs';
3+
// oxlint-disable-next-line no-restricted-imports -- vi.spyOn(os,'tmpdir') aims production's cache home
34
import os from 'node:os';
45
import path from 'node:path';
56
import { afterEach, test, vi } from 'vitest';

‎packages/platform-android/src/__tests__/install-artifact-cancellation.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import assert from 'node:assert/strict';
22
import dns from 'node:dns/promises';
33
import { promises as fs } from 'node:fs';
4+
// oxlint-disable-next-line no-restricted-imports -- vi.spyOn(os,'tmpdir') aims production's install scratch
45
import os from 'node:os';
56
import path from 'node:path';
67
import { Readable } from 'node:stream';

‎packages/platform-apple/src/runner/__tests__/runner-xctestrun.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { test, vi, beforeEach } from 'vitest';
22
import assert from 'node:assert/strict';
33
import fs from 'node:fs';
4+
// oxlint-disable-next-line no-restricted-imports -- mirrors production's os.tmpdir xctestrun path
45
import os from 'node:os';
56
import path from 'node:path';
67
import { pathToFileURL } from 'node:url';

‎packages/platform-web/src/__tests__/test-utils.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import crypto from 'node:crypto';
22
import fs from 'node:fs';
3+
// oxlint-disable-next-line no-restricted-imports -- real Unix socket path under TMPDIR (104-char limit)
34
import os from 'node:os';
45
import path from 'node:path';
56
import type { CommandExecutorOverride, ExecOptions } from '@agent-device/host-kit/command';

‎src/__tests__/cli-diff.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { describe, test } from 'vitest';
22
import assert from 'node:assert/strict';
33
import fs from 'node:fs';
4+
// oxlint-disable-next-line no-restricted-imports -- asserts the default diff path under os.tmpdir
45
import os from 'node:os';
56
import path from 'node:path';
67
import { PNG } from '@agent-device/capture-kit/png';

‎src/__tests__/daemon-process-takeover.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import assert from 'node:assert/strict';
22
import { spawn } from 'node:child_process';
33
import fs from 'node:fs';
4+
// oxlint-disable-next-line no-restricted-imports -- real /tmp socket path within the 104-char limit
45
import os from 'node:os';
56
import path from 'node:path';
67
import { afterEach, test } from 'vitest';

‎src/__tests__/hermetic-env-setup.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// oxlint-disable-next-line no-restricted-imports -- exercises the TMPDIR mechanism and os.availableParallelism
12
import os from 'node:os';
23
import path from 'node:path';
34
import { afterEach, test, vi } from 'vitest';

‎src/__tests__/hermetic-env-setup.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import fs from 'node:fs';
2+
// oxlint-disable-next-line no-restricted-imports -- sets the run's TMPDIR; must read the real tmpdir
23
import os from 'node:os';
34
import path from 'node:path';
45
import { afterEach } from 'vitest';

‎src/__tests__/install-source.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import assert from 'node:assert/strict';
33
import dns from 'node:dns/promises';
44
import fsSync from 'node:fs';
55
import fs from 'node:fs/promises';
6+
// oxlint-disable-next-line no-restricted-imports -- vi.spyOn(os,'tmpdir') aims production's install source
67
import os from 'node:os';
78
import path from 'node:path';
89
import { Readable } from 'node:stream';

0 commit comments

Comments
 (0)