Skip to content

Respect OPENCODE_CONFIG in open-cursor CLI#91

Merged
Nomadcxx merged 2 commits into
Nomadcxx:mainfrom
KakatkarAkshay:fix-cli-opencode-config-env
Jun 15, 2026
Merged

Respect OPENCODE_CONFIG in open-cursor CLI#91
Nomadcxx merged 2 commits into
Nomadcxx:mainfrom
KakatkarAkshay:fix-cli-opencode-config-env

Conversation

@KakatkarAkshay

Copy link
Copy Markdown
Contributor

Summary

  • Honor OPENCODE_CONFIG when open-cursor CLI commands resolve the config path
  • Preserve --config as the highest-precedence override
  • Update help text and add CLI path resolution tests

Tests

  • bun test tests/unit/cli/opencode-cursor.test.ts
  • bun test tests/unit/plugin-toggle.test.ts

Note: bun test tests/unit/models/sync.test.ts currently exits 1 locally without diagnostic output; this test file is outside the CLI resolver change.

@coderabbitai

coderabbitai Bot commented Jun 15, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: b0731e58-45be-41a9-bd3b-72194943f1b2

📥 Commits

Reviewing files that changed from the base of the PR and between 06fc889 and e7bc3b3.

📒 Files selected for processing (1)
  • tests/unit/cli/opencode-cursor.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/unit/cli/opencode-cursor.test.ts

📝 Walkthrough

Walkthrough

resolvePaths in src/cli/opencode-cursor.ts is exported with updated configPath default resolution that checks process.env.OPENCODE_CONFIG before falling back to opencodeDir/opencode.json. The --config help text is updated to document this new default. A comprehensive test suite with three cases validates default fallback behavior, env-var usage, and explicit flag precedence.

Changes

OPENCODE_CONFIG env var for config path resolution

Layer / File(s) Summary
resolvePaths export and OPENCODE_CONFIG fallback
src/cli/opencode-cursor.ts
resolvePaths is exported; configPath now resolves options.configprocess.env.OPENCODE_CONFIGopencodeDir/opencode.json; printHelp documents the new default.
Path resolution unit tests
tests/unit/cli/opencode-cursor.test.ts
Test suite adds three cases: default config path respecting XDG_CONFIG_HOME/homedir, OPENCODE_CONFIG env var when no explicit config is provided, and explicit config flag precedence over env var, with try/finally cleanup.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~5 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately reflects the main change: adding support for the OPENCODE_CONFIG environment variable in the CLI.
Description check ✅ Passed The description is clearly related to the changeset, explaining the rationale, implementation details, and test coverage for respecting OPENCODE_CONFIG.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
tests/unit/cli/opencode-cursor.test.ts (1)

132-165: ⚡ Quick win

Consider adding a test for the default path fallback.

The current tests verify env-var usage and flag precedence. Adding a test that verifies the default path (when neither --config nor OPENCODE_CONFIG is set) would make the suite more complete and serve as a regression guard.

✅ Suggested test case
+  it("falls back to default config path when neither --config nor OPENCODE_CONFIG is set", () => {
+    const originalConfig = process.env.OPENCODE_CONFIG;
+    delete process.env.OPENCODE_CONFIG;
+
+    try {
+      const { configPath } = resolvePaths({});
+      const configHome = process.env.XDG_CONFIG_HOME && process.env.XDG_CONFIG_HOME.length > 0
+        ? process.env.XDG_CONFIG_HOME
+        : join(require("os").homedir(), ".config");
+      const expectedDefault = resolve(join(configHome, "opencode", "opencode.json"));
+      expect(configPath).toBe(expectedDefault);
+    } finally {
+      if (originalConfig === undefined) {
+        delete process.env.OPENCODE_CONFIG;
+      } else {
+        process.env.OPENCODE_CONFIG = originalConfig;
+      }
+    }
+  });
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/unit/cli/opencode-cursor.test.ts` around lines 132 - 165, Add a new
test case in the "cli/opencode-cursor path resolution" describe block to verify
the default path fallback behavior. The test should clear the OPENCODE_CONFIG
environment variable (if set) and call resolvePaths with no arguments, then
assert that the returned configPath matches the expected default path. Follow
the same pattern as the existing tests in the describe block by saving the
original OPENCODE_CONFIG value, clearing it in the test setup, verifying the
default path behavior, and properly restoring the original value in the finally
block. This test should be added alongside the existing "uses OPENCODE_CONFIG
when --config is not provided" and "prefers --config over OPENCODE_CONFIG" test
cases.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@tests/unit/cli/opencode-cursor.test.ts`:
- Around line 132-165: Add a new test case in the "cli/opencode-cursor path
resolution" describe block to verify the default path fallback behavior. The
test should clear the OPENCODE_CONFIG environment variable (if set) and call
resolvePaths with no arguments, then assert that the returned configPath matches
the expected default path. Follow the same pattern as the existing tests in the
describe block by saving the original OPENCODE_CONFIG value, clearing it in the
test setup, verifying the default path behavior, and properly restoring the
original value in the finally block. This test should be added alongside the
existing "uses OPENCODE_CONFIG when --config is not provided" and "prefers
--config over OPENCODE_CONFIG" test cases.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: fab1e727-d769-4a24-b0d9-3ddab57c9959

📥 Commits

Reviewing files that changed from the base of the PR and between cadaa9e and 06fc889.

📒 Files selected for processing (2)
  • src/cli/opencode-cursor.ts
  • tests/unit/cli/opencode-cursor.test.ts

@Nomadcxx Nomadcxx merged commit 5b70561 into Nomadcxx:main Jun 15, 2026
3 checks passed
@Nomadcxx

Copy link
Copy Markdown
Owner

Thanks Akshay, good catch here.

I merged this one. The change makes sense and lines the CLI up with how the plugin/runtime already resolve OPENCODE_CONFIG.

I also pushed a tiny follow-up cleanup after merge to reuse the shared config path resolver, just so this logic does not drift in two places.

cheers, RAMA

@KakatkarAkshay KakatkarAkshay deleted the fix-cli-opencode-config-env branch June 15, 2026 15:47
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.

2 participants