rachnasutra 0.5.2 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +32 -1
- package/CITATION.cff +2 -2
- package/README.md +4 -4
- package/dist/audit.js +117 -18
- package/dist/baseline.js +52 -0
- package/dist/browser.js +35 -5
- package/dist/cli.js +140 -27
- package/dist/fsutil.js +11 -4
- package/dist/redact.js +17 -7
- package/dist/report.js +51 -17
- package/dist/rules.js +70 -19
- package/dist/verify.js +35 -7
- package/docs/cli-reference.md +16 -3
- package/docs/status.md +2 -2
- package/documents/rachnasutra/00-overview.md +13 -2
- package/documents/rachnasutra/01-executive-summary.md +3 -1
- package/documents/rachnasutra/02-functional-specification.md +1 -1
- package/documents/rachnasutra/03-architecture.md +4 -0
- package/documents/rachnasutra/04-technical-reference.md +12 -7
- package/documents/rachnasutra/05-user-guide.md +53 -3
- package/documents/rachnasutra/07-skills-and-agents.md +2 -0
- package/documents/rachnasutra/08-security-and-privacy.md +2 -1
- package/documents/rachnasutra/10-testing-and-evidence.md +9 -5
- package/documents/rachnasutra/11-deployment-and-ci.md +2 -0
- package/documents/rachnasutra/12-roadmap-and-status.md +2 -2
- package/documents/rachnasutra/13-maintainer-handbook.md +4 -0
- package/documents/rachnasutra/16-validation-and-benchmarks.md +12 -2
- package/documents/rachnasutra/18-quick-tour.md +120 -0
- package/documents/rachnasutra/19-real-world-scenarios.md +251 -0
- package/llms.txt +2 -0
- package/package.json +4 -2
- package/samples/broken-ui/latest.html +96 -73
- package/samples/broken-ui/latest.json +236 -25
- package/samples/broken-ui/latest.md +2 -2
- package/samples/broken-ui/latest.sarif +1 -1
- package/samples/good-ui/latest.html +27 -7
- package/samples/good-ui/latest.json +4 -3
- package/samples/good-ui/latest.md +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -2,7 +2,38 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes follow [Semantic Versioning](https://semver.org/). Report schema version is tracked separately (`schemaVersion`).
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## 0.6.0
|
|
6
|
+
|
|
7
|
+
Upgrading from 0.5.x: some pipelines that passed will now exit 2 or 5. See "Behaviour changes" below. Tag `v0.6.0` publishes this version through `.github/workflows/publish.yml`.
|
|
8
|
+
|
|
9
|
+
- HTML reports: Auto, Light, Dark and Mix themes, severity and status filters, highlighted code context and print styles. Still no script
|
|
10
|
+
- JSON findings carry `evidence[].context` (redacted source lines). `--no-excerpts` removes it
|
|
11
|
+
- New `rachnasutra baseline` command, `--baseline` flag and `baseline` config key: gates count new findings only, and a repeated `baseline` run removes fixed entries without adding new ones. SARIF results carry `baselineState`
|
|
12
|
+
- New `rachnasutra-disable-next-line`, `-line` and `-file` comments. A rule ID is required. Silenced findings are counted in reports and listed under `suppressed` in JSON
|
|
13
|
+
|
|
14
|
+
Behaviour changes. Read these before upgrading a pipeline.
|
|
15
|
+
|
|
16
|
+
- Unknown flags, missing or bad values, and a path that is not a directory now exit 2. `--base-url`, `--viewport`, `--profile`, `--level` and `--url` did nothing and are now rejected
|
|
17
|
+
- A gate (`ci`, `--fail-on` or `failOn`) exits 5 when the scan was partial, files were unreadable, or no supported file was found. `--allow-empty` permits the empty case
|
|
18
|
+
- `--out` without `--format` writes `md`, `html` and `json`
|
|
19
|
+
- `dist`, `build`, `out`, `target`, `vendor`, `coverage` and `reports` are skipped only at the scan root or beside a project file, so more files can be scanned
|
|
20
|
+
- Template files (`.php`, `.erb`, `.ejs`, `.cshtml`, `.hbs`, `.njk`, `.liquid`, `.twig`) and `.pcss` are now scanned
|
|
21
|
+
- CSS-in-JS findings report the true source line, so their fingerprints change once. Lines with newly redacted secrets also change fingerprint
|
|
22
|
+
|
|
23
|
+
Fixes and additions
|
|
24
|
+
|
|
25
|
+
- `--key=value` flags work. `--no-excerpts` removes source excerpts and the absolute path from reports
|
|
26
|
+
- Redaction also covers unquoted environment values, JSON keys, prefixed names, JWT, Bearer, Stripe and npm tokens, URL passwords, titles and browser findings
|
|
27
|
+
- `verify --report` pairs identical findings one to one, keeps the baseline's category scope, and lists browser findings as not re-checked
|
|
28
|
+
- The version comes from `package.json` only
|
|
29
|
+
- CSS-in-JS: `.attrs`, TypeScript generics, `createGlobalStyle` and `injectGlobal`
|
|
30
|
+
- Large files scan in near-linear time (a 144 KB generated page: 18 s before, 0.3 s now, on the development machine)
|
|
31
|
+
- Browser mode sends MIME types, uses a free debugging port and answers a malformed URL with 400
|
|
32
|
+
- `verify` passes in the installed npm package, and CI tests the packed tarball
|
|
33
|
+
|
|
34
|
+
- Documentation overhaul: a designed home page, a five-minute tour with real output and screenshots, seven real-world scenarios, 14 diagrams and data charts (flow charts, decision tree, CI gate, skill orchestration, report anatomy, benchmark charts) that follow light and dark mode, grouped navigation, and figures added to the user guide, architecture, skills, CI and validation pages
|
|
35
|
+
- Site redesign: website-style home page, top navigation, footer, light theme by default with a remembered dark toggle, theme-matched diagrams (light and dark SVG variants), tap-to-enlarge lightbox so wide diagrams are readable on phones, mobile drawer navigation
|
|
36
|
+
- `npm run diagrams` regenerates the SVGs from the published benchmark data; `npm run images` recaptures the report screenshots
|
|
6
37
|
|
|
7
38
|
## 0.5.2
|
|
8
39
|
|
package/CITATION.cff
CHANGED
|
@@ -8,8 +8,8 @@ authors:
|
|
|
8
8
|
repository-code: "https://github.com/shahvatsalofficial/rachnasutra"
|
|
9
9
|
url: "https://github.com/shahvatsalofficial/rachnasutra"
|
|
10
10
|
license: Apache-2.0
|
|
11
|
-
version: 0.
|
|
12
|
-
date-released: "2026-11-
|
|
11
|
+
version: 0.6.0
|
|
12
|
+
date-released: "2026-11-29"
|
|
13
13
|
keywords:
|
|
14
14
|
- ui-ux
|
|
15
15
|
- accessibility
|
package/README.md
CHANGED
|
@@ -8,9 +8,9 @@
|
|
|
8
8
|
[](LICENSE)
|
|
9
9
|

|
|
10
10
|

|
|
11
|
-

|
|
12
12
|
|
|
13
|
-
**Quick links:** [Live docs](https://shahvatsalofficial.github.io/rachnasutra/) | [Documentation](documents/rachnasutra/00-overview.md) | [Validation](documents/rachnasutra/16-validation-and-benchmarks.md) | [Sample report](samples/broken-ui/latest.md) | [Test evidence](documents/rachnasutra/10-testing-and-evidence.md) | [Rules](documents/rachnasutra/06-audit-rules-reference.md) | [Legal and limits](documents/rachnasutra/09-legal-and-compliance.md)
|
|
13
|
+
**Quick links:** [Live docs](https://shahvatsalofficial.github.io/rachnasutra/) | [5-minute tour](documents/rachnasutra/18-quick-tour.md) | [Real-world scenarios](documents/rachnasutra/19-real-world-scenarios.md) | [Documentation](documents/rachnasutra/00-overview.md) | [Validation](documents/rachnasutra/16-validation-and-benchmarks.md) | [Sample report](samples/broken-ui/latest.md) | [Test evidence](documents/rachnasutra/10-testing-and-evidence.md) | [Rules](documents/rachnasutra/06-audit-rules-reference.md) | [Legal and limits](documents/rachnasutra/09-legal-and-compliance.md)
|
|
14
14
|
|
|
15
15
|
RachnaSutra AI is an open-source **UI/UX design engineering and auditing agent**: 13 portable [Agent Skills](https://agentskills.io/specification) led by **RachnaSutra Prime**, plus a **keyless CLI** that audits front-end code for accessibility (WCAG 2.2 AA oriented), responsive design, design-system, content and performance risks. Reports come out as JSON, Markdown, accessible HTML and SARIF 2.1.0.
|
|
16
16
|
|
|
@@ -118,7 +118,7 @@ Everything below is reproducible from this repository.
|
|
|
118
118
|
|
|
119
119
|
| Evidence | Result | Where |
|
|
120
120
|
|---|---|---|
|
|
121
|
-
| Automated tests | **
|
|
121
|
+
| Automated tests | **158 of 158 passing** locally on Node 24 (this machine). Blocking CI is Windows and Linux on Node 20, 22, 24 and 26. macOS is not in CI: GitHub cancels those jobs before a runner starts | [test-results.txt](https://github.com/shahvatsalofficial/rachnasutra/blob/main/documents/rachnasutra/evidence/test-results.txt) |
|
|
122
122
|
| Every rule tested both ways | A failing and a passing input for all 33 rules, plus false-positive guards; the same inputs generate the docs | [rule examples](documents/rachnasutra/15-rule-examples.md) |
|
|
123
123
|
| W3C ACT test cases | 154 cases, 10 rules: **71% precision, 65% recall** after fixing defects the benchmark found (first run: 53% and 38%) | [act.md](benchmarks/results/act.md) |
|
|
124
124
|
| Comparison with axe-core | axe-core is **more accurate** (92% / 83% against 81% / 73% on 7 comparable rules); RachnaSutra works on source files, offline, in CI | [act-vs-axe.md](benchmarks/results/act-vs-axe.md) |
|
|
@@ -126,7 +126,7 @@ Everything below is reproducible from this repository.
|
|
|
126
126
|
| Before and after on a real template | 14 findings resolved, 0 introduced; axe-core agrees | [case study](case-studies/clean-blog/README.md) |
|
|
127
127
|
| Intentionally flawed fixture | **22 findings**, each with file and line; identical on every run | [sample report](samples/broken-ui/latest.md) |
|
|
128
128
|
| Correct fixture | **0 findings** | [sample report](samples/good-ui/latest.md) |
|
|
129
|
-
| Contrast maths | Matches WCAG reference ratios (21:1 black on white; 4.54:1 for `#767676` on white) | [tests](test/rachnasutra.test.mjs) |
|
|
129
|
+
| Contrast maths | Matches WCAG reference ratios (21:1 black on white; 4.54:1 for `#767676` on white) | [tests](https://github.com/shahvatsalofficial/rachnasutra/blob/main/test/rachnasutra.test.mjs) |
|
|
130
130
|
| Security tests | Secret redaction, path traversal, report escaping, prompt-injection text in audited files | [security doc](documents/rachnasutra/08-security-and-privacy.md) |
|
|
131
131
|
| Browser mode | `audit --mode browser` on this machine used Edge, wrote `screenshot.png`, ran axe-core, and recorded Lighthouse lab scores. Exit 3 only when Playwright or a browser binary is missing | [status](docs/status.md) |
|
|
132
132
|
|
package/dist/audit.js
CHANGED
|
@@ -1,42 +1,102 @@
|
|
|
1
1
|
import { createHash } from 'node:crypto';
|
|
2
|
-
import { promises as fs } from 'node:fs';
|
|
2
|
+
import { promises as fs, readFileSync } from 'node:fs';
|
|
3
3
|
import path from 'node:path';
|
|
4
|
+
import { packageRoot } from './adapters.js';
|
|
5
|
+
import { redact } from './redact.js';
|
|
4
6
|
import { exists, readText, walk, clearTextCache } from './fsutil.js';
|
|
5
7
|
import { MARKUP_EXT, RULE_CATALOG, STYLE_EXT, runRules } from './rules.js';
|
|
6
8
|
import { inspectTokens } from './tokens.js';
|
|
7
9
|
export const SEVERITY_ORDER = ['critical', 'high', 'medium', 'low', 'info'];
|
|
8
10
|
const CODE_EXT = new Set(['.js', '.jsx', '.ts', '.tsx', '.mjs', '.cjs']);
|
|
9
|
-
|
|
11
|
+
const SERVER_TAG_EXT = new Set(['.php', '.erb', '.ejs', '.cshtml']);
|
|
12
|
+
const CSS_IN_JS = /\b(?:styled(?:\.[A-Za-z0-9]+|\([^()]*\))(?:\.attrs\((?:[^()]|\([^()]*\))*\))?|css|createGlobalStyle|injectGlobal)(?:<(?:[^`<>]|<[^`<>]*>)*>)?`/g;
|
|
13
|
+
/** Index of the closing backtick of a template starting at `from`, plus the `${...}` ranges inside it. */
|
|
14
|
+
function scanTemplate(text, from) {
|
|
15
|
+
const holes = [];
|
|
16
|
+
for (let i = from; i < text.length; i++) {
|
|
17
|
+
if (text[i] === '\\')
|
|
18
|
+
i++;
|
|
19
|
+
else if (text[i] === '`')
|
|
20
|
+
return { end: i, holes };
|
|
21
|
+
else if (text[i] === '$' && text[i + 1] === '{') {
|
|
22
|
+
// shortcut: braces inside quoted strings in an interpolation are counted too; parse JS if that ever matters
|
|
23
|
+
const open = i;
|
|
24
|
+
let depth = 0;
|
|
25
|
+
for (i += 1; i < text.length; i++) {
|
|
26
|
+
if (text[i] === '`')
|
|
27
|
+
i = scanTemplate(text, i + 1).end;
|
|
28
|
+
else if (text[i] === '{')
|
|
29
|
+
depth++;
|
|
30
|
+
else if (text[i] === '}' && --depth === 0)
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
holes.push([open, i + 1]);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return { end: -1, holes };
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Pull CSS out of styled-components, emotion and the css`` helper. The result has the same length and line
|
|
40
|
+
* breaks as the source, with everything that is not CSS blanked, so findings point at the true line.
|
|
41
|
+
* Object styles and other CSS-in-JS shapes are left alone.
|
|
42
|
+
*/
|
|
10
43
|
export function extractCssInJs(text) {
|
|
11
|
-
|
|
12
|
-
for (const m of text.matchAll(
|
|
13
|
-
const
|
|
14
|
-
|
|
44
|
+
let out;
|
|
45
|
+
for (const m of text.matchAll(CSS_IN_JS)) {
|
|
46
|
+
const start = m.index + m[0].length;
|
|
47
|
+
const { end, holes } = scanTemplate(text, start);
|
|
48
|
+
if (end < 0 || !text.slice(start, end).trim())
|
|
15
49
|
continue;
|
|
16
|
-
|
|
50
|
+
out ??= text.replace(/[^\r\n]/g, ' ').split('');
|
|
51
|
+
for (let i = start; i < end; i++)
|
|
52
|
+
out[i] = text[i];
|
|
53
|
+
for (const [a, b] of holes)
|
|
54
|
+
for (let i = a; i < b; i++)
|
|
55
|
+
if (text[i] !== '\n' && text[i] !== '\r')
|
|
56
|
+
out[i] = 'X';
|
|
57
|
+
const own = out.slice(start, end).join('');
|
|
58
|
+
if (!own.includes('{')) {
|
|
59
|
+
// flat declarations need a selector: it goes into the blanked characters before and after the body
|
|
60
|
+
out[start - 2] = 'x';
|
|
61
|
+
out[start - 1] = '{';
|
|
62
|
+
out[end] = '}';
|
|
63
|
+
}
|
|
17
64
|
}
|
|
18
|
-
return
|
|
65
|
+
return out ? out.join('') : '';
|
|
19
66
|
}
|
|
20
67
|
export const CONFIG_FILE = 'rachnasutra.config.json';
|
|
68
|
+
let version;
|
|
69
|
+
/** package.json is the only place the version is written. */
|
|
21
70
|
export function toolVersion() {
|
|
22
|
-
|
|
71
|
+
version ??= JSON.parse(readFileSync(path.join(packageRoot(), 'package.json'), 'utf8')).version;
|
|
72
|
+
return version;
|
|
73
|
+
}
|
|
74
|
+
/** A user mistake (bad path or config), reported as a usage error instead of a crash. */
|
|
75
|
+
export class UsageError extends Error {
|
|
23
76
|
}
|
|
24
77
|
export async function loadConfig(root) {
|
|
25
78
|
const p = path.join(root, CONFIG_FILE);
|
|
26
79
|
const def = { exclude: [], disableRules: [] };
|
|
27
80
|
if (!(await exists(p)))
|
|
28
81
|
return def;
|
|
29
|
-
|
|
82
|
+
let parsed;
|
|
83
|
+
try {
|
|
84
|
+
parsed = JSON.parse(await fs.readFile(p, 'utf8'));
|
|
85
|
+
}
|
|
86
|
+
catch (e) {
|
|
87
|
+
throw new UsageError(`${p} is not readable JSON: ${e.message}`);
|
|
88
|
+
}
|
|
89
|
+
const errs = validateConfig(parsed);
|
|
30
90
|
if (errs.length)
|
|
31
|
-
throw new
|
|
32
|
-
return { ...def, ...
|
|
91
|
+
throw new UsageError(`${CONFIG_FILE} invalid: ${errs.join('; ')}`);
|
|
92
|
+
return { ...def, ...parsed };
|
|
33
93
|
}
|
|
34
94
|
export function validateConfig(o) {
|
|
35
95
|
const errs = [];
|
|
36
96
|
if (!o || typeof o !== 'object' || Array.isArray(o))
|
|
37
97
|
return ['config must be an object'];
|
|
38
98
|
const c = o;
|
|
39
|
-
const known = new Set(['exclude', 'disableRules', 'failOn', 'maxFiles', 'imageBudgetKb']);
|
|
99
|
+
const known = new Set(['exclude', 'disableRules', 'failOn', 'maxFiles', 'imageBudgetKb', 'baseline']);
|
|
40
100
|
for (const k of Object.keys(c))
|
|
41
101
|
if (!known.has(k))
|
|
42
102
|
errs.push(`unknown key "${k}"`);
|
|
@@ -44,6 +104,8 @@ export function validateConfig(o) {
|
|
|
44
104
|
if (c[k] !== undefined && !(Array.isArray(c[k]) && c[k].every((x) => typeof x === 'string')))
|
|
45
105
|
errs.push(`${k} must be a string array`);
|
|
46
106
|
}
|
|
107
|
+
if (c.baseline !== undefined && !(typeof c.baseline === 'string' && c.baseline))
|
|
108
|
+
errs.push('baseline must be a file path');
|
|
47
109
|
if (c.failOn !== undefined && c.failOn !== 'confirmed-critical' && !SEVERITY_ORDER.includes(c.failOn))
|
|
48
110
|
errs.push('failOn must be confirmed-critical|critical|high|medium|low|info');
|
|
49
111
|
for (const k of ['maxFiles', 'imageBudgetKb']) {
|
|
@@ -59,6 +121,25 @@ export function validateConfig(o) {
|
|
|
59
121
|
return errs;
|
|
60
122
|
}
|
|
61
123
|
const fingerprint = (h) => createHash('sha256').update(`${h.rule}|${h.file}|${h.evidence[0]?.excerpt ?? h.title}`).digest('hex').slice(0, 12);
|
|
124
|
+
/** Two redacted lines either side of each finding, for the HTML report. */
|
|
125
|
+
function addContext(findings, docs) {
|
|
126
|
+
const files = new Map();
|
|
127
|
+
for (const d of docs) {
|
|
128
|
+
const text = d.source ?? d.text;
|
|
129
|
+
// key material spans lines that the line-based redaction cannot recognise, so such files get no context
|
|
130
|
+
if (!text.includes('PRIVATE KEY-----'))
|
|
131
|
+
files.set(d.file.rel, text.split(/\r?\n/));
|
|
132
|
+
}
|
|
133
|
+
for (const f of findings) {
|
|
134
|
+
for (const e of f.evidence) {
|
|
135
|
+
const lines = files.get(e.path);
|
|
136
|
+
if (!lines || !e.line)
|
|
137
|
+
continue;
|
|
138
|
+
const start = Math.max(1, e.line - 2);
|
|
139
|
+
e.context = { start, lines: lines.slice(start - 1, e.line + 2).map((l) => redact(l.trimEnd()).slice(0, 160)) };
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
62
143
|
export async function runAudit(rootArg, opts = {}) {
|
|
63
144
|
const root = path.resolve(rootArg);
|
|
64
145
|
clearTextCache();
|
|
@@ -76,16 +157,21 @@ export async function runAudit(rootArg, opts = {}) {
|
|
|
76
157
|
continue;
|
|
77
158
|
if (isMarkup || isStyle) {
|
|
78
159
|
fileTypes[f.ext] = (fileTypes[f.ext] ?? 0) + 1;
|
|
79
|
-
|
|
160
|
+
// server tags (<?php ?>, <% %>) become same-length filler so their ">" cannot cut an HTML tag short
|
|
161
|
+
const scanned = SERVER_TAG_EXT.has(f.ext) ? text.replace(/<[?%][\s\S]*?[?%]>/g, (x) => x.replace(/[^\r\n]/g, 'T')) : text;
|
|
162
|
+
docs.push({ file: f, text: scanned, source: text, kind: isMarkup ? 'markup' : 'style', isHtmlDoc: f.ext === '.html' || f.ext === '.htm' });
|
|
80
163
|
}
|
|
81
164
|
const extracted = extractCssInJs(text);
|
|
82
165
|
if (extracted && CODE_EXT.has(f.ext)) {
|
|
83
|
-
docs.push({ file: f, text: extracted, kind: 'style', isHtmlDoc: false });
|
|
166
|
+
docs.push({ file: f, text: extracted, source: text, kind: 'style', isHtmlDoc: false });
|
|
84
167
|
}
|
|
85
168
|
}
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
|
|
169
|
+
const silenced = [];
|
|
170
|
+
const wanted = (h) => !config.disableRules.includes(h.rule) && (!opts.categories || opts.categories.includes(h.category));
|
|
171
|
+
const raw = runRules({
|
|
172
|
+
docs, assets: corpus.assets, imageBudgetBytes: (config.imageBudgetKb ?? 500) * 1024,
|
|
173
|
+
maxPerRule: opts.uncapped ? Infinity : undefined, suppressed: silenced,
|
|
174
|
+
}).filter(wanted);
|
|
89
175
|
raw.sort((a, b) => SEVERITY_ORDER.indexOf(a.severity) - SEVERITY_ORDER.indexOf(b.severity) ||
|
|
90
176
|
a.rule.localeCompare(b.rule) || a.file.localeCompare(b.file) || (a.line ?? 0) - (b.line ?? 0));
|
|
91
177
|
const seen = new Set();
|
|
@@ -99,11 +185,21 @@ export async function runAudit(rootArg, opts = {}) {
|
|
|
99
185
|
findings.push({
|
|
100
186
|
id: `RS-${String(findings.length + 1).padStart(4, '0')}`,
|
|
101
187
|
...h,
|
|
188
|
+
title: redact(h.title),
|
|
102
189
|
platform: 'web',
|
|
103
190
|
status: h.confidence === 'high' ? 'confirmed' : 'review-required',
|
|
104
191
|
fingerprint: fp,
|
|
105
192
|
});
|
|
106
193
|
}
|
|
194
|
+
const suppressed = silenced.filter(wanted).map((h, i) => ({
|
|
195
|
+
id: `RS-S${String(i + 1).padStart(4, '0')}`,
|
|
196
|
+
...h,
|
|
197
|
+
title: redact(h.title),
|
|
198
|
+
platform: 'web',
|
|
199
|
+
status: h.confidence === 'high' ? 'confirmed' : 'review-required',
|
|
200
|
+
fingerprint: fingerprint(h),
|
|
201
|
+
}));
|
|
202
|
+
addContext(findings, docs);
|
|
107
203
|
const markupN = docs.filter((d) => d.kind === 'markup').length;
|
|
108
204
|
const styleN = docs.filter((d) => d.kind === 'style').length;
|
|
109
205
|
const rulesIn = (cat) => RULE_CATALOG.filter((r) => r.category === cat).length;
|
|
@@ -132,14 +228,17 @@ export async function runAudit(rootArg, opts = {}) {
|
|
|
132
228
|
generatedAt: new Date().toISOString(),
|
|
133
229
|
root,
|
|
134
230
|
mode: 'static',
|
|
231
|
+
...(opts.categories ? { categories: opts.categories } : {}),
|
|
135
232
|
filesScanned: docs.length,
|
|
136
233
|
fileTypes,
|
|
137
234
|
skipped: corpus.skipped,
|
|
138
235
|
truncated: corpus.truncated,
|
|
139
236
|
findings,
|
|
237
|
+
...(suppressed.length ? { suppressed } : {}),
|
|
140
238
|
coverage,
|
|
141
239
|
tokens,
|
|
142
240
|
limitations: [
|
|
241
|
+
...(suppressed.length ? [`${suppressed.length} finding(s) were silenced by rachnasutra-disable comments. The JSON report lists them under "suppressed".`] : []),
|
|
143
242
|
'Static analysis reads source text only. Nothing was rendered, executed or sent over a network.',
|
|
144
243
|
'Findings are review aids. Automated checks cannot establish WCAG conformance; manual testing is required.',
|
|
145
244
|
'CSS frameworks, CSS-in-JS and runtime-injected markup are only partly visible.',
|
package/dist/baseline.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { promises as fs } from 'node:fs';
|
|
2
|
+
import { UsageError, toolVersion } from './audit.js';
|
|
3
|
+
import { matchByFingerprint } from './verify.js';
|
|
4
|
+
export const BASELINE_FILE = 'rachnasutra.baseline.json';
|
|
5
|
+
/** Read a baseline. Returns null when the file does not exist. */
|
|
6
|
+
export async function readBaseline(file) {
|
|
7
|
+
let text;
|
|
8
|
+
try {
|
|
9
|
+
text = await fs.readFile(file, 'utf8');
|
|
10
|
+
}
|
|
11
|
+
catch (e) {
|
|
12
|
+
if (e.code === 'ENOENT')
|
|
13
|
+
return null;
|
|
14
|
+
throw new UsageError(`Cannot read baseline ${file}: ${e.message}`);
|
|
15
|
+
}
|
|
16
|
+
let data;
|
|
17
|
+
try {
|
|
18
|
+
data = JSON.parse(text);
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
data = undefined;
|
|
22
|
+
}
|
|
23
|
+
const ok = data?.baselineVersion === 1 && Array.isArray(data.entries) &&
|
|
24
|
+
data.entries.every((e) => typeof e?.fingerprint === 'string' && typeof e.rule === 'string');
|
|
25
|
+
if (!ok)
|
|
26
|
+
throw new UsageError(`Not a RachnaSutra baseline: ${file}`);
|
|
27
|
+
return data;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Entries for the current findings. With a previous baseline this is a ratchet: only findings that
|
|
31
|
+
* were already accepted stay, so the file can shrink but never absorb a new problem.
|
|
32
|
+
*/
|
|
33
|
+
export function nextBaseline(res, previous) {
|
|
34
|
+
const kept = previous ? matchByFingerprint(res.findings, previous.entries).matched : res.findings;
|
|
35
|
+
return {
|
|
36
|
+
baselineVersion: 1,
|
|
37
|
+
tool: `rachnasutra ${toolVersion()}`,
|
|
38
|
+
entries: kept
|
|
39
|
+
.map(({ rule, category, file, line, fingerprint }) => ({ rule, category, file, line, fingerprint }))
|
|
40
|
+
.sort((a, b) => a.file.localeCompare(b.file) || a.rule.localeCompare(b.rule) || (a.line ?? 0) - (b.line ?? 0)),
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/** Mark each finding as accepted or new. Returns how many accepted entries no longer occur. */
|
|
44
|
+
export function applyBaseline(res, baseline) {
|
|
45
|
+
const entries = baseline.entries.filter((e) => !res.categories || res.categories.includes(e.category));
|
|
46
|
+
const known = new Set(matchByFingerprint(res.findings, entries).matched);
|
|
47
|
+
for (const f of res.findings)
|
|
48
|
+
f.baselineState = known.has(f) ? 'unchanged' : 'new';
|
|
49
|
+
const counts = { unchanged: known.size, added: res.findings.length - known.size, fixed: entries.length - known.size };
|
|
50
|
+
res.limitations.push(`Baseline: ${counts.added} new finding(s), ${counts.unchanged} already accepted, ${counts.fixed} no longer present. Gates count new findings only.`);
|
|
51
|
+
return counts;
|
|
52
|
+
}
|
package/dist/browser.js
CHANGED
|
@@ -2,6 +2,7 @@ import { createHash } from 'node:crypto';
|
|
|
2
2
|
import { createServer } from 'node:http';
|
|
3
3
|
import { mkdir, readFile, writeFile } from 'node:fs/promises';
|
|
4
4
|
import path from 'node:path';
|
|
5
|
+
import { redact } from './redact.js';
|
|
5
6
|
export class BrowserMissing extends Error {
|
|
6
7
|
constructor(message) {
|
|
7
8
|
super(message);
|
|
@@ -33,10 +34,37 @@ async function launchBrowser(port) {
|
|
|
33
34
|
}
|
|
34
35
|
}
|
|
35
36
|
}
|
|
36
|
-
|
|
37
|
+
const MIME = {
|
|
38
|
+
'.html': 'text/html; charset=utf-8', '.htm': 'text/html; charset=utf-8', '.css': 'text/css; charset=utf-8',
|
|
39
|
+
'.js': 'text/javascript; charset=utf-8', '.mjs': 'text/javascript; charset=utf-8', '.json': 'application/json; charset=utf-8',
|
|
40
|
+
'.svg': 'image/svg+xml', '.png': 'image/png', '.jpg': 'image/jpeg', '.jpeg': 'image/jpeg', '.gif': 'image/gif',
|
|
41
|
+
'.webp': 'image/webp', '.avif': 'image/avif', '.ico': 'image/x-icon', '.woff': 'font/woff', '.woff2': 'font/woff2',
|
|
42
|
+
'.ttf': 'font/ttf', '.otf': 'font/otf', '.txt': 'text/plain; charset=utf-8', '.xml': 'application/xml', '.wasm': 'application/wasm',
|
|
43
|
+
};
|
|
44
|
+
/** A port the operating system reports as free right now. */
|
|
45
|
+
function freePort() {
|
|
46
|
+
return new Promise((resolve, reject) => {
|
|
47
|
+
const s = createServer();
|
|
48
|
+
s.once('error', reject);
|
|
49
|
+
s.listen(0, '127.0.0.1', () => {
|
|
50
|
+
const addr = s.address();
|
|
51
|
+
s.close(() => resolve(typeof addr === 'object' && addr ? addr.port : 0));
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
/** Local static server for the page under test. */
|
|
56
|
+
export function serve(dir) {
|
|
37
57
|
const root = path.resolve(dir);
|
|
38
58
|
const server = createServer(async (req, res) => {
|
|
39
|
-
|
|
59
|
+
let pathname;
|
|
60
|
+
try {
|
|
61
|
+
pathname = decodeURIComponent(new URL(req.url ?? '/', 'http://127.0.0.1').pathname);
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
res.statusCode = 400;
|
|
65
|
+
res.end();
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
40
68
|
const rel = pathname === '/' ? 'index.html' : pathname.replace(/^\/+/, '');
|
|
41
69
|
const abs = path.resolve(root, rel);
|
|
42
70
|
if (abs !== root && !abs.startsWith(root + path.sep)) {
|
|
@@ -46,6 +74,7 @@ function serve(dir) {
|
|
|
46
74
|
}
|
|
47
75
|
try {
|
|
48
76
|
const buf = await readFile(abs);
|
|
77
|
+
res.setHeader('content-type', MIME[path.extname(abs).toLowerCase()] ?? 'application/octet-stream');
|
|
49
78
|
res.end(buf);
|
|
50
79
|
}
|
|
51
80
|
catch {
|
|
@@ -63,18 +92,19 @@ function serve(dir) {
|
|
|
63
92
|
}
|
|
64
93
|
function finding(n, rule, title, severity, file, excerpt) {
|
|
65
94
|
const fingerprint = createHash('sha256').update(`${rule}|${file}|${excerpt}`).digest('hex').slice(0, 12);
|
|
95
|
+
const shown = redact(excerpt).slice(0, 240);
|
|
66
96
|
return {
|
|
67
97
|
id: `RS-${String(n).padStart(4, '0')}`,
|
|
68
98
|
rule,
|
|
69
99
|
category: 'accessibility',
|
|
70
|
-
title,
|
|
100
|
+
title: redact(title),
|
|
71
101
|
severity,
|
|
72
102
|
confidence: 'high',
|
|
73
103
|
status: 'confirmed',
|
|
74
104
|
platform: 'web',
|
|
75
105
|
file,
|
|
76
106
|
line: 1,
|
|
77
|
-
evidence: [{ path: file, line: 1, excerpt:
|
|
107
|
+
evidence: [{ path: file, line: 1, excerpt: shown }],
|
|
78
108
|
user_impact: 'A rendered-page check reported this. Static source rules cannot see it.',
|
|
79
109
|
recommended_fix: 'Open the page in a browser and fix the cited element. Re-run with --mode browser.',
|
|
80
110
|
verification: 'Re-run `rachnasutra audit --mode browser`.',
|
|
@@ -92,7 +122,7 @@ export async function runBrowserAudit(root, outDir, startId) {
|
|
|
92
122
|
catch {
|
|
93
123
|
throw new BrowserMissing(`No index.html in ${root}. Nothing was rendered.`);
|
|
94
124
|
}
|
|
95
|
-
const debugPort =
|
|
125
|
+
const debugPort = await freePort();
|
|
96
126
|
const { browser, channel } = await launchBrowser(debugPort);
|
|
97
127
|
const site = await serve(root);
|
|
98
128
|
await mkdir(outDir, { recursive: true });
|