Skip to content

fix(workspace): repair preserved justfile.project with missing base recipes on upgrade - #891

Merged
c-vigo merged 5 commits into
devfrom
bugfix/877-upgrade-strands-base-recipes
Jul 7, 2026
Merged

c-vigo merged 5 commits into
devfrom
bugfix/877-upgrade-strands-base-recipes

Conversation

@c-vigo

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

Copy link
Copy Markdown
Contributor

Description

Closes #877

The 0.4.0 scaffold retired .devcontainer/justfile.base and relocated the base recipes (lint, format, precommit, test, test-cov, sync, update) into justfile.project — a PRESERVE_FILES entry. Upgrading 0.3.x consumers therefore kept their old justfile.project and never received the recipes, while the shipped ci.yml calls just sync / just precommit / just test, so in-container CI failed with justfile does not contain recipe 'sync' (observed on hyrr and talys during 0.4.0 field validation).

Design decision

Chosen: option (b) from the issue — upgrade-time repair of the preserved justfile.project. init-workspace --force now probes each CI-contract recipe with just --show against the assembled import graph and appends only the missing ones, sourcing the recipe blocks verbatim from the template justfile.project (which stays the SSoT) under a clearly marked, review-me banner.

Why not the alternatives:

  • (a) Move the recipes into a managed justfile (justfile.devc or a resurrected base file): justfile.devc lives under .devcontainer/, which a direnv-mode workspace does not have — the recipes would vanish there. Any managed root-level file would also collide (just duplicate-recipe parse error) with fresh 0.4.0 scaffolds and consumers that already migrated the recipes into their justfile.project, and it would reverse the deliberate 0.4.0 decision that teams own and customize these recipes (the field complaint about sync semantics shows they need to).
  • (c) MIGRATION.md step + warning only: keeps every upgraded consumer's CI red until a human intervenes; the repair is deterministic and safe, so automating it is strictly better. The MIGRATION.md step and the existing non-fatal warning are still included.

Properties of the repair: customized consumer recipes always win (only unresolved names are appended), re-running the upgrade is a no-op, and fresh scaffolds are untouched (they get the template file wholesale).

Changes Made

  • assets/init-workspace.sh:
    • CI_CONTRACT_RECIPES list + extract_template_recipe() (awk block extraction from the template justfile.project).
    • Post-scaffold repair: appends missing CI-contract recipes to a preserved justfile.project under a marked banner.
    • Removes the retired .devcontainer/justfile.base on upgrade — only where the scaffold manages .devcontainer/ (never in direnv mode, respecting the [BUG] install.sh --mode direnv --force overwrites populated consumer files (pyproject.toml, .devcontainer/) #738 boundary).
    • Warns loudly if the managed root justfile lacks the scaffold import? block (talys field case: recipes present but unreachable).
  • tests/bats/init-workspace.bats: five new tests (repair delivers all seven recipes; customized recipes win + idempotency; stale justfile.base removed; direnv-mode pre-existing .devcontainer/ untouched; import-block verification present). TDD: RED committed first, then GREEN.
  • docs/MIGRATION.md: new step 1 in the 0.3.x upgrade checklist describing the relocation, the automatic repair, and the root-justfile import check.
  • CHANGELOG.md (+ hook-synced .devcontainer mirror): Unreleased/Fixed entry.

Type of Change

  • fix -- Bug fix

Modifiers

  • Breaking change (!)

Changelog Entry

Fixed

  • Scaffold upgrade strands base recipes in a preserved justfile.project (#877)
    • 0.4.0 moved lint/format/precommit/test/test-cov/sync/update into justfile.project, which is preserved on upgrade — 0.3.x consumers never received them and the shipped ci.yml failed with justfile does not contain recipe 'sync'. init-workspace --force now appends the missing base recipes from the template into the preserved file (customized recipes always win; idempotent).
    • The retired .devcontainer/justfile.base is removed on upgrade where the scaffold manages .devcontainer/ (never in direnv mode, #738), and the installer warns if the root justfile lacks the scaffold import? block.

Testing

  • Tests pass locally: bats tests/bats/init-workspace.bats tests/bats/install.bats (123 ok), uv run pytest tests/test_install_script.py (23 passed)
  • Manual testing performed (describe below)

Manual Testing Details

Ran init-workspace.sh --force against a temp workspace carrying a pre-0.4.0 justfile.project (own project var + info recipe, no base recipes): consumer content preserved, all seven recipes appended under the marked banner, just --list parses and resolves the full layered graph; second run appended nothing.

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
  • 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
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published

Out of scope / follow-up

The template sync recipe's semantics change (plain uv sync → uv sync --all-extras --all-groups), noted at the end of #877, is deliberately untouched here; the repair appends the current template recipe as-is. It likely deserves its own issue (it breaks repos that quarantine platform-limited deps in optional extras, e.g. hyrr's geometry extra).

c-vigo added 3 commits July 7, 2026 11:41
RED for #877: a preserved pre-0.4.0 justfile.project never receives the
relocated base recipes (lint/format/precommit/test/test-cov/sync/update),
so the shipped ci.yml fails with missing-recipe errors. Also cover stale
.devcontainer/justfile.base removal, the direnv-mode #738 boundary, and
the root-justfile import block verification.

Refs: #877
…ecipes on upgrade

0.4.0 relocated the base recipes into justfile.project, which is
preserved on upgrade, so 0.3.x consumers never received them and the
shipped ci.yml failed with missing-recipe errors. The upgrade now
appends any CI-contract recipe (lint/format/precommit/test/test-cov/
sync/update) that does not resolve in the import graph, sourcing the
blocks from the template (SSoT); customized consumer recipes always
win and re-runs are no-ops. Also removes the retired
.devcontainer/justfile.base where the scaffold manages .devcontainer/
(never in direnv mode, #738) and warns when the managed root justfile
lacks the scaffold import block.

Refs: #877
MIGRATION.md 0.3.x checklist gains the base-recipe relocation/repair
step; CHANGELOG Unreleased/Fixed entry for the stranded recipes (the
.devcontainer mirror is hook-synced).

Refs: #877
c-vigo added 2 commits July 7, 2026 12:09
A syntax error in the preserved justfile.project makes every recipe
probe fail, so the repair appends all template recipes on each --force
run, duplicating them and hard-breaking just once the consumer fixes
the original error.

Refs: #877
…not parse

A syntax error in the preserved justfile.project made every
`just --show` probe fail, so all seven template recipes were
appended on each --force run — duplicating recipes the consumer
already defined and hard-failing just with 'recipe redefined' once
the original error was fixed. Gate the repair on `just --list`
parsing the workspace graph, warn loudly and skip otherwise. Also
guard against a missing `just` binary and an empty template
extraction.

Refs: #877
@c-vigo

c-vigo commented Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

Independent review (pre-push): ran bats tests/bats/init-workspace.bats on the branch — all 5 new #877 tests passed (test 60 / #859 needs network, fails identically on dev, unrelated). One real defect found and since fixed on this branch: an unparseable preserved justfile.project made just --show fail for all recipes, so the repair appended all 7 template recipes even when already defined — non-idempotently (grep -c '^sync:' went 1 → 2 → 3 across two --force runs), and the duplicates become a hard Recipe 'sync' … redefined error once the consumer fixes their syntax error. Fixed by gating the repair on an import-graph parse check (warn + skip when the graph does not parse), with a bats regression test; defect reproduced at f4874b9, fix verified in e7efac3 + 834ec0b (RED confirmed failing, GREEN confirmed passing).

Non-blocking notes: template-recipe drift is pinned by the CI alignment test; the parse gate also covers the missing-just edge; test 67 pins the import-block check's existence but not the warning path itself. Everything else checked out: #738 direnv boundary respected (rsync exclude + MODE guard), awk extraction handles attributes/multi-line/last-recipe, customized recipes win, happy-path re-runs are no-ops, set -e safe around the probes, changelog/mirror placement fine.

@c-vigo
c-vigo merged commit 7f578e2 into dev Jul 7, 2026
13 checks passed
@c-vigo
c-vigo deleted the bugfix/877-upgrade-strands-base-recipes branch July 7, 2026 11:25
c-vigo added a commit that referenced this pull request Jul 7, 2026
…ade (#895)

## Description

Closes #878

The scaffold upgrade (`init-workspace.sh --force`) replaced the
consumer's `.pre-commit-config.yaml` wholesale — it was not in
`PRESERVE_FILES` — silently dropping repo-specific configuration: the
global `exclude:` block (hyrr: physics data tables, generated schemas,
jupytext pairs — post-upgrade the hook suite "fixed" ~45 files it must
never touch) and per-hook `exclude:` keys (hyrr: the
`detect-private-key` exclusion for a file carrying PEM marker literals →
false positive).

## Design decision

Chosen: **preserve-with-managed-warning**, the first option listed on
the issue and the one consistent with the #877 precedent (#891): the
consumer owns the file. `.pre-commit-config.yaml` joins
`PRESERVE_FILES`, and the upgrade adds two non-fatal guards:

- **Diff hint** — when the preserved file differs from the incoming
template, the installer prints a unified diff so template hook-stack
evolution stays visible and consumers fold it in deliberately (nothing
is lost silently in either direction: the consumer file is kept
verbatim, the template delta is printed in full). A stock consumer whose
file matches the template gets no noise.
- **Parse gate** — the preserved config is checked with `prek
validate-config` (prek ships in `devTools`, so it is on PATH in the
image and the dev-shell); a config the runner cannot load breaks every
commit in the new image, so the installer warns loudly, pointing at the
exact command. Same philosophy as the #877 `just --list` parse gate:
probe with the real tool, warn, never fail the scaffold.

No `.bak-upgrade` backup file is needed: under preserve, the consumer's
data is never touched, and the diff output carries the template side.

Why not **replace-but-carry-over** (rewrite from template, re-apply
consumer `exclude:`/`files:` keys):

- **No YAML parser is guaranteed at init-workspace runtime.** The image
`pythonEnv` is python3.14 + vig-utils (rich) + pip-licenses — no PyYAML;
`devTools` carries no `yq`. A structured merge would need a new image
dependency for one upgrade step, and a regex/awk-based merge would risk
corrupting exactly the file it must protect (block scalars, nested hook
maps).
- **Key-level carry-over still loses data silently.** Real consumers
customize more than excludes — they add whole hooks and repos (jupytext,
schema checks). Carrying over only `exclude:`/`files:` keys would drop
those just as silently as today's wholesale replacement.
- **It reverses the 0.4.0 ownership direction.** The `justfile.project`
precedent (#877/#891) deliberately made these team-owned, customizable
files; the hook config is the same class — the issue exists precisely
because repos must customize it.

### Implications for #881 and template-driven hook evolution

A pure preserve means hook-stack evolution (runner migrations, compat
fixes like `default_language_version: python3.14` #803 or `typos
--force-exclude` #859, new hooks) no longer arrives automatically — a
consumer upgrading from a pre-prek scaffold keeps a pre-prek-era config.
This PR mitigates that with the always-printed template diff plus the
MIGRATION.md step, and the design keeps the #881 path open rather than
harder: the new post-scaffold guard block is the natural hook point for
future surgical repairs on the preserved file (#877-style), e.g. an
upgrade-time scan/rewrite of retired `pre-commit` invocations in
preserved files, or a targeted key repair once a YAML-capable tool is in
the toolchain. Config-side, prek is a drop-in reader of
`.pre-commit-config.yaml`, so preserved configs keep loading; the
`pre-commit` *binary* references that #881 covers live in
`justfile.project`/`.githooks`, which were already preserved before this
PR — #881's scope is unchanged.

## Changes Made

- `assets/init-workspace.sh`:
- `.pre-commit-config.yaml` added to `PRESERVE_FILES` (with the #878
rationale comment, mirroring the neighboring entries).
- `PRECOMMIT_CONFIG_PREEXISTED` recorded pre-scaffold (same pattern as
`JUSTFILE_PROJECT_PREEXISTED`).
- Post-scaffold guard: prints the consumer-vs-template unified diff when
they differ, then warns (non-fatally) if `prek validate-config` rejects
the preserved file; silent for stock consumers; `prek` absence is
tolerated.
- `tests/bats/init-workspace.bats`: four new end-to-end tests
(customizations survive verbatim; diff hint printed with template
content visible; no hint when the file matches the template; invalid
preserved config warns and stays preserved). TDD: RED committed first,
then GREEN.
- `docs/MIGRATION.md`: new step 2 in the 0.3.x upgrade checklist
describing the preservation, the diff review, and the `prek
validate-config` check.
- `CHANGELOG.md` (+ hook-synced `.devcontainer` mirror):
Unreleased/Fixed entry.

## Type of Change

- [x] `fix` -- Bug fix

### Modifiers

- [ ] Breaking change (`!`)

## Changelog Entry

### Fixed

- **Scaffold upgrade replaces `.pre-commit-config.yaml`, silently
clobbering repo-specific hook config**
([#878](#878))
- The upgrade overwrote the consumer's `.pre-commit-config.yaml`
wholesale, dropping the repo-specific global `exclude:` block and
per-hook `exclude:` keys — the hook suite then rewrote data files it
must never touch and false-flagged PEM marker literals. The file is now
preserved on upgrade (like `justfile.project`,
[#877](#877)).
- Because template hook-stack evolution no longer arrives automatically,
`init-workspace --force` prints a diff of the preserved file against the
incoming template so consumers can fold changes in deliberately, and
warns (non-fatally) when the preserved config does not parse under `prek
validate-config` — a config the runner cannot load breaks every commit
in the new image.

## Testing

- [x] Tests pass locally: `bats tests/bats/init-workspace.bats` (72 ok),
full hook suite green (`just precommit`)
- [x] Manual testing performed (describe below)

### Manual Testing Details

Ran `init-workspace.sh --force` against a temp workspace carrying a
hyrr-shaped `.pre-commit-config.yaml` (global `exclude:
^data/stopping/|\.dat$` + `detect-private-key` per-hook exclude): the
consumer file survived verbatim, the installer printed the "yours was
kept" banner with the full unified diff against the template, and the
scaffold completed successfully. A second run on a stock
(template-identical) workspace printed no warning.

## 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
- [x] New and existing unit tests pass locally with my changes
- [ ] Any dependent changes have been merged and published
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