@ihyeon/error-to-test 0.5.4 → 0.5.6

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 CHANGED
@@ -121,6 +121,8 @@ error-to-test compare ./before ./current
121
121
  error-to-test compare ./before ./current --format json --out ./comparison.json
122
122
  ```
123
123
 
124
+ 이전 기준본에서 호출 위치가 다른 오류가 같은 메시지로 묶였거나 밀리초보다 정밀한 시간 범위로 필터링했다면, 기준본과 비교본의 원본 로그를 모두 0.5.6 이상으로 다시 분석한 뒤 `compare`나 `--max-new`를 실행하세요. 저장된 번들에는 생성 당시의 그룹과 시간 범위가 남습니다.
125
+
124
126
  현재에만 있는 서명(`only-current`), 양쪽에 있는 서명(`both`), 이전에만 있는 서명(`only-baseline`)으로 나누고 제공된 로그 건수와 증감을 보여줍니다. 릴리스만 제외하고 프로젝트·환경·실행 환경·오류 유형·페이지 경로·전체 오류 서명이 일치해야 합니다. 메시지나 소스 위치가 바뀌면 별도 서명이며, 비슷한 문장을 같은 원인으로 추정하지 않습니다.
125
127
 
126
128
  TC 생성 대상에서 제외된 묶음도 모두 비교합니다. 한쪽에 여러 릴리스가 있으면 같은 비교 키의 건수를 합산하고 원래 묶음 ID·릴리스 목록을 남깁니다. 단일 릴리스끼리 비교하려면 먼저 `analyze --release`로 범위를 정하세요. 페이지 조회 수는 합산하지 않습니다.
@@ -308,10 +310,13 @@ SDK가 반환한 오류 ID에서 그룹·TC 후보·검토 차단 사유·최근
308
310
  ```sh
309
311
  error-to-test trace ./review-analysis --event-id "YOUR_EVENT_ID"
310
312
  error-to-test trace ./review-analysis --event-id "YOUR_EVENT_ID" --project "YOUR_PROJECT"
313
+ error-to-test trace ./review-analysis --reference '{"project":"YOUR_PROJECT","eventId":"YOUR_EVENT_ID"}'
311
314
  error-to-test trace ./review-analysis --event-id "YOUR_EVENT_ID" --format json
312
315
  error-to-test trace ./review-analysis --event-id "YOUR_EVENT_ID" --target-fingerprint "$TARGET_FINGERPRINT"
313
316
  ```
314
317
 
318
+ Browser Error Log에서 복사한 JSON을 `--reference`에 붙여 넣으면 공백이나 따옴표가 포함된 프로젝트 이름과 오류 ID까지 그대로 조회합니다. `--reference`와 개별 ID·프로젝트 옵션은 함께 사용하지 않습니다.
319
+
315
320
  `error-to-test/trace-1`은 여러 프로젝트에서 같은 ID를 썼다면 일치하는 그룹을 모두 반환합니다. `--project`로 프로젝트 이름을 정확히 지정하면 그 프로젝트만 조회하며, ID가 다른 프로젝트에만 있으면 `found: false`와 종료 코드 2를 반환합니다. 미선택·차단·검토 준비와 최근 실행에서 빠진 TC의 `not-run`을 구분하고, 실행 결과는 `results`와 동일한 대상 범위·최근 실행 규칙을 따릅니다. 오류 메시지나 스택 대신 ID·프로젝트·그룹·TC·상태와 입력 해시, 부분 수집 여부, 보존 범위 미확인 경고를 표시합니다. ID가 저장된 분석 입력에 없으면 `found: false`와 종료 코드 2를 반환합니다. 서비스 전체에서 발생하지 않았다는 뜻은 아닙니다. 잘못된 번들·옵션은 코드 1입니다. 원본 바이트는 필요 시 `verify --input`으로 확인하세요. API는 `readEventTrace(directory, eventId, { project, targetFingerprint })`와 `renderEventTrace(trace)`입니다.
316
321
 
317
322
  Flow QA 설치와 실행 대상 설정은 별도로 필요합니다. 위 `flows/`·`cases/` 구조를 기존 검토 화면에서 읽을 수 있습니다. 분석 명령은 브라우저를 실행하거나 외부 모델에 요청하지 않습니다. TC 통과만으로 원래 오류를 수정 완료 처리하지 않습니다.
package/README.md CHANGED
@@ -133,6 +133,8 @@ error-to-test compare ./before ./current
133
133
  error-to-test compare ./before ./current --format json --out ./comparison.json
134
134
  ```
135
135
 
136
+ If an older baseline grouped distinct source locations under the same error message, reanalyze the original logs for both snapshots with 0.5.6 or later before running `compare` or `--max-new`. Do the same for older analyses filtered with sub-millisecond time bounds. A saved bundle retains the groups and time window computed when it was created.
137
+
136
138
  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.
137
139
 
138
140
  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.
@@ -402,10 +404,13 @@ Use the ID shown by Browser Error Log to find its observed groups, selected TC c
402
404
  ```sh
403
405
  error-to-test trace ./analysis --event-id "YOUR_EVENT_ID"
404
406
  error-to-test trace ./analysis --event-id "YOUR_EVENT_ID" --project "YOUR_PROJECT"
407
+ error-to-test trace ./analysis --reference '{"project":"YOUR_PROJECT","eventId":"YOUR_EVENT_ID"}'
405
408
  error-to-test trace ./analysis --event-id "YOUR_EVENT_ID" --format json
406
409
  error-to-test trace ./analysis --event-id "YOUR_EVENT_ID" --target-fingerprint "$TARGET_FINGERPRINT"
407
410
  ```
408
411
 
412
+ Paste the JSON copied from Browser Error Log into `--reference` to match its exact project and event ID, including spaces and quotes. Use `--reference` or the separate ID and project options.
413
+
409
414
  The read-only `error-to-test/trace-1` result includes all matching groups because two projects can reuse an ID. Pass `--project` to match one exact project name; an ID found only in other projects then yields `found: false` and exit `2`. It retains `unselected`, `blocked`, and `review-ready` states; a selected case omitted from the latest linked run is `not-run`. Linked results use the same latest-run and target-scope rules as `results`. Output includes source hashes, partial-export status, and unknown retention without copying error messages or stacks. An ID missing from the saved input yields `found: false` and CLI exit `2`; it does not establish that the event never occurred or was never collected. Invalid bundles, linked results, or options exit `1`. Original input bytes can be rechecked with `verify --input` when available.
410
415
 
411
416
  The API is `await readEventTrace(directory, eventId, { project, targetFingerprint })` and `renderEventTrace(trace)`. Omit the options argument to use all projects and the latest linked run across all targets. `trace` reads the verified snapshot and writes no files.
package/dist/cli.js CHANGED
@@ -38,7 +38,7 @@ const help = `Error to Test — local error analysis and regression TC drafts
38
38
  error-to-test results new-directory [--format text|json] [--out summary.md] [--target-fingerprint SHA256] [--require-pass | --fail-on STATUS ...]
39
39
  error-to-test readiness new-directory [--format text|json]
40
40
  error-to-test coverage new-directory [--format text|json]
41
- error-to-test trace new-directory --event-id ID [--project NAME] [--format text|json] [--target-fingerprint SHA256]
41
+ error-to-test trace new-directory (--event-id ID [--project NAME] | --reference JSON) [--format text|json] [--target-fingerprint SHA256]
42
42
  error-to-test compare BASELINE CURRENT [--format text|json] [--out comparison.md] [--max-new N]
43
43
 
44
44
  Options:
@@ -53,6 +53,7 @@ Options:
53
53
  --format text|json Readiness format (default: text Markdown; exit 0 ready, 2 blocked/empty, 1 on error)
54
54
  --format text|json Observed group coverage format (default: text Markdown; read-only, no gate)
55
55
  --event-id ID Trace an SDK event ID within one saved analysis (exit 2 when absent)
56
+ --reference JSON Trace a copied Browser Error Log {project,eventId} reference
56
57
  --project NAME Scope trace matches to one exact project name
57
58
  --target-fingerprint SHA256 Scope trace outcomes to this linked target fingerprint
58
59
  --profile FILE Confirmed app scenarios and explicit assertions (analyze/verify); existing profile to extend (init-profile)
@@ -189,7 +190,7 @@ export async function main(args = process.argv.slice(2)) {
189
190
  help: { type: 'boolean', short: 'h' }, version: { type: 'boolean', short: 'v' }, input: { type: 'string', multiple: true }, error: { type: 'string' }, report: { type: 'string' },
190
191
  format: { type: 'string' }, profile: { type: 'string' }, baseline: { type: 'string' }, project: { type: 'string' }, environment: { type: 'string' },
191
192
  release: { type: 'string' }, page: { type: 'string' }, type: { type: 'string' }, runtime: { type: 'string' }, from: { type: 'string' }, to: { type: 'string' },
192
- top: { type: 'string' }, 'min-count': { type: 'string' }, 'max-new': { type: 'string' }, group: { type: 'string', multiple: true }, 'fail-on': { type: 'string', multiple: true }, 'require-pass': { type: 'boolean' }, 'target-fingerprint': { type: 'string' }, 'event-id': { type: 'string' }, out: { type: 'string' }, reviewed: { type: 'boolean' },
193
+ top: { type: 'string' }, 'min-count': { type: 'string' }, 'max-new': { type: 'string' }, group: { type: 'string', multiple: true }, 'fail-on': { type: 'string', multiple: true }, 'require-pass': { type: 'boolean' }, 'target-fingerprint': { type: 'string' }, 'event-id': { type: 'string' }, reference: { type: 'string' }, out: { type: 'string' }, reviewed: { type: 'boolean' },
193
194
  draft: { type: 'string' }, port: { type: 'string' },
194
195
  reproduce: { type: 'string', multiple: true }, precondition: { type: 'string', multiple: true },
195
196
  expected: { type: 'string' }, 'expected-source': { type: 'string' },
@@ -458,17 +459,45 @@ export async function main(args = process.argv.slice(2)) {
458
459
  return;
459
460
  }
460
461
  if (command === 'trace') {
461
- if (positionals.length !== 2 || !positionals[1]?.trim() || !values['event-id']?.trim()) {
462
- throw new Error('trace requires one bundle directory and --event-id ID.');
462
+ if (positionals.length !== 2 || !positionals[1]?.trim() ||
463
+ (values['event-id'] === undefined) === (values.reference === undefined)) {
464
+ throw new Error('trace requires one bundle directory and exactly one of --event-id ID or --reference JSON.');
463
465
  }
464
- if (Object.keys(values).some(key => !['event-id', 'project', 'format', 'target-fingerprint', 'help'].includes(key))) {
465
- throw new Error('Unsupported option for trace. Use only --event-id ID, --project NAME, --format text|json, and --target-fingerprint SHA256.');
466
+ if (Object.keys(values).some(key => !['event-id', 'reference', 'project', 'format', 'target-fingerprint', 'help'].includes(key))) {
467
+ throw new Error('Unsupported option for trace. Use only --event-id ID, --reference JSON, --project NAME, --format text|json, and --target-fingerprint SHA256.');
466
468
  }
467
469
  const format = values.format ?? 'text';
468
470
  if (format !== 'text' && format !== 'json')
469
471
  throw new Error('trace --format must be text or json.');
470
- const trace = await readEventTrace(resolve(positionals[1]), values['event-id'], {
471
- project: values.project, targetFingerprint: values['target-fingerprint'],
472
+ if (values.reference !== undefined && values.project !== undefined) {
473
+ throw new Error('Use --reference on its own; it already contains the project and event ID.');
474
+ }
475
+ let eventId = values['event-id'];
476
+ let project = values.project;
477
+ if (values.reference !== undefined) {
478
+ if (Buffer.byteLength(values.reference, 'utf8') > 64 * 1024) {
479
+ throw new Error('--reference JSON must be 64 KiB or smaller.');
480
+ }
481
+ let parsed;
482
+ try {
483
+ parsed = JSON.parse(values.reference);
484
+ }
485
+ catch {
486
+ throw new Error('--reference requires a JSON object with project and eventId strings.');
487
+ }
488
+ if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
489
+ throw new Error('--reference requires a JSON object with project and eventId strings.');
490
+ }
491
+ const candidate = parsed;
492
+ if (typeof candidate.project !== 'string' || !candidate.project.trim() ||
493
+ typeof candidate.eventId !== 'string' || !candidate.eventId.trim()) {
494
+ throw new Error('--reference requires a JSON object with project and eventId strings.');
495
+ }
496
+ eventId = candidate.eventId;
497
+ project = candidate.project;
498
+ }
499
+ const trace = await readEventTrace(resolve(positionals[1]), eventId, {
500
+ project, targetFingerprint: values['target-fingerprint'],
472
501
  });
473
502
  const content = format === 'json' ? jsonText(trace) : renderEventTrace(trace);
474
503
  if (Buffer.byteLength(content) > 64 * 1024 * 1024)
@@ -583,6 +612,8 @@ export async function main(args = process.argv.slice(2)) {
583
612
  throw new Error('--target-fingerprint applies to results only.');
584
613
  if (values['event-id'] !== undefined)
585
614
  throw new Error('--event-id applies to trace only.');
615
+ if (values.reference !== undefined)
616
+ throw new Error('--reference applies to trace only.');
586
617
  if (values['max-new'] !== undefined)
587
618
  throw new Error('--max-new applies to compare only.');
588
619
  if (values.baseline !== undefined && values.baseline.trim() === '')
@@ -1,6 +1,6 @@
1
1
  import { fencedText, literal, readVerifiedBundle } from "./artifacts.js";
2
2
  import { pagePath, redactText } from "./redact.js";
3
- import { hash, record, timestamp } from "./validation.js";
3
+ import { compareTimestamps, hash, record, timestamp } from "./validation.js";
4
4
  const statuses = ['only-current', 'both', 'only-baseline'];
5
5
  const runtimes = ['browser', 'webview-ios', 'webview-android', 'unknown'];
6
6
  const types = ['javascript', 'promise', 'react', 'console', 'http', 'network', 'resource', 'manual'];
@@ -37,7 +37,7 @@ function coverage(value, label) {
37
37
  const p = record(raw.period, `${label}.period`);
38
38
  const from = p.from === undefined ? undefined : timestamp(p.from, `${label}.period.from`);
39
39
  const to = p.to === undefined ? undefined : timestamp(p.to, `${label}.period.to`);
40
- if (from && to && from > to)
40
+ if (from && to && compareTimestamps(from, to) > 0)
41
41
  throw new Error(`${label}.period.from exceeds to.`);
42
42
  if (!from && !to)
43
43
  throw new Error(`${label}.period must contain a bound.`);
package/dist/grouping.js CHANGED
@@ -1,18 +1,20 @@
1
1
  import { isDeepStrictEqual } from 'node:util';
2
- import { hash } from "./validation.js";
2
+ import { compareTimestamps, hash } from "./validation.js";
3
3
  import { pagePath } from "./redact.js";
4
- function sourceFrame(stack) {
4
+ function sourceFrame(stack, message) {
5
5
  if (!stack)
6
6
  return '';
7
7
  const lines = stack.split(/\r?\n/).map((line) => line.trim()).filter(Boolean);
8
- const frame = lines.find((line) => /\bat\s+|@|:\d+(?::\d+)?/.test(line));
8
+ const frame = lines.find((line) => line !== message && (/^at\s+\S/.test(line)
9
+ || /^[^@:]*@(?:.+:\d+|\[native code\])$/.test(line)
10
+ || /^(?:[a-z][\w+.-]*:\/\/|\.{0,2}\/|[A-Za-z]:[\\/]|[^\s:]+\.\w+)\S*:\d+$/.test(line)));
9
11
  return frame ?? '';
10
12
  }
11
13
  function signature(item) {
12
14
  const network = item.network;
13
15
  const site = network
14
16
  ? `${network.method.toUpperCase()} ${pagePath(network.url)} ${network.status ?? ''}`
15
- : sourceFrame(item.stack ?? item.componentStack);
17
+ : sourceFrame(item.stack, item.message) || sourceFrame(item.componentStack, item.message);
16
18
  return [item.name ?? '', item.message, site].join(' | ');
17
19
  }
18
20
  function sharedContext(observations) {
@@ -58,16 +60,16 @@ export function groupObservations(observations) {
58
60
  group.count++;
59
61
  group.eventIds.push(item.id);
60
62
  group.evidence.push(item);
61
- if (item.occurredAt && (!group.lastOccurredAt || item.occurredAt > group.lastOccurredAt))
63
+ if (item.occurredAt && (!group.lastOccurredAt || compareTimestamps(item.occurredAt, group.lastOccurredAt) > 0))
62
64
  group.lastOccurredAt = item.occurredAt;
63
65
  }
64
66
  for (const group of groups.values()) {
65
67
  group.eventIds.sort();
66
68
  group.viewCount = new Set(group.evidence.map((item) => item.viewId).filter((id) => !!id)).size;
67
69
  group.context = sharedContext(group.evidence);
68
- group.evidence.sort((a, b) => (b.occurredAt ?? '').localeCompare(a.occurredAt ?? '') || a.id.localeCompare(b.id));
70
+ group.evidence.sort((a, b) => compareTimestamps(b.occurredAt, a.occurredAt) || a.id.localeCompare(b.id));
69
71
  group.evidence = group.evidence.slice(0, 5);
70
72
  }
71
73
  return [...groups.values()].sort((a, b) => b.viewCount - a.viewCount || b.count - a.count ||
72
- (b.lastOccurredAt ?? '').localeCompare(a.lastOccurredAt ?? '') || a.id.localeCompare(b.id));
74
+ compareTimestamps(b.lastOccurredAt, a.lastOccurredAt) || a.id.localeCompare(b.id));
73
75
  }
package/dist/input.js CHANGED
@@ -1,4 +1,4 @@
1
- import { record, text, optionalText, strings, timestamp, parseWebSteps, hash } from "./validation.js";
1
+ import { compareTimestamps, record, text, optionalText, strings, timestamp, parseWebSteps, hash } from "./validation.js";
2
2
  import { redactText, safeUrl } from "./redact.js";
3
3
  import { inputSource } from "./input-source.js";
4
4
  const TYPES = new Set(['javascript', 'promise', 'react', 'console', 'http', 'network', 'resource', 'manual']);
@@ -257,7 +257,7 @@ export function parseInput(content, options = {}) {
257
257
  throw new Error('Input is empty');
258
258
  const from = options.from === undefined ? undefined : timestamp(options.from, 'from');
259
259
  const to = options.to === undefined ? undefined : timestamp(options.to, 'to');
260
- if (from && to && from > to)
260
+ if (from && to && compareTimestamps(from, to) > 0)
261
261
  throw new Error('from must not exceed to');
262
262
  if (!['auto', 'json', 'text', 'jsonl'].includes(format))
263
263
  throw new Error('Invalid input format');
@@ -334,8 +334,8 @@ export function parseInput(content, options = {}) {
334
334
  (!options.release || item.release === options.release) &&
335
335
  (!options.page || item.page === safeUrl(options.page)) &&
336
336
  (!options.type || item.type === options.type) &&
337
- (!from || !!item.occurredAt && item.occurredAt >= from) &&
338
- (!to || !!item.occurredAt && item.occurredAt <= to);
337
+ (!from || !!item.occurredAt && compareTimestamps(item.occurredAt, from) >= 0) &&
338
+ (!to || !!item.occurredAt && compareTimestamps(item.occurredAt, to) <= 0);
339
339
  if (!matches)
340
340
  filtered++;
341
341
  return matches;
@@ -1,5 +1,5 @@
1
1
  import { literal, readVerifiedBundle } from "./artifacts.js";
2
- import { record, timestamp } from "./validation.js";
2
+ import { compareTimestamps, record, timestamp } from "./validation.js";
3
3
  const MAX_REPORT_BYTES = 64 * 1024 * 1024;
4
4
  const groupIdPattern = /^group-[0-9a-f]{16}$/;
5
5
  const candidateIdPattern = /^[a-zA-Z0-9][a-zA-Z0-9_-]{0,79}$/;
@@ -46,7 +46,7 @@ function sourceCoverage(value) {
46
46
  invalid('coverage.period');
47
47
  const from = period.from === undefined ? undefined : timestamp(period.from, 'coverage.period.from');
48
48
  const to = period.to === undefined ? undefined : timestamp(period.to, 'coverage.period.to');
49
- if (from !== undefined && to !== undefined && from > to)
49
+ if (from !== undefined && to !== undefined && compareTimestamps(from, to) > 0)
50
50
  invalid('coverage.period order');
51
51
  if (from !== undefined)
52
52
  lines.push(`Period from: ${period.from}`);
package/dist/results.js CHANGED
@@ -2,7 +2,7 @@ import { randomUUID } from 'node:crypto';
2
2
  import { link, lstat, mkdir, rm, writeFile } from 'node:fs/promises';
3
3
  import { resolve } from 'node:path';
4
4
  import { jsonText, readVerifiedBundle } from "./artifacts.js";
5
- import { record, text, timestamp } from "./validation.js";
5
+ import { compareTimestamps, record, text, timestamp } from "./validation.js";
6
6
  import { redactText } from "./redact.js";
7
7
  import { reportedTargetIdentity, validateResultSelection } from "./result-selection.js";
8
8
  import { MAX_LINKED_RESULT_BYTES } from "./run-summary.js";
@@ -59,7 +59,7 @@ export async function linkFlowQaReport(directory, rawReport) {
59
59
  if (status === 'passed' && cases.some(item => item.status !== 'passed'))
60
60
  throw new Error('The report status contradicts its case results.');
61
61
  const startedAt = timestamp(report.startedAt, 'report.startedAt'), finishedAt = timestamp(report.finishedAt, 'report.finishedAt');
62
- if (finishedAt < startedAt)
62
+ if (compareTimestamps(finishedAt, startedAt) < 0)
63
63
  throw new Error('The run finished before its start timestamp.');
64
64
  const output = {
65
65
  schemaVersion: 'error-to-test/results-1', runId,
@@ -3,7 +3,7 @@ import { lstat, open, opendir } from 'node:fs/promises';
3
3
  import { join, resolve } from 'node:path';
4
4
  import { literal, readVerifiedBundle } from "./artifacts.js";
5
5
  import { redactText } from "./redact.js";
6
- import { record, text, timestamp } from "./validation.js";
6
+ import { compareTimestamps, record, text, timestamp } from "./validation.js";
7
7
  import { safeReportedTargetName, validatedTargetFingerprint, validateResultSelection } from "./result-selection.js";
8
8
  const runStatuses = new Set(['passed', 'failed', 'blocked', 'error', 'interrupted']);
9
9
  const caseStatuses = new Set(['passed', 'failed', 'flaky', 'blocked', 'skipped', 'error']);
@@ -96,7 +96,7 @@ function parseResult(content, name, inputSha256, suiteSha256, expected) {
96
96
  throw new Error(`Linked result ${name} has an invalid run status.`);
97
97
  const startedAt = timestamp(raw.startedAt, `${name}.startedAt`);
98
98
  const finishedAt = timestamp(raw.finishedAt, `${name}.finishedAt`);
99
- if (finishedAt < startedAt)
99
+ if (compareTimestamps(finishedAt, startedAt) < 0)
100
100
  throw new Error(`Linked result ${name} finished before it started.`);
101
101
  text(raw.note, `${name}.note`);
102
102
  const targetName = raw.targetName === undefined ? undefined : safeReportedTargetName(raw.targetName, `${name}.targetName`);
@@ -134,9 +134,9 @@ function parseResult(content, name, inputSha256, suiteSha256, expected) {
134
134
  }
135
135
  function later(a, b) {
136
136
  if (a.finishedAt !== b.finishedAt)
137
- return a.finishedAt > b.finishedAt;
137
+ return compareTimestamps(a.finishedAt, b.finishedAt) > 0;
138
138
  if (a.startedAt !== b.startedAt)
139
- return a.startedAt > b.startedAt;
139
+ return compareTimestamps(a.startedAt, b.startedAt) > 0;
140
140
  return a.runId > b.runId;
141
141
  }
142
142
  function nonnegativeCount(value, label) {
@@ -5,4 +5,6 @@ export declare function text(value: unknown, label: string, required?: boolean):
5
5
  export declare function optionalText(value: unknown, label: string): string | undefined;
6
6
  export declare function strings(value: unknown, label: string): string[];
7
7
  export declare function timestamp(value: unknown, label: string): string;
8
+ /** Compare timestamps normalized by timestamp(), including their sub-millisecond digits. */
9
+ export declare function compareTimestamps(left?: string, right?: string): number;
8
10
  export declare function parseWebSteps(value: unknown, label: string): WebStep[];
@@ -36,7 +36,21 @@ export function timestamp(value, label) {
36
36
  const local = new Date(parsed + offset * 60000);
37
37
  if (!Number.isFinite(parsed) || local.getUTCFullYear() !== year || local.getUTCMonth() + 1 !== month || local.getUTCDate() !== day || local.getUTCHours() !== hour || local.getUTCMinutes() !== minute || local.getUTCSeconds() !== second)
38
38
  throw new Error(`${label} is not a valid timestamp.`);
39
- return new Date(parsed).toISOString();
39
+ const utc = new Date(parsed).toISOString();
40
+ const fraction = match[7]?.padEnd(9, '0');
41
+ if (!fraction || fraction.slice(3) === '000000')
42
+ return utc;
43
+ return `${utc.slice(0, -4)}${fraction}Z`;
44
+ }
45
+ /** Compare timestamps normalized by timestamp(), including their sub-millisecond digits. */
46
+ export function compareTimestamps(left, right) {
47
+ if (!left || !right)
48
+ return Number(Boolean(left)) - Number(Boolean(right));
49
+ const milliseconds = Date.parse(left) - Date.parse(right);
50
+ if (milliseconds !== 0)
51
+ return Math.sign(milliseconds);
52
+ const fraction = (value) => Number(/\.([0-9]{3,9})Z$/.exec(value)?.[1]?.padEnd(9, '0') ?? '000000000');
53
+ return Math.sign(fraction(left) - fraction(right));
40
54
  }
41
55
  const roles = new Set(['button', 'link', 'textbox', 'heading', 'checkbox', 'radio', 'combobox', 'option', 'status', 'alert', 'dialog', 'tab', 'row', 'cell', 'list', 'listitem', 'navigation', 'searchbox', 'switch']);
42
56
  function exactKeys(raw, keys, label) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ihyeon/error-to-test",
3
- "version": "0.5.4",
3
+ "version": "0.5.6",
4
4
  "description": "Turn captured browser errors and pasted error reports into traceable regression test candidates.",
5
5
  "license": "MIT",
6
6
  "author": "Hyeonse Im",