import assert from 'node:assert/strict'; import { spawnSync } from 'node:child_process'; import path from 'node:path'; const repoRoot = process.cwd(); const scriptPath = path.join(repoRoot, 'scripts', 'postgres-tuning-evidence.js'); function run(args) { return spawnSync(process.execPath, [scriptPath, ...args], { cwd: repoRoot, encoding: 'utf8', env: { PATH: process.env.PATH || '', Path: process.env.Path || '', SystemRoot: process.env.SystemRoot || '', ComSpec: process.env.ComSpec || '', TEMP: process.env.TEMP || '', TMP: process.env.TMP || '', }, }); } const sharedSql = run(['--print-sql', '--profile=shared-host']); assert.equal(sharedSql.status, 0, sharedSql.stderr); assert.match(sharedSql.stdout, /alter system set shared_buffers = '3GB';/); assert.match(sharedSql.stdout, /alter system set statement_timeout = '30s';/); assert.match(sharedSql.stdout, /alter system set jit = 'off';/); assert.match(sharedSql.stdout, /alter system set track_io_timing = 'on';/); assert.match(sharedSql.stdout, /alter system set track_wal_io_timing = 'on';/); assert.match(sharedSql.stdout, /alter system set temp_file_limit = '4GB';/); const dedicatedSql = run(['--print-sql', '--profile=dedicated-db']); assert.equal(dedicatedSql.status, 0, dedicatedSql.stderr); assert.match(dedicatedSql.stdout, /alter system set shared_buffers = '4GB';/); assert.match(dedicatedSql.stdout, /alter system set max_wal_size = '8GB';/); assert.match(dedicatedSql.stdout, /alter system set temp_file_limit = '8GB';/); const invalidProfile = run(['--print-sql', '--profile=unknown']); assert.notEqual(invalidProfile.status, 0, 'unknown profile should fail'); assert.match(`${invalidProfile.stderr}${invalidProfile.stdout}`, /Unknown PostgreSQL tuning profile/); console.log('[PASS] PostgreSQL tuning evidence helpers');