voyage/tests/lib/reading-defects.test.mjs
Kjell Tore Guttormsen 8094b00861
fix: brief template teaches runnable criteria; commands call validators through the plugin root
The skills reading (2026-10-06) found two defects the operator decided to fix
once wave 1 was merged:
- the brief template's Success Criteria examples used a pipe and npx, which
  the criteria runner refuses (and the brief validator now warns on);
- trekcontinue and trekexecute called lib/ scripts relative to the working
  directory, which is the user's repo, not the plugin.

Tests fail on the old text first (tests/lib/reading-defects.test.mjs).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-08 08:52:52 +02:00

42 lines
2 KiB
JavaScript

// tests/lib/reading-defects.test.mjs
// Defects the skills reading found (docs/skillsanalyse.local.md § 6, 2026-10-06);
// the operator decided they are fixed in a small delivery once wave 1 was
// merged. Each test fails on the code the reading measured.
import { test } from 'node:test';
import { strict as assert } from 'node:assert';
import { readFileSync, readdirSync } from 'node:fs';
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
import { runnableCheck } from '../../lib/verification/criteria-runner.mjs';
const HERE = dirname(fileURLToPath(import.meta.url));
const ROOT = join(HERE, '..', '..');
const read = (p) => readFileSync(join(ROOT, p), 'utf8');
// --- 1. the brief template teaches only criteria the runner can run ---------
test('brief template: every example command under Success Criteria is one the criteria runner accepts', () => {
const md = read('templates/trekbrief-template.md');
const start = md.indexOf('## Success Criteria');
const section = md.slice(start, md.indexOf('\n## ', start + 1));
const examples = section.split('\n').filter((l) => l.startsWith('- {criterion')).join('\n');
const commands = [...examples.matchAll(/`([^`\n]+)`/g)].map((m) => m[1]).filter((c) => !/^"/.test(c));
assert.ok(commands.length >= 3, `found ${commands.length} example commands`);
for (const command of commands) {
const r = runnableCheck({ command });
assert.equal(r.runnable, true, `${command}: ${r.reason}`);
}
});
// --- 2. commands reach Voyage's own scripts through the plugin root ---------
test('commands: no Voyage script is called relative to the working directory (it is the user\'s repo)', () => {
const offenders = [];
for (const f of readdirSync(join(ROOT, 'commands')).filter((n) => n.endsWith('.md'))) {
read(`commands/${f}`).split('\n').forEach((line, i) => {
if (/(?:node |from ['"]|import\(['"])(?:\.\/)?lib\//.test(line)) offenders.push(`commands/${f}:${i + 1}`);
});
}
assert.deepEqual(offenders, []);
});