The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.
TypeScript 3d-modelingagent-frameworkagent-harnessai-agentscadclaude-codecodexcoding-agentsdeveloper-toolsesp32game-developmentmcp-servermulti-agentopen-hardwareopencodeopenharnesspcbroboticsterminaltmux
strudel: test the pane server and the toolchain scripts; a bad escape no longer kills the pane
dee5e36e33159f5
diff --git a/store/agents/strudel/README.md b/store/agents/strudel/README.mdindex de2850c39..885a0188b 100644--- a/store/agents/strudel/README.md+++ b/store/agents/strudel/README.md@@ -22,7 +22,9 @@ hear it in the Strudel pane as the agent writes the pattern. Runs on Claude Codeharness dsh check . # conformanceharness dsh install "$PWD" --link # this checkout as the installed agentpython3 -m unittest toolchain/test_verdict.py # the verdict+python3 -m unittest toolchain/test_scripts.py # setup, doctor, init, viewer.sh, with stub commandsnode --test pane/voices.test.mjs # the pane's voice parser+node --test test/viewer.test.mjs # the pane server, over HTTP, with a stand-in REPL```## What cannot be checked herediff --git a/store/agents/strudel/package.json b/store/agents/strudel/package.jsonindex 2cfb88768..f836d6778 100644--- a/store/agents/strudel/package.json+++ b/store/agents/strudel/package.json@@ -4,7 +4,7 @@"description": "Strudel as a Harness agent: the pane is Strudel's own REPL, self-hosted from @strudel/repl","license": "MIT","scripts": {- "test": "node --test pane/voices.test.mjs && python3 -m unittest toolchain/test_verdict.py"+ "test": "node --test pane/voices.test.mjs test/viewer.test.mjs && python3 -m unittest toolchain/test_verdict.py toolchain/test_scripts.py"},"dependencies": {"@strudel/repl": "1.3.0"diff --git a/store/agents/strudel/test/preload.mjs b/store/agents/strudel/test/preload.mjsnew file mode 100644index 000000000..ebb66ec00--- /dev/null+++ b/store/agents/strudel/test/preload.mjs@@ -0,0 +1,12 @@+// Loaded with `node --import` into the viewer under test, never in production (see viewer.test.mjs).+// SIGTERM exits through process.exit, so V8 coverage is written when a test stops the viewer; and+// with VIEWER_TEST_FAST_TIMERS set, timers of 10 s or more run 50 times sooner, so the 20-second+// keep-alive ping is reached in a test instead of after a wait.+process.on('SIGTERM', () => process.exit(0))++if (process.env.VIEWER_TEST_FAST_TIMERS) {+ const { setTimeout: later, setInterval: every } = globalThis+ const scale = (ms) => (ms >= 10_000 ? ms / 50 : ms)+ globalThis.setTimeout = (fn, ms, ...args) => later(fn, scale(ms), ...args)+ globalThis.setInterval = (fn, ms, ...args) => every(fn, scale(ms), ...args)+}diff --git a/store/agents/strudel/test/viewer.test.mjs b/store/agents/strudel/test/viewer.test.mjsnew file mode 100644index 000000000..c1ef45ad4--- /dev/null+++ b/store/agents/strudel/test/viewer.test.mjs@@ -0,0 +1,279 @@+// node --test test/ — the pane's server (viewer.mjs), run as Harness runs it, over HTTP.+//+// The viewer serves the REPL from its own node_modules, so each test builds a package root in a temp+// dir: viewer.mjs and pane/ are symlinks to this checkout (node runs with --preserve-symlinks-main,+// so the viewer's own directory is the temp root) and node_modules holds a two-file stand-in for+// @strudel/repl's dist. No npm install, no network, and this checkout is never written to.+import { after, before, describe, test } from 'node:test'+import assert from 'node:assert/strict'+import { spawn } from 'node:child_process'+import { chmodSync, mkdirSync, mkdtempSync, realpathSync, rmSync, symlinkSync, utimesSync, writeFileSync } from 'node:fs'+import { request as httpRequest } from 'node:http'+import { createServer } from 'node:net'+import { tmpdir } from 'node:os'+import { dirname, join } from 'node:path'+import { fileURLToPath } from 'node:url'++const PKG = join(dirname(fileURLToPath(import.meta.url)), '..')+const PRELOAD = join(PKG, 'test', 'preload.mjs')+const sleep = (ms) => new Promise((ok) => setTimeout(ok, ms))++function tempDir(prefix) {+ return realpathSync(mkdtempSync(join(tmpdir(), prefix)))+}++/** A package root: the real viewer and pane, a stand-in REPL bundle. */+function packageRoot() {+ const root = tempDir('strudel-viewer-')+ symlinkSync(join(PKG, 'viewer.mjs'), join(root, 'viewer.mjs'))+ symlinkSync(join(PKG, 'pane'), join(root, 'pane'))+ const dist = join(root, 'node_modules', '@strudel', 'repl', 'dist')+ mkdirSync(join(dist, 'assets'), { recursive: true })+ writeFileSync(join(dist, 'index.js'), 'export const repl = 1\n')+ writeFileSync(join(dist, 'assets', 'clockworker-abc.js'), 'onmessage = () => {}\n')+ return root+}++function freePort() {+ return new Promise((ok, fail) => {+ const probe = createServer().listen(0, '127.0.0.1', () => {+ const { port } = probe.address()+ probe.close(() => ok(port))+ }).on('error', fail)+ })+}++async function startViewer(workspace, { fastTimers = false } = {}) {+ const root = packageRoot()+ const port = await freePort()+ const env = { ...process.env, HARNESS_VIEWER_PORT: String(port), HARNESS_WORKSPACE: workspace }+ if (fastTimers) env.VIEWER_TEST_FAST_TIMERS = '1'+ const child = spawn(process.execPath, ['--preserve-symlinks', '--preserve-symlinks-main', '--import', PRELOAD, join(root, 'viewer.mjs')],+ { env, stdio: ['ignore', 'pipe', 'pipe'] })+ let log = ''+ child.stdout.on('data', (d) => { log += d })+ child.stderr.on('data', (d) => { log += d })+ const exited = new Promise((ok) => child.on('exit', (code, signal) => ok({ code, signal })))+ for (let i = 0; i < 200 && !log.includes('listening on'); i++) await sleep(25)+ assert.match(log, /\[strudel\] listening on http:\/\/127\.0\.0\.1:\d+\//)+ return {+ port,+ root,+ log: () => log,+ alive: () => child.exitCode === null && child.signalCode === null,+ async stop() {+ if (child.exitCode === null && child.signalCode === null) child.kill('SIGTERM')+ await exited+ rmSync(root, { recursive: true, force: true })+ },+ }+}++function get(port, path, { method = 'GET' } = {}) {+ return new Promise((ok, fail) => {+ const req = httpRequest({ host: '127.0.0.1', port, path, method }, (res) => {+ const chunks = []+ res.on('data', (c) => chunks.push(c))+ res.on('end', () => ok({ status: res.statusCode, headers: res.headers, body: Buffer.concat(chunks).toString('utf8') }))+ })+ req.on('error', fail)+ req.end()+ })+}++/** An open /events stream: everything it has said so far, and a wait for a pattern. */+function events(port) {+ return new Promise((ok, fail) => {+ const req = httpRequest({ host: '127.0.0.1', port, path: '/events' }, (res) => {+ let text = ''+ res.setEncoding('utf8')+ res.on('data', (d) => { text += d })+ const stream = {+ res,+ text: () => text,+ async until(pattern, ms = 5000) {+ for (let waited = 0; waited < ms; waited += 20) {+ if (pattern.test(text)) return text+ await sleep(20)+ }+ assert.fail(`no ${pattern} on /events within ${ms} ms; got ${JSON.stringify(text)}`)+ },+ close() { req.destroy() },+ }+ ok(stream)+ })+ req.on('error', fail)+ req.end()+ })+}++describe('the pane server', () => {+ let parent+ let ws+ let viewer++ before(async () => {+ parent = tempDir('strudel-ws-')+ ws = join(parent, 'ws')+ mkdirSync(ws)+ writeFileSync(join(parent, 'secret.txt'), 'not the workspace\n')+ writeFileSync(join(ws, 'track.strudel'), 's("sbd*4")\n')+ mkdirSync(join(ws, '.harness'))+ mkdirSync(join(ws, 'node_modules'))+ mkdirSync(join(ws, 'song'))+ viewer = await startViewer(ws)+ })+ after(async () => {+ await viewer.stop()+ rmSync(parent, { recursive: true, force: true })+ })++ test('/ is the pane page', async () => {+ const page = await get(viewer.port, '/')+ assert.equal(page.status, 200)+ assert.equal(page.headers['content-type'], 'text/html; charset=utf-8')+ assert.equal(page.headers['cache-control'], 'no-store')+ assert.match(page.body, /<html/i)+ })++ test('/_pane/ serves the pane files fresh, and nothing outside pane/', async () => {+ const css = await get(viewer.port, '/_pane/pane.css')+ assert.equal(css.status, 200)+ assert.equal(css.headers['content-type'], 'text/css')+ assert.equal(css.headers['cache-control'], 'no-store')+ // An escaped slash survives URL parsing, so this reaches safe() as pane/../viewer.mjs — a file+ // that exists, one level up.+ assert.equal((await get(viewer.port, '/_pane/..%2fviewer.mjs')).status, 404)+ assert.equal((await get(viewer.port, '/_pane/missing.js')).status, 404)+ })++ test('/vendor/ serves the REPL bundle and its siblings, cached; HEAD says the size', async () => {+ const bundle = await get(viewer.port, '/vendor/index.js')+ assert.equal(bundle.status, 200)+ assert.equal(bundle.headers['content-type'], 'text/javascript')+ assert.equal(bundle.headers['cache-control'], 'max-age=3600')+ assert.equal(bundle.body, 'export const repl = 1\n')+ assert.equal((await get(viewer.port, '/vendor/assets/clockworker-abc.js')).status, 200)+ const head = await get(viewer.port, '/vendor/index.js', { method: 'HEAD' })+ assert.equal(head.status, 200)+ assert.equal(head.headers['content-length'], String('export const repl = 1\n'.length))+ assert.equal(head.body, '')+ assert.equal((await get(viewer.port, '/vendor/assets')).status, 404) // a directory+ assert.equal((await get(viewer.port, '/vendor/')).status, 404) // the dist directory itself+ })++ test('any other path is a workspace file, never one outside it', async () => {+ const track = await get(viewer.port, '/track.strudel')+ assert.equal(track.status, 200)+ assert.equal(track.headers['content-type'], 'text/plain; charset=utf-8')+ assert.equal(track.headers['cache-control'], 'no-store')+ assert.equal(track.body, 's("sbd*4")\n')+ writeFileSync(join(ws, 'song', 'stem.bin'), 'x')+ assert.equal((await get(viewer.port, '/song/stem.bin')).headers['content-type'], 'application/octet-stream')+ assert.equal((await get(viewer.port, '/..%2fsecret.txt')).status, 404)+ assert.equal((await get(viewer.port, '/nope.strudel')).status, 404)+ })++ test('a malformed escape in the path is a 400, and the server keeps serving', async () => {+ // Before the fix decodeURIComponent threw inside the request handler and took the pane down.+ const bad = await get(viewer.port, '/%E0%A4%A')+ assert.equal(bad.status, 400)+ assert.equal((await get(viewer.port, '/')).status, 200)+ assert.ok(viewer.alive())+ })++ test('/events says hello, then one change per burst of saves, ignoring .harness and node_modules', async () => {+ const stream = await events(viewer.port)+ assert.equal(stream.res.headers['content-type'], 'text/event-stream')+ await stream.until(/: hello\n\n/)+ await sleep(400) // let the directories made in before() settle+ const settled = stream.text()+ writeFileSync(join(ws, '.harness', 'verdict.json'), '{}')+ writeFileSync(join(ws, 'node_modules', 'x.js'), '')+ await sleep(600)+ assert.equal(stream.text(), settled, 'a verdict write or a node_modules change is not a save')+ for (let i = 0; i < 10; i++) writeFileSync(join(ws, i % 2 ? 'track.strudel' : join('song', 'b-side.strudel')), `s("sbd*${i}")\n`)+ await stream.until(/event: change\ndata: \{\}\n\n/)+ await sleep(500)+ const changes = stream.text().split('event: change').length - 1+ assert.ok(changes >= 1 && changes < 10, `ten saves in a burst are debounced, got ${changes} change events`)+ stream.close()+ })+})++describe('/_files: the tracks the pane can open', () => {+ let ws+ let viewer++ before(async () => {+ ws = tempDir('strudel-files-')+ const file = (rel, mtimeSeconds, body = 's("sbd")\n') => {+ mkdirSync(join(ws, dirname(rel)), { recursive: true })+ writeFileSync(join(ws, rel), body)+ utimesSync(join(ws, rel), mtimeSeconds, mtimeSeconds)+ }+ file('old.strudel', 1_000_000)+ file('new.strudel', 3_000_000)+ file('a/b/c/d/deep.strudel', 2_000_000) // four directories down: still walked+ file('a/b/c/d/e/too-deep.strudel', 2_000_000) // five: not+ file('.hidden/secret.strudel', 2_000_000)+ file('.dot.strudel', 2_000_000)+ file('node_modules/pkg/demo.strudel', 2_000_000)+ file('notes.txt', 2_000_000)+ file('locked/inside.strudel', 2_000_000)+ chmodSync(join(ws, 'locked'), 0o000) // unreadable: skipped, not a 500+ file('searchless/listed.strudel', 2_000_000)+ chmodSync(join(ws, 'searchless'), 0o444) // listable, but its files cannot be stat'ed+ viewer = await startViewer(ws)+ })+ after(async () => {+ await viewer.stop()+ chmodSync(join(ws, 'locked'), 0o755)+ chmodSync(join(ws, 'searchless'), 0o755)+ rmSync(ws, { recursive: true, force: true })+ })++ test('newest first, four levels deep, no hidden files, no node_modules, only .strudel', async () => {+ const res = await get(viewer.port, '/_files')+ assert.equal(res.status, 200)+ assert.equal(res.headers['content-type'], 'application/json')+ const files = JSON.parse(res.body)+ assert.deepEqual(files.map((f) => f.path), ['new.strudel', 'a/b/c/d/deep.strudel', 'old.strudel'])+ assert.equal(files[0].mtime, 3_000_000_000)+ })++ test('at most fifty', async () => {+ mkdirSync(join(ws, 'many'))+ for (let i = 0; i < 55; i++) writeFileSync(join(ws, 'many', `t${i}.strudel`), '')+ const files = JSON.parse((await get(viewer.port, '/_files')).body)+ assert.equal(files.length, 50)+ })+})++describe('the pane server, at the edges', () => {+ test('a workspace that does not exist: no watch, no tracks, the pane still serves', async () => {+ const parent = tempDir('strudel-gone-')+ const viewer = await startViewer(join(parent, 'gone'))+ try {+ assert.match(viewer.log(), /\[strudel\] watch failed: /)+ assert.deepEqual(JSON.parse((await get(viewer.port, '/_files')).body), [])+ assert.equal((await get(viewer.port, '/')).status, 200)+ } finally {+ await viewer.stop()+ rmSync(parent, { recursive: true, force: true })+ }+ })++ test('an open /events stream is pinged so it stays open', async () => {+ const ws = tempDir('strudel-ping-')+ const viewer = await startViewer(ws, { fastTimers: true }) // the 20 s ping every 400 ms+ try {+ const stream = await events(viewer.port)+ await stream.until(/: ping\n\n/, 3000)+ stream.close()+ } finally {+ await viewer.stop()+ rmSync(ws, { recursive: true, force: true })+ }+ })+})diff --git a/store/agents/strudel/toolchain/test_scripts.py b/store/agents/strudel/toolchain/test_scripts.pynew file mode 100644index 000000000..23e1ca3dc--- /dev/null+++ b/store/agents/strudel/toolchain/test_scripts.py@@ -0,0 +1,203 @@+"""python3 -m unittest toolchain/test_scripts.py — setup, doctor, init and the viewer launcher.++Each test builds a package root in a temp dir with this checkout's scripts symlinked in file by file,+and runs them with PATH set to a bin dir that holds only the tools the test grants: real ones+(bash, node, python3, …) linked in, or stubs written here. So a "miss node" branch is a PATH without+node, npm is a stub that lays out node_modules or fails, and nothing touches the network or this+checkout.+"""+from __future__ import annotations++import json+import os+import shutil+import subprocess+import tempfile+import unittest+from pathlib import Path++HERE = Path(__file__).resolve().parent+PKG = HERE.parent+REPL_VERSION = json.loads((PKG / "package.json").read_text())["dependencies"]["@strudel/repl"]+BASE_TOOLS = ("bash", "dirname", "mkdir")+++class Sandbox:+ def __init__(self, test: unittest.TestCase, tools: tuple[str, ...] = ()) -> None:+ tmp = tempfile.TemporaryDirectory()+ test.addCleanup(tmp.cleanup)+ self.dir = Path(tmp.name).resolve()+ self.root = self.dir / "strudel"+ self.bin = self.dir / "bin"+ self.bin.mkdir()+ (self.root / "toolchain").mkdir(parents=True)+ for tool in BASE_TOOLS + tools:+ self.grant(tool)++ def link(self, rel: str) -> None:+ (self.root / rel).symlink_to(PKG / rel)++ def grant(self, tool: str) -> None:+ found = shutil.which(tool)+ assert found, f"{tool} is needed on this machine to run the test"+ (self.bin / tool).symlink_to(found)++ def stub(self, name: str, body: str) -> None:+ path = self.bin / name+ path.write_text("#!/bin/bash\n" + body)+ path.chmod(0o755)++ def run(self, rel: str, cwd: Path | None = None, **env: str) -> subprocess.CompletedProcess:+ clean = {k: v for k, v in os.environ.items() if not k.startswith("HARNESS_")}+ return subprocess.run([str(self.root / rel)], cwd=cwd or self.dir, capture_output=True, text=True,+ env={**clean, "PATH": str(self.bin), **env}, timeout=60)+++def lines(done: subprocess.CompletedProcess) -> list[str]:+ return done.stdout.splitlines()+++class Setup(unittest.TestCase):+ def sandbox(self, *tools: str) -> Sandbox:+ box = Sandbox(self, tools)+ box.link("toolchain/setup.sh")+ box.link("package.json")+ return box++ def test_node_is_required(self) -> None:+ done = self.sandbox().run("toolchain/setup.sh")+ self.assertEqual(done.returncode, 1)+ self.assertEqual(lines(done), ["miss node >= 18 on PATH"])++ def test_npm_is_required(self) -> None:+ done = self.sandbox("node").run("toolchain/setup.sh")+ self.assertEqual(done.returncode, 1)+ self.assertEqual(lines(done), ["miss npm on PATH"])++ def test_python3_is_required(self) -> None:+ box = self.sandbox("node")+ box.stub("npm", "exit 0\n")+ done = box.run("toolchain/setup.sh")+ self.assertEqual(done.returncode, 1)+ self.assertEqual(lines(done), ["miss python3 (the verdict)"])++ def npm(self, box: Sandbox, body: str) -> None:+ box.stub("npm", f'echo "$PWD $*" >> "{box.dir}/npm.calls"\n' + body)++ def test_npm_ci_lays_out_the_repl(self) -> None:+ box = self.sandbox("node", "python3")+ self.npm(box, f"""mkdir -p node_modules/@strudel/repl/dist+echo 'export {{}}' > node_modules/@strudel/repl/dist/index.js+echo '{{"name": "@strudel/repl", "version": "{REPL_VERSION}"}}' > node_modules/@strudel/repl/package.json+""")+ done = box.run("toolchain/setup.sh")+ self.assertEqual(done.returncode, 0, done.stderr)+ self.assertEqual(lines(done), [+ f" npm ci (@strudel/repl {REPL_VERSION})",+ f"ok strudel {REPL_VERSION} · AGPL-3.0-or-later, from npm, unmodified",+ ])+ # From the package dir, whatever the caller's cwd, and from the lockfile.+ self.assertEqual((box.dir / "npm.calls").read_text(), f"{box.root} ci --silent --no-audit --no-fund\n")++ def test_npm_ci_that_leaves_no_bundle(self) -> None:+ box = self.sandbox("node", "python3")+ self.npm(box, "exit 0\n")+ done = box.run("toolchain/setup.sh")+ self.assertEqual(done.returncode, 1)+ self.assertEqual(lines(done)[-1], "miss the Strudel REPL bundle after npm ci")++ def test_a_failing_npm_ci_stops_setup(self) -> None:+ box = self.sandbox("node", "python3")+ self.npm(box, "echo 'npm ERR! network' >&2; exit 1\n")+ done = box.run("toolchain/setup.sh")+ self.assertEqual(done.returncode, 1)+ self.assertEqual(lines(done), [f" npm ci (@strudel/repl {REPL_VERSION})"])+++class Doctor(unittest.TestCase):+ def test_a_ready_machine(self) -> None:+ box = Sandbox(self, ("node", "python3"))+ box.link("toolchain/doctor.sh")+ repl = box.root / "node_modules" / "@strudel" / "repl"+ (repl / "dist").mkdir(parents=True)+ (repl / "dist" / "index.js").write_text("export {}\n")+ (repl / "package.json").write_text('{"name": "@strudel/repl", "version": "9.9.9"}\n')+ done = box.run("toolchain/doctor.sh")+ self.assertEqual(done.returncode, 0, done.stdout + done.stderr)+ out = lines(done)+ self.assertEqual(out[0], "ok strudel 9.9.9 (the pane's REPL)")+ self.assertRegex(out[1], r"^ok node v\d+\.\d+\.\d+ \(the pane server and the syntax check\)$")+ self.assertRegex(out[2], r"^ok Python 3\.\d+\.\d+ \(the verdict\)$")+ self.assertTrue(out[3].startswith("note the pane needs a click to start audio"))+ self.assertEqual(len(out), 4)++ def test_an_empty_machine(self) -> None:+ box = Sandbox(self)+ box.link("toolchain/doctor.sh")+ done = box.run("toolchain/doctor.sh")+ self.assertEqual(done.returncode, 1)+ out = lines(done)+ self.assertEqual(out[:3], ["miss node_modules — run toolchain/setup.sh", "miss node >= 18", "miss python3"])+ self.assertTrue(out[3].startswith("note "))+++class InitWorkspace(unittest.TestCase):+ def sandbox(self, *tools: str) -> tuple[Sandbox, Path]:+ box = Sandbox(self, tools)+ box.link("toolchain/init-workspace.sh")+ box.link("toolchain/verdict.py")+ ws = box.dir / "ws"+ ws.mkdir()+ shutil.copy(PKG / "template" / "track.strudel", ws / "track.strudel")+ return box, ws++ def test_it_needs_the_install_dir(self) -> None:+ box, ws = self.sandbox("python3")+ done = box.run("toolchain/init-workspace.sh", cwd=ws)+ self.assertNotEqual(done.returncode, 0)+ self.assertIn("HARNESS_DSH_DIR", done.stderr)+ self.assertFalse((ws / ".harness").exists())++ def test_it_seeds_the_verdict_for_the_starter_track(self) -> None:+ box, ws = self.sandbox("python3", "node")+ done = box.run("toolchain/init-workspace.sh", cwd=ws, HARNESS_DSH_DIR=str(box.root))+ self.assertEqual(done.returncode, 0, done.stderr)+ self.assertEqual(done.stdout, "")+ verdict = json.loads((ws / ".harness" / "verdict.json").read_text())+ self.assertTrue(verdict["ready"])+ self.assertEqual(verdict["artifact"], "track.strudel")++ def test_a_verdict_that_cannot_run_does_not_fail_the_init(self) -> None:+ box, ws = self.sandbox() # no python3 on PATH+ done = box.run("toolchain/init-workspace.sh", cwd=ws, HARNESS_DSH_DIR=str(box.root))+ self.assertEqual(done.returncode, 0, done.stderr)+ self.assertTrue((ws / ".harness").is_dir())+ self.assertFalse((ws / ".harness" / "verdict.json").exists())+++class ViewerLauncher(unittest.TestCase):+ def sandbox(self) -> Sandbox:+ box = Sandbox(self, ("pwd",))+ box.link("viewer.sh")+ box.stub("node", 'echo "node $* in $PWD port=$HARNESS_VIEWER_PORT ws=$HARNESS_WORKSPACE"\n')+ return box++ def test_it_needs_a_port_and_a_workspace(self) -> None:+ box = self.sandbox()+ no_port = box.run("viewer.sh", HARNESS_WORKSPACE=str(box.dir))+ self.assertNotEqual(no_port.returncode, 0)+ self.assertIn("HARNESS_VIEWER_PORT", no_port.stderr)+ no_ws = box.run("viewer.sh", HARNESS_VIEWER_PORT="4100")+ self.assertNotEqual(no_ws.returncode, 0)+ self.assertIn("HARNESS_WORKSPACE", no_ws.stderr)+ self.assertEqual(no_port.stdout + no_ws.stdout, "")++ def test_it_runs_the_viewer_beside_it(self) -> None:+ box = self.sandbox()+ done = box.run("viewer.sh", HARNESS_VIEWER_PORT="4100", HARNESS_WORKSPACE="/Users/example/track")+ self.assertEqual(done.returncode, 0, done.stderr)+ self.assertEqual(done.stdout, f"node {box.root}/viewer.mjs in {box.dir} port=4100 ws=/Users/example/track\n")+++if __name__ == "__main__":+ unittest.main()diff --git a/store/agents/strudel/viewer.mjs b/store/agents/strudel/viewer.mjsindex 0fac43796..dad525f42 100644--- a/store/agents/strudel/viewer.mjs+++ b/store/agents/strudel/viewer.mjs@@ -52,8 +52,9 @@ function send(res, full, req, fresh = false) {res.writeHead(200, { 'content-type': type, 'cache-control': full.startsWith(VENDOR) && !fresh ? 'max-age=3600' : 'no-store' }); res.end(readFileSync(full))}createServer((req, res) => {- const url = new URL(req.url ?? '/', `http://127.0.0.1:${port}`)- const path = decodeURIComponent(url.pathname)+ const url = new URL(req.url, `http://127.0.0.1:${port}`)+ let path+ try { path = decodeURIComponent(url.pathname) } catch { res.writeHead(400); res.end('bad path'); return }if (path === '/') { res.writeHead(200, { 'content-type': 'text/html; charset=utf-8', 'cache-control': 'no-store' }); res.end(page()); return }if (path.startsWith('/_pane/')) { send(res, safe(PANE, path.slice('/_pane/'.length)), req, true); return }if (path === '/_files') { res.writeHead(200, { 'content-type': 'application/json', 'cache-control': 'no-store' }); res.end(JSON.stringify(tracks())); return }@@ -65,7 +66,9 @@ createServer((req, res) => {let timer = nulltry {watch(workspace, { recursive: true }, (_event, name) => {- const n = String(name ?? ''); if (!n || n.startsWith('.harness') || n.includes('node_modules')) return+ /* c8 ignore next */ // name is null only where fs.watch cannot report file names; macOS FSEvents always does+ const n = String(name ?? '')+ if (!n || n.startsWith('.harness') || n.includes('node_modules')) returnif (timer) clearTimeout(timer)timer = setTimeout(() => { for (const c of clients) c.write('event: change\ndata: {}\n\n') }, 200)})