rungate 0.5.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/affected-tests.ts +398 -0
- package/lib/agent-audit.ts +2 -3
- package/lib/agent-worktree.ts +287 -0
- package/lib/agents-md-sections.ts +209 -0
- package/lib/behavioral-cache.ts +150 -2
- package/lib/branch-diff.ts +139 -0
- package/lib/branch-protection.ts +790 -0
- package/lib/brief-ac-alignment.ts +104 -0
- package/lib/brief-references.ts +205 -0
- package/lib/bun-version.ts +347 -0
- package/lib/check-remedy.ts +140 -0
- package/lib/ci-checkout.ts +18 -1
- package/lib/ci-history-depth.ts +159 -0
- package/lib/ci-setup-step.ts +96 -0
- package/lib/claude-code-action.ts +85 -0
- package/lib/claude-tool-vocabulary.ts +188 -0
- package/lib/cli-commands.ts +15 -0
- package/lib/commit-sha.ts +42 -0
- package/lib/commit-subject.ts +90 -0
- package/lib/compliance-report.ts +377 -45
- package/lib/compliance.ts +196 -20
- package/lib/config-loader.ts +51 -1
- package/lib/config-trackable.ts +391 -0
- package/lib/conformity.ts +1272 -189
- package/lib/containment.ts +238 -0
- package/lib/content-hash.ts +24 -0
- package/lib/context-docs.ts +143 -28
- package/lib/create-brief.ts +2 -1
- package/lib/create-sc.ts +323 -4
- package/lib/dev-liveness.ts +180 -0
- package/lib/discovery-branch-points.ts +432 -0
- package/lib/discovery-stability.ts +481 -0
- package/lib/distribution-currency.ts +186 -0
- package/lib/doc-routing.ts +157 -0
- package/lib/doc-scan-targets.ts +9 -0
- package/lib/evidence-command-transport.ts +160 -0
- package/lib/evidence-prevalidator.ts +246 -2
- package/lib/evidence-satisfiability.ts +534 -12
- package/lib/failure-intake.ts +317 -0
- package/lib/fallow-availability.ts +286 -0
- package/lib/fs-write-capabilities.ts +232 -0
- package/lib/gate-refusal-currency.ts +112 -0
- package/lib/gate-run-split.ts +147 -0
- package/lib/gate-timeouts.ts +82 -0
- package/lib/generators/agent-briefs.ts +4 -1
- package/lib/generators/agents-md.ts +204 -48
- package/lib/generators/code-map.ts +2 -1
- package/lib/generators/types.ts +8 -0
- package/lib/git-dates.ts +55 -0
- package/lib/git-isolation.ts +140 -0
- package/lib/github.ts +15 -0
- package/lib/google-auth-action.ts +93 -0
- package/lib/harness-project.ts +48 -0
- package/lib/harness-provenance.ts +255 -0
- package/lib/hook-evidence.ts +235 -0
- package/lib/hook-scopes.ts +386 -0
- package/lib/hook-target-tree.ts +398 -0
- package/lib/hook-trees.ts +447 -0
- package/lib/js-top-level-code.ts +78 -10
- package/lib/junit-checks.ts +536 -0
- package/lib/launch-base.ts +253 -0
- package/lib/line-citation.ts +372 -0
- package/lib/local-calendar-day.ts +78 -0
- package/lib/orphan-reaper.ts +468 -0
- package/lib/parity-binding.ts +205 -0
- package/lib/per-test-timeouts.ts +219 -0
- package/lib/plan-coverage.ts +151 -0
- package/lib/prior-branch.ts +201 -8
- package/lib/process-table.ts +146 -0
- package/lib/project-state-derivation.ts +219 -0
- package/lib/project-state-root.ts +258 -0
- package/lib/project-state-shape.ts +59 -0
- package/lib/promote-outputs.ts +6 -2
- package/lib/published-artifact.ts +525 -0
- package/lib/readdir-sorted.ts +45 -0
- package/lib/report-provenance.ts +156 -0
- package/lib/review-execution-reading.ts +206 -0
- package/lib/review-tool-agreement.ts +433 -0
- package/lib/rule-promotion.ts +234 -0
- package/lib/rule-retirement.ts +525 -0
- package/lib/run-branch.ts +612 -0
- package/lib/rungate-schema.ts +19 -0
- package/lib/runner-home.ts +274 -0
- package/lib/sc-claim-forms.ts +75 -0
- package/lib/sc-id-cross-tree.ts +323 -0
- package/lib/sc-ids.ts +121 -13
- package/lib/sc-reservations.ts +289 -0
- package/lib/scaffold/ai-review-findings.ts +403 -0
- package/lib/scaffold/ai-review-step.ts +4777 -0
- package/lib/scaffold/managed-workflow.ts +587 -192
- package/lib/scaffold/owned-files.ts +186 -39
- package/lib/scaffold/pre-push-hook.ts +49 -5
- package/lib/scaffold/rehearsal.ts +205 -71
- package/lib/scaffold/steps.ts +1517 -293
- package/lib/scaffold/workflow-census.ts +217 -0
- package/lib/scaffold/workflow-drift.ts +217 -0
- package/lib/scaffold/write-steps.ts +10 -4
- package/lib/scan-budget.ts +247 -0
- package/lib/scanner.ts +80 -62
- package/lib/scratch-roots.ts +50 -5
- package/lib/screenshot-discovery.ts +121 -0
- package/lib/screenshot-upload.ts +41 -1
- package/lib/secret-patterns.ts +511 -8
- package/lib/ship-mode.ts +219 -0
- package/lib/source-slice.ts +294 -0
- package/lib/spec-listing.ts +148 -0
- package/lib/spec-requirements.ts +209 -0
- package/lib/stale-cleanup.ts +37 -3
- package/lib/suite-flake.ts +278 -0
- package/lib/suite-measurement.ts +23 -4
- package/lib/suite-run-reading.ts +411 -1
- package/lib/suite-timeout-margin.ts +193 -0
- package/lib/test-case-bodies.ts +883 -0
- package/lib/test-case-deletion.ts +653 -0
- package/lib/test-census.ts +97 -29
- package/lib/test-command-positions.ts +274 -0
- package/lib/test-command.ts +133 -0
- package/lib/test-suite-lock.ts +325 -26
- package/lib/tool-probe.ts +142 -0
- package/lib/top-level-cd.ts +393 -0
- package/lib/tracked-vs-ignored.ts +234 -0
- package/lib/tree-entries.ts +89 -0
- package/lib/ts-ast.ts +200 -0
- package/lib/validators/spec-validators.ts +3 -2
- package/lib/walk-test-files.ts +97 -0
- package/lib/workflow-actions.ts +263 -0
- package/lib/worktree-collect.ts +177 -5
- package/lib/worktree-repo.ts +36 -1
- package/package.json +2 -1
- package/scripts/ai-review-findings.ts +45 -0
- package/scripts/audit-specs.ts +247 -12
- package/scripts/audit-transcript.ts +2 -1
- package/scripts/convert-spec.ts +2 -1
- package/scripts/create-sc.ts +37 -7
- package/scripts/create-spec.ts +2 -1
- package/scripts/create-success.ts +2 -1
- package/scripts/extract-constraints.ts +197 -26
- package/scripts/generate-code-map.ts +62 -28
- package/scripts/scaffold-project.ts +12 -2
- package/scripts/split-spec.ts +2 -1
- package/scripts/sync-sc-status.ts +127 -14
- package/scripts/sync-spec-tests.ts +2 -1
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
*/
|
|
49
49
|
|
|
50
50
|
import { spawnSync } from "child_process";
|
|
51
|
-
import { mkdtempSync, rmSync, lstatSync, readdirSync, readlinkSync, realpathSync } from "fs";
|
|
51
|
+
import { chmodSync, mkdirSync, mkdtempSync, rmSync, lstatSync, readdirSync, readlinkSync, realpathSync, statSync } from "fs";
|
|
52
52
|
import { tmpdir } from "os";
|
|
53
53
|
import { join, resolve, sep } from "path";
|
|
54
54
|
|
|
@@ -189,8 +189,16 @@ export function cloneForRehearsal(root: string): Rehearsal {
|
|
|
189
189
|
const parent = mkdtempSync(join(tmpdir(), "rungate-rehearsal-"));
|
|
190
190
|
const dir = join(parent, "tree");
|
|
191
191
|
const fail = (why: string): never => {
|
|
192
|
-
|
|
193
|
-
|
|
192
|
+
// Through `removeTree`: what a failed copy leaves behind is whatever
|
|
193
|
+
// made it fail, and a bare `rmSync` here throws that errno in place of
|
|
194
|
+
// the refusal below — so the caller is told the audit crashed rather
|
|
195
|
+
// than why it declined. A clone we cannot clean up is still a decline,
|
|
196
|
+
// so a leftover is appended to the sentence rather than replacing it.
|
|
197
|
+
const leaked = removeTree(parent);
|
|
198
|
+
throw new Error(
|
|
199
|
+
`audit did NOT run: ${why}` +
|
|
200
|
+
(leaked === null ? "" : ` (and the clone is still on disk: ${parent} — ${leaked})`),
|
|
201
|
+
);
|
|
194
202
|
};
|
|
195
203
|
|
|
196
204
|
// `-c` asks for an APFS clonefile. It fails on filesystems that cannot do
|
|
@@ -206,29 +214,13 @@ export function cloneForRehearsal(root: string): Rehearsal {
|
|
|
206
214
|
// on, so no test could ever reach the second branch. One shared helper
|
|
207
215
|
// removes the ordering rather than testing it.
|
|
208
216
|
let method: Rehearsal["method"] = "clone";
|
|
209
|
-
if (attemptCopy(
|
|
210
|
-
if (attemptCopy(
|
|
217
|
+
if (attemptCopy(root, dir, "-Rc", 300_000) !== 0) {
|
|
218
|
+
if (attemptCopy(root, dir, "-R", 600_000) !== 0) {
|
|
211
219
|
return fail("the tree could not be copied");
|
|
212
220
|
}
|
|
213
221
|
method = "copy";
|
|
214
222
|
}
|
|
215
223
|
|
|
216
|
-
// Pruning happens through `rmSync(..., { recursive: true })`, which
|
|
217
|
-
// follows a symlinked PARENT. `.claude/worktrees` in a tree where
|
|
218
|
-
// `.claude -> /real/.claude` therefore resolves outside the clone and
|
|
219
|
-
// deletes the consumer's real worktrees — a destructive path traversal
|
|
220
|
-
// performed by the mode that promises to write nothing. Found by the
|
|
221
|
-
// commit security review.
|
|
222
|
-
//
|
|
223
|
-
// So nothing is deleted through a symlink. Each excluded path is walked
|
|
224
|
-
// component by component; the moment a component is a link, the link
|
|
225
|
-
// itself is unlinked (never followed) and the walk stops. `node_modules`
|
|
226
|
-
// being a symlink is the common case — the pre-push hook makes one — and
|
|
227
|
-
// must stay cheap rather than refusing the audit.
|
|
228
|
-
for (const rel of REHEARSAL_EXCLUDES) {
|
|
229
|
-
prunePathWithoutFollowingLinks(dir, rel);
|
|
230
|
-
}
|
|
231
|
-
|
|
232
224
|
const missing = missingTopLevel(root, dir);
|
|
233
225
|
if (missing.length > 0) {
|
|
234
226
|
return fail(`the copy is incomplete — ${missing.length} top-level entr(ies) missing: ${missing.slice(0, 5).join(", ")}`);
|
|
@@ -248,15 +240,157 @@ export function cloneForRehearsal(root: string): Rehearsal {
|
|
|
248
240
|
}
|
|
249
241
|
|
|
250
242
|
/**
|
|
251
|
-
*
|
|
243
|
+
* One `cp` invocation. Injectable so a test can record what was copied
|
|
244
|
+
* rather than infer it from the result — "this path is absent from the
|
|
245
|
+
* clone" is true under BOTH orderings, so absence cannot witness the fix.
|
|
246
|
+
*/
|
|
247
|
+
export type CopyRunner = (args: string[], timeout: number) => number;
|
|
248
|
+
|
|
249
|
+
const realCp: CopyRunner = (args, timeout) =>
|
|
250
|
+
spawnSync("cp", args, { encoding: "utf-8", timeout }).status ?? 1;
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Copy `src` to `dst`, never reading an excluded path (#549).
|
|
254
|
+
*
|
|
255
|
+
* The exclusion used to be applied AFTER the clone: `cp -R` copied the whole
|
|
256
|
+
* tree and `prunePathWithoutFollowingLinks` then deleted
|
|
257
|
+
* `.claude/worktrees`. On this repository that directory is **737 MB across
|
|
258
|
+
* 104 worktrees**, and the recursive `rm` died with `EFAULT: bad address in
|
|
259
|
+
* system call argument`. So `bunx rungate scaffold .` could not run on
|
|
260
|
+
* rungate — the harness could not scaffold itself, which is SUCCESS.md
|
|
261
|
+
* claim 5 pointed inward. The exclude list was right the whole time; the
|
|
262
|
+
* ORDERING defeated it, and a consumer with a merely LARGE gitignored
|
|
263
|
+
* directory got a preview that silently spent minutes copying files it was
|
|
264
|
+
* about to delete.
|
|
265
|
+
*
|
|
266
|
+
* ## How the level walk works, and why it is not a full recursive copy
|
|
267
|
+
*
|
|
268
|
+
* Only directories that are an ANCESTOR of an exclude are walked. Everything
|
|
269
|
+
* else is handed to `cp` whole, so the APFS clonefile still applies to the
|
|
270
|
+
* subtree and the cost stays bounded by metadata. On this repo that is two
|
|
271
|
+
* walked directories — the root and `.claude` — and one `cp` per top-level
|
|
272
|
+
* entry.
|
|
273
|
+
*
|
|
274
|
+
* ## Symlinks keep the answers `prunePathWithoutFollowingLinks` worked out
|
|
275
|
+
*
|
|
276
|
+
* They were paid for by a commit security review and the reasons have not
|
|
277
|
+
* changed; what changed is that they are now decisions about what to COPY
|
|
278
|
+
* rather than about what to delete, which is strictly safer because a
|
|
279
|
+
* decision not to copy cannot escape the clone.
|
|
280
|
+
*
|
|
281
|
+
* - **An excluded path that is itself a link** (`node_modules -> /elsewhere`,
|
|
282
|
+
* which the pre-push hook creates): skipped. Previously it was copied and
|
|
283
|
+
* then unlinked; now it is never read. Same clone, one fewer traversal.
|
|
284
|
+
* - **A link that is an ANCESTOR of an exclude** (`.claude -> /real/.claude`
|
|
285
|
+
* while excluding `.claude/worktrees`): copied AS A LINK and not descended
|
|
286
|
+
* into. Descending would read the consumer's real tree, and deleting
|
|
287
|
+
* through it is what the old code's `rmSync(..., { recursive: true })`
|
|
288
|
+
* would have done. The link then reaches `escapingSymlinks`, which refuses
|
|
289
|
+
* the audit — which is what an ancestor pointing out of the clone is for.
|
|
290
|
+
*
|
|
291
|
+
* Returns the first non-zero `cp` status, or 0.
|
|
292
|
+
*/
|
|
293
|
+
/**
|
|
294
|
+
* Remove a tree we own, clearing what makes a removal refuse first.
|
|
295
|
+
* Returns `null` when the path is gone, or the reason it is not.
|
|
296
|
+
*
|
|
297
|
+
* Two things stop `rm` on a tree this module created, and neither is a
|
|
298
|
+
* permission the owner actually lacks:
|
|
252
299
|
*
|
|
253
|
-
*
|
|
254
|
-
*
|
|
300
|
+
* - **BSD file flags.** `cp -Rc` is a clonefile and a clonefile carries
|
|
301
|
+
* flags, so a clone of this repo holds the `uchg` files it sets on
|
|
302
|
+
* `gates/prompts/*.md`. `rm` answers "Operation not permitted" and bun
|
|
303
|
+
* reports it as `EFAULT: bad address in system call argument`, naming
|
|
304
|
+
* neither the file nor the flag. That is #549's error message.
|
|
305
|
+
* - **A directory with no owner-read or owner-execute bit.** An unreadable
|
|
306
|
+
* directory is one `cp` cannot copy, so it is exactly what a failed first
|
|
307
|
+
* attempt leaves behind — and `rmSync` cannot list it to empty it. The
|
|
308
|
+
* owner can always chmod it; `rm -rf` never does.
|
|
309
|
+
*
|
|
310
|
+
* Both are best-effort: `chflags` does not exist on Linux, where there are
|
|
311
|
+
* no BSD flags either, and a failing `chmod` is a tree we do not own, which
|
|
312
|
+
* the removal below will report in its own words.
|
|
255
313
|
*/
|
|
256
|
-
function
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
314
|
+
function removeTree(path: string): string | null {
|
|
315
|
+
spawnSync("chflags", ["-R", "nouchg,noschg", path], { timeout: 60_000 });
|
|
316
|
+
spawnSync("chmod", ["-R", "u+rwX", path], { timeout: 60_000 });
|
|
317
|
+
try {
|
|
318
|
+
rmSync(path, { recursive: true, force: true });
|
|
319
|
+
return null;
|
|
320
|
+
} catch (err) {
|
|
321
|
+
if (spawnSync("rm", ["-rf", path], { encoding: "utf-8", timeout: 120_000 }).status === 0) {
|
|
322
|
+
return null;
|
|
323
|
+
}
|
|
324
|
+
return (err as Error).message;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
export function copyTreeExcluding(
|
|
329
|
+
src: string,
|
|
330
|
+
dst: string,
|
|
331
|
+
excludes: readonly string[],
|
|
332
|
+
cpFlag: string,
|
|
333
|
+
timeout: number,
|
|
334
|
+
run: CopyRunner = realCp,
|
|
335
|
+
): number {
|
|
336
|
+
// Unconditional, so there is one code path rather than two with an
|
|
337
|
+
// ordering between them: a failed `cp -Rc` may have copied part of the
|
|
338
|
+
// tree, and falling back on top of that leaves a PARTIAL clone whose
|
|
339
|
+
// steps report less than `--fix` will do.
|
|
340
|
+
//
|
|
341
|
+
// Through `removeTree`, not a bare `rmSync`. What the first attempt left
|
|
342
|
+
// behind is whatever made it fail — on Linux CI an unreadable directory
|
|
343
|
+
// `cp -R` could not copy and `rmSync` then cannot remove — and a throw
|
|
344
|
+
// here escapes `cloneForRehearsal` as a raw EACCES instead of its refusal
|
|
345
|
+
// sentence. That is the same defect as the one in `discardRehearsal`
|
|
346
|
+
// below, one function earlier.
|
|
347
|
+
if (removeTree(dst) !== null) return 1;
|
|
348
|
+
const paths = excludes.map(e => e.split("/").filter(Boolean)).filter(p => p.length > 0);
|
|
349
|
+
return copyLevel(src, dst, paths, cpFlag, timeout, run);
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
function copyLevel(
|
|
353
|
+
src: string,
|
|
354
|
+
dst: string,
|
|
355
|
+
excludes: string[][],
|
|
356
|
+
cpFlag: string,
|
|
357
|
+
timeout: number,
|
|
358
|
+
run: CopyRunner,
|
|
359
|
+
): number {
|
|
360
|
+
mkdirSync(dst, { recursive: true });
|
|
361
|
+
// The mode of a directory we created ourselves rather than let `cp`
|
|
362
|
+
// create. Without this an 0o700 `.claude` becomes 0o755 in the clone, and
|
|
363
|
+
// a step that reads permissions would see a tree that is not the
|
|
364
|
+
// consumer's.
|
|
365
|
+
try { chmodSync(dst, statSync(src).mode & 0o7777); } catch { /* best effort */ }
|
|
366
|
+
|
|
367
|
+
let entries;
|
|
368
|
+
try {
|
|
369
|
+
entries = readdirSync(src, { withFileTypes: true });
|
|
370
|
+
} catch {
|
|
371
|
+
return 1;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
for (const e of entries) {
|
|
375
|
+
if (excludes.some(p => p.length === 1 && p[0] === e.name)) continue;
|
|
376
|
+
const deeper = excludes.filter(p => p.length > 1 && p[0] === e.name).map(p => p.slice(1));
|
|
377
|
+
// `isDirectory()` is false for a symlink, which is the behaviour this
|
|
378
|
+
// relies on: an ancestor link falls through to the `cp` below and is
|
|
379
|
+
// copied as a link rather than walked.
|
|
380
|
+
if (deeper.length > 0 && e.isDirectory()) {
|
|
381
|
+
const st = copyLevel(join(src, e.name), join(dst, e.name), deeper, cpFlag, timeout, run);
|
|
382
|
+
if (st !== 0) return st;
|
|
383
|
+
continue;
|
|
384
|
+
}
|
|
385
|
+
const st = run([cpFlag, join(src, e.name), join(dst, e.name)], timeout);
|
|
386
|
+
if (st !== 0) return st;
|
|
387
|
+
}
|
|
388
|
+
return 0;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
/** Copy into `dir`, excluding what the clone does not want. */
|
|
392
|
+
function attemptCopy(root: string, dir: string, cpFlag: string, timeout: number): number {
|
|
393
|
+
return copyTreeExcluding(root, dir, REHEARSAL_EXCLUDES, cpFlag, timeout);
|
|
260
394
|
}
|
|
261
395
|
|
|
262
396
|
/**
|
|
@@ -281,54 +415,54 @@ export function missingTopLevel(root: string, dir: string): string[] {
|
|
|
281
415
|
}
|
|
282
416
|
|
|
283
417
|
/**
|
|
284
|
-
*
|
|
285
|
-
*
|
|
286
|
-
*
|
|
287
|
-
*
|
|
288
|
-
*
|
|
289
|
-
*
|
|
290
|
-
*
|
|
291
|
-
*
|
|
292
|
-
*
|
|
293
|
-
*
|
|
294
|
-
*
|
|
295
|
-
*
|
|
296
|
-
*
|
|
297
|
-
*
|
|
298
|
-
*
|
|
299
|
-
*
|
|
300
|
-
*
|
|
301
|
-
*
|
|
302
|
-
*
|
|
303
|
-
*
|
|
304
|
-
*
|
|
305
|
-
*
|
|
306
|
-
*
|
|
418
|
+
* Throw the clone away. Safe to call twice. Returns why it could not, or
|
|
419
|
+
* `null`.
|
|
420
|
+
*
|
|
421
|
+
* ## The clone can contain files that refuse to be deleted (#549)
|
|
422
|
+
*
|
|
423
|
+
* `cp -Rc` is a clonefile, and a clonefile carries the source's BSD FILE
|
|
424
|
+
* FLAGS. This repository sets `uchg` on `gates/prompts/*.md` — that is the
|
|
425
|
+
* prompt-immutability feature working as designed — so the clone contains
|
|
426
|
+
* immutable files and `rm` refuses them:
|
|
427
|
+
*
|
|
428
|
+
* ```
|
|
429
|
+
* rm: .../tree/gates/prompts/evidence-validator.md: Operation not permitted
|
|
430
|
+
* ```
|
|
431
|
+
*
|
|
432
|
+
* bun reports that as `EFAULT: bad address in system call argument, rm`,
|
|
433
|
+
* which names neither the file nor the flag, and the THROW took down a
|
|
434
|
+
* scaffold run whose report had already printed. That is the whole of #549's
|
|
435
|
+
* symptom: `bunx rungate scaffold .` could not complete on rungate itself.
|
|
436
|
+
* The 737 MB `.claude/worktrees` directory the issue identified made it
|
|
437
|
+
* slower and held most of the flagged copies, and excluding it from the copy
|
|
438
|
+
* is right and necessary — but the thing `rm` was actually refusing was a
|
|
439
|
+
* flag, not a size.
|
|
440
|
+
*
|
|
441
|
+
* So the flags are cleared in the CLONE before it is removed. Only in the
|
|
442
|
+
* clone: `r.parent` always comes from `mkdtemp`, the consumer's own files
|
|
443
|
+
* are never touched, and the flags are deliberately left intact DURING the
|
|
444
|
+
* rehearsal so the steps see the tree the consumer has rather than a more
|
|
445
|
+
* permissive one.
|
|
446
|
+
*
|
|
447
|
+
* ## A cleanup failure is reported, not thrown
|
|
448
|
+
*
|
|
449
|
+
* The report is already printed by the time this runs. Turning a leaked temp
|
|
450
|
+
* directory into a non-zero exit loses the audit; saying nothing loses the
|
|
451
|
+
* leak, which is #437. So it returns the sentence and the caller prints it.
|
|
307
452
|
*/
|
|
308
|
-
function
|
|
309
|
-
let current = root;
|
|
310
|
-
const parts = rel.split("/").filter(Boolean);
|
|
311
|
-
for (let i = 0; i < parts.length; i++) {
|
|
312
|
-
current = join(current, parts[i]!);
|
|
313
|
-
let st;
|
|
314
|
-
try { st = lstatSync(current); } catch { return; } // absent: nothing to prune
|
|
315
|
-
const last = i === parts.length - 1;
|
|
316
|
-
if (st.isSymbolicLink()) {
|
|
317
|
-
if (last) rmSync(current, { force: true });
|
|
318
|
-
return; // an ancestor link: prune nothing, and let the refusal catch it
|
|
319
|
-
}
|
|
320
|
-
if (!last && !st.isDirectory()) return;
|
|
321
|
-
}
|
|
322
|
-
rmSync(current, { recursive: true, force: true });
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
/** Throw the clone away. Safe to call twice. */
|
|
326
|
-
export function discardRehearsal(r: Rehearsal): void {
|
|
453
|
+
export function discardRehearsal(r: Rehearsal): string | null {
|
|
327
454
|
// `r.parent`, not `join(r.dir, "..")`. Deriving a deletion target by
|
|
328
455
|
// walking up from a path is how a cleanup ends up removing something it
|
|
329
456
|
// does not own; the owner is recorded at creation instead. Leaving the
|
|
330
457
|
// mkdtemp behind is the leak #437 is about, so it is the parent that goes.
|
|
331
|
-
|
|
458
|
+
//
|
|
459
|
+
// One binding with the copy's own cleanup, so the flag-clearing and the
|
|
460
|
+
// mode-clearing cannot drift apart between the two places that delete a
|
|
461
|
+
// tree this module made.
|
|
462
|
+
const why = removeTree(r.parent);
|
|
463
|
+
if (why === null) return null;
|
|
464
|
+
return `the rehearsal clone could not be removed and is still on disk: ${r.parent} — ` +
|
|
465
|
+
`${why}. Remove it by hand; nothing in the consumer's tree was touched.`;
|
|
332
466
|
}
|
|
333
467
|
|
|
334
468
|
/**
|