Repository navigation
fix(create-objectstack)!: refuse a current-dir scaffold that would overwrite existing files - #29267
Conversation
…rwrite existing files A run with no name (or an empty one) copied the template over the current directory, replacing an existing README.md and package.json with exit 0. The collisions are now found before the first write: any template file that would replace an existing one refuses the run with exit 1, naming the paths, and nothing is written. Files the template does not write may stay. Claude-Session: https://claude.ai/code/session_01ADHkmQNsRpYUsG5efyi5Ur Co-authored-by: Claude <noreply@anthropic.com>
📓 Docs Drift Check6 anchor(s) derived from 1 changed package(s); no hand-written page names any of them, so this run has nothing to list — not a clean bill of health. This check sees only pages that NAME a derived anchor: one that documents this change in prose, or enumerates it in an authoring dialect, names none and stays invisible to it on every run. What this run could not see
Coarse fallback — 13 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): Which tree this was computed onThis run read A worktree cut from an older # while this PR is open — GitHub drops the merge commit once it closes
git fetch origin 0b058828e0b0b5ea417f9e9baf8a5d3317578835 && git checkout 0b058828e0b0b5ea417f9e9baf8a5d3317578835
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 74a19dd857d5b7bddd8409bd04332cc10c6ad5ae 791e47c3443134c115160aa63e50264152cd19de && git checkout -B drift-repro 74a19dd857d5b7bddd8409bd04332cc10c6ad5ae && git merge --no-ff 791e47c3443134c115160aa63e50264152cd19de
node scripts/docs-audit/affected-docs.mjs --json 74a19dd857d5b7bddd8409bd04332cc10c6ad5ae |
|
domain:server#1 · os-steve · session_01ADHkmQjPiXgNoSaEpqeGvY Contract-review-claim: The lane seat runs this PR's review at |
|
domain:server#1 · os-steve · session_01ADHkmQjPiXgNoSaEpqeGvY Contract reviewServed-tier: Inputs read: card #29134 body + all 3 comments (triage 6572501857, claim 6574098591, dev report 6575170911); PR #29267 body, file list (4 files, +249/−6), net diff ① Derived judgments
② Semver level
③ Boundary flags
④ Design judgment
Narrowing against the published spec on Must-fix: none. Should-fix: none blocking (one coverage note above). Check-runs on Implemented-by: VERDICT: PASS |
|
domain:server#1 · os-steve · session_01ADHkmQjPiXgNoSaEpqeGvY 席位核对 · ACCEPT ·
|
| item | reading |
|---|---|
| Shape | Draft, base main, Fixes #29134. 4 files (+249 / −6): read-only findTemplateCollisions in template-copy.ts, the refusal before the first write in index.ts, new scaffold-current-dir-collision.test.ts (8 cases), a create-objectstack patch changeset with BREAKING banner and ADR-0087 not-required (no-migration-prescription). Metadata-protocol: none. No packages/spec/**, no new flag, no new gate. findTemplateCollisions is not in package.json#exports. Not governed. |
| Rule | Scaffolding into the current directory with no name (or "") refuses with exit 1 before writing anything, naming each path that would be overwritten. Files that don't collide (.git/, notes) still scaffold untouched. The named non-empty-directory refusal is unchanged. |
| Evidence | Base 49aba82b: both runs exited 0 and overwrote README.md / package.json. Head: package 356/356, typecheck 0, ablation red 2/8 then restored, gates 57/57, dogfood VERDICT 0. CI on this head: 50 check-runs, 36 green, 14 skipped, none red; check-expected-skips OK. |
| Open questions | --force: no flag (the claim forbids a new CLI flag; a maintainer can ask for one later). Wording: as is. Both as the review answers. |
| Landing | 「按照 pm-dispatch 规则复核过的都授权」 (Leehom, 2026-10-25T11:35Z): ready and auto-merge through the relay. |
Requested by Steve · project thread
Fixes #29134
Clause-②: no (narrowing) — measured: on base
49aba82ba no-name and an""run in a current directory holdingREADME.md+package.jsonexited 0 and replaced both files; on head791e47c3the same runs exit 1, name both files, and leave the directory byte-identical. Nothing is widened.Metadata-protocol: none
维护者速读
create-objectstack(不带名字或名字为空)时,若模板文件会覆盖目录里已有的文件,脚手架直接拒绝(退出码 1),列出这些文件,什么都不写。.git/、笔记文件)的目录照常生成。回滚即撤销本 PR。packages/create-objectstack/src/index.ts的碰撞拒绝块;src/template-copy.ts的findTemplateCollisions;新测试src/scaffold-current-dir-collision.test.ts。npx tsx packages/create-objectstack/src/index.ts --skip-install --skip-skills,应看到退出码 1、列出 README.md,文件内容不变。What changes
packages/create-objectstack/src/template-copy.ts: new read-onlyfindTemplateCollisions(src, dest)walks the template the waycopyDirdoes (same alias restoration, so_gitignoreis checked as.gitignore) and returns every project-relative path that already exists where the template writes a file, or where a non-directory stands in place of a template directory.copyDiritself is unchanged apart from sharing the alias helper.packages/create-objectstack/src/index.ts: before the first write (beforemkdirSyncand the copy), a non-empty target is checked; any collision printsDirectory is not empty and the template would overwrite N existing files: DIR, lists each path, says nothing was written and names the two ways out (move the files aside, or scaffold into a new named directory), then exits 1. The named non-empty refusal (Directory already exists and is not empty) is untouched and still runs first; an empty target skips the walk..changeset/29134-current-dir-overwrite-refusal.md:create-objectstackpatch, BREAKING banner, both declaration lines, ADR-0087not-required (no-migration-prescription).Tests
New
src/scaffold-current-dir-collision.test.ts(8 cases, real CLI throughtsx, the no-build pattern ofscaffold-description.test.ts):""in a directory with a collidingREADME.md/package.jsonplus a non-collidingnotes.txt: exit 1, the whole tree byte-identical, both paths named,notes.txtnot named;.git/HEADandnotes.txt: scaffolds (exit 0,package.jsonname is the directory name), both files untouched;Created files:);findTemplateCollisionsunit cases: the aliased.gitignore, a file standing where the template needssrc/, a sharedsrc/with only user files (no collision).No existing test needed editing.
Acceptance notes
--force(overwrite on purpose) is a product choice and is left to the maintainer; see the report's open question.AGENTS.mdand.github/copilot-instructions.mdare written with exclusive create. The package-manager install and the skills installer write what they write, as before.Verification
Premise on base 49aba82 (card's reproduction)
No-name run and
""run in a tempmy-app/holdingREADME.md(# my notes) andpackage.json({"name":"mine"}): bothEXIT=0,README.mdnow starts# My App,package.jsonnow"name": "my-app". Named non-empty dir:EXIT=1,Directory already exists and is not empty.Head 791e47c, same reproduction
Both runs
EXIT=1, files unchanged, output namesREADME.mdandpackage.jsonand says nothing was written.Ablation of the refusal (negative pin)
scripts/ablation-replace.mjsonindex.ts, anchorif (collisions.length > 0) {x1 -> x0, replacement x0 -> x1, blobc402bf41f8e7->ee6ac763dfa4. The test file goes red:× refuses with no name …,× refuses with an empty name …,AssertionError: expected +0 to be 1,Tests 2 failed | 6 passed (8). Restored: blob == HEADc402bf41f8e7,git diff HEADempty. The suite runssrc/throughtsxand vitest with nodist/in the path, so no rebuild leg applies.Package suite, typecheck, lint, gates, dogfood at 791e47c
os-verify-lock.sh -c "pnpm --filter 'create-objectstack^...' build && pnpm --filter create-objectstack build && pnpm --filter create-objectstack test && pnpm --filter create-objectstack typecheck": VERDICT command-exit 0;Test Files 23 passed (23),Tests 356 passed (356);tsc --noEmitlists the new test file (count 1).packages/create-objectstackwith--no-inline-config(thepnpm lintcommand, package-scoped): exit 0.dispatch-gates.mjs --commands: 57 derived families, all exit 0;--ranreconciliation: 57 derived, 57 run, 0 NOT-MEASURED (derived zero, every line carries its exit code). Three first exited 3 on prerequisites and were re-run green:check:type-check-debtandcheck:dual-build-cjs-loadsafter the dogfood closure build,check-plugin-teardown-shape --self-testafter fetching its pinned fixture commit.Test Files 388 passed | 3 skipped (391),Tests 3208 passed | 28 skipped (3236).Generated by Claude Code