@crvouga/atlas 1.5.0 → 1.7.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/CHANGELOG.md +13 -1
- package/docs/extending.md +17 -0
- package/docs/ui.md +25 -1
- package/llms-full.txt +42 -1
- package/package.json +1 -1
- package/packages/visualizer/README.md +28 -0
- package/packages/visualizer/src/evidence/behavior-panel.tsx +10 -16
- package/packages/visualizer/src/evidence/check-detail.tsx +50 -15
- package/packages/visualizer/src/evidence/outcome-summary.tsx +208 -0
- package/packages/visualizer/src/evidence/outcome.test.ts +129 -0
- package/packages/visualizer/src/evidence/outcome.ts +309 -0
- package/packages/visualizer/src/explorer/Explorer.tsx +105 -25
- package/packages/visualizer/src/explorer/RunsView.tsx +173 -35
- package/packages/visualizer/src/explorer/TestDetail.tsx +23 -1
- package/packages/visualizer/src/explorer/catalog.tsx +9 -5
- package/packages/visualizer/src/explorer/search-notes.tsx +74 -0
- package/packages/visualizer/src/explorer/search.ts +19 -6
- package/packages/visualizer/src/find/Finder.tsx +127 -81
- package/packages/visualizer/src/find/behaviors.ts +205 -0
- package/packages/visualizer/src/find/corpus.ts +21 -7
- package/packages/visualizer/src/find/doc-search.ts +66 -0
- package/packages/visualizer/src/find/query.ts +247 -0
- package/packages/visualizer/src/find/rank.ts +195 -47
- package/packages/visualizer/src/find/search.test.ts +322 -0
- package/packages/visualizer/src/find/semantic-search.ts +153 -0
- package/packages/visualizer/src/find/semantic.ts +2 -2
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import type { LayerHeader, LayerRow } from '@crvouga/atlas/reports/evidence-types';
|
|
2
|
+
import type { CheckSlot } from '@crvouga/atlas/reports/evidence-view';
|
|
3
|
+
import type { EvidenceResult } from '@crvouga/atlas/reports/layer-merge';
|
|
4
|
+
import { expect, test } from 'bun:test';
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
chronology,
|
|
8
|
+
failedStep,
|
|
9
|
+
failureNote,
|
|
10
|
+
outcomeHeadline,
|
|
11
|
+
passedAfterFailure,
|
|
12
|
+
phaseOf,
|
|
13
|
+
reachOf,
|
|
14
|
+
recordOf,
|
|
15
|
+
selectedResult,
|
|
16
|
+
sourceLabels,
|
|
17
|
+
type ResultRecord
|
|
18
|
+
} from './outcome';
|
|
19
|
+
|
|
20
|
+
const header = (id: string, at: number, extra: Partial<LayerHeader> = {}): LayerHeader => ({
|
|
21
|
+
id, backend: 'b', producer: 'p', packageDir: null, recordedAtMs: at, sha: null, branch: null, environment: 'desktop-web', runUrl: null,
|
|
22
|
+
parameters: {}, recording: null, live: false, counts: { passed: 0, failed: 0, running: 0, 'not-run': 0 }, execution: id, ...extra
|
|
23
|
+
});
|
|
24
|
+
const row = (status: LayerRow['status']): LayerRow => ({
|
|
25
|
+
kind: 'checks', id: 'x', title: 'X', status, specPath: null, detail: '', measurements: [], testId: null, variant: {}, durationMs: null
|
|
26
|
+
});
|
|
27
|
+
const result = (id: string, status: LayerRow['status'], extra: Partial<LayerHeader> = {}): EvidenceResult => ({
|
|
28
|
+
key: id, slot: 's', layer: header(id, 1, extra), parameters: {}, warning: null, row: row(status)
|
|
29
|
+
});
|
|
30
|
+
const slot = (status: CheckSlot['status'], outcomes: EvidenceResult[]): CheckSlot => ({
|
|
31
|
+
key: 's', id: 'x', title: 'X', specPath: null, status, outcomes, diagnostics: [], latestAtMs: 1, live: false
|
|
32
|
+
});
|
|
33
|
+
const entry = (r: EvidenceResult) => ({ layer: r.layer, row: r.row });
|
|
34
|
+
|
|
35
|
+
test('the heading names the selected outcome before the other sources, and never reads it as the combined status', () => {
|
|
36
|
+
const passed = result('a', 'passed');
|
|
37
|
+
const failed = result('b', 'failed', { environment: 'api' });
|
|
38
|
+
const both = slot('failed', [passed, failed]);
|
|
39
|
+
expect(outcomeHeadline(entry(passed), both).text).toBe('Selected result passed; another scoped source failed');
|
|
40
|
+
expect(outcomeHeadline(entry(failed), both).text).toBe('Selected result failed; the other scoped source: 1 passed');
|
|
41
|
+
expect(outcomeHeadline(entry(passed), slot('passed', [passed])).text).toBe('Selected result passed');
|
|
42
|
+
expect(outcomeHeadline(entry(result('c', 'running')), slot('running', [result('c', 'running')])).text).toBe('Selected result is still running');
|
|
43
|
+
expect(outcomeHeadline(entry(passed), slot('failed', [passed, failed, result('d', 'failed')])).text).toContain('2 other scoped sources failed');
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test('an earlier result says so and names what the combined report now shows', () => {
|
|
47
|
+
const current = result('new', 'passed');
|
|
48
|
+
const old = result('old', 'failed');
|
|
49
|
+
const headline = outcomeHeadline(entry(old), slot('passed', [current]));
|
|
50
|
+
expect(headline.current).toBe(false);
|
|
51
|
+
expect(headline.text).toBe('This earlier result failed; the combined report now shows passed across its current source');
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test('the selected result is the pinned run, else the named source, else the newest', () => {
|
|
55
|
+
const a = result('a', 'passed');
|
|
56
|
+
const b = result('b', 'failed');
|
|
57
|
+
const both = slot('failed', [a, b]);
|
|
58
|
+
expect(selectedResult(both)?.layer.id).toBe('a');
|
|
59
|
+
expect(selectedResult(both, undefined, 'b')?.layer.id).toBe('b');
|
|
60
|
+
expect(selectedResult(both, undefined, 'unknown')?.layer.id).toBe('a');
|
|
61
|
+
expect(selectedResult(both, entry(b), 'a')?.layer.id).toBe('b');
|
|
62
|
+
expect(selectedResult(slot('passed', []))).toBeUndefined();
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
test('sources that share a name are told apart by status, revision and their place among them', () => {
|
|
66
|
+
const labels = sourceLabels(
|
|
67
|
+
[result('a', 'passed', { sha: 'b'.repeat(40), producer: 'one' }), result('b', 'failed', { sha: 'a'.repeat(40), producer: 'two' }), result('c', 'passed', { environment: 'api' })],
|
|
68
|
+
1_000
|
|
69
|
+
);
|
|
70
|
+
expect(labels.map((label) => label.text)).toEqual([
|
|
71
|
+
'Desktop web · Passed · just now · bbbbbbb · result 1 of 2 from one',
|
|
72
|
+
'Desktop web · Failed · just now · aaaaaaa · result 2 of 2 from two',
|
|
73
|
+
'Api · Passed · just now · revision not recorded'
|
|
74
|
+
]);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test('the phase comes from the recorded kind, never from the wording', () => {
|
|
78
|
+
expect(phaseOf('hook')).toBe('setup');
|
|
79
|
+
expect(phaseOf('Given')).toBe('setup');
|
|
80
|
+
expect(phaseOf('then')).toBe('behavior');
|
|
81
|
+
expect(phaseOf('action')).toBe('unspecified');
|
|
82
|
+
expect(phaseOf(undefined)).toBe('unspecified');
|
|
83
|
+
const point = failedStep([{ name: 'setup failed to connect', status: 'failed', offsetMs: 0 }]);
|
|
84
|
+
expect(point?.phase).toBe('unspecified');
|
|
85
|
+
expect(reachOf(point).state).toBe('unknown');
|
|
86
|
+
expect(reachOf(undefined).state).toBe('unknown');
|
|
87
|
+
expect(reachOf(failedStep([{ name: 'Seed', kind: 'hook', status: 'failed' }])).state).toBe('setup-failed');
|
|
88
|
+
expect(reachOf(failedStep([{ name: 'Check', kind: 'assertion', status: 'failed' }])).state).toBe('expectation-failed');
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
test('the failed step is the first innermost one in time order', () => {
|
|
92
|
+
const point = failedStep([
|
|
93
|
+
{ id: 'late', name: 'Late', status: 'failed', offsetMs: 900 },
|
|
94
|
+
{ id: 'group', name: 'Group', status: 'failed', offsetMs: 100 },
|
|
95
|
+
{ id: 'leaf', parentId: 'group', name: 'Leaf', status: 'failed', offsetMs: 150, detail: 'nope' },
|
|
96
|
+
{ name: 'Fine', status: 'passed', offsetMs: 0 }
|
|
97
|
+
]);
|
|
98
|
+
expect(point?.name).toBe('Leaf');
|
|
99
|
+
expect(point?.detail).toBe('nope');
|
|
100
|
+
expect(failedStep([{ name: 'ok', status: 'passed' }])).toBeUndefined();
|
|
101
|
+
expect(failedStep(undefined)).toBeUndefined();
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
test('only a producer-declared failure is read, and only a known attribution counts', () => {
|
|
105
|
+
expect(failureNote({ 'atlas.failure': { expected: 200, actual: { status: 500 }, attribution: 'environment' } })).toEqual({
|
|
106
|
+
expected: '200',
|
|
107
|
+
actual: '{"status":500}',
|
|
108
|
+
attribution: 'environment'
|
|
109
|
+
});
|
|
110
|
+
expect(failureNote({ 'atlas.failure': { attribution: 'the intern' } })).toBeUndefined();
|
|
111
|
+
expect(failureNote({ other: {} })).toBeUndefined();
|
|
112
|
+
expect(failureNote(undefined)).toBeUndefined();
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
test('a chronology is only told for one source whose outcome changed, oldest first, without declaring a cause', () => {
|
|
116
|
+
const record = (layer: string, status: ResultRecord['status'], at: number, env: string | null = 'desktop-web'): ResultRecord => ({
|
|
117
|
+
...recordOf(entry(result(layer, status, { environment: env, recordedAtMs: at }))),
|
|
118
|
+
at
|
|
119
|
+
});
|
|
120
|
+
const early = record('1', 'failed', 100);
|
|
121
|
+
const late = record('2', 'passed', 200);
|
|
122
|
+
const timeline = chronology(late, [late, early, record('3', 'passed', 150, 'api')]);
|
|
123
|
+
expect(timeline.map((each) => each.record.layer)).toEqual(['1', '2']);
|
|
124
|
+
expect(timeline[1]!.selected).toBe(true);
|
|
125
|
+
expect(passedAfterFailure(timeline)).toBe(true);
|
|
126
|
+
expect(passedAfterFailure(chronology(early, [early, late]).slice().reverse())).toBe(false);
|
|
127
|
+
expect(chronology(late, [late])).toEqual([]);
|
|
128
|
+
expect(chronology(late, [late, record('4', 'passed', 50)])).toEqual([]);
|
|
129
|
+
});
|
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Outcome explanation
|
|
3
|
+
*
|
|
4
|
+
* Pure reading of what one selected result says, set beside everything else recorded for the same check, so a
|
|
5
|
+
* detail never leads with a summary that contradicts its evidence. The selected source's outcome, the other current
|
|
6
|
+
* sources, where a failure happened, whether the behavior was reached, and the chronology of one source are all
|
|
7
|
+
* stated separately. Nothing here changes a status or a winner: it only words what was recorded, and anything that
|
|
8
|
+
* was not recorded stays unknown. In particular a failure is never attributed to the product, the test harness or
|
|
9
|
+
* the environment from the wording of its message; only a producer's own `atlas.failure` declaration is shown.
|
|
10
|
+
*/
|
|
11
|
+
import type { HistoryEntry, CheckSlot } from '@crvouga/atlas/reports/evidence-view';
|
|
12
|
+
import { isVideoAttachment, type EvidenceHolder } from '@crvouga/atlas/reports/evidence-detail';
|
|
13
|
+
import { environmentLabel } from '@crvouga/atlas/reports/layer-axes';
|
|
14
|
+
import type { EvidenceResult } from '@crvouga/atlas/reports/layer-merge';
|
|
15
|
+
import type { ReportStep, RunReport } from '@crvouga/atlas/reports/report-types';
|
|
16
|
+
import type { Attachment, Step } from '@crvouga/atlas/schema';
|
|
17
|
+
import { ago, shortSha, statusWord } from './format';
|
|
18
|
+
|
|
19
|
+
/** The extension key under which a producer may declare why and where a check failed. */
|
|
20
|
+
export const FAILURE_EXTENSION = 'atlas.failure';
|
|
21
|
+
|
|
22
|
+
/** Who a producer declared a failure to be the fault of. Absent is unknown, never inferred. */
|
|
23
|
+
export type Attribution = 'product' | 'test-harness' | 'environment';
|
|
24
|
+
|
|
25
|
+
const ATTRIBUTIONS: readonly string[] = ['product', 'test-harness', 'environment'];
|
|
26
|
+
|
|
27
|
+
/** What a producer declared about a failure: the expectation, what was observed, and optionally whose fault it was. */
|
|
28
|
+
export type FailureNote = {
|
|
29
|
+
readonly expected?: string;
|
|
30
|
+
readonly actual?: string;
|
|
31
|
+
readonly attribution?: Attribution;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/** Whether the failed step belongs to getting ready for the behavior, to the behavior itself, or is not known to be either. */
|
|
35
|
+
export type Phase = 'setup' | 'behavior' | 'unspecified';
|
|
36
|
+
|
|
37
|
+
/** Step kinds (an open vocabulary) that are preparation, not the behavior under test. */
|
|
38
|
+
const SETUP_KINDS = new Set(['hook', 'setup', 'fixture', 'before', 'beforeall', 'beforeeach', 'given']);
|
|
39
|
+
/** Step kinds that are the behavior being exercised or an expectation about it. */
|
|
40
|
+
const BEHAVIOR_KINDS = new Set(['when', 'then', 'assertion', 'expect']);
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Which phase a step of this `kind` belongs to. Decided by the recorded kind only, never by a step's name or message;
|
|
44
|
+
* a kind that is not recognized, or none, is `unspecified`.
|
|
45
|
+
*/
|
|
46
|
+
export function phaseOf(kind: string | undefined): Phase {
|
|
47
|
+
const key = kind?.toLowerCase();
|
|
48
|
+
if (!key) return 'unspecified';
|
|
49
|
+
return SETUP_KINDS.has(key) ? 'setup' : BEHAVIOR_KINDS.has(key) ? 'behavior' : 'unspecified';
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** The step at which a result failed, as far as the recording says. */
|
|
53
|
+
export type FailurePoint = {
|
|
54
|
+
readonly name: string;
|
|
55
|
+
readonly kind: string | undefined;
|
|
56
|
+
readonly phase: Phase;
|
|
57
|
+
/** The step's own message, as recorded. */
|
|
58
|
+
readonly detail: string | undefined;
|
|
59
|
+
/** How long after the check started it began, when recorded. */
|
|
60
|
+
readonly offsetMs: number | undefined;
|
|
61
|
+
readonly note: FailureNote | undefined;
|
|
62
|
+
/** The videos on the step itself, if it has any. */
|
|
63
|
+
readonly videos: readonly Attachment[];
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
function text(value: unknown): string | undefined {
|
|
67
|
+
if (value === undefined || value === null) return undefined;
|
|
68
|
+
if (typeof value === 'string') return value;
|
|
69
|
+
if (typeof value === 'number' || typeof value === 'boolean') return String(value);
|
|
70
|
+
return JSON.stringify(value);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* The failure a producer declared under {@link FAILURE_EXTENSION} in `extensions`: `expected`, `actual` and an
|
|
75
|
+
* `attribution` of `product`, `test-harness` or `environment`. Anything else is ignored; undefined when nothing usable is there.
|
|
76
|
+
*/
|
|
77
|
+
export function failureNote(extensions: Readonly<Record<string, unknown>> | undefined): FailureNote | undefined {
|
|
78
|
+
const raw = extensions?.[FAILURE_EXTENSION];
|
|
79
|
+
if (!raw || typeof raw !== 'object' || Array.isArray(raw)) return undefined;
|
|
80
|
+
const { expected, actual, attribution } = raw as Record<string, unknown>;
|
|
81
|
+
const note: { expected?: string; actual?: string; attribution?: Attribution } = {};
|
|
82
|
+
const e = text(expected);
|
|
83
|
+
const a = text(actual);
|
|
84
|
+
if (e !== undefined) note.expected = e;
|
|
85
|
+
if (a !== undefined) note.actual = a;
|
|
86
|
+
if (typeof attribution === 'string' && ATTRIBUTIONS.includes(attribution)) note.attribution = attribution as Attribution;
|
|
87
|
+
return Object.keys(note).length ? note : undefined;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* The first failed step of a recorded check, preferring the innermost one (a failed action inside a failed group is
|
|
92
|
+
* the action). Steps are ordered by their start offset, else by their position. Undefined when no step failed or none
|
|
93
|
+
* was recorded.
|
|
94
|
+
*/
|
|
95
|
+
export function failedStep(steps: readonly Step[] | undefined): FailurePoint | undefined {
|
|
96
|
+
if (!steps?.length) return undefined;
|
|
97
|
+
const failedParents = new Set(steps.filter((step) => step.status === 'failed' && step.parentId).map((step) => step.parentId));
|
|
98
|
+
const order = steps.map((step, index) => ({ step, index }));
|
|
99
|
+
order.sort((a, b) => (a.step.offsetMs ?? 0) - (b.step.offsetMs ?? 0) || a.index - b.index);
|
|
100
|
+
const found = order.find(({ step }) => step.status === 'failed' && !(step.id !== undefined && failedParents.has(step.id)))?.step;
|
|
101
|
+
if (!found) return undefined;
|
|
102
|
+
return {
|
|
103
|
+
name: found.name,
|
|
104
|
+
kind: found.kind,
|
|
105
|
+
phase: phaseOf(found.kind),
|
|
106
|
+
detail: found.detail,
|
|
107
|
+
offsetMs: found.offsetMs,
|
|
108
|
+
note: failureNote(found.extensions),
|
|
109
|
+
videos: (found.attachments ?? []).filter(isVideoAttachment)
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** The first innermost failed step of an Atlas run's own timeline (see {@link failedStep}). */
|
|
114
|
+
export function failedReportStep(report: RunReport | undefined): FailurePoint | undefined {
|
|
115
|
+
if (!report) return undefined;
|
|
116
|
+
const walk = (steps: readonly ReportStep[]): ReportStep | undefined => {
|
|
117
|
+
for (const step of steps) {
|
|
118
|
+
if (step.status !== 'failed') continue;
|
|
119
|
+
return walk(step.steps) ?? step;
|
|
120
|
+
}
|
|
121
|
+
return undefined;
|
|
122
|
+
};
|
|
123
|
+
const found = walk(report.steps);
|
|
124
|
+
if (!found) return undefined;
|
|
125
|
+
return {
|
|
126
|
+
name: found.title,
|
|
127
|
+
kind: found.kind,
|
|
128
|
+
phase: phaseOf(found.kind),
|
|
129
|
+
detail: found.error,
|
|
130
|
+
offsetMs: Math.max(0, found.startedAtMs - report.meta.startedAtMs),
|
|
131
|
+
note: undefined,
|
|
132
|
+
videos: []
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** The recorded videos a holder carries on itself, its steps and its attempts. */
|
|
137
|
+
export function videosIn(holder: EvidenceHolder | undefined): Attachment[] {
|
|
138
|
+
if (!holder) return [];
|
|
139
|
+
return [
|
|
140
|
+
...(holder.attachments ?? []).filter(isVideoAttachment),
|
|
141
|
+
...(holder.steps ?? []).flatMap((step) => (step.attachments ?? []).filter(isVideoAttachment)),
|
|
142
|
+
...(holder.attempts ?? []).flatMap((attempt) => [
|
|
143
|
+
...(attempt.attachments ?? []).filter(isVideoAttachment),
|
|
144
|
+
...(attempt.steps ?? []).flatMap((step) => (step.attachments ?? []).filter(isVideoAttachment))
|
|
145
|
+
])
|
|
146
|
+
];
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** The one-line statement of what the failure point says about the behavior. */
|
|
150
|
+
export function reachOf(point: FailurePoint | undefined): { readonly state: 'setup-failed' | 'expectation-failed' | 'unknown'; readonly text: string } {
|
|
151
|
+
if (!point) return { state: 'unknown', text: 'Where it failed was not recorded, so whether the behavior was reached is unknown.' };
|
|
152
|
+
if (point.phase === 'setup')
|
|
153
|
+
return { state: 'setup-failed', text: `Behavior not verified: setup failed at “${point.name}”. The execution is still recorded as failed.` };
|
|
154
|
+
if (point.phase === 'behavior')
|
|
155
|
+
return { state: 'expectation-failed', text: `The behavior was reached and an expectation was not met at “${point.name}”.` };
|
|
156
|
+
return { state: 'unknown', text: `Failed at “${point.name}”. Whether the behavior was reached is not recorded.` };
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const WORD = { passed: 'passed', failed: 'failed', running: 'is still running', 'not-run': 'was not run' } as const;
|
|
160
|
+
|
|
161
|
+
/** Counts of results by status, in words: `1 passed, 2 failed`. */
|
|
162
|
+
function tally(results: readonly EvidenceResult[]): string {
|
|
163
|
+
const counts = new Map<string, number>();
|
|
164
|
+
for (const { row } of results) counts.set(row.status, (counts.get(row.status) ?? 0) + 1);
|
|
165
|
+
return (['passed', 'failed', 'running', 'not-run'] as const)
|
|
166
|
+
.filter((status) => counts.has(status))
|
|
167
|
+
.map((status) => `${counts.get(status)} ${status === 'not-run' ? 'not run' : status}`)
|
|
168
|
+
.join(', ');
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/** What the selected result says, and the current results of the other sources it must be read beside. */
|
|
172
|
+
export type Headline = {
|
|
173
|
+
readonly text: string;
|
|
174
|
+
/** The current results from other sources than the selected one, newest first. */
|
|
175
|
+
readonly others: readonly EvidenceResult[];
|
|
176
|
+
/** False when the selected result is an earlier one that a newer run has replaced in the combined report. */
|
|
177
|
+
readonly current: boolean;
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* The heading for a selected result: its own outcome first, then what the other current sources recorded. A passing
|
|
182
|
+
* selection beside a failing source says both; an earlier result says it is earlier and names the combined status.
|
|
183
|
+
* Never reads the selected outcome as the check's status.
|
|
184
|
+
*/
|
|
185
|
+
export function outcomeHeadline(selected: HistoryEntry, slot: CheckSlot): Headline {
|
|
186
|
+
const current = slot.outcomes.some((outcome) => outcome.layer.id === selected.layer.id);
|
|
187
|
+
const others = slot.outcomes.filter((outcome) => outcome.layer.id !== selected.layer.id);
|
|
188
|
+
const own = WORD[selected.row.status];
|
|
189
|
+
if (!current) {
|
|
190
|
+
return {
|
|
191
|
+
current,
|
|
192
|
+
others,
|
|
193
|
+
text: `This earlier result ${own}; the combined report now shows ${statusWord(slot.status).toLowerCase()} across ${others.length === 1 ? 'its current source' : `its ${others.length} current sources`}`
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
const failed = others.filter((outcome) => outcome.row.status === 'failed').length;
|
|
197
|
+
let text = `Selected result ${own}`;
|
|
198
|
+
if (selected.row.status === 'passed' && failed > 0) text += `; ${failed === 1 ? 'another scoped source' : `${failed} other scoped sources`} failed`;
|
|
199
|
+
else if (others.length > 0) text += `; ${others.length === 1 ? 'the other scoped source' : 'other scoped sources'}: ${tally(others)}`;
|
|
200
|
+
return { current, others, text };
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* The result a detail shows: the run the address pins, else the current result of the source it names, else the newest.
|
|
205
|
+
* Undefined only for a check with no result.
|
|
206
|
+
*/
|
|
207
|
+
export function selectedResult(slot: CheckSlot, pinned?: HistoryEntry, source?: string): HistoryEntry | undefined {
|
|
208
|
+
if (pinned) return pinned;
|
|
209
|
+
const found = (source ? slot.outcomes.find((outcome) => outcome.layer.id === source) : undefined) ?? slot.outcomes[0];
|
|
210
|
+
return found ? { layer: found.layer, row: found.row } : undefined;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/** How a choosable source is told apart from its siblings without reading opaque producer ids. */
|
|
214
|
+
export type SourceLabel = {
|
|
215
|
+
/** The environment and parameters, or the producer when neither is named. */
|
|
216
|
+
readonly name: string;
|
|
217
|
+
/** Status in words. */
|
|
218
|
+
readonly status: string;
|
|
219
|
+
/** When it was recorded, relative. */
|
|
220
|
+
readonly when: string;
|
|
221
|
+
/** The commit, or the branch, or `revision not recorded`. */
|
|
222
|
+
readonly revision: string;
|
|
223
|
+
/** Present when other sources share the same name: its place among them, newest first, and its producer. */
|
|
224
|
+
readonly attempt: string | undefined;
|
|
225
|
+
/** All of the above in one line. */
|
|
226
|
+
readonly text: string;
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Labels for the current results of a check so each can be told from the others by status, time, revision and,
|
|
231
|
+
* when several share a name, its place among them. `now` is epoch milliseconds.
|
|
232
|
+
*/
|
|
233
|
+
export function sourceLabels(outcomes: readonly EvidenceResult[], now: number): SourceLabel[] {
|
|
234
|
+
const names = outcomes.map((outcome) => {
|
|
235
|
+
const environment = outcome.layer.environment ? environmentLabel(outcome.layer.environment) : '';
|
|
236
|
+
const parameters = Object.entries(outcome.parameters)
|
|
237
|
+
.map(([name, value]) => `${name}: ${value}`)
|
|
238
|
+
.join(', ');
|
|
239
|
+
return [environment, parameters].filter(Boolean).join(' · ') || outcome.layer.producer;
|
|
240
|
+
});
|
|
241
|
+
return outcomes.map((outcome, index) => {
|
|
242
|
+
const name = names[index]!;
|
|
243
|
+
const siblings = names.flatMap((each, at) => (each === name ? [at] : []));
|
|
244
|
+
const attempt =
|
|
245
|
+
siblings.length > 1 ? `result ${siblings.indexOf(index) + 1} of ${siblings.length} from ${outcome.layer.producer}` : undefined;
|
|
246
|
+
const revision = shortSha(outcome.layer.sha) ?? outcome.layer.branch ?? 'revision not recorded';
|
|
247
|
+
const status = statusWord(outcome.row.status);
|
|
248
|
+
const when = ago(outcome.layer.recordedAtMs, now);
|
|
249
|
+
return { name, status, when, revision, attempt, text: [name, status, when, revision, attempt].filter(Boolean).join(' · ') };
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/** What the chronology needs to know of one recorded result, whether it came from the held layers or from a test's history. */
|
|
254
|
+
export type ResultRecord = {
|
|
255
|
+
/** The id of the layer that recorded it. */
|
|
256
|
+
readonly layer: string;
|
|
257
|
+
readonly kind: string;
|
|
258
|
+
readonly status: HistoryEntry['row']['status'];
|
|
259
|
+
readonly at: number;
|
|
260
|
+
readonly sha: string | null;
|
|
261
|
+
readonly producer: string;
|
|
262
|
+
readonly environment: string | null;
|
|
263
|
+
readonly parameters: Readonly<Record<string, string>>;
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
/** The record of a layer's result. */
|
|
267
|
+
export function recordOf(entry: HistoryEntry): ResultRecord {
|
|
268
|
+
const { layer, row } = entry;
|
|
269
|
+
return {
|
|
270
|
+
layer: layer.id,
|
|
271
|
+
kind: row.kind,
|
|
272
|
+
status: row.status,
|
|
273
|
+
at: layer.recordedAtMs,
|
|
274
|
+
sha: layer.sha,
|
|
275
|
+
producer: layer.producer,
|
|
276
|
+
environment: layer.environment,
|
|
277
|
+
parameters: layer.parameters
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/** One record of the selected result's own source, for the chronology. */
|
|
282
|
+
export type ChronologyEntry = { readonly record: ResultRecord; readonly selected: boolean };
|
|
283
|
+
|
|
284
|
+
function samePlace(a: ResultRecord, b: ResultRecord): boolean {
|
|
285
|
+
return (
|
|
286
|
+
a.producer === b.producer &&
|
|
287
|
+
a.environment === b.environment &&
|
|
288
|
+
JSON.stringify(Object.entries(a.parameters).sort()) === JSON.stringify(Object.entries(b.parameters).sort())
|
|
289
|
+
);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* The records of the selected result's own source (same producer, environment and parameters), oldest first, one per
|
|
294
|
+
* layer. Empty when there is only one, or when they all have the same outcome, so there is no chronology to tell.
|
|
295
|
+
*/
|
|
296
|
+
export function chronology(selected: ResultRecord, history: readonly ResultRecord[]): ChronologyEntry[] {
|
|
297
|
+
const seen = new Set<string>();
|
|
298
|
+
const own = history
|
|
299
|
+
.filter((record) => samePlace(record, selected) && !seen.has(`${record.layer}|${record.kind}`) && seen.add(`${record.layer}|${record.kind}`))
|
|
300
|
+
.sort((a, b) => a.at - b.at);
|
|
301
|
+
if (own.length < 2 || new Set(own.map((record) => record.status)).size < 2) return [];
|
|
302
|
+
return own.map((record) => ({ record, selected: record.layer === selected.layer && record.kind === selected.kind }));
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/** Whether the newest record of a chronology passed after an earlier one failed. */
|
|
306
|
+
export function passedAfterFailure(entries: readonly ChronologyEntry[]): boolean {
|
|
307
|
+
const last = entries.at(-1);
|
|
308
|
+
return last !== undefined && last.record.status === 'passed' && entries.slice(0, -1).some((each) => each.record.status === 'failed');
|
|
309
|
+
}
|