29 lines
1.4 KiB
JavaScript
29 lines
1.4 KiB
JavaScript
import { test } from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { mkdtempSync, mkdirSync, writeFileSync, rmSync } from 'node:fs';
|
|
import { tmpdir } from 'node:os';
|
|
import { dirname, join } from 'node:path';
|
|
const secret = 'sk-test-NOT-A-SECRET-1234';
|
|
// JSON.parse quotes a prefix near this fault on Node 26; check partial leaks too.
|
|
const malformed = secret;
|
|
function scratch(t) {
|
|
const root = mkdtempSync(join(tmpdir(), 'r3-'));
|
|
t.after(() => rmSync(root, { recursive: true, force: true }));
|
|
return root;
|
|
}
|
|
function write(file, text = malformed) {
|
|
mkdirSync(dirname(file), { recursive: true });
|
|
writeFileSync(file, text, { mode: 0o600 });
|
|
return file;
|
|
}
|
|
import { checkProject, initProject } from '../src/index.mjs';
|
|
test('project record JSON problems name the file without parser bytes', async t => {
|
|
const root = scratch(t), context = { business: { id: 'acme', human: 'jason', projects: { stack: { root: join(root, 'code') } } }, project: 'stack', dataRoot: join(root, 'data') };
|
|
const { repo } = await initProject(context);
|
|
write(join(repo, 'requirements/REQ-1.json'));
|
|
const result = await checkProject(context);
|
|
assert.equal(result.ok, false);
|
|
assert.ok(result.problems.some(p => p.includes('requirements/REQ-1.json: invalid JSON')), JSON.stringify(result.problems));
|
|
assert.doesNotMatch(JSON.stringify(result), /sk-test|Unexpected token/);
|
|
});
|