From bf75b552c848cd33814a55087d46f861c8396c38 Mon Sep 17 00:00:00 2001 From: aiirvizionz Date: Sat, 18 Jul 2026 16:48:02 -0600 Subject: [PATCH] fix(tui): pass run args to scripts --- src/tui.mjs | 5 ++++- test/tui.test.mjs | 27 ++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/tui.mjs b/src/tui.mjs index 2ab2a74..1e80582 100644 --- a/src/tui.mjs +++ b/src/tui.mjs @@ -273,6 +273,7 @@ function printPrds() { async function runFile(args) { // Parse /run options the same way the CLI does (R3: two entrypoints agree). let max, dryRun = false, file = null; + const argv = []; for (let i = 0; i < args.length; i++) { const a = args[i]; if (a === "--max" || a === "-n") { @@ -290,6 +291,8 @@ async function runFile(args) { return; } else if (!file) { file = a; + } else { + argv.push(a); } } if (!file) { console.log(err("usage: /run [--max N] [--dry-run]")); return; } @@ -300,7 +303,7 @@ async function runFile(args) { console.log(hr()); if (dryRun) console.log(info("dry run — narrating without executing")); let result = { iterations: 0 }; - const opts = { commands: moshVocabulary(), dryRun, out: (s) => console.log(s) }; + const opts = { commands: moshVocabulary(), dryRun, argv, out: (s) => console.log(s) }; if (max !== undefined) opts.max = max; try { result = await runScript(src, opts); diff --git a/test/tui.test.mjs b/test/tui.test.mjs index 0890c80..bb09a13 100644 --- a/test/tui.test.mjs +++ b/test/tui.test.mjs @@ -1,5 +1,8 @@ import assert from "node:assert/strict"; -import { spawn } from "node:child_process"; +import { spawn, spawnSync } from "node:child_process"; +import { mkdirSync, mkdtempSync, writeFileSync } from "node:fs"; +import { tmpdir } from "node:os"; +import { join } from "node:path"; import test from "node:test"; import { fileURLToPath } from "node:url"; @@ -55,3 +58,25 @@ test("TUI /run rejects unknown options before reading a script file", async () = assert.match(result.stdout, /unknown option --dryrun/); assert.doesNotMatch(result.stdout, /can't read --dryrun/); }); + +test("TUI /run passes positional args through to moshscript argv", () => { + const dir = mkdtempSync(join(tmpdir(), "moshcode-tui-")); + mkdirSync(join(dir, "space dir")); + const script = join(dir, "space dir", "argv.mosh"); + writeFileSync(script, 'say(argv[0]); say(argv[1]);\n'); + const scriptArg = script.replaceAll("\\", "/"); + + const result = spawnSync( + process.execPath, + ["bin/moshcode.mjs"], + { + cwd: join(import.meta.dirname, ".."), + input: `/run "${scriptArg}" alpha "two words"\n/quit\n`, + encoding: "utf8", + }, + ); + + assert.equal(result.status, 0, result.stderr || result.stdout); + assert.match(result.stdout, /alpha/); + assert.match(result.stdout, /two words/); +});