Skip to content

fix: use underscores in db_url var key examples - #1848

Merged
max-sixty merged 1 commit into
mainfrom
vars-underscore
Apr 1, 2026
Merged

max-sixty merged 1 commit into
mainfrom
vars-underscore

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

Hyphens in var keys conflict with Jinja2 expression parsing — vars.db-url is interpreted as vars.db minus url. Renamed db-url to db_url in the database examples in hook docs and tips-patterns.

This was written by Claude Code on behalf of maximilian

Hyphens in var keys conflict with Jinja2 expression parsing — `vars.db-url`
is interpreted as `vars.db` minus `url`. Underscores avoid the ambiguity.

Co-Authored-By: Claude <[email protected]>
@max-sixty
max-sixty merged commit 0d7fe83 into main Apr 1, 2026
23 checks passed
@max-sixty
max-sixty deleted the vars-underscore branch April 1, 2026 01:27
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.

2 participants