config-audit/tests/lib/humanizer-data.test.mjs
Kjell Tore Guttormsen 239e88cecb fix(acr): on-demand copy for oversized skill-body finding (M-BUG-16)
The skill-listing check emits a third finding for an oversized skill BODY
(v5.11 B7, RAW title "Skill body is large (loads on demand when the skill
runs)"). The body is an ON-DEMAND cost — it loads only when the skill is
invoked, not the always-loaded listing Claude reads every turn. The scanner is
careful to distinguish the two (RAW title + comment + evidence note).

But the humanizer-data SKL.static map had no entry for this title, so it fell
through to SKL._default ("A skill is using more of the listing budget than it
should"). The humanized title therefore claimed a listing-budget cost and
directly contradicted the finding's own humanized evidence ("loads ON DEMAND
only ... NOT every turn like the always-loaded listing") — the same internal
contradiction class as M-BUG-15/M-BUG-14, and the same "new finding type added
without a matching humanizer entry" gap the scanner checklist warns about.

Found by finding-granularity premise-verification of the linkedin-posts scan
before feeding it to the analyze pipeline (the prior session's pass focused on
the GAP findings and did not catch the SKL fall-through).

- humanizer-data.mjs: add SKL.static entry for "Skill body is large (loads on
  demand when the skill runs)" with on-demand-correct title ("A skill's body is
  large (it loads only when that skill runs)"), description, and recommendation.
  No listing-budget language; tier1/tier3 forbidden-word checks pass.
- RED-first tests at both layers: humanizer.test.mjs (humanizeFinding path:
  title is not the listing-budget _default, conveys on-demand body) and
  humanizer-data.test.mjs (static entry exists, on-demand-correct).

RAW envelope unaffected (humanizer bypassed for --raw/--json), frozen v5.0.0
snapshots untouched, default-output fixtures contain no oversized-body skill so
no snapshot regen. Suite 1357->1359/0 (+2).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01683eAqVecv9VZfQzL8CQ9h
2026-06-30 13:30:22 +02:00

234 lines
11 KiB
JavaScript

import { test } from 'node:test';
import assert from 'node:assert/strict';
import { readFile } from 'node:fs/promises';
import { fileURLToPath } from 'node:url';
import { dirname, resolve } from 'node:path';
import { TRANSLATIONS } from '../../scanners/lib/humanizer-data.mjs';
const __dirname = dirname(fileURLToPath(import.meta.url));
const FORBIDDEN_PATH = resolve(__dirname, '..', 'lint-forbidden-words.json');
const EXPECTED_SCANNERS = ['CML', 'SET', 'HKV', 'RUL', 'MCP', 'IMP', 'CNF', 'GAP', 'TOK', 'CPS', 'DIS', 'COL', 'PLH', 'SKL', 'OST'];
function stripBacktickSpans(s) {
return s.replace(/`[^`]*`/g, '');
}
async function loadForbidden() {
const raw = await readFile(FORBIDDEN_PATH, 'utf8');
return JSON.parse(raw);
}
test('TRANSLATIONS exports an object', () => {
assert.equal(typeof TRANSLATIONS, 'object');
assert.ok(TRANSLATIONS !== null);
});
test('TRANSLATIONS covers all 15 expected scanner prefixes', () => {
for (const prefix of EXPECTED_SCANNERS) {
assert.ok(TRANSLATIONS[prefix], `missing scanner prefix: ${prefix}`);
}
});
test('every scanner has a _default fallback with all 3 fields', () => {
for (const prefix of EXPECTED_SCANNERS) {
const scanner = TRANSLATIONS[prefix];
assert.ok(scanner._default, `${prefix} missing _default`);
assert.ok(typeof scanner._default.title === 'string' && scanner._default.title.length > 0,
`${prefix} _default missing title`);
assert.ok(typeof scanner._default.description === 'string' && scanner._default.description.length > 0,
`${prefix} _default missing description`);
assert.ok(typeof scanner._default.recommendation === 'string' && scanner._default.recommendation.length > 0,
`${prefix} _default missing recommendation`);
}
});
test('every scanner has a static map (may be empty)', () => {
for (const prefix of EXPECTED_SCANNERS) {
assert.equal(typeof TRANSLATIONS[prefix].static, 'object',
`${prefix} missing static map`);
assert.ok(TRANSLATIONS[prefix].static !== null);
}
});
test('every scanner has a patterns array (may be empty)', () => {
for (const prefix of EXPECTED_SCANNERS) {
assert.ok(Array.isArray(TRANSLATIONS[prefix].patterns),
`${prefix} patterns must be an array`);
}
});
test('every static-title entry has all 3 fields', () => {
for (const prefix of EXPECTED_SCANNERS) {
const staticMap = TRANSLATIONS[prefix].static;
for (const [title, t] of Object.entries(staticMap)) {
assert.ok(typeof t.title === 'string' && t.title.length > 0,
`${prefix} static["${title}"] missing title`);
assert.ok(typeof t.description === 'string' && t.description.length > 0,
`${prefix} static["${title}"] missing description`);
assert.ok(typeof t.recommendation === 'string' && t.recommendation.length > 0,
`${prefix} static["${title}"] missing recommendation`);
}
}
});
test('every pattern entry has regex + translation with all 3 fields', () => {
for (const prefix of EXPECTED_SCANNERS) {
for (const p of TRANSLATIONS[prefix].patterns) {
assert.ok(p.regex instanceof RegExp,
`${prefix} pattern missing regex`);
assert.ok(typeof p.translation.title === 'string' && p.translation.title.length > 0,
`${prefix} pattern translation missing title`);
assert.ok(typeof p.translation.description === 'string' && p.translation.description.length > 0,
`${prefix} pattern translation missing description`);
assert.ok(typeof p.translation.recommendation === 'string' && p.translation.recommendation.length > 0,
`${prefix} pattern translation missing recommendation`);
}
}
});
test('no translated string contains tier1 forbidden words (outside backtick spans)', async () => {
const data = await loadForbidden();
const tier1Words = data.tier1.map((e) => e.word);
const violations = [];
for (const prefix of EXPECTED_SCANNERS) {
const scanner = TRANSLATIONS[prefix];
const allTranslations = [
scanner._default,
...Object.values(scanner.static),
...scanner.patterns.map((p) => p.translation),
];
for (const t of allTranslations) {
for (const field of ['title', 'description', 'recommendation']) {
const text = stripBacktickSpans(t[field]).toLowerCase();
for (const word of tier1Words) {
const lower = word.toLowerCase();
// word-boundary match for single words, plain substring for multi-word phrases
const re = lower.includes(' ')
? new RegExp(lower.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'))
: new RegExp(`\\b${lower.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}\\b`);
if (re.test(text)) {
violations.push(`${prefix} ${field}: "${word}" in "${t[field]}"`);
}
}
}
}
}
assert.equal(violations.length, 0,
`tier1 violations:\n ${violations.slice(0, 20).join('\n ')}`);
});
test('no translated string contains tier3 jargon (outside backtick spans)', async () => {
const data = await loadForbidden();
const tier3Words = data.tier3.map((e) => e.word);
const violations = [];
for (const prefix of EXPECTED_SCANNERS) {
const scanner = TRANSLATIONS[prefix];
const allTranslations = [
scanner._default,
...Object.values(scanner.static),
...scanner.patterns.map((p) => p.translation),
];
for (const t of allTranslations) {
for (const field of ['title', 'description', 'recommendation']) {
const text = stripBacktickSpans(t[field]);
for (const word of tier3Words) {
const lower = word.toLowerCase();
const re = lower.includes(' ') || lower.includes('/') || lower.includes('-') || lower.includes('.')
? new RegExp(lower.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'i')
: new RegExp(`\\b${lower.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}\\b`, 'i');
if (re.test(text)) {
violations.push(`${prefix} ${field}: "${word}" in "${t[field]}"`);
}
}
}
}
}
assert.equal(violations.length, 0,
`tier3 violations (jargon outside backticks):\n ${violations.slice(0, 20).join('\n ')}`);
});
test('CML, SET, HKV, RUL, MCP, IMP, GAP, TOK, PLH have non-empty static maps', () => {
// These scanners produce findings with titles we documented. Empty static map suggests missed coverage.
for (const prefix of ['CML', 'SET', 'HKV', 'RUL', 'MCP', 'IMP', 'GAP', 'TOK', 'PLH', 'OST']) {
const count = Object.keys(TRANSLATIONS[prefix].static).length;
assert.ok(count > 0, `${prefix}.static is empty — expected at least 1 translated title`);
}
});
test('GAP "CLAUDE.md not modular" copy is size-neutral (M-BUG-14)', () => {
// The t2_2 check is a pure presence check (no length gate), so a small
// non-modular CLAUDE.md must not be told it is "big"/"long" or that it
// costs "loading time". Title + description must stay size/cost-neutral
// and keep only the honest structural "split into linked files" framing.
const t = TRANSLATIONS.GAP.static['CLAUDE.md not modular'];
assert.ok(t, 'GAP static map missing "CLAUDE.md not modular"');
const title = t.title.toLowerCase();
const desc = t.description.toLowerCase();
assert.ok(!/\bbig\b/.test(title), `title overclaims size: "${t.title}"`);
assert.ok(!/\blong\b/.test(title), `title overclaims size: "${t.title}"`);
assert.ok(!/\bbig\b/.test(desc), `description overclaims size: "${t.description}"`);
assert.ok(!/\blong\b/.test(desc), `description overclaims size: "${t.description}"`);
assert.ok(!/loading time/.test(desc), `description overclaims load cost: "${t.description}"`);
assert.ok(/split/.test(desc), `description should keep structural split framing: "${t.description}"`);
});
test('GAP enhancement-gap titles do not presuppose the feature exists (M-BUG-15)', () => {
// t2_3 ("No path-scoped rules") and t3_6 ("No subagent isolation") iterate a
// collection and return false for an EMPTY one — so they fire even when the
// user has zero rules / zero subagents. The humanized title must therefore
// not assert the feature exists, or it contradicts the sibling presence gap
// ("No custom subagents" → "You haven't set up any specialized helper agents
// yet"). Mirror the house "You haven't set up X yet" framing — honest for
// both the zero-state and the has-but-unconfigured state.
const rules = TRANSLATIONS.GAP.static['No path-scoped rules'];
const iso = TRANSLATIONS.GAP.static['No subagent isolation'];
assert.ok(rules, 'GAP static map missing "No path-scoped rules"');
assert.ok(iso, 'GAP static map missing "No subagent isolation"');
// Title must not presuppose existing rules / subagents.
assert.ok(!/your rules all load/i.test(rules.title),
`t2_3 title presupposes existing rules: "${rules.title}"`);
assert.ok(!/your subagents/i.test(iso.title),
`t3_6 title presupposes existing subagents: "${iso.title}"`);
// Title must still name the feature it points at.
assert.ok(/path-scoped rules/i.test(rules.title),
`t2_3 title should still name path-scoped rules: "${rules.title}"`);
assert.ok(/isolation/i.test(iso.title),
`t3_6 title should still name subagent isolation: "${iso.title}"`);
});
test('SKL oversized-body copy is on-demand, not listing-budget (M-BUG-16)', () => {
// The skill-listing check emits a third finding for an oversized skill BODY,
// which loads ON DEMAND only when the skill runs — not the always-loaded
// listing. Before the fix this title had no static entry and fell through to
// the SKL _default ("using more of the listing budget"), contradicting the
// finding's own evidence ("NOT every turn like the always-loaded listing").
const t = TRANSLATIONS.SKL.static['Skill body is large (loads on demand when the skill runs)'];
assert.ok(t, 'SKL static map missing "Skill body is large (loads on demand when the skill runs)"');
assert.ok(!/listing budget/i.test(t.title), `body title must not claim listing budget: "${t.title}"`);
assert.ok(!/listing budget/i.test(t.description), `body description must not claim listing budget: "${t.description}"`);
// Must convey the on-demand body cost.
assert.ok(/body/i.test(t.title), `body title should name the body: "${t.title}"`);
assert.ok(/loads only|on demand|when (it|that|the) skill runs|when you invoke/i.test(t.title + ' ' + t.description),
`copy should convey the on-demand load: "${t.title}" / "${t.description}"`);
});
test('CNF, COL, PLH have at least one pattern entry (template-literal titles)', () => {
// These scanners use template-literal titles for some findings.
for (const prefix of ['CNF', 'COL', 'PLH']) {
assert.ok(TRANSLATIONS[prefix].patterns.length > 0,
`${prefix} expected ≥1 pattern entry for template-literal titles`);
}
});
test('TRANSLATIONS does not mutate when re-imported (deep-frozen-ish)', async () => {
// Quick sanity — translate object reference equality between imports
const { TRANSLATIONS: t2 } = await import('../../scanners/lib/humanizer-data.mjs');
assert.equal(t2, TRANSLATIONS, 'TRANSLATIONS reference should be stable across imports');
});