Repository navigation
fix(init): scope placeholder substitution to the paths devkit ships - #1707
Conversation
…ution pass
Two behavioural tests seed files the template never ships -- one under docs/,
one under .venv/lib/ -- each carrying literal {{SHORT_NAME}}, {{ORG_NAME}} and
{{GITHUB_REPOSITORY}}, and assert they survive a first scaffold and an upgrade
untouched while the managed files still resolve.
Both fail today: the runtime substitution walk greps the WHOLE workspace, so it
rewrites consumer files that happen to carry a token.
Refs: #1693
One substitution routine replaces the image-only manifest branch and the
whole-workspace fallback. emit_substitution_candidates walks a source tree and
emits the workspace destinations that exist as regular files, derived exactly as
sweep_scaffold_writable derives its chmod set; the pass runs it for
$TEMPLATE_DIR (plus $SMOKE_TEST_DIR under --smoke-test) and pipes the result
through one batched grep and one batched sed.
Scoping is the point. The retired fallback greped $WORKSPACE_DIR, so every
consumer file carrying a literal {{SHORT_NAME}}/{{ORG_NAME}}/{{GITHUB_REPOSITORY}}
was rewritten on scaffold AND on upgrade -- in the image that is the mounted
repo, .venv and node_modules included. That is the defect this closes, hence
fix, not refactor; the manifest retirement and the two log lines are the
mechanical part. .venv is dropped from the template walk to mirror the copy
rsync's --exclude, because the image bakes a venv inside the template tree.
MANIFEST_FILE is gone; SCRIPT_DIR stays (library, justfile.d, gitignore.d,
smoke-test overlay) and its comment now says so, as do the four other comments
that claimed the manifest "already lists" a path.
Refs: #1693
Nothing reads /root/assets/.placeholder-manifest.txt since the substitution pass became a single scoped routine, so the flake step that grepped the template at build time is gone. test_placeholder_manifest_baked becomes test_placeholder_manifest_absent: a negative pin, so neither the file nor the build step creeps back. scripts/sync_manifest.py's MANIFEST is a different mechanism and is untouched. Refs: #1693
… slash
A trailing slash makes the candidate walk's prefix strip look for `…/workspace//`,
which no `find` output starts with, so every relative path stays absolute, no
destination resolves and the pass substitutes nothing while exiting 0. The
scaffold then ships 13 managed files with live tokens.
Fails today: the run succeeds and justfile.project still reads {{SHORT_NAME}}.
Refs: #1693
… dir
`${1%/}` in emit_substitution_candidates, so the prefix strip that maps a
template path to its workspace destination cannot be defeated by a caller
passing TEMPLATE_DIR with a trailing slash.
The same latent bug exists in sweep_scaffold_writable, the --preview walk and
the +x sweep, which share the mapping idiom. Out of scope here and left for a
follow-up issue rather than fixed by a drive-by.
Refs: #1693
…mantics The copy rsync excludes `.git` and `.venv` by basename, so it skips them at any depth. The candidate walk excludes them by path prefix, which only covers the top level, so a nested `.venv` leaks into the pass and a consumer's own virtualenv files get substituted. Fails today on the nested case: $ws/pkg/.venv/pyvenv.cfg comes back rewritten. Refs: #1693
… walk The copy rsync's `--exclude='.git' --exclude='.venv'` are basename patterns and match at any depth; the walk's `-not -path "$src_dir/.venv/*"` only matched the top level, so a nested one leaked and the pass could reach a destination the copy never wrote. `\( -name .git -o -name .venv \) -prune` is the faithful form, and cheaper: pruned directories are no longer descended. The contract comment also stops claiming the set is derived "exactly as" sweep_scaffold_writable derives its own -- the mapping idiom is shared, the filters are not -- and now states the boundary plainly: a consumer file sitting at a path devkit ships is still substituted, as it always was. Refs: #1693
Image-level byte-identity proof (acceptance criterion)OLD = the image built by PR #1706's CI run (36119970797,
The one content difference is this PR's own changelog entry, mirrored into the scaffolded CI on this PR: all 17 checks green, including |
Description
init-workspace.shhad two placeholder-substitution paths: an image-only fastpath that sed'ed one file per entry of a manifest baked into the image (#718),
and a runtime fallback that batched
grep -rl | xargs sed -iover the wholeworkspace (#1687). This replaces both with one routine whose candidate set is
the files devkit ships, mapped into the workspace.
The issue's premise needs a correction. #1693 called the manifest path
"15-20x slower" on the strength of a ~117-entry list. The baked manifest has
13 entries, not 117, and on a clean tree the manifest path measured 31 ms
against 16 ms for the fallback — speed is noise at that size, and the
"retire it because it is slower" framing does not hold.
What does hold, and is the real reason to land this, is scope. The fallback
greps
$WORKSPACE_DIR, which in the container is the consumer's mounted repo —.venv,node_modulesand all. Any file at a path devkit does not ship, holdinga literal
{{SHORT_NAME}},{{ORG_NAME}}or{{GITHUB_REPOSITORY}}token, wasrewritten in place on the first scaffold and again on every upgrade.
Reproduced with seeded files; two of the new BATS tests fail on
devfor exactlythat reason. The manifest path never had that reach, so retiring it without
scoping the survivor would have made the consumer-facing behaviour strictly
worse. Scoping is also cheaper where it matters: on a 7.4k-file consumer tree the
walk drops from 405 ms to 38 ms.
What this does not change, stated plainly. The new scope is the set of
paths devkit ships, not the set of files devkit owns. A consumer file living
at a shipped path that an upgrade preserves rather than overwrites —
README.md,.typos.toml,.pre-commit-config.yaml,renovate.json, a consumerflake.nix,.devcontainer/*underdirenv/bare— still has its tokens resolved. That isthe retired manifest path's reach exactly, and the reach
sweep_scaffold_writablestill has for its
chmod, so it is neither a regression nor a change; it wassimply never written down.
PRESERVE_FILESis a copy-time concept and does notcarry over to substitution. The changelog entry and the routine's contract
comment both say so now.
Type of Change
feat-- New featurefix-- Bug fixdocs-- Documentation onlychore-- Maintenance task (deps, config, etc.)refactor-- Code restructuring (no behavior change)test-- Adding or updating testsci-- CI/CD pipeline changesbuild-- Build system or dependency changesrevert-- Reverts a previous commitstyle-- Code style (formatting, whitespace)Modifiers
!) -- This change breaks backward compatibilityChanges Made
assets/init-workspace.shemit_substitution_candidates <src_dir>: walksfind -L "$src_dir" -mindepth 1 -type f, skipping.git/and.venv/, maps each relative path to$WORKSPACE_DIR/$reland emits it NUL-terminated when the destination is aregular file and not a symlink. It maps template paths to workspace paths the
same way
sweep_scaffold_writabledoes — a shared idiom, not an identicalroutine: the filters differ (that one takes
-eof any type forchmod, thisone regular files only, and it prunes where the other does not).
$TEMPLATE_DIR, plus$SMOKE_TEST_DIRunder--smoke-test(the overlay lands outside the template tree — same guardsweep_scaffold_writableuses), and pipes the result through one batchedxargs -0 grep -lZand one batchedxargs -0 sed -i..gitand.venvare pruned by name at any depth(
\( -name .git -o -name .venv \) -prune), which is what the copy rsync's--exclude='.git' --exclude='.venv'mean — they are basename patterns — so thewalk cannot reach a destination the copy never wrote. The case that matters in
production is the venv the image bakes inside
/root/assets/workspace([BUG] Nix image missing /root/assets/workspace/.venv — consumer post-create.sh aborts on first line #735).Pruning is also cheaper than filtering: the directories are not descended.
emit_substitution_candidatesnormalizes a trailing slash off its argument(
${1%/}). Without it,TEMPLATE_DIR=".../workspace/"makes the prefix striplook for
.../workspace//, which nofindoutput starts with, so everyrelative path stays absolute, no destination resolves, and the pass substitutes
nothing while exiting 0 — a scaffold that silently ships 13 files with live
tokens.
regular files only, symlinked destinations skipped,
.git/skipped, binariesmatched (no
-I), failures swallowed so neithergrepexit 1 nor exit 2 tripsset -o pipefail.MANIFEST_FILEvariable, theif [[ -f "$MANIFEST_FILE" ]]branch, and both log lines (
Using build-time manifest (N files),Warning: Manifest not found, searching at runtime (slower)).SCRIPT_DIRstays — it locatesparse-github-remote-lib.sh,justfile.d/,gitignore.d/and the smoke-test overlay — and its comment now says soinstead of "for manifest location". Four other comments that claimed the
manifest "already lists" a path (
seed_node_justfile_project's call site,render_license's header, its inline rationale, its call site) are reworded tothe template-shipped set.
flake.nix/root/assets/.placeholder-manifest.txtis removed. Nothing reads it.tests/init-workspace.bats), each RED before itsfix:
docs/my-template.tmpland
.venv/lib/consumer-tokens.txt, each carrying all three tokens — andassert they survive a first scaffold and an upgrade untouched while the
managed files still resolve;
TEMPLATE_DIRand assertsjustfile.projectis substituted;.venv/lib/pyvenv.cfgandpkg/.venv/pyvenv.cfg, seeds both paths in the workspace with tokens, andasserts neither is touched — the nested one is what the old path-prefix
filter leaked.
test_image.py::test_placeholder_manifest_bakedbecomestest_placeholder_manifest_absent: a negative pin, so neither the baked filenor the flake step creeps back.
scripts/sync_manifest.py'sMANIFESTis a different mechanism(
test_manifest_files,verify_file_identity) and is untouched.Changelog Entry
Two notes on that entry.
The #1687 bullet in the same
## Unreleasedsection had its "the host-sideplaceholder-substitution fallback" changed to "pass", so both entries stay
true in one release now that there is no second path for it to be the fallback of.
The three tokens are written with inner spaces because
assets/workspace/.devcontainer/CHANGELOG.mdis template-shipped: the mirror iscopied into every scaffold and is therefore in the candidate set, so a literal
{{SHORT_NAME}}in a changelog entry renders as "a literaltestproj" in theconsumer's copy. Verified: the scaffolded mirror carries no token from this entry.
Testing
just test)just testis not checked because it builds on the local:devimage, which isa known false-failure trap for
test_image.py/test_integration.py; CI'stest-imagejob is the authority for those. Everythingjust testruns thatdoes not need the image was run and is reported below.
Manual Testing Details
BATS —
bats -j 8 tests/bats/init-workspace.bats: 304/304 (300 before,plus four new tests).
bats -j 8 tests/bats/install.bats: 95/95.Python (host-runnable) —
pytest tests/test_utils.py tests/test_install_script.py packages/vig-utils/tests: 654 passed.pytest tests/test_image.py --collect-only: 112 collected, withTestFileStructure::test_placeholder_manifest_absentin place of the retiredtest_placeholder_manifest_baked.Every new test was confirmed RED before its fix:
dev): the seeded file came back asname: testproj / org: test / repo: test/repo, i.e. rewritten;justfile.projectstill read{{SHORT_NAME}}— the pass had silently done nothing;.venv:pkg/.venv/pyvenv.cfgcame back asprompt = testproj test test/repo.Host-side byte-identity proof — the
devscript (git show dev:assets/init-workspace.sh) and this branch's, each rendering the same sixcases into fresh trees, compared with
diff -rand withfind . -printf '%m %y %p\n' | LC_ALL=C sort | sha256sum:diff -r--mode both179411cb1ffd3afcidentical--mode devcontainer282f5fb0a1e3edecidentical--mode direnv7063d83f9b6d1d1bidentical--mode bare186b3bd5895626a0identical--smoke-test --mode both5cb8373e9452920eidenticalDEVKIT_LICENSE=proprietarye29777fff4f255fbidenticalNo managed file in any rendered tree retains a
{{SHORT_NAME}},{{ORG_NAME}}or
{{GITHUB_REPOSITORY}}token..vig-osstill carries{{IMAGE_TAG}}inevery tree, old and new alike: that token is resolved by the image build, never
by this pass.
Absent destinations are skipped silently.
devcontainerandbaremodeexercise this on every run — the template ships
flake.nixand.envrc, therendered workspace has neither — and both renders above are byte-identical with
no
find/grep/sed/xargsnoise in the log. Separately verified by deletingSECURITY.md,.typos.toml,justfile.projectanddocs/CONTRIBUTING.mdfroma rendered tree and re-running the upgrade: exit 0, no error output, no leftover
tokens.
Static checks —
shellcheck -S warning -x assets/init-workspace.shclean;prek run --all-filesclean (53 hooks passed, nothing modified) after thesync-manifesthook regeneratedassets/workspace/.devcontainer/CHANGELOG.md,which is committed alongside
CHANGELOG.md.Flake eval —
nix eval .#packages.x86_64-linux.devkitImage.drvPathstillevaluates, and the drvPath moves relative to
dev, as expected: the image nolonger contains the manifest file. No hash is quoted here — the changelog mirror
is baked into the image, so the value changes with every edit to this branch's
CHANGELOG.md, and a pasted hash would be stale by the time anyone checked it.Image-level proof: pending CI artifact. Acceptance criterion 3 asks for the
diff -r+%m %y %pcomparison across the old and new image, not justhost-side, and that needs this PR's image built. A reusable driver is ready —
it mirrors
tests/conftest.py::_build_podman_cmd(mounts$ws:/workspace,passes
SHORT_NAME/ORG_NAME/GITHUB_REPOSITORY), renders all six casesunder both images, excludes
.vig-osfrom the comparison and reports itsDEVKIT_VERSIONdrift separately, and asserts the retired manifest is absentfrom the new image. It will be run against the CI-built image before merge and
its output posted here.
test_image.pyandtest_integration.pyin thetest-imagejob are the suite-level half of the same proof and cannot be runlocally (a stale local
:devimage is a known false-failure trap).Checklist
docs/templates/, then runjust docs)CHANGELOG.mdin the[Unreleased]section (and pasted the entry above)No documentation update:
docs/carries no prose about the placeholder manifest.The only mentions live in
docs/issues/issue-718.md,docs/issues/issue-1687.md,docs/pull-requests/pr-802.mdandpr-813.md, which are historical records ofthose changes and are not rewritten. The released
CHANGELOGentry for #718 thatnames the manifest also stays as written.
Additional Notes
emit_substitution_candidatesis latent in three siblings that share the same${src_path#"$src_dir"/}mapping idiom —sweep_scaffold_writable, the--previewwalk and the+xsweep. They are deliberately not touched:out of this issue's scope, and a drive-by across three production walks is not
what this PR should carry.
assets/workspace/.devcontainer/CHANGELOG.mdalready carried four literalsubstitution tokens before this branch, all inside released entries (the
vigOS/devcorg default,init-precommit.sh's hard-coded root, the perf: bake the build-time placeholder manifest into the Nix image #718manifest entry itself, and the
--repoflag entry). Those are rewritten in aconsumer's scaffolded mirror today and were rewritten before this PR too —
identical reach, since the mirror is template-shipped either way. Released
entries are not edited, so they stay; worth its own issue if anyone cares.
render_licensestill resolves{{ORG_NAME}}itself rather than leaning onthe shared pass. That reasoning is unchanged by the scoping — the proprietary
template lives in
assets/licenses/, outside the walked tree, and its outputis only reachable because
assets/workspace/LICENSEhappens to carry the sametoken — so the comment is reworded, not the code.
.venvfixes on theirown: both are defects in a routine this same PR introduces, so relative to the
last release there is nothing for a consumer to read beyond the entry already
written.
test), the routine (fix— itstops rewriting files devkit does not ship; the manifest retirement is the
mechanical part), the flake step and image pin (
build), the changelog(
docs), then the trailing-slash test + fix and the.venv-prune test + fix(
test/fixpairs, each RED first).Refs: #1693