@webpieces/pr-gate 0.4.786 → 0.4.787

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webpieces/pr-gate",
3
- "version": "0.4.786",
3
+ "version": "0.4.787",
4
4
  "description": "Gated PR system: 3-point squash-merge, merge validation gate, and red/yellow/green PR dashboard. Standalone scripts, no Nx dependency required.",
5
5
  "type": "commonjs",
6
6
  "main": "./src/index.js",
@@ -16,8 +16,8 @@
16
16
  },
17
17
  "dependencies": {
18
18
  "@inversifyjs/binding-decorators": "1.1.5",
19
- "@webpieces/ai-hook-rules": "0.4.786",
20
- "@webpieces/rules-config": "0.4.786",
19
+ "@webpieces/ai-hook-rules": "0.4.787",
20
+ "@webpieces/rules-config": "0.4.787",
21
21
  "inversify": "7.10.4",
22
22
  "reflect-metadata": "0.2.2"
23
23
  },
@@ -1,4 +1,4 @@
1
- import { AgedTreeSweeper, DotWebpieces, RepoRootFinder } from '@webpieces/rules-config';
1
+ import { AgedTreeSweeper, DotWebpieces, RepoRootFinder, TmpScratchSweeper } from '@webpieces/rules-config';
2
2
  /**
3
3
  * 30-day garbage collection of this tree's `.webpieces` scratch state.
4
4
  *
@@ -14,15 +14,26 @@ import { AgedTreeSweeper, DotWebpieces, RepoRootFinder } from '@webpieces/rules-
14
14
  * `aiWritable()` for why `pr-review/` has to sit in the worktree). The repo-wide `shared()` dir is never
15
15
  * swept: its entries belong to every worktree at once.
16
16
  * This used to sweep a second, machine-global root (`~/.webpieces/prs/...`, which survived `rm -rf <clone>`
17
- * and so had no other owner). That store is gone — the gated merge body is the PR's own description now —
18
- * and with it the only artifact webpieces ever wrote outside a repo. See
19
- * `decisions/0005-the-pr-description-is-the-merge-body.md`.
17
+ * and so had no other owner). That store is gone — the gated merge body is the PR's own description now.
18
+ * See `decisions/0005-the-pr-description-is-the-merge-body.md`.
19
+ *
20
+ * ─── That removal came with a claim that was false, and this is the correction ─────────────────────
21
+ * This docblock used to end "and with it the only artifact webpieces ever wrote outside a repo". It was
22
+ * not: every `packages/tooling/**` spec mints its fixture with `fs.mkdtempSync(os.tmpdir(), 'wp-...')`,
23
+ * and so did two runtime paths. Nothing reaped any of them, and because THIS comment asserted there was
24
+ * nothing out there to reap, nobody went looking. Measured on one developer machine: 270,200 abandoned
25
+ * `wp-*` directories in `$TMPDIR`.
26
+ *
27
+ * The fix is ownership at the call site — `SpecTempDirs` for fixtures, `RepoScratchDirs` (which lands
28
+ * under the `.webpieces` scope swept below) for the two runtime paths. `TmpScratchSweeper` is the
29
+ * backstop for the residue an exit handler cannot cover: a SIGKILLed worker, a lost power rail.
20
30
  */
21
31
  export declare class CleanTmp {
22
32
  private readonly repoRootFinder;
23
33
  private readonly sweeper;
34
+ private readonly tmpSweeper;
24
35
  private readonly dotDir;
25
- constructor(repoRootFinder: RepoRootFinder, sweeper: AgedTreeSweeper, dotDir?: DotWebpieces);
36
+ constructor(repoRootFinder: RepoRootFinder, sweeper: AgedTreeSweeper, tmpSweeper: TmpScratchSweeper, dotDir?: DotWebpieces);
26
37
  cleanTmp(): Promise<void>;
27
38
  /**
28
39
  * The per-worktree roots that exist, de-duplicated. `local()` and `aiWritable()` are the SAME path
@@ -22,17 +22,29 @@ const SEP = '━━━━━━━━━━━━━━━━━━━━━━
22
22
  * `aiWritable()` for why `pr-review/` has to sit in the worktree). The repo-wide `shared()` dir is never
23
23
  * swept: its entries belong to every worktree at once.
24
24
  * This used to sweep a second, machine-global root (`~/.webpieces/prs/...`, which survived `rm -rf <clone>`
25
- * and so had no other owner). That store is gone — the gated merge body is the PR's own description now —
26
- * and with it the only artifact webpieces ever wrote outside a repo. See
27
- * `decisions/0005-the-pr-description-is-the-merge-body.md`.
25
+ * and so had no other owner). That store is gone — the gated merge body is the PR's own description now.
26
+ * See `decisions/0005-the-pr-description-is-the-merge-body.md`.
27
+ *
28
+ * ─── That removal came with a claim that was false, and this is the correction ─────────────────────
29
+ * This docblock used to end "and with it the only artifact webpieces ever wrote outside a repo". It was
30
+ * not: every `packages/tooling/**` spec mints its fixture with `fs.mkdtempSync(os.tmpdir(), 'wp-...')`,
31
+ * and so did two runtime paths. Nothing reaped any of them, and because THIS comment asserted there was
32
+ * nothing out there to reap, nobody went looking. Measured on one developer machine: 270,200 abandoned
33
+ * `wp-*` directories in `$TMPDIR`.
34
+ *
35
+ * The fix is ownership at the call site — `SpecTempDirs` for fixtures, `RepoScratchDirs` (which lands
36
+ * under the `.webpieces` scope swept below) for the two runtime paths. `TmpScratchSweeper` is the
37
+ * backstop for the residue an exit handler cannot cover: a SIGKILLed worker, a lost power rail.
28
38
  */
29
39
  let CleanTmp = class CleanTmp {
30
40
  repoRootFinder;
31
41
  sweeper;
42
+ tmpSweeper;
32
43
  dotDir;
33
- constructor(repoRootFinder, sweeper, dotDir = rules_config_1.dotWebpieces) {
44
+ constructor(repoRootFinder, sweeper, tmpSweeper, dotDir = rules_config_1.dotWebpieces) {
34
45
  this.repoRootFinder = repoRootFinder;
35
46
  this.sweeper = sweeper;
47
+ this.tmpSweeper = tmpSweeper;
36
48
  this.dotDir = dotDir;
37
49
  }
38
50
  async cleanTmp() {
@@ -53,6 +65,12 @@ let CleanTmp = class CleanTmp {
53
65
  const total = new rules_config_1.SweepCount();
54
66
  for (const base of bases)
55
67
  total.add(this.sweeper.sweep(base, cutoffMs, this.reporter(base)));
68
+ // The `$TMPDIR` backstop. Counted into the same total so one line reports one cleanup, and run
69
+ // last because it is the only part that touches a directory webpieces does not own.
70
+ const tmpCutoffMs = rules_config_1.TMP_SCRATCH_RETENTION_DAYS * 24 * 60 * 60 * 1000;
71
+ total.add(this.tmpSweeper.sweep(tmpCutoffMs, (removed) => {
72
+ process.stdout.write(` 🗑️ dir: ${removed}/\n`);
73
+ }));
56
74
  if (total.empty) {
57
75
  process.stdout.write(` ✅ Nothing older than ${rules_config_1.RETENTION_DAYS} days; no empty directories\n`);
58
76
  }
@@ -92,6 +110,7 @@ exports.CleanTmp = CleanTmp = tslib_1.__decorate([
92
110
  (0, inversify_1.injectable)(inversify_1.bindingScopeValues.Singleton),
93
111
  tslib_1.__metadata("design:paramtypes", [rules_config_1.RepoRootFinder,
94
112
  rules_config_1.AgedTreeSweeper,
113
+ rules_config_1.TmpScratchSweeper,
95
114
  rules_config_1.DotWebpieces])
96
115
  ], CleanTmp);
97
116
  //# sourceMappingURL=cleanTmp.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"cleanTmp.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/cleanTmp.ts"],"names":[],"mappings":";;;;AAAA,+CAAyB;AACzB,mDAA6B;AAC7B,0DAEiC;AACjC,yCAA2D;AAE3D,MAAM,GAAG,GAAG,0DAA0D,CAAC;AAEvE;;;;;;;;;;;;;;;;;;GAkBG;AAEI,IAAM,QAAQ,GAAd,MAAM,QAAQ;IAEI;IACA;IACA;IAHrB,YACqB,cAA8B,EAC9B,OAAwB,EACxB,SAAuB,2BAAY;QAFnC,mBAAc,GAAd,cAAc,CAAgB;QAC9B,YAAO,GAAP,OAAO,CAAiB;QACxB,WAAM,GAAN,MAAM,CAA6B;IACrD,CAAC;IAEJ,KAAK,CAAC,QAAQ;QACV,MAAM,QAAQ,GAAG,IAAI,CAAC,cAAc,CAAC,eAAe,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;QACpE,4FAA4F;QAC5F,gGAAgG;QAChG,mFAAmF;QACnF,6FAA6F;QAC7F,8FAA8F;QAC9F,MAAM,KAAK,GAAG,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;QACxC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO;QAE/B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,GAAG,GAAG,GAAG,oCAAoC,GAAG,GAAG,GAAG,IAAI,CAAC,CAAC;QACrF,KAAK,MAAM,IAAI,IAAI,KAAK;YAAE,OA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QAAQ,CAAC,CAAC,CAAC;QACnF,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;QAC/B,OAAO,UAAU,CAAC,MAAM,CAAC,CAAC,IAAY,EAAW,EAAE;YAC/C,IAAI,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC;gBAAE,OAAO,KAAK,CAAC;YACzD,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YACf,OAAO,IAAI,CAAC;QAChB,CAAC,CAAC,CAAC;IACP,CAAC;IAED,gGAAgG;IACxF,QAAQ,CAAC,IAAY;QACzB,OAAO,CAAC,OAAe,EAAE,KAAc,EAAQ,EAAE;YAC7C,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC;YAC1C,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,UAAU,KAAK,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;QACjG,CAAC,CAAC;IACN,CAAC;CACJ,CAAA;AA3DY,4BAAQ;mBAAR,QAAQ;IADpB,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGA,6BAAc;QACrB,8BAAe;QAChB,2BAAY;GAJhC,QAAQ,CA2DpB","sourcesContent":["import * as fs from 'fs';\nimport * as path from 'path';\nimport {\n AgedTreeSweeper, DotWebpieces, RETENTION_DAYS, RepoRootFinder, SweepCount, dotWebpieces,\n} from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\n/**\n * 30-day garbage collection of this tree's `.webpieces` scratch state.\n *\n * Runs at the end of every merge/PR flow (see merge-end.ts). Any file older than the cutoff is deleted\n * and any directory left empty afterwards is pruned; the root itself is never removed.\n *\n * Everything the tooling still needs is rewritten on each run under a fresh mtime (instruct-ai/ docs,\n * the active logs, the *-status.json state files), and every writer `mkdirSync(..., { recursive: true })`s\n * its target first — so pruning a stale home dir is harmless; the next write recreates it.\n *\n * The roots are the two PER-WORKTREE scopes — `DotWebpieces.local()` and `DotWebpieces.aiWritable()` —\n * which are one and the same directory in the primary clone and two in a linked worktree (see\n * `aiWritable()` for why `pr-review/` has to sit in the worktree). The repo-wide `shared()` dir is never\n * swept: its entries belong to every worktree at once.\n * This used to sweep a second, machine-global root (`~/.webpieces/prs/...`, which survived `rm -rf <clone>`\n * and so had no other owner). That store is gone — the gated merge body is the PR's own description now —\n * and with it the only artifact webpieces ever wrote outside a repo. See\n * `decisions/0005-the-pr-description-is-the-merge-body.md`.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class CleanTmp {\n constructor(\n private readonly repoRootFinder: RepoRootFinder,\n private readonly sweeper: AgedTreeSweeper,\n private readonly dotDir: DotWebpieces = dotWebpieces,\n ) {}\n\n async cleanTmp(): Promise<void> {\n const repoRoot = this.repoRootFinder.resolveRepoRoot(process.cwd());\n // The two per-worktree scopes, and only those. It must never sweep the repo-wide dir, whose\n // entries (merged-branches.json, the main-sync status and its lock) belong to every worktree at\n // once. In the primary clone these collapse to the same path and it is swept once.\n // local() — merge-info/, instruct-ai/, logs/ in <primary>/.webpieces/worktrees/<name>\n // aiWritable() — pr-review/ in <worktree>/.webpieces, where the agent can actually write it\n const bases = this.sweepBases(repoRoot);\n if (bases.length === 0) return;\n\n process.stdout.write('\\n' + SEP + '🧹 Garbage-Collecting .webpieces\\n' + SEP + '\\n');\n for (const base of bases) process.stdout.write(`Location: ${base}\\n`);\n process.stdout.write(`Retention: ${RETENTION_DAYS} days (older files reaped; empty dirs pruned)\\n\\n`);\n\n const cutoffMs = RETENTION_DAYS * 24 * 60 * 60 * 1000;\n const total = new SweepCount();\n for (const base of bases) total.add(this.sweeper.sweep(base, cutoffMs, this.reporter(base)));\n\n if (total.empty) {\n process.stdout.write(` ✅ Nothing older than ${RETENTION_DAYS} days; no empty directories\\n`);\n } else {\n const fileWord = total.files === 1 ? 'file' : 'files';\n const dirWord = total.dirs === 1 ? 'directory' : 'directories';\n process.stdout.write(`\\n ✅ Reaped ${total.files} old ${fileWord} and pruned ${total.dirs} empty ${dirWord}\\n`);\n }\n\n process.stdout.write('\\n' + SEP + '\\n');\n }\n\n /**\n * The per-worktree roots that exist, de-duplicated. `local()` and `aiWritable()` are the SAME path\n * in the primary clone — sweeping it twice would double-count and print every removal twice — and\n * two different paths in a linked worktree, where BOTH need reaping or `pr-review/` accumulates in\n * the worktree forever.\n */\n private sweepBases(repoRoot: string): string[] {\n const candidates = [this.dotDir.local(repoRoot), this.dotDir.aiWritable(repoRoot)];\n const seen = new Set<string>();\n return candidates.filter((base: string): boolean => {\n if (seen.has(base) || !fs.existsSync(base)) return false;\n seen.add(base);\n return true;\n });\n }\n\n // One line per removal, relative to the root it came from, so the two roots read as one report.\n private reporter(base: string): (removed: string, isDir: boolean) => void {\n return (removed: string, isDir: boolean): void => {\n const label = isDir ? 'dir: ' : 'file: ';\n process.stdout.write(` 🗑️ ${label} ${path.relative(base, removed)}${isDir ? '/' : ''}\\n`);\n };\n }\n}\n"]}
1
+ {"version":3,"file":"cleanTmp.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/cleanTmp.ts"],"names":[],"mappings":";;;;AAAA,+CAAyB;AACzB,mDAA6B;AAC7B,0DAGiC;AACjC,yCAA2D;AAE3D,MAAM,GAAG,GAAG,0DAA0D,CAAC;AAEvE;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEI,IAAM,QAAQ,GAAd,MAAM,QAAQ;IAEI;IACA;IACA;IACA;IAJrB,YACqB,cAA8B,EAC9B,OAAwB,EACxB,UAA6B,EAC7B,SAAuB,2BAAY;QAHnC,mBAAc,GAAd,c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,OAAO,IAAI,CAAC;QAChB,CAAC,CAAC,CAAC;IACP,CAAC;IAED,gGAAgG;IACxF,QAAQ,CAAC,IAAY;QACzB,OAAO,CAAC,OAAe,EAAE,KAAc,EAAQ,EAAE;YAC7C,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC;YAC1C,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,UAAU,KAAK,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;QACjG,CAAC,CAAC;IACN,CAAC;CACJ,CAAA;AAnEY,4BAAQ;mBAAR,QAAQ;IADpB,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGA,6BAAc;QACrB,8BAAe;QACZ,gCAAiB;QACrB,2BAAY;GALhC,QAAQ,CAmEpB","sourcesContent":["import * as fs from 'fs';\nimport * as path from 'path';\nimport {\n AgedTreeSweeper, DotWebpieces, RETENTION_DAYS, RepoRootFinder, SweepCount,\n TMP_SCRATCH_RETENTION_DAYS, TmpScratchSweeper, dotWebpieces,\n} from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\n/**\n * 30-day garbage collection of this tree's `.webpieces` scratch state.\n *\n * Runs at the end of every merge/PR flow (see merge-end.ts). Any file older than the cutoff is deleted\n * and any directory left empty afterwards is pruned; the root itself is never removed.\n *\n * Everything the tooling still needs is rewritten on each run under a fresh mtime (instruct-ai/ docs,\n * the active logs, the *-status.json state files), and every writer `mkdirSync(..., { recursive: true })`s\n * its target first — so pruning a stale home dir is harmless; the next write recreates it.\n *\n * The roots are the two PER-WORKTREE scopes — `DotWebpieces.local()` and `DotWebpieces.aiWritable()` —\n * which are one and the same directory in the primary clone and two in a linked worktree (see\n * `aiWritable()` for why `pr-review/` has to sit in the worktree). The repo-wide `shared()` dir is never\n * swept: its entries belong to every worktree at once.\n * This used to sweep a second, machine-global root (`~/.webpieces/prs/...`, which survived `rm -rf <clone>`\n * and so had no other owner). That store is gone — the gated merge body is the PR's own description now.\n * See `decisions/0005-the-pr-description-is-the-merge-body.md`.\n *\n * ─── That removal came with a claim that was false, and this is the correction ─────────────────────\n * This docblock used to end \"and with it the only artifact webpieces ever wrote outside a repo\". It was\n * not: every `packages/tooling/**` spec mints its fixture with `fs.mkdtempSync(os.tmpdir(), 'wp-...')`,\n * and so did two runtime paths. Nothing reaped any of them, and because THIS comment asserted there was\n * nothing out there to reap, nobody went looking. Measured on one developer machine: 270,200 abandoned\n * `wp-*` directories in `$TMPDIR`.\n *\n * The fix is ownership at the call site — `SpecTempDirs` for fixtures, `RepoScratchDirs` (which lands\n * under the `.webpieces` scope swept below) for the two runtime paths. `TmpScratchSweeper` is the\n * backstop for the residue an exit handler cannot cover: a SIGKILLed worker, a lost power rail.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class CleanTmp {\n constructor(\n private readonly repoRootFinder: RepoRootFinder,\n private readonly sweeper: AgedTreeSweeper,\n private readonly tmpSweeper: TmpScratchSweeper,\n private readonly dotDir: DotWebpieces = dotWebpieces,\n ) {}\n\n async cleanTmp(): Promise<void> {\n const repoRoot = this.repoRootFinder.resolveRepoRoot(process.cwd());\n // The two per-worktree scopes, and only those. It must never sweep the repo-wide dir, whose\n // entries (merged-branches.json, the main-sync status and its lock) belong to every worktree at\n // once. In the primary clone these collapse to the same path and it is swept once.\n // local() — merge-info/, instruct-ai/, logs/ in <primary>/.webpieces/worktrees/<name>\n // aiWritable() — pr-review/ in <worktree>/.webpieces, where the agent can actually write it\n const bases = this.sweepBases(repoRoot);\n if (bases.length === 0) return;\n\n process.stdout.write('\\n' + SEP + '🧹 Garbage-Collecting .webpieces\\n' + SEP + '\\n');\n for (const base of bases) process.stdout.write(`Location: ${base}\\n`);\n process.stdout.write(`Retention: ${RETENTION_DAYS} days (older files reaped; empty dirs pruned)\\n\\n`);\n\n const cutoffMs = RETENTION_DAYS * 24 * 60 * 60 * 1000;\n const total = new SweepCount();\n for (const base of bases) total.add(this.sweeper.sweep(base, cutoffMs, this.reporter(base)));\n\n // The `$TMPDIR` backstop. Counted into the same total so one line reports one cleanup, and run\n // last because it is the only part that touches a directory webpieces does not own.\n const tmpCutoffMs = TMP_SCRATCH_RETENTION_DAYS * 24 * 60 * 60 * 1000;\n total.add(this.tmpSweeper.sweep(tmpCutoffMs, (removed: string): void => {\n process.stdout.write(` 🗑️ dir: ${removed}/\\n`);\n }));\n\n if (total.empty) {\n process.stdout.write(` ✅ Nothing older than ${RETENTION_DAYS} days; no empty directories\\n`);\n } else {\n const fileWord = total.files === 1 ? 'file' : 'files';\n const dirWord = total.dirs === 1 ? 'directory' : 'directories';\n process.stdout.write(`\\n ✅ Reaped ${total.files} old ${fileWord} and pruned ${total.dirs} empty ${dirWord}\\n`);\n }\n\n process.stdout.write('\\n' + SEP + '\\n');\n }\n\n /**\n * The per-worktree roots that exist, de-duplicated. `local()` and `aiWritable()` are the SAME path\n * in the primary clone — sweeping it twice would double-count and print every removal twice — and\n * two different paths in a linked worktree, where BOTH need reaping or `pr-review/` accumulates in\n * the worktree forever.\n */\n private sweepBases(repoRoot: string): string[] {\n const candidates = [this.dotDir.local(repoRoot), this.dotDir.aiWritable(repoRoot)];\n const seen = new Set<string>();\n return candidates.filter((base: string): boolean => {\n if (seen.has(base) || !fs.existsSync(base)) return false;\n seen.add(base);\n return true;\n });\n }\n\n // One line per removal, relative to the root it came from, so the two roots read as one report.\n private reporter(base: string): (removed: string, isDir: boolean) => void {\n return (removed: string, isDir: boolean): void => {\n const label = isDir ? 'dir: ' : 'file: ';\n process.stdout.write(` 🗑️ ${label} ${path.relative(base, removed)}${isDir ? '/' : ''}\\n`);\n };\n }\n}\n"]}
@@ -1,3 +1,4 @@
1
+ import { RepoScratchDirs } from '@webpieces/rules-config';
1
2
  /**
2
3
  * Where the "known generated" answer came from, so a failure message can say whether it is speaking
3
4
  * from the workspace's own declarations or from the built-in fallback.
@@ -39,7 +40,9 @@ export declare class GeneratedArtifacts {
39
40
  * and such targets write into `dist/`, which is gitignored and therefore invisible to this gate anyway.
40
41
  */
41
42
  export declare class GeneratedArtifactRegistry {
43
+ private readonly scratchDirs;
42
44
  private cached;
45
+ constructor(scratchDirs: RepoScratchDirs);
43
46
  /** The declared build outputs for this repo, from nx when readable and the fallback table otherwise. */
44
47
  resolve(repoRoot: string): GeneratedArtifacts;
45
48
  /** Test seam: pre-seed the resolved set so specs never shell out to nx. */
@@ -4,7 +4,6 @@ exports.GeneratedArtifactRegistry = exports.GeneratedArtifacts = exports.FALLBAC
4
4
  const tslib_1 = require("tslib");
5
5
  const child_process_1 = require("child_process");
6
6
  const fs = tslib_1.__importStar(require("fs"));
7
- const os = tslib_1.__importStar(require("os"));
8
7
  const path = tslib_1.__importStar(require("path"));
9
8
  const rules_config_1 = require("@webpieces/rules-config");
10
9
  const inversify_1 = require("inversify");
@@ -61,8 +60,12 @@ exports.GeneratedArtifacts = GeneratedArtifacts;
61
60
  * and such targets write into `dist/`, which is gitignored and therefore invisible to this gate anyway.
62
61
  */
63
62
  let GeneratedArtifactRegistry = class GeneratedArtifactRegistry {
63
+ scratchDirs;
64
64
  // Resolved once per process: the graph does not change while one PR-gate command runs.
65
65
  cached = null;
66
+ constructor(scratchDirs) {
67
+ this.scratchDirs = scratchDirs;
68
+ }
66
69
  /** The declared build outputs for this repo, from nx when readable and the fallback table otherwise. */
67
70
  resolve(repoRoot) {
68
71
  if (this.cached !== null)
@@ -86,7 +89,7 @@ let GeneratedArtifactRegistry = class GeneratedArtifactRegistry {
86
89
  const nxBin = path.join(repoRoot, 'node_modules', '.bin', 'nx');
87
90
  if (!fs.existsSync(nxBin))
88
91
  return null;
89
- const outFile = path.join(fs.mkdtempSync(path.join(os.tmpdir(), 'wp-nxgraph-')), 'graph.json');
92
+ const outFile = path.join(this.scratchDirs.make(repoRoot, 'wp-nxgraph-'), 'graph.json');
90
93
  const run = (0, child_process_1.spawnSync)(nxBin, ['graph', '--file', outFile], { cwd: repoRoot, encoding: 'utf8', stdio: 'pipe' });
91
94
  if (run.status !== 0 || !fs.existsSync(outFile))
92
95
  return null;
@@ -143,6 +146,7 @@ let GeneratedArtifactRegistry = class GeneratedArtifactRegistry {
143
146
  };
144
147
  exports.GeneratedArtifactRegistry = GeneratedArtifactRegistry;
145
148
  exports.GeneratedArtifactRegistry = GeneratedArtifactRegistry = tslib_1.__decorate([
146
- (0, inversify_1.injectable)(inversify_1.bindingScopeValues.Singleton)
149
+ (0, inversify_1.injectable)(inversify_1.bindingScopeValues.Singleton),
150
+ tslib_1.__metadata("design:paramtypes", [rules_config_1.RepoScratchDirs])
147
151
  ], GeneratedArtifactRegistry);
148
152
  //# sourceMappingURL=generated-artifact-registry.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"generated-artifact-registry.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/generated-artifact-registry.ts"],"names":[],"mappings":";;;;AAAA,iDAA0C;AAC1C,+CAAyB;AACzB,+CAAyB;AACzB,mDAA6B;AAC7B,0DAAkD;AAClD,yCAA2D;AAE3D;;;GAGG;AACU,QAAA,kBAAkB,GAAG,qCAAqC,CAAC;AAC3D,QAAA,wBAAwB,GAAG,kDAAkD,CAAC;AAE3F;;;;;;;;;GASG;AACU,QAAA,wBAAwB,GAAsB;IACvD,gBAAgB;IAChB,cAAc;IACd,gBAAgB;IAChB,gCAAgC;IAChC,gCAAgC;IAChC,mBAAmB;IACnB,wCAAwC;CAC3C,CAAC;AAEF;;;GAGG;AACH,MAAa,kBAAkB;IAC3B,KAAK,CAAW;IAChB,MAAM,CAAS;IAEf,YAAY,KAAe,EAAE,MAAc;QACvC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IA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AAE,CAAC;gBAC5C,KAAK,MAAM,GAAG,IAAI,OAAO,CAAC,UAAU,CAAC,CAAC,OAAO,IAAI,EAAE,EAAE,CAAC;oBAClD,MAAM,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,IAAI,GAAG,CAAC,CAAC;oBACpD,IAAI,QAAQ,KAAK,IAAI;wBAAE,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;gBAC/C,CAAC;YACL,CAAC;QACL,CAAC;QACD,OAAO,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,CAAC;IACpC,CAAC;IAED,oGAAoG;IAC5F,MAAM,CAAC,GAAW,EAAE,WAAmB;QAC3C,MAAM,QAAQ,GAAG,GAAG;aACf,OAAO,CAAC,kBAAkB,EAAE,WAAW,CAAC;aACxC,OAAO,CAAC,sBAAsB,EAAE,EAAE,CAAC;aACnC,OAAO,CAAC,oBAAoB,EAAE,GAAG,CAAC,CAAC;QACxC,IAAI,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC;YAAE,OAAO,IAAI,CAAC;QACxC,MAAM,UAAU,GAAG,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;QACrE,OAAO,UAAU,KAAK,EAAE,IAAI,UAAU,KAAK,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC;IACvE,CAAC;CACJ,CAAA;AA9EY,8DAAyB;oCAAzB,yBAAyB;IADrC,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;GAC5B,yBAAyB,CA8ErC","sourcesContent":["import { spawnSync } from 'child_process';\nimport * as fs from 'fs';\nimport * as os from 'os';\nimport * as path from 'path';\nimport { toError } from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\n\n/**\n * Where the \"known generated\" answer came from, so a failure message can say whether it is speaking\n * from the workspace's own declarations or from the built-in fallback.\n */\nexport const ARTIFACT_SOURCE_NX = 'nx project graph (target `outputs`)';\nexport const ARTIFACT_SOURCE_FALLBACK = 'built-in fallback (nx project graph unavailable)';\n\n/**\n * The fallback \"known generated\" set, used ONLY when the nx project graph cannot be read (nx not\n * installed, `nx graph` failed, unparseable output). It deliberately mirrors what the webpieces nx\n * plugin declares as `outputs` today — `di-graph-generate` writes design.{json,md,html} per project\n * and the architecture targets write architecture/*.\n *\n * It is a fallback and not the primary source precisely because a hand-maintained list drifts: the\n * moment a repo adds a target that writes a new committed artifact, only the nx `outputs` declaration\n * knows about it. Data (a module-level table), not a list buried inside a function.\n */\nexport const FALLBACK_GENERATED_PATHS: readonly string[] = [\n '**/design.json',\n '**/design.md',\n '**/design.html',\n 'architecture/dependencies.json',\n 'architecture/dependencies.html',\n 'architecture/apis',\n 'architecture/runtime-dependencies.json',\n];\n\n/**\n * The set of repo-relative paths/globs that a build is EXPECTED to rewrite, plus where the set came\n * from. Data-only (per CLAUDE.md) — the resolution logic lives in GeneratedArtifactRegistry.\n */\nexport class GeneratedArtifacts {\n paths: string[];\n source: string;\n\n constructor(paths: string[], source: string) {\n this.paths = paths;\n this.source = source;\n }\n}\n\n/**\n * Answers \"is this path something the build is SUPPOSED to rewrite?\" from the workspace's own nx\n * target `outputs` declarations rather than from a parallel list maintained by hand.\n *\n * Why nx `outputs`: every target that writes a checked-in artifact already has to declare it there or\n * nx caching corrupts the workspace, so the declaration is load-bearing and therefore maintained. A\n * second list in the PR gate would be maintained by nobody and would drift the first time a repo adds\n * a generator. One `nx graph --file=<tmp>` dumps the whole workspace (every project, every target,\n * every `outputs` entry) in one ~2s call, so this costs one subprocess per PR-gate run.\n *\n * Tokens: `{projectRoot}` and `{workspaceRoot}` are expanded; anything still holding a `{...}` token\n * (`{options.outputPath}`, `{options.outputFile}`) is DROPPED — it is only resolvable per-invocation,\n * and such targets write into `dist/`, which is gitignored and therefore invisible to this gate anyway.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class GeneratedArtifactRegistry {\n // Resolved once per process: the graph does not change while one PR-gate command runs.\n private cached: GeneratedArtifacts | null = null;\n\n /** The declared build outputs for this repo, from nx when readable and the fallback table otherwise. */\n resolve(repoRoot: string): GeneratedArtifacts {\n if (this.cached !== null) return this.cached;\n const fromNx = this.readNxOutputs(repoRoot);\n this.cached = fromNx !== null\n ? new GeneratedArtifacts(fromNx, ARTIFACT_SOURCE_NX)\n : new GeneratedArtifacts(FALLBACK_GENERATED_PATHS.slice(), ARTIFACT_SOURCE_FALLBACK);\n return this.cached;\n }\n\n /** Test seam: pre-seed the resolved set so specs never shell out to nx. */\n seed(artifacts: GeneratedArtifacts): void {\n this.cached = artifacts;\n }\n\n /**\n * Dump the nx project graph to a temp file and collect every target's `outputs`. Returns null (not\n * an empty list) when nx is unavailable or unreadable, so the caller can tell \"no nx\" apart from\n * \"nx says this workspace declares nothing\".\n */\n private readNxOutputs(repoRoot: string): string[] | null {\n const nxBin = path.join(repoRoot, 'node_modules', '.bin', 'nx');\n if (!fs.existsSync(nxBin)) return null;\n const outFile = path.join(fs.mkdtempSync(path.join(os.tmpdir(), 'wp-nxgraph-')), 'graph.json');\n const run = spawnSync(nxBin, ['graph', '--file', outFile], { cwd: repoRoot, encoding: 'utf8', stdio: 'pipe' });\n if (run.status !== 0 || !fs.existsSync(outFile)) return null;\n return this.parseGraph(outFile);\n }\n\n /** Read + narrow the dumped graph. Null on anything unreadable, so the caller falls back. */\n private parseGraph(outFile: string): string[] | null {\n // webpieces-disable no-unmanaged-exceptions -- chokepoint: an unreadable/corrupt graph dump must\n // fall back to the built-in table, never fail a PR flow over a cache artifact we only consult\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n // webpieces-disable no-any-unknown -- opaque nx JSON, narrowed field by field below\n const parsed = JSON.parse(fs.readFileSync(outFile, 'utf8')) as NxGraphFile;\n const nodes = parsed.graph?.nodes;\n if (nodes === undefined) return null;\n return this.collectOutputs(nodes);\n } catch (err: unknown) {\n const error = toError(err);\n void error; // unreadable graph => fall back to the built-in table\n return null;\n }\n }\n\n /** Walk every project → every target → every `outputs` entry, expanding the nx path tokens. */\n private collectOutputs(nodes: Record<string, NxGraphNode>): string[] {\n const found = new Set<string>();\n for (const projectName of Object.keys(nodes)) {\n const data = nodes[projectName].data;\n const targets = data.targets;\n if (targets === undefined) continue;\n for (const targetName of Object.keys(targets)) {\n for (const raw of targets[targetName].outputs ?? []) {\n const expanded = this.expand(raw, data.root ?? '.');\n if (expanded !== null) found.add(expanded);\n }\n }\n }\n return Array.from(found).sort();\n }\n\n /** Expand `{projectRoot}` / `{workspaceRoot}`; drop anything still carrying an unresolved token. */\n private expand(raw: string, projectRoot: string): string | null {\n const replaced = raw\n .replace(/\\{projectRoot\\}/g, projectRoot)\n .replace(/\\{workspaceRoot\\}\\//g, '')\n .replace(/\\{workspaceRoot\\}/g, '.');\n if (replaced.includes('{')) return null;\n const normalized = replaced.replace(/\\\\/g, '/').replace(/^\\.\\//, '');\n return normalized === '' || normalized === '.' ? null : normalized;\n }\n}\n\n// Structural views of the `nx graph --file=<json>` payload. Interfaces (not classes) on purpose: these\n// describe a foreign JSON shape we narrow, never something this codebase constructs.\ninterface NxGraphFile {\n graph?: NxGraphBody;\n}\n\ninterface NxGraphBody {\n nodes?: Record<string, NxGraphNode>;\n}\n\ninterface NxGraphNode {\n data: NxProjectData;\n}\n\ninterface NxProjectData {\n root?: string;\n targets?: Record<string, NxTarget>;\n}\n\ninterface NxTarget {\n outputs?: string[];\n}\n"]}
1
+ {"version":3,"file":"generated-artifact-registry.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/generated-artifact-registry.ts"],"names":[],"mappings":";;;;AAAA,iDAA0C;AAC1C,+CAAyB;AACzB,mDAA6B;AAC7B,0DAAmE;AACnE,yCAA2D;AAE3D;;;GAGG;AACU,QAAA,kBAAkB,GAAG,qCAAqC,CAAC;AAC3D,QAA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,EAAE,IAAI,UAAU,KAAK,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC;IACvE,CAAC;CACJ,CAAA;AAhFY,8DAAyB;oCAAzB,yBAAyB;IADrC,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAKK,8BAAe;GAJhD,yBAAyB,CAgFrC","sourcesContent":["import { spawnSync } from 'child_process';\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport { RepoScratchDirs, toError } from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\n\n/**\n * Where the \"known generated\" answer came from, so a failure message can say whether it is speaking\n * from the workspace's own declarations or from the built-in fallback.\n */\nexport const ARTIFACT_SOURCE_NX = 'nx project graph (target `outputs`)';\nexport const ARTIFACT_SOURCE_FALLBACK = 'built-in fallback (nx project graph unavailable)';\n\n/**\n * The fallback \"known generated\" set, used ONLY when the nx project graph cannot be read (nx not\n * installed, `nx graph` failed, unparseable output). It deliberately mirrors what the webpieces nx\n * plugin declares as `outputs` today — `di-graph-generate` writes design.{json,md,html} per project\n * and the architecture targets write architecture/*.\n *\n * It is a fallback and not the primary source precisely because a hand-maintained list drifts: the\n * moment a repo adds a target that writes a new committed artifact, only the nx `outputs` declaration\n * knows about it. Data (a module-level table), not a list buried inside a function.\n */\nexport const FALLBACK_GENERATED_PATHS: readonly string[] = [\n '**/design.json',\n '**/design.md',\n '**/design.html',\n 'architecture/dependencies.json',\n 'architecture/dependencies.html',\n 'architecture/apis',\n 'architecture/runtime-dependencies.json',\n];\n\n/**\n * The set of repo-relative paths/globs that a build is EXPECTED to rewrite, plus where the set came\n * from. Data-only (per CLAUDE.md) — the resolution logic lives in GeneratedArtifactRegistry.\n */\nexport class GeneratedArtifacts {\n paths: string[];\n source: string;\n\n constructor(paths: string[], source: string) {\n this.paths = paths;\n this.source = source;\n }\n}\n\n/**\n * Answers \"is this path something the build is SUPPOSED to rewrite?\" from the workspace's own nx\n * target `outputs` declarations rather than from a parallel list maintained by hand.\n *\n * Why nx `outputs`: every target that writes a checked-in artifact already has to declare it there or\n * nx caching corrupts the workspace, so the declaration is load-bearing and therefore maintained. A\n * second list in the PR gate would be maintained by nobody and would drift the first time a repo adds\n * a generator. One `nx graph --file=<tmp>` dumps the whole workspace (every project, every target,\n * every `outputs` entry) in one ~2s call, so this costs one subprocess per PR-gate run.\n *\n * Tokens: `{projectRoot}` and `{workspaceRoot}` are expanded; anything still holding a `{...}` token\n * (`{options.outputPath}`, `{options.outputFile}`) is DROPPED — it is only resolvable per-invocation,\n * and such targets write into `dist/`, which is gitignored and therefore invisible to this gate anyway.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class GeneratedArtifactRegistry {\n // Resolved once per process: the graph does not change while one PR-gate command runs.\n private cached: GeneratedArtifacts | null = null;\n\n constructor(private readonly scratchDirs: RepoScratchDirs) {}\n\n /** The declared build outputs for this repo, from nx when readable and the fallback table otherwise. */\n resolve(repoRoot: string): GeneratedArtifacts {\n if (this.cached !== null) return this.cached;\n const fromNx = this.readNxOutputs(repoRoot);\n this.cached = fromNx !== null\n ? new GeneratedArtifacts(fromNx, ARTIFACT_SOURCE_NX)\n : new GeneratedArtifacts(FALLBACK_GENERATED_PATHS.slice(), ARTIFACT_SOURCE_FALLBACK);\n return this.cached;\n }\n\n /** Test seam: pre-seed the resolved set so specs never shell out to nx. */\n seed(artifacts: GeneratedArtifacts): void {\n this.cached = artifacts;\n }\n\n /**\n * Dump the nx project graph to a temp file and collect every target's `outputs`. Returns null (not\n * an empty list) when nx is unavailable or unreadable, so the caller can tell \"no nx\" apart from\n * \"nx says this workspace declares nothing\".\n */\n private readNxOutputs(repoRoot: string): string[] | null {\n const nxBin = path.join(repoRoot, 'node_modules', '.bin', 'nx');\n if (!fs.existsSync(nxBin)) return null;\n const outFile = path.join(this.scratchDirs.make(repoRoot, 'wp-nxgraph-'), 'graph.json');\n const run = spawnSync(nxBin, ['graph', '--file', outFile], { cwd: repoRoot, encoding: 'utf8', stdio: 'pipe' });\n if (run.status !== 0 || !fs.existsSync(outFile)) return null;\n return this.parseGraph(outFile);\n }\n\n /** Read + narrow the dumped graph. Null on anything unreadable, so the caller falls back. */\n private parseGraph(outFile: string): string[] | null {\n // webpieces-disable no-unmanaged-exceptions -- chokepoint: an unreadable/corrupt graph dump must\n // fall back to the built-in table, never fail a PR flow over a cache artifact we only consult\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n // webpieces-disable no-any-unknown -- opaque nx JSON, narrowed field by field below\n const parsed = JSON.parse(fs.readFileSync(outFile, 'utf8')) as NxGraphFile;\n const nodes = parsed.graph?.nodes;\n if (nodes === undefined) return null;\n return this.collectOutputs(nodes);\n } catch (err: unknown) {\n const error = toError(err);\n void error; // unreadable graph => fall back to the built-in table\n return null;\n }\n }\n\n /** Walk every project → every target → every `outputs` entry, expanding the nx path tokens. */\n private collectOutputs(nodes: Record<string, NxGraphNode>): string[] {\n const found = new Set<string>();\n for (const projectName of Object.keys(nodes)) {\n const data = nodes[projectName].data;\n const targets = data.targets;\n if (targets === undefined) continue;\n for (const targetName of Object.keys(targets)) {\n for (const raw of targets[targetName].outputs ?? []) {\n const expanded = this.expand(raw, data.root ?? '.');\n if (expanded !== null) found.add(expanded);\n }\n }\n }\n return Array.from(found).sort();\n }\n\n /** Expand `{projectRoot}` / `{workspaceRoot}`; drop anything still carrying an unresolved token. */\n private expand(raw: string, projectRoot: string): string | null {\n const replaced = raw\n .replace(/\\{projectRoot\\}/g, projectRoot)\n .replace(/\\{workspaceRoot\\}\\//g, '')\n .replace(/\\{workspaceRoot\\}/g, '.');\n if (replaced.includes('{')) return null;\n const normalized = replaced.replace(/\\\\/g, '/').replace(/^\\.\\//, '');\n return normalized === '' || normalized === '.' ? null : normalized;\n }\n}\n\n// Structural views of the `nx graph --file=<json>` payload. Interfaces (not classes) on purpose: these\n// describe a foreign JSON shape we narrow, never something this codebase constructs.\ninterface NxGraphFile {\n graph?: NxGraphBody;\n}\n\ninterface NxGraphBody {\n nodes?: Record<string, NxGraphNode>;\n}\n\ninterface NxGraphNode {\n data: NxProjectData;\n}\n\ninterface NxProjectData {\n root?: string;\n targets?: Record<string, NxTarget>;\n}\n\ninterface NxTarget {\n outputs?: string[];\n}\n"]}
@@ -1,3 +1,4 @@
1
+ import { RepoRootFinder, RepoScratchDirs } from '@webpieces/rules-config';
1
2
  /** The filename inside the temp dir. Named, because it is what a human sees in a `gh` error. */
2
3
  export declare const MERGE_BODY_FILE = "merge-commit-body.md";
3
4
  /**
@@ -18,6 +19,9 @@ export declare const MERGE_BODY_FILE = "merge-commit-body.md";
18
19
  * `gh` invocation. See `decisions/0005-the-pr-description-is-the-merge-body.md`.
19
20
  */
20
21
  export declare class MergeBodyTempFile {
22
+ private readonly repoRootFinder;
23
+ private readonly scratchDirs;
24
+ constructor(repoRootFinder: RepoRootFinder, scratchDirs: RepoScratchDirs);
21
25
  /** @returns an absolute path to a file holding exactly `body`. Never ''. */
22
26
  write(body: string): string;
23
27
  }
@@ -3,9 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MergeBodyTempFile = exports.MERGE_BODY_FILE = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const fs = tslib_1.__importStar(require("fs"));
6
- const os = tslib_1.__importStar(require("os"));
7
6
  const path = tslib_1.__importStar(require("path"));
8
7
  const inversify_1 = require("inversify");
8
+ const rules_config_1 = require("@webpieces/rules-config");
9
9
  /** The filename inside the temp dir. Named, because it is what a human sees in a `gh` error. */
10
10
  exports.MERGE_BODY_FILE = 'merge-commit-body.md';
11
11
  /**
@@ -26,15 +26,24 @@ exports.MERGE_BODY_FILE = 'merge-commit-body.md';
26
26
  * `gh` invocation. See `decisions/0005-the-pr-description-is-the-merge-body.md`.
27
27
  */
28
28
  let MergeBodyTempFile = class MergeBodyTempFile {
29
+ repoRootFinder;
30
+ scratchDirs;
31
+ constructor(repoRootFinder, scratchDirs) {
32
+ this.repoRootFinder = repoRootFinder;
33
+ this.scratchDirs = scratchDirs;
34
+ }
29
35
  /** @returns an absolute path to a file holding exactly `body`. Never ''. */
30
36
  write(body) {
31
- const file = path.join(fs.mkdtempSync(path.join(os.tmpdir(), 'wp-merge-body-')), exports.MERGE_BODY_FILE);
37
+ const repoRoot = this.repoRootFinder.resolveRepoRoot(process.cwd());
38
+ const file = path.join(this.scratchDirs.make(repoRoot, 'wp-merge-body-'), exports.MERGE_BODY_FILE);
32
39
  fs.writeFileSync(file, body);
33
40
  return file;
34
41
  }
35
42
  };
36
43
  exports.MergeBodyTempFile = MergeBodyTempFile;
37
44
  exports.MergeBodyTempFile = MergeBodyTempFile = tslib_1.__decorate([
38
- (0, inversify_1.injectable)(inversify_1.bindingScopeValues.Singleton)
45
+ (0, inversify_1.injectable)(inversify_1.bindingScopeValues.Singleton),
46
+ tslib_1.__metadata("design:paramtypes", [rules_config_1.RepoRootFinder,
47
+ rules_config_1.RepoScratchDirs])
39
48
  ], MergeBodyTempFile);
40
49
  //# sourceMappingURL=merge-body-temp-file.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"merge-body-temp-file.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/merge-body-temp-file.ts"],"names":[],"mappings":";;;;AAAA,+CAAyB;AACzB,+CAAyB;AACzB,mDAA6B;AAC7B,yCAA2D;AAE3D,gGAAgG;AACnF,QAAA,eAAe,GAAG,sBAAsB,CAAC;AAEtD;;;;;;;;;;;;;;;;GAgBG;AAEI,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IAC1B,4EAA4E;IAC5E,KAAK,CAAC,IAAY;QACd,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,MAAM,EAAE,EAAE,gBAAgB,CAAC,CAAC,EAAE,uBAAe,CAAC,CAAC;QAClG,EAAE,CAAC,aAAa,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAC7B,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ,CAAA;AAPY,8CAAiB;4BAAjB,iBAAiB;IAD7B,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;GAC5B,iBAAiB,CAO7B","sourcesContent":["import * as fs from 'fs';\nimport * as os from 'os';\nimport * as path from 'path';\nimport { injectable, bindingScopeValues } from 'inversify';\n\n/** The filename inside the temp dir. Named, because it is what a human sees in a `gh` error. */\nexport const MERGE_BODY_FILE = 'merge-commit-body.md';\n\n/**\n * Writes the gated squash-commit body to a THROWAWAY file, because `gh pr merge --body-file` takes a\n * path and not a string. That is the entire job.\n *\n * ─── Why this is temp state and not a store ────────────────────────────────────────────────────────\n * It replaces `MergeBodyFiler`, which filed the same bytes under\n * `~/.webpieces/prs/<host>/<owner>/<repo>/<n>/merge-commit-body.md` so a later `wp-land-pr` could find\n * them. That store existed because the PR DESCRIPTION was a different (much longer) string from the\n * merge body, so the bytes finish produced lived nowhere else. Since the two surfaces were swapped —\n * the description IS the compact body, and the dashboard moved into the PR's comments — the durable\n * copy is the PR itself. A machine-global cache of a fact GitHub owns can only be missing, stale, or on\n * the wrong computer, and it was all three. `wp-land-pr` now reads `gh pr view --json body`.\n *\n * So both callers reach the same place from different directions: finish already holds the bytes it\n * just published, land reads them back from the PR, and each needs them on disk for the length of one\n * `gh` invocation. See `decisions/0005-the-pr-description-is-the-merge-body.md`.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class MergeBodyTempFile {\n /** @returns an absolute path to a file holding exactly `body`. Never ''. */\n write(body: string): string {\n const file = path.join(fs.mkdtempSync(path.join(os.tmpdir(), 'wp-merge-body-')), MERGE_BODY_FILE);\n fs.writeFileSync(file, body);\n return file;\n }\n}\n"]}
1
+ {"version":3,"file":"merge-body-temp-file.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/merge-body-temp-file.ts"],"names":[],"mappings":";;;;AAAA,+CAAyB;AACzB,mDAA6B;AAC7B,yCAA2D;AAC3D,0DAA0E;AAE1E,gGAAgG;AACnF,QAAA,eAAe,GAAG,sBAAsB,CAAC;AAEtD;;;;;;;;;;;;;;;;GAgBG;AAEI,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IAEL;IACA;IAFrB,YACqB,cAA8B,EAC9B,WAA4B;QAD5B,mBAAc,GAAd,cAAc,CAAgB;QAC9B,gBAAW,GAAX,WAAW,CAAiB;IAC9C,CAAC;IAEJ,4EAA4E;IAC5E,KAAK,CAAC,IAAY;QACd,MAAM,QAAQ,GAAG,IAAI,CAAC,cAAc,CAAC,eAAe,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;QACpE,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,QAAQ,EAAE,gBAAgB,CAAC,EAAE,uBAAe,CAAC,CAAC;QAC3F,EAAE,CAAC,aAAa,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAC7B,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ,CAAA;AAbY,8CAAiB;4BAAjB,iBAAiB;IAD7B,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGA,6BAAc;QACjB,8BAAe;GAHxC,iBAAiB,CAa7B","sourcesContent":["import * as fs from 'fs';\nimport * as path from 'path';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { RepoRootFinder, RepoScratchDirs } from '@webpieces/rules-config';\n\n/** The filename inside the temp dir. Named, because it is what a human sees in a `gh` error. */\nexport const MERGE_BODY_FILE = 'merge-commit-body.md';\n\n/**\n * Writes the gated squash-commit body to a THROWAWAY file, because `gh pr merge --body-file` takes a\n * path and not a string. That is the entire job.\n *\n * ─── Why this is temp state and not a store ────────────────────────────────────────────────────────\n * It replaces `MergeBodyFiler`, which filed the same bytes under\n * `~/.webpieces/prs/<host>/<owner>/<repo>/<n>/merge-commit-body.md` so a later `wp-land-pr` could find\n * them. That store existed because the PR DESCRIPTION was a different (much longer) string from the\n * merge body, so the bytes finish produced lived nowhere else. Since the two surfaces were swapped —\n * the description IS the compact body, and the dashboard moved into the PR's comments — the durable\n * copy is the PR itself. A machine-global cache of a fact GitHub owns can only be missing, stale, or on\n * the wrong computer, and it was all three. `wp-land-pr` now reads `gh pr view --json body`.\n *\n * So both callers reach the same place from different directions: finish already holds the bytes it\n * just published, land reads them back from the PR, and each needs them on disk for the length of one\n * `gh` invocation. See `decisions/0005-the-pr-description-is-the-merge-body.md`.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class MergeBodyTempFile {\n constructor(\n private readonly repoRootFinder: RepoRootFinder,\n private readonly scratchDirs: RepoScratchDirs,\n ) {}\n\n /** @returns an absolute path to a file holding exactly `body`. Never ''. */\n write(body: string): string {\n const repoRoot = this.repoRootFinder.resolveRepoRoot(process.cwd());\n const file = path.join(this.scratchDirs.make(repoRoot, 'wp-merge-body-'), MERGE_BODY_FILE);\n fs.writeFileSync(file, body);\n return file;\n }\n}\n"]}