@yokla/report 0.0.0-stage → 0.3.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,80 @@
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
+ case 'fixture-missing':
69
+ return problems.errors[0] ?? c.status;
70
+ case 'unmeasured':
71
+ return problems.unmeasured.length > 0
72
+ ? `unmeasured ${problems.unmeasured.join('; ')}`
73
+ : 'no check applied to any turn';
74
+ case 'known-gap':
75
+ return `known gap: ${c.knownGap?.reason ?? 'no reason given'}${c.knownGap?.issue === undefined ? '' : ` (${c.knownGap.issue})`}`;
76
+ case 'gap-closed':
77
+ return 'passes now; remove the known-gap marker and update the baseline';
78
+ }
79
+ }
80
+ //# 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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MAAM,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC;QACzE,OAAO,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC;IACtE,CAAC,CAAC;SACD,IAAI,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC;AAED,0EAA0E;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,CAAC;QACb,KAAK,iBAAiB;YACpB,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC;QACxC,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,CAoFjE"}
@@ -0,0 +1,80 @@
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
+ for (const issue of results.run.issues ?? [])
77
+ err.push(` run: ${issue}`);
78
+ return { out, err };
79
+ }
80
+ //# 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,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,SAAS,KAAK,IAAI,EAAE,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AK,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,6 +1,48 @@
1
1
  {
2
2
  "name": "@yokla/report",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.3.0",
4
+ "description": "Terminal, JUnit XML and HTML reports.",
5
+ "license": "Apache-2.0",
6
+ "repository": {
7
+ "type": "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.3.0"
47
+ }
6
48
  }
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
+ }