From 816660b239f787ea49f4d7dd0c739d4234aefc41 Mon Sep 17 00:00:00 2001 From: Denozordec Date: Thu, 19 Nov 2026 12:19:14 +0700 Subject: [PATCH] =?UTF-8?q?chore(test):=20=D1=80=D0=B0=D0=B7=D0=B1=D0=B8?= =?UTF-8?q?=D1=82=D1=8C=20=D0=BF=D1=80=D0=B8=D1=91=D0=BC=D0=BA=D1=83=20sco?= =?UTF-8?q?ped-=D0=BC=D0=B0=D1=80=D1=88=D1=80=D1=83=D1=82=D0=B8=D0=B7?= =?UTF-8?q?=D0=B0=D1=86=D0=B8=D0=B8=20=D0=BD=D0=B0=20=D1=82=D1=80=D0=B8=20?= =?UTF-8?q?=D1=88=D0=B0=D1=80=D0=B4=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Опция `part` (forward, inverse, route-ai) запускает один этап приёмки; без опции выполняются все три, как раньше. Основной набор пропускает приёмку целиком, только если в шардах перечислены все её части; неполный набор частей - ошибка (acceptance-shards.test.ts). Замер: весь набор 334 с (был 430 с, до шардов 958 с проверок), 149 строк результатов совпадают с прошлым шардированным прогоном, каждый этап выполнен один раз. Co-Authored-By: Claude Opus 5.5 --- backend/scripts/test-mcp-postgres-sharded.mjs | 6 ++++-- .../src/modules/mcp/acceptance-shards.test.ts | 9 +++++++++ backend/src/modules/mcp/acceptance-shards.ts | 16 ++++++++++++++++ backend/src/modules/mcp/integration.test.ts | 2 +- .../mcp/routing-community-scoped-acceptance.ts | 10 ++++++++-- 5 files changed, 38 insertions(+), 5 deletions(-) create mode 100644 backend/src/modules/mcp/acceptance-shards.test.ts diff --git a/backend/scripts/test-mcp-postgres-sharded.mjs b/backend/scripts/test-mcp-postgres-sharded.mjs index 7d83edb4..3dfe3bf4 100644 --- a/backend/scripts/test-mcp-postgres-sharded.mjs +++ b/backend/scripts/test-mcp-postgres-sharded.mjs @@ -5,9 +5,11 @@ import { spawn } from 'node:child_process' import { fileURLToPath } from 'node:url' -// Grouped by measured duration (2026-11-19): scoped routing ~370 s, the rest ~130-150 s each. +// Grouped by measured duration (2026-11-19): each shard ~110-190 s, the primary ~320 s. const shards = { - 'scoped-routing': ['acceptScopedRouteCommunitySwitch'], + 'scoped-forward': ['acceptScopedRouteCommunitySwitch:forward'], + 'scoped-inverse': ['acceptScopedRouteCommunitySwitch:inverse'], + 'scoped-route-ai': ['acceptScopedRouteCommunitySwitch:route-ai'], 'wireguard-create': ['acceptWireguardInterfaceCreation', 'acceptRouteCommunityContextMcp', 'acceptWireguardPeerCreation'], 'wireguard-change': ['acceptWireguardInterfaceUpdate', 'acceptWireguardImport'], } diff --git a/backend/src/modules/mcp/acceptance-shards.test.ts b/backend/src/modules/mcp/acceptance-shards.test.ts new file mode 100644 index 00000000..27816350 --- /dev/null +++ b/backend/src/modules/mcp/acceptance-shards.test.ts @@ -0,0 +1,9 @@ +import assert from "node:assert/strict" +import { skippedAcceptances } from "./acceptance-shards.js" + +const scoped = ["forward", "inverse", "route-ai"].map(part => `acceptScopedRouteCommunitySwitch:${part}`) +assert.deepEqual([...skippedAcceptances([...scoped, "acceptWireguardImport"].join(","))].sort(), ["acceptScopedRouteCommunitySwitch", "acceptWireguardImport"]) +assert.throws(() => skippedAcceptances(scoped[0]), /is split/, "a partly sharded acceptance must not drop out of the primary run") +assert.throws(() => skippedAcceptances("unknownAcceptance"), /Unknown acceptance shard/) +assert.equal(skippedAcceptances(undefined).size, 0) +console.log("Acceptance shards: whole or all-parts skip only; partial split and unknown names refused") diff --git a/backend/src/modules/mcp/acceptance-shards.ts b/backend/src/modules/mcp/acceptance-shards.ts index 304418a8..d986188d 100644 --- a/backend/src/modules/mcp/acceptance-shards.ts +++ b/backend/src/modules/mcp/acceptance-shards.ts @@ -5,6 +5,9 @@ import type { AuthUser } from "../../lib/permissions.js" * MCP_INTEGRATION_SKIP; acceptance-shard.test.ts runs the names listed in MCP_ACCEPTANCE_SHARD. */ export const ACCEPTANCE_SHARDS: Record Promise> = { acceptScopedRouteCommunitySwitch: async actor => (await import("./routing-community-scoped-acceptance.js")).acceptScopedRouteCommunitySwitch(actor), + "acceptScopedRouteCommunitySwitch:forward": async actor => (await import("./routing-community-scoped-acceptance.js")).acceptScopedRouteCommunitySwitch(actor, { part: "forward" }), + "acceptScopedRouteCommunitySwitch:inverse": async actor => (await import("./routing-community-scoped-acceptance.js")).acceptScopedRouteCommunitySwitch(actor, { part: "inverse" }), + "acceptScopedRouteCommunitySwitch:route-ai": async actor => (await import("./routing-community-scoped-acceptance.js")).acceptScopedRouteCommunitySwitch(actor, { part: "route-ai" }), acceptWireguardInterfaceCreation: async actor => (await import("./wireguard-interface-create-acceptance.js")).acceptWireguardInterfaceCreation(actor), acceptRouteCommunityContextMcp: async actor => (await import("./routing-community-context-acceptance.js")).acceptRouteCommunityContextMcp(actor), acceptWireguardPeerCreation: async actor => (await import("./wireguard-peer-create-acceptance.js")).acceptWireguardPeerCreation(actor), @@ -12,6 +15,19 @@ export const ACCEPTANCE_SHARDS: Record Promise (await import("./wireguard-import-acceptance.js")).acceptWireguardImport(actor), } +/** Acceptances the primary run may skip: a listed name, or a name whose every `name:part` is listed. + * Listing only some parts of a name is an error, so a stage can never drop out of both runs. */ +export function skippedAcceptances(value: string | undefined): Set { + const listed = new Set(acceptanceShardNames(value)), skipped = new Set() + for (const name of listed) { + const base = name.split(":")[0], parts = Object.keys(ACCEPTANCE_SHARDS).filter(key => key.startsWith(base + ":")) + if (name === base) { skipped.add(base); continue } + if (!parts.every(part => listed.has(part))) throw new Error(`Acceptance ${base} is split: list all of ${parts.join(", ")}`) + skipped.add(base) + } + return skipped +} + /** Names from an environment list; an unknown name is an error, never a silent skip. */ export function acceptanceShardNames(value: string | undefined): string[] { const names = (value ?? "").split(",").map(name => name.trim()).filter(Boolean) diff --git a/backend/src/modules/mcp/integration.test.ts b/backend/src/modules/mcp/integration.test.ts index 239c3f2e..3071b474 100644 --- a/backend/src/modules/mcp/integration.test.ts +++ b/backend/src/modules/mcp/integration.test.ts @@ -37,7 +37,7 @@ const soft = async (name: string, check: () => Promise) => { try { return await check() } catch (error) { softFailures.push(`${name}: ${error instanceof Error ? error.stack ?? error.message : String(error)}`) } } // Acceptances run by parallel shards (scripts/test-mcp-postgres-sharded.mjs) are skipped here, by exact name. -const shardedOut = new Set((await import("./acceptance-shards.js")).acceptanceShardNames(process.env.MCP_INTEGRATION_SKIP)) +const shardedOut = (await import("./acceptance-shards.js")).skippedAcceptances(process.env.MCP_INTEGRATION_SKIP) const shardable = async (name: string) => { if (shardedOut.has(name)) { console.log(`- ${name}: runs in a parallel shard`); return } await soft(name, async () => (await import("./acceptance-shards.js")).ACCEPTANCE_SHARDS[name](actor)) diff --git a/backend/src/modules/mcp/routing-community-scoped-acceptance.ts b/backend/src/modules/mcp/routing-community-scoped-acceptance.ts index 25785015..bf84817b 100644 --- a/backend/src/modules/mcp/routing-community-scoped-acceptance.ts +++ b/backend/src/modules/mcp/routing-community-scoped-acceptance.ts @@ -47,7 +47,7 @@ type BrowserRoutingJourney = (access: { token: string; connectionId: string; type ForwardCheckpoint = (approved: { token: string; connectionId: string; planId: string }) => Promise type InverseToolCall = (token: string, name: string, input: Record) => Promise -export async function acceptScopedRouteCommunitySwitch(actor: AuthUser, options: { originalEffectsOnly?: boolean; controllerFailoverOnly?: boolean; originalCredentialRevocationOnly?: boolean; forwardRoundsOnly?: boolean; manualForwardExpiry?: "before-intent" | "after-intent"; manualInverseChargeOnly?: boolean; manualInverseChargeCase?: "positive" | "quota" | "concurrent" | "unknown" | "revoked" | "nonpersistent" | "mixed-forward"; lateInverseAuthorityChange?: "edit" | "disable" | "grant" | "path-proof" | "path-age"; browserJourney?: BrowserRoutingJourney; bareReadbackOnly?: boolean; forwardCheckpoint?: ForwardCheckpoint; expireDuringInverseProbe?: boolean; expireDuringInversePostProbe?: boolean; inverseCheckpointDrift?: boolean; inverseRouteEffects?: boolean; inverseEffectsCheckpointDrift?: boolean; loseInverseAck?: boolean; inverseToolCall?: InverseToolCall } = {}) { +export async function acceptScopedRouteCommunitySwitch(actor: AuthUser, options: { /** One stage of the default run (shards); default runs all three. */ part?: "forward" | "inverse" | "route-ai"; originalEffectsOnly?: boolean; controllerFailoverOnly?: boolean; originalCredentialRevocationOnly?: boolean; forwardRoundsOnly?: boolean; manualForwardExpiry?: "before-intent" | "after-intent"; manualInverseChargeOnly?: boolean; manualInverseChargeCase?: "positive" | "quota" | "concurrent" | "unknown" | "revoked" | "nonpersistent" | "mixed-forward"; lateInverseAuthorityChange?: "edit" | "disable" | "grant" | "path-proof" | "path-age"; browserJourney?: BrowserRoutingJourney; bareReadbackOnly?: boolean; forwardCheckpoint?: ForwardCheckpoint; expireDuringInverseProbe?: boolean; expireDuringInversePostProbe?: boolean; inverseCheckpointDrift?: boolean; inverseRouteEffects?: boolean; inverseEffectsCheckpointDrift?: boolean; loseInverseAck?: boolean; inverseToolCall?: InverseToolCall } = {}) { if (options.browserJourney || options.bareReadbackOnly || options.manualForwardExpiry) assert.equal(process.env.NODE_ENV, "test") if (options.expireDuringInverseProbe || options.expireDuringInversePostProbe || options.inverseCheckpointDrift || options.inverseRouteEffects) assert(options.bareReadbackOnly) if (options.inverseEffectsCheckpointDrift) assert(options.inverseRouteEffects) @@ -1540,7 +1540,7 @@ export async function acceptScopedRouteCommunitySwitch(actor: AuthUser, options: // valid, while the external native body changes to B BEFORE preparation. // Public ingress cannot set internal profile context; this trusted-host // preparation case proves the native gate independently binds enrollment. - { + if (!options.part || options.part === "forward") { const driftId=randomUUID(),driftCurrent=await effectiveMcpConnection(principal),driftExpiry=new Date(Math.min(Date.now()+600000,driftCurrent.owner_valid_until.getTime(),Date.parse(principal.credentialExpiresAt),Date.parse(driftCurrent.policy.expiresAt))) await withApplicationMutationLock(()=>withConfigMutationLock([sid],async()=>{ const baseline=await prepareRoutingControllerBaseline(driftId,1,profile("a"),driftExpiry.toISOString(),{principal,connection:driftCurrent}) @@ -1619,6 +1619,7 @@ export async function acceptScopedRouteCommunitySwitch(actor: AuthUser, options: securityProof: false, logCoverage: "unknown", forwardingVerified: false })) return { accepted: true, forwardRoundCases: accepted, securityProof: false, forwardingVerified: false } } + if (!options.part || options.part === "forward") { for (const key of ["a", "b"]) { const before = structuredClone(filters), { plan, input } = await prepare(key), count = writes const op = await execute(plan.planId); assert.equal(op.state, "applied"); assert.equal(writes, count + 1) @@ -1715,6 +1716,9 @@ export async function acceptScopedRouteCommunitySwitch(actor: AuthUser, options: console.log("Scoped post-write authority: protection, endpoint epoch, policy pause and immutable path-row tampering still stop configuration confirmation; exact one PATCH and no replay") assert.ok(postCheckpointsObserved >= 4) console.log("Scoped CONFIG_APPLIED SQL/HTTP: encrypted exact operation checkpoint precedes post-probe, native body/candidate/proofs bound, tamper blocked, failed control probe partial, unknown probe unknown, no inverse or replay") + } + if (options.part === "forward") return { accepted: true, part: options.part } + if (!options.part || options.part === "inverse") { for (const scenario of ["normal", "concurrent", "lost", "ignored", "collateral", "late-protection", "late-epoch", "primary-down"] as const) { console.log("Scoped inverse scenario:", scenario) reset(); await refresh() @@ -1812,6 +1816,8 @@ export async function acceptScopedRouteCommunitySwitch(actor: AuthUser, options: } assert.ok(inversePostChecks >= 2) console.log("Scoped inverse SQL/HTTP: exact encrypted source/op/step, fresh A proof in B context, one durable inverse slot, exact original bytes, RECOVERY_VERIFIED, lost/ignored/collateral no replay, late protection/ABA fences, primary-down alternate and generic VERIFIED separation") + } + if (options.part === "inverse") return { accepted: true, part: options.part } for (const scenario of ["stale", "late-epoch-aba", "late-protection", "late-pause"] as const) { reset(); await refresh(); const { plan } = await prepare(), before = writes, protection = randomUUID() afterIntent = async () => {