Files
MikrotikManager/backend/scripts/test-mcp-postgres-sharded.mjs
T
DenozordecandClaude Opus 5.5 1e96ddac79 chore(test): вынести 14 самодостаточных приёмок из основного набора MCP, объединить шарды
- шард misc: 14 приёмок, которые создают свои серверы и проходят в чистой БД
  (BGP, фильтры, аптайм, путь, артефакты логов, live-трафик, контекст пути,
  management transport, сохранение и CREATE ID); verifyMcpAlertsOutbox зависит от
  состояния основного набора и остался в нём;
- шарды scoped forward+inverse и WireGuard объединены: меньше процессов спорят за CPU;
- acceptance-shard.test.ts при MCP_INTEGRATION_CONTINUE=1 продолжает после отказа
  и перечисляет все упавшие приёмки;
- mcp-host-files: в сообщение отказа добавлен error_code (один нестабильный отказ
  rejected до отправки за 4 прогона, причина не установлена).

Замер: основной набор отдельно 180-277 с (разброс машины до 30%), шарды 93-144 с;
149 строк результатов на месте.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-19 15:11:47 +07:00

51 lines
3.4 KiB
JavaScript

// 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, after the service speed-ups): each shard ~60-150 s,
// the primary ~220 s. Fewer, fuller shards leave more CPU to the primary.
const shards = {
'scoped-forward-inverse': ['acceptScopedRouteCommunitySwitch:forward', 'acceptScopedRouteCommunitySwitch:inverse'],
'scoped-route-ai': ['acceptScopedRouteCommunitySwitch:route-ai'],
wireguard: ['acceptWireguardInterfaceCreation', 'acceptRouteCommunityContextMcp', 'acceptWireguardPeerCreation', 'acceptWireguardInterfaceUpdate', 'acceptWireguardImport'],
misc: ['verifyMcpBgpExport', 'verifyMcpBgpFilterBinding', 'verifyMcpBgpCommunityPolicy', 'verifyMcpBgpPrefixes', 'verifyMcpFilterWrites', 'verifyMcpUptimeOverview', 'verifyMcpPathCompletion', 'verifyMcpLogArtifacts', 'verifyMcpFlowLive', 'verifyMcpControlPathContext', 'acceptManagementTransport', 'acceptRouteCommunityContextCompatibilityMcp', 'acceptNativeConservation', 'acceptNativeCreateId'],
'overlay-ipsec': ['verifyMcpFlowOverlay', 'acceptWireguardInterfaceDeletion', 'acceptIpsecPeerDeletion', 'acceptIpsecUserDeletion', 'acceptIpsecCertificateDeletion', 'acceptIpsecPeerUpdate'],
}
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