Repository navigation
fix: reject underscore in vars keys (invalid git config variable name) - #2285
Conversation
7538eeb to
446bf54
Compare
worktrunk-bot
left a comment
There was a problem hiding this comment.
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.
446bf54 to
c94d838
Compare
|
thanks @Mziserman ! |
|
@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? |
|
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 ( |
…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]>
Problem
wt config state vars set db_suffix=foosilently passes validation but then fails with a cryptic git error: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
_invalidate_vars_keyearly, with a clear message pointing users to use hyphens instead:No other changes — branch names with
/already work correctly via git's quoted subsection form.