@ouispec/testing 0.0.0-stage → 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Closure Studio
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,9 @@
1
- # Temporary Holding Version
1
+ # @ouispec/testing
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The OUI conformance kit (ADR-0226 §3.2). It runs in the integrator's own test runner, in any DOM environment, and checks a product against the published contract (`@ouispec/contract`):
4
+
5
+ - `checkDesignSystem` — a tier 1 design system: its table and declaration match the schemas, every entry registers with its declared kind, every export that takes a callback is accounted for, and every binding's `run` returns its callback's result (a job's `pending.jobId` too).
6
+ - `checkApp` — every action of a generated manifest has a handler mounted on the page that offers it.
7
+ - `checkTier2` — every tier 2 wrapper forwards `valueFrom` correctly, and every uncontrolled use is reported.
8
+
9
+ `assertConformant(report)` throws with every violation, by rule. See the integrator guide's "The conformance kit" section for a worked example.
package/dist/app.d.ts ADDED
@@ -0,0 +1,18 @@
1
+ import { type ExampleElements, type Wrapper } from './harness.js';
2
+ import { type ConformanceReport } from './report.js';
3
+ export interface AppSpec {
4
+ /** The app, for the report. */
5
+ name: string;
6
+ /** The build's generated manifest (`oui-manifest.json`). */
7
+ manifest: unknown;
8
+ /**
9
+ * What mounts each surface, by surface id: the page component, or several
10
+ * states of it that together show every control (a dialog open, a row
11
+ * present). A room's surface is mounted by a page that hosts the room.
12
+ */
13
+ pages: Readonly<Record<string, ExampleElements | (() => ExampleElements)>>;
14
+ /** Providers the pages need: the router, the theme, the data the page loads. */
15
+ wrapper?: Wrapper;
16
+ }
17
+ export declare function checkApp(spec: AppSpec): Promise<ConformanceReport>;
18
+ //# sourceMappingURL=app.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":"AAWA,OAAO,EAAwB,KAAK,eAAe,EAAE,KAAK,OAAO,EAAE,MAAM,cAAc,CAAC;AACxF,OAAO,EAAiB,KAAK,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEpE,MAAM,WAAW,OAAO;IACtB,+BAA+B;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,4DAA4D;IAC5D,QAAQ,EAAE,OAAO,CAAC;IAClB;;;;OAIG;IACH,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,eAAe,GAAG,CAAC,MAAM,eAAe,CAAC,CAAC,CAAC,CAAC;IAC3E,gFAAgF;IAChF,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,wBAAsB,QAAQ,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAsBxE"}
package/dist/app.js ADDED
@@ -0,0 +1,71 @@
1
+ /**
2
+ * An app against its generated manifest (ADR-0226 §3.2, the fourth rule):
3
+ * every action the build declares has a handler mounted on the page that
4
+ * offers it. A declared action nothing mounts is a tool the assistant is
5
+ * promised and can never use.
6
+ */
7
+ import { createElement, Fragment } from 'react';
8
+ import { NAVIGATION_SURFACE_ID } from '@ouispec/bindings';
9
+ import { contractProblems } from '@ouispec/contract/validate';
10
+ import { describeError, mount } from './harness.js';
11
+ import { ReportBuilder } from './report.js';
12
+ export async function checkApp(spec) {
13
+ const out = new ReportBuilder(spec.name);
14
+ const problems = contractProblems('oui-manifest.json', spec.manifest);
15
+ if (!out.check('matches-contract', 'manifest', problems.length ? problems.join('; ') : null))
16
+ return out.report();
17
+ const manifest = spec.manifest;
18
+ for (const surface of manifest.surfaces) {
19
+ // The navigation surface's action is served by the app's router (`connectBindings({ navigation })`).
20
+ if (surface.id === NAVIGATION_SURFACE_ID)
21
+ continue;
22
+ const actions = surface.actions.filter(a => a.source === 'control' || a.source === 'room-action');
23
+ if (!actions.length)
24
+ continue;
25
+ const fixture = spec.pages[surface.id];
26
+ if (!fixture) {
27
+ out.check('actions-mounted', surface.id, `offers ${actions.length} action(s), and no page in \`pages\` mounts it`);
28
+ continue;
29
+ }
30
+ await checkSurface(surface, fixture, spec.wrapper, out);
31
+ }
32
+ for (const id of Object.keys(spec.pages)) {
33
+ if (!manifest.surfaces.some(s => s.id === id))
34
+ out.check('actions-mounted', id, 'is in `pages` but the manifest has no such surface');
35
+ }
36
+ return out.report();
37
+ }
38
+ async function checkSurface(surface, fixture, wrapper, out) {
39
+ const controls = new Set();
40
+ const rooms = new Set();
41
+ const elements = typeof fixture === 'function' ? fixture() : fixture;
42
+ for (const state of Array.isArray(elements) ? elements : [elements]) {
43
+ let mounted;
44
+ try {
45
+ mounted = await mount(createElement(Fragment, null, state), wrapper);
46
+ }
47
+ catch (err) {
48
+ out.check('actions-mounted', surface.id, `its page failed to mount: ${describeError(err)}`);
49
+ return;
50
+ }
51
+ try {
52
+ for (const c of mounted.registry.controls())
53
+ controls.add(c.id);
54
+ for (const r of mounted.registry.rooms())
55
+ rooms.add(r.registration.catalog.room);
56
+ }
57
+ finally {
58
+ await mounted.unmount();
59
+ }
60
+ }
61
+ for (const action of surface.actions) {
62
+ if (action.source === 'control') {
63
+ out.check('actions-mounted', `${surface.id} ${action.name}`, controls.has(action.id) ? null : `declares the control ${action.id}, and no state of the page mounts a handler for it`);
64
+ }
65
+ else if (action.source === 'room-action') {
66
+ const room = action.id.split('/')[0];
67
+ out.check('actions-mounted', `${surface.id} ${action.name}`, rooms.has(room) ? null : `belongs to the room ${room}, and no state of the page registers it`);
68
+ }
69
+ }
70
+ }
71
+ //# sourceMappingURL=app.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app.js","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEhD,OAAO,EAAE,qBAAqB,EAA0C,MAAM,mBAAmB,CAAC;AAClG,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAE9D,OAAO,EAAE,aAAa,EAAE,KAAK,EAAsC,MAAM,cAAc,CAAC;AACxF,OAAO,EAAE,aAAa,EAA0B,MAAM,aAAa,CAAC;AAiBpE,MAAM,CAAC,KAAK,UAAU,QAAQ,CAAC,IAAa;IAC1C,MAAM,GAAG,GAAG,IAAI,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACzC,MAAM,QAAQ,GAAG,gBAAgB,CAAC,mBAAmB,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;IACtE,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,kBAAkB,EAAE,UAAU,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QAAE,OAAO,GAAG,CAAC,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AAI,EAAE,EAC9B,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,wBAAwB,MAAM,CAAC,EAAE,oDAAoD,CACvH,CAAC;QACJ,CAAC;aAAM,IAAI,MAAM,CAAC,MAAM,KAAK,aAAa,EAAE,CAAC;YAC3C,MAAM,IAAI,GAAG,MAAM,CAAC,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;YACrC,GAAG,CAAC,KAAK,CACP,iBAAiB,EACjB,GAAG,OAAO,CAAC,EAAE,IAAI,MAAM,CAAC,IAAI,EAAE,EAC9B,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,uBAAuB,IAAI,yCAAyC,CAC9F,CAAC;QACJ,CAAC;IACH,CAAC;AACH,CAAC"}
@@ -0,0 +1,23 @@
1
+ import { type SourceEntry } from './exports.js';
2
+ import { type ControlExample, type Wrapper } from './harness.js';
3
+ import { type ConformanceReport } from './report.js';
4
+ export interface DesignSystemSpec {
5
+ /** The package's name, as apps import it. */
6
+ name: string;
7
+ /** Its `package.json`: where it declares its control table (`oui.agentControls`, or `closure.agentControls` during the transition). */
8
+ packageJson: Readonly<Record<string, unknown>>;
9
+ /** Its control table, exactly as it ships (`agent-controls.json`, with `$kinds`). */
10
+ table: unknown;
11
+ /** The package's exports: its module namespace. */
12
+ exports: Readonly<Record<string, unknown>>;
13
+ /** An example of each table entry. */
14
+ examples: Readonly<Record<string, ControlExample>>;
15
+ /** Exports that are not controls, or are operated only by the person: export → why. */
16
+ excluded?: Readonly<Record<string, string>>;
17
+ /** Where its types are, to find every export that takes a callback. */
18
+ source: SourceEntry;
19
+ /** Providers its controls need around them. */
20
+ wrapper?: Wrapper;
21
+ }
22
+ export declare function checkDesignSystem(spec: DesignSystemSpec): Promise<ConformanceReport>;
23
+ //# sourceMappingURL=design-system.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"design-system.d.ts","sourceRoot":"","sources":["../src/design-system.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAsB,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AACpE,OAAO,EASL,KAAK,cAAc,EACnB,KAAK,OAAO,EACb,MAAM,cAAc,CAAC;AACtB,OAAO,EAAiB,KAAK,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAGpE,MAAM,WAAW,gBAAgB;IAC/B,6CAA6C;IAC7C,IAAI,EAAE,MAAM,CAAC;IACb,uIAAuI;IACvI,WAAW,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IAC/C,qFAAqF;IACrF,KAAK,EAAE,OAAO,CAAC;IACf,mDAAmD;IACnD,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IAC3C,sCAAsC;IACtC,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC;IACnD,uFAAuF;IACvF,QAAQ,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAC5C,uEAAuE;IACvE,MAAM,EAAE,WAAW,CAAC;IACpB,+CAA+C;IAC/C,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAyBD,wBAAsB,iBAAiB,CAAC,IAAI,EAAE,gBAAgB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAyE1F"}
@@ -0,0 +1,191 @@
1
+ /**
2
+ * A tier 1 design system against the contract (ADR-0226 §2.2, §3.2): its
3
+ * control table and declaration match the schemas, every entry registers with
4
+ * the kind it declares, every export that takes a callback is accounted for,
5
+ * and every binding's `run` returns what the consumer's callback returned.
6
+ */
7
+ import { createElement, Fragment } from 'react';
8
+ import { agentDeclaration, controlKindRegistrationProblem, readControlTable, registerControlKind, } from '@ouispec/bindings';
9
+ import { contractProblems } from '@ouispec/contract/validate';
10
+ import { exportedComponents } from './exports.js';
11
+ import { describeError, exampleContext, exampleRender, exampleValue, kitBindingId, mount, runRegistration, sameValue, } from './harness.js';
12
+ import { ReportBuilder } from './report.js';
13
+ import { sampleValue } from './sample.js';
14
+ function partsOf(descriptor) {
15
+ const parts = [];
16
+ if (descriptor.kind && !descriptor.display)
17
+ parts.push({ name: 'self', kind: descriptor.kind, callbacks: descriptor.callbacks });
18
+ for (const [slot, d] of Object.entries(descriptor.slots ?? {})) {
19
+ parts.push({ name: slot, kind: d.kind, callbacks: d.callback ? [d.callback] : [] });
20
+ }
21
+ if (descriptor.entries)
22
+ parts.push({ name: 'entries', kind: descriptor.entries.kind, callbacks: [descriptor.entries.callback] });
23
+ return parts;
24
+ }
25
+ /** The sentinel a consumer's callback returns, which `run` must hand back unchanged. */
26
+ const RESULT = { ok: true, data: { returnedBy: 'the consumer callback' } };
27
+ const JOB_ID = 'oui-conformance-kit-job';
28
+ const JOB_RESULT = { ok: true, pending: { jobId: JOB_ID } };
29
+ export async function checkDesignSystem(spec) {
30
+ const out = new ReportBuilder(spec.name);
31
+ // ─── The contract: what ships and what is declared ─────────────────────────
32
+ const declared = agentDeclaration(spec.name, spec.packageJson, 'agentControls');
33
+ out.check('matches-contract', 'package.json', declared.error ??
34
+ (typeof declared.value === 'string' && declared.value.trim()
35
+ ? null
36
+ : 'declares no control table: its package.json needs "oui": { "agentControls": "<path to its control table>" }'));
37
+ const schemaProblems = contractProblems('control-table.json', spec.table);
38
+ out.check('matches-contract', 'control table', schemaProblems.length ? schemaProblems.join('; ') : null);
39
+ const { controls, kinds } = readControlTable(spec.table);
40
+ for (const registration of kinds) {
41
+ const problem = controlKindRegistrationProblem(registration);
42
+ if (!out.check('matches-contract', `$kinds ${registration.kind}`, problem))
43
+ continue;
44
+ try {
45
+ registerControlKind(registration);
46
+ }
47
+ catch (err) {
48
+ out.check('matches-contract', `$kinds ${registration.kind}`, describeError(err));
49
+ }
50
+ }
51
+ const registered = new Set(kinds.map(k => k.kind));
52
+ for (const [name, descriptor] of Object.entries(controls)) {
53
+ const unknown = partsOf(descriptor).filter(p => p.kind.startsWith('x-') && !registered.has(p.kind));
54
+ out.check('matches-contract', name, unknown.length ? `uses ${unknown.map(p => p.kind).join(', ')}, which the table's $kinds do not register` : null);
55
+ }
56
+ // ─── Every export that takes a callback is accounted for ───────────────────
57
+ const excluded = spec.excluded ?? {};
58
+ const components = exportedComponents(spec.source);
59
+ const exported = new Set(Object.keys(spec.exports));
60
+ for (const component of components) {
61
+ if (!component.callbacks.length)
62
+ continue;
63
+ const reason = excluded[component.name];
64
+ out.check('callbacks-accounted', component.name, component.name in controls || (typeof reason === 'string' && reason.trim())
65
+ ? null
66
+ : `takes ${component.callbacks.join(', ')} but is neither in the control table nor excluded with a reason`);
67
+ }
68
+ for (const [name, reason] of Object.entries(excluded)) {
69
+ out.check('callbacks-accounted', name, !exported.has(name)
70
+ ? 'is excluded but the package does not export it'
71
+ : name in controls
72
+ ? 'is both in the control table and excluded'
73
+ : !reason.trim()
74
+ ? 'is excluded without a reason'
75
+ : null);
76
+ }
77
+ for (const name of Object.keys(controls)) {
78
+ out.check('callbacks-accounted', name, exported.has(name) ? null : 'is in the control table but the package does not export it');
79
+ }
80
+ // ─── Each entry registers its kind, and returns its callback's result ──────
81
+ for (const [name, descriptor] of Object.entries(controls)) {
82
+ await checkEntry(spec, name, descriptor, out);
83
+ }
84
+ return out.report();
85
+ }
86
+ async function checkEntry(spec, name, descriptor, out) {
87
+ const parts = partsOf(descriptor);
88
+ if (!parts.length && !descriptor.display)
89
+ return;
90
+ const example = spec.examples[name];
91
+ if (!example) {
92
+ out.check('registers-declared-kind', name, 'has no example, so the kit cannot mount it: add one to `examples`');
93
+ return;
94
+ }
95
+ const slots = Object.keys(descriptor.slots ?? {});
96
+ // Mount every state once, and find what each part registered.
97
+ const mountAll = async (plan) => {
98
+ const run = exampleContext(name, slots);
99
+ run.plan(plan);
100
+ const elements = exampleRender(example)(run.ctx);
101
+ const states = Array.isArray(elements) ? elements : [elements];
102
+ const mounted = [];
103
+ for (const state of states)
104
+ mounted.push(await mount(createElement(Fragment, null, state), spec.wrapper));
105
+ return { run, mounted };
106
+ };
107
+ let first;
108
+ try {
109
+ first = await mountAll(undefined);
110
+ }
111
+ catch (err) {
112
+ out.check('registers-declared-kind', name, `its example failed to mount: ${describeError(err)}`);
113
+ return;
114
+ }
115
+ try {
116
+ if (descriptor.display) {
117
+ const id = kitBindingId(name, 'self');
118
+ const shown = first.mounted.some(m => m.registry.facts().some(f => f.id === id));
119
+ out.check('registers-declared-kind', name, shown ? null : `is a display, and did not report its facts under its binding (${id})`);
120
+ }
121
+ for (const part of parts) {
122
+ const id = kitBindingId(name, part.name);
123
+ const regs = first.mounted.flatMap(m => m.registry.controls().filter(c => c.id === id));
124
+ const subject = part.name === 'self' ? name : `${name} ${part.name}`;
125
+ if (!regs.length) {
126
+ out.check('registers-declared-kind', subject, `did not register its binding (${id}): the example must render it with \`agent\``);
127
+ continue;
128
+ }
129
+ const wrong = regs.find(r => r.kind !== part.kind);
130
+ out.check('registers-declared-kind', subject, wrong ? `registers as "${wrong.kind}", but its table entry declares "${part.kind}"` : null);
131
+ }
132
+ }
133
+ finally {
134
+ for (const m of first.mounted)
135
+ await m.unmount();
136
+ }
137
+ // Running each part that calls a consumer callback returns that callback's result, a job's too.
138
+ for (const part of parts) {
139
+ if (!part.callbacks.length)
140
+ continue;
141
+ const subject = part.name === 'self' ? name : `${name} ${part.name}`;
142
+ for (const [plan, what] of [
143
+ [RESULT, 'result'],
144
+ [JOB_RESULT, 'job'],
145
+ ]) {
146
+ const { run, mounted } = await mountAll(plan);
147
+ try {
148
+ const id = kitBindingId(name, part.name);
149
+ const reg = mounted.flatMap(m => m.registry.controls().filter(c => c.id === id))[0];
150
+ if (!reg)
151
+ break; // reported above
152
+ const problem = await runPart(reg, part, example, run.calls, plan, what);
153
+ out.check('run-returns-result', `${subject} (${what})`, problem);
154
+ if (problem)
155
+ break;
156
+ }
157
+ finally {
158
+ for (const m of mounted)
159
+ await m.unmount();
160
+ }
161
+ }
162
+ }
163
+ }
164
+ async function runPart(reg, part, example, calls, plan, what) {
165
+ if (reg.disabled)
166
+ return 'registered as disabled: the example must render it usable';
167
+ const given = exampleValue(example, part.name);
168
+ const value = given.given ? given.value : reg.valueSchema ? sampleValue(reg.valueSchema, reg.value) : undefined;
169
+ if (reg.valueSchema && value === undefined) {
170
+ return `the kit cannot make a value its schema accepts (${JSON.stringify(reg.valueSchema)}): give one in the example's \`values\``;
171
+ }
172
+ calls.clear();
173
+ let result;
174
+ try {
175
+ result = await runRegistration(reg, value);
176
+ }
177
+ catch (err) {
178
+ return `run threw: ${describeError(err)}`;
179
+ }
180
+ const called = part.callbacks.filter(cb => calls.has(cb));
181
+ if (!called.length) {
182
+ return `running it did not call ${part.callbacks.join(' or ')}${result.ok ? '' : ` (it answered ${result.code}: ${result.message})`}`;
183
+ }
184
+ if (!sameValue(result, plan)) {
185
+ return what === 'job'
186
+ ? `its ${called[0]} returned { ok: true, pending: { jobId } }, but run returned ${JSON.stringify(result)}: a job control must report pending.jobId`
187
+ : `its ${called[0]} returned ${JSON.stringify(plan)}, but run returned ${JSON.stringify(result)}`;
188
+ }
189
+ return null;
190
+ }
191
+ //# sourceMappingURL=design-system.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"design-system.js","sourceRoot":"","sources":["../src/design-system.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEhD,OAAO,EACL,gBAAgB,EAChB,8BAA8B,EAC9B,gBAAgB,EAChB,mBAAmB,GAIpB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAE9D,OAAO,EAAE,kBAAkB,EAAoB,MAAM,cAAc,CAAC;AACpE,OAAO,EACL,aAAa,EACb,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AAC,WAAW,CAAC,yCAAyC,CAAC;IACrI,CAAC;IACD,KAAK,CAAC,KAAK,EAAE,CAAC;IACd,IAAI,MAAM,CAAC;IACX,IAAI,CAAC;QACH,MAAM,GAAG,MAAM,eAAe,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IAC7C,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,cAAc,aAAa,CAAC,GAAG,CAAC,EAAE,CAAC;IAC5C,CAAC;IACD,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;IAC1D,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;QACnB,OAAO,2BAA2B,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,iBAAiB,MAAM,CAAC,IAAI,KAAK,MAAM,CAAC,OAAO,GAAG,EAAE,CAAC;IACxI,CAAC;IACD,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,CAAC,EAAE,CAAC;QAC7B,OAAO,IAAI,KAAK,KAAK;YACnB,CAAC,CAAC,OAAO,MAAM,CAAC,CAAC,CAAC,gEAAgE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,2CAA2C;YACnJ,CAAC,CAAC,OAAO,MAAM,CAAC,CAAC,CAAC,aAAa,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,sBAAsB,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC;IACtG,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -0,0 +1,14 @@
1
+ export interface SourceEntry {
2
+ /** The tsconfig the package compiles with. */
3
+ tsconfig: string;
4
+ /** The module whose exports are the package's public surface (`src/index.ts`). */
5
+ entry: string;
6
+ }
7
+ export interface ExportedComponent {
8
+ name: string;
9
+ /** The props that take a callback. */
10
+ callbacks: string[];
11
+ }
12
+ /** Every component the entry exports, with the callback props it takes. */
13
+ export declare function exportedComponents(source: SourceEntry): ExportedComponent[];
14
+ //# sourceMappingURL=exports.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exports.d.ts","sourceRoot":"","sources":["../src/exports.ts"],"names":[],"mappings":"AAaA,MAAM,WAAW,WAAW;IAC1B,8CAA8C;IAC9C,QAAQ,EAAE,MAAM,CAAC;IACjB,kFAAkF;IAClF,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,sCAAsC;IACtC,SAAS,EAAE,MAAM,EAAE,CAAC;CACrB;AAED,2EAA2E;AAC3E,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,WAAW,GAAG,iBAAiB,EAAE,CAkC3E"}
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Which of a design system's exports take a callback, read from its types
3
+ * (ADR-0226 §3.2, the second rule): a component whose props include a
4
+ * callback is something a page can make interactive, so it must be in the
5
+ * control table or excluded with a reason. "A callback" is what the generator
6
+ * treats as one where a page uses a component: a function-typed prop named
7
+ * `on…`, or one of the handlers that make an element interactive.
8
+ */
9
+ import { dirname, resolve } from 'node:path';
10
+ import ts from 'typescript';
11
+ import { CALLBACK_PROP, INTERACTIVE_HANDLERS } from '@ouispec/bindings';
12
+ /** Every component the entry exports, with the callback props it takes. */
13
+ export function exportedComponents(source) {
14
+ const tsconfig = resolve(source.tsconfig);
15
+ const read = ts.readConfigFile(tsconfig, ts.sys.readFile);
16
+ if (read.error)
17
+ throw new Error(`Cannot read ${tsconfig}: ${ts.flattenDiagnosticMessageText(read.error.messageText, '\n')}`);
18
+ const parsed = ts.parseJsonConfigFileContent(read.config, ts.sys, dirname(tsconfig));
19
+ const entry = resolve(source.entry);
20
+ const program = ts.createProgram({ rootNames: [entry], options: { ...parsed.options, noEmit: true } });
21
+ const checker = program.getTypeChecker();
22
+ const file = program.getSourceFile(entry);
23
+ if (!file)
24
+ throw new Error(`${entry} is not part of the program ${tsconfig} makes`);
25
+ const moduleSymbol = checker.getSymbolAtLocation(file);
26
+ if (!moduleSymbol)
27
+ return [];
28
+ const out = [];
29
+ for (const exported of checker.getExportsOfModule(moduleSymbol)) {
30
+ const name = exported.getName();
31
+ if (!/^[A-Z]/.test(name))
32
+ continue;
33
+ const symbol = exported.flags & ts.SymbolFlags.Alias ? checker.getAliasedSymbol(exported) : exported;
34
+ if (!(symbol.flags & (ts.SymbolFlags.Value | ts.SymbolFlags.Class)))
35
+ continue;
36
+ const type = checker.getTypeOfSymbolAtLocation(symbol, file);
37
+ const props = propsOf(checker, type);
38
+ if (!props)
39
+ continue;
40
+ const callbacks = new Set();
41
+ for (const part of props.isUnion() ? props.types : [props]) {
42
+ for (const prop of checker.getPropertiesOfType(part)) {
43
+ const propName = prop.getName();
44
+ if (!(INTERACTIVE_HANDLERS.includes(propName) || CALLBACK_PROP.test(propName)))
45
+ continue;
46
+ const propType = checker.getNonNullableType(checker.getTypeOfSymbolAtLocation(prop, file));
47
+ if (takesFunction(propType))
48
+ callbacks.add(propName);
49
+ }
50
+ }
51
+ out.push({ name, callbacks: [...callbacks].sort() });
52
+ }
53
+ return out.sort((a, b) => a.name.localeCompare(b.name));
54
+ }
55
+ /** The props of a component type: its call signature's first parameter, or its constructor's. */
56
+ function propsOf(checker, type) {
57
+ const signatures = [...type.getCallSignatures(), ...type.getConstructSignatures()];
58
+ for (const signature of signatures) {
59
+ const first = signature.getParameters()[0];
60
+ if (!first)
61
+ continue;
62
+ const declaration = first.valueDeclaration ?? first.declarations?.[0];
63
+ if (!declaration)
64
+ continue;
65
+ const props = checker.getTypeOfSymbolAtLocation(first, declaration);
66
+ if (props.flags & (ts.TypeFlags.Object | ts.TypeFlags.Intersection | ts.TypeFlags.Union))
67
+ return props;
68
+ }
69
+ return null;
70
+ }
71
+ function takesFunction(type) {
72
+ if (type.isUnion())
73
+ return type.types.some(takesFunction);
74
+ return type.getCallSignatures().length > 0;
75
+ }
76
+ //# sourceMappingURL=exports.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exports.js","sourceRoot":"","sources":["../src/exports.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAexE,2EAA2E;AAC3E,MAAM,UAAU,kBAAkB,CAAC,MAAmB;IACpD,MAAM,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAC1C,MAAM,IAAI,GAAG,EAAE,CAAC,cAAc,CAAC,QAAQ,EAAE,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC1D,IAAI,IAAI,CAAC,KAAK;QAAE,MAAM,IAAI,KAAK,CAAC,eAAe,QAAQ,KAAK,EAAE,CAAC,4BAA4B,CAAC,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC;IAC7H,MAAM,MAAM,GAAG,EAAE,CAAC,0BAA0B,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC,GAAG,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;IACrF,MAAM,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACpC,MAAM,OAAO,GAAG,EAAE,CAAC,aAAa,CAAC,EAAE,SAAS,EAAE,CAAC,KAAK,CAAC,EAAE,OAAO,EAAE,EAAE,GAAG,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC;IACvG,MAAM,OAAO,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC;IACzC,MAAM,IAAI,GAAG,OAAO,CAAC,a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yBAAyB,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC;QACpE,IAAI,KAAK,CAAC,KAAK,GAAG,CAAC,EAAE,CAAC,SAAS,CAAC,MAAM,GAAG,EAAE,CAAC,SAAS,CAAC,YAAY,GAAG,EAAE,CAAC,SAAS,CAAC,KAAK,CAAC;YAAE,OAAO,KAAK,CAAC;IACzG,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,SAAS,aAAa,CAAC,IAAa;IAClC,IAAI,IAAI,CAAC,OAAO,EAAE;QAAE,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;IAC1D,OAAO,IAAI,CAAC,iBAAiB,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC;AAC7C,CAAC"}
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Mounting an example under a binding registry, in whatever test runner and
3
+ * DOM the integrator uses (jsdom, happy-dom, a browser), and the context an
4
+ * example is written against: the bindings to pass, and the callbacks whose
5
+ * calls and results the kit watches.
6
+ */
7
+ import { type ComponentType, type ReactElement, type ReactNode } from 'react';
8
+ import { type AgentBinding, type BindingRegistry, type ControlRegistration, type RoomResult } from '@ouispec/bindings';
9
+ /** Providers the integrator's controls need around them: a theme, an overlay layer. */
10
+ export type Wrapper = ComponentType<{
11
+ children: ReactNode;
12
+ }>;
13
+ /** One example of a control, or several states of it, which together show every part it binds. */
14
+ export type ExampleElements = ReactElement | readonly ReactElement[];
15
+ /**
16
+ * How an example of a control is written: render the control the way a page
17
+ * uses it, with the bindings and callbacks the context gives.
18
+ *
19
+ * ```tsx
20
+ * Button: ({ agent, on }) => <Button agent={agent()} onClick={on('onClick')}>Save</Button>,
21
+ * Card: ({ slots, agent, on }) => (
22
+ * <Card agent={slots()} onOpen={on('onOpen')} onDelete={on('onDelete')}
23
+ * menuItems={[{ label: 'Rename', onClick: on('onClick'), agent: agent('entries') }]} />
24
+ * ),
25
+ * ```
26
+ */
27
+ export type ControlExample = ((ctx: ExampleContext) => ExampleElements) | {
28
+ render: (ctx: ExampleContext) => ExampleElements;
29
+ /** The value to run a part with, by part (`self`, a slot, `entries`), where the kit's own sample would not do. */
30
+ values?: Readonly<Record<string, unknown>>;
31
+ };
32
+ export interface ExampleContext {
33
+ /** The binding for the control itself (`self`, the default), one of its slots, or its `entries`. */
34
+ agent(part?: string): AgentBinding;
35
+ /** The `agent` prop of a composite: a binding for each of the slots its table entry declares. */
36
+ slots(): Record<string, AgentBinding>;
37
+ /**
38
+ * The consumer's callback, named as the table names it (`onClick`, or a
39
+ * non-function callback such as `action` or `print`, for the function the
40
+ * control calls through it). The kit records each call, and the callback
41
+ * returns what the kit plans: the result `run` must hand back.
42
+ */
43
+ on(callback: string): (...args: unknown[]) => unknown;
44
+ }
45
+ /** The binding id the kit gives a control's part: `kit.<export>.<part>`, lower-kebab. */
46
+ export declare function kitBindingId(exportName: string, part: string): string;
47
+ export interface ExampleRun {
48
+ ctx: ExampleContext;
49
+ /** Each callback's calls, by the name the example gave it. */
50
+ calls: Map<string, unknown[][]>;
51
+ /** What the next call of any callback returns. */
52
+ plan(result: unknown): void;
53
+ }
54
+ export declare function exampleContext(exportName: string, slotNames: readonly string[]): ExampleRun;
55
+ export declare function exampleRender(example: ControlExample): (ctx: ExampleContext) => ExampleElements;
56
+ export declare function exampleValue(example: ControlExample, part: string): {
57
+ given: boolean;
58
+ value?: unknown;
59
+ };
60
+ export interface Mounted {
61
+ registry: BindingRegistry;
62
+ unmount(): Promise<void>;
63
+ }
64
+ /** Mount `element` under a fresh registry and the integrator's providers, and let it settle. */
65
+ export declare function mount(element: ReactElement, wrapper?: Wrapper): Promise<Mounted>;
66
+ /** Run a registration as the assistant would, inside `act`, and return what it returned. */
67
+ export declare function runRegistration(registration: ControlRegistration, value: unknown): Promise<RoomResult>;
68
+ /** Deep equality of JSON-like values. */
69
+ export declare function sameValue(a: unknown, b: unknown): boolean;
70
+ export declare function describeError(err: unknown): string;
71
+ //# sourceMappingURL=harness.d.ts.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