11import assert from "node:assert/strict" ;
2+ import { spawnSync } from "node:child_process" ;
3+ import { mkdirSync , mkdtempSync , writeFileSync } from "node:fs" ;
4+ import { tmpdir } from "node:os" ;
5+ import { join } from "node:path" ;
26import test from "node:test" ;
37
48import { splitCommandLine } from "../src/tui.mjs" ;
@@ -23,3 +27,25 @@ test("TUI command parsing rejects incomplete quoting", () => {
2327 assert . throws ( ( ) => splitCommandLine ( '/coinpay --description "unfinished' ) , / u n t e r m i n a t e d / ) ;
2428 assert . throws ( ( ) => splitCommandLine ( "/ugig trailing\\" ) , / t r a i l i n g e s c a p e / ) ;
2529} ) ;
30+
31+ test ( "TUI /run passes positional args through to moshscript argv" , ( ) => {
32+ const dir = mkdtempSync ( join ( tmpdir ( ) , "moshcode-tui-" ) ) ;
33+ mkdirSync ( join ( dir , "space dir" ) ) ;
34+ const script = join ( dir , "space dir" , "argv.mosh" ) ;
35+ writeFileSync ( script , 'say(argv[0]); say(argv[1]);\n' ) ;
36+ const scriptArg = script . replaceAll ( "\\" , "/" ) ;
37+
38+ const result = spawnSync (
39+ process . execPath ,
40+ [ "bin/moshcode.mjs" ] ,
41+ {
42+ cwd : join ( import . meta. dirname , ".." ) ,
43+ input : `/run "${ scriptArg } " alpha "two words"\n/quit\n` ,
44+ encoding : "utf8" ,
45+ } ,
46+ ) ;
47+
48+ assert . equal ( result . status , 0 , result . stderr || result . stdout ) ;
49+ assert . match ( result . stdout , / a l p h a / ) ;
50+ assert . match ( result . stdout , / t w o w o r d s / ) ;
51+ } ) ;
0 commit comments