Skip to content

feat(workflow): add scaffold-drift CI gate (DEVKIT_DRIFT_CHECK) - #1297

Merged
c-vigo merged 2 commits into
devfrom
feature/1295-scaffold-drift-check
Jul 29, 2026
Merged

c-vigo merged 2 commits into
devfrom
feature/1295-scaffold-drift-check

Conversation

@c-vigo

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

Copy link
Copy Markdown
Contributor

Closes #1295

Summary

Adds a scaffold-drift job to the scaffolded consumer ci.yml that re-runs the pinned devkit version's scaffold over the checkout and fails a PR whose managed files diverge from it — DEVKIT_VERSION bumped without re-scaffolding, or a managed file hand-edited. Today a pin-only bump merges green; this closes the #1093 skew gap with an enforced gate. Prerequisite for #1296.

Mechanism

Re-scaffold + git diff, not install.sh --preview: the preview report classifies OVERWRITTEN by path existence, not content, so it cannot distinguish drift from an up-to-date file. The job docker runs init-workspace.sh --force --no-prompts from the pinned image over the checkout (direnv/bare consumers resolve an empty container: image, and the scaffold assets live only inside the image), then git add -A && git diff --cached surfaces divergence. *.project files and persisted .vig-os values are exempt by construction; .gitignored files (*.local) via git. VIG_OS_VERSION=<pin> keeps the DEVKIT_VERSION line stable against the image's baked version. install.sh needed no changes.

Knob

New .vig-os key DEVKIT_DRIFT_CHECK (true default / false), a pure runtime gate read via resolve-toolchain's new drift-check output — flipping it needs no re-scaffold; the value round-trips across --force upgrades, and an invalid literal fails the scaffold loudly (mirrors DEVKIT_REFS_POLICY). The ghcr image literal stays in resolve-toolchain (new all-modes drift-image output) per the #991 SSoT invariant.

Cost control

Runs on PRs only (~1.5 GiB image pull), riding the same gate as commit-checks/dependency-review — a per-job paths filter isn't possible inside one workflow. Summary treats skip-as-OK, failure trips the gate.

Test evidence

  • tests/test_scaffold_drift.py (new, 15 tests) + test_ci_runner.py + test_scaffold_lint.py: 70 passed
  • tests/bats/init-workspace.bats (3 new tests): 278/278 pass
  • prek run --all-files: green (both hook layers)
  • actionlint on the template: clean

Reviewer notes

  • On a DEVKIT_CI_RUNNER self-hosted runner the job inherits runs-on and needs a docker CLI on that host; hosted ubuntu-24.04 is unaffected. Worth checking on meatgrinder before a consumer with a self-hosted runner adopts.
  • True path-narrowing (only pull the image when .vig-os/flake.lock/managed files change) would need a dedicated scaffold-drift.yml with on.pull_request.paths; kept as an in-ci.yml job per the issue's wording.

Refs: #1295

c-vigo added 2 commits July 29, 2026 13:49
Cover the #1295 scaffold-drift check before implementing it:
- resolve-toolchain emits a `drift-check` output from DEVKIT_DRIFT_CHECK
  (default true; explicit false disables), emitted in every mode
- ci.yml carries a `scaffold-drift` job gated PR-only + on the knob, that
  re-runs init-workspace.sh --force and diffs the managed tree, honors the
  runner override, and feeds the summary gate
- init-workspace persists DEVKIT_DRIFT_CHECK across upgrades and rejects an
  invalid value loudly

Refs: #1295
The scaffolded ci.yml gains a `scaffold-drift` job that re-runs the pinned
devkit version's scaffold over the checkout and fails a PR whose managed files
diverge from it — DEVKIT_VERSION bumped without re-scaffolding, or a managed
file hand-edited. A pin-only bump otherwise merges green; nothing else re-runs
the scaffold or diffs against it (init-workspace.sh #1093 skew warning fires
only during an upgrade, not on the skewed PR).

Mechanism is re-scaffold + `git diff`, NOT `install.sh --preview`: the preview
report classifies OVERWRITTEN by path existence (`path_present`), not content,
so an exit-code-on-overwrite flag would fire for every populated consumer and
cannot distinguish drift from an up-to-date managed file. Re-running
init-workspace.sh --force rewrites the managed files to exactly what the pin
produces while preserving *.project files and persisted .vig-os values by
construction; `git diff` (honoring .gitignore, so *.local is exempt too) then
surfaces any real divergence. This needs no change to the scaffold's copy logic
— init-workspace.sh already honors WORKSPACE_DIR/TEMPLATE_DIR and pins
DEVKIT_VERSION from VIG_OS_VERSION.

The job docker-runs the in-image scaffold on the host runner rather than via a
job-level container: a direnv/bare consumer resolves an EMPTY image (its jobs
run on the host) yet the scaffold assets live only inside the devcontainer
image. resolve-toolchain gains a `drift-image` output (the image ref for every
mode) so the ghcr.io/vig-os/devcontainer literal stays out of ci.yml (the #991
SSoT invariant), and VIG_OS_VERSION=<current pin> keeps the DEVKIT_VERSION line
stable against the image's baked full version.

Opt-out via the new .vig-os key DEVKIT_DRIFT_CHECK (true default / false
disables), read at runtime through resolve-toolchain's `drift-check` output so
flipping it needs no re-scaffold; the value round-trips across --force upgrades
and an invalid literal fails the scaffold loudly. Runs on PRs only for cost
control (the ~1.5 GiB image pull) — a single workflow cannot apply a per-job
paths filter, so it rides the same pull_request-only gate as
commit-checks/dependency-review. #1284 feature groups are unaffected: the job
ships as part of ci.yml, needing no group of its own.

Refs: #1295
@c-vigo
c-vigo merged commit b8056ff into dev Jul 29, 2026
13 checks passed
@c-vigo
c-vigo deleted the feature/1295-scaffold-drift-check branch July 29, 2026 19:59
c-vigo added a commit that referenced this pull request Jul 30, 2026
Union-resolves the #1295/#1296 overlap in CHANGELOG.md (+ mirror), .vig-os
and init-workspace.sh after PR #1297 merged to dev.

Refs: #1296
c-vigo added a commit that referenced this pull request Jul 30, 2026
Closes #1296

## Summary

Scaffolds a self-polling `devkit-upgrade.yml` workflow into consumers:
weekly (Monday 06:00, aligned with the Renovate window) it queries
devkit's `releases/latest`, and when the repo's `.vig-os` pin is behind
it runs the full-fidelity `install.sh --force --version <X>` upgrade —
pin + `flake.lock` `vigos` node + scaffold regeneration move together —
commits inside the project shell so consumer hooks run (dist rebuild,
trailer strip, commit-msg validation), and opens the adoption PR.
`workflow_dispatch` with an explicit `version` input (final or rc) is
the release-train / lane-re-bump path. Merging stays human. Depends on
the #1295 drift gate (PR #1297) as its safety net.

## Design

- **Feature group**: new `devkit-upgrade` group in the #1284 opt-out
mechanism (never ship the file at all), composing with the runtime
knobs:
- **`DEVKIT_AUTO_UPGRADE`** (`.vig-os`, default enabled): gates the
*schedule path only*; manual dispatch always runs.
**`DEVKIT_UPGRADE_EXCLUDE`**: comma-separated paths reset before the
adoption commit (e.g. vault's generated-doc churn). Both round-trip
across `--force` upgrades.
- **Version logic**: `releases/latest` excludes prereleases/drafts, so
cron never proposes an rc; a prerelease-aware compare makes the schedule
a no-op when the pin is current **or ahead** (an rc of a newer train is
never downgraded). Resolved versions are strictly semver-validated
before reaching any shell/gh sink.
- **Train keying**: adoption issue/branch/PR key on the train
(`chore/<issue>-devkit-1-5-0`, dots→dashes for the branch guard), so
rc1→rc2→final reuse one issue/branch/PR force-updated; commit + PR title
carry the exact version.
- **Base branch**: ships `dev` literals, retargeted to `main` at
scaffold time for trunk repos via `render_workflow_model` (the
sync-issues.yml precedent).
- **Token**: dedicated `DEVKIT_UPGRADE_TOKEN` secret (fail-fast with a
clear error when absent) — the default `GITHUB_TOKEN` is used only for
the read-only release query, since PRs it creates don't trigger CI.
Commit identity configurable via
`vars.DEVKIT_UPGRADE_AUTHOR_NAME/EMAIL`; the default avoids the
agent-blocklist.
- **Security**: every untrusted value (dispatch input, event fields, API
responses) routed through `env:`; actions SHA-pinned; `permissions: {}`
at workflow level, `contents: read` on the job. One deliberate zizmor
`artipacked` baseline entry (the checkout persists the dedicated token
because the branch push needs it), commented in `zizmor.yml`.

## Test evidence

- `tests/test_workflow_devkit_upgrade.py` (new, 15 tests; RED-first) +
workflow-model/sync-settings/scaffold-lint/zizmor-baseline/ci-runner
suites: 121 passed
- `tests/bats/init-workspace.bats` (feature-group assertions): 275/275
pass
- `zizmor --offline` over the workspace templates: no findings
- `prek run --all-files`: green (both hook layers)

## Reviewer notes

- **Provisioning is deliberately out of code scope**: the
`DEVKIT_UPGRADE_TOKEN` App/PAT identity (and optional
`DEVKIT_UPGRADE_AUTHOR_*` variables) must be created per the #1296
checklist before the workflow can act; until then it fails fast with a
pointer. The default author email is a placeholder — set the real
identity at provisioning.
- **Live proof requires a consumer**: this template never executes in
devkit's own CI; first end-to-end validation comes with the first
consumer adoption (worth exercising via `workflow_dispatch` on one lane
during the 1.5.0 rollout).
- The `nix develop -c git commit` step assumes a flake-bearing
(direnv/both) consumer — true for all five current consumers;
bare/devcontainer-only consumers are out of scope per the issue.
- Untracked files matching `DEVKIT_UPGRADE_EXCLUDE` are not reset (`git
checkout --` only restores tracked paths) — acceptable for the known use
case (tracked generated PDFs).
- Merge-order note: this PR and #1297 both touch `CHANGELOG.md`,
`.vig-os`, and `init-workspace.sh`; whichever merges second needs a
trivial conflict resolution (GitHub merges don't apply the changelog
union driver).

Refs: #1296
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