@bridge_gpt/mcp-server 0.2.74 → 0.2.76
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 +6 -6
- package/build/authored-plan.js +542 -0
- package/build/bridge-permissions.js +8 -0
- package/build/codex-auto-recovery.js +25 -7
- package/build/commands.generated.js +7 -7
- package/build/conductor/bridge-api-client.js +807 -52
- package/build/conductor/declare-blocked.js +4 -0
- package/build/conductor/driver-pass.js +8 -0
- package/build/conductor/epic-implementer-cli.js +341 -96
- package/build/conductor/epic-server-journal.js +13 -0
- package/build/conductor/epic-server-recipe.js +15 -5
- package/build/conductor/epic-server-runtime.js +163 -45
- package/build/conductor/epic-server.js +13 -6
- package/build/conductor/gate-discovery.js +209 -9
- package/build/conductor/gate-settings-review.js +7 -11
- package/build/conductor/install-doctor.js +30 -2
- package/build/conductor/launch-plan.js +58 -12
- package/build/conductor/local-merge.js +54 -12
- package/build/conductor/open-decision-phrases.js +50 -0
- package/build/conductor/pr-ci-producer.js +12 -3
- package/build/conductor/prerequisite-inputs.js +181 -14
- package/build/conductor/readiness-sections.js +46 -13
- package/build/conductor/readiness.js +3 -40
- package/build/conductor/recovery-cli.js +12 -12
- package/build/conductor/repository-workflow-remedy.js +147 -7
- package/build/conductor/ui-readiness.js +224 -0
- package/build/conductor/wait-run-attention.js +9 -4
- package/build/conductor/wait-run-cli.js +9 -2
- package/build/connect-github-api.js +18 -0
- package/build/connect-github.js +35 -18
- package/build/docs.generated.js +3 -3
- package/build/drive-epic.js +787 -37
- package/build/epic-ci-workflow.js +3 -2
- package/build/epic-implementer-bin.js +200 -66
- 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/epic-launch-context.js +8 -1
- package/build/epic-shared/cut-protocol.js +55 -3
- package/build/executor/completion-contract.js +24 -1
- package/build/executor/failure-reason-codes.js +2 -0
- package/build/executor/gate-qualification-job.js +193 -23
- package/build/executor/gate-qualification-tests-ran.js +232 -0
- package/build/executor/integration-job.js +56 -2
- package/build/executor/job-runner.js +13 -723
- package/build/executor/job-type-wrappers.js +734 -0
- package/build/executor/merge-job.js +45 -1
- package/build/executor/permissions.js +187 -2
- package/build/executor/preflight.js +6 -2
- package/build/executor/process-containment.js +8 -1
- package/build/executor/provider-checks.js +28 -5
- package/build/executor/reconcile-overlap-job.js +70 -17
- package/build/executor/required-verification.js +28 -2
- package/build/executor/required-work-ledger.js +7 -2
- package/build/executor/resume-pre-spawn.js +32 -8
- package/build/executor/runner.js +30 -5
- 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/executor/worktree.js +12 -1
- package/build/generated/ticket-status.js +20 -0
- package/build/index.js +627 -551
- package/build/init.js +16 -0
- package/build/install-bridge-conductor-answers.js +32 -1
- package/build/install-bridge-conductor-apply.js +21 -3
- package/build/install-bridge-conductor-assessment.js +185 -12
- package/build/install-bridge-conductor-compact.js +2 -0
- package/build/install-bridge-conductor-contracts.js +9 -1
- package/build/install-bridge-conductor-gate.js +257 -80
- package/build/install-bridge-conductor-setup.js +106 -6
- package/build/install-bridge-conductor-trial-report.js +170 -0
- package/build/install-bridge-conductor.js +740 -124
- package/build/mcp-host-config.js +54 -37
- package/build/phase-context-git-probe.js +16 -0
- package/build/pipelines.generated.js +15 -15
- package/build/plan-execution-ledger.js +27 -0
- package/build/plan-generation.js +17 -0
- package/build/plane/plane-freshness.js +43 -26
- package/build/printed-remedy-commands.js +62 -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/secret-redaction.js +3 -0
- package/build/setup-epic.js +51 -9
- package/build/test-support/create-preview-world.js +232 -0
- package/build/test-support/executor-source-files.js +1 -1
- package/build/ticket-delivery.js +65 -0
- package/build/v2-readiness-requirements.js +13 -4
- package/build/version.generated.js +3 -3
- package/build/worker-guard-hook-bin.js +2 -2
- package/build/worktree-core.js +51 -7
- package/docs/EPIC-IMPLEMENTER.md +83 -4
- package/docs/epic-implementer/getting-started.md +1 -1
- package/docs/install/github-app.md +79 -92
- package/package.json +1 -1
- package/pipelines/implement-ticket.json +2 -2
- package/build/conductor/epic-reconcile.js +0 -603
- package/build/conductor/epic-runtime.js +0 -2020
- package/build/conductor/epic-state.js +0 -774
|
@@ -55,17 +55,38 @@
|
|
|
55
55
|
* result keeps exactly the pre-existing shape (no `dependency_preparation`).
|
|
56
56
|
* Every message and fact stays value-free: no install output, path, argv, or
|
|
57
57
|
* environment value.
|
|
58
|
+
*
|
|
59
|
+
* 7. **A declared worker database is provisioned exactly as a worker job's is
|
|
60
|
+
* (BAPI-1698).** When the SEALED declaration carries a disposable
|
|
61
|
+
* `worker_database`, the job provisions it through the executor's existing
|
|
62
|
+
* worker-resource seam after dependency preparation and before any command,
|
|
63
|
+
* runs the commands with the database environment a worker would get, and
|
|
64
|
+
* drops it before the checkout is removed. A completed provisioning failure
|
|
65
|
+
* is a COMPLETED job (`worker_database_preparation: "failed"`, every command
|
|
66
|
+
* `not_run`); a cancelled provisioning is an interruption. Such a job
|
|
67
|
+
* requires `gate_qualification.worker_database.v1`, so an older executor
|
|
68
|
+
* leaves it queued.
|
|
69
|
+
*
|
|
70
|
+
* 8. **Best-effort evidence that tests ran (BAPI-1698).** A command that exited
|
|
71
|
+
* zero is checked against a small, conservative set of plain signs that it
|
|
72
|
+
* executed no tests (see `gate-qualification-tests-ran.ts`). Such a command
|
|
73
|
+
* reports the qualification-only `no_tests_ran`, which never passes. This is
|
|
74
|
+
* not proof that tests ran: an unfamiliar, quiet, or ambiguous command keeps
|
|
75
|
+
* its pass.
|
|
58
76
|
*/
|
|
59
77
|
import { createHash } from "node:crypto";
|
|
60
|
-
import { mkdtemp, rm } from "node:fs/promises";
|
|
78
|
+
import { mkdtemp, readFile, rm } from "node:fs/promises";
|
|
61
79
|
import os from "node:os";
|
|
62
80
|
import path from "node:path";
|
|
63
81
|
import { validateBranchName } from "../base-ref.js";
|
|
64
82
|
import { parseDependencyInstallStrict, } from "../dependency-install-declarations.js";
|
|
65
83
|
import { refreshDeclaredDependencies } from "./dependency-refresh.js";
|
|
84
|
+
import { assessTestsRanInCheckout } from "./gate-qualification-tests-ran.js";
|
|
66
85
|
import { buildDependencyInstallEnv, buildExecutorBaseWorkerEnv } from "./env.js";
|
|
86
|
+
import { parseWorkerDatabasePayload, workerEnvNamesOf, } from "./worker-database-config.js";
|
|
87
|
+
import { formatWorkerDatabaseDropFailedLine, formatWorkerDatabaseUnavailableLine } from "./worker-database.js";
|
|
67
88
|
import { ARTIFACT_GIT_TIMEOUT_MS, OWNERSHIP_POLL_MS, canonicalJson, createSupervisedCommandLauncher, preCheckArtifactState, runRequiredVerificationCommands, toCompletionCheckFact, } from "./required-verification.js";
|
|
68
|
-
import { GATE_QUALIFICATION_CAPABILITY, } from "./types.js";
|
|
89
|
+
import { GATE_QUALIFICATION_CAPABILITY, GATE_QUALIFICATION_WORKER_DATABASE_CAPABILITY, } from "./types.js";
|
|
69
90
|
// ---------------------------------------------------------------------------
|
|
70
91
|
// Contract constants
|
|
71
92
|
// ---------------------------------------------------------------------------
|
|
@@ -98,11 +119,18 @@ export const GATE_QUALIFICATION_DEADLINE_RESERVE_MS = 60_000;
|
|
|
98
119
|
const HEX64_RE = /^[0-9a-f]{64}$/;
|
|
99
120
|
const FULL_SHA_RE = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/;
|
|
100
121
|
const SYMREF_HEAD_RE = /^ref: refs\/heads\/(\S+)\tHEAD$/m;
|
|
122
|
+
/**
|
|
123
|
+
* BAPI-1698 — a qualification-ONLY command outcome: the command exited zero, but
|
|
124
|
+
* the executor found plain evidence that it executed no tests. It never appears
|
|
125
|
+
* in a worker completion, so the shared {@link CheckOutcome} is unchanged.
|
|
126
|
+
*/
|
|
127
|
+
export const GATE_QUALIFICATION_NO_TESTS_RAN = "no_tests_ran";
|
|
101
128
|
/** Fixed `/fail` messages, one per inability. */
|
|
102
129
|
const MESSAGES = {
|
|
103
130
|
contract: "gate_qualification payload failed contract validation",
|
|
104
131
|
capability: "gate_qualification job does not require the gate qualification capability",
|
|
105
132
|
repo: "gate_qualification payload names a different repository than the job",
|
|
133
|
+
databaseCapability: "gate_qualification job with a worker database does not require the worker database capability",
|
|
106
134
|
defaultBranch: "default branch could not be resolved",
|
|
107
135
|
fetch: "default branch could not be fetched",
|
|
108
136
|
revParse: "default branch commit could not be resolved",
|
|
@@ -235,6 +263,20 @@ export function parseGateQualificationPayload(job) {
|
|
|
235
263
|
return refuse(MESSAGES.contract);
|
|
236
264
|
dependencyInstallOption = { dependencyInstall: entries };
|
|
237
265
|
}
|
|
266
|
+
// BAPI-1698: the worker database is read from the SIGNED body only, through the
|
|
267
|
+
// worker pathway's own parser. Only a valid disposable declaration is sealed;
|
|
268
|
+
// anything else is refused before any git or process effect.
|
|
269
|
+
let workerDatabaseOption = {};
|
|
270
|
+
if (Object.prototype.hasOwnProperty.call(envelope, "worker_database")) {
|
|
271
|
+
const database = parseWorkerDatabasePayload(envelope.worker_database, workerEnvNamesOf(envelope.worker_env));
|
|
272
|
+
if (database.classification !== "enabled")
|
|
273
|
+
return refuse(MESSAGES.contract);
|
|
274
|
+
if (Array.isArray(job.required_capabilities) &&
|
|
275
|
+
!job.required_capabilities.includes(GATE_QUALIFICATION_WORKER_DATABASE_CAPABILITY)) {
|
|
276
|
+
return refuse(MESSAGES.databaseCapability);
|
|
277
|
+
}
|
|
278
|
+
workerDatabaseOption = { workerDatabase: database.config };
|
|
279
|
+
}
|
|
238
280
|
// The envelope digest covers the object exactly as received, minus its own
|
|
239
281
|
// digest key, so any field the server signed is checked byte for byte.
|
|
240
282
|
const { digest, ...signed } = envelope;
|
|
@@ -253,6 +295,7 @@ export function parseGateQualificationPayload(job) {
|
|
|
253
295
|
? { workerEnv: envelope.worker_env }
|
|
254
296
|
: {},
|
|
255
297
|
dependencyInstallOption,
|
|
298
|
+
workerDatabaseOption,
|
|
256
299
|
},
|
|
257
300
|
};
|
|
258
301
|
}
|
|
@@ -319,17 +362,16 @@ async function removeCheckout(deps, dir) {
|
|
|
319
362
|
// Best effort: a leftover temporary directory costs disk, never correctness.
|
|
320
363
|
}
|
|
321
364
|
}
|
|
322
|
-
// ---------------------------------------------------------------------------
|
|
323
|
-
// The core
|
|
324
|
-
// ---------------------------------------------------------------------------
|
|
325
365
|
function toResultFact(fact) {
|
|
326
366
|
// The shared server-bound view, minus `position`: the result envelope keys
|
|
327
|
-
// each fact by identity only.
|
|
367
|
+
// each fact by identity only. BAPI-1698: a zero-test pass reports the
|
|
368
|
+
// qualification-only `no_tests_ran`, which carries no reason.
|
|
328
369
|
const bounded = toCompletionCheckFact(fact);
|
|
370
|
+
const noTests = fact.qualificationOutcome === GATE_QUALIFICATION_NO_TESTS_RAN;
|
|
329
371
|
return {
|
|
330
372
|
identity: bounded.identity,
|
|
331
|
-
outcome: bounded.outcome,
|
|
332
|
-
reason: bounded.reason,
|
|
373
|
+
outcome: noTests ? GATE_QUALIFICATION_NO_TESTS_RAN : bounded.outcome,
|
|
374
|
+
reason: noTests ? null : bounded.reason,
|
|
333
375
|
duration_ms: bounded.duration_ms,
|
|
334
376
|
};
|
|
335
377
|
}
|
|
@@ -341,20 +383,27 @@ function isInterruptionFact(fact) {
|
|
|
341
383
|
}
|
|
342
384
|
/**
|
|
343
385
|
* Fold what was observed into one classification, by fixed precedence:
|
|
344
|
-
* interruption, preparation failure,
|
|
345
|
-
*
|
|
346
|
-
*
|
|
386
|
+
* interruption, dependency preparation failure, worker-database preparation
|
|
387
|
+
* failure (BAPI-1698), any `launch_error`/`spawn_failed` fact, any other
|
|
388
|
+
* unsuccessful or not-run fact except `no_tests_ran`, then `no_tests_ran`
|
|
389
|
+
* (BAPI-1698), then passed. The server derives the same phase from the stored
|
|
390
|
+
* result; the completion envelope carries no `phase`.
|
|
347
391
|
*/
|
|
348
392
|
export function foldGateQualificationOutcome(input) {
|
|
349
393
|
if (input.facts.some(isInterruptionFact))
|
|
350
394
|
return "interrupted";
|
|
351
395
|
if (input.preparationFailed === true)
|
|
352
396
|
return "dependency_preparation_failed";
|
|
397
|
+
if (input.databasePreparationFailed === true)
|
|
398
|
+
return "worker_database_preparation_failed";
|
|
353
399
|
if (input.facts.some((fact) => fact.outcome === "launch_error" || fact.reason === "spawn_failed")) {
|
|
354
400
|
return "could_not_start";
|
|
355
401
|
}
|
|
356
|
-
if (input.facts.some((fact) => fact.outcome !== "exited_zero"))
|
|
402
|
+
if (input.facts.some((fact) => fact.outcome !== "exited_zero" && fact.outcome !== GATE_QUALIFICATION_NO_TESTS_RAN)) {
|
|
357
403
|
return "ran_and_failed";
|
|
404
|
+
}
|
|
405
|
+
if (input.facts.some((fact) => fact.outcome === GATE_QUALIFICATION_NO_TESTS_RAN))
|
|
406
|
+
return "no_tests_ran";
|
|
358
407
|
return "passed";
|
|
359
408
|
}
|
|
360
409
|
/**
|
|
@@ -363,7 +412,10 @@ export function foldGateQualificationOutcome(input) {
|
|
|
363
412
|
* Returns the bounded result envelope, or a fixed-text inability. Never throws
|
|
364
413
|
* for a git, process, or payload condition, and never returns command output.
|
|
365
414
|
*/
|
|
366
|
-
export async function runGateQualificationJob(
|
|
415
|
+
export async function runGateQualificationJob(
|
|
416
|
+
// BAPI-1698: `id` names the job's worker database. Optional only so callers
|
|
417
|
+
// that never seal a database keep their shape; the executor always passes it.
|
|
418
|
+
job, input, deps) {
|
|
367
419
|
const startedAt = deps.now();
|
|
368
420
|
const inability = (errorKind, message) => {
|
|
369
421
|
deps.errorLog(`[gate_qualification] ${message}`);
|
|
@@ -404,6 +456,12 @@ export async function runGateQualificationJob(job, input, deps) {
|
|
|
404
456
|
catch {
|
|
405
457
|
return inability(GATE_QUALIFICATION_CHECKOUT_UNAVAILABLE, MESSAGES.checkout);
|
|
406
458
|
}
|
|
459
|
+
const jobId = job.id !== undefined ? String(job.id) : "gate-qualification";
|
|
460
|
+
// BAPI-1698: the provisioned worker database, set only once provisioning
|
|
461
|
+
// returned both a target and its role. Dropped in `finally`, before the
|
|
462
|
+
// checkout is removed.
|
|
463
|
+
let databaseTarget;
|
|
464
|
+
let databaseRole;
|
|
407
465
|
try {
|
|
408
466
|
const added = await git(deps, ["worktree", "add", "--detach", dir, sha], GATE_QUALIFICATION_WORKTREE_ADD_TIMEOUT_MS);
|
|
409
467
|
if (!added.ok)
|
|
@@ -448,7 +506,9 @@ export async function runGateQualificationJob(job, input, deps) {
|
|
|
448
506
|
}));
|
|
449
507
|
const dependencyInstall = payload.dependencyInstallOption.dependencyInstall;
|
|
450
508
|
const installDeclared = dependencyInstall !== undefined;
|
|
509
|
+
const workerDatabase = payload.workerDatabaseOption.workerDatabase;
|
|
451
510
|
let preparationFailed = false;
|
|
511
|
+
let databasePreparationFailed = false;
|
|
452
512
|
let facts = [];
|
|
453
513
|
try {
|
|
454
514
|
// BAPI-1637 — dependency preparation, only when the sealed declaration
|
|
@@ -480,7 +540,54 @@ export async function runGateQualificationJob(job, input, deps) {
|
|
|
480
540
|
return inability(GATE_QUALIFICATION_INTERRUPTED, MESSAGES.interrupted);
|
|
481
541
|
preparationFailed = refreshed.stale.length > 0;
|
|
482
542
|
}
|
|
483
|
-
|
|
543
|
+
// BAPI-1698 — the sealed disposable worker database, after a successful
|
|
544
|
+
// dependency preparation and before any command, through the executor's
|
|
545
|
+
// existing worker-resource seam. A failed dependency preparation means the
|
|
546
|
+
// database is never attempted; it still reports as not ready.
|
|
547
|
+
if (workerDatabase !== undefined) {
|
|
548
|
+
if (preparationFailed) {
|
|
549
|
+
databasePreparationFailed = true;
|
|
550
|
+
}
|
|
551
|
+
else if (deps.workerResources === undefined) {
|
|
552
|
+
databasePreparationFailed = true;
|
|
553
|
+
deps.errorLog("[gate_qualification] worker database unavailable: this executor cannot provision one");
|
|
554
|
+
}
|
|
555
|
+
else {
|
|
556
|
+
const provisioned = await deps.workerResources
|
|
557
|
+
.provisionDatabase({
|
|
558
|
+
jobId,
|
|
559
|
+
worktreePath: dir,
|
|
560
|
+
signal: commandAbort.signal,
|
|
561
|
+
config: workerDatabase,
|
|
562
|
+
// BAPI-1521 — own-key forwarding: absence keeps the legacy migration env.
|
|
563
|
+
...payload.workerEnvOption,
|
|
564
|
+
})
|
|
565
|
+
.catch(() => ({ kind: "unavailable", category: "create_failed" }));
|
|
566
|
+
if (provisioned.kind === "provisioned") {
|
|
567
|
+
databaseTarget = provisioned.target;
|
|
568
|
+
databaseRole = provisioned.role;
|
|
569
|
+
}
|
|
570
|
+
else if (provisioned.category === "cancelled" || commandAbort.signal.aborted) {
|
|
571
|
+
// A cancelled provisioning proved nothing about the gate: an inability.
|
|
572
|
+
return inability(GATE_QUALIFICATION_INTERRUPTED, MESSAGES.interrupted);
|
|
573
|
+
}
|
|
574
|
+
else {
|
|
575
|
+
databasePreparationFailed = true;
|
|
576
|
+
try {
|
|
577
|
+
const cause = "cause" in provisioned ? provisioned.cause : undefined;
|
|
578
|
+
deps.errorLog(formatWorkerDatabaseUnavailableLine(jobId, provisioned.category, cause));
|
|
579
|
+
// A created database whose rollback failed stays for the host operator.
|
|
580
|
+
if ("retainedName" in provisioned && provisioned.retainedName) {
|
|
581
|
+
deps.errorLog(formatWorkerDatabaseDropFailedLine(jobId, provisioned.retainedName));
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
catch {
|
|
585
|
+
/* sink */
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
if (preparationFailed || databasePreparationFailed) {
|
|
484
591
|
// The install did not complete, so nothing was launched. One bounded
|
|
485
592
|
// `not_run` fact per declared command, in declaration order.
|
|
486
593
|
facts = commands.map((command) => ({
|
|
@@ -497,7 +604,12 @@ export async function runGateQualificationJob(job, input, deps) {
|
|
|
497
604
|
// BAPI-1521 — the effective environment is built here, AFTER the envelope
|
|
498
605
|
// was verified and BEFORE any command runs, from the sealed declaration.
|
|
499
606
|
// The injected dependencies are never mutated.
|
|
500
|
-
|
|
607
|
+
// BAPI-1698: a provisioned worker database reaches the commands through
|
|
608
|
+
// the worker environment builder's own explicit options, never ambiently.
|
|
609
|
+
const commandEnv = deps.commandEnv ??
|
|
610
|
+
buildGateQualificationEnv(deps.baseEnv ?? {}, payload.workerEnvOption, workerDatabase !== undefined && databaseTarget !== undefined
|
|
611
|
+
? { workerDatabase: databaseTarget, workerDatabaseConfig: workerDatabase }
|
|
612
|
+
: {});
|
|
501
613
|
const run = await runRequiredVerificationCommands({
|
|
502
614
|
commands,
|
|
503
615
|
worktreePath: dir,
|
|
@@ -517,21 +629,52 @@ export async function runGateQualificationJob(job, input, deps) {
|
|
|
517
629
|
deps.clearTimer(watchTimer);
|
|
518
630
|
input.signal.removeEventListener("abort", onOuterAbort);
|
|
519
631
|
}
|
|
520
|
-
//
|
|
632
|
+
// BAPI-1698 — best-effort executing-test evidence, applied AFTER the shared
|
|
633
|
+
// runner made every execution decision (so it never stops a later command)
|
|
634
|
+
// and while the detached checkout still exists. Only an exit-zero fact is
|
|
635
|
+
// assessed, from the output tail the runner already kept.
|
|
636
|
+
const readTextFile = deps.readTextFile ??
|
|
637
|
+
(async () => {
|
|
638
|
+
throw new Error("no reader");
|
|
639
|
+
});
|
|
640
|
+
const qualificationFacts = [];
|
|
521
641
|
for (const fact of facts) {
|
|
522
|
-
|
|
523
|
-
if (
|
|
524
|
-
|
|
642
|
+
let qualificationOutcome = fact.outcome;
|
|
643
|
+
if (fact.outcome === "exited_zero") {
|
|
644
|
+
const command = commands.find((candidate) => candidate.identity === fact.identity);
|
|
645
|
+
if (command !== undefined) {
|
|
646
|
+
const assessment = await assessTestsRanInCheckout({
|
|
647
|
+
argv: command.argv,
|
|
648
|
+
output: fact.output,
|
|
649
|
+
checkoutDir: dir,
|
|
650
|
+
readFile: readTextFile,
|
|
651
|
+
});
|
|
652
|
+
if (assessment === "no_tests")
|
|
653
|
+
qualificationOutcome = GATE_QUALIFICATION_NO_TESTS_RAN;
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
qualificationFacts.push({ ...fact, qualificationOutcome });
|
|
657
|
+
}
|
|
658
|
+
// Ordinals and closed tokens only: no name, argv, output, or path reaches a
|
|
659
|
+
// persistent log (BAPI-1698: a command name is owner-authored text).
|
|
660
|
+
for (const fact of qualificationFacts) {
|
|
661
|
+
deps.log(`[gate_qualification] command ${fact.position}: ${fact.qualificationOutcome}${fact.qualificationOutcome !== GATE_QUALIFICATION_NO_TESTS_RAN && fact.reason ? ` (${fact.reason})` : ""}`);
|
|
662
|
+
if (deps.showLocalOutput && fact.qualificationOutcome !== "exited_zero" && fact.output.trim().length > 0) {
|
|
663
|
+
deps.errorLog(`[gate_qualification] output tail for command ${fact.position}:\n${fact.output}`);
|
|
525
664
|
}
|
|
526
665
|
}
|
|
527
666
|
// 5. An interruption proved nothing about the gate: an inability, never a
|
|
528
667
|
// completed "failed" that the server would record as unqualified. A completed
|
|
529
668
|
// preparation failure, by contrast, IS a result.
|
|
530
|
-
const folded = foldGateQualificationOutcome({
|
|
669
|
+
const folded = foldGateQualificationOutcome({
|
|
670
|
+
facts: qualificationFacts.map((fact) => ({ outcome: fact.qualificationOutcome, reason: fact.reason })),
|
|
671
|
+
preparationFailed,
|
|
672
|
+
databasePreparationFailed,
|
|
673
|
+
});
|
|
531
674
|
if (folded === "interrupted") {
|
|
532
675
|
return inability(GATE_QUALIFICATION_INTERRUPTED, MESSAGES.interrupted);
|
|
533
676
|
}
|
|
534
|
-
const resultFacts =
|
|
677
|
+
const resultFacts = qualificationFacts.map(toResultFact);
|
|
535
678
|
return {
|
|
536
679
|
ok: true,
|
|
537
680
|
result: {
|
|
@@ -543,10 +686,30 @@ export async function runGateQualificationJob(job, input, deps) {
|
|
|
543
686
|
...(installDeclared
|
|
544
687
|
? { dependency_preparation: preparationFailed ? "failed" : "ready" }
|
|
545
688
|
: {}),
|
|
689
|
+
...(workerDatabase !== undefined
|
|
690
|
+
? {
|
|
691
|
+
worker_database_preparation: databaseTarget !== undefined && !databasePreparationFailed ? "ready" : "failed",
|
|
692
|
+
}
|
|
693
|
+
: {}),
|
|
546
694
|
},
|
|
547
695
|
};
|
|
548
696
|
}
|
|
549
697
|
finally {
|
|
698
|
+
// BAPI-1698: the worker database goes first, while its checkout still
|
|
699
|
+
// exists, and only when provisioning returned both a target and a role.
|
|
700
|
+
if (databaseTarget !== undefined && databaseRole !== undefined && deps.workerResources !== undefined) {
|
|
701
|
+
const dropped = await deps.workerResources
|
|
702
|
+
.dropDatabase(databaseTarget, databaseRole)
|
|
703
|
+
.catch(() => ({ kind: "failed" }));
|
|
704
|
+
if (dropped.kind !== "dropped") {
|
|
705
|
+
try {
|
|
706
|
+
deps.errorLog(formatWorkerDatabaseDropFailedLine(jobId, databaseTarget.name));
|
|
707
|
+
}
|
|
708
|
+
catch {
|
|
709
|
+
/* sink */
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
}
|
|
550
713
|
await removeCheckout(deps, dir);
|
|
551
714
|
}
|
|
552
715
|
}
|
|
@@ -560,9 +723,11 @@ export async function runGateQualificationJob(job, input, deps) {
|
|
|
560
723
|
* BAPI-1521: the sealed declaration's `worker_env` is passed with its presence
|
|
561
724
|
* intact — absent keeps the compatibility constants, present replaces them.
|
|
562
725
|
*/
|
|
563
|
-
export function buildGateQualificationEnv(parentEnv, workerEnvOption = {}) {
|
|
726
|
+
export function buildGateQualificationEnv(parentEnv, workerEnvOption = {}, databaseOption = {}) {
|
|
564
727
|
// BAPI-1521: `CI=1` is applied last, so a declaration can never turn it off.
|
|
565
|
-
|
|
728
|
+
// BAPI-1698: a provisioned worker database uses the builder's existing explicit
|
|
729
|
+
// options, so the commands see exactly the database keys a worker would.
|
|
730
|
+
return { ...buildExecutorBaseWorkerEnv(parentEnv, { ...workerEnvOption, ...databaseOption }), CI: "1" };
|
|
566
731
|
}
|
|
567
732
|
/**
|
|
568
733
|
* Production dependencies built from the executor's own boundary.
|
|
@@ -611,5 +776,10 @@ export function createProductionGateQualificationDeps(input) {
|
|
|
611
776
|
...(deps.runDependencyInstall ? { runDependencyInstall: deps.runDependencyInstall } : {}),
|
|
612
777
|
sleep: deps.sleep,
|
|
613
778
|
platform: deps.platform,
|
|
779
|
+
// BAPI-1698: the checkout's root `package.json`, read for test-script indirection only.
|
|
780
|
+
readTextFile: (filePath) => readFile(filePath, "utf8"),
|
|
781
|
+
// BAPI-1698: the executor's existing worker-resource seam, forwarded as is.
|
|
782
|
+
// Only the executor CLI supplies it; the default deps never provision.
|
|
783
|
+
...(deps.workerResources ? { workerResources: deps.workerResources } : {}),
|
|
614
784
|
};
|
|
615
785
|
}
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Best-effort evidence that a gate-qualification command executed tests (BAPI-1698).
|
|
3
|
+
*
|
|
4
|
+
* WHY THIS MODULE EXISTS. A trial run that "passed" because its command was
|
|
5
|
+
* `echo ok`, `pytest --collect-only`, or a runner that found nothing to run tells
|
|
6
|
+
* the owner their gate works when it does not. This module looks for PLAIN signs
|
|
7
|
+
* that an exit-zero command executed no tests, so the qualification can report
|
|
8
|
+
* the qualification-only `no_tests_ran` instead of a pass.
|
|
9
|
+
*
|
|
10
|
+
* It is deliberately conservative. It is not proof that tests ran, and it never
|
|
11
|
+
* tries to be: every unfamiliar, quiet, mixed, or ambiguous case answers `ran`,
|
|
12
|
+
* so a working command is never refused for being unusual. In particular:
|
|
13
|
+
*
|
|
14
|
+
* - argv rules cover a small fixed set of non-test utilities (`echo`, `true`,
|
|
15
|
+
* `ls`, `printf`, `:`) and the listing, collection, help, and version modes of
|
|
16
|
+
* a few well-known runners;
|
|
17
|
+
* - a package-manager `test` script is inspected exactly ONE level deep, and a
|
|
18
|
+
* script with shell control (`&&`, `;`, `|`, quoting, substitution) is `ran`;
|
|
19
|
+
* - an output summary counts only when it has a known runner's own structure
|
|
20
|
+
* with a whole-number count, and any positive execution count wins.
|
|
21
|
+
*
|
|
22
|
+
* Nothing here runs a command, reads beyond the checkout's root `package.json`,
|
|
23
|
+
* or keeps more output than the caller already holds. The output and argv it sees
|
|
24
|
+
* are local only; it returns a closed token and nothing else.
|
|
25
|
+
*/
|
|
26
|
+
import path from "node:path";
|
|
27
|
+
/** Plainly non-test programs. Exiting zero says nothing about tests. */
|
|
28
|
+
const NON_TEST_UTILITIES = new Set(["echo", "true", "ls", "printf", ":"]);
|
|
29
|
+
/** Interpreters that may run pytest as `-m pytest`. */
|
|
30
|
+
const PYTHON_RE = /^python(?:3(?:\.\d+)?)?(?:\.exe)?$/;
|
|
31
|
+
const PYTEST_NON_EXECUTING = new Set(["--collect-only", "--co", "--help", "-h", "--version", "-V"]);
|
|
32
|
+
const JEST_NON_EXECUTING = new Set(["--listTests", "--help", "-h", "--version", "-v"]);
|
|
33
|
+
const VITEST_NON_EXECUTING = new Set(["list", "--help", "-h", "--version", "-v"]);
|
|
34
|
+
const MOCHA_NON_EXECUTING = new Set(["--help", "-h", "--version", "-V", "--dry-run"]);
|
|
35
|
+
const PACKAGE_MANAGERS = new Set(["npm", "yarn", "pnpm"]);
|
|
36
|
+
/** Shell control a script may contain. Its presence makes the script `ran`. */
|
|
37
|
+
const SHELL_CONTROL_RE = /&&|;|\||\|\||[`$'"<>()\\]/;
|
|
38
|
+
function baseName(program) {
|
|
39
|
+
return path.basename(program.replace(/\\/g, "/"));
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Strip one leading launcher that only resolves a program (`npx`, `uv run`,
|
|
43
|
+
* `poetry run`, `pipenv run`, `pnpm exec`, `yarn exec`), with its own flags.
|
|
44
|
+
*/
|
|
45
|
+
function stripLauncher(argv) {
|
|
46
|
+
if (argv.length === 0)
|
|
47
|
+
return argv;
|
|
48
|
+
const first = baseName(argv[0]);
|
|
49
|
+
let rest = null;
|
|
50
|
+
if (first === "npx")
|
|
51
|
+
rest = argv.slice(1);
|
|
52
|
+
else if ((first === "uv" || first === "poetry" || first === "pipenv") && argv[1] === "run")
|
|
53
|
+
rest = argv.slice(2);
|
|
54
|
+
else if ((first === "pnpm" || first === "yarn") && argv[1] === "exec")
|
|
55
|
+
rest = argv.slice(2);
|
|
56
|
+
if (rest === null)
|
|
57
|
+
return argv;
|
|
58
|
+
let index = 0;
|
|
59
|
+
while (index < rest.length && rest[index].startsWith("-"))
|
|
60
|
+
index += 1;
|
|
61
|
+
return rest.slice(index);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Classify a command's argv on its own. `no_tests` only for a plain non-test
|
|
65
|
+
* utility or a well-known runner in a mode that executes no test.
|
|
66
|
+
*/
|
|
67
|
+
export function classifyArgv(argv) {
|
|
68
|
+
const resolved = stripLauncher(argv);
|
|
69
|
+
if (resolved.length === 0)
|
|
70
|
+
return "ran";
|
|
71
|
+
const program = baseName(resolved[0]);
|
|
72
|
+
const args = resolved.slice(1);
|
|
73
|
+
if (NON_TEST_UTILITIES.has(program))
|
|
74
|
+
return "no_tests";
|
|
75
|
+
const any = (set) => args.some((arg) => set.has(arg));
|
|
76
|
+
if (program === "pytest" || program === "py.test")
|
|
77
|
+
return any(PYTEST_NON_EXECUTING) ? "no_tests" : "ran";
|
|
78
|
+
if (PYTHON_RE.test(program) && args[0] === "-m" && args[1] === "pytest") {
|
|
79
|
+
return args.slice(2).some((arg) => PYTEST_NON_EXECUTING.has(arg)) ? "no_tests" : "ran";
|
|
80
|
+
}
|
|
81
|
+
if (program === "jest")
|
|
82
|
+
return any(JEST_NON_EXECUTING) ? "no_tests" : "ran";
|
|
83
|
+
if (program === "vitest")
|
|
84
|
+
return any(VITEST_NON_EXECUTING) ? "no_tests" : "ran";
|
|
85
|
+
if (program === "mocha")
|
|
86
|
+
return any(MOCHA_NON_EXECUTING) ? "no_tests" : "ran";
|
|
87
|
+
return "ran";
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* True when `argv` runs the package `test` script through npm, yarn, or pnpm:
|
|
91
|
+
* `npm test`, `npm t`, `npm run test`, `yarn test`, `yarn run test`, `pnpm test`,
|
|
92
|
+
* `pnpm run test`. Returns the arguments forwarded after `--`, or null.
|
|
93
|
+
*/
|
|
94
|
+
function packageTestInvocation(argv) {
|
|
95
|
+
if (argv.length < 2)
|
|
96
|
+
return null;
|
|
97
|
+
const manager = baseName(argv[0]);
|
|
98
|
+
if (!PACKAGE_MANAGERS.has(manager))
|
|
99
|
+
return null;
|
|
100
|
+
let index = 1;
|
|
101
|
+
if (argv[index] === "run" || argv[index] === "run-script")
|
|
102
|
+
index += 1;
|
|
103
|
+
const script = argv[index];
|
|
104
|
+
if (script !== "test" && !(manager === "npm" && script === "t" && index === 1))
|
|
105
|
+
return null;
|
|
106
|
+
const rest = argv.slice(index + 1);
|
|
107
|
+
if (rest.length === 0)
|
|
108
|
+
return { forwarded: [] };
|
|
109
|
+
// Only a plain `-- args` tail is understood; anything else is not ours to read.
|
|
110
|
+
if (rest[0] !== "--")
|
|
111
|
+
return manager === "npm" ? null : { forwarded: [...rest] };
|
|
112
|
+
return { forwarded: rest.slice(1) };
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Classify a package `test` script exactly one level deep. Shell control makes
|
|
116
|
+
* it `ran`; a nested script (`npm run test:unit`) is not followed and is `ran`.
|
|
117
|
+
*/
|
|
118
|
+
function classifyPackageScript(script, forwarded) {
|
|
119
|
+
const trimmed = script.trim();
|
|
120
|
+
if (trimmed.length === 0 || SHELL_CONTROL_RE.test(trimmed))
|
|
121
|
+
return "ran";
|
|
122
|
+
const tokens = trimmed.split(/\s+/);
|
|
123
|
+
if (PACKAGE_MANAGERS.has(baseName(tokens[0])))
|
|
124
|
+
return "ran";
|
|
125
|
+
return classifyArgv([...tokens, ...forwarded]);
|
|
126
|
+
}
|
|
127
|
+
// ---------------------------------------------------------------------------
|
|
128
|
+
// Output summaries
|
|
129
|
+
// ---------------------------------------------------------------------------
|
|
130
|
+
/** Known runners' own "nothing ran" summary lines. Anchored; whole counts only. */
|
|
131
|
+
const ZERO_TEST_SUMMARIES = [
|
|
132
|
+
// pytest
|
|
133
|
+
/^=+ no tests ran(?: in \d+(?:\.\d+)?s)? =+$/m,
|
|
134
|
+
/^collected 0 items\s*$/m,
|
|
135
|
+
// unittest
|
|
136
|
+
/^Ran 0 tests in \d+(?:\.\d+)?s$/m,
|
|
137
|
+
// jest / vitest with pass-with-no-tests
|
|
138
|
+
/^No tests found, exiting with code 0$/m,
|
|
139
|
+
/^No test files found, exiting with code 0$/m,
|
|
140
|
+
/^Tests:\s+0 total$/m,
|
|
141
|
+
// mocha
|
|
142
|
+
/^\s*0 passing(?: \(\d+m?s\))?\s*$/m,
|
|
143
|
+
// node:test (TAP)
|
|
144
|
+
/^# tests 0$/m,
|
|
145
|
+
];
|
|
146
|
+
/** Recognized positive execution counts. Any one of these means tests ran. */
|
|
147
|
+
const POSITIVE_COUNTS = [
|
|
148
|
+
/\b[1-9]\d* (?:passed|failed|errors?|xfailed|xpassed)\b/,
|
|
149
|
+
/^Ran [1-9]\d* tests? in /m,
|
|
150
|
+
/^Tests:\s+.*\b[1-9]\d* (?:passed|failed|total)\b/m,
|
|
151
|
+
/^\s*[1-9]\d* (?:passing|failing|pending)\b/m,
|
|
152
|
+
/^# (?:tests|pass|fail) [1-9]\d*$/m,
|
|
153
|
+
/^ok\s+\S+\s+\d/m,
|
|
154
|
+
/^--- (?:PASS|FAIL): /m,
|
|
155
|
+
/^collected [1-9]\d* items?\b/m,
|
|
156
|
+
];
|
|
157
|
+
const GO_NO_TEST_FILES_RE = /^\?\s+\S+\s+\[no test files\]$/;
|
|
158
|
+
function isGoTest(argv) {
|
|
159
|
+
const resolved = stripLauncher(argv);
|
|
160
|
+
return resolved.length >= 2 && baseName(resolved[0]) === "go" && resolved[1] === "test";
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Classify the output tail. `no_tests` only when a known runner's own zero-test
|
|
164
|
+
* summary is present and no positive execution count is; `go test` counts only
|
|
165
|
+
* when EVERY nonblank line reports no test files.
|
|
166
|
+
*/
|
|
167
|
+
export function classifyOutput(argv, output) {
|
|
168
|
+
if (POSITIVE_COUNTS.some((re) => re.test(output)))
|
|
169
|
+
return "ran";
|
|
170
|
+
if (isGoTest(argv)) {
|
|
171
|
+
const lines = output.split(/\r?\n/).map((line) => line.trim()).filter((line) => line.length > 0);
|
|
172
|
+
return lines.length > 0 && lines.every((line) => GO_NO_TEST_FILES_RE.test(line)) ? "no_tests" : "ran";
|
|
173
|
+
}
|
|
174
|
+
return ZERO_TEST_SUMMARIES.some((re) => re.test(output)) ? "no_tests" : "ran";
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* The pure classifier: argv first (including a resolved package `test` script,
|
|
178
|
+
* one level deep), then the output tail. Never throws; defaults to `ran`.
|
|
179
|
+
*/
|
|
180
|
+
export function assessTestsRan(input) {
|
|
181
|
+
try {
|
|
182
|
+
if (classifyArgv(input.argv) === "no_tests")
|
|
183
|
+
return "no_tests";
|
|
184
|
+
const invocation = packageTestInvocation(input.argv);
|
|
185
|
+
if (invocation !== null && typeof input.packageTestScript === "string") {
|
|
186
|
+
if (classifyPackageScript(input.packageTestScript, invocation.forwarded) === "no_tests")
|
|
187
|
+
return "no_tests";
|
|
188
|
+
}
|
|
189
|
+
return classifyOutput(input.argv, input.output);
|
|
190
|
+
}
|
|
191
|
+
catch {
|
|
192
|
+
return "ran";
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* The checkout's root `package.json` `test` script when `argv` runs it through
|
|
197
|
+
* npm, yarn, or pnpm; `null` on any read or parse error, a missing script, or an
|
|
198
|
+
* unusable shape. Never throws.
|
|
199
|
+
*/
|
|
200
|
+
export async function resolvePackageTestScript(argv, checkoutDir, readFile) {
|
|
201
|
+
if (packageTestInvocation(argv) === null)
|
|
202
|
+
return null;
|
|
203
|
+
try {
|
|
204
|
+
const parsed = JSON.parse(await readFile(path.join(checkoutDir, "package.json")));
|
|
205
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed))
|
|
206
|
+
return null;
|
|
207
|
+
const scripts = parsed.scripts;
|
|
208
|
+
if (typeof scripts !== "object" || scripts === null || Array.isArray(scripts))
|
|
209
|
+
return null;
|
|
210
|
+
const test = scripts.test;
|
|
211
|
+
return typeof test === "string" ? test : null;
|
|
212
|
+
}
|
|
213
|
+
catch {
|
|
214
|
+
return null;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* The checkout-reading adapter: resolves the package `test` script (when argv
|
|
219
|
+
* runs one) and classifies. Any read or parse failure falls back to classifying
|
|
220
|
+
* without the script, which can only answer `ran` for the indirection itself.
|
|
221
|
+
* Never throws.
|
|
222
|
+
*/
|
|
223
|
+
export async function assessTestsRanInCheckout(input) {
|
|
224
|
+
let packageTestScript = null;
|
|
225
|
+
try {
|
|
226
|
+
packageTestScript = await resolvePackageTestScript(input.argv, input.checkoutDir, input.readFile);
|
|
227
|
+
}
|
|
228
|
+
catch {
|
|
229
|
+
packageTestScript = null;
|
|
230
|
+
}
|
|
231
|
+
return assessTestsRan({ argv: input.argv, output: input.output, packageTestScript });
|
|
232
|
+
}
|