@bridge_gpt/mcp-server 0.2.72 → 0.2.74
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 +15 -0
- package/build/agents.generated.js +6 -6
- package/build/bridge-config.js +7 -1
- package/build/bridge-permissions.js +30 -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/command-provisioning.js +4 -3
- package/build/commands.generated.js +7 -6
- package/build/conductor/bridge-api-client.js +867 -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 +48 -1
- package/build/conductor/declare-blocked.js +554 -0
- package/build/conductor/declared-extras.js +335 -0
- package/build/conductor/doctor.js +108 -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-pass-output.js +104 -0
- package/build/conductor/driver-pass.js +571 -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 +281 -43
- package/build/conductor/epic-implementer-cli.js +199 -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-upload.js +1567 -0
- package/build/conductor/epic-server-sfcc.js +85 -0
- package/build/conductor/epic-server-state.js +427 -0
- package/build/conductor/epic-server.js +647 -0
- package/build/conductor/gate-discovery.js +196 -11
- package/build/conductor/gate-settings-review.js +261 -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-delivery.js +280 -0
- package/build/credential-launch-safety.js +142 -0
- package/build/credential-materialization.js +91 -16
- package/build/credential-references-node-deps.js +29 -0
- package/build/credential-references.js +1394 -0
- package/build/credential-references.test-fixtures.js +211 -0
- package/build/credential-scan-conventions.js +145 -0
- package/build/credential-scan.js +517 -0
- package/build/credential-store.js +121 -1
- package/build/credentials-cli.js +252 -3
- package/build/dependency-install-declarations.js +102 -1
- package/build/docs.generated.js +10 -3
- package/build/doctor.js +95 -3
- package/build/drive-epic-help.js +21 -2
- package/build/drive-epic.js +2095 -375
- package/build/engine-paths.js +20 -0
- package/build/epic-branch-ci-summary.js +157 -0
- package/build/epic-capability-statement.js +175 -0
- package/build/epic-ci-workflow-drift.js +77 -23
- package/build/epic-ci-workflow-install.js +137 -44
- package/build/epic-ci-workflow-v2.js +274 -0
- package/build/epic-ci-workflow-v3.js +273 -0
- package/build/epic-ci-workflow.js +165 -18
- package/build/epic-implementer-bin.js +2204 -56
- package/build/epic-launch-context.js +702 -0
- package/build/epic-server-record.js +288 -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/credential-delivery-step.js +168 -0
- package/build/executor/deps.js +3 -1
- package/build/executor/env.js +98 -23
- package/build/executor/epic-server-context.js +157 -0
- package/build/executor/gate-qualification-job.js +127 -26
- package/build/executor/guarded-fast-forward-push.js +13 -8
- package/build/executor/http-client.js +52 -5
- package/build/executor/job-runner.js +577 -81
- package/build/executor/observation.js +8 -0
- package/build/executor/permissions.js +85 -3
- package/build/executor/pre-pr-checks.js +363 -0
- package/build/executor/prompt-spec.js +149 -3
- 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 +58 -4
- package/build/generated-assets-catalog.js +2 -2
- package/build/git-exclude-lock.js +187 -0
- package/build/index.js +824 -366
- package/build/init.js +26 -11
- package/build/install-bridge-conductor-answers.js +528 -0
- package/build/install-bridge-conductor-apply.js +288 -0
- package/build/install-bridge-conductor-assessment.js +1222 -0
- package/build/install-bridge-conductor-compact.js +186 -0
- package/build/install-bridge-conductor-contracts.js +72 -0
- package/build/install-bridge-conductor-gate.js +1312 -198
- package/build/install-bridge-conductor-setup.js +577 -83
- package/build/install-bridge-conductor.js +3381 -544
- package/build/install-bridge.js +280 -25
- package/build/install-doctor.js +38 -8
- package/build/install-maintenance.js +26 -3
- package/build/install-sfcc-detection.js +120 -0
- package/build/install-sfcc-setup.js +185 -0
- package/build/launcher-config-inspection.js +162 -1
- package/build/mcp-grant-candidates.js +779 -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 +292 -15
- package/build/mcp-presets.js +107 -0
- package/build/mcp-provisioning.js +155 -6
- package/build/mcp-registration-doctor.js +31 -2
- package/build/mcp-server-invocation.js +19 -1
- package/build/merge-workflow-install.js +243 -110
- package/build/pipelines.generated.js +7 -6
- 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/status.js +8 -2
- package/build/plane/terminal-run-cleanup.js +18 -4
- package/build/printed-remedy-commands.js +211 -12
- package/build/project-root.js +40 -0
- 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 +41 -0
- package/build/repository-toolchains.js +6 -3
- package/build/run-unit-tests-launcher.js +8 -1
- package/build/setup-epic.js +1305 -210
- package/build/setup-progress.js +44 -0
- package/build/setup-question.js +122 -4
- package/build/sfcc/credentials.js +3 -2
- package/build/sfcc/hostname.js +98 -2
- package/build/sfcc/tool-wrapper.js +6 -95
- package/build/start-tickets.js +193 -29
- package/build/test-support/executor-source-files.js +200 -0
- package/build/testing-config-client.js +25 -2
- package/build/third-party-mcp-targets.js +63 -2
- 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/build/with-credentials.js +208 -0
- package/build/worktree-credential-delivery.js +340 -0
- 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,6 +1,6 @@
|
|
|
1
1
|
import { parseAssessmentNegotiation } from './readiness-assessment.js';
|
|
2
2
|
import { READINESS_PREREQUISITE_BY_ID } from "../readiness-prerequisites.generated.js";
|
|
3
|
-
import { READINESS_PREREQUISITE_FIXES } from "../printed-remedy-commands.js";
|
|
3
|
+
import { PREVIOUS_SERVER_READINESS_FIXES, READINESS_PREREQUISITE_FIXES } from "../printed-remedy-commands.js";
|
|
4
4
|
/**
|
|
5
5
|
* TypeScript-side Bridge API access layer for the conductor producer (BAPI-395).
|
|
6
6
|
*
|
|
@@ -21,7 +21,7 @@ import { normalizePrNumber, normalizeSha } from "./git-ci-types.js";
|
|
|
21
21
|
import { ConductorValidationError } from "./errors.js";
|
|
22
22
|
import { parseContinuationStatusResult, parseContinueParkedChildResult, } from "./epic-child-continuation.js";
|
|
23
23
|
import { resolveDeclaredRunBaseBranch } from "./run-branch.js";
|
|
24
|
-
import { CI_DATABASE_DEFAULT, isCiDatabase, parseDependencyInstallStrict, } from "../dependency-install-declarations.js";
|
|
24
|
+
import { CI_DATABASE_DEFAULT, isCiDatabase, parseDependencyInstallStrict, parseMustOrderPathsStrict, } from "../dependency-install-declarations.js";
|
|
25
25
|
import { safeEpicLaunchTargetUrl } from "../epic-launch-diagnostic.js";
|
|
26
26
|
import { validateHttpBaseUrl } from "../base-url.js";
|
|
27
27
|
import { RERUN_CI_CHECK_STATUSES, RERUN_CI_NOT_RUNNABLE_REASONS, RERUN_CI_OUTCOMES, isCiResumeRefusalCode, } from "./repair-contract.js";
|
|
@@ -29,6 +29,18 @@ import { RERUN_CI_CHECK_STATUSES, RERUN_CI_NOT_RUNNABLE_REASONS, RERUN_CI_OUTCOM
|
|
|
29
29
|
export const CONDUCTOR_DEFAULT_BASE_URL = "https://bridgegpt-api.com";
|
|
30
30
|
/** Default per-request timeout for conductor Bridge API calls. */
|
|
31
31
|
export const CONDUCTOR_FETCH_TIMEOUT_MS = 30_000;
|
|
32
|
+
/**
|
|
33
|
+
* BAPI-1593 — the budget for one full readiness read (the GET report and the
|
|
34
|
+
* preview's read-only POST alike). A readiness report composes many server-side
|
|
35
|
+
* probes, and a read that ran a little past the 30 s default used to turn a
|
|
36
|
+
* healthy server into an unknown launch.
|
|
37
|
+
*/
|
|
38
|
+
export const CONDUCTOR_READINESS_FETCH_TIMEOUT_MS = 60_000;
|
|
39
|
+
/**
|
|
40
|
+
* BAPI-1593 — the approve-plan budget. Approval seeds tickets and activates the
|
|
41
|
+
* run in one request, which can outlast the 30 s default even when it succeeds.
|
|
42
|
+
*/
|
|
43
|
+
export const CONDUCTOR_APPROVE_FETCH_TIMEOUT_MS = 120_000;
|
|
32
44
|
/** Keep an explicit readiness target from borrowing a key bound to another ambient endpoint. */
|
|
33
45
|
export function readinessEndpointEnvironments(env, baseUrl) {
|
|
34
46
|
if (baseUrl === undefined)
|
|
@@ -51,9 +63,33 @@ export function readinessEndpointEnvironments(env, baseUrl) {
|
|
|
51
63
|
* Resolve `{ repoName, apiKey, baseUrl }` from the environment, the shared repo
|
|
52
64
|
* resolver, and the shared credential store. Never throws and never embeds the
|
|
53
65
|
* secret value in any failure text. No Postgres/DB module is imported here.
|
|
66
|
+
*
|
|
67
|
+
* Launch-specific access (profile target and its endpoint-bound credential) is
|
|
68
|
+
* opt-in through `followEpicLaunchProfile`: selected Epic Implementer verbs set
|
|
69
|
+
* it, while other callers keep general `BAPI_BASE_URL` resolution unchanged.
|
|
54
70
|
*/
|
|
55
71
|
export async function resolveConductorBridgeApiAccess(deps = {}) {
|
|
56
72
|
const env = deps.env ?? process.env;
|
|
73
|
+
if (deps.followEpicLaunchProfile === true && env.BAPI_EPIC_LAUNCH_PROFILE?.trim()) {
|
|
74
|
+
const launch = await resolveEpicLaunchBridgeApiAccess({}, deps);
|
|
75
|
+
if (launch.ok)
|
|
76
|
+
return { ok: true, access: launch.access };
|
|
77
|
+
if (launch.kind === "credential-unbound") {
|
|
78
|
+
// No fallback to ambient credentials: the profile named this endpoint.
|
|
79
|
+
return { ok: false, kind: "credentials-unavailable", error: launch.error };
|
|
80
|
+
}
|
|
81
|
+
if (launch.kind === "profile-unusable") {
|
|
82
|
+
// One fixed, secret-free line per resolution; the general path continues.
|
|
83
|
+
process.stderr.write("warning: the selected Epic launch profile is unusable; using general Bridge API resolution\n");
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
return {
|
|
87
|
+
ok: false,
|
|
88
|
+
kind: launch.kind === "repo-missing" ? "repo-missing" : "credentials-unavailable",
|
|
89
|
+
error: launch.error,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
}
|
|
57
93
|
const cwd = deps.cwd ?? process.cwd();
|
|
58
94
|
const homedir = deps.homedir ?? os.homedir;
|
|
59
95
|
const platform = deps.platform ?? process.platform;
|
|
@@ -363,6 +399,9 @@ function formatValidationDetailItem(item) {
|
|
|
363
399
|
}
|
|
364
400
|
/** BAPI-1550 — the shape of a closed executor-job-type token (e.g. `ci_fix`). */
|
|
365
401
|
const HOLDER_JOB_TYPE_RE = /^[a-z][a-z_]{0,39}$/;
|
|
402
|
+
/** BAPI-1585 — closed-token shapes for an approval refusal's code, predicate, and reason. */
|
|
403
|
+
const REFUSAL_ERROR_CODE_RE = /^[A-Z][A-Z0-9_]{0,63}$/;
|
|
404
|
+
const REFUSAL_TOKEN_RE = /^[a-z][a-z0-9_]{0,63}$/;
|
|
366
405
|
/**
|
|
367
406
|
* Extract sanitized diagnostics from a parsed backend error body. Recognizes the
|
|
368
407
|
* FastAPI/backend shapes `{ detail: { error_code, message } }`,
|
|
@@ -411,6 +450,21 @@ export function extractSanitizedErrorDiagnostics(body) {
|
|
|
411
450
|
diagnostics.errorCode = boundedErrorPreview(errorCode);
|
|
412
451
|
if (message)
|
|
413
452
|
diagnostics.bodyPreview = boundedErrorPreview(message);
|
|
453
|
+
diagnostics.detailKind =
|
|
454
|
+
typeof detail === "string"
|
|
455
|
+
? "string"
|
|
456
|
+
: detail && typeof detail === "object" && !Array.isArray(detail)
|
|
457
|
+
? "object"
|
|
458
|
+
: "other";
|
|
459
|
+
if (detail && typeof detail === "object" && !Array.isArray(detail)) {
|
|
460
|
+
const d = detail;
|
|
461
|
+
if (typeof d["predicate"] === "string" && REFUSAL_TOKEN_RE.test(d["predicate"])) {
|
|
462
|
+
diagnostics.predicate = d["predicate"];
|
|
463
|
+
}
|
|
464
|
+
if (typeof d["reason_code"] === "string" && REFUSAL_TOKEN_RE.test(d["reason_code"])) {
|
|
465
|
+
diagnostics.reasonCode = d["reason_code"];
|
|
466
|
+
}
|
|
467
|
+
}
|
|
414
468
|
const gateEvidence = extractGateProfileEvidence(detail);
|
|
415
469
|
if (gateEvidence)
|
|
416
470
|
diagnostics.gateProfileEvidence = gateEvidence;
|
|
@@ -469,6 +523,13 @@ function redactDiagnosticValues(diagnostics, secrets) {
|
|
|
469
523
|
out.holderJobId = diagnostics.holderJobId;
|
|
470
524
|
out.holderJobType = diagnostics.holderJobType;
|
|
471
525
|
}
|
|
526
|
+
// BAPI-1585: closed tokens, pattern-checked at extraction.
|
|
527
|
+
if (diagnostics.detailKind)
|
|
528
|
+
out.detailKind = diagnostics.detailKind;
|
|
529
|
+
if (diagnostics.predicate)
|
|
530
|
+
out.predicate = diagnostics.predicate;
|
|
531
|
+
if (diagnostics.reasonCode)
|
|
532
|
+
out.reasonCode = diagnostics.reasonCode;
|
|
472
533
|
// BAPI-1520: pattern-checked at extraction, so there is nothing left to scrub.
|
|
473
534
|
if (diagnostics.gateProfileEvidence)
|
|
474
535
|
out.gateProfileEvidence = diagnostics.gateProfileEvidence;
|
|
@@ -537,8 +598,14 @@ export class ConductorBridgeApiError extends Error {
|
|
|
537
598
|
/** BAPI-1550 — the queued job holding the serial lane (a complete pair, or absent). */
|
|
538
599
|
holderJobId;
|
|
539
600
|
holderJobType;
|
|
601
|
+
/** BAPI-1585 — the `detail` shape and closed refusal tokens, when the body carried them. */
|
|
602
|
+
detailKind;
|
|
603
|
+
predicate;
|
|
604
|
+
reasonCode;
|
|
540
605
|
/** BAPI-1520 — sanitized structural evidence of a gate-profile refusal. */
|
|
541
606
|
gateProfileEvidence;
|
|
607
|
+
/** BAPI-1593 — the server answered 2xx, but its body could not be read. */
|
|
608
|
+
unreadableSuccess;
|
|
542
609
|
constructor(kindOrMessage, status, diagnostics) {
|
|
543
610
|
const isKnownKind = CONDUCTOR_BRIDGE_API_ERROR_KINDS.includes(kindOrMessage);
|
|
544
611
|
const errorCode = diagnostics?.errorCode;
|
|
@@ -573,8 +640,16 @@ export class ConductorBridgeApiError extends Error {
|
|
|
573
640
|
this.holderJobId = diagnostics.holderJobId;
|
|
574
641
|
this.holderJobType = diagnostics.holderJobType;
|
|
575
642
|
}
|
|
643
|
+
if (diagnostics?.detailKind)
|
|
644
|
+
this.detailKind = diagnostics.detailKind;
|
|
645
|
+
if (diagnostics?.predicate)
|
|
646
|
+
this.predicate = diagnostics.predicate;
|
|
647
|
+
if (diagnostics?.reasonCode)
|
|
648
|
+
this.reasonCode = diagnostics.reasonCode;
|
|
576
649
|
if (diagnostics?.gateProfileEvidence)
|
|
577
650
|
this.gateProfileEvidence = diagnostics.gateProfileEvidence;
|
|
651
|
+
if (diagnostics?.unreadableSuccess === true)
|
|
652
|
+
this.unreadableSuccess = true;
|
|
578
653
|
}
|
|
579
654
|
}
|
|
580
655
|
/**
|
|
@@ -600,6 +675,141 @@ export function safeDiagnosticMessage(err, fallback) {
|
|
|
600
675
|
}
|
|
601
676
|
return fallback;
|
|
602
677
|
}
|
|
678
|
+
/** Gateway statuses that, with no typed body, say nothing about whether the POST applied. */
|
|
679
|
+
const UNCERTAIN_GATEWAY_STATUSES = new Set([502, 503, 504]);
|
|
680
|
+
/**
|
|
681
|
+
* Classify a create/approve failure as uncertain, or `null` when it is a proven
|
|
682
|
+
* answer (a typed refusal, a 4xx, a 500, an auth failure). Pure.
|
|
683
|
+
*/
|
|
684
|
+
export function classifyMutationUncertainty(err) {
|
|
685
|
+
if (!(err instanceof ConductorBridgeApiError))
|
|
686
|
+
return null;
|
|
687
|
+
if (err.errorCode !== undefined)
|
|
688
|
+
return null;
|
|
689
|
+
if (err.kind === "timeout")
|
|
690
|
+
return "timeout";
|
|
691
|
+
if (err.kind === "network")
|
|
692
|
+
return err.unreadableSuccess === true ? "unreadable_response" : "network";
|
|
693
|
+
if (err.kind === "server" && typeof err.status === "number" && UNCERTAIN_GATEWAY_STATUSES.has(err.status)) {
|
|
694
|
+
return "gateway_unavailable";
|
|
695
|
+
}
|
|
696
|
+
return null;
|
|
697
|
+
}
|
|
698
|
+
/**
|
|
699
|
+
* BAPI-1593 — a create or approve whose outcome is unknown. A subclass, so every
|
|
700
|
+
* existing `instanceof ConductorBridgeApiError` handler keeps its behavior; only a
|
|
701
|
+
* caller that reconciles reads `operation` and `uncertainty`. It carries no body,
|
|
702
|
+
* URL, or exception text: there was no readable answer to carry.
|
|
703
|
+
*/
|
|
704
|
+
export class ConductorMutationOutcomeUnknownError extends ConductorBridgeApiError {
|
|
705
|
+
operation;
|
|
706
|
+
uncertainty;
|
|
707
|
+
constructor(operation, uncertainty, cause) {
|
|
708
|
+
super(cause.kind, cause.status, cause.unreadableSuccess === true ? { unreadableSuccess: true } : undefined);
|
|
709
|
+
this.name = "ConductorMutationOutcomeUnknownError";
|
|
710
|
+
this.operation = operation;
|
|
711
|
+
this.uncertainty = uncertainty;
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
/** Re-throw an uncertain create/approve failure as {@link ConductorMutationOutcomeUnknownError}. */
|
|
715
|
+
function rethrowMutationFailure(operation, err) {
|
|
716
|
+
const uncertainty = classifyMutationUncertainty(err);
|
|
717
|
+
if (uncertainty !== null) {
|
|
718
|
+
throw new ConductorMutationOutcomeUnknownError(operation, uncertainty, err);
|
|
719
|
+
}
|
|
720
|
+
throw err;
|
|
721
|
+
}
|
|
722
|
+
// ---------------------------------------------------------------------------
|
|
723
|
+
// BAPI-1593 — one readiness acquisition per launch operation
|
|
724
|
+
// ---------------------------------------------------------------------------
|
|
725
|
+
//
|
|
726
|
+
// "Retry once" means once per launch operation, not once per caller. A launch
|
|
727
|
+
// creates ONE acquisition and hands its result to every later consumer in the
|
|
728
|
+
// same operation (drive-epic hands it to setup-epic). Nothing is cached across
|
|
729
|
+
// operations or process-wide, and the preview's POST `/launch-readiness` and the
|
|
730
|
+
// launch's GET report are separate acquisitions: one never stands in for the
|
|
731
|
+
// other.
|
|
732
|
+
//
|
|
733
|
+
// The single-attempt callback makes exactly one request, parsing included, so
|
|
734
|
+
// there is no nested retry below this boundary.
|
|
735
|
+
/** The fixed pause before the one readiness retry. */
|
|
736
|
+
export const READINESS_RETRY_BACKOFF_MS = 1_500;
|
|
737
|
+
/** Two full reads at most: one attempt plus one retry. */
|
|
738
|
+
export const READINESS_MAX_ATTEMPTS = 2;
|
|
739
|
+
/** Map a failed readiness attempt to its closed unknown reason. */
|
|
740
|
+
export function readinessUnknownReason(err) {
|
|
741
|
+
if (!(err instanceof ConductorBridgeApiError))
|
|
742
|
+
return "invalid_response";
|
|
743
|
+
if (err.kind === "timeout")
|
|
744
|
+
return "timeout";
|
|
745
|
+
if (err.kind === "network")
|
|
746
|
+
return err.unreadableSuccess === true ? "unreadable_response" : "network";
|
|
747
|
+
if (err.kind === "server")
|
|
748
|
+
return "server_error";
|
|
749
|
+
if (err.kind === "unauthorized")
|
|
750
|
+
return "unauthorized";
|
|
751
|
+
if (err.kind === "invalid-input")
|
|
752
|
+
return "invalid_response";
|
|
753
|
+
return "http_error";
|
|
754
|
+
}
|
|
755
|
+
/**
|
|
756
|
+
* The unknown reasons a retry can change: a slow, dropped, or half-deployed
|
|
757
|
+
* server. A 4xx or an auth failure is the server's definite answer, so a second
|
|
758
|
+
* identical request would only repeat it.
|
|
759
|
+
*/
|
|
760
|
+
const RETRYABLE_READINESS_REASONS = new Set([
|
|
761
|
+
"timeout",
|
|
762
|
+
"network",
|
|
763
|
+
"unreadable_response",
|
|
764
|
+
"server_error",
|
|
765
|
+
"invalid_response",
|
|
766
|
+
]);
|
|
767
|
+
const defaultReadinessSleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
768
|
+
/**
|
|
769
|
+
* Create one launch-scoped readiness acquisition over a single-attempt read.
|
|
770
|
+
*
|
|
771
|
+
* A success or a proven refusal settles it at once. A transient first failure
|
|
772
|
+
* (timeout, network, unreadable body, 5xx, invalid shape) is retried once after
|
|
773
|
+
* {@link READINESS_RETRY_BACKOFF_MS}; a second failure settles it as `unknown`.
|
|
774
|
+
* A 4xx or auth failure settles as `unknown` at once: retrying cannot change it.
|
|
775
|
+
*/
|
|
776
|
+
export function createReadinessAcquisition(readOnce, options = {}) {
|
|
777
|
+
const sleep = options.sleep ?? defaultReadinessSleep;
|
|
778
|
+
let latest = null;
|
|
779
|
+
const attempt = async (n) => {
|
|
780
|
+
try {
|
|
781
|
+
latest = { kind: "ready", readiness: await readOnce(), attempts: n };
|
|
782
|
+
}
|
|
783
|
+
catch (err) {
|
|
784
|
+
latest = isSchemaIncompatibleError(err)
|
|
785
|
+
? { kind: "refused", error: err, attempts: n }
|
|
786
|
+
: { kind: "unknown", reason: readinessUnknownReason(err), error: err, attempts: n };
|
|
787
|
+
}
|
|
788
|
+
return latest;
|
|
789
|
+
};
|
|
790
|
+
let first = null;
|
|
791
|
+
let settled = null;
|
|
792
|
+
const firstAttempt = () => {
|
|
793
|
+
first ??= attempt(1);
|
|
794
|
+
return first;
|
|
795
|
+
};
|
|
796
|
+
const result = () => {
|
|
797
|
+
settled ??= (async () => {
|
|
798
|
+
const one = await firstAttempt();
|
|
799
|
+
if (one.kind !== "unknown" || !RETRYABLE_READINESS_REASONS.has(one.reason))
|
|
800
|
+
return one;
|
|
801
|
+
options.onRetry?.(one.reason);
|
|
802
|
+
await sleep(READINESS_RETRY_BACKOFF_MS);
|
|
803
|
+
return attempt(READINESS_MAX_ATTEMPTS);
|
|
804
|
+
})();
|
|
805
|
+
return settled;
|
|
806
|
+
};
|
|
807
|
+
return { firstAttempt, result, peek: () => latest };
|
|
808
|
+
}
|
|
809
|
+
/** Acquire readiness once for a standalone operation: one attempt plus at most one retry. */
|
|
810
|
+
export function acquireConductorReadiness(readOnce, options = {}) {
|
|
811
|
+
return createReadinessAcquisition(readOnce, options).result();
|
|
812
|
+
}
|
|
603
813
|
/**
|
|
604
814
|
* GET auth headers. The API key travels ONLY in a header, never in the URL.
|
|
605
815
|
*
|
|
@@ -643,7 +853,7 @@ export async function fetchConductorJsonWithTimeout(url, headers, timeoutMs, fet
|
|
|
643
853
|
return await resp.json();
|
|
644
854
|
}
|
|
645
855
|
catch {
|
|
646
|
-
throw new ConductorBridgeApiError("network");
|
|
856
|
+
throw new ConductorBridgeApiError("network", undefined, { unreadableSuccess: true });
|
|
647
857
|
}
|
|
648
858
|
}
|
|
649
859
|
finally {
|
|
@@ -803,7 +1013,7 @@ async function fetchConductorJsonWithMethodStatusAndTimeout(method, url, headers
|
|
|
803
1013
|
return { status: resp.status, body: await resp.json() };
|
|
804
1014
|
}
|
|
805
1015
|
catch {
|
|
806
|
-
throw new ConductorBridgeApiError("network");
|
|
1016
|
+
throw new ConductorBridgeApiError("network", undefined, { unreadableSuccess: true });
|
|
807
1017
|
}
|
|
808
1018
|
}
|
|
809
1019
|
finally {
|
|
@@ -1058,7 +1268,7 @@ export async function claimEpicSupervisionLease(access, request, fetchImpl = glo
|
|
|
1058
1268
|
* Returns the server payload verbatim — no ready-set computation, plan-hash
|
|
1059
1269
|
* assertion, or derived control-loop fields are added.
|
|
1060
1270
|
*/
|
|
1061
|
-
export async function fetchEpicRunState(access, epicKey, fetchImpl = globalThis.fetch, options) {
|
|
1271
|
+
export async function fetchEpicRunState(access, epicKey, fetchImpl = globalThis.fetch, options, timeoutMs) {
|
|
1062
1272
|
requireNonEmptyString(epicKey);
|
|
1063
1273
|
// Defaulted in the body, not the signature: the source-boundary test brace-matches
|
|
1064
1274
|
// from the first open brace after the function name, so a default object literal
|
|
@@ -1072,7 +1282,9 @@ export async function fetchEpicRunState(access, epicKey, fetchImpl = globalThis.
|
|
|
1072
1282
|
if (readOptions.ticket_key !== undefined)
|
|
1073
1283
|
params.ticket_key = readOptions.ticket_key;
|
|
1074
1284
|
const url = buildConductorJiraUrl(access.baseUrl, `${epicRunApiPath(epicKey)}/state`, params);
|
|
1075
|
-
|
|
1285
|
+
// BAPI-1593 — a caller reconciling against one overall deadline caps this GET
|
|
1286
|
+
// to the time it has left; every other caller keeps the default budget.
|
|
1287
|
+
const parsed = await fetchConductorJsonWithTimeout(url, conductorGetHeaders(access), timeoutMs ?? CONDUCTOR_FETCH_TIMEOUT_MS, fetchImpl);
|
|
1076
1288
|
return parsed;
|
|
1077
1289
|
}
|
|
1078
1290
|
/**
|
|
@@ -1129,6 +1341,79 @@ export async function fetchStoredTicket(access, ticketNumber, fetchImpl = global
|
|
|
1129
1341
|
}
|
|
1130
1342
|
return { ticket_number: ticketNumber, description: record["description"] };
|
|
1131
1343
|
}
|
|
1344
|
+
/**
|
|
1345
|
+
* BAPI-1621 — GET `/jira/tickets/{ticket_number}` for a description that may be
|
|
1346
|
+
* blank. The server returns `null` (or omits the field) for a ticket with no
|
|
1347
|
+
* body, and that is a successful read of absent text: it maps to `""`.
|
|
1348
|
+
* {@link fetchStoredTicket} stays strict for its own callers. A mismatched key or
|
|
1349
|
+
* any other non-string description is still a shape failure, and transport and
|
|
1350
|
+
* HTTP failures throw exactly as `fetchStoredTicket` does.
|
|
1351
|
+
*/
|
|
1352
|
+
export async function fetchStoredTicketDescription(access, ticketNumber, fetchImpl = globalThis.fetch) {
|
|
1353
|
+
requireNonEmptyString(ticketNumber);
|
|
1354
|
+
requireNoSlashPathSegment(ticketNumber);
|
|
1355
|
+
const url = buildConductorJiraUrl(access.baseUrl, `/tickets/${encodeURIComponent(ticketNumber)}`, { repo_name: access.repoName });
|
|
1356
|
+
const parsed = await fetchConductorJsonWithTimeout(url, conductorGetHeaders(access), CONDUCTOR_FETCH_TIMEOUT_MS, fetchImpl, { readErrorField: true });
|
|
1357
|
+
const record = parsed && typeof parsed === "object" && !Array.isArray(parsed)
|
|
1358
|
+
? parsed
|
|
1359
|
+
: undefined;
|
|
1360
|
+
if (!record || record["ticket_number"] !== ticketNumber) {
|
|
1361
|
+
throw new ConductorBridgeApiError("http", 200);
|
|
1362
|
+
}
|
|
1363
|
+
const description = record["description"];
|
|
1364
|
+
if (description === null || description === undefined)
|
|
1365
|
+
return "";
|
|
1366
|
+
if (typeof description !== "string")
|
|
1367
|
+
throw new ConductorBridgeApiError("http", 200);
|
|
1368
|
+
return description;
|
|
1369
|
+
}
|
|
1370
|
+
/** null for an absent value, the string for a string, undefined for anything else. */
|
|
1371
|
+
function epicChildField(value) {
|
|
1372
|
+
if (value === null || value === undefined)
|
|
1373
|
+
return null;
|
|
1374
|
+
return typeof value === "string" ? value : undefined;
|
|
1375
|
+
}
|
|
1376
|
+
/**
|
|
1377
|
+
* GET `/jira/tickets/{epic_key}/children` — the epic's direct children through
|
|
1378
|
+
* the server's ticket-store seam, for both ticket backends.
|
|
1379
|
+
*
|
|
1380
|
+
* Failed requests throw a sanitized {@link ConductorBridgeApiError}. A body that
|
|
1381
|
+
* does not match the strict shape also throws, as a protocol error, so a caller
|
|
1382
|
+
* can always tell "the read failed" from "the list is incomplete"
|
|
1383
|
+
* (`enumeration_complete: false`) from "the epic has no children" (an empty,
|
|
1384
|
+
* complete list).
|
|
1385
|
+
*/
|
|
1386
|
+
export async function fetchEpicChildren(access, epicKey, fetchImpl = globalThis.fetch) {
|
|
1387
|
+
requireNonEmptyString(epicKey);
|
|
1388
|
+
requireNoSlashPathSegment(epicKey);
|
|
1389
|
+
const url = buildConductorJiraUrl(access.baseUrl, `/tickets/${encodeURIComponent(epicKey)}/children`, { repo_name: access.repoName });
|
|
1390
|
+
const parsed = await fetchConductorJsonWithTimeout(url, conductorGetHeaders(access), CONDUCTOR_FETCH_TIMEOUT_MS, fetchImpl, { readErrorField: true });
|
|
1391
|
+
const record = parsed && typeof parsed === "object" && !Array.isArray(parsed)
|
|
1392
|
+
? parsed
|
|
1393
|
+
: undefined;
|
|
1394
|
+
if (!record ||
|
|
1395
|
+
record["epic_key"] !== epicKey ||
|
|
1396
|
+
typeof record["enumeration_complete"] !== "boolean" ||
|
|
1397
|
+
!Array.isArray(record["children"])) {
|
|
1398
|
+
throw new ConductorBridgeApiError("http", 200);
|
|
1399
|
+
}
|
|
1400
|
+
const children = [];
|
|
1401
|
+
for (const raw of record["children"]) {
|
|
1402
|
+
const child = raw && typeof raw === "object" && !Array.isArray(raw) ? raw : undefined;
|
|
1403
|
+
const key = child?.["ticket_key"];
|
|
1404
|
+
if (!child || typeof key !== "string" || key.trim() === "") {
|
|
1405
|
+
throw new ConductorBridgeApiError("http", 200);
|
|
1406
|
+
}
|
|
1407
|
+
const status = epicChildField(child["status"]);
|
|
1408
|
+
const category = epicChildField(child["status_category"]);
|
|
1409
|
+
const issueType = epicChildField(child["issue_type"]);
|
|
1410
|
+
if (status === undefined || category === undefined || issueType === undefined) {
|
|
1411
|
+
throw new ConductorBridgeApiError("http", 200);
|
|
1412
|
+
}
|
|
1413
|
+
children.push({ ticket_key: key, status, status_category: category, issue_type: issueType });
|
|
1414
|
+
}
|
|
1415
|
+
return { epic_key: epicKey, children, enumeration_complete: record["enumeration_complete"] };
|
|
1416
|
+
}
|
|
1132
1417
|
// ---------------------------------------------------------------------------
|
|
1133
1418
|
// Executor wind-down: read-only completion-state projection (BAPI-1010)
|
|
1134
1419
|
// ---------------------------------------------------------------------------
|
|
@@ -1206,6 +1491,56 @@ export async function readEpicRunCompletionState(access, epicRunId, fetchImpl =
|
|
|
1206
1491
|
state: featureBranch !== undefined ? { status, featureBranch } : { status },
|
|
1207
1492
|
};
|
|
1208
1493
|
}
|
|
1494
|
+
// ---------------------------------------------------------------------------
|
|
1495
|
+
// BAPI-1545 — the advisory capability statement
|
|
1496
|
+
// ---------------------------------------------------------------------------
|
|
1497
|
+
/** Install's bound on the statement write; a failure only warns. */
|
|
1498
|
+
export const EPIC_CAPABILITY_STATEMENT_WRITE_TIMEOUT_MS = 15_000;
|
|
1499
|
+
/** The worker-spawn read is advisory and short. */
|
|
1500
|
+
export const EPIC_CAPABILITY_STATEMENT_READ_TIMEOUT_MS = 5_000;
|
|
1501
|
+
const EPIC_CAPABILITY_STATEMENT_PATH = `${EPIC_RUNS_API_PREFIX}/capability-statement`;
|
|
1502
|
+
/**
|
|
1503
|
+
* PUT `/jira/epic-runs/capability-statement` with `{repo_name, statement}`.
|
|
1504
|
+
* Throws a sanitized {@link ConductorBridgeApiError} on any failure; install
|
|
1505
|
+
* catches it and prints one warning. The statement is advisory: it is never an
|
|
1506
|
+
* authorization source.
|
|
1507
|
+
*/
|
|
1508
|
+
export async function writeEpicCapabilityStatement(access, statement, fetchImpl, timeoutMs = EPIC_CAPABILITY_STATEMENT_WRITE_TIMEOUT_MS) {
|
|
1509
|
+
const url = buildConductorJiraUrl(access.baseUrl, EPIC_CAPABILITY_STATEMENT_PATH);
|
|
1510
|
+
await fetchConductorJsonPutWithTimeout(url, conductorPostHeaders(access), JSON.stringify({ repo_name: access.repoName, statement }), timeoutMs, fetchImpl);
|
|
1511
|
+
}
|
|
1512
|
+
/**
|
|
1513
|
+
* GET `/jira/epic-runs/capability-statement?repo_name=`. Never throws. Any
|
|
1514
|
+
* transport or shape failure is a reason the caller treats as "append nothing".
|
|
1515
|
+
*/
|
|
1516
|
+
export async function readEpicCapabilityStatement(access, fetchImpl = globalThis.fetch, timeoutMs = EPIC_CAPABILITY_STATEMENT_READ_TIMEOUT_MS) {
|
|
1517
|
+
let parsed;
|
|
1518
|
+
try {
|
|
1519
|
+
const url = buildConductorJiraUrl(access.baseUrl, EPIC_CAPABILITY_STATEMENT_PATH, { repo_name: access.repoName });
|
|
1520
|
+
parsed = await fetchConductorJsonWithTimeout(url, conductorGetHeaders(access), timeoutMs, fetchImpl);
|
|
1521
|
+
}
|
|
1522
|
+
catch (err) {
|
|
1523
|
+
if (err instanceof ConductorBridgeApiError) {
|
|
1524
|
+
if (err.kind === "timeout")
|
|
1525
|
+
return { ok: false, reason: "timeout" };
|
|
1526
|
+
if (err.kind === "unauthorized")
|
|
1527
|
+
return { ok: false, reason: "unauthorized" };
|
|
1528
|
+
if (err.kind === "server")
|
|
1529
|
+
return { ok: false, reason: "server" };
|
|
1530
|
+
if (err.kind === "http")
|
|
1531
|
+
return { ok: false, reason: "http" };
|
|
1532
|
+
}
|
|
1533
|
+
return { ok: false, reason: "network" };
|
|
1534
|
+
}
|
|
1535
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
|
|
1536
|
+
return { ok: false, reason: "malformed" };
|
|
1537
|
+
const doc = parsed;
|
|
1538
|
+
if (doc.state === "present")
|
|
1539
|
+
return { ok: true, state: "present", statement: doc.statement };
|
|
1540
|
+
if (doc.state === "absent" || doc.state === "unavailable")
|
|
1541
|
+
return { ok: true, state: doc.state };
|
|
1542
|
+
return { ok: false, reason: "malformed" };
|
|
1543
|
+
}
|
|
1209
1544
|
/**
|
|
1210
1545
|
* GET `/jira/epic-runs/runs?repo_name=<repo>&status=active` and return the
|
|
1211
1546
|
* list of active epic runs. Caps at 20 results — enough for typical deployments
|
|
@@ -1323,8 +1658,16 @@ export async function createEpicRunWithDisposition(access, request, fetchImpl =
|
|
|
1323
1658
|
body.budget_cost_cents = request.budgetCostCents;
|
|
1324
1659
|
}
|
|
1325
1660
|
const url = buildConductorJiraUrl(access.baseUrl, `${EPIC_RUNS_API_PREFIX}/runs`);
|
|
1326
|
-
|
|
1327
|
-
|
|
1661
|
+
// BAPI-1593 — sent exactly once. An uncertain outcome throws
|
|
1662
|
+
// `ConductorMutationOutcomeUnknownError`; the caller re-reads, never re-sends.
|
|
1663
|
+
let response;
|
|
1664
|
+
try {
|
|
1665
|
+
response = await fetchConductorJsonWithMethodStatusAndTimeout("POST", url, conductorPostHeaders(access), JSON.stringify(body), CONDUCTOR_FETCH_TIMEOUT_MS, fetchImpl);
|
|
1666
|
+
}
|
|
1667
|
+
catch (err) {
|
|
1668
|
+
rethrowMutationFailure("create", err);
|
|
1669
|
+
}
|
|
1670
|
+
return { run: response.body, created: response.status === 201 };
|
|
1328
1671
|
}
|
|
1329
1672
|
/**
|
|
1330
1673
|
* PATCH `/jira/epic-runs/runs/{identifier}` with a COMPLETE replacement of the
|
|
@@ -2795,6 +3138,8 @@ export function parseRecordSkippedChildrenResponse(parsed, expectedKeys) {
|
|
|
2795
3138
|
function safeCount(value) {
|
|
2796
3139
|
return typeof value === "number" && Number.isSafeInteger(value) && value >= 0 ? value : 0;
|
|
2797
3140
|
}
|
|
3141
|
+
const GATE_PROFILE_STAMP_REASON_RE = /^[a-z0-9_]+$/;
|
|
3142
|
+
const ESCALATION_WARNING_RE = /^[a-z][a-z0-9_]{0,63}$/;
|
|
2798
3143
|
/**
|
|
2799
3144
|
* POST the immutable plan blob to the durable-store endpoint. The blob is
|
|
2800
3145
|
* written once per `(epic_run_id, plan_version)` and never mutated — a
|
|
@@ -2892,6 +3237,24 @@ function parseApproveEpicPlanSuccess(parsed) {
|
|
|
2892
3237
|
};
|
|
2893
3238
|
}
|
|
2894
3239
|
}
|
|
3240
|
+
// BAPI-1602 — tolerant: only a bounded snake_case token is kept.
|
|
3241
|
+
const escalationWarning = record["escalation_warning"];
|
|
3242
|
+
if (typeof escalationWarning === "string" && ESCALATION_WARNING_RE.test(escalationWarning)) {
|
|
3243
|
+
result.escalationWarning = escalationWarning;
|
|
3244
|
+
}
|
|
3245
|
+
// BAPI-1601 — tolerant: only a non-null, non-array object yields a stamp, and
|
|
3246
|
+
// nothing about it can fail an approval that already succeeded.
|
|
3247
|
+
const stamp = record["gate_profile_stamp"];
|
|
3248
|
+
if (stamp && typeof stamp === "object" && !Array.isArray(stamp)) {
|
|
3249
|
+
const raw = stamp;
|
|
3250
|
+
const reasons = Array.isArray(raw["reasons"])
|
|
3251
|
+
? raw["reasons"].filter((reason) => typeof reason === "string" && GATE_PROFILE_STAMP_REASON_RE.test(reason))
|
|
3252
|
+
: [];
|
|
3253
|
+
result.gateProfileStamp = {
|
|
3254
|
+
autoMerge: typeof raw["auto_merge"] === "boolean" ? raw["auto_merge"] : "unknown",
|
|
3255
|
+
reasons,
|
|
3256
|
+
};
|
|
3257
|
+
}
|
|
2895
3258
|
return result;
|
|
2896
3259
|
}
|
|
2897
3260
|
export async function approveEpicPlan(access, request, fetchImpl = globalThis.fetch) {
|
|
@@ -2903,7 +3266,9 @@ export async function approveEpicPlan(access, request, fetchImpl = globalThis.fe
|
|
|
2903
3266
|
plan_version: request.planVersion,
|
|
2904
3267
|
});
|
|
2905
3268
|
try {
|
|
2906
|
-
|
|
3269
|
+
// BAPI-1593 — sent exactly once, with the approval budget. An uncertain
|
|
3270
|
+
// outcome throws `ConductorMutationOutcomeUnknownError` (see the catch).
|
|
3271
|
+
const parsed = await fetchConductorJsonPostWithTimeout(url, conductorPostHeaders(access), body, CONDUCTOR_APPROVE_FETCH_TIMEOUT_MS, fetchImpl);
|
|
2907
3272
|
return parseApproveEpicPlanSuccess(parsed);
|
|
2908
3273
|
}
|
|
2909
3274
|
catch (error) {
|
|
@@ -2918,9 +3283,23 @@ export async function approveEpicPlan(access, request, fetchImpl = globalThis.fe
|
|
|
2918
3283
|
if (/multiple active runs/i.test(preview)) {
|
|
2919
3284
|
return { ok: false, kind: "conflict", reason: "multiple_active_runs" };
|
|
2920
3285
|
}
|
|
2921
|
-
|
|
3286
|
+
// BAPI-1585: "superseded" is only the server's bare-string message (both the
|
|
3287
|
+
// ordinary and the concurrent-CAS wording). Any other 409 — a structured
|
|
3288
|
+
// refusal such as UNATTENDED_POSTURE_REFUSED, or a shape we do not
|
|
3289
|
+
// recognize — is a refusal and is never reported as benign.
|
|
3290
|
+
if (error.detailKind === "string" && /superseded/i.test(preview)) {
|
|
3291
|
+
return { ok: false, kind: "conflict", reason: "superseded" };
|
|
3292
|
+
}
|
|
3293
|
+
const code = error.errorCode;
|
|
3294
|
+
return {
|
|
3295
|
+
ok: false,
|
|
3296
|
+
kind: "refused",
|
|
3297
|
+
error_code: typeof code === "string" && REFUSAL_ERROR_CODE_RE.test(code) ? code : "unknown",
|
|
3298
|
+
predicate: error.predicate ?? "unknown",
|
|
3299
|
+
reason_code: error.reasonCode ?? "unknown",
|
|
3300
|
+
};
|
|
2922
3301
|
}
|
|
2923
|
-
|
|
3302
|
+
rethrowMutationFailure("approve", error);
|
|
2924
3303
|
}
|
|
2925
3304
|
}
|
|
2926
3305
|
/**
|
|
@@ -3294,6 +3673,17 @@ export const REQUIRED_CHECKS_VERIFICATIONS = new Set([
|
|
|
3294
3673
|
"unknown_name",
|
|
3295
3674
|
"unverifiable",
|
|
3296
3675
|
]);
|
|
3676
|
+
/**
|
|
3677
|
+
* BAPI-1602 — prerequisite rows an OLDER server may still send after this build
|
|
3678
|
+
* stopped knowing them. A retired row is kept and rendered with the server's own
|
|
3679
|
+
* text, never dropped and never fatal, because dropping it would hide a blocker
|
|
3680
|
+
* the older server also enforces. Only rows named here get this treatment.
|
|
3681
|
+
*/
|
|
3682
|
+
const RETIRED_READINESS_PREREQUISITE_IDS = new Set(['server.test-command']);
|
|
3683
|
+
const RETIRED_ROW_TEXT_MAX = 400;
|
|
3684
|
+
function isBoundedServerText(value) {
|
|
3685
|
+
return typeof value === 'string' && value.length <= RETIRED_ROW_TEXT_MAX && !/[\u0000-\u001f\u007f]/.test(value);
|
|
3686
|
+
}
|
|
3297
3687
|
export function parseReadinessPrerequisites(raw) {
|
|
3298
3688
|
if (!Array.isArray(raw))
|
|
3299
3689
|
return undefined;
|
|
@@ -3303,10 +3693,20 @@ export function parseReadinessPrerequisites(raw) {
|
|
|
3303
3693
|
if (typeof item !== 'object' || item === null || Array.isArray(item))
|
|
3304
3694
|
return undefined;
|
|
3305
3695
|
const r = item;
|
|
3696
|
+
if (typeof r.id === 'string' && RETIRED_READINESS_PREREQUISITE_IDS.has(r.id) && !READINESS_PREREQUISITE_BY_ID.has(r.id)) {
|
|
3697
|
+
if (seen.has(r.id) || Object.keys(r).sort().join(',') !== 'check_status,fix,id,impact,label,scope' ||
|
|
3698
|
+
!isBoundedServerText(r.label) || !isBoundedServerText(r.fix) || !['customer', 'self_host'].includes(String(r.scope)) ||
|
|
3699
|
+
!['met', 'not_met', 'unknown', 'not_applicable'].includes(String(r.check_status)) || !['blocking', 'warning', 'info'].includes(String(r.impact)) ||
|
|
3700
|
+
(r.check_status === 'unknown' && r.impact === 'blocking'))
|
|
3701
|
+
return undefined;
|
|
3702
|
+
seen.add(r.id);
|
|
3703
|
+
result.push(r);
|
|
3704
|
+
continue;
|
|
3705
|
+
}
|
|
3306
3706
|
const d = typeof r.id === 'string' ? READINESS_PREREQUISITE_BY_ID.get(r.id) : undefined;
|
|
3307
3707
|
if (!d || seen.has(d.id) || Object.keys(r).sort().join(',') !== 'check_status,fix,id,impact,label,scope' || r.label !== d.label || r.scope !== d.scope ||
|
|
3308
3708
|
!['met', 'not_met', 'unknown', 'not_applicable'].includes(String(r.check_status)) || !['blocking', 'warning', 'info'].includes(String(r.impact)) ||
|
|
3309
|
-
typeof r.fix !== 'string' || !Object.values(READINESS_PREREQUISITE_FIXES).includes(r.fix) ||
|
|
3709
|
+
typeof r.fix !== 'string' || !(Object.values(READINESS_PREREQUISITE_FIXES).includes(r.fix) || PREVIOUS_SERVER_READINESS_FIXES.includes(r.fix)) ||
|
|
3310
3710
|
(r.check_status === 'unknown' && r.impact === 'blocking'))
|
|
3311
3711
|
return undefined;
|
|
3312
3712
|
seen.add(d.id);
|
|
@@ -3349,15 +3749,33 @@ export const GATE_PROFILE_ADMISSION_REASONS = [
|
|
|
3349
3749
|
export const GATE_PROFILE_WARNING_CODES = [
|
|
3350
3750
|
"provider_check_not_seen_on_epic_branches",
|
|
3351
3751
|
"epic_branch_search_unavailable",
|
|
3752
|
+
// BAPI-1606: warn-only rows for WATCHED checks. They never hold a launch.
|
|
3753
|
+
"watched_check_not_seen",
|
|
3754
|
+
"watched_check_evidence_unavailable",
|
|
3755
|
+
];
|
|
3756
|
+
/**
|
|
3757
|
+
* BAPI-1606 — the closed reasons a watched check can warn with at run time. The
|
|
3758
|
+
* `explain_run` tool returns the server's projection unparsed, so these are named
|
|
3759
|
+
* here only as the contract surface; no runtime warning parser exists.
|
|
3760
|
+
*/
|
|
3761
|
+
export const WATCHED_CHECK_WARNING_REASONS = [
|
|
3762
|
+
"watched_check_missing",
|
|
3763
|
+
"watched_check_pending",
|
|
3764
|
+
"watched_check_did_not_run",
|
|
3765
|
+
"watched_check_unavailable",
|
|
3352
3766
|
];
|
|
3353
3767
|
/**
|
|
3354
3768
|
* True when the server's rules waive the CI lane file
|
|
3355
3769
|
* (`.github/workflows/epic-implementer-ci.yml`): a repository with a STORED gate
|
|
3356
|
-
* profile names its own checks, so the lane file is not required.
|
|
3357
|
-
*
|
|
3770
|
+
* profile names its own checks, so the lane file is not required. BAPI-1602: so
|
|
3771
|
+
* does a repository whose readable configured checks are its own reporting CI,
|
|
3772
|
+
* which the server reports as one bounded fact (`supervisor.reporting_ci_configured`).
|
|
3773
|
+
* Nothing is inferred from recent CI runs. Absent profile or fact (older server, or
|
|
3774
|
+
* an unreadable configuration) keeps the lane-file requirement exactly as before.
|
|
3358
3775
|
*/
|
|
3359
3776
|
export function gateProfileWaivesCiWorkflow(readiness) {
|
|
3360
|
-
return readiness.gate_profile?.source === "stored"
|
|
3777
|
+
return readiness.gate_profile?.source === "stored" ||
|
|
3778
|
+
readiness.supervisor?.reporting_ci_configured === true;
|
|
3361
3779
|
}
|
|
3362
3780
|
/** BAPI-1405 — the review mode the server will actually apply to this repository. */
|
|
3363
3781
|
export const EFFECTIVE_REVIEW_MODES = [
|
|
@@ -3630,6 +4048,7 @@ export function parseConductorReadinessResponse(body) {
|
|
|
3630
4048
|
required_checks_retired_gate_configured: parseOptionalBool(sup, "required_checks_retired_gate_configured"),
|
|
3631
4049
|
required_checks_ci_workflow_absent: parseOptionalBool(sup, "required_checks_ci_workflow_absent"),
|
|
3632
4050
|
required_checks_review_workflow_absent: parseOptionalBool(sup, "required_checks_review_workflow_absent"),
|
|
4051
|
+
reporting_ci_configured: parseOptionalBool(sup, "reporting_ci_configured"),
|
|
3633
4052
|
},
|
|
3634
4053
|
github: {
|
|
3635
4054
|
credentials_readable: requireBool(gh, "credentials_readable"),
|
|
@@ -3897,6 +4316,7 @@ function parseGateProfile(body) {
|
|
|
3897
4316
|
revision,
|
|
3898
4317
|
provider_checks: list(o.provider_checks).map((c) => ({
|
|
3899
4318
|
name: requiredName(c.name),
|
|
4319
|
+
watched: c.watched === true,
|
|
3900
4320
|
outcome: enumOrNull(c.outcome, ["reported", "unseen", "evidence_unavailable"]),
|
|
3901
4321
|
epic_branch_seen: boolOrNull(c.epic_branch_seen),
|
|
3902
4322
|
})),
|
|
@@ -3922,8 +4342,37 @@ function parseGateProfile(body) {
|
|
|
3922
4342
|
code: tokenOrNull(w.code) ?? "unknown",
|
|
3923
4343
|
name: safeSubject(w.name),
|
|
3924
4344
|
})),
|
|
4345
|
+
...optionalWorkerSetupFields(o),
|
|
3925
4346
|
};
|
|
3926
4347
|
}
|
|
4348
|
+
/**
|
|
4349
|
+
* BAPI-1598. The two additive readiness fields. LENIENT by design: an older
|
|
4350
|
+
* server omits them, and a value this client does not understand is omitted too,
|
|
4351
|
+
* never turned into confirmed evidence and never a shape error (a readiness body
|
|
4352
|
+
* that cannot be read would become "no readiness at all").
|
|
4353
|
+
*/
|
|
4354
|
+
function optionalWorkerSetupFields(o) {
|
|
4355
|
+
const out = {};
|
|
4356
|
+
const handoff = o.verification_handoff_default;
|
|
4357
|
+
if (handoff === "proceed" || handoff === "block")
|
|
4358
|
+
out.verification_handoff_default = handoff;
|
|
4359
|
+
const raw = o.worker_database;
|
|
4360
|
+
if (typeof raw === "object" && raw !== null && !Array.isArray(raw)) {
|
|
4361
|
+
const w = raw;
|
|
4362
|
+
const names = w.protected_databases;
|
|
4363
|
+
if ((w.mode === "none" || w.mode === "disposable_postgres") &&
|
|
4364
|
+
(names === undefined || names === null ||
|
|
4365
|
+
(Array.isArray(names) && names.length <= 16 && names.every((n) => safeSubject(n) !== null)))) {
|
|
4366
|
+
const role = safeSubject(w.worker_role);
|
|
4367
|
+
out.worker_database = {
|
|
4368
|
+
mode: w.mode,
|
|
4369
|
+
protected_databases: Array.isArray(names) ? names : [],
|
|
4370
|
+
worker_role: role,
|
|
4371
|
+
};
|
|
4372
|
+
}
|
|
4373
|
+
}
|
|
4374
|
+
return out;
|
|
4375
|
+
}
|
|
3927
4376
|
const EPIC_BRANCH_CI_DECISIONS = new Set(["include", "decline"]);
|
|
3928
4377
|
const EPIC_BRANCH_CI_OBSERVATION_QUALITIES = new Set(["exact", "inferred", "could_not_tell"]);
|
|
3929
4378
|
const EPIC_BRANCH_CI_EXEMPTION_OUTCOMES = new Set(["exempt", "not_exempt", "unknown"]);
|
|
@@ -4044,6 +4493,9 @@ function parseMergeExecution(body) {
|
|
|
4044
4493
|
throw readinessShapeError();
|
|
4045
4494
|
}
|
|
4046
4495
|
return {
|
|
4496
|
+
...(o.probe_skipped_reason === "merge_execution_mode_not_github_actions"
|
|
4497
|
+
? { probe_skipped_reason: "merge_execution_mode_not_github_actions" }
|
|
4498
|
+
: {}),
|
|
4047
4499
|
branch_scope: requireEnum(o, "branch_scope", MERGE_EXECUTION_BRANCH_SCOPES),
|
|
4048
4500
|
branch_protection_probe_succeeded: requireBool(o, "branch_protection_probe_succeeded"),
|
|
4049
4501
|
branch_protection_actions_bot_admitted: requireBool(o, "branch_protection_actions_bot_admitted"),
|
|
@@ -4151,7 +4603,7 @@ export async function fetchConductorReadiness(access, fetchImpl = globalThis.fet
|
|
|
4151
4603
|
// `detail.error` (the applied stamp, the missing objects, the repair route),
|
|
4152
4604
|
// so that field is read, with room for the object names.
|
|
4153
4605
|
try {
|
|
4154
|
-
const body = await fetchConductorJsonWithTimeout(url, conductorGetHeaders(access),
|
|
4606
|
+
const body = await fetchConductorJsonWithTimeout(url, conductorGetHeaders(access), CONDUCTOR_READINESS_FETCH_TIMEOUT_MS, fetchImpl, { readErrorField: true, errorFieldPreviewMax: SCHEMA_REFUSAL_PREVIEW_MAX, readErrorFieldOnlyFor: [SCHEMA_INCOMPATIBLE_ERROR_CODE] });
|
|
4155
4607
|
const parsed = parseConductorReadinessResponse(body);
|
|
4156
4608
|
if (options.assessmentVersion === 1) {
|
|
4157
4609
|
const negotiation = parseAssessmentNegotiation(requireObject(body));
|
|
@@ -4754,6 +5206,21 @@ export async function regeneratePlanTicket(access, request, fetchImpl = globalTh
|
|
|
4754
5206
|
// nothing here echoes a response body, the API key, or command output.
|
|
4755
5207
|
/** The capability token the gate-profile server answers (BAPI-1390). */
|
|
4756
5208
|
export const GATE_PROFILE_CAPABILITY_TOKEN = "gate_profile.v1";
|
|
5209
|
+
/**
|
|
5210
|
+
* The additive capability a server answers when it accepts and stores a provider
|
|
5211
|
+
* check as watched (BAPI-1606). It follows {@link GATE_PROFILE_CAPABILITY_TOKEN}
|
|
5212
|
+
* and never replaces it. Setup reads it through
|
|
5213
|
+
* {@link probeConductorGateProfileWatchedCapability}.
|
|
5214
|
+
*/
|
|
5215
|
+
export const GATE_PROFILE_WATCHED_CAPABILITY_TOKEN = "gate_profile.watched.v1";
|
|
5216
|
+
/**
|
|
5217
|
+
* The additive capability a server answers when it accepts and stores the
|
|
5218
|
+
* optional `worker_database` and `verification_handoff_default` settings
|
|
5219
|
+
* (BAPI-1598). It follows {@link GATE_PROFILE_WATCHED_CAPABILITY_TOKEN} and never
|
|
5220
|
+
* replaces it. Its absence is informational: setup then skips only those two
|
|
5221
|
+
* fields, and nothing about creating, approving, or launching a run depends on it.
|
|
5222
|
+
*/
|
|
5223
|
+
export const GATE_PROFILE_WORKER_SETUP_CAPABILITY_TOKEN = "gate_profile.worker_setup.v1";
|
|
4757
5224
|
const GATE_PROFILE_KINDS = new Set(["provider", "local", "mixed", "none"]);
|
|
4758
5225
|
const GATE_PROFILE_SOURCES = new Set(["stored", "legacy", "unconfirmed"]);
|
|
4759
5226
|
const GATE_QUALIFICATION_STATES = new Set(["qualified", "unqualified", "stale", "not_required"]);
|
|
@@ -4777,6 +5244,8 @@ const GATE_MAX_LOCAL_COMMANDS = 16;
|
|
|
4777
5244
|
const GATE_MAX_CUSTOMIZED = 64;
|
|
4778
5245
|
/** The provider-history walk makes bounded provider calls; give it longer. */
|
|
4779
5246
|
const GATE_CHECK_HISTORY_TIMEOUT_MS = 90_000;
|
|
5247
|
+
/** The learned-command request makes one model call on the server; give it longer. */
|
|
5248
|
+
const CONDUCTOR_LEARNED_TEST_COMMAND_TIMEOUT_MS = 90_000;
|
|
4780
5249
|
const GATE_MAX_WORKER_ENV = 32;
|
|
4781
5250
|
const GATE_WORKER_ENV_VALUE_MAX_BYTES = 1024;
|
|
4782
5251
|
const GATE_WORKER_ENV_NAME_RE = /^[A-Z_][A-Z0-9_]{0,63}$/;
|
|
@@ -4843,6 +5312,20 @@ function parseDependencyInstallField(raw) {
|
|
|
4843
5312
|
throw readinessShapeError();
|
|
4844
5313
|
return entries.length > 0 ? entries : undefined;
|
|
4845
5314
|
}
|
|
5315
|
+
/**
|
|
5316
|
+
* BAPI-1580 — parse a returned `must_order_paths` list, fail-closed. Absent or
|
|
5317
|
+
* `null` is no declaration; any invalid entry, duplicate, or over-bound list
|
|
5318
|
+
* throws the field-free shape error, never a partly trusted or emptied list.
|
|
5319
|
+
* Returns the canonical sorted list.
|
|
5320
|
+
*/
|
|
5321
|
+
function parseMustOrderPathsField(raw) {
|
|
5322
|
+
if (raw === undefined || raw === null)
|
|
5323
|
+
return [];
|
|
5324
|
+
const paths = parseMustOrderPathsStrict(raw);
|
|
5325
|
+
if (paths === null)
|
|
5326
|
+
throw readinessShapeError();
|
|
5327
|
+
return paths;
|
|
5328
|
+
}
|
|
4846
5329
|
/** BAPI-1551 — absent or `null` is `unknown`; any other non-enum value throws. */
|
|
4847
5330
|
function parseCiDatabaseField(raw) {
|
|
4848
5331
|
if (raw === undefined || raw === null)
|
|
@@ -4851,6 +5334,71 @@ function parseCiDatabaseField(raw) {
|
|
|
4851
5334
|
throw readinessShapeError();
|
|
4852
5335
|
return raw;
|
|
4853
5336
|
}
|
|
5337
|
+
/** BAPI-1598. Parse a returned worker-database declaration, fail-closed; absent and `null` read as unset. */
|
|
5338
|
+
function parseWorkerDatabaseField(raw) {
|
|
5339
|
+
if (raw === undefined || raw === null)
|
|
5340
|
+
return undefined;
|
|
5341
|
+
const o = requireObject(raw);
|
|
5342
|
+
for (const key of Object.keys(o)) {
|
|
5343
|
+
if (!["mode", "worker_role", "protected_databases", "env_names", "migrate_command"].includes(key)) {
|
|
5344
|
+
throw readinessShapeError();
|
|
5345
|
+
}
|
|
5346
|
+
}
|
|
5347
|
+
const mode = o.mode === undefined ? "none" : o.mode;
|
|
5348
|
+
if (mode !== "none" && mode !== "disposable_postgres")
|
|
5349
|
+
throw readinessShapeError();
|
|
5350
|
+
const names = (value) => {
|
|
5351
|
+
if (value === undefined || value === null)
|
|
5352
|
+
return undefined;
|
|
5353
|
+
if (!Array.isArray(value) || value.length > 16 || value.some((n) => typeof n !== "string" || n.length === 0 || n.length > 128)) {
|
|
5354
|
+
throw readinessShapeError();
|
|
5355
|
+
}
|
|
5356
|
+
return value;
|
|
5357
|
+
};
|
|
5358
|
+
const out = { mode };
|
|
5359
|
+
if (o.worker_role !== undefined && o.worker_role !== null) {
|
|
5360
|
+
if (typeof o.worker_role !== "string" || o.worker_role.length === 0 || o.worker_role.length > 128)
|
|
5361
|
+
throw readinessShapeError();
|
|
5362
|
+
out.worker_role = o.worker_role;
|
|
5363
|
+
}
|
|
5364
|
+
const protectedDatabases = names(o.protected_databases);
|
|
5365
|
+
if (protectedDatabases)
|
|
5366
|
+
out.protected_databases = protectedDatabases;
|
|
5367
|
+
const envNames = names(o.env_names);
|
|
5368
|
+
if (envNames)
|
|
5369
|
+
out.env_names = envNames;
|
|
5370
|
+
if (o.migrate_command !== undefined && o.migrate_command !== null) {
|
|
5371
|
+
const m = requireObject(o.migrate_command);
|
|
5372
|
+
for (const key of Object.keys(m)) {
|
|
5373
|
+
if (key !== "argv" && key !== "timeout_seconds" && key !== "head_check")
|
|
5374
|
+
throw readinessShapeError();
|
|
5375
|
+
}
|
|
5376
|
+
const argv = m.argv;
|
|
5377
|
+
if (!Array.isArray(argv) || argv.length === 0 || argv.length > GATE_MAX_ARGV_ENTRIES ||
|
|
5378
|
+
argv.some((a) => typeof a !== "string" || a.length === 0 || a.length > GATE_ARGV_ENTRY_MAX)) {
|
|
5379
|
+
throw readinessShapeError();
|
|
5380
|
+
}
|
|
5381
|
+
if (typeof m.timeout_seconds !== "number" || !Number.isInteger(m.timeout_seconds))
|
|
5382
|
+
throw readinessShapeError();
|
|
5383
|
+
if (m.head_check !== undefined && m.head_check !== null && m.head_check !== "alembic" && m.head_check !== "none") {
|
|
5384
|
+
throw readinessShapeError();
|
|
5385
|
+
}
|
|
5386
|
+
out.migrate_command = {
|
|
5387
|
+
argv: argv,
|
|
5388
|
+
timeout_seconds: m.timeout_seconds,
|
|
5389
|
+
...(m.head_check ? { head_check: m.head_check } : {}),
|
|
5390
|
+
};
|
|
5391
|
+
}
|
|
5392
|
+
return out;
|
|
5393
|
+
}
|
|
5394
|
+
/** BAPI-1598. Parse the stored hand-off default; absent and `null` read as unset (effective `proceed`). */
|
|
5395
|
+
function parseHandoffDefaultField(raw) {
|
|
5396
|
+
if (raw === undefined || raw === null)
|
|
5397
|
+
return undefined;
|
|
5398
|
+
if (raw !== "proceed" && raw !== "block")
|
|
5399
|
+
throw readinessShapeError();
|
|
5400
|
+
return raw;
|
|
5401
|
+
}
|
|
4854
5402
|
/** Parse a returned or proposed reproduction hint, fail-closed. */
|
|
4855
5403
|
function parseReproductionHint(raw) {
|
|
4856
5404
|
const o = requireObject(raw);
|
|
@@ -4888,17 +5436,28 @@ function parseGateProfileBody(raw) {
|
|
|
4888
5436
|
const checksRaw = o.provider_checks;
|
|
4889
5437
|
if (!Array.isArray(checksRaw) || checksRaw.length > GATE_MAX_PROVIDER_CHECKS)
|
|
4890
5438
|
throw readinessShapeError();
|
|
4891
|
-
|
|
5439
|
+
// BAPI-1606: the server lists required entries first, then watched ones flagged
|
|
5440
|
+
// `watched: true`. Split them here; the hints stay keyed by name for both groups.
|
|
5441
|
+
const providerChecks = [];
|
|
5442
|
+
const watchedChecks = [];
|
|
4892
5443
|
const reproductionHints = new Map();
|
|
4893
|
-
checksRaw.forEach((c
|
|
4894
|
-
const
|
|
5444
|
+
checksRaw.forEach((c) => {
|
|
5445
|
+
const entry = requireObject(c);
|
|
5446
|
+
const name = gateName(entry.name, GATE_MEMBER_NAME_MAX);
|
|
5447
|
+
if (entry.watched !== undefined && typeof entry.watched !== "boolean")
|
|
5448
|
+
throw readinessShapeError();
|
|
5449
|
+
(entry.watched === true ? watchedChecks : providerChecks).push(name);
|
|
5450
|
+
const reproduce = entry.reproduce;
|
|
4895
5451
|
if (reproduce === undefined || reproduce === null)
|
|
4896
5452
|
return;
|
|
4897
|
-
reproductionHints.set(
|
|
5453
|
+
reproductionHints.set(name, parseReproductionHint(reproduce));
|
|
4898
5454
|
});
|
|
4899
5455
|
const workerEnv = parseWorkerEnvList(o.worker_env);
|
|
4900
5456
|
const dependencyInstall = parseDependencyInstallField(o.dependency_install);
|
|
4901
5457
|
const ciDatabase = parseCiDatabaseField(o.ci_database);
|
|
5458
|
+
const mustOrderPaths = parseMustOrderPathsField(o.must_order_paths);
|
|
5459
|
+
const workerDatabase = parseWorkerDatabaseField(o.worker_database);
|
|
5460
|
+
const handoffDefault = parseHandoffDefaultField(o.verification_handoff_default);
|
|
4902
5461
|
const commandsRaw = o.local_commands;
|
|
4903
5462
|
if (!Array.isArray(commandsRaw) || commandsRaw.length > GATE_MAX_LOCAL_COMMANDS)
|
|
4904
5463
|
throw readinessShapeError();
|
|
@@ -4955,10 +5514,14 @@ function parseGateProfileBody(raw) {
|
|
|
4955
5514
|
return {
|
|
4956
5515
|
kind,
|
|
4957
5516
|
provider_checks: providerChecks,
|
|
5517
|
+
...(watchedChecks.length > 0 ? { watched_checks: watchedChecks } : {}),
|
|
4958
5518
|
...(workerEnv ? { worker_env: workerEnv } : {}),
|
|
4959
5519
|
...(reproductionHints.size > 0 ? { reproduction_hints: reproductionHints } : {}),
|
|
4960
5520
|
...(dependencyInstall ? { dependency_install: dependencyInstall } : {}),
|
|
4961
5521
|
...(ciDatabase !== "unknown" ? { ci_database: ciDatabase } : {}),
|
|
5522
|
+
...(workerDatabase ? { worker_database: workerDatabase } : {}),
|
|
5523
|
+
...(handoffDefault ? { verification_handoff_default: handoffDefault } : {}),
|
|
5524
|
+
must_order_paths: mustOrderPaths,
|
|
4962
5525
|
local_commands: localCommands,
|
|
4963
5526
|
migration_guard: guard,
|
|
4964
5527
|
customized_commands: customized.map((n) => gateName(n, GATE_MEMBER_NAME_MAX)),
|
|
@@ -5024,7 +5587,7 @@ export async function fetchConductorGateProfile(access, fetchImpl) {
|
|
|
5024
5587
|
return parseConductorGateProfileResponse(body, access.repoName);
|
|
5025
5588
|
}
|
|
5026
5589
|
/**
|
|
5027
|
-
* BAPI-1520 (extended by BAPI-1551) — which extension fields the older server rejected, and only when
|
|
5590
|
+
* BAPI-1520 (extended by BAPI-1551 and BAPI-1580) — which extension fields the older server rejected, and only when
|
|
5028
5591
|
* the request actually carried them. `worker_env` counts only at exactly
|
|
5029
5592
|
* `["body","worker_env"]`; `reproduce` only at exactly
|
|
5030
5593
|
* `["body","provider_checks",<index>,"reproduce"]`. Any other 422 returns
|
|
@@ -5042,6 +5605,11 @@ export function classifyGateProfileExtensionRejection(err, request) {
|
|
|
5042
5605
|
// BAPI-1551: reported only when true, so the BAPI-1520 shape is unchanged.
|
|
5043
5606
|
let dependencyInstall = false;
|
|
5044
5607
|
let ciDatabase = false;
|
|
5608
|
+
// BAPI-1580: same rule.
|
|
5609
|
+
let mustOrderPaths = false;
|
|
5610
|
+
// BAPI-1598: same rule.
|
|
5611
|
+
let workerDatabase = false;
|
|
5612
|
+
let handoffDefault = false;
|
|
5045
5613
|
for (const issue of issues) {
|
|
5046
5614
|
if (issue.type !== "extra_forbidden")
|
|
5047
5615
|
return null;
|
|
@@ -5061,6 +5629,21 @@ export function classifyGateProfileExtensionRejection(err, request) {
|
|
|
5061
5629
|
return null;
|
|
5062
5630
|
ciDatabase = true;
|
|
5063
5631
|
}
|
|
5632
|
+
else if (loc.length === 2 && loc[0] === "body" && loc[1] === "must_order_paths") {
|
|
5633
|
+
if (!confirm || confirm.must_order_paths === undefined)
|
|
5634
|
+
return null;
|
|
5635
|
+
mustOrderPaths = true;
|
|
5636
|
+
}
|
|
5637
|
+
else if (loc.length === 2 && loc[0] === "body" && loc[1] === "worker_database") {
|
|
5638
|
+
if (!confirm || confirm.worker_database === undefined)
|
|
5639
|
+
return null;
|
|
5640
|
+
workerDatabase = true;
|
|
5641
|
+
}
|
|
5642
|
+
else if (loc.length === 2 && loc[0] === "body" && loc[1] === "verification_handoff_default") {
|
|
5643
|
+
if (!confirm || confirm.verification_handoff_default === undefined)
|
|
5644
|
+
return null;
|
|
5645
|
+
handoffDefault = true;
|
|
5646
|
+
}
|
|
5064
5647
|
else if (loc.length === 4 &&
|
|
5065
5648
|
loc[0] === "body" &&
|
|
5066
5649
|
loc[1] === "provider_checks" &&
|
|
@@ -5080,6 +5663,9 @@ export function classifyGateProfileExtensionRejection(err, request) {
|
|
|
5080
5663
|
reproduce,
|
|
5081
5664
|
...(dependencyInstall ? { dependency_install: true } : {}),
|
|
5082
5665
|
...(ciDatabase ? { ci_database: true } : {}),
|
|
5666
|
+
...(mustOrderPaths ? { must_order_paths: true } : {}),
|
|
5667
|
+
...(workerDatabase ? { worker_database: true } : {}),
|
|
5668
|
+
...(handoffDefault ? { verification_handoff_default: true } : {}),
|
|
5083
5669
|
};
|
|
5084
5670
|
}
|
|
5085
5671
|
/** The safe refusal context of a failed write, or `undefined` when there is none. */
|
|
@@ -5244,6 +5830,46 @@ export async function fetchConductorGateCheckHistory(access, names, fetchImpl) {
|
|
|
5244
5830
|
* all read as unsupported, so the installer writes nothing.
|
|
5245
5831
|
*/
|
|
5246
5832
|
export async function probeConductorGateProfileCapability(access, fetchImpl) {
|
|
5833
|
+
const read = await readGateProfileCapabilityTokens(access, fetchImpl);
|
|
5834
|
+
if (!read.ok)
|
|
5835
|
+
return { supported: false, reason: read.reason };
|
|
5836
|
+
return read.tokens.includes(GATE_PROFILE_CAPABILITY_TOKEN)
|
|
5837
|
+
? { supported: true }
|
|
5838
|
+
: { supported: false, reason: "absent" };
|
|
5839
|
+
}
|
|
5840
|
+
/**
|
|
5841
|
+
* BAPI-1603 — the same capability read, answering whether the server stores a
|
|
5842
|
+
* provider check as WATCHED (`gate_profile.watched.v1`). NEVER throws and fails
|
|
5843
|
+
* closed: anything but an advertised token reads as unsupported, and the caller
|
|
5844
|
+
* then skips only its watched-member writes. It never reads as a request to turn
|
|
5845
|
+
* watched checks into required ones.
|
|
5846
|
+
*/
|
|
5847
|
+
export async function probeConductorGateProfileWatchedCapability(access, fetchImpl) {
|
|
5848
|
+
const read = await readGateProfileCapabilityTokens(access, fetchImpl);
|
|
5849
|
+
if (!read.ok)
|
|
5850
|
+
return { supported: false, reason: read.reason };
|
|
5851
|
+
return read.tokens.includes(GATE_PROFILE_WATCHED_CAPABILITY_TOKEN)
|
|
5852
|
+
? { supported: true }
|
|
5853
|
+
: { supported: false, reason: "absent" };
|
|
5854
|
+
}
|
|
5855
|
+
/**
|
|
5856
|
+
* BAPI-1598 — the same capability read, answering whether the server stores the
|
|
5857
|
+
* optional worker-database and hand-off-default settings
|
|
5858
|
+
* (`gate_profile.worker_setup.v1`). NEVER throws and fails closed: anything but an
|
|
5859
|
+
* advertised token reads as unsupported, and the caller then omits only those two
|
|
5860
|
+
* fields. It is informational and never a prerequisite for readiness, creation,
|
|
5861
|
+
* approval, or launch.
|
|
5862
|
+
*/
|
|
5863
|
+
export async function probeConductorGateProfileWorkerSetupCapability(access, fetchImpl) {
|
|
5864
|
+
const read = await readGateProfileCapabilityTokens(access, fetchImpl);
|
|
5865
|
+
if (!read.ok)
|
|
5866
|
+
return { supported: false, reason: read.reason };
|
|
5867
|
+
return read.tokens.includes(GATE_PROFILE_WORKER_SETUP_CAPABILITY_TOKEN)
|
|
5868
|
+
? { supported: true }
|
|
5869
|
+
: { supported: false, reason: "absent" };
|
|
5870
|
+
}
|
|
5871
|
+
/** The advertised capability tokens, or the closed reason they could not be read. */
|
|
5872
|
+
async function readGateProfileCapabilityTokens(access, fetchImpl) {
|
|
5247
5873
|
let body;
|
|
5248
5874
|
try {
|
|
5249
5875
|
body = await fetchConductorJsonWithTimeout(gateProfileUrl(access, "capability/"), conductorGetHeaders(access), CONDUCTOR_FETCH_TIMEOUT_MS, fetchImpl);
|
|
@@ -5251,25 +5877,204 @@ export async function probeConductorGateProfileCapability(access, fetchImpl) {
|
|
|
5251
5877
|
catch (err) {
|
|
5252
5878
|
if (err instanceof ConductorBridgeApiError) {
|
|
5253
5879
|
if (err.kind === "unauthorized")
|
|
5254
|
-
return {
|
|
5880
|
+
return { ok: false, reason: "unauthorized" };
|
|
5255
5881
|
if (err.kind === "network" || err.kind === "timeout")
|
|
5256
|
-
return {
|
|
5882
|
+
return { ok: false, reason: "unreachable" };
|
|
5257
5883
|
if (err.kind === "invalid-input")
|
|
5258
|
-
return {
|
|
5884
|
+
return { ok: false, reason: "unreadable" };
|
|
5259
5885
|
}
|
|
5260
|
-
return {
|
|
5886
|
+
return { ok: false, reason: "absent" };
|
|
5261
5887
|
}
|
|
5262
5888
|
if (typeof body !== "object" || body === null || Array.isArray(body)) {
|
|
5263
|
-
return {
|
|
5889
|
+
return { ok: false, reason: "unreadable" };
|
|
5264
5890
|
}
|
|
5265
5891
|
const o = body;
|
|
5266
5892
|
const caps = o.capabilities;
|
|
5267
5893
|
if (o.repo_name !== access.repoName || !Array.isArray(caps) || caps.some((c) => typeof c !== "string")) {
|
|
5268
|
-
return {
|
|
5894
|
+
return { ok: false, reason: "unreadable" };
|
|
5895
|
+
}
|
|
5896
|
+
return { ok: true, tokens: caps };
|
|
5897
|
+
}
|
|
5898
|
+
const MISSING_FIELD_NAME_PATTERN = /^[a-z][a-z0-9_]{0,63}$/;
|
|
5899
|
+
/**
|
|
5900
|
+
* BAPI-1680: parse the optional `missing_fields` list. Isolated from the required
|
|
5901
|
+
* readiness evidence: it can only ever yield `[]` or a clean list, and never throws,
|
|
5902
|
+
* so a bad name can never turn a confirmed response into unknown.
|
|
5903
|
+
*
|
|
5904
|
+
* Returns `[]` when the key is absent or not an array of strings, when duplicates
|
|
5905
|
+
* occur (the whole list is dropped, not deduplicated), or when the names that match
|
|
5906
|
+
* `^[a-z][a-z0-9_]{0,63}$` do not number exactly `expectedCount`. Valid unknown
|
|
5907
|
+
* identifiers and server order are preserved untouched.
|
|
5908
|
+
*/
|
|
5909
|
+
function parseOptionalMissingFields(raw, expectedCount) {
|
|
5910
|
+
if (!Array.isArray(raw) || raw.some((n) => typeof n !== "string"))
|
|
5911
|
+
return [];
|
|
5912
|
+
const names = raw.filter((n) => MISSING_FIELD_NAME_PATTERN.test(n));
|
|
5913
|
+
if (new Set(names).size !== names.length)
|
|
5914
|
+
return [];
|
|
5915
|
+
return names.length === expectedCount ? names : [];
|
|
5916
|
+
}
|
|
5917
|
+
/**
|
|
5918
|
+
* GET the repository's learned-field counts. NEVER throws. Only a validated body
|
|
5919
|
+
* is `confirmed`; a 503 `STATE_UNAVAILABLE`, a missing route, a failed transport,
|
|
5920
|
+
* and a malformed or self-contradicting body are all `unknown`, so none of them
|
|
5921
|
+
* can authorize a "not learned" refusal.
|
|
5922
|
+
*/
|
|
5923
|
+
export async function fetchConductorRepositoryLearning(access, fetchImpl) {
|
|
5924
|
+
let body;
|
|
5925
|
+
try {
|
|
5926
|
+
body = await fetchConductorJsonWithTimeout(buildConductorJiraUrl(access.baseUrl, `${EPIC_RUNS_API_PREFIX}/supervisor-setup/repository-learning/`, { repo_name: access.repoName }), conductorGetHeaders(access), CONDUCTOR_FETCH_TIMEOUT_MS, fetchImpl);
|
|
5927
|
+
}
|
|
5928
|
+
catch (err) {
|
|
5929
|
+
if (!(err instanceof ConductorBridgeApiError))
|
|
5930
|
+
return { status: "unknown", reason: "unreachable" };
|
|
5931
|
+
if (err.kind === "unauthorized")
|
|
5932
|
+
return { status: "unknown", reason: "unauthorized" };
|
|
5933
|
+
if (err.kind === "network" || err.kind === "timeout")
|
|
5934
|
+
return { status: "unknown", reason: "unreachable" };
|
|
5935
|
+
if (err.status === 404 || err.status === 405)
|
|
5936
|
+
return { status: "unknown", reason: "unsupported" };
|
|
5937
|
+
if (err.kind === "server" || err.errorCode === "STATE_UNAVAILABLE") {
|
|
5938
|
+
return { status: "unknown", reason: "unavailable" };
|
|
5939
|
+
}
|
|
5940
|
+
return { status: "unknown", reason: "unreadable" };
|
|
5941
|
+
}
|
|
5942
|
+
try {
|
|
5943
|
+
const o = requireObject(body);
|
|
5944
|
+
if (o.repo_name !== access.repoName)
|
|
5945
|
+
throw readinessShapeError();
|
|
5946
|
+
const learned = requireBool(o, "learned");
|
|
5947
|
+
const set = requireInt(o, "learned_fields_set");
|
|
5948
|
+
const total = requireInt(o, "learned_fields_total");
|
|
5949
|
+
// The server defines learned as "every field set"; a body that disagrees with
|
|
5950
|
+
// its own counts is unreadable evidence, never a confirmed answer.
|
|
5951
|
+
if (set < 0 || total < 0 || set > total || learned !== (total > 0 && set === total)) {
|
|
5952
|
+
throw readinessShapeError();
|
|
5953
|
+
}
|
|
5954
|
+
return {
|
|
5955
|
+
status: "confirmed",
|
|
5956
|
+
learned,
|
|
5957
|
+
learned_fields_set: set,
|
|
5958
|
+
learned_fields_total: total,
|
|
5959
|
+
missing_fields: parseOptionalMissingFields(o.missing_fields, total - set),
|
|
5960
|
+
};
|
|
5961
|
+
}
|
|
5962
|
+
catch {
|
|
5963
|
+
return { status: "unknown", reason: "unreadable" };
|
|
5964
|
+
}
|
|
5965
|
+
}
|
|
5966
|
+
/** The server's cap on client hints; extra candidates are never sent. */
|
|
5967
|
+
export const LEARNED_TEST_COMMAND_MAX_CANDIDATES = 8;
|
|
5968
|
+
/** The closed reasons the server gives when it found no command to try. */
|
|
5969
|
+
export const LEARNED_TEST_COMMAND_NO_COMMAND_REASONS = [
|
|
5970
|
+
"no_testing_instructions",
|
|
5971
|
+
"llm_unavailable",
|
|
5972
|
+
"llm_output_invalid",
|
|
5973
|
+
"no_candidates",
|
|
5974
|
+
"working_directory_unsupported",
|
|
5975
|
+
"not_plain_argv",
|
|
5976
|
+
"command_not_allowed",
|
|
5977
|
+
"invalid_command",
|
|
5978
|
+
];
|
|
5979
|
+
const LEARNED_COMMAND_DISPLAY_MAX = 4096;
|
|
5980
|
+
const LEARNED_COMMAND_MAX_DISPLAYED = 16;
|
|
5981
|
+
function learnedCommandText(value, max) {
|
|
5982
|
+
if (typeof value !== "string" || value.length === 0 || value.length > max || /[\u0000-\u001F\u007F]/.test(value)) {
|
|
5983
|
+
throw readinessShapeError();
|
|
5984
|
+
}
|
|
5985
|
+
return value;
|
|
5986
|
+
}
|
|
5987
|
+
/** Validate a learned-command 200 body, fail-closed. Throws the field-free shape error. */
|
|
5988
|
+
export function parseConductorLearnedTestCommandResponse(body, expectedRepoName) {
|
|
5989
|
+
const o = requireObject(body);
|
|
5990
|
+
if (o.repo_name !== expectedRepoName)
|
|
5991
|
+
throw readinessShapeError();
|
|
5992
|
+
const source = () => {
|
|
5993
|
+
if (o.source !== "learned" && o.source !== "owner")
|
|
5994
|
+
throw readinessShapeError();
|
|
5995
|
+
return o.source;
|
|
5996
|
+
};
|
|
5997
|
+
switch (o.outcome) {
|
|
5998
|
+
case "qualification_queued": {
|
|
5999
|
+
const jobId = requireInt(o, "job_id");
|
|
6000
|
+
const baseRevision = requireInt(o, "base_revision");
|
|
6001
|
+
if (jobId <= 0 || baseRevision < 0)
|
|
6002
|
+
throw readinessShapeError();
|
|
6003
|
+
const raw = o.commands;
|
|
6004
|
+
if (!Array.isArray(raw) || raw.length === 0 || raw.length > LEARNED_COMMAND_MAX_DISPLAYED) {
|
|
6005
|
+
throw readinessShapeError();
|
|
6006
|
+
}
|
|
6007
|
+
const commands = raw.map((item) => {
|
|
6008
|
+
const c = requireObject(item);
|
|
6009
|
+
return {
|
|
6010
|
+
name: learnedCommandText(c.name, GATE_COMMAND_NAME_MAX),
|
|
6011
|
+
command: learnedCommandText(c.command, LEARNED_COMMAND_DISPLAY_MAX),
|
|
6012
|
+
};
|
|
6013
|
+
});
|
|
6014
|
+
return { kind: "qualification_queued", source: source(), jobId, baseRevision, commands };
|
|
6015
|
+
}
|
|
6016
|
+
case "no_command": {
|
|
6017
|
+
const reason = o.reason;
|
|
6018
|
+
if (typeof reason !== "string" ||
|
|
6019
|
+
!LEARNED_TEST_COMMAND_NO_COMMAND_REASONS.includes(reason)) {
|
|
6020
|
+
throw readinessShapeError();
|
|
6021
|
+
}
|
|
6022
|
+
return {
|
|
6023
|
+
kind: "no_command",
|
|
6024
|
+
source: source(),
|
|
6025
|
+
reason: reason,
|
|
6026
|
+
};
|
|
6027
|
+
}
|
|
6028
|
+
case "not_needed":
|
|
6029
|
+
if (o.reason !== "local_gate_already_stored")
|
|
6030
|
+
throw readinessShapeError();
|
|
6031
|
+
return { kind: "not_needed" };
|
|
6032
|
+
default:
|
|
6033
|
+
throw readinessShapeError();
|
|
6034
|
+
}
|
|
6035
|
+
}
|
|
6036
|
+
/**
|
|
6037
|
+
* POST a learned-command request: extract (or validate the owner's) command and
|
|
6038
|
+
* queue one qualification trial bound to `expectedRevision`. NEVER throws. Nothing
|
|
6039
|
+
* is stored by this call; the trial runs on the owner's executor and the server
|
|
6040
|
+
* promotes the local gate only when every command passes.
|
|
6041
|
+
*/
|
|
6042
|
+
export async function requestConductorLearnedTestCommand(access, request, fetchImpl) {
|
|
6043
|
+
const candidates = (request.candidates ?? [])
|
|
6044
|
+
.slice(0, LEARNED_TEST_COMMAND_MAX_CANDIDATES)
|
|
6045
|
+
.map((c) => (c.source === undefined ? { command: c.command } : { command: c.command, source: c.source }));
|
|
6046
|
+
const payload = { expected_revision: request.expectedRevision };
|
|
6047
|
+
if (candidates.length > 0)
|
|
6048
|
+
payload.candidates = candidates;
|
|
6049
|
+
if (request.ownerCommand !== undefined)
|
|
6050
|
+
payload.owner_command = request.ownerCommand;
|
|
6051
|
+
let body;
|
|
6052
|
+
try {
|
|
6053
|
+
body = await fetchConductorJsonWithMethodAndTimeout("POST", buildConductorJiraUrl(access.baseUrl, `${EPIC_RUNS_API_PREFIX}/supervisor-setup/learned-test-command/`, { repo_name: access.repoName }), conductorPostHeaders(access), JSON.stringify(payload), CONDUCTOR_LEARNED_TEST_COMMAND_TIMEOUT_MS, fetchImpl);
|
|
6054
|
+
}
|
|
6055
|
+
catch (err) {
|
|
6056
|
+
if (!(err instanceof ConductorBridgeApiError))
|
|
6057
|
+
return { kind: "uncertain" };
|
|
6058
|
+
if (err.errorCode === "STALE_REVISION")
|
|
6059
|
+
return { kind: "stale_revision" };
|
|
6060
|
+
if (err.errorCode === "STATE_UNAVAILABLE")
|
|
6061
|
+
return { kind: "state_unavailable" };
|
|
6062
|
+
if (err.kind === "unauthorized")
|
|
6063
|
+
return { kind: "refused", reason: "unauthorized" };
|
|
6064
|
+
if (err.unreadableSuccess === true)
|
|
6065
|
+
return { kind: "uncertain" };
|
|
6066
|
+
if (err.kind === "timeout" || err.kind === "network" || err.kind === "server")
|
|
6067
|
+
return { kind: "uncertain" };
|
|
6068
|
+
if (err.status === 404 || err.status === 405)
|
|
6069
|
+
return { kind: "unsupported" };
|
|
6070
|
+
return { kind: "refused", reason: "rejected" };
|
|
6071
|
+
}
|
|
6072
|
+
try {
|
|
6073
|
+
return parseConductorLearnedTestCommandResponse(body, access.repoName);
|
|
6074
|
+
}
|
|
6075
|
+
catch {
|
|
6076
|
+
return { kind: "malformed" };
|
|
5269
6077
|
}
|
|
5270
|
-
return caps.includes(GATE_PROFILE_CAPABILITY_TOKEN)
|
|
5271
|
-
? { supported: true }
|
|
5272
|
-
: { supported: false, reason: "absent" };
|
|
5273
6078
|
}
|
|
5274
6079
|
const QUALIFICATION_REFUSAL_CODES = Object.freeze({
|
|
5275
6080
|
PROFILE_NOT_CONFIRMED: "profile-not-confirmed",
|
|
@@ -5318,6 +6123,16 @@ export async function enqueueConductorGateQualification(access, request, fetchIm
|
|
|
5318
6123
|
}
|
|
5319
6124
|
return { kind: "accepted", jobId, jobStatus, revision };
|
|
5320
6125
|
}
|
|
6126
|
+
/**
|
|
6127
|
+
* BAPI-1637 — how a completed qualification job's commands ended, as the server
|
|
6128
|
+
* derived it from stored evidence. Closed: an unknown token reads as `null`.
|
|
6129
|
+
*/
|
|
6130
|
+
export const CONDUCTOR_GATE_QUALIFICATION_PHASES = [
|
|
6131
|
+
"dependency_preparation_failed",
|
|
6132
|
+
"could_not_start",
|
|
6133
|
+
"ran_and_failed",
|
|
6134
|
+
"passed",
|
|
6135
|
+
];
|
|
5321
6136
|
export function parseConductorGateQualificationJob(body, expectedRepoName, expectedJobId) {
|
|
5322
6137
|
const o = requireObject(body);
|
|
5323
6138
|
if (o.repo_name !== expectedRepoName || o.job_id !== expectedJobId)
|
|
@@ -5337,6 +6152,10 @@ export function parseConductorGateQualificationJob(body, expectedRepoName, expec
|
|
|
5337
6152
|
qualification_state: (state ?? null),
|
|
5338
6153
|
current_revision: requireNullableInt(o, "current_revision"),
|
|
5339
6154
|
failure: (failure ?? null),
|
|
6155
|
+
phase: CONDUCTOR_GATE_QUALIFICATION_PHASES.includes(o.phase)
|
|
6156
|
+
? o.phase
|
|
6157
|
+
: null,
|
|
6158
|
+
dependency_install_declared: typeof o.dependency_install_declared === "boolean" ? o.dependency_install_declared : null,
|
|
5340
6159
|
};
|
|
5341
6160
|
}
|
|
5342
6161
|
/** GET one qualification job's verified state. Throws a sanitized error on failure. */
|
|
@@ -5347,7 +6166,7 @@ export async function fetchConductorGateQualificationJob(access, jobId, fetchImp
|
|
|
5347
6166
|
/** Authenticated read-only preview of the same effective policy sent at creation. */
|
|
5348
6167
|
export async function previewLaunchReadiness(access, policyJson, fetchImpl = globalThis.fetch) {
|
|
5349
6168
|
const url = buildConductorJiraUrl(access.baseUrl, `${EPIC_RUNS_API_PREFIX}/launch-readiness`);
|
|
5350
|
-
const body = await fetchConductorJsonPostWithTimeout(url, conductorPostHeaders(access), JSON.stringify({ repo_name: access.repoName, policy_json: policyJson }),
|
|
6169
|
+
const body = await fetchConductorJsonPostWithTimeout(url, conductorPostHeaders(access), JSON.stringify({ repo_name: access.repoName, policy_json: policyJson }), CONDUCTOR_READINESS_FETCH_TIMEOUT_MS, fetchImpl);
|
|
5351
6170
|
return parseConductorReadinessResponse(body);
|
|
5352
6171
|
}
|
|
5353
6172
|
/** BAPI-1567 combined policy transport. Artifacts live only in transient memory. */
|
|
@@ -5386,10 +6205,12 @@ function setupProjection(value) {
|
|
|
5386
6205
|
if (!setupObject(value.gate))
|
|
5387
6206
|
return false;
|
|
5388
6207
|
const gate = value.gate;
|
|
5389
|
-
const allowed = ["kind", "provider_checks", "local_commands", "migration_guard", "customized_commands", "failure_formats", "worker_env", "dependency_install", "ci_database", "source"];
|
|
6208
|
+
const allowed = ["kind", "provider_checks", "local_commands", "migration_guard", "customized_commands", "failure_formats", "worker_env", "dependency_install", "ci_database", "must_order_paths", "worker_database", "verification_handoff_default", "source"];
|
|
5390
6209
|
if (Object.keys(gate).some(k => !allowed.includes(k)) || !["provider", "mixed", "local", "none"].includes(String(gate.kind)))
|
|
5391
6210
|
return false;
|
|
5392
|
-
|
|
6211
|
+
// BAPI-1606: a provider entry is `{name}` (required) or `{name, watched: true}`.
|
|
6212
|
+
if (!Array.isArray(gate.provider_checks) || !gate.provider_checks.every(c => setupObject(c) && typeof c.name === "string"
|
|
6213
|
+
&& (exact(c, ["name"]) || (exact(c, ["name", "watched"]) && c.watched === true))))
|
|
5393
6214
|
return false;
|
|
5394
6215
|
if (!Array.isArray(gate.local_commands) || !gate.local_commands.every(c => setupObject(c) && exact(c, ["name", "argv", "timeout_seconds"])
|
|
5395
6216
|
&& typeof c.name === "string" && Array.isArray(c.argv) && c.argv.every(a => typeof a === "string") && Number.isSafeInteger(c.timeout_seconds)))
|
|
@@ -5467,8 +6288,19 @@ export async function previewConductorSetupPolicy(access, request, fetchImpl) {
|
|
|
5467
6288
|
}
|
|
5468
6289
|
if (request.gate?.provider_checks) {
|
|
5469
6290
|
const checks = body.after.gate?.provider_checks;
|
|
5470
|
-
if (!Array.isArray(checks)
|
|
5471
|
-
|
|
6291
|
+
if (!Array.isArray(checks))
|
|
6292
|
+
throw new ConductorSetupPolicyError("malformed");
|
|
6293
|
+
const actual = checks.map(c => typeof c === "string" ? c : c?.name);
|
|
6294
|
+
// BAPI-1606: the server projects required members first and watched members
|
|
6295
|
+
// second, so the request is compared in that order, flags kept.
|
|
6296
|
+
const requested = request.gate.provider_checks;
|
|
6297
|
+
const serverOrder = [...requested.filter(c => c.watched !== true), ...requested.filter(c => c.watched === true)].map(c => c.name);
|
|
6298
|
+
const sameSequence = JSON.stringify(actual) === JSON.stringify(serverOrder);
|
|
6299
|
+
// An entry that omitted `watched` inherits the stored flag, so the position it
|
|
6300
|
+
// lands in is the server's to decide: accept the same names in either order.
|
|
6301
|
+
const inheritsFlag = requested.some(c => !("watched" in c));
|
|
6302
|
+
const sameNames = inheritsFlag && JSON.stringify([...actual].sort()) === JSON.stringify(requested.map(c => c.name).sort());
|
|
6303
|
+
if (!sameSequence && !sameNames)
|
|
5472
6304
|
throw new ConductorSetupPolicyError("malformed");
|
|
5473
6305
|
}
|
|
5474
6306
|
const { preview_artifact: artifact, ...publicPreview } = body;
|