@orkestrel/capture 0.0.8 → 0.0.9

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.
@@ -1,3 +1,83 @@
1
+ /**
2
+ * Builds the required output pair of each state an eligible owner-bearing case declares.
3
+ *
4
+ * @param cases - Every collected case, including cases a runner filter excluded
5
+ * @param rules - The host's part and source resolvers
6
+ * @param options - The producing project and the portfolio mapping of each state
7
+ * @returns One destination per declared state, in case and state order
8
+ * @throws Thrown as a `HOST` capture error when a state has no single mapping or resolves outside its case's owner or the scope, part, and optional section form.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * buildCaptureDestinations(cases, rules, { project: 'journey:light-390', portfolios })[0]?.file
13
+ * // 'tmp/captures/states/pages/inbox--light-390.png'
14
+ * ```
15
+ */
16
+ export declare function buildCaptureDestinations(cases: readonly CaptureCase[], rules: CaptureRules, options: CaptureDestinationOptions): readonly CaptureDestination[];
17
+
18
+ /**
19
+ * Builds a run record from collected cases, the run's destinations, and its observed and emitted states.
20
+ *
21
+ * @param options - The cases, registry, observed states, emitted state-to-path pairs, and execution context
22
+ * @returns The final record, without the journey artifact the caller binds after rendering it
23
+ * @throws Thrown as a `HOST` capture error for an owner-bearing case with no variant, and as an `EVIDENCE` capture error for an emitted state with no destination, a path other than its destination's file, or a producing case with no measured duration.
24
+ *
25
+ * @example
26
+ * ```ts
27
+ * const run = buildCaptureRun({ cases, registry, observed, emitted, variant: 'light-390', time })
28
+ * validateCaptureRun(run, readCaptureReport(parseJSON(text)), 'journey:light-390')
29
+ * ```
30
+ */
31
+ export declare function buildCaptureRun(options: CaptureRunOptions): CaptureRun;
32
+
33
+ /**
34
+ * Builds the owner and capture tags a wrapper declares for its owner population.
35
+ *
36
+ * @param owners - Every canonical owner path the host declares
37
+ * @returns The unique `owner:` tag of each owner and ancestor, and each owner's scope and part tags
38
+ * @throws Thrown as a `HOST` capture error naming each owner that is not a canonical selector.
39
+ *
40
+ * @example
41
+ * ```ts
42
+ * buildCaptureTags(['pages:mail'])
43
+ * // ['owner:pages', 'owner:pages:mail', 'pages', 'pages:mail']
44
+ * ```
45
+ */
46
+ export declare function buildCaptureTags(owners: readonly string[]): readonly string[];
47
+
48
+ /**
49
+ * Builds the Vitest test options of one capture case from its declaration.
50
+ *
51
+ * @param input - The case's owner, states, producing variant, and harness values
52
+ * @param rules - The host's owners and part resolver
53
+ * @returns The derived tags, the capture metadata, and the optional timeout
54
+ * @throws Thrown as a `HOST` capture error for an undeclared owner or tag, tags beside an owner, capture tags with no states, or a state whose part is undeclared or outside the owner.
55
+ *
56
+ * @example
57
+ * ```ts
58
+ * buildCaptureTest({ owner: 'pages:mail', states: ['inbox'], variant: 'light-390' }, rules).tags
59
+ * // ['owner:pages', 'owner:pages:mail', 'pages', 'pages:mail']
60
+ * ```
61
+ */
62
+ export declare function buildCaptureTest(input: CaptureTestInput, rules: CaptureRules): CaptureTestOptions;
63
+
64
+ /**
65
+ * Names the journey artifact line prefixes that bind a run record and each case that ran.
66
+ *
67
+ * @remarks
68
+ * The preflight reader requires the line `record=<record path>` and one `case-ran=<full name>`
69
+ * line for each stamping case.
70
+ *
71
+ * @example
72
+ * ```ts
73
+ * `${CAPTURE_ARTIFACT_PREFIXES.case}mail opens the inbox` // 'case-ran=mail opens the inbox'
74
+ * ```
75
+ */
76
+ export declare const CAPTURE_ARTIFACT_PREFIXES: Readonly<{
77
+ readonly record: 'record=';
78
+ readonly case: 'case-ran=';
79
+ }>;
80
+
1
81
  /**
2
82
  * Keys the global brand a capture error carries, so a duplicate installation recognizes it.
3
83
  *
@@ -49,6 +129,16 @@ export declare const CAPTURE_LOOKUPS_FILE = "lookups.json";
49
129
  */
50
130
  export declare const CAPTURE_MANIFEST_FILE = "manifest.json";
51
131
 
132
+ /**
133
+ * Names the tag prefix that marks a case's owner path and each ancestor of it.
134
+ *
135
+ * @example
136
+ * ```ts
137
+ * `${CAPTURE_OWNER_PREFIX}pages:mail` // 'owner:pages:mail'
138
+ * ```
139
+ */
140
+ export declare const CAPTURE_OWNER_PREFIX = "owner:";
141
+
52
142
  /**
53
143
  * Holds the eight bytes every PNG file opens with.
54
144
  *
@@ -116,6 +206,22 @@ export declare interface CaptureArtifact {
116
206
  readonly digest: string;
117
207
  }
118
208
 
209
+ /**
210
+ * Carries the run records a journey artifact binds and the cases it shows ran.
211
+ *
212
+ * @example
213
+ * ```ts
214
+ * const lines: CaptureArtifactLines = {
215
+ * records: ['tmp/captures/states/runs/run-1/selected/light-390.json'],
216
+ * cases: ['mail opens the inbox'],
217
+ * }
218
+ * ```
219
+ */
220
+ export declare interface CaptureArtifactLines {
221
+ readonly records: readonly string[];
222
+ readonly cases: readonly string[];
223
+ }
224
+
119
225
  /**
120
226
  * Carries the owner-bearing projection of a Vitest JSON assertion.
121
227
  *
@@ -152,6 +258,28 @@ export declare interface CaptureBox {
152
258
  readonly height: number;
153
259
  }
154
260
 
261
+ /**
262
+ * Carries one collected case, including a case a runner filter excluded.
263
+ *
264
+ * @example
265
+ * ```ts
266
+ * const entry: CaptureCase = {
267
+ * name: 'mail opens the inbox',
268
+ * mode: 'run',
269
+ * tags: ['owner:pages', 'owner:pages:mail', 'pages', 'pages:mail'],
270
+ * meta: { owner: 'pages:mail', states: ['inbox'], variant: 'light-390' },
271
+ * result: { state: 'pass', duration: 812 },
272
+ * }
273
+ * ```
274
+ */
275
+ export declare interface CaptureCase {
276
+ readonly name: string;
277
+ readonly mode: string;
278
+ readonly tags: readonly string[];
279
+ readonly meta: CaptureMeta;
280
+ readonly result?: CaptureTaskResult;
281
+ }
282
+
155
283
  /**
156
284
  * Binds a successful full collection to the unchanged complete anchor and exact evidence bytes.
157
285
  *
@@ -226,6 +354,19 @@ export declare interface CaptureDestination {
226
354
  readonly sources: CaptureSources;
227
355
  }
228
356
 
357
+ /**
358
+ * Configures the producing project and the portfolio mappings of a destination build.
359
+ *
360
+ * @example
361
+ * ```ts
362
+ * const options: CaptureDestinationOptions = { project: 'journey:light-390', portfolios: [mapping] }
363
+ * ```
364
+ */
365
+ export declare interface CaptureDestinationOptions {
366
+ readonly project: string;
367
+ readonly portfolios: readonly CaptureMapping[];
368
+ }
369
+
229
370
  /**
230
371
  * Records declared patterns, expanded file hashes, and their combined digest.
231
372
  *
@@ -423,6 +564,110 @@ export declare interface CaptureManifest {
423
564
  readonly lookups: readonly CaptureLookup[];
424
565
  }
425
566
 
567
+ /**
568
+ * Maps the states one portfolio writes to its output variant and physical root.
569
+ *
570
+ * @example
571
+ * ```ts
572
+ * const mapping: CaptureMapping = {
573
+ * portfolio: 'states',
574
+ * directory: 'tmp/captures/states',
575
+ * scoped: true,
576
+ * variant: 'light-390',
577
+ * states: ['inbox'],
578
+ * }
579
+ * ```
580
+ */
581
+ export declare interface CaptureMapping extends CapturePortfolioRoot {
582
+ readonly variant: string;
583
+ readonly states: readonly string[];
584
+ }
585
+
586
+ /**
587
+ * Declares the capture metadata a journey case carries in Vitest's task metadata.
588
+ *
589
+ * @remarks
590
+ * Extend Vitest's `TaskMeta` with it in the workspace's own module declaration, so a case's
591
+ * `meta` option and every collected task carry these fields.
592
+ *
593
+ * @example
594
+ * ```ts
595
+ * const meta: CaptureMeta = { owner: 'pages:mail', states: ['inbox'], variant: 'light-390' }
596
+ * ```
597
+ */
598
+ export declare interface CaptureMeta {
599
+ readonly owner?: string;
600
+ readonly states?: readonly string[];
601
+ readonly variant?: string;
602
+ readonly eligible?: boolean;
603
+ }
604
+
605
+ /**
606
+ * Resolves a declared state to the canonical owner path of the part that renders it.
607
+ *
608
+ * @remarks Throw for a state the host does not declare.
609
+ *
610
+ * @example
611
+ * ```ts
612
+ * const part: CapturePartHandler = (state) => (state.startsWith('inbox') ? 'pages:mail' : 'pages:board')
613
+ * ```
614
+ */
615
+ export declare type CapturePartHandler = (state: string) => string;
616
+
617
+ /**
618
+ * Supplies a host-authorized physical portfolio root without repeating its states or variants.
619
+ *
620
+ * @example
621
+ * ```ts
622
+ * const root: CapturePortfolioRoot = { portfolio: 'states', directory: 'tmp/captures/states', scoped: true }
623
+ * ```
624
+ */
625
+ export declare interface CapturePortfolioRoot {
626
+ readonly portfolio: string;
627
+ readonly directory: string;
628
+ readonly scoped: boolean;
629
+ }
630
+
631
+ /**
632
+ * Declares the values a journey wrapper provides to each project, which the runner and the suite read.
633
+ *
634
+ * @remarks
635
+ * Extend Vitest's `ProvidedContext` with it in the workspace's own module declaration. `request` is
636
+ * present only when a runner is the parent, and `capture` reports whether frames are written.
637
+ * `sources` holds the shared and test source patterns the suite attributes to every destination.
638
+ *
639
+ * @example
640
+ * ```ts
641
+ * const provided: CaptureProvided = {
642
+ * variant: 'light-390',
643
+ * variants: [{ name: 'light-390', width: 390, height: 844 }],
644
+ * directory: 'tmp/captures/states',
645
+ * record: 'tmp/captures/states/runs/run-1/selected/light-390.json',
646
+ * inputs: ['src/**'],
647
+ * sources: { shared: ['src/core/**'], tests: ['tests/**'] },
648
+ * final: 'closes the run',
649
+ * first: 'light-390',
650
+ * portfolios: [{ portfolio: 'states', directory: 'tmp/captures/states', scoped: true }],
651
+ * capture: false,
652
+ * }
653
+ * ```
654
+ */
655
+ export declare interface CaptureProvided {
656
+ readonly variant: string;
657
+ readonly variants: readonly CaptureViewport[];
658
+ readonly directory: string;
659
+ readonly record: string;
660
+ readonly inputs: readonly string[];
661
+ readonly sources: Pick<CaptureSources, 'shared' | 'tests'>;
662
+ readonly final: string;
663
+ readonly first: string;
664
+ readonly uniform?: readonly string[];
665
+ readonly portfolios: readonly CapturePortfolioRoot[];
666
+ readonly standalone?: readonly CapturePortfolioRoot[];
667
+ readonly capture: boolean;
668
+ readonly request?: CaptureRequest;
669
+ }
670
+
426
671
  /**
427
672
  * Binds a complete registry reading to its report and input hashes.
428
673
  *
@@ -499,6 +744,24 @@ export declare interface CaptureRequest extends CaptureSelection, CaptureIdentit
499
744
  readonly args: readonly string[];
500
745
  }
501
746
 
747
+ /**
748
+ * Supplies the host's owner population and its part and source resolvers.
749
+ *
750
+ * @remarks
751
+ * `owners` lists every canonical owner path the host declares. `part` and `sources` carry the
752
+ * product rules the package never infers.
753
+ *
754
+ * @example
755
+ * ```ts
756
+ * const rules: CaptureRules = { owners: ['pages:mail'], part: () => 'pages:mail', sources }
757
+ * ```
758
+ */
759
+ export declare interface CaptureRules {
760
+ readonly owners: readonly string[];
761
+ readonly part: CapturePartHandler;
762
+ readonly sources: CaptureSourcesHandler;
763
+ }
764
+
502
765
  /**
503
766
  * Records collected declarations, successful observations, and emitted output separately.
504
767
  *
@@ -524,6 +787,36 @@ export declare interface CaptureRun {
524
787
  readonly entries: readonly CaptureEntry[];
525
788
  }
526
789
 
790
+ /**
791
+ * Supplies the collected cases, the destinations, and the observed and emitted states of one run record.
792
+ *
793
+ * @remarks
794
+ * `observed` lists every state the run placed, whether or not it wrote a frame. `emitted` pairs
795
+ * each written state with the path its portfolio wrote. `time` is an ISO 8601 timestamp, and
796
+ * `request` is the runner request the wrapper provided.
797
+ *
798
+ * @example
799
+ * ```ts
800
+ * const options: CaptureRunOptions = {
801
+ * cases,
802
+ * registry,
803
+ * observed: ['inbox'],
804
+ * emitted: [['inbox', 'tmp/captures/states/pages/inbox--light-390.png']],
805
+ * variant: 'light-390',
806
+ * time: '2026-11-15T09:00:00.000Z',
807
+ * }
808
+ * ```
809
+ */
810
+ export declare interface CaptureRunOptions {
811
+ readonly cases: readonly CaptureCase[];
812
+ readonly registry: readonly CaptureDestination[];
813
+ readonly observed: readonly string[];
814
+ readonly emitted: ReadonlyArray<readonly [state: string, path: string]>;
815
+ readonly variant: string;
816
+ readonly time: string;
817
+ readonly request?: CaptureRequest;
818
+ }
819
+
527
820
  /**
528
821
  * Carries the selection fields a request and a parking check read.
529
822
  *
@@ -552,6 +845,18 @@ export declare interface CaptureSources {
552
845
  readonly tests: readonly string[];
553
846
  }
554
847
 
848
+ /**
849
+ * Resolves a canonical owner path to its own, shared, and behavioral source attribution.
850
+ *
851
+ * @remarks Throw for an owner the host does not attribute.
852
+ *
853
+ * @example
854
+ * ```ts
855
+ * const sources: CaptureSourcesHandler = (owner) => ({ own: [`src/${owner.split(':')[1]}/**`], shared: [], tests: [] })
856
+ * ```
857
+ */
858
+ export declare type CaptureSourcesHandler = (owner: string) => CaptureSources;
859
+
555
860
  /**
556
861
  * Stamps one emitted frame with execution, source, image, and registry provenance.
557
862
  *
@@ -602,6 +907,82 @@ export declare interface CaptureStoredManifest extends CaptureManifest {
602
907
  readonly collections?: readonly CaptureCollectionReceipt[];
603
908
  }
604
909
 
910
+ /**
911
+ * Mirrors the members of a Vitest file, suite, or test task that case collection reads.
912
+ *
913
+ * @remarks
914
+ * A Vitest `RunnerTask` satisfies it when the workspace's `TaskMeta` extends `CaptureMeta`. A task with
915
+ * `filepath` is a file, and a task with `tasks` is a file or a suite.
916
+ *
917
+ * @example
918
+ * ```ts
919
+ * const task: CaptureTask = { name: 'opens the inbox', mode: 'run', meta: { owner: 'pages:mail' } }
920
+ * ```
921
+ */
922
+ export declare interface CaptureTask {
923
+ readonly name: string;
924
+ readonly mode: string;
925
+ readonly tags?: readonly string[];
926
+ readonly meta: CaptureMeta;
927
+ readonly result?: CaptureTaskResult;
928
+ readonly filepath?: string;
929
+ readonly tasks?: readonly CaptureTask[];
930
+ }
931
+
932
+ /**
933
+ * Mirrors the members of Vitest's `TaskResult` that a run record reads.
934
+ *
935
+ * @example
936
+ * ```ts
937
+ * const result: CaptureTaskResult = { state: 'pass', duration: 812 }
938
+ * ```
939
+ */
940
+ export declare interface CaptureTaskResult {
941
+ readonly state: string;
942
+ readonly duration?: number;
943
+ }
944
+
945
+ /**
946
+ * Supplies one case's owner, states, producing variant, and harness registration values.
947
+ *
948
+ * @remarks
949
+ * An owner-bearing case derives its tags from its owner and states; a case without an owner, such
950
+ * as the final case, names its tags.
951
+ *
952
+ * @example
953
+ * ```ts
954
+ * const input: CaptureTestInput = { owner: 'pages:mail', states: ['inbox'], variant: 'light-390' }
955
+ * ```
956
+ */
957
+ export declare interface CaptureTestInput {
958
+ readonly owner?: string;
959
+ readonly states?: readonly string[];
960
+ readonly variant: string;
961
+ readonly eligible?: boolean;
962
+ readonly timeout?: number;
963
+ readonly tags?: readonly string[];
964
+ }
965
+
966
+ /**
967
+ * Carries the Vitest test options a capture case registers with.
968
+ *
969
+ * @remarks
970
+ * `tags` is a mutable array because Vitest's `TestOptions` declares its `tags` member that way.
971
+ *
972
+ * @example
973
+ * ```ts
974
+ * const options: CaptureTestOptions = {
975
+ * tags: ['owner:pages', 'owner:pages:mail', 'pages', 'pages:mail'],
976
+ * meta: { owner: 'pages:mail', states: ['inbox'], variant: 'light-390' },
977
+ * }
978
+ * ```
979
+ */
980
+ export declare interface CaptureTestOptions {
981
+ readonly tags: string[];
982
+ readonly meta: CaptureMeta;
983
+ readonly timeout?: number;
984
+ }
985
+
605
986
  /**
606
987
  * Declares a host viewport's name and pixel geometry without inferring it from a file name.
607
988
  *
@@ -629,6 +1010,34 @@ export declare interface CaptureWarning {
629
1010
  readonly cases: readonly string[];
630
1011
  }
631
1012
 
1013
+ /**
1014
+ * Expands an owner path into its prefixes, from its scope through the owner itself.
1015
+ *
1016
+ * @param owner - A canonical owner path
1017
+ * @returns Each colon-bounded prefix, shortest first
1018
+ *
1019
+ * @example
1020
+ * ```ts
1021
+ * collectCaptureAncestors('pages:mail:inbox') // ['pages', 'pages:mail', 'pages:mail:inbox']
1022
+ * ```
1023
+ */
1024
+ export declare function collectCaptureAncestors(owner: string): readonly string[];
1025
+
1026
+ /**
1027
+ * Collects every leaf case under a task, keeping cases a runner filter excluded and their results.
1028
+ *
1029
+ * @param task - A Vitest file, suite, or test task
1030
+ * @param ancestors - The titles of the suites that enclose the task, excluding the file name. Default: none
1031
+ * @returns Each case with its suite titles and own title joined by spaces, as the Vitest JSON reporter names it
1032
+ *
1033
+ * @example
1034
+ * ```ts
1035
+ * collectCaptureCases({ name: 'mail', mode: 'run', meta: {}, tasks: [inbox] })[0]?.name
1036
+ * // 'mail opens the inbox'
1037
+ * ```
1038
+ */
1039
+ export declare function collectCaptureCases(task: CaptureTask, ancestors?: readonly string[]): readonly CaptureCase[];
1040
+
632
1041
  /**
633
1042
  * Names every changed, added, or removed file in hash populations.
634
1043
  *
@@ -1140,6 +1549,20 @@ export declare function matchesCaptureMembers(left: readonly string[], right: re
1140
1549
  */
1141
1550
  export declare function matchesCaptureSelector(owner: string, selector: string): boolean;
1142
1551
 
1552
+ /**
1553
+ * Reads the record bindings and the ran cases from a journey artifact's text.
1554
+ *
1555
+ * @param text - The artifact text, with LF or CRLF line endings
1556
+ * @returns The path of each `record=` line and the full name of each `case-ran=` line, in text order
1557
+ *
1558
+ * @example
1559
+ * ```ts
1560
+ * readCaptureArtifact('# light-390\r\nrecord=tmp/run.json\r\ncase-ran=mail opens the inbox\r\n')
1561
+ * // { records: ['tmp/run.json'], cases: ['mail opens the inbox'] }
1562
+ * ```
1563
+ */
1564
+ export declare function readCaptureArtifact(text: string): CaptureArtifactLines;
1565
+
1143
1566
  /**
1144
1567
  * Reads Git's NUL-delimited porcelain paths without treating spaces or quoted names as separators.
1145
1568
  *
@@ -1169,6 +1592,39 @@ export declare function readCaptureDirty(output: string): readonly string[];
1169
1592
  */
1170
1593
  export declare function readCaptureReport(value: unknown): CaptureReport;
1171
1594
 
1595
+ /**
1596
+ * Renders the journey artifact lines that bind a run record and each case that passed in it.
1597
+ *
1598
+ * @param record - The run record's portable path
1599
+ * @param run - The run whose passed cases the artifact names
1600
+ * @returns The `record=` line, then one `case-ran=` line per passed case, without line endings
1601
+ * @throws Thrown as an `EVIDENCE` capture error for a record path that is not portable or a case name that holds a line break.
1602
+ *
1603
+ * @example
1604
+ * ```ts
1605
+ * renderCaptureArtifact('tmp/captures/states/runs/run-1/selected/light-390.json', {
1606
+ * passed: ['mail opens the inbox'],
1607
+ * })
1608
+ * // ['record=tmp/captures/states/runs/run-1/selected/light-390.json', 'case-ran=mail opens the inbox']
1609
+ * ```
1610
+ */
1611
+ export declare function renderCaptureArtifact(record: string, run: Pick<CaptureRun, 'passed'>): readonly string[];
1612
+
1613
+ /**
1614
+ * Refuses a selection whose cases place states owned outside the selected owner.
1615
+ *
1616
+ * @param cases - Every collected case, including cases a runner filter excluded
1617
+ * @param rules - The host's owners and part resolver
1618
+ * @param selection - The runner's selection, absent when no runner is the parent
1619
+ * @throws Thrown as a `SELECTION` capture error for an undeclared selector, and as a `HOST` capture error naming each case that places a selected state from outside the selected owner.
1620
+ *
1621
+ * @example
1622
+ * ```ts
1623
+ * requireCaptureCases(cases, rules, { selector: 'pages:mail' }) // returns when no case is parked
1624
+ * ```
1625
+ */
1626
+ export declare function requireCaptureCases(cases: readonly CaptureCase[], rules: CaptureRules, selection?: CaptureSelection): void;
1627
+
1172
1628
  /**
1173
1629
  * Refuses duplicate declarations or portable storage-key collisions before indexing.
1174
1630
  *