mirror of
https://github.com/pbakaus/impeccable.git
synced 2026-09-12 22:26:38 +03:00
Recover joined URL arguments without splitting local paths, derive advisory behavior from registry severity across consumers, inspect readable linked CSS in URL scans, and report only the dominant primary font. AI assistance disclosure: Implemented and verified with Codex under maintainer direction.
68 lines
2.1 KiB
JavaScript
68 lines
2.1 KiB
JavaScript
import { after, describe, it } from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import fs from 'node:fs';
|
|
import os from 'node:os';
|
|
import path from 'node:path';
|
|
import { spawnSync } from 'node:child_process';
|
|
import { fileURLToPath } from 'node:url';
|
|
|
|
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
const cli = path.join(root, 'cli', 'bin', 'cli.js');
|
|
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'impeccable-stdin-dispatch-'));
|
|
|
|
function detectStdinFile(filePath, expectedStatus = 2) {
|
|
const result = spawnSync(
|
|
process.execPath,
|
|
[cli, 'detect', '--json', '--no-config', '--no-design-system'],
|
|
{
|
|
input: JSON.stringify({ tool_input: { file_path: filePath } }),
|
|
encoding: 'utf8',
|
|
},
|
|
);
|
|
assert.equal(result.status, expectedStatus, result.stderr);
|
|
return JSON.parse(result.stdout);
|
|
}
|
|
|
|
after(() => {
|
|
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
});
|
|
|
|
describe('detect CLI stdin file dispatch', () => {
|
|
it('uses the static HTML engine for an HTML tool-input path', () => {
|
|
const filePath = path.join(tempDir, 'page.html');
|
|
fs.writeFileSync(
|
|
path.join(tempDir, 'page.css'),
|
|
'.notice { border-left: 4px solid blue; border-radius: 12px; }',
|
|
);
|
|
fs.writeFileSync(filePath, `
|
|
<!doctype html>
|
|
<link rel="stylesheet" href="./page.css">
|
|
<div class="notice">Notice</div>
|
|
`);
|
|
|
|
const findings = detectStdinFile(filePath);
|
|
assert.ok(findings.some(
|
|
(item) => item.file === filePath && item.antipattern === 'side-tab',
|
|
));
|
|
});
|
|
|
|
it('uses the text engine for a non-HTML tool-input path', () => {
|
|
const filePath = path.join(tempDir, 'styles.css');
|
|
fs.writeFileSync(filePath, `
|
|
.grid {
|
|
background-image:
|
|
linear-gradient(#eee 1px, transparent 1px),
|
|
linear-gradient(90deg, #eee 1px, transparent 1px);
|
|
background-size: 24px 24px;
|
|
}
|
|
`);
|
|
|
|
const findings = detectStdinFile(filePath, 0);
|
|
assert.ok(findings.some(
|
|
(item) => item.file === filePath
|
|
&& item.antipattern === 'codex-grid-background'
|
|
&& item.advisory === true,
|
|
));
|
|
});
|
|
});
|