Skip to content

feat(setup): preflight guard for scaffold upgrades and --preview diff report - #903

Merged
c-vigo merged 6 commits into
devfrom
feature/886-upgrade-preflight-guard
Jul 7, 2026
Merged

c-vigo merged 6 commits into
devfrom
feature/886-upgrade-preflight-guard

Conversation

@c-vigo

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

Copy link
Copy Markdown
Contributor

Description

Adds the upgrade preflight guard and diff preview specified in #886: install.sh --force (the upgrade path) now requires a dedicated working branch with a clean tree, so every scaffold upgrade lands as a single reviewable, revertible diff; a new --preview mode prints the full file report without touching the tree.

Closes #886

Type of Change

  • feat -- New feature
  • fix -- Bug fix
  • docs -- Documentation only
  • chore -- Maintenance task (deps, config, etc.)
  • refactor -- Code restructuring (no behavior change)
  • test -- Adding or updating tests
  • ci -- CI/CD pipeline changes
  • build -- Build system or dependency changes
  • revert -- Reverts a previous commit
  • style -- Code style (formatting, whitespace)

Modifiers

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

Changes Made

  • install.sh — host-side preflight guard on the --force path only (the host is the only place git state is reliable; a worktree's gitdir is not mounted into the container):
    • refuses on main, dev, release/* (prefix), and detached HEAD;
    • refuses on a dirty tree (git status --porcelain must be empty; gitignored clutter passes);
    • on a protected branch with a clean tree, offers to create and switch to chore/devkit-upgrade-<version>; non-interactively it refuses with that command as the hint;
    • non-git directories get a loud "no VCS safety net" warning plus an explicit confirmation;
    • a single --skip-preflight flag bypasses, printed in every refusal;
    • exemptions: --smoke-test (the downstream release gate runs install.sh --version <tag> --smoke-test --force --docker . headless — verified against devcontainer-smoke-test repository-dispatch.yml), --preview (report-only), and fresh installs (no --force);
    • under --dry-run the guard still evaluates but never mutates (accepting the branch offer only reports what it would do).
  • assets/init-workspace.sh — --preview mode: rides the existing conflict-report machinery (now mode-aware: direnv-mode .devcontainer/ and devcontainer-mode stub filters), extended with an ADDED listing and the mode-prune DELETED listing (.devcontainer/justfile.base on upgrades, the direnv-mode .devcontainer/ prune), then exits 0 before any mutation. install.sh forwards the flag and skips all post-init (user conf, git setup) in preview. Kept cleanly callable for feat(workspace): persist delivery mode, identity, and modules in .vig-os — declarative manifest with a new "bare" mode #885's destructive mode switches.
  • devc-upgrade recipe: surfaces the guard and the new flags in its help/output text (no logic change).
  • Docs: docs/MIGRATION.md gains an "Upgrade preflight guard and preview" section; install.sh --help documents --skip-preflight and the --preview vs --dry-run distinction.

Changelog Entry

Added

  • Preflight guard and diff preview for scaffold upgrades (#886)
    • install.sh --force upgrades now refuse on main/dev/release/*/detached HEAD and on a dirty tree, so every upgrade lands as a reviewable, revertible diff on a dedicated branch; on a protected branch with a clean tree the installer offers to create and switch to chore/devkit-upgrade-<version>, and non-git directories get a warn-and-confirm path. A single --skip-preflight flag bypasses the guard; --smoke-test runs and fresh installs are exempt.
    • New --preview mode prints the add/overwrite/preserve/delete file report (including mode-prune deletions such as the retired .devcontainer/justfile.base) and exits without changing any files — unlike --dry-run, which only prints the container command.

Testing

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

Manual Testing Details

TDD (RED commit first, then implementation):

  • tests/bats/install.bats: 78/78 — protected branches (main/dev/release/* prefix), detached HEAD, dirty tree (tracked + untracked-unignored), gitignored-only clutter passes, git-worktree fixture (.git file) both refusing and passing, --skip-preflight, --smoke-test exemption, non-git warn/confirm/decline, dry-run branch offer never mutates, fresh-install exemption, --preview forwarding + guard exemption, help text.
  • tests/bats/init-workspace.bats: 81/81 — --preview exits 0 with the report, leaves the tree byte-identical (diff -r against a pre-copy), lists .devcontainer/justfile.base and the direnv-mode .devcontainer/ prune as DELETED without deleting, works without --force on a populated tree, lists ADDED files without scaffolding them.
  • uv run pytest: 820 passed; the two tests/test_image.py failures are stale-local-image artifacts (one also fails on the dev base commit; the other is the manifest sha check against a local image that predates this branch's changelog/justfile.devc edits — CI rebuilds the image from the branch).
  • Full hook suite green: just precommit → exit 0.

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

  • Accepted residual gap (per the issue's alternatives): direct podman run … init-workspace.sh --force invocations bypass the host guard.
  • The nix-image.yml CI scaffold check runs init-workspace.sh directly against a fresh temp dir — host guard not in its path, unaffected.

Refs: #886

c-vigo added 6 commits July 7, 2026 15:22
Refuse upgrades on main/dev/release/* or detached HEAD and on a dirty
tree; offer chore/devkit-upgrade-<version> on a protected branch; add
--skip-preflight bypass. --smoke-test, --preview, and fresh installs
are exempt.

Refs: #886
Extends the --force conflict report with mode-aware filtering, an ADDED
listing, and the mode-prune DELETED listing, then exits 0 before any
mutation. install.sh forwards the flag and skips post-init in preview.

Refs: #886
MIGRATION.md updating section, install.sh/devc-upgrade help surfaces,
and the changelog entry (with the sync-manifest mirror).

Refs: #886
The upgrade preflight guard (#886) now refuses --force on a non-git
temporary directory, so the fixture provides a clean feature branch.

Refs: #886
…eflight-guard

# Conflicts:
#	CHANGELOG.md
#	assets/workspace/.devcontainer/CHANGELOG.md
@c-vigo
c-vigo merged commit f78299e into dev Jul 7, 2026
13 checks passed
@c-vigo
c-vigo deleted the feature/886-upgrade-preflight-guard branch July 7, 2026 13:55
c-vigo added a commit that referenced this pull request Jul 7, 2026
…ntity and bare mode (#911)

## Description

Promotes `.vig-os` from a single-purpose version pin into the project's
declarative manifest and adds the new `bare` delivery mode.

- **Manifest**: `DEVKIT_MODE`, `DEVKIT_PROJECT`, `DEVKIT_ORG`,
`DEVKIT_REPO` (plus reserved `DEVKIT_MODULES`, #884) are persisted
alongside `DEVCONTAINER_VERSION` — flat `KEY=VALUE` format unchanged,
`DEVCONTAINER_VERSION` not renamed (#781 owns that).
- **Precedence**: explicit flag/env > `.vig-os` > prompt/default, in
both `init-workspace.sh` and `install.sh`; resolved values are written
back on every (re)scaffold, so a manifest-bearing repo upgrades with
`--force` and **no mode/identity flags** while keeping its shape and
names.
- **Legacy inference**: version-only manifests get their mode inferred
conservatively from the tree shape on upgrade (wider mode on ambiguity —
the #859 combination resolves to `both` — inference printed, interactive
runs confirm, persisted afterwards; never reshapes on inference alone).
- **No implicit mode switches**: an explicit `--mode` contradicting the
persisted `DEVKIT_MODE` refuses in both scripts, pointing at `--preview`
(#886) and the deliberate DEVKIT_MODE-edit-on-a-clean-branch flow.
`--preview` and `--smoke-test` are exempt.
- **`bare` mode**: standards-only scaffold (justfiles,
`.pre-commit-config.yaml`, `.github/` CI, `pyproject.toml`, `.vig-os`);
prunes `.devcontainer/`, `flake.nix`, `.envrc` behind the #738/#859
pre-existence guards; ships a host-native `ci.yml`
(`assets/workspace-bare/` overlay): no resolve-image step, no container
jobs — pinned `astral-sh/setup-uv` plus `uv tool install rust-just prek`
drive the same `just sync|precommit|test` contract. The root justfile's
`import?` semantics keep the graph loading without `.devcontainer/`
(proven by bats).
- **Preview UX**: a populated pre-existing `.devcontainer/` now appears
as an explicit PRESERVED line in direnv/bare reports (previously
silently absent).

Closes #885

## Type of Change

- [x] `feat` -- New feature

### Modifiers

- [ ] Breaking change (`!`) -- backward compatible (`semver:minor`); all
existing `.vig-os` parsers are byte-for-byte unaffected
(regression-tested).

## Changes Made

- `assets/workspace/.vig-os`: manifest template with the new key set and
cross-references (#883/#884/#781 noted in comments).
- `assets/init-workspace.sh`: tolerant manifest reader + write-back;
flag/env > manifest > prompt precedence for
SHORT_NAME/ORG_NAME/GITHUB_REPOSITORY/MODE; mode-mismatch refusal;
conservative legacy inference; `bare` mode (rsync exclusion, prune with
guards, host-native ci.yml overlay, report/DELETED integration);
`DEVKIT_MODULES` round-trip across the managed-file overwrite.
- `install.sh`: reads the same keys host-side (mode/name/org/repo
defaults), refuses conflicting `--mode` before pulling the image,
accepts/forwards `--mode bare`, skips the host user-conf step for bare,
bare-aware next-steps hint.
- `assets/workspace-bare/.github/workflows/ci.yml`: host-native CI
template (SHA-pinned actions; yamllint-clean via the hook suite).
- `docs/MIGRATION.md`: four delivery modes + a `.vig-os` project
manifest section (keys, precedence, inference, mode-switch policy,
future flags note for #883).
- Tests: 19 new bats cases in `init-workspace.bats` (manifest matrix
across modes × fresh/legacy/manifest-bearing, refusal/preview, inference
incl. the #859 ambiguity, bare shape + CI-contract resolution), 9 in
`install.bats`, new `manifest-parsers.bats` +
`tests/test_resolve_image_manifest.py` (parser tolerance, byte-identical
outputs).

## Changelog Entry

### Added

- **`.vig-os` project manifest and new `bare` delivery mode**
([#885](#885))
- `.vig-os` now persists the delivery mode and identity (`DEVKIT_MODE`,
`DEVKIT_PROJECT`, `DEVKIT_ORG`, `DEVKIT_REPO`, reserved
`DEVKIT_MODULES`) alongside the version pin — flat `KEY=VALUE` format
unchanged, existing parsers byte-for-byte unaffected. Precedence
flag/env > `.vig-os` > prompt/default, with resolved values written
back, so manifest-bearing repos upgrade with `--force` and no
mode/identity flags while keeping shape and names.
- Legacy (version-only) consumers get their mode inferred conservatively
from the tree shape on upgrade (wider mode on ambiguity, inference
printed and persisted, never reshaping); an explicit `--mode`
contradicting the persisted `DEVKIT_MODE` refuses, pointing at
`--preview` and the preflight-guard flow.
- New `bare` mode ships the standards layer only (justfiles, hooks
config, `.github/` CI, `pyproject.toml`, `.vig-os`), prunes
`.devcontainer/`/`flake.nix`/`.envrc` behind the #738/#859 pre-existence
guards, and scaffolds a host-native `ci.yml` (no image resolution, no
container jobs — `setup-uv` on the runner drives the same `just
sync|precommit|test` contract).

(mirrored in `assets/workspace/.devcontainer/CHANGELOG.md`)

## Testing

- [x] Tests pass locally (`just test-bats`: 100/100 init-workspace,
87/87 install, 4/4 manifest-parsers; `uv run pytest
tests/test_resolve_image_manifest.py`: 2 passed)
- [x] Manual testing performed (describe below)

### Manual Testing Details

- TDD: each sub-feature landed as a RED bats commit (verified failing)
followed by its GREEN implementation commit.
- Full hook suite green locally: `just precommit` (prek run --all-files)
exits 0 — includes yamllint (strict) over the new host-native ci.yml,
shellcheck over both scripts, and check-action-pins.
- The 9 `githooks.bats` failures observed in a nix dev-shell are
pre-existing and environmental (`IN_NIX_SHELL` set); all 12 pass with
`env -u IN_NIX_SHELL`. No `.githooks` files are touched by this PR.

## 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
- [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 (#886/PR #903
and #884/#897 are already on dev; #877 landed as upgrade-time repair —
bare viability is proven via `import?` + justfile.project, see bats)


## Review follow-up

Addresses the review on the torn-manifest window plus the nits, belt and
braces:

- **Torn-state fix (defect):** the template `.vig-os` now ships
`DEVKIT_MODE=` (empty = unset to every parser), and `init-workspace.sh`
persists the resolved `DEVKIT_MODE`/`DEVKIT_PROJECT`/`DEVKIT_ORG`
immediately after the template rsync — before any abort-capable step
(notably `resolve_github_repository`). An upgrade aborted inside the
window (e.g. `--no-prompts` on a legacy tree with a non-github origin)
can no longer persist `DEVKIT_MODE=both` in a direnv-shaped repo, so the
next `--force` run infers/refuses as if the torn run never happened.
`DEVKIT_REPO` stays in the late write-back (only known after origin
resolution); `DEVKIT_PROJECT`/`ORG`/`REPO` already shipped empty in the
template, so empty-as-unset covers them. Reproduced RED with a new
end-to-end bats test (abort, assert manifest not poisoned, re-run,
assert `.devcontainer/` is NOT re-added), then GREEN.
- **Pinned bare CI tools (nit):** the bare `ci.yml` now installs
`rust-just==1.51.0` and `prek==0.3.11` — the versions the flake
toolchain ships — with a comment noting the Renovate/manual bump path.
- **MIGRATION.md (nit):** explicitly flags that `SHORT_NAME`/`ORG_NAME`
env vars now suppress the interactive prompts (precedence flag/env >
manifest > prompt).

Verification: init-workspace 102/102, install 87/87, manifest-parsers
4/4 (193/193 in one run); `just precommit` exits 0 (52 hooks passed).
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