Skip to content

fix: reject underscore in vars keys (invalid git config variable name) - #2285

Merged
max-sixty merged 1 commit into
max-sixty:mainfrom
Mziserman:fix/reject-underscore-vars-key
Apr 18, 2026
Merged

max-sixty merged 1 commit into
max-sixty:mainfrom
Mziserman:fix/reject-underscore-vars-key

Conversation

@Mziserman

Copy link
Copy Markdown
Contributor

Problem

wt config state vars set db_suffix=foo silently passes validation but then fails with a cryptic git error:

error: invalid key: worktrunk.state.main.vars.db_suffix

Git config variable names (the last .-separated segment) must match [a-zA-Z][a-zA-Z0-9-]* — underscores are not allowed at that position.

Fix

Reject _ in validate_vars_key early, with a clear message pointing users to use hyphens instead:

Invalid key "db_suffix": keys must contain only letters, digits, and hyphens

No other changes — branch names with / already work correctly via git's quoted subsection form.

@Mziserman
Mziserman force-pushed the fix/reject-underscore-vars-key branch 4 times, most recently from 7538eeb to 446bf54 Compare April 18, 2026 12:02
@Mziserman
Mziserman marked this pull request as ready for review April 18, 2026 12:10

@worktrunk-bot worktrunk-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The code change looks right — per git-config(1), variable names must match [a-zA-Z][a-zA-Z0-9-]*, so underscores at the final position always fail. Good surface-level fix.

One spot still needs updating, though: the after_long_help text at src/cli/config.rs:903 (auto-synced to docs/content/config.md and skills/worktrunk/reference/config.md) still tells users the opposite of the new validator:

Keys must contain only letters, digits, hyphens, and underscores — dots conflict with git config's section separator.

After this PR, wt config vars --help and the online docs will still promise underscores are allowed while the code rejects them. Consider updating that sentence and then running cargo test --test integration test_command_pages_and_skill_files_are_in_sync to propagate. Happy to push that follow-up if helpful.

Minor: the existing test_vars_invalid_key only exercises a dot key. A one-line extension to also assert the underscore path would lock in the new behaviour.

@Mziserman
Mziserman force-pushed the fix/reject-underscore-vars-key branch from 446bf54 to c94d838 Compare April 18, 2026 12:27
@Mziserman
Mziserman requested a review from worktrunk-bot April 18, 2026 12:28
@max-sixty
max-sixty merged commit c70e77b into max-sixty:main Apr 18, 2026
35 of 36 checks passed
@max-sixty

Copy link
Copy Markdown
Owner

thanks @Mziserman !

@max-sixty

Copy link
Copy Markdown
Owner

@worktrunk-bot thanks for the review

in this case, I think you could have been more helpful by adding suggestions or at least offering to fix. could you put an issue into the tend repo for this case, and we can look at adjusting the guidance slightly?

@worktrunk-bot

Copy link
Copy Markdown
Collaborator

Filed as max-sixty/tend#303. Summary: the review skill's "offer to push a fix commit" recipe doesn't spell out concrete wording, so I reached for hedging language (if helpful) on one finding and no offer at all on the other. Suggested tightening the rule to cover test additions (not just typos/docs) and requiring consistent, unambiguous offers across all concrete findings in a review.

max-sixty added a commit that referenced this pull request Sep 26, 2026
…ipes wt rejects (#4279)

Two recipes on the Tips & Patterns page fail when copied. This PR fixes
both, adds a test that runs the database recipe straight from the page,
and makes the hook-output JSON report real branch names so the log
recipes can scope to the current branch.

- **Database per worktree**: the `set-vars` step passed three
`KEY=VALUE` pairs to one `wt config state vars set`, which accepts
exactly one (`error: unexpected argument 'port=…' found`). Because the
step failed, `vars.container` and `vars.port` were never set for the
`db` step or `pre-remove`. The step now runs three `vars set` calls
chained with `&&`. The recipe also stored `db_url`, and vars keys have
rejected underscores since #2285 (Git config variable names can't
contain them). It's now `db-url`, in the `vars get` example too. #1848
had moved this key from hyphens to underscores because Jinja parses
`vars.db-url` as subtraction. That doesn't apply here: the recipe reads
the key only with `wt config state vars get db-url`, never in a
template.
- **Monitor hook logs**: `wt config state logs get
--hook=user:post-start:server` and the `wtlog` alias built on it fail
with `unexpected argument '--hook'`, because #2161 removed that flag.
Its replacement, a `jq` filter over `wt config state logs
--format=json`, couldn't scope to the current branch. The JSON `branch`
field was the sanitized log directory (`feature/x` became
`feature-x-<hash>`), so the help example used `startswith` and `head -1`
and tailed whichever worktree's `server` log was newest.
- **Hook-output JSON `branch`**: the field now holds the real branch
name. It maps each log directory back through `sanitize_for_filename`
over the local branches, and is `null` when no local branch writes
there: a deleted branch, a detached HEAD, or a directory two branches
share. The recipes in the help and on the page match `[.branch, .source,
.hook_type, .name]` exactly. The extending page's `hook-log` alias
compared `.branch` with `{{ branch | sanitize_hash }}`, the on-disk
form, and now passes `{{ branch }}` to jq with `--arg`, like its other
values. The `wtlog` alias becomes a shell function taking the hook name.

`test_doc_example_database_set_vars_step_runs` pulls the `set-vars` step
from the page's TOML block, runs it as a `wt` alias with `wt` on `PATH`,
and checks the stored `port`. It fails on `main` with the argument error
above. After the first fix it also caught the `db_url` rejection.
`test_logs_get_json_branch_is_unsanitized` covers the branch mapping,
including the deleted and shared-directory cases. I ran the new recipe
by hand from a `feature/x` worktree next to an `other/y` worktree, and
it tailed only the `feature/x` log.

The `skills/` and `plugins/` copies of the page are regenerated by
`test_docs_are_in_sync`.

---------

Co-authored-by: worktrunk-bot <[email protected]>
Co-authored-by: Maximilian Roos <[email protected]>
Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
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.

3 participants