diff --git a/backend/package.json b/backend/package.json index 312a2c3b..8d51dd52 100644 --- a/backend/package.json +++ b/backend/package.json @@ -7,6 +7,7 @@ "test:mcp:module-completion": "tsx src/services/ipsec-server-init-model.test.ts && tsx src/modules/mcp/ipsec-server-init-actions.test.ts && tsx src/services/wireguard-revision-restore.test.ts && tsx src/modules/mcp/vrf-ticket-runtime.test.ts && tsx src/services/ipsec-restore.test.ts && tsx src/services/ipsec-pool-dependencies.test.ts && tsx src/services/vrf-production-transition.test.ts && tsx src/services/vrf-production-action-binding.test.ts && tsx src/services/ipsec-revision-restore-model.test.ts && tsx src/modules/mcp/ipsec-revision-actions.test.ts && tsx src/modules/mcp/service-native-progress.test.ts && tsx src/services/ipsec-revision-restore.test.ts && tsx src/services/ipsec-revision-secret.test.ts", "test:mcp:module-completion:pg": "node scripts/test-mcp-postgres.mjs --module-completion --restore", "test:mcp:pg": "node scripts/test-mcp-postgres.mjs", + "test:mcp:pg:sharded": "node scripts/test-mcp-postgres-sharded.mjs", "test:mcp:users-bindings:pg": "node scripts/test-mcp-postgres.mjs --users-bindings", "test:mcp:bridge-vlan:pg": "node scripts/test-mcp-postgres.mjs --bridge-vlan-configuration", "test:mcp:external-process:pg": "node scripts/mcp-external-process/run-owned.mjs", diff --git a/backend/scripts/test-mcp-postgres-sharded.mjs b/backend/scripts/test-mcp-postgres-sharded.mjs new file mode 100644 index 00000000..7d83edb4 --- /dev/null +++ b/backend/scripts/test-mcp-postgres-sharded.mjs @@ -0,0 +1,47 @@ +// Runs the primary MCP PostgreSQL integration suite with its slowest self-contained acceptances +// moved to parallel shards. Every process owns a disposable PostgreSQL (test-mcp-postgres.mjs). +// Coverage equals `node scripts/test-mcp-postgres.mjs`: the primary run skips exactly the names +// the shards run (MCP_INTEGRATION_SKIP), and an unknown name fails both sides. +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. +const shards = { + 'scoped-routing': ['acceptScopedRouteCommunitySwitch'], + 'wireguard-create': ['acceptWireguardInterfaceCreation', 'acceptRouteCommunityContextMcp', 'acceptWireguardPeerCreation'], + 'wireguard-change': ['acceptWireguardInterfaceUpdate', 'acceptWireguardImport'], +} +const harness = fileURLToPath(new URL('./test-mcp-postgres.mjs', import.meta.url)) +const cwd = fileURLToPath(new URL('../', import.meta.url)) +const started = performance.now() +const seconds = () => ((performance.now() - started) / 1000).toFixed(0).padStart(4) + +function run(label, args, env) { + return new Promise(resolve => { + const child = spawn(process.execPath, [harness, ...args], { cwd, env: { ...process.env, ...env }, stdio: ['ignore', 'pipe', 'pipe'] }) + for (const stream of [child.stdout, child.stderr]) { + let pending = '' + stream.setEncoding('utf8') + stream.on('data', chunk => { + const lines = (pending + chunk).split(/\r?\n/) + pending = lines.pop() + for (const line of lines) if (line) console.log(`${seconds()}s [${label}] ${line}`) + }) + stream.on('end', () => { if (pending) console.log(`${seconds()}s [${label}] ${pending}`) }) + } + child.once('error', error => { console.error(`[${label}] ${error.message}`); resolve({ label, code: 1, at: seconds() }) }) + child.once('exit', code => resolve({ label, code: code ?? 1, at: seconds() })) + }) +} + +const jobs = [run('primary', [], { MCP_INTEGRATION_SKIP: Object.values(shards).flat().join(',') })] +for (const [label, names] of Object.entries(shards)) { + // Stagger starts: each harness picks a free port just before PostgreSQL binds it. + await new Promise(resolve => setTimeout(resolve, 1500)) + jobs.push(run(label, [`--acceptance-shard=${names.join(',')}`], {})) +} +const results = await Promise.all(jobs) +console.log('\nMCP PostgreSQL sharded run:') +for (const result of results) console.log(` ${result.code === 0 ? 'PASS' : 'FAIL'} ${result.label} (exit ${result.code}, done at ${result.at.trim()}s)`) +console.log(` total ${seconds().trim()}s`) +process.exitCode = results.every(result => result.code === 0) ? 0 : 1 diff --git a/backend/scripts/test-mcp-postgres.mjs b/backend/scripts/test-mcp-postgres.mjs index 6dc621a7..1b4defb5 100644 --- a/backend/scripts/test-mcp-postgres.mjs +++ b/backend/scripts/test-mcp-postgres.mjs @@ -190,6 +190,9 @@ if (wireguardExport && process.argv.includes('--wireguard-transfer')) throw new const wireguardTransfer = process.argv.includes('--wireguard-transfer') || wireguardExport const scopedCheckpointAdapters = process.argv.includes('--scoped-checkpoint-adapters') const nativeConservation = process.argv.includes('--native-conservation') +// Parallel shard of self-contained acceptances (scripts/test-mcp-postgres-sharded.mjs); no terminal restore stage. +const acceptanceShard = process.argv.find(arg => arg.startsWith('--acceptance-shard='))?.slice('--acceptance-shard='.length) +if (acceptanceShard !== undefined && (!acceptanceShard || process.argv.length !== 3)) throw new Error('--acceptance-shard= runs alone') const nativeCreateId = process.argv.includes('--native-create-id') const moduleCompletion = process.argv.includes('--module-completion') const completionTarget = process.argv.find(arg => arg.startsWith('--only='))?.slice(7) ?? 'all' @@ -271,7 +274,7 @@ try { if (regressionOnly) console.log('Selected regression only: primary integration and terminal restore are not run') if (profilesOnly) console.log('Profiles-only regression matrix: primary integration NOT RUN; terminal restore NOT RUN; full acceptance is not claimed') const result = regressionOnly || profilesOnly ? 0 : await new Promise((resolve, reject) => { - const child = spawn(process.execPath, pollMemory ? ['--max-old-space-size=192', '--max-semi-space-size=16', fileURLToPath(new URL('../dist-mcp-memory/services/server-poll-memory.owned.test.js', import.meta.url))] : ['--import', 'tsx', ...(flowActiveRebuild ? ['--import', new URL('../src/services/traffic-flow-active-rebuild-preload.mjs', import.meta.url).href] : []), usersBindings ? 'src/modules/mcp/users-bindings-owned.test.ts' : bridgeVlanConfiguration ? 'src/modules/mcp/bridge-vlan-configuration-http.test.ts' : protocolLimits ? 'src/modules/mcp/protocol-limits.owned.test.ts' : principalSecuritySource ? 'src/modules/mcp/principal-security-source.owned.test.ts' : pollJournalSnapshot ? 'src/services/server-poll-journal-snapshot.owned.test.ts' : pollTerminalArchive ? 'src/services/server-poll-terminal-archive.owned.test.ts' : pollArchiveSchema ? 'src/db/server-poll-terminal-archives.sql.test.ts' : telemetrySettingsConfiguration ? 'src/modules/mcp/telemetry-settings-configuration.owned.test.ts' : routingReservationSchema ? 'src/db/routing-reservation-schema.owned.test.ts' : routingForwardRounds ? 'src/modules/mcp/routing-network-forward-rounds.owned.test.ts' : flowActiveServices ? 'src/services/traffic-flow-active-services.owned.test.ts' : flowActiveRebuild ? 'src/services/traffic-flow-active-rebuild.owned.test.ts' : flowQuality ? 'src/services/traffic-flow-quality.owned.test.ts' : flowWorkerIpc ? 'src/services/traffic-flow-worker-ipc.owned.test.ts' : manualUptime ? 'src/modules/mcp/manual-uptime-http.test.ts' : manualPingGroup ? 'src/modules/mcp/manual-ping-group-http.test.ts' : manualTraffic ? 'src/modules/mcp/manual-traffic-http.test.ts' : manualApiPing ? 'src/modules/mcp/manual-api-ping-http.test.ts' : simpleSpeedChr ? 'src/modules/mcp/simple-speed-chr.test.ts' : simpleSpeed ? 'src/modules/mcp/simple-speed-http.test.ts' : externalPeerMetadata ? 'src/services/bandwidth-external-peer-metadata.sql.test.ts' : operatorPeerMetadata ? 'src/services/bandwidth-operator-metadata.sql.test.ts' : publicRegistryMetadata ? 'src/services/bandwidth-public-registry.sql.test.ts' : operatorDockerSql ? 'src/services/bandwidth-operator-docker-stop.sql.test.ts' : probeOperationRetirement ? 'src/services/server-probe-operation-retirement.owned.test.ts' : ordinaryOperationRetirement ? 'src/modules/mcp/ordinary-operation-retirement.owned.test.ts' : pollOperationRetirement ? 'src/services/server-poll-operation-retirement.owned.test.ts' : mcpOperationOrigin ? 'src/modules/mcp/operation-execution-origin.sql.test.ts' : mcpSpeedOriginal ? 'src/modules/mcp/speed-bandwidth-original.sql.test.ts' : routerConfigurationGuard ? 'src/services/router-configuration-guard.sql.test.ts' : scheduledSpeedOriginal ? 'src/services/bandwidth-scheduled-speed-original.sql.test.ts' : bandwidthSpeedWorkflow ? 'src/services/bandwidth-speed-workflow.sql.test.ts' : restSpeedOriginal ? 'src/services/bandwidth-rest-speed-original.sql.test.ts' : operationLocks ? 'src/services/operation-config-lock-lease.sql.test.ts' : serviceExecutionOrigin ? 'src/modules/mcp/service-execution-origin.sql.test.ts' : bandwidthNodeSource ? 'src/services/bandwidth-node-source.sql.test.ts' : bandwidthExternalRegistry ? 'src/services/bandwidth-external-node-registry.sql.test.ts' : bandwidthNodeRegistry ? 'src/services/bandwidth-node-registry.sql.test.ts' : bandwidthControlSource ? 'src/services/bandwidth-control-source.sql.test.ts' : bandwidthAdmission ? 'src/services/bandwidth-admission.sql.test.ts' : serverPollStorageFresh ? 'src/services/server-poll-storage-fresh.sql.test.ts' : serverPollStorage ? 'src/services/server-poll-storage.sql.test.ts' : probeStorageFresh ? 'src/services/server-probe-storage-fresh.sql.test.ts' : probeLegacyOrphans ? 'src/services/server-probe-legacy-orphans.sql.test.ts' : diagnosticCancelHost ? 'src/modules/mcp/diagnostic-cancellation-storage.sql.test.ts' : ipsecExportHttp ? 'src/modules/mcp/ipsec-existing-certificate-export-http.sql.test.ts' : ipsecExportJournal ? 'src/services/ipsec-existing-certificate-export-rest-journal.sql.test.ts' : migrationDataInventory ? 'src/db/migration-data-inventory.sql.test.ts' : probeStorageHistory ? 'src/services/server-probe-storage-history.sql.test.ts' : probeStorageJournal ? 'src/services/server-probe-storage-journal.sql.test.ts' : controlledSchemaReference ? 'src/db/controlled-schema-reference.sql.test.ts' : controlledMigrations ? 'src/db/controlled-migrations.sql.test.ts' : databaseSchemaControl ? 'src/db/database-schema-control.sql.test.ts' : migrationSchemaInventory ? 'src/db/migration-schema-inventory.sql.test.ts' : routingNetworkNative ? 'src/modules/mcp/routing-network-native.sql.test.ts' : routingReservationRuntime ? 'src/modules/mcp/routing-reservation-runtime.sql.test.ts' : routingReservations ? 'src/modules/mcp/routing-reservation.sql.test.ts' : collectorPartitionWriters ? 'src/services/collector-partition-writes.sql.test.ts' : serverPollDurable ? 'src/services/server-poll-durable-session.sql.test.ts' : routingRecoveryAuthority ? 'src/modules/mcp/routing-recovery-authority.sql.test.ts' : legacyFlowRebuild ? 'src/test/legacy-flow-rebuild-sql.ts' : probeJournal ? 'src/services/server-probe-journal.sql.test.ts' : flowHostKeys ? 'src/modules/mcp/flow-host-keys-http.test.ts' : flowRebuildMcp ? 'src/modules/mcp/flow-facts-rebuild-http.test.ts' : flowRebuild ? 'src/test/flow-facts-rebuild-sql.ts' : flowWrites ? 'src/services/traffic-flow-write-transaction.pg.test.ts' : nativeConservation ? 'src/modules/mcp/native-conservation-sql.test.ts' : nativeCreateId ? 'src/modules/mcp/native-create-id-http.test.ts' : ipsecAdapters ? "src/modules/mcp/ipsec-adapters-http.test.ts" : recoveryMaintenance ? "src/modules/mcp/recovery-maintenance-http.test.ts" : scopedCheckpointAdapters ? "src/modules/mcp/scoped-checkpoint-adapters-http.test.ts" : wireguardTransfer ? 'src/modules/mcp/wireguard-transfer-http.test.ts' : interfaceEventsCompatibility ? 'src/modules/mcp/interface-events-compatibility-http.test.ts' : scopedRoutingDiagnostics ? 'src/modules/mcp/scoped-routing-diagnostics-http.test.ts' : applicationAdapters ? 'src/modules/mcp/application-adapters-http.test.ts' : greRevision ? 'src/modules/mcp/gre-revision-http.test.ts' : chrGreRevisionRecovery ? 'src/modules/mcp/chr-gre-revision-recovery.test.ts' : chrGreRevision ? 'src/modules/mcp/chr-gre-revision.test.ts' : chrLegacyOspf ? 'src/modules/mcp/chr-ospf-legacy.test.ts' : chrFilters ? 'src/modules/mcp/chr-filter-write.test.ts' : chrGreMutation ? 'src/modules/mcp/chr-gre-mutation.test.ts' : chrFirewallRestore ? 'src/modules/mcp/chr-firewall-restore.test.ts' : chrAddress ? 'src/modules/mcp/chr-address-list.test.ts' : chrFirewallWrite ? 'src/modules/mcp/chr-firewall-write.test.ts' : chrVpn ? 'src/modules/mcp/chr-vpn-catalog.test.ts' : chrFirewallMove ? 'src/modules/mcp/chr-firewall-move.test.ts' : chrRecursive ? 'src/modules/mcp/chr-recursive-restore.test.ts' : chrIdentity ? 'src/modules/mcp/chr-ospf-identity-readonly.test.ts' : chrRead ? 'src/modules/mcp/chr-readonly-acceptance.test.ts' : chr ? 'src/modules/mcp/chr-acceptance.test.ts' : 'src/modules/mcp/integration.test.ts'], { + const child = spawn(process.execPath, pollMemory ? ['--max-old-space-size=192', '--max-semi-space-size=16', fileURLToPath(new URL('../dist-mcp-memory/services/server-poll-memory.owned.test.js', import.meta.url))] : ['--import', 'tsx', ...(flowActiveRebuild ? ['--import', new URL('../src/services/traffic-flow-active-rebuild-preload.mjs', import.meta.url).href] : []), acceptanceShard ? 'src/modules/mcp/acceptance-shard.test.ts' : usersBindings ? 'src/modules/mcp/users-bindings-owned.test.ts' : bridgeVlanConfiguration ? 'src/modules/mcp/bridge-vlan-configuration-http.test.ts' : protocolLimits ? 'src/modules/mcp/protocol-limits.owned.test.ts' : principalSecuritySource ? 'src/modules/mcp/principal-security-source.owned.test.ts' : pollJournalSnapshot ? 'src/services/server-poll-journal-snapshot.owned.test.ts' : pollTerminalArchive ? 'src/services/server-poll-terminal-archive.owned.test.ts' : pollArchiveSchema ? 'src/db/server-poll-terminal-archives.sql.test.ts' : telemetrySettingsConfiguration ? 'src/modules/mcp/telemetry-settings-configuration.owned.test.ts' : routingReservationSchema ? 'src/db/routing-reservation-schema.owned.test.ts' : routingForwardRounds ? 'src/modules/mcp/routing-network-forward-rounds.owned.test.ts' : flowActiveServices ? 'src/services/traffic-flow-active-services.owned.test.ts' : flowActiveRebuild ? 'src/services/traffic-flow-active-rebuild.owned.test.ts' : flowQuality ? 'src/services/traffic-flow-quality.owned.test.ts' : flowWorkerIpc ? 'src/services/traffic-flow-worker-ipc.owned.test.ts' : manualUptime ? 'src/modules/mcp/manual-uptime-http.test.ts' : manualPingGroup ? 'src/modules/mcp/manual-ping-group-http.test.ts' : manualTraffic ? 'src/modules/mcp/manual-traffic-http.test.ts' : manualApiPing ? 'src/modules/mcp/manual-api-ping-http.test.ts' : simpleSpeedChr ? 'src/modules/mcp/simple-speed-chr.test.ts' : simpleSpeed ? 'src/modules/mcp/simple-speed-http.test.ts' : externalPeerMetadata ? 'src/services/bandwidth-external-peer-metadata.sql.test.ts' : operatorPeerMetadata ? 'src/services/bandwidth-operator-metadata.sql.test.ts' : publicRegistryMetadata ? 'src/services/bandwidth-public-registry.sql.test.ts' : operatorDockerSql ? 'src/services/bandwidth-operator-docker-stop.sql.test.ts' : probeOperationRetirement ? 'src/services/server-probe-operation-retirement.owned.test.ts' : ordinaryOperationRetirement ? 'src/modules/mcp/ordinary-operation-retirement.owned.test.ts' : pollOperationRetirement ? 'src/services/server-poll-operation-retirement.owned.test.ts' : mcpOperationOrigin ? 'src/modules/mcp/operation-execution-origin.sql.test.ts' : mcpSpeedOriginal ? 'src/modules/mcp/speed-bandwidth-original.sql.test.ts' : routerConfigurationGuard ? 'src/services/router-configuration-guard.sql.test.ts' : scheduledSpeedOriginal ? 'src/services/bandwidth-scheduled-speed-original.sql.test.ts' : bandwidthSpeedWorkflow ? 'src/services/bandwidth-speed-workflow.sql.test.ts' : restSpeedOriginal ? 'src/services/bandwidth-rest-speed-original.sql.test.ts' : operationLocks ? 'src/services/operation-config-lock-lease.sql.test.ts' : serviceExecutionOrigin ? 'src/modules/mcp/service-execution-origin.sql.test.ts' : bandwidthNodeSource ? 'src/services/bandwidth-node-source.sql.test.ts' : bandwidthExternalRegistry ? 'src/services/bandwidth-external-node-registry.sql.test.ts' : bandwidthNodeRegistry ? 'src/services/bandwidth-node-registry.sql.test.ts' : bandwidthControlSource ? 'src/services/bandwidth-control-source.sql.test.ts' : bandwidthAdmission ? 'src/services/bandwidth-admission.sql.test.ts' : serverPollStorageFresh ? 'src/services/server-poll-storage-fresh.sql.test.ts' : serverPollStorage ? 'src/services/server-poll-storage.sql.test.ts' : probeStorageFresh ? 'src/services/server-probe-storage-fresh.sql.test.ts' : probeLegacyOrphans ? 'src/services/server-probe-legacy-orphans.sql.test.ts' : diagnosticCancelHost ? 'src/modules/mcp/diagnostic-cancellation-storage.sql.test.ts' : ipsecExportHttp ? 'src/modules/mcp/ipsec-existing-certificate-export-http.sql.test.ts' : ipsecExportJournal ? 'src/services/ipsec-existing-certificate-export-rest-journal.sql.test.ts' : migrationDataInventory ? 'src/db/migration-data-inventory.sql.test.ts' : probeStorageHistory ? 'src/services/server-probe-storage-history.sql.test.ts' : probeStorageJournal ? 'src/services/server-probe-storage-journal.sql.test.ts' : controlledSchemaReference ? 'src/db/controlled-schema-reference.sql.test.ts' : controlledMigrations ? 'src/db/controlled-migrations.sql.test.ts' : databaseSchemaControl ? 'src/db/database-schema-control.sql.test.ts' : migrationSchemaInventory ? 'src/db/migration-schema-inventory.sql.test.ts' : routingNetworkNative ? 'src/modules/mcp/routing-network-native.sql.test.ts' : routingReservationRuntime ? 'src/modules/mcp/routing-reservation-runtime.sql.test.ts' : routingReservations ? 'src/modules/mcp/routing-reservation.sql.test.ts' : collectorPartitionWriters ? 'src/services/collector-partition-writes.sql.test.ts' : serverPollDurable ? 'src/services/server-poll-durable-session.sql.test.ts' : routingRecoveryAuthority ? 'src/modules/mcp/routing-recovery-authority.sql.test.ts' : legacyFlowRebuild ? 'src/test/legacy-flow-rebuild-sql.ts' : probeJournal ? 'src/services/server-probe-journal.sql.test.ts' : flowHostKeys ? 'src/modules/mcp/flow-host-keys-http.test.ts' : flowRebuildMcp ? 'src/modules/mcp/flow-facts-rebuild-http.test.ts' : flowRebuild ? 'src/test/flow-facts-rebuild-sql.ts' : flowWrites ? 'src/services/traffic-flow-write-transaction.pg.test.ts' : nativeConservation ? 'src/modules/mcp/native-conservation-sql.test.ts' : nativeCreateId ? 'src/modules/mcp/native-create-id-http.test.ts' : ipsecAdapters ? "src/modules/mcp/ipsec-adapters-http.test.ts" : recoveryMaintenance ? "src/modules/mcp/recovery-maintenance-http.test.ts" : scopedCheckpointAdapters ? "src/modules/mcp/scoped-checkpoint-adapters-http.test.ts" : wireguardTransfer ? 'src/modules/mcp/wireguard-transfer-http.test.ts' : interfaceEventsCompatibility ? 'src/modules/mcp/interface-events-compatibility-http.test.ts' : scopedRoutingDiagnostics ? 'src/modules/mcp/scoped-routing-diagnostics-http.test.ts' : applicationAdapters ? 'src/modules/mcp/application-adapters-http.test.ts' : greRevision ? 'src/modules/mcp/gre-revision-http.test.ts' : chrGreRevisionRecovery ? 'src/modules/mcp/chr-gre-revision-recovery.test.ts' : chrGreRevision ? 'src/modules/mcp/chr-gre-revision.test.ts' : chrLegacyOspf ? 'src/modules/mcp/chr-ospf-legacy.test.ts' : chrFilters ? 'src/modules/mcp/chr-filter-write.test.ts' : chrGreMutation ? 'src/modules/mcp/chr-gre-mutation.test.ts' : chrFirewallRestore ? 'src/modules/mcp/chr-firewall-restore.test.ts' : chrAddress ? 'src/modules/mcp/chr-address-list.test.ts' : chrFirewallWrite ? 'src/modules/mcp/chr-firewall-write.test.ts' : chrVpn ? 'src/modules/mcp/chr-vpn-catalog.test.ts' : chrFirewallMove ? 'src/modules/mcp/chr-firewall-move.test.ts' : chrRecursive ? 'src/modules/mcp/chr-recursive-restore.test.ts' : chrIdentity ? 'src/modules/mcp/chr-ospf-identity-readonly.test.ts' : chrRead ? 'src/modules/mcp/chr-readonly-acceptance.test.ts' : chr ? 'src/modules/mcp/chr-acceptance.test.ts' : 'src/modules/mcp/integration.test.ts'], { cwd: pollMemory ? directory : new URL('../', import.meta.url), stdio: 'inherit', env: { ...(pollMemory ? pollMemoryEnvironment : process.env), MMAPP_OWN_SKIP_POLL_CAPACITY: String(pollRetirementFocused), MMAPP_OWN_PROTOCOL_LIMITS: String(protocolLimits), @@ -283,6 +286,7 @@ try { MMAPP_OWN_REST_REPLICA_ONLY: String(restReplicaOnly), MMAPP_OWN_RESTORE_QUARANTINE_ONLY: String(restoreQuarantineOnly), MMAPP_OWN_LOGS_SDK_SCENARIO: logsSdkScenario, + MCP_ACCEPTANCE_SHARD: acceptanceShard ?? '', MMAPP_OWN_SQLITE_IMPORT_CLI_ONLY: String(sqliteImportCliOnly), MMAPP_OWN_LEGACY_BGP_ONLY: String(legacyBgpOnly), ...(routingOriginalEffects ? { MMAPP_OWN_ROUTING_ORIGINAL_EFFECTS: 'true' } : {}), @@ -296,7 +300,7 @@ try { }) exitCode = result if (result === 0 && restoreQuarantineOnly) console.log('Restore quarantine: focused real PostgreSQL restore scenario complete') - else if (result === 0 && !regressionOnly && !profilesOnly && !usersBindings && !bridgeVlanConfiguration && !protocolLimits && !pollMemory && !principalSecuritySource && !pollJournalSnapshot && !pollArchiveSchema && !telemetrySettingsConfiguration && !routingReservationSchema && !routingForwardRounds && !flowActiveServices && !flowActiveRebuild && !flowQuality && !flowWorkerIpc && !manualUptime && !manualPingGroup && !manualTraffic && !manualApiPing && !simpleSpeed && !simpleSpeedChr && !externalPeerMetadata && !operatorPeerMetadata && !publicRegistryMetadata && !operatorDockerSql && !mcpOperationOrigin && !mcpSpeedOriginal && !routerConfigurationGuard && !scheduledSpeedOriginal && !bandwidthSpeedWorkflow && !restSpeedOriginal && !operationLocks && !serviceExecutionOrigin && !bandwidthNodeSource && !bandwidthNodeRegistry && !bandwidthExternalRegistry && !bandwidthControlSource && !bandwidthAdmission && !probeLegacyOrphans && !probeStorageJournal && !probeStorageHistory && !probeJournal && !chr && !flowWrites && !flowRebuild && !flowRebuildMcp && (process.argv.includes('--restore') || process.env.MMAPP_PG_CLIENT_BIN)) { + else if (result === 0 && !acceptanceShard && !regressionOnly && !profilesOnly && !usersBindings && !bridgeVlanConfiguration && !protocolLimits && !pollMemory && !principalSecuritySource && !pollJournalSnapshot && !pollArchiveSchema && !telemetrySettingsConfiguration && !routingReservationSchema && !routingForwardRounds && !flowActiveServices && !flowActiveRebuild && !flowQuality && !flowWorkerIpc && !manualUptime && !manualPingGroup && !manualTraffic && !manualApiPing && !simpleSpeed && !simpleSpeedChr && !externalPeerMetadata && !operatorPeerMetadata && !publicRegistryMetadata && !operatorDockerSql && !mcpOperationOrigin && !mcpSpeedOriginal && !routerConfigurationGuard && !scheduledSpeedOriginal && !bandwidthSpeedWorkflow && !restSpeedOriginal && !operationLocks && !serviceExecutionOrigin && !bandwidthNodeSource && !bandwidthNodeRegistry && !bandwidthExternalRegistry && !bandwidthControlSource && !bandwidthAdmission && !probeLegacyOrphans && !probeStorageJournal && !probeStorageHistory && !probeJournal && !chr && !flowWrites && !flowRebuild && !flowRebuildMcp && (process.argv.includes('--restore') || process.env.MMAPP_PG_CLIENT_BIN)) { exitCode = await new Promise((resolve, reject) => { const child = spawn(process.execPath, ['--import', 'tsx', 'src/modules/mcp/database-restore.test.ts'], { cwd: new URL('../', import.meta.url), stdio: 'inherit', env: { ...process.env, diff --git a/backend/src/modules/mcp/acceptance-shard.test.ts b/backend/src/modules/mcp/acceptance-shard.test.ts new file mode 100644 index 00000000..2fbed10c --- /dev/null +++ b/backend/src/modules/mcp/acceptance-shard.test.ts @@ -0,0 +1,26 @@ +import assert from "node:assert/strict" +// Run only from scripts/test-mcp-postgres.mjs --acceptance-shard=: a disposable PostgreSQL of its own. +const { acceptanceShardNames, ACCEPTANCE_SHARDS } = await import("./acceptance-shards.js") +const names = acceptanceShardNames(process.env.MCP_ACCEPTANCE_SHARD) +assert.ok(names.length, "MCP_ACCEPTANCE_SHARD lists no acceptance") +const { pool, closePool } = await import("../../db/index.js") +const { applySqlMigrations } = await import("../../db/migrate.js") +const { updateMcpSettings } = await import("./store.js") +const actor = { id: "integration-owner", email: "test@example.invalid", name: "Test", apps: ["mm"], permissions: ["mm:settings:admin", "mm:certificates:write", "mm:network:admin", "mm:bgp:admin", "mm:servers:admin", "mm:filters:admin"], expiresAt: Date.now() + 4 * 3600000 } +try { + await applySqlMigrations(pool) + assert.equal((await pool.query("SELECT count(*)::int AS n FROM servers")).rows[0].n, 0, "Disposable empty database required") + await updateMcpSettings({ enabled: true }, actor) + for (const name of names) { + const started = performance.now() + await ACCEPTANCE_SHARDS[name](actor) + console.log(`✓ shard ${name} ${((performance.now() - started) / 1000).toFixed(1)}s`) + } +} finally { + await pool.query("UPDATE servers SET enabled=false").catch(() => {}) + await (await import("../../services/scheduler.js")).stopSchedulerForDatabaseOperation() + await (await import("../../services/traffic-flow-ingest.js")).stopTrafficFlowListenerForDatabaseOperation() + await closePool() +} +// The same teardown leak as integration.test.ts can keep the loop alive; exit once output is flushed. +process.stderr.write("", () => process.stdout.write("", () => process.exit())) diff --git a/backend/src/modules/mcp/acceptance-shards.ts b/backend/src/modules/mcp/acceptance-shards.ts new file mode 100644 index 00000000..304418a8 --- /dev/null +++ b/backend/src/modules/mcp/acceptance-shards.ts @@ -0,0 +1,21 @@ +import type { AuthUser } from "../../lib/permissions.js" + +/** Self-contained acceptances (own server rows, own MCP connections) that can run in a separate + * process against their own disposable PostgreSQL. integration.test.ts skips the names listed in + * 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), + 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), + acceptWireguardInterfaceUpdate: async actor => (await import("./wireguard-interface-update-acceptance.js")).acceptWireguardInterfaceUpdate(actor), + acceptWireguardImport: async actor => (await import("./wireguard-import-acceptance.js")).acceptWireguardImport(actor), +} + +/** 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) + const unknown = names.filter(name => !Object.hasOwn(ACCEPTANCE_SHARDS, name)) + if (unknown.length) throw new Error(`Unknown acceptance shard: ${unknown.join(", ")}`) + return names +} diff --git a/backend/src/modules/mcp/integration.test.ts b/backend/src/modules/mcp/integration.test.ts index 1dc313a2..239c3f2e 100644 --- a/backend/src/modules/mcp/integration.test.ts +++ b/backend/src/modules/mcp/integration.test.ts @@ -36,6 +36,12 @@ const soft = async (name: string, check: () => Promise) => { if (process.env.MCP_INTEGRATION_CONTINUE !== "1") return check() 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 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)) +} // One fixed authority deadline for the long integration suite; never renewed during the run. const fixtureAuthExpiresAt = Date.now() + 4 * 60 * 60 * 1000 const actor: AuthUser = { id: "integration-owner", email: "test@example.invalid", name: "Test", apps: ["mm"], permissions: ["mm:settings:admin", "mm:certificates:write", "mm:network:admin", "mm:bgp:admin", "mm:servers:admin", "mm:filters:admin"], expiresAt: fixtureAuthExpiresAt } @@ -1727,9 +1733,9 @@ try { await acceptWireguardPeerDeletion(actor) await acceptWireguardPeerUpdate(actor) await acceptWireguardInterfaceDeletion(actor) - await (await import("./wireguard-interface-create-acceptance.js")).acceptWireguardInterfaceCreation(actor) - await (await import("./routing-community-context-acceptance.js")).acceptRouteCommunityContextMcp(actor) - await (await import("./wireguard-peer-create-acceptance.js")).acceptWireguardPeerCreation(actor) + await shardable("acceptWireguardInterfaceCreation") + await shardable("acceptRouteCommunityContextMcp") + await shardable("acceptWireguardPeerCreation") await (await import("../../test/mcp-flow-analytics.js")).verifyMcpFlowAnalytics(actor) await (await import("../../test/mcp-flow-map.js")).verifyMcpFlowMap(actor) await (await import("../../test/mcp-flow-live.js")).verifyMcpFlowLive(actor) @@ -2981,11 +2987,11 @@ try { await fixtureScheduler.pauseSchedulerJobsAndWait() try { await soft("verifyMcpControlPathContext", async () => (await import("./control-path-context-acceptance.js")).verifyMcpControlPathContext(actor)) - await soft("acceptScopedRouteCommunitySwitch", async () => (await import("./routing-community-scoped-acceptance.js")).acceptScopedRouteCommunitySwitch(actor)) + await shardable("acceptScopedRouteCommunitySwitch") await soft("verifyMcpTerminalDiagnostics", async () => (await import("../../test/mcp-terminal-diagnostics.js")).verifyMcpTerminalDiagnostics(actor, app)) await soft("verifyMcpEventsBatch", async () => (await import("../../test/mcp-events-batch.js")).verifyMcpEventsBatch(actor, app)) - await soft("acceptWireguardInterfaceUpdate", async () => (await import("./wireguard-interface-update-acceptance.js")).acceptWireguardInterfaceUpdate(actor)) - await soft("acceptWireguardImport", async () => (await import("./wireguard-import-acceptance.js")).acceptWireguardImport(actor)) + await shardable("acceptWireguardInterfaceUpdate") + await shardable("acceptWireguardImport") await soft("acceptWireguardExportMcp", async () => (await import("./wireguard-export-acceptance.js")).acceptWireguardExportMcp(actor, app)) await soft("acceptProtectionRegistrationScope", async () => (await import("./protection-scope-acceptance.js")).acceptProtectionRegistrationScope(actor)) console.log("Routing controller CAS SQL:", await (await import("./routing-controller-cas-acceptance.js")).acceptRoutingControllerCas())