Files
MikrotikManager/backend/scripts/test-mcp-postgres-sharded.mjs
T
DenozordecandClaude Opus 5.5 aca54ec213 chore(test): запускать интеграционный набор MCP шардами параллельно
`npm --prefix backend run test:mcp:pg:sharded`: основной набор и три шарда
(маршрутизация scoped, создание WireGuard, изменение WireGuard), каждый со своей
одноразовой PostgreSQL. Основной набор пропускает ровно те приёмки, что идут в
шардах (MCP_INTEGRATION_SKIP), неизвестное имя - ошибка с обеих сторон.

Замер: 430 с вместо 958 с проверок (плюс прежние 15 минут зависания на выходе);
все 147 проверок полного прогона на месте, этап восстановления БД пройден.

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

48 lines
2.6 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): 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