@ggui-ai/ui-visual-tester 0.1.0-rc.1
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 +201 -0
- package/README.md +58 -0
- package/dist/fixture-runtime.d.ts +84 -0
- package/dist/fixture-runtime.d.ts.map +1 -0
- package/dist/fixture-runtime.js +280 -0
- package/dist/index.d.ts +115 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +15 -0
- package/dist/validate.d.ts +31 -0
- package/dist/validate.d.ts.map +1 -0
- package/dist/validate.js +195 -0
- package/fixture/fixture-runtime.js +50833 -0
- package/package.json +75 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for describing the origin of the Work and
|
|
141
|
+
reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Support. While redistributing the Work or
|
|
166
|
+
Derivative Works thereof, You may choose to offer, and charge a
|
|
167
|
+
fee for, acceptance of support, warranty, indemnity, or other
|
|
168
|
+
liability obligations and/or rights consistent with this License.
|
|
169
|
+
However, in accepting such obligations, You may act only on Your
|
|
170
|
+
own behalf and on Your sole responsibility, not on behalf of any
|
|
171
|
+
other Contributor, and only if You agree to indemnify, defend,
|
|
172
|
+
and hold each Contributor harmless for any liability incurred by,
|
|
173
|
+
or claims asserted against, such Contributor by reason of your
|
|
174
|
+
accepting any such warranty or support.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Loqu, Inc. (Guuey)
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
200
|
+
implied. See the License for the specific language governing
|
|
201
|
+
permissions and limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# @ggui-ai/ui-visual-tester
|
|
2
|
+
|
|
3
|
+
Behavioral validator for [ggui](https://ggui.ai)-generated component code.
|
|
4
|
+
|
|
5
|
+
Structural validators (schema checks, wire-preservation, compile/lint)
|
|
6
|
+
confirm that a component is _shaped_ correctly. They cannot tell you
|
|
7
|
+
whether a button actually _does_ anything when clicked. This package
|
|
8
|
+
closes that gap.
|
|
9
|
+
|
|
10
|
+
`validateContractBehavior` renders a component in a real Chromium tab
|
|
11
|
+
via Playwright, drives every action declared in its contract, and
|
|
12
|
+
classifies each one:
|
|
13
|
+
|
|
14
|
+
- **context-bound** actions (no `nextStep`) must mutate DOM bound to
|
|
15
|
+
contract state.
|
|
16
|
+
- **agent-bound** actions (with `nextStep`) must dispatch to the agent.
|
|
17
|
+
- ambiguous actions accept either signal.
|
|
18
|
+
|
|
19
|
+
Failures are reported per-action (`action-no-effect`,
|
|
20
|
+
`action-not-rendered`, `render-failed`, `timeout`).
|
|
21
|
+
|
|
22
|
+
## Install
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
pnpm add @ggui-ai/ui-visual-tester
|
|
26
|
+
pnpm add -D playwright-core # optional peer dependency
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
`playwright-core` is an **optional peer dependency** — the validator
|
|
30
|
+
does not import it directly. The caller injects the module, which keeps
|
|
31
|
+
the default install free of the ~300MB Chromium binary.
|
|
32
|
+
|
|
33
|
+
## Usage
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
import { chromium } from "playwright-core";
|
|
37
|
+
import { validateContractBehavior } from "@ggui-ai/ui-visual-tester";
|
|
38
|
+
|
|
39
|
+
const result = await validateContractBehavior({
|
|
40
|
+
componentCode,
|
|
41
|
+
contract,
|
|
42
|
+
playwright: { chromium },
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
if (!result.ok) {
|
|
46
|
+
for (const failure of result.failures) {
|
|
47
|
+
console.error(failure.kind, failure.actionName, failure.diagnostic);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Calling `validateContractBehavior` without a `playwright` module throws
|
|
53
|
+
`PlaywrightNotAvailableError` with a clear pointer — Chromium is opt-in
|
|
54
|
+
by design.
|
|
55
|
+
|
|
56
|
+
## License
|
|
57
|
+
|
|
58
|
+
Apache-2.0
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser-side fixture runtime for `validateContractBehavior`.
|
|
3
|
+
*
|
|
4
|
+
* Bundled to an IIFE by `scripts/build-fixture-bundle.mjs` and injected
|
|
5
|
+
* into the test page via `addScriptTag({content: bundle})`. Exposes
|
|
6
|
+
* one global function:
|
|
7
|
+
*
|
|
8
|
+
* window.__validateContractBehavior_run__(input): Promise<RunOutcome>
|
|
9
|
+
*
|
|
10
|
+
* The Node-side driver (`validate.ts`) calls this once per action with
|
|
11
|
+
* the compiled component source + the classification gate (Option C —
|
|
12
|
+
* `agent-bound` vs `context-bound`). The fixture mounts the component
|
|
13
|
+
* once, finds the button by label, clicks it, then waits for the
|
|
14
|
+
* required signal to fire.
|
|
15
|
+
*/
|
|
16
|
+
import * as React from 'react';
|
|
17
|
+
import * as ReactDomClient from 'react-dom/client';
|
|
18
|
+
import * as DesignPrimitives from '@ggui-ai/design/primitives';
|
|
19
|
+
import * as DesignComponents from '@ggui-ai/design/components';
|
|
20
|
+
import * as DesignCompositions from '@ggui-ai/design/compositions';
|
|
21
|
+
import * as DesignInteract from '@ggui-ai/design/interact';
|
|
22
|
+
import * as Wire from '@ggui-ai/wire';
|
|
23
|
+
interface DispatchRecord {
|
|
24
|
+
readonly actionName: string;
|
|
25
|
+
readonly data: unknown;
|
|
26
|
+
readonly t: number;
|
|
27
|
+
}
|
|
28
|
+
type ActionClassification = 'agent-bound' | 'context-bound';
|
|
29
|
+
interface RunInput {
|
|
30
|
+
readonly componentCode: string;
|
|
31
|
+
readonly contract: unknown;
|
|
32
|
+
readonly actionName: string;
|
|
33
|
+
readonly classification: ActionClassification;
|
|
34
|
+
readonly settleMs: number;
|
|
35
|
+
readonly waitMs: number;
|
|
36
|
+
}
|
|
37
|
+
type RunOutcome = {
|
|
38
|
+
readonly status: 'render-failed';
|
|
39
|
+
readonly diagnostic: string;
|
|
40
|
+
} | {
|
|
41
|
+
readonly status: 'action-not-rendered';
|
|
42
|
+
} | {
|
|
43
|
+
readonly status: 'action-no-effect';
|
|
44
|
+
readonly diagnostic: string;
|
|
45
|
+
} | {
|
|
46
|
+
readonly status: 'ok';
|
|
47
|
+
readonly dispatchFired: boolean;
|
|
48
|
+
readonly domChanged: boolean;
|
|
49
|
+
};
|
|
50
|
+
declare global {
|
|
51
|
+
interface Window {
|
|
52
|
+
__ggui_test_dispatches__?: DispatchRecord[];
|
|
53
|
+
__validateContractBehavior_run__?: (input: RunInput) => Promise<RunOutcome>;
|
|
54
|
+
__ggui__?: GguiRegistry;
|
|
55
|
+
__REACT?: typeof React;
|
|
56
|
+
__GGUI_PRIMITIVES?: typeof DesignPrimitives;
|
|
57
|
+
__GGUI_COMPONENTS?: typeof DesignComponents;
|
|
58
|
+
__GGUI_COMPOSITIONS?: typeof DesignCompositions;
|
|
59
|
+
__GGUI_INTERACT?: typeof DesignInteract;
|
|
60
|
+
__GGUI_APP_COMPONENTS?: Record<string, unknown>;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
interface GguiRegistry {
|
|
64
|
+
react: typeof React;
|
|
65
|
+
reactDom: typeof ReactDomClient;
|
|
66
|
+
primitives: typeof DesignPrimitives;
|
|
67
|
+
components: typeof DesignComponents;
|
|
68
|
+
compositions: typeof DesignCompositions;
|
|
69
|
+
interact: typeof DesignInteract;
|
|
70
|
+
/**
|
|
71
|
+
* App-components slot — populated by the renderer when an app's
|
|
72
|
+
* `appComponents` table is in scope. ui-visual-tester leaves it empty
|
|
73
|
+
* (the validator's job is to verify a generated component's contract
|
|
74
|
+
* wiring, not its app-component composition); generated code that
|
|
75
|
+
* imports `@ggui-ai/design/app-components` will get an empty named
|
|
76
|
+
* shim. If a real failure occurs from this, the diagnostic surfaces
|
|
77
|
+
* it via render-failed.
|
|
78
|
+
*/
|
|
79
|
+
appComponents: Record<string, unknown>;
|
|
80
|
+
wire: typeof Wire;
|
|
81
|
+
adapters: Record<string, unknown>;
|
|
82
|
+
}
|
|
83
|
+
export {};
|
|
84
|
+
//# sourceMappingURL=fixture-runtime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fixture-runtime.d.ts","sourceRoot":"","sources":["../src/fixture-runtime.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,cAAc,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,gBAAgB,MAAM,4BAA4B,CAAC;AAC/D,OAAO,KAAK,gBAAgB,MAAM,4BAA4B,CAAC;AAC/D,OAAO,KAAK,kBAAkB,MAAM,8BAA8B,CAAC;AACnE,OAAO,KAAK,cAAc,MAAM,0BAA0B,CAAC;AAC3D,OAAO,KAAK,IAAI,MAAM,eAAe,CAAC;AAqCtC,UAAU,cAAc;IACtB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,KAAK,oBAAoB,GAAG,aAAa,GAAG,eAAe,CAAC;AAE5D,UAAU,QAAQ;IAChB,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,cAAc,EAAE,oBAAoB,CAAC;IAC9C,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED,KAAK,UAAU,GACX;IAAE,QAAQ,CAAC,MAAM,EAAE,eAAe,CAAC;IAAC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;CAAE,GACjE;IAAE,QAAQ,CAAC,MAAM,EAAE,qBAAqB,CAAA;CAAE,GAC1C;IAAE,QAAQ,CAAC,MAAM,EAAE,kBAAkB,CAAC;IAAC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;CAAE,GACpE;IACE,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC;IACtB,QAAQ,CAAC,aAAa,EAAE,OAAO,CAAC;IAChC,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;CAC9B,CAAC;AAEN,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,wBAAwB,CAAC,EAAE,cAAc,EAAE,CAAC;QAC5C,gCAAgC,CAAC,EAAE,CAAC,KAAK,EAAE,QAAQ,KAAK,OAAO,CAAC,UAAU,CAAC,CAAC;QAC5E,QAAQ,CAAC,EAAE,YAAY,CAAC;QACxB,OAAO,CAAC,EAAE,OAAO,KAAK,CAAC;QACvB,iBAAiB,CAAC,EAAE,OAAO,gBAAgB,CAAC;QAC5C,iBAAiB,CAAC,EAAE,OAAO,gBAAgB,CAAC;QAC5C,mBAAmB,CAAC,EAAE,OAAO,kBAAkB,CAAC;QAChD,eAAe,CAAC,EAAE,OAAO,cAAc,CAAC;QACxC,qBAAqB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KACjD;CACF;AAED,UAAU,YAAY;IACpB,KAAK,EAAE,OAAO,KAAK,CAAC;IACpB,QAAQ,EAAE,OAAO,cAAc,CAAC;IAChC,UAAU,EAAE,OAAO,gBAAgB,CAAC;IACpC,UAAU,EAAE,OAAO,gBAAgB,CAAC;IACpC,YAAY,EAAE,OAAO,kBAAkB,CAAC;IACxC,QAAQ,EAAE,OAAO,cAAc,CAAC;IAChC;;;;;;;;OAQG;IACH,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACvC,IAAI,EAAE,OAAO,IAAI,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC"}
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser-side fixture runtime for `validateContractBehavior`.
|
|
3
|
+
*
|
|
4
|
+
* Bundled to an IIFE by `scripts/build-fixture-bundle.mjs` and injected
|
|
5
|
+
* into the test page via `addScriptTag({content: bundle})`. Exposes
|
|
6
|
+
* one global function:
|
|
7
|
+
*
|
|
8
|
+
* window.__validateContractBehavior_run__(input): Promise<RunOutcome>
|
|
9
|
+
*
|
|
10
|
+
* The Node-side driver (`validate.ts`) calls this once per action with
|
|
11
|
+
* the compiled component source + the classification gate (Option C —
|
|
12
|
+
* `agent-bound` vs `context-bound`). The fixture mounts the component
|
|
13
|
+
* once, finds the button by label, clicks it, then waits for the
|
|
14
|
+
* required signal to fire.
|
|
15
|
+
*/
|
|
16
|
+
import * as React from 'react';
|
|
17
|
+
import * as ReactDomClient from 'react-dom/client';
|
|
18
|
+
import * as DesignPrimitives from '@ggui-ai/design/primitives';
|
|
19
|
+
import * as DesignComponents from '@ggui-ai/design/components';
|
|
20
|
+
import * as DesignCompositions from '@ggui-ai/design/compositions';
|
|
21
|
+
import * as DesignInteract from '@ggui-ai/design/interact';
|
|
22
|
+
import * as Wire from '@ggui-ai/wire';
|
|
23
|
+
import { rewriteImports, stripMarkers, } from '@ggui-ai/design/rendering';
|
|
24
|
+
function parseActionEntry(raw) {
|
|
25
|
+
if (raw === null || typeof raw !== 'object')
|
|
26
|
+
return null;
|
|
27
|
+
const r = raw;
|
|
28
|
+
if (typeof r.label !== 'string')
|
|
29
|
+
return null;
|
|
30
|
+
return { label: r.label };
|
|
31
|
+
}
|
|
32
|
+
function parseContract(raw) {
|
|
33
|
+
const out = {};
|
|
34
|
+
if (raw === null || typeof raw !== 'object')
|
|
35
|
+
return { actionSpec: out };
|
|
36
|
+
const v = raw;
|
|
37
|
+
if (v.actionSpec === null || typeof v.actionSpec !== 'object') {
|
|
38
|
+
return { actionSpec: out };
|
|
39
|
+
}
|
|
40
|
+
for (const [name, entry] of Object.entries(v.actionSpec)) {
|
|
41
|
+
const parsed = parseActionEntry(entry);
|
|
42
|
+
if (parsed !== null)
|
|
43
|
+
out[name] = parsed;
|
|
44
|
+
}
|
|
45
|
+
return { actionSpec: out };
|
|
46
|
+
}
|
|
47
|
+
function installRegistry() {
|
|
48
|
+
const registry = {
|
|
49
|
+
react: React,
|
|
50
|
+
reactDom: ReactDomClient,
|
|
51
|
+
primitives: DesignPrimitives,
|
|
52
|
+
components: DesignComponents,
|
|
53
|
+
compositions: DesignCompositions,
|
|
54
|
+
interact: DesignInteract,
|
|
55
|
+
appComponents: {},
|
|
56
|
+
wire: Wire,
|
|
57
|
+
adapters: {},
|
|
58
|
+
};
|
|
59
|
+
window.__ggui__ = registry;
|
|
60
|
+
window.__REACT = React;
|
|
61
|
+
window.__GGUI_PRIMITIVES = DesignPrimitives;
|
|
62
|
+
window.__GGUI_COMPONENTS = DesignComponents;
|
|
63
|
+
window.__GGUI_COMPOSITIONS = DesignCompositions;
|
|
64
|
+
window.__GGUI_INTERACT = DesignInteract;
|
|
65
|
+
window.__GGUI_APP_COMPONENTS = registry.appComponents;
|
|
66
|
+
return registry;
|
|
67
|
+
}
|
|
68
|
+
function findActionButton(root, label) {
|
|
69
|
+
const ariaMatch = root.querySelector(`[aria-label="${CSS.escape(label)}"]`);
|
|
70
|
+
if (ariaMatch instanceof HTMLElement)
|
|
71
|
+
return ariaMatch;
|
|
72
|
+
const lc = label.toLowerCase();
|
|
73
|
+
const candidates = root.querySelectorAll('button, [role="button"], a, [data-action]');
|
|
74
|
+
for (const el of Array.from(candidates)) {
|
|
75
|
+
if (!(el instanceof HTMLElement))
|
|
76
|
+
continue;
|
|
77
|
+
const txt = (el.textContent ?? '').trim().toLowerCase();
|
|
78
|
+
if (txt.length > 0 && txt.includes(lc))
|
|
79
|
+
return el;
|
|
80
|
+
}
|
|
81
|
+
for (const el of Array.from(root.querySelectorAll('*'))) {
|
|
82
|
+
if (!(el instanceof HTMLElement))
|
|
83
|
+
continue;
|
|
84
|
+
const txt = (el.textContent ?? '').trim().toLowerCase();
|
|
85
|
+
if (txt === lc)
|
|
86
|
+
return el;
|
|
87
|
+
}
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
async function loadModule(code) {
|
|
91
|
+
const blob = new Blob([code], { type: 'application/javascript' });
|
|
92
|
+
const url = URL.createObjectURL(blob);
|
|
93
|
+
try {
|
|
94
|
+
return await import(/* @vite-ignore */ url);
|
|
95
|
+
}
|
|
96
|
+
finally {
|
|
97
|
+
URL.revokeObjectURL(url);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
function hoistImports(code) {
|
|
101
|
+
const parts = code.split(';');
|
|
102
|
+
const imports = [];
|
|
103
|
+
const rest = [];
|
|
104
|
+
for (const part of parts) {
|
|
105
|
+
const trimmed = part.trimStart();
|
|
106
|
+
if (trimmed.startsWith('import')) {
|
|
107
|
+
imports.push(part);
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
rest.push(part);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
if (imports.length === 0)
|
|
114
|
+
return code;
|
|
115
|
+
return imports.join(';') + ';' + rest.join(';');
|
|
116
|
+
}
|
|
117
|
+
async function evaluateComponent(code) {
|
|
118
|
+
const cleaned = stripMarkers(code);
|
|
119
|
+
const hoisted = hoistImports(cleaned);
|
|
120
|
+
const rewritten = rewriteImports(hoisted, { mode: 'data-url' });
|
|
121
|
+
const mod = await loadModule(rewritten);
|
|
122
|
+
const Comp = mod.default ??
|
|
123
|
+
Object.values(mod).find((v) => typeof v === 'function');
|
|
124
|
+
if (Comp === undefined) {
|
|
125
|
+
throw new Error('Module does not export a default component');
|
|
126
|
+
}
|
|
127
|
+
return Comp;
|
|
128
|
+
}
|
|
129
|
+
function mountTree(Comp) {
|
|
130
|
+
const container = document.createElement('div');
|
|
131
|
+
container.id = 'ggui-vt-mount';
|
|
132
|
+
document.body.replaceChildren(container);
|
|
133
|
+
installRegistry();
|
|
134
|
+
const dispatches = window.__ggui_test_dispatches__ ?? [];
|
|
135
|
+
window.__ggui_test_dispatches__ = dispatches;
|
|
136
|
+
/**
|
|
137
|
+
* Minimal `WireConfig` for the fixture. The fixture only needs
|
|
138
|
+
* `dispatch` (records into `__ggui_test_dispatches__` for the
|
|
139
|
+
* agent-bound classification gate) and `subscribe` (no-op — no
|
|
140
|
+
* streams in the validator's scope).
|
|
141
|
+
*/
|
|
142
|
+
const wireConfig = {
|
|
143
|
+
app: { appId: 'vt-app', appName: 'vt-app' },
|
|
144
|
+
session: { sessionId: 'vt-session', isConnected: true },
|
|
145
|
+
auth: { isAuthenticated: false },
|
|
146
|
+
dispatch: (actionName, data) => {
|
|
147
|
+
dispatches.push({ actionName, data, t: Date.now() });
|
|
148
|
+
},
|
|
149
|
+
subscribe: () => () => { },
|
|
150
|
+
};
|
|
151
|
+
const root = ReactDomClient.createRoot(container);
|
|
152
|
+
const componentElement = React.createElement(Comp, {});
|
|
153
|
+
const tree = React.createElement(Wire.GguiWireProvider, {
|
|
154
|
+
config: wireConfig,
|
|
155
|
+
children: componentElement,
|
|
156
|
+
});
|
|
157
|
+
root.render(tree);
|
|
158
|
+
return { container, root };
|
|
159
|
+
}
|
|
160
|
+
function tearDown(handles) {
|
|
161
|
+
handles.root.unmount();
|
|
162
|
+
handles.container.remove();
|
|
163
|
+
if (window.__ggui_test_dispatches__) {
|
|
164
|
+
window.__ggui_test_dispatches__.length = 0;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
function delay(ms) {
|
|
168
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
169
|
+
}
|
|
170
|
+
function signalRequirement(classification) {
|
|
171
|
+
if (classification === 'agent-bound') {
|
|
172
|
+
return {
|
|
173
|
+
requireDispatch: true,
|
|
174
|
+
requireDom: false,
|
|
175
|
+
description: 'agent-bound (nextStep present): require dispatch(...) to fire',
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
// context-bound — local state / DOM mutation expected.
|
|
179
|
+
return {
|
|
180
|
+
requireDispatch: false,
|
|
181
|
+
requireDom: true,
|
|
182
|
+
description: 'context-bound (no nextStep): require DOM change post-click',
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
async function run(input) {
|
|
186
|
+
installRegistry();
|
|
187
|
+
let Comp;
|
|
188
|
+
try {
|
|
189
|
+
Comp = await evaluateComponent(input.componentCode);
|
|
190
|
+
}
|
|
191
|
+
catch (err) {
|
|
192
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
193
|
+
return { status: 'render-failed', diagnostic: msg };
|
|
194
|
+
}
|
|
195
|
+
const errSlot = { current: null };
|
|
196
|
+
const onWindowError = (event) => {
|
|
197
|
+
if (errSlot.current === null) {
|
|
198
|
+
errSlot.current =
|
|
199
|
+
event.error instanceof Error ? event.error : new Error(event.message);
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
window.addEventListener('error', onWindowError);
|
|
203
|
+
const view = parseContract(input.contract);
|
|
204
|
+
let handles = null;
|
|
205
|
+
try {
|
|
206
|
+
try {
|
|
207
|
+
handles = mountTree(Comp);
|
|
208
|
+
}
|
|
209
|
+
catch (err) {
|
|
210
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
211
|
+
return { status: 'render-failed', diagnostic: msg };
|
|
212
|
+
}
|
|
213
|
+
await delay(input.settleMs);
|
|
214
|
+
if (errSlot.current !== null) {
|
|
215
|
+
return { status: 'render-failed', diagnostic: errSlot.current.message };
|
|
216
|
+
}
|
|
217
|
+
const entry = view.actionSpec[input.actionName];
|
|
218
|
+
if (entry === undefined) {
|
|
219
|
+
return {
|
|
220
|
+
status: 'render-failed',
|
|
221
|
+
diagnostic: `actionSpec.${input.actionName} missing`,
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
const button = findActionButton(handles.container, entry.label);
|
|
225
|
+
if (button === null) {
|
|
226
|
+
return { status: 'action-not-rendered' };
|
|
227
|
+
}
|
|
228
|
+
const beforeText = handles.container.textContent ?? '';
|
|
229
|
+
const beforeHtml = handles.container.innerHTML;
|
|
230
|
+
const dispatchesBefore = (window.__ggui_test_dispatches__ ?? []).length;
|
|
231
|
+
button.click();
|
|
232
|
+
const start = Date.now();
|
|
233
|
+
let dispatchFired = false;
|
|
234
|
+
let domChanged = false;
|
|
235
|
+
while (Date.now() - start < input.waitMs) {
|
|
236
|
+
await delay(50);
|
|
237
|
+
if (!dispatchFired &&
|
|
238
|
+
(window.__ggui_test_dispatches__ ?? []).length > dispatchesBefore) {
|
|
239
|
+
dispatchFired = true;
|
|
240
|
+
}
|
|
241
|
+
if (!domChanged) {
|
|
242
|
+
const afterText = handles.container.textContent ?? '';
|
|
243
|
+
const afterHtml = handles.container.innerHTML;
|
|
244
|
+
if (afterText !== beforeText || afterHtml !== beforeHtml) {
|
|
245
|
+
domChanged = true;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
if (dispatchFired && domChanged)
|
|
249
|
+
break;
|
|
250
|
+
// Early-exit if the REQUIRED signal has fired (don't wait for the
|
|
251
|
+
// other one — speeds up the slow stage when the wiring is correct).
|
|
252
|
+
const req = signalRequirement(input.classification);
|
|
253
|
+
if (req.requireDispatch && dispatchFired)
|
|
254
|
+
break;
|
|
255
|
+
if (req.requireDom && domChanged)
|
|
256
|
+
break;
|
|
257
|
+
}
|
|
258
|
+
const req = signalRequirement(input.classification);
|
|
259
|
+
const required = (req.requireDispatch ? dispatchFired : true) &&
|
|
260
|
+
(req.requireDom ? domChanged : true);
|
|
261
|
+
if (!required) {
|
|
262
|
+
const missing = [];
|
|
263
|
+
if (req.requireDispatch && !dispatchFired)
|
|
264
|
+
missing.push('dispatch');
|
|
265
|
+
if (req.requireDom && !domChanged)
|
|
266
|
+
missing.push('DOM change');
|
|
267
|
+
return {
|
|
268
|
+
status: 'action-no-effect',
|
|
269
|
+
diagnostic: `${req.description}; observed dispatch=${dispatchFired}, domChanged=${domChanged}; missing=${missing.join('+')}`,
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
return { status: 'ok', dispatchFired, domChanged };
|
|
273
|
+
}
|
|
274
|
+
finally {
|
|
275
|
+
window.removeEventListener('error', onWindowError);
|
|
276
|
+
if (handles !== null)
|
|
277
|
+
tearDown(handles);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
window.__validateContractBehavior_run__ = run;
|