Repository navigation
fix(workspace): render knobs unconditionally and refuse symlinks - #1641
Merged
Merged
Conversation
c-vigo
enabled auto-merge
September 16, 2026 18:29
This was referenced Sep 17, 2026
c-vigo
added a commit
that referenced
this pull request
Sep 17, 2026
…ways (#1643) ## Description `render_workflow_model` applies the `gitflow → trunk` retarget one way — it early-returns unless the resolved model is `trunk`. For every **managed** file it touches that is harmless: the template overwrite restores the gitflow shape on the next upgrade and the render simply does not re-run. `.pre-commit-config.yaml` is **preserved**, so the trunk edits stayed in it forever. A consumer switching back to gitflow therefore lost the dev-branch guard silently: `no-commit-to-branch` stopped blocking direct commits to `dev`, on a repo whose `.vig-os` says `gitflow`. No error, no notice. Last instance of the class fixed in #1640. ## Type of Change - [x] `fix` -- Bug fix ### Modifiers - [ ] Breaking change (`!`) -- This change breaks backward compatibility ## Changes Made I scoped this out of #1641 believing it spanned many files and needed its own design. That premise was wrong, and measuring it first is what made the fix small: every other target self-heals, so the entire stale surface is two lines of one file. | Target | Managed / preserved | After a trunk → gitflow round-trip | |---|---|---| | `ci.yml`, `codeql.yml`, `sync-issues.yml`, `prepare-release.yml`, `promote-release.yml` | managed | restored | | `.github/renovate-default.json` | managed | restored (`["dev"]`) | | `.devcontainer/justfile.gh` | managed | restored | | `.claude/skills/branch-naming/SKILL.md` | managed | restored | | **`.pre-commit-config.yaml`** | **preserved** | **STALE** | So the `.pre-commit-config.yaml` edits move out of `render_workflow_model` into a new `render_branch_guard_model`, which runs for **both** models and renders the dev clause *from* the resolved model instead of only subtracting it under trunk. It goes through the `precommit_render_target` resolver added in #1640, keeping the symlink and absent-file refusals in one place. Each direction's anchors stop matching once applied, so a re-run is a no-op and a default gitflow scaffold stays byte-identical to the template. **One trap worth recording, because it silently produced a no-op fix.** GNU sed 4.10 treats a *mid-pattern* `$` in a basic regular expression as an end anchor, not a literal. So the obvious insert pattern ```sed s|(?!main$)(?!^(chore)|(?!main$)(?!dev$)(?!^(chore)| ``` matches nothing at all — and fails silently, leaving the file untouched. The existing `(?!dev$)` strip only works because its `$)` sits at the very end of the pattern. Both metacharacters are escaped in the insert pattern for that reason; the replacement side needs no escaping, since sed gives `$`/`^` no meaning there. The comment in the source records this so the next person does not rediscover it. Flake-hooks consumers were never affected: their guard comes from `mkProjectShell`, which reads `DEVKIT_WORKFLOW` at eval time (#1224/#1434) and was already correct in both directions. It was only the scaffolded YAML that was one-way. ## Changelog Entry ```md ### Fixed - **Switching `trunk` back to `gitflow` restores the dev-branch guard** ([#1642](#1642)) - `render_workflow_model` applied the `gitflow -> trunk` retarget one way. For every managed file it touches that is harmless — the template overwrite restores the gitflow shape on the next upgrade — but `.pre-commit-config.yaml` is preserved, so a consumer switching back kept the trunk edits and lost the `(?!dev$)` clause: `no-commit-to-branch` silently stopped blocking direct commits to `dev` on a repo whose manifest said `gitflow` - The dev clause now renders from the resolved model in BOTH directions, in a new `render_branch_guard_model` that runs for either model and goes through the `precommit_render_target` resolver. Each direction's anchors stop matching once applied, so a re-run is a no-op and a default gitflow scaffold stays byte-identical to the template - Flake-hooks consumers were never affected: their guard comes from `mkProjectShell`, which reads `DEVKIT_WORKFLOW` at eval time and was already correct in both directions ``` ## Testing - [x] Tests pass locally (`just test`) - [x] Manual testing performed (describe below) ### Manual Testing Details Four new bats cases, committed first (`5c33a7ca`) with the two behavioural ones red: - trunk → gitflow restores both the `(?!dev$)` clause and its comment (red) - the restored file matches the template **byte for byte**, the way a managed file does — this is the assertion that caught the silent no-op sed (red) - the gitflow render is idempotent: a second upgrade does not double-insert (green before, pins the new code path) - the render refuses a symlinked config (green before via #1640's resolver; pins that the refactor keeps it) Full runs, all green: - `bats tests/bats/init-workspace.bats` — 270 passed, 0 failed. Deliberately includes the #1205 workflow-switch suite, the #1255 flake-hooks fixtures, the #1282/#1431/#1432/#1633/#1640 knob suites and the trunk-render composition tests. - `pytest` (minus the two suites needing a freshly built local image) — 1070 passed, 1 skipped. `tests/test_flake_checks.py` caught a `typos` violation in a source comment on the first run; reworded rather than allowlisted. - `prek run --all-files` — green, no reformats. ## Checklist - [x] My code follows the project's style guidelines - [x] I have performed a self-review of my code - [x] I have commented my code, particularly in hard-to-understand areas - [x] I have updated the documentation accordingly (edit `docs/templates/`, then run `just docs`) - [x] I have updated `CHANGELOG.md` in the `[Unreleased]` section (and pasted the entry above) - [x] My changes generate no new warnings or errors - [x] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [x] Any dependent changes have been merged and published ## Additional Notes The contradiction guard still refuses a `--workflow` flag that contradicts the persisted `DEVKIT_WORKFLOW`; this changes nothing there. The switch path this fixes is the guard's own documented step 3 — set `DEVKIT_WORKFLOW` in `.vig-os` on a dedicated branch and re-run the upgrade. Refs: #1642
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.
Description
.pre-commit-config.yamlis preserved across upgrades (#878 — the consumer ownsits hook excludes), so it accumulates past renders. The three knob renders
early-returned on an empty manifest key, which means "don't touch it", not
"restore the default". A consumer who set a knob and later cleared it kept
the previous render locally, while CI — which re-derives from
.vig-oson everyrun with no memory — resolved the default. The local hook and
validate-commit-rangethen disagreed about the same gate.The scaffold-drift gate (#1295) could not catch it: it re-runs the scaffold and
git diffs, so it hits the same early return, reproduces the stale filebyte-identically, and sees no drift.
Type of Change
fix-- Bug fixModifiers
!) -- This change breaks backward compatibilityChanges Made
All in
assets/init-workspace.sh.1. The three renders are unconditional and idempotent.
render_commit_types,render_branch_typesandrender_refs_policynow write the resolved value onevery run. For an unset knob that rewrites exactly what the template already
ships, so a default scaffold stays byte-identical and the drift baseline is
untouched; for a cleared knob it restores the default instead of stranding the
previous render.
2.
render_branch_typesgained a generic anchor. It was anchored on theliteral stock alternation, which by construction stops matching the moment a
custom set has been rendered — so making it unconditional alone would not have
fixed it, because the stock set could never be written back. The anchor is now
the
(?!^(prefix plus the)/[0-9]suffix, which together pin exactly this onealternation: the
(chore)/[a-z0-9]clause has the wrong suffix, and therenovate/worktreeclauses have no inner group. Verified to round-tripbyte-identically: stock → custom → stock reproduces the template line exactly.
With the stock literal gone, the old ordering constraint (this render had to run
before anything else that rewrites the line) goes with it.
3. New
precommit_render_targethelper refuses a symlinked config. This iswhat makes the rest safe. A flake-hooks consumer's
.pre-commit-config.yamlis agitignored
/nix/storesymlink (#883/#1167).[[ -f ]]is true for it, and GNUsed -iwrites a temp file and renames it over the path — replacing the symlinkwith a regular file, which shadows the generated config with a frozen copy and
silently drops the consumer's
hooks/hooksExcludescustomizations. Making therenders unconditional multiplies the chances of hitting that, so every in-place
render of this file now goes through one resolver that refuses both an absent and
a symlinked target.
render_workflow_model's.pre-commit-config.yamlblock wascarrying the same latent hazard and now uses it too.
Skipping costs a flake-hooks consumer nothing: their knobs reach the hook through
mkProjectShell, which reads the same.vig-oskeys at eval time (#1434).Changelog Entry
Testing
just test)Manual Testing Details
Five new bats cases in
tests/bats/init-workspace.bats, committed failing first(
b4963195— all five red, the symlink one red after a successful upgrade,i.e. for the right reason):
DEVKIT_COMMIT_TYPESrestores the stock 11--typesDEVKIT_BRANCH_TYPESrestores the stock alternation (the case thegeneric anchor exists for)
DEVKIT_REFS_OPTIONAL_TYPESrestoreschoreDEVKIT_REFS_POLICYrestoreschore.pre-commit-config.yamlsurvives an upgrade with all three knobsset: still a symlink, target byte-identical by sha256
Full runs, all green:
bats tests/bats/init-workspace.bats— 266 passed, 0 failed. Covers thesurrounding surface this touches: the Upgrade deploys template .pre-commit-config.yaml into direnv consumers, shadowing the flake-generated config #1255 flake-hooks fixtures, the feat(workspace): scaffold-time Refs policy knob (DEVKIT_REFS_POLICY) for validate-commit-msg + validate-commit-range #1282 /
[FEATURE] feat(workspace): scaffold-time commit-types knob (DEVKIT_COMMIT_TYPES) for validate-commit-msg + validate-commit-range #1431 / [FEATURE] feat(workspace): scaffold-time branch-types knob (DEVKIT_BRANCH_TYPES) for the branch guard + mkProjectShell branchTypes #1432 / [FEATURE] Refs policy: exempt a named set of commit types, not just the literal
chore#1633 knob suites, and the trunk-render composition tests.pytest(minus the two image/integration suites that need a freshly builtlocal dev image) — 1071 passed, 1 skipped.
prek run --all-files— green, no reformats.Checklist
docs/templates/, then runjust docs)CHANGELOG.mdin the[Unreleased]section (and pasted the entry above)Additional Notes
render_workflow_model'sgitflow → trunktransform has the same one-way shape— switching a consumer back cannot restore the dropped
(?!dev$)clause or theprose substitutions — and is deliberately not fixed here. It is a set of
anchored prose/marker substitutions across many files rather than a single value
slot, so it needs its own design rather than this pattern. It does get the
symlink guard, since that hazard is identical.
Refs: #1640