aboutsummaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/core/core-bundle.js3
-rw-r--r--modules/core/module-loader.js2
-rw-r--r--modules/core/terminal.js3
-rw-r--r--modules/ext/critical-ext-bundle.js44
-rw-r--r--modules/ext/shell.js44
-rw-r--r--modules/test/test-shell-test-cmd.js98
6 files changed, 189 insertions, 5 deletions
diff --git a/modules/core/core-bundle.js b/modules/core/core-bundle.js
index b070e65..07609e3 100644
--- a/modules/core/core-bundle.js
+++ b/modules/core/core-bundle.js
@@ -4553,6 +4553,9 @@ Only output XML function calls for tool tasks. If no tool is needed, answer norm
}
return; }
catch (err) {
+ // v4.6.134: `silent` errors are control flow, not failures — `test`/`[`
+ // reject to tell `&&`/`||` to skip, and must print nothing (POSIX).
+ if (err && err.silent) return;
this.print(`Error in ${modName}.${cmd}: ${err.message}`, 'error');
console.error(`[Terminal] Error in ${modName}.${cmd}:`, err);
return;
diff --git a/modules/core/module-loader.js b/modules/core/module-loader.js
index 0d39123..52cee36 100644
--- a/modules/core/module-loader.js
+++ b/modules/core/module-loader.js
@@ -4,7 +4,7 @@
// Core module bundle loaded synchronously in main.html.
// This loader only handles version cache-busting, splash, terminal init, and optional ext modules.
- const LATEST_VER = 'v4.6.132';
+ const LATEST_VER = 'v4.6.135';
const CACHE = '?v=' + LATEST_VER;
// Exposed so ext modules can register their own URL with the same cache-busting version
// instead of an unversioned path the browser may already have cached (shell.js did).
diff --git a/modules/core/terminal.js b/modules/core/terminal.js
index 4122b3c..ca6bb61 100644
--- a/modules/core/terminal.js
+++ b/modules/core/terminal.js
@@ -1961,6 +1961,9 @@
}
return; }
catch (err) {
+ // v4.6.134: `silent` errors are control flow, not failures — `test`/`[`
+ // reject to tell `&&`/`||` to skip, and must print nothing (POSIX).
+ if (err && err.silent) return;
this.print(`Error in ${modName}.${cmd}: ${err.message}`, 'error');
console.error(`[Terminal] Error in ${modName}.${cmd}:`, err);
return;
diff --git a/modules/ext/critical-ext-bundle.js b/modules/ext/critical-ext-bundle.js
index 0f2e1b9..53f1205 100644
--- a/modules/ext/critical-ext-bundle.js
+++ b/modules/ext/critical-ext-bundle.js
@@ -170,6 +170,46 @@ class ShellModule {
this.commands['script'] = (args) => this._cmdScript(args);
this.commands['sh'] = (args) => this._cmdScript(args);
this.commands['set'] = () => this._cmdSet();
+ // v4.6.133: `test` / `[` were not registered, so `[ -f /x ] && echo yes` fell through to the
+ // AI fallback and asked a model whether a file exists. _evalTest() already implemented the
+ // operators (-f -d -e -z -n ! = !=) for the if/while parser; the command was simply missing.
+ // `test` already means "run the regression suite" in the on-demand test-suite module, so a
+ // non-expression argument list is delegated to whatever handler was registered before us.
+ const prevTest = this.commands['test'];
+ this.commands['test'] = (args) => this._cmdTest(args, 'test', prevTest);
+ this.commands['['] = (args) => this._cmdTest(args, '[');
+ }
+
+ /** True when the argv looks like a POSIX test expression rather than a suite-runner subcommand. */
+ _looksLikeTest(expr) {
+ if (!expr) return false;
+ if (/^(?:!(?:\s|$)|-[fderwxszn]\b)/.test(expr)) return true; // `-f x`, `! -d y`
+ if (/\s(?:=|==|!=)\s/.test(expr)) return true; // `a = b`
+ return false;
+ }
+
+ /** POSIX-ish `test`/`[`: silent on success, throws a silent error on false so `&&`/`||` skip. */
+ _cmdTest(args, name, fallback) {
+ let expr = (args || []).join(' ').trim();
+ if (name === 'test' && !this._looksLikeTest(expr) && typeof fallback === 'function') {
+ return fallback(args); // `test`, `test auto`, `test list` -> the suite runner
+ }
+ if (name === '[') {
+ if (!expr.endsWith(']')) throw new Error("[ : missing ']'");
+ expr = expr.slice(0, -1).trim();
+ }
+ if (!expr) { // `test` with no expression: false, and no output
+ const e = new Error(''); e.silent = true; throw e;
+ }
+ if (!this._evalTest(expr)) {
+ const e = new Error(''); e.silent = true; throw e; // POSIX: exit 1 prints nothing
+ }
+ }
+
+ /** Error printer shared by the shell paths: `silent` errors are control flow (a false test), not failures. */
+ _printErr(term, e) {
+ if (!e || e.silent) return;
+ (term || this.terminal).print('Error: ' + (e.message || e), 'error');
}
// ── Hook into terminal.executeCommand ──
@@ -259,7 +299,7 @@ class ShellModule {
await self.commands[cmd](args);
lastOk = true;
} catch(e) {
- this.print('Error: ' + e.message, 'error');
+ self._printErr(this, e);
lastOk = false;
}
} else {
@@ -267,7 +307,7 @@ class ShellModule {
await this.security.checkAndRun(expandedCmd);
lastOk = true;
} catch(e) {
- this.print('Error: ' + e.message, 'error');
+ self._printErr(this, e);
lastOk = false;
}
}
diff --git a/modules/ext/shell.js b/modules/ext/shell.js
index cb26484..ff07d92 100644
--- a/modules/ext/shell.js
+++ b/modules/ext/shell.js
@@ -34,6 +34,46 @@ class ShellModule {
this.commands['script'] = (args) => this._cmdScript(args);
this.commands['sh'] = (args) => this._cmdScript(args);
this.commands['set'] = () => this._cmdSet();
+ // v4.6.133: `test` / `[` were not registered, so `[ -f /x ] && echo yes` fell through to the
+ // AI fallback and asked a model whether a file exists. _evalTest() already implemented the
+ // operators (-f -d -e -z -n ! = !=) for the if/while parser; the command was simply missing.
+ // `test` already means "run the regression suite" in the on-demand test-suite module, so a
+ // non-expression argument list is delegated to whatever handler was registered before us.
+ const prevTest = this.commands['test'];
+ this.commands['test'] = (args) => this._cmdTest(args, 'test', prevTest);
+ this.commands['['] = (args) => this._cmdTest(args, '[');
+ }
+
+ /** True when the argv looks like a POSIX test expression rather than a suite-runner subcommand. */
+ _looksLikeTest(expr) {
+ if (!expr) return false;
+ if (/^(?:!(?:\s|$)|-[fderwxszn]\b)/.test(expr)) return true; // `-f x`, `! -d y`
+ if (/\s(?:=|==|!=)\s/.test(expr)) return true; // `a = b`
+ return false;
+ }
+
+ /** POSIX-ish `test`/`[`: silent on success, throws a silent error on false so `&&`/`||` skip. */
+ _cmdTest(args, name, fallback) {
+ let expr = (args || []).join(' ').trim();
+ if (name === 'test' && !this._looksLikeTest(expr) && typeof fallback === 'function') {
+ return fallback(args); // `test`, `test auto`, `test list` -> the suite runner
+ }
+ if (name === '[') {
+ if (!expr.endsWith(']')) throw new Error("[ : missing ']'");
+ expr = expr.slice(0, -1).trim();
+ }
+ if (!expr) { // `test` with no expression: false, and no output
+ const e = new Error(''); e.silent = true; throw e;
+ }
+ if (!this._evalTest(expr)) {
+ const e = new Error(''); e.silent = true; throw e; // POSIX: exit 1 prints nothing
+ }
+ }
+
+ /** Error printer shared by the shell paths: `silent` errors are control flow (a false test), not failures. */
+ _printErr(term, e) {
+ if (!e || e.silent) return;
+ (term || this.terminal).print('Error: ' + (e.message || e), 'error');
}
// ── Hook into terminal.executeCommand ──
@@ -123,7 +163,7 @@ class ShellModule {
await self.commands[cmd](args);
lastOk = true;
} catch(e) {
- this.print('Error: ' + e.message, 'error');
+ self._printErr(this, e);
lastOk = false;
}
} else {
@@ -131,7 +171,7 @@ class ShellModule {
await this.security.checkAndRun(expandedCmd);
lastOk = true;
} catch(e) {
- this.print('Error: ' + e.message, 'error');
+ self._printErr(this, e);
lastOk = false;
}
}
diff --git a/modules/test/test-shell-test-cmd.js b/modules/test/test-shell-test-cmd.js
new file mode 100644
index 0000000..6abdd11
--- /dev/null
+++ b/modules/test/test-shell-test-cmd.js
@@ -0,0 +1,98 @@
+// node modules/test/test-shell-test-cmd.js
+//
+// `test` / `[` were not registered, so `[ -f /x ] && echo yes` fell through to the AI fallback and
+// asked a model whether a file exists (measured 2026-10-29 on v4.6.132). _evalTest() already had the
+// operators; the command was missing. Contract pinned here:
+// success -> resolves silently
+// false -> rejects with a `silent` error (so `&&`/`||` skip without printing "Error: ")
+// `[` -> requires the closing bracket, never delegates
+// `test` -> a non-POSIX argv still reaches the regression-suite runner registered before it
+const fs = require('fs'), path = require('path');
+// shell.js ends with `if (typeof window.webx11 !== 'undefined' && window.webx11) { … }` — and
+// `typeof window.webx11` throws when `window` itself is undeclared, so give it an empty object.
+global.window = {};
+const src = fs.readFileSync(path.join(__dirname, '../ext/shell.js'), 'utf8');
+const ShellModule = new Function(src + '\n;return typeof ShellModule !== "undefined" ? ShellModule : null;')();
+
+let pass = 0, fail = 0;
+const ok = (name, cond, detail) => { cond ? pass++ : (fail++, console.log('FAIL ' + name + (detail ? ' — ' + detail : ''))); };
+const eq = (name, got, want) => ok(name, JSON.stringify(got) === JSON.stringify(want), 'got ' + JSON.stringify(got) + ' want ' + JSON.stringify(want));
+
+function mk(filesArg) {
+ const printed = [];
+ const files = filesArg || { '/a.txt': 'x', '/dir': null }; // null => directory
+ const term = {
+ print: (m, lvl) => printed.push({ m: String(m), lvl: lvl || 'plain' }),
+ markDirty: () => {},
+ fs: {
+ currentPath: [],
+ readFile: p => (typeof files[p] === 'string' ? files[p] : null),
+ readDir: p => (p in files && files[p] === null ? [] : null)
+ },
+ // A real (simple) parser: the assertions prove _tokenize delegates by counting the calls.
+ security: { calls: 0, _parseArgs: function (s) { this.calls++; return s.trim() ? s.trim().split(/\s+/) : []; } }
+ };
+ const m = new ShellModule();
+ m.terminal = term;
+ m.registerCommands();
+ return { m, term, printed };
+}
+
+const throws = async (fn) => { try { await fn(); return null; } catch (e) { return e; } };
+
+(async () => {
+ const { m, term, printed } = mk();
+
+ ok('test command registered', typeof m.commands['test'] === 'function');
+ ok('[ command registered', typeof m.commands['['] === 'function');
+
+ ok('test -f existing file -> resolves', await throws(() => m.commands['test'](['-f', '/a.txt'])) === null);
+
+ const missing = await throws(() => m.commands['test'](['-f', '/nope']));
+ ok('test -f missing file -> rejects', !!missing);
+ ok('rejection is silent', !!missing && missing.silent === true, 'silent=' + (missing && missing.silent));
+ ok('rejection carries no message', !!missing && !missing.message, 'msg=' + JSON.stringify(missing && missing.message));
+
+ ok('[ -f /a.txt ] -> resolves', await throws(() => m.commands['['](['-f', '/a.txt', ']'])) === null);
+
+ const noBracket = await throws(() => m.commands['['](['-f', '/a.txt']));
+ ok('[ without ] -> rejects', !!noBracket && /missing '\]'/.test(noBracket.message), noBracket && noBracket.message);
+ ok('[ without ] is NOT silent (a syntax error must be visible)', !!noBracket && !noBracket.silent);
+
+ ok('test -d dir -> resolves', await throws(() => m.commands['test'](['-d', '/dir'])) === null);
+ ok('test -d file -> rejects', !!(await throws(() => m.commands['test'](['-d', '/a.txt']))));
+
+ const noExpr = await throws(() => m.commands['test']([]));
+ ok('test with no fallback and no args -> silent reject (POSIX false)', !!noExpr && noExpr.silent === true);
+
+ // shared printer: silent errors print nothing, real ones print "Error: …"
+ printed.length = 0;
+ m._printErr(term, Object.assign(new Error(''), { silent: true }));
+ ok('_printErr swallows silent errors', printed.length === 0, JSON.stringify(printed));
+ m._printErr(term, new Error('boom'));
+ eq('_printErr prints real errors', printed, [{ m: 'Error: boom', lvl: 'error' }]);
+
+ // _tokenize must delegate to the security parser, never to split(/\s+/) of its own
+ const before = term.security.calls;
+ eq('_tokenize delegates to security._parseArgs', m._tokenize('anything at all'), ['anything', 'at', 'all']);
+ ok('_tokenize actually called the parser', term.security.calls > before, 'calls=' + term.security.calls);
+ eq('_tokenize empty -> []', m._tokenize(' '), []);
+ eq('_tokenize undefined -> []', m._tokenize(undefined), []);
+
+ // `test` also names the on-demand regression-suite runner ("test auto" / "test list").
+ const { m: d } = mk();
+ const seen = [];
+ const prev = d.commands['test'];
+ d.commands['test'] = (args) => d._cmdTest(args, 'test', (a) => { seen.push(a); return 'suite'; });
+ ok('previous handler is what delegation falls back to', typeof prev === 'function');
+
+ ok('test auto delegates to the suite runner', (await d.commands['test'](['auto'])) === 'suite' && JSON.stringify(seen) === '[["auto"]]', JSON.stringify(seen));
+ ok('bare test delegates to the suite runner', (await d.commands['test']([])) === 'suite' && seen.length === 2, JSON.stringify(seen));
+ ok('test -f still runs POSIX (no delegation)', (await throws(() => d.commands['test'](['-f', '/a.txt']))) === null && seen.length === 2, 'seen=' + JSON.stringify(seen));
+ ok('string equality form runs POSIX', (await throws(() => d.commands['test'](['/a.txt', '=', '/a.txt']))) === null && seen.length === 2, 'seen=' + JSON.stringify(seen));
+ const t2 = await throws(() => d.commands['['](['-f', '/nope', ']']));
+ ok('[ never delegates', !!t2 && t2.silent === true, JSON.stringify(seen));
+
+ console.log(pass + '/' + (pass + fail) + ' pass');
+ process.exit(fail ? 1 : 0);
+})();