@bridge_gpt/mcp-server 0.2.69 → 0.2.71
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 +140 -292
- package/build/agent-launchers/claude-executor-adapter.js +27 -5
- package/build/agent-registry.js +5 -5
- package/build/agents.generated.js +15 -5
- package/build/artifact-diff.js +110 -0
- package/build/bin-entrypoint.js +36 -0
- package/build/bounded-wait.js +9 -1
- package/build/bridge-permissions.js +36 -9
- package/build/claude-review-workflow-drift.js +3 -3
- package/build/codex-bridge-profile.js +1 -1
- package/build/commands.generated.js +6 -6
- package/build/conductor/bridge-api-client.js +858 -21
- package/build/conductor/bring-up-facts.js +9 -9
- package/build/conductor/command-drift-production.js +7 -2
- package/build/conductor/doctor.js +472 -18
- package/build/conductor/epic-child-continuation.js +54 -3
- package/build/conductor/epic-implementer-cli.js +136 -34
- package/build/conductor/epic-runtime.js +2 -2
- package/build/conductor/epic-state.js +1 -1
- package/build/conductor/gate-discovery.js +524 -10
- package/build/conductor/gate-settings-review.js +451 -0
- package/build/conductor/hook-runtime-qualification.js +1 -1
- package/build/conductor/install-doctor.js +4 -2
- package/build/conductor/launch-need-probes.js +342 -0
- package/build/conductor/launch-plan.js +145 -0
- package/build/conductor/local-merge.js +241 -56
- package/build/conductor/merge-credential.js +172 -0
- package/build/conductor/merge-execution-eligibility.js +1 -1
- package/build/conductor/merged-child-check.js +95 -0
- package/build/conductor/plan-trim.js +30 -0
- package/build/conductor/pr-ci-producer.js +1 -1
- package/build/conductor/precheck-timings.js +14 -0
- package/build/conductor/preview-observations.js +10 -0
- package/build/conductor/readiness-cli.js +11 -6
- package/build/conductor/readiness-prerequisites.js +41 -0
- package/build/conductor/readiness-sections.js +348 -55
- package/build/conductor/readiness.js +99 -87
- package/build/conductor/recovery-cli.js +665 -23
- package/build/conductor/recovery-operations.js +350 -8
- package/build/conductor/repair-contract.js +47 -2
- package/build/conductor/repository-workflow-remedy.js +8 -6
- package/build/conductor/stored-merge-credential.js +76 -0
- package/build/conductor/stored-merge-token-probe.js +28 -0
- package/build/conductor/temporary-plan.js +50 -0
- package/build/conductor/wait-run-cli.js +759 -0
- package/build/conductor/worker-database-doctor-inspector.js +49 -0
- package/build/conductor-bin.js +2 -2
- package/build/conductor-claude-hook-bin.js +2 -2
- package/build/conductor-claude-hook-removed-stub-bin.js +2 -5
- package/build/conductor-removed-stub-bin.js +2 -5
- package/build/credential-store.js +356 -13
- package/build/docs.generated.js +26 -13
- package/build/doctor.js +94 -32
- package/build/drive-epic-help.js +212 -0
- package/build/drive-epic.js +1989 -379
- package/build/epic-ci-workflow-drift.js +125 -0
- package/build/epic-ci-workflow-install.js +240 -0
- package/build/epic-ci-workflow-v1.js +132 -0
- package/build/epic-ci-workflow.js +318 -0
- package/build/epic-contract-context.js +326 -0
- package/build/epic-implementer-bin.js +58 -42
- package/build/epic-implementer-claude-hook-bin.js +2 -2
- package/build/escalation-reachability.js +134 -0
- package/build/executor/ci-rerun-job.js +220 -14
- package/build/executor/cleanup-report.js +99 -0
- package/build/executor/cli.js +12 -1
- package/build/executor/completion-contract.js +66 -11
- package/build/executor/completion-supervision.js +99 -0
- package/build/executor/delivery-outcome.js +179 -0
- package/build/executor/deps.js +3 -0
- package/build/executor/env.js +276 -1
- package/build/executor/failure-reason-codes.js +126 -0
- package/build/executor/gate-qualification-job.js +20 -5
- package/build/executor/heartbeat.js +38 -0
- package/build/executor/http-client.js +72 -0
- package/build/executor/integration-job.js +298 -5
- package/build/executor/job-errors.js +36 -6
- package/build/executor/job-runner.js +830 -45
- package/build/executor/likely-tests.js +42 -3
- package/build/executor/merge-job.js +145 -2
- package/build/executor/observation.js +73 -4
- package/build/executor/permissions.js +193 -97
- package/build/executor/preflight.js +19 -3
- package/build/executor/process-containment.js +46 -2
- package/build/executor/prompt-spec.js +113 -9
- package/build/executor/rebase-finalization.js +38 -3
- package/build/executor/reconcile-overlap-job.js +41 -8
- package/build/executor/required-work-ledger.js +236 -81
- package/build/executor/resume-pre-spawn.js +38 -1
- package/build/executor/runner.js +91 -3
- package/build/executor/test-clock.js +8 -0
- package/build/executor/types.js +37 -2
- package/build/executor/worker-cli-launcher.js +259 -0
- package/build/executor/worker-command.js +177 -5
- package/build/executor/worker-database-target.js +91 -0
- package/build/executor/worker-database.js +927 -0
- package/build/executor/worker-finalization.js +106 -0
- package/build/executor/worker-guard-hook.js +203 -0
- package/build/executor/worker-resources.js +58 -0
- package/build/executor/worker-verification-guidance.js +44 -2
- package/build/executor/worktree.js +303 -15
- package/build/executor-launch.js +11 -1
- package/build/generated-assets-doctor.js +9 -1
- package/build/generated-assets-health.js +13 -4
- package/build/generated-assets-legacy.js +39 -0
- package/build/generated-assets-paths.js +12 -1
- package/build/generated-assets-repair.js +4 -1
- package/build/generated-assets-test-support.js +12 -0
- package/build/github-remote.js +33 -0
- package/build/github-sign-in.js +62 -0
- package/build/index.js +1133 -546
- package/build/init.js +39 -1
- package/build/install-bridge-conductor-gate.js +270 -11
- package/build/install-bridge-conductor-setup.js +427 -0
- package/build/install-bridge-conductor.js +1545 -268
- package/build/install-bridge.js +376 -60
- package/build/mcp-install-state.js +8 -2
- package/build/merge-pull-request.js +6 -0
- package/build/merge-workflow-install.js +782 -344
- package/build/phase-result-artifacts.js +75 -20
- package/build/pipeline-orchestrator.js +247 -4
- package/build/pipelines.generated.js +35 -35
- package/build/plan-discovery.js +15 -2
- package/build/plan-execution-ledger.js +321 -17
- package/build/plan-phase-routing.js +48 -13
- package/build/plane/cli.js +105 -51
- package/build/plane/defaults.js +3 -0
- package/build/plane/plane-freshness.js +298 -0
- package/build/plane/preflight.js +19 -0
- package/build/plane/schema-compatibility.js +137 -0
- package/build/plane/shutdown-deps.js +38 -0
- package/build/plane/shutdown.js +83 -8
- package/build/plane/terminal-run-cleanup.js +303 -0
- package/build/printed-remedy-commands.js +33 -4
- package/build/readiness-check.js +6 -2
- package/build/readiness-prerequisites.generated.js +532 -0
- package/build/readme.generated.js +1 -1
- package/build/repository-toolchains.js +581 -0
- package/build/setup-epic.js +421 -34
- package/build/shared-resources.generated.js +5 -0
- package/build/start-tickets.js +28 -15
- package/build/test-command-detection.js +284 -0
- package/build/test-command-validation.js +73 -0
- package/build/testing-config-client.js +150 -0
- package/build/ticket-delivery-artifacts.js +265 -0
- package/build/ticket-delivery-enrollment.js +369 -0
- package/build/ticket-delivery.js +205 -0
- package/build/ticket-review-summary.js +14 -0
- package/build/upgrade-cli.js +13 -0
- package/build/v2-readiness-requirements.js +552 -0
- package/build/version.generated.js +3 -3
- package/build/worker-guard-hook-bin.js +2 -2
- package/build/worktree-core.js +22 -7
- package/docs/BRIDGE-DIRECTORY-README.md +48 -0
- package/docs/EPIC-IMPLEMENTER-INSTALL.md +12 -867
- package/docs/EPIC-IMPLEMENTER.md +142 -63
- package/docs/epic-implementer/getting-started.md +187 -0
- package/docs/epic-implementer/self-hosting.md +133 -0
- package/package.json +4 -4
- package/pipelines/idea-to-ticket.json +1 -1
- package/pipelines/implement-ticket.json +8 -8
- package/pipelines/review-ticket.json +2 -2
- package/design-assets/favicon/favicon-32x32.png +0 -0
- package/design-assets/just-logo-rough-draft.png +0 -0
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { READINESS_PREREQUISITE_BY_ID } from "../readiness-prerequisites.generated.js";
|
|
2
|
+
import { READINESS_PREREQUISITE_FIXES } from "../printed-remedy-commands.js";
|
|
1
3
|
/**
|
|
2
4
|
* TypeScript-side Bridge API access layer for the conductor producer (BAPI-395).
|
|
3
5
|
*
|
|
@@ -191,8 +193,93 @@ const CONDUCTOR_BRIDGE_API_ERROR_KINDS = [
|
|
|
191
193
|
"server",
|
|
192
194
|
"http",
|
|
193
195
|
];
|
|
196
|
+
const WORKER_ENV_REFUSAL_REASONS = new Set([
|
|
197
|
+
"worker_env_reserved_name",
|
|
198
|
+
"worker_env_secret_name",
|
|
199
|
+
"worker_env_duplicate",
|
|
200
|
+
]);
|
|
201
|
+
const GATE_EVIDENCE_FIELD_RE = /^[a-z_]{1,40}$/;
|
|
202
|
+
const GATE_EVIDENCE_NAME_RE = /^[A-Z_][A-Z0-9_]{0,63}$/;
|
|
203
|
+
const GATE_EVIDENCE_LOC_PART_RE = /^[A-Za-z0-9_]{1,64}$/;
|
|
204
|
+
const GATE_EVIDENCE_TYPE_RE = /^[a-z_.]{1,64}$/;
|
|
205
|
+
const GATE_EVIDENCE_MAX_ISSUES = 4;
|
|
206
|
+
const GATE_EVIDENCE_MAX_LOC_PARTS = 8;
|
|
207
|
+
/**
|
|
208
|
+
* Extract the BAPI-1520 structural evidence from a parsed error body. Only the
|
|
209
|
+
* `detail.field`/`reason`/`name` of the route's own envelope and the `type` and
|
|
210
|
+
* `loc` of validation issues are read; `input`, `ctx`, and `msg` never are.
|
|
211
|
+
*/
|
|
212
|
+
function extractGateProfileEvidence(detail) {
|
|
213
|
+
const evidence = {};
|
|
214
|
+
if (Array.isArray(detail)) {
|
|
215
|
+
const issues = [];
|
|
216
|
+
for (const item of detail.slice(0, GATE_EVIDENCE_MAX_ISSUES)) {
|
|
217
|
+
if (!item || typeof item !== "object")
|
|
218
|
+
continue;
|
|
219
|
+
const rec = item;
|
|
220
|
+
const type = rec["type"];
|
|
221
|
+
const loc = rec["loc"];
|
|
222
|
+
if (typeof type !== "string" || !GATE_EVIDENCE_TYPE_RE.test(type))
|
|
223
|
+
continue;
|
|
224
|
+
if (!Array.isArray(loc) || loc.length === 0 || loc.length > GATE_EVIDENCE_MAX_LOC_PARTS)
|
|
225
|
+
continue;
|
|
226
|
+
const parts = [];
|
|
227
|
+
let ok = true;
|
|
228
|
+
for (const part of loc) {
|
|
229
|
+
if (typeof part === "number" && Number.isSafeInteger(part) && part >= 0)
|
|
230
|
+
parts.push(part);
|
|
231
|
+
else if (typeof part === "string" && GATE_EVIDENCE_LOC_PART_RE.test(part))
|
|
232
|
+
parts.push(part);
|
|
233
|
+
else
|
|
234
|
+
ok = false;
|
|
235
|
+
}
|
|
236
|
+
if (ok)
|
|
237
|
+
issues.push({ loc: parts, type });
|
|
238
|
+
}
|
|
239
|
+
if (issues.length > 0)
|
|
240
|
+
evidence.issues = issues;
|
|
241
|
+
}
|
|
242
|
+
else if (detail && typeof detail === "object") {
|
|
243
|
+
const d = detail;
|
|
244
|
+
if (typeof d["field"] === "string" && GATE_EVIDENCE_FIELD_RE.test(d["field"])) {
|
|
245
|
+
evidence.field = d["field"];
|
|
246
|
+
}
|
|
247
|
+
if (typeof d["reason"] === "string" && WORKER_ENV_REFUSAL_REASONS.has(d["reason"])) {
|
|
248
|
+
evidence.reason = d["reason"];
|
|
249
|
+
}
|
|
250
|
+
if (typeof d["name"] === "string" && GATE_EVIDENCE_NAME_RE.test(d["name"])) {
|
|
251
|
+
evidence.name = d["name"];
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
return Object.keys(evidence).length > 0 ? evidence : undefined;
|
|
255
|
+
}
|
|
194
256
|
/** Max length of the sanitized body preview embedded in error diagnostics. */
|
|
195
257
|
const CONDUCTOR_ERROR_PREVIEW_MAX = 200;
|
|
258
|
+
/** BAPI-1455 — the stable readiness refusal code for a proven-missing local schema object. */
|
|
259
|
+
export const SCHEMA_INCOMPATIBLE_ERROR_CODE = "SCHEMA_INCOMPATIBLE";
|
|
260
|
+
/** BAPI-1455 — the bound for that refusal's server-authored explanation. */
|
|
261
|
+
const SCHEMA_REFUSAL_PREVIEW_MAX = 2000;
|
|
262
|
+
/** Whether a readiness read failed because the local schema is proven incompatible. */
|
|
263
|
+
export function isSchemaIncompatibleError(err) {
|
|
264
|
+
return err instanceof ConductorBridgeApiError && err.errorCode === SCHEMA_INCOMPATIBLE_ERROR_CODE;
|
|
265
|
+
}
|
|
266
|
+
/** BAPI-1455 — the fixed repair route. Never `alembic stamp`, never a downgrade. */
|
|
267
|
+
export const SCHEMA_INCOMPATIBLE_REPAIR_ROUTE = "Write a reviewed, forward-only Alembic migration that restores the missing objects, " +
|
|
268
|
+
"or rebuild the local database only with the owner's explicit consent.";
|
|
269
|
+
/**
|
|
270
|
+
* The operator lines for a `SCHEMA_INCOMPATIBLE` readiness refusal. The server's
|
|
271
|
+
* explanation (applied stamp and missing objects, from its maintained list) is
|
|
272
|
+
* shown when present; the heading and the repair route are fixed text.
|
|
273
|
+
*/
|
|
274
|
+
export function formatSchemaIncompatibleRefusal(subject, err) {
|
|
275
|
+
return [
|
|
276
|
+
`${subject}: REFUSED (schema-incompatible) — Local schema incompatible. ` +
|
|
277
|
+
"Launch-critical schema objects are missing, so no run was created.",
|
|
278
|
+
...(err.bodyPreview ? [` ${err.bodyPreview}`] : []),
|
|
279
|
+
` Repair: ${SCHEMA_INCOMPATIBLE_REPAIR_ROUTE}`,
|
|
280
|
+
" A migration stamp is not proof of schema; `alembic stamp` cannot restore missing DDL.",
|
|
281
|
+
];
|
|
282
|
+
}
|
|
196
283
|
/**
|
|
197
284
|
* Redact obvious secret-shaped tokens from a diagnostic preview string so a
|
|
198
285
|
* backend message that happens to echo a token/header never reaches a log line.
|
|
@@ -243,11 +330,9 @@ function stripWebhookUrlsDeep(value, depth = 0) {
|
|
|
243
330
|
return out;
|
|
244
331
|
}
|
|
245
332
|
/** Collapse whitespace, redact secrets, and bound a string to the preview cap. */
|
|
246
|
-
function boundedErrorPreview(text) {
|
|
333
|
+
function boundedErrorPreview(text, max = CONDUCTOR_ERROR_PREVIEW_MAX) {
|
|
247
334
|
const redacted = redactErrorPreview(text).replace(/\s+/g, " ").trim();
|
|
248
|
-
return redacted.length >
|
|
249
|
-
? `${redacted.slice(0, CONDUCTOR_ERROR_PREVIEW_MAX)}…`
|
|
250
|
-
: redacted;
|
|
335
|
+
return redacted.length > max ? `${redacted.slice(0, max)}…` : redacted;
|
|
251
336
|
}
|
|
252
337
|
/** Max number of FastAPI `loc` components rendered into a diagnostic path. */
|
|
253
338
|
const CONDUCTOR_VALIDATION_LOC_MAX_PARTS = 8;
|
|
@@ -322,6 +407,9 @@ export function extractSanitizedErrorDiagnostics(body) {
|
|
|
322
407
|
diagnostics.errorCode = boundedErrorPreview(errorCode);
|
|
323
408
|
if (message)
|
|
324
409
|
diagnostics.bodyPreview = boundedErrorPreview(message);
|
|
410
|
+
const gateEvidence = extractGateProfileEvidence(detail);
|
|
411
|
+
if (gateEvidence)
|
|
412
|
+
diagnostics.gateProfileEvidence = gateEvidence;
|
|
325
413
|
// BAPI-872: extract the allowlisted stale-CAS `current_row_version`, from
|
|
326
414
|
// either the nested `detail` object or (defensively) the top level. Only a
|
|
327
415
|
// genuine non-negative safe integer is accepted — never a boolean (JS has no
|
|
@@ -357,6 +445,9 @@ function redactDiagnosticValues(diagnostics, secrets) {
|
|
|
357
445
|
if (typeof diagnostics.currentRowVersion === "number") {
|
|
358
446
|
out.currentRowVersion = diagnostics.currentRowVersion;
|
|
359
447
|
}
|
|
448
|
+
// BAPI-1520: pattern-checked at extraction, so there is nothing left to scrub.
|
|
449
|
+
if (diagnostics.gateProfileEvidence)
|
|
450
|
+
out.gateProfileEvidence = diagnostics.gateProfileEvidence;
|
|
360
451
|
return out;
|
|
361
452
|
}
|
|
362
453
|
/**
|
|
@@ -369,7 +460,9 @@ async function readSanitizedErrorDiagnostics(resp, headers = {}, options = {}) {
|
|
|
369
460
|
try {
|
|
370
461
|
const parsed = stripWebhookUrlsDeep(await resp.json());
|
|
371
462
|
const diagnostics = extractSanitizedErrorDiagnostics(parsed);
|
|
372
|
-
|
|
463
|
+
const codeAllowed = options.readErrorFieldOnlyFor === undefined ||
|
|
464
|
+
(diagnostics.errorCode !== undefined && options.readErrorFieldOnlyFor.includes(diagnostics.errorCode));
|
|
465
|
+
if (options.readErrorField && codeAllowed && !diagnostics.bodyPreview) {
|
|
373
466
|
// BAPI-1154: opt-in only. The route layer's `_http_error` envelope carries
|
|
374
467
|
// its server-authored explanation in `detail.error`, which the shared
|
|
375
468
|
// extractor deliberately does not read (pinned by its own tests). The
|
|
@@ -382,7 +475,7 @@ async function readSanitizedErrorDiagnostics(resp, headers = {}, options = {}) {
|
|
|
382
475
|
? detail["error"]
|
|
383
476
|
: undefined;
|
|
384
477
|
if (typeof error === "string" && error.trim()) {
|
|
385
|
-
diagnostics.bodyPreview = boundedErrorPreview(error.trim());
|
|
478
|
+
diagnostics.bodyPreview = boundedErrorPreview(error.trim(), options.errorFieldPreviewMax);
|
|
386
479
|
}
|
|
387
480
|
}
|
|
388
481
|
const secrets = Object.entries(headers)
|
|
@@ -417,6 +510,8 @@ export class ConductorBridgeApiError extends Error {
|
|
|
417
510
|
* that need it read this field directly.
|
|
418
511
|
*/
|
|
419
512
|
currentRowVersion;
|
|
513
|
+
/** BAPI-1520 — sanitized structural evidence of a gate-profile refusal. */
|
|
514
|
+
gateProfileEvidence;
|
|
420
515
|
constructor(kindOrMessage, status, diagnostics) {
|
|
421
516
|
const isKnownKind = CONDUCTOR_BRIDGE_API_ERROR_KINDS.includes(kindOrMessage);
|
|
422
517
|
const errorCode = diagnostics?.errorCode;
|
|
@@ -446,6 +541,8 @@ export class ConductorBridgeApiError extends Error {
|
|
|
446
541
|
if (typeof diagnostics?.currentRowVersion === "number") {
|
|
447
542
|
this.currentRowVersion = diagnostics.currentRowVersion;
|
|
448
543
|
}
|
|
544
|
+
if (diagnostics?.gateProfileEvidence)
|
|
545
|
+
this.gateProfileEvidence = diagnostics.gateProfileEvidence;
|
|
449
546
|
}
|
|
450
547
|
}
|
|
451
548
|
/**
|
|
@@ -488,7 +585,7 @@ export function conductorGetHeaders(access) {
|
|
|
488
585
|
* non-2xx response — never including the response body, headers, or API key. The
|
|
489
586
|
* timer is always cleared.
|
|
490
587
|
*/
|
|
491
|
-
export async function fetchConductorJsonWithTimeout(url, headers, timeoutMs, fetchImpl = globalThis.fetch) {
|
|
588
|
+
export async function fetchConductorJsonWithTimeout(url, headers, timeoutMs, fetchImpl = globalThis.fetch, errorOptions = {}) {
|
|
492
589
|
const controller = new AbortController();
|
|
493
590
|
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
494
591
|
try {
|
|
@@ -501,7 +598,7 @@ export async function fetchConductorJsonWithTimeout(url, headers, timeoutMs, fet
|
|
|
501
598
|
throw new ConductorBridgeApiError(controller.signal.aborted ? "timeout" : "network");
|
|
502
599
|
}
|
|
503
600
|
if (!resp.ok) {
|
|
504
|
-
const diagnostics = await readSanitizedErrorDiagnostics(resp, headers);
|
|
601
|
+
const diagnostics = await readSanitizedErrorDiagnostics(resp, headers, errorOptions);
|
|
505
602
|
if (resp.status === 401 || resp.status === 403) {
|
|
506
603
|
throw new ConductorBridgeApiError("unauthorized", resp.status, diagnostics);
|
|
507
604
|
}
|
|
@@ -787,6 +884,28 @@ export const REVIEW_HEAD_REFUSAL_CODES = [
|
|
|
787
884
|
"REVIEW_HEAD_LIVE_WORK",
|
|
788
885
|
"REVIEW_HEAD_UNAVAILABLE",
|
|
789
886
|
];
|
|
887
|
+
/**
|
|
888
|
+
* BAPI-1537 — the server's closed refusal codes for the external-repair case.
|
|
889
|
+
* Each is an HTTP 409 that writes nothing and leaves the ticket parked.
|
|
890
|
+
*/
|
|
891
|
+
export const EXTERNAL_REPAIR_REFUSAL_CODES = [
|
|
892
|
+
"EXTERNAL_REPAIR_RUN_NOT_RECOVERABLE",
|
|
893
|
+
"EXTERNAL_REPAIR_NOT_PARKED",
|
|
894
|
+
"EXTERNAL_REPAIR_LIVE_WORK",
|
|
895
|
+
"EXTERNAL_REPAIR_BRANCH_MISMATCH",
|
|
896
|
+
"EXTERNAL_REPAIR_ANCESTRY",
|
|
897
|
+
"EXTERNAL_REPAIR_PR_MISMATCH",
|
|
898
|
+
"EXTERNAL_REPAIR_PR_AMBIGUOUS",
|
|
899
|
+
"EXTERNAL_REPAIR_HEAD_CLAIMED",
|
|
900
|
+
"EXTERNAL_REPAIR_OPERATION_CONFLICT",
|
|
901
|
+
"EXTERNAL_REPAIR_UNAVAILABLE",
|
|
902
|
+
"EXTERNAL_REPAIR_ALREADY_INTEGRATED",
|
|
903
|
+
];
|
|
904
|
+
/**
|
|
905
|
+
* BAPI-1537 — the external-repair refusals that may be retried with the SAME
|
|
906
|
+
* operation id once the cause clears. Never retried automatically.
|
|
907
|
+
*/
|
|
908
|
+
export const EXTERNAL_REPAIR_RETRYABLE_CODES = ["EXTERNAL_REPAIR_UNAVAILABLE"];
|
|
790
909
|
// ---------------------------------------------------------------------------
|
|
791
910
|
// Local boundary validators (reject before any fetch call)
|
|
792
911
|
// ---------------------------------------------------------------------------
|
|
@@ -1037,6 +1156,41 @@ export async function fetchActiveEpicRuns(access, fetchImpl = globalThis.fetch)
|
|
|
1037
1156
|
}
|
|
1038
1157
|
return [];
|
|
1039
1158
|
}
|
|
1159
|
+
/** Every status after which a run can still do work. */
|
|
1160
|
+
const NON_TERMINAL_EPIC_RUN_STATUSES = ["planning", "pending_approval", "active", "blocked"];
|
|
1161
|
+
const NON_TERMINAL_EPIC_RUN_PAGE_LIMIT = 100;
|
|
1162
|
+
/**
|
|
1163
|
+
* The ids of every non-terminal epic run the server holds for the access's
|
|
1164
|
+
* repository (BAPI-1496 plane cleanup). `null` unless the answer is CONCLUSIVE:
|
|
1165
|
+
* any failed read, malformed body, or full page (which may hide more runs)
|
|
1166
|
+
* returns `null`, never a shorter list. Never throws.
|
|
1167
|
+
*/
|
|
1168
|
+
export async function listNonTerminalEpicRunIds(access, fetchImpl = globalThis.fetch) {
|
|
1169
|
+
const ids = [];
|
|
1170
|
+
try {
|
|
1171
|
+
for (const status of NON_TERMINAL_EPIC_RUN_STATUSES) {
|
|
1172
|
+
const url = buildConductorJiraUrl(access.baseUrl, `${EPIC_RUNS_API_PREFIX}/runs`, {
|
|
1173
|
+
repo_name: access.repoName,
|
|
1174
|
+
status,
|
|
1175
|
+
limit: String(NON_TERMINAL_EPIC_RUN_PAGE_LIMIT),
|
|
1176
|
+
});
|
|
1177
|
+
const parsed = await fetchConductorJsonWithTimeout(url, conductorGetHeaders(access), CONDUCTOR_FETCH_TIMEOUT_MS, fetchImpl);
|
|
1178
|
+
const runs = parsed && typeof parsed === "object" ? parsed.runs : undefined;
|
|
1179
|
+
if (!Array.isArray(runs) || runs.length >= NON_TERMINAL_EPIC_RUN_PAGE_LIMIT)
|
|
1180
|
+
return null;
|
|
1181
|
+
for (const run of runs) {
|
|
1182
|
+
const id = run && typeof run === "object" ? run.epic_run_id : undefined;
|
|
1183
|
+
if (typeof id !== "string" || id.length === 0)
|
|
1184
|
+
return null;
|
|
1185
|
+
ids.push(id);
|
|
1186
|
+
}
|
|
1187
|
+
}
|
|
1188
|
+
}
|
|
1189
|
+
catch {
|
|
1190
|
+
return null;
|
|
1191
|
+
}
|
|
1192
|
+
return ids;
|
|
1193
|
+
}
|
|
1040
1194
|
/**
|
|
1041
1195
|
* POST `/jira/epic-runs/runs` to create the durable epic run row.
|
|
1042
1196
|
*
|
|
@@ -1327,6 +1481,7 @@ export async function postContinueParkedChild(access, request, fetchImpl = globa
|
|
|
1327
1481
|
request_fingerprint: request.requestFingerprint,
|
|
1328
1482
|
...(request.reason ? { reason: request.reason } : {}),
|
|
1329
1483
|
...(request.workerExitProof ? { worker_exit_proof: request.workerExitProof } : {}),
|
|
1484
|
+
...(request.driverContext !== undefined ? { driver_context: request.driverContext } : {}),
|
|
1330
1485
|
});
|
|
1331
1486
|
const controller = new AbortController();
|
|
1332
1487
|
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
@@ -1416,9 +1571,15 @@ export async function postGrantContinuation(access, request, fetchImpl = globalT
|
|
|
1416
1571
|
typeof body.replayed === "boolean" &&
|
|
1417
1572
|
grant && typeof grant === "object" &&
|
|
1418
1573
|
grant.request_id === request.requestId) {
|
|
1574
|
+
const fields = body;
|
|
1575
|
+
const replayed = fields.replayed;
|
|
1419
1576
|
return {
|
|
1420
1577
|
kind: "result", requestId: request.requestId,
|
|
1421
|
-
replayed
|
|
1578
|
+
replayed,
|
|
1579
|
+
committed: typeof fields.committed === "boolean" ? fields.committed : !replayed,
|
|
1580
|
+
sourceParkGeneration: typeof fields.source_park_generation === "number"
|
|
1581
|
+
? fields.source_park_generation : null,
|
|
1582
|
+
gate: typeof fields.gate === "string" ? fields.gate : null,
|
|
1422
1583
|
};
|
|
1423
1584
|
}
|
|
1424
1585
|
if (response.status >= 500 || response.ok) {
|
|
@@ -1459,6 +1620,9 @@ export async function adoptCurrentHeadAndUnparkTicket(access, request, fetchImpl
|
|
|
1459
1620
|
expected_row_version: request.expectedRowVersion,
|
|
1460
1621
|
...(request.idempotencyKey !== undefined ? { idempotency_key: request.idempotencyKey } : {}),
|
|
1461
1622
|
...(request.reason !== undefined ? { reason: request.reason } : {}),
|
|
1623
|
+
...(request.externalRepairOperationId !== undefined
|
|
1624
|
+
? { external_repair_operation_id: request.externalRepairOperationId }
|
|
1625
|
+
: {}),
|
|
1462
1626
|
});
|
|
1463
1627
|
return postUnparkLikeRequest(url, conductorPostHeaders(access), body, fetchImpl);
|
|
1464
1628
|
}
|
|
@@ -1584,6 +1748,75 @@ export async function dispatchRemediation(access, request, fetchImpl = globalThi
|
|
|
1584
1748
|
const parsed = await postRepairRequest(access, `${epicRunApiPath(request.epicRunId)}/tickets/${encodeURIComponent(request.ticketKey)}/dispatch-remediation`, withGuard({ context: request.context }, request.guard), fetchImpl);
|
|
1585
1749
|
return parseDispatchRemediationResult(parsed);
|
|
1586
1750
|
}
|
|
1751
|
+
function parseHandoffResolutionRecord(value) {
|
|
1752
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
1753
|
+
throw new ConductorBridgeApiError("server");
|
|
1754
|
+
}
|
|
1755
|
+
const r = value;
|
|
1756
|
+
const steps = r["steps"];
|
|
1757
|
+
if (!Array.isArray(steps) ||
|
|
1758
|
+
!steps.every((step) => typeof step === "number" && Number.isSafeInteger(step) && step > 0) ||
|
|
1759
|
+
typeof r["binding_attempt_id"] !== "string" ||
|
|
1760
|
+
typeof r["evidence_revision"] !== "number" ||
|
|
1761
|
+
typeof r["epic_head_sha"] !== "string" ||
|
|
1762
|
+
typeof r["evidence_ref"] !== "string" ||
|
|
1763
|
+
typeof r["actor"] !== "string" ||
|
|
1764
|
+
(r["kind"] !== "verified" && r["kind"] !== "risk_accepted") ||
|
|
1765
|
+
typeof r["reason"] !== "string" ||
|
|
1766
|
+
typeof r["at"] !== "string") {
|
|
1767
|
+
throw new ConductorBridgeApiError("server");
|
|
1768
|
+
}
|
|
1769
|
+
return {
|
|
1770
|
+
steps: steps,
|
|
1771
|
+
binding_attempt_id: r["binding_attempt_id"],
|
|
1772
|
+
evidence_revision: r["evidence_revision"],
|
|
1773
|
+
epic_head_sha: r["epic_head_sha"],
|
|
1774
|
+
evidence_ref: r["evidence_ref"],
|
|
1775
|
+
actor: r["actor"],
|
|
1776
|
+
kind: r["kind"],
|
|
1777
|
+
reason: r["reason"],
|
|
1778
|
+
at: r["at"],
|
|
1779
|
+
};
|
|
1780
|
+
}
|
|
1781
|
+
function parseResolveHandoffResult(parsed) {
|
|
1782
|
+
const p = parseRepairBase(parsed);
|
|
1783
|
+
const remaining = p["remaining_unresolved"];
|
|
1784
|
+
if (typeof p["ticket_key"] !== "string" ||
|
|
1785
|
+
!Array.isArray(p["resolutions"]) ||
|
|
1786
|
+
typeof remaining !== "number" ||
|
|
1787
|
+
!Number.isSafeInteger(remaining) ||
|
|
1788
|
+
remaining < 0) {
|
|
1789
|
+
throw new ConductorBridgeApiError("server");
|
|
1790
|
+
}
|
|
1791
|
+
return {
|
|
1792
|
+
epic_run_id: p["epic_run_id"],
|
|
1793
|
+
ticket_key: p["ticket_key"],
|
|
1794
|
+
committed: p["committed"],
|
|
1795
|
+
event_recorded: p["event_recorded"],
|
|
1796
|
+
resolutions: p["resolutions"].map(parseHandoffResolutionRecord),
|
|
1797
|
+
remaining_unresolved: remaining,
|
|
1798
|
+
};
|
|
1799
|
+
}
|
|
1800
|
+
/**
|
|
1801
|
+
* POST `/jira/epic-runs/runs/{epic_run_id}/tickets/{ticket_key}/resolve-handoff`
|
|
1802
|
+
* (BAPI-1494) — body `{repo_name, steps, kind, evidence_ref, reason}` and nothing
|
|
1803
|
+
* else. There is no actor field: the SERVER records the verified request actor.
|
|
1804
|
+
*/
|
|
1805
|
+
export async function resolveHandoff(access, request, fetchImpl = globalThis.fetch) {
|
|
1806
|
+
requireNonEmptyString(request.epicRunId);
|
|
1807
|
+
requireNonEmptyString(request.ticketKey);
|
|
1808
|
+
const parsed = await postRepairRequest(access, `${epicRunApiPath(request.epicRunId)}/tickets/${encodeURIComponent(request.ticketKey)}/resolve-handoff`, {
|
|
1809
|
+
steps: request.steps,
|
|
1810
|
+
kind: request.kind,
|
|
1811
|
+
evidence_ref: request.evidenceRef,
|
|
1812
|
+
reason: request.reason,
|
|
1813
|
+
}, fetchImpl);
|
|
1814
|
+
return parseResolveHandoffResult(parsed);
|
|
1815
|
+
}
|
|
1816
|
+
/** The synthetic code an old server's missing escalate route is reported under. */
|
|
1817
|
+
export const ESCALATE_ROUTE_UNAVAILABLE_CODE = "ESCALATE_ROUTE_UNAVAILABLE";
|
|
1818
|
+
/** The fixed operator text for a server that has no `escalate` route. */
|
|
1819
|
+
export const ESCALATE_ROUTE_UNAVAILABLE_MESSAGE = "escalate is not available on this server; the Bridge API server needs an upgrade before using it";
|
|
1587
1820
|
export async function escalateTicket(access, request, fetchImpl = globalThis.fetch) {
|
|
1588
1821
|
requireNonEmptyString(request.epicRunId);
|
|
1589
1822
|
requireNonEmptyString(request.ticketKey);
|
|
@@ -1591,7 +1824,22 @@ export async function escalateTicket(access, request, fetchImpl = globalThis.fet
|
|
|
1591
1824
|
requireNonEmptyString(request.actionNeeded);
|
|
1592
1825
|
if (request.actionNeeded.length > 300)
|
|
1593
1826
|
throw new ConductorBridgeApiError("server");
|
|
1594
|
-
|
|
1827
|
+
let result;
|
|
1828
|
+
try {
|
|
1829
|
+
result = await postRepairRequest(access, `${epicRunApiPath(request.epicRunId)}/tickets/${encodeURIComponent(request.ticketKey)}/escalate`, { cause: request.cause, action_needed: request.actionNeeded }, fetchImpl);
|
|
1830
|
+
}
|
|
1831
|
+
catch (err) {
|
|
1832
|
+
// An untyped 404/405 means the server predates the route; a server-coded
|
|
1833
|
+
// refusal keeps its own code and reason.
|
|
1834
|
+
if (err instanceof ConductorBridgeApiError && !err.errorCode &&
|
|
1835
|
+
(err.status === 404 || err.status === 405)) {
|
|
1836
|
+
throw new ConductorBridgeApiError("http", err.status, {
|
|
1837
|
+
errorCode: ESCALATE_ROUTE_UNAVAILABLE_CODE,
|
|
1838
|
+
bodyPreview: ESCALATE_ROUTE_UNAVAILABLE_MESSAGE,
|
|
1839
|
+
});
|
|
1840
|
+
}
|
|
1841
|
+
throw err;
|
|
1842
|
+
}
|
|
1595
1843
|
const value = result;
|
|
1596
1844
|
if (!value || !["created", "deduplicated", "suppressed"].includes(value.status) ||
|
|
1597
1845
|
!Number.isSafeInteger(value.notification_id) || value.notification_id <= 0 ||
|
|
@@ -2259,6 +2507,149 @@ function safeStringArray(value) {
|
|
|
2259
2507
|
return [];
|
|
2260
2508
|
return value.filter((v) => typeof v === "string" && v !== "");
|
|
2261
2509
|
}
|
|
2510
|
+
// ---------------------------------------------------------------------------
|
|
2511
|
+
// BAPI-1510 — already-merged child detection and skipped-child audit clients
|
|
2512
|
+
// ---------------------------------------------------------------------------
|
|
2513
|
+
export const CHILD_MERGE_CLASSIFICATIONS = ["done", "probably_done", "not_done", "unknown"];
|
|
2514
|
+
export const CHILD_MERGE_EVIDENCE_SOURCES = ["delivery_binding", "feature_branch", "none"];
|
|
2515
|
+
export const CHILD_MERGE_ANCESTRY_VALUES = ["covered", "behind", "unknown", "not_checked"];
|
|
2516
|
+
export const CHILD_MERGE_REASONS = [
|
|
2517
|
+
"merged_on_cut_commit",
|
|
2518
|
+
"merged_without_delivery_record",
|
|
2519
|
+
"merged_after_index",
|
|
2520
|
+
"ancestry_unknown",
|
|
2521
|
+
"no_merged_pr_found",
|
|
2522
|
+
"binding_ambiguous",
|
|
2523
|
+
"provider_unavailable",
|
|
2524
|
+
"binding_read_failed",
|
|
2525
|
+
"merge_sha_unavailable",
|
|
2526
|
+
"ancestry_unavailable_for_provider",
|
|
2527
|
+
"deadline_exceeded",
|
|
2528
|
+
];
|
|
2529
|
+
const FULL_COMMIT_SHA_PATTERN = /^[0-9a-f]{40}$/;
|
|
2530
|
+
function isOneOf(allowed, value) {
|
|
2531
|
+
return typeof value === "string" && allowed.includes(value);
|
|
2532
|
+
}
|
|
2533
|
+
/**
|
|
2534
|
+
* POST `/jira/epic-runs/child-merge-status`: read-only classification of plan
|
|
2535
|
+
* children against one indexed cut commit. Creates no run, event, or charge.
|
|
2536
|
+
*
|
|
2537
|
+
* The response is validated strictly: a missing, duplicated, or reordered child,
|
|
2538
|
+
* an out-of-vocabulary value, a malformed PR number or SHA, or an echoed cut that
|
|
2539
|
+
* differs from the requested one is a protocol error. A malformed body must never
|
|
2540
|
+
* reach plan trimming.
|
|
2541
|
+
*/
|
|
2542
|
+
export async function classifyChildMergeStatus(access, request, fetchImpl = globalThis.fetch) {
|
|
2543
|
+
const url = buildConductorJiraUrl(access.baseUrl, `${EPIC_RUNS_API_PREFIX}/child-merge-status`);
|
|
2544
|
+
const parsed = await fetchConductorJsonPostWithTimeout(url, conductorPostHeaders(access), JSON.stringify({
|
|
2545
|
+
repo_name: access.repoName,
|
|
2546
|
+
epic_key: request.epicKey,
|
|
2547
|
+
child_keys: [...request.childKeys],
|
|
2548
|
+
cut_commit_sha: request.cutCommitSha,
|
|
2549
|
+
}), CONDUCTOR_FETCH_TIMEOUT_MS, fetchImpl);
|
|
2550
|
+
return parseChildMergeStatusResponse(parsed, request);
|
|
2551
|
+
}
|
|
2552
|
+
/** Strict parse of the classification body; throws a sanitized error on any deviation. */
|
|
2553
|
+
export function parseChildMergeStatusResponse(parsed, request) {
|
|
2554
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
2555
|
+
throw new ConductorBridgeApiError("server");
|
|
2556
|
+
}
|
|
2557
|
+
const p = parsed;
|
|
2558
|
+
const cut = p["cut_commit_sha"];
|
|
2559
|
+
const children = p["children"];
|
|
2560
|
+
if (typeof cut !== "string" || cut !== request.cutCommitSha || !Array.isArray(children)) {
|
|
2561
|
+
throw new ConductorBridgeApiError("server");
|
|
2562
|
+
}
|
|
2563
|
+
if (children.length !== request.childKeys.length) {
|
|
2564
|
+
throw new ConductorBridgeApiError("server");
|
|
2565
|
+
}
|
|
2566
|
+
const seen = new Set();
|
|
2567
|
+
const results = [];
|
|
2568
|
+
for (let i = 0; i < children.length; i += 1) {
|
|
2569
|
+
const raw = children[i];
|
|
2570
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) {
|
|
2571
|
+
throw new ConductorBridgeApiError("server");
|
|
2572
|
+
}
|
|
2573
|
+
const c = raw;
|
|
2574
|
+
const key = c["ticket_key"];
|
|
2575
|
+
if (typeof key !== "string" || key !== request.childKeys[i] || seen.has(key)) {
|
|
2576
|
+
throw new ConductorBridgeApiError("server");
|
|
2577
|
+
}
|
|
2578
|
+
seen.add(key);
|
|
2579
|
+
const pr = c["pr_number"];
|
|
2580
|
+
const sha = c["merge_commit_sha"];
|
|
2581
|
+
if (!isOneOf(CHILD_MERGE_CLASSIFICATIONS, c["classification"]) ||
|
|
2582
|
+
!isOneOf(CHILD_MERGE_EVIDENCE_SOURCES, c["evidence_source"]) ||
|
|
2583
|
+
!isOneOf(CHILD_MERGE_ANCESTRY_VALUES, c["ancestry"]) ||
|
|
2584
|
+
!isOneOf(CHILD_MERGE_REASONS, c["reason"]) ||
|
|
2585
|
+
!(pr === null || (typeof pr === "number" && Number.isSafeInteger(pr) && pr > 0)) ||
|
|
2586
|
+
!(sha === null || (typeof sha === "string" && FULL_COMMIT_SHA_PATTERN.test(sha)))) {
|
|
2587
|
+
throw new ConductorBridgeApiError("server");
|
|
2588
|
+
}
|
|
2589
|
+
results.push({
|
|
2590
|
+
ticket_key: key,
|
|
2591
|
+
classification: c["classification"],
|
|
2592
|
+
evidence_source: c["evidence_source"],
|
|
2593
|
+
pr_number: pr,
|
|
2594
|
+
merge_commit_sha: sha,
|
|
2595
|
+
ancestry: c["ancestry"],
|
|
2596
|
+
reason: c["reason"],
|
|
2597
|
+
});
|
|
2598
|
+
}
|
|
2599
|
+
return { cut_commit_sha: cut, children: results };
|
|
2600
|
+
}
|
|
2601
|
+
export const SKIPPED_CHILD_OUTCOMES = ["recorded", "already_recorded", "refused"];
|
|
2602
|
+
export const SKIPPED_CHILD_REFUSAL_REASONS = [
|
|
2603
|
+
"not_skippable",
|
|
2604
|
+
"child_present_in_plan",
|
|
2605
|
+
"run_context_unavailable",
|
|
2606
|
+
];
|
|
2607
|
+
/**
|
|
2608
|
+
* POST `/jira/epic-runs/{epic_run_id}/skipped-children`: audit-only record of
|
|
2609
|
+
* children a newly created run left out. The body carries repository identity,
|
|
2610
|
+
* child keys, and confirmation booleans only; the server derives every fact.
|
|
2611
|
+
*/
|
|
2612
|
+
export async function recordSkippedChildren(access, epicRunId, children, fetchImpl = globalThis.fetch) {
|
|
2613
|
+
const url = buildConductorJiraUrl(access.baseUrl, `${EPIC_RUNS_API_PREFIX}/${encodeURIComponent(epicRunId)}/skipped-children`);
|
|
2614
|
+
const parsed = await fetchConductorJsonPostWithTimeout(url, conductorPostHeaders(access), JSON.stringify({
|
|
2615
|
+
repo_name: access.repoName,
|
|
2616
|
+
children: children.map((c) => ({
|
|
2617
|
+
ticket_key: c.ticketKey,
|
|
2618
|
+
operator_confirmed: c.operatorConfirmed,
|
|
2619
|
+
})),
|
|
2620
|
+
}), CONDUCTOR_FETCH_TIMEOUT_MS, fetchImpl);
|
|
2621
|
+
return parseRecordSkippedChildrenResponse(parsed, children.map((c) => c.ticketKey));
|
|
2622
|
+
}
|
|
2623
|
+
/** Strict parse of the recording body; throws a sanitized error on any deviation. */
|
|
2624
|
+
export function parseRecordSkippedChildrenResponse(parsed, expectedKeys) {
|
|
2625
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
2626
|
+
throw new ConductorBridgeApiError("server");
|
|
2627
|
+
}
|
|
2628
|
+
const results = parsed["results"];
|
|
2629
|
+
if (!Array.isArray(results) || results.length !== expectedKeys.length) {
|
|
2630
|
+
throw new ConductorBridgeApiError("server");
|
|
2631
|
+
}
|
|
2632
|
+
const out = [];
|
|
2633
|
+
for (let i = 0; i < results.length; i += 1) {
|
|
2634
|
+
const raw = results[i];
|
|
2635
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) {
|
|
2636
|
+
throw new ConductorBridgeApiError("server");
|
|
2637
|
+
}
|
|
2638
|
+
const r = raw;
|
|
2639
|
+
const reason = r["reason"];
|
|
2640
|
+
if (r["ticket_key"] !== expectedKeys[i] ||
|
|
2641
|
+
!isOneOf(SKIPPED_CHILD_OUTCOMES, r["outcome"]) ||
|
|
2642
|
+
!(reason === null || reason === undefined || isOneOf(SKIPPED_CHILD_REFUSAL_REASONS, reason))) {
|
|
2643
|
+
throw new ConductorBridgeApiError("server");
|
|
2644
|
+
}
|
|
2645
|
+
out.push({
|
|
2646
|
+
ticket_key: expectedKeys[i],
|
|
2647
|
+
outcome: r["outcome"],
|
|
2648
|
+
reason: (reason ?? null),
|
|
2649
|
+
});
|
|
2650
|
+
}
|
|
2651
|
+
return { results: out };
|
|
2652
|
+
}
|
|
2262
2653
|
/** Non-negative safe integer, or 0 for anything else (absent field included). */
|
|
2263
2654
|
function safeCount(value) {
|
|
2264
2655
|
return typeof value === "number" && Number.isSafeInteger(value) && value >= 0 ? value : 0;
|
|
@@ -2615,6 +3006,40 @@ export const REQUIRED_CHECKS_VERIFICATIONS = new Set([
|
|
|
2615
3006
|
"unknown_name",
|
|
2616
3007
|
"unverifiable",
|
|
2617
3008
|
]);
|
|
3009
|
+
export function parseReadinessPrerequisites(raw) {
|
|
3010
|
+
if (!Array.isArray(raw))
|
|
3011
|
+
return undefined;
|
|
3012
|
+
const seen = new Set();
|
|
3013
|
+
const result = [];
|
|
3014
|
+
for (const item of raw) {
|
|
3015
|
+
if (typeof item !== 'object' || item === null || Array.isArray(item))
|
|
3016
|
+
return undefined;
|
|
3017
|
+
const r = item;
|
|
3018
|
+
const d = typeof r.id === 'string' ? READINESS_PREREQUISITE_BY_ID.get(r.id) : undefined;
|
|
3019
|
+
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 ||
|
|
3020
|
+
!['met', 'not_met', 'unknown', 'not_applicable'].includes(String(r.check_status)) || !['blocking', 'warning', 'info'].includes(String(r.impact)) ||
|
|
3021
|
+
typeof r.fix !== 'string' || !Object.values(READINESS_PREREQUISITE_FIXES).includes(r.fix) ||
|
|
3022
|
+
(r.check_status === 'unknown' && r.impact === 'blocking'))
|
|
3023
|
+
return undefined;
|
|
3024
|
+
seen.add(d.id);
|
|
3025
|
+
result.push(r);
|
|
3026
|
+
}
|
|
3027
|
+
return result;
|
|
3028
|
+
}
|
|
3029
|
+
export const ESCALATION_CHANNELS = ["webhook", "email", "none", "unknown"];
|
|
3030
|
+
export const WEBHOOK_LAST_DELIVERIES = ["failed", "handed_off", "queued", "unknown"];
|
|
3031
|
+
/** BAPI-1452 — the three supported merge execution modes, as the server reports them. */
|
|
3032
|
+
export const RESOLVED_MERGE_EXECUTION_MODES = ["local", "machine_token", "github_actions"];
|
|
3033
|
+
/**
|
|
3034
|
+
* BAPI-1452 — a provider repository identity: exactly one `/`, each side
|
|
3035
|
+
* starting with an alphanumeric and bounded, no whitespace, control
|
|
3036
|
+
* characters, URL syntax, or path traversal.
|
|
3037
|
+
*/
|
|
3038
|
+
const PROVIDER_REPOSITORY_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._-]{0,99}\/[A-Za-z0-9][A-Za-z0-9._-]{0,99}$/;
|
|
3039
|
+
/** True when `value` is a well-formed `owner/name` provider identity (BAPI-1452). */
|
|
3040
|
+
export function isProviderRepositoryIdentity(value) {
|
|
3041
|
+
return typeof value === "string" && PROVIDER_REPOSITORY_PATTERN.test(value);
|
|
3042
|
+
}
|
|
2618
3043
|
/** BAPI-1260 — one mandatory-evidence verdict. Only `confirmed` ever holds. */
|
|
2619
3044
|
export const ADMISSION_EVIDENCE_VERDICTS = [
|
|
2620
3045
|
"confirmed",
|
|
@@ -2892,6 +3317,9 @@ export function parseConductorReadinessResponse(body) {
|
|
|
2892
3317
|
const thr = requireObject(root.thresholds);
|
|
2893
3318
|
const requiredChecksCount = requireInt(sup, "required_checks_count");
|
|
2894
3319
|
return {
|
|
3320
|
+
...(typeof root.is_production === 'boolean' ? { is_production: root.is_production } : {}),
|
|
3321
|
+
...(root.is_production === undefined || typeof root.is_production === 'boolean'
|
|
3322
|
+
? { prerequisites: parseReadinessPrerequisites(root.prerequisites) } : {}),
|
|
2895
3323
|
repo_name: repoName,
|
|
2896
3324
|
supervisor: {
|
|
2897
3325
|
setup_present: requireBool(sup, "setup_present"),
|
|
@@ -2966,8 +3394,51 @@ export function parseConductorReadinessResponse(body) {
|
|
|
2966
3394
|
const diagnostics = parseReadinessDiagnostics(root);
|
|
2967
3395
|
return diagnostics === undefined ? {} : { diagnostics };
|
|
2968
3396
|
})(),
|
|
3397
|
+
...parseLaunchMergeFacts(root),
|
|
3398
|
+
...parseEscalationObservations(root),
|
|
2969
3399
|
};
|
|
2970
3400
|
}
|
|
3401
|
+
/**
|
|
3402
|
+
* BAPI-1495 — the closed escalation observations. Absent stays absent (an older
|
|
3403
|
+
* server). A present value outside the closed set is dropped rather than rejecting
|
|
3404
|
+
* the read: the wording seam reads a dropped field as unknown.
|
|
3405
|
+
*/
|
|
3406
|
+
function parseEscalationObservations(body) {
|
|
3407
|
+
const out = {};
|
|
3408
|
+
if (ESCALATION_CHANNELS.includes(body.escalation_channel)) {
|
|
3409
|
+
out.escalation_channel = body.escalation_channel;
|
|
3410
|
+
}
|
|
3411
|
+
if (body.webhook_last_delivery === null) {
|
|
3412
|
+
out.webhook_last_delivery = null;
|
|
3413
|
+
}
|
|
3414
|
+
else if (WEBHOOK_LAST_DELIVERIES.includes(body.webhook_last_delivery)) {
|
|
3415
|
+
out.webhook_last_delivery = body.webhook_last_delivery;
|
|
3416
|
+
}
|
|
3417
|
+
return out;
|
|
3418
|
+
}
|
|
3419
|
+
/**
|
|
3420
|
+
* BAPI-1452 — parse the two additive launch facts.
|
|
3421
|
+
*
|
|
3422
|
+
* Absent keys stay absent (an older server). A PRESENT value that is not a
|
|
3423
|
+
* supported mode, or not a well-formed `owner/name`, becomes `null` rather
|
|
3424
|
+
* than rejecting the whole readiness read: these facts only feed a launch
|
|
3425
|
+
* warning, and losing every other readiness fact over one malformed additive
|
|
3426
|
+
* field would be the wrong trade. `null` is never read as a usable default.
|
|
3427
|
+
*/
|
|
3428
|
+
function parseLaunchMergeFacts(body) {
|
|
3429
|
+
const out = {};
|
|
3430
|
+
if (Object.prototype.hasOwnProperty.call(body, "resolved_merge_execution_mode")) {
|
|
3431
|
+
const mode = body.resolved_merge_execution_mode;
|
|
3432
|
+
out.resolved_merge_execution_mode = RESOLVED_MERGE_EXECUTION_MODES.includes(mode)
|
|
3433
|
+
? mode
|
|
3434
|
+
: null;
|
|
3435
|
+
}
|
|
3436
|
+
if (Object.prototype.hasOwnProperty.call(body, "provider_repository")) {
|
|
3437
|
+
const repository = body.provider_repository;
|
|
3438
|
+
out.provider_repository = isProviderRepositoryIdentity(repository) ? repository : null;
|
|
3439
|
+
}
|
|
3440
|
+
return out;
|
|
3441
|
+
}
|
|
2971
3442
|
function parseReadinessDiagnostics(body) {
|
|
2972
3443
|
if (body.diagnostics === undefined || body.diagnostics === null)
|
|
2973
3444
|
return undefined;
|
|
@@ -3246,6 +3717,7 @@ export function parseEpicBranchCiReadiness(body) {
|
|
|
3246
3717
|
});
|
|
3247
3718
|
return {
|
|
3248
3719
|
effective_review_mode: enumOrNull(o.effective_review_mode, EFFECTIVE_REVIEW_MODES),
|
|
3720
|
+
effective_review_mode_scope: o.effective_review_mode_scope === "run" ? "run" : "repository",
|
|
3249
3721
|
decision,
|
|
3250
3722
|
evidence,
|
|
3251
3723
|
no_ci_warning: requireBool(o, "no_ci_warning"),
|
|
@@ -3380,20 +3852,96 @@ function parseUnattended(body) {
|
|
|
3380
3852
|
escalation_email_available: o.escalation_email_available === true,
|
|
3381
3853
|
};
|
|
3382
3854
|
}
|
|
3383
|
-
|
|
3384
|
-
* GET `/jira/epic-runs/conductor-readiness?repo_name=<repo>`.
|
|
3385
|
-
*
|
|
3386
|
-
* The API key travels ONLY in `X-API-Key`; `repo_name` is URL-encoded into the
|
|
3387
|
-
* query string because the endpoint scopes on it. Fails closed on transport,
|
|
3388
|
-
* auth, and shape errors alike.
|
|
3389
|
-
*/
|
|
3390
|
-
export async function fetchConductorReadiness(access, fetchImpl = globalThis.fetch) {
|
|
3855
|
+
export async function fetchConductorReadiness(access, fetchImpl = globalThis.fetch, options = {}) {
|
|
3391
3856
|
const url = buildConductorJiraUrl(access.baseUrl, `${EPIC_RUNS_API_PREFIX}/conductor-readiness`, {
|
|
3392
3857
|
repo_name: access.repoName,
|
|
3858
|
+
...(options.epicRunId ? { epic_run_id: options.epicRunId } : {}),
|
|
3859
|
+
});
|
|
3860
|
+
// BAPI-1455 — a `SCHEMA_INCOMPATIBLE` refusal explains itself in
|
|
3861
|
+
// `detail.error` (the applied stamp, the missing objects, the repair route),
|
|
3862
|
+
// so that field is read, with room for the object names.
|
|
3863
|
+
const body = await fetchConductorJsonWithTimeout(url, conductorGetHeaders(access), CONDUCTOR_FETCH_TIMEOUT_MS, fetchImpl, {
|
|
3864
|
+
readErrorField: true,
|
|
3865
|
+
errorFieldPreviewMax: SCHEMA_REFUSAL_PREVIEW_MAX,
|
|
3866
|
+
readErrorFieldOnlyFor: [SCHEMA_INCOMPATIBLE_ERROR_CODE],
|
|
3393
3867
|
});
|
|
3394
|
-
const body = await fetchConductorJsonWithTimeout(url, conductorGetHeaders(access), CONDUCTOR_FETCH_TIMEOUT_MS, fetchImpl);
|
|
3395
3868
|
return parseConductorReadinessResponse(body);
|
|
3396
3869
|
}
|
|
3870
|
+
/** The answer for every failure: an older server, a non-200, a timeout, a bad body. */
|
|
3871
|
+
export const REPOSITORY_USAGE_ADVISORY_UNAVAILABLE = Object.freeze({
|
|
3872
|
+
state: "unavailable",
|
|
3873
|
+
utilization_percent: null,
|
|
3874
|
+
status: null,
|
|
3875
|
+
observed_at: null,
|
|
3876
|
+
resets_at: null,
|
|
3877
|
+
stale: null,
|
|
3878
|
+
});
|
|
3879
|
+
/** Same size as the plane freshness probes' bound, so no launch read waits longer. */
|
|
3880
|
+
export const REPOSITORY_USAGE_ADVISORY_TIMEOUT_MS = 30_000;
|
|
3881
|
+
const USAGE_ADVISORY_STATES = new Set([
|
|
3882
|
+
"observed",
|
|
3883
|
+
"below_warning_threshold",
|
|
3884
|
+
"absent",
|
|
3885
|
+
"unavailable",
|
|
3886
|
+
]);
|
|
3887
|
+
const USAGE_ADVISORY_FIELD_MAX = 64;
|
|
3888
|
+
function boundedUsageString(value) {
|
|
3889
|
+
if (value === undefined || value === null)
|
|
3890
|
+
return null;
|
|
3891
|
+
if (typeof value !== "string" || value.length > USAGE_ADVISORY_FIELD_MAX)
|
|
3892
|
+
return undefined;
|
|
3893
|
+
return value;
|
|
3894
|
+
}
|
|
3895
|
+
/** Validate a usage-advisory body. `null` when any field is out of contract. */
|
|
3896
|
+
export function parseRepositoryUsageAdvisory(body) {
|
|
3897
|
+
if (body === null || typeof body !== "object" || Array.isArray(body))
|
|
3898
|
+
return null;
|
|
3899
|
+
const o = body;
|
|
3900
|
+
if (typeof o.state !== "string" || !USAGE_ADVISORY_STATES.has(o.state))
|
|
3901
|
+
return null;
|
|
3902
|
+
const percent = o.utilization_percent;
|
|
3903
|
+
let utilization = null;
|
|
3904
|
+
if (percent !== undefined && percent !== null) {
|
|
3905
|
+
if (typeof percent !== "number" || !Number.isInteger(percent) || percent < 0 || percent > 100)
|
|
3906
|
+
return null;
|
|
3907
|
+
utilization = percent;
|
|
3908
|
+
}
|
|
3909
|
+
const status = boundedUsageString(o.status);
|
|
3910
|
+
const observedAt = boundedUsageString(o.observed_at);
|
|
3911
|
+
const resetsAt = boundedUsageString(o.resets_at);
|
|
3912
|
+
if (status === undefined || observedAt === undefined || resetsAt === undefined)
|
|
3913
|
+
return null;
|
|
3914
|
+
if (observedAt !== null && Number.isNaN(Date.parse(observedAt)))
|
|
3915
|
+
return null;
|
|
3916
|
+
let stale = null;
|
|
3917
|
+
if (o.stale !== undefined && o.stale !== null) {
|
|
3918
|
+
if (typeof o.stale !== "boolean")
|
|
3919
|
+
return null;
|
|
3920
|
+
stale = o.stale;
|
|
3921
|
+
}
|
|
3922
|
+
const state = o.state;
|
|
3923
|
+
if (state === "observed" && (utilization === null || status === null))
|
|
3924
|
+
return null;
|
|
3925
|
+
return { state, utilization_percent: utilization, status, observed_at: observedAt, resets_at: resetsAt, stale };
|
|
3926
|
+
}
|
|
3927
|
+
/**
|
|
3928
|
+
* GET `/jira/epic-runs/usage-advisory?repo_name=<repo>`. NEVER throws: a 404
|
|
3929
|
+
* from an older server, any other non-200, a transport failure, a timeout, or a
|
|
3930
|
+
* malformed body is {@link REPOSITORY_USAGE_ADVISORY_UNAVAILABLE}. The launch
|
|
3931
|
+
* preview turns that into a warning row; it can never change a launch decision.
|
|
3932
|
+
*/
|
|
3933
|
+
export async function fetchRepositoryUsageAdvisory(access, fetchImpl = globalThis.fetch) {
|
|
3934
|
+
try {
|
|
3935
|
+
const url = buildConductorJiraUrl(access.baseUrl, `${EPIC_RUNS_API_PREFIX}/usage-advisory`, {
|
|
3936
|
+
repo_name: access.repoName,
|
|
3937
|
+
});
|
|
3938
|
+
const body = await fetchConductorJsonWithTimeout(url, conductorGetHeaders(access), REPOSITORY_USAGE_ADVISORY_TIMEOUT_MS, fetchImpl);
|
|
3939
|
+
return parseRepositoryUsageAdvisory(body) ?? REPOSITORY_USAGE_ADVISORY_UNAVAILABLE;
|
|
3940
|
+
}
|
|
3941
|
+
catch {
|
|
3942
|
+
return REPOSITORY_USAGE_ADVISORY_UNAVAILABLE;
|
|
3943
|
+
}
|
|
3944
|
+
}
|
|
3397
3945
|
const ROW_OUTCOMES = new Set(["created", "changed", "preserved"]);
|
|
3398
3946
|
function optionalRowOutcome(o, key) {
|
|
3399
3947
|
const v = o[key];
|
|
@@ -3766,6 +4314,126 @@ export async function resumeCiTicket(access, request, fetchImpl = globalThis.fet
|
|
|
3766
4314
|
clearTimeout(timer);
|
|
3767
4315
|
}
|
|
3768
4316
|
}
|
|
4317
|
+
/** The closed refusal table of `regenerate-plan`; `CONFLICT` is the stale row version. */
|
|
4318
|
+
export const REGENERATE_PLAN_REFUSAL_CODES = [
|
|
4319
|
+
"PLAN_REGEN_NOT_ELIGIBLE",
|
|
4320
|
+
"PLAN_REGEN_OPERATION_CONFLICT",
|
|
4321
|
+
"PLAN_REGEN_ANSWERED_CONFLICT",
|
|
4322
|
+
"PLAN_REGEN_STALE_PARK",
|
|
4323
|
+
"PLAN_REGEN_ALLOWANCE_SPENT",
|
|
4324
|
+
"PLAN_REGEN_ROUTE_NOT_ALLOWED",
|
|
4325
|
+
"PLAN_REGEN_RUN_NOT_ACTIVE",
|
|
4326
|
+
"PLAN_REGEN_BUSY",
|
|
4327
|
+
"PLAN_REGEN_SCHEMA_UNAVAILABLE",
|
|
4328
|
+
"SPEC_SNAPSHOT_UNAVAILABLE",
|
|
4329
|
+
"TICKET_NOT_IN_RUN",
|
|
4330
|
+
"NOT_FOUND",
|
|
4331
|
+
"CONFLICT",
|
|
4332
|
+
];
|
|
4333
|
+
/** True when `code` is one of the closed `regenerate-plan` refusal codes. */
|
|
4334
|
+
export function isRegeneratePlanRefusalCode(code) {
|
|
4335
|
+
return REGENERATE_PLAN_REFUSAL_CODES.includes(code);
|
|
4336
|
+
}
|
|
4337
|
+
/** Strictly parse a `regenerate-plan` success body; anything short of the contract throws. */
|
|
4338
|
+
export function parseRegeneratePlanResult(value) {
|
|
4339
|
+
if (!isPlainRecord(value))
|
|
4340
|
+
throw new ConductorBridgeApiError("server");
|
|
4341
|
+
const v = value;
|
|
4342
|
+
if (typeof v.epic_run_id !== "string" || !v.epic_run_id ||
|
|
4343
|
+
typeof v.ticket_key !== "string" || !v.ticket_key ||
|
|
4344
|
+
(v.outcome !== "committed" && v.outcome !== "replayed" && v.outcome !== "answered_replay") ||
|
|
4345
|
+
(v.accepted_route !== "test" && v.accepted_route !== "implementation") ||
|
|
4346
|
+
!isNonNegativeInt(v.answered_park_generation) ||
|
|
4347
|
+
!isNonNegativeInt(v.row_version) ||
|
|
4348
|
+
!nullableString(v.ticket_status) ||
|
|
4349
|
+
v.plan_ready !== false) {
|
|
4350
|
+
throw new ConductorBridgeApiError("server");
|
|
4351
|
+
}
|
|
4352
|
+
return {
|
|
4353
|
+
epic_run_id: v.epic_run_id,
|
|
4354
|
+
ticket_key: v.ticket_key,
|
|
4355
|
+
outcome: v.outcome,
|
|
4356
|
+
accepted_route: v.accepted_route,
|
|
4357
|
+
answered_park_generation: v.answered_park_generation,
|
|
4358
|
+
row_version: v.row_version,
|
|
4359
|
+
ticket_status: (v.ticket_status ?? null),
|
|
4360
|
+
plan_ready: false,
|
|
4361
|
+
};
|
|
4362
|
+
}
|
|
4363
|
+
/**
|
|
4364
|
+
* POST `/jira/epic-runs/runs/{epic_run_id}/tickets/{ticket_key}/regenerate-plan`.
|
|
4365
|
+
*
|
|
4366
|
+
* Sends the pinned operation key and park generation only in the authenticated
|
|
4367
|
+
* body. Never throws for an HTTP or transport outcome: every response is
|
|
4368
|
+
* classified into a {@link RegeneratePlanPostOutcome}, so the caller — not this
|
|
4369
|
+
* function — decides whether an uncertain outcome is retried with the SAME
|
|
4370
|
+
* operation. It never falls back to another mutation.
|
|
4371
|
+
*/
|
|
4372
|
+
export async function regeneratePlanTicket(access, request, fetchImpl = globalThis.fetch, timeoutMs = CONDUCTOR_FETCH_TIMEOUT_MS) {
|
|
4373
|
+
requireNonEmptyString(request.epicRunId);
|
|
4374
|
+
requireNonEmptyString(request.ticketKey);
|
|
4375
|
+
requireNonEmptyString(request.operationKey);
|
|
4376
|
+
requireNonEmptyString(request.reason);
|
|
4377
|
+
requireNonNegativeSafeInteger(request.expectedRowVersion);
|
|
4378
|
+
requireNonNegativeSafeInteger(request.parkGeneration);
|
|
4379
|
+
const url = buildConductorJiraUrl(access.baseUrl, `${continuationChildPath(request.epicRunId, request.ticketKey)}/regenerate-plan`);
|
|
4380
|
+
const body = JSON.stringify({
|
|
4381
|
+
repo_name: access.repoName,
|
|
4382
|
+
route: request.route,
|
|
4383
|
+
reason: request.reason,
|
|
4384
|
+
expected_row_version: request.expectedRowVersion,
|
|
4385
|
+
park_generation: request.parkGeneration,
|
|
4386
|
+
operation_key: request.operationKey,
|
|
4387
|
+
});
|
|
4388
|
+
const controller = new AbortController();
|
|
4389
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
4390
|
+
try {
|
|
4391
|
+
let resp;
|
|
4392
|
+
try {
|
|
4393
|
+
resp = await fetchImpl(url, {
|
|
4394
|
+
method: "POST",
|
|
4395
|
+
headers: conductorPostHeaders(access),
|
|
4396
|
+
body,
|
|
4397
|
+
signal: controller.signal,
|
|
4398
|
+
});
|
|
4399
|
+
}
|
|
4400
|
+
catch {
|
|
4401
|
+
return { kind: "uncertain", reason: controller.signal.aborted ? "timeout" : "network" };
|
|
4402
|
+
}
|
|
4403
|
+
let parsed;
|
|
4404
|
+
let parsedOk = true;
|
|
4405
|
+
try {
|
|
4406
|
+
parsed = await resp.json();
|
|
4407
|
+
}
|
|
4408
|
+
catch {
|
|
4409
|
+
parsedOk = false;
|
|
4410
|
+
}
|
|
4411
|
+
if (resp.status >= 200 && resp.status < 300) {
|
|
4412
|
+
if (!parsedOk)
|
|
4413
|
+
return { kind: "uncertain", reason: "malformed", status: resp.status };
|
|
4414
|
+
try {
|
|
4415
|
+
return { kind: "result", result: parseRegeneratePlanResult(parsed) };
|
|
4416
|
+
}
|
|
4417
|
+
catch {
|
|
4418
|
+
return { kind: "uncertain", reason: "malformed", status: resp.status };
|
|
4419
|
+
}
|
|
4420
|
+
}
|
|
4421
|
+
const errorCode = parsedOk ? safeDetailErrorCode(parsed) : null;
|
|
4422
|
+
if (errorCode !== null && isRegeneratePlanRefusalCode(errorCode)) {
|
|
4423
|
+
return { kind: "refused", status: resp.status, errorCode };
|
|
4424
|
+
}
|
|
4425
|
+
if (errorCode === null && (resp.status === 404 || resp.status === 405)) {
|
|
4426
|
+
return { kind: "unsupported_server", status: resp.status };
|
|
4427
|
+
}
|
|
4428
|
+
if (resp.status >= 500) {
|
|
4429
|
+
return { kind: "uncertain", reason: "server", status: resp.status };
|
|
4430
|
+
}
|
|
4431
|
+
return { kind: "rejected", status: resp.status, errorCode };
|
|
4432
|
+
}
|
|
4433
|
+
finally {
|
|
4434
|
+
clearTimeout(timer);
|
|
4435
|
+
}
|
|
4436
|
+
}
|
|
3769
4437
|
// ---------------------------------------------------------------------------
|
|
3770
4438
|
// BAPI-1391 — gate profile, provider history, capability probe, qualification
|
|
3771
4439
|
// ---------------------------------------------------------------------------
|
|
@@ -3801,6 +4469,81 @@ const GATE_MAX_LOCAL_COMMANDS = 16;
|
|
|
3801
4469
|
const GATE_MAX_CUSTOMIZED = 64;
|
|
3802
4470
|
/** The provider-history walk makes bounded provider calls; give it longer. */
|
|
3803
4471
|
const GATE_CHECK_HISTORY_TIMEOUT_MS = 90_000;
|
|
4472
|
+
const GATE_MAX_WORKER_ENV = 32;
|
|
4473
|
+
const GATE_WORKER_ENV_VALUE_MAX_BYTES = 1024;
|
|
4474
|
+
const GATE_WORKER_ENV_NAME_RE = /^[A-Z_][A-Z0-9_]{0,63}$/;
|
|
4475
|
+
const GATE_MAX_ARGV_ENTRIES = 32;
|
|
4476
|
+
/** Whether `value` is an acceptable worker-variable value (limits mirror the server). */
|
|
4477
|
+
export function isValidWorkerEnvValue(value) {
|
|
4478
|
+
if (typeof value !== "string")
|
|
4479
|
+
return false;
|
|
4480
|
+
if (/[\u0000\r\n]/.test(value))
|
|
4481
|
+
return false;
|
|
4482
|
+
// A lone surrogate cannot be encoded as UTF-8; the server refuses it too.
|
|
4483
|
+
if (/[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/.test(value))
|
|
4484
|
+
return false;
|
|
4485
|
+
return Buffer.byteLength(value, "utf8") <= GATE_WORKER_ENV_VALUE_MAX_BYTES;
|
|
4486
|
+
}
|
|
4487
|
+
/** Whether `name` matches the worker-variable name syntax. */
|
|
4488
|
+
export function isValidWorkerEnvName(name) {
|
|
4489
|
+
return typeof name === "string" && GATE_WORKER_ENV_NAME_RE.test(name);
|
|
4490
|
+
}
|
|
4491
|
+
/**
|
|
4492
|
+
* Parse a returned `worker_env` list, fail-closed. Malformed data throws the
|
|
4493
|
+
* field-free shape error; it is never turned into an empty list and its
|
|
4494
|
+
* contents never reach the message.
|
|
4495
|
+
*/
|
|
4496
|
+
function parseWorkerEnvList(raw) {
|
|
4497
|
+
if (raw === undefined || raw === null)
|
|
4498
|
+
return undefined;
|
|
4499
|
+
if (!Array.isArray(raw) || raw.length > GATE_MAX_WORKER_ENV)
|
|
4500
|
+
throw readinessShapeError();
|
|
4501
|
+
const seen = new Set();
|
|
4502
|
+
const entries = [];
|
|
4503
|
+
for (const item of raw) {
|
|
4504
|
+
const o = requireObject(item);
|
|
4505
|
+
for (const key of Object.keys(o)) {
|
|
4506
|
+
if (key !== "name" && key !== "value" && key !== "committed_literal")
|
|
4507
|
+
throw readinessShapeError();
|
|
4508
|
+
}
|
|
4509
|
+
if (!isValidWorkerEnvName(o.name) || !isValidWorkerEnvValue(o.value) || seen.has(o.name)) {
|
|
4510
|
+
throw readinessShapeError();
|
|
4511
|
+
}
|
|
4512
|
+
seen.add(o.name);
|
|
4513
|
+
const entry = { name: o.name, value: o.value };
|
|
4514
|
+
if (o.committed_literal !== undefined) {
|
|
4515
|
+
if (typeof o.committed_literal !== "boolean")
|
|
4516
|
+
throw readinessShapeError();
|
|
4517
|
+
// False and omitted are the same state, so only true is carried.
|
|
4518
|
+
if (o.committed_literal)
|
|
4519
|
+
entry.committed_literal = true;
|
|
4520
|
+
}
|
|
4521
|
+
entries.push(entry);
|
|
4522
|
+
}
|
|
4523
|
+
return entries.length > 0 ? entries : undefined;
|
|
4524
|
+
}
|
|
4525
|
+
/** Parse a returned or proposed reproduction hint, fail-closed. */
|
|
4526
|
+
function parseReproductionHint(raw) {
|
|
4527
|
+
const o = requireObject(raw);
|
|
4528
|
+
for (const key of Object.keys(o)) {
|
|
4529
|
+
if (key !== "argv" && key !== "timeout_seconds")
|
|
4530
|
+
throw readinessShapeError();
|
|
4531
|
+
}
|
|
4532
|
+
const argv = o.argv;
|
|
4533
|
+
if (!Array.isArray(argv) ||
|
|
4534
|
+
argv.length === 0 ||
|
|
4535
|
+
argv.length > GATE_MAX_ARGV_ENTRIES ||
|
|
4536
|
+
argv.some((a) => typeof a !== "string" ||
|
|
4537
|
+
a.trim().length === 0 ||
|
|
4538
|
+
a.length > GATE_ARGV_ENTRY_MAX ||
|
|
4539
|
+
a.includes("\u0000"))) {
|
|
4540
|
+
throw readinessShapeError();
|
|
4541
|
+
}
|
|
4542
|
+
const timeout = requireInt(o, "timeout_seconds");
|
|
4543
|
+
if (timeout < 1 || timeout > 1800)
|
|
4544
|
+
throw readinessShapeError();
|
|
4545
|
+
return { argv: [...argv], timeout_seconds: timeout };
|
|
4546
|
+
}
|
|
3804
4547
|
function gateName(value, max) {
|
|
3805
4548
|
if (typeof value !== "string")
|
|
3806
4549
|
throw readinessShapeError();
|
|
@@ -3817,6 +4560,14 @@ function parseGateProfileBody(raw) {
|
|
|
3817
4560
|
if (!Array.isArray(checksRaw) || checksRaw.length > GATE_MAX_PROVIDER_CHECKS)
|
|
3818
4561
|
throw readinessShapeError();
|
|
3819
4562
|
const providerChecks = checksRaw.map((c) => gateName(requireObject(c).name, GATE_MEMBER_NAME_MAX));
|
|
4563
|
+
const reproductionHints = new Map();
|
|
4564
|
+
checksRaw.forEach((c, index) => {
|
|
4565
|
+
const reproduce = requireObject(c).reproduce;
|
|
4566
|
+
if (reproduce === undefined || reproduce === null)
|
|
4567
|
+
return;
|
|
4568
|
+
reproductionHints.set(providerChecks[index], parseReproductionHint(reproduce));
|
|
4569
|
+
});
|
|
4570
|
+
const workerEnv = parseWorkerEnvList(o.worker_env);
|
|
3820
4571
|
const commandsRaw = o.local_commands;
|
|
3821
4572
|
if (!Array.isArray(commandsRaw) || commandsRaw.length > GATE_MAX_LOCAL_COMMANDS)
|
|
3822
4573
|
throw readinessShapeError();
|
|
@@ -3873,6 +4624,8 @@ function parseGateProfileBody(raw) {
|
|
|
3873
4624
|
return {
|
|
3874
4625
|
kind,
|
|
3875
4626
|
provider_checks: providerChecks,
|
|
4627
|
+
...(workerEnv ? { worker_env: workerEnv } : {}),
|
|
4628
|
+
...(reproductionHints.size > 0 ? { reproduction_hints: reproductionHints } : {}),
|
|
3876
4629
|
local_commands: localCommands,
|
|
3877
4630
|
migration_guard: guard,
|
|
3878
4631
|
customized_commands: customized.map((n) => gateName(n, GATE_MEMBER_NAME_MAX)),
|
|
@@ -3881,6 +4634,18 @@ function parseGateProfileBody(raw) {
|
|
|
3881
4634
|
revision,
|
|
3882
4635
|
};
|
|
3883
4636
|
}
|
|
4637
|
+
/** The qualification's optional worker-variable digest, fail-closed. */
|
|
4638
|
+
function parseQualificationWorkerEnvDigest(raw) {
|
|
4639
|
+
if (raw === undefined || raw === null)
|
|
4640
|
+
return undefined;
|
|
4641
|
+
const q = requireObject(raw);
|
|
4642
|
+
const digest = q.worker_env_digest;
|
|
4643
|
+
if (digest === undefined || digest === null)
|
|
4644
|
+
return undefined;
|
|
4645
|
+
if (typeof digest !== "string" || !GATE_DIGEST_RE.test(digest))
|
|
4646
|
+
throw readinessShapeError();
|
|
4647
|
+
return digest;
|
|
4648
|
+
}
|
|
3884
4649
|
/** Validate a gate-profile body, fail-closed. */
|
|
3885
4650
|
export function parseConductorGateProfileResponse(body, expectedRepoName) {
|
|
3886
4651
|
const o = requireObject(body);
|
|
@@ -3904,6 +4669,7 @@ export function parseConductorGateProfileResponse(body, expectedRepoName) {
|
|
|
3904
4669
|
if (outcome !== undefined && outcome !== null && (typeof outcome !== "string" || !GATE_PROFILE_WRITE_OUTCOMES.has(outcome))) {
|
|
3905
4670
|
throw readinessShapeError();
|
|
3906
4671
|
}
|
|
4672
|
+
const qualificationDigest = parseQualificationWorkerEnvDigest(o.qualification);
|
|
3907
4673
|
return {
|
|
3908
4674
|
repo_name: expectedRepoName,
|
|
3909
4675
|
source,
|
|
@@ -3913,6 +4679,7 @@ export function parseConductorGateProfileResponse(body, expectedRepoName) {
|
|
|
3913
4679
|
profile,
|
|
3914
4680
|
qualification_state: requireEnum(o, "qualification_state", GATE_QUALIFICATION_STATES),
|
|
3915
4681
|
outcome: (outcome ?? null),
|
|
4682
|
+
...(qualificationDigest ? { qualification_worker_env_digest: qualificationDigest } : {}),
|
|
3916
4683
|
};
|
|
3917
4684
|
}
|
|
3918
4685
|
function gateProfileUrl(access, suffix = "") {
|
|
@@ -3923,9 +4690,68 @@ export async function fetchConductorGateProfile(access, fetchImpl) {
|
|
|
3923
4690
|
const body = await fetchConductorJsonWithTimeout(gateProfileUrl(access), conductorGetHeaders(access), CONDUCTOR_FETCH_TIMEOUT_MS, fetchImpl);
|
|
3924
4691
|
return parseConductorGateProfileResponse(body, access.repoName);
|
|
3925
4692
|
}
|
|
3926
|
-
|
|
4693
|
+
/**
|
|
4694
|
+
* BAPI-1520 — which extension fields the older server rejected, and only when
|
|
4695
|
+
* the request actually carried them. `worker_env` counts only at exactly
|
|
4696
|
+
* `["body","worker_env"]`; `reproduce` only at exactly
|
|
4697
|
+
* `["body","provider_checks",<index>,"reproduce"]`. Any other 422 returns
|
|
4698
|
+
* `null`, so an unrelated 422 is never read as an older-server case.
|
|
4699
|
+
*/
|
|
4700
|
+
export function classifyGateProfileExtensionRejection(err, request) {
|
|
4701
|
+
if (!(err instanceof ConductorBridgeApiError) || err.status !== 422)
|
|
4702
|
+
return null;
|
|
4703
|
+
const issues = err.gateProfileEvidence?.issues;
|
|
4704
|
+
if (!issues || issues.length === 0)
|
|
4705
|
+
return null;
|
|
4706
|
+
const confirm = request.action === "confirm" ? request : null;
|
|
4707
|
+
let workerEnv = false;
|
|
4708
|
+
let reproduce = false;
|
|
4709
|
+
for (const issue of issues) {
|
|
4710
|
+
if (issue.type !== "extra_forbidden")
|
|
4711
|
+
return null;
|
|
4712
|
+
const loc = issue.loc;
|
|
4713
|
+
if (loc.length === 2 && loc[0] === "body" && loc[1] === "worker_env") {
|
|
4714
|
+
if (!confirm || confirm.worker_env === undefined)
|
|
4715
|
+
return null;
|
|
4716
|
+
workerEnv = true;
|
|
4717
|
+
}
|
|
4718
|
+
else if (loc.length === 4 &&
|
|
4719
|
+
loc[0] === "body" &&
|
|
4720
|
+
loc[1] === "provider_checks" &&
|
|
4721
|
+
typeof loc[2] === "number" &&
|
|
4722
|
+
loc[3] === "reproduce") {
|
|
4723
|
+
const check = confirm?.provider_checks?.[loc[2]];
|
|
4724
|
+
if (!check || check.reproduce === undefined)
|
|
4725
|
+
return null;
|
|
4726
|
+
reproduce = true;
|
|
4727
|
+
}
|
|
4728
|
+
else {
|
|
4729
|
+
return null;
|
|
4730
|
+
}
|
|
4731
|
+
}
|
|
4732
|
+
return { worker_env: workerEnv, reproduce };
|
|
4733
|
+
}
|
|
4734
|
+
/** The safe refusal context of a failed write, or `undefined` when there is none. */
|
|
4735
|
+
function gateProfileRefusalDetail(err) {
|
|
4736
|
+
if (!(err instanceof ConductorBridgeApiError))
|
|
4737
|
+
return undefined;
|
|
4738
|
+
const evidence = err.gateProfileEvidence;
|
|
4739
|
+
if (!evidence)
|
|
4740
|
+
return undefined;
|
|
4741
|
+
const detail = {};
|
|
4742
|
+
if (evidence.field)
|
|
4743
|
+
detail.field = evidence.field;
|
|
4744
|
+
if (evidence.reason)
|
|
4745
|
+
detail.reason = evidence.reason;
|
|
4746
|
+
if (evidence.name)
|
|
4747
|
+
detail.name = evidence.name;
|
|
4748
|
+
return Object.keys(detail).length > 0 ? detail : undefined;
|
|
4749
|
+
}
|
|
4750
|
+
export function classifyGateProfileWriteFailure(err, request) {
|
|
3927
4751
|
if (!(err instanceof ConductorBridgeApiError))
|
|
3928
4752
|
return "network";
|
|
4753
|
+
if (request && classifyGateProfileExtensionRejection(err, request))
|
|
4754
|
+
return "extension-unsupported";
|
|
3929
4755
|
if (err.errorCode === "STALE_REVISION")
|
|
3930
4756
|
return "stale-revision";
|
|
3931
4757
|
if (err.errorCode === "UNKNOWN_STORED_STATE")
|
|
@@ -3959,7 +4785,12 @@ export async function putConductorGateProfile(access, request, fetchImpl) {
|
|
|
3959
4785
|
return { ok: true, profile: parseConductorGateProfileResponse(body, access.repoName) };
|
|
3960
4786
|
}
|
|
3961
4787
|
catch (err) {
|
|
3962
|
-
|
|
4788
|
+
const detail = gateProfileRefusalDetail(err);
|
|
4789
|
+
return {
|
|
4790
|
+
ok: false,
|
|
4791
|
+
refusal: classifyGateProfileWriteFailure(err, request),
|
|
4792
|
+
...(detail ? { detail } : {}),
|
|
4793
|
+
};
|
|
3963
4794
|
}
|
|
3964
4795
|
}
|
|
3965
4796
|
const EPIC_BRANCH_CI_AUDITED_FIELD_LIMIT = 8;
|
|
@@ -4162,3 +4993,9 @@ export async function fetchConductorGateQualificationJob(access, jobId, fetchImp
|
|
|
4162
4993
|
const body = await fetchConductorJsonWithTimeout(gateProfileUrl(access, `qualification/${encodeURIComponent(String(jobId))}/`), conductorGetHeaders(access), CONDUCTOR_FETCH_TIMEOUT_MS, fetchImpl);
|
|
4163
4994
|
return parseConductorGateQualificationJob(body, access.repoName, jobId);
|
|
4164
4995
|
}
|
|
4996
|
+
/** Authenticated read-only preview of the same effective policy sent at creation. */
|
|
4997
|
+
export async function previewLaunchReadiness(access, policyJson, fetchImpl = globalThis.fetch) {
|
|
4998
|
+
const url = buildConductorJiraUrl(access.baseUrl, `${EPIC_RUNS_API_PREFIX}/launch-readiness`);
|
|
4999
|
+
const body = await fetchConductorJsonPostWithTimeout(url, conductorPostHeaders(access), JSON.stringify({ repo_name: access.repoName, policy_json: policyJson }), CONDUCTOR_FETCH_TIMEOUT_MS, fetchImpl);
|
|
5000
|
+
return parseConductorReadinessResponse(body);
|
|
5001
|
+
}
|