@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.
@@ -0,0 +1,102 @@
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 { act, createElement } from 'react';
8
+ import { createRoot } from 'react-dom/client';
9
+ import { createBindingRegistry } from '@ouispec/bindings';
10
+ import { AgentBindingProvider } from '@ouispec/bindings/react';
11
+ /** The binding id the kit gives a control's part: `kit.<export>.<part>`, lower-kebab. */
12
+ export function kitBindingId(exportName, part) {
13
+ return `kit.${kebab(exportName)}.${kebab(part)}`;
14
+ }
15
+ function kebab(name) {
16
+ return name
17
+ .replace(/([a-z0-9])([A-Z])/g, '$1-$2')
18
+ .replace(/[^A-Za-z0-9]+/g, '-')
19
+ .toLowerCase()
20
+ .replace(/^-+|-+$/g, '');
21
+ }
22
+ export function exampleContext(exportName, slotNames) {
23
+ const calls = new Map();
24
+ let planned = undefined;
25
+ const agent = (part = 'self') => ({
26
+ id: kitBindingId(exportName, part),
27
+ description: `The conformance kit's binding of ${exportName}${part === 'self' ? '' : `'s ${part}`}`,
28
+ });
29
+ return {
30
+ ctx: {
31
+ agent,
32
+ slots: () => Object.fromEntries(slotNames.map(slot => [slot, agent(slot)])),
33
+ on: callback => (...args) => {
34
+ const list = calls.get(callback) ?? [];
35
+ list.push(args);
36
+ calls.set(callback, list);
37
+ return planned;
38
+ },
39
+ },
40
+ calls,
41
+ plan: result => {
42
+ planned = result;
43
+ },
44
+ };
45
+ }
46
+ export function exampleRender(example) {
47
+ return typeof example === 'function' ? example : example.render;
48
+ }
49
+ export function exampleValue(example, part) {
50
+ if (typeof example === 'function' || !example.values || !(part in example.values))
51
+ return { given: false };
52
+ return { given: true, value: example.values[part] };
53
+ }
54
+ /** Mount `element` under a fresh registry and the integrator's providers, and let it settle. */
55
+ export async function mount(element, wrapper) {
56
+ globalThis.IS_REACT_ACT_ENVIRONMENT = true;
57
+ if (typeof document === 'undefined') {
58
+ throw new Error('The OUI conformance kit renders controls: run it in a DOM environment (jsdom, happy-dom or a browser)');
59
+ }
60
+ const registry = createBindingRegistry();
61
+ const container = document.createElement('div');
62
+ document.body.appendChild(container);
63
+ const root = createRoot(container);
64
+ const inner = wrapper ? createElement(wrapper, null, element) : element;
65
+ await act(async () => {
66
+ root.render(createElement(AgentBindingProvider, { registry }, inner));
67
+ });
68
+ await act(async () => { });
69
+ return {
70
+ registry,
71
+ unmount: async () => {
72
+ await act(async () => root.unmount());
73
+ container.remove();
74
+ },
75
+ };
76
+ }
77
+ /** Run a registration as the assistant would, inside `act`, and return what it returned. */
78
+ export async function runRegistration(registration, value) {
79
+ let result = { ok: false, code: 'NOT_RUN', message: 'did not run' };
80
+ await act(async () => {
81
+ result = await registration.run(value === undefined ? {} : { value });
82
+ });
83
+ return result;
84
+ }
85
+ /** Deep equality of JSON-like values. */
86
+ export function sameValue(a, b) {
87
+ if (Object.is(a, b))
88
+ return true;
89
+ if (typeof a !== 'object' || typeof b !== 'object' || !a || !b)
90
+ return false;
91
+ if (Array.isArray(a) !== Array.isArray(b))
92
+ return false;
93
+ const ka = Object.keys(a).filter(k => a[k] !== undefined);
94
+ const kb = Object.keys(b).filter(k => b[k] !== undefined);
95
+ if (ka.length !== kb.length)
96
+ return false;
97
+ return ka.every(k => sameValue(a[k], b[k]));
98
+ }
99
+ export function describeError(err) {
100
+ return err instanceof Error ? err.message : String(err);
101
+ }
102
+ //# sourceMappingURL=harness.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"harness.js","sourceRoot":"","sources":["../src/harness.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,GAAG,EAAE,aAAa,EAAyD,MAAM,OAAO,CAAC;AAClG,OAAO,EAAE,UAAU,EAAE,MAAM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Q,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC;QAAE,OAAO,KAAK,CAAC;IAC7E,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;QAAE,OAAO,KAAK,CAAC;IACxD,MAAM,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,CAAW,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAE,CAA6B,CAAC,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC;IACjG,MAAM,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,CAAW,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAE,CAA6B,CAAC,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC;IACjG,IAAI,EAAE,CAAC,MAAM,KAAK,EAAE,CAAC,MAAM;QAAE,OAAO,KAAK,CAAC;IAC1C,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,SAAS,CAAE,CAA6B,CAAC,CAAC,CAAC,EAAG,CAA6B,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACxG,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,GAAY;IACxC,OAAO,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;AAC1D,CAAC"}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * @ouispec/testing — the OUI conformance kit (ADR-0226 §3.2).
3
+ *
4
+ * It runs in the integrator's own test runner, in any DOM environment, and
5
+ * reports against the published contract (`@ouispec/contract`):
6
+ *
7
+ * - `checkDesignSystem`: a tier 1 design system — its table and declaration
8
+ * match the schemas, every entry registers with the kind it declares, every
9
+ * export that takes a callback is accounted for, and every binding's `run`
10
+ * returns its callback's result (a job's `pending.jobId` too);
11
+ * - `checkApp`: every action of a generated manifest has a handler mounted on
12
+ * the page that offers it;
13
+ * - `checkTier2`: every tier 2 wrapper forwards `valueFrom` correctly, and
14
+ * every uncontrolled use of a mapped control is reported.
15
+ *
16
+ * Each returns a `ConformanceReport`; `assertConformant` throws with every
17
+ * violation listed, so any runner fails with the whole report.
18
+ *
19
+ * ```ts
20
+ * it('passes the OUI conformance kit', async () => {
21
+ * assertConformant(await checkDesignSystem({ name: '@acme/ui', packageJson, table, exports: ui, examples, excluded, source }));
22
+ * });
23
+ * ```
24
+ */
25
+ export { checkDesignSystem, type DesignSystemSpec } from './design-system.js';
26
+ export { checkApp, type AppSpec } from './app.js';
27
+ export { checkTier2, type Tier2Spec, type Tier2Use } from './tier2.js';
28
+ export { readShippedPackage, type ShippedPackage } from './package.js';
29
+ export { exportedComponents, type ExportedComponent, type SourceEntry } from './exports.js';
30
+ export { kitBindingId, type ControlExample, type ExampleContext, type ExampleElements, type Wrapper } from './harness.js';
31
+ export { sampleValue } from './sample.js';
32
+ export { assertConformant, CONFORMANCE_RULES, ConformanceError, formatReport, type ConformanceReport, type ConformanceRule, type Violation, } from './report.js';
33
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,OAAO,EAAE,iBAAiB,EAAE,KAAK,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC9E,OAAO,EAAE,QAAQ,EAAE,KAAK,OAAO,EAAE,MAAM,UAAU,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,KAAK,SAAS,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,CAAC;AACvE,OAAO,EAAE,kBAAkB,EAAE,KAAK,cAAc,EAAE,MAAM,cAAc,CAAC;AACvE,OAAO,EAAE,kBAAkB,EAAE,KAAK,iBAAiB,EAAE,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAC5F,OAAO,EAAE,YAAY,EAAE,KAAK,cAAc,EAAE,KAAK,cAAc,EAAE,KAAK,eAAe,EAAE,KAAK,OAAO,EAAE,MAAM,cAAc,CAAC;AAC1H,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,YAAY,EACZ,KAAK,iBAAiB,EACtB,KAAK,eAAe,EACpB,KAAK,SAAS,GACf,MAAM,aAAa,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,33 @@
1
+ /**
2
+ * @ouispec/testing — the OUI conformance kit (ADR-0226 §3.2).
3
+ *
4
+ * It runs in the integrator's own test runner, in any DOM environment, and
5
+ * reports against the published contract (`@ouispec/contract`):
6
+ *
7
+ * - `checkDesignSystem`: a tier 1 design system — its table and declaration
8
+ * match the schemas, every entry registers with the kind it declares, every
9
+ * export that takes a callback is accounted for, and every binding's `run`
10
+ * returns its callback's result (a job's `pending.jobId` too);
11
+ * - `checkApp`: every action of a generated manifest has a handler mounted on
12
+ * the page that offers it;
13
+ * - `checkTier2`: every tier 2 wrapper forwards `valueFrom` correctly, and
14
+ * every uncontrolled use of a mapped control is reported.
15
+ *
16
+ * Each returns a `ConformanceReport`; `assertConformant` throws with every
17
+ * violation listed, so any runner fails with the whole report.
18
+ *
19
+ * ```ts
20
+ * it('passes the OUI conformance kit', async () => {
21
+ * assertConformant(await checkDesignSystem({ name: '@acme/ui', packageJson, table, exports: ui, examples, excluded, source }));
22
+ * });
23
+ * ```
24
+ */
25
+ export { checkDesignSystem } from './design-system.js';
26
+ export { checkApp } from './app.js';
27
+ export { checkTier2 } from './tier2.js';
28
+ export { readShippedPackage } from './package.js';
29
+ export { exportedComponents } from './exports.js';
30
+ export { kitBindingId } from './harness.js';
31
+ export { sampleValue } from './sample.js';
32
+ export { assertConformant, CONFORMANCE_RULES, ConformanceError, formatReport, } from './report.js';
33
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,OAAO,EAAE,iBAAiB,EAAyB,MAAM,oBAAoB,CAAC;AAC9E,OAAO,EAAE,QAAQ,EAAgB,MAAM,UAAU,CAAC;AAClD,OAAO,EAAE,UAAU,EAAiC,MAAM,YAAY,CAAC;AACvE,OAAO,EAAE,kBAAkB,EAAuB,MAAM,cAAc,CAAC;AACvE,OAAO,EAAE,kBAAkB,EAA4C,MAAM,cAAc,CAAC;AAC5F,OAAO,EAAE,YAAY,EAAgF,MAAM,cAAc,CAAC;AAC1H,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,YAAY,GAIb,MAAM,aAAa,CAAC"}
@@ -0,0 +1,9 @@
1
+ export interface ShippedPackage {
2
+ name: string;
3
+ packageJson: Readonly<Record<string, unknown>>;
4
+ /** The control table file's contents; `undefined` when the declaration names none, or a file that is not there. */
5
+ table: unknown;
6
+ }
7
+ /** Read a built package's `package.json` and the control table it declares. Build the package first. */
8
+ export declare function readShippedPackage(dir: string): ShippedPackage;
9
+ //# sourceMappingURL=package.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"package.d.ts","sourceRoot":"","sources":["../src/package.ts"],"names":[],"mappings":"AAUA,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IAC/C,mHAAmH;IACnH,KAAK,EAAE,OAAO,CAAC;CAChB;AAED,wGAAwG;AACxG,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,cAAc,CAW9D"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * A design-system package as it ships: its `package.json`, and the control
3
+ * table its declaration names (`oui.agentControls`, or `closure.agentControls`
4
+ * during the transition), read from disk exactly as an app's generator reads it.
5
+ */
6
+ import { existsSync, readFileSync } from 'node:fs';
7
+ import { join, resolve } from 'node:path';
8
+ import { agentDeclaration } from '@ouispec/bindings';
9
+ /** Read a built package's `package.json` and the control table it declares. Build the package first. */
10
+ export function readShippedPackage(dir) {
11
+ const packageJson = JSON.parse(readFileSync(join(dir, 'package.json'), 'utf8'));
12
+ const name = typeof packageJson.name === 'string' ? packageJson.name : dir;
13
+ const declared = agentDeclaration(name, packageJson, 'agentControls');
14
+ let table;
15
+ if (typeof declared.value === 'string') {
16
+ const file = resolve(dir, declared.value);
17
+ if (!existsSync(file))
18
+ throw new Error(`${name} names ${declared.value} as its ${declared.source}, but it is not there: build the package first`);
19
+ table = JSON.parse(readFileSync(file, 'utf8'));
20
+ }
21
+ return { name, packageJson, table };
22
+ }
23
+ //# sourceMappingURL=package.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"package.js","sourceRoot":"","sources":["../src/package.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAE1C,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AASrD,wGAAwG;AACxG,MAAM,UAAU,kBAAkB,CAAC,GAAW;IAC5C,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,EAAE,cAAc,CAAC,EAAE,MAAM,CAAC,CAA4B,CAAC;IAC3G,MAAM,IAAI,GAAG,OAAO,WAAW,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC;IAC3E,MAAM,QAAQ,GAAG,gBAAgB,CAAC,IAAI,EAAE,WAAW,EAAE,eAAe,CAAC,CAAC;IACtE,IAAI,KAAc,CAAC;IACnB,IAAI,OAAO,QAAQ,CAAC,KAAK,KAAK,QAAQ,EAAE,CAAC;QACvC,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC;QAC1C,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,GAAG,IAAI,UAAU,QAAQ,CAAC,KAAK,WAAW,QAAQ,CAAC,MAAM,gDAAgD,CAAC,CAAC;QAClJ,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;IACjD,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,CAAC;AACtC,CAAC"}
@@ -0,0 +1,50 @@
1
+ /**
2
+ * What the conformance kit checks (ADR-0226 §3.2), and what it reports.
3
+ *
4
+ * Each rule has an id an integrator's test can name, the ADR's wording, and
5
+ * the checks that ran under it, so a passing report shows that every rule was
6
+ * exercised and not merely that nothing was found.
7
+ */
8
+ /** The kit's rules, in the order ADR-0226 §3.2 lists them, after the schemas they rest on. */
9
+ export declare const CONFORMANCE_RULES: {
10
+ readonly 'matches-contract': "What the package ships and declares matches the published schemas: its control table, its `oui` (or, during the transition, `closure`) declaration in package.json, a manifest, a mapping.";
11
+ readonly 'registers-declared-kind': "Every table entry registers at runtime with the kind it declares.";
12
+ readonly 'callbacks-accounted': "Every export that takes a callback is in the table, or excluded with a reason.";
13
+ readonly 'run-returns-result': "Every binding’s `run` returns its callback’s result, and a job control reports `pending.jobId`.";
14
+ readonly 'actions-mounted': "Every generated manifest action has a mounted handler on the page that offers it.";
15
+ readonly 'tier2-forwards-value': "Every tier 2 wrapper forwards `valueFrom` correctly.";
16
+ readonly 'tier2-reports-uncontrolled': "Every use of a mapped control that does not pass its `controlled` prop is reported.";
17
+ };
18
+ export type ConformanceRule = keyof typeof CONFORMANCE_RULES;
19
+ export interface Violation {
20
+ rule: ConformanceRule;
21
+ /** What broke it: an export, a slot of one, a manifest action, a use. */
22
+ subject: string;
23
+ message: string;
24
+ }
25
+ export interface ConformanceReport {
26
+ /** Who was checked: a design system's package, an app, a mapping. */
27
+ target: string;
28
+ violations: Violation[];
29
+ /** How many checks ran under each rule. */
30
+ checked: Partial<Record<ConformanceRule, number>>;
31
+ }
32
+ /** A report being written. */
33
+ export declare class ReportBuilder {
34
+ private readonly target;
35
+ private readonly violations;
36
+ private readonly checked;
37
+ constructor(target: string);
38
+ /** One check ran under `rule`; when `problem` is given, it failed. */
39
+ check(rule: ConformanceRule, subject: string, problem?: string | null): boolean;
40
+ report(): ConformanceReport;
41
+ }
42
+ /** A report as text: one line per violation, under its rule. */
43
+ export declare function formatReport(report: ConformanceReport): string;
44
+ export declare class ConformanceError extends Error {
45
+ readonly report: ConformanceReport;
46
+ constructor(report: ConformanceReport);
47
+ }
48
+ /** Throw a `ConformanceError` listing every violation, so any test runner fails with the full report. */
49
+ export declare function assertConformant(report: ConformanceReport): void;
50
+ //# sourceMappingURL=report.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"report.d.ts","sourceRoot":"","sources":["../src/report.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,8FAA8F;AAC9F,eAAO,MAAM,iBAAiB;;;;;;;;CASpB,CAAC;AAEX,MAAM,MAAM,eAAe,GAAG,MAAM,OAAO,iBAAiB,CAAC;AAE7D,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,eAAe,CAAC;IACtB,yEAAyE;IACzE,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,iBAAiB;IAChC,qEAAqE;IACrE,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,SAAS,EAAE,CAAC;IACxB,2CAA2C;IAC3C,OAAO,EAAE,OAAO,CAAC,MAAM,CAAC,eAAe,EAAE,MAAM,CAAC,CAAC,CAAC;CACnD;AAED,8BAA8B;AAC9B,qBAAa,aAAa;IAIZ,OAAO,CAAC,QAAQ,CAAC,MAAM;IAHnC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAmB;IAC9C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAgD;gBAE3C,MAAM,EAAE,MAAM;IAE3C,sEAAsE;IACtE,KAAK,CAAC,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO;IAM/E,MAAM,IAAI,iBAAiB;CAG5B;AAED,gEAAgE;AAChE,wBAAgB,YAAY,CAAC,MAAM,EAAE,iBAAiB,GAAG,MAAM,CAe9D;AAED,qBAAa,gBAAiB,SAAQ,KAAK;IAC7B,QAAQ,CAAC,MAAM,EAAE,iBAAiB;gBAAzB,MAAM,EAAE,iBAAiB;CAI/C;AAED,yGAAyG;AACzG,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,iBAAiB,GAAG,IAAI,CAEhE"}
package/dist/report.js ADDED
@@ -0,0 +1,69 @@
1
+ /**
2
+ * What the conformance kit checks (ADR-0226 §3.2), and what it reports.
3
+ *
4
+ * Each rule has an id an integrator's test can name, the ADR's wording, and
5
+ * the checks that ran under it, so a passing report shows that every rule was
6
+ * exercised and not merely that nothing was found.
7
+ */
8
+ /** The kit's rules, in the order ADR-0226 §3.2 lists them, after the schemas they rest on. */
9
+ export const CONFORMANCE_RULES = {
10
+ 'matches-contract': 'What the package ships and declares matches the published schemas: its control table, its `oui` (or, during the transition, `closure`) declaration in package.json, a manifest, a mapping.',
11
+ 'registers-declared-kind': 'Every table entry registers at runtime with the kind it declares.',
12
+ 'callbacks-accounted': 'Every export that takes a callback is in the table, or excluded with a reason.',
13
+ 'run-returns-result': 'Every binding’s `run` returns its callback’s result, and a job control reports `pending.jobId`.',
14
+ 'actions-mounted': 'Every generated manifest action has a mounted handler on the page that offers it.',
15
+ 'tier2-forwards-value': 'Every tier 2 wrapper forwards `valueFrom` correctly.',
16
+ 'tier2-reports-uncontrolled': 'Every use of a mapped control that does not pass its `controlled` prop is reported.',
17
+ };
18
+ /** A report being written. */
19
+ export class ReportBuilder {
20
+ target;
21
+ violations = [];
22
+ checked = {};
23
+ constructor(target) {
24
+ this.target = target;
25
+ }
26
+ /** One check ran under `rule`; when `problem` is given, it failed. */
27
+ check(rule, subject, problem) {
28
+ this.checked[rule] = (this.checked[rule] ?? 0) + 1;
29
+ if (problem)
30
+ this.violations.push({ rule, subject, message: problem });
31
+ return !problem;
32
+ }
33
+ report() {
34
+ return { target: this.target, violations: [...this.violations], checked: { ...this.checked } };
35
+ }
36
+ }
37
+ /** A report as text: one line per violation, under its rule. */
38
+ export function formatReport(report) {
39
+ if (!report.violations.length) {
40
+ const ran = Object.entries(report.checked)
41
+ .map(([rule, n]) => `${rule} ${n}`)
42
+ .join(', ');
43
+ return `${report.target} conforms to the OUI contract (${ran || 'no checks ran'}).`;
44
+ }
45
+ const lines = [`${report.target} breaks the OUI contract in ${report.violations.length} place(s):`];
46
+ for (const rule of Object.keys(CONFORMANCE_RULES)) {
47
+ const mine = report.violations.filter(v => v.rule === rule);
48
+ if (!mine.length)
49
+ continue;
50
+ lines.push(` ${rule}: ${CONFORMANCE_RULES[rule]}`);
51
+ for (const v of mine)
52
+ lines.push(` - ${v.subject}: ${v.message}`);
53
+ }
54
+ return lines.join('\n');
55
+ }
56
+ export class ConformanceError extends Error {
57
+ report;
58
+ constructor(report) {
59
+ super(formatReport(report));
60
+ this.report = report;
61
+ this.name = 'ConformanceError';
62
+ }
63
+ }
64
+ /** Throw a `ConformanceError` listing every violation, so any test runner fails with the full report. */
65
+ export function assertConformant(report) {
66
+ if (report.violations.length)
67
+ throw new ConformanceError(report);
68
+ }
69
+ //# sourceMappingURL=report.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"report.js","sourceRoot":"","sources":["../src/report.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,8FAA8F;AAC9F,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,k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live schema, and different from what it shows now where the schema allows,
4
+ * so running it is a change the control's callback must see.
5
+ */
6
+ import { type JsonSchema } from '@ouispec/bindings';
7
+ /** A valid value for `schema` other than `current` when there is one; `undefined` when the kit cannot make one. */
8
+ export declare function sampleValue(schema: JsonSchema, current?: unknown): unknown;
9
+ //# sourceMappingURL=sample.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sample.d.ts","sourceRoot":"","sources":["../src/sample.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAiB,KAAK,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAInE,mHAAmH;AACnH,wBAAgB,WAAW,CAAC,MAAM,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO,CAK1E"}
package/dist/sample.js ADDED
@@ -0,0 +1,113 @@
1
+ /**
2
+ * A value the assistant could set a control to: valid against the control's
3
+ * live schema, and different from what it shows now where the schema allows,
4
+ * so running it is a change the control's callback must see.
5
+ */
6
+ import { validateValue } from '@ouispec/bindings';
7
+ const SAMPLE_TEXT = 'Set by the OUI conformance kit';
8
+ /** A valid value for `schema` other than `current` when there is one; `undefined` when the kit cannot make one. */
9
+ export function sampleValue(schema, current) {
10
+ for (const candidate of candidates(schema, current)) {
11
+ if (candidate !== undefined && !validateValue(schema, candidate))
12
+ return candidate;
13
+ }
14
+ return undefined;
15
+ }
16
+ function candidates(schema, current) {
17
+ const alternatives = schema.anyOf ?? schema.oneOf;
18
+ if (alternatives) {
19
+ const nonNull = alternatives.filter(a => a.type !== 'null');
20
+ return [...nonNull, ...alternatives].flatMap(a => candidates(a, current));
21
+ }
22
+ if (schema.const !== undefined)
23
+ return [schema.const];
24
+ if (schema.enum) {
25
+ const values = schema.enum.filter(v => v !== null);
26
+ return [...values.filter(v => v !== current), ...values, ...(schema.enum.includes(null) ? [null] : [])];
27
+ }
28
+ const types = schema.type === undefined ? [] : typeof schema.type === 'string' ? [schema.type] : [...schema.type];
29
+ const ordered = [...types.filter(t => t !== 'null'), ...types.filter(t => t === 'null')];
30
+ if (!ordered.length)
31
+ return [SAMPLE_TEXT];
32
+ return ordered.flatMap(type => byType(type, schema, current));
33
+ }
34
+ function byType(type, schema, current) {
35
+ switch (type) {
36
+ case 'boolean':
37
+ return typeof current === 'boolean' ? [!current] : [true, false];
38
+ case 'number':
39
+ case 'integer':
40
+ return numbers(schema, current, type === 'integer');
41
+ case 'string':
42
+ return strings(schema, current);
43
+ case 'array':
44
+ return [array(schema, current)];
45
+ case 'object':
46
+ return [object(schema)];
47
+ case 'null':
48
+ return [null];
49
+ default:
50
+ return [];
51
+ }
52
+ }
53
+ function numbers(schema, current, integer) {
54
+ const min = schema.minimum;
55
+ const max = schema.maximum;
56
+ const step = schema.multipleOf ?? (integer ? 1 : undefined);
57
+ const snap = (n) => (step ? Math.round(n / step) * step : n);
58
+ const picks = [
59
+ min !== undefined && max !== undefined ? snap(min + (max - min) / 2) : undefined,
60
+ min !== undefined ? snap(min + (step ?? 1)) : undefined,
61
+ max !== undefined ? snap(max - (step ?? 1)) : undefined,
62
+ min,
63
+ max,
64
+ 1,
65
+ 0,
66
+ 2,
67
+ ].filter((n) => typeof n === 'number' && Number.isFinite(n));
68
+ return [...picks.filter(n => n !== current), ...picks];
69
+ }
70
+ function strings(schema, current) {
71
+ switch (schema.format) {
72
+ case 'date':
73
+ return current === '2026-10-02' ? ['2026-10-03'] : ['2026-10-02'];
74
+ case 'uri':
75
+ return ['https://example.com/oui-conformance-kit'];
76
+ case 'email':
77
+ return ['kit@example.com'];
78
+ case 'time':
79
+ return ['12:30'];
80
+ }
81
+ // A colour control's value is a CSS colour (`deriveValueSchema`'s `color` kind says so).
82
+ if (/colou?r/i.test(schema.description ?? ''))
83
+ return current === '#336699' ? ['#993366'] : ['#336699'];
84
+ let text = current === SAMPLE_TEXT ? `${SAMPLE_TEXT}, again` : SAMPLE_TEXT;
85
+ if (schema.maxLength !== undefined)
86
+ text = text.slice(0, schema.maxLength);
87
+ if (schema.minLength !== undefined && text.length < schema.minLength)
88
+ text = text.padEnd(schema.minLength, 'k');
89
+ return [text, 'kit'];
90
+ }
91
+ function array(schema, current) {
92
+ const items = schema.items ?? {};
93
+ const want = Math.max(1, schema.minItems ?? 1);
94
+ if (items.enum) {
95
+ const values = items.enum.filter(v => v !== null);
96
+ const now = Array.isArray(current) ? current : [];
97
+ const fresh = values.filter(v => !now.includes(v));
98
+ return [...fresh, ...values].slice(0, Math.min(want, values.length) || 1);
99
+ }
100
+ const out = [];
101
+ for (let i = 0; i < want; i++)
102
+ out.push(sampleValue(items));
103
+ return out;
104
+ }
105
+ function object(schema) {
106
+ const out = {};
107
+ for (const key of schema.required ?? []) {
108
+ const prop = schema.properties?.[key];
109
+ out[key] = prop ? sampleValue(prop) : SAMPLE_TEXT;
110
+ }
111
+ return out;
112
+ }
113
+ //# sourceMappingURL=sample.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sample.js","sourceRoot":"","sources":["../src/sample.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,aAAa,EAAmB,MAAM,mBAAmB,CAAC;AAEnE,MAAM,WAAW,GAAG,gCAAgC,CAAC;AAErD,mHAAmH;AACnH,MAAM,UAAU,WAAW,CAAC,MAAkB,EAAE,OAAiB;IAC/D,KAAK,MAAM,SAAS,IAAI,UAAU,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC;QACpD,IAAI,SAAS,KAAK,SAAS,IAAI,CAAC,aAAa,CAAC,MAAM,EAAE,SAAS,CAAC;YAAE,OAAO,SAAS,CAAC;IACrF,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,SAAS,UAAU,CAAC,MAAkB,EAAE,OAAgB;IACtD,MAAM,YAAY,GAAG,MAAM,CAAC,KAAK,IAAI,MAAM,CAAC,KAAK,CAAC;IAClD,IAAI,YAAY,EAAE,CAAC;QACjB,MAAM,OAAO,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE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AC,CAAC,CAAC,CAAC;QACnD,OAAO,CAAC,GAAG,KAAK,EAAE,GAAG,MAAM,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;IAC5E,CAAC;IACD,MAAM,GAAG,GAAc,EAAE,CAAC;IAC1B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,EAAE;QAAE,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC;IAC5D,OAAO,GAAG,CAAC;AACb,CAAC;AAED,SAAS,MAAM,CAAC,MAAkB;IAChC,MAAM,GAAG,GAA4B,EAAE,CAAC;IACxC,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,QAAQ,IAAI,EAAE,EAAE,CAAC;QACxC,MAAM,IAAI,GAAG,MAAM,CAAC,UAAU,EAAE,CAAC,GAAG,CAAC,CAAC;QACtC,GAAG,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC;IACpD,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -0,0 +1,27 @@
1
+ import { type ControlExample, type Wrapper } from './harness.js';
2
+ import { type ConformanceReport } from './report.js';
3
+ /** One use of a mapped control in the app's source, as the generator found it. */
4
+ export interface Tier2Use {
5
+ /** The mapped export (`Select`). */
6
+ component: string;
7
+ /** The file, relative to the app. */
8
+ file: string;
9
+ line: number;
10
+ /** The props the use passes. */
11
+ props: readonly string[];
12
+ }
13
+ export interface Tier2Spec {
14
+ /** The mapping file's contents. */
15
+ mapping: unknown;
16
+ /** The bound module's exports: one wrapper per mapped control, by its export name. */
17
+ wrappers: Readonly<Record<string, unknown>>;
18
+ /** An example of each wrapper, used as an app uses it (its callback named as the mapping's first). */
19
+ examples: Readonly<Record<string, ControlExample>>;
20
+ /** Every use of a mapped control in the app, as the generator found them. */
21
+ uses?: readonly Tier2Use[];
22
+ /** The uses the generator reported as uncontrolled. */
23
+ reported?: readonly Tier2Use[];
24
+ wrapper?: Wrapper;
25
+ }
26
+ export declare function checkTier2(spec: Tier2Spec): Promise<ConformanceReport>;
27
+ //# sourceMappingURL=tier2.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tier2.d.ts","sourceRoot":"","sources":["../src/tier2.ts"],"names":[],"mappings":"AAYA,OAAO,EASL,KAAK,cAAc,EACnB,KAAK,OAAO,EACb,MAAM,cAAc,CAAC;AACtB,OAAO,EAAiB,KAAK,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAGpE,kFAAkF;AAClF,MAAM,WAAW,QAAQ;IACvB,oCAAoC;IACpC,SAAS,EAAE,MAAM,CAAC;IAClB,qCAAqC;IACrC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,gCAAgC;IAChC,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;CAC1B;AAED,MAAM,WAAW,SAAS;IACxB,mCAAmC;IACnC,OAAO,EAAE,OAAO,CAAC;IACjB,sFAAsF;IACtF,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IAC5C,sGAAsG;IACtG,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC;IACnD,6EAA6E;IAC7E,IAAI,CAAC,EAAE,SAAS,QAAQ,EAAE,CAAC;IAC3B,uDAAuD;IACvD,QAAQ,CAAC,EAAE,SAAS,QAAQ,EAAE,CAAC;IAC/B,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAeD,wBAAsB,UAAU,CAAC,IAAI,EAAE,SAAS,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAkF5E"}
package/dist/tier2.js ADDED
@@ -0,0 +1,98 @@
1
+ /**
2
+ * Tier 2 against its mapping (ADR-0226 §2.3, §3.2, the fifth rule): each
3
+ * generated wrapper registers the mapped kind, hands the app's callback the
4
+ * value where `valueFrom` says the third-party component puts it, and returns
5
+ * that callback's result; and every use of a mapped control that does not
6
+ * pass its `controlled` prop is reported by the generator.
7
+ */
8
+ import { createElement, Fragment } from 'react';
9
+ import { contractProblems } from '@ouispec/contract/validate';
10
+ import { describeError, exampleContext, exampleRender, exampleValue, kitBindingId, mount, runRegistration, sameValue, } from './harness.js';
11
+ import { ReportBuilder } from './report.js';
12
+ import { sampleValue } from './sample.js';
13
+ const RESULT = { ok: true, data: { returnedBy: 'the app callback' } };
14
+ /** The value at `path` (dotted) inside `arg`. */
15
+ function at(arg, path) {
16
+ if (!path)
17
+ return arg;
18
+ let node = arg;
19
+ for (const key of path.split('.')) {
20
+ if (node === null || typeof node !== 'object')
21
+ return undefined;
22
+ node = node[key];
23
+ }
24
+ return node;
25
+ }
26
+ export async function checkTier2(spec) {
27
+ const problems = contractProblems('tier2-mapping.json', spec.mapping);
28
+ const pkg = spec.mapping?.package;
29
+ const out = new ReportBuilder(`the tier 2 mapping of ${typeof pkg === 'string' ? pkg : 'an unnamed package'}`);
30
+ if (!out.check('matches-contract', 'mapping', problems.length ? problems.join('; ') : null))
31
+ return out.report();
32
+ const mapping = spec.mapping;
33
+ for (const [name, control] of Object.entries(mapping.controls)) {
34
+ const subject = `${name} wrapper`;
35
+ if (typeof spec.wrappers[name] !== 'function' && typeof spec.wrappers[name] !== 'object') {
36
+ out.check('tier2-forwards-value', subject, 'the bound module exports no wrapper for it');
37
+ continue;
38
+ }
39
+ const example = spec.examples[name];
40
+ if (!example) {
41
+ out.check('tier2-forwards-value', subject, 'has no example, so the kit cannot mount it: add one to `examples`');
42
+ continue;
43
+ }
44
+ const callback = control.callbacks[0];
45
+ const run = exampleContext(name, []);
46
+ run.plan(RESULT);
47
+ let mounted;
48
+ try {
49
+ const elements = exampleRender(example)(run.ctx);
50
+ mounted = await mount(createElement(Fragment, null, ...(Array.isArray(elements) ? elements : [elements])), spec.wrapper);
51
+ }
52
+ catch (err) {
53
+ out.check('tier2-forwards-value', subject, `its example failed to mount: ${describeError(err)}`);
54
+ continue;
55
+ }
56
+ try {
57
+ const id = kitBindingId(name, 'self');
58
+ const reg = mounted.registry.controls().find(c => c.id === id);
59
+ if (!reg) {
60
+ out.check('registers-declared-kind', subject, `did not register its binding (${id}): a wrapper calls useAgentBinding with \`agent\``);
61
+ continue;
62
+ }
63
+ out.check('registers-declared-kind', subject, reg.kind === control.kind ? null : `registers as "${reg.kind}", but the mapping declares "${control.kind}"`);
64
+ const given = exampleValue(example, 'self');
65
+ const value = given.given ? given.value : reg.valueSchema ? sampleValue(reg.valueSchema, reg.value) : undefined;
66
+ run.calls.clear();
67
+ const result = await runRegistration(reg, value);
68
+ const calls = run.calls.get(callback) ?? [];
69
+ if (!calls.length) {
70
+ out.check('tier2-forwards-value', subject, `running it did not call the app's ${callback}${result.ok ? '' : ` (${result.code}: ${result.message})`}`);
71
+ continue;
72
+ }
73
+ if (control.valueFrom) {
74
+ const passed = at(calls[0][control.valueFrom.arg], control.valueFrom.path);
75
+ const where = `argument ${control.valueFrom.arg}${control.valueFrom.path ? `.${control.valueFrom.path}` : ''}`;
76
+ out.check('tier2-forwards-value', subject, sameValue(passed, value)
77
+ ? null
78
+ : `set to ${JSON.stringify(value)}, it called ${callback} with ${JSON.stringify(passed)} at ${where}, where the mapping says the value is`);
79
+ }
80
+ out.check('run-returns-result', subject, sameValue(result, RESULT) ? null : `its ${callback} returned ${JSON.stringify(RESULT)}, but run returned ${JSON.stringify(result)}`);
81
+ }
82
+ finally {
83
+ await mounted.unmount();
84
+ }
85
+ }
86
+ // Every uncontrolled use is reported, so the app learns its control would not show the value.
87
+ const reported = new Set((spec.reported ?? []).map(u => `${u.component}@${u.file}:${u.line}`));
88
+ for (const use of spec.uses ?? []) {
89
+ const controlled = mapping.controls[use.component]?.controlled;
90
+ if (!controlled || use.props.includes(controlled))
91
+ continue;
92
+ out.check('tier2-reports-uncontrolled', `${use.component} at ${use.file}:${use.line}`, reported.has(`${use.component}@${use.file}:${use.line}`)
93
+ ? null
94
+ : `does not pass ${controlled}, so the control would not show a value the assistant sets, and the generator did not report it`);
95
+ }
96
+ return out.report();
97
+ }
98
+ //# sourceMappingURL=tier2.js.map