Skip to content

fix: preserve gh cli auth config#167

Merged
Astro-Han merged 1 commit into
devfrom
codex/fix-gh-cli-auth-env
Apr 22, 2026
Merged

fix: preserve gh cli auth config#167
Astro-Han merged 1 commit into
devfrom
codex/fix-gh-cli-auth-env

Conversation

@Astro-Han

@Astro-Han Astro-Han commented Apr 22, 2026

Copy link
Copy Markdown
Owner

Summary

Preserve GitHub CLI authentication for PawWork agent commands by deriving GH_CONFIG_DIR before the desktop server overwrites XDG_CONFIG_HOME with PawWork's isolated config directory.

Why

PawWork's desktop server correctly isolates opencode state under the app user data directory, but gh also uses XDG_CONFIG_HOME to locate hosts.yml. After the isolation change, agent-run gh auth status looked in PawWork's config directory and reported that the user was not logged in even though the normal terminal login still worked.

Related Issue

No issue. This is a narrow regression fix with a reproduced root cause.

How To Verify

cd packages/desktop-electron
bun test src/main/server.test.ts
bun run typecheck

Manual env repro:

  1. env -u GH_CONFIG_DIR -u GH_TOKEN -u GITHUB_TOKEN XDG_CONFIG_HOME="$isolated_config" gh auth status reports not logged in.
  2. env -u GH_TOKEN -u GITHUB_TOKEN XDG_CONFIG_HOME="$isolated_config" GH_CONFIG_DIR="$gh_auth_dir" gh auth status sees the existing login.

Screenshots or Recordings

Not applicable. No visible UI change.

Checklist

  • I linked the related issue, or stated why there is no issue
  • This PR has type, scope, and priority labels, or I requested maintainer labeling
  • I listed the relevant verification steps, including tests when behavior changed
  • I manually checked visible UI or copy changes when needed, with screenshots or recordings
  • I considered macOS and Windows impact for desktop, packaging, updater, signing, paths, shell, or permissions changes
  • I called out docs, release notes, dependencies, permissions, credentials, deletion behavior, or generated/local file changes when relevant
  • I am targeting dev, and my PR title and commit messages use Conventional Commits in English

Summary by CodeRabbit

  • Bug Fixes

    • Improved GitHub CLI configuration directory resolution to properly handle environment variable precedence across different platforms.
  • Tests

    • Enhanced test coverage for environment variable handling and platform-specific configuration path derivation.

@Astro-Han Astro-Han added bug Something isn't working P1 High priority platform Electron shell, OS integration, packaging, updater, signing, paths, and permissions labels Apr 22, 2026
@coderabbitai

coderabbitai Bot commented Apr 22, 2026

Copy link
Copy Markdown
Contributor

Warning

Rate limit exceeded

@Astro-Han has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 2 minutes and 17 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 2 minutes and 17 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 01f95ca1-14e0-43f1-80dd-fd695fda3159

📥 Commits

Reviewing files that changed from the base of the PR and between 789a4df and 63aefcb.

📒 Files selected for processing (2)
  • packages/desktop-electron/src/main/server.test.ts
  • packages/desktop-electron/src/main/server.ts
📝 Walkthrough

Walkthrough

This PR introduces logic to resolve the GitHub CLI configuration directory based on environment variables and platform-specific fallbacks, with comprehensive tests validating environment precedence across Windows and Unix-like systems.

Changes

Cohort / File(s) Summary
GitHub CLI Config Directory Resolution
packages/desktop-electron/src/main/server.ts
Implements githubConfigDir resolver that determines GH_CONFIG_DIR via priority chain: process env variable, XDG_CONFIG_HOME/gh, Windows app data path, or HOME/.config/gh. Adjusts environment spread ordering and exports resolver for testing.
Test Suite for Environment Precedence
packages/desktop-electron/src/main/server.test.ts
Adds mutable mockShellEnv fixture with per-test reset, introduces nonWindowsTest helper, and validates environment precedence (process env overrides shell env), GH_CONFIG_DIR resolution paths across platforms, and interaction with XDG_* variables.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~18 minutes

Poem

🐰 Through shells and process roots we roam,
Finding configs far from home,
XDG and Windows paths align,
GitHub CLI's path divine! ✨

🚥 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 'fix: preserve gh cli auth config' clearly and concisely describes the main change—preserving GitHub CLI authentication config—which matches the core objective of the PR.
Description check ✅ Passed The PR description covers all required template sections: Summary, Why, Related Issue, How To Verify (with commands), Screenshots/Recordings (N/A noted), and a completed Checklist with platform considerations.
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.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/fix-gh-cli-auth-env

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

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request implements logic to resolve the GitHub CLI configuration directory across different platforms and integrates it into the server environment setup. It also includes comprehensive tests for various environment configurations. The review feedback recommends making path utilities injectable to better support cross-platform testing and suggests adding support for lowercase appdata environment variables on Windows.

Comment thread packages/desktop-electron/src/main/server.ts Outdated
@Astro-Han Astro-Han force-pushed the codex/fix-gh-cli-auth-env branch from 954327d to 789a4df Compare April 22, 2026 19:53

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/desktop-electron/src/main/server.ts`:
- Around line 75-90: The env merge is duplicated in buildServerEnv: create a
single mergedEnv (e.g., const mergedEnv = { ...shellEnv, ...process.env }) and
use mergedEnv both when calling githubConfigDir and when spreading into the
returned object (replace the two occurrences of { ...shellEnv, ...process.env }
and the later ...process.env with mergedEnv) so precedence is preserved and
maintenance drift is avoided; keep other returned keys (OPENCODE_*,
PAWWORK_RUNTIME_*, XDG_DATA_HOME) unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 545529b0-d3ce-45c3-9854-bfef599fd5a9

📥 Commits

Reviewing files that changed from the base of the PR and between 0bddc5a and 789a4df.

📒 Files selected for processing (2)
  • packages/desktop-electron/src/main/server.test.ts
  • packages/desktop-electron/src/main/server.ts

Comment thread packages/desktop-electron/src/main/server.ts
@Astro-Han Astro-Han force-pushed the codex/fix-gh-cli-auth-env branch from 789a4df to 63aefcb Compare April 22, 2026 20:10
@Astro-Han Astro-Han merged commit 710f913 into dev Apr 22, 2026
23 checks passed
@Astro-Han Astro-Han deleted the codex/fix-gh-cli-auth-env branch April 22, 2026 20:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working P1 High priority platform Electron shell, OS integration, packaging, updater, signing, paths, and permissions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant