diff options
| author | Agando <roduccomm@gmail.com> | 2026-10-29 12:42:30 +0100 |
|---|---|---|
| committer | Agando <roduccomm@gmail.com> | 2026-10-29 12:42:30 +0100 |
| commit | af36a408670e6caa61527b5bc5e6f9915b69369c (patch) | |
| tree | 15bb6373bf33c205419b725e97bfd4bfc4fa53d2 /modules/test | |
| parent | db65ce7628b0073c41ff1c13334723a043b24479 (diff) | |
fix(newos4): pipe stage quoting, maintain ordering, help cost row, plan status (v4.6.131)
Four items closed in one batch; three ran as parallel subagents on disjoint files, the bundle was
rebuilt once by the parent (rebuild-bundles.py serialises the working tree, which carries other
sessions' work — see 161372f).
1. PIPE STAGES KEEP THEIR QUOTES. `js "a b".length | wc -c` reached eval as `a b.length` and printed
a ReferenceError. terminal.js executePipeChain() now keeps `stages[i]` aligned 1:1 with
`pipeParts[i]` (the `.filter(argv => argv.length > 0)` shifted the index; replaced by a lastStage
scan + `if (argv.length === 0) continue`) and forwards the stage's own text to the dispatcher.
The core path alone was dead code: ShellModule.init() replaces terminal.executePipeChain
(shell.js:144), and that override is what runs in the browser (`executePipeChain.toString()`
contained `cmdText.split`, not `lastStage`). Both now pass `cmdText`/`pipeParts[i]`.
test-pipe-guard.js was rewritten for the new shape and now also asserts the shell override
forwards raw text — the assertion that would have caught the shadowing. RED on HEAD: both flags
false; GREEN now.
2. MAINTENANCE --fix CAN CLEAR ITS OWN WARN. check_index() ran before check_atlas(), which is what
regenerates course/atlas.json, so --fix rebuilt modules-index.json from the stale atlas and the
same WARN reappeared every run. check_atlas() now runs immediately before check_index().
modules-index.json regenerated: cost/usage present, 349 commands, version 2026-10-29-atlas.
3. `cost` DOCUMENTED. modules/core/module-billing.js registers `cost [on|off]` (an alias of `usage`);
help.html had no row. Added above the `usage` row. help coverage 362/363 -> 363/363.
4. SHIPPED PLANS STOP ASKING FOR A DECISION. The applier only flips review<->safe, so every executed
review-gated plan kept counting as an open decision (5 of 5). newos4-feedback-collect.py now reads
the body: a `## Status` / `## Implementation` heading followed by shipped|executed plus a version,
commit or date is `status: done`; those stay in `plans` (visible as shipped) but leave
plans_review and awaiting_decision. Counts: plans_review 5 -> 0, awaiting_decision 4 -> 1
(the remaining one is a real open report, RPT-20261027-160751).
admin/feedback.html read `it.status[0]`, which would render `d` for a string status; it now
prefers `status_lines[0]`.
Also carried, authored by earlier uncommitted sessions and already live in the bundle (attributed,
not silently absorbed): modules/core/module-billing.js (new, BillingModule: cost/usage),
its CORE_FILES entry in scripts/rebuild-bundles.py, and the BillingModule registry entry in
terminal.js. The bundle was rebuilt from HEAD + this batch with ollama-manager.js taken from HEAD,
so another session's in-flight `_httpError` refactor is deliberately NOT in the shipped bundle
(grep -c _httpError core-bundle.js = 0).
Verification
node modules/test/test-pipe-guard.js -> {"empty":[],"blank":[],"classifyGuarded":true,"pipeGuarded":true,"shellForwardsRaw":true}
node modules/test/test-parse-args.js -> 28/28 pass
maintained job -> node tests 21/21 pass
scripts/newos4-maintain.py -> maintenance result: OK (modules-index 349, help 363/363,
changelog current v4.6.131)
live v4.6.131 (real DOM, no print monkey-patch):
js "a b".length | wc -c -> 1 (js printed 3, one byte)
js "a b".length -> 3
js "abc".toUpperCase() -> ABC
echo "two words" -> two words
node -e "import('fs')" -> red error + Node-builtin hint
js 6*7 -> 42
unhandledrejection -> 0
livePipeImpl: shell-override, livePipeForwardsRaw: true, costRegistered: true
Diffstat (limited to 'modules/test')
| -rw-r--r-- | modules/test/test-parse-args.js | 4 | ||||
| -rw-r--r-- | modules/test/test-pipe-guard.js | 36 |
2 files changed, 31 insertions, 9 deletions
diff --git a/modules/test/test-parse-args.js b/modules/test/test-parse-args.js index 75fd7ab..f9836ae 100644 --- a/modules/test/test-parse-args.js +++ b/modules/test/test-parse-args.js @@ -51,6 +51,10 @@ ok('dispatchCommand takes rawText', /async dispatchCommand\(cmd, args, rawText\) ok('module receives rawText', /mod\.commands\[cmd\]\(args, rawText\)/.test(termSrc)); ok('checkAndRun records raw input', /this\._currentRaw\s*=\s*rawInput/.test(termSrc)); ok('_dispatch forwards raw input', /dispatchCommand\(cmd, args, this\._currentRaw/.test(termSrc)); +// Pipes must forward each stage's own text too, otherwise splitPipe()'s raw stage is thrown +// away by a second _parseArgs() pass and `js "a b".length | wc -c` sees `a b.length`. +const chainSrc = termSrc.match(/async executePipeChain\(pipeParts\)\s*\{[\s\S]*?\n\s{12}\}/); +ok('executePipeChain keeps the raw stage', !!chainSrc && /dispatchCommand\(cmd, args, pipeParts\[i\]/.test(chainSrc[0]), chainSrc ? 'no pipeParts[i] passthrough' : 'executePipeChain not found'); // ---- 3. console command uses the raw expression --------------------------------------- const consoleSrc = fs.readFileSync(path.join(extDir, 'console.js'), 'utf8'); diff --git a/modules/test/test-pipe-guard.js b/modules/test/test-pipe-guard.js index 0bd7cc9..7851613 100644 --- a/modules/test/test-pipe-guard.js +++ b/modules/test/test-pipe-guard.js @@ -1,8 +1,13 @@ // modules/test/test-pipe-guard.js — run: node modules/test/test-pipe-guard.js -// Fails fast if either guard is removed or if a guard is placed AFTER the parts[0] read. -// Behavioural proof is the browser matrix (plan Task 8); this test is the cheap tripwire. +// Cheap tripwire for the three things that silently broke pipe handling before: +// 1. _parseArgs('') returning a non-empty argv (parts[0] === undefined -> TypeError, 989 hits) +// 2. the empty-stage guard being placed AFTER the parts[0] read +// 3. v4.6.131: the raw stage text being discarded, in BOTH pipe implementations — the core one +// and the ShellModule override that actually replaces it at boot (measured 2026-10-29: +// terminal.executePipeChain.toString() contained `cmdText.split`, not `lastStage`). const fs = require('fs'), path = require('path'); const src = fs.readFileSync(path.join(__dirname, '../core/terminal.js'), 'utf8'); +const shellSrc = fs.readFileSync(path.join(__dirname, '../ext/shell.js'), 'utf8'); // 1. _parseArgs('') must return [] — that precondition is what made parts[0] undefined. // The source is a CLASS METHOD, so wrap it in an object literal (a bare `new Function('m(){…}')` @@ -19,16 +24,29 @@ const cGuard = src.indexOf('if (!parts.length)', ci); const cRead = src.indexOf('parts[0].toLowerCase()', ci); const classifyGuarded = ci >= 0 && cGuard > ci && cGuard < cRead; +// 3. core executePipeChain: skip empty stages without shifting the index (v4.6.131 replaced the +// `.filter(argv => argv.length > 0)` with a lastStage scan so stages[i] stays aligned with +// pipeParts[i]), and forward each stage's raw text to the dispatcher. const pi = src.indexOf('async executePipeChain('); -const pGuard = src.indexOf('if (!stages.length)', pi); -const pFilter = src.indexOf('.filter(argv => argv.length > 0)', pi); -const pRead = src.indexOf('argv[0].toLowerCase()', pi); -const pipeGuarded = pi >= 0 && pFilter > pi && pGuard > pFilter && pRead > pGuard - && src.indexOf('i < stages.length - 1', pi) > 0; +const body = pi >= 0 ? src.slice(pi, src.indexOf('async capturePipeOutput(', pi)) : ''; +const pEmpty = body.indexOf('if (lastStage < 0)'); +const pSkip = body.indexOf('if (argv.length === 0) continue'); +const pRead = body.indexOf('argv[0].toLowerCase()'); +const pRaw = body.indexOf('dispatchCommand(cmd, args, pipeParts[i])'); +const pipeGuarded = pi >= 0 && pEmpty > 0 && pSkip > pEmpty && pRead > pSkip && pRaw > pRead + && body.indexOf('this.capturePipeOutput(cmd, args, pipeParts[i])') > 0; -const report = { empty, blank, classifyGuarded, pipeGuarded }; +// 4. the override that actually runs: ShellModule.init() replaces terminal.executePipeChain, so a +// fix in the core alone is dead code. Measured live: the wrapper is the shell's. +const si = shellSrc.indexOf('this.terminal.executePipeChain = async function(pipeParts)'); +const shellBody = si >= 0 ? shellSrc.slice(si, shellSrc.indexOf('_splitSequence(', si)) : ''; +const shellForwardsRaw = si >= 0 + && shellBody.indexOf('this.dispatchCommand(cmd, args, cmdText)') > 0 + && shellBody.indexOf('this.capturePipeOutput(cmd, args, cmdText)') > 0; + +const report = { empty, blank, classifyGuarded, pipeGuarded, shellForwardsRaw }; console.log(JSON.stringify(report)); const ok = Array.isArray(empty) && empty.length === 0 && Array.isArray(blank) && blank.length === 0 - && classifyGuarded && pipeGuarded; + && classifyGuarded && pipeGuarded && shellForwardsRaw; process.exit(ok ? 0 : 1); |