Skip to content

fix: load .env from env-based working_dir#2140

Merged
yottahmd merged 6 commits into
mainfrom
codex/fix-dotenv-working-dir-env
May 12, 2026
Merged

fix: load .env from env-based working_dir#2140
yottahmd merged 6 commits into
mainfrom
codex/fix-dotenv-working-dir-env

Conversation

@yottahmd
Copy link
Copy Markdown
Collaborator

@yottahmd yottahmd commented May 12, 2026

Summary

  • resolve dotenv lookup bases using the same DAG/base env scope that can feed working_dir
  • keep runtime working_dir expansion unchanged while making .env discovery match the resolved directory
  • add regression coverage for env-based working_dir and DAG-dir fallback masking

Fixes #2135

Testing

  • go test ./internal/core/spec -run TestDAGLoadEnv -count=1
  • go test ./internal/core/... -count=1
  • git diff --check -- internal/core/dag.go internal/core/spec/builder_test.go

Summary by CodeRabbit

  • Bug Fixes

    • More reliable .env loading when a working directory is set via variables — resolved working directory is expanded before discovery so its .env takes precedence.
    • Improved path expansion and evaluation during dotenv loading to ensure correct values are applied.
  • Tests

    • Added tests covering .env loading with resolved working directories and precedence scenarios.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 12, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a126a1ac-ba0b-488e-b84e-1f110f27aac9

📥 Commits

Reviewing files that changed from the base of the PR and between 23e417a and 76afa97.

📒 Files selected for processing (1)
  • internal/intg/cfg_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • internal/intg/cfg_test.go

📝 Walkthrough

Walkthrough

loadDotEnvFiles now constructs an eval.EnvScope from DAG params, presolved build env, and DAG env; ensures a non-nil eval context; expands WorkingDir through that scope before computing dotenv search roots; rebuilds FileResolver bases; deduplicates candidates; and loads each .env using the scoped evaluation context. Unit and integration tests verify resolved-working_dir loading and precedence.

Changes

Dotenv variable expansion in working directory

Layer / File(s) Summary
Dotenv loading with variable expansion
internal/core/dag.go
loadDotEnvFiles constructs an eval.EnvScope from DAG params, presolved build env, and DAG env; ensures a non-nil eval context; expands WorkingDir via the scope; recalculates FileResolver bases from expanded working dir and DAG location; deduplicates dotenv candidates; and loads dotenv files using the scoped context. Adds helpers dotenvEnvScope and expandDotEnvPath and a buildenv import.
Dotenv loading test coverage
internal/core/spec/builder_test.go
Added two TestDAGLoadEnv subtests verifying .env loading when working_dir is resolved via ${...} placeholders and that working-dir .env takes precedence over DAG-dir .env. Added envSliceMap helper for assertions.
Integration test for resolved working_dir
internal/intg/cfg_test.go
Added TestDotEnvUsesResolvedWorkingDirFromBaseEnv which mutates test base config to point QUANT_SIGNAL_DIR at a target dir, writes .env files in both resolved working dir and DAG dir (conflicting value), runs a DAG with working_dir: ${QUANT_SIGNAL_DIR} and dotenv: .env, and asserts .env values and $PWD come from the resolved working dir. Also added config import.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • dagucloud/dagu#2131: Both PRs modify DAG-level env evaluation using eval.EnvScope; this PR adds dotenv path expansion within the constructed scope.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 37.50% 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: load .env from env-based working_dir' clearly and concisely describes the main change: fixing .env file loading when working_dir uses environment variables.
Description check ✅ Passed The description covers all template requirements: a summary of the fix strategy, specific changes made, linked issue (#2135), and detailed testing instructions.
Linked Issues check ✅ Passed The PR successfully addresses all coding requirements from issue #2135: it resolves dotenv paths using env-based scope, enables .env discovery for environment-variable working_dir references, preserves runtime expansion behavior, and adds regression tests.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing .env loading for env-based working_dir: modifications to DAG loading logic, unit tests for the new behavior, and integration tests for regression coverage.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/fix-dotenv-working-dir-env

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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.

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 12, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 12, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@yottahmd
Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 12, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@yottahmd
Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 12, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@yottahmd yottahmd merged commit 5a5287c into main May 12, 2026
10 checks passed
@yottahmd yottahmd deleted the codex/fix-dotenv-working-dir-env branch May 12, 2026 09:18
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.

bug: .env file isn't parsed when working_dir is an environment variable

1 participant