Files
SeedPass/js/packages/cli/test/helpers/platform.ts
T
thePR0M3TH3ANandClaude Opus 5 e2e9aa851e Fix what three platforms found: two shipped bugs, four unportable tests
The platform workflow's first run produced seventeen failures on Windows and
macOS, where the JavaScript suite had never executed. Two were real defects
in shipped code.

A CONTAINMENT CHECK THAT REFUSED EVERYTHING ON WINDOWS

`resolveWithinProfile` compared `target.startsWith(root + "/")` with a
hardcoded forward slash. On Windows `resolve()` returns
`C:\profile\file.txt` and the comparison asked for `C:\profile/`, so it
matched nothing: document export and import refused every path, including
legitimate ones. It failed CLOSED, so nothing leaked — the feature simply did
not work. Now uses `relative()`, which needs no separator of our choosing.

A COMMAND PARSER THAT ATE WINDOWS PATHS

`parseCommandSpec` treated backslash as a POSIX escape unconditionally, so
`--exec "C:\Program Files\tool.exe"` was spawned as the command `C:Program`
with an argument `Filestool.exe`. Every Windows path handed to --exec or
--stdin-to was mangled before the spawn. This is the SECOND instance of this
exact bug today — the Python TUI palette had it too — which is what a whole
class looks like rather than a one-off.

`windows` is an explicit parameter, not a `process.platform` read, so both
branches are tested from either platform. That parameter is the actual fix
for the class: the reason these survived is that the Windows branch could
only ever run on Windows.

THE REST WERE TESTS, NOT CODE

- `/bin/true` does not exist on macOS (it is /usr/bin/true), so a spawn failed
  with ENOENT and the refusal looked like the daemon's crash-safety fix having
  regressed. Now uses process.execPath, which exists everywhere by definition.
- The oversized-request test treated its own EPIPE as fatal. The daemon caps
  the line, answers and hangs up; on macOS that hangup lands while the client
  is still pushing the remaining megabyte. Correct server behaviour was
  failing the test on one platform and passing on the other.
- Three sink tests wrote `#!/bin/sh` files. Shebangs and /bin/sh do not exist
  on Windows. Now Node scripts run by the interpreter already running the
  tests.
- Eight `0600` assertions and two clipboard tests are guarded by documented
  constants in test/helpers/platform.ts. Windows has no POSIX mode bits and
  the runner has no clipboard.

The skips state a gap rather than closing it, and TODO.md now records that the
Windows permissions question grew from two Python tests to ten across both
languages — including the vault index and the semantic index, which hold
secrets. With TypeScript becoming the only implementation that is a shipping
question, not a test-suite one.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01Vtx94nXDmNgXEeThUZP4QN
2026-08-20 14:39:52 -04:00

43 lines
1.7 KiB
TypeScript

/**
* Platform guards for tests, with the reason attached to each.
*
* These exist so a skip is a stated decision rather than a quiet gap. The
* JavaScript suite first ran on Windows and macOS on 2026-08-20 and produced
* seventeen failures. Most were real bugs and got fixed — a Windows path
* containment check that refused everything, a command parser that ate
* backslashes, tests naming `/bin/true` and `cat`. What is left behind these
* constants are the cases where the property under test does not exist on
* that platform at all.
*
* Use as `it.skipIf(NO_POSIX_PERMISSIONS)("...", ...)`.
*/
import process from "node:process";
export const IS_WINDOWS = process.platform === "win32";
/**
* POSIX mode bits — every `0600` assertion.
*
* Windows has no such thing: `chmod` toggles a read-only flag and `stat`
* reports 0o666 whatever you asked for, so these assertions cannot hold.
* Skipped rather than relaxed, because the property is real and a weakened
* assertion would answer it falsely.
*
* Skipping does NOT answer the underlying question, which is tracked in
* TODO.md: on Windows these files inherit directory ACLs instead of carrying
* an explicit owner-only mode, and the vault index, the semantic index and
* the recovery-drill key all hold secrets. Verifying that the inherited ACL
* is user-scoped, and asserting THAT on Windows, is the real fix.
*/
export const NO_POSIX_PERMISSIONS = IS_WINDOWS;
/**
* A working system clipboard.
*
* The Windows CI runner is headless and has none, so clipboardSink writes
* nowhere and reads back empty. Nothing about the code is wrong; there is no
* clipboard to put a secret on.
*/
export const NO_CLIPBOARD = IS_WINDOWS;