@bridge_gpt/mcp-server 0.2.75 → 0.2.77
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 +8 -6
- package/build/agents.generated.js +5 -5
- package/build/cli-dispatch.js +333 -0
- package/build/codex-auto-recovery.js +25 -7
- package/build/commands.generated.js +8 -8
- package/build/conductor/bridge-api-client.js +193 -13
- package/build/conductor/declare-blocked.js +146 -7
- package/build/conductor/driver-pass.js +8 -0
- package/build/conductor/driver-register.js +8 -2
- package/build/conductor/epic-implementer-cli.js +15 -10
- package/build/conductor/epic-server-journal.js +52 -22
- 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/install-doctor.js +30 -2
- package/build/conductor/launch-plan.js +28 -7
- package/build/conductor/local-merge.js +55 -13
- package/build/conductor/pr-ci-producer.js +12 -3
- package/build/conductor/readiness-prerequisites.js +89 -2
- package/build/conductor/readiness-sections.js +46 -13
- package/build/conductor/readiness.js +3 -40
- package/build/conductor/recovery-cli.js +14 -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/docs.generated.js +67 -4
- package/build/doctor.js +97 -1
- package/build/drive-epic.js +625 -33
- package/build/engine-paths.js +10 -0
- package/build/epic-coherence-input-cli.js +105 -10
- package/build/epic-coherence-input.js +877 -4
- package/build/epic-coherence-input.test-fixtures.js +117 -0
- package/build/epic-implementer-bin.js +947 -120
- package/build/epic-implementer-env.js +2 -2
- package/build/epic-launch-context.js +8 -1
- package/build/epic-shared/cut-protocol.js +55 -3
- package/build/executor/completion-contract.js +14 -1
- package/build/executor/failure-reason-codes.js +2 -0
- package/build/executor/guarded-fast-forward-push.js +25 -2
- package/build/executor/integration-job.js +56 -2
- package/build/executor/job-runner.js +87 -28
- package/build/executor/likely-tests.js +78 -6
- package/build/executor/merge-job.js +45 -1
- package/build/executor/permissions.js +187 -2
- package/build/executor/provider-checks.js +101 -5
- package/build/executor/rebase-finalization.js +29 -27
- package/build/executor/reconcile-overlap-job.js +70 -17
- package/build/executor/rename-aside.js +265 -0
- package/build/executor/required-work-ledger.js +89 -6
- package/build/executor/resume-pre-spawn.js +32 -8
- package/build/executor/runner.js +26 -4
- package/build/executor/types.js +121 -0
- package/build/executor/worktree.js +39 -2
- package/build/index.js +2500 -495
- package/build/init.js +16 -0
- package/build/install-bridge-conductor-answers.js +4 -0
- package/build/install-bridge-conductor-apply.js +10 -0
- package/build/install-bridge-conductor-assessment.js +84 -0
- package/build/install-bridge-conductor-contracts.js +9 -1
- package/build/install-bridge-conductor-setup.js +103 -3
- package/build/install-bridge-conductor.js +440 -812
- package/build/install-bridge.js +4 -11
- package/build/language-catalog.generated.js +2649 -0
- package/build/mcp-host-config.js +54 -37
- package/build/phase-context-git-probe.js +16 -0
- package/build/pipelines.generated.js +47 -19
- package/build/plan-execution-ledger.js +35 -0
- package/build/plan-generation.js +34 -0
- package/build/plane/build-freshness.js +6 -0
- package/build/plane/cli.js +12 -5
- package/build/plane/plane-freshness.js +43 -26
- package/build/printed-remedy-commands.js +17 -0
- package/build/readiness-prerequisites.generated.js +28 -0
- package/build/readme.generated.js +1 -1
- package/build/run-unit-tests-launcher.js +3 -1
- package/build/secret-redaction.js +3 -0
- package/build/server.js +7946 -0
- package/build/setup-epic.js +41 -8
- package/build/start-tickets-prereqs.js +3 -6
- package/build/test-support/console-guard.js +30 -0
- package/build/test-support/create-preview-world.js +232 -0
- package/build/test-support/module-imports.js +155 -0
- package/build/test-support/server-client.js +96 -0
- package/build/test-support/stdio-server.js +146 -0
- package/build/ticket-delivery.js +65 -0
- package/build/v2-readiness-requirements.js +39 -5
- package/build/version.generated.js +3 -3
- package/build/worktree-core.js +51 -7
- package/docs/EPIC-IMPLEMENTER.md +150 -2
- package/docs/epic-implementer/getting-started.md +5 -1
- package/package.json +3 -3
- package/pipelines/implement-ticket.json +2 -2
- package/pipelines/learn-repository.json +19 -1
package/build/setup-epic.js
CHANGED
|
@@ -95,7 +95,8 @@ import { formatEpicLaunchChannelIdentity, getPinnedEpicLaunchPolicy, readEpicLau
|
|
|
95
95
|
import { mapLegacyMergeExecutionModeToPolicyMode, resolveMergeExecutionMode, } from "./merge-pull-request.js";
|
|
96
96
|
import { MERGE_EXECUTION_INELIGIBLE, MERGE_EXECUTION_MODE_GITHUB_ACTIONS, MERGE_WORKFLOW_CODEOWNER_INSTRUCTION, MERGE_WORKFLOW_REMEDY_COMMAND, } from "./conductor/merge-execution-contract.js";
|
|
97
97
|
import { classifyMergeExecutionEligibility } from "./conductor/merge-execution-eligibility.js";
|
|
98
|
-
import {
|
|
98
|
+
import { repositoryReadinessVerdict, requiredChecksAdmissionRemedy, requiredChecksAdmissionVerdict, } from "./conductor/repository-workflow-remedy.js";
|
|
99
|
+
import { gateProfileAwareRepositoryWorkflowRemedy } from "./conductor/readiness.js";
|
|
99
100
|
import { resolveTrackedPaths } from "./git-reachability.js";
|
|
100
101
|
import { validateBranchName } from "./base-ref.js";
|
|
101
102
|
import { TICKET_KEY_PATTERN } from "./ticket-key-utils.js";
|
|
@@ -1827,6 +1828,10 @@ function uncertainty(reason) {
|
|
|
1827
1828
|
export function isSetupEpicPrerequisiteWarning(value) {
|
|
1828
1829
|
return typeof value === "object" && value !== null && value.warning === true;
|
|
1829
1830
|
}
|
|
1831
|
+
/** BAPI-1714 — confirmed -> true, denied -> false, unknown -> null. */
|
|
1832
|
+
function verdictToFact(verdict) {
|
|
1833
|
+
return verdict === "confirmed" ? true : verdict === "denied" ? false : null;
|
|
1834
|
+
}
|
|
1830
1835
|
/** The unattended facts of either input, each `null` when the input does not establish it. */
|
|
1831
1836
|
function unattendedFactsOf(input) {
|
|
1832
1837
|
if (input === null)
|
|
@@ -1849,7 +1854,10 @@ function unattendedFactsOf(input) {
|
|
|
1849
1854
|
return {
|
|
1850
1855
|
conductorAllowed: bool(unattended.conductor_allowed),
|
|
1851
1856
|
webhookDefaultDeclared: bool(unattended.notify_webhook_default_declared),
|
|
1852
|
-
|
|
1857
|
+
// BAPI-1714 — the shared verdict: `false` only for a PROVEN deficiency (the
|
|
1858
|
+
// server flag is false AND its admission record says denied). An unverifiable
|
|
1859
|
+
// read is `null`, which continues as uncertainty and never refuses.
|
|
1860
|
+
repositoryReadinessConfirmed: verdictToFact(repositoryReadinessVerdict(input)),
|
|
1853
1861
|
emailAvailable: bool(unattended.escalation_email_available),
|
|
1854
1862
|
emailTransport: transport !== undefined &&
|
|
1855
1863
|
transport.severity !== null &&
|
|
@@ -1859,6 +1867,9 @@ function unattendedFactsOf(input) {
|
|
|
1859
1867
|
: "unknown",
|
|
1860
1868
|
};
|
|
1861
1869
|
}
|
|
1870
|
+
/** BAPI-1714 — the snapshot-false refusal: a snapshot holds no workflow detail to name. */
|
|
1871
|
+
const SNAPSHOT_REPOSITORY_READINESS_REMEDY = "The repository's review or CI workflow is missing something an auto-merging run needs. " +
|
|
1872
|
+
`Run \`npx -y ${MCP_PACKAGE_NAME} epic-implementer readiness\` to see what; fix it, or pass \`--attended\`.`;
|
|
1862
1873
|
export function evaluateSetupEpicUnattendedPrerequisites(readiness, requestedPolicy) {
|
|
1863
1874
|
const facts = unattendedFactsOf(readiness);
|
|
1864
1875
|
// A missing `unattended` block proves nothing (an older server, or an unreadable
|
|
@@ -1919,13 +1930,20 @@ export function evaluateSetupEpicUnattendedPrerequisites(readiness, requestedPol
|
|
|
1919
1930
|
}
|
|
1920
1931
|
if (facts.repositoryReadinessConfirmed === false) {
|
|
1921
1932
|
// BAPI-1359: the shared formatter names the specific missing item; the reason
|
|
1922
|
-
// code and the trailing sentence are unchanged.
|
|
1923
|
-
//
|
|
1933
|
+
// code and the trailing sentence are unchanged.
|
|
1934
|
+
//
|
|
1935
|
+
// BAPI-1714: a full report gets the gate-aware remedy, which names only the
|
|
1936
|
+
// failing workflow section (no fixed opening that could name a workflow that
|
|
1937
|
+
// is fine). A snapshot carries no workflow detail, so it gets one fixed,
|
|
1938
|
+
// truthful message that points at the read-only readiness command. Neither
|
|
1939
|
+
// says "could not verify" or "Retry readiness": this refusal is a PROVEN
|
|
1940
|
+
// deficiency, never an unknown.
|
|
1941
|
+
const remedy = readiness !== null && !isReadinessSnapshot(readiness)
|
|
1942
|
+
? gateProfileAwareRepositoryWorkflowRemedy(readiness)
|
|
1943
|
+
: SNAPSHOT_REPOSITORY_READINESS_REMEDY;
|
|
1924
1944
|
return {
|
|
1925
1945
|
reason: "repository_readiness_unconfirmed",
|
|
1926
|
-
message:
|
|
1927
|
-
"epic-implementer-ci workflows to be CONFIRMED on the default branch, and they are not. " +
|
|
1928
|
-
`${repositoryWorkflowRemedy(readiness !== null && !isReadinessSnapshot(readiness) ? readiness : null)} No run was created.`,
|
|
1946
|
+
message: `${remedy} No run was created.`,
|
|
1929
1947
|
};
|
|
1930
1948
|
}
|
|
1931
1949
|
if (facts.repositoryReadinessConfirmed === null)
|
|
@@ -4011,8 +4029,12 @@ async function executeSetupEpic(argv, overrides, runIdSink, handoff) {
|
|
|
4011
4029
|
if (classified.status === "behind_target") {
|
|
4012
4030
|
// One plain push (no force, no leading '+'). Whatever it returns, the remote
|
|
4013
4031
|
// is re-read once; only an exact match with the cut lets setup continue.
|
|
4032
|
+
// `--no-verify`, as in the exact cut (epic-shared/cut-protocol.ts): this push
|
|
4033
|
+
// sends no new code, only moves the branch forward to the canonical indexed
|
|
4034
|
+
// commit. A repository's pre-push hook (tests, Husky, pre-commit) would
|
|
4035
|
+
// otherwise run here with an inherited environment and can block the launch.
|
|
4014
4036
|
try {
|
|
4015
|
-
await runGit(gitDeps, ["push", "origin", `${cutCommitSha}:refs/heads/${branch}`]);
|
|
4037
|
+
await runGit(gitDeps, ["push", "--no-verify", "origin", `${cutCommitSha}:refs/heads/${branch}`]);
|
|
4016
4038
|
}
|
|
4017
4039
|
catch { /* judged by the re-read below */ }
|
|
4018
4040
|
let reread;
|
|
@@ -4233,6 +4255,17 @@ async function executeSetupEpic(argv, overrides, runIdSink, handoff) {
|
|
|
4233
4255
|
deps.errorLog(`setup-epic REFUSED (${unattended.reason}): ${unattended.message}`);
|
|
4234
4256
|
return 1;
|
|
4235
4257
|
}
|
|
4258
|
+
// BAPI-1526 — first approval would refuse this create's required checks.
|
|
4259
|
+
// `launchReadiness` is the policy-aware report for this same
|
|
4260
|
+
// `composedForCreate`, so the server already exempted any policy approval
|
|
4261
|
+
// would exempt. Only a proven denial refuses, and only before a run exists:
|
|
4262
|
+
// a `null` report (the POST failed) or any other record continues, and
|
|
4263
|
+
// approval stays the authority. A drive-epic create delegates here, so both
|
|
4264
|
+
// entry points refuse before the run row exists.
|
|
4265
|
+
if (existingRunId === null && requiredChecksAdmissionVerdict(launchReadiness) === "denied") {
|
|
4266
|
+
deps.errorLog(`setup-epic REFUSED (required_checks_admission_denied): ${requiredChecksAdmissionRemedy(launchReadiness)} No run was created.`);
|
|
4267
|
+
return 1;
|
|
4268
|
+
}
|
|
4236
4269
|
}
|
|
4237
4270
|
}
|
|
4238
4271
|
try {
|
|
@@ -525,12 +525,9 @@ export async function resolveMainWorktreePathForDoctor(deps) {
|
|
|
525
525
|
/**
|
|
526
526
|
* Secret-free remediation hint shared by the Claude MCP shadowing descriptor.
|
|
527
527
|
*
|
|
528
|
-
*
|
|
529
|
-
*
|
|
530
|
-
* module
|
|
531
|
-
* identifiers ANYWHERE in the source — including comments and user-facing prose,
|
|
532
|
-
* which is why the advice below is phrased as "delete, or move aside". Keep every
|
|
533
|
-
* such identifier out of this file, even inside a comment like this one.
|
|
528
|
+
* The prereqs module performs no filesystem or credential writes, so the advice
|
|
529
|
+
* below tells the user what to do rather than doing it. `module-boundaries.test.ts`
|
|
530
|
+
* holds the rule: this module imports no filesystem module and no credential writer.
|
|
534
531
|
*/
|
|
535
532
|
const CLAUDE_MCP_SHADOWING_HINT = `Run \`${CLAUDE_MCP_SHADOWING_REMEDIATION_COMMAND}\` to clear the '${MCP_SERVER_NAME}' MCP ` +
|
|
536
533
|
"registration in ~/.claude.json (use the matching scope if it is registered at user scope, " +
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fail any test in the calling file that writes through `console.*`.
|
|
3
|
+
*
|
|
4
|
+
* Some modules must never log at all — the merge path handles API keys, merge
|
|
5
|
+
* tokens, and provider bodies, and a stray `console.error(err)` or
|
|
6
|
+
* `console.log(headers)` is how one leaks. Calling this once at the top level of
|
|
7
|
+
* a test file wraps every console method for each test and fails the test that
|
|
8
|
+
* used one, so every path the file's tests already drive is checked.
|
|
9
|
+
*/
|
|
10
|
+
import assert from "node:assert/strict";
|
|
11
|
+
import { afterEach, beforeEach, mock } from "node:test";
|
|
12
|
+
const METHODS = ["log", "info", "warn", "error", "debug", "trace"];
|
|
13
|
+
export function failOnConsoleOutput() {
|
|
14
|
+
let calls = [];
|
|
15
|
+
let restore = [];
|
|
16
|
+
beforeEach(() => {
|
|
17
|
+
calls = [];
|
|
18
|
+
restore = METHODS.map((name) => {
|
|
19
|
+
const spy = mock.method(console, name, (...parts) => {
|
|
20
|
+
calls.push(`console.${name}(${parts.map(String).join(" ")})`);
|
|
21
|
+
});
|
|
22
|
+
return () => spy.mock.restore();
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
afterEach(() => {
|
|
26
|
+
for (const undo of restore)
|
|
27
|
+
undo();
|
|
28
|
+
assert.deepEqual(calls, [], "this module must not write through console.*");
|
|
29
|
+
});
|
|
30
|
+
}
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A small, hermetic `drive-epic` CREATE-preview world for tests outside `drive-epic.test.ts`.
|
|
3
|
+
*
|
|
4
|
+
* It is the same recipe the drive-epic suite uses: every boundary is an in-memory fake, every
|
|
5
|
+
* plane or launch seam throws when reached, and the plan comes from a supplied `--plan-file`
|
|
6
|
+
* whose DAG is served from memory. A preview built here reaches the decision `create`, so the
|
|
7
|
+
* launch-plan facts, and with them the BAPI-1718 UI readiness advisory, are collected.
|
|
8
|
+
*
|
|
9
|
+
* `runDriveEpicCli` merges its overrides over the production defaults. Every seam a create
|
|
10
|
+
* preview could reach is therefore named here, so a test never touches the network, `gh`, `git`,
|
|
11
|
+
* the owner's home, or a real credential.
|
|
12
|
+
*/
|
|
13
|
+
import { resolve as nativePath } from "node:path";
|
|
14
|
+
import { runDriveEpicCli } from "../drive-epic.js";
|
|
15
|
+
import { buildEpicLaunchContext } from "../epic-launch-context.js";
|
|
16
|
+
import { inspectHostSleep } from "../plane/plane-freshness.js";
|
|
17
|
+
export const PREVIEW_WORLD_SENTINEL_KEY = "preview-world-secret-do-not-print";
|
|
18
|
+
export const PREVIEW_WORLD_EPIC = "BAPI-1275";
|
|
19
|
+
export const PREVIEW_WORLD_PLAN_PATH = nativePath("/supplied/plan.json");
|
|
20
|
+
export const PREVIEW_WORLD_ACCESS = {
|
|
21
|
+
repoName: "bapi",
|
|
22
|
+
apiKey: PREVIEW_WORLD_SENTINEL_KEY,
|
|
23
|
+
baseUrl: "https://example.invalid",
|
|
24
|
+
};
|
|
25
|
+
/** A fully green readiness report: the preview reaches `create`. */
|
|
26
|
+
export function greenPreviewReadiness(repoName = "bapi") {
|
|
27
|
+
return {
|
|
28
|
+
repo_name: repoName,
|
|
29
|
+
merge_execution: {
|
|
30
|
+
branch_scope: "default_branch",
|
|
31
|
+
branch_protection_probe_succeeded: true,
|
|
32
|
+
branch_protection_actions_bot_admitted: true,
|
|
33
|
+
merge_workflow_probe_succeeded: true,
|
|
34
|
+
merge_workflow_present: true,
|
|
35
|
+
merge_workflow_enabled: true,
|
|
36
|
+
merge_workflow_version: 1,
|
|
37
|
+
merge_workflow_token_write_authority: true,
|
|
38
|
+
},
|
|
39
|
+
bring_up: {
|
|
40
|
+
migration_readable: true,
|
|
41
|
+
database_migration_current: true,
|
|
42
|
+
heartbeat_readable: true,
|
|
43
|
+
worker_present: true,
|
|
44
|
+
fresh_reconciler_count: 1,
|
|
45
|
+
single_transition_authority: true,
|
|
46
|
+
},
|
|
47
|
+
supervisor: {
|
|
48
|
+
setup_present: true,
|
|
49
|
+
setup_source: "project_default",
|
|
50
|
+
setup_created_at: null,
|
|
51
|
+
setup_updated_at: null,
|
|
52
|
+
config_present: true,
|
|
53
|
+
config_source: "project_default",
|
|
54
|
+
config_created_at: null,
|
|
55
|
+
config_updated_at: null,
|
|
56
|
+
required_checks_count: 2,
|
|
57
|
+
required_checks_empty: false,
|
|
58
|
+
auto_merge_enabled: true,
|
|
59
|
+
merge_approval_required_set: true,
|
|
60
|
+
review_policy_alignment: null,
|
|
61
|
+
review_policy_present: true,
|
|
62
|
+
},
|
|
63
|
+
github: {
|
|
64
|
+
credentials_readable: true,
|
|
65
|
+
owner_resolved: true,
|
|
66
|
+
repo_id_resolved: true,
|
|
67
|
+
installation_id_resolved: true,
|
|
68
|
+
credentials_complete: true,
|
|
69
|
+
actions_probe_succeeded: true,
|
|
70
|
+
actions_permission_present: true,
|
|
71
|
+
actions_permission_level: "read",
|
|
72
|
+
actions_write: false,
|
|
73
|
+
},
|
|
74
|
+
reconciler: {
|
|
75
|
+
liveness_readable: true,
|
|
76
|
+
last_tick_at: "2026-08-21T00:00:00Z",
|
|
77
|
+
last_tick_age_seconds: 5,
|
|
78
|
+
stale: false,
|
|
79
|
+
active_run_count: 0,
|
|
80
|
+
expired_lease_count: 0,
|
|
81
|
+
},
|
|
82
|
+
executor: {
|
|
83
|
+
liveness_readable: true,
|
|
84
|
+
last_seen_at: "2026-08-21T00:00:00Z",
|
|
85
|
+
last_seen_age_seconds: 5,
|
|
86
|
+
ready: true,
|
|
87
|
+
},
|
|
88
|
+
thresholds: { reconciler_stale_after_seconds: 120, executor_stale_after_seconds: 120 },
|
|
89
|
+
review_workflow: null,
|
|
90
|
+
conductor_ci_workflow: null,
|
|
91
|
+
unattended: {
|
|
92
|
+
conductor_allowed: true,
|
|
93
|
+
notify_webhook_default_declared: true,
|
|
94
|
+
notify_webhook_default_verified: true,
|
|
95
|
+
repository_readiness_confirmed: true,
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
function refuse(name) {
|
|
100
|
+
throw new Error(`${name} must not be reached by a create preview`);
|
|
101
|
+
}
|
|
102
|
+
export function createPreviewWorld(o) {
|
|
103
|
+
const out = [];
|
|
104
|
+
const err = [];
|
|
105
|
+
const mutations = [];
|
|
106
|
+
const repoName = o.repoName ?? PREVIEW_WORLD_ACCESS.repoName;
|
|
107
|
+
const access = { ...PREVIEW_WORLD_ACCESS, repoName };
|
|
108
|
+
const readiness = greenPreviewReadiness(repoName);
|
|
109
|
+
const dag = JSON.stringify({
|
|
110
|
+
plan_version: 1,
|
|
111
|
+
nodes: o.keys.map((ticket_key, i) => ({
|
|
112
|
+
ticket_key,
|
|
113
|
+
status: "planned",
|
|
114
|
+
depends_on: i === 0 ? [] : [o.keys[i - 1]],
|
|
115
|
+
automations: [],
|
|
116
|
+
...(o.touchedFiles?.[ticket_key] !== undefined ? { touched_files: o.touchedFiles[ticket_key] } : {}),
|
|
117
|
+
})),
|
|
118
|
+
edges: o.keys.slice(1).map((key, i) => ({ from: o.keys[i], to: key })),
|
|
119
|
+
});
|
|
120
|
+
const deps = {
|
|
121
|
+
inspectRepositoryIdentity: async () => ({ repoRoot: nativePath("/repo"), isBridge: true }),
|
|
122
|
+
resolveAccess: async () => ({ ok: true, access }),
|
|
123
|
+
adoptLaunchTarget: () => undefined,
|
|
124
|
+
readReadiness: async () => readiness,
|
|
125
|
+
// A launch reads no readiness; the preview's stored snapshot is never read back here.
|
|
126
|
+
readScopeBaseBranch: async () => "main",
|
|
127
|
+
readLaunchContext: async (binding) => ({
|
|
128
|
+
kind: "usable",
|
|
129
|
+
value: {
|
|
130
|
+
sourceVersion: 2,
|
|
131
|
+
context: buildEpicLaunchContext({
|
|
132
|
+
epicKey: binding.epicKey,
|
|
133
|
+
baseBranch: binding.baseBranch,
|
|
134
|
+
targetBaseUrl: binding.targetBaseUrl,
|
|
135
|
+
writtenAt: binding.now,
|
|
136
|
+
readiness: { kind: "ready", readiness, attempts: 1 },
|
|
137
|
+
repoName: binding.repository?.repoName ?? null,
|
|
138
|
+
isBridge: binding.repository?.isBridge ?? null,
|
|
139
|
+
serverPlanDigest: "digest-0123456789",
|
|
140
|
+
}),
|
|
141
|
+
},
|
|
142
|
+
}),
|
|
143
|
+
writeLaunchContext: async () => ({ ok: true, path: "(not written in tests)" }),
|
|
144
|
+
writeLaunchOutcome: async () => ({ ok: true, path: "(not written in tests)" }),
|
|
145
|
+
reportLaunch: () => undefined,
|
|
146
|
+
resolveDocsDir: async () => ({ ok: true, docsDir: nativePath("/repo/docs/tmp") }),
|
|
147
|
+
discoveryFs: {
|
|
148
|
+
readdir: async () => { throw Object.assign(new Error("ENOENT"), { code: "ENOENT" }); },
|
|
149
|
+
readFile: async () => { throw new Error("ENOENT"); },
|
|
150
|
+
},
|
|
151
|
+
readPlanDag: async () => dag,
|
|
152
|
+
readPolicyFile: async () => { throw new Error("ENOENT: no fixture policy"); },
|
|
153
|
+
readLiveEpicRun: async () => ({ kind: "none" }),
|
|
154
|
+
readEligibilityArtifact: async () => { throw new Error("ENOENT: no fixture artifact"); },
|
|
155
|
+
previewSetupEpic: async () => ({
|
|
156
|
+
exitCode: 0,
|
|
157
|
+
stdout: [JSON.stringify({
|
|
158
|
+
dry_run: true,
|
|
159
|
+
epic_key: PREVIEW_WORLD_EPIC,
|
|
160
|
+
repo_name: repoName,
|
|
161
|
+
plan_version: 1,
|
|
162
|
+
local_plan_hash: "sha256:abc",
|
|
163
|
+
existing_run_id: null,
|
|
164
|
+
feature_branch: `epic/${PREVIEW_WORLD_EPIC}`,
|
|
165
|
+
server_validated: true,
|
|
166
|
+
policy_applied: "absent",
|
|
167
|
+
warnings: [],
|
|
168
|
+
create_policy: {
|
|
169
|
+
posture: "unattended",
|
|
170
|
+
v2_auto_merge_enabled: true,
|
|
171
|
+
merge_execution_mode: "machine_token",
|
|
172
|
+
integration_preparation: { enabled: true },
|
|
173
|
+
},
|
|
174
|
+
})],
|
|
175
|
+
stderr: [],
|
|
176
|
+
}),
|
|
177
|
+
inspectRunExecutorPrecondition: async () => ({ ok: true }),
|
|
178
|
+
// Nothing that creates, prepares, or starts a run may run.
|
|
179
|
+
runSetupEpic: async () => { mutations.push("runSetupEpic"); return refuse("runSetupEpic"); },
|
|
180
|
+
prepareRunExecutor: async () => { mutations.push("prepareRunExecutor"); return refuse("prepareRunExecutor"); },
|
|
181
|
+
ensureRunExecutor: async () => { mutations.push("ensureRunExecutor"); return refuse("ensureRunExecutor"); },
|
|
182
|
+
runPlane: async () => { mutations.push("runPlane"); return refuse("runPlane"); },
|
|
183
|
+
launchControlPlane: async () => { mutations.push("launchControlPlane"); return refuse("launchControlPlane"); },
|
|
184
|
+
requestScopedLanes: async () => { mutations.push("requestScopedLanes"); return refuse("requestScopedLanes"); },
|
|
185
|
+
runPlanePreflight: async () => refuse("runPlanePreflight"),
|
|
186
|
+
probePlanePort: async () => refuse("probePlanePort"),
|
|
187
|
+
readRunState: async () => refuse("readRunState"),
|
|
188
|
+
readPlaneReconcilerState: async () => refuse("readPlaneReconcilerState"),
|
|
189
|
+
readPlaneManifest: async () => refuse("readPlaneManifest"),
|
|
190
|
+
cleanupTerminalRunPlane: async () => refuse("cleanupTerminalRunPlane"),
|
|
191
|
+
listLiveRunIds: async () => refuse("listLiveRunIds"),
|
|
192
|
+
resolvePlaneEndpoint: () => ({
|
|
193
|
+
ok: true,
|
|
194
|
+
endpoint: { host: "127.0.0.1", port: 8000, baseUrl: "http://127.0.0.1:8000" },
|
|
195
|
+
}),
|
|
196
|
+
cwd: () => nativePath("/repo"),
|
|
197
|
+
// Hermetic launch-need probes: each answers "could not tell".
|
|
198
|
+
inspectRequiredRunners: async () => ({ state: "unverifiable", reason: "probe_failed" }),
|
|
199
|
+
inspectHostSleep: (root) => inspectHostSleep(root, { execFile: async () => refuse("pmset"), platform: "linux" }),
|
|
200
|
+
execEngineStatus: undefined,
|
|
201
|
+
runCommand: async () => ({ exitCode: 0, stdout: "", stderr: "" }),
|
|
202
|
+
launchSleep: async () => undefined,
|
|
203
|
+
attemptPlanGeneration: undefined,
|
|
204
|
+
publishGeneratedPlan: undefined,
|
|
205
|
+
lookupAuthoredPlan: undefined,
|
|
206
|
+
uploadAuthoredPlan: undefined,
|
|
207
|
+
materializeAuthoredPlan: undefined,
|
|
208
|
+
readPrerequisiteCache: async () => ({ kind: "unavailable" }),
|
|
209
|
+
// The advisory UI readiness reads are the test's to install; absent means unavailable.
|
|
210
|
+
readUiTicketDescription: undefined,
|
|
211
|
+
listUiTrackedFiles: undefined,
|
|
212
|
+
readUiMcpGrant: undefined,
|
|
213
|
+
readUiEpicServerRecord: undefined,
|
|
214
|
+
log: (line) => out.push(line),
|
|
215
|
+
errorLog: (line) => err.push(line),
|
|
216
|
+
...o.seams,
|
|
217
|
+
};
|
|
218
|
+
return {
|
|
219
|
+
deps,
|
|
220
|
+
out,
|
|
221
|
+
err,
|
|
222
|
+
mutations,
|
|
223
|
+
preview: async (extraArgv = [], options = {}) => {
|
|
224
|
+
out.length = 0;
|
|
225
|
+
err.length = 0;
|
|
226
|
+
const json = options.json !== false;
|
|
227
|
+
const code = await runDriveEpicCli([PREVIEW_WORLD_EPIC, "--plan-file", PREVIEW_WORLD_PLAN_PATH, "--dry-run", ...(json ? ["--json"] : []), ...extraArgv], deps);
|
|
228
|
+
const doc = (json ? JSON.parse(out[0] ?? "null") : null);
|
|
229
|
+
return { code, doc, text: [...out, ...err].join("\n") };
|
|
230
|
+
},
|
|
231
|
+
};
|
|
232
|
+
}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Read a source module's imports, for tests that guard import boundaries.
|
|
3
|
+
*
|
|
4
|
+
* Many safety rules are about what a module may depend on: a pure builder never
|
|
5
|
+
* imports `node:child_process`, `doctor` never imports the credential writer,
|
|
6
|
+
* the readiness collector never imports the MCP server. Checking those with
|
|
7
|
+
* `source.includes("node:fs")` is fooled by a comment and misses a dynamic
|
|
8
|
+
* `import("…")`. These helpers strip comments and read every static import,
|
|
9
|
+
* `export … from`, `import type`, and dynamic `import("…")` specifier.
|
|
10
|
+
*
|
|
11
|
+
* Paths are relative to `mcp_server/src`. Tests run from `build/`, so the
|
|
12
|
+
* TypeScript source is read from `src/`.
|
|
13
|
+
*/
|
|
14
|
+
import assert from "node:assert/strict";
|
|
15
|
+
import { readFileSync } from "node:fs";
|
|
16
|
+
import path from "node:path";
|
|
17
|
+
const SRC_DIR = path.join(import.meta.dirname, "..", "..", "src");
|
|
18
|
+
/** Characters after which a `/` starts a regex literal rather than a division. */
|
|
19
|
+
const REGEX_PREFIX = new Set(["(", ",", "=", ":", "[", "!", "&", "|", "?", "{", "}", ";", "+", "-", "*", "%", "<", ">", "~", "^", ""]);
|
|
20
|
+
/**
|
|
21
|
+
* Remove `//` line comments and block comments, leaving strings and regex
|
|
22
|
+
* literals intact (a quote inside `/[;"']/` must not open a string).
|
|
23
|
+
*/
|
|
24
|
+
export function stripComments(source) {
|
|
25
|
+
let out = "";
|
|
26
|
+
let i = 0;
|
|
27
|
+
while (i < source.length) {
|
|
28
|
+
const c = source[i];
|
|
29
|
+
const next = source[i + 1];
|
|
30
|
+
if (c === "/" && next !== "/" && next !== "*" && REGEX_PREFIX.has(out.trimEnd().slice(-1))) {
|
|
31
|
+
// A regex literal: copy it through, honouring escapes and character classes.
|
|
32
|
+
let j = i + 1;
|
|
33
|
+
let inClass = false;
|
|
34
|
+
while (j < source.length && source[j] !== "\n") {
|
|
35
|
+
const ch = source[j];
|
|
36
|
+
if (ch === "\\")
|
|
37
|
+
j += 2;
|
|
38
|
+
else if (ch === "[")
|
|
39
|
+
(inClass = true), (j += 1);
|
|
40
|
+
else if (ch === "]")
|
|
41
|
+
(inClass = false), (j += 1);
|
|
42
|
+
else if (ch === "/" && !inClass)
|
|
43
|
+
break;
|
|
44
|
+
else
|
|
45
|
+
j += 1;
|
|
46
|
+
}
|
|
47
|
+
out += source.slice(i, j + 1);
|
|
48
|
+
i = j + 1;
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
if (c === "/" && next === "/") {
|
|
52
|
+
const end = source.indexOf("\n", i);
|
|
53
|
+
i = end < 0 ? source.length : end;
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
if (c === "/" && next === "*") {
|
|
57
|
+
const end = source.indexOf("*/", i + 2);
|
|
58
|
+
i = end < 0 ? source.length : end + 2;
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
if (c === '"' || c === "'" || c === "`") {
|
|
62
|
+
let j = i + 1;
|
|
63
|
+
while (j < source.length && source[j] !== c)
|
|
64
|
+
j += source[j] === "\\" ? 2 : 1;
|
|
65
|
+
out += source.slice(i, j + 1);
|
|
66
|
+
i = j + 1;
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
out += c;
|
|
70
|
+
i += 1;
|
|
71
|
+
}
|
|
72
|
+
return out;
|
|
73
|
+
}
|
|
74
|
+
const STATIC_IMPORT = /^\s*(import|export)\s+(type\s+)?([^;]*?)\bfrom\s*["']([^"']+)["']|^\s*import\s*["']([^"']+)["']/gm;
|
|
75
|
+
/** Every static import and re-export statement of a source text. */
|
|
76
|
+
export function staticImportStatements(source) {
|
|
77
|
+
const code = stripComments(source);
|
|
78
|
+
const out = [];
|
|
79
|
+
for (const m of code.matchAll(STATIC_IMPORT)) {
|
|
80
|
+
if (m[5] !== undefined) {
|
|
81
|
+
out.push({ specifier: m[5], typeOnly: false, reexport: false, names: [], namespace: false });
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
const clause = m[3] ?? "";
|
|
85
|
+
const braced = /\{([^}]*)\}/.exec(clause)?.[1] ?? "";
|
|
86
|
+
const names = braced
|
|
87
|
+
.split(",")
|
|
88
|
+
.map((n) => n.trim().replace(/^type\s+/, "").split(/\s+as\s+/)[0].trim())
|
|
89
|
+
.filter(Boolean);
|
|
90
|
+
const defaultName = /^\s*([A-Za-z_$][\w$]*)\s*(,|$)/.exec(clause)?.[1];
|
|
91
|
+
if (defaultName && defaultName !== "type")
|
|
92
|
+
names.push(defaultName);
|
|
93
|
+
out.push({
|
|
94
|
+
specifier: m[4],
|
|
95
|
+
typeOnly: Boolean(m[2]),
|
|
96
|
+
reexport: m[1] === "export",
|
|
97
|
+
names,
|
|
98
|
+
namespace: /\*\s*as\s/.test(clause) || (m[1] === "export" && /^\s*\*/.test(clause)),
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
return out;
|
|
102
|
+
}
|
|
103
|
+
/** Specifiers loaded with a dynamic `import("…")`. */
|
|
104
|
+
export function dynamicImportsOfSource(source) {
|
|
105
|
+
const code = stripComments(source);
|
|
106
|
+
return [...new Set([...code.matchAll(/\bimport\s*\(\s*["']([^"']+)["']\s*\)/g)].map((m) => m[1]))];
|
|
107
|
+
}
|
|
108
|
+
/** Every module specifier a source text imports (static and dynamic), duplicates removed. */
|
|
109
|
+
export function importsOfSource(source) {
|
|
110
|
+
return [...new Set([...staticImportStatements(source).map((s) => s.specifier), ...dynamicImportsOfSource(source)])];
|
|
111
|
+
}
|
|
112
|
+
function read(relativePath) {
|
|
113
|
+
return readFileSync(path.join(SRC_DIR, relativePath), "utf8");
|
|
114
|
+
}
|
|
115
|
+
/** Every module specifier `mcp_server/src/<relativePath>` imports, static or dynamic. */
|
|
116
|
+
export function importsOf(relativePath) {
|
|
117
|
+
return importsOfSource(read(relativePath));
|
|
118
|
+
}
|
|
119
|
+
/** The static import statements of `mcp_server/src/<relativePath>`. */
|
|
120
|
+
export function staticImportsOf(relativePath) {
|
|
121
|
+
return staticImportStatements(read(relativePath));
|
|
122
|
+
}
|
|
123
|
+
/** Specifiers `mcp_server/src/<relativePath>` loads with a dynamic `import("…")`. */
|
|
124
|
+
export function dynamicImportsOf(relativePath) {
|
|
125
|
+
return dynamicImportsOfSource(read(relativePath));
|
|
126
|
+
}
|
|
127
|
+
/** A specifier matches a banned entry exactly, or as a path ending (`/doctor.js`). */
|
|
128
|
+
function matches(specifier, entry) {
|
|
129
|
+
return specifier === entry || specifier.endsWith(`/${entry.replace(/^\.\//, "")}`);
|
|
130
|
+
}
|
|
131
|
+
/** Fail if the module imports any banned specifier. */
|
|
132
|
+
export function assertImportsNone(relativePath, banned) {
|
|
133
|
+
const offenders = importsOf(relativePath).filter((s) => banned.some((b) => matches(s, b)));
|
|
134
|
+
assert.deepEqual(offenders, [], `${relativePath} must not import ${offenders.join(", ")}`);
|
|
135
|
+
}
|
|
136
|
+
/** Fail if the module imports anything outside the allowed list. */
|
|
137
|
+
export function assertImportsOnly(relativePath, allowed) {
|
|
138
|
+
const offenders = importsOf(relativePath).filter((s) => !allowed.some((a) => matches(s, a)));
|
|
139
|
+
assert.deepEqual(offenders, [], `${relativePath} imports outside its allow-list: ${offenders.join(", ")}`);
|
|
140
|
+
}
|
|
141
|
+
/** Fail unless the module imports every required specifier. */
|
|
142
|
+
export function assertImportsAll(relativePath, required) {
|
|
143
|
+
const imports = importsOf(relativePath);
|
|
144
|
+
const missing = required.filter((r) => !imports.some((s) => matches(s, r)));
|
|
145
|
+
assert.deepEqual(missing, [], `${relativePath} must import ${missing.join(", ")}`);
|
|
146
|
+
}
|
|
147
|
+
/** Fail if the module imports any of these names from a specifier. */
|
|
148
|
+
export function assertImportsNoName(relativePath, specifier, names) {
|
|
149
|
+
const statements = staticImportsOf(relativePath).filter((s) => matches(s.specifier, specifier));
|
|
150
|
+
const offenders = names.filter((n) => statements.some((s) => s.names.includes(n)));
|
|
151
|
+
assert.deepEqual(offenders, [], `${relativePath} must not import ${offenders.join(", ")} from ${specifier}`);
|
|
152
|
+
// A namespace or dynamic import of the module would reach every name.
|
|
153
|
+
assert.ok(!statements.some((s) => s.namespace), `${relativePath} imports ${specifier} as a namespace`);
|
|
154
|
+
assert.ok(!dynamicImportsOf(relativePath).some((d) => matches(d, specifier)), `${relativePath} loads ${specifier} dynamically, which could reach ${names.join(", ")}`);
|
|
155
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Drive the real MCP server's tool handlers from a test.
|
|
3
|
+
*
|
|
4
|
+
* `server.ts` builds the server and registers every tool on import and does no
|
|
5
|
+
* I/O until `startServer()`. This helper sets the environment, replaces `fetch`
|
|
6
|
+
* with a recorder, imports the module once, and connects an in-memory MCP client,
|
|
7
|
+
* so a test calls a tool exactly as an agent would and sees the requests it
|
|
8
|
+
* made. Rules that live in `startServer()` (index scope, stdio connect) are not
|
|
9
|
+
* reachable here; those tests mock the SDK instead.
|
|
10
|
+
*
|
|
11
|
+
* Call `connectServer` once per test file: the environment is read when the
|
|
12
|
+
* module loads, and each test file runs in its own process.
|
|
13
|
+
*/
|
|
14
|
+
import { mkdirSync, mkdtempSync } from "node:fs";
|
|
15
|
+
import os from "node:os";
|
|
16
|
+
import path from "node:path";
|
|
17
|
+
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
18
|
+
import { InMemoryTransport } from "@modelcontextprotocol/sdk/inMemory.js";
|
|
19
|
+
function headerRecord(init) {
|
|
20
|
+
const out = {};
|
|
21
|
+
const headers = init?.headers;
|
|
22
|
+
if (!headers)
|
|
23
|
+
return out;
|
|
24
|
+
if (headers instanceof Headers) {
|
|
25
|
+
headers.forEach((value, key) => {
|
|
26
|
+
out[key.toLowerCase()] = value;
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
else if (Array.isArray(headers)) {
|
|
30
|
+
for (const [key, value] of headers)
|
|
31
|
+
out[key.toLowerCase()] = value;
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
for (const [key, value] of Object.entries(headers))
|
|
35
|
+
out[key.toLowerCase()] = String(value);
|
|
36
|
+
}
|
|
37
|
+
return out;
|
|
38
|
+
}
|
|
39
|
+
export async function connectServer(env = {}) {
|
|
40
|
+
const projectRoot = mkdtempSync(path.join(os.tmpdir(), "server-client-root-"));
|
|
41
|
+
mkdirSync(path.join(projectRoot, ".git"));
|
|
42
|
+
Object.assign(process.env, {
|
|
43
|
+
BAPI_BASE_URL: "https://bridge.example.test",
|
|
44
|
+
BAPI_REPO_NAME: "server-client-repo",
|
|
45
|
+
BAPI_API_KEY: "server-client-sentinel-key",
|
|
46
|
+
BAPI_PROJECT_ROOT: projectRoot,
|
|
47
|
+
BAPI_MCP_UPDATE_CHECK_ENABLED: "false",
|
|
48
|
+
...env,
|
|
49
|
+
});
|
|
50
|
+
const requests = [];
|
|
51
|
+
let responder = () => undefined;
|
|
52
|
+
globalThis.fetch = (async (input, init) => {
|
|
53
|
+
const raw = init?.body;
|
|
54
|
+
let body = raw;
|
|
55
|
+
if (typeof raw === "string") {
|
|
56
|
+
try {
|
|
57
|
+
body = JSON.parse(raw);
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
body = raw;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
const request = {
|
|
64
|
+
url: String(input),
|
|
65
|
+
method: (init?.method ?? "GET").toUpperCase(),
|
|
66
|
+
headers: headerRecord(init),
|
|
67
|
+
body,
|
|
68
|
+
};
|
|
69
|
+
requests.push(request);
|
|
70
|
+
const answer = responder(request);
|
|
71
|
+
if (answer instanceof Error)
|
|
72
|
+
throw answer;
|
|
73
|
+
const status = answer?.status ?? 200;
|
|
74
|
+
const payload = answer?.body ?? {};
|
|
75
|
+
return new Response(typeof payload === "string" ? payload : JSON.stringify(payload), {
|
|
76
|
+
status,
|
|
77
|
+
headers: { "content-type": typeof payload === "string" ? "text/plain" : "application/json" },
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
const { bridgeServer } = await import("../server.js");
|
|
81
|
+
const [serverSide, clientSide] = InMemoryTransport.createLinkedPair();
|
|
82
|
+
await bridgeServer.connect(serverSide);
|
|
83
|
+
const client = new Client({ name: "server-client-test", version: "0.0.0" });
|
|
84
|
+
await client.connect(clientSide);
|
|
85
|
+
return {
|
|
86
|
+
requests,
|
|
87
|
+
projectRoot,
|
|
88
|
+
respond(next) {
|
|
89
|
+
responder = next;
|
|
90
|
+
},
|
|
91
|
+
async call(name, args = {}) {
|
|
92
|
+
const result = (await client.callTool({ name, arguments: args }));
|
|
93
|
+
return { text: result.content?.[0]?.text ?? "", isError: Boolean(result.isError) };
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
}
|