diff --git a/changelog/2026-12-06-device-send-windows-paths.md b/changelog/2026-12-06-device-send-windows-paths.md new file mode 100644 index 0000000000..d0ff851b91 --- /dev/null +++ b/changelog/2026-12-06-device-send-windows-paths.md @@ -0,0 +1 @@ +Developer tools: `scripts/device-send.py` now reaches the unit queue on Windows when Node or the repository sits in a folder with a space (such as `C:\Users\Jo Doe`). It used to stop with `Cannot find module` because Windows passed the path to Node split in two. diff --git a/scripts/device-send.py b/scripts/device-send.py index d4ca038152..cb5064e615 100755 --- a/scripts/device-send.py +++ b/scripts/device-send.py @@ -13,8 +13,18 @@ if not node: raise SystemExit('The unit queue needs Node on PATH (scripts/unit-queue.mjs); for an emulator, set MODWERK_UNIT=emulator.') here = os.path.abspath(__file__) - os.execv(node, [node, os.path.join(os.path.dirname(here), 'unit-queue.mjs'), 'run', '--unit', 'octatrack', '--note', ('device-send ' + line)[:120], - '--expect', '2m', '--steps', line, '--', sys.executable, '-B', here] + sys.argv[1:]) + command = [node, os.path.join(os.path.dirname(here), 'unit-queue.mjs'), 'run', '--unit', 'octatrack', '--note', ('device-send ' + line)[:120], + '--expect', '2m', '--steps', line, '--', sys.executable, '-B', here] + sys.argv[1:] + if os.name != 'nt': + os.execv(node, command) + # Windows execv joins the arguments unquoted, so a path with a space ("C:\Users\Jo Doe") reaches Node split in two. + import subprocess + child = subprocess.Popen(command) + while True: + try: + raise SystemExit(child.wait()) + except KeyboardInterrupt: + pass # Ctrl+C reaches the queue as well: it rolls back the trial and ends in its own time. path = os.environ.get('MODWERK_DEV_SOCKET', '/tmp/modwerk-dev.sock') # A port number is TCP on this computer (Windows Python has no AF_UNIX), anything else a Unix socket. s = socket.socket(socket.AF_INET) if path.isdigit() else socket.socket(socket.AF_UNIX) diff --git a/scripts/device-send.test.mjs b/scripts/device-send.test.mjs new file mode 100644 index 0000000000..6e154b16ec --- /dev/null +++ b/scripts/device-send.test.mjs @@ -0,0 +1,33 @@ +import { spawnSync } from 'node:child_process' +import { copyFileSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs' +import { tmpdir } from 'node:os' +import { join } from 'node:path' +import { fileURLToPath } from 'node:url' +import { afterEach, describe, expect, it } from 'vitest' + +const python = process.platform === 'win32' ? 'python' : 'python3' +const source = fileURLToPath(new URL('./device-send.py', import.meta.url)) +let root + +afterEach(() => { if (root) rmSync(root, { recursive: true, force: true }) }) + +describe('device-send.py', () => { + // Windows os.execv joins its arguments unquoted: from a folder with a space ("C:\Users\Jo Doe") Node got a split path. + it('hands its line to the unit queue intact from a path with a space, and ends with the queue\'s code', () => { + root = mkdtempSync(join(tmpdir(), 'device send ')) + const scripts = join(root, 'with space', 'scripts') + mkdirSync(scripts, { recursive: true }) + copyFileSync(source, join(scripts, 'device-send.py')) + writeFileSync(join(scripts, 'unit-queue.mjs'), 'console.log(JSON.stringify(process.argv.slice(2))); process.exit(3)\n') + const env = { ...process.env } + delete env.MODWERK_UNIT_TURN + delete env.MODWERK_UNIT + const result = spawnSync(python, ['-B', join(scripts, 'device-send.py'), 'press PLAY', 'a "quoted" word'], { encoding: 'utf8', env }) + expect(result.stderr).toBe('') + expect(result.status).toBe(3) + const args = JSON.parse(result.stdout) + expect(args.slice(0, 4)).toEqual(['run', '--unit', 'octatrack', '--note']) + expect(args).toContain('press PLAY a "quoted" word') + expect(args.slice(args.indexOf('--') + 2)).toEqual(['-B', join(scripts, 'device-send.py'), 'press PLAY', 'a "quoted" word']) + }) +})