crossexamdev 0.2.0 → 0.4.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/README.md +7 -2
- package/bin/crossexam.js +253 -5
- package/package.json +1 -1
- package/src/claims.js +138 -120
- package/src/evidence.js +3 -1
- package/src/findings.js +194 -0
- package/src/github.js +93 -69
- package/src/mcp.js +155 -5
- package/src/mutate.js +582 -0
- package/src/redact.js +59 -0
- package/src/reliability.js +154 -0
- package/src/report.js +195 -99
- package/src/sandbox.js +627 -0
- package/src/strength.js +637 -0
- package/src/upload.js +212 -0
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
// Reliability intelligence: how reliably each agent produces working software,
|
|
2
|
+
// built only from evidence crossexam recorded itself (~/.crossexam/ledger.jsonl):
|
|
3
|
+
// claims verdicts on what agents said (verify, the MCP tool, the Claude Code hook)
|
|
4
|
+
// strength how many planted defects their tests caught (mutate, verify --mutate, MCP)
|
|
5
|
+
// fixes whether their corrections closed findings on independent re-checks
|
|
6
|
+
// The three are reported side by side and never blended into one score: an
|
|
7
|
+
// agent can be honest about its claims and still ship weak tests.
|
|
8
|
+
import fs from 'node:fs';
|
|
9
|
+
import os from 'node:os';
|
|
10
|
+
import path from 'node:path';
|
|
11
|
+
|
|
12
|
+
const ledgerFile = () => path.join(process.env.CROSSEXAM_HOME || path.join(os.homedir(), '.crossexam'), 'ledger.jsonl');
|
|
13
|
+
|
|
14
|
+
/** Monday of the week a date falls in, as yyyy-mm-dd. */
|
|
15
|
+
export function weekOf(iso) {
|
|
16
|
+
const d = new Date(iso);
|
|
17
|
+
if (Number.isNaN(d.getTime())) return null;
|
|
18
|
+
const day = (d.getUTCDay() + 6) % 7;
|
|
19
|
+
d.setUTCDate(d.getUTCDate() - day);
|
|
20
|
+
return d.toISOString().slice(0, 10);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function readLedger(file = ledgerFile()) {
|
|
24
|
+
let text = '';
|
|
25
|
+
try {
|
|
26
|
+
text = fs.readFileSync(file, 'utf8');
|
|
27
|
+
} catch {
|
|
28
|
+
return [];
|
|
29
|
+
}
|
|
30
|
+
const out = [];
|
|
31
|
+
for (const l of text.split('\n')) {
|
|
32
|
+
if (!l.trim()) continue;
|
|
33
|
+
try {
|
|
34
|
+
out.push(JSON.parse(l));
|
|
35
|
+
} catch {
|
|
36
|
+
/* a torn line from a crash: skip it */
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return out;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const pct = (a, b) => (b ? Math.round((a / b) * 1000) / 1000 : null);
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Per-agent reliability from ledger records.
|
|
46
|
+
* @param {{ since?: number, agent?: string, repo?: string, records?: any[] }} opts
|
|
47
|
+
*/
|
|
48
|
+
export function reliability({ since = 0, agent, repo, records } = {}) {
|
|
49
|
+
const recs = (records ?? readLedger()).filter((r) => {
|
|
50
|
+
const at = Date.parse(r.at ?? '');
|
|
51
|
+
if (since && !(at >= since)) return false;
|
|
52
|
+
if (agent && r.agent !== agent) return false;
|
|
53
|
+
if (repo && r.repo !== repo) return false;
|
|
54
|
+
return true;
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
const agents = new Map();
|
|
58
|
+
const get = (name) => {
|
|
59
|
+
const k = name || 'unknown';
|
|
60
|
+
if (!agents.has(k))
|
|
61
|
+
agents.set(k, {
|
|
62
|
+
agent: k,
|
|
63
|
+
claims: { checked: 0, verified: 0, contradicted: 0, stale: 0, unbacked: 0, review: 0 },
|
|
64
|
+
strength: { runs: 0, killed: 0, survived: 0, weakRuns: 0, behaviouralSurvivors: 0 },
|
|
65
|
+
fixes: { sessions: new Map() },
|
|
66
|
+
weeks: new Map(),
|
|
67
|
+
last: null,
|
|
68
|
+
});
|
|
69
|
+
return agents.get(k);
|
|
70
|
+
};
|
|
71
|
+
const week = (a, at) => {
|
|
72
|
+
const w = weekOf(at);
|
|
73
|
+
if (!w) return null;
|
|
74
|
+
if (!a.weeks.has(w)) a.weeks.set(w, { week: w, checked: 0, falseDone: 0, killed: 0, survived: 0 });
|
|
75
|
+
return a.weeks.get(w);
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
for (const r of recs) {
|
|
79
|
+
// a claim: from verify / MCP (type "verify") or the transcript hook (no type)
|
|
80
|
+
if ((r.type === 'verify' || !r.type) && r.verdict) {
|
|
81
|
+
const a = get(r.agent);
|
|
82
|
+
a.claims.checked++;
|
|
83
|
+
a.claims[r.verdict] = (a.claims[r.verdict] ?? 0) + 1;
|
|
84
|
+
const w = week(a, r.at);
|
|
85
|
+
if (w && r.verdict !== 'review') {
|
|
86
|
+
w.checked++;
|
|
87
|
+
if (r.verdict === 'contradicted' || r.verdict === 'stale') w.falseDone++;
|
|
88
|
+
}
|
|
89
|
+
a.last = !a.last || r.at > a.last ? r.at : a.last;
|
|
90
|
+
} else if (r.type === 'mutation' && r.killed + r.survived > 0) {
|
|
91
|
+
const a = get(r.agent);
|
|
92
|
+
a.strength.runs++;
|
|
93
|
+
a.strength.killed += r.killed;
|
|
94
|
+
a.strength.survived += r.survived;
|
|
95
|
+
if (r.rating === 'weak') a.strength.weakRuns++;
|
|
96
|
+
a.strength.behaviouralSurvivors += (r.survivors ?? []).filter((s) => s.behavioural).length;
|
|
97
|
+
const w = week(a, r.at);
|
|
98
|
+
if (w) {
|
|
99
|
+
w.killed += r.killed;
|
|
100
|
+
w.survived += r.survived;
|
|
101
|
+
}
|
|
102
|
+
a.last = !a.last || r.at > a.last ? r.at : a.last;
|
|
103
|
+
} else if (r.type === 'reverify') {
|
|
104
|
+
const a = get(r.agent);
|
|
105
|
+
// keep the latest round per session
|
|
106
|
+
const prev = a.fixes.sessions.get(r.session);
|
|
107
|
+
if (!prev || r.round >= prev.round) a.fixes.sessions.set(r.session, { ...r, firstRound: prev?.firstRound ?? (r.round === 1 ? r : null) });
|
|
108
|
+
else if (r.round === 1) prev.firstRound = r;
|
|
109
|
+
a.last = !a.last || r.at > a.last ? r.at : a.last;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const rows = [...agents.values()].map((a) => {
|
|
114
|
+
const judged = a.claims.checked - a.claims.review;
|
|
115
|
+
const sessions = [...a.fixes.sessions.values()];
|
|
116
|
+
const closed = sessions.filter((s) => s.allResolved);
|
|
117
|
+
const first = sessions.filter((s) => s.firstRound);
|
|
118
|
+
return {
|
|
119
|
+
agent: a.agent,
|
|
120
|
+
evidence: a.claims.checked + a.strength.runs + sessions.length,
|
|
121
|
+
last: a.last,
|
|
122
|
+
claims: { ...a.claims, falseDoneRate: pct(a.claims.contradicted + a.claims.stale, judged) },
|
|
123
|
+
strength: {
|
|
124
|
+
runs: a.strength.runs,
|
|
125
|
+
killed: a.strength.killed,
|
|
126
|
+
survived: a.strength.survived,
|
|
127
|
+
weakRuns: a.strength.weakRuns,
|
|
128
|
+
behaviouralSurvivors: a.strength.behaviouralSurvivors,
|
|
129
|
+
score: pct(a.strength.killed, a.strength.killed + a.strength.survived),
|
|
130
|
+
},
|
|
131
|
+
fixes: {
|
|
132
|
+
sessions: sessions.length,
|
|
133
|
+
closed: closed.length,
|
|
134
|
+
firstRecheckRate: pct(first.filter((s) => s.firstRound.allResolved).length, first.length),
|
|
135
|
+
roundsToClose: closed.length ? Math.round((closed.reduce((n, s) => n + s.round, 0) / closed.length) * 10) / 10 : null,
|
|
136
|
+
stillOpen: sessions.length - closed.length,
|
|
137
|
+
},
|
|
138
|
+
weeks: [...a.weeks.values()]
|
|
139
|
+
.sort((x, y) => x.week.localeCompare(y.week))
|
|
140
|
+
.map((w) => ({ week: w.week, falseDoneRate: pct(w.falseDone, w.checked), score: pct(w.killed, w.killed + w.survived), checked: w.checked })),
|
|
141
|
+
};
|
|
142
|
+
});
|
|
143
|
+
rows.sort((x, y) => y.evidence - x.evidence);
|
|
144
|
+
return { since: since ? new Date(since).toISOString() : null, records: recs.length, agents: rows };
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** One sentence per agent, in plain words, with the evidence behind it. */
|
|
148
|
+
export function describeAgent(a) {
|
|
149
|
+
const parts = [];
|
|
150
|
+
if (a.claims.falseDoneRate != null) parts.push(`${Math.round((1 - a.claims.falseDoneRate) * 100)}% of its claims held up (${a.claims.checked} checked)`);
|
|
151
|
+
if (a.strength.score != null) parts.push(`its tests caught ${Math.round(a.strength.score * 100)}% of planted defects (${a.strength.runs} run${a.strength.runs === 1 ? '' : 's'})`);
|
|
152
|
+
if (a.fixes.firstRecheckRate != null) parts.push(`${Math.round(a.fixes.firstRecheckRate * 100)}% of its fixes closed every finding on the first re-check`);
|
|
153
|
+
return parts.length ? parts.join('; ') : 'not enough evidence yet';
|
|
154
|
+
}
|
package/src/report.js
CHANGED
|
@@ -1,99 +1,195 @@
|
|
|
1
|
-
// Aggregate claims into a reliability report and print it for humans.
|
|
2
|
-
|
|
3
|
-
export const VERDICTS = ['verified', 'contradicted', 'stale', 'unbacked', 'review'];
|
|
4
|
-
|
|
5
|
-
export function buildReport(claims, meta = {}) {
|
|
6
|
-
const tally = (key) => {
|
|
7
|
-
const m = {};
|
|
8
|
-
for (const c of claims) {
|
|
9
|
-
const k = typeof key === 'function' ? key(c) : c[key];
|
|
10
|
-
m[k] ??= { claims: 0, verified: 0, contradicted: 0, stale: 0, unbacked: 0, review: 0 };
|
|
11
|
-
m[k].claims++;
|
|
12
|
-
m[k][c.verdict]++;
|
|
13
|
-
}
|
|
14
|
-
for (const v of Object.values(m)) Object.assign(v, rates(v));
|
|
15
|
-
return m;
|
|
16
|
-
};
|
|
17
|
-
const totals = tally(() => 'all').all ?? { claims: 0, ...rates({}) };
|
|
18
|
-
return {
|
|
19
|
-
version: 1,
|
|
20
|
-
generatedAt: new Date().toISOString(),
|
|
21
|
-
...meta,
|
|
22
|
-
totals,
|
|
23
|
-
byAgent: tally('agent'),
|
|
24
|
-
byModel: tally('model'),
|
|
25
|
-
byRepo: tally('repo'),
|
|
26
|
-
byKind: tally('kind'),
|
|
27
|
-
byTaskType: tally('taskType'),
|
|
28
|
-
matrix: tally((c) => `${c.agent}|${c.kind}`),
|
|
29
|
-
claims: claims.sort((a, b) => String(b.at).localeCompare(String(a.at))),
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function rates(v) {
|
|
34
|
-
const checked = (v.verified || 0) + (v.contradicted || 0) + (v.stale || 0);
|
|
35
|
-
const settled = checked + (v.unbacked || 0);
|
|
36
|
-
return {
|
|
37
|
-
// Of claims that had a check behind them, how many were false or out of date.
|
|
38
|
-
falseDoneRate: checked ? round(((v.contradicted || 0) + (v.stale || 0)) / checked) : 0,
|
|
39
|
-
// Of all settled claims, how many were backed by a passing check.
|
|
40
|
-
trustRate: settled ? round((v.verified || 0) / settled) : 0,
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const round = (n) => Math.round(n * 1000) / 1000;
|
|
45
|
-
|
|
46
|
-
// ---------- terminal output ----------
|
|
47
|
-
|
|
48
|
-
const tty = process.stdout.isTTY && !process.env.NO_COLOR;
|
|
49
|
-
const paint = (code) => (s) => (tty ? `\x1b[${code}m${s}\x1b[0m` : String(s));
|
|
50
|
-
export const c = { dim: paint('2'), bold: paint('1'), red: paint('31'), green: paint('32'), yellow: paint('33'), blue: paint('34'), gray: paint('90') };
|
|
51
|
-
|
|
52
|
-
const MARK = { verified: c.green('✓ verified'), contradicted: c.red('✗ contradicted'), stale: c.yellow('◷ stale'), unbacked: c.gray('○ unbacked'), review: c.blue('◇ review') };
|
|
53
|
-
|
|
54
|
-
export function printReport(r, { limit = 8 } = {}) {
|
|
55
|
-
const t = r.totals;
|
|
56
|
-
const line = (s = '') => process.stdout.write(s + '\n');
|
|
57
|
-
line();
|
|
58
|
-
line(` ${c.bold('crossexam')} ${c.dim('· cross-examined ' + r.sessions + ' sessions, ' + r.turns + ' turns')}`);
|
|
59
|
-
line();
|
|
60
|
-
if (!t.claims) {
|
|
61
|
-
line(c.dim(' No completion claims found. Agents that never say "done" are hard to catch lying.'));
|
|
62
|
-
line();
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
line(` ${pad(t.claims, 5)} claims ${c.green(pad(t.verified, 4))} verified ${c.red(pad(t.contradicted, 4))} contradicted ${c.yellow(pad(t.stale, 4))} stale ${c.gray(pad(t.unbacked, 4))} unbacked ${c.blue(pad(t.review, 4))} review`);
|
|
66
|
-
line();
|
|
67
|
-
line(` ${c.bold(pct(t.falseDoneRate))} of checked claims were false or stale ${c.dim('(contradicted + stale) / (verified + contradicted + stale)')}`);
|
|
68
|
-
if (r.ranCheckTurns) line(` ${c.bold(r.contradictedTurns + ' of ' + r.ranCheckTurns)} turns that ran a check ended with a contradicted claim ${c.dim('(' + pct(r.contradictedTurns / r.ranCheckTurns) + ')')}`);
|
|
69
|
-
line();
|
|
70
|
-
|
|
71
|
-
const table = (title, m) => {
|
|
72
|
-
const rows = Object.entries(m).sort((a, b) => b[1].claims - a[1].claims).slice(0, 6);
|
|
73
|
-
if (!rows.length) return;
|
|
74
|
-
line(c.dim(` ${title.padEnd(26)} claims trust false-done`));
|
|
75
|
-
for (const [k, v] of rows) line(` ${k.slice(0, 26).padEnd(26)} ${pad(v.claims, 6)} ${pad(pct(v.trustRate), 5)} ${v.falseDoneRate > 0.1 ? c.red(pad(pct(v.falseDoneRate), 5)) : pad(pct(v.falseDoneRate), 5)}`);
|
|
76
|
-
line();
|
|
77
|
-
};
|
|
78
|
-
table('by agent', r.byAgent);
|
|
79
|
-
table('by model', r.byModel);
|
|
80
|
-
table('by claim', r.byKind);
|
|
81
|
-
table('by repo', r.byRepo);
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
line(c.bold('
|
|
86
|
-
line();
|
|
87
|
-
for (const
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
1
|
+
// Aggregate claims into a reliability report and print it for humans.
|
|
2
|
+
|
|
3
|
+
export const VERDICTS = ['verified', 'contradicted', 'stale', 'unbacked', 'review'];
|
|
4
|
+
|
|
5
|
+
export function buildReport(claims, meta = {}) {
|
|
6
|
+
const tally = (key) => {
|
|
7
|
+
const m = {};
|
|
8
|
+
for (const c of claims) {
|
|
9
|
+
const k = typeof key === 'function' ? key(c) : c[key];
|
|
10
|
+
m[k] ??= { claims: 0, verified: 0, contradicted: 0, stale: 0, unbacked: 0, review: 0 };
|
|
11
|
+
m[k].claims++;
|
|
12
|
+
m[k][c.verdict]++;
|
|
13
|
+
}
|
|
14
|
+
for (const v of Object.values(m)) Object.assign(v, rates(v));
|
|
15
|
+
return m;
|
|
16
|
+
};
|
|
17
|
+
const totals = tally(() => 'all').all ?? { claims: 0, ...rates({}) };
|
|
18
|
+
return {
|
|
19
|
+
version: 1,
|
|
20
|
+
generatedAt: new Date().toISOString(),
|
|
21
|
+
...meta,
|
|
22
|
+
totals,
|
|
23
|
+
byAgent: tally('agent'),
|
|
24
|
+
byModel: tally('model'),
|
|
25
|
+
byRepo: tally('repo'),
|
|
26
|
+
byKind: tally('kind'),
|
|
27
|
+
byTaskType: tally('taskType'),
|
|
28
|
+
matrix: tally((c) => `${c.agent}|${c.kind}`),
|
|
29
|
+
claims: claims.sort((a, b) => String(b.at).localeCompare(String(a.at))),
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function rates(v) {
|
|
34
|
+
const checked = (v.verified || 0) + (v.contradicted || 0) + (v.stale || 0);
|
|
35
|
+
const settled = checked + (v.unbacked || 0);
|
|
36
|
+
return {
|
|
37
|
+
// Of claims that had a check behind them, how many were false or out of date.
|
|
38
|
+
falseDoneRate: checked ? round(((v.contradicted || 0) + (v.stale || 0)) / checked) : 0,
|
|
39
|
+
// Of all settled claims, how many were backed by a passing check.
|
|
40
|
+
trustRate: settled ? round((v.verified || 0) / settled) : 0,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const round = (n) => Math.round(n * 1000) / 1000;
|
|
45
|
+
|
|
46
|
+
// ---------- terminal output ----------
|
|
47
|
+
|
|
48
|
+
const tty = process.stdout.isTTY && !process.env.NO_COLOR;
|
|
49
|
+
const paint = (code) => (s) => (tty ? `\x1b[${code}m${s}\x1b[0m` : String(s));
|
|
50
|
+
export const c = { dim: paint('2'), bold: paint('1'), red: paint('31'), green: paint('32'), yellow: paint('33'), blue: paint('34'), gray: paint('90') };
|
|
51
|
+
|
|
52
|
+
const MARK = { verified: c.green('✓ verified'), contradicted: c.red('✗ contradicted'), stale: c.yellow('◷ stale'), unbacked: c.gray('○ unbacked'), review: c.blue('◇ review') };
|
|
53
|
+
|
|
54
|
+
export function printReport(r, { limit = 8 } = {}) {
|
|
55
|
+
const t = r.totals;
|
|
56
|
+
const line = (s = '') => process.stdout.write(s + '\n');
|
|
57
|
+
line();
|
|
58
|
+
line(` ${c.bold('crossexam')} ${c.dim('· cross-examined ' + r.sessions + ' sessions, ' + r.turns + ' turns')}`);
|
|
59
|
+
line();
|
|
60
|
+
if (!t.claims) {
|
|
61
|
+
line(c.dim(' No completion claims found. Agents that never say "done" are hard to catch lying.'));
|
|
62
|
+
line();
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
line(` ${pad(t.claims, 5)} claims ${c.green(pad(t.verified, 4))} verified ${c.red(pad(t.contradicted, 4))} contradicted ${c.yellow(pad(t.stale, 4))} stale ${c.gray(pad(t.unbacked, 4))} unbacked ${c.blue(pad(t.review, 4))} review`);
|
|
66
|
+
line();
|
|
67
|
+
line(` ${c.bold(pct(t.falseDoneRate))} of checked claims were false or stale ${c.dim('(contradicted + stale) / (verified + contradicted + stale)')}`);
|
|
68
|
+
if (r.ranCheckTurns) line(` ${c.bold(r.contradictedTurns + ' of ' + r.ranCheckTurns)} turns that ran a check ended with a contradicted claim ${c.dim('(' + pct(r.contradictedTurns / r.ranCheckTurns) + ')')}`);
|
|
69
|
+
line();
|
|
70
|
+
|
|
71
|
+
const table = (title, m) => {
|
|
72
|
+
const rows = Object.entries(m).sort((a, b) => b[1].claims - a[1].claims).slice(0, 6);
|
|
73
|
+
if (!rows.length) return;
|
|
74
|
+
line(c.dim(` ${title.padEnd(26)} claims trust false-done`));
|
|
75
|
+
for (const [k, v] of rows) line(` ${k.slice(0, 26).padEnd(26)} ${pad(v.claims, 6)} ${pad(pct(v.trustRate), 5)} ${v.falseDoneRate > 0.1 ? c.red(pad(pct(v.falseDoneRate), 5)) : pad(pct(v.falseDoneRate), 5)}`);
|
|
76
|
+
line();
|
|
77
|
+
};
|
|
78
|
+
table('by agent', r.byAgent);
|
|
79
|
+
table('by model', r.byModel);
|
|
80
|
+
table('by claim', r.byKind);
|
|
81
|
+
table('by repo', r.byRepo);
|
|
82
|
+
|
|
83
|
+
if (r.mutation) {
|
|
84
|
+
const m = r.mutation;
|
|
85
|
+
line(` ${c.bold('Test strength')} ${c.dim(`· ${m.runs} mutation run${m.runs === 1 ? '' : 's'}, ${pct(m.score)} of ${m.killed + m.survived} planted defects caught · separate from the verdicts above`)}`);
|
|
86
|
+
line(c.dim(` ${'by agent'.padEnd(26)} runs caught weak runs`));
|
|
87
|
+
for (const [k, v] of Object.entries(m.byAgent).sort((a, b) => b[1].runs - a[1].runs).slice(0, 6)) {
|
|
88
|
+
line(` ${k.slice(0, 26).padEnd(26)} ${pad(v.runs, 4)} ${(v.score < 0.6 ? c.red : v.score < 0.8 ? c.yellow : c.green)(pad(pct(v.score), 5))} ${pad(v.weakRuns, 4)}`);
|
|
89
|
+
}
|
|
90
|
+
line();
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const bad = r.claims.filter((x) => x.verdict === 'contradicted' || x.verdict === 'stale').slice(0, limit);
|
|
94
|
+
if (bad.length) {
|
|
95
|
+
line(c.bold(' Most recent false "done"s'));
|
|
96
|
+
line();
|
|
97
|
+
for (const x of bad) printClaim(x, line);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export function printClaim(x, line = (s = '') => process.stdout.write(s + '\n')) {
|
|
102
|
+
line(` ${MARK[x.verdict]} ${c.dim(x.repo + ' · ' + x.agent + ' · ' + (x.at || '').slice(0, 10))}`);
|
|
103
|
+
line(` “${x.claim.length > 140 ? x.claim.slice(0, 137) + '…' : x.claim}”`);
|
|
104
|
+
line(` ${c.dim('→ ' + x.reason)}`);
|
|
105
|
+
line();
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const pad = (v, n) => String(v).padStart(n);
|
|
109
|
+
const pct = (n) => `${(n * 100).toFixed(n && n < 0.1 ? 1 : 0)}%`;
|
|
110
|
+
|
|
111
|
+
// ---------- test strength ----------
|
|
112
|
+
|
|
113
|
+
const RATING = { strong: c.green('strong'), moderate: c.yellow('moderate'), weak: c.red('weak'), inconclusive: c.gray('inconclusive') };
|
|
114
|
+
const SHORT = { MUTATION_KILLED: c.green('killed'), MUTATION_SURVIVED: c.red('survived'), MUTATION_INVALID: c.gray('invalid'), MUTATION_UNRESOLVED: c.yellow('unresolved') };
|
|
115
|
+
|
|
116
|
+
export function printStrength(r, { line = (s = '') => process.stdout.write(s + '\n'), limit = 8 } = {}) {
|
|
117
|
+
const s = r.summary;
|
|
118
|
+
const secs = (ms) => `${(ms / 1000).toFixed(1)}s`;
|
|
119
|
+
line();
|
|
120
|
+
const iso = r.isolation || {};
|
|
121
|
+
const isoLabel = !iso.method ? c.yellow('not run: no sandbox') : iso.sandboxed ? c.green(`sandboxed (${iso.method})`) : c.red(c.bold('NOT SANDBOXED'));
|
|
122
|
+
line(` ${c.bold('crossexam')} ${c.dim('· test strength · ' + r.repo + ' · ' + r.scope + ' · ')}${isoLabel}`);
|
|
123
|
+
line();
|
|
124
|
+
if (r.headline) {
|
|
125
|
+
const tone = r.headline.tone === 'good' ? c.green : r.headline.tone === 'warn' ? c.red : c.dim;
|
|
126
|
+
line(` ${RATING[r.rating]}${s.score != null ? c.dim(` · mutation score ${Math.round(s.score * 100)}%`) : ''}`);
|
|
127
|
+
line(` ${tone(r.headline.text)}`);
|
|
128
|
+
line();
|
|
129
|
+
}
|
|
130
|
+
if (s.attempted) {
|
|
131
|
+
line(` ${pad(s.attempted, 3)} attempted ${pad(s.valid, 3)} valid ${c.green(pad(s.killed, 3))} killed ${c.red(pad(s.survived, 3))} survived ${c.gray(pad(s.invalid, 3))} invalid ${c.yellow(pad(s.unresolved, 3))} unresolved`);
|
|
132
|
+
line(c.dim(` ${secs(s.ms)} total${r.baseline ? ` · baseline ${secs(r.baseline.ms)}` : ''}${s.cachedResults ? ` · ${s.cachedResults} from cache` : ''} · ${r.testCommand}`));
|
|
133
|
+
line();
|
|
134
|
+
}
|
|
135
|
+
const fns = r.functions.filter((f) => f.killed + f.survived);
|
|
136
|
+
if (fns.length) {
|
|
137
|
+
line(c.dim(' function file caught'));
|
|
138
|
+
for (const f of fns.slice(0, 10)) {
|
|
139
|
+
const total = f.killed + f.survived;
|
|
140
|
+
const bar = c.green('█'.repeat(f.killed)) + c.red('█'.repeat(f.survived));
|
|
141
|
+
line(` ${(f.name || '(top level)').slice(0, 32).padEnd(32)} ${`${f.file}:${f.line}`.slice(-28).padEnd(28)} ${pad(f.killed + '/' + total, 5)} ${bar}`);
|
|
142
|
+
}
|
|
143
|
+
line();
|
|
144
|
+
}
|
|
145
|
+
const surv = r.mutants.filter((m) => m.status === 'MUTATION_SURVIVED');
|
|
146
|
+
if (surv.length) {
|
|
147
|
+
line(c.bold(' Defects the tests did not notice'));
|
|
148
|
+
line();
|
|
149
|
+
for (const m of surv.slice(0, limit)) {
|
|
150
|
+
const kind = m.category && !['logic', 'arithmetic'].includes(m.category) ? `${m.category} · ` : '';
|
|
151
|
+
line(` ${SHORT[m.status]} ${m.file}:${m.line} ${c.dim((m.function || 'top level') + ' · ' + kind + m.operator)}`);
|
|
152
|
+
if (m.before != null) line(c.dim(` - ${m.before.split('\n')[0].slice(0, 110)}`));
|
|
153
|
+
if (m.after != null) line(` ${c.red('+ ' + m.after.split('\n')[0].slice(0, 110))}`);
|
|
154
|
+
line(` ${c.dim('→ ' + m.why)}`);
|
|
155
|
+
line();
|
|
156
|
+
}
|
|
157
|
+
if (surv.length > limit) line(c.dim(` …and ${surv.length - limit} more (--json for all)\n`));
|
|
158
|
+
}
|
|
159
|
+
const tests = r.associatedTests.map((t) => t.file);
|
|
160
|
+
if (r.files.length) line(c.dim(` Tests that touch the changed code: ${tests.length ? tests.slice(0, 6).join(', ') + (tests.length > 6 ? ` +${tests.length - 6}` : '') : 'none found'}`));
|
|
161
|
+
if (r.skippedFiles.length) line(c.dim(` Not mutated: ${r.skippedFiles.slice(0, 5).map((f) => `${f.file} (${f.reason})`).join(', ')}${r.skippedFiles.length > 5 ? ` +${r.skippedFiles.length - 5}` : ''}`));
|
|
162
|
+
for (const n of r.notes) if (n !== r.headline?.text) line(c.dim(` ${n}`));
|
|
163
|
+
line();
|
|
164
|
+
printExecution(r, line);
|
|
165
|
+
line(c.dim(' A mutation score says how well the tests pin down the changed code, not whether the code is correct.'));
|
|
166
|
+
line();
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** What crossexam actually did, in plain words, so nobody has to read the source to know. */
|
|
170
|
+
export function printExecution(r, line = (s = '') => process.stdout.write(s + '\n')) {
|
|
171
|
+
const e = r.execution || {};
|
|
172
|
+
const iso = r.isolation || {};
|
|
173
|
+
const row = (k, v) => line(` ${c.dim(k.padEnd(14))} ${v}`);
|
|
174
|
+
line(c.bold(' What crossexam did'));
|
|
175
|
+
row('repository', `${e.repository ?? r.repo} ${c.dim(r.cwd || '')}`);
|
|
176
|
+
row('compared', r.scope);
|
|
177
|
+
row('files', r.files.length ? `${r.files.length} evaluated: ${r.files.slice(0, 4).map((f) => f.file).join(', ')}${r.files.length > 4 ? ` +${r.files.length - 4}` : ''}` : 'none');
|
|
178
|
+
row('mutations', `${e.mutantsGenerated ?? 0} generated, ${r.summary.attempted - r.summary.cachedResults} run now, ${r.summary.cachedResults} from cache, ${r.remaining} left for later`);
|
|
179
|
+
row('test runs', `${e.testRuns ?? 0}${r.testCommand ? ` ${c.dim(r.testCommand)}` : ''}`);
|
|
180
|
+
if (!iso.method) row('isolation', c.yellow('none available, so nothing was executed'));
|
|
181
|
+
else {
|
|
182
|
+
row('isolation', iso.sandboxed ? c.green(iso.method) : c.red(c.bold('NOT SANDBOXED') + ' (you passed --unsandboxed)'));
|
|
183
|
+
row(' filesystem', iso.filesystem);
|
|
184
|
+
row(' network', iso.network);
|
|
185
|
+
row(' environment', iso.environment);
|
|
186
|
+
const l = iso.limits || {};
|
|
187
|
+
row(' limits', [l.timeoutSeconds ? `${l.timeoutSeconds}s per run` : null, l.memoryMb ? `${l.memoryMb} MB memory` : null, l.cpuSeconds ? `${l.cpuSeconds}s CPU` : null, l.cpus ? `${l.cpus} CPUs` : null].filter(Boolean).join(', ') || 'timeout only');
|
|
188
|
+
}
|
|
189
|
+
row('duration', `${((e.durationMs ?? r.summary.ms) / 1000).toFixed(1)}s`);
|
|
190
|
+
const cl = e.cleanup || {};
|
|
191
|
+
row('cleanup', cl.status === 'removed' ? c.green('temporary copy removed') : cl.status === 'incomplete' ? c.yellow(`copy left at ${cl.path}`) : c.dim('nothing was created'));
|
|
192
|
+
if (e.staleCopiesRemoved) row('', c.dim(`also removed ${e.staleCopiesRemoved} copy left by an interrupted earlier run`));
|
|
193
|
+
if (r.workingTreeUntouched != null) row('your repo', r.workingTreeUntouched ? c.green('unchanged (every file hash, HEAD, refs, stash and status match)') : c.yellow('changed during the run, not by crossexam'));
|
|
194
|
+
line();
|
|
195
|
+
}
|