@ihyeon/error-to-test 0.1.13 → 0.1.15
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.ko.md +33 -0
- package/README.md +39 -0
- package/dist/analysis.d.ts +1 -0
- package/dist/analysis.js +46 -6
- package/dist/artifacts.d.ts +1 -0
- package/dist/artifacts.js +15 -4
- package/dist/cli.js +58 -6
- package/dist/comparison.d.ts +38 -0
- package/dist/comparison.js +198 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/types.d.ts +10 -0
- package/package.json +1 -1
package/README.ko.md
CHANGED
|
@@ -44,6 +44,39 @@ error-to-test analyze --input errors.json --min-count 3 --top 10 --out ./recurri
|
|
|
44
44
|
|
|
45
45
|
JavaScript API에서는 `analyzeErrors(content, { minCount: 3, top: 10 })`으로 같은 기준을 적용합니다.
|
|
46
46
|
|
|
47
|
+
두 분석 결과는 `compare`로 비교할 수 있습니다. 릴리스가 바뀐 뒤 어떤 오류 서명이 다시 관측됐는지 확인할 때 사용합니다.
|
|
48
|
+
|
|
49
|
+
```sh
|
|
50
|
+
error-to-test analyze --input before-errors.json --release r1 --out ./before
|
|
51
|
+
error-to-test analyze --input current-errors.json --release r2 --out ./current
|
|
52
|
+
error-to-test compare ./before ./current
|
|
53
|
+
error-to-test compare ./before ./current --format json --out ./comparison.json
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
현재에만 있는 서명(`only-current`), 양쪽에 있는 서명(`both`), 이전에만 있는 서명(`only-baseline`)으로 나누고 제공된 로그 건수와 증감을 보여줍니다. 릴리스만 제외하고 프로젝트·환경·실행 환경·오류 유형·페이지 경로·전체 오류 서명이 일치해야 합니다. 메시지나 소스 위치가 바뀌면 별도 서명이며, 비슷한 문장을 같은 원인으로 추정하지 않습니다.
|
|
57
|
+
|
|
58
|
+
TC 생성 대상에서 제외된 묶음도 모두 비교합니다. 한쪽에 여러 릴리스가 있으면 같은 비교 키의 건수를 합산하고 원래 묶음 ID·릴리스 목록을 남깁니다. 단일 릴리스끼리 비교하려면 먼저 `analyze --release`로 범위를 정하세요. 페이지 조회 수는 합산하지 않습니다.
|
|
59
|
+
|
|
60
|
+
이전에만 관측됐다는 표시가 수정 완료를 의미하지 않습니다. 건수는 입력에 포함된 이벤트·보고서 수이며, 발생률이나 영향 사용자 수가 아닙니다. 양쪽의 부분 내보내기·기간·필터·수집 범위와 경고도 표시합니다. 수집 이벤트 건수와 수동 제출 보고서 건수의 비교는 거부합니다. 수동 JSON과 텍스트는 같은 제출 보고서 기준으로 비교하되 형식 차이를 알립니다.
|
|
61
|
+
|
|
62
|
+
양쪽 번들을 검증한 뒤 읽으며 원래 산출물·TC 상태·검토 조건·연결 결과는 수정하지 않습니다. 기본 출력은 Markdown이고, `--format json`은 `error-to-test/comparison-1`을 반환합니다. `--out`은 양쪽 번들의 `results` 폴더 밖에 있는 새 파일만 허용합니다. API는 `compareBundles()`와 `renderComparison()`입니다.
|
|
63
|
+
|
|
64
|
+
`analyze --baseline`을 쓰면 **이전 분석에서 관측되지 않은 서명만 골라 TC를 생성**할 수 있습니다.
|
|
65
|
+
|
|
66
|
+
```sh
|
|
67
|
+
error-to-test analyze --input before-errors.json --out ./before
|
|
68
|
+
error-to-test analyze --input current-errors.json --baseline ./before --min-count 3 --top 10 --out ./new-signature-tcs
|
|
69
|
+
error-to-test init-profile ./new-signature-tcs --out ./new-signature-profile.json
|
|
70
|
+
# 확인한 요구사항·준비 조건·동작·assertion으로 프로필 수정
|
|
71
|
+
error-to-test analyze --input current-errors.json --baseline ./before --min-count 3 --top 10 --profile ./new-signature-profile.json --out ./reviewed-new-signatures
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
`compare`와 같은 기준으로 릴리스만 제외한 전체 서명을 비교합니다. 이전 분석에서 TC 생성 대상이 아니었던 묶음도 비교에 포함합니다. 이전에 없던 현재 묶음을 먼저 고른 뒤 `--min-count`, `--top`을 적용하므로 순위가 높은 기존 오류 때문에 새 서명의 TC가 밀려나지 않습니다. 최소 건수는 현재의 각 묶음별로 적용하며 서로 다른 릴리스의 건수를 합치지 않습니다. 현재의 전체 묶음·원본 해시·수집 범위는 그대로 남습니다. 선택할 후보가 없으면 suite 없이 정상 번들을 만듭니다.
|
|
75
|
+
|
|
76
|
+
`analysis.json`의 `selection`과 보고서에 선택 방식(`only-current`), 이전 입력·검증된 분석 파일의 SHA-256, 이전 수집 범위, 선택·제외 묶음 수를 기록합니다. 이 정보도 새 번들의 분석 해시로 검증됩니다. 이전 번들은 한 번 검증해 읽으며 수정하지 않습니다. 이후 이전 번들이 바뀌어도 저장된 선택 결과는 바뀌지 않습니다. 프로필을 보완할 때 같은 이전 번들과 필터를 유지하세요. 맥락 질문과 검토 조건도 계속 적용하며, `--reviewed`는 검토 확인만 처리합니다.
|
|
77
|
+
|
|
78
|
+
이전에 없었다는 표시가 새로 유입된 버그나 회귀를 확정하지는 않습니다. 부분 내보내기·기간·수집 범위 차이 등 비교 경고를 유지하고, 수집 이벤트와 수동 제출 보고서를 섞으면 거부합니다. 출력은 이전 번들의 `results` 폴더 밖에 있는 새 디렉터리만 허용합니다. API는 `await analyzeWithBaseline(content, baselineDirectory, { minCount: 3, top: 10, profile })`이며 이전 번들 검증도 수행합니다.
|
|
79
|
+
|
|
47
80
|
`report.md` 상단에서 TC 초안 수와 추가 정보가 필요한 TC 수를 확인할 수 있습니다. 초안도 실행 전에 검토해야 합니다. 오류 묶음·수집 건수와 함께 대표 로그의 오류·React 컴포넌트 스택, 재현 방법·사전 조건·테스트 단계·부족한 정보도 표시합니다. 같은 스택은 한 번만 표시하며, 전체 로그의 모든 스택을 나열하지는 않습니다. 재현 단계와 정상 기대 결과, 명시적인 assertion이 없으면 질문이 있는 TC를 생성합니다. 직접 입력한 보고서에는 실제 발생 시각·사용자 수를 만들어 넣지 않습니다. 수집 건수도 실제 발생률을 뜻하지 않으며, 원본 내보내기의 일부 데이터 표시를 유지합니다.
|
|
48
81
|
|
|
49
82
|
기본 suite는 검토 질문으로 실행이 차단됩니다. TC와 프로필을 확인한 뒤 다른 출력 폴더에 `--reviewed`로 다시 생성하면 검토 질문만 제거됩니다. 나머지 질문은 그대로 실행을 차단합니다. 프로필의 `setupConfirmed`는 준비 조건을 확인했다는 표시이며, 계정·데이터를 자동으로 준비하는 기능은 아닙니다.
|
package/README.md
CHANGED
|
@@ -67,6 +67,45 @@ Use `--min-count N` (1..10,000; default 1) to generate TCs only for groups with
|
|
|
67
67
|
error-to-test analyze --input errors.json --min-count 3 --top 10 --out ./recurring-errors
|
|
68
68
|
```
|
|
69
69
|
|
|
70
|
+
### Compare two analyses
|
|
71
|
+
|
|
72
|
+
Compare verified snapshots, including snapshots from different releases:
|
|
73
|
+
|
|
74
|
+
```sh
|
|
75
|
+
error-to-test analyze --input before-errors.json --release r1 --out ./before
|
|
76
|
+
error-to-test analyze --input current-errors.json --release r2 --out ./current
|
|
77
|
+
error-to-test compare ./before ./current
|
|
78
|
+
error-to-test compare ./before ./current --format json --out ./comparison.json
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Each signature is classified as `only-current`, `both`, or `only-baseline`, with supplied record counts on both sides and their difference. Matching keeps project, environment, runtime, error type, page path, and the complete fingerprint-v1 signature; only release is excluded. Changes to messages or source locations remain separate signatures. This comparison does not infer a common root cause from similar text.
|
|
82
|
+
|
|
83
|
+
All source groups participate, including groups excluded from TC generation by `--top` or `--min-count`. Multiple release groups with the same comparison key are aggregated on each side, with their original group IDs and release labels preserved. Use `analyze --release` first when you want one release per side. View counts are not summed or compared.
|
|
84
|
+
|
|
85
|
+
`only-baseline` means absent from the supplied current snapshot, not fixed. Counts are supplied records, not error rates or affected users. Each side's coverage, filters, partial-export flag, unknown retention, and analysis warnings remain visible. Different collection windows or scopes can explain differences; comparisons between captured-event counts and submitted-report counts are rejected. Manual JSON and text both count submitted reports and can be compared, with a format-difference warning.
|
|
86
|
+
|
|
87
|
+
Both bundles must pass consistency verification. The command reads their verified snapshots without editing artifacts, TC states, review gates, or linked results. Markdown is the default; `--format json` returns `error-to-test/comparison-1`. `--out` requires a new file outside either bundle's `results` directory. The API equivalents are `await compareBundles(baselineDirectory, currentDirectory)` and `renderComparison(comparison)`.
|
|
88
|
+
|
|
89
|
+
### Generate TCs for signatures absent from a baseline
|
|
90
|
+
|
|
91
|
+
Pass a verified analysis bundle to `analyze --baseline` to focus TC generation on current signatures that were not observed in that baseline:
|
|
92
|
+
|
|
93
|
+
```sh
|
|
94
|
+
error-to-test analyze --input before-errors.json --out ./before
|
|
95
|
+
error-to-test analyze --input current-errors.json --baseline ./before --min-count 3 --top 10 --out ./new-signature-tcs
|
|
96
|
+
error-to-test init-profile ./new-signature-tcs --out ./new-signature-profile.json
|
|
97
|
+
# Fill the profile with confirmed requirements, setup, actions, and assertions.
|
|
98
|
+
error-to-test analyze --input current-errors.json --baseline ./before --min-count 3 --top 10 --profile ./new-signature-profile.json --out ./reviewed-new-signatures
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
The filter uses the same exact identity as `compare`, excluding release only. Every baseline group participates, even one excluded from its TC selection. Current groups absent from the baseline are selected first, then `--min-count` and `--top` apply in the existing ranked order. Counts remain per current group; different releases are not pooled to meet `--min-count`. All current groups and source coverage remain in the analysis and report. No matching candidates means a valid bundle without a suite.
|
|
102
|
+
|
|
103
|
+
The analysis records `selection.mode: "only-current"`, the baseline input and verified analysis SHA-256 hashes, baseline coverage, and group selection counts. These are covered by the new bundle's analysis hash. The baseline is read once without modification; later baseline edits do not alter this saved selection. Reuse the same baseline and filters when refining the profile. Existing context questions and the review gate still apply; `--reviewed` only acknowledges review.
|
|
104
|
+
|
|
105
|
+
“Absent from baseline” does not establish that an error was newly introduced or is a confirmed regression. Partial exports, different periods, and reporting practices can explain absence; comparison coverage warnings are retained. Captured-event and submitted-report sources cannot be mixed. Output must be a new directory outside the baseline's `results` directory.
|
|
106
|
+
|
|
107
|
+
The async API is `await analyzeWithBaseline(content, baselineDirectory, { minCount: 3, top: 10, profile })`. It verifies the baseline bundle itself and accepts the same analysis options as `analyzeErrors`.
|
|
108
|
+
|
|
70
109
|
## Confirm the intended behavior
|
|
71
110
|
|
|
72
111
|
See [examples/profile.json](examples/profile.json). Profiles use `schemaVersion: "error-to-test/profile-1"`, a name, and up to 100 scenarios. Each scenario has a unique ID, title, at least one match predicate, a requirement, its `expectedSource`, and explicit steps. Set `setupConfirmed: true` only after confirming how preconditions are established. Preconditions are descriptions; this package does not prepare accounts or data.
|
package/dist/analysis.d.ts
CHANGED
|
@@ -6,3 +6,4 @@ export interface AnalyzeOptions extends ParseInputOptions {
|
|
|
6
6
|
minCount?: number;
|
|
7
7
|
}
|
|
8
8
|
export declare function analyzeErrors(content: string, options?: AnalyzeOptions): Analysis;
|
|
9
|
+
export declare function analyzeWithBaseline(content: string, baselineDirectory: string, options?: AnalyzeOptions): Promise<Analysis>;
|
package/dist/analysis.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { parseInput } from "./input.js";
|
|
2
2
|
import { groupObservations } from "./grouping.js";
|
|
3
3
|
import { createCandidates, parseProfile } from "./candidates.js";
|
|
4
|
+
import { readVerifiedBundle } from "./artifacts.js";
|
|
5
|
+
import { compareAnalyses } from "./comparison.js";
|
|
4
6
|
import { hash } from "./validation.js";
|
|
5
|
-
|
|
7
|
+
function analyze(content, options, baseline) {
|
|
6
8
|
const top = options.top ?? 100;
|
|
7
9
|
if (!Number.isInteger(top) || top < 1 || top > 100)
|
|
8
10
|
throw new Error('top must be an integer between 1 and 100.');
|
|
@@ -24,20 +26,58 @@ export function analyzeErrors(content, options = {}) {
|
|
|
24
26
|
const profile = rawProfile === undefined ? undefined : parseProfile(rawProfile);
|
|
25
27
|
const input = parseInput(content, options);
|
|
26
28
|
const groups = groupObservations(input.observations);
|
|
27
|
-
const
|
|
29
|
+
const source = { sha256: input.sha256, ...(profileSource !== undefined ? { profileSha256: hash(profileSource) } : {}) };
|
|
28
30
|
const warnings = [...input.warnings];
|
|
29
|
-
|
|
30
|
-
|
|
31
|
+
let selectedGroups = groups;
|
|
32
|
+
let selection;
|
|
33
|
+
if (baseline) {
|
|
34
|
+
const comparison = compareAnalyses(baseline.analysis, {
|
|
35
|
+
schemaVersion: 'error-to-test/analysis-1', source, coverage: input.coverage, groups, warnings: [],
|
|
36
|
+
});
|
|
37
|
+
const onlyCurrentIds = new Set(comparison.issues.filter(issue => issue.status === 'only-current')
|
|
38
|
+
.flatMap(issue => issue.current?.groupIds ?? []));
|
|
39
|
+
selectedGroups = groups.filter(group => onlyCurrentIds.has(group.id));
|
|
40
|
+
selection = {
|
|
41
|
+
mode: 'only-current',
|
|
42
|
+
baseline: { inputSha256: comparison.baseline.inputSha256, analysisSha256: baseline.analysisSha256,
|
|
43
|
+
coverage: comparison.baseline.coverage },
|
|
44
|
+
onlyCurrentGroupCount: selectedGroups.length,
|
|
45
|
+
excludedGroupCount: groups.length - selectedGroups.length,
|
|
46
|
+
};
|
|
47
|
+
warnings.push(`Baseline TC selection: ${selection.onlyCurrentGroupCount} of ${groups.length} current groups have signatures absent from the supplied baseline; ${selection.excludedGroupCount} already observed. Selection precedes minCount and top. Absence from this baseline does not establish introduction, regression, or resolution.`);
|
|
48
|
+
// A prior baseline-aware bundle may already carry comparison notes. Keep the
|
|
49
|
+
// comparison's bounded coverage cautions without recursively echoing history.
|
|
50
|
+
warnings.push(...comparison.warnings.filter(warning => !warning.startsWith('Baseline:') && !warning.startsWith('Current:')));
|
|
51
|
+
if (comparison.baseline.coverage.duplicates || comparison.baseline.coverage.filtered) {
|
|
52
|
+
warnings.push(`Baseline source coverage: ${comparison.baseline.coverage.duplicates} duplicate and ${comparison.baseline.coverage.filtered} filtered supplied records.`);
|
|
53
|
+
}
|
|
54
|
+
if (comparison.baseline.coverage.period) {
|
|
55
|
+
warnings.push('Baseline date filtering applies only to reports with observed timestamps; undated reports may have been excluded.');
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
const eligibleGroups = selectedGroups.filter(group => group.count >= minCount);
|
|
59
|
+
if (eligibleGroups.length < selectedGroups.length)
|
|
60
|
+
warnings.push(`TC selection requires at least ${minCount} supplied records per group; ${eligibleGroups.length} of ${selectedGroups.length} groups are eligible. All groups remain in analysis.json. These counts are supplied records, not global rates.`);
|
|
31
61
|
if (eligibleGroups.length > top)
|
|
32
62
|
warnings.push(minCount === 1
|
|
33
|
-
? `TC selection includes the first ${top} of ${
|
|
63
|
+
? `TC selection includes the first ${top} of ${selectedGroups.length} ranked groups. All groups remain in analysis.json.`
|
|
34
64
|
: `TC selection includes the first ${top} of ${eligibleGroups.length} eligible ranked groups. All groups remain in analysis.json.`);
|
|
35
65
|
return {
|
|
36
66
|
schemaVersion: 'error-to-test/analysis-1',
|
|
37
|
-
source
|
|
67
|
+
source,
|
|
38
68
|
coverage: input.coverage,
|
|
39
69
|
groups,
|
|
40
70
|
candidates: createCandidates(eligibleGroups.slice(0, top), profile),
|
|
41
71
|
warnings,
|
|
72
|
+
...(selection ? { selection } : {}),
|
|
42
73
|
};
|
|
43
74
|
}
|
|
75
|
+
export function analyzeErrors(content, options = {}) {
|
|
76
|
+
return analyze(content, options);
|
|
77
|
+
}
|
|
78
|
+
export async function analyzeWithBaseline(content, baselineDirectory, options = {}) {
|
|
79
|
+
const baseline = await readVerifiedBundle(baselineDirectory);
|
|
80
|
+
if (typeof baseline.provenance.analysisSha256 !== 'string')
|
|
81
|
+
throw new Error('STALE_BUNDLE: The baseline analysis hash is missing.');
|
|
82
|
+
return analyze(content, options, { analysis: baseline.analysis, analysisSha256: baseline.provenance.analysisSha256 });
|
|
83
|
+
}
|
package/dist/artifacts.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Analysis } from './types.ts';
|
|
2
2
|
export declare function jsonText(value: unknown): string;
|
|
3
|
+
export declare function fencedText(value: string): string;
|
|
3
4
|
export declare function literal(value: string): string;
|
|
4
5
|
export declare function renderReport(analysis: Analysis): string;
|
|
5
6
|
export declare function writeBundle(directory: string, analysis: Analysis, options?: {
|
package/dist/artifacts.js
CHANGED
|
@@ -4,12 +4,13 @@ import { exportFlowQa } from "./exports/flow-qa.js";
|
|
|
4
4
|
import { hash, record, text } from "./validation.js";
|
|
5
5
|
import { redactText } from "./redact.js";
|
|
6
6
|
export function jsonText(value) { return `${JSON.stringify(value, null, 2)}\n`; }
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const runs =
|
|
7
|
+
// Use only after callers have sanitized each untrusted field for its context.
|
|
8
|
+
export function fencedText(value) {
|
|
9
|
+
const runs = value.match(/`+/g) ?? [];
|
|
10
10
|
const fence = '`'.repeat(Math.max(3, ...runs.map(run => run.length + 1)));
|
|
11
|
-
return `${fence}text\n${
|
|
11
|
+
return `${fence}text\n${value}\n${fence}`;
|
|
12
12
|
}
|
|
13
|
+
export function literal(value) { return fencedText(redactText(value)); }
|
|
13
14
|
export function renderReport(analysis) {
|
|
14
15
|
const draftCandidates = analysis.candidates.filter(candidate => candidate.state === 'draft').length;
|
|
15
16
|
const needsContextCandidates = analysis.candidates.filter(candidate => candidate.state === 'needs-context').length;
|
|
@@ -21,6 +22,16 @@ export function renderReport(analysis) {
|
|
|
21
22
|
`Duplicate records: ${analysis.coverage.duplicates} · Filtered records: ${analysis.coverage.filtered}`, '',
|
|
22
23
|
'Counts describe the supplied records. They are not error rates, affected-user counts, or proof of complete collection.',
|
|
23
24
|
'Drafts require review. A passing TC proves only its assertions; it does not automatically close the source issue.', ''];
|
|
25
|
+
if (analysis.selection)
|
|
26
|
+
lines.push('## Baseline candidate selection', '', literal([
|
|
27
|
+
'Mode: only-current (signatures absent from the supplied baseline)',
|
|
28
|
+
`Baseline input SHA-256: ${analysis.selection.baseline.inputSha256}`,
|
|
29
|
+
`Baseline analysis SHA-256: ${analysis.selection.baseline.analysisSha256}`,
|
|
30
|
+
`Baseline: ${analysis.selection.baseline.coverage.kind} / ${analysis.selection.baseline.coverage.frequency} · partial ${analysis.selection.baseline.coverage.partial ? 'yes' : 'no'} · retention unknown`,
|
|
31
|
+
`Only-current groups before min-count/top: ${analysis.selection.onlyCurrentGroupCount}`,
|
|
32
|
+
`Groups excluded as already observed: ${analysis.selection.excludedGroupCount}`,
|
|
33
|
+
'All current groups remain below. Absence from this baseline does not establish when an error was introduced.',
|
|
34
|
+
].join('\n')), '');
|
|
24
35
|
if (analysis.warnings.length)
|
|
25
36
|
lines.push('## Coverage and selection notes', '', literal(analysis.warnings.join('\n')), '');
|
|
26
37
|
if (!analysis.groups.length)
|
package/dist/cli.js
CHANGED
|
@@ -2,8 +2,9 @@ import { parseArgs } from 'node:util';
|
|
|
2
2
|
import { randomUUID } from 'node:crypto';
|
|
3
3
|
import { lstat, mkdir, readFile, realpath, writeFile } from 'node:fs/promises';
|
|
4
4
|
import { dirname, isAbsolute, relative, resolve, sep } from 'node:path';
|
|
5
|
-
import { analyzeErrors } from "./analysis.js";
|
|
5
|
+
import { analyzeErrors, analyzeWithBaseline } from "./analysis.js";
|
|
6
6
|
import { jsonText, readBoundedFile, readVerifiedBundle, verifyBundle, writeBundle } from "./artifacts.js";
|
|
7
|
+
import { compareBundles, renderComparison } from "./comparison.js";
|
|
7
8
|
import { createProfileTemplate } from "./profile-template.js";
|
|
8
9
|
import { redactText } from "./redact.js";
|
|
9
10
|
import { linkFlowQaReport } from "./results.js";
|
|
@@ -11,6 +12,7 @@ import { readRunSummary, renderRunSummary } from "./run-summary.js";
|
|
|
11
12
|
const help = `Error to Test — local error analysis and regression TC drafts
|
|
12
13
|
|
|
13
14
|
error-to-test analyze --input errors.json --profile profile.json --out new-directory
|
|
15
|
+
error-to-test analyze --input errors.json --baseline previous-bundle --out new-directory
|
|
14
16
|
error-to-test analyze --input error.txt --format text --page /items --out new-directory
|
|
15
17
|
error-to-test analyze --error "TypeError: item is undefined" --page /items --out new-directory
|
|
16
18
|
cat error.txt | error-to-test analyze --input - --format text --out new-directory
|
|
@@ -18,13 +20,16 @@ const help = `Error to Test — local error analysis and regression TC drafts
|
|
|
18
20
|
error-to-test init-profile new-directory --out profile.json
|
|
19
21
|
error-to-test link-run new-directory --report path/to/qa-report.json
|
|
20
22
|
error-to-test results new-directory [--format text|json] [--out summary.md]
|
|
23
|
+
error-to-test compare BASELINE CURRENT [--format text|json] [--out comparison.md]
|
|
21
24
|
|
|
22
25
|
Options:
|
|
23
26
|
--input FILE SDK export, manual JSON, or plain error text (- for stdin)
|
|
24
27
|
--error TEXT Submit a single error directly; remaining lines are its stack
|
|
25
28
|
--format auto|json|text Analyze input format; auto rejects malformed JSON-looking input
|
|
26
29
|
--format text|json Results summary format (default: text Markdown)
|
|
30
|
+
--format text|json Compare format (default: text Markdown)
|
|
27
31
|
--profile FILE Confirmed app scenarios and explicit assertions (optional)
|
|
32
|
+
--baseline DIRECTORY Select only signatures absent from this verified bundle, before --min-count and --top; retain all groups in analysis.json (analyze only)
|
|
28
33
|
--project NAME Metadata for a manual report
|
|
29
34
|
--environment NAME Metadata for a manual report
|
|
30
35
|
--release NAME Metadata for a manual report
|
|
@@ -41,6 +46,7 @@ Options:
|
|
|
41
46
|
--out DIRECTORY New analyze directory; existing files are never overwritten
|
|
42
47
|
--out FILE New init-profile JSON file; existing files are never overwritten
|
|
43
48
|
--out FILE New results summary file; existing files are never overwritten
|
|
49
|
+
--out FILE New comparison file; existing files are never overwritten
|
|
44
50
|
--reviewed Acknowledge review; unresolved questions still block cases
|
|
45
51
|
--report FILE Normalized Flow QA report (link-run only)
|
|
46
52
|
--version, -v Print the package version
|
|
@@ -89,7 +95,7 @@ function insideBundleResults(bundleRoot, path) {
|
|
|
89
95
|
export async function main(args = process.argv.slice(2)) {
|
|
90
96
|
const { values, positionals } = parseArgs({ args, allowPositionals: true, strict: true, options: {
|
|
91
97
|
help: { type: 'boolean', short: 'h' }, version: { type: 'boolean', short: 'v' }, input: { type: 'string' }, error: { type: 'string' }, report: { type: 'string' },
|
|
92
|
-
format: { type: 'string' }, profile: { type: 'string' }, project: { type: 'string' }, environment: { type: 'string' },
|
|
98
|
+
format: { type: 'string' }, profile: { type: 'string' }, baseline: { type: 'string' }, project: { type: 'string' }, environment: { type: 'string' },
|
|
93
99
|
release: { type: 'string' }, page: { type: 'string' }, type: { type: 'string' }, runtime: { type: 'string' }, from: { type: 'string' }, to: { type: 'string' },
|
|
94
100
|
top: { type: 'string' }, 'min-count': { type: 'string' }, out: { type: 'string' }, reviewed: { type: 'boolean' },
|
|
95
101
|
reproduce: { type: 'string', multiple: true }, precondition: { type: 'string', multiple: true },
|
|
@@ -106,7 +112,7 @@ export async function main(args = process.argv.slice(2)) {
|
|
|
106
112
|
}
|
|
107
113
|
if (positionals.length === 0) {
|
|
108
114
|
if (Object.keys(values).length)
|
|
109
|
-
throw new Error('A command is required. Use analyze, init-profile, verify, link-run, or
|
|
115
|
+
throw new Error('A command is required. Use analyze, init-profile, verify, link-run, results, or compare. See --help.');
|
|
110
116
|
process.stdout.write(help);
|
|
111
117
|
return;
|
|
112
118
|
}
|
|
@@ -185,6 +191,43 @@ export async function main(args = process.argv.slice(2)) {
|
|
|
185
191
|
process.stdout.write(`Results summary written: ${out}\n`);
|
|
186
192
|
return;
|
|
187
193
|
}
|
|
194
|
+
if (command === 'compare') {
|
|
195
|
+
if (positionals.length !== 3 || !positionals[1] || !positionals[2])
|
|
196
|
+
throw new Error('compare requires BASELINE and CURRENT bundle directories.');
|
|
197
|
+
if (Object.keys(values).some(key => !['format', 'out', 'help'].includes(key)))
|
|
198
|
+
throw new Error('Unsupported option for compare. Use only --format text|json and --out FILE.');
|
|
199
|
+
const format = values.format ?? 'text';
|
|
200
|
+
if (format !== 'text' && format !== 'json')
|
|
201
|
+
throw new Error('compare --format must be text or json.');
|
|
202
|
+
const baseline = resolve(positionals[1]);
|
|
203
|
+
const current = resolve(positionals[2]);
|
|
204
|
+
const comparison = await compareBundles(baseline, current);
|
|
205
|
+
const content = format === 'json' ? jsonText(comparison) : renderComparison(comparison);
|
|
206
|
+
if (Buffer.byteLength(content) > 64 * 1024 * 1024)
|
|
207
|
+
throw new Error('The comparison exceeds 64 MiB. Narrow the bundles before requesting output.');
|
|
208
|
+
if (values.out === undefined) {
|
|
209
|
+
process.stdout.write(content);
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
const out = resolve(values.out);
|
|
213
|
+
const canonical = await canonicalOutput(out);
|
|
214
|
+
for (const bundle of [baseline, current]) {
|
|
215
|
+
if (insideBundleResults(await realpath(bundle), canonical)) {
|
|
216
|
+
throw new Error('The comparison cannot be written inside either bundle results directory. Choose an outside --out FILE path.');
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
await mkdir(dirname(out), { recursive: true });
|
|
220
|
+
try {
|
|
221
|
+
await writeFile(out, content, { flag: 'wx', mode: 0o600 });
|
|
222
|
+
}
|
|
223
|
+
catch (error) {
|
|
224
|
+
if (error.code === 'EEXIST')
|
|
225
|
+
throw new Error('The output file already exists. Choose a new --out FILE path.');
|
|
226
|
+
throw error;
|
|
227
|
+
}
|
|
228
|
+
process.stdout.write(`Comparison written: ${out}\n`);
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
188
231
|
if (command === 'verify') {
|
|
189
232
|
if (positionals.length !== 2 || !positionals[1])
|
|
190
233
|
throw new Error('verify requires one bundle directory.');
|
|
@@ -198,9 +241,11 @@ export async function main(args = process.argv.slice(2)) {
|
|
|
198
241
|
return;
|
|
199
242
|
}
|
|
200
243
|
if (command !== 'analyze' || positionals.length !== 1)
|
|
201
|
-
throw new Error('Use analyze, init-profile, verify, link-run, or
|
|
244
|
+
throw new Error('Use analyze, init-profile, verify, link-run, results, or compare. See --help.');
|
|
202
245
|
if (values.report)
|
|
203
246
|
throw new Error('--report applies to link-run only.');
|
|
247
|
+
if (values.baseline !== undefined && values.baseline.trim() === '')
|
|
248
|
+
throw new Error('--baseline requires a bundle directory.');
|
|
204
249
|
if ((values.input === undefined) === (values.error === undefined))
|
|
205
250
|
throw new Error('Provide exactly one of --input or --error.');
|
|
206
251
|
const format = values.format ?? 'auto';
|
|
@@ -232,16 +277,23 @@ export async function main(args = process.argv.slice(2)) {
|
|
|
232
277
|
throw new Error('Reported context options require --error. Use manual JSON or a profile for file input.');
|
|
233
278
|
content = values.input === '-' ? await stdinText() : await readBoundedFile(resolve(values.input));
|
|
234
279
|
}
|
|
235
|
-
const
|
|
280
|
+
const options = {
|
|
236
281
|
format: inputFormat, ...(values.profile ? { profile: await readBoundedFile(resolve(values.profile), 1024 * 1024) } : {}),
|
|
237
282
|
project: values.project, environment: values.environment, release: values.release, page: values.page, type: values.type, runtime: values.runtime,
|
|
238
283
|
from: values.from, to: values.to, ...(values.top !== undefined ? { top: Number(values.top) } : {}),
|
|
239
284
|
...(values['min-count'] !== undefined ? { minCount: Number(values['min-count']) } : {}),
|
|
240
|
-
}
|
|
285
|
+
};
|
|
286
|
+
const baseline = values.baseline === undefined ? undefined : resolve(values.baseline);
|
|
287
|
+
const analysis = baseline === undefined ? analyzeErrors(content, options) : await analyzeWithBaseline(content, baseline, options);
|
|
241
288
|
const out = resolve(values.out ?? `.error-to-test/run-${Date.now()}-${randomUUID().slice(0, 8)}`);
|
|
289
|
+
if (baseline !== undefined && insideBundleResults(await realpath(baseline), await canonicalOutput(out))) {
|
|
290
|
+
throw new Error('The analysis cannot be written inside the baseline bundle results directory. Choose an outside --out DIRECTORY path.');
|
|
291
|
+
}
|
|
242
292
|
const files = await writeBundle(out, analysis, { reviewed: values.reviewed });
|
|
243
293
|
const drafts = analysis.candidates.filter(candidate => candidate.state === 'draft').length;
|
|
244
294
|
process.stdout.write(`${analysis.groups.length} error groups; ${analysis.candidates.length} TC candidates (${drafts} drafts, ${analysis.candidates.length - drafts} need context).\n`);
|
|
295
|
+
if (analysis.selection)
|
|
296
|
+
process.stdout.write(`${analysis.selection.onlyCurrentGroupCount} only-current groups; ${analysis.selection.excludedGroupCount} baseline-matched groups excluded from TC selection.\n`);
|
|
245
297
|
process.stdout.write(`Review ${resolve(out, 'report.md')}\n${files.length} artifacts written. Review acknowledgment: ${values.reviewed ? 'yes' : 'pending'}.\n`);
|
|
246
298
|
}
|
|
247
299
|
export function reportCliError(error) {
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { EventType, Runtime, SourceCoverage } from './types.ts';
|
|
2
|
+
export type ComparisonStatus = 'only-current' | 'both' | 'only-baseline';
|
|
3
|
+
export interface ComparisonSide {
|
|
4
|
+
inputSha256: string;
|
|
5
|
+
groupCount: number;
|
|
6
|
+
recordCount: number;
|
|
7
|
+
coverage: SourceCoverage;
|
|
8
|
+
}
|
|
9
|
+
export interface ComparisonOccurrence {
|
|
10
|
+
count: number;
|
|
11
|
+
groupIds: string[];
|
|
12
|
+
releases: string[];
|
|
13
|
+
}
|
|
14
|
+
export interface ComparisonIssue {
|
|
15
|
+
id: string;
|
|
16
|
+
status: ComparisonStatus;
|
|
17
|
+
project: string;
|
|
18
|
+
environment: string;
|
|
19
|
+
runtime: Runtime;
|
|
20
|
+
type: EventType;
|
|
21
|
+
pagePath: string;
|
|
22
|
+
signature: string;
|
|
23
|
+
message: string;
|
|
24
|
+
baseline?: ComparisonOccurrence;
|
|
25
|
+
current?: ComparisonOccurrence;
|
|
26
|
+
delta: number;
|
|
27
|
+
}
|
|
28
|
+
export interface AnalysisComparison {
|
|
29
|
+
schemaVersion: 'error-to-test/comparison-1';
|
|
30
|
+
baseline: ComparisonSide;
|
|
31
|
+
current: ComparisonSide;
|
|
32
|
+
counts: Record<ComparisonStatus, number>;
|
|
33
|
+
issues: ComparisonIssue[];
|
|
34
|
+
warnings: string[];
|
|
35
|
+
}
|
|
36
|
+
export declare function compareBundles(baselineDirectory: string, currentDirectory: string): Promise<AnalysisComparison>;
|
|
37
|
+
export declare function compareAnalyses(baselineAnalysis: unknown, currentAnalysis: unknown): AnalysisComparison;
|
|
38
|
+
export declare function renderComparison(comparison: AnalysisComparison): string;
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { fencedText, literal, readVerifiedBundle } from "./artifacts.js";
|
|
2
|
+
import { pagePath, redactText } from "./redact.js";
|
|
3
|
+
import { hash, record, timestamp } from "./validation.js";
|
|
4
|
+
const statuses = ['only-current', 'both', 'only-baseline'];
|
|
5
|
+
const runtimes = ['browser', 'webview-ios', 'webview-android', 'unknown'];
|
|
6
|
+
const types = ['javascript', 'promise', 'react', 'console', 'http', 'network', 'manual'];
|
|
7
|
+
const kinds = ['browser-error-json', 'manual-json', 'manual-text'];
|
|
8
|
+
const normalizedMax = 128 * 1024;
|
|
9
|
+
const hex64 = /^[0-9a-f]{64}$/;
|
|
10
|
+
const groupId = /^group-[0-9a-f]{16}$/;
|
|
11
|
+
const comparisonId = /^comparison-[0-9a-f]{64}$/;
|
|
12
|
+
function integer(value, label, max = 10000, min = 0) {
|
|
13
|
+
if (!Number.isSafeInteger(value) || value < min || value > max)
|
|
14
|
+
throw new Error(`${label} must be an integer between ${min} and ${max}.`);
|
|
15
|
+
return value;
|
|
16
|
+
}
|
|
17
|
+
function bounded(value, label, max = normalizedMax, required = true) {
|
|
18
|
+
if (typeof value !== 'string' || value.length > max || (required && !value.trim()))
|
|
19
|
+
throw new Error(`${label} must be a ${required ? 'non-empty ' : ''}string of at most ${max} characters.`);
|
|
20
|
+
return value;
|
|
21
|
+
}
|
|
22
|
+
function coverage(value, label) {
|
|
23
|
+
const raw = record(value, label);
|
|
24
|
+
if (!kinds.includes(raw.kind))
|
|
25
|
+
throw new Error(`${label}.kind is unsupported.`);
|
|
26
|
+
const kind = raw.kind;
|
|
27
|
+
const frequency = kind === 'browser-error-json' ? 'captured-events' : 'submitted-reports';
|
|
28
|
+
if (raw.frequency !== frequency)
|
|
29
|
+
throw new Error(`${label}.frequency is incompatible with kind.`);
|
|
30
|
+
if (typeof raw.partial !== 'boolean' || raw.retention !== 'unknown')
|
|
31
|
+
throw new Error(`${label} has unsupported partial or retention data.`);
|
|
32
|
+
const inputCount = integer(raw.inputCount, `${label}.inputCount`);
|
|
33
|
+
const duplicates = integer(raw.duplicates, `${label}.duplicates`);
|
|
34
|
+
const filtered = integer(raw.filtered, `${label}.filtered`);
|
|
35
|
+
let period;
|
|
36
|
+
if (raw.period !== undefined) {
|
|
37
|
+
const p = record(raw.period, `${label}.period`);
|
|
38
|
+
const from = p.from === undefined ? undefined : timestamp(p.from, `${label}.period.from`);
|
|
39
|
+
const to = p.to === undefined ? undefined : timestamp(p.to, `${label}.period.to`);
|
|
40
|
+
if (from && to && from > to)
|
|
41
|
+
throw new Error(`${label}.period.from exceeds to.`);
|
|
42
|
+
if (!from && !to)
|
|
43
|
+
throw new Error(`${label}.period must contain a bound.`);
|
|
44
|
+
period = { ...(from ? { from } : {}), ...(to ? { to } : {}) };
|
|
45
|
+
}
|
|
46
|
+
return { kind, frequency, partial: raw.partial, inputCount, duplicates, filtered, retention: 'unknown', ...(period ? { period } : {}) };
|
|
47
|
+
}
|
|
48
|
+
function parseSnapshot(value, label) {
|
|
49
|
+
const raw = record(value, label), source = record(raw.source, `${label}.source`);
|
|
50
|
+
if (raw.schemaVersion !== 'error-to-test/analysis-1' || typeof source.sha256 !== 'string' || !hex64.test(source.sha256))
|
|
51
|
+
throw new Error(`${label} has an unsupported source contract.`);
|
|
52
|
+
const cov = coverage(raw.coverage, `${label}.coverage`);
|
|
53
|
+
if (!Array.isArray(raw.groups) || raw.groups.length > 10000)
|
|
54
|
+
throw new Error(`${label}.groups must contain at most 10000 groups.`);
|
|
55
|
+
const seen = new Set();
|
|
56
|
+
const groups = raw.groups.map((item, index) => {
|
|
57
|
+
const name = `${label}.groups[${index}]`, g = record(item, name);
|
|
58
|
+
if (g.fingerprintVersion !== 1)
|
|
59
|
+
throw new Error(`${name} has unsupported fingerprintVersion.`);
|
|
60
|
+
if (typeof g.id !== 'string' || !groupId.test(g.id) || seen.has(g.id))
|
|
61
|
+
throw new Error(`${name}.id is invalid or duplicated.`);
|
|
62
|
+
seen.add(g.id);
|
|
63
|
+
if (!runtimes.includes(g.runtime) || !types.includes(g.type))
|
|
64
|
+
throw new Error(`${name} has unsupported runtime or type.`);
|
|
65
|
+
return {
|
|
66
|
+
id: g.id, project: bounded(g.project, `${name}.project`), environment: bounded(g.environment, `${name}.environment`),
|
|
67
|
+
release: bounded(g.release, `${name}.release`), runtime: g.runtime, type: g.type,
|
|
68
|
+
pagePath: bounded(g.pagePath, `${name}.pagePath`, normalizedMax, false),
|
|
69
|
+
signature: bounded(g.signature, `${name}.signature`, normalizedMax, false),
|
|
70
|
+
message: bounded(g.message, `${name}.message`), count: integer(g.count, `${name}.count`, 10000, 1),
|
|
71
|
+
};
|
|
72
|
+
});
|
|
73
|
+
const recordCount = groups.reduce((sum, g) => sum + g.count, 0);
|
|
74
|
+
if (recordCount + cov.duplicates + cov.filtered !== cov.inputCount)
|
|
75
|
+
throw new Error(`${label} group counts do not match source coverage.`);
|
|
76
|
+
if (!Array.isArray(raw.warnings) || raw.warnings.length > 100)
|
|
77
|
+
throw new Error(`${label}.warnings must contain at most 100 strings.`);
|
|
78
|
+
const warnings = raw.warnings.map((warning, index) => redactText(bounded(warning, `${label}.warnings[${index}]`, normalizedMax, false)));
|
|
79
|
+
return { side: { inputSha256: source.sha256, groupCount: groups.length, recordCount, coverage: cov }, groups, warnings };
|
|
80
|
+
}
|
|
81
|
+
function key(g) { return JSON.stringify([g.project, g.environment, g.runtime, g.type, g.pagePath, g.signature]); }
|
|
82
|
+
function aggregate(groups) {
|
|
83
|
+
const map = new Map();
|
|
84
|
+
for (const g of groups) {
|
|
85
|
+
const k = key(g), found = map.get(k);
|
|
86
|
+
if (found) {
|
|
87
|
+
found.count += g.count;
|
|
88
|
+
found.ids.add(g.id);
|
|
89
|
+
found.releases.add(g.release);
|
|
90
|
+
}
|
|
91
|
+
else
|
|
92
|
+
map.set(k, { group: g, count: g.count, ids: new Set([g.id]), releases: new Set([g.release]) });
|
|
93
|
+
}
|
|
94
|
+
return map;
|
|
95
|
+
}
|
|
96
|
+
const sorted = (items) => [...items].sort();
|
|
97
|
+
function occurrence(a) { return { count: a.count, groupIds: sorted(a.ids), releases: sorted(a.releases).map(redactText) }; }
|
|
98
|
+
export async function compareBundles(baselineDirectory, currentDirectory) {
|
|
99
|
+
const baseline = (await readVerifiedBundle(baselineDirectory)).analysis;
|
|
100
|
+
const current = (await readVerifiedBundle(currentDirectory)).analysis;
|
|
101
|
+
return compareAnalyses(baseline, current);
|
|
102
|
+
}
|
|
103
|
+
// Shared by verified bundle comparison and baseline-aware candidate selection.
|
|
104
|
+
// Identity is computed from the stored normalized fields before display redaction.
|
|
105
|
+
export function compareAnalyses(baselineAnalysis, currentAnalysis) {
|
|
106
|
+
const baseline = parseSnapshot(baselineAnalysis, 'Baseline');
|
|
107
|
+
const current = parseSnapshot(currentAnalysis, 'Current');
|
|
108
|
+
if (baseline.side.coverage.frequency !== current.side.coverage.frequency)
|
|
109
|
+
throw new Error('Comparison requires matching count frequency; captured events and submitted reports cannot share a delta.');
|
|
110
|
+
const before = aggregate(baseline.groups), after = aggregate(current.groups);
|
|
111
|
+
const counts = { 'only-current': 0, both: 0, 'only-baseline': 0 };
|
|
112
|
+
const issues = sorted(new Set([...before.keys(), ...after.keys()])).map((k) => {
|
|
113
|
+
const b = before.get(k), c = after.get(k), group = (c ?? b).group;
|
|
114
|
+
const status = b && c ? 'both' : c ? 'only-current' : 'only-baseline';
|
|
115
|
+
counts[status]++;
|
|
116
|
+
const issue = { id: `comparison-${hash(k)}`, status, project: redactText(group.project), environment: redactText(group.environment),
|
|
117
|
+
runtime: group.runtime, type: group.type, pagePath: pagePath(group.pagePath), signature: redactText(group.signature),
|
|
118
|
+
message: redactText(group.message), ...(b ? { baseline: occurrence(b) } : {}), ...(c ? { current: occurrence(c) } : {}),
|
|
119
|
+
delta: (c?.count ?? 0) - (b?.count ?? 0) };
|
|
120
|
+
return { rawKey: k, issue };
|
|
121
|
+
}).sort((a, b) => statuses.indexOf(a.issue.status) - statuses.indexOf(b.issue.status) || (a.rawKey < b.rawKey ? -1 : a.rawKey > b.rawKey ? 1 : 0)).map(entry => entry.issue);
|
|
122
|
+
const warnings = [
|
|
123
|
+
'Counts describe supplied, deduplicated, filtered records only. Absence is not resolution; no error rates or affected-user counts can be inferred. Retention coverage is unknown.',
|
|
124
|
+
'All analysis groups are compared, including groups excluded from TC candidate selection.',
|
|
125
|
+
'Release is excluded from identity. Multiple supplied releases are aggregated; use analyze --release before each bundle for a single-release comparison.',
|
|
126
|
+
...baseline.warnings.map(w => `Baseline: ${w}`), ...current.warnings.map(w => `Current: ${w}`),
|
|
127
|
+
];
|
|
128
|
+
if (baseline.side.coverage.partial || current.side.coverage.partial)
|
|
129
|
+
warnings.push('At least one source export is partial; observed counts may be incomplete.');
|
|
130
|
+
if (baseline.side.coverage.kind !== current.side.coverage.kind)
|
|
131
|
+
warnings.push('Source kinds differ; counts may reflect different reporting practices.');
|
|
132
|
+
if (JSON.stringify(baseline.side.coverage.period) !== JSON.stringify(current.side.coverage.period))
|
|
133
|
+
warnings.push('Source period filters differ or are missing.');
|
|
134
|
+
const contexts = (groups) => sorted(new Set(groups.map(g => JSON.stringify([g.project, g.environment, g.runtime, g.type, g.pagePath]))));
|
|
135
|
+
if (JSON.stringify(contexts(baseline.groups)) !== JSON.stringify(contexts(current.groups)))
|
|
136
|
+
warnings.push('Observed project/environment/runtime/type/page contexts differ between supplied snapshots.');
|
|
137
|
+
return { schemaVersion: 'error-to-test/comparison-1', baseline: baseline.side, current: current.side, counts, issues, warnings };
|
|
138
|
+
}
|
|
139
|
+
function renderSide(value, label) {
|
|
140
|
+
const side = record(value, label), sha = side.inputSha256;
|
|
141
|
+
if (typeof sha !== 'string' || !hex64.test(sha))
|
|
142
|
+
throw new Error(`${label}.inputSha256 is invalid.`);
|
|
143
|
+
const cov = coverage(side.coverage, `${label}.coverage`);
|
|
144
|
+
const groupCount = integer(side.groupCount, `${label}.groupCount`), recordCount = integer(side.recordCount, `${label}.recordCount`);
|
|
145
|
+
if (recordCount + cov.duplicates + cov.filtered !== cov.inputCount)
|
|
146
|
+
throw new Error(`${label} counts do not match coverage.`);
|
|
147
|
+
return `${label}: ${sha} · ${cov.kind} / ${cov.frequency} · ${groupCount} groups / ${recordCount} records · partial ${cov.partial ? 'yes' : 'no'} · period ${cov.period ? `${cov.period.from ?? 'unbounded'} to ${cov.period.to ?? 'unbounded'}` : 'unspecified'} · retention unknown`;
|
|
148
|
+
}
|
|
149
|
+
function renderOccurrence(value, label) {
|
|
150
|
+
const raw = record(value, label), count = integer(raw.count, `${label}.count`, 10000, 1);
|
|
151
|
+
if (!Array.isArray(raw.groupIds) || raw.groupIds.length > 10000 || !raw.groupIds.every(id => typeof id === 'string' && groupId.test(id)))
|
|
152
|
+
throw new Error(`${label}.groupIds is invalid.`);
|
|
153
|
+
if (!Array.isArray(raw.releases) || raw.releases.length > 10000)
|
|
154
|
+
throw new Error(`${label}.releases is invalid.`);
|
|
155
|
+
const releases = raw.releases.map((release, i) => bounded(release, `${label}.releases[${i}]`));
|
|
156
|
+
return [`${label}: ${count} records`, '', fencedText(`Releases: ${releases.map(redactText).join(', ')}\nGroup IDs: ${sorted(raw.groupIds).join(', ')}`), ''];
|
|
157
|
+
}
|
|
158
|
+
export function renderComparison(comparison) {
|
|
159
|
+
const raw = record(comparison, 'comparison');
|
|
160
|
+
if (raw.schemaVersion !== 'error-to-test/comparison-1')
|
|
161
|
+
throw new Error('Unsupported comparison contract.');
|
|
162
|
+
const counts = record(raw.counts, 'comparison.counts');
|
|
163
|
+
for (const status of statuses)
|
|
164
|
+
integer(counts[status], `comparison.counts.${status}`);
|
|
165
|
+
if (!Array.isArray(raw.issues) || raw.issues.length > 20000)
|
|
166
|
+
throw new Error('comparison.issues is invalid.');
|
|
167
|
+
if (!Array.isArray(raw.warnings) || raw.warnings.length > 300)
|
|
168
|
+
throw new Error('comparison.warnings is invalid.');
|
|
169
|
+
const lines = ['# Error to Test comparison', '', renderSide(raw.baseline, 'Baseline'), renderSide(raw.current, 'Current'), '',
|
|
170
|
+
`Only current: ${counts['only-current']} · Both: ${counts.both} · Only baseline: ${counts['only-baseline']}`, '',
|
|
171
|
+
'Counts refer to supplied records. Absence does not establish resolution or an error rate.', ''];
|
|
172
|
+
if (raw.warnings.length)
|
|
173
|
+
lines.push('## Coverage notes', '', literal(raw.warnings.map((w, i) => bounded(w, `comparison.warnings[${i}]`, normalizedMax, false)).join('\n')), '');
|
|
174
|
+
const observed = { 'only-current': 0, both: 0, 'only-baseline': 0 };
|
|
175
|
+
for (const [index, value] of raw.issues.entries()) {
|
|
176
|
+
const name = `comparison.issues[${index}]`, issue = record(value, name);
|
|
177
|
+
if (typeof issue.id !== 'string' || !comparisonId.test(issue.id) || !statuses.includes(issue.status))
|
|
178
|
+
throw new Error(`${name} has invalid id or status.`);
|
|
179
|
+
if (!runtimes.includes(issue.runtime) || !types.includes(issue.type))
|
|
180
|
+
throw new Error(`${name} has invalid runtime or type.`);
|
|
181
|
+
const status = issue.status;
|
|
182
|
+
const before = issue.baseline === undefined ? 0 : integer(record(issue.baseline, `${name}.baseline`).count, `${name}.baseline.count`, 10000, 1);
|
|
183
|
+
const after = issue.current === undefined ? 0 : integer(record(issue.current, `${name}.current`).count, `${name}.current.count`, 10000, 1);
|
|
184
|
+
if ((status === 'both' && (!before || !after)) || (status === 'only-current' && (before || !after)) || (status === 'only-baseline' && (!before || after)) || integer(issue.delta, `${name}.delta`, 10000, -10000) !== after - before)
|
|
185
|
+
throw new Error(`${name} has inconsistent status or delta.`);
|
|
186
|
+
observed[status]++;
|
|
187
|
+
const fields = [redactText(bounded(issue.project, `${name}.project`)), redactText(bounded(issue.environment, `${name}.environment`)), issue.runtime, issue.type,
|
|
188
|
+
pagePath(bounded(issue.pagePath, `${name}.pagePath`, normalizedMax, false)), redactText(bounded(issue.signature, `${name}.signature`, normalizedMax, false)), redactText(bounded(issue.message, `${name}.message`))];
|
|
189
|
+
lines.push(`## ${issue.id} · ${status}`, '', `Baseline: ${before} · Current: ${after} · Delta: ${after - before >= 0 ? '+' : ''}${after - before}`, '', fencedText(`Project: ${fields[0]}\nEnvironment: ${fields[1]}\nRuntime: ${fields[2]}\nType: ${fields[3]}\nPage: ${fields[4]}\nMessage: ${fields[6]}\nSignature: ${fields[5]}`), '');
|
|
190
|
+
if (issue.baseline !== undefined)
|
|
191
|
+
lines.push(...renderOccurrence(issue.baseline, 'Baseline'));
|
|
192
|
+
if (issue.current !== undefined)
|
|
193
|
+
lines.push(...renderOccurrence(issue.current, 'Current'));
|
|
194
|
+
}
|
|
195
|
+
if (statuses.some(status => observed[status] !== counts[status]))
|
|
196
|
+
throw new Error('Comparison bucket counts do not match issues.');
|
|
197
|
+
return `${lines.join('\n')}\n`;
|
|
198
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { analyzeErrors, type AnalyzeOptions } from './analysis.ts';
|
|
1
|
+
export { analyzeErrors, analyzeWithBaseline, type AnalyzeOptions } from './analysis.ts';
|
|
2
2
|
export { parseInput, type ParseInputOptions } from './input.ts';
|
|
3
3
|
export { groupObservations } from './grouping.ts';
|
|
4
4
|
export { createCandidates, parseProfile } from './candidates.ts';
|
|
@@ -7,4 +7,5 @@ export { writeBundle, verifyBundle, renderReport } from './artifacts.ts';
|
|
|
7
7
|
export { linkFlowQaReport } from './results.ts';
|
|
8
8
|
export { createProfileTemplate } from './profile-template.ts';
|
|
9
9
|
export { readRunSummary, renderRunSummary, type RunSummary, type LinkedRunStatus, type LinkedCaseStatus } from './run-summary.ts';
|
|
10
|
+
export { compareBundles, renderComparison, type AnalysisComparison, type ComparisonStatus, type ComparisonSide, type ComparisonOccurrence, type ComparisonIssue } from './comparison.ts';
|
|
10
11
|
export type * from './types.ts';
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { analyzeErrors } from "./analysis.js";
|
|
1
|
+
export { analyzeErrors, analyzeWithBaseline } from "./analysis.js";
|
|
2
2
|
export { parseInput } from "./input.js";
|
|
3
3
|
export { groupObservations } from "./grouping.js";
|
|
4
4
|
export { createCandidates, parseProfile } from "./candidates.js";
|
|
@@ -7,3 +7,4 @@ export { writeBundle, verifyBundle, renderReport } from "./artifacts.js";
|
|
|
7
7
|
export { linkFlowQaReport } from "./results.js";
|
|
8
8
|
export { createProfileTemplate } from "./profile-template.js";
|
|
9
9
|
export { readRunSummary, renderRunSummary } from "./run-summary.js";
|
|
10
|
+
export { compareBundles, renderComparison } from "./comparison.js";
|
package/dist/types.d.ts
CHANGED
|
@@ -163,6 +163,16 @@ export interface Analysis {
|
|
|
163
163
|
groups: IssueGroup[];
|
|
164
164
|
candidates: TestCandidate[];
|
|
165
165
|
warnings: string[];
|
|
166
|
+
selection?: {
|
|
167
|
+
mode: 'only-current';
|
|
168
|
+
baseline: {
|
|
169
|
+
inputSha256: string;
|
|
170
|
+
analysisSha256: string;
|
|
171
|
+
coverage: SourceCoverage;
|
|
172
|
+
};
|
|
173
|
+
onlyCurrentGroupCount: number;
|
|
174
|
+
excludedGroupCount: number;
|
|
175
|
+
};
|
|
166
176
|
}
|
|
167
177
|
export interface FlowQaSuite {
|
|
168
178
|
schemaVersion: 'flow-qa/suite-1';
|
package/package.json
CHANGED