diff options
Diffstat (limited to 'modules/test/test-pipe-guard.js')
| -rw-r--r-- | modules/test/test-pipe-guard.js | 36 |
1 files changed, 27 insertions, 9 deletions
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); |