@bridge_gpt/mcp-server 0.2.72 → 0.2.73
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/README.md +5 -5
- package/build/agent-launchers/claude-executor-adapter.js +3 -0
- package/build/agents.generated.js +6 -6
- package/build/bridge-permissions.js +27 -0
- package/build/ci-system-detection.js +50 -0
- package/build/ci-trigger-adapters.js +631 -0
- package/build/ci-trigger-install.js +106 -0
- package/build/codex-launcher-pin.js +33 -2
- package/build/codex-skill-adapter.js +3 -1
- package/build/command-host.js +33 -0
- package/build/commands.generated.js +7 -6
- package/build/conductor/bridge-api-client.js +842 -35
- package/build/conductor/bring-up-facts.js +18 -5
- package/build/conductor/command-drift-production.js +42 -17
- package/build/conductor/command-drift.js +47 -0
- package/build/conductor/declare-blocked.js +554 -0
- package/build/conductor/doctor.js +106 -21
- package/build/conductor/driver-commands.js +141 -0
- package/build/conductor/driver-guard.js +277 -0
- package/build/conductor/driver-lapse.js +321 -0
- package/build/conductor/driver-register.js +176 -0
- package/build/conductor/driver-release.js +174 -0
- package/build/conductor/driver-session-state.js +315 -0
- package/build/conductor/epic-branch-ci-inspection.js +222 -29
- package/build/conductor/epic-implementer-cli.js +166 -15
- package/build/conductor/epic-server-database.js +162 -0
- package/build/conductor/epic-server-guidance.js +278 -0
- package/build/conductor/epic-server-journal.js +239 -0
- package/build/conductor/epic-server-processes.js +324 -0
- package/build/conductor/epic-server-recipe.js +397 -0
- package/build/conductor/epic-server-runtime.js +1207 -0
- package/build/conductor/epic-server-sfcc.js +107 -0
- package/build/conductor/epic-server-state.js +427 -0
- package/build/conductor/epic-server.js +594 -0
- package/build/conductor/gate-discovery.js +150 -5
- package/build/conductor/gate-settings-review.js +224 -4
- package/build/conductor/launch-need-probes.js +6 -53
- package/build/conductor/launch-plan.js +313 -156
- package/build/conductor/prerequisite-inputs.js +879 -45
- package/build/conductor/readiness-assessment.js +16 -1
- package/build/conductor/readiness-cli.js +20 -9
- package/build/conductor/readiness-prerequisites.js +28 -9
- package/build/conductor/readiness-sections.js +133 -126
- package/build/conductor/readiness.js +1 -1
- package/build/conductor/recovery-cli.js +13 -2
- package/build/conductor/tools.js +6 -5
- package/build/conductor/wait-run-attention.js +2 -2
- package/build/conductor/wait-run-cli.js +208 -22
- package/build/conductor/worker-database-doctor-inspector.js +33 -2
- package/build/conductor/worker-setup-tally.js +27 -0
- package/build/credential-store.js +71 -1
- package/build/dependency-install-declarations.js +55 -0
- package/build/docs.generated.js +2 -2
- package/build/doctor.js +54 -3
- package/build/drive-epic-help.js +21 -2
- package/build/drive-epic.js +1811 -351
- package/build/engine-paths.js +20 -0
- package/build/epic-branch-ci-summary.js +140 -0
- package/build/epic-capability-statement.js +107 -0
- package/build/epic-ci-workflow-drift.js +30 -15
- package/build/epic-ci-workflow-install.js +110 -42
- package/build/epic-ci-workflow-v2.js +274 -0
- package/build/epic-ci-workflow.js +38 -12
- package/build/epic-implementer-bin.js +2101 -44
- package/build/epic-launch-context.js +607 -0
- package/build/epic-server-record.js +273 -0
- package/build/epic-shared/bridge-client.js +11 -3
- package/build/escalation-reachability.js +43 -0
- package/build/executor/ci-fix-test-runs.js +334 -0
- package/build/executor/completion-contract.js +8 -1
- package/build/executor/env.js +59 -22
- package/build/executor/epic-server-context.js +141 -0
- package/build/executor/gate-qualification-job.js +127 -26
- package/build/executor/http-client.js +52 -5
- package/build/executor/job-runner.js +423 -69
- package/build/executor/observation.js +8 -0
- package/build/executor/pre-pr-checks.js +363 -0
- package/build/executor/prompt-spec.js +114 -2
- package/build/executor/reconcile-overlap-job.js +5 -3
- package/build/executor/required-work-diagnostics.js +4 -2
- package/build/executor/required-work-ledger.js +936 -38
- package/build/executor/results.js +58 -0
- package/build/executor/terminal-mutation.js +8 -0
- package/build/executor/worker-command.js +72 -3
- package/build/executor/worker-database-config.js +281 -0
- package/build/executor/worker-database-target.js +16 -12
- package/build/executor/worker-database.js +320 -101
- package/build/executor/worker-finalization.js +7 -1
- package/build/executor/worker-resources.js +25 -3
- package/build/executor/worker-verification-guidance.js +18 -3
- package/build/executor/worktree.js +20 -1
- package/build/executor-launch.js +54 -2
- package/build/generated-assets-catalog.js +2 -2
- package/build/index.js +664 -335
- package/build/init.js +26 -11
- package/build/install-bridge-conductor-answers.js +465 -0
- package/build/install-bridge-conductor-apply.js +259 -0
- package/build/install-bridge-conductor-assessment.js +895 -0
- package/build/install-bridge-conductor-compact.js +161 -0
- package/build/install-bridge-conductor-contracts.js +63 -0
- package/build/install-bridge-conductor-gate.js +1197 -196
- package/build/install-bridge-conductor-setup.js +535 -79
- package/build/install-bridge-conductor.js +2885 -560
- package/build/install-bridge.js +199 -21
- package/build/install-maintenance.js +26 -3
- package/build/launcher-config-inspection.js +162 -1
- package/build/mcp-grant-candidates.js +767 -0
- package/build/mcp-grant-doctor.js +63 -0
- package/build/mcp-grant.js +288 -0
- package/build/mcp-host-targets.js +8 -0
- package/build/mcp-identity.js +23 -0
- package/build/mcp-invoke.js +126 -13
- package/build/mcp-presets.js +107 -0
- package/build/mcp-provisioning.js +134 -2
- package/build/mcp-registration-doctor.js +31 -2
- package/build/mcp-server-invocation.js +6 -1
- package/build/merge-workflow-install.js +234 -109
- package/build/pipelines.generated.js +5 -5
- package/build/plan-discovery.js +97 -4
- package/build/plan-execution-ledger.js +100 -7
- package/build/plan-generation-io.js +262 -0
- package/build/plan-generation.js +424 -0
- package/build/plane/build-freshness.js +6 -1
- package/build/plane/cli.js +75 -9
- package/build/plane/plane-freshness.js +17 -0
- package/build/plane/preflight.js +50 -10
- package/build/plane/shutdown.js +19 -0
- package/build/plane/terminal-run-cleanup.js +18 -4
- package/build/printed-remedy-commands.js +206 -12
- package/build/readiness-check.js +77 -0
- package/build/readiness-prerequisites.generated.js +122 -14
- package/build/readme.generated.js +1 -1
- package/build/repository-state-paths.js +38 -0
- package/build/run-unit-tests-launcher.js +8 -1
- package/build/setup-epic.js +1190 -196
- package/build/setup-progress.js +44 -0
- package/build/setup-question.js +122 -4
- package/build/third-party-mcp-targets.js +30 -0
- package/build/ticket-delivery-enrollment.js +9 -0
- package/build/upgrade-cli.js +85 -2
- package/build/v2-readiness-requirements.js +28 -1
- package/build/version.generated.js +3 -3
- package/docs/EPIC-IMPLEMENTER-INSTALL.md +9 -1
- package/docs/epic-implementer/getting-started.md +3 -1
- package/docs/epic-implementer/self-hosting.md +14 -1
- package/package.json +2 -2
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { MCP_PACKAGE_NAME } from "./mcp-identity.js";
|
|
2
|
+
import { createSetupProgressTimer, withSetupProgress } from "./setup-progress.js";
|
|
1
3
|
import { askSetupQuestion, setupConsentQuestion } from "./setup-question.js";
|
|
2
4
|
/**
|
|
3
5
|
* `install epic-implementer` — the owner-confirmed repository gate (BAPI-1391).
|
|
@@ -12,19 +14,24 @@ import { askSetupQuestion, setupConsentQuestion } from "./setup-question.js";
|
|
|
12
14
|
*
|
|
13
15
|
* Five properties are load-bearing:
|
|
14
16
|
*
|
|
15
|
-
* 1. **Discovery never confirms.** The deterministic collector
|
|
17
|
+
* 1. **Discovery never confirms on its own.** The deterministic collector
|
|
16
18
|
* (`conductor/gate-discovery.ts`) reads the working tree and the provider's
|
|
17
|
-
* real check history and PROPOSES a typed gate.
|
|
18
|
-
*
|
|
19
|
-
* which are owner input.
|
|
19
|
+
* real check history and PROPOSES a typed gate. Nothing is stored until the
|
|
20
|
+
* owner authorizes the combined policy change the server previews, or
|
|
21
|
+
* supplies explicit gate flags, which are owner input. Setup no longer asks
|
|
22
|
+
* the owner to pick gate members: checks the repository's CI has really
|
|
23
|
+
* reported become WATCHED members (BAPI-1603), and a stored confirmed gate is
|
|
24
|
+
* never rewritten from discovery. No LLM ever writes a gate: a local command
|
|
25
|
+
* is stored only by the server, after it passes once under the executor.
|
|
20
26
|
* 2. **The capability probe precedes every gate write.** A server that does not
|
|
21
27
|
* advertise `gate_profile.v1` gets "Bridge API update required" and nothing
|
|
22
28
|
* is written — including the qualification enqueue, and the short-lived
|
|
23
29
|
* executor whose claim carries `job_types` (an older server answers that key
|
|
24
30
|
* with 422). The probe is a read and runs after the base-URL consent.
|
|
25
31
|
* 3. **Removals are visible.** The stored and proposed gates are shown side by
|
|
26
|
-
* side before any write
|
|
27
|
-
* flag-driven removal
|
|
32
|
+
* side before any write. Typed gate flags are the owner's consent, so a
|
|
33
|
+
* flag-driven removal applies without a removal question and the completed
|
|
34
|
+
* removal is reported plainly afterward.
|
|
28
35
|
* 4. **A refused write changes nothing.** BAPI-1390's PUT is admin-only and
|
|
29
36
|
* compare-and-swaps the revision; on a refusal the installer shows the PRIOR
|
|
30
37
|
* gate, never the proposal, as what is in force.
|
|
@@ -40,10 +47,12 @@ import { askSetupQuestion, setupConsentQuestion } from "./setup-question.js";
|
|
|
40
47
|
* It never confirms a gate, authorizes a merge, or changes an approval rule
|
|
41
48
|
* without an explicit typed "yes".
|
|
42
49
|
*/
|
|
43
|
-
import { ConductorBridgeApiError, GATE_PROFILE_CAPABILITY_TOKEN, enqueueConductorGateQualification, fetchConductorGateCheckHistory, fetchConductorGateProfile, fetchConductorGateQualificationJob, probeConductorGateProfileCapability, putConductorGateProfile, putEpicBranchCiDecision, } from "./conductor/bridge-api-client.js";
|
|
50
|
+
import { ConductorBridgeApiError, GATE_PROFILE_CAPABILITY_TOKEN, enqueueConductorGateQualification, fetchConductorGateCheckHistory, fetchConductorGateProfile, fetchConductorGateQualificationJob, fetchConductorReadiness, probeConductorGateProfileCapability, probeConductorGateProfileWatchedCapability, probeConductorGateProfileWorkerSetupCapability, putConductorGateProfile, requestConductorLearnedTestCommand, putEpicBranchCiDecision, } from "./conductor/bridge-api-client.js";
|
|
51
|
+
import { describeGateConsequence } from "./conductor/readiness-sections.js";
|
|
44
52
|
import { applyApprovalExemption, assessApprovalExemptionScope, buildEpicBranchCiEvidence, exemptionManualSteps, inspectEpicBranchWorkflowCoverage, readEpicBranchRulesViaGh, } from "./conductor/epic-branch-ci-inspection.js";
|
|
45
|
-
import { describeEvidence, discoverDeclarations, discoverGate, LOCAL_COMMAND_TIMEOUT_SECONDS, } from "./conductor/gate-discovery.js";
|
|
46
|
-
import { dependencyInstallEqual, describeSettingsEdit, hasSettingsToReview, hasUnstoredDeclarationProposal, hintEqual, renderDeclarationsOnly, renderSettingsReview, reviewDeclarations, reviewDiscoveredSettings, settingsMatchStored, storedCiDatabase, terminalSafe, workerEnvEqual, } from "./conductor/gate-settings-review.js";
|
|
53
|
+
import { describeEvidence, discoverDeclarations, discoverGate, LOCAL_COMMAND_TIMEOUT_SECONDS, reportedProviderChecks, } from "./conductor/gate-discovery.js";
|
|
54
|
+
import { dependencyInstallEqual, describeSettingsEdit, hasSettingsToReview, hasUnstoredDeclarationProposal, hintEqual, mustOrderOffer, mustOrderShortfallWarning, recommendedSettingsSelection, renderDeclarationsOnly, renderSettingsReview, reviewDeclarations, reviewDiscoveredSettings, settingsMatchStored, storedCiDatabase, terminalSafe, workerDatabaseEqual, workerEnvEqual, } from "./conductor/gate-settings-review.js";
|
|
55
|
+
import { canonicalMustOrderPaths, sameMustOrderPaths, } from "./dependency-install-declarations.js";
|
|
47
56
|
import { PRINTED_EXECUTOR_INSTALL_SERVICE_COMMAND, PRINTED_EXECUTOR_ID_INSTRUCTION, PRINTED_QUALIFY_GATE_COMMAND, PRINTED_REPO_WIDE_EXECUTOR_COMMAND, } from "./printed-remedy-commands.js";
|
|
48
57
|
export function emptyConductorGateFlags() {
|
|
49
58
|
return {
|
|
@@ -152,17 +161,12 @@ export function validateConductorGateFlags(flags, context) {
|
|
|
152
161
|
if (flags.gateNone && flags.migrationGuard !== undefined) {
|
|
153
162
|
return "--gate-none has no members, so it cannot take a --migration-guard.";
|
|
154
163
|
}
|
|
155
|
-
if (flags.clearGate && (hasExplicitGateInput(flags) || flags.
|
|
156
|
-
return "--clear-gate runs on its own: it cannot be combined with gate flags
|
|
164
|
+
if (flags.clearGate && (hasExplicitGateInput(flags) || flags.qualifyGate)) {
|
|
165
|
+
return "--clear-gate runs on its own: it cannot be combined with gate flags or --qualify-gate.";
|
|
157
166
|
}
|
|
158
167
|
if (flags.clearGate && context.replaceDoneGate) {
|
|
159
168
|
return "--clear-gate cannot be combined with --replace-done-gate.";
|
|
160
169
|
}
|
|
161
|
-
if (flags.confirmGate && !hasExplicitGateInput(flags)) {
|
|
162
|
-
return ("--confirm-gate confirms explicit gate flags. Supply --provider-check, --local-command, " +
|
|
163
|
-
"--gate-none, --migration-guard, or --customized-command, or run without it to confirm " +
|
|
164
|
-
"the discovered proposal at a prompt.");
|
|
165
|
-
}
|
|
166
170
|
if (flags.migrationGuard?.kind === "provider" && flags.providerChecks.length > 0 &&
|
|
167
171
|
!flags.providerChecks.includes(flags.migrationGuard.ref)) {
|
|
168
172
|
return "--migration-guard provider:<check> must name one of the supplied provider checks exactly.";
|
|
@@ -199,6 +203,26 @@ export function createQualificationExecutorRunner(seams) {
|
|
|
199
203
|
return { started, exitCode };
|
|
200
204
|
};
|
|
201
205
|
}
|
|
206
|
+
/**
|
|
207
|
+
* BAPI-1604 — in an available terminal, discovered CI settings that need no
|
|
208
|
+
* individual confirmation are applied from the safe recommended selection and
|
|
209
|
+
* printed as receipts, instead of being asked one by one. `--review-ci-settings`
|
|
210
|
+
* restores the individual review.
|
|
211
|
+
*/
|
|
212
|
+
function usesSafeSettingDefaults(io) {
|
|
213
|
+
return io.isTTY === true && io.reviewCiSettings !== true;
|
|
214
|
+
}
|
|
215
|
+
/** Name-only receipts for a safe selection; a skipped item is named, never valued. */
|
|
216
|
+
function logSafeSettingReceipts(io, selection, stored, dryRun) {
|
|
217
|
+
const lines = describeSettingsEdit(selection.edit, stored);
|
|
218
|
+
if (lines.length > 0) {
|
|
219
|
+
io.log(dryRun ? " Safe CI settings setup would apply (dry run):" : " Safe CI settings applied with the gate:");
|
|
220
|
+
for (const line of lines)
|
|
221
|
+
io.log(line);
|
|
222
|
+
}
|
|
223
|
+
for (const skipped of selection.skipped)
|
|
224
|
+
io.log(` ${skipped}`);
|
|
225
|
+
}
|
|
202
226
|
const YES = new Set(["y", "yes"]);
|
|
203
227
|
async function ask(io, promptText) {
|
|
204
228
|
const decision = await askSetupQuestion(setupConsentQuestion(promptText), { read: io.promptLine, write: io.log });
|
|
@@ -245,6 +269,7 @@ export function desiredFromStored(profile) {
|
|
|
245
269
|
return {
|
|
246
270
|
kind: profile.kind,
|
|
247
271
|
providerChecks: [...profile.provider_checks],
|
|
272
|
+
...(profile.watched_checks !== undefined ? { watchedChecks: [...profile.watched_checks] } : {}),
|
|
248
273
|
localCommands: profile.local_commands.map((c) => ({
|
|
249
274
|
name: c.name,
|
|
250
275
|
argv: [...c.argv],
|
|
@@ -271,9 +296,13 @@ export function gateMatchesStored(desired, stored, storedProfile) {
|
|
|
271
296
|
(stored.customizedCommands !== undefined &&
|
|
272
297
|
desired.customizedCommands.length === stored.customizedCommands.length &&
|
|
273
298
|
desired.customizedCommands.every((c, i) => c === stored.customizedCommands?.[i]));
|
|
299
|
+
const desiredWatched = desired.watchedChecks ?? [];
|
|
300
|
+
const storedWatched = stored.watchedChecks ?? [];
|
|
274
301
|
return (desired.kind === stored.kind &&
|
|
275
302
|
desired.providerChecks.length === stored.providerChecks.length &&
|
|
276
303
|
desired.providerChecks.every((c, i) => c === stored.providerChecks[i]) &&
|
|
304
|
+
desiredWatched.length === storedWatched.length &&
|
|
305
|
+
desiredWatched.every((c, i) => c === storedWatched[i]) &&
|
|
277
306
|
desired.localCommands.length === stored.localCommands.length &&
|
|
278
307
|
desired.localCommands.every((c, i) => sameCommand(c, stored.localCommands[i])) &&
|
|
279
308
|
sameGuard &&
|
|
@@ -288,8 +317,82 @@ function settingsOf(desired) {
|
|
|
288
317
|
...(desired.reproduce !== undefined ? { reproduce: desired.reproduce } : {}),
|
|
289
318
|
...(desired.dependencyInstall !== undefined ? { dependencyInstall: desired.dependencyInstall } : {}),
|
|
290
319
|
...(desired.ciDatabase !== undefined ? { ciDatabase: desired.ciDatabase } : {}),
|
|
320
|
+
...(desired.mustOrderPaths !== undefined ? { mustOrderPaths: desired.mustOrderPaths } : {}),
|
|
321
|
+
...(desired.workerDatabase !== undefined ? { workerDatabase: desired.workerDatabase } : {}),
|
|
291
322
|
};
|
|
292
323
|
}
|
|
324
|
+
const UNSAFE_PROVIDER_NAME_RE = /["$`\\!]/;
|
|
325
|
+
const RESTORE_COMMAND_PREFIX = `To put them back, run: npx -y ${MCP_PACKAGE_NAME} install epic-implementer `;
|
|
326
|
+
/**
|
|
327
|
+
* Human-facing guidance for putting a prior gate back after a removal. It keeps
|
|
328
|
+
* the stored order (provider checks, local commands, then the migration guard)
|
|
329
|
+
* and names EVERY flag-restorable member, because member flags replace the whole
|
|
330
|
+
* gate. An executable command is emitted only when every such member is safely
|
|
331
|
+
* representable; one unsafe member suppresses the command rather than leaving a
|
|
332
|
+
* safe subset. Watched checks have no flag and are never rendered as one.
|
|
333
|
+
*/
|
|
334
|
+
export function describeGateRestoration(prior) {
|
|
335
|
+
const flags = [];
|
|
336
|
+
const members = [];
|
|
337
|
+
const unsafe = [];
|
|
338
|
+
const providerSafe = (name) => isValidCheckName(name) && !UNSAFE_PROVIDER_NAME_RE.test(name);
|
|
339
|
+
for (const check of prior.providerChecks) {
|
|
340
|
+
members.push(`--provider-check ${terminalSafe(check)}`);
|
|
341
|
+
if (providerSafe(check))
|
|
342
|
+
flags.push(`--provider-check "${check}"`);
|
|
343
|
+
else
|
|
344
|
+
unsafe.push(`provider check ${terminalSafe(check)}`);
|
|
345
|
+
}
|
|
346
|
+
for (const command of prior.localCommands) {
|
|
347
|
+
members.push(`--local-command ${terminalSafe(command.name)}`);
|
|
348
|
+
const literal = `${command.name}=${command.argv.join(" ")}`;
|
|
349
|
+
const parsed = parseLocalCommandFlag(literal);
|
|
350
|
+
const safe = LITERAL_COMMAND_NAME_RE.test(command.name) &&
|
|
351
|
+
command.argv.every((w) => LITERAL_ARGV_WORD_RE.test(w)) &&
|
|
352
|
+
parsed.ok &&
|
|
353
|
+
parsed.value.form === "literal" &&
|
|
354
|
+
parsed.value.name === command.name &&
|
|
355
|
+
parsed.value.argv.length === command.argv.length &&
|
|
356
|
+
parsed.value.argv.every((w, i) => w === command.argv[i]);
|
|
357
|
+
if (safe)
|
|
358
|
+
flags.push(`--local-command "${literal}"`);
|
|
359
|
+
else
|
|
360
|
+
unsafe.push(`local command ${terminalSafe(command.name)}`);
|
|
361
|
+
}
|
|
362
|
+
if (prior.migrationGuard !== null) {
|
|
363
|
+
const guard = prior.migrationGuard;
|
|
364
|
+
members.push(`--migration-guard ${guard.kind}:${terminalSafe(guard.name)}`);
|
|
365
|
+
const safe = guard.kind === "provider" ? providerSafe(guard.name) : LITERAL_COMMAND_NAME_RE.test(guard.name);
|
|
366
|
+
if (safe)
|
|
367
|
+
flags.push(`--migration-guard "${guard.kind}:${guard.name}"`);
|
|
368
|
+
else
|
|
369
|
+
unsafe.push(`migration guard ${guard.kind}:${terminalSafe(guard.name)}`);
|
|
370
|
+
}
|
|
371
|
+
const lines = [];
|
|
372
|
+
if (members.length > 0) {
|
|
373
|
+
if (unsafe.length === 0) {
|
|
374
|
+
lines.push(RESTORE_COMMAND_PREFIX + flags.join(" "));
|
|
375
|
+
}
|
|
376
|
+
else {
|
|
377
|
+
lines.push(` The earlier gate had these flag-restorable members: ${members.join("; ")}.`);
|
|
378
|
+
lines.push(` These values cannot be safely written as a command: ${unsafe.join("; ")}.`);
|
|
379
|
+
lines.push(" Name all of the earlier members together in one install epic-implementer invocation: " +
|
|
380
|
+
"member flags replace the whole gate, so restoring them one at a time would not work.");
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
if ((prior.watchedChecks ?? []).length > 0) {
|
|
384
|
+
lines.push(" Watched checks have no flag. To have setup look for them again, run setup with --clear-gate, " +
|
|
385
|
+
"then run setup with no gate flags; it rediscovers watched checks from your CI, which may not " +
|
|
386
|
+
"match the earlier membership, and the earlier required and local members are not restored that way.");
|
|
387
|
+
}
|
|
388
|
+
for (const command of prior.localCommands) {
|
|
389
|
+
if (command.timeout_seconds !== LOCAL_COMMAND_TIMEOUT_SECONDS) {
|
|
390
|
+
lines.push(` Note: local command ${terminalSafe(command.name)} had a ${command.timeout_seconds}s timeout; ` +
|
|
391
|
+
`restoring it with --local-command uses the default ${LOCAL_COMMAND_TIMEOUT_SECONDS}s.`);
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
return lines;
|
|
395
|
+
}
|
|
293
396
|
/** Human descriptions of every member `next` removes from `prior`. */
|
|
294
397
|
export function gateRemovals(prior, next) {
|
|
295
398
|
if (prior === null)
|
|
@@ -299,6 +402,10 @@ export function gateRemovals(prior, next) {
|
|
|
299
402
|
if (!next.providerChecks.includes(check))
|
|
300
403
|
removed.push(`provider check "${check}"`);
|
|
301
404
|
}
|
|
405
|
+
for (const check of prior.watchedChecks ?? []) {
|
|
406
|
+
if (!(next.watchedChecks ?? []).includes(check))
|
|
407
|
+
removed.push(`watched check "${check}"`);
|
|
408
|
+
}
|
|
302
409
|
for (const command of prior.localCommands) {
|
|
303
410
|
if (!next.localCommands.some((c) => sameCommand(c, command))) {
|
|
304
411
|
removed.push(`local command ${command.name}`);
|
|
@@ -315,22 +422,40 @@ export function confirmRequestFor(desired, expectedRevision, stored) {
|
|
|
315
422
|
// BAPI-1520: a setting is sent only when it effectively changes what is stored.
|
|
316
423
|
// An unchanged hint is omitted (the server keeps it); `reproduce: null` is sent
|
|
317
424
|
// only to remove a hint that is actually stored.
|
|
318
|
-
const
|
|
425
|
+
const storedWatched = new Set(stored?.watched_checks ?? []);
|
|
426
|
+
// BAPI-1606: the server keeps a check's stored membership when `watched` is
|
|
427
|
+
// omitted. A check the gate now REQUIRES that is stored as watched must say
|
|
428
|
+
// `watched: false`, or it would stay watched; every other required check sends
|
|
429
|
+
// exactly the entry it always did.
|
|
430
|
+
const providerEntry = (name, watched) => {
|
|
431
|
+
const membership = watched ? { watched: true } : storedWatched.has(name) ? { watched: false } : {};
|
|
319
432
|
const edit = desired.reproduce?.get(name);
|
|
320
433
|
if (edit === undefined)
|
|
321
|
-
return { name };
|
|
434
|
+
return { name, ...membership };
|
|
322
435
|
const current = stored?.reproduction_hints?.get(name) ?? null;
|
|
323
436
|
if (edit === null)
|
|
324
|
-
return current !== null ? { name, reproduce: null } : { name };
|
|
437
|
+
return current !== null ? { name, reproduce: null, ...membership } : { name, ...membership };
|
|
325
438
|
if (current !== null && hintEqual(edit, current))
|
|
326
|
-
return { name };
|
|
327
|
-
return { name, reproduce: { argv: [...edit.argv], timeout_seconds: edit.timeout_seconds } };
|
|
328
|
-
}
|
|
439
|
+
return { name, ...membership };
|
|
440
|
+
return { name, reproduce: { argv: [...edit.argv], timeout_seconds: edit.timeout_seconds }, ...membership };
|
|
441
|
+
};
|
|
442
|
+
// Required entries first, then watched ones: the server's own order.
|
|
443
|
+
const providerChecks = [
|
|
444
|
+
...desired.providerChecks.map((name) => providerEntry(name, false)),
|
|
445
|
+
...(desired.watchedChecks ?? [])
|
|
446
|
+
.filter((name) => !desired.providerChecks.includes(name))
|
|
447
|
+
.map((name) => providerEntry(name, true)),
|
|
448
|
+
];
|
|
329
449
|
const sendWorkerEnv = desired.workerEnv !== undefined && !workerEnvEqual(desired.workerEnv, stored?.worker_env);
|
|
330
450
|
// BAPI-1551: each declaration is sent only when it differs from what is stored;
|
|
331
451
|
// a clear sends `[]`, and a reset of the CI-database value sends `null`.
|
|
332
452
|
const sendDependencyInstall = desired.dependencyInstall !== undefined && !dependencyInstallEqual(desired.dependencyInstall, stored?.dependency_install);
|
|
333
453
|
const sendCiDatabase = desired.ciDatabase !== undefined && desired.ciDatabase !== storedCiDatabase(stored);
|
|
454
|
+
// BAPI-1580: the canonical list is sent only when it differs from the stored one.
|
|
455
|
+
const mustOrderPaths = desired.mustOrderPaths !== undefined ? canonicalMustOrderPaths(desired.mustOrderPaths) : undefined;
|
|
456
|
+
const sendMustOrderPaths = mustOrderPaths !== undefined && !sameMustOrderPaths(mustOrderPaths, stored?.must_order_paths ?? []);
|
|
457
|
+
// BAPI-1598: sent only when it differs from what is stored; it replaces the stored object whole.
|
|
458
|
+
const sendWorkerDatabase = desired.workerDatabase !== undefined && !workerDatabaseEqual(desired.workerDatabase, stored?.worker_database);
|
|
334
459
|
return {
|
|
335
460
|
action: "confirm",
|
|
336
461
|
confirm: true,
|
|
@@ -359,6 +484,10 @@ export function confirmRequestFor(desired, expectedRevision, stored) {
|
|
|
359
484
|
...(sendCiDatabase && desired.ciDatabase !== undefined
|
|
360
485
|
? { ci_database: desired.ciDatabase === "unknown" ? null : desired.ciDatabase }
|
|
361
486
|
: {}),
|
|
487
|
+
...(sendMustOrderPaths && mustOrderPaths !== undefined ? { must_order_paths: mustOrderPaths } : {}),
|
|
488
|
+
...(sendWorkerDatabase && desired.workerDatabase !== undefined
|
|
489
|
+
? { worker_database: structuredClone(desired.workerDatabase) }
|
|
490
|
+
: {}),
|
|
362
491
|
};
|
|
363
492
|
}
|
|
364
493
|
function resolveLocalCommand(flag, proposal) {
|
|
@@ -380,8 +509,11 @@ function resolveLocalCommand(flag, proposal) {
|
|
|
380
509
|
*/
|
|
381
510
|
export function desiredFromFlags(flags, current, proposal) {
|
|
382
511
|
let providerChecks;
|
|
512
|
+
let watchedChecks = [];
|
|
383
513
|
let localCommands;
|
|
384
514
|
if (hasExplicitGateMembers(flags)) {
|
|
515
|
+
// The member flags ARE the gate: stored watched checks are not carried over,
|
|
516
|
+
// and the comparison shows them as removals.
|
|
385
517
|
providerChecks = [...flags.providerChecks];
|
|
386
518
|
localCommands = [];
|
|
387
519
|
for (const flag of flags.localCommands) {
|
|
@@ -401,6 +533,7 @@ export function desiredFromFlags(flags, current, proposal) {
|
|
|
401
533
|
}
|
|
402
534
|
else if (current !== null) {
|
|
403
535
|
providerChecks = [...current.providerChecks];
|
|
536
|
+
watchedChecks = [...(current.watchedChecks ?? [])];
|
|
404
537
|
localCommands = current.localCommands.map((c) => ({ ...c, argv: [...c.argv] }));
|
|
405
538
|
}
|
|
406
539
|
else {
|
|
@@ -439,6 +572,7 @@ export function desiredFromFlags(flags, current, proposal) {
|
|
|
439
572
|
desired: {
|
|
440
573
|
kind: kindForMembers(providerChecks, localCommands),
|
|
441
574
|
providerChecks,
|
|
575
|
+
...(watchedChecks.length > 0 ? { watchedChecks } : {}),
|
|
442
576
|
localCommands,
|
|
443
577
|
migrationGuard,
|
|
444
578
|
customizedCommands: flags.customizedCommands,
|
|
@@ -448,28 +582,33 @@ export function desiredFromFlags(flags, current, proposal) {
|
|
|
448
582
|
// ---------------------------------------------------------------------------
|
|
449
583
|
// Rendering
|
|
450
584
|
// ---------------------------------------------------------------------------
|
|
451
|
-
const KIND_CONSEQUENCE = Object.freeze({
|
|
452
|
-
provider: "every check must have actually reported on this repository before an unattended run is admitted",
|
|
453
|
-
local: "the executor runs these commands before each auto-merge; they must pass once under the executor " +
|
|
454
|
-
"(qualification) before an unattended run is admitted",
|
|
455
|
-
mixed: "BOTH legs gate every merge: each provider check must report green AND each local command must pass",
|
|
456
|
-
none: "no gate: an unattended run is admitted, but every child merge waits for your approval",
|
|
457
|
-
});
|
|
458
585
|
function quoted(names) {
|
|
459
586
|
return names.map((n) => `"${n}"`).join(", ");
|
|
460
587
|
}
|
|
461
|
-
/**
|
|
462
|
-
|
|
588
|
+
/** BAPI-1637 — the minimal shape the shared consequence wording needs, from a desired gate. */
|
|
589
|
+
function consequenceGate(gate) {
|
|
590
|
+
return { kind: gate.kind, hasWatchedChecks: (gate.watchedChecks ?? []).length > 0 };
|
|
591
|
+
}
|
|
592
|
+
/**
|
|
593
|
+
* One-gate description lines (members, conjunction, guard, customized). The
|
|
594
|
+
* consequence line is the shared {@link describeGateConsequence}, the same wording
|
|
595
|
+
* readiness renders; `ciFacts` is the server's `epic_branch_ci` block when the
|
|
596
|
+
* caller has one, and its absence leaves gate-only wording.
|
|
597
|
+
*/
|
|
598
|
+
export function describeGate(gate, indent = " ", ciFacts) {
|
|
463
599
|
const lines = [];
|
|
464
600
|
const members = [];
|
|
601
|
+
const watched = gate.watchedChecks ?? [];
|
|
465
602
|
if (gate.providerChecks.length > 0)
|
|
466
603
|
members.push(`provider checks ${quoted(gate.providerChecks)}`);
|
|
604
|
+
if (watched.length > 0)
|
|
605
|
+
members.push(`watched checks ${quoted(watched)}`);
|
|
467
606
|
if (gate.localCommands.length > 0) {
|
|
468
607
|
members.push(`local commands ${gate.localCommands.map((c) => `${c.name} (${c.argv.join(" ")})`).join(", ")}`);
|
|
469
608
|
}
|
|
470
609
|
lines.push(`${indent}${gate.kind}` +
|
|
471
610
|
(members.length > 0 ? ` — ${members.join(gate.kind === "mixed" ? " AND " : "; ")}` : ""));
|
|
472
|
-
lines.push(`${indent} ${
|
|
611
|
+
lines.push(`${indent} ${describeGateConsequence(consequenceGate(gate), ciFacts)}`);
|
|
473
612
|
if (gate.migrationGuard !== null) {
|
|
474
613
|
lines.push(`${indent} migration guard: ${gate.migrationGuard.kind} ${gate.migrationGuard.name}`);
|
|
475
614
|
}
|
|
@@ -478,6 +617,221 @@ export function describeGate(gate, indent = " ") {
|
|
|
478
617
|
}
|
|
479
618
|
return lines;
|
|
480
619
|
}
|
|
620
|
+
const asPolicyRecord = (value) => value !== null && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
621
|
+
const policySame = (a, b) => JSON.stringify(a) === JSON.stringify(b);
|
|
622
|
+
const SETTING_SOURCE_WORDS = { project_default: "project default", built_in: "built-in default" };
|
|
623
|
+
const GATE_LEAD_BY_KIND = {
|
|
624
|
+
provider: "required CI checks",
|
|
625
|
+
local: "required local commands",
|
|
626
|
+
mixed: "required CI checks and local commands",
|
|
627
|
+
none: "no required checks",
|
|
628
|
+
};
|
|
629
|
+
const workerEnvNames = (gate) => (Array.isArray(gate.worker_env) ? gate.worker_env : [])
|
|
630
|
+
.map((entry) => (typeof asPolicyRecord(entry).name === "string" ? String(asPolicyRecord(entry).name) : ""))
|
|
631
|
+
.filter((name) => name !== "");
|
|
632
|
+
const onOff = (value) => (value === true || value === "true" ? "on" : value === false || value === "false" ? "off" : "not set");
|
|
633
|
+
/**
|
|
634
|
+
* BAPI-1658 — owner-facing words for each review-policy source, taken from the
|
|
635
|
+
* readiness wording for the same four values. `none` means no review result is
|
|
636
|
+
* used to hold child merges; it is NOT permission to merge, and other merge
|
|
637
|
+
* checks still apply.
|
|
638
|
+
*/
|
|
639
|
+
const REVIEW_POLICY_WORDS = {
|
|
640
|
+
repository_policy: "epic-branch merges need no review verdict, but a review asking for changes still sends the child back for fixes",
|
|
641
|
+
verdict_protocol: "child merges wait for the claude-review verdict",
|
|
642
|
+
native_review_decision: "child merges wait for GitHub's own review decision",
|
|
643
|
+
none: "no review result holds child merges; other merge checks still apply",
|
|
644
|
+
};
|
|
645
|
+
/**
|
|
646
|
+
* BAPI-1658 — owner-facing words for each gate qualification state. Qualification
|
|
647
|
+
* is only the proof run of the gate's local commands: `not_required` means there
|
|
648
|
+
* is nothing to prove, not that any other merge check is waived, and `qualified`
|
|
649
|
+
* does not promise overall readiness.
|
|
650
|
+
*/
|
|
651
|
+
const QUALIFICATION_WORDS = {
|
|
652
|
+
qualified: "the local commands have passed their proof run; other merge checks still apply",
|
|
653
|
+
unqualified: "the local commands have not passed their proof run yet, so an unattended run is not admitted until they do",
|
|
654
|
+
stale: "the local commands must pass again before an unattended run is admitted",
|
|
655
|
+
not_required: "there are no local commands to prove; other merge checks still apply",
|
|
656
|
+
};
|
|
657
|
+
/** Gate projection keys described one line each, in a stable order. Values are never printed. */
|
|
658
|
+
const GATE_ANCILLARY_AREAS = [
|
|
659
|
+
["customized_commands", "Customized commands"],
|
|
660
|
+
["failure_formats", "Failure formats"],
|
|
661
|
+
["dependency_install", "Dependency refresh"],
|
|
662
|
+
["ci_database", "CI database setting"],
|
|
663
|
+
["must_order_paths", "Must-order paths"],
|
|
664
|
+
["worker_database", "Worker database setting"],
|
|
665
|
+
["verification_handoff_default", "Verification handoff default"],
|
|
666
|
+
];
|
|
667
|
+
/** Gate keys the formatter understands; `source` is provenance, never a change worth a line. */
|
|
668
|
+
const GATE_KNOWN_KEYS = new Set([
|
|
669
|
+
"kind", "provider_checks", "local_commands", "migration_guard", "worker_env", "source",
|
|
670
|
+
...GATE_ANCILLARY_AREAS.map(([key]) => key),
|
|
671
|
+
]);
|
|
672
|
+
const isAbsentPolicyValue = (value) => value === undefined || value === null || (Array.isArray(value) && value.length === 0);
|
|
673
|
+
/** Equal values, where a missing, null, or empty value counts as the same "nothing". */
|
|
674
|
+
const policySameOrBothAbsent = (a, b) => (isAbsentPolicyValue(a) && isAbsentPolicyValue(b)) || policySame(a, b);
|
|
675
|
+
/**
|
|
676
|
+
* Plain, one-line-per-change descriptions of a setup-policy difference.
|
|
677
|
+
*
|
|
678
|
+
* Presentation only: it accepts differences the server already established (the
|
|
679
|
+
* preview's `effects`, or the applied read-back as before/after pairs), decides
|
|
680
|
+
* no policy, and performs no I/O. Fields that did not change inside a broader
|
|
681
|
+
* `gate`, `setup`, `config`, or `sources` effect are omitted. Worker environment
|
|
682
|
+
* is described by name only. `ciFacts` is the readiness `epic_branch_ci` block
|
|
683
|
+
* when the caller already has it; the gate consequence is the shared wording.
|
|
684
|
+
*/
|
|
685
|
+
export function describePolicyChanges(effects, ciFacts, options = {}) {
|
|
686
|
+
const lines = [];
|
|
687
|
+
for (const effect of effects) {
|
|
688
|
+
const before = asPolicyRecord(effect.before);
|
|
689
|
+
const after = asPolicyRecord(effect.after);
|
|
690
|
+
switch (effect.category) {
|
|
691
|
+
case "gate": {
|
|
692
|
+
const noGate = effect.after === null || effect.after === undefined;
|
|
693
|
+
if (noGate)
|
|
694
|
+
lines.push("Gate: no gate is stored.");
|
|
695
|
+
const kind = typeof after.kind === "string" && after.kind in GATE_LEAD_BY_KIND ? after.kind : null;
|
|
696
|
+
const beforeKind = before.kind;
|
|
697
|
+
const members = (Array.isArray(after.provider_checks) ? after.provider_checks : []);
|
|
698
|
+
const kindChanged = kind !== beforeKind;
|
|
699
|
+
const membersChanged = !policySame(after.provider_checks, before.provider_checks)
|
|
700
|
+
|| !policySame(after.local_commands, before.local_commands)
|
|
701
|
+
|| !policySame(after.migration_guard, before.migration_guard);
|
|
702
|
+
if (!noGate && (kindChanged || membersChanged)) {
|
|
703
|
+
// BAPI-1657: a consequence that already opens with its lead is printed once, without repeating the lead.
|
|
704
|
+
const lead = kind === null ? "changed" : GATE_LEAD_BY_KIND[kind];
|
|
705
|
+
if (options.brief === true)
|
|
706
|
+
lines.push(`Gate: ${lead}`);
|
|
707
|
+
else {
|
|
708
|
+
const consequence = kind === null ? "" : describeGateConsequence({ kind, hasWatchedChecks: members.some((c) => c.watched === true) }, ciFacts);
|
|
709
|
+
lines.push(consequence.startsWith(`${lead}:`) ? `Gate: ${consequence}` : `Gate: ${lead}.${consequence === "" ? "" : ` ${consequence}`}`);
|
|
710
|
+
}
|
|
711
|
+
// BAPI-1658: the summary names the kind, not what changed inside it. A member list that changed
|
|
712
|
+
// while the kind stayed the same, and a migration guard, each get their own line.
|
|
713
|
+
if (!kindChanged && !policySame(after.provider_checks, before.provider_checks))
|
|
714
|
+
lines.push("Provider checks: the list changed");
|
|
715
|
+
if (!kindChanged && !policySame(after.local_commands, before.local_commands))
|
|
716
|
+
lines.push("Local commands: the list changed");
|
|
717
|
+
if (!policySame(after.migration_guard, before.migration_guard)) {
|
|
718
|
+
lines.push(`Migration guard: ${isAbsentPolicyValue(after.migration_guard) ? "removed" : isAbsentPolicyValue(before.migration_guard) ? "added" : "changed"}`);
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
// BAPI-1658: compared on the whole value, so a value-only change is seen; only names are printed.
|
|
722
|
+
if (!policySameOrBothAbsent(after.worker_env, before.worker_env)) {
|
|
723
|
+
const names = workerEnvNames(after);
|
|
724
|
+
lines.push(`Worker environment: ${names.length === 0 ? "no variables are set" : `variables set by name: ${names.join(", ")}`}`);
|
|
725
|
+
}
|
|
726
|
+
for (const [key, area] of GATE_ANCILLARY_AREAS) {
|
|
727
|
+
if (policySameOrBothAbsent(after[key], before[key]))
|
|
728
|
+
continue;
|
|
729
|
+
lines.push(`${area}: ${isAbsentPolicyValue(after[key]) ? "removed" : isAbsentPolicyValue(before[key]) ? "added" : "changed"}`);
|
|
730
|
+
}
|
|
731
|
+
if (Object.keys({ ...before, ...after }).some((key) => !GATE_KNOWN_KEYS.has(key) && !policySame(before[key], after[key]))) {
|
|
732
|
+
lines.push("Gate: other gate details changed.");
|
|
733
|
+
}
|
|
734
|
+
break;
|
|
735
|
+
}
|
|
736
|
+
case "setup": {
|
|
737
|
+
if (!policySame(after.review_policy, before.review_policy)) {
|
|
738
|
+
const source = asPolicyRecord(after.review_policy).source;
|
|
739
|
+
lines.push(after.review_policy === null || after.review_policy === undefined
|
|
740
|
+
? "Review policy: no project default is stored"
|
|
741
|
+
: typeof source === "string" && Object.hasOwn(REVIEW_POLICY_WORDS, source) ? `Review policy: ${REVIEW_POLICY_WORDS[source]}` : "Review policy: changed");
|
|
742
|
+
}
|
|
743
|
+
if (!policySame(after.review_source, before.review_source)) {
|
|
744
|
+
lines.push(`Review source: ${after.review_source === null || after.review_source === undefined ? "not set" : String(after.review_source)}`);
|
|
745
|
+
}
|
|
746
|
+
if (!policySame(after.min_approvals, before.min_approvals)) {
|
|
747
|
+
lines.push(`Required approvals: ${after.min_approvals === null || after.min_approvals === undefined ? "not set" : String(after.min_approvals)}`);
|
|
748
|
+
}
|
|
749
|
+
break;
|
|
750
|
+
}
|
|
751
|
+
case "config": {
|
|
752
|
+
for (const key of Object.keys({ ...before, ...after })) {
|
|
753
|
+
if (policySame(before[key], after[key]))
|
|
754
|
+
continue;
|
|
755
|
+
const v = after[key];
|
|
756
|
+
if (key === "merge_approval_required") {
|
|
757
|
+
lines.push(v === true || v === "true" ? "Child merges: each one waits for your approval"
|
|
758
|
+
: v === false || v === "false" ? "Child merges: no approval is asked for" : "Child merges: approval setting is not set");
|
|
759
|
+
}
|
|
760
|
+
else if (key === "auto_merge_enabled")
|
|
761
|
+
lines.push(`Auto-merge: ${onOff(v)}`);
|
|
762
|
+
else if (key === "teardown_enabled")
|
|
763
|
+
lines.push(`Teardown after merge: ${onOff(v)}`);
|
|
764
|
+
else if (key === "auto_rereview_enabled")
|
|
765
|
+
lines.push(`Automatic re-review: ${onOff(v)}`);
|
|
766
|
+
else if (key === "merge_execution")
|
|
767
|
+
lines.push(`Who runs merges: ${String(v)}`);
|
|
768
|
+
else
|
|
769
|
+
lines.push(`Setting changed: ${key.replace(/_/g, " ")}`);
|
|
770
|
+
}
|
|
771
|
+
break;
|
|
772
|
+
}
|
|
773
|
+
case "sources": {
|
|
774
|
+
for (const key of ["setup", "config"]) {
|
|
775
|
+
if (policySame(before[key], after[key]))
|
|
776
|
+
continue;
|
|
777
|
+
const word = typeof after[key] === "string" ? SETTING_SOURCE_WORDS[after[key]] ?? "unrecognized" : "unrecognized";
|
|
778
|
+
lines.push(`Settings source (${key}): ${word}`);
|
|
779
|
+
}
|
|
780
|
+
break;
|
|
781
|
+
}
|
|
782
|
+
case "qualification":
|
|
783
|
+
lines.push(`Gate qualification: ${typeof effect.after === "string" && Object.hasOwn(QUALIFICATION_WORDS, effect.after) ? QUALIFICATION_WORDS[effect.after] : "changed"}`);
|
|
784
|
+
break;
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
return lines;
|
|
788
|
+
}
|
|
789
|
+
/**
|
|
790
|
+
* BAPI-1637 — the post-epic-branch-CI summary: what the STORED gate means for
|
|
791
|
+
* merges, in the same words readiness uses. Reads readiness once and renders the
|
|
792
|
+
* shared consequence from that response's stored gate and `epic_branch_ci` facts,
|
|
793
|
+
* never from local flags or the profile the setup just built. Advisory: a failed
|
|
794
|
+
* readiness read falls back to the stored gate alone (gate-only wording, no
|
|
795
|
+
* invented CI fact); if that read fails too, nothing is printed. Never throws and
|
|
796
|
+
* never prints a transport error.
|
|
797
|
+
*/
|
|
798
|
+
export async function runGateConsequenceSummary(io, access, gateDeps) {
|
|
799
|
+
let gate = null;
|
|
800
|
+
let ciFacts = null;
|
|
801
|
+
try {
|
|
802
|
+
const readiness = await (gateDeps?.fetchReadiness ?? fetchConductorReadiness)(access, io.fetchJson);
|
|
803
|
+
const profile = readiness.gate_profile;
|
|
804
|
+
if (profile !== undefined && profile !== null) {
|
|
805
|
+
gate = {
|
|
806
|
+
kind: profile.kind,
|
|
807
|
+
hasWatchedChecks: profile.provider_checks.some((check) => check.watched === true),
|
|
808
|
+
};
|
|
809
|
+
ciFacts = readiness.epic_branch_ci ?? null;
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
catch {
|
|
813
|
+
gate = null;
|
|
814
|
+
}
|
|
815
|
+
if (gate === null) {
|
|
816
|
+
try {
|
|
817
|
+
const stored = await fetchConductorGateProfile(access, io.fetchJson);
|
|
818
|
+
if (stored.confirmed && stored.profile !== null) {
|
|
819
|
+
gate = consequenceGate(desiredFromStored(stored.profile));
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
catch {
|
|
823
|
+
gate = null;
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
if (gate === null)
|
|
827
|
+
return;
|
|
828
|
+
const line = describeGateConsequence(gate, ciFacts);
|
|
829
|
+
if (line === "")
|
|
830
|
+
return;
|
|
831
|
+
io.log("");
|
|
832
|
+
io.log("What the stored gate means for merges:");
|
|
833
|
+
io.log(` ${line}`);
|
|
834
|
+
}
|
|
481
835
|
function describeHistory(proposal) {
|
|
482
836
|
switch (proposal.history.status) {
|
|
483
837
|
case "available":
|
|
@@ -746,15 +1100,28 @@ async function reviewSettingsInto(io, proposal, current, desired) {
|
|
|
746
1100
|
if (!prompt || !hasSettingsToReview(proposal, current.profile, desired.providerChecks)) {
|
|
747
1101
|
return { desired, changed: false };
|
|
748
1102
|
}
|
|
1103
|
+
if (usesSafeSettingDefaults(io)) {
|
|
1104
|
+
const selection = recommendedSettingsSelection(proposal, current.profile, desired.providerChecks);
|
|
1105
|
+
logSafeSettingReceipts(io, selection, current.profile, false);
|
|
1106
|
+
return {
|
|
1107
|
+
desired: { ...desired, ...settingsFieldsOf(selection.edit) },
|
|
1108
|
+
changed: !settingsMatchStored(selection.edit, current.profile),
|
|
1109
|
+
};
|
|
1110
|
+
}
|
|
749
1111
|
const edit = await reviewDiscoveredSettings({ log: io.log, promptLine: prompt }, proposal, current.profile, desired.providerChecks);
|
|
750
|
-
const merged = {
|
|
751
|
-
|
|
1112
|
+
const merged = { ...desired, ...settingsFieldsOf(edit) };
|
|
1113
|
+
return { desired: merged, changed: !settingsMatchStored(edit, current.profile) };
|
|
1114
|
+
}
|
|
1115
|
+
/** The desired-gate fields an edit sets; untouched settings stay omitted from the write. */
|
|
1116
|
+
function settingsFieldsOf(edit) {
|
|
1117
|
+
return {
|
|
752
1118
|
...(edit.workerEnv !== undefined ? { workerEnv: edit.workerEnv } : {}),
|
|
753
1119
|
...(edit.reproduce !== undefined ? { reproduce: edit.reproduce } : {}),
|
|
754
1120
|
...(edit.dependencyInstall !== undefined ? { dependencyInstall: edit.dependencyInstall } : {}),
|
|
755
1121
|
...(edit.ciDatabase !== undefined ? { ciDatabase: edit.ciDatabase } : {}),
|
|
1122
|
+
...(edit.mustOrderPaths !== undefined ? { mustOrderPaths: edit.mustOrderPaths } : {}),
|
|
1123
|
+
...(edit.workerDatabase !== undefined ? { workerDatabase: edit.workerDatabase } : {}),
|
|
756
1124
|
};
|
|
757
|
-
return { desired: merged, changed: !settingsMatchStored(edit, current.profile) };
|
|
758
1125
|
}
|
|
759
1126
|
/**
|
|
760
1127
|
* BAPI-1551 — keep the confirmed gate, and offer any unstored declaration
|
|
@@ -770,7 +1137,7 @@ async function keptGateWithDeclarations(io, current, currentDesired, gateDeps, o
|
|
|
770
1137
|
if (!offered.changed)
|
|
771
1138
|
return unchanged;
|
|
772
1139
|
renderGateComparison(io, current, offered.desired, []);
|
|
773
|
-
if (!options.planningOnly && !(await ask(io, "Store these worker setup declarations with the gate? [y/N]: "))) {
|
|
1140
|
+
if (!options.planningOnly && !usesSafeSettingDefaults(io) && !(await ask(io, "Store these worker setup declarations with the gate? [y/N]: "))) {
|
|
774
1141
|
io.log(" Declarations not stored; the stored gate and its settings are unchanged.");
|
|
775
1142
|
for (const key of offered.offeredKeys)
|
|
776
1143
|
options.declinedDeclarations?.add(key);
|
|
@@ -797,28 +1164,23 @@ async function keptGateWithDeclarations(io, current, currentDesired, gateDeps, o
|
|
|
797
1164
|
async function offerDeclarationChanges(io, current, desired, gateDeps, options) {
|
|
798
1165
|
const none = { desired, changed: false, offeredKeys: [] };
|
|
799
1166
|
const prompt = io.promptLine;
|
|
800
|
-
|
|
801
|
-
if (!prompt || !fs || options.dryRun || current.profile === null)
|
|
1167
|
+
if (!gateDeps?.discoveryFs || current.profile === null)
|
|
802
1168
|
return none;
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
1169
|
+
const safeDefaults = usesSafeSettingDefaults(io);
|
|
1170
|
+
// A dry run previews the safe selection but never reviews; a real run needs a reader or safe defaults.
|
|
1171
|
+
if (options.dryRun ? !safeDefaults : !prompt)
|
|
1172
|
+
return none;
|
|
1173
|
+
const proposal = await discoverDeclarationProposal(current, desired, gateDeps, options.declinedDeclarations);
|
|
1174
|
+
if (proposal === null)
|
|
808
1175
|
return none;
|
|
809
|
-
}
|
|
810
|
-
// Never re-offer what the owner already ignored or declined in this invocation.
|
|
811
1176
|
const declined = options.declinedDeclarations;
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
...(declarations.dependencyInstallNotes ? { dependencyInstallNotes: declarations.dependencyInstallNotes } : {}),
|
|
818
|
-
...(ci !== undefined && !declined?.has(ciDatabaseProposalKey(ci.value)) ? { ciDatabaseProposal: ci } : {}),
|
|
819
|
-
};
|
|
820
|
-
if (!hasUnstoredDeclarationProposal(proposal, current.profile))
|
|
1177
|
+
if (!hasUnstoredDeclarationProposal(proposal, current.profile)) {
|
|
1178
|
+
// BAPI-1580: discoveries the bound keeps from being offered are still named.
|
|
1179
|
+
const warning = mustOrderShortfallWarning(proposal, current.profile);
|
|
1180
|
+
if (warning !== null)
|
|
1181
|
+
io.log(warning);
|
|
821
1182
|
return none;
|
|
1183
|
+
}
|
|
822
1184
|
const offeredKeys = [
|
|
823
1185
|
...(proposal.dependencyInstallCandidates ?? [])
|
|
824
1186
|
.filter((c) => !(current.profile?.dependency_install ?? []).some((e) => dependencyInstallEqual([e], [c])))
|
|
@@ -827,7 +1189,29 @@ async function offerDeclarationChanges(io, current, desired, gateDeps, options)
|
|
|
827
1189
|
proposal.ciDatabaseProposal.value !== storedCiDatabase(current.profile)
|
|
828
1190
|
? [ciDatabaseProposalKey(proposal.ciDatabaseProposal.value)]
|
|
829
1191
|
: []),
|
|
1192
|
+
...mustOrderOffer(proposal, current.profile).offered.map(mustOrderProposalKey),
|
|
1193
|
+
...(proposal.workerDatabaseProposal !== undefined && current.profile.worker_database === undefined
|
|
1194
|
+
? [WORKER_DATABASE_PROPOSAL_KEY]
|
|
1195
|
+
: []),
|
|
830
1196
|
];
|
|
1197
|
+
if (safeDefaults) {
|
|
1198
|
+
const { edit: selected } = recommendedSettingsSelection(proposal, current.profile, desired.providerChecks);
|
|
1199
|
+
const edit = {
|
|
1200
|
+
...(selected.dependencyInstall !== undefined ? { dependencyInstall: selected.dependencyInstall } : {}),
|
|
1201
|
+
...(selected.ciDatabase !== undefined ? { ciDatabase: selected.ciDatabase } : {}),
|
|
1202
|
+
...(selected.mustOrderPaths !== undefined ? { mustOrderPaths: selected.mustOrderPaths } : {}),
|
|
1203
|
+
...(selected.workerDatabase !== undefined ? { workerDatabase: selected.workerDatabase } : {}),
|
|
1204
|
+
};
|
|
1205
|
+
io.log("");
|
|
1206
|
+
logSafeSettingReceipts(io, { edit, skipped: [] }, current.profile, options.dryRun);
|
|
1207
|
+
if (options.dryRun)
|
|
1208
|
+
return none;
|
|
1209
|
+
return {
|
|
1210
|
+
desired: { ...desired, ...settingsFieldsOf(edit) },
|
|
1211
|
+
changed: !settingsMatchStored(edit, current.profile),
|
|
1212
|
+
offeredKeys,
|
|
1213
|
+
};
|
|
1214
|
+
}
|
|
831
1215
|
io.log("");
|
|
832
1216
|
io.log(" Discovery proposes worker setup declarations this gate does not store yet (optional):");
|
|
833
1217
|
renderDeclarationsOnly(io, proposal, current.profile, true);
|
|
@@ -836,7 +1220,12 @@ async function offerDeclarationChanges(io, current, desired, gateDeps, options)
|
|
|
836
1220
|
...desired,
|
|
837
1221
|
...(edit.dependencyInstall !== undefined ? { dependencyInstall: edit.dependencyInstall } : {}),
|
|
838
1222
|
...(edit.ciDatabase !== undefined ? { ciDatabase: edit.ciDatabase } : {}),
|
|
1223
|
+
...(edit.mustOrderPaths !== undefined ? { mustOrderPaths: edit.mustOrderPaths } : {}),
|
|
1224
|
+
...(edit.workerDatabase !== undefined ? { workerDatabase: edit.workerDatabase } : {}),
|
|
839
1225
|
};
|
|
1226
|
+
if (proposal.workerDatabaseProposal !== undefined && edit.workerDatabase === undefined) {
|
|
1227
|
+
declined?.add(WORKER_DATABASE_PROPOSAL_KEY);
|
|
1228
|
+
}
|
|
840
1229
|
// A proposal the owner did not take is remembered as declined for this invocation.
|
|
841
1230
|
const resultingList = edit.dependencyInstall ?? current.profile.dependency_install ?? [];
|
|
842
1231
|
const resultingCi = edit.ciDatabase ?? storedCiDatabase(current.profile);
|
|
@@ -848,8 +1237,105 @@ async function offerDeclarationChanges(io, current, desired, gateDeps, options)
|
|
|
848
1237
|
if (proposal.ciDatabaseProposal !== undefined && proposal.ciDatabaseProposal.value !== resultingCi) {
|
|
849
1238
|
declined?.add(ciDatabaseProposalKey(proposal.ciDatabaseProposal.value));
|
|
850
1239
|
}
|
|
1240
|
+
const resultingMustOrder = edit.mustOrderPaths ?? current.profile.must_order_paths;
|
|
1241
|
+
for (const entry of mustOrderOffer(proposal, current.profile).offered) {
|
|
1242
|
+
if (!resultingMustOrder.includes(entry))
|
|
1243
|
+
declined?.add(mustOrderProposalKey(entry));
|
|
1244
|
+
}
|
|
851
1245
|
return { desired: merged, changed: !settingsMatchStored(edit, current.profile), offeredKeys };
|
|
852
1246
|
}
|
|
1247
|
+
/**
|
|
1248
|
+
* BAPI-1638 — the declaration discovery shared by the terminal offer and the
|
|
1249
|
+
* read-only planner. Reads repository files only: no prompt, no write. `null`
|
|
1250
|
+
* means there is nothing to discover from (no seam, no stored profile, or a
|
|
1251
|
+
* failed read). Discovery PROPOSES settings; it never authorizes the gate or a
|
|
1252
|
+
* declaration.
|
|
1253
|
+
*/
|
|
1254
|
+
async function discoverDeclarationProposal(current, desired, gateDeps, declined,
|
|
1255
|
+
/** The read-only planner also proposes declarations for a gate that is not stored yet. */
|
|
1256
|
+
allowUnstored = false) {
|
|
1257
|
+
const fs = gateDeps?.discoveryFs;
|
|
1258
|
+
if (!fs || (current.profile === null && !allowUnstored))
|
|
1259
|
+
return null;
|
|
1260
|
+
let declarations;
|
|
1261
|
+
try {
|
|
1262
|
+
declarations = await discoverDeclarations({ fs, providerChecks: desired.providerChecks });
|
|
1263
|
+
}
|
|
1264
|
+
catch {
|
|
1265
|
+
return null;
|
|
1266
|
+
}
|
|
1267
|
+
// Never re-offer what the owner already ignored or declined in this invocation.
|
|
1268
|
+
const candidates = (declarations.dependencyInstallCandidates ?? []).filter((c) => !declined?.has(dependencyProposalKey(c)));
|
|
1269
|
+
const ci = declarations.ciDatabaseProposal;
|
|
1270
|
+
const mustOrder = (declarations.mustOrderPathCandidates ?? []).filter((p) => !declined?.has(mustOrderProposalKey(p)));
|
|
1271
|
+
const workerDatabase = declarations.workerDatabaseProposal;
|
|
1272
|
+
return {
|
|
1273
|
+
...emptyProposal(),
|
|
1274
|
+
...(workerDatabase !== undefined && !declined?.has(WORKER_DATABASE_PROPOSAL_KEY)
|
|
1275
|
+
? { workerDatabaseProposal: workerDatabase }
|
|
1276
|
+
: {}),
|
|
1277
|
+
...(candidates.length > 0 ? { dependencyInstallCandidates: candidates } : {}),
|
|
1278
|
+
...(declarations.dependencyInstallNotes ? { dependencyInstallNotes: declarations.dependencyInstallNotes } : {}),
|
|
1279
|
+
...(ci !== undefined && !declined?.has(ciDatabaseProposalKey(ci.value)) ? { ciDatabaseProposal: ci } : {}),
|
|
1280
|
+
...(mustOrder.length > 0 ? { mustOrderPathCandidates: mustOrder } : {}),
|
|
1281
|
+
...(declarations.mustOrderPathOverflow !== undefined
|
|
1282
|
+
? { mustOrderPathOverflow: declarations.mustOrderPathOverflow }
|
|
1283
|
+
: {}),
|
|
1284
|
+
};
|
|
1285
|
+
}
|
|
1286
|
+
/**
|
|
1287
|
+
* BAPI-1638 — plan the worker-setup declarations without a terminal.
|
|
1288
|
+
*
|
|
1289
|
+
* Read-only: the same discovery and the same safe recommended selection the
|
|
1290
|
+
* terminal path uses, split into one entry per answer key. It asks nothing,
|
|
1291
|
+
* writes nothing, and never decides. An entry is a proposal the owner approves
|
|
1292
|
+
* or declines by its key; discovery alone authorizes nothing.
|
|
1293
|
+
*/
|
|
1294
|
+
export async function planDeclarationSelections(current, desired, gateDeps) {
|
|
1295
|
+
// A first install has no stored profile: its declarations are proposed with the
|
|
1296
|
+
// gate, so the first apply stores them before the learned check starts.
|
|
1297
|
+
const proposal = await discoverDeclarationProposal(current, desired, gateDeps, undefined, true);
|
|
1298
|
+
if (proposal === null)
|
|
1299
|
+
return [];
|
|
1300
|
+
if (!hasUnstoredDeclarationProposal(proposal, current.profile))
|
|
1301
|
+
return [];
|
|
1302
|
+
const { edit } = recommendedSettingsSelection(proposal, current.profile, desired.providerChecks);
|
|
1303
|
+
const entries = [];
|
|
1304
|
+
const stored = current.profile;
|
|
1305
|
+
if (edit.dependencyInstall !== undefined) {
|
|
1306
|
+
entries.push({
|
|
1307
|
+
key: "dependency_install",
|
|
1308
|
+
proposalKeys: (proposal.dependencyInstallCandidates ?? []).map(dependencyProposalKey),
|
|
1309
|
+
fields: { dependencyInstall: edit.dependencyInstall },
|
|
1310
|
+
summary: describeSettingsEdit({ dependencyInstall: edit.dependencyInstall }, stored),
|
|
1311
|
+
});
|
|
1312
|
+
}
|
|
1313
|
+
if (edit.ciDatabase !== undefined) {
|
|
1314
|
+
entries.push({
|
|
1315
|
+
key: "ci_database",
|
|
1316
|
+
proposalKeys: [ciDatabaseProposalKey(edit.ciDatabase)],
|
|
1317
|
+
fields: { ciDatabase: edit.ciDatabase },
|
|
1318
|
+
summary: describeSettingsEdit({ ciDatabase: edit.ciDatabase }, stored),
|
|
1319
|
+
});
|
|
1320
|
+
}
|
|
1321
|
+
if (edit.mustOrderPaths !== undefined) {
|
|
1322
|
+
entries.push({
|
|
1323
|
+
key: "must_order_paths",
|
|
1324
|
+
proposalKeys: mustOrderOffer(proposal, stored).offered.map(mustOrderProposalKey),
|
|
1325
|
+
fields: { mustOrderPaths: edit.mustOrderPaths },
|
|
1326
|
+
summary: describeSettingsEdit({ mustOrderPaths: edit.mustOrderPaths }, stored),
|
|
1327
|
+
});
|
|
1328
|
+
}
|
|
1329
|
+
if (edit.workerDatabase !== undefined) {
|
|
1330
|
+
entries.push({
|
|
1331
|
+
key: "worker_database",
|
|
1332
|
+
proposalKeys: [WORKER_DATABASE_PROPOSAL_KEY],
|
|
1333
|
+
fields: { workerDatabase: edit.workerDatabase },
|
|
1334
|
+
summary: describeSettingsEdit({ workerDatabase: edit.workerDatabase }, stored),
|
|
1335
|
+
});
|
|
1336
|
+
}
|
|
1337
|
+
return entries;
|
|
1338
|
+
}
|
|
853
1339
|
/** BAPI-1551 — a proposal's identity for the per-invocation declined set: the whole entry. */
|
|
854
1340
|
export function dependencyProposalKey(entry) {
|
|
855
1341
|
return `dependency_install:${JSON.stringify([entry.cwd, entry.argv, entry.lockfiles])}`;
|
|
@@ -858,6 +1344,12 @@ export function dependencyProposalKey(entry) {
|
|
|
858
1344
|
export function ciDatabaseProposalKey(value) {
|
|
859
1345
|
return `ci_database:${value}`;
|
|
860
1346
|
}
|
|
1347
|
+
/** BAPI-1598 — the declined-set key of the worker-database proposal. */
|
|
1348
|
+
export const WORKER_DATABASE_PROPOSAL_KEY = "worker_database:proposed";
|
|
1349
|
+
/** BAPI-1580 — the declined-set key of one must-order proposal. */
|
|
1350
|
+
export function mustOrderProposalKey(entry) {
|
|
1351
|
+
return `must_order_paths:${entry}`;
|
|
1352
|
+
}
|
|
861
1353
|
/**
|
|
862
1354
|
* Decide the repository gate for this run (BEFORE any write).
|
|
863
1355
|
*
|
|
@@ -915,21 +1407,13 @@ export async function resolveConductorGate(io, access, flags, gateDeps, options)
|
|
|
915
1407
|
io.log(" The confirmed gate already matches — no gate write is needed.");
|
|
916
1408
|
return { kind: "plan", plan: { current, desired: currentDesired, write: null, removals: [], origin: "stored" } };
|
|
917
1409
|
}
|
|
918
|
-
if (settingsChanged && !options.dryRun && !options.planningOnly) {
|
|
1410
|
+
if (settingsChanged && !options.dryRun && !options.planningOnly && !usesSafeSettingDefaults(io)) {
|
|
919
1411
|
const ok = await ask(io, "Store these CI settings with the gate? [y/N]: ");
|
|
920
1412
|
if (!ok) {
|
|
921
1413
|
io.errorLog("CI settings not confirmed — nothing was written, and the stored gate is unchanged.");
|
|
922
1414
|
return { kind: "exit", code: 1 };
|
|
923
1415
|
}
|
|
924
1416
|
}
|
|
925
|
-
if (removals.length > 0 && !flags.confirmGate && !options.dryRun && !options.planningOnly) {
|
|
926
|
-
const ok = await ask(io, "Confirm this gate, including the removals above? [y/N]: ");
|
|
927
|
-
if (!ok) {
|
|
928
|
-
io.errorLog("Gate change not confirmed — nothing was written, and the stored gate is unchanged.");
|
|
929
|
-
io.errorLog("Pass --confirm-gate to confirm a removal from a script.");
|
|
930
|
-
return { kind: "exit", code: 1 };
|
|
931
|
-
}
|
|
932
|
-
}
|
|
933
1417
|
return {
|
|
934
1418
|
kind: "plan",
|
|
935
1419
|
plan: {
|
|
@@ -941,8 +1425,8 @@ export async function resolveConductorGate(io, access, flags, gateDeps, options)
|
|
|
941
1425
|
},
|
|
942
1426
|
};
|
|
943
1427
|
}
|
|
944
|
-
if (options.
|
|
945
|
-
return
|
|
1428
|
+
if (options.inferCi === true) {
|
|
1429
|
+
return inferredCiPlan(io, access, current, currentDesired, gateDeps, options);
|
|
946
1430
|
}
|
|
947
1431
|
if (currentDesired !== null) {
|
|
948
1432
|
io.log(current.source === "legacy"
|
|
@@ -993,7 +1477,7 @@ export async function resolveConductorGate(io, access, flags, gateDeps, options)
|
|
|
993
1477
|
},
|
|
994
1478
|
};
|
|
995
1479
|
}
|
|
996
|
-
/** BAPI-1461 — `desired` with `check` added as a provider member (kept when present). */
|
|
1480
|
+
/** BAPI-1461 — `desired` with `check` added as a required provider member (kept when present). */
|
|
997
1481
|
function withProviderCheck(desired, check) {
|
|
998
1482
|
if (desired.providerChecks.includes(check))
|
|
999
1483
|
return desired;
|
|
@@ -1001,92 +1485,143 @@ function withProviderCheck(desired, check) {
|
|
|
1001
1485
|
return {
|
|
1002
1486
|
...desired,
|
|
1003
1487
|
providerChecks,
|
|
1488
|
+
// A name is never both required and watched.
|
|
1489
|
+
...(desired.watchedChecks !== undefined
|
|
1490
|
+
? { watchedChecks: desired.watchedChecks.filter((name) => name !== check) }
|
|
1491
|
+
: {}),
|
|
1004
1492
|
localCommands: desired.localCommands.map((c) => ({ ...c, argv: [...c.argv] })),
|
|
1005
1493
|
kind: kindForMembers(providerChecks, desired.localCommands),
|
|
1006
1494
|
};
|
|
1007
1495
|
}
|
|
1008
1496
|
/**
|
|
1009
|
-
* BAPI-
|
|
1497
|
+
* BAPI-1603 — the gate change that adds the managed workflow's check to the CURRENT
|
|
1498
|
+
* stored gate, for a caller that has just seen the setup pull request opened or
|
|
1499
|
+
* reused. Built from the profile read right now, so the server-promoted local
|
|
1500
|
+
* member and any watched checks are kept; the write names its expected revision.
|
|
1501
|
+
* `null` when the gate already requires the check, or there is no confirmed gate
|
|
1502
|
+
* to add it to.
|
|
1503
|
+
*/
|
|
1504
|
+
export function planManagedProviderGate(current, check) {
|
|
1505
|
+
if (!current.confirmed || current.profile === null)
|
|
1506
|
+
return null;
|
|
1507
|
+
const stored = desiredFromStored(current.profile);
|
|
1508
|
+
if (stored.providerChecks.includes(check))
|
|
1509
|
+
return null;
|
|
1510
|
+
const desired = withProviderCheck(stored, check);
|
|
1511
|
+
return {
|
|
1512
|
+
current,
|
|
1513
|
+
desired,
|
|
1514
|
+
write: confirmRequestFor(desired, current.revision, current.profile),
|
|
1515
|
+
removals: [],
|
|
1516
|
+
origin: "stored",
|
|
1517
|
+
};
|
|
1518
|
+
}
|
|
1519
|
+
/** The command-free gate setup starts from: no members, nothing to qualify. */
|
|
1520
|
+
function emptyDesiredGate() {
|
|
1521
|
+
return { kind: "none", providerChecks: [], localCommands: [], migrationGuard: null, customizedCommands: undefined };
|
|
1522
|
+
}
|
|
1523
|
+
/**
|
|
1524
|
+
* BAPI-1603 — the converging setup's gate decision when no gate flag was given.
|
|
1525
|
+
*
|
|
1526
|
+
* - A confirmed stored gate (provider, local, mixed, none, watched, or the
|
|
1527
|
+
* legacy `--required-check` form) is kept exactly as it is. Discovery can
|
|
1528
|
+
* still offer worker setup declarations, but never changes its members.
|
|
1529
|
+
* - A stored value that could not be read is NOT replaced: it is unknown, not
|
|
1530
|
+
* absent, so nothing is inferred and nothing is written.
|
|
1531
|
+
* - Otherwise the plan comes from facts, with no question:
|
|
1532
|
+
* reported provider checks ⇒ stored as WATCHED members (when the server can
|
|
1533
|
+
* store them), never as required ones, and never adding the managed check;
|
|
1534
|
+
* nothing reported ⇒ a command-free `none` gate, so the server's promotion of
|
|
1535
|
+
* a proven local command later lands on a stored profile.
|
|
1010
1536
|
*
|
|
1011
|
-
*
|
|
1012
|
-
* - A confirmed provider or mixed gate without it: the check is ADDED (every
|
|
1013
|
-
* member kept), shown against the stored gate, and stored later under the
|
|
1014
|
-
* combined gate-and-defaults consent.
|
|
1015
|
-
* - A confirmed local-only or `none` gate: changing its kind is a policy change,
|
|
1016
|
-
* so the comparison is shown and the owner is asked here. A decline keeps the
|
|
1017
|
-
* stored gate and is reported as an outstanding blocking fix.
|
|
1018
|
-
* - No confirmed gate: the discovery proposal plus the check, shown for the
|
|
1019
|
-
* combined consent. Nothing is stored here.
|
|
1537
|
+
* The write is planned, not made: it goes through the combined policy preview.
|
|
1020
1538
|
*/
|
|
1021
|
-
async function
|
|
1539
|
+
async function inferredCiPlan(io, access, current, currentDesired, gateDeps, options) {
|
|
1022
1540
|
if (currentDesired !== null) {
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1541
|
+
io.log(current.source === "legacy"
|
|
1542
|
+
? " Using the confirmed gate from this repository's existing --required-check setup."
|
|
1543
|
+
: ` Using the confirmed gate (revision ${current.revision}).`);
|
|
1544
|
+
for (const line of describeGate(currentDesired))
|
|
1545
|
+
io.log(line);
|
|
1546
|
+
return keptGateWithDeclarations(io, current, currentDesired, gateDeps, options);
|
|
1547
|
+
}
|
|
1548
|
+
const plan = (desired, write, inferred) => ({
|
|
1549
|
+
kind: "plan",
|
|
1550
|
+
plan: { current, desired, write, removals: [], origin: "inferred", inferred },
|
|
1551
|
+
});
|
|
1552
|
+
if (current.stored_malformed) {
|
|
1553
|
+
io.log(" The stored repository gate could not be read, so setup leaves it alone and plans nothing.");
|
|
1554
|
+
return plan(emptyDesiredGate(), null, {
|
|
1555
|
+
ciPlan: "none",
|
|
1556
|
+
reportedChecks: [],
|
|
1557
|
+
watchedWritable: false,
|
|
1558
|
+
watchedUnsupported: false,
|
|
1559
|
+
storedUnreadable: true,
|
|
1560
|
+
trialEligible: false,
|
|
1561
|
+
reasons: [],
|
|
1562
|
+
});
|
|
1563
|
+
}
|
|
1564
|
+
const proposal = await runGateDiscovery(io, access, gateDeps);
|
|
1565
|
+
const reported = reportedProviderChecks(proposal).slice(0, MAX_TYPED_CHECKS);
|
|
1566
|
+
if (reported.length === 0 && proposal.history.status === "unavailable") {
|
|
1567
|
+
// Unknown is not absent: a stored `none` would be kept on every rerun and
|
|
1568
|
+
// hide the repository's real CI for good. Store nothing and say why.
|
|
1569
|
+
io.log(" Bridge could not read this repository's CI history, so it cannot tell whether there is CI to watch. " +
|
|
1570
|
+
"It stores no gate now; run setup again when the history can be read.");
|
|
1571
|
+
return plan(emptyDesiredGate(), null, {
|
|
1572
|
+
ciPlan: "none",
|
|
1573
|
+
reportedChecks: [],
|
|
1574
|
+
watchedWritable: false,
|
|
1575
|
+
watchedUnsupported: false,
|
|
1576
|
+
storedUnreadable: false,
|
|
1577
|
+
trialEligible: false,
|
|
1578
|
+
reasons: [],
|
|
1579
|
+
});
|
|
1580
|
+
}
|
|
1581
|
+
if (reported.length === 0) {
|
|
1582
|
+
const desired = emptyDesiredGate();
|
|
1034
1583
|
renderGateComparison(io, current, desired, []);
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
...currentDesired,
|
|
1046
|
-
...(desired.dependencyInstall !== undefined ? { dependencyInstall: desired.dependencyInstall } : {}),
|
|
1047
|
-
...(desired.ciDatabase !== undefined ? { ciDatabase: desired.ciDatabase } : {}),
|
|
1048
|
-
};
|
|
1049
|
-
return {
|
|
1050
|
-
kind: "plan",
|
|
1051
|
-
plan: {
|
|
1052
|
-
current,
|
|
1053
|
-
desired: kept,
|
|
1054
|
-
write: offered.changed ? confirmRequestFor(kept, current.revision, current.profile) : null,
|
|
1055
|
-
removals: [],
|
|
1056
|
-
origin: "stored",
|
|
1057
|
-
},
|
|
1058
|
-
ensureDeclined: true,
|
|
1059
|
-
};
|
|
1060
|
-
}
|
|
1061
|
-
}
|
|
1062
|
-
}
|
|
1063
|
-
return {
|
|
1064
|
-
kind: "plan",
|
|
1065
|
-
plan: {
|
|
1066
|
-
current,
|
|
1067
|
-
desired,
|
|
1068
|
-
write: confirmRequestFor(desired, current.revision, current.profile),
|
|
1069
|
-
removals: [],
|
|
1070
|
-
origin: "stored",
|
|
1071
|
-
},
|
|
1072
|
-
};
|
|
1584
|
+
return plan(desired, confirmRequestFor(desired, current.revision, current.profile), {
|
|
1585
|
+
ciPlan: "none",
|
|
1586
|
+
reportedChecks: [],
|
|
1587
|
+
watchedWritable: false,
|
|
1588
|
+
watchedUnsupported: false,
|
|
1589
|
+
storedUnreadable: false,
|
|
1590
|
+
trialEligible: true,
|
|
1591
|
+
// BAPI-1654: missing reported checks, said as such. It is not proof the repository has no CI.
|
|
1592
|
+
reasons: ["No CI checks have reported on this repository yet."],
|
|
1593
|
+
});
|
|
1073
1594
|
}
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1595
|
+
// Reported checks exist. Whether the server can store them as watched is a
|
|
1596
|
+
// separate fact; an older one is never given a required-check or `none` stand-in.
|
|
1597
|
+
const watchedCapability = await probeConductorGateProfileWatchedCapability(access, io.fetchJson);
|
|
1598
|
+
if (!watchedCapability.supported) {
|
|
1599
|
+
io.log(` Bridge found ${reported.length} CI check(s) but this server cannot store watched checks, so it ` +
|
|
1600
|
+
"stores no CI checks for now. Nothing was replaced; update the Bridge API, then run setup again.");
|
|
1601
|
+
return plan(emptyDesiredGate(), null, {
|
|
1602
|
+
ciPlan: "watched",
|
|
1603
|
+
reportedChecks: reported,
|
|
1604
|
+
watchedWritable: false,
|
|
1605
|
+
watchedUnsupported: true,
|
|
1606
|
+
storedUnreadable: false,
|
|
1607
|
+
trialEligible: true,
|
|
1608
|
+
reasons: [],
|
|
1609
|
+
});
|
|
1610
|
+
}
|
|
1611
|
+
const desired = { ...emptyDesiredGate(), watchedChecks: reported };
|
|
1079
1612
|
renderGateComparison(io, current, desired, []);
|
|
1080
|
-
return {
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1613
|
+
return plan(desired, confirmRequestFor(desired, current.revision, current.profile), {
|
|
1614
|
+
ciPlan: "watched",
|
|
1615
|
+
reportedChecks: reported,
|
|
1616
|
+
watchedWritable: true,
|
|
1617
|
+
watchedUnsupported: false,
|
|
1618
|
+
storedUnreadable: false,
|
|
1619
|
+
trialEligible: true,
|
|
1620
|
+
reasons: [
|
|
1621
|
+
"Bridge found CI checks that have already reported on this repository. It watches them: one that " +
|
|
1622
|
+
"finishes red stops a merge, and one that is missing only warns.",
|
|
1623
|
+
],
|
|
1624
|
+
});
|
|
1090
1625
|
}
|
|
1091
1626
|
const GATE_WRITE_REFUSAL_TEXT = Object.freeze({
|
|
1092
1627
|
"stale-revision": "the stored gate changed since it was read. Re-run to see the current gate.",
|
|
@@ -1100,7 +1635,7 @@ const GATE_WRITE_REFUSAL_TEXT = Object.freeze({
|
|
|
1100
1635
|
server: "the Bridge API reported an internal error.",
|
|
1101
1636
|
rejected: "the Bridge API rejected the request.",
|
|
1102
1637
|
"extension-unsupported": "this server is older than the installer and cannot store worker variables, reproduction hints, " +
|
|
1103
|
-
"dependency refresh declarations,
|
|
1638
|
+
"dependency refresh declarations, CI database behavior, or must-order paths.",
|
|
1104
1639
|
});
|
|
1105
1640
|
/** Plain-language text for each closed `worker_env` refusal reason (BAPI-1520). */
|
|
1106
1641
|
const WORKER_ENV_REASON_TEXT = Object.freeze({
|
|
@@ -1109,22 +1644,37 @@ const WORKER_ENV_REASON_TEXT = Object.freeze({
|
|
|
1109
1644
|
worker_env_secret_name: "looks secret. Drop it, or confirm its committed-literal assertion individually, then confirm again.",
|
|
1110
1645
|
worker_env_duplicate: "appears more than once. Keep one entry, then confirm again.",
|
|
1111
1646
|
});
|
|
1112
|
-
/** The request without the BAPI-1520 and BAPI-
|
|
1647
|
+
/** The request without the BAPI-1520, BAPI-1551, and BAPI-1580 extension fields, and what it dropped. */
|
|
1113
1648
|
function withoutExtensions(request) {
|
|
1114
1649
|
const workerEnvNames = (request.worker_env ?? []).map((e) => e.name);
|
|
1115
1650
|
const hintChecks = (request.provider_checks ?? [])
|
|
1116
1651
|
.filter((c) => c.reproduce !== undefined)
|
|
1117
1652
|
.map((c) => c.name);
|
|
1118
|
-
const { worker_env: _dropped, dependency_install: _install, ci_database: _database, ...rest } = request;
|
|
1653
|
+
const { worker_env: _dropped, dependency_install: _install, ci_database: _database, must_order_paths: _mustOrder, worker_database: _workerDatabase, verification_handoff_default: _handoff, ...rest } = request;
|
|
1119
1654
|
void _dropped;
|
|
1120
1655
|
void _install;
|
|
1121
1656
|
void _database;
|
|
1657
|
+
void _mustOrder;
|
|
1658
|
+
void _workerDatabase;
|
|
1659
|
+
void _handoff;
|
|
1122
1660
|
return {
|
|
1661
|
+
...(request.worker_database !== undefined || request.verification_handoff_default !== undefined
|
|
1662
|
+
? { workerDatabase: true }
|
|
1663
|
+
: {}),
|
|
1123
1664
|
...(request.dependency_install !== undefined ? { dependencyInstall: request.dependency_install } : {}),
|
|
1124
1665
|
...(request.ci_database !== undefined ? { ciDatabase: request.ci_database } : {}),
|
|
1666
|
+
...(request.must_order_paths !== undefined ? { mustOrderPaths: request.must_order_paths } : {}),
|
|
1125
1667
|
request: {
|
|
1126
1668
|
...rest,
|
|
1127
|
-
...(request.provider_checks
|
|
1669
|
+
...(request.provider_checks
|
|
1670
|
+
? {
|
|
1671
|
+
provider_checks: request.provider_checks.map((c) => ({
|
|
1672
|
+
name: c.name,
|
|
1673
|
+
// Dropping a hint must never change a check's membership.
|
|
1674
|
+
...(c.watched !== undefined ? { watched: c.watched } : {}),
|
|
1675
|
+
})),
|
|
1676
|
+
}
|
|
1677
|
+
: {}),
|
|
1128
1678
|
},
|
|
1129
1679
|
workerEnvNames,
|
|
1130
1680
|
hintChecks,
|
|
@@ -1145,23 +1695,55 @@ export async function storeConductorGate(io, access, plan) {
|
|
|
1145
1695
|
gateMatchesStored(plan.desired, desiredFromStored(plan.current.profile), plan.current.profile)) {
|
|
1146
1696
|
return plan.current;
|
|
1147
1697
|
}
|
|
1148
|
-
|
|
1698
|
+
// BAPI-1598: the worker-database and hand-off settings are optional. A server
|
|
1699
|
+
// that does not advertise their capability gets the request without them, and the
|
|
1700
|
+
// owner is told they were not configured. Never a setup or launch stop.
|
|
1701
|
+
let write = plan.write;
|
|
1702
|
+
let workerSetupSkipped = false;
|
|
1703
|
+
if (write.worker_database !== undefined || write.verification_handoff_default !== undefined) {
|
|
1704
|
+
const probe = await probeConductorGateProfileWorkerSetupCapability(access, io.fetchJson);
|
|
1705
|
+
if (!probe.supported) {
|
|
1706
|
+
const { worker_database: _workerDatabase, verification_handoff_default: _handoff, ...rest } = write;
|
|
1707
|
+
void _workerDatabase;
|
|
1708
|
+
void _handoff;
|
|
1709
|
+
write = rest;
|
|
1710
|
+
workerSetupSkipped = true;
|
|
1711
|
+
if (plan.current.source === "stored" &&
|
|
1712
|
+
plan.current.profile !== null &&
|
|
1713
|
+
gateMatchesStored({ ...plan.desired, workerDatabase: undefined }, desiredFromStored(plan.current.profile), plan.current.profile)) {
|
|
1714
|
+
reportUnsavedSettings(io, { workerEnvNames: [], hintChecks: [], workerDatabase: true });
|
|
1715
|
+
io.log(" The gate itself already matched, so nothing was written.");
|
|
1716
|
+
return plan.current;
|
|
1717
|
+
}
|
|
1718
|
+
}
|
|
1719
|
+
}
|
|
1720
|
+
let outcome = await putConductorGateProfile(access, write, io.postJson);
|
|
1149
1721
|
// BAPI-1520: an older server rejects exactly the extension fields it does not
|
|
1150
1722
|
// know. Retry ONCE without them, keep everything else the owner approved, and
|
|
1151
1723
|
// report what was not stored by name.
|
|
1152
1724
|
let unsaved = null;
|
|
1153
1725
|
if (!outcome.ok && outcome.refusal === "extension-unsupported") {
|
|
1154
|
-
const stripped = withoutExtensions(
|
|
1726
|
+
const stripped = withoutExtensions(write);
|
|
1155
1727
|
unsaved = {
|
|
1156
1728
|
workerEnvNames: stripped.workerEnvNames,
|
|
1157
1729
|
hintChecks: stripped.hintChecks,
|
|
1158
1730
|
...(stripped.dependencyInstall !== undefined ? { dependencyInstall: stripped.dependencyInstall } : {}),
|
|
1159
1731
|
...(stripped.ciDatabase !== undefined ? { ciDatabase: stripped.ciDatabase } : {}),
|
|
1732
|
+
...(stripped.mustOrderPaths !== undefined ? { mustOrderPaths: stripped.mustOrderPaths } : {}),
|
|
1733
|
+
...(stripped.workerDatabase !== undefined ? { workerDatabase: true } : {}),
|
|
1160
1734
|
};
|
|
1161
1735
|
const storedDesired = plan.current.profile !== null ? desiredFromStored(plan.current.profile) : null;
|
|
1162
1736
|
const membersUnchanged = plan.current.source === "stored" &&
|
|
1163
1737
|
storedDesired !== null &&
|
|
1164
|
-
gateMatchesStored({
|
|
1738
|
+
gateMatchesStored({
|
|
1739
|
+
...plan.desired,
|
|
1740
|
+
workerEnv: undefined,
|
|
1741
|
+
reproduce: undefined,
|
|
1742
|
+
dependencyInstall: undefined,
|
|
1743
|
+
ciDatabase: undefined,
|
|
1744
|
+
mustOrderPaths: undefined,
|
|
1745
|
+
workerDatabase: undefined,
|
|
1746
|
+
}, storedDesired);
|
|
1165
1747
|
if (membersUnchanged) {
|
|
1166
1748
|
reportUnsavedSettings(io, unsaved);
|
|
1167
1749
|
io.log(" The gate itself already matched, so nothing was written.");
|
|
@@ -1169,6 +1751,39 @@ export async function storeConductorGate(io, access, plan) {
|
|
|
1169
1751
|
}
|
|
1170
1752
|
outcome = await putConductorGateProfile(access, stripped.request, io.postJson);
|
|
1171
1753
|
}
|
|
1754
|
+
if (!outcome.ok && (outcome.refusal === "network" || outcome.refusal === "timeout" || outcome.refusal === "server")) {
|
|
1755
|
+
// BAPI-1638 — an ambiguous answer may have stored the gate. Reconcile with one
|
|
1756
|
+
// authoritative read before saying anything was or was not written; never retry blindly.
|
|
1757
|
+
// Compare against what was actually SENT: a narrowed request leaves out the fields it stripped.
|
|
1758
|
+
const sentDesired = {
|
|
1759
|
+
...plan.desired,
|
|
1760
|
+
...(workerSetupSkipped || unsaved?.workerDatabase === true ? { workerDatabase: undefined } : {}),
|
|
1761
|
+
...(unsaved !== null
|
|
1762
|
+
? { workerEnv: undefined, reproduce: undefined, dependencyInstall: undefined, ciDatabase: undefined, mustOrderPaths: undefined }
|
|
1763
|
+
: {}),
|
|
1764
|
+
};
|
|
1765
|
+
let reread = null;
|
|
1766
|
+
try {
|
|
1767
|
+
reread = await fetchConductorGateProfile(access, io.fetchJson);
|
|
1768
|
+
}
|
|
1769
|
+
catch {
|
|
1770
|
+
reread = null;
|
|
1771
|
+
}
|
|
1772
|
+
if (reread !== null && reread.revision > plan.current.revision && reread.confirmed && reread.profile !== null
|
|
1773
|
+
&& gateMatchesStored(sentDesired, desiredFromStored(reread.profile), reread.profile)) {
|
|
1774
|
+
io.log(` stored repository gate: ${reread.profile.kind ?? "none"} (revision ${reread.revision}; confirmed by reading it back)`);
|
|
1775
|
+
if (unsaved !== null)
|
|
1776
|
+
reportUnsavedSettings(io, unsaved);
|
|
1777
|
+
else if (workerSetupSkipped)
|
|
1778
|
+
reportUnsavedSettings(io, { workerEnvNames: [], hintChecks: [], workerDatabase: true });
|
|
1779
|
+
return reread;
|
|
1780
|
+
}
|
|
1781
|
+
if (reread === null) {
|
|
1782
|
+
io.errorLog(`Repository gate write uncertain (${outcome.refusal}): ${GATE_WRITE_REFUSAL_TEXT[outcome.refusal]}`);
|
|
1783
|
+
io.errorLog(" It may or may not have been stored, and it could not be read back. Read the gate before retrying.");
|
|
1784
|
+
return null;
|
|
1785
|
+
}
|
|
1786
|
+
}
|
|
1172
1787
|
if (!outcome.ok) {
|
|
1173
1788
|
io.errorLog(`Repository gate not stored (${outcome.refusal}): ${GATE_WRITE_REFUSAL_TEXT[outcome.refusal]}`);
|
|
1174
1789
|
const reason = outcome.detail?.reason;
|
|
@@ -1196,6 +1811,8 @@ export async function storeConductorGate(io, access, plan) {
|
|
|
1196
1811
|
io.log(` stored repository gate: ${outcome.profile.profile?.kind ?? "none"} (revision ${outcome.profile.revision})`);
|
|
1197
1812
|
if (unsaved !== null)
|
|
1198
1813
|
reportUnsavedSettings(io, unsaved);
|
|
1814
|
+
else if (workerSetupSkipped)
|
|
1815
|
+
reportUnsavedSettings(io, { workerEnvNames: [], hintChecks: [], workerDatabase: true });
|
|
1199
1816
|
return outcome.profile;
|
|
1200
1817
|
}
|
|
1201
1818
|
/**
|
|
@@ -1221,6 +1838,16 @@ function describeUnsentDeclarations(write) {
|
|
|
1221
1838
|
if (write.ci_database !== undefined) {
|
|
1222
1839
|
lines.push(` Not stored — CI database behavior: ${write.ci_database ?? "unknown (reset)"}`);
|
|
1223
1840
|
}
|
|
1841
|
+
if (write.worker_database !== undefined) {
|
|
1842
|
+
// Never the declaration itself: its identifiers and command stay in admin output.
|
|
1843
|
+
lines.push(" Not stored — worker database setup. Nothing else about setup or launch depends on it.");
|
|
1844
|
+
}
|
|
1845
|
+
if (write.must_order_paths !== undefined) {
|
|
1846
|
+
const paths = write.must_order_paths ?? [];
|
|
1847
|
+
lines.push(paths.length === 0
|
|
1848
|
+
? " Not stored — must-order paths: clear every stored entry"
|
|
1849
|
+
: ` Not stored — must-order paths (re-enter them to keep them): ${paths.map(terminalSafe).join(", ")}`);
|
|
1850
|
+
}
|
|
1224
1851
|
return lines;
|
|
1225
1852
|
}
|
|
1226
1853
|
/**
|
|
@@ -1231,7 +1858,9 @@ function reportUnsavedSettings(io, unsaved) {
|
|
|
1231
1858
|
if (unsaved.workerEnvNames.length === 0 &&
|
|
1232
1859
|
unsaved.hintChecks.length === 0 &&
|
|
1233
1860
|
unsaved.dependencyInstall === undefined &&
|
|
1234
|
-
unsaved.ciDatabase === undefined
|
|
1861
|
+
unsaved.ciDatabase === undefined &&
|
|
1862
|
+
unsaved.mustOrderPaths === undefined &&
|
|
1863
|
+
unsaved.workerDatabase === undefined) {
|
|
1235
1864
|
return;
|
|
1236
1865
|
}
|
|
1237
1866
|
io.log(" ⚠ Partly stored: this server is older than the installer and cannot store these settings.");
|
|
@@ -1244,6 +1873,8 @@ function reportUnsavedSettings(io, unsaved) {
|
|
|
1244
1873
|
for (const line of describeUnsentDeclarations({
|
|
1245
1874
|
...(unsaved.dependencyInstall !== undefined ? { dependency_install: unsaved.dependencyInstall } : {}),
|
|
1246
1875
|
...(unsaved.ciDatabase !== undefined ? { ci_database: unsaved.ciDatabase } : {}),
|
|
1876
|
+
...(unsaved.mustOrderPaths !== undefined ? { must_order_paths: unsaved.mustOrderPaths } : {}),
|
|
1877
|
+
...(unsaved.workerDatabase !== undefined ? { worker_database: { mode: "none" } } : {}),
|
|
1247
1878
|
})) {
|
|
1248
1879
|
io.log(line);
|
|
1249
1880
|
}
|
|
@@ -1294,9 +1925,33 @@ function reportJob(io, job) {
|
|
|
1294
1925
|
return "qualified";
|
|
1295
1926
|
}
|
|
1296
1927
|
if (job.job_status === "succeeded") {
|
|
1928
|
+
// BAPI-1637: the phase is the server's reading of the stored result. The gate
|
|
1929
|
+
// stays unqualified in every branch, and each says so.
|
|
1930
|
+
if (job.phase === "dependency_preparation_failed") {
|
|
1931
|
+
io.errorLog(` Failed — ${DEPENDENCY_INSTALL_FAILED_TEXT} The local gate stays unqualified, so unattended ` +
|
|
1932
|
+
"auto-merge stays closed.");
|
|
1933
|
+
io.errorLog(` ${DEPENDENCY_INSTALL_REPAIR_TEXT}`);
|
|
1934
|
+
io.errorLog(` Qualify again: ${PRINTED_QUALIFY_GATE_COMMAND}`);
|
|
1935
|
+
return "failed";
|
|
1936
|
+
}
|
|
1937
|
+
if (job.phase === "could_not_start") {
|
|
1938
|
+
io.errorLog(` Failed — ${COULD_NOT_START_TEXT} The local gate stays unqualified, so unattended auto-merge ` +
|
|
1939
|
+
"stays closed.");
|
|
1940
|
+
io.errorLog(` ${CHANGE_TEST_COMMAND_HINT} Then qualify again: ${PRINTED_QUALIFY_GATE_COMMAND}`);
|
|
1941
|
+
return "failed";
|
|
1942
|
+
}
|
|
1943
|
+
if (job.phase === null && job.dependency_install_declared === true) {
|
|
1944
|
+
io.errorLog(` Failed — ${PREPARATION_UNCERTAIN_TEXT} The local gate stays unqualified, so unattended ` +
|
|
1945
|
+
"auto-merge stays closed.");
|
|
1946
|
+
io.errorLog(` ${PREPARATION_UNCERTAIN_REPAIR_TEXT} Then qualify again: ${PRINTED_QUALIFY_GATE_COMMAND}`);
|
|
1947
|
+
return "failed";
|
|
1948
|
+
}
|
|
1297
1949
|
io.errorLog(" Failed — a confirmed command did not pass under the executor. The installation itself " +
|
|
1298
1950
|
"succeeded, but the local gate stays unqualified, so unattended auto-merge stays closed.");
|
|
1299
1951
|
io.errorLog(` Fix the command, then qualify again: ${PRINTED_QUALIFY_GATE_COMMAND}`);
|
|
1952
|
+
if (job.phase === "ran_and_failed" && job.dependency_install_declared === false) {
|
|
1953
|
+
io.errorLog(` ${MISSING_INSTALL_TEXT}`);
|
|
1954
|
+
}
|
|
1300
1955
|
return "failed";
|
|
1301
1956
|
}
|
|
1302
1957
|
io.errorLog(` Failed — the executor could not run job ${job.job_id} (no clean default-branch checkout, ` +
|
|
@@ -1387,6 +2042,268 @@ export async function runConductorGateQualification(io, access, gateDeps, input)
|
|
|
1387
2042
|
return reportJob(io, latest);
|
|
1388
2043
|
}
|
|
1389
2044
|
// ---------------------------------------------------------------------------
|
|
2045
|
+
// BAPI-1603: the learned test command, proven by a server-owned trial
|
|
2046
|
+
// ---------------------------------------------------------------------------
|
|
2047
|
+
//
|
|
2048
|
+
// Setup never asks for a test command and never stores one itself. It asks the
|
|
2049
|
+
// server to find the command from the repository's learned prose (or to validate
|
|
2050
|
+
// the owner's `--test-command`), the server queues one TRIAL qualification, the
|
|
2051
|
+
// short-lived executor drains it, and the server promotes the local member only if
|
|
2052
|
+
// every command passes. Success is read from the validated job and a fresh read of
|
|
2053
|
+
// the gate profile, never from the executor's exit status, and the client writes no
|
|
2054
|
+
// local member. Anything uncertain is reconciled by re-reading authoritative state
|
|
2055
|
+
// before anything else happens, and the request is never repeated automatically.
|
|
2056
|
+
/** How often a running trial prints one plain progress line. */
|
|
2057
|
+
export const LEARNED_TRIAL_PROGRESS_INTERVAL_MS = 10_000;
|
|
2058
|
+
/** The commands a profile's local members run, by digest, in order. */
|
|
2059
|
+
function localDigests(profile) {
|
|
2060
|
+
return (profile?.local_commands ?? []).map((c) => c.digest).join(",");
|
|
2061
|
+
}
|
|
2062
|
+
/**
|
|
2063
|
+
* Whether `read` shows the trial's promotion: a confirmed profile with local
|
|
2064
|
+
* commands that differ from the ones the trial started with, qualified at its own
|
|
2065
|
+
* revision, past the revision the trial was bound to.
|
|
2066
|
+
*/
|
|
2067
|
+
function promotionObserved(read, input) {
|
|
2068
|
+
if (read === null || !read.confirmed || read.profile === null)
|
|
2069
|
+
return false;
|
|
2070
|
+
if (read.profile.local_commands.length === 0)
|
|
2071
|
+
return false;
|
|
2072
|
+
if (read.qualification_state !== "qualified")
|
|
2073
|
+
return false;
|
|
2074
|
+
if (read.revision <= input.current.revision)
|
|
2075
|
+
return false;
|
|
2076
|
+
return localDigests(read.profile) !== localDigests(input.current.profile);
|
|
2077
|
+
}
|
|
2078
|
+
async function readGateProfileOrNull(io, access) {
|
|
2079
|
+
try {
|
|
2080
|
+
return await fetchConductorGateProfile(access, io.fetchJson);
|
|
2081
|
+
}
|
|
2082
|
+
catch {
|
|
2083
|
+
return null;
|
|
2084
|
+
}
|
|
2085
|
+
}
|
|
2086
|
+
/**
|
|
2087
|
+
* Ask the server for the learned (or owner-supplied) test command, drain the trial
|
|
2088
|
+
* it queues, and report only what the server and a fresh profile read confirm.
|
|
2089
|
+
* Never throws and never writes a gate: an unqualified, stale, or could-not-run
|
|
2090
|
+
* trial leaves the profile exactly as the server holds it.
|
|
2091
|
+
*/
|
|
2092
|
+
export async function runLearnedTestCommandTrial(io, access, gateDeps, input) {
|
|
2093
|
+
const requestedSource = input.ownerCommand !== undefined ? "owner" : "learned";
|
|
2094
|
+
const posted = await requestConductorLearnedTestCommand(access, {
|
|
2095
|
+
expectedRevision: input.current.revision,
|
|
2096
|
+
...(input.candidates !== undefined ? { candidates: input.candidates } : {}),
|
|
2097
|
+
...(input.ownerCommand !== undefined ? { ownerCommand: input.ownerCommand } : {}),
|
|
2098
|
+
}, io.postJson);
|
|
2099
|
+
switch (posted.kind) {
|
|
2100
|
+
case "not_needed":
|
|
2101
|
+
case "stale_revision":
|
|
2102
|
+
case "unsupported":
|
|
2103
|
+
return { status: posted.kind };
|
|
2104
|
+
case "state_unavailable":
|
|
2105
|
+
return { status: "unavailable" };
|
|
2106
|
+
case "refused":
|
|
2107
|
+
return { status: "refused", reason: posted.reason };
|
|
2108
|
+
case "no_command":
|
|
2109
|
+
return { status: "no_command", source: posted.source, reason: posted.reason };
|
|
2110
|
+
case "uncertain":
|
|
2111
|
+
case "malformed": {
|
|
2112
|
+
// The request may have queued a trial and even finished it. Read the
|
|
2113
|
+
// authoritative profile before anything else.
|
|
2114
|
+
const read = await readGateProfileOrNull(io, access);
|
|
2115
|
+
if (promotionObserved(read, input)) {
|
|
2116
|
+
return { status: "promoted", source: requestedSource, commands: [], profile: read };
|
|
2117
|
+
}
|
|
2118
|
+
return { status: "uncertain", reason: "request_unclear", profile: read };
|
|
2119
|
+
}
|
|
2120
|
+
case "qualification_queued":
|
|
2121
|
+
break;
|
|
2122
|
+
}
|
|
2123
|
+
const { source, jobId, commands } = posted;
|
|
2124
|
+
const reconcile = async (reason) => {
|
|
2125
|
+
const read = await readGateProfileOrNull(io, access);
|
|
2126
|
+
if (promotionObserved(read, input))
|
|
2127
|
+
return { status: "promoted", source, commands, profile: read };
|
|
2128
|
+
return { status: "uncertain", reason, profile: read };
|
|
2129
|
+
};
|
|
2130
|
+
let job = await readJob(io, access, jobId);
|
|
2131
|
+
if (job === null)
|
|
2132
|
+
return reconcile("job_unreadable");
|
|
2133
|
+
if (!isTerminal(job)) {
|
|
2134
|
+
const runExecutor = gateDeps?.runQualificationExecutor;
|
|
2135
|
+
if (!runExecutor) {
|
|
2136
|
+
io.errorLog(" The trial is queued and needs a repository-wide executor to run it:");
|
|
2137
|
+
executorRemedy(io);
|
|
2138
|
+
return reconcile("executor_not_run");
|
|
2139
|
+
}
|
|
2140
|
+
io.log(" Running it once on this computer, in a clean checkout of your default branch…");
|
|
2141
|
+
// One progress notice covers the whole wait: the run itself and the polling that follows it.
|
|
2142
|
+
const progressTimer = gateDeps?.progressTimer ?? {
|
|
2143
|
+
...createSetupProgressTimer(),
|
|
2144
|
+
intervalMs: gateDeps?.progressIntervalMs ?? LEARNED_TRIAL_PROGRESS_INTERVAL_MS,
|
|
2145
|
+
};
|
|
2146
|
+
const { run, latest } = await withSetupProgress("checking the test command", async () => {
|
|
2147
|
+
let ran;
|
|
2148
|
+
try {
|
|
2149
|
+
ran = await runExecutor({ repoName: access.repoName, baseUrl: input.baseUrl });
|
|
2150
|
+
}
|
|
2151
|
+
catch {
|
|
2152
|
+
ran = { started: false, exitCode: 1 };
|
|
2153
|
+
}
|
|
2154
|
+
// The exit code proves nothing: read the server.
|
|
2155
|
+
const now = gateDeps?.now ?? (() => Date.now());
|
|
2156
|
+
const sleep = gateDeps?.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
|
|
2157
|
+
const deadline = now() + QUALIFICATION_OBSERVATION_BUDGET_MS;
|
|
2158
|
+
let seen = null;
|
|
2159
|
+
while (true) {
|
|
2160
|
+
const read = await readJob(io, access, jobId);
|
|
2161
|
+
if (read !== null)
|
|
2162
|
+
seen = read;
|
|
2163
|
+
if (seen !== null && isTerminal(seen))
|
|
2164
|
+
break;
|
|
2165
|
+
// A queued job after the executor returned will not move on its own here.
|
|
2166
|
+
if (seen !== null && seen.job_status === "queued")
|
|
2167
|
+
break;
|
|
2168
|
+
const remaining = deadline - now();
|
|
2169
|
+
if (remaining <= 0)
|
|
2170
|
+
break;
|
|
2171
|
+
await sleep(Math.min(QUALIFICATION_OBSERVATION_INTERVAL_MS, remaining));
|
|
2172
|
+
}
|
|
2173
|
+
return { run: ran, latest: seen };
|
|
2174
|
+
}, { errorLog: io.errorLog, timer: progressTimer });
|
|
2175
|
+
if (latest === null)
|
|
2176
|
+
return reconcile(run.started ? "job_unreadable" : "executor_not_run");
|
|
2177
|
+
if (!isTerminal(latest)) {
|
|
2178
|
+
return reconcile(latest.job_status === "queued" ? (run.started ? "executor_failed" : "executor_not_run") : "still_running");
|
|
2179
|
+
}
|
|
2180
|
+
job = latest;
|
|
2181
|
+
}
|
|
2182
|
+
const read = await readGateProfileOrNull(io, access);
|
|
2183
|
+
// BAPI-1637: the server's own read of the finished job, carried as it came.
|
|
2184
|
+
const evidence = {
|
|
2185
|
+
phase: job.phase,
|
|
2186
|
+
dependencyInstallDeclared: job.dependency_install_declared,
|
|
2187
|
+
};
|
|
2188
|
+
if (job.qualification_state === "stale" || job.failure === "stale") {
|
|
2189
|
+
return { status: "stale", source, profile: read, evidence };
|
|
2190
|
+
}
|
|
2191
|
+
if (job.job_status === "succeeded" && job.qualification_state === "qualified") {
|
|
2192
|
+
if (promotionObserved(read, input))
|
|
2193
|
+
return { status: "promoted", source, commands, profile: read, evidence };
|
|
2194
|
+
return { status: "uncertain", reason: "result_unreadable", profile: read, evidence };
|
|
2195
|
+
}
|
|
2196
|
+
if (job.job_status === "succeeded" && job.qualification_state === "unqualified") {
|
|
2197
|
+
return { status: "unqualified", source, profile: read, evidence };
|
|
2198
|
+
}
|
|
2199
|
+
if (job.job_status === "succeeded") {
|
|
2200
|
+
// Finished without a verdict: only a promotion the profile shows can settle it.
|
|
2201
|
+
if (promotionObserved(read, input))
|
|
2202
|
+
return { status: "promoted", source, commands, profile: read, evidence };
|
|
2203
|
+
return { status: "uncertain", reason: "result_unreadable", profile: read, evidence };
|
|
2204
|
+
}
|
|
2205
|
+
return { status: "could_not_run", source, profile: read, evidence };
|
|
2206
|
+
}
|
|
2207
|
+
// BAPI-1637 — fixed wording for each completed phase. None of it names a command,
|
|
2208
|
+
// an install step, a path, or any output: the server's phase token selects the text.
|
|
2209
|
+
const DEPENDENCY_INSTALL_FAILED_TEXT = "The dependency install failed, so the tests did not run.";
|
|
2210
|
+
const DEPENDENCY_INSTALL_REPAIR_TEXT = "Correct the install step (for example, a lockfile that no longer matches the manifest), then run setup again.";
|
|
2211
|
+
const COULD_NOT_START_TEXT = "The test command could not be started (the program could not launch).";
|
|
2212
|
+
const MISSING_INSTALL_TEXT = "No install step was declared, so the dependencies may be missing. Run setup again and accept the proposed install step.";
|
|
2213
|
+
const PREPARATION_UNCERTAIN_TEXT = "Bridge cannot tell whether the dependency install ran before the tests, so it cannot say why the check did not pass.";
|
|
2214
|
+
const PREPARATION_UNCERTAIN_REPAIR_TEXT = "Update the Bridge executor to the latest version, then run setup again.";
|
|
2215
|
+
/** The instruction every successful and failed trial line ends with. */
|
|
2216
|
+
const CHANGE_TEST_COMMAND_HINT = 'Change it with --test-command "<your command>".';
|
|
2217
|
+
/**
|
|
2218
|
+
* Print one trial outcome in plain words. The validated command is named ONLY on
|
|
2219
|
+
* the successful path, and only as the server returned it; no other outcome prints
|
|
2220
|
+
* a command, executor output, or a raw server response.
|
|
2221
|
+
*/
|
|
2222
|
+
export function reportLearnedCommandTrial(io, result) {
|
|
2223
|
+
const learned = (source) => source === "owner" ? "you gave it with --test-command" : "it learned from your repository";
|
|
2224
|
+
switch (result.status) {
|
|
2225
|
+
case "promoted": {
|
|
2226
|
+
const named = result.commands.map((c) => `\`${c.command.replace(/[\u0000-\u001F\u007F]/g, "?")}\``).join(", ");
|
|
2227
|
+
io.log(named.length > 0
|
|
2228
|
+
? ` Bridge will run ${named} before each merge. It is the command ${learned(result.source)}, and Bridge ` +
|
|
2229
|
+
`checked it by running it once. ${CHANGE_TEST_COMMAND_HINT}`
|
|
2230
|
+
: ` Bridge stored a test command ${learned(result.source)} and checked it by running it once. ` +
|
|
2231
|
+
CHANGE_TEST_COMMAND_HINT);
|
|
2232
|
+
return;
|
|
2233
|
+
}
|
|
2234
|
+
case "not_needed":
|
|
2235
|
+
io.log(" Bridge already has a test command for this repository, so it did not look for another.");
|
|
2236
|
+
return;
|
|
2237
|
+
case "no_command":
|
|
2238
|
+
io.log(` Bridge found no test command to try (${NO_COMMAND_TEXT[result.reason]}). It stored none. ` +
|
|
2239
|
+
"Give one with --test-command \"<your command>\" and Bridge will check it by running it once.");
|
|
2240
|
+
return;
|
|
2241
|
+
case "unqualified": {
|
|
2242
|
+
const { phase, dependencyInstallDeclared } = result.evidence ?? { phase: null, dependencyInstallDeclared: null };
|
|
2243
|
+
if (phase === "dependency_preparation_failed") {
|
|
2244
|
+
io.log(` ${DEPENDENCY_INSTALL_FAILED_TEXT} Bridge stored no learned command. ${DEPENDENCY_INSTALL_REPAIR_TEXT}`);
|
|
2245
|
+
return;
|
|
2246
|
+
}
|
|
2247
|
+
if (phase === "could_not_start") {
|
|
2248
|
+
io.log(` ${COULD_NOT_START_TEXT} Bridge stored none. ${CHANGE_TEST_COMMAND_HINT}`);
|
|
2249
|
+
return;
|
|
2250
|
+
}
|
|
2251
|
+
if (phase === null && dependencyInstallDeclared === true) {
|
|
2252
|
+
io.log(` ${PREPARATION_UNCERTAIN_TEXT} Bridge stored none. ${PREPARATION_UNCERTAIN_REPAIR_TEXT}`);
|
|
2253
|
+
return;
|
|
2254
|
+
}
|
|
2255
|
+
io.log(" The test command did not pass when Bridge ran it once, so Bridge stored none. " +
|
|
2256
|
+
"Fix the failing tests, or give another command with --test-command \"<your command>\".");
|
|
2257
|
+
if (phase === "ran_and_failed" && dependencyInstallDeclared === false)
|
|
2258
|
+
io.log(` ${MISSING_INSTALL_TEXT}`);
|
|
2259
|
+
return;
|
|
2260
|
+
}
|
|
2261
|
+
case "stale":
|
|
2262
|
+
io.log(" The gate changed while the test command was being checked, so Bridge stored none. Run setup again.");
|
|
2263
|
+
return;
|
|
2264
|
+
case "could_not_run":
|
|
2265
|
+
io.log(" Bridge could not run the test command (no clean checkout of your default branch, or the run was " +
|
|
2266
|
+
"interrupted), so it stored none. Run setup again.");
|
|
2267
|
+
return;
|
|
2268
|
+
case "stale_revision":
|
|
2269
|
+
io.log(" The gate changed before the test command could be checked, so nothing was started. Run setup again.");
|
|
2270
|
+
return;
|
|
2271
|
+
case "unsupported":
|
|
2272
|
+
io.log(" This Bridge server cannot learn a test command yet, so Bridge skipped it. Update the Bridge API to use it.");
|
|
2273
|
+
return;
|
|
2274
|
+
case "unavailable":
|
|
2275
|
+
io.log(" Bridge could not prepare the test command right now and started nothing. Run setup again shortly.");
|
|
2276
|
+
return;
|
|
2277
|
+
case "refused":
|
|
2278
|
+
io.log(result.reason === "unauthorized"
|
|
2279
|
+
? " This key cannot ask Bridge to check a test command (an administrator key is needed), so Bridge skipped it."
|
|
2280
|
+
: " Bridge's server refused the test command request, so Bridge skipped it.");
|
|
2281
|
+
return;
|
|
2282
|
+
case "uncertain":
|
|
2283
|
+
io.log(` Bridge cannot tell whether the test command was stored (${UNCERTAIN_TEXT[result.reason]}). ` +
|
|
2284
|
+
"It will not try again on its own. Run setup again to read what the server holds.");
|
|
2285
|
+
return;
|
|
2286
|
+
}
|
|
2287
|
+
}
|
|
2288
|
+
const NO_COMMAND_TEXT = Object.freeze({
|
|
2289
|
+
no_testing_instructions: "the repository has no learned testing instructions",
|
|
2290
|
+
llm_unavailable: "the server could not read them just now",
|
|
2291
|
+
llm_output_invalid: "the server could not turn them into a command",
|
|
2292
|
+
no_candidates: "they name no command",
|
|
2293
|
+
working_directory_unsupported: "the command must run from a subdirectory, which a gate cannot do",
|
|
2294
|
+
not_plain_argv: "the command is not a plain program and arguments",
|
|
2295
|
+
command_not_allowed: "the command is not allowed",
|
|
2296
|
+
invalid_command: "the command is not valid",
|
|
2297
|
+
});
|
|
2298
|
+
const UNCERTAIN_TEXT = Object.freeze({
|
|
2299
|
+
request_unclear: "the request did not answer clearly",
|
|
2300
|
+
executor_not_run: "no executor ran the check",
|
|
2301
|
+
executor_failed: "the executor did not finish the check",
|
|
2302
|
+
job_unreadable: "the check's state could not be read",
|
|
2303
|
+
still_running: "the check was still running",
|
|
2304
|
+
result_unreadable: "the result could not be confirmed",
|
|
2305
|
+
});
|
|
2306
|
+
// ---------------------------------------------------------------------------
|
|
1390
2307
|
// Standalone actions: --clear-gate and --qualify-gate
|
|
1391
2308
|
// ---------------------------------------------------------------------------
|
|
1392
2309
|
/** `--clear-gate`: BAPI-1390's clear action under the revision compare-and-swap. */
|
|
@@ -1535,6 +2452,31 @@ const COVERAGE_NEXT_STEP = Object.freeze({
|
|
|
1535
2452
|
no_workflows: "add a workflow with a pull_request trigger whose branches list includes 'epic/**'.",
|
|
1536
2453
|
});
|
|
1537
2454
|
const GENERIC_COVERAGE_NEXT_STEP = "check by hand that a pull_request trigger includes 'epic/**'.";
|
|
2455
|
+
/** BAPI-1654 — each coverage state and reason in plain words, so no internal token reaches the owner. */
|
|
2456
|
+
const PLAIN_COVERAGE = Object.freeze({
|
|
2457
|
+
covers: "runs on epic-branch PRs",
|
|
2458
|
+
does_not_cover: "does not run on epic-branch PRs",
|
|
2459
|
+
could_not_tell: "could not be confirmed to run on epic-branch PRs",
|
|
2460
|
+
});
|
|
2461
|
+
const PLAIN_COVERAGE_REASON = Object.freeze({
|
|
2462
|
+
pr_trigger_covers: "its pull_request trigger includes epic branches",
|
|
2463
|
+
no_pr_trigger: "it has no pull_request trigger",
|
|
2464
|
+
branch_filter_excludes_epic: "its pull_request branch list leaves out epic branches",
|
|
2465
|
+
path_filter: "a paths filter decides whether it starts",
|
|
2466
|
+
branch_filter_uncertain: "its branch filter could not be matched to epic branches with certainty",
|
|
2467
|
+
types_filter: "its pull_request types leave out opened or synchronize",
|
|
2468
|
+
indirect_trigger: "another workflow starts it",
|
|
2469
|
+
reusable_workflow_job: "a job calls a reusable workflow",
|
|
2470
|
+
unparseable: "it could not be read as a workflow",
|
|
2471
|
+
unsupported_structure: "it uses YAML that Bridge does not read confidently",
|
|
2472
|
+
listing_failed: "the workflow folder could not be listed",
|
|
2473
|
+
file_limit_reached: "there are too many workflow files to read",
|
|
2474
|
+
read_failed: "it could not be read",
|
|
2475
|
+
no_workflows: "there are no workflow files",
|
|
2476
|
+
});
|
|
2477
|
+
function plainCoverageReason(reason) {
|
|
2478
|
+
return PLAIN_COVERAGE_REASON[reason] ?? "Bridge could not tell why";
|
|
2479
|
+
}
|
|
1538
2480
|
function coverageNextStep(reason) {
|
|
1539
2481
|
return COVERAGE_NEXT_STEP[reason] ?? GENERIC_COVERAGE_NEXT_STEP;
|
|
1540
2482
|
}
|
|
@@ -1612,11 +2554,11 @@ export function renderEpicBranchCiFindings(io, coverage, rules) {
|
|
|
1612
2554
|
if (coverage.coverage !== "covers" && unresolved.length > 0) {
|
|
1613
2555
|
io.log(" Workflows that do not clearly cover epic-branch PRs:");
|
|
1614
2556
|
for (const w of unresolved) {
|
|
1615
|
-
io.log(` ${w.path}: ${w.coverage}
|
|
2557
|
+
io.log(` ${w.path}: ${PLAIN_COVERAGE[w.coverage]}, because ${plainCoverageReason(w.reason)} — next step: ${coverageNextStep(w.reason)}`);
|
|
1616
2558
|
}
|
|
1617
2559
|
}
|
|
1618
2560
|
else if (coverage.coverage !== "covers") {
|
|
1619
|
-
io.log(`
|
|
2561
|
+
io.log(` ${plainCoverageReason(coverage.reason)} — next step: ${coverageNextStep(coverage.reason)}`);
|
|
1620
2562
|
}
|
|
1621
2563
|
}
|
|
1622
2564
|
/**
|
|
@@ -1631,7 +2573,27 @@ export function renderEpicBranchCiFindings(io, coverage, rules) {
|
|
|
1631
2573
|
*
|
|
1632
2574
|
* Returns the decision, or null when none was made.
|
|
1633
2575
|
*/
|
|
1634
|
-
export async function resolveEpicBranchCiDecision(io, flag
|
|
2576
|
+
export async function resolveEpicBranchCiDecision(io, flag,
|
|
2577
|
+
/**
|
|
2578
|
+
* BAPI-1604 — when set, the decision is read from the inspected coverage instead of
|
|
2579
|
+
* asked: only a confirmed `covers` becomes an inferred `include`. Anything else records
|
|
2580
|
+
* nothing, asks nothing, and says how to record a choice. An explicit flag still wins.
|
|
2581
|
+
*/
|
|
2582
|
+
inferFrom) {
|
|
2583
|
+
if (inferFrom !== undefined) {
|
|
2584
|
+
if (flag !== null) {
|
|
2585
|
+
io.log(` Using --epic-branch-ci-decision=${flag}.`);
|
|
2586
|
+
return flag;
|
|
2587
|
+
}
|
|
2588
|
+
if (inferFrom === "covers") {
|
|
2589
|
+
io.log(" Epic-branch CI: include (a workflow runs on epic-branch PRs).");
|
|
2590
|
+
return "include";
|
|
2591
|
+
}
|
|
2592
|
+
io.log(" No epic-branch CI decision was recorded: Bridge could not confirm that a workflow runs on epic-branch PRs. " +
|
|
2593
|
+
"To record one, pass --epic-branch-ci-decision=include or --epic-branch-ci-decision=decline. " +
|
|
2594
|
+
"Until one is recorded, runs behave as include.");
|
|
2595
|
+
return null;
|
|
2596
|
+
}
|
|
1635
2597
|
io.log(" Include: each child waits for the checks that run on its epic-branch PR before it merges.");
|
|
1636
2598
|
io.log(" Decline: children merge into the epic branch without waiting for checks that never run there. " +
|
|
1637
2599
|
"Problems then surface only at the human-gated integration PR into the base branch.");
|
|
@@ -1668,7 +2630,13 @@ function printExemptionManualSteps(io, ownerRepo, branch) {
|
|
|
1668
2630
|
* include/decline choice and warning-toned. A ruleset is changed only after an
|
|
1669
2631
|
* explicit typed "yes", a passed scope check, and a confirming re-read.
|
|
1670
2632
|
*/
|
|
1671
|
-
export async function offerApprovalExemption(io, seams, run, ownerRepo, branch, rules
|
|
2633
|
+
export async function offerApprovalExemption(io, seams, run, ownerRepo, branch, rules,
|
|
2634
|
+
/**
|
|
2635
|
+
* BAPI-1638 — an explicit decision from the shared apply. `approve` stands in
|
|
2636
|
+
* for the typed `yes` (the answers path never prompts); `decline` changes
|
|
2637
|
+
* nothing. Absent keeps the interactive typed-`yes` question exactly as before.
|
|
2638
|
+
*/
|
|
2639
|
+
decision) {
|
|
1672
2640
|
const approvals = rules?.approvalsRequired ?? "could_not_tell";
|
|
1673
2641
|
if (approvals === "no")
|
|
1674
2642
|
return "not_needed";
|
|
@@ -1685,12 +2653,14 @@ export async function offerApprovalExemption(io, seams, run, ownerRepo, branch,
|
|
|
1685
2653
|
"Whether it can is unknown: check the ruleset's bypass list.");
|
|
1686
2654
|
io.log(" Bridge can exclude epic/** from this approval rule with your own gh login. It changes only the " +
|
|
1687
2655
|
"ruleset's excluded branches, and only for a repository ruleset that holds nothing but the approval rule.");
|
|
1688
|
-
if (!io.promptLine) {
|
|
2656
|
+
if (decision === undefined && !io.promptLine) {
|
|
1689
2657
|
io.log(" This run cannot prompt, so nothing was changed. The --epic-branch-ci-decision flag never grants this.");
|
|
1690
2658
|
printExemptionManualSteps(io, ownerRepo, branch);
|
|
1691
2659
|
return "printed_steps";
|
|
1692
2660
|
}
|
|
1693
|
-
const consent =
|
|
2661
|
+
const consent = decision !== undefined
|
|
2662
|
+
? decision === "approve"
|
|
2663
|
+
: await ask(io, "Exclude epic/** from the approval rule now? Type yes to change it [y/N]: ");
|
|
1694
2664
|
if (!consent) {
|
|
1695
2665
|
io.log(" Not changed.");
|
|
1696
2666
|
printExemptionManualSteps(io, ownerRepo, branch);
|
|
@@ -1726,35 +2696,16 @@ export async function offerApprovalExemption(io, seams, run, ownerRepo, branch,
|
|
|
1726
2696
|
return "could_not_tell";
|
|
1727
2697
|
}
|
|
1728
2698
|
/**
|
|
1729
|
-
*
|
|
1730
|
-
*
|
|
1731
|
-
*
|
|
1732
|
-
*
|
|
1733
|
-
*
|
|
1734
|
-
* step returns. It never writes `decline` unless the owner chose it.
|
|
2699
|
+
* BAPI-1638 — collect the epic-branch CI evidence: detect the provider, find an
|
|
2700
|
+
* example epic branch, inspect workflow coverage, and read the epic-branch rules.
|
|
2701
|
+
* Read-only. A failed read is recorded as `could_not_tell` (or `null` rules),
|
|
2702
|
+
* never guessed. The exemption's own scope check runs only after approval,
|
|
2703
|
+
* inside {@link offerApprovalExemption}.
|
|
1735
2704
|
*/
|
|
1736
|
-
export async function
|
|
1737
|
-
const result = {
|
|
1738
|
-
status: "completed",
|
|
1739
|
-
coverage: null,
|
|
1740
|
-
rules: null,
|
|
1741
|
-
exemptionOutcome: null,
|
|
1742
|
-
decision: null,
|
|
1743
|
-
evidence: null,
|
|
1744
|
-
recorded: false,
|
|
1745
|
-
manualAction: null,
|
|
1746
|
-
};
|
|
1747
|
-
io.log("");
|
|
1748
|
-
io.log("Epic-branch CI — do checks run on pull requests into epic branches?");
|
|
2705
|
+
export async function collectEpicBranchCi(gateDeps) {
|
|
1749
2706
|
const seams = gateDeps?.epicBranchCi;
|
|
1750
|
-
if (!seams)
|
|
1751
|
-
|
|
1752
|
-
return { ...result, status: "skipped_no_seams" };
|
|
1753
|
-
}
|
|
1754
|
-
if (options.dryRun) {
|
|
1755
|
-
io.log(" Dry run — would inspect workflow triggers and epic-branch rules, then ask include or decline. Nothing was recorded.");
|
|
1756
|
-
return { ...result, status: "skipped_dry_run" };
|
|
1757
|
-
}
|
|
2707
|
+
if (!seams)
|
|
2708
|
+
return { status: "skipped_no_seams" };
|
|
1758
2709
|
let provider;
|
|
1759
2710
|
try {
|
|
1760
2711
|
provider = await seams.detectProvider();
|
|
@@ -1762,12 +2713,8 @@ export async function runEpicBranchCiInspection(io, access, gateDeps, options) {
|
|
|
1762
2713
|
catch {
|
|
1763
2714
|
provider = { kind: "unknown" };
|
|
1764
2715
|
}
|
|
1765
|
-
if (provider.kind !== "github")
|
|
1766
|
-
|
|
1767
|
-
(provider.kind === "unknown" ? " (or could not be read)" : "") +
|
|
1768
|
-
". No epic-branch CI decision was recorded.");
|
|
1769
|
-
return { ...result, status: "skipped_not_github" };
|
|
1770
|
-
}
|
|
2716
|
+
if (provider.kind !== "github")
|
|
2717
|
+
return { status: "skipped_not_github", provider: provider.kind };
|
|
1771
2718
|
const ownerRepo = provider.ownerRepo;
|
|
1772
2719
|
const run = safeGhRunner(seams.runGh);
|
|
1773
2720
|
let branch = EPIC_BRANCH_CI_PROBE_BRANCH;
|
|
@@ -1793,11 +2740,63 @@ export async function runEpicBranchCiInspection(io, access, gateDeps, options) {
|
|
|
1793
2740
|
catch {
|
|
1794
2741
|
rules = null;
|
|
1795
2742
|
}
|
|
2743
|
+
return { status: "collected", ownerRepo, branch, coverage, rules };
|
|
2744
|
+
}
|
|
2745
|
+
/**
|
|
2746
|
+
* BAPI-1638 — the decision write, alone: `putEpicBranchCiDecision` (or the test
|
|
2747
|
+
* override). Called only with an explicit or coverage-confirmed decision.
|
|
2748
|
+
*/
|
|
2749
|
+
export async function applyEpicBranchCiDecision(io, access, seams, request) {
|
|
2750
|
+
const record = seams.recordDecision ??
|
|
2751
|
+
((acc, body) => putEpicBranchCiDecision(acc, acc.repoName, body, io.postJson));
|
|
2752
|
+
try {
|
|
2753
|
+
await record(access, request);
|
|
2754
|
+
return { recorded: true };
|
|
2755
|
+
}
|
|
2756
|
+
catch (err) {
|
|
2757
|
+
return { recorded: false, kind: err instanceof ConductorBridgeApiError ? err.kind : "error" };
|
|
2758
|
+
}
|
|
2759
|
+
}
|
|
2760
|
+
export async function runEpicBranchCiInspection(io, access, gateDeps, options) {
|
|
2761
|
+
const result = {
|
|
2762
|
+
status: "completed",
|
|
2763
|
+
coverage: null,
|
|
2764
|
+
rules: null,
|
|
2765
|
+
exemptionOutcome: null,
|
|
2766
|
+
decision: null,
|
|
2767
|
+
evidence: null,
|
|
2768
|
+
recorded: false,
|
|
2769
|
+
manualAction: null,
|
|
2770
|
+
};
|
|
2771
|
+
io.log("");
|
|
2772
|
+
io.log("Epic-branch CI — do checks run on pull requests into epic branches?");
|
|
2773
|
+
const seams = gateDeps?.epicBranchCi;
|
|
2774
|
+
if (!seams) {
|
|
2775
|
+
io.log(" skipped — this caller supplied no epic-branch CI inspection seams. Nothing was recorded.");
|
|
2776
|
+
return { ...result, status: "skipped_no_seams" };
|
|
2777
|
+
}
|
|
2778
|
+
if (options.dryRun) {
|
|
2779
|
+
io.log(" Dry run — would inspect workflow triggers and epic-branch rules, then ask include or decline. Nothing was recorded.");
|
|
2780
|
+
return { ...result, status: "skipped_dry_run" };
|
|
2781
|
+
}
|
|
2782
|
+
const collected = options.collected ?? (await collectEpicBranchCi(gateDeps));
|
|
2783
|
+
if (collected.status === "skipped_no_seams") {
|
|
2784
|
+
io.log(" skipped — this caller supplied no epic-branch CI inspection seams. Nothing was recorded.");
|
|
2785
|
+
return { ...result, status: "skipped_no_seams" };
|
|
2786
|
+
}
|
|
2787
|
+
if (collected.status === "skipped_not_github") {
|
|
2788
|
+
io.log(" The epic-branch CI inspection is GitHub-only, and this repository's remote is not on github.com" +
|
|
2789
|
+
(collected.provider === "unknown" ? " (or could not be read)" : "") +
|
|
2790
|
+
". No epic-branch CI decision was recorded.");
|
|
2791
|
+
return { ...result, status: "skipped_not_github" };
|
|
2792
|
+
}
|
|
2793
|
+
const { ownerRepo, branch, coverage, rules } = collected;
|
|
2794
|
+
const run = safeGhRunner(seams.runGh);
|
|
1796
2795
|
result.coverage = coverage.coverage;
|
|
1797
2796
|
result.rules = rules;
|
|
1798
2797
|
renderEpicBranchCiFindings(io, coverage, rules);
|
|
1799
|
-
const decision = await resolveEpicBranchCiDecision(io, options.decisionFlag);
|
|
1800
|
-
const exemptionOutcome = await offerApprovalExemption(io, seams, run, ownerRepo, branch, rules);
|
|
2798
|
+
const decision = await resolveEpicBranchCiDecision(io, options.decisionFlag, options.inferFromCoverage === true ? coverage.coverage : undefined);
|
|
2799
|
+
const exemptionOutcome = await offerApprovalExemption(io, seams, run, ownerRepo, branch, rules, options.exemptionDecision);
|
|
1801
2800
|
const evidence = buildEpicBranchCiEvidence(coverage.coverage, rules, exemptionOutcome);
|
|
1802
2801
|
result.decision = decision;
|
|
1803
2802
|
result.exemptionOutcome = exemptionOutcome;
|
|
@@ -1806,15 +2805,17 @@ export async function runEpicBranchCiInspection(io, access, gateDeps, options) {
|
|
|
1806
2805
|
// the reason was already printed. It is not added to the manual steps.
|
|
1807
2806
|
if (decision === null)
|
|
1808
2807
|
return result;
|
|
1809
|
-
|
|
1810
|
-
(
|
|
1811
|
-
|
|
1812
|
-
|
|
2808
|
+
if (options.recordedDecision !== undefined && options.recordedDecision === decision) {
|
|
2809
|
+
io.log(` epic-branch CI decision already recorded: ${decision}`);
|
|
2810
|
+
return { ...result, recorded: true, unchanged: true };
|
|
2811
|
+
}
|
|
2812
|
+
const written = await applyEpicBranchCiDecision(io, access, seams, { decision, evidence });
|
|
2813
|
+
if (written.recorded) {
|
|
1813
2814
|
result.recorded = true;
|
|
1814
2815
|
io.log(` recorded epic-branch CI decision: ${decision}`);
|
|
1815
2816
|
}
|
|
1816
|
-
|
|
1817
|
-
const kind =
|
|
2817
|
+
else {
|
|
2818
|
+
const kind = written.kind;
|
|
1818
2819
|
io.errorLog(`Warning: the epic-branch CI decision could not be recorded (${kind}). The install continues; ` +
|
|
1819
2820
|
"re-run it to record the decision.");
|
|
1820
2821
|
result.manualAction =
|