Skip to content

fix(generate): use relative paths for env vars in generated README#2865

Open
mikeland73 wants to merge 3 commits into
mainfrom
claude/focused-goldberg-b0xqg2
Open

fix(generate): use relative paths for env vars in generated README#2865
mikeland73 wants to merge 3 commits into
mainfrom
claude/focused-goldberg-b0xqg2

Conversation

@mikeland73

Copy link
Copy Markdown
Collaborator

Summary

Fixes #2178.

devbox generate readme rendered plugin-provided environment variables with their fully expanded absolute paths. For example, enabling the postgresql plugin produced a README containing:

PGDATA="/home/carloratm/ooo/oha/.devbox/virtenv/postgresql/data"
PGHOST="/home/carloratm/ooo/oha/.devbox/virtenv/postgresql"

This leaks machine-specific paths — including the user's home directory / username — into a file that is typically committed to the repository.

The generated README already strips the absolute project directory out of scripts via configfile.Scripts.WithRelativePaths(projectDir). Environment variables were the one place this wasn't applied, because Config().Env() expands included-plugin env values to absolute paths before they reach the template.

Fix

Apply the same relative-path treatment to env var values before rendering: replace the absolute project directory with ., so the example above becomes:

PGDATA="./.devbox/virtenv/postgresql/data"
PGHOST="./.devbox/virtenv/postgresql"

This is intentionally consistent with the existing Scripts.WithRelativePaths behavior (same strings.ReplaceAll(value, projectDir, ".") transformation), and matches what was requested on the issue:

It would indeed be nice, when the generated README.md file only has relative references.

Values that don't contain the project dir (e.g. PGPORT="5432") are left untouched.

How was it tested?

  • Added internal/devbox/docgen/docgen_test.go covering: project-dir substitution, that the input map is not mutated, and that an empty project dir returns env unchanged.
  • go test ./internal/devbox/docgen/ passes; go vet and gofmt are clean.

cc the original reporter (the issue's author account has since been deleted) and @ametad, who reconfirmed the request on the issue.


Generated by Claude Code

devbox generate readme rendered plugin-provided environment variables
(e.g. PGDATA, PGHOST from the postgresql plugin) with their fully
expanded absolute paths, leaking machine-specific paths such as the
user's home directory into the committed README.

Replace the absolute project directory with "." in env var values,
mirroring the existing Scripts.WithRelativePaths behavior already
applied to scripts in the generated README.

Fixes #2178
Copilot AI review requested due to automatic review settings June 12, 2026 14:16

Copilot AI 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.

Pull request overview

This PR fixes devbox generate readme so that plugin-provided environment variables rendered into the generated README use project-relative paths instead of fully expanded absolute paths, avoiding leakage of machine-specific directories/usernames.

Changes:

  • Apply project-dir-to-. substitution to generated README env var values (mirroring existing scripts behavior).
  • Add focused unit tests for env var relative-path handling (substitution, non-mutation, empty project dir behavior).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
internal/devbox/docgen/docgen.go Adds env var path relativization before README template rendering.
internal/devbox/docgen/docgen_test.go Adds tests covering the new env var relative-path behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/devbox/docgen/docgen.go
Comment thread internal/devbox/docgen/docgen_test.go Outdated
claude added 2 commits June 12, 2026 14:20
…st data

Address review feedback:
- envWithRelativePaths now returns an independent copy even when
  projectDir is empty (via maps.Clone), matching its doc comment so
  callers can always mutate the result safely.
- Use a generic project path in the test fixture instead of a
  real-looking username.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

[Minor] Generate readme should not expand env variables paths

3 participants