Skip to content

Commit 7b1de91

Browse files
committed
test: add source-docs drift test and update GitHub repo description to 7 sources
1 parent d36a39b commit 7b1de91

4 files changed

Lines changed: 58 additions & 7 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ All notable changes to ScriptHunt will be documented in this file.
1616
- Version drift test (`tests/version-drift.test.js`) fails when app, package.json, service worker, README badge, or CHANGELOG versions disagree. Runs as part of `npm run qa`.
1717
- Security scanner now distinguishes `@connect` metadata risk from browser extension site-access requirements — warns when `GM_xmlhttpRequest` is granted without `@connect`, and explains that named `@connect` hosts may also need browser-level site-access permission.
1818
- License names are normalized to SPDX identifiers during source normalization — common aliases like "MIT License", "Apache License 2.0", "GNU GPL v3" map to stable filter values while unknown/custom licenses pass through as-is.
19+
- Source-docs drift test (`tests/source-docs.test.js`) fails when README source table count doesn't match the code source registry, or when sources are missing from README. GitHub repo description updated to list all 7 sources.
1920

2021
## [v0.4.1]
2122

ROADMAP.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,6 @@
4242
Complexity: L
4343

4444

45-
- [ ] P2 — Make source capability truth executable
46-
Why: The app supports seven sources, README reflects seven, but the GitHub repo description still advertises four; source facts should not be hand-synced across code, docs, and distribution metadata.
47-
Evidence: `index.html:1033`, `README.md:93`, `gh repo view SysAdminDoc/UserScriptHunt`.
48-
Touches: `index.html` source registry, README source table/check script, package scripts, repository metadata update command.
49-
Acceptance: each source declares endpoint type, proxy/CORS mode, page size, locale support, and metadata confidence in code; a local check fails when README source docs drift; the GitHub repo description is updated to match current source coverage.
50-
Complexity: M
5145

5246
- [ ] P2 — Improve GitHub discovery controls and rate-limit clarity
5347
Why: GitHub repository/code search is valuable but broad, capped, and rate-limited; power users need controls that map to GitHub's documented qualifiers without editing raw queries.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"private": true,
55
"scripts": {
66
"qa": "npm audit && npm test",
7-
"test": "node --test tests/worker.test.js tests/version-drift.test.js && playwright test",
7+
"test": "node --test tests/worker.test.js tests/version-drift.test.js tests/source-docs.test.js && playwright test",
88
"test:install": "playwright install chromium",
99
"serve:test": "node tests/static-server.js 3217 ."
1010
},

tests/source-docs.test.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
const assert = require('node:assert/strict');
2+
const fs = require('node:fs');
3+
const path = require('node:path');
4+
const test = require('node:test');
5+
6+
const root = path.join(__dirname, '..');
7+
8+
function readFile(name) {
9+
return fs.readFileSync(path.join(root, name), 'utf8');
10+
}
11+
12+
test('README source table matches code source registry', () => {
13+
const html = readFile('index.html');
14+
const readme = readFile('README.md');
15+
16+
const sourceMatch = html.match(/var SOURCES\s*=\s*\{([\s\S]*?)\n\s*\};/);
17+
assert.ok(sourceMatch, 'SOURCES registry should exist in index.html');
18+
19+
const nameMatches = sourceMatch[1].matchAll(/name:\s*'([^']+)'/g);
20+
const codeSourceNames = Array.from(nameMatches, (m) => m[1]).sort();
21+
22+
assert.ok(codeSourceNames.length >= 6, 'Should have at least 6 sources in code');
23+
24+
for (const name of codeSourceNames) {
25+
assert.ok(
26+
readme.includes(name),
27+
`README should mention source "${name}" from the code registry`
28+
);
29+
}
30+
31+
const sourceTableMatch = readme.match(/\| Source \| Method.*\n\|[-:|]+\n([\s\S]*?)(?:\n\n|\n---)/);
32+
assert.ok(sourceTableMatch, 'README should have a source table');
33+
34+
const readmeSourceLines = sourceTableMatch[1].trim().split('\n').filter((l) => l.startsWith('|'));
35+
assert.equal(
36+
readmeSourceLines.length,
37+
codeSourceNames.length,
38+
`README source table rows (${readmeSourceLines.length}) should match code source count (${codeSourceNames.length})`
39+
);
40+
});
41+
42+
test('each source declares page size in code', () => {
43+
const html = readFile('index.html');
44+
const sourceMatch = html.match(/var SOURCES\s*=\s*\{([\s\S]*?)\n\s*\};/);
45+
assert.ok(sourceMatch);
46+
47+
const idMatches = sourceMatch[1].matchAll(/(\w+):\s*\{\s*id:/g);
48+
const sourceIds = Array.from(idMatches, (m) => m[1]);
49+
50+
for (const id of sourceIds) {
51+
const pageSizeRx = new RegExp(id + '.*?pageSize:\\s*(\\d+)', 's');
52+
const match = sourceMatch[1].match(pageSizeRx);
53+
assert.ok(match, `Source "${id}" should declare a pageSize`);
54+
assert.ok(parseInt(match[1]) > 0, `Source "${id}" pageSize should be positive`);
55+
}
56+
});

0 commit comments

Comments
 (0)