Skip to content

fix(repro-yaml): export env vars before bun -e (bash positional bug) - #1204

Merged
namastex888 merged 1 commit into
devfrom
fix/repro-yaml-schema-env
Apr 18, 2026
Merged

namastex888 merged 1 commit into
devfrom
fix/repro-yaml-schema-env

Conversation

@automagik-genie

Copy link
Copy Markdown
Contributor

Follow-up to PR #1201 (G7 of wish `dir-sync-frontmatter-refresh`). One-file, 13-line fix.

Symptom

Running `bash scripts/tests/repro-yaml-config.sh` against v4.260418.19 crashed twice:

  1. First hit: `TypeError: undefined is not an object (evaluating 'xs.map')` inside postgres.js when `sql`CREATE SCHEMA ${sql(process.env.TEST_SCHEMA)}`` got passed `undefined`.
  2. Second hit (once past TEST_SCHEMA): `ENOENT: no such file or directory, lstat 'WORK=/tmp/repro-yaml-XXXX'` — `builtin-agents.ts` `resolvePackageRoot` treated the string literal `WORK=...` as a path.

Cause

Two `bun -e "..."` invocations had `KEY="$VAL"` trailing the command. Bash only treats `KEY=VAL` as an env assignment when it prefixes a command — trailing is a positional argument. So `process.env.KEY` was always undefined inside the bun script, and the literal `KEY=VAL` string got picked up as the first positional arg to whichever binary the script reached.

Fix

Export `TEST_SCHEMA` and `WORK` before the first `bun -e` call. Drop the trailing `KEY=VAL` from the two downstream invocations.

Verification

```
$ bash scripts/tests/repro-yaml-config.sh
...
✓ first sync migrated alice, no 'Unchanged' literal
✓ agent.yaml present, .bak present, AGENTS.md is body-only
✓ edited agent.yaml: model sonnet → opus
✓ second sync propagated yaml edit to DB (model=opus)
==> ALL INVARIANTS HOLD
```

Test plan

  • Shell reproducer exits 0 against live pgserve
  • CI Quality Gate green (this PR doesn't touch any source — unit tests shouldn't change)

🤖 Generated with Claude Code

Two occurrences of `bun -e "..." KEY="$VAL"` in
`scripts/tests/repro-yaml-config.sh` had the env-var in a TRAILING
position, which bash treats as a positional argument to bun — not as
an environment assignment — so `process.env.KEY` was always
undefined inside the script.

First symptom: `TypeError: undefined is not an object (evaluating
'xs.map')` from postgres.js when it tried to serialize `undefined`
as an identifier in `CREATE SCHEMA ${sql(process.env.TEST_SCHEMA)}`.
Second symptom (once past TEST_SCHEMA): `ENOENT: no such file or
directory, lstat 'WORK=/tmp/repro-yaml-XXXX'` because `WORK="$WORK"`
was picked up as a positional path arg by `builtin-agents.ts`'s
package-root resolver.

Fix: export both `TEST_SCHEMA` and `WORK` before the first bun
invocation. Drop the trailing `KEY=VAL` positionals from the two
downstream `bun -e` calls.

Verified: `bash scripts/tests/repro-yaml-config.sh` → "ALL INVARIANTS
HOLD", migration + yaml-edit-to-DB propagation both land.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Apr 18, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: da4ee24a-493c-4254-9e47-04758d23b2f9

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/repro-yaml-schema-env

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.

@namastex888
namastex888 merged commit 7942d1d into dev Apr 18, 2026
6 checks passed

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

Code Review

This pull request refactors the repro-yaml-config.sh script to ensure environment variables like TEST_SCHEMA and WORK are correctly inherited by bun -e child processes. By exporting these variables globally rather than passing them as trailing arguments, the script avoids bash interpreting them as positional arguments. A review comment suggests moving the TEST_SCHEMA export even earlier in the script to ensure that the cleanup trap can successfully drop the schema if the script fails prematurely.

# `KEY=VALUE` after `bun -e "..."` does NOT get passed through to the
# child process's env (bash treats it as a positional arg). Exporting
# up front is the only form that actually makes it into the script.
export TEST_SCHEMA="$SCHEMA"

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.

medium

The export of TEST_SCHEMA should ideally be moved to line 30 (immediately after SCHEMA is defined). This ensures that the cleanup trap (set at line 53) can correctly access process.env.TEST_SCHEMA and drop the schema even if the script fails or is interrupted before reaching this line. Currently, an early exit would cause the bun call in the cleanup function to fail because the environment variable is not yet set.

@automagik-genie
automagik-genie deleted the fix/repro-yaml-schema-env branch September 25, 2026 04:50
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