Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

test: enforce Windows .exe basename contract in allowedCommands test (#2549)

Adam Eivydca535165b96
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 5f90ac8d2f..cd9fe7d8e2 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -19,6 +19,7 @@
## Fixed
- **POST session run page crashed (React error #130) when transitioning into a cognitive drill.** `DrillTransition.jsx`'s `DOMAIN_ICONS` map was missing a `cognitive` entry, yet `DRILL_TO_DOMAIN` maps every cognitive drill type (n-back, digit-span, stroop, schulte-table, mental-rotation, reaction-time) to the `cognitive` domain — so finishing a drill whose successor was a cognitive drill (e.g. a Doubling Chain followed by a cognitive drill) resolved the transition-card icon to `undefined` and blanked the run page with a minified React error. Added the `cognitive: Brain` icon and hardened the lookup to fall back to `ChevronRight` for any unmapped domain, so a future domain gap degrades gracefully instead of crashing. A regression test renders the transition for every `DRILL_TO_DOMAIN` type.
+- **[issue-2549] Enforce the Windows `.exe` basename contract in the CoS Runner allowlist test.** The `allowedCommands.test.js` case for a Windows absolute path (`C:\\...\\claude.exe`) ended on `expect(typeof result).toBe('boolean')`, which passes for any boolean — so on POSIX CI the Windows path handling was never actually asserted and a regression would go unnoticed. It's replaced with concrete assertions: a POSIX-style `.exe` path (`/opt/tools/claude.exe`) that exercises the basename-then-strip logic deterministically on every OS (allowed), a matching rejection for a non-allowlisted `.exe` (`/opt/tools/bash.exe`), and a per-platform assertion for the real backslash form that expects `true` on `win32` and `false` on POSIX (where `path.basename` doesn't split backslashes). Both new assertions were verified to fail against a broken implementation (dropping the `.exe` strip; forcing `win32` basename on POSIX). Test-only change — no runtime behavior change.
- **[issue-2536] Catch unhandled rejections from Telegram handlers and health/probe timers.** Several async boundaries were fire-and-forget: the Telegram client dispatched `onText`/`emitter.on` handlers without awaiting or catching, `telegram.js` ran `setInterval(healthCheck)` and a couple of sync-context `bot.sendMessage(...)` calls without a `.catch`, and `instances.js` scheduled `probeAllPeers()` from `setTimeout`/`setInterval` without one — so a rejected handler or a failed fs/network read leaked an unhandled promise rejection (process-killing on Node ≥15). The client now routes every handler invocation through a `runHandler` wrapper that logs a single emoji-prefixed line on rejection; the health-check interval and both probe timers wrap their async callback in `.catch`; and the `/start`, `/help`, and unauthorized-notice sends now await or `.catch` their promise. A vitest suite drives the client's `onText` and `message` paths with a throwing handler and asserts no `unhandledRejection` escapes.
- **[issue-2519] CoS handlers no longer flash a false-success toast after a failed API call.** Several Chief of Staff actions (`handleForceEvaluate` on the CoS page, the Tasks tab "Run Now" button, and the Config tab's Save + autonomy-level change) `.catch`-swallowed the request rejection and then unconditionally toasted success and mutated optimistic UI — so a network/server error still read as "done." Each now awaits inside try/catch and only toasts success / advances state after the request resolves: a failed Save keeps the editor open, and a failed autonomy-level change reverts the optimistic form params. Errors surface via a single `toast.error` (the calls already pass `{ silent: true }`).
- **[issue-2520] Pass `{ silent: true }` on client API calls that own a custom error toast.** Several call sites routed a request through the auto-toasting `request()` helper AND showed their own `toast.error` in `.catch`, so a failure surfaced two stacked toasts. The music managers (Artists/Albums/Tracks load + create/update/delete), MusicVideo (list/create/delete/analyze/plan/add-scene/delete-scene/reorder), and DataDog (load/save/delete/test) now pass `{ silent: true }` on those calls; CharacterSheet's local `charGet`/`charPost`/`charPut` helpers are silent-by-default (every caller owns its own catch toast or the `loadError` banner) with an opt-out. Each failing action now shows a single toast.
diff --git a/server/cos-runner/allowedCommands.test.js b/server/cos-runner/allowedCommands.test.js
index 7b3f110936..0c454ca03d 100644
--- a/server/cos-runner/allowedCommands.test.js
+++ b/server/cos-runner/allowedCommands.test.js
@@ -36,17 +36,30 @@ describe('isAllowedCommand', () => {
expect(isAllowedCommand('claude.EXE')).toBe(true);
});
- it('allows C:\\Users\\user\\AppData\\Local\\claude.exe', () => {
- // On Windows: basename('C:\\...\\claude.exe') → 'claude.exe' with path module
- // On Unix: basename treats it as one segment — but we still strip the .exe
+ // Deterministic on EVERY OS: a POSIX-style absolute path whose basename is
+ // "claude.exe". path.basename('/opt/tools/claude.exe') === 'claude.exe' on
+ // both win32 and posix, so after the .exe strip the result is 'claude' and
+ // the command is allowed regardless of the host running the test. This
+ // enforces the "strip .exe after basename" contract on all platforms —
+ // it fails concretely (not via typeof) if the .exe stripping regresses.
+ it('allows a full path ending in claude.exe on all OSes (/opt/tools/claude.exe)', () => {
+ expect(isAllowedCommand('/opt/tools/claude.exe')).toBe(true);
+ });
+
+ it('rejects a full path ending in a non-allowed .exe (/opt/tools/bash.exe)', () => {
+ expect(isAllowedCommand('/opt/tools/bash.exe')).toBe(false);
+ });
+
+ // The real Windows backslash form. path.basename is platform-specific:
+ // on win32 it splits on "\\" → 'claude.exe' → strip → 'claude' (allowed);
+ // on posix backslashes are ordinary chars so basename returns the whole
+ // string → 'C:\\...\\claude' after strip → not allowed. Assert the concrete
+ // expected boolean per-platform so a regression in EITHER direction fails
+ // here — never `typeof result === 'boolean'`, which passes for any boolean.
+ it('resolves a Windows backslash .exe path per-platform', () => {
const windowsPath = 'C:\\Users\\user\\AppData\\Local\\claude.exe';
- // basename() on POSIX returns the whole string for a Windows path —
- // the .exe strip still makes it pass IF the full-basename is 'claude.exe'.
- // Test the logic contract: after strip, the result is 'claude'.
- const result = isAllowedCommand(windowsPath);
- // On POSIX, basename('C:\\...\\claude.exe') is the whole string which
- // won't match 'claude', so we just assert the function doesn't throw.
- expect(typeof result).toBe('boolean');
+ const expected = process.platform === 'win32';
+ expect(isAllowedCommand(windowsPath)).toBe(expected);
});
});