test(cli): deterministic torn-write regression coverage; document module

Address the openchamber-ai review's non-blocking notes:

- Concurrency evidence: the torn-write test now injects a slow, chunked
  writeFile (one open handle, file grows prefix->full) so a torn read is
  deterministically observable in the 30ms window. A companion test runs the
  naive direct writer under the same load and asserts torn reads ARE produced,
  proving the atomicity test can actually fail on the pre-fix writer.
- Windows fallback comment: no longer claims the copyFile fallback is atomic;
  it is called out as a last resort confined to Windows.
- Module map: document cli-settings-accessors.js in bin/lib/DOCUMENTATION.md.
This commit is contained in:
quiz152
2026-08-09 11:39:42 +08:00
parent 7a165fd0bb
commit 95338dbbb1
3 changed files with 101 additions and 34 deletions
+12
View File
@@ -78,6 +78,18 @@ These modules hold reusable, non-presentational logic for commands.
- `cli-paths.js`
- Data, run, log, settings, tunnel profile, and managed-local config paths.
- `cli-settings-accessors.js`
- Minimal settings.json read/write for CLI contexts that must not load the
full web settings runtime (`connect-url` relay identity resolution).
- Mirrors the settings runtime's guarantees so a CLI read-modify-write can
never corrupt shared state: atomic tmp+rename writes (no concurrent reader
in the running app can observe a torn file), a strict read that throws on
corrupt/unreadable payloads, and the same `0600` file mode.
- The strict read gates relay identity regeneration exactly like the server
runtime: a swallowed read failure can never mint a replacement signing or
encryption keypair, which would change `serverId` and orphan every paired
device and push binding.
- `cli-process.js`
- PID files, instance registry files, process identity checks, runtime metadata checks, and process termination helpers.