// sarif-version.test.mjs — Regression for #56 (LOW, v7.8.3). // // toSARIF defaults version='6.0.0' and the orchestrator called toSARIF(output) // with no version argument, so SARIF output hardcoded a stale driver.version. // The orchestrator must pass the real plugin version (package.json) through. import { describe, it } from 'node:test'; import assert from 'node:assert/strict'; import { spawn } from 'node:child_process'; import { resolve, dirname, join } from 'node:path'; import { fileURLToPath } from 'node:url'; import { mkdtempSync, writeFileSync, rmSync, readFileSync } from 'node:fs'; import { tmpdir } from 'node:os'; const __dirname = dirname(fileURLToPath(import.meta.url)); const ORCHESTRATOR = resolve(__dirname, '../../scanners/scan-orchestrator.mjs'); const PKG_VERSION = JSON.parse( readFileSync(resolve(__dirname, '../../package.json'), 'utf8'), ).version; function run(args, timeout = 120000) { return new Promise((resolvePromise) => { const chunks = []; const errChunks = []; const child = spawn('node', [ORCHESTRATOR, ...args], { timeout, stdio: ['ignore', 'pipe', 'pipe'], }); child.stdout.on('data', (c) => chunks.push(c)); child.stderr.on('data', (c) => errChunks.push(c)); child.on('close', (code) => { resolvePromise({ code: code ?? 1, stdout: Buffer.concat(chunks).toString(), stderr: Buffer.concat(errChunks).toString(), }); }); }); } describe('scan-orchestrator: SARIF driver.version (#56)', () => { it('driver.version matches package.json version, not the stale 6.0.0 default', async () => { const dir = mkdtempSync(join(tmpdir(), 'sarif-version-')); try { writeFileSync(join(dir, 'README.md'), '# tiny fixture\n'); const { stdout } = await run([dir, '--format', 'sarif']); const sarif = JSON.parse(stdout); const driver = sarif.runs[0].tool.driver; assert.equal( driver.version, PKG_VERSION, `SARIF driver.version should be the plugin version ${PKG_VERSION}, got ${driver.version}`, ); } finally { rmSync(dir, { recursive: true, force: true }); } }); });