@webpieces/pr-gate 0.4.975 → 0.4.977
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 +6 -6
- package/src/scripts/commands/await-checks-command.d.ts +6 -3
- package/src/scripts/commands/await-checks-command.js +17 -12
- package/src/scripts/commands/await-checks-command.js.map +1 -1
- package/src/scripts/commands/await-reviews-command.d.ts +1 -1
- package/src/scripts/commands/await-reviews-command.js +3 -3
- package/src/scripts/commands/await-reviews-command.js.map +1 -1
- package/src/scripts/commands/check-pr-command.d.ts +3 -1
- package/src/scripts/commands/check-pr-command.js +12 -9
- package/src/scripts/commands/check-pr-command.js.map +1 -1
- package/src/scripts/commands/cleanup-command.js +12 -12
- package/src/scripts/commands/cleanup-command.js.map +1 -1
- package/src/scripts/commands/finish-push-dev-command.js +3 -4
- package/src/scripts/commands/finish-push-dev-command.js.map +1 -1
- package/src/scripts/commands/finish-update-command.js +1 -1
- package/src/scripts/commands/finish-update-command.js.map +1 -1
- package/src/scripts/commands/finish-upsert-pr-command.d.ts +4 -1
- package/src/scripts/commands/finish-upsert-pr-command.js +65 -62
- package/src/scripts/commands/finish-upsert-pr-command.js.map +1 -1
- package/src/scripts/commands/human-post-pr-command.d.ts +8 -6
- package/src/scripts/commands/human-post-pr-command.js +33 -32
- package/src/scripts/commands/human-post-pr-command.js.map +1 -1
- package/src/scripts/commands/land-pr-command.d.ts +5 -1
- package/src/scripts/commands/land-pr-command.js +37 -23
- package/src/scripts/commands/land-pr-command.js.map +1 -1
- package/src/scripts/commands/main-checkout.d.ts +4 -1
- package/src/scripts/commands/main-checkout.js +22 -22
- package/src/scripts/commands/main-checkout.js.map +1 -1
- package/src/scripts/commands/push-dev-command.js +28 -29
- package/src/scripts/commands/push-dev-command.js.map +1 -1
- package/src/scripts/commands/reap-worktree-command.js +4 -5
- package/src/scripts/commands/reap-worktree-command.js.map +1 -1
- package/src/scripts/commands/review-upsert-pr-command.js +10 -10
- package/src/scripts/commands/review-upsert-pr-command.js.map +1 -1
- package/src/scripts/commands/start-update-command.d.ts +1 -1
- package/src/scripts/commands/start-update-command.js +3 -3
- package/src/scripts/commands/start-update-command.js.map +1 -1
- package/src/scripts/commands/start-upsert-pr-command.js +4 -4
- package/src/scripts/commands/start-upsert-pr-command.js.map +1 -1
- package/src/scripts/commands/sync-main-command.js +6 -6
- package/src/scripts/commands/sync-main-command.js.map +1 -1
- package/src/scripts/commands/upsert-hotfix-pr-command.d.ts +6 -4
- package/src/scripts/commands/upsert-hotfix-pr-command.js +46 -43
- package/src/scripts/commands/upsert-hotfix-pr-command.js.map +1 -1
- package/src/scripts/commands/working-tree-gate.d.ts +4 -1
- package/src/scripts/commands/working-tree-gate.js +14 -11
- package/src/scripts/commands/working-tree-gate.js.map +1 -1
- package/src/scripts/commands/worktree-cleanup.d.ts +4 -4
- package/src/scripts/commands/worktree-cleanup.js +4 -4
- package/src/scripts/commands/worktree-cleanup.js.map +1 -1
- package/src/scripts/commands/write-review-command.js +4 -6
- package/src/scripts/commands/write-review-command.js.map +1 -1
- package/src/scripts/commands/write-review-fixes-command.js +3 -4
- package/src/scripts/commands/write-review-fixes-command.js.map +1 -1
- package/src/scripts/git-finishUpsertPr.js +2 -2
- package/src/scripts/git-finishUpsertPr.js.map +1 -1
- package/src/scripts/git-gatherInfo.js +6 -7
- package/src/scripts/git-gatherInfo.js.map +1 -1
- package/src/scripts/pr-gate-container.d.ts +9 -0
- package/src/scripts/pr-gate-container.js +19 -0
- package/src/scripts/pr-gate-container.js.map +1 -0
- package/src/scripts/workflow/await-loop.d.ts +1 -1
- package/src/scripts/workflow/await-loop.js +1 -1
- package/src/scripts/workflow/await-loop.js.map +1 -1
- package/src/scripts/workflow/build-affected.js +1 -1
- package/src/scripts/workflow/build-affected.js.map +1 -1
- package/src/scripts/workflow/build-artifact-gate.d.ts +1 -1
- package/src/scripts/workflow/build-artifact-gate.js +3 -3
- package/src/scripts/workflow/build-artifact-gate.js.map +1 -1
- package/src/scripts/workflow/build-gate-log.d.ts +9 -6
- package/src/scripts/workflow/build-gate-log.js +34 -40
- package/src/scripts/workflow/build-gate-log.js.map +1 -1
- package/src/scripts/workflow/checklist-detector.d.ts +2 -2
- package/src/scripts/workflow/checklist-detector.js +4 -4
- package/src/scripts/workflow/checklist-detector.js.map +1 -1
- package/src/scripts/workflow/checklist-scanner.d.ts +1 -1
- package/src/scripts/workflow/checklist-scanner.js +11 -11
- package/src/scripts/workflow/checklist-scanner.js.map +1 -1
- package/src/scripts/workflow/checklist-scope-hasher.d.ts +1 -1
- package/src/scripts/workflow/checklist-scope-hasher.js +2 -2
- package/src/scripts/workflow/checklist-scope-hasher.js.map +1 -1
- package/src/scripts/workflow/dev-deploy-refs.d.ts +5 -5
- package/src/scripts/workflow/dev-deploy-refs.js +8 -8
- package/src/scripts/workflow/dev-deploy-refs.js.map +1 -1
- package/src/scripts/workflow/dev-resolve-runner.d.ts +3 -3
- package/src/scripts/workflow/dev-resolve-runner.js +30 -30
- package/src/scripts/workflow/dev-resolve-runner.js.map +1 -1
- package/src/scripts/workflow/diff-basis.d.ts +4 -2
- package/src/scripts/workflow/diff-basis.js +18 -15
- package/src/scripts/workflow/diff-basis.js.map +1 -1
- package/src/scripts/workflow/diff-materializer.d.ts +5 -3
- package/src/scripts/workflow/diff-materializer.js +18 -15
- package/src/scripts/workflow/diff-materializer.js.map +1 -1
- package/src/scripts/workflow/gated-pr-publisher.d.ts +8 -6
- package/src/scripts/workflow/gated-pr-publisher.js +23 -22
- package/src/scripts/workflow/gated-pr-publisher.js.map +1 -1
- package/src/scripts/workflow/generated-artifact-registry.d.ts +4 -2
- package/src/scripts/workflow/generated-artifact-registry.js +11 -8
- package/src/scripts/workflow/generated-artifact-registry.js.map +1 -1
- package/src/scripts/workflow/git-exec.d.ts +22 -12
- package/src/scripts/workflow/git-exec.js +45 -29
- package/src/scripts/workflow/git-exec.js.map +1 -1
- package/src/scripts/workflow/git-findForkPoint.d.ts +6 -2
- package/src/scripts/workflow/git-findForkPoint.js +31 -23
- package/src/scripts/workflow/git-findForkPoint.js.map +1 -1
- package/src/scripts/workflow/git-readAiBranchName.d.ts +4 -2
- package/src/scripts/workflow/git-readAiBranchName.js +8 -5
- package/src/scripts/workflow/git-readAiBranchName.js.map +1 -1
- package/src/scripts/workflow/hotfix-pr-publisher.d.ts +4 -3
- package/src/scripts/workflow/hotfix-pr-publisher.js +7 -6
- package/src/scripts/workflow/hotfix-pr-publisher.js.map +1 -1
- package/src/scripts/workflow/landed-tree-resolver.d.ts +4 -2
- package/src/scripts/workflow/landed-tree-resolver.js +11 -8
- package/src/scripts/workflow/landed-tree-resolver.js.map +1 -1
- package/src/scripts/workflow/landed-worktree-reaper.d.ts +4 -2
- package/src/scripts/workflow/landed-worktree-reaper.js +12 -9
- package/src/scripts/workflow/landed-worktree-reaper.js.map +1 -1
- package/src/scripts/workflow/merge-end.d.ts +5 -4
- package/src/scripts/workflow/merge-end.js +28 -27
- package/src/scripts/workflow/merge-end.js.map +1 -1
- package/src/scripts/workflow/merge-start.d.ts +5 -1
- package/src/scripts/workflow/merge-start.js +56 -49
- package/src/scripts/workflow/merge-start.js.map +1 -1
- package/src/scripts/workflow/open-pr-check.d.ts +4 -2
- package/src/scripts/workflow/open-pr-check.js +11 -8
- package/src/scripts/workflow/open-pr-check.js.map +1 -1
- package/src/scripts/workflow/pr-comment-upserter.d.ts +5 -3
- package/src/scripts/workflow/pr-comment-upserter.js +15 -14
- package/src/scripts/workflow/pr-comment-upserter.js.map +1 -1
- package/src/scripts/workflow/pr-context-writer.d.ts +1 -1
- package/src/scripts/workflow/pr-context-writer.js +3 -3
- package/src/scripts/workflow/pr-context-writer.js.map +1 -1
- package/src/scripts/workflow/pr-merger.d.ts +8 -5
- package/src/scripts/workflow/pr-merger.js +32 -27
- package/src/scripts/workflow/pr-merger.js.map +1 -1
- package/src/scripts/workflow/provenance-enforcer.d.ts +4 -2
- package/src/scripts/workflow/provenance-enforcer.js +19 -17
- package/src/scripts/workflow/provenance-enforcer.js.map +1 -1
- package/src/scripts/workflow/review-round-state.d.ts +7 -6
- package/src/scripts/workflow/review-round-state.js +33 -38
- package/src/scripts/workflow/review-round-state.js.map +1 -1
- package/src/scripts/workflow/run-update.js +1 -1
- package/src/scripts/workflow/run-update.js.map +1 -1
- package/src/scripts/workflow/squash-settings-enforcer.d.ts +6 -3
- package/src/scripts/workflow/squash-settings-enforcer.js +19 -14
- package/src/scripts/workflow/squash-settings-enforcer.js.map +1 -1
- package/src/scripts/wp-await-checks.js +2 -2
- package/src/scripts/wp-await-checks.js.map +1 -1
- package/src/scripts/wp-await-reviews.js +2 -2
- package/src/scripts/wp-await-reviews.js.map +1 -1
- package/src/scripts/wp-build.js +2 -2
- package/src/scripts/wp-build.js.map +1 -1
- package/src/scripts/wp-check-pr.js +2 -2
- package/src/scripts/wp-check-pr.js.map +1 -1
- package/src/scripts/wp-cleanup.js +2 -2
- package/src/scripts/wp-cleanup.js.map +1 -1
- package/src/scripts/wp-finish-push-dev.js +2 -2
- package/src/scripts/wp-finish-push-dev.js.map +1 -1
- package/src/scripts/wp-finish-update.js +2 -2
- package/src/scripts/wp-finish-update.js.map +1 -1
- package/src/scripts/wp-human-post-pr.js +2 -2
- package/src/scripts/wp-human-post-pr.js.map +1 -1
- package/src/scripts/wp-land-pr.js +2 -2
- package/src/scripts/wp-land-pr.js.map +1 -1
- package/src/scripts/wp-push-dev.js +2 -2
- package/src/scripts/wp-push-dev.js.map +1 -1
- package/src/scripts/wp-reap-worktree.js +2 -2
- package/src/scripts/wp-reap-worktree.js.map +1 -1
- package/src/scripts/wp-review-upsert-pr.js +2 -2
- package/src/scripts/wp-review-upsert-pr.js.map +1 -1
- package/src/scripts/wp-start-update.js +2 -2
- package/src/scripts/wp-start-update.js.map +1 -1
- package/src/scripts/wp-start-upsert-pr.js +2 -2
- package/src/scripts/wp-start-upsert-pr.js.map +1 -1
- package/src/scripts/wp-sync-main.js +2 -2
- package/src/scripts/wp-sync-main.js.map +1 -1
- package/src/scripts/wp-upsert-hotfix-pr.js +2 -2
- package/src/scripts/wp-upsert-hotfix-pr.js.map +1 -1
- package/src/scripts/wp-write-review-fixes.js +2 -2
- package/src/scripts/wp-write-review-fixes.js.map +1 -1
- package/src/scripts/wp-write-review.js +2 -2
- package/src/scripts/wp-write-review.js.map +1 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { BuildTermination } from '@webpieces/rules-config';
|
|
2
|
+
import { GitProcessApi, NativeProcessApi } from '@webpieces/tooling-common';
|
|
2
3
|
import { GateLogFile } from './gate-log-file';
|
|
3
4
|
import { StageOutputLog } from './stage-output-log';
|
|
4
5
|
/** How often the heartbeat reports the log's size. Hardcoded: a knob here would be a knob the PR gate's
|
|
@@ -57,13 +58,15 @@ export declare class BuildLogHeartbeat {
|
|
|
57
58
|
export declare class BuildGateLog {
|
|
58
59
|
private readonly files;
|
|
59
60
|
private readonly stageConsole;
|
|
60
|
-
|
|
61
|
+
private readonly git;
|
|
62
|
+
private readonly processes;
|
|
63
|
+
constructor(files: GateLogFile, stageConsole: StageOutputLog, git: GitProcessApi, processes: NativeProcessApi);
|
|
61
64
|
/** Absolute path of the log for `stage` at the current HEAD, creating its directory. */
|
|
62
|
-
pathFor(repoRoot: string, stage: string): string
|
|
65
|
+
pathFor(repoRoot: string, stage: string): Promise<string>;
|
|
63
66
|
/** The same path, and '' when no log has been WRITTEN there yet. Used by finish's skip path. */
|
|
64
|
-
existingLogFor(repoRoot: string, stage: string): string
|
|
67
|
+
existingLogFor(repoRoot: string, stage: string): Promise<string>;
|
|
65
68
|
/** `build.log` for `wp-build`; `build-gate-<stage>-<branch>-<shortSha>.log` for the PR-flow stages. */
|
|
66
|
-
fileNameFor(repoRoot: string, stage: string): string
|
|
69
|
+
fileNameFor(repoRoot: string, stage: string): Promise<string>;
|
|
67
70
|
/**
|
|
68
71
|
* Run `buildCommand` with its stdout AND stderr redirected in full to `logPath`, printing a heartbeat
|
|
69
72
|
* every HEARTBEAT_MS so the caller can see it is alive. Returns the BUILD's raw termination facts.
|
|
@@ -87,10 +90,10 @@ export declare class BuildGateLog {
|
|
|
87
90
|
* agent guessing or rebuilding — so it is told to surface the contradiction to the human and stop.
|
|
88
91
|
*/
|
|
89
92
|
failureMessage(buildCommand: string, logPath: string, termination: BuildTermination): string;
|
|
90
|
-
private
|
|
93
|
+
private recordTermination;
|
|
91
94
|
/** One stable, human-readable spelling shared by the FullLog and the immediate failure output. */
|
|
92
95
|
private terminationRecord;
|
|
93
96
|
private resolvePath;
|
|
94
97
|
private slug;
|
|
95
|
-
private
|
|
98
|
+
private gitOut;
|
|
96
99
|
}
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BuildGateLog = exports.BuildLogHeartbeat = exports.BUILD_LOG_NAME = exports.BUILD_STAGE = exports.FINISH_STAGE = exports.REVIEW_STAGE = exports.FAILURE_TAIL_LINES = exports.HEARTBEAT_MS = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const child_process_1 = require("child_process");
|
|
6
5
|
const fs = tslib_1.__importStar(require("fs"));
|
|
7
6
|
const rules_config_1 = require("@webpieces/rules-config");
|
|
8
7
|
const tooling_common_1 = require("@webpieces/tooling-common");
|
|
@@ -27,8 +26,8 @@ const build_log_follower_1 = require("./build-log-follower");
|
|
|
27
26
|
// pipeline the shell reports TEE's status, which is 0 whether the build passed or failed, so the status
|
|
28
27
|
// had to be smuggled out through a side file. With no pipe, the child's own exit code IS the answer.
|
|
29
28
|
//
|
|
30
|
-
// ─── Why async (
|
|
31
|
-
//
|
|
29
|
+
// ─── Why async (a child that does not block, not a synchronous spawn) ──────────────────────────────────────────────────────────────
|
|
30
|
+
// A synchronous spawn blocks the event loop for the length of the build, so NOTHING can print while it runs — and
|
|
32
31
|
// a silent terminal for 3–7 minutes is indistinguishable from a hang. The heartbeat is the reason this is
|
|
33
32
|
// async, and it is why `run` returns a Promise and `BuildAffected.runBuildGate` is async with it.
|
|
34
33
|
//
|
|
@@ -102,25 +101,29 @@ exports.BuildLogHeartbeat = BuildLogHeartbeat;
|
|
|
102
101
|
let BuildGateLog = class BuildGateLog {
|
|
103
102
|
files;
|
|
104
103
|
stageConsole;
|
|
105
|
-
|
|
104
|
+
git;
|
|
105
|
+
processes;
|
|
106
|
+
constructor(files, stageConsole, git, processes) {
|
|
106
107
|
this.files = files;
|
|
107
108
|
this.stageConsole = stageConsole;
|
|
109
|
+
this.git = git;
|
|
110
|
+
this.processes = processes;
|
|
108
111
|
}
|
|
109
112
|
/** Absolute path of the log for `stage` at the current HEAD, creating its directory. */
|
|
110
113
|
pathFor(repoRoot, stage) {
|
|
111
114
|
return this.resolvePath(repoRoot, stage);
|
|
112
115
|
}
|
|
113
116
|
/** The same path, and '' when no log has been WRITTEN there yet. Used by finish's skip path. */
|
|
114
|
-
existingLogFor(repoRoot, stage) {
|
|
115
|
-
const file = this.resolvePath(repoRoot, stage);
|
|
117
|
+
async existingLogFor(repoRoot, stage) {
|
|
118
|
+
const file = await this.resolvePath(repoRoot, stage);
|
|
116
119
|
return fs.existsSync(file) ? file : '';
|
|
117
120
|
}
|
|
118
121
|
/** `build.log` for `wp-build`; `build-gate-<stage>-<branch>-<shortSha>.log` for the PR-flow stages. */
|
|
119
|
-
fileNameFor(repoRoot, stage) {
|
|
122
|
+
async fileNameFor(repoRoot, stage) {
|
|
120
123
|
if (stage === exports.BUILD_STAGE)
|
|
121
124
|
return exports.BUILD_LOG_NAME;
|
|
122
125
|
const branch = this.slug(tooling_common_1.gitCheckout.branch(repoRoot) ?? '');
|
|
123
|
-
const sha = this.slug(this.
|
|
126
|
+
const sha = this.slug(await this.gitOut(repoRoot, ['rev-parse', '--short', 'HEAD']));
|
|
124
127
|
return `build-gate-${this.slug(stage)}-${branch === '' ? 'nobranch' : branch}-${sha === '' ? 'nosha' : sha}.log`;
|
|
125
128
|
}
|
|
126
129
|
/**
|
|
@@ -141,7 +144,7 @@ let BuildGateLog = class BuildGateLog {
|
|
|
141
144
|
// the one CliExitError.
|
|
142
145
|
// eslint-disable-next-line @webpieces/no-unmanaged-exceptions
|
|
143
146
|
try {
|
|
144
|
-
return
|
|
147
|
+
return this.recordTermination(await this.processes.runShellToFile(buildCommand, repoRoot, fd), fd);
|
|
145
148
|
}
|
|
146
149
|
finally {
|
|
147
150
|
clearInterval(timer);
|
|
@@ -179,30 +182,19 @@ let BuildGateLog = class BuildGateLog {
|
|
|
179
182
|
`Read that FILE for the failures. Do NOT re-run the build to see them.\n` +
|
|
180
183
|
`If you do not see failures in that log, report that to the user and stop.\n`);
|
|
181
184
|
}
|
|
182
|
-
//
|
|
183
|
-
//
|
|
184
|
-
//
|
|
185
|
-
//
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
});
|
|
196
|
-
child.on('close', (code, signal) => {
|
|
197
|
-
if (settled)
|
|
198
|
-
return;
|
|
199
|
-
settled = true;
|
|
200
|
-
const termination = new rules_config_1.BuildTermination(code, signal);
|
|
201
|
-
if (code === null || signal !== null)
|
|
202
|
-
fs.writeSync(fd, `\n${this.terminationRecord(termination)}\n`);
|
|
203
|
-
resolve(termination);
|
|
204
|
-
});
|
|
205
|
-
});
|
|
185
|
+
// The child's close code AND signal. A command that never starts (a shell that is missing, a cwd that
|
|
186
|
+
// vanished) fails CLOSED to 1 — calling a build that never ran green is the one outcome that must be
|
|
187
|
+
// impossible — and the reason is APPENDED TO THE LOG, so the failure message's pointer still leads to
|
|
188
|
+
// it rather than to an empty file.
|
|
189
|
+
recordTermination(ended, fd) {
|
|
190
|
+
if (ended.startError !== null) {
|
|
191
|
+
fs.writeSync(fd, `\nThe build command could not be started: ${ended.startError}\n`);
|
|
192
|
+
return new rules_config_1.BuildTermination(1, null);
|
|
193
|
+
}
|
|
194
|
+
const termination = new rules_config_1.BuildTermination(ended.code, ended.signal);
|
|
195
|
+
if (ended.code === null || ended.signal !== null)
|
|
196
|
+
fs.writeSync(fd, `\n${this.terminationRecord(termination)}\n`);
|
|
197
|
+
return termination;
|
|
206
198
|
}
|
|
207
199
|
/** One stable, human-readable spelling shared by the FullLog and the immediate failure output. */
|
|
208
200
|
terminationRecord(termination) {
|
|
@@ -210,8 +202,8 @@ let BuildGateLog = class BuildGateLog {
|
|
|
210
202
|
const signal = termination.signal === null ? 'none' : termination.signal;
|
|
211
203
|
return `Build process termination: exit code ${code}; signal ${signal}.`;
|
|
212
204
|
}
|
|
213
|
-
resolvePath(repoRoot, stage) {
|
|
214
|
-
const name = this.fileNameFor(repoRoot, stage);
|
|
205
|
+
async resolvePath(repoRoot, stage) {
|
|
206
|
+
const name = await this.fileNameFor(repoRoot, stage);
|
|
215
207
|
// `wp-build`'s log sits at the ROOT of the state dir, not under `logs/`, because it is the one log
|
|
216
208
|
// path a person types from memory. Everything else keeps the per-commit names in `logs/`.
|
|
217
209
|
return stage === exports.BUILD_STAGE
|
|
@@ -224,17 +216,19 @@ let BuildGateLog = class BuildGateLog {
|
|
|
224
216
|
}
|
|
225
217
|
// One local git read. Fails SOFT to '' — a missing branch/sha degrades the FILENAME, and degrading a
|
|
226
218
|
// filename may never be the reason a build gate does not run.
|
|
227
|
-
|
|
228
|
-
const result =
|
|
229
|
-
if (result.
|
|
219
|
+
async gitOut(repoRoot, args) {
|
|
220
|
+
const result = await this.git.run(['-C', repoRoot, ...args]);
|
|
221
|
+
if (!result.ok)
|
|
230
222
|
return '';
|
|
231
|
-
return
|
|
223
|
+
return result.stdout.trim();
|
|
232
224
|
}
|
|
233
225
|
};
|
|
234
226
|
exports.BuildGateLog = BuildGateLog;
|
|
235
227
|
exports.BuildGateLog = BuildGateLog = tslib_1.__decorate([
|
|
236
228
|
(0, inversify_1.injectable)(inversify_1.bindingScopeValues.Singleton),
|
|
237
229
|
tslib_1.__metadata("design:paramtypes", [gate_log_file_1.GateLogFile,
|
|
238
|
-
stage_output_log_1.StageOutputLog
|
|
230
|
+
stage_output_log_1.StageOutputLog,
|
|
231
|
+
tooling_common_1.GitProcessApi,
|
|
232
|
+
tooling_common_1.NativeProcessApi])
|
|
239
233
|
], BuildGateLog);
|
|
240
234
|
//# sourceMappingURL=build-gate-log.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build-gate-log.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/build-gate-log.ts"],"names":[],"mappings":";;;;AAAA,iDAA+D;AAC/D,+CAAyB;AACzB,0DAA2D;AAC3D,8DAAwD;AACxD,yCAA2D;AAE3D,mDAA8C;AAC9C,yDAAoD;AACpD,6DAAwD;AAExD,0GAA0G;AAC1G,yGAAyG;AACzG,2GAA2G;AAC3G,mGAAmG;AACnG,kGAAkG;AAClG,EAAE;AACF,uGAAuG;AACvG,kGAAkG;AAClG,EAAE;AACF,0GAA0G;AAC1G,sGAAsG;AACtG,wGAAwG;AACxG,2GAA2G;AAC3G,2GAA2G;AAC3G,wGAAwG;AACxG,qGAAqG;AACrG,EAAE;AACF,0GAA0G;AAC1G,0GAA0G;AAC1G,0GAA0G;AAC1G,kGAAkG;AAClG,EAAE;AACF,uGAAuG;AACvG,0GAA0G;AAC1G,uGAAuG;AAEvG;uEACuE;AAC1D,QAAA,YAAY,GAAG,MAAM,CAAC;AAEnC;;sCAEsC;AACzB,QAAA,kBAAkB,GAAG,EAAE,CAAC;AAErC;;GAEG;AACU,QAAA,YAAY,GAAG,QAAQ,CAAC;AACxB,QAAA,YAAY,GAAG,QAAQ,CAAC;AACrC,uGAAuG;AAC1F,QAAA,WAAW,GAAG,OAAO,CAAC;AAEnC,8FAA8F;AACjF,QAAA,cAAc,GAAG,WAAW,CAAC;AAE1C;;;;;;;GAOG;AACH,MAAa,iBAAiB;IAIL;IACA;IACA;IALb,QAAQ,GAAkB,IAAI,CAAC;IAEvC,YACqB,KAAkB,EAClB,OAAe,EACf,WAAmB;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AAW,CAAC,QAAgB,EAAE,KAAa;QAC/C,MAAM,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;QAC/C,mGAAmG;QACnG,0FAA0F;QAC1F,OAAO,KAAK,KAAK,mBAAW;YACxB,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,CAAC;YACtC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;IAC9C,CAAC;IAED,wGAAwG;IAChG,IAAI,CAAC,KAAa;QACtB,OAAO,KAAK,CAAC,OAAO,CAAC,mBAAmB,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;IAC3E,CAAC;IAED,qGAAqG;IACrG,8DAA8D;IACtD,GAAG,CAAC,QAAgB,EAAE,IAAc;QACxC,MAAM,MAAM,GAAG,IAAA,yBAAS,EAAC,KAAK,EAAE,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC;QACjF,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,EAAE,CAAC;QACnC,OAAO,CAAC,MAAM,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IACxC,CAAC;CACJ,CAAA;AAvJY,oCAAY;uBAAZ,YAAY;IADxB,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGT,2BAAW;QACJ,iCAAc;GAHxC,YAAY,CAuJxB","sourcesContent":["import { spawn, spawnSync, ChildProcess } from 'child_process';\nimport * as fs from 'fs';\nimport { BuildTermination } from '@webpieces/rules-config';\nimport { gitCheckout } from '@webpieces/tooling-common';\nimport { injectable, bindingScopeValues } from 'inversify';\n\nimport { GateLogFile } from './gate-log-file';\nimport { StageOutputLog } from './stage-output-log';\nimport { BuildLogFollower } from './build-log-follower';\n\n// ─── Why ───────────────────────────────────────────────────────────────────────────────────────────────\n// The build gate already builds everything. When the output only ever went to the CONSOLE, an agent that\n// wanted a different slice of it re-ran the WHOLE BUILD to get it: one measured session spent 23.9 minutes\n// across nine `nx affected` runs, five of them with NO code change in between — `| tail -50`, then\n// `> /tmp/file`, then `| grep`, then `| sed -n '1100,1230p'`. ~19 minutes spent re-reading a log.\n//\n// So the build's output is not streamed; it is REDIRECTED, in full, to a file whose path the caller is\n// handed on completion. Reading a different slice is then a `grep` of a FILE, not a second build.\n//\n// ─── Why a redirect and not `tee` ──────────────────────────────────────────────────────────────────────\n// An earlier cut of this used `cmd 2>&1 | tee log`, to keep the terminal byte-identical. That is what\n// makes the transcript expensive in the first place — an AI caller carries every line of it in context.\n// The redirect keeps the console to a handful of lines (a heartbeat, then a pointer at the file), which is\n// the entire productivity claim. Losing `tee` also deletes the `$?`-into-a-side-file dance it needed: in a\n// pipeline the shell reports TEE's status, which is 0 whether the build passed or failed, so the status\n// had to be smuggled out through a side file. With no pipe, the child's own exit code IS the answer.\n//\n// ─── Why async (`spawn`, not `spawnSync`) ──────────────────────────────────────────────────────────────\n// `spawnSync` blocks the event loop for the length of the build, so NOTHING can print while it runs — and\n// a silent terminal for 3–7 minutes is indistinguishable from a hang. The heartbeat is the reason this is\n// async, and it is why `run` returns a Promise and `BuildAffected.runBuildGate` is async with it.\n//\n// It is also the reason the heartbeat goes through `StageOutputLog.say` rather than `process.stdout` —\n// stage ② and stage ③ capture their own console output to a file, and a heartbeat captured into a file is\n// a heartbeat nobody can see. The 600-second watchdog that kills a silent command does not read files.\n\n/** How often the heartbeat reports the log's size. Hardcoded: a knob here would be a knob the PR gate's\n * own build never receives, and the two must stay the same command. */\nexport const HEARTBEAT_MS = 10_000;\n\n/** How many trailing log lines the failure message echoes, so the immediate cause is visible without a\n * second command. Small on purpose — the FULL log is one grep away and the message must not become the\n * transcript it exists to replace. */\nexport const FAILURE_TAIL_LINES = 20;\n\n/**\n * Which stage's gate is being captured. The value decides the log FILENAME.\n */\nexport const REVIEW_STAGE = 'review';\nexport const FINISH_STAGE = 'finish';\n// `wp-build`, which is not a stage of the PR flow but runs the SAME gate (BuildAffected.runBuildGate).\nexport const BUILD_STAGE = 'build';\n\n/** The one fixed log name — see BuildGateLog.fileNameFor for why only `wp-build` gets one. */\nexport const BUILD_LOG_NAME = 'build.log';\n\n/**\n * The heartbeat's state: the line count reported on the PREVIOUS tick, so a tick that has not moved can\n * say so. Stateful per RUN, which is why it is constructed per run rather than injected.\n *\n * `still` is the load-bearing word. A build that is linking, or waiting on a cold nx cache, produces no\n * output for minutes; without `still` the caller sees the same number twice and cannot tell a stalled\n * BUILD from a stalled REPORTER.\n */\nexport class BuildLogHeartbeat {\n private previous: number | null = null;\n\n constructor(\n private readonly files: GateLogFile,\n private readonly logPath: string,\n private readonly displayPath: string,\n ) {}\n\n /** One heartbeat line — `<path> size <n> lines`, plus ` still` when <n> has not moved. */\n tick(): string {\n const count = this.files.lineCount(this.logPath);\n const still = this.previous !== null && count === this.previous ? ' still' : '';\n this.previous = count;\n return `${this.displayPath} size ${count} lines${still}`;\n }\n}\n\n/**\n * Captures the build gate's full output to a file, reports progress while it runs, and renders the\n * pointer the caller is handed instead of a rebuild instruction.\n *\n * WHERE the file goes, how the previous run is kept, and what the pointer reads like are `GateLogFile`'s\n * — one mechanism, shared with the stage console log, so there is a single answer to \"where is it?\".\n *\n * ─── Two naming schemes, one rule each ─────────────────────────────────────────────────────────────────\n * • `wp-build` (BUILD_STAGE) writes ONE fixed path, `.webpieces/build.log`. It is fixed because a HUMAN\n * OR AN AGENT TYPES IT — `grep -n error .webpieces/build.log` has to be writable from memory, and a\n * name carrying a branch and a sha is not. History comes from the rotation instead.\n * • stage ② and stage ③ write `logs/build-gate-<stage>-<branch>-<shortSha>.log`, because those two\n * gates CAN run against one commit and a failure message from one must not be pointing at a file the\n * other overwrote. Nobody types those names; the failure message prints them.\n *\n * ─── Concurrency ───────────────────────────────────────────────────────────────────────────────────────\n * The DIRECTORY is `dotWebpieces.local()`-scoped — `<primary>/.webpieces/worktrees/<git worktree name>/`\n * in a linked worktree — so \"N agents in N worktrees\" is safe by construction rather than by naming. The\n * residual case is two builds in the SAME worktree at once, which is already unsupported: both would be\n * driving one git index.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class BuildGateLog {\n constructor(\n private readonly files: GateLogFile,\n private readonly stageConsole: StageOutputLog,\n ) {}\n\n /** Absolute path of the log for `stage` at the current HEAD, creating its directory. */\n pathFor(repoRoot: string, stage: string): string {\n return this.resolvePath(repoRoot, stage);\n }\n\n /** The same path, and '' when no log has been WRITTEN there yet. Used by finish's skip path. */\n existingLogFor(repoRoot: string, stage: string): string {\n const file = this.resolvePath(repoRoot, stage);\n return fs.existsSync(file) ? file : '';\n }\n\n /** `build.log` for `wp-build`; `build-gate-<stage>-<branch>-<shortSha>.log` for the PR-flow stages. */\n fileNameFor(repoRoot: string, stage: string): string {\n if (stage === BUILD_STAGE) return BUILD_LOG_NAME;\n const branch = this.slug(gitCheckout.branch(repoRoot) ?? '');\n const sha = this.slug(this.git(repoRoot, ['rev-parse', '--short', 'HEAD']));\n return `build-gate-${this.slug(stage)}-${branch === '' ? 'nobranch' : branch}-${sha === '' ? 'nosha' : sha}.log`;\n }\n\n /**\n * Run `buildCommand` with its stdout AND stderr redirected in full to `logPath`, printing a heartbeat\n * every HEARTBEAT_MS so the caller can see it is alive. Returns the BUILD's raw termination facts.\n * Nothing is truncated. Ordinary AI-facing callers do not stream; the explicitly human-attested\n * PR escape hatch may wrap this with runStreaming(), which follows the same durable file live.\n */\n async run(repoRoot: string, buildCommand: string, logPath: string): Promise<BuildTermination> {\n this.files.rotate(logPath);\n const fd = fs.openSync(logPath, 'w');\n const heartbeat = new BuildLogHeartbeat(\n this.files,\n logPath,\n this.files.displayPath(repoRoot, logPath),\n );\n const timer = setInterval((): void => {\n this.stageConsole.say(`${heartbeat.tick()}\\n`);\n }, HEARTBEAT_MS);\n // webpieces-disable no-unmanaged-exceptions -- chokepoint: the timer and the fd MUST be released\n // whatever the child does, and the exit code is returned rather than thrown so runBuildGate owns\n // the one CliExitError.\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n return await this.awaitExit(\n spawn(buildCommand, { cwd: repoRoot, shell: true, stdio: ['ignore', fd, fd] }),\n fd,\n );\n } finally {\n clearInterval(timer);\n fs.closeSync(fd);\n }\n }\n\n /** Human-only variant: preserve the durable log and follow its appended bytes live. */\n runStreaming(\n repoRoot: string,\n buildCommand: string,\n logPath: string,\n ): Promise<BuildTermination> {\n // run() synchronously rotates and opens the file before reaching its first await, so the follower\n // cannot accidentally replay the previous build that was at this path.\n const completion = this.run(repoRoot, buildCommand, logPath);\n const follower = new BuildLogFollower(logPath, this.stageConsole);\n follower.start();\n return completion.finally((): void => follower.stop());\n }\n\n /**\n * The success summary: the caller is told WHERE the full output is, not handed the output.\n */\n successMessage(logPath: string): string {\n return `\\nBuild success\\n${this.files.pointer(logPath)}`;\n }\n\n /**\n * The ENTIRE message the caller gets on a failed build. It names the log, echoes the last\n * FAILURE_TAIL_LINES lines so the immediate cause needs no second command, and forbids the rebuild\n * this whole file exists to prevent.\n *\n * The last sentence is not filler. If the log holds no visible failure then something upstream is wrong\n * (a runner that died without printing, a truncated redirect), and the worst possible response is an\n * agent guessing or rebuilding — so it is told to surface the contradiction to the human and stop.\n */\n failureMessage(buildCommand: string, logPath: string, termination: BuildTermination): string {\n return (\n `\\nBuild Failed: ${buildCommand}\\n${this.files.pointer(logPath)}\\n` +\n `${this.terminationRecord(termination)}\\n` +\n `Last ${FAILURE_TAIL_LINES} lines of that log:\\n${this.files.tail(logPath, FAILURE_TAIL_LINES)}\\n` +\n `Read that FILE for the failures. Do NOT re-run the build to see them.\\n` +\n `If you do not see failures in that log, report that to the user and stop.\\n`\n );\n }\n\n // Resolve, and wait for, the child's close code AND signal. A spawn that never starts (a shell that is\n // missing, a cwd that vanished) fails CLOSED to 1 — calling a build that never ran green is the one\n // outcome that must be impossible — and the reason is APPENDED TO THE LOG, so the failure message's\n // pointer still leads to it rather than to an empty file.\n private awaitExit(child: ChildProcess, fd: number): Promise<BuildTermination> {\n return new Promise<BuildTermination>(\n (resolve: (termination: BuildTermination) => void): void => {\n let settled = false;\n child.on('error', (err: Error): void => {\n if (settled) return;\n settled = true;\n fs.writeSync(fd, `\\nThe build command could not be started: ${err.message}\\n`);\n resolve(new BuildTermination(1, null));\n });\n child.on('close', (code: number | null, signal: NodeJS.Signals | null): void => {\n if (settled) return;\n settled = true;\n const termination = new BuildTermination(code, signal);\n if (code === null || signal !== null)\n fs.writeSync(fd, `\\n${this.terminationRecord(termination)}\\n`);\n resolve(termination);\n });\n },\n );\n }\n\n /** One stable, human-readable spelling shared by the FullLog and the immediate failure output. */\n private terminationRecord(termination: BuildTermination): string {\n const code = termination.code === null ? 'null' : String(termination.code);\n const signal = termination.signal === null ? 'none' : termination.signal;\n return `Build process termination: exit code ${code}; signal ${signal}.`;\n }\n\n private resolvePath(repoRoot: string, stage: string): string {\n const name = this.fileNameFor(repoRoot, stage);\n // `wp-build`'s log sits at the ROOT of the state dir, not under `logs/`, because it is the one log\n // path a person types from memory. Everything else keeps the per-commit names in `logs/`.\n return stage === BUILD_STAGE\n ? this.files.localPath(repoRoot, name)\n : this.files.logsPath(repoRoot, name);\n }\n\n // Anything that is not a filename-safe character becomes '-', so `dean/feat` cannot create directories.\n private slug(value: string): string {\n return value.replace(/[^A-Za-z0-9._-]+/g, '-').replace(/^-+|-+$/g, '');\n }\n\n // One local git read. Fails SOFT to '' — a missing branch/sha degrades the FILENAME, and degrading a\n // filename may never be the reason a build gate does not run.\n private git(repoRoot: string, args: string[]): string {\n const result = spawnSync('git', ['-C', repoRoot, ...args], { encoding: 'utf8' });\n if (result.status !== 0) return '';\n return (result.stdout ?? '').trim();\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"build-gate-log.js","sourceRoot":"","sources":["../../../../../../../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M,CAAC,QAAgB,EAAE,IAAc;QACjD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC;QAC7D,IAAI,CAAC,MAAM,CAAC,EAAE;YAAE,OAAO,EAAE,CAAC;QAC1B,OAAO,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;IAChC,CAAC;CACJ,CAAA;AA3IY,oCAAY;uBAAZ,YAAY;IADxB,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGT,2BAAW;QACJ,iCAAc;QACvB,8BAAa;QACP,iCAAgB;GALvC,YAAY,CA2IxB","sourcesContent":["import * as fs from 'fs';\nimport { BuildTermination } from '@webpieces/rules-config';\nimport { gitCheckout, GitProcessApi, NativeProcessApi, ShellTerminationDto } from '@webpieces/tooling-common';\nimport { injectable, bindingScopeValues } from 'inversify';\n\nimport { GateLogFile } from './gate-log-file';\nimport { StageOutputLog } from './stage-output-log';\nimport { BuildLogFollower } from './build-log-follower';\n\n// ─── Why ───────────────────────────────────────────────────────────────────────────────────────────────\n// The build gate already builds everything. When the output only ever went to the CONSOLE, an agent that\n// wanted a different slice of it re-ran the WHOLE BUILD to get it: one measured session spent 23.9 minutes\n// across nine `nx affected` runs, five of them with NO code change in between — `| tail -50`, then\n// `> /tmp/file`, then `| grep`, then `| sed -n '1100,1230p'`. ~19 minutes spent re-reading a log.\n//\n// So the build's output is not streamed; it is REDIRECTED, in full, to a file whose path the caller is\n// handed on completion. Reading a different slice is then a `grep` of a FILE, not a second build.\n//\n// ─── Why a redirect and not `tee` ──────────────────────────────────────────────────────────────────────\n// An earlier cut of this used `cmd 2>&1 | tee log`, to keep the terminal byte-identical. That is what\n// makes the transcript expensive in the first place — an AI caller carries every line of it in context.\n// The redirect keeps the console to a handful of lines (a heartbeat, then a pointer at the file), which is\n// the entire productivity claim. Losing `tee` also deletes the `$?`-into-a-side-file dance it needed: in a\n// pipeline the shell reports TEE's status, which is 0 whether the build passed or failed, so the status\n// had to be smuggled out through a side file. With no pipe, the child's own exit code IS the answer.\n//\n// ─── Why async (a child that does not block, not a synchronous spawn) ──────────────────────────────────────────────────────────────\n// A synchronous spawn blocks the event loop for the length of the build, so NOTHING can print while it runs — and\n// a silent terminal for 3–7 minutes is indistinguishable from a hang. The heartbeat is the reason this is\n// async, and it is why `run` returns a Promise and `BuildAffected.runBuildGate` is async with it.\n//\n// It is also the reason the heartbeat goes through `StageOutputLog.say` rather than `process.stdout` —\n// stage ② and stage ③ capture their own console output to a file, and a heartbeat captured into a file is\n// a heartbeat nobody can see. The 600-second watchdog that kills a silent command does not read files.\n\n/** How often the heartbeat reports the log's size. Hardcoded: a knob here would be a knob the PR gate's\n * own build never receives, and the two must stay the same command. */\nexport const HEARTBEAT_MS = 10_000;\n\n/** How many trailing log lines the failure message echoes, so the immediate cause is visible without a\n * second command. Small on purpose — the FULL log is one grep away and the message must not become the\n * transcript it exists to replace. */\nexport const FAILURE_TAIL_LINES = 20;\n\n/**\n * Which stage's gate is being captured. The value decides the log FILENAME.\n */\nexport const REVIEW_STAGE = 'review';\nexport const FINISH_STAGE = 'finish';\n// `wp-build`, which is not a stage of the PR flow but runs the SAME gate (BuildAffected.runBuildGate).\nexport const BUILD_STAGE = 'build';\n\n/** The one fixed log name — see BuildGateLog.fileNameFor for why only `wp-build` gets one. */\nexport const BUILD_LOG_NAME = 'build.log';\n\n/**\n * The heartbeat's state: the line count reported on the PREVIOUS tick, so a tick that has not moved can\n * say so. Stateful per RUN, which is why it is constructed per run rather than injected.\n *\n * `still` is the load-bearing word. A build that is linking, or waiting on a cold nx cache, produces no\n * output for minutes; without `still` the caller sees the same number twice and cannot tell a stalled\n * BUILD from a stalled REPORTER.\n */\nexport class BuildLogHeartbeat {\n private previous: number | null = null;\n\n constructor(\n private readonly files: GateLogFile,\n private readonly logPath: string,\n private readonly displayPath: string,\n ) {}\n\n /** One heartbeat line — `<path> size <n> lines`, plus ` still` when <n> has not moved. */\n tick(): string {\n const count = this.files.lineCount(this.logPath);\n const still = this.previous !== null && count === this.previous ? ' still' : '';\n this.previous = count;\n return `${this.displayPath} size ${count} lines${still}`;\n }\n}\n\n/**\n * Captures the build gate's full output to a file, reports progress while it runs, and renders the\n * pointer the caller is handed instead of a rebuild instruction.\n *\n * WHERE the file goes, how the previous run is kept, and what the pointer reads like are `GateLogFile`'s\n * — one mechanism, shared with the stage console log, so there is a single answer to \"where is it?\".\n *\n * ─── Two naming schemes, one rule each ─────────────────────────────────────────────────────────────────\n * • `wp-build` (BUILD_STAGE) writes ONE fixed path, `.webpieces/build.log`. It is fixed because a HUMAN\n * OR AN AGENT TYPES IT — `grep -n error .webpieces/build.log` has to be writable from memory, and a\n * name carrying a branch and a sha is not. History comes from the rotation instead.\n * • stage ② and stage ③ write `logs/build-gate-<stage>-<branch>-<shortSha>.log`, because those two\n * gates CAN run against one commit and a failure message from one must not be pointing at a file the\n * other overwrote. Nobody types those names; the failure message prints them.\n *\n * ─── Concurrency ───────────────────────────────────────────────────────────────────────────────────────\n * The DIRECTORY is `dotWebpieces.local()`-scoped — `<primary>/.webpieces/worktrees/<git worktree name>/`\n * in a linked worktree — so \"N agents in N worktrees\" is safe by construction rather than by naming. The\n * residual case is two builds in the SAME worktree at once, which is already unsupported: both would be\n * driving one git index.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class BuildGateLog {\n constructor(\n private readonly files: GateLogFile,\n private readonly stageConsole: StageOutputLog,\n private readonly git: GitProcessApi,\n private readonly processes: NativeProcessApi,\n ) {}\n\n /** Absolute path of the log for `stage` at the current HEAD, creating its directory. */\n pathFor(repoRoot: string, stage: string): Promise<string> {\n return this.resolvePath(repoRoot, stage);\n }\n\n /** The same path, and '' when no log has been WRITTEN there yet. Used by finish's skip path. */\n async existingLogFor(repoRoot: string, stage: string): Promise<string> {\n const file = await this.resolvePath(repoRoot, stage);\n return fs.existsSync(file) ? file : '';\n }\n\n /** `build.log` for `wp-build`; `build-gate-<stage>-<branch>-<shortSha>.log` for the PR-flow stages. */\n async fileNameFor(repoRoot: string, stage: string): Promise<string> {\n if (stage === BUILD_STAGE) return BUILD_LOG_NAME;\n const branch = this.slug(gitCheckout.branch(repoRoot) ?? '');\n const sha = this.slug(await this.gitOut(repoRoot, ['rev-parse', '--short', 'HEAD']));\n return `build-gate-${this.slug(stage)}-${branch === '' ? 'nobranch' : branch}-${sha === '' ? 'nosha' : sha}.log`;\n }\n\n /**\n * Run `buildCommand` with its stdout AND stderr redirected in full to `logPath`, printing a heartbeat\n * every HEARTBEAT_MS so the caller can see it is alive. Returns the BUILD's raw termination facts.\n * Nothing is truncated. Ordinary AI-facing callers do not stream; the explicitly human-attested\n * PR escape hatch may wrap this with runStreaming(), which follows the same durable file live.\n */\n async run(repoRoot: string, buildCommand: string, logPath: string): Promise<BuildTermination> {\n this.files.rotate(logPath);\n const fd = fs.openSync(logPath, 'w');\n const heartbeat = new BuildLogHeartbeat(\n this.files,\n logPath,\n this.files.displayPath(repoRoot, logPath),\n );\n const timer = setInterval((): void => {\n this.stageConsole.say(`${heartbeat.tick()}\\n`);\n }, HEARTBEAT_MS);\n // webpieces-disable no-unmanaged-exceptions -- chokepoint: the timer and the fd MUST be released\n // whatever the child does, and the exit code is returned rather than thrown so runBuildGate owns\n // the one CliExitError.\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n return this.recordTermination(await this.processes.runShellToFile(buildCommand, repoRoot, fd), fd);\n } finally {\n clearInterval(timer);\n fs.closeSync(fd);\n }\n }\n\n /** Human-only variant: preserve the durable log and follow its appended bytes live. */\n runStreaming(\n repoRoot: string,\n buildCommand: string,\n logPath: string,\n ): Promise<BuildTermination> {\n // run() synchronously rotates and opens the file before reaching its first await, so the follower\n // cannot accidentally replay the previous build that was at this path.\n const completion = this.run(repoRoot, buildCommand, logPath);\n const follower = new BuildLogFollower(logPath, this.stageConsole);\n follower.start();\n return completion.finally((): void => follower.stop());\n }\n\n /**\n * The success summary: the caller is told WHERE the full output is, not handed the output.\n */\n successMessage(logPath: string): string {\n return `\\nBuild success\\n${this.files.pointer(logPath)}`;\n }\n\n /**\n * The ENTIRE message the caller gets on a failed build. It names the log, echoes the last\n * FAILURE_TAIL_LINES lines so the immediate cause needs no second command, and forbids the rebuild\n * this whole file exists to prevent.\n *\n * The last sentence is not filler. If the log holds no visible failure then something upstream is wrong\n * (a runner that died without printing, a truncated redirect), and the worst possible response is an\n * agent guessing or rebuilding — so it is told to surface the contradiction to the human and stop.\n */\n failureMessage(buildCommand: string, logPath: string, termination: BuildTermination): string {\n return (\n `\\nBuild Failed: ${buildCommand}\\n${this.files.pointer(logPath)}\\n` +\n `${this.terminationRecord(termination)}\\n` +\n `Last ${FAILURE_TAIL_LINES} lines of that log:\\n${this.files.tail(logPath, FAILURE_TAIL_LINES)}\\n` +\n `Read that FILE for the failures. Do NOT re-run the build to see them.\\n` +\n `If you do not see failures in that log, report that to the user and stop.\\n`\n );\n }\n\n // The child's close code AND signal. A command that never starts (a shell that is missing, a cwd that\n // vanished) fails CLOSED to 1 — calling a build that never ran green is the one outcome that must be\n // impossible — and the reason is APPENDED TO THE LOG, so the failure message's pointer still leads to\n // it rather than to an empty file.\n private recordTermination(ended: ShellTerminationDto, fd: number): BuildTermination {\n if (ended.startError !== null) {\n fs.writeSync(fd, `\\nThe build command could not be started: ${ended.startError}\\n`);\n return new BuildTermination(1, null);\n }\n const termination = new BuildTermination(ended.code, ended.signal);\n if (ended.code === null || ended.signal !== null)\n fs.writeSync(fd, `\\n${this.terminationRecord(termination)}\\n`);\n return termination;\n }\n\n /** One stable, human-readable spelling shared by the FullLog and the immediate failure output. */\n private terminationRecord(termination: BuildTermination): string {\n const code = termination.code === null ? 'null' : String(termination.code);\n const signal = termination.signal === null ? 'none' : termination.signal;\n return `Build process termination: exit code ${code}; signal ${signal}.`;\n }\n\n private async resolvePath(repoRoot: string, stage: string): Promise<string> {\n const name = await this.fileNameFor(repoRoot, stage);\n // `wp-build`'s log sits at the ROOT of the state dir, not under `logs/`, because it is the one log\n // path a person types from memory. Everything else keeps the per-commit names in `logs/`.\n return stage === BUILD_STAGE\n ? this.files.localPath(repoRoot, name)\n : this.files.logsPath(repoRoot, name);\n }\n\n // Anything that is not a filename-safe character becomes '-', so `dean/feat` cannot create directories.\n private slug(value: string): string {\n return value.replace(/[^A-Za-z0-9._-]+/g, '-').replace(/^-+|-+$/g, '');\n }\n\n // One local git read. Fails SOFT to '' — a missing branch/sha degrades the FILENAME, and degrading a\n // filename may never be the reason a build gate does not run.\n private async gitOut(repoRoot: string, args: string[]): Promise<string> {\n const result = await this.git.run(['-C', repoRoot, ...args]);\n if (!result.ok) return '';\n return result.stdout.trim();\n }\n}\n"]}
|
|
@@ -44,7 +44,7 @@ export declare class ChecklistDetector {
|
|
|
44
44
|
roster(defs: readonly ChecklistDefinition[], changedFiles: readonly string[]): TriggeredChecklist[];
|
|
45
45
|
detect(defs: readonly ChecklistDefinition[], changedFiles: readonly string[]): TriggeredChecklist[];
|
|
46
46
|
private firedPatterns;
|
|
47
|
-
detectForRepo(repoRoot: string, defs: readonly ChecklistDefinition[]): TriggeredChecklist[]
|
|
48
|
-
detectForRange(repoRoot: string, defs: readonly ChecklistDefinition[], base: string, head?: string): TriggeredChecklist[]
|
|
47
|
+
detectForRepo(repoRoot: string, defs: readonly ChecklistDefinition[]): Promise<TriggeredChecklist[]>;
|
|
48
|
+
detectForRange(repoRoot: string, defs: readonly ChecklistDefinition[], base: string, head?: string): Promise<TriggeredChecklist[]>;
|
|
49
49
|
toRequired(triggered: readonly TriggeredChecklist[]): RequiredChecklist[];
|
|
50
50
|
}
|
|
@@ -83,10 +83,10 @@ let ChecklistDetector = class ChecklistDetector {
|
|
|
83
83
|
return def.patterns.filter((p) => changedFiles.some((f) => (0, rules_config_1.isPathExcluded)(f, [p])));
|
|
84
84
|
}
|
|
85
85
|
// Resolve the diff base for the local branch, then detect. Returns [] when there is no base to diff.
|
|
86
|
-
detectForRepo(repoRoot, defs) {
|
|
86
|
+
async detectForRepo(repoRoot, defs) {
|
|
87
87
|
if (defs.length === 0)
|
|
88
88
|
return [];
|
|
89
|
-
const range = this.diffScope.resolveBase(repoRoot);
|
|
89
|
+
const range = await this.diffScope.resolveBase(repoRoot);
|
|
90
90
|
if (!range.base)
|
|
91
91
|
return [];
|
|
92
92
|
return this.detectForRange(repoRoot, defs, range.base, range.head);
|
|
@@ -94,12 +94,12 @@ let ChecklistDetector = class ChecklistDetector {
|
|
|
94
94
|
// Same detection against an EXPLICIT (base, head) — used by CI, where the useful range is the PR's
|
|
95
95
|
// merge base .. head. tsOnly=false is load-bearing: the default drops every *.sql / Dockerfile / .env*
|
|
96
96
|
// / metadata file a checklist most wants to key on, silently producing "no checklists matched".
|
|
97
|
-
detectForRange(repoRoot, defs, base, head) {
|
|
97
|
+
async detectForRange(repoRoot, defs, base, head) {
|
|
98
98
|
if (defs.length === 0 || !base)
|
|
99
99
|
return [];
|
|
100
100
|
const opts = new rules_config_1.ChangedFilesOptions();
|
|
101
101
|
opts.tsOnly = false;
|
|
102
|
-
const changedFiles = this.diffScope.getChangedFiles(repoRoot, base, head, opts);
|
|
102
|
+
const changedFiles = await this.diffScope.getChangedFiles(repoRoot, base, head, opts);
|
|
103
103
|
return this.detect(defs, changedFiles);
|
|
104
104
|
}
|
|
105
105
|
// Flatten matched checklists into the RequiredChecklist shape that summary.json enforcement + the hint
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checklist-detector.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/checklist-detector.ts"],"names":[],"mappings":";;;;AAAA,0DAEiC;AACjC,yCAA2D;AAE3D,sGAAsG;AACtG,iFAAiF;AACjF,MAAa,kBAAkB;IAC3B,GAAG,CAAsB;IACzB,YAAY,CAAW;IACvB,uGAAuG;IACvG,yGAAyG;IACzG,eAAe,CAAW;IAE1B,YAAY,GAAwB,EAAE,YAAsB,EAAE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IAAoC,EAAE,YAA+B;QACxE,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,YAAY,CAAC;aACjC,MAAM,CAAC,CAAC,CAAqB,EAAW,EAAE,CAAC,CAAC,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAC/E,CAAC;IAED,yGAAyG;IACzG,kEAAkE;IAC1D,aAAa,CAAC,GAAwB,EAAE,YAA+B;QAC3E,OAAO,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAS,EAAW,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAS,EAAW,EAAE,CAAC,IAAA,6BAAc,EAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC1H,CAAC;IAED,qGAAqG;IACrG,aAAa,CAAC,QAAgB,EAAE,IAAoC;
|
|
1
|
+
{"version":3,"file":"checklist-detector.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/checklist-detector.ts"],"names":[],"mappings":";;;;AAAA,0DAEiC;AACjC,yCAA2D;AAE3D,sGAAsG;AACtG,iFAAiF;AACjF,MAAa,kBAAkB;IAC3B,GAAG,CAAsB;IACzB,YAAY,CAAW;IACvB,uGAAuG;IACvG,yGAAyG;IACzG,eAAe,CAAW;IAE1B,YAAY,GAAwB,EAAE,YAAsB,EAAE,kBAA4B,EAAE;QACxF,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;IAC3C,CAAC;CACJ;AAZD,gDAYC;AAED;;;GAGG;AACH,MAAa,eAAe;IACxB,OAAO,CAAuB,CAAC,qEAAqE;IACpG,gBAAgB,CAAS,CAAM,+DAA+D;IAC9F;;;;OAIG;IACH,YAAY,CAAU;IAEtB,YAAY,OAA6B,EAAE,gBAAwB,EAAE,YAAqB;QACtF,IAAI,CAAC,O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,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC,YAAY,EAAE,CAAC,CAAC,eAAe,EAAE,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC;IACrG,CAAC;CACJ,CAAA;AA9DY,8CAAiB;4BAAjB,iBAAiB;IAD7B,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAEG,wBAAS;GADxC,iBAAiB,CA8D7B","sourcesContent":["import {\n ChecklistDefinition, RequiredChecklist, DiffScope, ChangedFilesOptions, isPathExcluded,\n} from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\n\n// A checklist whose `patterns` matched the diff (so its reviewer subagent must run), plus the matched\n// files (for the dashboard + hint). Data-only (per CLAUDE.md, classes for data).\nexport class TriggeredChecklist {\n def: ChecklistDefinition;\n matchedFiles: string[];\n // Which of `def.patterns` actually hit a changed file. Carried so the printed instruction can say WHAT\n // matched, not just which files: a reviewer judges a `db/migrations/**` hit differently from a `**` one.\n matchedPatterns: string[];\n\n constructor(def: ChecklistDefinition, matchedFiles: string[], matchedPatterns: string[] = []) {\n this.def = def;\n this.matchedFiles = matchedFiles;\n this.matchedPatterns = matchedPatterns;\n }\n}\n\n/**\n * Every DEFINED checklist paired with what it matched, plus the two facts a reader needs to judge a skip:\n * how many files were even considered, and whether a diff was computable at all. Data-only (per CLAUDE.md).\n */\nexport class ChecklistRoster {\n entries: TriggeredChecklist[]; // one per defined checklist, in config order; matchedFiles may be []\n changedFileCount: number; // N — \"matched 0 of N changed files\" is only meaningful with N\n /**\n * false when no fork point resolved. Load-bearing: with no base the changed-file set is EMPTY, so\n * nothing matches — including patternless ALWAYS-RUNS checklists. Rendering that as \"all skipped ✅\"\n * would post a green all-clear to GitHub for a PR where no checklist was actually evaluated.\n */\n baseResolved: boolean;\n\n constructor(entries: TriggeredChecklist[], changedFileCount: number, baseResolved: boolean) {\n this.entries = entries;\n this.changedFileCount = changedFileCount;\n this.baseResolved = baseResolved;\n }\n}\n\n/**\n * Decides which company review checklists a branch matched, from what the diff CHANGED. Path matching\n * uses `isPathExcluded` — the SAME minimatch-based matcher rules-config already shares across\n * exclude-paths and the rule validators. A checklist with empty `patterns` matches every PR (always runs).\n *\n * `@injectable(bindingScopeValues.Singleton)` + injects {@link DiffScope} so it appears in the DI design\n * and reuses the ONE git-diff service instead of adding new git plumbing.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class ChecklistDetector {\n constructor(private readonly diffScope: DiffScope) {}\n\n /**\n * Pure matching over EVERY defined checklist, matched or not — one entry per def, in config order, with\n * `matchedFiles: []` for the ones nothing hit. This is what lets the PR comment publish the full roster:\n * a skipped checklist is the normal, healthy outcome, and a comment that lists only the ones that fired\n * cannot distinguish \"evaluated and irrelevant\" from \"never configured\".\n *\n * A skipped entry has `matchedPatterns: []` — and so does a PATTERNLESS one. They mean opposite things,\n * so a renderer must decide \"always runs\" from `def.patterns.length === 0`, NEVER from\n * `matchedPatterns.length`, or every skipped checklist claims the whole diff was in its scope.\n */\n roster(defs: readonly ChecklistDefinition[], changedFiles: readonly string[]): TriggeredChecklist[] {\n return defs.map((def: ChecklistDefinition): TriggeredChecklist => {\n const matched = def.patterns.length === 0\n ? [...changedFiles]\n : changedFiles.filter((f: string): boolean => isPathExcluded(f, def.patterns));\n return new TriggeredChecklist(def, matched, this.firedPatterns(def, changedFiles));\n });\n }\n\n // Pure matching — unit-testable without git. Return every checklist whose patterns hit a changed file\n // (empty patterns ⇒ always matches). Defined as the roster minus the empty entries so the set that GATES\n // and the set the comment REPORTS can never be computed two different ways.\n detect(defs: readonly ChecklistDefinition[], changedFiles: readonly string[]): TriggeredChecklist[] {\n return this.roster(defs, changedFiles)\n .filter((t: TriggeredChecklist): boolean => t.matchedFiles.length > 0);\n }\n\n // Which of a checklist's globs hit at least one changed file. [] for a patternless checklist (it matches\n // every PR, and saying \"matched by nothing\" would read as a bug).\n private firedPatterns(def: ChecklistDefinition, changedFiles: readonly string[]): string[] {\n return def.patterns.filter((p: string): boolean => changedFiles.some((f: string): boolean => isPathExcluded(f, [p])));\n }\n\n // Resolve the diff base for the local branch, then detect. Returns [] when there is no base to diff.\n async detectForRepo(repoRoot: string, defs: readonly ChecklistDefinition[]): Promise<TriggeredChecklist[]> {\n if (defs.length === 0) return [];\n const range = await this.diffScope.resolveBase(repoRoot);\n if (!range.base) return [];\n return this.detectForRange(repoRoot, defs, range.base, range.head);\n }\n\n // Same detection against an EXPLICIT (base, head) — used by CI, where the useful range is the PR's\n // merge base .. head. tsOnly=false is load-bearing: the default drops every *.sql / Dockerfile / .env*\n // / metadata file a checklist most wants to key on, silently producing \"no checklists matched\".\n async detectForRange(repoRoot: string, defs: readonly ChecklistDefinition[], base: string, head?: string): Promise<TriggeredChecklist[]> {\n if (defs.length === 0 || !base) return [];\n const opts = new ChangedFilesOptions();\n opts.tsOnly = false;\n const changedFiles = await this.diffScope.getChangedFiles(repoRoot, base, head, opts);\n return this.detect(defs, changedFiles);\n }\n\n // Flatten matched checklists into the RequiredChecklist shape that summary.json enforcement + the hint\n // consume.\n toRequired(triggered: readonly TriggeredChecklist[]): RequiredChecklist[] {\n return triggered.map((t: TriggeredChecklist): RequiredChecklist =>\n new RequiredChecklist(\n t.def.id, t.def.reviewer, t.def.doc, t.matchedFiles, t.matchedPatterns, t.def.required));\n }\n}\n"]}
|
|
@@ -182,7 +182,7 @@ export declare class ChecklistScanner {
|
|
|
182
182
|
* reviewer-agent file exists), both callers already run it for other fields, and keeping the read out of
|
|
183
183
|
* here leaves this a function of its inputs rather than of the filesystem.
|
|
184
184
|
*/
|
|
185
|
-
scan(repoRoot: string, defined: ChecklistDefinition[], opts: ChecklistScanOptions): ChecklistScan
|
|
185
|
+
scan(repoRoot: string, defined: ChecklistDefinition[], opts: ChecklistScanOptions): Promise<ChecklistScan>;
|
|
186
186
|
/**
|
|
187
187
|
* FROZEN at the briefing (issue #1053): once a review round has started, the checklists this branch owes
|
|
188
188
|
* are the ones that were briefed (still defined, with whatever the current diff matches for each) — never
|
|
@@ -247,16 +247,16 @@ let ChecklistScanner = class ChecklistScanner {
|
|
|
247
247
|
* reviewer-agent file exists), both callers already run it for other fields, and keeping the read out of
|
|
248
248
|
* here leaves this a function of its inputs rather than of the filesystem.
|
|
249
249
|
*/
|
|
250
|
-
scan(repoRoot, defined, opts) {
|
|
251
|
-
const featureName = this.aiBranchName.getFeatureName();
|
|
250
|
+
async scan(repoRoot, defined, opts) {
|
|
251
|
+
const featureName = await this.aiBranchName.getFeatureName();
|
|
252
252
|
const summaryPath = (0, rules_config_1.summaryJsonPath)(repoRoot, featureName);
|
|
253
253
|
// ONE basis for the file set, the reproduce command and any downstream materialization. The fork
|
|
254
254
|
// point still comes from ForkPoint (never DiffScope.resolveBase) — DiffBasisResolver injects it.
|
|
255
|
-
const basis = this.diffBasisResolver.resolve(repoRoot);
|
|
255
|
+
const basis = await this.diffBasisResolver.resolve(repoRoot);
|
|
256
256
|
const base = basis.base;
|
|
257
257
|
// ONE changed-file computation feeds both the roster (all X) and the applicable set (N). `detect` is
|
|
258
258
|
// pure and defined as the roster minus its empty entries, so the two cannot disagree about a match.
|
|
259
|
-
const changedFiles = this.changedFiles(repoRoot, base);
|
|
259
|
+
const changedFiles = await this.changedFiles(repoRoot, base);
|
|
260
260
|
const roster = new checklist_detector_1.ChecklistRoster(this.checklistDetector.roster(defined, changedFiles), changedFiles.length, base !== '');
|
|
261
261
|
const matched = this.checklistDetector.toRequired(this.checklistDetector.detect(defined, changedFiles));
|
|
262
262
|
// THE ONE CHOKE POINT for both reviewer opt-outs. Suppressing HERE — rather than in
|
|
@@ -265,7 +265,7 @@ let ChecklistScanner = class ChecklistScanner {
|
|
|
265
265
|
// existing. A second check in either command would be a second answer to one question.
|
|
266
266
|
const context = opts.contextStage === ''
|
|
267
267
|
? this.prContextWriter.contextFor(repoRoot, featureName, basis)
|
|
268
|
-
: this.prContextWriter.ensure(repoRoot, featureName, basis, opts.contextStage, changedFiles);
|
|
268
|
+
: await this.prContextWriter.ensure(repoRoot, featureName, basis, opts.contextStage, changedFiles);
|
|
269
269
|
const homeConfig = this.homeConfig.load();
|
|
270
270
|
const projectDisabled = defined.some((d) => d.reviewer.maxAgents === 0);
|
|
271
271
|
if (homeConfig.turnOffAllReviewers || projectDisabled) {
|
|
@@ -274,11 +274,11 @@ let ChecklistScanner = class ChecklistScanner {
|
|
|
274
274
|
// WHAT was suppressed, which is the difference between an honest record and a silent one.
|
|
275
275
|
return new ChecklistScan(defined, [], [], [], context, summaryPath, base, roster, [], true, matched, basis, changedFiles, [], []);
|
|
276
276
|
}
|
|
277
|
-
const judged = this.judgedScope(repoRoot, summaryPath, roster, matched);
|
|
277
|
+
const judged = this.judgedScope(repoRoot, featureName, summaryPath, roster, matched);
|
|
278
278
|
const applicable = judged.applicable;
|
|
279
|
-
const scopeHashes = this.scopeHasher.hashes(repoRoot, basis, applicable);
|
|
279
|
+
const scopeHashes = await this.scopeHasher.hashes(repoRoot, basis, applicable);
|
|
280
280
|
const loaded = this.reviewJsonService.loadChecklistResults(summaryPath, applicable);
|
|
281
|
-
const orangeFixes = this.rounds.orangeFixes(repoRoot, summaryPath, loaded);
|
|
281
|
+
const orangeFixes = await this.rounds.orangeFixes(repoRoot, summaryPath, loaded);
|
|
282
282
|
for (const result of loaded)
|
|
283
283
|
result.remediation = orangeFixes[result.id] ?? '';
|
|
284
284
|
const standings = this.standingsOf(summaryPath, loaded, scopeHashes)
|
|
@@ -306,8 +306,8 @@ let ChecklistScanner = class ChecklistScanner {
|
|
|
306
306
|
* Before any round starts, the set is simply what the diff matches.
|
|
307
307
|
*/
|
|
308
308
|
// eslint-disable-next-line @typescript-eslint/max-params
|
|
309
|
-
judgedScope(repoRoot, summaryPath, roster, matched) {
|
|
310
|
-
const receipt = this.receipts.read(repoRoot,
|
|
309
|
+
judgedScope(repoRoot, featureName, summaryPath, roster, matched) {
|
|
310
|
+
const receipt = this.receipts.read(repoRoot, featureName);
|
|
311
311
|
if (!this.rounds.roundStarted(summaryPath, receipt))
|
|
312
312
|
return new JudgedScope(matched, []);
|
|
313
313
|
const briefedIds = new Set(this.rounds.briefedChecklistIds(summaryPath, receipt));
|
|
@@ -384,7 +384,7 @@ let ChecklistScanner = class ChecklistScanner {
|
|
|
384
384
|
* deletes a migration, an auth check or a terraform rule changed exactly what a
|
|
385
385
|
* checklist exists to catch, and under the default no checklist fires at all.
|
|
386
386
|
*/
|
|
387
|
-
changedFiles(repoRoot, base) {
|
|
387
|
+
async changedFiles(repoRoot, base) {
|
|
388
388
|
if (base === '')
|
|
389
389
|
return [];
|
|
390
390
|
const opts = new rules_config_1.ChangedFilesOptions();
|