Repository navigation
fix: cross-platform body-dump paths via XDG state dir (#864) - #865
Conversation
src/loop/core.ts: the compress-loop REREQUEST dump (ACP_DUMP_BODY=1) used a
raw `${process.env.HOME}/.local/state/billion-context/dumps` path. $HOME is
undefined on Windows, so mkdirSync created a junk `undefined/.local/...`
directory under cwd, and XDG_STATE_HOME was ignored — inconsistent with the
other two dump sites which used stateDir(). Now uses dumpsDir(). The session
id in the filename is also sanitized like error-dump.ts does: session ids are
client-provided verbatim (src/session-id.ts) and could contain '/'.
src/paths.ts: new dumpsDir() = ACP_DUMP_DIR override || <stateDir>/dumps,
so every dump writer (server req JSON + raw REQ/RES/INCOMING, loop REREQUEST,
BILI_DUMP_4XX err dumps) shares one location that co-locates with bili.log.
src/server.ts / src/error-dump.ts: slash-concatenated dump paths -> path.join.
src/ca.ts: explicit win32 branch in PLATFORM_CA_CANDIDATES (empty list —
Node's Mozilla root set is the only root source on Windows) instead of
falling through to Linux bundle paths that can never exist there.
tests/issue-393-registry-window.test.ts: logFile /tmp/issue-393-test.log ->
os.tmpdir(); on Windows the old path silently degraded to stderr-only logging
so file logging was never actually exercised there.
tests/dumps-dir.test.ts: unit tests for dumpsDir() precedence (ACP_DUMP_DIR >
XDG_STATE_HOME > ~/.local/state default).
Pre-flight: typecheck OK, 1514 tests pass / 0 fail, build OK.
a3a22f1 to
dd5ee7e
Compare
📦 Built Package ArtifactBranch: Option A — Install from npm PR tag (recommended)npm install -g billion-context@pr-865Each push to this PR publishes a new version under the Option B — Download artifact
tar xzf billion-context-pr865.tgz
npm install -g packageInstall instructions are refreshed on each push. |
[bot] 🏷 Review update — rebased onto current master, CI in flight While reviewing I found the PR had gone unmergeable ( Per the repo's review discipline (rebase to current master before claiming mergeable), I:
Hot-file check: several open PRs also touch Code review itself is done and positive (see my earlier comment for the full walkthrough). Final verdict pending the CI matrix (ubuntu/windows × node 22/24 + zero-token e2e + version-guard) on |
Windows CI failed 'dumpsDir: respects XDG_STATE_HOME': stateDir() resolves the env override via path.resolve (paths.ts xdg()), which on win32 turns the drive-relative fixture /custom/state into <cwd-drive>:\custom\state, while the test's bare path.join expectation stayed drive-less. Mirror the product resolution in the assertion instead of hardcoding POSIX semantics.
[bot] 🏷 Review complete — two commits added by me during review, verdict below Code review (the fix itself): positive. All seven files are on-purpose and minimal; no stray changes, no lock-file churn,
What I changed while reviewing (both pushed to the PR head; nothing merged):
CI on final head
Verdict: this PR is clean, correct in both compression modes, and mergeable from its own scope once master's #857 test is dealt with (either fixed first, or merged knowingly-red at your call — merge is yours, not mine). Hot-file note: several open PRs touch 中文摘要:PR 代码本身审查通过(路径统一走 XDG、会话 id 已消毒、CA 空列表安全);review 期间我直接补了两个 commit——rebase 到最新 master(解决一处 import 冲突)+ 修复新测试在 Windows 上必挂的断言( |
What
Issue #864 asked to find and fix all hardcoded Linux directories so bili works cross-platform, following the XDG spec where applicable.
Investigation result:
src/contained no literal/tmp— every temp-file site already usesos.tmpdir(), andsrc/paths.tsalready implements the XDG base dirs (XDG_CONFIG_HOME/XDG_DATA_HOME/XDG_CACHE_HOME/XDG_STATE_HOMEwith~/.config,~/.local/share,~/.cache,~/.local/statefallbacks). The real offenders were the four body-dump writers, three of which disagreed about where dumps go:src/loop/core.ts(REREQUEST dump,ACP_DUMP_BODY=1)${process.env.HOME}/.local/state/billion-context/dumps$HOMEis undefined on Windows →mkdirSynccreated a junkundefined/.local/...tree under cwd; ignoredXDG_STATE_HOME; inconsistent with the other sitessrc/server.ts(req JSON + raw REQ/RES/INCOMING)${stateDir()}/dumps,${stateDir()}/rawslash-concatenatedsrc/error-dump.ts(BILI_DUMP_4XX)tests/issue-393-registry-window.test.ts/tmp/issue-393-test.logChanges
src/paths.ts: newdumpsDir()=ACP_DUMP_DIRoverride ‖path.join(stateDir(), "dumps"). All dump writers now share one XDG-based location that co-locates withbili.log.src/loop/core.ts: REREQUEST dump usesdumpsDir(). Also sanitizes the session id embedded in the filename ([^a-zA-Z0-9_-]→_) likeerror-dump.tsalready did — session ids are client-provided verbatim (seesrc/session-id.ts), so a hostile id containing/would previously break or escape the path.src/server.ts/src/error-dump.ts: slash-concatenated paths →path.join.src/ca.ts: explicitwin32branch inPLATFORM_CA_CANDIDATES(empty list — Node's built-in Mozilla root set is the only root source on Windows) instead of falling through to Linux bundle paths that can never exist there. Behavior unchanged; the list no longer lies about what is probed.tests/issue-393-registry-window.test.ts:/tmp/...→os.tmpdir().tests/dumps-dir.test.ts(new): unit tests fordumpsDir()precedence —ACP_DUMP_DIR>XDG_STATE_HOME>~/.local/state/billion-context/dumpsdefault.Reviewed and intentionally unchanged:
src/launcher.ts/src/client-config.ts/src/discover.ts/src/plugin-install.ts/src/update.ts/src/decompress-shared.ts(all alreadyos.homedir()/os.tmpdir()/XDG-based), test fixture strings that are pure mock values without real I/O, and the e2e suite's repo-localtmp/working dir (deliberate — codex refuses TMPDIR homes).Windows keeps the documented
%USERPROFILE%\.config|\.local\share|\.local\state\billion-contextlayout rather than mapping to%APPDATA%: changing it now would orphan existing sessions and CA state with zero user benefit.Pre-flight
npm run typecheck✓npm test✓ (1514 pass / 0 fail / 2 skipped e2e-gated)npm run build✓Closes #864