Skip to content

feat(workspace): exempt a named set of commit types from Refs - #1639

Merged
c-vigo merged 4 commits into
devfrom
feature/1633-refs-optional-types
Sep 16, 2026
Merged

c-vigo merged 4 commits into
devfrom
feature/1633-refs-optional-types

Conversation

@c-vigo

@c-vigo c-vigo commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

Description

DEVKIT_REFS_POLICY decides which commit types may omit the Refs: line, but its
"some types exempt" case is hardcoded to the literal type name chore. A consumer
that adds a custom type via DEVKIT_COMMIT_TYPES cannot exempt that type without
exempting every type — so the two knobs compose badly: you can add the type, but
not give it the Refs treatment the type was added for.

This adds DEVKIT_REFS_OPTIONAL_TYPES, a comma-separated (whitespace-tolerant)
FULL REPLACEMENT list of the types that may omit Refs:, mirroring the pattern
DEVKIT_COMMIT_TYPES and DEVKIT_BRANCH_TYPES already establish. The enum stays
as sugar; the narrower key wins.

Absent or blank resolves to chore — byte-identical to today's default render for
devkit and every existing consumer.

Type of Change

  • feat -- New feature

Modifiers

  • Breaking change (!) -- This change breaks backward compatibility

Changes Made

The value feeds three renderers in lockstep — a consumer cannot patch this
locally, because CI re-derives the list from the same key:

Renderer File
Scaffolded .pre-commit-config.yaml assets/init-workspace.sh — new RESOLVED_REFS_OPTIONAL_TYPES, resolved next to RESOLVED_COMMIT_TYPES so the subset guard has the approved list; render_refs_policy renders it
Flake-generated consumer hook nix/hooks.nix (refsOptionalTypesFor, consumer) → mkProjectShell's new refsOptionalTypes argument in flake.nix → the .vig-os reader in assets/workspace/flake.nix
CI's validate-commit-range assets/workspace/.github/actions/resolve-toolchain/action.yml — the refs-optional-types output

Plus the manifest surface: the key ships bare in assets/workspace/.vig-os, is
read before the template overwrite and written back on upgrade (else an upgrade
silently resets a consumer's exempt set and their issue-less commit type starts
failing commit-checks).

Precedence. DEVKIT_REFS_OPTIONAL_TYPES wins over DEVKIT_REFS_POLICY; the
scaffold prints a notice when both are set. DEVKIT_REFS_POLICY=required remains
the way to exempt nothing at all (an empty --refs-optional-types reads as falsy
to validate-commit-msg and reverts to its own {chore} default, which is why
required still travels as the none sentinel).

Guards. Entries must be lowercase alphanumerics AND a subset of the resolved
DEVKIT_COMMIT_TYPES — exempting a type the validator would reject anyway is a
manifest bug. The scaffold aborts loudly and mkProjectShell fails eval; CI warns
rather than failing the job. hooksModule.defaultCommitTypes is now exported so
the flake's subset assert validates against the same list the argv is built from,
rather than a fourth copy of the stock 11.

Two bugs found in self-review and fixed in 8779f34b, each with a regression test
committed first (59a8490e):

  • The render must gate on the keys, not the resolved value.
    .pre-commit-config.yaml is preserved across upgrades, never template-overwritten,
    so its current arg is whatever the previous render left. Skipping the sed because
    the resolved value happened to equal the chore default stranded a consumer
    narrowing its exempt set with the previous, wider arg locally while CI resolved
    the narrow one — precisely the local/CI divergence this issue exists to prevent.
  • Fail-safe for an exemption list means the smallest set, not the stock mapping.
    CI's fallback on an invalid value fell back to the DEVKIT_REFS_POLICY mapping;
    under DEVKIT_REFS_POLICY=optional that switched the Refs gate off for every type
    because the narrower key had a typo. It now clamps to chore unless the policy is
    already narrower (none). This is the one place the #1431 commit-types analogy
    inverts — there the stock list is a subset of any sane custom one, here it is not.

docs/COMMIT_MESSAGE_STANDARD.md is shipped to consumers and said only chore is
exempt; it now carries the same consumer-knob pointer the commit-types table has.

Changelog Entry

### Added

- **`DEVKIT_REFS_OPTIONAL_TYPES`: exempt a named set of commit types from the
  `Refs:` requirement** ([#1633](https://github.com/vig-os/devkit/issues/1633))
  - New `.vig-os` key — a comma-separated (whitespace-tolerant) FULL
    REPLACEMENT list of the commit types whose `Refs:` line is optional. It
    generalizes `DEVKIT_REFS_POLICY`, whose "some types exempt" case was
    hardcoded to the literal `chore`, so a repo that adds a custom type via
    `DEVKIT_COMMIT_TYPES` can now exempt exactly that type instead of
    exempting every type or none
  - Resolved identically by all three renderers — the scaffolded
    `.pre-commit-config.yaml`, the flake-generated consumer hook
    (`mkProjectShell`'s new `refsOptionalTypes` argument, read from the
    manifest by the scaffolded `flake.nix`), and CI's `resolve-toolchain`
    `refs-optional-types` output — so local and CI cannot disagree
  - Entries must be lowercase alphanumerics AND a subset of the resolved
    `DEVKIT_COMMIT_TYPES`; the scaffold and `mkProjectShell` refuse loudly,
    and CI warns and clamps to the NARROWEST exemption rather than failing
    the job — an invalid exemption list must never relax the Refs gate. The
    narrower key WINS over `DEVKIT_REFS_POLICY` (the scaffold prints a
    notice when both are set); `DEVKIT_REFS_POLICY=required` still means
    "exempt nothing"
  - Backward compatible: an absent or blank key resolves to `chore`, a
    byte-identical render for devkit and every existing consumer

Testing

  • Tests pass locally (just test)
  • Manual testing performed (describe below)

Manual Testing Details

  • tests/test_flake_hooks.py — 75 passed. Adds a refsoptionaltypes consumer shell
    (custom commitTypes + refsPolicy = "required" + refsOptionalTypes), which
    pins both the rendered arg and the precedence in one assertion, plus three
    eval-time refusals (charset, empty list, non-subset) and the template-reader
    forwarding probe.
  • tests/test_ci_runner.py — 69 passed. The resolve-toolchain resolution table,
    the precedence over each of the three policy values, and the clamp: an invalid
    list under optional must resolve to chore, under required to none, with a
    ::warning:: asserted through exec_resolve_toolchain.
  • tests/bats/init-workspace.bats — the #1633 and knob suites: default unchanged,
    named set rendered + written back, the narrowing re-render, the precedence notice,
    and two new loud-refusal rows (bad charset, non-subset).
  • Full pytest (1064 passed) and prek run --all-files (green, no reformats).
  • Two unrelated failures, red on dev too: test_image.py::test_manifest_files and
    test_integration.py::test_github_cli_authentication — both need a freshly built
    local dev image; the former is stale relative to dev itself (8e7c4916 changed
    .pymarkdown).

Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have updated the documentation accordingly (edit docs/templates/, then run just docs)
  • I have updated CHANGELOG.md in the [Unreleased] section (and pasted the entry above)
  • My changes generate no new warnings or errors
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published

Additional Notes

Two things deliberately left out of scope:

  • Deprecating DEVKIT_REFS_POLICY. The issue allows either; keeping it as sugar
    costs one case arm per renderer and breaks no consumer. It also remains the only
    way to say "exempt nothing", since an empty list means chore to the validator.
  • The pre-existing staleness when a consumer clears a render key.
    render_commit_types and render_branch_types gate on "key absent", so clearing
    the key leaves the previous render in the preserved .pre-commit-config.yaml.
    This PR matches that behaviour rather than diverging from it; fixing it properly
    means an unconditional sed guarded against the flake-hooks store symlink, across
    all three renders — a separate issue, not a drive-by here.

Refs: #1633

@c-vigo
c-vigo enabled auto-merge September 16, 2026 17:46
@c-vigo
c-vigo merged commit 7ce8030 into dev Sep 16, 2026
14 checks passed
@c-vigo
c-vigo deleted the feature/1633-refs-optional-types branch September 16, 2026 17:57
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