@yokla/report 0.0.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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,uEAAuE;AAEvE,OAAO,EAAE,uBAAuB,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAChE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAC7D,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,UAAU,EAAmC,MAAM,eAAe,CAAC;AAC1F,OAAO,EAAE,eAAe,EAAwB,MAAM,eAAe,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type { Results } from '@yokla/core';
2
+ export declare function xmlText(text: string): string;
3
+ export declare function xmlAttribute(text: string): string;
4
+ export declare function junitXml(results: Results): string;
5
+ //# sourceMappingURL=junit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"junit.d.ts","sourceRoot":"","sources":["../src/junit.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAe3C,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAI5C;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAMjD;AAyED,wBAAgB,QAAQ,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAqBjD"}
package/dist/junit.js ADDED
@@ -0,0 +1,105 @@
1
+ // JUnit XML (design §16), for CI systems that show test reports. One
2
+ // testsuite per yokla suite, one testcase per case:
3
+ // - fail becomes <failure>; error and fixture-missing become <error>;
4
+ // - unmeasured and known-gap become <skipped>, so neither reads as a pass;
5
+ // - gap-closed, unstable samples and advisory findings go to <system-out>.
6
+ // Only finding messages are written, never the target's answers.
7
+ import { caseProblems, caseReason } from './problems.js';
8
+ /** Whether XML 1.0 can carry this code point; lone surrogates can't. */
9
+ function allowed(code) {
10
+ return (code === 0x09 ||
11
+ code === 0x0a ||
12
+ code === 0x0d ||
13
+ (code >= 0x20 && code <= 0xd7ff) ||
14
+ (code >= 0xe000 && code <= 0xfffd) ||
15
+ (code >= 0x10000 && code <= 0x10ffff));
16
+ }
17
+ export function xmlText(text) {
18
+ let clean = '';
19
+ for (const char of text)
20
+ clean += allowed(char.codePointAt(0) ?? 0) ? char : '\uFFFD';
21
+ return clean.replaceAll('&', '&amp;').replaceAll('<', '&lt;').replaceAll('>', '&gt;');
22
+ }
23
+ export function xmlAttribute(text) {
24
+ return xmlText(text)
25
+ .replaceAll('"', '&quot;')
26
+ .replaceAll('\n', '&#10;')
27
+ .replaceAll('\r', '&#13;')
28
+ .replaceAll('\t', '&#9;');
29
+ }
30
+ function seconds(ms) {
31
+ return (ms / 1000).toFixed(3);
32
+ }
33
+ function caseMs(c) {
34
+ return c.samples
35
+ .flatMap((sample) => sample.turns)
36
+ .reduce((total, turn) => total + (turn.response?.latencyMs ?? 0), 0);
37
+ }
38
+ function problemLine(problem) {
39
+ return `sample ${String(problem.sample)}, turn ${String(problem.turn)}: ${problem.check} (${problem.dimension}): ${problem.message}`;
40
+ }
41
+ function count(cases) {
42
+ // A proposed case doesn't gate (ADR-0004), so it is skipped whatever its status.
43
+ const approved = cases.filter((c) => c.review !== 'proposed');
44
+ const has = (...statuses) => approved.filter((c) => statuses.includes(c.status)).length;
45
+ return {
46
+ tests: cases.length,
47
+ failures: has('fail'),
48
+ errors: has('error', 'fixture-missing'),
49
+ skipped: has('unmeasured', 'known-gap') + (cases.length - approved.length),
50
+ };
51
+ }
52
+ function countAttributes(counts) {
53
+ return `tests="${String(counts.tests)}" failures="${String(counts.failures)}" errors="${String(counts.errors)}" skipped="${String(counts.skipped)}"`;
54
+ }
55
+ function testcase(c) {
56
+ const problems = caseProblems(c);
57
+ const reason = caseReason(c, problems) ?? '';
58
+ const children = [];
59
+ if (c.review === 'proposed') {
60
+ const message = `proposed, not approved yet: ${c.status}${reason === '' ? '' : `: ${reason}`}`;
61
+ children.push(`<skipped message="${xmlAttribute(message)}"/>`);
62
+ }
63
+ else if (c.status === 'fail') {
64
+ const body = problems.deciding.map(problemLine).join('\n');
65
+ children.push(`<failure type="fail" message="${xmlAttribute(reason)}">${xmlText(body)}</failure>`);
66
+ }
67
+ else if (c.status === 'error' || c.status === 'fixture-missing') {
68
+ const body = problems.errors.join('\n');
69
+ children.push(`<error type="${c.status}" message="${xmlAttribute(reason)}">${xmlText(body)}</error>`);
70
+ }
71
+ else if (c.status === 'unmeasured' || c.status === 'known-gap') {
72
+ const message = c.status === 'unmeasured' ? `unmeasured: ${reason}` : reason;
73
+ children.push(`<skipped message="${xmlAttribute(message)}"/>`);
74
+ }
75
+ const notes = [
76
+ ...(c.status === 'gap-closed' ? [`gap closed: ${reason}`] : []),
77
+ ...(c.unstable ? ['unstable: the samples disagree'] : []),
78
+ ...problems.advisory.map((problem) => `advisory: ${problemLine(problem)}`),
79
+ ];
80
+ if (notes.length > 0)
81
+ children.push(`<system-out>${xmlText(notes.join('\n'))}</system-out>`);
82
+ const open = `<testcase name="${xmlAttribute(c.id)}" classname="${xmlAttribute(`yokla.${c.suite}`)}" time="${seconds(caseMs(c))}"`;
83
+ if (children.length === 0)
84
+ return [` ${open}/>`];
85
+ return [` ${open}>`, ...children.map((child) => ` ${child}`), ' </testcase>'];
86
+ }
87
+ export function junitXml(results) {
88
+ const suites = new Map();
89
+ for (const c of results.cases) {
90
+ const list = suites.get(c.suite) ?? [];
91
+ list.push(c);
92
+ suites.set(c.suite, list);
93
+ }
94
+ const lines = [
95
+ '<?xml version="1.0" encoding="UTF-8"?>',
96
+ `<testsuites name="yokla" ${countAttributes(count(results.cases))} time="${seconds(results.run.durationMs)}">`,
97
+ ];
98
+ for (const [suite, cases] of suites) {
99
+ const time = cases.reduce((total, c) => total + caseMs(c), 0);
100
+ lines.push(` <testsuite name="${xmlAttribute(suite)}" ${countAttributes(count(cases))} time="${seconds(time)}" timestamp="${xmlAttribute(results.run.startedAt)}">`, ...cases.flatMap(testcase), ' </testsuite>');
101
+ }
102
+ lines.push('</testsuites>', '');
103
+ return lines.join('\n');
104
+ }
105
+ //# sourceMappingURL=junit.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"junit.js","sourceRoot":"","sources":["../src/junit.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,oDAAoD;AACpD,sEAAsE;AACtE,2EAA2E;AAC3E,2EAA2E;AAC3E,iEAAiE;AAGjE,OAAO,EAAE,YAAY,EAAE,UAAU,EAAiC,MAAM,eAAe,CAAC;AAExF,wEAAwE;AACxE,SAAS,OAAO,CAAC,IAAY;IAC3B,OAAO,CACL,IAAI,KAAK,IAAI;QACb,IAAI,KAAK,IAAI;QACb,IAAI,KAAK,IAAI;QACb,CAAC,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,MAAM,CAAC;QAChC,CAAC,IAAI,IAAI,MAAM,IAAI,IAAI,IAAI,MAAM,CAAC;QAClC,CAAC,IAAI,IAAI,OAAO,IAAI,IAAI,IAAI,QAAQ,CAAC,CACtC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,OAAO,CAAC,IAAY;IAClC,IAAI,KAAK,GAAG,EAAE,CAAC;IACf,KAAK,MAAM,IAAI,IAAI,IAAI;QAAE,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC;IACtF,OAAO,KAAK,CAAC,UAAU,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,UAAU,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,UAAU,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;AACx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,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QAC9D,KAAK,CAAC,IAAI,CACR,sBAAsB,YAAY,CAAC,KAAK,CAAC,KAAK,eAAe,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,UAAU,OAAO,CAAC,IAAI,CAAC,gBAAgB,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,EACzJ,GAAG,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,EAC1B,gBAAgB,CACjB,CAAC;IACJ,CAAC;IACD,KAAK,CAAC,IAAI,CAAC,eAAe,EAAE,EAAE,CAAC,CAAC;IAChC,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC"}
@@ -0,0 +1,25 @@
1
+ import type { Results } from '@yokla/core';
2
+ export type CaseResult = Results['cases'][number];
3
+ export interface Problem {
4
+ readonly sample: number;
5
+ readonly turn: number;
6
+ readonly check: string;
7
+ readonly dimension: string;
8
+ readonly message: string;
9
+ }
10
+ export interface CaseProblems {
11
+ /** Failing findings in dimensions that failed and decide the case. */
12
+ readonly deciding: readonly Problem[];
13
+ /** Failing findings in advisory dimensions; reported, never deciding. */
14
+ readonly advisory: readonly Problem[];
15
+ /** Turn errors and check errors. */
16
+ readonly errors: readonly string[];
17
+ /** Thresholds checks couldn't measure, as "dimension: reason", once each (ADR-0014). */
18
+ readonly unmeasured: readonly string[];
19
+ }
20
+ export declare function caseProblems(c: CaseResult): CaseProblems;
21
+ /** "filter-honesty 1/3: <first message>; fabrication 2/3: …" */
22
+ export declare function dimensionSummary(c: CaseResult, problems: readonly Problem[], advisory: boolean): string;
23
+ /** One line on why a case did not pass, or undefined for a plain pass. */
24
+ export declare function caseReason(c: CaseResult, problems: CaseProblems): string | undefined;
25
+ //# sourceMappingURL=problems.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"problems.d.ts","sourceRoot":"","sources":["../src/problems.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAG3C,MAAM,MAAM,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC;AAElD,MAAM,WAAW,OAAO;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,WAAW,YAAY;IAC3B,sEAAsE;IACtE,QAAQ,CAAC,QAAQ,EAAE,SAAS,OAAO,EAAE,CAAC;IACtC,yEAAyE;IACzE,QAAQ,CAAC,QAAQ,EAAE,SAAS,OAAO,EAAE,CAAC;IACtC,oCAAoC;IACpC,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;IACnC,wFAAwF;IACxF,QAAQ,CAAC,UAAU,EAAE,SAAS,MAAM,EAAE,CAAC;CACxC;AAED,wBAAgB,YAAY,CAAC,CAAC,EAAE,UAAU,GAAG,YAAY,CA0CxD;AAED,gEAAgE;AAChE,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,UAAU,EAAE,QAAQ,EAAE,SAAS,OAAO,EAAE,EAAE,QAAQ,EAAE,OAAO,UAS9F;AAED,0EAA0E;AAC1E,wBAAgB,UAAU,CAAC,CAAC,EAAE,UAAU,EAAE,QAAQ,EAAE,YAAY,GAAG,MAAM,GAAG,SAAS,CAoBpF"}
@@ -0,0 +1,82 @@
1
+ // What went wrong in a case, read from results.v1 alone (ADR-0007): the
2
+ // failing findings of its failing dimensions, split into deciding and
3
+ // advisory ones, and the errors of its turns and checks.
4
+ import { withOrigin } from './format.js';
5
+ export function caseProblems(c) {
6
+ const failed = c.dimensions.filter((d) => d.verdict === 'fail');
7
+ const deciding = new Set(failed.filter((d) => d.policy !== 'advisory').map((d) => d.dimension));
8
+ const advisory = new Set(failed.filter((d) => d.policy === 'advisory').map((d) => d.dimension));
9
+ const found = {
10
+ deciding: [],
11
+ advisory: [],
12
+ errors: [],
13
+ unmeasured: [],
14
+ };
15
+ for (const sample of c.samples) {
16
+ for (const [turn, result] of sample.turns.entries()) {
17
+ const where = `sample ${String(sample.index)}, turn ${String(turn)}`;
18
+ if (result.error !== undefined)
19
+ found.errors.push(`${where}: ${result.error}`);
20
+ for (const check of result.checks) {
21
+ for (const gap of check.unmeasured ?? []) {
22
+ const line = `${gap.dimension}: ${gap.reason}`;
23
+ if (!found.unmeasured.includes(line))
24
+ found.unmeasured.push(line);
25
+ }
26
+ for (const finding of check.findings) {
27
+ if (finding.verdict === 'error')
28
+ found.errors.push(`${where}: ${finding.message}`);
29
+ if (finding.verdict !== 'fail')
30
+ continue;
31
+ const problem = {
32
+ sample: sample.index,
33
+ turn,
34
+ check: check.check,
35
+ dimension: finding.dimension,
36
+ // Where the value it is about came from, when known (ADR-0033).
37
+ message: withOrigin(finding),
38
+ };
39
+ if (deciding.has(finding.dimension))
40
+ found.deciding.push(problem);
41
+ else if (advisory.has(finding.dimension))
42
+ found.advisory.push(problem);
43
+ }
44
+ }
45
+ }
46
+ }
47
+ return found;
48
+ }
49
+ /** "filter-honesty 1/3: <first message>; fabrication 2/3: …" */
50
+ export function dimensionSummary(c, problems, advisory) {
51
+ return c.dimensions
52
+ .filter((d) => d.verdict === 'fail' && (d.policy === 'advisory') === advisory)
53
+ .map((d) => {
54
+ const first = problems.find((p) => p.dimension === d.dimension);
55
+ const counts = `${d.dimension} ${String(d.failed)}/${String(d.samples)}`;
56
+ return first === undefined ? counts : `${counts}: ${first.message}`;
57
+ })
58
+ .join('; ');
59
+ }
60
+ /** One line on why a case did not pass, or undefined for a plain pass. */
61
+ export function caseReason(c, problems) {
62
+ switch (c.status) {
63
+ case 'pass':
64
+ return undefined;
65
+ case 'fail':
66
+ return dimensionSummary(c, problems.deciding, false);
67
+ case 'error':
68
+ return problems.errors[0] ?? c.status;
69
+ case 'fixture-missing':
70
+ // The facts the data no longer holds; the case sent nothing (ADR-0053).
71
+ return c.fixture === undefined ? c.status : `fixture missing: ${c.fixture.join('; ')}`;
72
+ case 'unmeasured':
73
+ return problems.unmeasured.length > 0
74
+ ? `unmeasured ${problems.unmeasured.join('; ')}`
75
+ : 'no check applied to any turn';
76
+ case 'known-gap':
77
+ return `known gap: ${c.knownGap?.reason ?? 'no reason given'}${c.knownGap?.issue === undefined ? '' : ` (${c.knownGap.issue})`}`;
78
+ case 'gap-closed':
79
+ return 'passes now; remove the known-gap marker and update the baseline';
80
+ }
81
+ }
82
+ //# sourceMappingURL=problems.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"problems.js","sourceRoot":"","sources":["../src/problems.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,sEAAsE;AACtE,yDAAyD;AAGzD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAuBzC,MAAM,UAAU,YAAY,CAAC,CAAa;IACxC,MAAM,MAAM,GAAG,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,KAAK,MAAM,CAAC,CAAC;IAChE,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC;IAChG,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC;IAChG,MAAM,KAAK,GAKP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A0E;AAC1E,MAAM,UAAU,UAAU,CAAC,CAAa,EAAE,QAAsB;IAC9D,QAAQ,CAAC,CAAC,MAAM,EAAE,CAAC;QACjB,KAAK,MAAM;YACT,OAAO,SAAS,CAAC;QACnB,KAAK,MAAM;YACT,OAAO,gBAAgB,CAAC,CAAC,EAAE,QAAQ,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;QACvD,KAAK,OAAO;YACV,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC;QACxC,KAAK,iBAAiB;YACpB,wEAAwE;YACxE,OAAO,CAAC,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,oBAAoB,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QACzF,KAAK,YAAY;YACf,OAAO,QAAQ,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC;gBACnC,CAAC,CAAC,cAAc,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;gBAChD,CAAC,CAAC,8BAA8B,CAAC;QACrC,KAAK,WAAW;YACd,OAAO,cAAc,CAAC,CAAC,QAAQ,EAAE,MAAM,IAAI,iBAAiB,GAAG,CAAC,CAAC,QAAQ,EAAE,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,KAAK,GAAG,EAAE,CAAC;QACnI,KAAK,YAAY;YACf,OAAO,iEAAiE,CAAC;IAC7E,CAAC;AACH,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { type Results } from '@yokla/core';
2
+ export interface TerminalSummary {
3
+ readonly out: readonly string[];
4
+ readonly err: readonly string[];
5
+ }
6
+ export declare function terminalSummary(results: Results): TerminalSummary;
7
+ //# sourceMappingURL=terminal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"terminal.d.ts","sourceRoot":"","sources":["../src/terminal.ts"],"names":[],"mappings":"AAIA,OAAO,EAAiB,KAAK,OAAO,EAAE,MAAM,aAAa,CAAC;AAI1D,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,GAAG,EAAE,SAAS,MAAM,EAAE,CAAC;IAChC,QAAQ,CAAC,GAAG,EAAE,SAAS,MAAM,EAAE,CAAC;CACjC;AAED,wBAAgB,eAAe,CAAC,OAAO,EAAE,OAAO,GAAG,eAAe,CA4FjE"}
@@ -0,0 +1,86 @@
1
+ // The terminal summary of a run (design §16): the status counts, one line per
2
+ // case that did not plainly pass, advisory findings, and what the target's
3
+ // logs observed. Errors and run issues go to stderr.
4
+ import { CASE_STATUSES } from '@yokla/core';
5
+ import { counted, observedTotals } from './format.js';
6
+ import { caseProblems, caseReason, dimensionSummary } from './problems.js';
7
+ export function terminalSummary(results) {
8
+ const out = [];
9
+ const err = [];
10
+ const counts = CASE_STATUSES.flatMap((status) => {
11
+ const count = results.summary.statuses[status];
12
+ return count === undefined ? [] : [`${status} ${String(count)}`];
13
+ });
14
+ out.push(`${String(results.summary.cases)} cases: ${counts.join(', ')}`);
15
+ if (results.run.sampling?.stopEarly === true) {
16
+ // How many samples --stop-early saved (ADR-0038).
17
+ const ran = results.cases.reduce((n, c) => n + c.samples.length, 0);
18
+ const planned = results.cases.reduce((n, c) => n + (c.samplesPlanned ?? c.samples.length), 0);
19
+ out.push(` --stop-early: ${counted(ran, 'sample')} ran of ${String(planned)} planned`);
20
+ }
21
+ const proposed = results.cases.filter((c) => c.review === 'proposed').length;
22
+ if (proposed > 0) {
23
+ out.push(` ${String(proposed)} proposed: they ran, and gate once a person sets their status to approved`);
24
+ }
25
+ const rows = [];
26
+ for (const c of results.cases) {
27
+ const problems = caseProblems(c);
28
+ const reason = caseReason(c, problems);
29
+ if (reason !== undefined) {
30
+ const stopped = c.samplesPlanned === undefined
31
+ ? ''
32
+ : ` [stopped after ${String(c.samples.length)} of ${String(c.samplesPlanned)} samples]`;
33
+ const marks = `${c.unstable ? ' [unstable]' : ''}${stopped}${c.review === 'proposed' ? ' [proposed]' : ''}`;
34
+ rows.push([c.status, c.id, `${reason}${marks}`]);
35
+ }
36
+ const advisory = dimensionSummary(c, problems.advisory, true);
37
+ if (advisory !== '')
38
+ rows.push(['advisory', c.id, advisory]);
39
+ for (const sample of c.samples) {
40
+ for (const turn of sample.turns) {
41
+ if (turn.error !== undefined)
42
+ err.push(` ${c.id} [sample ${String(sample.index)}]: ${turn.error}`);
43
+ }
44
+ }
45
+ }
46
+ const statusWidth = Math.max(0, ...rows.map(([status]) => status.length));
47
+ const idWidth = Math.max(0, ...rows.map(([, id]) => id.length));
48
+ for (const [status, id, reason] of rows) {
49
+ out.push(` ${status.padEnd(statusWidth)} ${id.padEnd(idWidth)} ${reason}`);
50
+ }
51
+ const observation = results.run.observation;
52
+ if (observation !== undefined) {
53
+ const totals = observedTotals(observation.totals, observation.missing, 'turn');
54
+ const all = observation.matched + observation.unmatched;
55
+ out.push(`target logs: ${String(observation.matched)} of ${String(all)} turns matched` +
56
+ (totals === '' ? '' : `; ${totals}`));
57
+ }
58
+ const proxy = results.run.proxy;
59
+ if (proxy !== undefined) {
60
+ const { calls: _calls, ...sums } = proxy.totals;
61
+ const totals = observedTotals(sums, proxy.missing, 'call');
62
+ out.push(`model proxy (${proxy.correlation}): ${counted(proxy.records, 'call')}, ${String(proxy.unattributed)} unattributed` +
63
+ (totals === '' ? '' : `; ${totals}`));
64
+ }
65
+ const spans = results.run.spans;
66
+ if (spans !== undefined) {
67
+ const { calls: _calls, ...sums } = spans.totals;
68
+ const totals = observedTotals(sums, spans.missing, 'call');
69
+ out.push(`spans (traceparent): ${counted(spans.received, 'call')}, ${String(spans.unattributed)} unattributed${spans.settled ? '' : ', still coming when the wait ran out'}` +
70
+ (totals === '' ? '' : `; ${totals}`));
71
+ }
72
+ const own = results.run.own;
73
+ if (own !== undefined) {
74
+ out.push(`yokla's own model: ${counted(own.calls, 'call')}, ${String(own.cached)} from the cache; costUsd ${own.costUsd === null ? 'unknown' : String(Math.round(own.costUsd * 1e6) / 1e6)}`);
75
+ }
76
+ const transforms = results.run.transforms;
77
+ if (transforms !== undefined && transforms.length > 0) {
78
+ out.push(`transforms: ${transforms
79
+ .map((transform) => `${transform.kind} (${counted(transform.messages, 'message')})`)
80
+ .join(', ')}`);
81
+ }
82
+ for (const issue of results.run.issues ?? [])
83
+ err.push(` run: ${issue}`);
84
+ return { out, err };
85
+ }
86
+ //# sourceMappingURL=terminal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"terminal.js","sourceRoot":"","sources":["../src/terminal.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,2EAA2E;AAC3E,qDAAqD;AAErD,OAAO,EAAE,aAAa,EAAgB,MAAM,aAAa,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAO3E,MAAM,UAAU,eAAe,CAAC,OAAgB;IAC9C,MAAM,GAAG,GAAa,EAAE,CAAC;IACzB,MAAM,GAAG,GAAa,EAAE,CAAC;IAEzB,MAAM,MAAM,GAAG,aAAa,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE;QAC9C,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;QAC/C,OAAO,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,IAAI,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IACnE,CAAC,CAAC,CAAC;IACH,GAAG,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,WAAW,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACzE,IAAI,OA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AG,CAAC,EAAE,CACpL,CAAC;IACJ,CAAC;IACD,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC;IAC1C,IAAI,UAAU,KAAK,SAAS,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACtD,GAAG,CAAC,IAAI,CACN,eAAe,UAAU;aACtB,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,GAAG,SAAS,CAAC,IAAI,KAAK,OAAO,CAAC,SAAS,CAAC,QAAQ,EAAE,SAAS,CAAC,GAAG,CAAC;aACnF,IAAI,CAAC,IAAI,CAAC,EAAE,CAChB,CAAC;IACJ,CAAC;IACD,KAAK,MAAM,KAAK,IAAI,OAAO,CAAC,GAAG,CAAC,MAAM,IAAI,EAAE;QAAE,GAAG,CAAC,IAAI,CAAC,UAAU,KAAK,EAAE,CAAC,CAAC;IAC1E,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC;AACtB,CAAC"}
package/package.json CHANGED
@@ -1,10 +1,48 @@
1
1
  {
2
2
  "name": "@yokla/report",
3
- "version": "0.0.0",
4
- "description": "Reserved for yokla. The first release is 0.3.0.",
3
+ "version": "0.4.0",
4
+ "description": "Terminal, JUnit XML and HTML reports.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
7
7
  "type": "git",
8
- "url": "git+https://github.com/thebozturk/yokla.git"
8
+ "url": "git+https://github.com/thebozturk/yokla.git",
9
+ "directory": "packages/report"
10
+ },
11
+ "homepage": "https://github.com/thebozturk/yokla#readme",
12
+ "bugs": {
13
+ "url": "https://github.com/thebozturk/yokla/issues"
14
+ },
15
+ "keywords": [
16
+ "yokla",
17
+ "llm",
18
+ "ai-assistant",
19
+ "chatbot",
20
+ "testing",
21
+ "evaluation",
22
+ "end-to-end",
23
+ "junit",
24
+ "html-report"
25
+ ],
26
+ "type": "module",
27
+ "engines": {
28
+ "node": ">=24"
29
+ },
30
+ "exports": {
31
+ ".": {
32
+ "@yokla/source": "./src/index.ts",
33
+ "types": "./dist/index.d.ts",
34
+ "default": "./dist/index.js"
35
+ }
36
+ },
37
+ "files": [
38
+ "dist",
39
+ "!dist/**/*.test.*",
40
+ "src",
41
+ "!src/**/*.test.*",
42
+ "!src/**/__snapshots__"
43
+ ],
44
+ "sideEffects": false,
45
+ "dependencies": {
46
+ "@yokla/core": "0.4.0"
9
47
  }
10
- }
48
+ }
package/src/compare.ts ADDED
@@ -0,0 +1,55 @@
1
+ // The terminal view of a comparison of runs (ADR-0042): each run with its
2
+ // gate verdict, cost and latency, the cases whose status differs, and the
3
+ // cheapest run that passes the gate.
4
+
5
+ import type { Comparison } from '@yokla/core';
6
+
7
+ function usd(value: number | null): string {
8
+ return value === null ? 'cost unknown' : `${value.toFixed(6)} USD`;
9
+ }
10
+
11
+ function ms(value: number | null): string {
12
+ return value === null ? '-' : `${String(Math.round(value))} ms`;
13
+ }
14
+
15
+ export function comparisonText(comparison: Comparison): string[] {
16
+ const out: string[] = [];
17
+ const letters = comparison.runs.map((_run, index) => String.fromCodePoint(65 + index));
18
+ out.push(`${String(comparison.runs.length)} runs compared:`);
19
+ comparison.runs.forEach((run, index) => {
20
+ const statuses = Object.entries(run.statuses)
21
+ .map(([status, count]) => `${status} ${String(count)}`)
22
+ .join(', ');
23
+ out.push(` ${letters[index] ?? '?'} ${run.label} (run ${run.id})`);
24
+ out.push(
25
+ ` gate ${run.gate.verdict}; ${statuses}; ${usd(run.costUsd)}, ${run.costPerTurnUsd === null ? 'per turn unknown' : `${run.costPerTurnUsd.toFixed(6)} USD a turn`}; latency p50 ${ms(run.latencyP50Ms)}, p95 ${ms(run.latencyP95Ms)}`,
26
+ );
27
+ for (const line of [...run.gate.problems, ...run.gate.breaches]) out.push(` - ${line}`);
28
+ });
29
+
30
+ const differing = comparison.cases.filter((c) => c.differs || c.changed);
31
+ if (differing.length === 0) {
32
+ out.push('every case has the same status in every run');
33
+ } else {
34
+ out.push(`${String(differing.length)} cases differ (${letters.join(' / ')}):`);
35
+ const width = Math.max(...differing.map((c) => c.id.length));
36
+ for (const c of differing) {
37
+ const statuses = c.statuses.map((status) => status ?? 'missing').join(' / ');
38
+ out.push(
39
+ ` ${c.id.padEnd(width)} ${statuses}${c.changed ? ' [definition differs: not compared]' : ''}`,
40
+ );
41
+ }
42
+ }
43
+
44
+ if (comparison.cheapest === null) {
45
+ out.push(`cheapest passing run: none named: ${comparison.noCheapest ?? ''}`);
46
+ } else {
47
+ const named = comparison.cheapest.runs.map((id) => {
48
+ const index = comparison.runs.findIndex((run) => run.id === id);
49
+ return `${letters[index] ?? '?'} (${comparison.runs[index]?.label ?? id})`;
50
+ });
51
+ out.push(`cheapest passing run: ${named.join(', ')}, ${usd(comparison.cheapest.costUsd)}`);
52
+ }
53
+ for (const notice of comparison.notices) out.push(`note: ${notice}`);
54
+ return out;
55
+ }
package/src/format.ts ADDED
@@ -0,0 +1,73 @@
1
+ import type { FindingOrigin } from '@yokla/core';
2
+
3
+ // Number formatting the reports share. It never depends on the locale, so the
4
+ // same results give the same report everywhere (ADR-0023).
5
+
6
+ export function counted(count: number, noun: string): string {
7
+ return `${String(count)} ${noun}${count === 1 ? '' : 's'}`;
8
+ }
9
+
10
+ /** At most six decimals: enough for a cost in USD. */
11
+ export function round(value: number): string {
12
+ return String(Math.round(value * 1e6) / 1e6);
13
+ }
14
+
15
+ /** "costUsd 0.0123 (no value on 2 turns), modelCalls 4" */
16
+ export function observedTotals(
17
+ totals: Readonly<Record<string, number>>,
18
+ missing: Readonly<Record<string, number>>,
19
+ noun: string,
20
+ ): string {
21
+ const names = [...new Set([...Object.keys(totals), ...Object.keys(missing)])];
22
+ return names
23
+ .map((name) => {
24
+ const total = totals[name];
25
+ const gap = missing[name];
26
+ const value = total === undefined ? '' : round(total);
27
+ if (gap === undefined) return `${name} ${value}`;
28
+ if (total === undefined) return `${name} no value on ${counted(gap, noun)}`;
29
+ return `${name} ${value} (no value on ${counted(gap, noun)})`;
30
+ })
31
+ .join(', ');
32
+ }
33
+
34
+ /** " (a, b)", or nothing for no parts. */
35
+ function detail(parts: readonly string[]): string {
36
+ return parts.length === 0 ? '' : ` (${parts.join(', ')})`;
37
+ }
38
+
39
+ /**
40
+ * Where a finding's value came from, in words (ADR-0033): "origin: what the
41
+ * model was sent (call 2, tool search_products)". Calls count from 1 here.
42
+ */
43
+ export function originText(origin: FindingOrigin): string {
44
+ const call = origin.call === undefined ? [] : [`call ${String(origin.call + 1)}`];
45
+ const number = origin.match === 'number' ? ['as a bare number'] : [];
46
+ switch (origin.stage) {
47
+ case 'input': {
48
+ const where =
49
+ origin.tool === undefined
50
+ ? origin.role === undefined
51
+ ? []
52
+ : [`${origin.role} message`]
53
+ : [`tool ${origin.tool}`];
54
+ return `origin: what the model was sent${detail([...call, ...where, ...number])}`;
55
+ }
56
+ case 'model':
57
+ return `origin: the model${detail([...call, ...number])}`;
58
+ case 'app':
59
+ return `origin: the app${detail(origin.reason === undefined ? [] : [origin.reason])}`;
60
+ case 'unknown':
61
+ return `origin: unknown${detail([...(origin.reason === undefined ? [] : [origin.reason]), ...call])}`;
62
+ }
63
+ }
64
+
65
+ /** A finding's message, with its origin when it has one (ADR-0033). */
66
+ export function withOrigin(finding: {
67
+ readonly message: string;
68
+ readonly origin?: FindingOrigin | undefined;
69
+ }): string {
70
+ return finding.origin === undefined
71
+ ? finding.message
72
+ : `${finding.message}; ${originText(finding.origin)}`;
73
+ }