Skip to content

Commit 23c99eb

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 23c99eb

13 files changed

Lines changed: 49 additions & 0 deletions

File tree

oxlint.config.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,5 +146,42 @@ export default defineConfig({
146146
output: 'writable',
147147
},
148148
},
149+
{
150+
// Product tests get scratch from the package tmp-dir helpers, which honor the run's
151+
// redirected TMPDIR; reading node:os reuses a fixed path across the suite. A file with a
152+
// justified read (mocking production, a real socket path, or the TMPDIR mechanism itself)
153+
// oxlint-disables its one import line with a reason instead of widening this list.
154+
files: [
155+
'src/**/*.test.ts',
156+
'src/**/*.fixtures.ts',
157+
'src/**/__tests__/**/*.ts',
158+
'src/**/test-utils/**/*.ts',
159+
'packages/*/src/**/*.test.ts',
160+
'packages/*/src/**/*.fixtures.ts',
161+
'packages/*/src/**/__tests__/**/*.ts',
162+
'packages/*/src/**/test-utils/**/*.ts',
163+
],
164+
rules: {
165+
'no-restricted-imports': [
166+
'error',
167+
{
168+
paths: [
169+
{
170+
name: 'node:os',
171+
message:
172+
'Create test scratch with mkdtempForTest()/mkdtempForTestSync() from the package tmp-dir helper instead of reading node:os.',
173+
},
174+
],
175+
},
176+
],
177+
},
178+
},
179+
{
180+
// The tmp-dir helper modules are the sanctioned os.tmpdir() readers.
181+
files: ['**/tmp-dir.ts', '**/tmp-dir.fixtures.ts'],
182+
rules: {
183+
'no-restricted-imports': ['error', { paths: [] }],
184+
},
185+
},
149186
],
150187
});

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)