@bridge_gpt/mcp-server 0.2.74 → 0.2.75
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 +14 -7
- package/build/agent-launchers/prompt.js +9 -21
- package/build/agents.generated.js +2 -2
- package/build/authored-plan.js +542 -0
- package/build/bridge-permissions.js +8 -0
- package/build/commands.generated.js +5 -5
- package/build/conductor/bridge-api-client.js +666 -46
- package/build/conductor/epic-implementer-cli.js +337 -93
- package/build/conductor/gate-discovery.js +209 -9
- package/build/conductor/gate-settings-review.js +7 -11
- package/build/conductor/launch-plan.js +58 -12
- package/build/conductor/open-decision-phrases.js +50 -0
- package/build/conductor/prerequisite-inputs.js +181 -14
- package/build/connect-github-api.js +18 -0
- package/build/connect-github.js +35 -18
- package/build/docs.generated.js +2 -2
- package/build/drive-epic.js +387 -12
- package/build/epic-ci-workflow.js +3 -2
- package/build/epic-implementer-bin.js +152 -38
- package/build/epic-implementer-bundle-cli.js +61 -0
- package/build/epic-implementer-claude-hook-bin.js +1 -1
- package/build/epic-implementer-env.js +3 -4
- package/build/epic-integration-pr.js +5 -2
- package/build/executor/completion-contract.js +24 -1
- package/build/executor/gate-qualification-job.js +193 -23
- package/build/executor/gate-qualification-tests-ran.js +232 -0
- package/build/executor/job-runner.js +9 -722
- package/build/executor/job-type-wrappers.js +734 -0
- package/build/executor/preflight.js +6 -2
- package/build/executor/process-containment.js +8 -1
- package/build/executor/required-verification.js +28 -2
- package/build/executor/runner.js +4 -1
- package/build/executor/types.js +9 -0
- package/build/executor/worker-database.js +6 -1
- package/build/executor/worker-guard-hook.js +24 -2
- package/build/generated/ticket-status.js +20 -0
- package/build/index.js +391 -257
- package/build/install-bridge-conductor-answers.js +28 -1
- package/build/install-bridge-conductor-apply.js +11 -3
- package/build/install-bridge-conductor-assessment.js +114 -12
- package/build/install-bridge-conductor-compact.js +2 -0
- package/build/install-bridge-conductor-gate.js +257 -80
- package/build/install-bridge-conductor-setup.js +4 -4
- package/build/install-bridge-conductor-trial-report.js +170 -0
- package/build/install-bridge-conductor.js +303 -31
- package/build/pipelines.generated.js +7 -7
- package/build/plan-generation.js +17 -0
- package/build/printed-remedy-commands.js +54 -0
- package/build/readme.generated.js +1 -1
- package/build/repository-toolchains.js +11 -5
- package/build/scripts/saved-commands-config-field-driver.js +65 -0
- package/build/setup-epic.js +10 -1
- package/build/test-support/executor-source-files.js +1 -1
- package/build/v2-readiness-requirements.js +5 -1
- package/build/version.generated.js +3 -3
- package/build/worker-guard-hook-bin.js +2 -2
- package/docs/EPIC-IMPLEMENTER.md +4 -4
- package/docs/install/github-app.md +79 -92
- package/package.json +1 -1
- package/build/conductor/epic-reconcile.js +0 -603
- package/build/conductor/epic-runtime.js +0 -2020
- package/build/conductor/epic-state.js +0 -774
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { parseAssessmentNegotiation } from './readiness-assessment.js';
|
|
2
2
|
import { READINESS_PREREQUISITE_BY_ID } from "../readiness-prerequisites.generated.js";
|
|
3
|
+
import { EPIC_TICKET_STATUS_VALUES } from "../generated/ticket-status.js";
|
|
3
4
|
import { PREVIOUS_SERVER_READINESS_FIXES, READINESS_PREREQUISITE_FIXES } from "../printed-remedy-commands.js";
|
|
4
5
|
/**
|
|
5
6
|
* TypeScript-side Bridge API access layer for the conductor producer (BAPI-395).
|
|
@@ -25,6 +26,7 @@ import { CI_DATABASE_DEFAULT, isCiDatabase, parseDependencyInstallStrict, parseM
|
|
|
25
26
|
import { safeEpicLaunchTargetUrl } from "../epic-launch-diagnostic.js";
|
|
26
27
|
import { validateHttpBaseUrl } from "../base-url.js";
|
|
27
28
|
import { RERUN_CI_CHECK_STATUSES, RERUN_CI_NOT_RUNNABLE_REASONS, RERUN_CI_OUTCOMES, isCiResumeRefusalCode, } from "./repair-contract.js";
|
|
29
|
+
import { hashPlan } from "./plan.js";
|
|
28
30
|
/** Default Bridge API base URL when `BAPI_BASE_URL` is unset. */
|
|
29
31
|
export const CONDUCTOR_DEFAULT_BASE_URL = "https://bridgegpt-api.com";
|
|
30
32
|
/** Default per-request timeout for conductor Bridge API calls. */
|
|
@@ -1029,8 +1031,8 @@ export async function fetchConductorJsonPostWithTimeout(url, headers, body, time
|
|
|
1029
1031
|
}
|
|
1030
1032
|
/**
|
|
1031
1033
|
* PATCH JSON with an `AbortController` timeout. Thin wrapper over
|
|
1032
|
-
* {@link fetchConductorJsonWithMethodAndTimeout}. Used by the
|
|
1033
|
-
*
|
|
1034
|
+
* {@link fetchConductorJsonWithMethodAndTimeout}. Used by the remaining live
|
|
1035
|
+
* PATCH consumers (run policy and node ticket-spec updates).
|
|
1034
1036
|
*/
|
|
1035
1037
|
export async function fetchConductorJsonPatchWithTimeout(url, headers, body, timeoutMs, fetchImpl) {
|
|
1036
1038
|
return fetchConductorJsonWithMethodAndTimeout("PATCH", url, headers, body, timeoutMs, fetchImpl);
|
|
@@ -1171,14 +1173,8 @@ function requireNoSlashPathSegment(value) {
|
|
|
1171
1173
|
throw new ConductorBridgeApiError("invalid-input");
|
|
1172
1174
|
}
|
|
1173
1175
|
}
|
|
1174
|
-
const EPIC_TICKET_STATUS_VALUES = [
|
|
1175
|
-
"planned", "ready", "dispatched", "running", "blocked", "abandoned", "done", "ready_for_review",
|
|
1176
|
-
"reviewing",
|
|
1177
|
-
// BAPI-527: asynchronous post-merge parse state (see EpicTicketStatusValue).
|
|
1178
|
-
"parse_pending",
|
|
1179
|
-
];
|
|
1180
1176
|
function requireEpicTicketStatusValue(value) {
|
|
1181
|
-
if (typeof value !== "string" || !EPIC_TICKET_STATUS_VALUES.
|
|
1177
|
+
if (typeof value !== "string" || !EPIC_TICKET_STATUS_VALUES.some((status) => status === value)) {
|
|
1182
1178
|
throw new ConductorBridgeApiError("invalid-input");
|
|
1183
1179
|
}
|
|
1184
1180
|
}
|
|
@@ -1738,8 +1734,12 @@ export async function stopEpicRun(access, request, fetchImpl = globalThis.fetch)
|
|
|
1738
1734
|
return parsed;
|
|
1739
1735
|
}
|
|
1740
1736
|
// ---------------------------------------------------------------------------
|
|
1741
|
-
//
|
|
1737
|
+
// Shared unpark / adopt recovery-result parser
|
|
1742
1738
|
// ---------------------------------------------------------------------------
|
|
1739
|
+
/**
|
|
1740
|
+
* Parse the shared unpark / adopt-current-head-and-unpark recovery result,
|
|
1741
|
+
* including the structured `{ok: false, kind: "cas-conflict"}` envelope.
|
|
1742
|
+
*/
|
|
1743
1743
|
function parseAdvanceEpicTicketStatusResult(parsed) {
|
|
1744
1744
|
if (!parsed || typeof parsed !== "object") {
|
|
1745
1745
|
throw new ConductorBridgeApiError("server");
|
|
@@ -1768,48 +1768,14 @@ function parseAdvanceEpicTicketStatusResult(parsed) {
|
|
|
1768
1768
|
}
|
|
1769
1769
|
throw new ConductorBridgeApiError("server");
|
|
1770
1770
|
}
|
|
1771
|
-
/**
|
|
1772
|
-
* PATCH the per-ticket CAS status endpoint
|
|
1773
|
-
* (`PATCH /runs/{epic_run_id}/tickets/{ticket_key}`). Surfaces structured CAS
|
|
1774
|
-
* conflicts as a distinct non-throwing outcome where the backend returns one;
|
|
1775
|
-
* the current backend instead raises a 400 CONFLICT on a stale row_version
|
|
1776
|
-
* (BAPI-1016 — the status stays 400; only the body error_code changed from the
|
|
1777
|
-
* former VALIDATION), which surfaces as a thrown `ConductorBridgeApiError("http", 400)`.
|
|
1778
|
-
* Transport/auth/server failures still throw a sanitized {@link ConductorBridgeApiError}.
|
|
1779
|
-
*/
|
|
1780
|
-
export async function advanceEpicTicketStatus(access, request, fetchImpl = globalThis.fetch) {
|
|
1781
|
-
requireNonEmptyString(request.epicKey);
|
|
1782
|
-
requireNonEmptyString(request.ticketKey);
|
|
1783
|
-
requireNonNegativeSafeInteger(request.expectedRowVersion);
|
|
1784
|
-
requireNonNegativeSafeInteger(request.planVersion);
|
|
1785
|
-
requireEpicTicketStatusValue(request.nextStatus);
|
|
1786
|
-
if (request.dispatchRunId !== undefined) {
|
|
1787
|
-
requireNonEmptyString(request.dispatchRunId);
|
|
1788
|
-
}
|
|
1789
|
-
// The backend declares this endpoint as PATCH /runs/{epic_run_id}/tickets/{ticket_key}
|
|
1790
|
-
// (api/routes/epic_runs.py:489). The body matches PatchEpicTicketStatusRequest:
|
|
1791
|
-
// repo_name + expected_row_version are required; status/plan_version/dispatch_run_id
|
|
1792
|
-
// are optional and accepted (the model does not forbid extras).
|
|
1793
|
-
const CAS_ENDPOINT_PATH = `${epicRunApiPath(request.epicKey)}/tickets/${encodeURIComponent(request.ticketKey)}`;
|
|
1794
|
-
const url = buildConductorJiraUrl(access.baseUrl, CAS_ENDPOINT_PATH);
|
|
1795
|
-
const body = JSON.stringify({
|
|
1796
|
-
repo_name: access.repoName,
|
|
1797
|
-
status: request.nextStatus,
|
|
1798
|
-
plan_version: request.planVersion,
|
|
1799
|
-
expected_row_version: request.expectedRowVersion,
|
|
1800
|
-
...(request.dispatchRunId ? { dispatch_run_id: request.dispatchRunId } : {}),
|
|
1801
|
-
});
|
|
1802
|
-
const parsed = await fetchConductorJsonPatchWithTimeout(url, conductorPostHeaders(access), body, CONDUCTOR_FETCH_TIMEOUT_MS, fetchImpl);
|
|
1803
|
-
return parseAdvanceEpicTicketStatusResult(parsed);
|
|
1804
|
-
}
|
|
1805
1771
|
// ---------------------------------------------------------------------------
|
|
1806
1772
|
// Operator recovery: ticket unpark + adopt-current-head-and-unpark (BAPI-872)
|
|
1807
1773
|
// ---------------------------------------------------------------------------
|
|
1808
1774
|
/**
|
|
1809
1775
|
* Catch a stale-CAS 400 thrown by the POST transport and translate it into the
|
|
1810
1776
|
* SAME `{ok: false, kind: "cas-conflict", current_row_version}` result
|
|
1811
|
-
* {@link parseAdvanceEpicTicketStatusResult}
|
|
1812
|
-
*
|
|
1777
|
+
* {@link parseAdvanceEpicTicketStatusResult} produces for a stale-CAS
|
|
1778
|
+
* conflict — the previously dormant conflict branch that now becomes production
|
|
1813
1779
|
* behavior for both unpark lanes. Only a genuine stale-CAS shape (400 status with
|
|
1814
1780
|
* a validated `currentRowVersion`) is translated; every other failure re-throws
|
|
1815
1781
|
* unchanged, preserving `ConductorBridgeApiError` for terminal, validation,
|
|
@@ -3314,6 +3280,252 @@ export async function getEpicPlan(access, epicKey, planVersion, fetchImpl = glob
|
|
|
3314
3280
|
const parsed = await fetchConductorJsonWithTimeout(url, conductorGetHeaders(access), CONDUCTOR_FETCH_TIMEOUT_MS, fetchImpl);
|
|
3315
3281
|
return parsed;
|
|
3316
3282
|
}
|
|
3283
|
+
/** Thrown by {@link saveAuthoredEpicPlan}. The message is fixed and value-free. */
|
|
3284
|
+
export class AuthoredEpicPlanSaveError extends Error {
|
|
3285
|
+
reason;
|
|
3286
|
+
constructor(reason) {
|
|
3287
|
+
super(`authored plan save failed (${reason})`);
|
|
3288
|
+
this.name = "AuthoredEpicPlanSaveError";
|
|
3289
|
+
this.reason = reason;
|
|
3290
|
+
}
|
|
3291
|
+
}
|
|
3292
|
+
function authoredPlansApiPath(epicKey, suffix = "") {
|
|
3293
|
+
return `${EPIC_RUNS_API_PREFIX}/epics/${encodeURIComponent(epicKey)}/authored-plans${suffix}`;
|
|
3294
|
+
}
|
|
3295
|
+
function isPlainObject(value) {
|
|
3296
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3297
|
+
}
|
|
3298
|
+
/**
|
|
3299
|
+
* Validate a snapshot body and recompute its hash. Returns `null` for any shape
|
|
3300
|
+
* problem and the string `"hash_mismatch"` when the blob does not hash to the
|
|
3301
|
+
* stored `plan_hash`. The returned blob is the server's own object, unchanged.
|
|
3302
|
+
*/
|
|
3303
|
+
export function parseAuthoredEpicPlanSnapshot(body) {
|
|
3304
|
+
if (!isPlainObject(body))
|
|
3305
|
+
return null;
|
|
3306
|
+
const { repo_name, epic_key, authored_version, plan_blob, plan_hash, eligibility_advisory, gap_check_record, saved_by, saved_at, } = body;
|
|
3307
|
+
if (typeof repo_name !== "string" || repo_name.length === 0)
|
|
3308
|
+
return null;
|
|
3309
|
+
if (typeof epic_key !== "string" || epic_key.length === 0)
|
|
3310
|
+
return null;
|
|
3311
|
+
if (typeof authored_version !== "number" ||
|
|
3312
|
+
!Number.isSafeInteger(authored_version) ||
|
|
3313
|
+
authored_version < 1) {
|
|
3314
|
+
return null;
|
|
3315
|
+
}
|
|
3316
|
+
if (typeof plan_hash !== "string" || plan_hash.length === 0)
|
|
3317
|
+
return null;
|
|
3318
|
+
if (typeof saved_by !== "string" || typeof saved_at !== "string")
|
|
3319
|
+
return null;
|
|
3320
|
+
if (eligibility_advisory !== null && !isPlainObject(eligibility_advisory))
|
|
3321
|
+
return null;
|
|
3322
|
+
if (gap_check_record !== null && !isPlainObject(gap_check_record))
|
|
3323
|
+
return null;
|
|
3324
|
+
if (!isPlainObject(plan_blob))
|
|
3325
|
+
return null;
|
|
3326
|
+
const version = plan_blob.plan_version;
|
|
3327
|
+
if (typeof version !== "number" || !Number.isInteger(version) || version < 1)
|
|
3328
|
+
return null;
|
|
3329
|
+
if (!Array.isArray(plan_blob.nodes) || plan_blob.nodes.length === 0)
|
|
3330
|
+
return null;
|
|
3331
|
+
if (!Array.isArray(plan_blob.edges))
|
|
3332
|
+
return null;
|
|
3333
|
+
for (const node of plan_blob.nodes) {
|
|
3334
|
+
if (!isPlainObject(node) || typeof node.ticket_key !== "string" || node.ticket_key.trim() === "") {
|
|
3335
|
+
return null;
|
|
3336
|
+
}
|
|
3337
|
+
}
|
|
3338
|
+
let recomputed;
|
|
3339
|
+
try {
|
|
3340
|
+
recomputed = hashPlan(plan_blob);
|
|
3341
|
+
}
|
|
3342
|
+
catch {
|
|
3343
|
+
return null;
|
|
3344
|
+
}
|
|
3345
|
+
if (recomputed !== plan_hash)
|
|
3346
|
+
return "hash_mismatch";
|
|
3347
|
+
return {
|
|
3348
|
+
repo_name,
|
|
3349
|
+
epic_key,
|
|
3350
|
+
authored_version,
|
|
3351
|
+
plan_blob: plan_blob,
|
|
3352
|
+
plan_hash,
|
|
3353
|
+
eligibility_advisory: (eligibility_advisory ?? null),
|
|
3354
|
+
gap_check_record: (gap_check_record ?? null),
|
|
3355
|
+
saved_by,
|
|
3356
|
+
saved_at,
|
|
3357
|
+
};
|
|
3358
|
+
}
|
|
3359
|
+
/** True only for FastAPI's default "route does not exist" body, exactly. */
|
|
3360
|
+
function isDefaultNotFoundBody(body) {
|
|
3361
|
+
if (!isPlainObject(body))
|
|
3362
|
+
return false;
|
|
3363
|
+
const keys = Object.keys(body);
|
|
3364
|
+
return keys.length === 1 && keys[0] === "detail" && body.detail === "Not Found";
|
|
3365
|
+
}
|
|
3366
|
+
async function readJsonResponse(run, timeoutMs) {
|
|
3367
|
+
const controller = new AbortController();
|
|
3368
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
3369
|
+
try {
|
|
3370
|
+
let resp;
|
|
3371
|
+
try {
|
|
3372
|
+
resp = await run(controller.signal);
|
|
3373
|
+
}
|
|
3374
|
+
catch {
|
|
3375
|
+
return controller.signal.aborted ? { kind: "timeout" } : { kind: "network" };
|
|
3376
|
+
}
|
|
3377
|
+
try {
|
|
3378
|
+
const body = await resp.json();
|
|
3379
|
+
return { kind: "response", status: resp.status, ok: resp.ok, body, bodyReadable: true };
|
|
3380
|
+
}
|
|
3381
|
+
catch {
|
|
3382
|
+
if (controller.signal.aborted)
|
|
3383
|
+
return { kind: "timeout" };
|
|
3384
|
+
return { kind: "response", status: resp.status, ok: resp.ok, body: undefined, bodyReadable: false };
|
|
3385
|
+
}
|
|
3386
|
+
}
|
|
3387
|
+
finally {
|
|
3388
|
+
clearTimeout(timer);
|
|
3389
|
+
}
|
|
3390
|
+
}
|
|
3391
|
+
function unknownReasonForStatus(status) {
|
|
3392
|
+
if (status === 401 || status === 403)
|
|
3393
|
+
return "unauthorized";
|
|
3394
|
+
if (status >= 500)
|
|
3395
|
+
return "server_error";
|
|
3396
|
+
return "http_error";
|
|
3397
|
+
}
|
|
3398
|
+
/**
|
|
3399
|
+
* Read the latest authored plan for an epic (BAPI-1706).
|
|
3400
|
+
*
|
|
3401
|
+
* - `found` / `not_stored` come only from a well-formed typed 200; a found
|
|
3402
|
+
* snapshot's blob must hash to its stored `plan_hash`.
|
|
3403
|
+
* - `server_too_old` comes only from a 404 whose body is exactly
|
|
3404
|
+
* `{"detail": "Not Found"}` — the route does not exist on this server.
|
|
3405
|
+
* - Everything else (401/403, other 404s, 405, 5xx, malformed 200s, a hash
|
|
3406
|
+
* mismatch, a timeout, a dropped connection) is `unknown`, never absence.
|
|
3407
|
+
*
|
|
3408
|
+
* Never throws.
|
|
3409
|
+
*/
|
|
3410
|
+
export async function getAuthoredEpicPlan(access, epicKey, fetchImpl = globalThis.fetch, timeoutMs = CONDUCTOR_FETCH_TIMEOUT_MS) {
|
|
3411
|
+
let url;
|
|
3412
|
+
try {
|
|
3413
|
+
requireNonEmptyString(epicKey);
|
|
3414
|
+
url = buildConductorJiraUrl(access.baseUrl, authoredPlansApiPath(epicKey, "/latest"), {
|
|
3415
|
+
repo_name: access.repoName,
|
|
3416
|
+
});
|
|
3417
|
+
}
|
|
3418
|
+
catch {
|
|
3419
|
+
return { kind: "unknown", reason: "malformed_response" };
|
|
3420
|
+
}
|
|
3421
|
+
const raw = await readJsonResponse((signal) => fetchImpl(url, { headers: conductorGetHeaders(access), signal }), timeoutMs);
|
|
3422
|
+
if (raw.kind !== "response")
|
|
3423
|
+
return { kind: "unknown", reason: raw.kind };
|
|
3424
|
+
if (!raw.ok) {
|
|
3425
|
+
if (raw.status === 404 && raw.bodyReadable && isDefaultNotFoundBody(raw.body)) {
|
|
3426
|
+
return { kind: "server_too_old" };
|
|
3427
|
+
}
|
|
3428
|
+
return { kind: "unknown", reason: unknownReasonForStatus(raw.status) };
|
|
3429
|
+
}
|
|
3430
|
+
if (!raw.bodyReadable || !isPlainObject(raw.body)) {
|
|
3431
|
+
return { kind: "unknown", reason: "malformed_response" };
|
|
3432
|
+
}
|
|
3433
|
+
if (raw.body.status === "not_stored" && Object.keys(raw.body).length === 1) {
|
|
3434
|
+
return { kind: "not_stored" };
|
|
3435
|
+
}
|
|
3436
|
+
if (raw.body.status !== "found")
|
|
3437
|
+
return { kind: "unknown", reason: "malformed_response" };
|
|
3438
|
+
const snapshot = parseAuthoredEpicPlanSnapshot(raw.body);
|
|
3439
|
+
if (snapshot === "hash_mismatch")
|
|
3440
|
+
return { kind: "unknown", reason: "hash_mismatch" };
|
|
3441
|
+
if (snapshot === null || snapshot.epic_key !== epicKey || snapshot.repo_name !== access.repoName) {
|
|
3442
|
+
return { kind: "unknown", reason: "malformed_response" };
|
|
3443
|
+
}
|
|
3444
|
+
return { kind: "found", snapshot };
|
|
3445
|
+
}
|
|
3446
|
+
/**
|
|
3447
|
+
* Read one numbered authored-plan version. A missing version is `not_found`
|
|
3448
|
+
* (an `unknown` reason), never `server_too_old`: only the latest route is used to
|
|
3449
|
+
* decide compatibility. Never throws.
|
|
3450
|
+
*/
|
|
3451
|
+
export async function getAuthoredEpicPlanVersion(access, epicKey, authoredVersion, fetchImpl = globalThis.fetch, timeoutMs = CONDUCTOR_FETCH_TIMEOUT_MS) {
|
|
3452
|
+
let url;
|
|
3453
|
+
try {
|
|
3454
|
+
requireNonEmptyString(epicKey);
|
|
3455
|
+
requirePositiveSafeInteger(authoredVersion);
|
|
3456
|
+
url = buildConductorJiraUrl(access.baseUrl, authoredPlansApiPath(epicKey, `/${authoredVersion}`), {
|
|
3457
|
+
repo_name: access.repoName,
|
|
3458
|
+
});
|
|
3459
|
+
}
|
|
3460
|
+
catch {
|
|
3461
|
+
return { kind: "unknown", reason: "malformed_response" };
|
|
3462
|
+
}
|
|
3463
|
+
const raw = await readJsonResponse((signal) => fetchImpl(url, { headers: conductorGetHeaders(access), signal }), timeoutMs);
|
|
3464
|
+
if (raw.kind !== "response")
|
|
3465
|
+
return { kind: "unknown", reason: raw.kind };
|
|
3466
|
+
if (!raw.ok) {
|
|
3467
|
+
return { kind: "unknown", reason: raw.status === 404 ? "not_found" : unknownReasonForStatus(raw.status) };
|
|
3468
|
+
}
|
|
3469
|
+
const snapshot = parseAuthoredEpicPlanSnapshot(raw.body);
|
|
3470
|
+
if (snapshot === "hash_mismatch")
|
|
3471
|
+
return { kind: "unknown", reason: "hash_mismatch" };
|
|
3472
|
+
if (snapshot === null || snapshot.authored_version !== authoredVersion) {
|
|
3473
|
+
return { kind: "unknown", reason: "malformed_response" };
|
|
3474
|
+
}
|
|
3475
|
+
return { kind: "found", snapshot };
|
|
3476
|
+
}
|
|
3477
|
+
/**
|
|
3478
|
+
* Save an authored plan (BAPI-1706). Returns the server's complete selected
|
|
3479
|
+
* snapshot plus `created`; with `ifAbsent` a concurrent writer's existing
|
|
3480
|
+
* snapshot comes back with `created: false`. The response is verified the same
|
|
3481
|
+
* way a read is, including the hash recheck. Throws only
|
|
3482
|
+
* {@link AuthoredEpicPlanSaveError}, whose message is fixed and value-free.
|
|
3483
|
+
*/
|
|
3484
|
+
export async function saveAuthoredEpicPlan(access, request, fetchImpl = globalThis.fetch, timeoutMs = CONDUCTOR_FETCH_TIMEOUT_MS) {
|
|
3485
|
+
let url;
|
|
3486
|
+
let body;
|
|
3487
|
+
try {
|
|
3488
|
+
requireNonEmptyString(request.epicKey);
|
|
3489
|
+
requireNonEmptyString(request.planHash);
|
|
3490
|
+
url = buildConductorJiraUrl(access.baseUrl, authoredPlansApiPath(request.epicKey));
|
|
3491
|
+
body = JSON.stringify({
|
|
3492
|
+
repo_name: access.repoName,
|
|
3493
|
+
plan_blob: request.planBlob,
|
|
3494
|
+
plan_hash: request.planHash,
|
|
3495
|
+
eligibility_advisory: request.eligibilityAdvisory,
|
|
3496
|
+
gap_check_record: request.gapCheckRecord,
|
|
3497
|
+
if_absent: request.ifAbsent === true,
|
|
3498
|
+
});
|
|
3499
|
+
}
|
|
3500
|
+
catch {
|
|
3501
|
+
throw new AuthoredEpicPlanSaveError("validation");
|
|
3502
|
+
}
|
|
3503
|
+
const raw = await readJsonResponse((signal) => fetchImpl(url, { method: "POST", headers: conductorPostHeaders(access), body, signal }), timeoutMs);
|
|
3504
|
+
if (raw.kind !== "response")
|
|
3505
|
+
throw new AuthoredEpicPlanSaveError(raw.kind);
|
|
3506
|
+
if (!raw.ok) {
|
|
3507
|
+
if (raw.status === 404 && raw.bodyReadable && isDefaultNotFoundBody(raw.body)) {
|
|
3508
|
+
throw new AuthoredEpicPlanSaveError("server_too_old");
|
|
3509
|
+
}
|
|
3510
|
+
if (raw.status === 400 || raw.status === 422)
|
|
3511
|
+
throw new AuthoredEpicPlanSaveError("validation");
|
|
3512
|
+
throw new AuthoredEpicPlanSaveError(unknownReasonForStatus(raw.status));
|
|
3513
|
+
}
|
|
3514
|
+
if (!raw.bodyReadable || !isPlainObject(raw.body) || typeof raw.body.created !== "boolean") {
|
|
3515
|
+
throw new AuthoredEpicPlanSaveError("malformed_response");
|
|
3516
|
+
}
|
|
3517
|
+
const snapshot = parseAuthoredEpicPlanSnapshot(raw.body);
|
|
3518
|
+
if (snapshot === "hash_mismatch")
|
|
3519
|
+
throw new AuthoredEpicPlanSaveError("hash_mismatch");
|
|
3520
|
+
if (snapshot === null || snapshot.epic_key !== request.epicKey || snapshot.repo_name !== access.repoName) {
|
|
3521
|
+
throw new AuthoredEpicPlanSaveError("malformed_response");
|
|
3522
|
+
}
|
|
3523
|
+
// A newly created version must be exactly what was sent.
|
|
3524
|
+
if (raw.body.created === true && snapshot.plan_hash !== request.planHash) {
|
|
3525
|
+
throw new AuthoredEpicPlanSaveError("hash_mismatch");
|
|
3526
|
+
}
|
|
3527
|
+
return { created: raw.body.created, snapshot };
|
|
3528
|
+
}
|
|
3317
3529
|
/**
|
|
3318
3530
|
* BAPI-1252: the backend's closed canonical refusal vocabulary, mirrored as
|
|
3319
3531
|
* string literals (the Python source is `api/models/canonical_index_state.py`;
|
|
@@ -5195,6 +5407,252 @@ export async function regeneratePlanTicket(access, request, fetchImpl = globalTh
|
|
|
5195
5407
|
}
|
|
5196
5408
|
}
|
|
5197
5409
|
// ---------------------------------------------------------------------------
|
|
5410
|
+
// BAPI-1705 — driver open-decision councils: `reserve-council` / `record-decision`
|
|
5411
|
+
// ---------------------------------------------------------------------------
|
|
5412
|
+
//
|
|
5413
|
+
// During an unattended run the driver may settle an eligible open choice by
|
|
5414
|
+
// council, at most twice per run. It first RESERVES one logical council under a
|
|
5415
|
+
// stable key (`<epic_run_id>:<ticket_key>:park-<park_generation>`), then SETTLES
|
|
5416
|
+
// that row once with every council request id it used and the outcome it
|
|
5417
|
+
// classified. Both calls are idempotent on the server: a repeated reservation key
|
|
5418
|
+
// returns the stored row, and an identical settle on a settled row is a replay.
|
|
5419
|
+
//
|
|
5420
|
+
// Like `regenerate-plan`, neither function throws for an HTTP or transport
|
|
5421
|
+
// outcome: every answer is classified, so the caller decides whether an uncertain
|
|
5422
|
+
// outcome is re-sent unchanged. Decision text travels only in the request body;
|
|
5423
|
+
// it is never placed in an error, a diagnostic, or a URL.
|
|
5424
|
+
/** The closed settle outcomes, mirroring `DRIVER_COUNCIL_OUTCOMES` on the server. */
|
|
5425
|
+
export const DRIVER_COUNCIL_OUTCOMES = ["continue", "stop", "split", "no_valid_response"];
|
|
5426
|
+
/** Server-side limit on decision text; longer text is refused, never truncated. */
|
|
5427
|
+
export const DRIVER_DECISION_TEXT_MAX_CHARS = 2000;
|
|
5428
|
+
/** The Jira comment marker prefix; the full marker is followed by the council row id. */
|
|
5429
|
+
export const DRIVER_DECISION_COMMENT_MARKER_PREFIX = "bridge-driver-decision:";
|
|
5430
|
+
/**
|
|
5431
|
+
* The closed refusal codes of the two routes, mirroring
|
|
5432
|
+
* `DRIVER_COUNCIL_REFUSAL_CODES` in `api/models/epic_run_driver_council.py`.
|
|
5433
|
+
* `DRIVER_COUNCIL_UNAVAILABLE` is deliberately absent: it means the store could
|
|
5434
|
+
* not be read or written, so the outcome is unknown, not refused.
|
|
5435
|
+
*/
|
|
5436
|
+
export const DRIVER_COUNCIL_REFUSAL_CODES = [
|
|
5437
|
+
"DECISION_ALLOWANCE_REACHED",
|
|
5438
|
+
"DRIVER_COUNCIL_RESERVATION_CONFLICT",
|
|
5439
|
+
"DRIVER_COUNCIL_CHILD_NOT_FOUND",
|
|
5440
|
+
"DRIVER_COUNCIL_NOT_FOUND",
|
|
5441
|
+
"DRIVER_COUNCIL_SETTLEMENT_CONFLICT",
|
|
5442
|
+
"DRIVER_COUNCIL_PARK_EPISODE_CHANGED",
|
|
5443
|
+
"COUNCIL_ID_INVALID",
|
|
5444
|
+
"COUNCIL_ID_NOT_FOUND",
|
|
5445
|
+
"COUNCIL_ID_MISMATCH",
|
|
5446
|
+
"COUNCIL_NOT_TERMINAL",
|
|
5447
|
+
"COUNCIL_BEFORE_RESERVATION",
|
|
5448
|
+
"NO_RESPONDING_PROVIDER",
|
|
5449
|
+
"DECISION_TEXT_MISSING",
|
|
5450
|
+
"DECISION_TEXT_TOO_LONG",
|
|
5451
|
+
"DECISION_TEXT_REDACTED",
|
|
5452
|
+
"DECISION_TEXT_NOT_ALLOWED",
|
|
5453
|
+
"DRIVER_DECISION_DUPLICATE",
|
|
5454
|
+
"SPEC_SNAPSHOT_UNAVAILABLE",
|
|
5455
|
+
"DRIVER_COUNCIL_RUN_NOT_ACTIVE",
|
|
5456
|
+
"DRIVER_COUNCIL_NOT_ELIGIBLE",
|
|
5457
|
+
"DRIVER_COUNCIL_VALIDATION",
|
|
5458
|
+
];
|
|
5459
|
+
/** True when `code` is one of the closed driver-council refusal codes. */
|
|
5460
|
+
export function isDriverCouncilRefusalCode(code) {
|
|
5461
|
+
return DRIVER_COUNCIL_REFUSAL_CODES.includes(code);
|
|
5462
|
+
}
|
|
5463
|
+
/** The stable reservation key for one park episode of one child. */
|
|
5464
|
+
export function driverCouncilReservationKey(epicRunId, ticketKey, parkGeneration) {
|
|
5465
|
+
requireNonEmptyString(epicRunId);
|
|
5466
|
+
requireNonEmptyString(ticketKey);
|
|
5467
|
+
requireNonNegativeSafeInteger(parkGeneration);
|
|
5468
|
+
return `${epicRunId}:${ticketKey}:park-${parkGeneration}`;
|
|
5469
|
+
}
|
|
5470
|
+
/** Read a safe closed code from `{"detail": {"error_code": ...}}` (`code` also accepted). */
|
|
5471
|
+
function driverCouncilDetailCode(body) {
|
|
5472
|
+
if (!isPlainRecord(body))
|
|
5473
|
+
return null;
|
|
5474
|
+
const detail = body.detail;
|
|
5475
|
+
if (!isPlainRecord(detail))
|
|
5476
|
+
return null;
|
|
5477
|
+
const code = typeof detail.error_code === "string" ? detail.error_code : detail.code;
|
|
5478
|
+
return typeof code === "string" && SAFE_ERROR_CODE_RE.test(code) ? code : null;
|
|
5479
|
+
}
|
|
5480
|
+
function isDriverCouncilOutcome(value) {
|
|
5481
|
+
return typeof value === "string" && DRIVER_COUNCIL_OUTCOMES.includes(value);
|
|
5482
|
+
}
|
|
5483
|
+
function parseDriverCouncilRow(value) {
|
|
5484
|
+
if (!isPlainRecord(value))
|
|
5485
|
+
throw new ConductorBridgeApiError("server");
|
|
5486
|
+
const v = value;
|
|
5487
|
+
if (!isNonNegativeInt(v.council_row_id) || v.council_row_id === 0 ||
|
|
5488
|
+
typeof v.reserved_at !== "string" || !v.reserved_at ||
|
|
5489
|
+
typeof v.reservation_key !== "string" || !v.reservation_key ||
|
|
5490
|
+
typeof v.epic_run_id !== "string" || !v.epic_run_id ||
|
|
5491
|
+
typeof v.ticket_key !== "string" || !v.ticket_key ||
|
|
5492
|
+
!(v.outcome === null || v.outcome === undefined || isDriverCouncilOutcome(v.outcome)) ||
|
|
5493
|
+
!Array.isArray(v.council_ids) || !v.council_ids.every((id) => typeof id === "string") ||
|
|
5494
|
+
!nullableNonNegativeInt(v.providers_responding) ||
|
|
5495
|
+
typeof v.parked_gate !== "string" ||
|
|
5496
|
+
!isNonNegativeInt(v.park_generation) ||
|
|
5497
|
+
!nullableString(v.settled_at)) {
|
|
5498
|
+
throw new ConductorBridgeApiError("server");
|
|
5499
|
+
}
|
|
5500
|
+
return {
|
|
5501
|
+
council_row_id: v.council_row_id,
|
|
5502
|
+
reserved_at: v.reserved_at,
|
|
5503
|
+
reservation_key: v.reservation_key,
|
|
5504
|
+
epic_run_id: v.epic_run_id,
|
|
5505
|
+
ticket_key: v.ticket_key,
|
|
5506
|
+
outcome: (v.outcome ?? null),
|
|
5507
|
+
council_ids: [...v.council_ids],
|
|
5508
|
+
providers_responding: (v.providers_responding ?? null),
|
|
5509
|
+
parked_gate: v.parked_gate,
|
|
5510
|
+
park_generation: v.park_generation,
|
|
5511
|
+
settled_at: (v.settled_at ?? null),
|
|
5512
|
+
};
|
|
5513
|
+
}
|
|
5514
|
+
/** Strictly parse a reserve answer; anything short of the contract throws. */
|
|
5515
|
+
export function parseReserveDriverCouncilResult(value) {
|
|
5516
|
+
const row = parseDriverCouncilRow(value);
|
|
5517
|
+
const outcomeKind = value.outcome_kind;
|
|
5518
|
+
if (outcomeKind !== "recorded" && outcomeKind !== "existing")
|
|
5519
|
+
throw new ConductorBridgeApiError("server");
|
|
5520
|
+
return { ...row, outcome_kind: outcomeKind };
|
|
5521
|
+
}
|
|
5522
|
+
/** Strictly parse a settle answer; anything short of the contract throws. */
|
|
5523
|
+
export function parseRecordDriverDecisionResult(value) {
|
|
5524
|
+
const row = parseDriverCouncilRow(value);
|
|
5525
|
+
const v = value;
|
|
5526
|
+
if (row.outcome === null ||
|
|
5527
|
+
typeof v.replayed !== "boolean" ||
|
|
5528
|
+
v.committed !== true ||
|
|
5529
|
+
!(v.fyi_recorded === null || v.fyi_recorded === undefined || typeof v.fyi_recorded === "boolean")) {
|
|
5530
|
+
throw new ConductorBridgeApiError("server");
|
|
5531
|
+
}
|
|
5532
|
+
return {
|
|
5533
|
+
...row,
|
|
5534
|
+
replayed: v.replayed,
|
|
5535
|
+
committed: true,
|
|
5536
|
+
fyi_recorded: (v.fyi_recorded ?? null),
|
|
5537
|
+
};
|
|
5538
|
+
}
|
|
5539
|
+
/**
|
|
5540
|
+
* The de-duplicated council id list, in first-seen order. Ids are trimmed and
|
|
5541
|
+
* lower-cased (they are UUIDs); every distinct id is kept.
|
|
5542
|
+
*/
|
|
5543
|
+
export function normalizeDriverCouncilIds(ids) {
|
|
5544
|
+
const seen = new Set();
|
|
5545
|
+
const out = [];
|
|
5546
|
+
for (const raw of ids) {
|
|
5547
|
+
requireNonEmptyString(raw);
|
|
5548
|
+
const id = raw.trim().toLowerCase();
|
|
5549
|
+
if (!seen.has(id)) {
|
|
5550
|
+
seen.add(id);
|
|
5551
|
+
out.push(id);
|
|
5552
|
+
}
|
|
5553
|
+
}
|
|
5554
|
+
if (out.length === 0)
|
|
5555
|
+
throw new ConductorBridgeApiError("invalid-input");
|
|
5556
|
+
return out;
|
|
5557
|
+
}
|
|
5558
|
+
async function sendDriverCouncilRequest(method, url, access, body, parse, fetchImpl, timeoutMs) {
|
|
5559
|
+
const controller = new AbortController();
|
|
5560
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
5561
|
+
try {
|
|
5562
|
+
let resp;
|
|
5563
|
+
try {
|
|
5564
|
+
resp = await fetchImpl(url, {
|
|
5565
|
+
method,
|
|
5566
|
+
headers: conductorPostHeaders(access),
|
|
5567
|
+
body,
|
|
5568
|
+
signal: controller.signal,
|
|
5569
|
+
});
|
|
5570
|
+
}
|
|
5571
|
+
catch {
|
|
5572
|
+
return { kind: "uncertain", reason: controller.signal.aborted ? "timeout" : "network" };
|
|
5573
|
+
}
|
|
5574
|
+
let parsed;
|
|
5575
|
+
let parsedOk = true;
|
|
5576
|
+
try {
|
|
5577
|
+
parsed = await resp.json();
|
|
5578
|
+
}
|
|
5579
|
+
catch {
|
|
5580
|
+
parsedOk = false;
|
|
5581
|
+
}
|
|
5582
|
+
if (resp.status >= 200 && resp.status < 300) {
|
|
5583
|
+
if (!parsedOk)
|
|
5584
|
+
return { kind: "uncertain", reason: "malformed", status: resp.status };
|
|
5585
|
+
try {
|
|
5586
|
+
return { kind: "result", result: parse(parsed) };
|
|
5587
|
+
}
|
|
5588
|
+
catch {
|
|
5589
|
+
return { kind: "uncertain", reason: "malformed", status: resp.status };
|
|
5590
|
+
}
|
|
5591
|
+
}
|
|
5592
|
+
const errorCode = parsedOk ? driverCouncilDetailCode(parsed) : null;
|
|
5593
|
+
if (errorCode !== null && isDriverCouncilRefusalCode(errorCode)) {
|
|
5594
|
+
return { kind: "refused", status: resp.status, errorCode };
|
|
5595
|
+
}
|
|
5596
|
+
if (errorCode === null && (resp.status === 404 || resp.status === 405)) {
|
|
5597
|
+
return { kind: "unsupported_server", status: resp.status };
|
|
5598
|
+
}
|
|
5599
|
+
if (resp.status >= 500) {
|
|
5600
|
+
return { kind: "uncertain", reason: "server", status: resp.status };
|
|
5601
|
+
}
|
|
5602
|
+
return { kind: "rejected", status: resp.status, errorCode };
|
|
5603
|
+
}
|
|
5604
|
+
finally {
|
|
5605
|
+
clearTimeout(timer);
|
|
5606
|
+
}
|
|
5607
|
+
}
|
|
5608
|
+
/**
|
|
5609
|
+
* POST `/jira/epic-runs/runs/{epic_run_id}/tickets/{ticket_key}/driver-councils`.
|
|
5610
|
+
*
|
|
5611
|
+
* Reserves one logical council under `reservationKey`. A repeated key returns the
|
|
5612
|
+
* stored row (`outcome_kind: "existing"`), even after the per-run allowance is spent; a new
|
|
5613
|
+
* key past the allowance is refused with `DECISION_ALLOWANCE_REACHED`.
|
|
5614
|
+
*/
|
|
5615
|
+
export async function reserveDriverCouncil(access, request, fetchImpl = globalThis.fetch, timeoutMs = CONDUCTOR_FETCH_TIMEOUT_MS) {
|
|
5616
|
+
requireNonEmptyString(request.epicRunId);
|
|
5617
|
+
requireNonEmptyString(request.ticketKey);
|
|
5618
|
+
requireNonEmptyString(request.reservationKey);
|
|
5619
|
+
const url = buildConductorJiraUrl(access.baseUrl, `${continuationChildPath(request.epicRunId, request.ticketKey)}/driver-councils`);
|
|
5620
|
+
const body = JSON.stringify({ repo_name: access.repoName, reservation_key: request.reservationKey });
|
|
5621
|
+
return sendDriverCouncilRequest("POST", url, access, body, parseReserveDriverCouncilResult, fetchImpl, timeoutMs);
|
|
5622
|
+
}
|
|
5623
|
+
/**
|
|
5624
|
+
* PUT `/jira/epic-runs/runs/{epic_run_id}/tickets/{ticket_key}/driver-councils/{council_row_id}`.
|
|
5625
|
+
*
|
|
5626
|
+
* Settles one reserved council with every council request id it used (first
|
|
5627
|
+
* request and any provider retry). `decision_text` is sent only for `continue`
|
|
5628
|
+
* and is `null` otherwise; the client refuses a request that breaks that rule
|
|
5629
|
+
* before any network call. The text is never placed in an error.
|
|
5630
|
+
*/
|
|
5631
|
+
export async function recordDriverDecision(access, request, fetchImpl = globalThis.fetch, timeoutMs = CONDUCTOR_FETCH_TIMEOUT_MS) {
|
|
5632
|
+
requireNonEmptyString(request.epicRunId);
|
|
5633
|
+
requireNonEmptyString(request.ticketKey);
|
|
5634
|
+
requirePositiveSafeInteger(request.councilRowId);
|
|
5635
|
+
if (!isDriverCouncilOutcome(request.outcome))
|
|
5636
|
+
throw new ConductorBridgeApiError("invalid-input");
|
|
5637
|
+
const councilIds = normalizeDriverCouncilIds(request.councilIds);
|
|
5638
|
+
if (request.outcome === "continue") {
|
|
5639
|
+
if (typeof request.decisionText !== "string" || request.decisionText.trim().length === 0) {
|
|
5640
|
+
throw new ConductorBridgeApiError("invalid-input");
|
|
5641
|
+
}
|
|
5642
|
+
}
|
|
5643
|
+
else if (request.decisionText !== null) {
|
|
5644
|
+
throw new ConductorBridgeApiError("invalid-input");
|
|
5645
|
+
}
|
|
5646
|
+
const url = buildConductorJiraUrl(access.baseUrl, `${continuationChildPath(request.epicRunId, request.ticketKey)}/driver-councils/${request.councilRowId}`);
|
|
5647
|
+
const body = JSON.stringify({
|
|
5648
|
+
repo_name: access.repoName,
|
|
5649
|
+
council_ids: councilIds,
|
|
5650
|
+
outcome: request.outcome,
|
|
5651
|
+
decision_text: request.outcome === "continue" ? request.decisionText : null,
|
|
5652
|
+
});
|
|
5653
|
+
return sendDriverCouncilRequest("PUT", url, access, body, parseRecordDriverDecisionResult, fetchImpl, timeoutMs);
|
|
5654
|
+
}
|
|
5655
|
+
// ---------------------------------------------------------------------------
|
|
5198
5656
|
// BAPI-1391 — gate profile, provider history, capability probe, qualification
|
|
5199
5657
|
// ---------------------------------------------------------------------------
|
|
5200
5658
|
//
|
|
@@ -5975,6 +6433,8 @@ export const LEARNED_TEST_COMMAND_NO_COMMAND_REASONS = [
|
|
|
5975
6433
|
"not_plain_argv",
|
|
5976
6434
|
"command_not_allowed",
|
|
5977
6435
|
"invalid_command",
|
|
6436
|
+
// BAPI-1699 — the approved saved generation is no longer the current one.
|
|
6437
|
+
"generation_superseded",
|
|
5978
6438
|
];
|
|
5979
6439
|
const LEARNED_COMMAND_DISPLAY_MAX = 4096;
|
|
5980
6440
|
const LEARNED_COMMAND_MAX_DISPLAYED = 16;
|
|
@@ -6048,6 +6508,8 @@ export async function requestConductorLearnedTestCommand(access, request, fetchI
|
|
|
6048
6508
|
payload.candidates = candidates;
|
|
6049
6509
|
if (request.ownerCommand !== undefined)
|
|
6050
6510
|
payload.owner_command = request.ownerCommand;
|
|
6511
|
+
if (request.expectedGeneration !== undefined)
|
|
6512
|
+
payload.expected_generation = request.expectedGeneration;
|
|
6051
6513
|
let body;
|
|
6052
6514
|
try {
|
|
6053
6515
|
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);
|
|
@@ -6076,6 +6538,109 @@ export async function requestConductorLearnedTestCommand(access, request, fetchI
|
|
|
6076
6538
|
return { kind: "malformed" };
|
|
6077
6539
|
}
|
|
6078
6540
|
}
|
|
6541
|
+
// ---------------------------------------------------------------------------
|
|
6542
|
+
// BAPI-1699 — saved Epic Implementer test commands (`config_field`)
|
|
6543
|
+
// ---------------------------------------------------------------------------
|
|
6544
|
+
/** The config field that holds the pending test-command selection. */
|
|
6545
|
+
export const SAVED_TEST_COMMANDS_FIELD = "epic_implementer_test_commands";
|
|
6546
|
+
/** The four derived trial states of a saved selection. */
|
|
6547
|
+
export const SAVED_TEST_COMMANDS_TRIAL_STATES = ["passed", "queued", "failed", "not_tried"];
|
|
6548
|
+
const SAVED_COMMANDS_MAX = 4;
|
|
6549
|
+
function parseSavedTestCommandsRecord(value) {
|
|
6550
|
+
const o = requireObject(value);
|
|
6551
|
+
const commands = o.commands;
|
|
6552
|
+
if (!Array.isArray(commands) || commands.length === 0 || commands.length > SAVED_COMMANDS_MAX) {
|
|
6553
|
+
throw readinessShapeError();
|
|
6554
|
+
}
|
|
6555
|
+
const checked = commands.map((command) => {
|
|
6556
|
+
if (typeof command !== "string" || command.length === 0 || command.length > 4096) {
|
|
6557
|
+
throw readinessShapeError();
|
|
6558
|
+
}
|
|
6559
|
+
return command;
|
|
6560
|
+
});
|
|
6561
|
+
if (o.source !== "config_field" && o.source !== "owner_command")
|
|
6562
|
+
throw readinessShapeError();
|
|
6563
|
+
if (o.set_by !== null && typeof o.set_by !== "string")
|
|
6564
|
+
throw readinessShapeError();
|
|
6565
|
+
if (typeof o.set_at !== "string" || o.set_at.length === 0)
|
|
6566
|
+
throw readinessShapeError();
|
|
6567
|
+
const generation = requireInt(o, "generation");
|
|
6568
|
+
if (generation < 1)
|
|
6569
|
+
throw readinessShapeError();
|
|
6570
|
+
return { commands: checked, source: o.source, set_by: o.set_by, set_at: o.set_at, generation };
|
|
6571
|
+
}
|
|
6572
|
+
function parseSavedTestCommandsEnvelope(body) {
|
|
6573
|
+
const o = requireObject(body);
|
|
6574
|
+
if (o.field_name !== SAVED_TEST_COMMANDS_FIELD)
|
|
6575
|
+
throw readinessShapeError();
|
|
6576
|
+
if (o.value === null)
|
|
6577
|
+
return null;
|
|
6578
|
+
const record = parseSavedTestCommandsRecord(o.value);
|
|
6579
|
+
const trial = o.trial_state;
|
|
6580
|
+
if (trial !== null && trial !== undefined && !SAVED_TEST_COMMANDS_TRIAL_STATES.includes(trial)) {
|
|
6581
|
+
throw readinessShapeError();
|
|
6582
|
+
}
|
|
6583
|
+
const inForce = o.commands_in_force;
|
|
6584
|
+
if (inForce !== null && inForce !== undefined) {
|
|
6585
|
+
if (!Array.isArray(inForce) || inForce.length > 16 || inForce.some((c) => typeof c !== "string")) {
|
|
6586
|
+
throw readinessShapeError();
|
|
6587
|
+
}
|
|
6588
|
+
}
|
|
6589
|
+
return {
|
|
6590
|
+
record,
|
|
6591
|
+
trialState: (trial ?? null),
|
|
6592
|
+
commandsInForce: (inForce ?? null),
|
|
6593
|
+
};
|
|
6594
|
+
}
|
|
6595
|
+
/** GET the saved record once. NEVER throws. */
|
|
6596
|
+
export async function readConductorSavedTestCommands(access, fetchImpl = globalThis.fetch) {
|
|
6597
|
+
let body;
|
|
6598
|
+
try {
|
|
6599
|
+
body = await fetchConductorJsonWithTimeout(buildConductorJiraUrl(access.baseUrl, `/config-field/${encodeURIComponent(SAVED_TEST_COMMANDS_FIELD)}`, {
|
|
6600
|
+
repo_name: access.repoName,
|
|
6601
|
+
}), conductorGetHeaders(access), CONDUCTOR_FETCH_TIMEOUT_MS, fetchImpl);
|
|
6602
|
+
}
|
|
6603
|
+
catch (err) {
|
|
6604
|
+
if (err instanceof ConductorBridgeApiError && (err.status === 400 || err.status === 404 || err.status === 405)) {
|
|
6605
|
+
return { kind: "unsupported" };
|
|
6606
|
+
}
|
|
6607
|
+
return { kind: "unreadable" };
|
|
6608
|
+
}
|
|
6609
|
+
try {
|
|
6610
|
+
const state = parseSavedTestCommandsEnvelope(body);
|
|
6611
|
+
return state === null ? { kind: "none" } : { kind: "saved", ...state };
|
|
6612
|
+
}
|
|
6613
|
+
catch {
|
|
6614
|
+
return { kind: "unreadable" };
|
|
6615
|
+
}
|
|
6616
|
+
}
|
|
6617
|
+
/** PUT the whole command list (the server replaces it). NEVER throws. */
|
|
6618
|
+
export async function saveConductorSavedTestCommands(access, commands, fetchImpl) {
|
|
6619
|
+
let body;
|
|
6620
|
+
try {
|
|
6621
|
+
body = await fetchConductorJsonWithMethodAndTimeout("PUT", buildConductorJiraUrl(access.baseUrl, `/config-field/${encodeURIComponent(SAVED_TEST_COMMANDS_FIELD)}`), conductorPostHeaders(access), JSON.stringify({ repo_name: access.repoName, value: [...commands] }), CONDUCTOR_FETCH_TIMEOUT_MS, fetchImpl);
|
|
6622
|
+
}
|
|
6623
|
+
catch (err) {
|
|
6624
|
+
if (!(err instanceof ConductorBridgeApiError))
|
|
6625
|
+
return { kind: "uncertain" };
|
|
6626
|
+
if (err.kind === "unauthorized")
|
|
6627
|
+
return { kind: "refused", reason: "unauthorized" };
|
|
6628
|
+
if (err.unreadableSuccess === true)
|
|
6629
|
+
return { kind: "uncertain" };
|
|
6630
|
+
if (err.kind === "timeout" || err.kind === "network" || err.kind === "server")
|
|
6631
|
+
return { kind: "uncertain" };
|
|
6632
|
+
if (err.status === 400 || err.status === 404 || err.status === 405)
|
|
6633
|
+
return { kind: "unsupported" };
|
|
6634
|
+
return { kind: "refused", reason: "rejected" };
|
|
6635
|
+
}
|
|
6636
|
+
try {
|
|
6637
|
+
const state = parseSavedTestCommandsEnvelope(body);
|
|
6638
|
+
return state === null ? { kind: "uncertain" } : { kind: "saved", ...state };
|
|
6639
|
+
}
|
|
6640
|
+
catch {
|
|
6641
|
+
return { kind: "uncertain" };
|
|
6642
|
+
}
|
|
6643
|
+
}
|
|
6079
6644
|
const QUALIFICATION_REFUSAL_CODES = Object.freeze({
|
|
6080
6645
|
PROFILE_NOT_CONFIRMED: "profile-not-confirmed",
|
|
6081
6646
|
NO_LOCAL_COMMANDS: "no-local-commands",
|
|
@@ -6129,10 +6694,64 @@ export async function enqueueConductorGateQualification(access, request, fetchIm
|
|
|
6129
6694
|
*/
|
|
6130
6695
|
export const CONDUCTOR_GATE_QUALIFICATION_PHASES = [
|
|
6131
6696
|
"dependency_preparation_failed",
|
|
6697
|
+
// BAPI-1698
|
|
6698
|
+
"worker_database_preparation_failed",
|
|
6132
6699
|
"could_not_start",
|
|
6133
6700
|
"ran_and_failed",
|
|
6701
|
+
// BAPI-1698
|
|
6702
|
+
"no_tests_ran",
|
|
6134
6703
|
"passed",
|
|
6135
6704
|
];
|
|
6705
|
+
/** BAPI-1698 — the closed per-command outcomes a qualification status read may project. */
|
|
6706
|
+
export const CONDUCTOR_GATE_QUALIFICATION_COMMAND_OUTCOMES = [
|
|
6707
|
+
"exited_zero",
|
|
6708
|
+
"exited_nonzero",
|
|
6709
|
+
"timed_out",
|
|
6710
|
+
"launch_error",
|
|
6711
|
+
"cancelled",
|
|
6712
|
+
"not_run",
|
|
6713
|
+
"no_tests_ran",
|
|
6714
|
+
];
|
|
6715
|
+
/** BAPI-1698 — the closed shared reasons a projected command fact may carry. */
|
|
6716
|
+
export const CONDUCTOR_GATE_QUALIFICATION_COMMAND_REASONS = [
|
|
6717
|
+
"declared_timeout",
|
|
6718
|
+
"reservation_exhausted",
|
|
6719
|
+
"stopped_after_interruption",
|
|
6720
|
+
"ownership_lost",
|
|
6721
|
+
"executor_cancelled",
|
|
6722
|
+
"spawn_failed",
|
|
6723
|
+
"killed_by_signal",
|
|
6724
|
+
];
|
|
6725
|
+
/** The same 16-command bound the server holds a qualification to. */
|
|
6726
|
+
const GATE_QUALIFICATION_MAX_COMMAND_RESULTS = 16;
|
|
6727
|
+
/**
|
|
6728
|
+
* BAPI-1698 — the projected command results, or `null` when absent (an older
|
|
6729
|
+
* server), malformed, or carrying any unknown token. Whole-list strict: one bad
|
|
6730
|
+
* entry makes attribution unavailable rather than partial. Never throws.
|
|
6731
|
+
*/
|
|
6732
|
+
export function parseGateQualificationCommandResults(raw) {
|
|
6733
|
+
if (!Array.isArray(raw) || raw.length === 0 || raw.length > GATE_QUALIFICATION_MAX_COMMAND_RESULTS)
|
|
6734
|
+
return null;
|
|
6735
|
+
const out = [];
|
|
6736
|
+
for (const item of raw) {
|
|
6737
|
+
if (typeof item !== "object" || item === null || Array.isArray(item))
|
|
6738
|
+
return null;
|
|
6739
|
+
const entry = item;
|
|
6740
|
+
if (Object.keys(entry).some((key) => key !== "outcome" && key !== "reason"))
|
|
6741
|
+
return null;
|
|
6742
|
+
if (!CONDUCTOR_GATE_QUALIFICATION_COMMAND_OUTCOMES.includes(entry.outcome))
|
|
6743
|
+
return null;
|
|
6744
|
+
const reason = entry.reason ?? null;
|
|
6745
|
+
if (reason !== null && !CONDUCTOR_GATE_QUALIFICATION_COMMAND_REASONS.includes(reason)) {
|
|
6746
|
+
return null;
|
|
6747
|
+
}
|
|
6748
|
+
out.push({
|
|
6749
|
+
outcome: entry.outcome,
|
|
6750
|
+
reason: reason,
|
|
6751
|
+
});
|
|
6752
|
+
}
|
|
6753
|
+
return out;
|
|
6754
|
+
}
|
|
6136
6755
|
export function parseConductorGateQualificationJob(body, expectedRepoName, expectedJobId) {
|
|
6137
6756
|
const o = requireObject(body);
|
|
6138
6757
|
if (o.repo_name !== expectedRepoName || o.job_id !== expectedJobId)
|
|
@@ -6156,6 +6775,7 @@ export function parseConductorGateQualificationJob(body, expectedRepoName, expec
|
|
|
6156
6775
|
? o.phase
|
|
6157
6776
|
: null,
|
|
6158
6777
|
dependency_install_declared: typeof o.dependency_install_declared === "boolean" ? o.dependency_install_declared : null,
|
|
6778
|
+
command_results: parseGateQualificationCommandResults(o.command_results),
|
|
6159
6779
|
};
|
|
6160
6780
|
}
|
|
6161
6781
|
/** GET one qualification job's verified state. Throws a sanitized error on failure. */
|