Skip to content

fix: make flake-generated branch guard workflow-model aware - #1231

Merged
c-vigo merged 5 commits into
devfrom
bugfix/1224-flake-branch-guard-workflow-aware
Jul 21, 2026
Merged

c-vigo merged 5 commits into
devfrom
bugfix/1224-flake-branch-guard-workflow-aware

Conversation

@c-vigo

@c-vigo c-vigo commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Summary

The scaffolded .pre-commit-config.yaml is workflow-model aware — render_workflow_model (assets/init-workspace.sh) drops the (?!dev$) protect-clause for DEVKIT_WORKFLOW=trunk. But a direnv consumer on flake-generated hooks (#1167, the default) gets its branch guard from mkProjectShell's nix/hooks.nix consumer render, which was not workflow aware: after switching to trunk it kept ^(?!main$)(?!dev$)…, guarding a dev branch a trunk repo does not have.

Impact is inert (the residual clause guards a non-existent branch; main protection 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:

  1. nix/hooks.nix — the branch-guard regex is now produced by a single branchNamePatternFor <workflow> helper; the (?!dev$) clause is emitted only for non-trunk. The top-level consumer render takes a workflow and drops the clause for trunk via a targeted no-commit-to-branch override (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).
  2. flake.nix — mkProjectShell gains a workflow ? "gitflow" argument (validated: gitflow | trunk), threaded into the consumer render.
  3. assets/workspace/flake.nix (scaffold template) — reads DEVKIT_WORKFLOW from .vig-os (via self, lazy + pathExists-guarded) and forwards it as workflow, so a fresh trunk direnv consumer's generated guard follows the model out of the box. gitflow / absent / blank all resolve to gitflow.

Decisions (autonomous)

  • Argument, not impure read. mkProjectShell cannot purely read the consumer's .vig-os (a devkit-flake path literal resolves to devkit's own tree). So the seam accepts a workflow argument and the consumer flake — which has self — does the read. This is the issue's second suggested option.
  • Reach for existing consumers. A consumer's flake.nix is preserved (never overwritten), so an already-scaffolded trunk repo needs its flake.nix re-scaffolded or a one-line workflow = "trunk"; to benefit; fresh trunk direnv scaffolds get it automatically. The bug is inert, so this is acceptable.
  • Test placement. The flake-eval half lives in tests/test_flake_hooks.py (reusing that suite's nix build fixtures); the scaffold-path half (the template forwards the value) lives in tests/test_workflow_model.py, per the issue's ask to extend that matrix.

Test evidence

  • New 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; invalid workflow rejected at eval.
  • New tests/test_workflow_model.py::test_trunk_flake_forwards_workflow_to_hooks: a trunk scaffold's flake.nix reads DEVKIT_WORKFLOW and forwards workflow, and its .vig-os declares trunk.
  • 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

c-vigo added 5 commits July 21, 2026 09:19
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
@c-vigo
c-vigo merged commit 436e7b5 into dev Jul 21, 2026
15 checks passed
@c-vigo
c-vigo deleted the bugfix/1224-flake-branch-guard-workflow-aware branch July 21, 2026 07: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.

1 participant