@pygmalionjs/pygmalion 0.8.1 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/binding-source.d.ts +25 -0
- package/dist-lib/{CameraLayer-B2D29VXQ.js → CameraLayer-BdOko8XE.js} +17 -17
- package/dist-lib/pygmalion.js +24599 -12746
- package/dist-lib/{runtime-BAy8W1mJ.js → runtime-Dxb-IaLN.js} +12414 -11114
- package/dist-lib/style.css +1 -1
- package/dist-lib/testing.js +10 -10
- package/dist-lib/types/binding/catalog.d.ts +10 -0
- package/dist-lib/types/binding/contracts.d.ts +202 -0
- package/dist-lib/types/binding/documentCommands.d.ts +38 -0
- package/dist-lib/types/binding/index.d.ts +6 -0
- package/dist-lib/types/binding/preview.d.ts +37 -0
- package/dist-lib/types/binding/source.d.ts +109 -0
- package/dist-lib/types/binding/useDataProjection.d.ts +9 -0
- package/dist-lib/types/binding/validate.d.ts +8 -0
- package/dist-lib/types/core/runtime.d.ts +6 -0
- package/dist-lib/types/document/appearance.d.ts +112 -0
- package/dist-lib/types/document/assets.d.ts +204 -0
- package/dist-lib/types/document/components.d.ts +169 -0
- package/dist-lib/types/document/contracts.d.ts +171 -0
- package/dist-lib/types/document/engine.d.ts +20 -0
- package/dist-lib/types/document/exportSettings.d.ts +45 -0
- package/dist-lib/types/document/geometry.d.ts +11 -0
- package/dist-lib/types/document/layout.d.ts +53 -0
- package/dist-lib/types/document/prototype.d.ts +424 -0
- package/dist-lib/types/document/prototypeReferences.d.ts +3 -0
- package/dist-lib/types/document/richText.d.ts +185 -0
- package/dist-lib/types/document/styles.d.ts +216 -0
- package/dist-lib/types/document/svgImport.d.ts +17 -0
- package/dist-lib/types/document/vector.d.ts +222 -0
- package/dist-lib/types/editor/designCompiler.d.ts +7 -0
- package/dist-lib/types/editor/designImport.d.ts +7 -0
- package/dist-lib/types/editor/inspect.d.ts +8 -0
- package/dist-lib/types/editor/revisionCatalogInstall.d.ts +1 -1
- package/dist-lib/types/editor/screenInteractions.d.ts +3 -3
- package/dist-lib/types/editor/store.d.ts +1 -1
- package/dist-lib/types/host/project.d.ts +44 -0
- package/dist-lib/types/host/registryConnections.d.ts +11 -0
- package/dist-lib/types/host/sourceFilePlan.d.ts +15 -0
- package/dist-lib/types/host/sourceWriteback.d.ts +50 -0
- package/dist-lib/types/lib.d.ts +101 -3
- package/dist-lib/types/token-library/bindings.d.ts +62 -0
- package/dist-lib/types/token-library/contracts.d.ts +117 -0
- package/dist-lib/types/token-library/engine.d.ts +13 -0
- package/dist-lib/types/workspace/WorkspaceShell.d.ts +9 -0
- package/dist-lib/types/workspace/application/ApplicationWorkspace.d.ts +3 -0
- package/dist-lib/types/workspace/configuration.d.ts +39 -0
- package/dist-lib/types/workspace/contracts.d.ts +64 -0
- package/dist-lib/types/workspace/controller.d.ts +35 -0
- package/dist-lib/types/workspace/documentSessions.d.ts +42 -0
- package/dist-lib/types/workspace/edit/AppearancePanel.d.ts +23 -0
- package/dist-lib/types/workspace/edit/ArrangeLayers.d.ts +10 -0
- package/dist-lib/types/workspace/edit/AssetsPanel.d.ts +16 -0
- package/dist-lib/types/workspace/edit/CanvasGuides.d.ts +19 -0
- package/dist-lib/types/workspace/edit/ComponentPanel.d.ts +11 -0
- package/dist-lib/types/workspace/edit/DataPanel.d.ts +16 -0
- package/dist-lib/types/workspace/edit/DesignWorkspace.d.ts +10 -0
- package/dist-lib/types/workspace/edit/LayerTree.d.ts +14 -0
- package/dist-lib/types/workspace/edit/LayoutPanel.d.ts +13 -0
- package/dist-lib/types/workspace/edit/PrototypePanel.d.ts +12 -0
- package/dist-lib/types/workspace/edit/ScopeTransferDialog.d.ts +40 -0
- package/dist-lib/types/workspace/edit/SelectionHandles.d.ts +52 -0
- package/dist-lib/types/workspace/edit/StylesPanel.d.ts +8 -0
- package/dist-lib/types/workspace/edit/TextEditor.d.ts +50 -0
- package/dist-lib/types/workspace/edit/VectorEditor.d.ts +89 -0
- package/dist-lib/types/workspace/edit/VectorToolbar.d.ts +5 -0
- package/dist-lib/types/workspace/edit/canvasGuideModel.d.ts +102 -0
- package/dist-lib/types/workspace/edit/clipboard.d.ts +35 -0
- package/dist-lib/types/workspace/edit/duplicateMetadata.d.ts +2 -0
- package/dist-lib/types/workspace/edit/geometryHandles.d.ts +224 -0
- package/dist-lib/types/workspace/edit/layerArrangement.d.ts +39 -0
- package/dist-lib/types/workspace/edit/layerMoves.d.ts +44 -0
- package/dist-lib/types/workspace/edit/projection.d.ts +12 -0
- package/dist-lib/types/workspace/edit/scopeTransfer.d.ts +96 -0
- package/dist-lib/types/workspace/edit/textStyles.d.ts +75 -0
- package/dist-lib/types/workspace/edit/vectorTools.d.ts +136 -0
- package/dist-lib/types/workspace/legacyModeAdapter.d.ts +13 -0
- package/dist-lib/types/workspace/source/ResponsiveLayoutPanel.d.ts +20 -0
- package/dist-lib/types/workspace/source/SourceReview.d.ts +11 -0
- package/dist-lib/types/workspace/source/appearanceSource.d.ts +19 -0
- package/dist-lib/types/workspace/source/compiler.d.ts +5 -0
- package/dist-lib/types/workspace/source/contracts.d.ts +156 -0
- package/dist-lib/types/workspace/source/controller.d.ts +50 -0
- package/dist-lib/types/workspace/source/documentRevision.d.ts +2 -0
- package/dist-lib/types/workspace/source/draftPreviewClient.d.ts +13 -0
- package/dist-lib/types/workspace/source/draftRecipe.d.ts +30 -0
- package/dist-lib/types/workspace/source/flowContracts.d.ts +72 -0
- package/dist-lib/types/workspace/source/prototypeSource.d.ts +4 -0
- package/dist-lib/types/workspace/source/responsive.d.ts +13 -0
- package/dist-lib/types/workspace/source/responsiveContracts.d.ts +78 -0
- package/dist-lib/types/workspace/source/structure.d.ts +21 -0
- package/dist-lib/types/workspace/source/textSource.d.ts +28 -0
- package/dist-lib/types/workspace/tokens/TokenLibraryContext.d.ts +11 -0
- package/dist-lib/types/workspace/tokens/TokenLibraryWorkspace.d.ts +14 -0
- package/dist-lib/types/workspace/tokens/contracts.d.ts +74 -0
- package/dist-lib/types/workspace/tokens/controller.d.ts +44 -0
- package/dist-lib/types/workspace/view/PrototypePlayer.d.ts +17 -0
- package/dist-lib/types/workspace/view/StoryboardWorkspace.d.ts +3 -0
- package/dist-lib/types/workspace/view/prototypePlayback.d.ts +46 -0
- package/draft-preview.d.ts +54 -0
- package/inspect.d.ts +2 -0
- package/node/design-session.mjs +3 -0
- package/node/inspect-plugin.mjs +3 -1
- package/node/inspect-writeback.mjs +18 -2
- package/node/preview-artifact-store.mjs +10 -7
- package/node/source-archive.mjs +88 -0
- package/node/source-bindings.mjs +65 -0
- package/node/source-file-lock.mjs +15 -0
- package/node/source-file-plan.mjs +162 -0
- package/node/source-file-proofs.mjs +44 -0
- package/node/source-responsive-codec.d.mts +17 -0
- package/node/source-responsive-codec.mjs +133 -0
- package/node/source-responsive.mjs +189 -0
- package/node/source-structure-reconcile.mjs +186 -0
- package/node/source-structure-wrapper-codec.d.mts +20 -0
- package/node/source-structure-wrapper-codec.mjs +205 -0
- package/node/source-structure.mjs +404 -0
- package/node/token-source-references.mjs +136 -0
- package/node/workspace-draft-preview-plugin.mjs +70 -0
- package/node/workspace-draft-preview.mjs +231 -0
- package/node/workspace-source-identity.d.mts +1 -0
- package/node/workspace-source-identity.mjs +21 -0
- package/node/workspace-source-plan.mjs +195 -0
- package/package.json +52 -6
- package/source-files.d.ts +35 -0
- package/source-responsive.d.ts +10 -0
- package/source-structure.d.ts +155 -0
- package/workspace-source-plan.d.ts +44 -0
- package/docs/coverage-contracts.md +0 -444
- package/docs/screen-state-contract.md +0 -252
|
@@ -1,444 +0,0 @@
|
|
|
1
|
-
# Coverage contracts
|
|
2
|
-
|
|
3
|
-
A host that ships a storyboard wants two questions answered before a change
|
|
4
|
-
merges:
|
|
5
|
-
|
|
6
|
-
1. **Representation.** Is every source route the application can render shown
|
|
7
|
-
somewhere the editor can open — a route preview or a registered component
|
|
8
|
-
fixture — or excluded for a stated reason?
|
|
9
|
-
2. **Classification.** Is every user scenario verified exactly once, and by
|
|
10
|
-
which declaration?
|
|
11
|
-
|
|
12
|
-
They are different questions with different answers. A declared preview URL
|
|
13
|
-
identifies where a screen should render; these static checks do not execute
|
|
14
|
-
that screen or verify a user interaction. A scenario claim identifies the
|
|
15
|
-
declaration responsible for a scenario; it says nothing about routes nobody
|
|
16
|
-
declared. The package answers each with its own functions, and a green answer
|
|
17
|
-
to one never stands in for the other.
|
|
18
|
-
|
|
19
|
-
Everything here runs in plain Node: no DOM, no Vite server, no editor mount,
|
|
20
|
-
no network. The functions are pure; they take declarations and return
|
|
21
|
-
diagnostics with structured identities. `scripts/smoke-consumer/smoke.ts` is a
|
|
22
|
-
complete consumer that imports them from the packed package and runs the
|
|
23
|
-
positive and negative cases below.
|
|
24
|
-
|
|
25
|
-
## Who owns what
|
|
26
|
-
|
|
27
|
-
| The host owns | The package validates |
|
|
28
|
-
| --- | --- |
|
|
29
|
-
| Source discovery and router-specific normalization: which files are routes, what their canonical pattern is, what their stable id is | That every discovered route is represented, by which screen, and how |
|
|
30
|
-
| Screen cases, fixtures, and the mapping from a fixture to the routes it stands for | That every mapping names a route discovery reports and a component the registry has |
|
|
31
|
-
| Verdicts for routes no screen represents: covered by a named declaration, or excluded for a reason | That every verdict names a surface that exists and a declaration that exists, exactly once |
|
|
32
|
-
| The scenario inventory and the claims that classify it | That every scenario is classified exactly once against declarations that exist |
|
|
33
|
-
| Product scope, migration baselines, and what the CI gate fails on | Counts by outcome, with exclusions and todo items apart from coverage |
|
|
34
|
-
|
|
35
|
-
The package never reads a router, a file system, or a running application in
|
|
36
|
-
this path. When a guarantee needs product knowledge, it belongs in the host;
|
|
37
|
-
the section [What stays in the host](#what-stays-in-the-host) lists those.
|
|
38
|
-
|
|
39
|
-
## Identify a route by its pattern, not by a preview URL
|
|
40
|
-
|
|
41
|
-
Discovery hands the audit `DiscoveredRoute` values:
|
|
42
|
-
|
|
43
|
-
```ts
|
|
44
|
-
interface DiscoveredRoute {
|
|
45
|
-
/** The canonical pattern, in whatever syntax the host normalized to. */
|
|
46
|
-
path?: string;
|
|
47
|
-
/** The host's stable identity for the route — usually its source path. */
|
|
48
|
-
id?: string;
|
|
49
|
-
}
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
`path` is the route as the router declares it, not an address someone visited:
|
|
53
|
-
`/items/:id`, or `/items/[id]` if the host keeps the framework's syntax. `id`
|
|
54
|
-
is the join key back to the source. A candidate for an unrepresented route is
|
|
55
|
-
identified as `route:<normalized path>` and carries the `id` as `sourceId`, so
|
|
56
|
-
a diagnostic can be matched to a route name or a source file without parsing
|
|
57
|
-
its message.
|
|
58
|
-
|
|
59
|
-
The package matches a discovered pattern against a screen's concrete `route`
|
|
60
|
-
in one way: segment for segment, where a `:param` or `*` segment accepts any
|
|
61
|
-
nonempty concrete segment. There is no prefix matching and no other parameter
|
|
62
|
-
syntax. A host whose router writes `[id]` either normalizes to `:id` before
|
|
63
|
-
calling the audit, or maps the route explicitly as the next section shows.
|
|
64
|
-
Router-specific discovery and normalization stay in the host on purpose; the
|
|
65
|
-
package does not carry a parser for any framework.
|
|
66
|
-
|
|
67
|
-
## Represent a route: preview, mapping, or fixture
|
|
68
|
-
|
|
69
|
-
A declared screen says what it represents through three fields, all of which a
|
|
70
|
-
`DesignScreenCase` already has:
|
|
71
|
-
|
|
72
|
-
```ts
|
|
73
|
-
interface DeclaredScreenRoute {
|
|
74
|
-
id: string;
|
|
75
|
-
/** The concrete canonical address the screen boots. */
|
|
76
|
-
route?: string;
|
|
77
|
-
/** The registered component the screen renders instead of navigating. */
|
|
78
|
-
componentName?: string;
|
|
79
|
-
/** Source routes the screen explicitly represents, by discovered id or path. */
|
|
80
|
-
coverageRoutes?: readonly string[];
|
|
81
|
-
}
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
`auditRouteCoverage` compares the two lists:
|
|
85
|
-
|
|
86
|
-
```ts
|
|
87
|
-
import { auditRouteCoverage } from '@pygmalionjs/pygmalion';
|
|
88
|
-
|
|
89
|
-
const audit = auditRouteCoverage({
|
|
90
|
-
routes, // DiscoveredRoute[] from the host's discovery
|
|
91
|
-
declaredScreens, // DesignScreenCase[] or result.routeMappings
|
|
92
|
-
registeredComponents, // the component registry, or its names
|
|
93
|
-
});
|
|
94
|
-
audit.candidates; // SurfaceCandidate[] — routes nothing represents
|
|
95
|
-
audit.represented; // RouteRepresentation[] — every (route, screen) pair that holds
|
|
96
|
-
audit.diagnostics; // RouteCoverageDiagnostic[] — mappings that name something missing
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
A screen represents a route in one of three ways, recorded as `via` on each
|
|
100
|
-
`RouteRepresentation`:
|
|
101
|
-
|
|
102
|
-
| `via` | How | Example |
|
|
103
|
-
| --- | --- | --- |
|
|
104
|
-
| `preview` | The screen's concrete `route` satisfies the discovered pattern | `route: '/records/main'` represents `/records/:section` |
|
|
105
|
-
| `mapping` | The screen lists the route in `coverageRoutes` and boots a route of its own | `route: '/items/fixture-1', coverageRoutes: ['/items/[id]']` |
|
|
106
|
-
| `fixture` | The screen lists the route in `coverageRoutes` and renders a registered component | `componentName: 'GuardedFixture', coverageRoutes: ['/guarded']` |
|
|
107
|
-
|
|
108
|
-
An explicit entry matches exactly: it equals the discovered route's `id`, or
|
|
109
|
-
it normalizes to the discovered route's path. No parameter is substituted and
|
|
110
|
-
no prefix is expanded. That is what keeps a fixture from covering more than the
|
|
111
|
-
host said, and a concrete preview from covering a pattern by resemblance.
|
|
112
|
-
|
|
113
|
-
The two opt-in checks are on by supplying their input. With
|
|
114
|
-
`registeredComponents`, a screen whose `componentName` is not registered
|
|
115
|
-
represents nothing, and the audit reports it. Without it, a fixture mapping is
|
|
116
|
-
taken at its word, which is the 0.7 behaviour plus explicit mappings.
|
|
117
|
-
|
|
118
|
-
### Diagnostics
|
|
119
|
-
|
|
120
|
-
Invalid mappings are reported apart from missing representation. The
|
|
121
|
-
candidates list is "what owes a verdict"; the diagnostics list is "what the
|
|
122
|
-
host wrote that no longer holds". A stale mapping produces both: the
|
|
123
|
-
diagnostic on the screen, and the route back among the candidates, because a
|
|
124
|
-
mapping that names something missing must never keep covering.
|
|
125
|
-
|
|
126
|
-
| `code` | Meaning | Fields |
|
|
127
|
-
| --- | --- | --- |
|
|
128
|
-
| `unknown-route` | A `coverageRoutes` entry matches no discovered route; it was removed or renamed | `screenId`, `route`, `componentName?` |
|
|
129
|
-
| `unregistered-component` | The screen's `componentName` is not among `registeredComponents` | `screenId`, `componentName` |
|
|
130
|
-
| `empty-mapping` | A `coverageRoutes` entry is blank | `screenId`, `route` |
|
|
131
|
-
| `missing-render-source` | A mapping has no nonempty preview route or component fixture | `screenId`, `route` |
|
|
132
|
-
|
|
133
|
-
Starting in 0.8.1, `coverageRoutes` alone never represents a route. A mapped
|
|
134
|
-
screen must also supply a nonempty preview `route` or a component fixture.
|
|
135
|
-
Empty or whitespace-only preview routes do not implicitly represent `/`.
|
|
136
|
-
Pass `registeredComponents` to check that every named fixture is registered.
|
|
137
|
-
|
|
138
|
-
A mapping without a render source produces `missing-render-source` and adds
|
|
139
|
-
no representation. If no other valid screen represents that source route, it
|
|
140
|
-
stays among the candidates. If another screen does represent it, the invalid
|
|
141
|
-
mapping still produces a diagnostic: a gate must inspect both `diagnostics`
|
|
142
|
-
and the candidates' verdicts, even when `candidates` is empty.
|
|
143
|
-
|
|
144
|
-
`enumerateRouteCandidates(input)` returns `audit.candidates` alone, for a
|
|
145
|
-
caller that only needs the holes.
|
|
146
|
-
|
|
147
|
-
### Examples
|
|
148
|
-
|
|
149
|
-
A static route with a preview:
|
|
150
|
-
|
|
151
|
-
```ts
|
|
152
|
-
auditRouteCoverage({
|
|
153
|
-
routes: [{ id: 'app/settings/page', path: '/settings' }],
|
|
154
|
-
declaredScreens: [{ id: 'screen:settings', route: '/settings' }],
|
|
155
|
-
});
|
|
156
|
-
// candidates: [] represented: [{ screenId: 'screen:settings', via: 'preview', … }]
|
|
157
|
-
```
|
|
158
|
-
|
|
159
|
-
A dynamic route, in the framework's own syntax, represented by the concrete
|
|
160
|
-
preview that instantiates it:
|
|
161
|
-
|
|
162
|
-
```ts
|
|
163
|
-
auditRouteCoverage({
|
|
164
|
-
routes: [{ id: 'app/items/[id]/page', path: '/items/[id]' }],
|
|
165
|
-
declaredScreens: [
|
|
166
|
-
{
|
|
167
|
-
id: 'screen:item-detail',
|
|
168
|
-
route: '/items/fixture-1',
|
|
169
|
-
coverageRoutes: ['app/items/[id]/page'],
|
|
170
|
-
},
|
|
171
|
-
],
|
|
172
|
-
});
|
|
173
|
-
// candidates: [] represented: [{ via: 'mapping', sourceId: 'app/items/[id]/page', … }]
|
|
174
|
-
```
|
|
175
|
-
|
|
176
|
-
Without the `coverageRoutes` entry the same input leaves `route:/items/[id]`
|
|
177
|
-
among the candidates: a concrete address does not satisfy a bracket pattern,
|
|
178
|
-
because the package does not parse that syntax. The route stays missing until
|
|
179
|
-
the host supplies the mapping, a registered fixture, or a normalized pattern
|
|
180
|
-
(`path: '/items/:id'`, which the concrete preview then satisfies).
|
|
181
|
-
|
|
182
|
-
A guarded route, represented by a registered component fixture and no
|
|
183
|
-
navigation URL:
|
|
184
|
-
|
|
185
|
-
```ts
|
|
186
|
-
auditRouteCoverage({
|
|
187
|
-
routes: [{ id: 'app/guarded/page', path: '/guarded' }],
|
|
188
|
-
declaredScreens: [
|
|
189
|
-
{ id: 'screen:guarded', componentName: 'GuardedFixture', coverageRoutes: ['/guarded'] },
|
|
190
|
-
],
|
|
191
|
-
registeredComponents: registry,
|
|
192
|
-
});
|
|
193
|
-
// candidates: [] represented: [{ via: 'fixture', componentName: 'GuardedFixture', … }]
|
|
194
|
-
```
|
|
195
|
-
|
|
196
|
-
Remove `GuardedFixture` from the registry and the same call reports
|
|
197
|
-
`unregistered-component` on `screen:guarded` and `route:/guarded` among the
|
|
198
|
-
candidates.
|
|
199
|
-
|
|
200
|
-
A multi-screen journey — every step is its own source route and its own
|
|
201
|
-
screen; the journey itself is declared to the storyboard as a `screenFlows`
|
|
202
|
-
path, which is a separate, host-owned declaration:
|
|
203
|
-
|
|
204
|
-
```ts
|
|
205
|
-
auditRouteCoverage({
|
|
206
|
-
routes: [
|
|
207
|
-
{ id: 'app/checkout/page', path: '/checkout' },
|
|
208
|
-
{ id: 'app/checkout/review/page', path: '/checkout/review' },
|
|
209
|
-
{ id: 'app/checkout/done/page', path: '/checkout/done' },
|
|
210
|
-
],
|
|
211
|
-
declaredScreens: [
|
|
212
|
-
{ id: 'screen:checkout', route: '/checkout' },
|
|
213
|
-
{ id: 'screen:checkout-review', route: '/checkout/review' },
|
|
214
|
-
{ id: 'screen:checkout-done', componentName: 'CheckoutDoneFixture', coverageRoutes: ['/checkout/done'] },
|
|
215
|
-
],
|
|
216
|
-
registeredComponents: registry,
|
|
217
|
-
});
|
|
218
|
-
```
|
|
219
|
-
|
|
220
|
-
A step reached from another step without a navigation (a confirmation dialog
|
|
221
|
-
on the review screen) is a screen state or an interactive-state axis of the
|
|
222
|
-
review screen, not a route; the [screen state contract](./screen-state-contract.md)
|
|
223
|
-
decides which.
|
|
224
|
-
|
|
225
|
-
### Audit before the collection strips the mapping
|
|
226
|
-
|
|
227
|
-
`createDesignScreenCollection` removes `coverageRoutes` from the pages it
|
|
228
|
-
returns, because the editor does not need it. The result keeps the route facts
|
|
229
|
-
beside them as `routeMappings`, one `DeclaredScreenRoute` per case, so the
|
|
230
|
-
audit runs on exactly the declarations the editor will show:
|
|
231
|
-
|
|
232
|
-
```ts
|
|
233
|
-
const result = createDesignScreenCollection({ cases, scenarios, behaviorScenarios });
|
|
234
|
-
const audit = auditRouteCoverage({
|
|
235
|
-
routes,
|
|
236
|
-
declaredScreens: result.routeMappings,
|
|
237
|
-
registeredComponents: registry,
|
|
238
|
-
});
|
|
239
|
-
```
|
|
240
|
-
|
|
241
|
-
The collection throws when scenario classification fails, so a gate that wants
|
|
242
|
-
the route audit even then passes the original `cases` instead; they satisfy
|
|
243
|
-
`DeclaredScreenRoute` as written.
|
|
244
|
-
|
|
245
|
-
## Answer the remaining routes: verdicts
|
|
246
|
-
|
|
247
|
-
A route nothing represents still exists; the host says what happens to it. A
|
|
248
|
-
`SurfaceClassification` names the candidate and gives one of two verdicts:
|
|
249
|
-
|
|
250
|
-
```ts
|
|
251
|
-
const classifications: SurfaceClassification[] = [
|
|
252
|
-
{ id: 'route:/labs', verdict: 'covered', by: 'screen:labs' },
|
|
253
|
-
{ id: 'route:/legacy', verdict: 'excluded', reason: 'redirects to /settings on every entry' },
|
|
254
|
-
];
|
|
255
|
-
```
|
|
256
|
-
|
|
257
|
-
`validateSurfaceDemands(candidates, classifications, options?)` checks them.
|
|
258
|
-
Every failure is an error; a warning would let a surface go unreviewed while
|
|
259
|
-
the build stayed green.
|
|
260
|
-
|
|
261
|
-
| `code` | Meaning |
|
|
262
|
-
| --- | --- |
|
|
263
|
-
| `unclassified` | A candidate has no verdict |
|
|
264
|
-
| `stale-verdict` | A verdict names a surface no enumerator reports |
|
|
265
|
-
| `duplicate-verdict` | Two verdicts answer one surface |
|
|
266
|
-
| `duplicate-candidate` | An enumerator reported one surface twice |
|
|
267
|
-
| `exclusion-reason` | An exclusion's reason is shorter than `MIN_SURFACE_REASON_LENGTH` |
|
|
268
|
-
| `empty-target` | A covered verdict names nothing |
|
|
269
|
-
| `unknown-target` | A covered verdict names a declaration that is not among `knownTargets` |
|
|
270
|
-
|
|
271
|
-
`unknown-target` is the check a deleted screen used to slip past: a verdict
|
|
272
|
-
saying `by: 'screen:settings'` kept covering `/settings` after the screen was
|
|
273
|
-
gone, because the target only had to be nonempty. Pass the declarations and it
|
|
274
|
-
becomes an error:
|
|
275
|
-
|
|
276
|
-
```ts
|
|
277
|
-
import { declaredCoverageTargets, validateSurfaceDemands } from '@pygmalionjs/pygmalion';
|
|
278
|
-
|
|
279
|
-
const knownTargets = declaredCoverageTargets({
|
|
280
|
-
screens: cases, // named by their own id, e.g. 'screen:settings'
|
|
281
|
-
components: registry, // named 'component:<name>'
|
|
282
|
-
targets: axes.map((axis) => `axis:${axis.id}`), // anything else, verbatim
|
|
283
|
-
});
|
|
284
|
-
const diagnostics = validateSurfaceDemands(audit.candidates, classifications, { knownTargets });
|
|
285
|
-
```
|
|
286
|
-
|
|
287
|
-
A screen is named by its own id — the same string a scenario claim's
|
|
288
|
-
`screenId` uses. A host with a different vocabulary for targets builds the set
|
|
289
|
-
itself and hands it to `knownTargets` directly.
|
|
290
|
-
|
|
291
|
-
## Classify scenarios exactly once
|
|
292
|
-
|
|
293
|
-
`createDesignScreenCollection` takes the scenario inventory and the cases that
|
|
294
|
-
demonstrate it and throws before the editor opens when any scenario is
|
|
295
|
-
classified zero times or twice, or when a case names a scenario the inventory
|
|
296
|
-
lacks. Its `coverage` counts screens and behaviors apart and lists what is
|
|
297
|
-
missing. The invariant is exact-once classification of the scenarios the host
|
|
298
|
-
supplied; the function does not discover scenarios, and it does not learn
|
|
299
|
-
about routes.
|
|
300
|
-
|
|
301
|
-
`validateScenarioCoverage(claims, context)` is the same invariant for the
|
|
302
|
-
claims ledger, where a scenario may be verified by a frame, a screen-state
|
|
303
|
-
sibling, a component prop, a viewport preset, a catalog sheet, an interactive
|
|
304
|
-
axis, a card slot, or a list length, or admitted as `behavior` or `todo` with
|
|
305
|
-
a reason. Every diagnostic carries a `code`, the `scenarioId`, the claim's
|
|
306
|
-
`kind`, its `screenId` when it named one, and the `target` the context lacks:
|
|
307
|
-
|
|
308
|
-
| `code` | Meaning |
|
|
309
|
-
| --- | --- |
|
|
310
|
-
| `unknown-scenario` | The claim names a scenario the inventory lacks |
|
|
311
|
-
| `unclaimed` | A scenario has no claim |
|
|
312
|
-
| `duplicate-claim` | A scenario has more than one claim |
|
|
313
|
-
| `insufficient-reason` | A `behavior` or `todo` reason is below the floor |
|
|
314
|
-
| `unknown-screen` | The screen or catalog sheet is not declared |
|
|
315
|
-
| `not-a-state-group` | A `screen-state` claim names a screen with no sibling states |
|
|
316
|
-
| `unknown-component`, `unknown-prop`, `unknown-value` | The registry lacks the component, the prop, or the value |
|
|
317
|
-
| `unknown-preset` | The viewport preset is not declared |
|
|
318
|
-
| `unknown-axis`, `unknown-option` | The interactive axis or option, or the card option, is not declared |
|
|
319
|
-
| `unknown-card`, `unknown-slot` | The card or slot is not declared |
|
|
320
|
-
| `unknown-list`, `count-out-of-range` | The list is not declared, or the count is outside its range |
|
|
321
|
-
| `base-option` | Warning: the claimed option is the axis base, which reproduces the capture |
|
|
322
|
-
|
|
323
|
-
### Case and step identity
|
|
324
|
-
|
|
325
|
-
Exact-once classification depends on the granularity of scenario ids. The
|
|
326
|
-
rule: one scenario id per state a reviewer should be able to select again,
|
|
327
|
-
classified by exactly one declaration.
|
|
328
|
-
|
|
329
|
-
- A journey of three screens is three scenario ids (or one id per step), each
|
|
330
|
-
classified by its own case. One scenario id spanning three screens cannot be
|
|
331
|
-
classified exactly once.
|
|
332
|
-
- A screen-state variant is a case of its own in the same `scenario` group,
|
|
333
|
-
distinguished by `state`. It carries its own scenario id, or the group's
|
|
334
|
-
canonical case carries the set in `scenarioIds`.
|
|
335
|
-
- A case demonstrates every id in its `scenarioIds`; the canonical
|
|
336
|
-
`scenarioId` is only where a reviewer is sent first.
|
|
337
|
-
- A viewport variant of a case is not a new scenario. Expand with
|
|
338
|
-
`expandDesignScreenCasesViewports`, which derives variant ids from the case
|
|
339
|
-
id and keeps the scenario ids with the authored case.
|
|
340
|
-
- An interaction step inside a recipe is how a case is reached, not a
|
|
341
|
-
scenario. A step a reviewer must be able to select on its own is a
|
|
342
|
-
screen-state axis option or a case.
|
|
343
|
-
- A route candidate id (`route:/checkout`) and a scenario id (`US-checkout`)
|
|
344
|
-
are different namespaces. A covered verdict names the screen that
|
|
345
|
-
represents the route; a claim names the screen that verifies the scenario.
|
|
346
|
-
The same screen may do both.
|
|
347
|
-
|
|
348
|
-
## A preview is not a scenario
|
|
349
|
-
|
|
350
|
-
A route the audit reports as represented has a screen that renders it. That
|
|
351
|
-
is all it says. Whether the screen demonstrates a user scenario is the claims
|
|
352
|
-
ledger's question, answered by a claim naming that screen; whether an
|
|
353
|
-
interaction is covered is a screen-state axis or an interactive-state claim,
|
|
354
|
-
never inferred from a URL. A gate that reports "all routes represented" has
|
|
355
|
-
not reported scenario coverage.
|
|
356
|
-
|
|
357
|
-
## Counts a report shows
|
|
358
|
-
|
|
359
|
-
Two summaries turn diagnostics into numbers without re-deriving them:
|
|
360
|
-
|
|
361
|
-
```ts
|
|
362
|
-
summarizeSurfaceDemands(candidates, classifications, { knownTargets });
|
|
363
|
-
// { total, covered, excluded, invalid, unclassified, excludedIds, invalidIds, unclassifiedIds }
|
|
364
|
-
|
|
365
|
-
summarizeScenarioCoverage(claims, context);
|
|
366
|
-
// { total, covered, behavior, todo, invalid, unclaimed, behaviorIds, todoIds, invalidIds, unclaimedIds, unknownIds }
|
|
367
|
-
```
|
|
368
|
-
|
|
369
|
-
`covered` counts only what validated clean. An exclusion is in `excluded`,
|
|
370
|
-
never in `covered`. A `todo` is in `todo`. A verdict or claim with an error is
|
|
371
|
-
in `invalid`. A surface or scenario nobody answered is in `unclassified` or
|
|
372
|
-
`unclaimed`. Nothing moves between buckets, so a report that shows all of
|
|
373
|
-
them shows the whole picture, and a report that shows only `covered` is
|
|
374
|
-
visibly incomplete.
|
|
375
|
-
|
|
376
|
-
## Join diagnostics to source
|
|
377
|
-
|
|
378
|
-
| Diagnostic | Identity fields |
|
|
379
|
-
| --- | --- |
|
|
380
|
-
| `SurfaceDemandDiagnostic` | `code`, `kind` (`route`, `control`, `request`), `candidateId`, `sourceId?`, `frameId?`, `target?` |
|
|
381
|
-
| `RouteCoverageDiagnostic` | `code`, `screenId`, `route?`, `componentName?` |
|
|
382
|
-
| `ScenarioCoverageDiagnostic` | `code`, `scenarioId`, `kind?`, `screenId?`, `target?` |
|
|
383
|
-
| `RouteRepresentation` | `candidateId`, `path`, `sourceId?`, `screenId`, `via`, `componentName?` |
|
|
384
|
-
|
|
385
|
-
`message` is for people. A gate joins on the fields: `sourceId` back to the
|
|
386
|
-
route's source path, `screenId` to the case and its `sourcePath`,
|
|
387
|
-
`scenarioId` to the scenario's `sourcePath`, `target` to the declaration that
|
|
388
|
-
is missing.
|
|
389
|
-
|
|
390
|
-
## What stays in the host
|
|
391
|
-
|
|
392
|
-
These guarantees need product knowledge, so the package does not provide
|
|
393
|
-
them; a host adopting the gate implements them itself:
|
|
394
|
-
|
|
395
|
-
- **Discovery and normalization.** Which files are routes, what their canonical
|
|
396
|
-
pattern is, and a stable `id` for each. The package matches patterns in one
|
|
397
|
-
syntax and parses no framework's.
|
|
398
|
-
- **Scope.** Which discovered routes are in the product at all. A route that is
|
|
399
|
-
out of scope gets an `excluded` verdict with a reason; the package does not
|
|
400
|
-
decide eligibility.
|
|
401
|
-
- **Fixture fidelity.** That a registered component fixture renders what the
|
|
402
|
-
route renders. The package checks that the component is registered, not
|
|
403
|
-
what it draws.
|
|
404
|
-
- **The inventory.** Scenario ids and their granularity, per the rules above.
|
|
405
|
-
- **Baselines.** A migration window is a host-held set of candidate ids that
|
|
406
|
-
are allowed to stay unclassified for now, subtracted from the diagnostics
|
|
407
|
-
before failing the build. The package does not downgrade severities.
|
|
408
|
-
- **CI policy.** Which diagnostics fail the build, on which Node version. The
|
|
409
|
-
package declares `engines.node`; the gate should run on the host's
|
|
410
|
-
supported version and on the declared minimum.
|
|
411
|
-
|
|
412
|
-
## A headless gate, end to end
|
|
413
|
-
|
|
414
|
-
```ts
|
|
415
|
-
import {
|
|
416
|
-
auditRouteCoverage,
|
|
417
|
-
createDesignScreenCollection,
|
|
418
|
-
declaredCoverageTargets,
|
|
419
|
-
summarizeScenarioCoverage,
|
|
420
|
-
summarizeSurfaceDemands,
|
|
421
|
-
validateScenarioCoverage,
|
|
422
|
-
validateSurfaceDemands,
|
|
423
|
-
} from '@pygmalionjs/pygmalion';
|
|
424
|
-
|
|
425
|
-
const routes = discoverRoutes(); // host: DiscoveredRoute[]
|
|
426
|
-
const result = createDesignScreenCollection({ cases, scenarios, behaviorScenarios });
|
|
427
|
-
|
|
428
|
-
const audit = auditRouteCoverage({
|
|
429
|
-
routes,
|
|
430
|
-
declaredScreens: result.routeMappings,
|
|
431
|
-
registeredComponents: registry,
|
|
432
|
-
});
|
|
433
|
-
const surfaces = validateSurfaceDemands(audit.candidates, classifications, {
|
|
434
|
-
knownTargets: declaredCoverageTargets({ screens: cases, components: registry }),
|
|
435
|
-
});
|
|
436
|
-
const ledger = validateScenarioCoverage(claims, context);
|
|
437
|
-
|
|
438
|
-
const failures = [...audit.diagnostics, ...surfaces, ...ledger].filter(
|
|
439
|
-
(diagnostic) => diagnostic.severity === 'error' && !baseline.has(keyOf(diagnostic)),
|
|
440
|
-
);
|
|
441
|
-
console.table(summarizeSurfaceDemands(audit.candidates, classifications));
|
|
442
|
-
console.table(summarizeScenarioCoverage(claims, context));
|
|
443
|
-
process.exit(failures.length === 0 ? 0 : 1);
|
|
444
|
-
```
|