Skip to content

feat: extract opencode_xdg.ts helper module - #566

Merged
jeonghun-jj-lee merged 1 commit into
mainfrom
560-extract-opencode-xdg
Aug 25, 2026
Merged

jeonghun-jj-lee merged 1 commit into
mainfrom
560-extract-opencode-xdg

Conversation

@jeonghun-jj-lee

@jeonghun-jj-lee jeonghun-jj-lee commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Closes #560

What

Extracts XDG path resolution into a standalone helper module (packages/extension/src/opencode_xdg.ts) with two pure functions:

  • opencodeConfigDir() — returns $XDG_CONFIG_HOME/opencode or ~/.config/opencode
  • opencodeDataDir() — returns $XDG_DATA_HOME/opencode or ~/.local/share/opencode

Why

Centralizes XDG logic currently inlined in chat_bridge.ts (and future consumers) into a single, tested module with no side effects.

Testing

4 vitest cases covering both env-set and env-unset branches for each function, with os.homedir() mocked to a predictable path.

Summary by CodeRabbit

  • New Features

    • Added support for resolving OpenCode configuration and data directories using XDG environment settings.
    • Added sensible home-directory fallbacks when custom XDG locations are not configured.
  • Tests

    • Added coverage for custom directory settings and default path resolution.

Add pure path-resolution helpers for XDG-compliant opencode config and data
directories:

- opencodeConfigDir(): $XDG_CONFIG_HOME/opencode or ~/.config/opencode
- opencodeDataDir(): $XDG_DATA_HOME/opencode or ~/.local/share/opencode

No side effects — consumers decide whether to mkdir. Reads env at call time
so tests can mock without module-reload hacks.
@jeonghun-jj-lee
jeonghun-jj-lee merged commit bee67c9 into main Aug 25, 2026
@coderabbitai

coderabbitai Bot commented Aug 25, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: e8dc128c-775b-4719-8086-d005d67c28e1

📥 Commits

Reviewing files that changed from the base of the PR and between d8dff37 and 631b399.

📒 Files selected for processing (2)
  • packages/extension/src/opencode_xdg.ts
  • packages/extension/test/opencode_xdg.test.ts

📝 Walkthrough

Walkthrough

Added pure helpers that resolve OpenCode configuration and data directories from XDG environment variables, with home-directory fallbacks. Added tests for custom, unset, and empty environment values.

Changes

OpenCode XDG resolution

Layer / File(s) Summary
Directory resolution and validation
packages/extension/src/opencode_xdg.ts, packages/extension/test/opencode_xdg.test.ts
Added opencodeConfigDir() and opencodeDataDir() with XDG overrides and default paths. Tests cover custom, unset, and empty environment values, plus mocked home-directory resolution.

Estimated code review effort: 2 (Simple) | ~10 minutes

✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 560-extract-opencode-xdg

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Extract opencode_xdg.ts helper module

1 participant