Skip to content

The agent that grows with you

fix: inject platform into buildCommandScreenshotMonitor instead of faking process.platform in tests

teknium1ed45828c8b1c
diff --git a/apps/desktop/scripts/build-command-screenshot-monitor.mjs b/apps/desktop/scripts/build-command-screenshot-monitor.mjs
index b59ce9be2c7..a77a35a2c0d 100644
--- a/apps/desktop/scripts/build-command-screenshot-monitor.mjs
+++ b/apps/desktop/scripts/build-command-screenshot-monitor.mjs
@@ -8,8 +8,13 @@ import { fileURLToPath } from 'node:url'
const script = fileURLToPath(import.meta.url)
const root = resolve(dirname(script), '..')
-export function buildCommandScreenshotMonitor({ distDir = resolve(root, 'dist') } = {}) {
- if (process.platform !== 'darwin') return null
+// `platform` is injectable so tests can exercise both branches without
+// redefining process.platform.
+export function buildCommandScreenshotMonitor({
+ distDir = resolve(root, 'dist'),
+ platform = process.platform,
+} = {}) {
+ if (platform !== 'darwin') return null
const output = resolve(distDir, 'native/command-screenshot-monitor')
const staging = `${output}.${process.pid}.tmp`
mkdirSync(dirname(output), { recursive: true })
diff --git a/apps/desktop/scripts/build-command-screenshot-monitor.test.mjs b/apps/desktop/scripts/build-command-screenshot-monitor.test.mjs
index 4b405543229..b83b608cfae 100644
--- a/apps/desktop/scripts/build-command-screenshot-monitor.test.mjs
+++ b/apps/desktop/scripts/build-command-screenshot-monitor.test.mjs
@@ -10,10 +10,7 @@ vi.mock('node:child_process', () => ({
const { execFileSync } = await import('node:child_process')
const { buildCommandScreenshotMonitor } = await import('./build-command-screenshot-monitor.mjs')
-const realPlatform = Object.getOwnPropertyDescriptor(process, 'platform')
-
afterEach(() => {
- Object.defineProperty(process, 'platform', realPlatform)
vi.mocked(execFileSync).mockReset()
})
@@ -21,13 +18,12 @@ afterEach(() => {
// so a non-macOS CI host still proves what the macOS build will run.
describe('buildCommandScreenshotMonitor argv', () => {
it('names the macOS SDK explicitly so driver and linker agree', () => {
- Object.defineProperty(process, 'platform', { ...realPlatform, value: 'darwin' })
const distDir = fs.mkdtempSync(path.join(os.tmpdir(), 'csm-argv-'))
const staging = path.resolve(distDir, `native/command-screenshot-monitor.${process.pid}.tmp`)
fs.mkdirSync(path.dirname(staging), { recursive: true })
fs.writeFileSync(staging, 'staged')
- const out = buildCommandScreenshotMonitor({ distDir })
+ const out = buildCommandScreenshotMonitor({ distDir, platform: 'darwin' })
expect(execFileSync).toHaveBeenCalledOnce()
const [cmd, argv] = vi.mocked(execFileSync).mock.calls[0]
@@ -40,9 +36,9 @@ describe('buildCommandScreenshotMonitor argv', () => {
})
it('is a no-op off macOS', () => {
- Object.defineProperty(process, 'platform', { ...realPlatform, value: 'linux' })
+ const distDir = path.join(os.tmpdir(), 'csm-never')
- expect(buildCommandScreenshotMonitor({ distDir: path.join(os.tmpdir(), 'csm-never') })).toBeNull()
+ expect(buildCommandScreenshotMonitor({ distDir, platform: 'linux' })).toBeNull()
expect(execFileSync).not.toHaveBeenCalled()
})
})