Files
MikrotikManager/backend/scripts/test-mcp-postgres-sharded.mjs
T
DenozordecandClaude Opus 5.5 816660b239 chore(test): разбить приёмку scoped-маршрутизации на три шарда
Опция `part` (forward, inverse, route-ai) запускает один этап приёмки; без опции
выполняются все три, как раньше. Основной набор пропускает приёмку целиком, только
если в шардах перечислены все её части; неполный набор частей - ошибка
(acceptance-shards.test.ts).

Замер: весь набор 334 с (был 430 с, до шардов 958 с проверок), 149 строк
результатов совпадают с прошлым шардированным прогоном, каждый этап выполнен один раз.

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

50 lines
2.8 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): each shard ~110-190 s, the primary ~320 s.
const shards = {
'scoped-forward': ['acceptScopedRouteCommunitySwitch:forward'],
'scoped-inverse': ['acceptScopedRouteCommunitySwitch:inverse'],
'scoped-route-ai': ['acceptScopedRouteCommunitySwitch:route-ai'],
'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