Repository navigation
fix: make flake-generated branch guard workflow-model aware - #1231
Merged
Merged
Conversation
Add a trunk-mode flake-hooks case to the workflow-model coverage: build mkProjectShell with workflow = trunk and assert the generated no-commit-to-branch guard drops the (?!dev$) clause while keeping (?!main$), mirroring render_workflow_model's scaffolded-path render. The seam does not exist yet, so the trunk build fails on an unexpected workflow argument (RED). Refs: #1224
The scaffolded .pre-commit-config.yaml drops the (?!dev\$) protect-clause for DEVKIT_WORKFLOW=trunk (render_workflow_model), but a direnv consumer on flake-generated hooks (#1167) gets its branch guard from mkProjectShell, which was not workflow aware — after switching to trunk it kept ^(?!main\$)(?!dev\$)…, guarding a dev branch a trunk repo does not have. Add a workflow argument to mkProjectShell (gitflow default | trunk, validated) and thread it to the nix/hooks.nix consumer render, which drops the (?!dev\$) clause for trunk via a single branchNamePatternFor helper — mirroring exactly the scaffold render. gitflow is a no-op, so the generated config stays byte-identical for existing consumers. Refs: #1224
The workflow-model matrix covered only the scaffolded-file path. Add a trunk-mode flake-hooks case: a trunk direnv consumer gets its branch guard from mkProjectShell, so the scaffolded flake.nix must read DEVKIT_WORKFLOW from .vig-os and forward it as the workflow argument. The template does not yet forward it, so the assertion fails (RED). Refs: #1224
A fresh direnv consumer defaults to flake-generated hooks (#1167), whose branch guard comes from mkProjectShell rather than the scaffolded .pre-commit-config.yaml. Have the scaffolded flake.nix read DEVKIT_WORKFLOW from .vig-os (via self, lazy + pathExists-guarded) and forward it as the workflow argument, so a trunk workspace generates a guard without the (?!dev\$) clause out of the box. gitflow and an absent/blank value resolve to gitflow, so existing consumers are unaffected. Refs: #1224
This was referenced Jul 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The scaffolded
.pre-commit-config.yamlis workflow-model aware —render_workflow_model(assets/init-workspace.sh) drops the(?!dev$)protect-clause forDEVKIT_WORKFLOW=trunk. But a direnv consumer on flake-generated hooks (#1167, the default) gets its branch guard frommkProjectShell'snix/hooks.nixconsumer render, which was not workflow aware: after switching to trunk it kept^(?!main$)(?!dev$)…, guarding adevbranch a trunk repo does not have.Impact is inert (the residual clause guards a non-existent branch;
mainprotection and the type prefixes still work), but the pattern must follow the workflow model for correctness. Found during the first live trunk switches (exo-pet/vault#31).Closes #1224.
Fix
Two seams, mirroring the scaffold render exactly:
nix/hooks.nix— the branch-guard regex is now produced by a singlebranchNamePatternFor <workflow>helper; the(?!dev$)clause is emitted only for non-trunk. The top-levelconsumerrender takes aworkflowand drops the clause fortrunkvia a targetedno-commit-to-branchoverride (lib.optionalAttrs), so gitflow is a no-op and the generated config stays byte-identical for existing consumers. The committed runner/scaffold YAML keeps the gitflow pattern (its trunk render remains the scaffold path's job).flake.nix—mkProjectShellgains aworkflow ? "gitflow"argument (validated:gitflow | trunk), threaded into the consumer render.assets/workspace/flake.nix(scaffold template) — readsDEVKIT_WORKFLOWfrom.vig-os(viaself, lazy +pathExists-guarded) and forwards it asworkflow, so a fresh trunk direnv consumer's generated guard follows the model out of the box. gitflow / absent / blank all resolve togitflow.Decisions (autonomous)
mkProjectShellcannot purely read the consumer's.vig-os(a devkit-flake path literal resolves to devkit's own tree). So the seam accepts aworkflowargument and the consumer flake — which hasself— does the read. This is the issue's second suggested option.flake.nixis preserved (never overwritten), so an already-scaffolded trunk repo needs itsflake.nixre-scaffolded or a one-lineworkflow = "trunk";to benefit; fresh trunk direnv scaffolds get it automatically. The bug is inert, so this is acceptable.tests/test_flake_hooks.py(reusing that suite'snix buildfixtures); the scaffold-path half (the template forwards the value) lives intests/test_workflow_model.py, per the issue's ask to extend that matrix.Test evidence
tests/test_flake_hooks.py::TestWorkflowModelBranchGuard(4 tests): gitflow consumer keeps(?!dev$); trunk consumer drops it while keeping(?!main$); trunk guard == gitflow guard minus the exact(?!dev$)deletion; invalidworkflowrejected at eval.tests/test_workflow_model.py::test_trunk_flake_forwards_workflow_to_hooks: a trunk scaffold'sflake.nixreadsDEVKIT_WORKFLOWand forwardsworkflow, and its.vig-osdeclarestrunk.tests/test_flake_hooks.py+tests/test_workflow_model.py: 56 passed.tests/test_flake_devshell.py test_downstream_flake.py test_flake_checks.py test_flake_modules.py: 41 passed, 1 skipped (drift gate + zero-hooks parity intact).bats tests/bats/init-workspace.bats: 232 passed (flake-hooks activation + template stub unaffected).prek run --all-files: all green.Refs: #1224