36 lines
1.7 KiB
JavaScript
36 lines
1.7 KiB
JavaScript
// Diagnostic only: retain owned adapter stderr before the fixture's normal cleanup.
|
|
// No test assertion, deadline, fixture, process launch or production code is changed.
|
|
import fs from 'node:fs';
|
|
import { join, resolve } from 'node:path';
|
|
import { syncBuiltinESMExports } from 'node:module';
|
|
const remove = fs.rmSync;
|
|
const tmp = resolve(process.env.TMPDIR);
|
|
const output = process.env.P332_CLEANUP_DIAGNOSTIC;
|
|
fs.rmSync = function(path, options) {
|
|
const root = resolve(String(path));
|
|
if (output && root.startsWith(tmp + '/') && root.slice(tmp.length + 1).startsWith('mosaic-launch-')) {
|
|
try {
|
|
const runs = join(root, 'data', 'launches', 'acme');
|
|
const captured = [];
|
|
for (const name of fs.readdirSync(runs)) {
|
|
const run = join(runs, name), file = join(run, 'session.json');
|
|
if (!fs.existsSync(file)) continue;
|
|
const session = JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
const stderr = {};
|
|
const turns = join(run, 'turns');
|
|
if (fs.existsSync(turns)) for (const entry of fs.readdirSync(turns)) {
|
|
if (!entry.endsWith('.stderr')) continue;
|
|
let text = fs.readFileSync(join(turns, entry), 'utf8');
|
|
for (const value of ['stand-in','fx332-pi','fx653-pi']) text = text.split(value).join('[fake-value-redacted]');
|
|
stderr[entry] = text;
|
|
}
|
|
captured.push({ harness: session.harness, adapter: session.adapter,
|
|
harnessEnvironmentNames: Object.keys(session.harnessEnv).sort(), stderr });
|
|
}
|
|
fs.writeFileSync(output, JSON.stringify(captured, null, 2) + '\n', { mode: 0o600 });
|
|
} catch {}
|
|
}
|
|
return remove.call(this, path, options);
|
|
};
|
|
syncBuiltinESMExports();
|