@ihyeon/error-to-test 0.2.4 → 0.2.5
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 +19 -0
- package/README.md +34 -0
- package/dist/artifacts.js +9 -0
- package/dist/cli.js +25 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/refinement.d.ts +3 -0
- package/dist/refinement.js +249 -0
- package/dist/types.d.ts +6 -0
- package/package.json +1 -1
package/README.ko.md
CHANGED
|
@@ -188,6 +188,25 @@ TC 생성과 동일하게 모든 조건을 함께 검사해 기존 규칙이 적
|
|
|
188
188
|
|
|
189
189
|
API는 `createProfileTemplate(analysis, { profile: existingProfile })`입니다. JSON 값만으로 구성한 객체 또는 BOM 하나를 지원하는 JSON 문자열을 1 MiB까지 받으며 입력 객체를 변경하지 않습니다. 객체의 선택 필드가 `undefined`이면 해당 속성을 생략하세요. `profile`을 생략하면 기존 빈 템플릿을 만듭니다.
|
|
190
190
|
|
|
191
|
+
프로필을 보완한 뒤에는 **원본 로그 없이 기존 번들에서 TC를 다시 생성**할 수 있습니다.
|
|
192
|
+
|
|
193
|
+
```sh
|
|
194
|
+
error-to-test refine ./initial-analysis --profile ./review-profile.json --out ./refined
|
|
195
|
+
error-to-test readiness ./refined
|
|
196
|
+
# 새 프로필과 TC를 검토한 뒤 별도 새 번들에 검토 확인
|
|
197
|
+
error-to-test refine ./initial-analysis --profile ./review-profile.json --reviewed --out ./refined-reviewed
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
기존에 실제 TC로 선택됐던 묶음만 저장된 순서대로 재생성합니다. 넓은 프로필 규칙도 이전에 제외된 묶음을 새로 선택하지 않으며, 선택된 한 묶음에 여러 규칙이 적용되면 여러 TC를 만들 수 있습니다. 전체 오류 묶음·원본 해시와 입력 파일 목록·수집 범위·이전 분석 기준과 그룹 선택 정보는 보존합니다. 선택 범위나 원본 메타데이터·필터·순위를 바꾸려면 원본 입력으로 `analyze`를 다시 실행하세요.
|
|
201
|
+
|
|
202
|
+
새 프로필로 전체를 교체하며 기존 프로필과 병합하지 않습니다. 1 MiB 제한과 BOM 하나 지원을 유지하고 정확한 프로필 바이트를 새 해시에 반영합니다. 검증된 원본 번들은 한 번 읽으며, `analysis.refinement`에 직전 분석·suite·프로필 해시와 기존 선택 묶음 ID를 기록합니다. 반복 재생성 시 이 항목은 직전 번들 기준으로 교체합니다.
|
|
203
|
+
|
|
204
|
+
대표 로그 5개 밖에서 확인된 질문과 충돌도 저장된 전체 묶음 맥락을 통해 계속 차단합니다. 이 맥락이 없는 오래된 번들, 선택된 TC가 없는 번들, 변경된 산출물, 잘못된 프로필은 거부합니다. 저장된 전체 맥락이 없으면 원본 로그로 다시 분석해야 합니다. `--reviewed`도 미해결 질문을 제거하지 않으며, 기존 번들이 검토됐어도 새 번들은 기본적으로 검토 대기입니다.
|
|
205
|
+
|
|
206
|
+
출력은 원본 번들 전체의 바깥에 있는 새 디렉터리여야 하며 경로 별칭도 검사합니다. 원본 산출물과 연결 실행 결과는 수정하지 않고, 과거 실행 결과도 새 번들에 복사하지 않습니다. 원본 입력 바이트를 다시 확인하는 기능은 아니므로 원본이 있으면 `verify ./refined --input ... --profile ./review-profile.json`로 별도 검증하세요. `--profile`·`--out`은 필수이며 분석 필터나 그룹 선택 옵션은 받지 않습니다. 브라우저 실행이나 원본 오류의 수정 완료 처리는 수행하지 않습니다.
|
|
207
|
+
|
|
208
|
+
API는 `await refineBundle(directory, profileJsonText)`입니다. JSON 문자열을 받아 새 `Analysis`를 반환하며 파일 저장·검토 승인·종료 코드 변경은 하지 않습니다. 저장하려면 별도 새 경로에 `writeBundle()`을 호출하세요.
|
|
209
|
+
|
|
191
210
|
```sh
|
|
192
211
|
node bin/error-to-test.mjs verify .error-to-test/example --input examples/errors.json --profile examples/profile.json
|
|
193
212
|
node bin/error-to-test.mjs analyze --input examples/errors.json --profile examples/profile.json --reviewed --out .error-to-test/reviewed
|
package/README.md
CHANGED
|
@@ -233,6 +233,40 @@ New templates retain blank expectation fields, `setupConfirmed: false`, and the
|
|
|
233
233
|
|
|
234
234
|
The API is `createProfileTemplate(analysis, { profile: existingProfile })`; `profile` accepts an object containing only JSON values or a JSON string, including one leading BOM, within 1 MiB. Omit undefined optional properties from object inputs. The function does not mutate either input. Without `profile`, it produces the original blank template.
|
|
235
235
|
|
|
236
|
+
### Apply a new profile without the original logs
|
|
237
|
+
|
|
238
|
+
`refine` regenerates TC candidates from a verified saved bundle and a replacement profile. It is useful after editing a generated profile when the original log files are no longer available:
|
|
239
|
+
|
|
240
|
+
```sh
|
|
241
|
+
error-to-test init-profile ./initial-analysis --out ./review-profile.json
|
|
242
|
+
# Fill confirmed requirements, setup, actions, and assertions in review-profile.json.
|
|
243
|
+
error-to-test refine ./initial-analysis --profile ./review-profile.json --out ./refined
|
|
244
|
+
error-to-test readiness ./refined
|
|
245
|
+
# After reviewing the replacement profile and cases, write another new bundle:
|
|
246
|
+
error-to-test refine ./initial-analysis --profile ./review-profile.json --reviewed --out ./refined-reviewed
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
Only groups represented by the source bundle's selected candidates are regenerated, in their saved order. Broad profile rules cannot add previously excluded groups; several matching rules can create several cases for a selected group. All observed groups, source fingerprints, coverage, and baseline/group selection metadata are preserved. To change the selected groups, original metadata, filters, or ranking, run `analyze` again with the original input.
|
|
250
|
+
|
|
251
|
+
The replacement profile is parsed as a complete profile, not merged with the old one. Its exact bytes, including one optional leading BOM, determine the new profile hash; the 1 MiB profile limit applies. The source is read once as a verified snapshot. `analysis.refinement` records the immediate source analysis/suite/profile hashes and previously selected group IDs; repeated refinement replaces this lineage entry rather than embedding history.
|
|
252
|
+
|
|
253
|
+
Saved full-group context questions and conflicts remain blockers even when they came from records outside the five representative samples. Bundles without complete saved group context, empty selections, changed artifacts, invalid profiles, or unsupported data are rejected. Reanalyze original logs to upgrade older bundles missing that context. No source defect is marked resolved and no browser is executed.
|
|
254
|
+
|
|
255
|
+
The output must be a new directory outside the entire source bundle, including path aliases; source artifacts and linked results remain untouched. Linked runs are not copied. Review acknowledgement defaults to pending even if the old bundle was reviewed. `--reviewed` only acknowledges the new review and does not clear missing context.
|
|
256
|
+
|
|
257
|
+
Original input bytes are not rechecked by `refine`; retained fingerprints describe the supplied saved analysis. If originals are available, use `verify ./refined --input ... --profile ./review-profile.json` to check them separately. The command requires `--profile` and `--out`; analyze-only filters and selection options are not accepted.
|
|
258
|
+
|
|
259
|
+
```js
|
|
260
|
+
import { readFile } from 'node:fs/promises';
|
|
261
|
+
import { refineBundle, writeBundle } from '@ihyeon/error-to-test';
|
|
262
|
+
|
|
263
|
+
const profileText = await readFile('./review-profile.json', 'utf8');
|
|
264
|
+
const analysis = await refineBundle('./initial-analysis', profileText);
|
|
265
|
+
await writeBundle('./refined', analysis); // Review remains pending by default.
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
`refineBundle(directory, profileText)` accepts JSON text and returns a new `Analysis`. It does not write files, approve cases, or change process exit codes. Use a separate new output directory when writing the result.
|
|
269
|
+
|
|
236
270
|
## Review and use Flow QA
|
|
237
271
|
|
|
238
272
|
Generated files (Flow QA source is limited to 128 KB; suite JSON to 512 KiB):
|
package/dist/artifacts.js
CHANGED
|
@@ -30,6 +30,15 @@ export function renderReport(analysis) {
|
|
|
30
30
|
'The source SHA-256 commits to the ordered file hashes and byte lengths. Verify with every original file in the same order.',
|
|
31
31
|
...analysis.source.inputs.map((input, index) => `${index + 1}. SHA-256: ${input.sha256} · Bytes: ${input.byteLength}`),
|
|
32
32
|
].join('\n')), '');
|
|
33
|
+
if (analysis.refinement)
|
|
34
|
+
lines.push('## Profile refinement', '', literal([
|
|
35
|
+
`Source analysis SHA-256: ${analysis.refinement.sourceAnalysisSha256}`,
|
|
36
|
+
...(analysis.refinement.sourceSuiteSha256 ? [`Source suite SHA-256: ${analysis.refinement.sourceSuiteSha256}`] : []),
|
|
37
|
+
...(analysis.refinement.sourceProfileSha256 ? [`Source profile SHA-256: ${analysis.refinement.sourceProfileSha256}`] : []),
|
|
38
|
+
`Previously selected group IDs: ${analysis.refinement.selectedGroupIds.join(', ')}`,
|
|
39
|
+
'TCs were regenerated from the verified saved groups and a replacement profile. Original input was not rechecked; selection and source coverage were not expanded.',
|
|
40
|
+
'The new bundle has its own review acknowledgement and suite. Linked run results were not transferred.',
|
|
41
|
+
].join('\n')), '');
|
|
33
42
|
if (analysis.groupFilter)
|
|
34
43
|
lines.push('## Explicit group selection', '', literal([
|
|
35
44
|
`Requested group IDs: ${analysis.groupFilter.groupIds.join(', ')}`,
|
package/dist/cli.js
CHANGED
|
@@ -11,6 +11,7 @@ import { redactText } from "./redact.js";
|
|
|
11
11
|
import { linkFlowQaReport } from "./results.js";
|
|
12
12
|
import { readRunSummary, renderRunSummary } from "./run-summary.js";
|
|
13
13
|
import { readReadiness, renderReadiness } from "./readiness.js";
|
|
14
|
+
import { refineBundle } from "./refinement.js";
|
|
14
15
|
const help = `Error to Test — local error analysis and regression TC drafts
|
|
15
16
|
|
|
16
17
|
error-to-test analyze --input errors-1.json --input errors-2.json --profile profile.json --out new-directory
|
|
@@ -23,6 +24,7 @@ const help = `Error to Test — local error analysis and regression TC drafts
|
|
|
23
24
|
error-to-test verify new-directory [--input errors-1.json --input errors-2.json] [--profile profile.json]
|
|
24
25
|
error-to-test init-profile new-directory --out profile.json
|
|
25
26
|
error-to-test init-profile new-directory --profile existing.json --out extended.json
|
|
27
|
+
error-to-test refine new-directory --profile updated.json --out refined-directory [--reviewed]
|
|
26
28
|
error-to-test link-run new-directory --report path/to/qa-report.json
|
|
27
29
|
error-to-test results new-directory [--format text|json] [--out summary.md]
|
|
28
30
|
error-to-test readiness new-directory [--format text|json]
|
|
@@ -36,6 +38,7 @@ Options:
|
|
|
36
38
|
--format text|json Compare format (default: text Markdown)
|
|
37
39
|
--format text|json Readiness format (default: text Markdown; exit 0 ready, 2 blocked/empty, 1 on error)
|
|
38
40
|
--profile FILE Confirmed app scenarios and explicit assertions (analyze/verify); existing profile to extend (init-profile)
|
|
41
|
+
--profile FILE Replacement profile for the bundle's previously selected groups (refine; required)
|
|
39
42
|
--baseline DIRECTORY Select only signatures absent from this verified bundle, before --min-count and --top; retain all groups in analysis.json (analyze only)
|
|
40
43
|
--project NAME Metadata for a manual report
|
|
41
44
|
--environment NAME Metadata for a manual report
|
|
@@ -52,6 +55,7 @@ Options:
|
|
|
52
55
|
--group GROUP_ID Select TCs only for these exact current group IDs; repeat up to 100 times (analyze only; before --min-count/--top)
|
|
53
56
|
--top N Generate TCs for the first N eligible ranked groups (1..100; after --min-count)
|
|
54
57
|
--out DIRECTORY New analyze directory; existing files are never overwritten
|
|
58
|
+
--out DIRECTORY New refine directory outside the source bundle (required; review defaults to pending)
|
|
55
59
|
--out FILE New init-profile JSON file; existing files are never overwritten
|
|
56
60
|
--out FILE New results summary file; existing files are never overwritten
|
|
57
61
|
--out FILE New comparison file; existing files are never overwritten
|
|
@@ -142,6 +146,10 @@ function insideBundleResults(bundleRoot, path) {
|
|
|
142
146
|
return false;
|
|
143
147
|
return rest.split(sep, 1)[0]?.toLowerCase() === 'results';
|
|
144
148
|
}
|
|
149
|
+
function insideBundle(bundleRoot, path) {
|
|
150
|
+
const rest = relative(bundleRoot.toLowerCase(), path.toLowerCase());
|
|
151
|
+
return rest === '' || (rest !== '..' && !rest.startsWith(`..${sep}`) && !isAbsolute(rest));
|
|
152
|
+
}
|
|
145
153
|
export async function main(args = process.argv.slice(2)) {
|
|
146
154
|
const { values, positionals } = parseArgs({ args, allowPositionals: true, strict: true, options: {
|
|
147
155
|
help: { type: 'boolean', short: 'h' }, version: { type: 'boolean', short: 'v' }, input: { type: 'string', multiple: true }, error: { type: 'string' }, report: { type: 'string' },
|
|
@@ -162,11 +170,26 @@ export async function main(args = process.argv.slice(2)) {
|
|
|
162
170
|
}
|
|
163
171
|
if (positionals.length === 0) {
|
|
164
172
|
if (Object.keys(values).length)
|
|
165
|
-
throw new Error('A command is required. Use analyze, init-profile, verify, link-run, results, compare, or readiness. See --help.');
|
|
173
|
+
throw new Error('A command is required. Use analyze, init-profile, refine, verify, link-run, results, compare, or readiness. See --help.');
|
|
166
174
|
process.stdout.write(help);
|
|
167
175
|
return;
|
|
168
176
|
}
|
|
169
177
|
const command = positionals[0];
|
|
178
|
+
if (command === 'refine') {
|
|
179
|
+
if (positionals.length !== 2 || !positionals[1]?.trim() || !values.profile?.trim() || !values.out?.trim())
|
|
180
|
+
throw new Error('refine requires one bundle directory, --profile FILE, and --out DIRECTORY.');
|
|
181
|
+
if (Object.keys(values).some(key => !['profile', 'out', 'reviewed', 'help'].includes(key)))
|
|
182
|
+
throw new Error('Unsupported option for refine. Use only --profile FILE, --out DIRECTORY, and --reviewed.');
|
|
183
|
+
const bundle = resolve(positionals[1]);
|
|
184
|
+
const out = resolve(values.out);
|
|
185
|
+
if (insideBundle(await realpath(bundle), await canonicalOutput(out)))
|
|
186
|
+
throw new Error('The refined output must be outside the source bundle. Choose a new --out DIRECTORY path.');
|
|
187
|
+
const analysis = await refineBundle(bundle, await readBoundedFile(resolve(values.profile), 1024 * 1024));
|
|
188
|
+
const files = await writeBundle(out, analysis, { reviewed: values.reviewed });
|
|
189
|
+
const drafts = analysis.candidates.filter(candidate => candidate.state === 'draft').length;
|
|
190
|
+
process.stdout.write(`${analysis.groups.length} error groups retained; ${analysis.candidates.length} refined TC candidates (${drafts} drafts, ${analysis.candidates.length - drafts} need context).\nReview ${resolve(out, 'report.md')}\n${files.length} artifacts written. Review acknowledgment: ${values.reviewed ? 'yes' : 'pending'}. Original input was not rechecked.\n`);
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
170
193
|
if (command === 'init-profile') {
|
|
171
194
|
if (positionals.length !== 2 || !positionals[1] || !values.out)
|
|
172
195
|
throw new Error('init-profile requires one bundle directory and --out FILE.');
|
|
@@ -339,7 +362,7 @@ export async function main(args = process.argv.slice(2)) {
|
|
|
339
362
|
return;
|
|
340
363
|
}
|
|
341
364
|
if (command !== 'analyze' || positionals.length !== 1)
|
|
342
|
-
throw new Error('Use analyze, init-profile, verify, link-run, results, compare, or readiness. See --help.');
|
|
365
|
+
throw new Error('Use analyze, init-profile, refine, verify, link-run, results, compare, or readiness. See --help.');
|
|
343
366
|
if (values.report)
|
|
344
367
|
throw new Error('--report applies to link-run only.');
|
|
345
368
|
if (values['max-new'] !== undefined)
|
package/dist/index.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export { exportFlowQa } from './exports/flow-qa.ts';
|
|
|
6
6
|
export { writeBundle, verifyBundle, renderReport } from './artifacts.ts';
|
|
7
7
|
export { linkFlowQaReport } from './results.ts';
|
|
8
8
|
export { createProfileTemplate, type ProfileTemplateOptions } from './profile-template.ts';
|
|
9
|
+
export { refineBundle } from './refinement.ts';
|
|
9
10
|
export { readRunSummary, renderRunSummary, type RunSummary, type LinkedRunStatus, type LinkedCaseStatus } from './run-summary.ts';
|
|
10
11
|
export { readReadiness, renderReadiness, type ReadinessSummary } from './readiness.ts';
|
|
11
12
|
export { compareBundles, renderComparison, type AnalysisComparison, type ComparisonStatus, type ComparisonSide, type ComparisonOccurrence, type ComparisonIssue } from './comparison.ts';
|
package/dist/index.js
CHANGED
|
@@ -6,6 +6,7 @@ export { exportFlowQa } from "./exports/flow-qa.js";
|
|
|
6
6
|
export { writeBundle, verifyBundle, renderReport } from "./artifacts.js";
|
|
7
7
|
export { linkFlowQaReport } from "./results.js";
|
|
8
8
|
export { createProfileTemplate } from "./profile-template.js";
|
|
9
|
+
export { refineBundle } from "./refinement.js";
|
|
9
10
|
export { readRunSummary, renderRunSummary } from "./run-summary.js";
|
|
10
11
|
export { readReadiness, renderReadiness } from "./readiness.js";
|
|
11
12
|
export { compareBundles, renderComparison } from "./comparison.js";
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
import { readVerifiedBundle } from "./artifacts.js";
|
|
2
|
+
import { createCandidates, parseProfile } from "./candidates.js";
|
|
3
|
+
import { validateInputSource } from "./input-source.js";
|
|
4
|
+
import { redactText } from "./redact.js";
|
|
5
|
+
import { hash, parseWebSteps, record } from "./validation.js";
|
|
6
|
+
const sha256 = /^[a-f0-9]{64}$/;
|
|
7
|
+
const groupId = /^group-[a-f0-9]{16}$/;
|
|
8
|
+
const caseId = /^TC_[a-f0-9]{16}$/;
|
|
9
|
+
const eventTypes = new Set(['javascript', 'promise', 'react', 'console', 'http', 'network', 'manual']);
|
|
10
|
+
const runtimes = new Set(['browser', 'webview-ios', 'webview-android', 'unknown']);
|
|
11
|
+
const kinds = new Set(['browser-error-json', 'manual-json', 'manual-text', 'browser-error-jsonl', 'manual-jsonl']);
|
|
12
|
+
const refinementNote = 'Refinement: Original input records were not rechecked; group ranking and the existing TC selection were preserved. Candidates were regenerated from the verified snapshot and supplied profile.';
|
|
13
|
+
function invalid(label) { throw new Error(`Invalid analysis snapshot: ${label}.`); }
|
|
14
|
+
function string(value, label, allowEmpty = false) {
|
|
15
|
+
if (typeof value !== 'string' || (!allowEmpty && !value.trim()))
|
|
16
|
+
invalid(label);
|
|
17
|
+
}
|
|
18
|
+
function optionalString(value, label) {
|
|
19
|
+
if (value !== undefined)
|
|
20
|
+
string(value, label, true);
|
|
21
|
+
}
|
|
22
|
+
function strings(value, label) {
|
|
23
|
+
if (!Array.isArray(value))
|
|
24
|
+
invalid(label);
|
|
25
|
+
for (const [index, item] of value.entries())
|
|
26
|
+
string(item, `${label}[${index}]`, true);
|
|
27
|
+
}
|
|
28
|
+
function optionalStrings(value, label) {
|
|
29
|
+
if (value !== undefined)
|
|
30
|
+
strings(value, label);
|
|
31
|
+
}
|
|
32
|
+
function integer(value, label, minimum = 0) {
|
|
33
|
+
if (typeof value !== 'number' || !Number.isSafeInteger(value) || value < minimum)
|
|
34
|
+
invalid(label);
|
|
35
|
+
}
|
|
36
|
+
function steps(value, label, required) {
|
|
37
|
+
if (value === undefined && !required)
|
|
38
|
+
return;
|
|
39
|
+
if (!Array.isArray(value))
|
|
40
|
+
invalid(label);
|
|
41
|
+
parseWebSteps(value, label);
|
|
42
|
+
}
|
|
43
|
+
function coverage(value, label) {
|
|
44
|
+
const raw = record(value, label);
|
|
45
|
+
if (!kinds.has(raw.kind) ||
|
|
46
|
+
raw.frequency !== (raw.kind === 'browser-error-json' || raw.kind === 'browser-error-jsonl' ? 'captured-events' : 'submitted-reports') ||
|
|
47
|
+
typeof raw.partial !== 'boolean' || raw.retention !== 'unknown')
|
|
48
|
+
invalid(label);
|
|
49
|
+
integer(raw.inputCount, `${label}.inputCount`, 1);
|
|
50
|
+
integer(raw.duplicates, `${label}.duplicates`);
|
|
51
|
+
integer(raw.filtered, `${label}.filtered`);
|
|
52
|
+
if (raw.period !== undefined) {
|
|
53
|
+
const period = record(raw.period, `${label}.period`);
|
|
54
|
+
optionalString(period.from, `${label}.period.from`);
|
|
55
|
+
optionalString(period.to, `${label}.period.to`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function observation(value, label) {
|
|
59
|
+
const raw = record(value, label);
|
|
60
|
+
for (const field of ['id', 'project', 'environment', 'release', 'message'])
|
|
61
|
+
string(raw[field], `${label}.${field}`);
|
|
62
|
+
if (raw.source !== 'browser-error' && raw.source !== 'manual')
|
|
63
|
+
invalid(`${label}.source`);
|
|
64
|
+
if (!eventTypes.has(raw.type) || !runtimes.has(raw.runtime))
|
|
65
|
+
invalid(`${label}.type/runtime`);
|
|
66
|
+
for (const field of ['name', 'stack', 'componentStack', 'page', 'occurredAt', 'viewId', 'expected', 'expectedSource']) {
|
|
67
|
+
optionalString(raw[field], `${label}.${field}`);
|
|
68
|
+
}
|
|
69
|
+
for (const field of ['reproduction', 'preconditions', 'questions'])
|
|
70
|
+
strings(raw[field], `${label}.${field}`);
|
|
71
|
+
steps(raw.steps, `${label}.steps`, true);
|
|
72
|
+
if (raw.network !== undefined) {
|
|
73
|
+
const network = record(raw.network, `${label}.network`);
|
|
74
|
+
string(network.method, `${label}.network.method`);
|
|
75
|
+
string(network.url, `${label}.network.url`);
|
|
76
|
+
if (network.status !== undefined) {
|
|
77
|
+
integer(network.status, `${label}.network.status`, 100);
|
|
78
|
+
if (network.status > 599)
|
|
79
|
+
invalid(`${label}.network.status`);
|
|
80
|
+
}
|
|
81
|
+
if (network.durationMs !== undefined && (typeof network.durationMs !== 'number' || !Number.isFinite(network.durationMs) || network.durationMs < 0)) {
|
|
82
|
+
invalid(`${label}.network.durationMs`);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function context(value, label, required) {
|
|
87
|
+
const missing = () => { throw new Error('Selected group lacks full source context. Reanalyze the original input before refining.'); };
|
|
88
|
+
if (value === undefined) {
|
|
89
|
+
if (required)
|
|
90
|
+
missing();
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
try {
|
|
94
|
+
const raw = record(value, label);
|
|
95
|
+
for (const field of ['expected', 'expectedSource'])
|
|
96
|
+
optionalString(raw[field], `${label}.${field}`);
|
|
97
|
+
for (const field of ['reproduction', 'preconditions'])
|
|
98
|
+
optionalStrings(raw[field], `${label}.${field}`);
|
|
99
|
+
steps(raw.steps, `${label}.steps`, false);
|
|
100
|
+
strings(raw.questions, `${label}.questions`);
|
|
101
|
+
strings(raw.conflicts, `${label}.conflicts`);
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
if (required)
|
|
105
|
+
missing();
|
|
106
|
+
throw error;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
function group(value, label, requireContext) {
|
|
110
|
+
const raw = record(value, label);
|
|
111
|
+
if (typeof raw.id !== 'string' || !groupId.test(raw.id))
|
|
112
|
+
invalid(`${label}.id`);
|
|
113
|
+
if (raw.fingerprintVersion !== 1)
|
|
114
|
+
invalid(`${label}.fingerprintVersion`);
|
|
115
|
+
for (const field of ['project', 'environment', 'release', 'signature', 'message'])
|
|
116
|
+
string(raw[field], `${label}.${field}`);
|
|
117
|
+
string(raw.pagePath, `${label}.pagePath`, true);
|
|
118
|
+
if (!eventTypes.has(raw.type) || !runtimes.has(raw.runtime))
|
|
119
|
+
invalid(`${label}.type/runtime`);
|
|
120
|
+
integer(raw.count, `${label}.count`, 1);
|
|
121
|
+
integer(raw.viewCount, `${label}.viewCount`);
|
|
122
|
+
if (raw.viewCount > raw.count)
|
|
123
|
+
invalid(`${label}.viewCount`);
|
|
124
|
+
optionalString(raw.lastOccurredAt, `${label}.lastOccurredAt`);
|
|
125
|
+
strings(raw.eventIds, `${label}.eventIds`);
|
|
126
|
+
if (raw.eventIds.length !== raw.count)
|
|
127
|
+
invalid(`${label}.eventIds`);
|
|
128
|
+
if (!Array.isArray(raw.evidence) || raw.evidence.length < 1 || raw.evidence.length > 5 || raw.evidence.length > raw.count)
|
|
129
|
+
invalid(`${label}.evidence`);
|
|
130
|
+
for (const [index, item] of raw.evidence.entries()) {
|
|
131
|
+
observation(item, `${label}.evidence[${index}]`);
|
|
132
|
+
if (!raw.eventIds.includes(item.id))
|
|
133
|
+
invalid(`${label}.evidence[${index}].id`);
|
|
134
|
+
}
|
|
135
|
+
context(raw.context, `${label}.context`, requireContext);
|
|
136
|
+
return raw;
|
|
137
|
+
}
|
|
138
|
+
function checkedAnalysis(value, provenance) {
|
|
139
|
+
const raw = record(value, 'analysis');
|
|
140
|
+
if (raw.schemaVersion !== 'error-to-test/analysis-1')
|
|
141
|
+
invalid('schemaVersion');
|
|
142
|
+
const source = record(raw.source, 'analysis.source');
|
|
143
|
+
validateInputSource(source);
|
|
144
|
+
if (source.profileSha256 !== undefined && (typeof source.profileSha256 !== 'string' || !sha256.test(source.profileSha256)))
|
|
145
|
+
invalid('source.profileSha256');
|
|
146
|
+
coverage(raw.coverage, 'analysis.coverage');
|
|
147
|
+
if (!Array.isArray(raw.groups) || !Array.isArray(raw.candidates))
|
|
148
|
+
invalid('groups/candidates');
|
|
149
|
+
strings(raw.warnings, 'analysis.warnings');
|
|
150
|
+
if (raw.selection !== undefined) {
|
|
151
|
+
const selection = record(raw.selection, 'analysis.selection');
|
|
152
|
+
if (selection.mode !== 'only-current')
|
|
153
|
+
invalid('selection.mode');
|
|
154
|
+
const baseline = record(selection.baseline, 'analysis.selection.baseline');
|
|
155
|
+
for (const field of ['inputSha256', 'analysisSha256']) {
|
|
156
|
+
if (typeof baseline[field] !== 'string' || !sha256.test(baseline[field]))
|
|
157
|
+
invalid(`selection.baseline.${field}`);
|
|
158
|
+
}
|
|
159
|
+
coverage(baseline.coverage, 'analysis.selection.baseline.coverage');
|
|
160
|
+
integer(selection.onlyCurrentGroupCount, 'analysis.selection.onlyCurrentGroupCount');
|
|
161
|
+
integer(selection.excludedGroupCount, 'analysis.selection.excludedGroupCount');
|
|
162
|
+
}
|
|
163
|
+
if (raw.groupFilter !== undefined) {
|
|
164
|
+
const filter = record(raw.groupFilter, 'analysis.groupFilter');
|
|
165
|
+
strings(filter.groupIds, 'analysis.groupFilter.groupIds');
|
|
166
|
+
if (filter.groupIds.some(id => !groupId.test(id)) || new Set(filter.groupIds).size !== filter.groupIds.length)
|
|
167
|
+
invalid('groupFilter.groupIds');
|
|
168
|
+
}
|
|
169
|
+
const selectedIds = new Set();
|
|
170
|
+
const candidateIds = new Set();
|
|
171
|
+
if (!Array.isArray(provenance.mappings) || provenance.mappings.length !== raw.candidates.length)
|
|
172
|
+
invalid('provenance.mappings');
|
|
173
|
+
for (const [index, value] of raw.candidates.entries()) {
|
|
174
|
+
const candidate = record(value, `analysis.candidates[${index}]`);
|
|
175
|
+
const mapping = record(provenance.mappings[index], `provenance.mappings[${index}]`);
|
|
176
|
+
if (typeof candidate.id !== 'string' || !caseId.test(candidate.id) || candidateIds.has(candidate.id))
|
|
177
|
+
invalid(`analysis.candidates[${index}].id`);
|
|
178
|
+
if (typeof candidate.groupId !== 'string' || !groupId.test(candidate.groupId))
|
|
179
|
+
invalid(`analysis.candidates[${index}].groupId`);
|
|
180
|
+
strings(candidate.eventIds, `analysis.candidates[${index}].eventIds`);
|
|
181
|
+
if (mapping.caseId !== candidate.id || mapping.candidateId !== candidate.id || mapping.groupId !== candidate.groupId ||
|
|
182
|
+
JSON.stringify(mapping.eventIds) !== JSON.stringify(candidate.eventIds))
|
|
183
|
+
invalid(`provenance.mappings[${index}]`);
|
|
184
|
+
candidateIds.add(candidate.id);
|
|
185
|
+
selectedIds.add(candidate.groupId);
|
|
186
|
+
}
|
|
187
|
+
if (!selectedIds.size)
|
|
188
|
+
throw new Error('Refinement requires at least one selected candidate group.');
|
|
189
|
+
const seenGroups = new Set();
|
|
190
|
+
const selectedGroups = [];
|
|
191
|
+
for (const [index, value] of raw.groups.entries()) {
|
|
192
|
+
const item = group(value, `analysis.groups[${index}]`, selectedIds.has(value?.id));
|
|
193
|
+
if (seenGroups.has(item.id))
|
|
194
|
+
invalid(`analysis.groups[${index}].id`);
|
|
195
|
+
seenGroups.add(item.id);
|
|
196
|
+
if (selectedIds.has(item.id))
|
|
197
|
+
selectedGroups.push(item);
|
|
198
|
+
}
|
|
199
|
+
if (selectedGroups.length !== selectedIds.size)
|
|
200
|
+
invalid('selected candidate group');
|
|
201
|
+
for (const [index, value] of raw.candidates.entries()) {
|
|
202
|
+
const candidate = value;
|
|
203
|
+
const selected = selectedGroups.find(item => item.id === candidate.groupId);
|
|
204
|
+
if (JSON.stringify(candidate.eventIds) !== JSON.stringify([...new Set(selected.eventIds)]))
|
|
205
|
+
invalid(`analysis.candidates[${index}].eventIds`);
|
|
206
|
+
}
|
|
207
|
+
return { analysis: raw, selectedGroups };
|
|
208
|
+
}
|
|
209
|
+
/** Rebuild candidates from a verified analysis snapshot without reading the original input or writing artifacts. */
|
|
210
|
+
export async function refineBundle(directory, profile) {
|
|
211
|
+
if (typeof profile !== 'string')
|
|
212
|
+
throw new Error('The profile must be JSON text.');
|
|
213
|
+
if (Buffer.byteLength(profile, 'utf8') > 1024 * 1024)
|
|
214
|
+
throw new Error('The profile must be 1 MiB or smaller.');
|
|
215
|
+
let parsed;
|
|
216
|
+
try {
|
|
217
|
+
parsed = JSON.parse(profile.replace(/^\uFEFF/, ''));
|
|
218
|
+
}
|
|
219
|
+
catch {
|
|
220
|
+
throw new Error('The profile is not valid JSON.');
|
|
221
|
+
}
|
|
222
|
+
const appProfile = parseProfile(parsed);
|
|
223
|
+
if (appProfile.scenarios.some(rule => redactText(rule.id) !== rule.id ||
|
|
224
|
+
(rule.match.groupId !== undefined && redactText(rule.match.groupId) !== rule.match.groupId))) {
|
|
225
|
+
throw new Error('The profile contains sensitive scenario IDs; remove them before refining.');
|
|
226
|
+
}
|
|
227
|
+
const verified = await readVerifiedBundle(directory);
|
|
228
|
+
const { analysis, selectedGroups } = checkedAnalysis(verified.analysis, verified.provenance);
|
|
229
|
+
const candidates = createCandidates(selectedGroups, appProfile);
|
|
230
|
+
if (candidates.length > 100)
|
|
231
|
+
throw new Error(`Flow QA supports at most 100 cases; received ${candidates.length}. Narrow the selected scenario rules.`);
|
|
232
|
+
const sourceAnalysisSha256 = verified.provenance.analysisSha256;
|
|
233
|
+
if (typeof sourceAnalysisSha256 !== 'string' || !sha256.test(sourceAnalysisSha256))
|
|
234
|
+
invalid('provenance.analysisSha256');
|
|
235
|
+
const sourceSuiteSha256 = verified.provenance.suiteSha256;
|
|
236
|
+
if (sourceSuiteSha256 !== undefined && (typeof sourceSuiteSha256 !== 'string' || !sha256.test(sourceSuiteSha256)))
|
|
237
|
+
invalid('provenance.suiteSha256');
|
|
238
|
+
const sourceProfileSha256 = verified.provenance.profileSha256;
|
|
239
|
+
if (sourceProfileSha256 !== undefined && (typeof sourceProfileSha256 !== 'string' || !sha256.test(sourceProfileSha256)))
|
|
240
|
+
invalid('provenance.profileSha256');
|
|
241
|
+
return {
|
|
242
|
+
...analysis,
|
|
243
|
+
source: { ...analysis.source, profileSha256: hash(profile) },
|
|
244
|
+
candidates,
|
|
245
|
+
warnings: [...analysis.warnings.filter(note => !note.startsWith('Refinement:')), refinementNote],
|
|
246
|
+
refinement: { sourceAnalysisSha256, ...(sourceSuiteSha256 === undefined ? {} : { sourceSuiteSha256 }),
|
|
247
|
+
...(sourceProfileSha256 === undefined ? {} : { sourceProfileSha256 }), selectedGroupIds: selectedGroups.map(item => item.id) },
|
|
248
|
+
};
|
|
249
|
+
}
|
package/dist/types.d.ts
CHANGED
|
@@ -182,6 +182,12 @@ export interface Analysis {
|
|
|
182
182
|
groupFilter?: {
|
|
183
183
|
groupIds: string[];
|
|
184
184
|
};
|
|
185
|
+
refinement?: {
|
|
186
|
+
sourceAnalysisSha256: string;
|
|
187
|
+
sourceSuiteSha256?: string;
|
|
188
|
+
sourceProfileSha256?: string;
|
|
189
|
+
selectedGroupIds: string[];
|
|
190
|
+
};
|
|
185
191
|
}
|
|
186
192
|
export interface FlowQaSuite {
|
|
187
193
|
schemaVersion: 'flow-qa/suite-1';
|
package/package.json
CHANGED