Files
oh-my-pi/packages/coding-agent/test
汐 2ae1a042d8 feat(utils): full XDG Base Directory support for all path helpers (#407)
* feat(utils): full XDG Base Directory support for all path helpers

Implement XDG-first resolution across all omp path helpers, extend the
migration command to cover every data/state/cache location, and fix
five data-safety issues found in review.

dirs.ts:
- Add getXdgCachePath() helper ($XDG_CACHE_HOME/omp/<subpath>)
- Add isDefaultAgentDir() helper: XDG lookup is only valid when the
  resolved agentDir equals the process default (~/.omp/agent); custom
  profiles set via PI_CODING_AGENT_DIR or setAgentDir() are never
  silently redirected to the global XDG database
- Update 15 functions to XDG-first resolution:
    data:  getPluginsDir, getRemoteDir, getRemoteHostDir, getPythonEnvDir,
           getWorktreeBaseDir
    state: getReportsDir, getSshControlDir, getCrashLogPath, getDebugLogPath
    cache: getPuppeteerDir, getGpuCachePath, getNativesDir
- Guard XDG lookup with isDefaultAgentDir(agentDir ?? getAgentDir()) in
  all 9 agent-subdir helpers so that callers passing the global default
  agentDir still resolve to the migrated XDG location, while callers
  passing a non-default agentDir or running under a custom profile via
  setAgentDir() bypass XDG entirely
- Plugin-derived helpers delegate to getPluginsDir() and follow XDG
  resolution automatically

migrate-xdg.ts:
- Add getXdgCacheHome() helper
- Extend MigrationItem.category to include 'cache'
- Add 12 new migration entries: reports, plugins, remote, ssh-control,
  remote-host, python-env, puppeteer, wt, gpu_cache.json, natives,
  omp-crash.log, omp-debug.log
- Refuse to run when PI_CODING_AGENT_DIR points to a non-default
  profile: migration only makes sense for the default ~/.omp/agent tree
- copyDirectory returns skipped source paths (target existed, non-force)
- verifyIntegrity: remove size-mismatch early-return that masked stale
  targets as successful copies
- executeMigration: delete only entries that were actually copied;
  use rmdir on source dir so it is removed only when empty, preserving
  any skipped files for a subsequent --force run
- executeMigration: rename partial target to <target>.bak on integrity
  failure instead of deleting; preserves pre-existing user data while
  preventing getXdgDataPath from treating the partial tree as
  authoritative; source remains intact for re-copy on next run

test isolation:
- Set XDG_DATA_HOME/XDG_STATE_HOME to non-existent paths in
  memories-runtime.test.ts beforeEach/afterEach to prevent
  getXdgDataPath/getXdgStatePath from resolving to real user data

* fix(utils,coding-agent): fix XDG support issues

dirs.ts:
- Refactor path resolution into DirResolver class. XDG base dirs are
  resolved once at construction from env vars (Linux only, no
  existsSync). setAgentDir creates a fresh instance, naturally
  invalidating all cached paths and recomputing isDefaultProfile.
- getRootSubdir/agentSubdir accept optional XdgCategory parameter;
  when set, the XDG base replaces the config root. Every accessor
  is a one-liner delegate.
- Non-Linux platforms: XDG fields are null, zero overhead. No
  filesystem probing, no string comparisons on the hot path.
- Config-only subdirs (themes, tools, commands, prompts, modules)
  have no XDG category — they stay under the config root.
- Remove `import { env } from 'bun'`, use process.env consistently.
- Restore JSDoc comments to document actual defaults (~/.omp/...).

migrate-xdg.ts:
- Gate migrateToXdg on Linux — exits with clear error on other
  platforms.
- Fix data loss bug: verifyIntegrity now accepts a Set of skipped
  paths and skips verification for files that were intentionally not
  copied (pre-existing at target in non-force mode).
- Fix nested directory source deletion: recursive removeSourceEntries
  walks the tree and only deletes files not in the skipped set.
- Remove dead _sourcePath variable and unused force parameter from
  verifyIntegrity.
- Remove `import { env } from 'bun'`, use process.env consistently.

logger.ts:
- Revert JSDoc to document ~/.omp/logs/ as default.

oauth.ts:
- Replace direct getAgentSubdir call with getTestAuthPath().

CHANGELOG.md:
- Merge duplicate section headers under [Unreleased].
- Add missing blank line before [13.11.1].

---------

Co-authored-by: can1357 <me@can.ac>
2026-03-14 14:52:12 +01:00
..
2026-03-14 10:46:26 +01:00
2026-03-14 10:46:26 +01:00