@gate-forge/witness 0.0.0-stage → 0.8.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.
Files changed (123) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +114 -2
  3. package/dist/adapter/contract-suite.d.ts +167 -0
  4. package/dist/adapter/contract-suite.d.ts.map +1 -0
  5. package/dist/adapter/contract-suite.js +348 -0
  6. package/dist/adapter/contract-suite.js.map +1 -0
  7. package/dist/adapter/contract.d.ts +266 -0
  8. package/dist/adapter/contract.d.ts.map +1 -0
  9. package/dist/adapter/contract.js +2 -0
  10. package/dist/adapter/contract.js.map +1 -0
  11. package/dist/adapter/index.d.ts +8 -0
  12. package/dist/adapter/index.d.ts.map +1 -0
  13. package/dist/adapter/index.js +2 -0
  14. package/dist/adapter/index.js.map +1 -0
  15. package/dist/adapter-kit/config.d.ts +163 -0
  16. package/dist/adapter-kit/config.d.ts.map +1 -0
  17. package/dist/adapter-kit/config.js +21 -0
  18. package/dist/adapter-kit/config.js.map +1 -0
  19. package/dist/adapter-kit/define.d.ts +47 -0
  20. package/dist/adapter-kit/define.d.ts.map +1 -0
  21. package/dist/adapter-kit/define.js +336 -0
  22. package/dist/adapter-kit/define.js.map +1 -0
  23. package/dist/adapter-kit/index.d.ts +34 -0
  24. package/dist/adapter-kit/index.d.ts.map +1 -0
  25. package/dist/adapter-kit/index.js +32 -0
  26. package/dist/adapter-kit/index.js.map +1 -0
  27. package/dist/adapter-kit/projection.d.ts +69 -0
  28. package/dist/adapter-kit/projection.d.ts.map +1 -0
  29. package/dist/adapter-kit/projection.js +85 -0
  30. package/dist/adapter-kit/projection.js.map +1 -0
  31. package/dist/adapter-kit/session.d.ts +105 -0
  32. package/dist/adapter-kit/session.d.ts.map +1 -0
  33. package/dist/adapter-kit/session.js +230 -0
  34. package/dist/adapter-kit/session.js.map +1 -0
  35. package/dist/client/witness-client.d.ts +193 -0
  36. package/dist/client/witness-client.d.ts.map +1 -0
  37. package/dist/client/witness-client.js +321 -0
  38. package/dist/client/witness-client.js.map +1 -0
  39. package/dist/constants.d.ts +189 -0
  40. package/dist/constants.d.ts.map +1 -0
  41. package/dist/constants.js +197 -0
  42. package/dist/constants.js.map +1 -0
  43. package/dist/index.d.ts +15 -0
  44. package/dist/index.d.ts.map +1 -0
  45. package/dist/index.js +20 -0
  46. package/dist/index.js.map +1 -0
  47. package/dist/json.d.ts +16 -0
  48. package/dist/json.d.ts.map +1 -0
  49. package/dist/json.js +21 -0
  50. package/dist/json.js.map +1 -0
  51. package/dist/queue/bullmq.d.ts +28 -0
  52. package/dist/queue/bullmq.d.ts.map +1 -0
  53. package/dist/queue/bullmq.js +210 -0
  54. package/dist/queue/bullmq.js.map +1 -0
  55. package/dist/queue/observer.d.ts +130 -0
  56. package/dist/queue/observer.d.ts.map +1 -0
  57. package/dist/queue/observer.js +179 -0
  58. package/dist/queue/observer.js.map +1 -0
  59. package/dist/surface.d.ts +211 -0
  60. package/dist/surface.d.ts.map +1 -0
  61. package/dist/surface.js +268 -0
  62. package/dist/surface.js.map +1 -0
  63. package/dist/witness/adapter-registry.d.ts +92 -0
  64. package/dist/witness/adapter-registry.d.ts.map +1 -0
  65. package/dist/witness/adapter-registry.js +370 -0
  66. package/dist/witness/adapter-registry.js.map +1 -0
  67. package/dist/witness/behavior-request.d.ts +80 -0
  68. package/dist/witness/behavior-request.d.ts.map +1 -0
  69. package/dist/witness/behavior-request.js +335 -0
  70. package/dist/witness/behavior-request.js.map +1 -0
  71. package/dist/witness/behavior.d.ts +52 -0
  72. package/dist/witness/behavior.d.ts.map +1 -0
  73. package/dist/witness/behavior.js +118 -0
  74. package/dist/witness/behavior.js.map +1 -0
  75. package/dist/witness/bin.d.ts +21 -0
  76. package/dist/witness/bin.d.ts.map +1 -0
  77. package/dist/witness/bin.js +254 -0
  78. package/dist/witness/bin.js.map +1 -0
  79. package/dist/witness/browser.d.ts +221 -0
  80. package/dist/witness/browser.d.ts.map +1 -0
  81. package/dist/witness/browser.js +644 -0
  82. package/dist/witness/browser.js.map +1 -0
  83. package/dist/witness/chaos.d.ts +179 -0
  84. package/dist/witness/chaos.d.ts.map +1 -0
  85. package/dist/witness/chaos.js +270 -0
  86. package/dist/witness/chaos.js.map +1 -0
  87. package/dist/witness/classifications.d.ts +42 -0
  88. package/dist/witness/classifications.d.ts.map +1 -0
  89. package/dist/witness/classifications.js +87 -0
  90. package/dist/witness/classifications.js.map +1 -0
  91. package/dist/witness/env-attestation.d.ts +98 -0
  92. package/dist/witness/env-attestation.d.ts.map +1 -0
  93. package/dist/witness/env-attestation.js +202 -0
  94. package/dist/witness/env-attestation.js.map +1 -0
  95. package/dist/witness/fixture-provider.d.ts +89 -0
  96. package/dist/witness/fixture-provider.d.ts.map +1 -0
  97. package/dist/witness/fixture-provider.js +116 -0
  98. package/dist/witness/fixture-provider.js.map +1 -0
  99. package/dist/witness/loopback-pins.d.ts +79 -0
  100. package/dist/witness/loopback-pins.d.ts.map +1 -0
  101. package/dist/witness/loopback-pins.js +244 -0
  102. package/dist/witness/loopback-pins.js.map +1 -0
  103. package/dist/witness/run-options.d.ts +47 -0
  104. package/dist/witness/run-options.d.ts.map +1 -0
  105. package/dist/witness/run-options.js +179 -0
  106. package/dist/witness/run-options.js.map +1 -0
  107. package/dist/witness/server.d.ts +34 -0
  108. package/dist/witness/server.d.ts.map +1 -0
  109. package/dist/witness/server.js +4899 -0
  110. package/dist/witness/server.js.map +1 -0
  111. package/dist/witness/task.d.ts +77 -0
  112. package/dist/witness/task.d.ts.map +1 -0
  113. package/dist/witness/task.js +201 -0
  114. package/dist/witness/task.js.map +1 -0
  115. package/dist/witness/twin-shapes.d.ts +51 -0
  116. package/dist/witness/twin-shapes.d.ts.map +1 -0
  117. package/dist/witness/twin-shapes.js +127 -0
  118. package/dist/witness/twin-shapes.js.map +1 -0
  119. package/dist/witness/types.d.ts +1094 -0
  120. package/dist/witness/types.d.ts.map +1 -0
  121. package/dist/witness/types.js +2 -0
  122. package/dist/witness/types.js.map +1 -0
  123. package/package.json +98 -4
@@ -0,0 +1,211 @@
1
+ /**
2
+ * The consumer-declared surface descriptor (plan Phase 1 item 7): the
3
+ * APPLICATION-SPECIFIC half of evidence — how the rendered UI is
4
+ * observed and driven (list page, rows and field cells, form templates,
5
+ * archive control, status values). The pack ships selectors for NO
6
+ * application; the consumer declares its own.
7
+ *
8
+ * OWNERSHIP: the descriptor's selectors are LOCATORS, never proof. The
9
+ * engine-owned browser (witness `browser.ts`) drives the rendered app
10
+ * with them and verifies navigation, the application request, the
11
+ * visible outcome, and persistence itself — a lying descriptor fails
12
+ * closed (elements never match) instead of manufacturing proof.
13
+ */
14
+ /**
15
+ * The current surface-descriptor version. Version 3 adds constrained
16
+ * locator-based list fields; earlier cell-index descriptors stay valid.
17
+ */
18
+ export declare const SURFACE_DESCRIPTOR_VERSION = 3;
19
+ /** Legacy surface-descriptor version (single-form create only). */
20
+ export declare const SURFACE_DESCRIPTOR_VERSION_1 = 1;
21
+ /** Surface-descriptor version with optional wizard create steps. */
22
+ export declare const SURFACE_DESCRIPTOR_VERSION_2 = 2;
23
+ /** Shared list-page and row selectors. */
24
+ interface SurfaceListBase {
25
+ /** List page path relative to the app base (e.g. `/`). */
26
+ path: string;
27
+ /** Selector proving the list page rendered (e.g. the page heading). */
28
+ readySelector: string;
29
+ /** Selector matching one entity row inside the list. */
30
+ rowSelector: string;
31
+ }
32
+ /** How v1/v2 list rows expose ids and fields in table cells. */
33
+ export interface SurfaceListCells extends SurfaceListBase {
34
+ /** Index of the row cell carrying the entity id (0-based). */
35
+ idCellIndex: number;
36
+ /** Field name → 0-based row-cell index, for reading rendered fields. */
37
+ fieldCellIndexes: Record<string, number>;
38
+ idLocator?: never;
39
+ fieldLocators?: never;
40
+ }
41
+ /** How a v3 list row exposes ids and fields through relative locators. */
42
+ export interface SurfaceListLocators extends SurfaceListBase {
43
+ /** Locator evaluated inside one matched row to read its entity id. */
44
+ idLocator: string;
45
+ /** Field name → locator evaluated inside the matched row. */
46
+ fieldLocators: Record<string, string>;
47
+ idCellIndex?: never;
48
+ fieldCellIndexes?: never;
49
+ }
50
+ /** List shape selected by the surface descriptor version. */
51
+ export type SurfaceList = SurfaceListCells | SurfaceListLocators;
52
+ /** How the CREATE form is driven (legacy single form, v1 + v2). */
53
+ export interface SurfaceCreate {
54
+ /** Create-form page path relative to the app base. */
55
+ formPath: string;
56
+ /** Selector proving the create form rendered. */
57
+ formReadySelector: string;
58
+ /** Field name → input selector on the create form. */
59
+ fields: Record<string, string>;
60
+ /** Submit control selector on the create form. */
61
+ submitSelector: string;
62
+ }
63
+ /**
64
+ * One engine-driven wizard step (surface v2, Phase 3): the closed
65
+ * operation set the engine can perform while walking a multi-screen
66
+ * create flow (draft orb → type picker → radios → searchable lists →
67
+ * submit). Steps are LOCATORS plus field references — never proof: a
68
+ * lying step fails closed (elements never match) exactly like a lying
69
+ * legacy selector. Custom searchable dropdowns, drag-and-drop, file
70
+ * pickers, and hover menus are NOT expressible — those flows stay on
71
+ * the Observe channel (documented limitation, never silently widened).
72
+ */
73
+ export type SurfaceStep =
74
+ /** Navigate to an app-relative path. */
75
+ {
76
+ goto: string;
77
+ }
78
+ /** Click a selector. */
79
+ | {
80
+ click: string;
81
+ }
82
+ /**
83
+ * Fill an input: `field` references a test-input field name (the
84
+ * engine types the journey's value for it); `value` is a literal the
85
+ * map declares. Exactly one of the two.
86
+ */
87
+ | {
88
+ fill: {
89
+ selector: string;
90
+ field?: string;
91
+ value?: string;
92
+ };
93
+ }
94
+ /** Check a radio/checkbox. */
95
+ | {
96
+ check: string;
97
+ }
98
+ /** Press a dismiss/confirm key (dialogs that close on Escape/Enter). */
99
+ | {
100
+ press: 'Escape' | 'Enter';
101
+ }
102
+ /** Wait for a selector (async panels, search results). */
103
+ | {
104
+ waitFor: string;
105
+ };
106
+ /**
107
+ * Wizard-driven CREATE (surface v2): `steps` replace the legacy
108
+ * single-form trio (`formPath`/`formReadySelector`/`submitSelector`
109
+ * must be ABSENT — a mixed descriptor is refused fail-closed, never
110
+ * driven half-legacy). `fields` stays REQUIRED: it declares the input
111
+ * vocabulary the test provides and the echo grades.
112
+ */
113
+ export interface SurfaceCreateSteps {
114
+ /** Declared input vocabulary (echo source; selectors live in steps). */
115
+ fields: Record<string, string>;
116
+ /** The wizard walk, in order. Non-empty. */
117
+ steps: SurfaceStep[];
118
+ }
119
+ /** How CREATE is driven: one legacy form (v1 + v2) or a wizard walk (v2 only). */
120
+ export type SurfaceCreateFlow = SurfaceCreate | SurfaceCreateSteps;
121
+ /**
122
+ * How the EDIT form is reached and driven. `{id}` templates are
123
+ * substituted with the entity id; the edit link is located INSIDE the
124
+ * entity's row.
125
+ */
126
+ export interface SurfaceEdit {
127
+ /** Row-scoped selector of the control navigating to the edit form. */
128
+ linkSelector: string;
129
+ /** `{id}`-templated selector proving the edit form rendered. */
130
+ formReadySelectorTemplate: string;
131
+ /** Field name → input selector on the edit form. */
132
+ fields: Record<string, string>;
133
+ /** `{id}`-templated page-scoped selector of the edit SAVE control. */
134
+ saveSelectorTemplate: string;
135
+ }
136
+ /** How the archive/delete control is located (row-scoped, `{id}`-templated). */
137
+ export interface SurfaceArchive {
138
+ /** `{id}`-templated row-scoped selector of the archive/delete control. */
139
+ controlSelectorTemplate: string;
140
+ }
141
+ /**
142
+ * Rendered-status observations the primitives assert after create and
143
+ * archive (fail-closed visible postconditions).
144
+ */
145
+ export interface SurfaceStatus {
146
+ /** Field name the status renders under (must be a row field). */
147
+ field: string;
148
+ /** Expected rendered value right after a create (e.g. `'active'`). */
149
+ createdValue?: string;
150
+ /** Expected rendered value after archive (e.g. `'archived'`). */
151
+ archivedValue?: string;
152
+ }
153
+ /**
154
+ * The declarative, consumer-owned description of the application
155
+ * surface the evidence primitives observe (plan Phase 1 item 7): the
156
+ * pack ships selectors for NO application — the consumer declares its
157
+ * own. Selector/path strings containing `{id}` are substituted with the
158
+ * entity id before use.
159
+ */
160
+ export interface SurfaceDescriptor {
161
+ /** Version 3 adds relative list locators; cell indexes remain compatible. */
162
+ schemaVersion: number;
163
+ list: SurfaceList;
164
+ create: SurfaceCreateFlow;
165
+ edit: SurfaceEdit;
166
+ archive: SurfaceArchive;
167
+ status: SurfaceStatus;
168
+ /**
169
+ * Where the browser lands after a successful mutation (the rendered
170
+ * result page); `path` is the expected `location.pathname`.
171
+ */
172
+ afterAction: {
173
+ path: string;
174
+ };
175
+ /**
176
+ * Fields recorded on a delete/archive `ui.action` record (the
177
+ * owner-declared archived state the journey drove, e.g.
178
+ * `{status: 'archived'}`).
179
+ */
180
+ deleteFields: Record<string, string>;
181
+ }
182
+ /**
183
+ * Substitutes `{id}` in a consumer-declared selector/path template with
184
+ * the entity id. Fail closed on ids that could break selector context
185
+ * (quotes/control characters) — a malformed id must error here, not
186
+ * silently match a different element.
187
+ */
188
+ export declare function renderSurfaceTemplate(template: string, entityId: string): string;
189
+ /**
190
+ * Structural validation of the consumer-declared surface descriptor
191
+ * (fail closed with the EXACT missing piece — a misdeclared surface must
192
+ * never surface later as a confusing selector timeout).
193
+ *
194
+ * Args:
195
+ * surface: the candidate descriptor.
196
+ *
197
+ * Returns:
198
+ * SurfaceDescriptor: the same descriptor, validated.
199
+ *
200
+ * Throws:
201
+ * Error: naming the first structural problem found.
202
+ */
203
+ export declare function validateSurface(surface: SurfaceDescriptor): SurfaceDescriptor;
204
+ /**
205
+ * Fills descriptor input fields exactly: every declared key must be a
206
+ * selector-known field with a string value (fail closed — the engine
207
+ * never invents form fields the consumer did not declare).
208
+ */
209
+ export declare function declaredSurfaceFields(where: string, input: Record<string, string>, known: Record<string, string>): Record<string, string>;
210
+ export {};
211
+ //# sourceMappingURL=surface.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"surface.d.ts","sourceRoot":"","sources":["../src/surface.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH;;;GAGG;AACH,eAAO,MAAM,0BAA0B,IAAI,CAAC;AAE5C,mEAAmE;AACnE,eAAO,MAA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,EAAE,MAAM,CAAC;IACtB,IAAI,EAAE,WAAW,CAAC;IAClB,MAAM,EAAE,iBAAiB,CAAC;IAC1B,IAAI,EAAE,WAAW,CAAC;IAClB,OAAO,EAAE,cAAc,CAAC;IACxB,MAAM,EAAE,aAAa,CAAC;IACtB;;;OAGG;IACH,WAAW,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IAC9B;;;;OAIG;IACH,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACtC;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAQhF;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,iBAAiB,GAAG,iBAAiB,CA6E7E;AAuID;;;;GAIG;AACH,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC7B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC5B,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAmBxB"}
@@ -0,0 +1,268 @@
1
+ /**
2
+ * The consumer-declared surface descriptor (plan Phase 1 item 7): the
3
+ * APPLICATION-SPECIFIC half of evidence — how the rendered UI is
4
+ * observed and driven (list page, rows and field cells, form templates,
5
+ * archive control, status values). The pack ships selectors for NO
6
+ * application; the consumer declares its own.
7
+ *
8
+ * OWNERSHIP: the descriptor's selectors are LOCATORS, never proof. The
9
+ * engine-owned browser (witness `browser.ts`) drives the rendered app
10
+ * with them and verifies navigation, the application request, the
11
+ * visible outcome, and persistence itself — a lying descriptor fails
12
+ * closed (elements never match) instead of manufacturing proof.
13
+ */
14
+ /**
15
+ * The current surface-descriptor version. Version 3 adds constrained
16
+ * locator-based list fields; earlier cell-index descriptors stay valid.
17
+ */
18
+ export const SURFACE_DESCRIPTOR_VERSION = 3;
19
+ /** Legacy surface-descriptor version (single-form create only). */
20
+ export const SURFACE_DESCRIPTOR_VERSION_1 = 1;
21
+ /** Surface-descriptor version with optional wizard create steps. */
22
+ export const SURFACE_DESCRIPTOR_VERSION_2 = 2;
23
+ /**
24
+ * Substitutes `{id}` in a consumer-declared selector/path template with
25
+ * the entity id. Fail closed on ids that could break selector context
26
+ * (quotes/control characters) — a malformed id must error here, not
27
+ * silently match a different element.
28
+ */
29
+ export function renderSurfaceTemplate(template, entityId) {
30
+ if (/['"\r\n\\]/.test(entityId)) {
31
+ throw new Error(`surface template '${template}' cannot be rendered for entity id ${JSON.stringify(entityId)}: ` +
32
+ 'ids carrying quotes or control characters are rejected fail-closed');
33
+ }
34
+ return template.replaceAll('{id}', entityId);
35
+ }
36
+ /**
37
+ * Structural validation of the consumer-declared surface descriptor
38
+ * (fail closed with the EXACT missing piece — a misdeclared surface must
39
+ * never surface later as a confusing selector timeout).
40
+ *
41
+ * Args:
42
+ * surface: the candidate descriptor.
43
+ *
44
+ * Returns:
45
+ * SurfaceDescriptor: the same descriptor, validated.
46
+ *
47
+ * Throws:
48
+ * Error: naming the first structural problem found.
49
+ */
50
+ export function validateSurface(surface) {
51
+ if (typeof surface !== 'object' || surface === null || Array.isArray(surface)) {
52
+ throw new Error('surface must be a SurfaceDescriptor object declared by the consumer');
53
+ }
54
+ if (surface.schemaVersion !== SURFACE_DESCRIPTOR_VERSION_1 &&
55
+ surface.schemaVersion !== SURFACE_DESCRIPTOR_VERSION_2 &&
56
+ surface.schemaVersion !== SURFACE_DESCRIPTOR_VERSION) {
57
+ throw new Error(`surface.schemaVersion ${String(surface.schemaVersion)} is not supported: this pack speaks ` +
58
+ `surface-descriptor versions ${String(SURFACE_DESCRIPTOR_VERSION_1)} (legacy single-form ` +
59
+ `create), ${String(SURFACE_DESCRIPTOR_VERSION_2)} (wizard steps), and ` +
60
+ `${String(SURFACE_DESCRIPTOR_VERSION)} (relative list locators) — redeclare ` +
61
+ 'the surface against a current version');
62
+ }
63
+ for (const section of ['list', 'create', 'edit', 'archive', 'status', 'afterAction']) {
64
+ if (typeof surface[section] !== 'object' || surface[section] === null) {
65
+ throw new Error(`surface.${section} is required by the surface descriptor`);
66
+ }
67
+ }
68
+ for (const key of ['path', 'readySelector', 'rowSelector']) {
69
+ if (typeof surface.list[key] !== 'string' || surface.list[key].length === 0) {
70
+ throw new Error(`surface.list.${key} must be a non-empty string`);
71
+ }
72
+ }
73
+ if (surface.schemaVersion === SURFACE_DESCRIPTOR_VERSION) {
74
+ const hasRelativeLocators = 'idLocator' in surface.list || 'fieldLocators' in surface.list;
75
+ if (hasRelativeLocators) {
76
+ const locatorList = surface.list;
77
+ if (typeof locatorList.idLocator !== 'string' || locatorList.idLocator.length === 0) {
78
+ throw new Error('surface.list.idLocator must be a non-empty locator relative to the row');
79
+ }
80
+ requireSelectorMap('list.fieldLocators', locatorList.fieldLocators);
81
+ if ('idCellIndex' in surface.list || 'fieldCellIndexes' in surface.list) {
82
+ throw new Error('surface v3 list must not mix relative locators and cell indexes');
83
+ }
84
+ }
85
+ else {
86
+ // A v3 descriptor may keep an existing table-index map unchanged.
87
+ const cellList = surface.list;
88
+ if (!Number.isInteger(cellList.idCellIndex) || cellList.idCellIndex < 0) {
89
+ throw new Error('surface.list.idLocator or a non-negative idCellIndex is required');
90
+ }
91
+ requireIndexMap('list.fieldCellIndexes', cellList.fieldCellIndexes);
92
+ }
93
+ }
94
+ else {
95
+ const cellList = surface.list;
96
+ if (!Number.isInteger(cellList.idCellIndex) || cellList.idCellIndex < 0) {
97
+ throw new Error('surface.list.idCellIndex must be a non-negative integer');
98
+ }
99
+ requireIndexMap('list.fieldCellIndexes', cellList.fieldCellIndexes);
100
+ if ('idLocator' in surface.list || 'fieldLocators' in surface.list) {
101
+ throw new Error('surface v1/v2 list must use cell indexes, not v3 relative locators');
102
+ }
103
+ }
104
+ validateCreateFlow(surface.schemaVersion, surface.create);
105
+ for (const key of ['linkSelector', 'formReadySelectorTemplate', 'saveSelectorTemplate']) {
106
+ if (typeof surface.edit[key] !== 'string' || surface.edit[key].length === 0) {
107
+ throw new Error(`surface.edit.${key} must be a non-empty string`);
108
+ }
109
+ }
110
+ requireSelectorMap('edit.fields', surface.edit.fields);
111
+ if (typeof surface.archive.controlSelectorTemplate !== 'string' ||
112
+ surface.archive.controlSelectorTemplate.length === 0) {
113
+ throw new Error('surface.archive.controlSelectorTemplate must be a non-empty string');
114
+ }
115
+ if (typeof surface.status.field !== 'string' || surface.status.field.length === 0) {
116
+ throw new Error('surface.status.field must be a non-empty field name');
117
+ }
118
+ if (typeof surface.afterAction.path !== 'string' || surface.afterAction.path.length === 0) {
119
+ throw new Error('surface.afterAction.path must be a non-empty path string');
120
+ }
121
+ requireSelectorMap('deleteFields', surface.deleteFields);
122
+ return surface;
123
+ }
124
+ /**
125
+ * Requires a field name → selector record (module-level: shared by the
126
+ * descriptor validator and the create-flow validator).
127
+ */
128
+ function requireSelectorMap(where, map) {
129
+ if (typeof map !== 'object' || map === null || Array.isArray(map)) {
130
+ throw new Error(`surface.${where} must be a record of field name → selector`);
131
+ }
132
+ for (const [field, selector] of Object.entries(map)) {
133
+ if (typeof selector !== 'string' || selector.length === 0) {
134
+ throw new Error(`surface.${where}.${field} must be a non-empty selector string`);
135
+ }
136
+ }
137
+ }
138
+ /**
139
+ * Requires a field name → cell index record (module-level: shared by
140
+ * the descriptor validator and the create-flow validator).
141
+ */
142
+ function requireIndexMap(where, map) {
143
+ if (typeof map !== 'object' || map === null || Array.isArray(map)) {
144
+ throw new Error(`surface.${where} must be a record of field name → cell index`);
145
+ }
146
+ for (const [field, index] of Object.entries(map)) {
147
+ if (!Number.isInteger(index) || index < 0) {
148
+ throw new Error(`surface.${where}.${field} must be a non-negative integer cell index`);
149
+ }
150
+ }
151
+ }
152
+ /**
153
+ * Validates the create flow: legacy single-form trio, or a wizard step
154
+ * walk in versions 2 and 3. Mixed shapes fail closed.
155
+ */
156
+ function validateCreateFlow(schemaVersion, create) {
157
+ if (typeof create !== 'object' || create === null || Array.isArray(create)) {
158
+ throw new Error('surface.create must be an object (legacy form or v2 steps)');
159
+ }
160
+ const record = create;
161
+ if ('steps' in record) {
162
+ if (schemaVersion !== SURFACE_DESCRIPTOR_VERSION_2 && schemaVersion !== SURFACE_DESCRIPTOR_VERSION) {
163
+ throw new Error('surface.create.steps requires surface-descriptor version ' +
164
+ `${String(SURFACE_DESCRIPTOR_VERSION_2)} or ${String(SURFACE_DESCRIPTOR_VERSION)} ` +
165
+ `(declared ${String(schemaVersion)})`);
166
+ }
167
+ for (const legacy of ['formPath', 'formReadySelector', 'submitSelector']) {
168
+ if (record[legacy] !== undefined) {
169
+ throw new Error(`surface.create mixes wizard steps with legacy '${legacy}' — declare steps or the ` +
170
+ 'single form, never both');
171
+ }
172
+ }
173
+ requireSelectorMap('create.fields', create.fields);
174
+ validateSteps(create.steps, create.fields);
175
+ return;
176
+ }
177
+ for (const key of ['formPath', 'formReadySelector', 'submitSelector']) {
178
+ if (typeof create[key] !== 'string' || create[key].length === 0) {
179
+ throw new Error(`surface.create.${key} must be a non-empty string`);
180
+ }
181
+ }
182
+ requireSelectorMap('create.fields', create.fields);
183
+ }
184
+ /**
185
+ * Validates one wizard step walk: non-empty, closed operation set,
186
+ * non-empty selectors/paths, fills carrying exactly one of
187
+ * field/value with the field in the declared vocabulary.
188
+ */
189
+ function validateSteps(steps, fields) {
190
+ if (!Array.isArray(steps) || steps.length === 0) {
191
+ throw new Error('surface.create.steps must be a non-empty array of wizard steps');
192
+ }
193
+ steps.forEach((step, index) => {
194
+ const where = `surface.create.steps[${String(index)}]`;
195
+ if (typeof step !== 'object' || step === null || Array.isArray(step)) {
196
+ throw new Error(`${where} must be a single-operation step object`);
197
+ }
198
+ const keys = Object.keys(step);
199
+ if (keys.length !== 1) {
200
+ throw new Error(`${where} must carry exactly one operation (goto/click/fill/check/press/waitFor)`);
201
+ }
202
+ const operation = keys[0];
203
+ const value = step[operation];
204
+ switch (operation) {
205
+ case 'goto':
206
+ case 'click':
207
+ case 'check':
208
+ case 'waitFor':
209
+ if (typeof value !== 'string' || value.length === 0) {
210
+ throw new Error(`${where}.${operation} must be a non-empty string`);
211
+ }
212
+ if (operation === 'goto' && !value.startsWith('/')) {
213
+ throw new Error(`${where}.goto must be an app-relative path starting with '/'`);
214
+ }
215
+ break;
216
+ case 'press':
217
+ if (value !== 'Escape' && value !== 'Enter') {
218
+ throw new Error(`${where}.press must be 'Escape' or 'Enter'`);
219
+ }
220
+ break;
221
+ case 'fill': {
222
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
223
+ throw new Error(`${where}.fill must be {selector, field?/value?}`);
224
+ }
225
+ const fill = value;
226
+ if (typeof fill['selector'] !== 'string' || fill['selector'].length === 0) {
227
+ throw new Error(`${where}.fill.selector must be a non-empty string`);
228
+ }
229
+ const hasField = typeof fill['field'] === 'string' && fill['field'].length > 0;
230
+ const hasValue = typeof fill['value'] === 'string';
231
+ if (hasField === hasValue) {
232
+ throw new Error(`${where}.fill needs exactly one of field/value (a test-input reference or a map literal)`);
233
+ }
234
+ if (hasField && !Object.prototype.hasOwnProperty.call(fields, fill['field'])) {
235
+ throw new Error(`${where}.fill.field '${fill['field']}' is not in the declared create.fields ` +
236
+ `vocabulary (${Object.keys(fields).sort().join(', ') || '<none>'})`);
237
+ }
238
+ break;
239
+ }
240
+ default:
241
+ throw new Error(`${where} carries unknown operation '${String(operation)}' (allowed: goto/click/fill/check/press/waitFor)`);
242
+ }
243
+ });
244
+ }
245
+ /**
246
+ * Fills descriptor input fields exactly: every declared key must be a
247
+ * selector-known field with a string value (fail closed — the engine
248
+ * never invents form fields the consumer did not declare).
249
+ */
250
+ export function declaredSurfaceFields(where, input, known) {
251
+ const entries = Object.entries(input ?? {});
252
+ if (entries.length === 0) {
253
+ throw new Error(`${where} requires at least one input field the journey enters in the UI`);
254
+ }
255
+ const declared = {};
256
+ for (const [field, value] of entries) {
257
+ if (!(field in known)) {
258
+ throw new Error(`${where} declares field '${field}' which the consumer's surface descriptor does not ` +
259
+ `declare a selector for (declared fields: ${Object.keys(known).sort().join(', ')})`);
260
+ }
261
+ if (typeof value !== 'string') {
262
+ throw new Error(`${where}.${field} must be a string (form inputs are text)`);
263
+ }
264
+ declared[field] = value;
265
+ }
266
+ return declared;
267
+ }
268
+ //# sourceMappingURL=surface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"surface.js","sourceRoot":"","sources":["../src/surface.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH;;;GAGG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,CAAC,CAAC;AAE5C,mEAAmE;AACnE,MAAM,CAAC,MAAM,4BAA4B,GAAG,CAAC,CAAC;AAC9C,oEAAoE;AACpE,MAAM,CAAC,MAAM,4BAA4B,GAAG,CAAC,CAAC;AA2J9C;;;;;GAKG;AACH,MAAM,UAAU,qBAAqB,CAAC,QAAgB,EAAE,QAAgB;IACtE,IAAI,YAAY,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;QAChC,MAAM,IAAI,KAAK,CACb,qBAAqB,QAAQ,sCAAsC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI;YAC7F,oEAAoE,CACvE,CAAC;IACJ,CAAC;IACD,OAAO,QAAQ,CAAC,UAAU,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;AAC/C,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,eAAe,CAAC,OAA0B;IACxD,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,KAAK,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QAC9E,MAAM,IAAI,KAAK,CAAC,qEAAqE,CAAC,CAAC;IACzF,CAAC;IACD,IACE,OAAO,CAAC,aAAa,KAAK,4BAA4B;QACtD,OAAO,CAAC,aAAa,KAAK,4BAA4B;QACtD,OAAO,CAAC,aAAa,KAAK,0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Q,GAAG,CACtE,CAAC;gBACJ,CAAC;gBACD,MAAM;YACR,CAAC;YACD;gBACE,MAAM,IAAI,KAAK,CACb,GAAG,KAAK,+BAA+B,MAAM,CAAC,SAAS,CAAC,kDAAkD,CAC3G,CAAC;QACN,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,qBAAqB,CACnC,KAAa,EACb,KAA6B,EAC7B,KAA6B;IAE7B,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC;IAC5C,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACzB,MAAM,IAAI,KAAK,CAAC,GAAG,KAAK,iEAAiE,CAAC,CAAC;IAC7F,CAAC;IACD,MAAM,QAAQ,GAA2B,EAAE,CAAC;IAC5C,KAAK,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,OAAO,EAAE,CAAC;QACrC,IAAI,CAAC,CAAC,KAAK,IAAI,KAAK,CAAC,EAAE,CAAC;YACtB,MAAM,IAAI,KAAK,CACb,GAAG,KAAK,oBAAoB,KAAK,qDAAqD;gBACpF,4CAA4C,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CACtF,CAAC;QACJ,CAAC;QACD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YAC9B,MAAM,IAAI,KAAK,CAAC,GAAG,KAAK,IAAI,KAAK,0CAA0C,CAAC,CAAC;QAC/E,CAAC;QACD,QAAQ,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC;IAC1B,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC"}
@@ -0,0 +1,92 @@
1
+ import type { AdapterContext, EvidenceAdapter, SessionIdentity } from './types.js';
2
+ /**
3
+ * Loads every `.mjs` adapter in `dir` into a frozen registry.
4
+ *
5
+ * Args:
6
+ * dir: the configured adapters directory (absolute).
7
+ *
8
+ * Returns:
9
+ * Map<string, EvidenceAdapter>: keyed by the file basename sans `.mjs`.
10
+ *
11
+ * Throws:
12
+ * AdapterRegistryError: fail-closed load problems — unreadable dir,
13
+ * unimportable module, or a module missing any contract member.
14
+ */
15
+ export declare function loadAdapters(dir: string): Promise<Map<string, EvidenceAdapter>>;
16
+ /**
17
+ * Validates one adapter module against the pin-#8 contract.
18
+ *
19
+ * Args:
20
+ * module: the default export of the adapter file.
21
+ * name: adapter name, used in diagnostics.
22
+ *
23
+ * Returns:
24
+ * EvidenceAdapter: the validated adapter.
25
+ *
26
+ * Throws:
27
+ * AdapterRegistryError: when any required member is missing or shaped
28
+ * wrong. Optional `baseUrl`, `identity`, and `fields` refine read and
29
+ * create-proof capabilities without changing adapters that omit them.
30
+ */
31
+ export declare function validateAdapter(module: unknown, name: string): EvidenceAdapter;
32
+ /** Fail-closed adapter-loading error (witness startup aborts). */
33
+ export declare class AdapterRegistryError extends Error {
34
+ constructor(message: string);
35
+ }
36
+ /**
37
+ * Validates one adapter's optional `observe` binding (Observe channel,
38
+ * Phase 2): a plain object with per-operation `{method, path}`
39
+ * entries. Method must be a concrete uppercase verb; path must be an
40
+ * absolute backend-facing path whose only template segment is `{id}` —
41
+ * required on read/update/delete (the entity-id carrier), forbidden on
42
+ * create (create ids come from the adapter list-diff, never from a
43
+ * path guess).
44
+ *
45
+ * Args:
46
+ * value: the adapter's `observe` export.
47
+ *
48
+ * Returns:
49
+ * string | null: the contract-violation description, or null when valid.
50
+ */
51
+ export declare function validateObserveBinding(value: unknown): string | null;
52
+ /**
53
+ * Validates one operation's optional `collection` declaration: the
54
+ * response shape whose ROWS name the entities an observe read credits.
55
+ * A collection read must be a `read` over `GET` on a path that carries
56
+ * no `{id}` template (the by-id reader owns that), and must declare the
57
+ * row `idKey`; `rowsKey` is optional and its absence declares that the
58
+ * response root is the row array. Every failure is a load-time
59
+ * contract violation — an adapter can never quietly fall back to
60
+ * inferring a collection from an arbitrary response body.
61
+ *
62
+ * Args:
63
+ * value: the operation entry's `collection` export.
64
+ * operation: the observe operation the declaration sits on.
65
+ * method: the operation's already-validated HTTP method.
66
+ * path: the operation's already-validated path template.
67
+ *
68
+ * Returns:
69
+ * string | null: the contract-violation description, or null when valid.
70
+ */
71
+ export declare function validateObserveCollection(value: unknown, operation: string, method: string, path: string): string | null;
72
+ /**
73
+ * The transport the witness hands to adapter `read` calls (GET-only).
74
+ *
75
+ * Args:
76
+ * baseUrl: the resolved read base.
77
+ * resourceId: the resource this adapter serves.
78
+ * get: the mediated GET primitive.
79
+ * headers: engine-side read headers, when the run issues one.
80
+ * session: the test session the read belongs to and the identity THAT
81
+ * session registered (plan Phase 4b item 3b). Omitted for
82
+ * engine-driven, probe and supervisor reads — those are not a test
83
+ * session's read and must never inherit one.
84
+ *
85
+ * Returns:
86
+ * AdapterContext: the frozen read context.
87
+ */
88
+ export declare function makeAdapterContext(baseUrl: string, resourceId: string, get: AdapterContext['get'], headers?: Record<string, string>, session?: {
89
+ sessionId: string;
90
+ sessionIdentity: SessionIdentity | null;
91
+ }): AdapterContext;
92
+ //# sourceMappingURL=adapter-registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adapter-registry.d.ts","sourceRoot":"","sources":["../../src/witness/adapter-registry.ts"],"names":[],"mappings":"AAoCA,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAEnF;;;;;;;;;;;;GAYG;AACH,wBAAsB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC,CA6BrF;AAqBD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,eAAe,CAuG9E;AAED,kEAAkE;AAClE,qBAAa,oBAAqB,SAAQ,KAAK;gBACjC,OAAO,EAAE,MAAM;CAI5B;AAgBD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAsDpE;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,OAAO,EACd,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,GACX,MAAM,GAAG,IAAI,CAqCf;AACD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,EAClB,GAAG,EAAE,cAAc,CAAC,KAAK,CAAC,EAC1B,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAChC,OAAO,CAAC,EAAE;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,eAAe,EAAE,eAAe,GAAG,IAAI,CAAA;CAAE,GACvE,cAAc,CAUhB"}