@kumikijs/cli 0.1.0 → 0.2.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 +202 -0
- package/README.md +24 -24
- package/dist/index.d.ts +28 -8
- package/dist/index.js +2 -2
- package/dist/kumiki.js +51 -6
- package/dist/{smoke-CY4f_tnY.js → mutate-BN6o0IXW.js} +352 -118
- package/package.json +17 -24
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
# @kumikijs/cli
|
|
2
|
-
|
|
3
|
-
The `kumiki` command — build, check, and AI-edit (list/view/add/replace/remove/rename/fix) Kumiki sources. Part of [Kumiki](https://github.com/kage1020/Kumiki), an AI-first web framework language.
|
|
4
|
-
|
|
5
|
-
## Install
|
|
6
|
-
|
|
7
|
-
```sh
|
|
8
|
-
npm i -g @kumikijs/cli
|
|
9
|
-
# or run without installing
|
|
10
|
-
npx @kumikijs/cli --help
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
## Usage
|
|
14
|
-
|
|
15
|
-
```sh
|
|
16
|
-
kumiki build <input.kumiki> <outdir> # compile to a runnable app
|
|
17
|
-
kumiki check <input.kumiki> # type-check and report diagnostics
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
Run `kumiki` with no arguments to see the full command list (list / view / add / replace / remove / rename / fix / smoke / run).
|
|
21
|
-
|
|
22
|
-
## License
|
|
23
|
-
|
|
24
|
-
Apache-2.0
|
|
1
|
+
# @kumikijs/cli
|
|
2
|
+
|
|
3
|
+
The `kumiki` command — build, check, and AI-edit (list/view/add/replace/remove/rename/fix) Kumiki sources. Part of [Kumiki](https://github.com/kage1020/Kumiki), an AI-first web framework language.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm i -g @kumikijs/cli
|
|
9
|
+
# or run without installing
|
|
10
|
+
npx @kumikijs/cli --help
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
kumiki build <input.kumiki> <outdir> # compile to a runnable app
|
|
17
|
+
kumiki check <input.kumiki> # type-check and report diagnostics
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Run `kumiki` with no arguments to see the full command list (list / view / add / replace / remove / rename / fix / smoke / run).
|
|
21
|
+
|
|
22
|
+
## License
|
|
23
|
+
|
|
24
|
+
Apache-2.0
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Def, KumikiError, Program } from "@kumikijs/compiler";
|
|
2
|
-
import { Scenario, ScenarioReport, SmokeReport } from "@kumikijs/runtime";
|
|
2
|
+
import { Scenario, ScenarioReport, SmokeReport, TestResult } from "@kumikijs/runtime";
|
|
3
3
|
|
|
4
4
|
//#region src/store.d.ts
|
|
5
5
|
type DefRange = {
|
|
@@ -46,7 +46,27 @@ type AutoPatch = {
|
|
|
46
46
|
apply: (text: string) => string;
|
|
47
47
|
};
|
|
48
48
|
declare function planFixes(store: Store, errors: KumikiError[]): AutoPatch[];
|
|
49
|
-
declare function fixCmd(path: string, apply: boolean, onlyCode?: string): void;
|
|
49
|
+
declare function fixCmd(path: string, apply: boolean, onlyCode?: string, capabilities?: string[]): void;
|
|
50
|
+
type FixFromTestOutcome = {
|
|
51
|
+
/** true when the named test ends up passing, or a fix is available in dry-run. */ok: boolean;
|
|
52
|
+
status: "not-found" | "already-pass" | "proposed" | "applied" | "no-patch" | "compile-proposed" | "compile-remaining"; /** Post-apply status of the named test, when an apply happened. */
|
|
53
|
+
pass?: boolean; /** The behavioral patch proposed or applied. */
|
|
54
|
+
patch?: AutoPatch; /** Count of Tier-1 compile fixes proposed or applied. */
|
|
55
|
+
compileFixes?: number; /** Names of other tests that regressed after applying. */
|
|
56
|
+
regressed?: string[];
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* A deterministic patch from a failing test, when one is provable: the failing
|
|
60
|
+
* leaf is a string whose *actual* value appears verbatim, exactly once, as a
|
|
61
|
+
* source string literal **in implementation code** (tile / reducer), not in a
|
|
62
|
+
* `test` body. `excludedLineRanges` are the 1-based inclusive line spans of the
|
|
63
|
+
* file's `test` definitions; a match inside one is skipped, because patching a
|
|
64
|
+
* test's own `given` / `expect` data would mutate the fixture into passing
|
|
65
|
+
* without touching any production definition. Returns null when no such patch
|
|
66
|
+
* exists — the caller reports the diff instead.
|
|
67
|
+
*/
|
|
68
|
+
declare function planTestPatch(source: string, r: TestResult, excludedLineRanges?: Array<[number, number]>): AutoPatch | null;
|
|
69
|
+
declare function fixFromTest(path: string, testName: string, apply: boolean, capabilities?: string[]): Promise<FixFromTestOutcome>;
|
|
50
70
|
//#endregion
|
|
51
71
|
//#region src/mutate.d.ts
|
|
52
72
|
declare function addDef(path: string, layer: string, name: string, body: string): void;
|
|
@@ -56,13 +76,13 @@ declare function renameDef(path: string, qname: string, newName: string): void;
|
|
|
56
76
|
//#endregion
|
|
57
77
|
//#region src/smoke.d.ts
|
|
58
78
|
/** Compile + mount + exercise a Kumiki source string; return the smoke report. */
|
|
59
|
-
declare function smokeSource(source: string): Promise<SmokeReport>;
|
|
60
|
-
declare function smokeFile(path: string): Promise<SmokeReport>;
|
|
79
|
+
declare function smokeSource(source: string, capabilities?: string[]): Promise<SmokeReport>;
|
|
80
|
+
declare function smokeFile(path: string, capabilities?: string[]): Promise<SmokeReport>;
|
|
61
81
|
/** CLI entry: print a human-readable report and exit non-zero on failure. */
|
|
62
|
-
declare function smokeCmd(path: string): Promise<void>;
|
|
82
|
+
declare function smokeCmd(path: string, capabilities?: string[]): Promise<void>;
|
|
63
83
|
/** Compile + mount + drive a scenario; return the structured trace. */
|
|
64
|
-
declare function runScenarioSource(source: string, scenario: Scenario): Promise<ScenarioReport>;
|
|
84
|
+
declare function runScenarioSource(source: string, scenario: Scenario, capabilities?: string[]): Promise<ScenarioReport>;
|
|
65
85
|
/** CLI entry: run a scenario JSON file against a .kumiki file; print the trace. */
|
|
66
|
-
declare function runCmd(kumikiPath: string, scenarioPath: string): Promise<void>;
|
|
86
|
+
declare function runCmd(kumikiPath: string, scenarioPath: string, capabilities?: string[]): Promise<void>;
|
|
67
87
|
//#endregion
|
|
68
|
-
export { type AutoPatch, type Store, addDef, directDeps, findReferences, fixCmd, listDefs, load, planFixes, removeDef, renameDef, replaceDef, runCmd, runScenarioSource, smokeCmd, smokeFile, smokeSource, viewDef, viewWithDeps };
|
|
88
|
+
export { type AutoPatch, type FixFromTestOutcome, type Store, addDef, directDeps, findReferences, fixCmd, fixFromTest, listDefs, load, planFixes, planTestPatch, removeDef, renameDef, replaceDef, runCmd, runScenarioSource, smokeCmd, smokeFile, smokeSource, viewDef, viewWithDeps };
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { _ as
|
|
2
|
-
export { addDef, directDeps, findReferences, fixCmd, listDefs, load, planFixes, removeDef, renameDef, replaceDef, runCmd, runScenarioSource, smokeCmd, smokeFile, smokeSource, viewDef, viewWithDeps };
|
|
1
|
+
import { _ as smokeCmd, a as fixCmd, c as planTestPatch, d as listDefs, f as load, g as runScenarioSource, h as runCmd, i as replaceDef, l as directDeps, m as viewWithDeps, n as removeDef, o as fixFromTest, p as viewDef, r as renameDef, s as planFixes, t as addDef, u as findReferences, v as smokeFile, y as smokeSource } from "./mutate-BN6o0IXW.js";
|
|
2
|
+
export { addDef, directDeps, findReferences, fixCmd, fixFromTest, listDefs, load, planFixes, planTestPatch, removeDef, renameDef, replaceDef, runCmd, runScenarioSource, smokeCmd, smokeFile, smokeSource, viewDef, viewWithDeps };
|
package/dist/kumiki.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { _ as
|
|
2
|
+
import { _ as smokeCmd, a as fixCmd, b as testCmd, d as listDefs, f as load, h as runCmd, i as replaceDef, m as viewWithDeps, n as removeDef, o as fixFromTest, p as viewDef, r as renameDef, t as addDef, u as findReferences } from "./mutate-BN6o0IXW.js";
|
|
3
3
|
import { createRequire } from "node:module";
|
|
4
4
|
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
5
5
|
import { check, compile } from "@kumikijs/compiler";
|
|
6
6
|
import { resolve } from "node:path";
|
|
7
|
+
import { CapabilityManifestError, resolveCapabilities } from "@kumikijs/compiler/node";
|
|
7
8
|
//#region src/kumiki.ts
|
|
8
9
|
const require = createRequire(import.meta.url);
|
|
9
10
|
function usage() {
|
|
@@ -15,12 +16,30 @@ function usage() {
|
|
|
15
16
|
console.error(" kumiki check <input.kumiki> [--strict-a11y]");
|
|
16
17
|
console.error(" kumiki smoke <input.kumiki>");
|
|
17
18
|
console.error(" kumiki run <input.kumiki> <scenario.json>");
|
|
19
|
+
console.error(" kumiki test <input.kumiki> [name|prefix*]");
|
|
20
|
+
console.error(" kumiki fix <input.kumiki> [--apply] [<code>]");
|
|
21
|
+
console.error(" kumiki fix <input.kumiki> --auto-patch <test-name> [--apply]");
|
|
18
22
|
process.exit(2);
|
|
19
23
|
}
|
|
24
|
+
/** Resolve manifest capabilities, exiting cleanly on a malformed manifest. */
|
|
25
|
+
function capsFor(inputPath) {
|
|
26
|
+
try {
|
|
27
|
+
return resolveCapabilities(inputPath);
|
|
28
|
+
} catch (e) {
|
|
29
|
+
if (e instanceof CapabilityManifestError) {
|
|
30
|
+
console.error(`capability manifest error: ${e.message}`);
|
|
31
|
+
process.exit(1);
|
|
32
|
+
}
|
|
33
|
+
throw e;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
20
36
|
function buildCmd(inputArg, outdirArg) {
|
|
21
37
|
const inputPath = resolve(process.cwd(), inputArg);
|
|
22
38
|
const outdir = resolve(process.cwd(), outdirArg);
|
|
23
|
-
const result = compile(readFileSync(inputPath, "utf8"), {
|
|
39
|
+
const result = compile(readFileSync(inputPath, "utf8"), {
|
|
40
|
+
runtimeSpecifier: "./runtime.js",
|
|
41
|
+
capabilities: capsFor(inputPath)
|
|
42
|
+
});
|
|
24
43
|
if (result.kind === "fail") {
|
|
25
44
|
for (const err of result.errors) console.error(`${err.code} ${err.kind} at ${err.pos.line}:${err.pos.col}: ${err.message}`);
|
|
26
45
|
process.exit(1);
|
|
@@ -53,7 +72,11 @@ function refsCmd(inputArg, qname) {
|
|
|
53
72
|
for (const r of refs) console.log(`${r.qname} ${inputArg}:${r.line}`);
|
|
54
73
|
}
|
|
55
74
|
function checkCmd(inputArg, strictA11y) {
|
|
56
|
-
const
|
|
75
|
+
const inputPath = resolve(process.cwd(), inputArg);
|
|
76
|
+
const errors = check(load(inputPath).program, {
|
|
77
|
+
strictA11y,
|
|
78
|
+
capabilities: capsFor(inputPath)
|
|
79
|
+
});
|
|
57
80
|
if (errors.length === 0) {
|
|
58
81
|
console.log("ok");
|
|
59
82
|
return;
|
|
@@ -101,14 +124,23 @@ async function main(argv) {
|
|
|
101
124
|
case "smoke": {
|
|
102
125
|
const input = argv[3];
|
|
103
126
|
if (!input) usage();
|
|
104
|
-
|
|
127
|
+
const inputPath = resolve(process.cwd(), input);
|
|
128
|
+
await smokeCmd(inputPath, capsFor(inputPath));
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
case "test": {
|
|
132
|
+
const input = argv[3];
|
|
133
|
+
if (!input) usage();
|
|
134
|
+
const inputPath = resolve(process.cwd(), input);
|
|
135
|
+
await testCmd(inputPath, argv.find((a, i) => i > 3 && !a.startsWith("--")), capsFor(inputPath));
|
|
105
136
|
return;
|
|
106
137
|
}
|
|
107
138
|
case "run": {
|
|
108
139
|
const input = argv[3];
|
|
109
140
|
const scenario = argv[4];
|
|
110
141
|
if (!input || !scenario) usage();
|
|
111
|
-
|
|
142
|
+
const inputPath = resolve(process.cwd(), input);
|
|
143
|
+
await runCmd(inputPath, resolve(process.cwd(), scenario), capsFor(inputPath));
|
|
112
144
|
return;
|
|
113
145
|
}
|
|
114
146
|
case "add": {
|
|
@@ -177,11 +209,24 @@ async function main(argv) {
|
|
|
177
209
|
const file = argv[3];
|
|
178
210
|
if (!file) {
|
|
179
211
|
console.error("Usage: kumiki fix <file> [--apply] [<code>]");
|
|
212
|
+
console.error(" kumiki fix <file> --auto-patch <test-name> [--apply]");
|
|
180
213
|
process.exit(2);
|
|
181
214
|
}
|
|
182
215
|
const apply = argv.includes("--apply");
|
|
216
|
+
const autoIdx = argv.indexOf("--auto-patch");
|
|
217
|
+
if (autoIdx !== -1) {
|
|
218
|
+
const testName = argv[autoIdx + 1];
|
|
219
|
+
if (!testName || testName.startsWith("--")) {
|
|
220
|
+
console.error("Usage: kumiki fix <file> --auto-patch <test-name> [--apply]");
|
|
221
|
+
process.exit(2);
|
|
222
|
+
}
|
|
223
|
+
const fixPath = resolve(process.cwd(), file);
|
|
224
|
+
if (!(await fixFromTest(fixPath, testName, apply, capsFor(fixPath))).ok) process.exitCode = 1;
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
183
227
|
const code = argv.find((a, i) => i > 3 && a !== "--apply");
|
|
184
|
-
|
|
228
|
+
const plainPath = resolve(process.cwd(), file);
|
|
229
|
+
fixCmd(plainPath, apply, code, capsFor(plainPath));
|
|
185
230
|
return;
|
|
186
231
|
}
|
|
187
232
|
default: usage();
|
|
@@ -6,6 +6,169 @@ import { pathToFileURL } from "node:url";
|
|
|
6
6
|
import { nodeRuntimeBundleReader } from "@kumikijs/compiler/node";
|
|
7
7
|
import { runScenario, smoke } from "@kumikijs/runtime";
|
|
8
8
|
import { JSDOM } from "jsdom";
|
|
9
|
+
//#region src/smoke.ts
|
|
10
|
+
let domReady = false;
|
|
11
|
+
function ensureDom() {
|
|
12
|
+
if (domReady) return;
|
|
13
|
+
const dom = new JSDOM("<!doctype html><html><body></body></html>", { url: "http://localhost/" });
|
|
14
|
+
const g = globalThis;
|
|
15
|
+
const w = dom.window;
|
|
16
|
+
for (const key of [
|
|
17
|
+
"window",
|
|
18
|
+
"document",
|
|
19
|
+
"navigator",
|
|
20
|
+
"location",
|
|
21
|
+
"history",
|
|
22
|
+
"localStorage",
|
|
23
|
+
"sessionStorage",
|
|
24
|
+
"HTMLElement",
|
|
25
|
+
"HTMLInputElement",
|
|
26
|
+
"HTMLSelectElement",
|
|
27
|
+
"HTMLTextAreaElement",
|
|
28
|
+
"Element",
|
|
29
|
+
"Node",
|
|
30
|
+
"Event",
|
|
31
|
+
"MouseEvent",
|
|
32
|
+
"CustomEvent",
|
|
33
|
+
"KeyboardEvent",
|
|
34
|
+
"CSS",
|
|
35
|
+
"getComputedStyle"
|
|
36
|
+
]) {
|
|
37
|
+
if (w[key] === void 0) continue;
|
|
38
|
+
try {
|
|
39
|
+
g[key] = w[key];
|
|
40
|
+
} catch {
|
|
41
|
+
Object.defineProperty(g, key, {
|
|
42
|
+
value: w[key],
|
|
43
|
+
configurable: true,
|
|
44
|
+
writable: true
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
domReady = true;
|
|
49
|
+
}
|
|
50
|
+
async function loadApp(source, capabilities = [], opts = {}) {
|
|
51
|
+
const result = compile(source, {
|
|
52
|
+
runtimeSpecifier: "ignored",
|
|
53
|
+
bundle: true,
|
|
54
|
+
readRuntimeBundle: nodeRuntimeBundleReader,
|
|
55
|
+
capabilities,
|
|
56
|
+
includeTests: opts.includeTests === true
|
|
57
|
+
});
|
|
58
|
+
if (result.kind !== "ok") throw new Error(`compile failed:\n${result.errors.map((e) => `${e.code} ${e.message}`).join("\n")}`);
|
|
59
|
+
const patched = result.js.replace(/mount\(App, document\.getElementById\("root"\)\);?/, "");
|
|
60
|
+
const file = join(mkdtempSync(join(tmpdir(), "kumiki-smoke-")), "app.mjs");
|
|
61
|
+
writeFileSync(file, patched);
|
|
62
|
+
await import(pathToFileURL(file).href);
|
|
63
|
+
const app = globalThis.__kumikiApp;
|
|
64
|
+
if (!app) throw new Error("compiled module did not expose __kumikiApp");
|
|
65
|
+
return app;
|
|
66
|
+
}
|
|
67
|
+
/** Compile + mount + exercise a Kumiki source string; return the smoke report. */
|
|
68
|
+
async function smokeSource(source, capabilities = []) {
|
|
69
|
+
ensureDom();
|
|
70
|
+
const app = await loadApp(source, capabilities);
|
|
71
|
+
const doc = globalThis.document;
|
|
72
|
+
const root = doc.createElement("div");
|
|
73
|
+
doc.body.appendChild(root);
|
|
74
|
+
try {
|
|
75
|
+
return await smoke(app, root, { settleMs: 20 });
|
|
76
|
+
} finally {
|
|
77
|
+
root.remove();
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
async function smokeFile(path, capabilities = []) {
|
|
81
|
+
return smokeSource(readFileSync(path, "utf8"), capabilities);
|
|
82
|
+
}
|
|
83
|
+
/** CLI entry: print a human-readable report and exit non-zero on failure. */
|
|
84
|
+
async function smokeCmd(path, capabilities = []) {
|
|
85
|
+
const report = await smokeFile(path, capabilities);
|
|
86
|
+
if (report.ok) {
|
|
87
|
+
console.log(`ok — mounted, rendered, ${report.interactions} interaction(s), no runtime errors`);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
console.error(`runtime smoke failed (mounted=${report.mounted}, rendered=${report.rendered}, interactions=${report.interactions}):`);
|
|
91
|
+
for (const i of report.issues) console.error(` [${i.phase}] ${i.message}${i.trigger ? ` (on ${i.trigger})` : ""}`);
|
|
92
|
+
process.exit(1);
|
|
93
|
+
}
|
|
94
|
+
/** Compile + mount + drive a scenario; return the structured trace. */
|
|
95
|
+
async function runScenarioSource(source, scenario, capabilities = []) {
|
|
96
|
+
ensureDom();
|
|
97
|
+
const app = await loadApp(source, capabilities);
|
|
98
|
+
const doc = globalThis.document;
|
|
99
|
+
const root = doc.createElement("div");
|
|
100
|
+
doc.body.appendChild(root);
|
|
101
|
+
try {
|
|
102
|
+
return await runScenario(app, root, scenario, { settleMs: 20 });
|
|
103
|
+
} finally {
|
|
104
|
+
root.remove();
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/** CLI entry: run a scenario JSON file against a .kumiki file; print the trace. */
|
|
108
|
+
async function runCmd(kumikiPath, scenarioPath, capabilities = []) {
|
|
109
|
+
const scenario = JSON.parse(readFileSync(scenarioPath, "utf8"));
|
|
110
|
+
const report = await runScenarioSource(readFileSync(kumikiPath, "utf8"), scenario, capabilities);
|
|
111
|
+
for (let i = 0; i < report.steps.length; i++) {
|
|
112
|
+
const s = report.steps[i];
|
|
113
|
+
if (!s) continue;
|
|
114
|
+
const head = `step ${i}${s.label ? ` (${s.label})` : ""}${s.action ? `: ${s.action}` : ""}`;
|
|
115
|
+
const status = s.errors.length === 0 && s.failures.length === 0 ? "ok" : "FAIL";
|
|
116
|
+
console.log(`[${status}] ${head}`);
|
|
117
|
+
for (const e of s.errors) console.log(` error: ${e}`);
|
|
118
|
+
for (const f of s.failures) console.log(` assert: ${f}`);
|
|
119
|
+
}
|
|
120
|
+
console.log(report.ok ? "\nscenario passed" : "\nscenario FAILED");
|
|
121
|
+
if (!report.ok) process.exit(1);
|
|
122
|
+
}
|
|
123
|
+
/** Compile a source with tests included, import it, and run every `test` definition. */
|
|
124
|
+
async function runTestsSource(source, capabilities = []) {
|
|
125
|
+
ensureDom();
|
|
126
|
+
await loadApp(source, capabilities, { includeTests: true });
|
|
127
|
+
return (globalThis.__kumikiTests ?? []).map((t) => t.run());
|
|
128
|
+
}
|
|
129
|
+
async function testFile(path, capabilities = []) {
|
|
130
|
+
return runTestsSource(readFileSync(path, "utf8"), capabilities);
|
|
131
|
+
}
|
|
132
|
+
/** Render a scalar leaf value for the §8.7.1 value arrow (strings get quoted). */
|
|
133
|
+
function leafStr(v) {
|
|
134
|
+
try {
|
|
135
|
+
return JSON.stringify(v) ?? String(v);
|
|
136
|
+
} catch {
|
|
137
|
+
return String(v);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
/** Match a test name against a filter: exact, or a `prefix-*` / `prefix*` wildcard. */
|
|
141
|
+
function matchesFilter(name, filter) {
|
|
142
|
+
if (!filter) return true;
|
|
143
|
+
if (filter.endsWith("*")) return name.startsWith(filter.slice(0, -1));
|
|
144
|
+
return name === filter;
|
|
145
|
+
}
|
|
146
|
+
/** CLI entry: run `test` definitions, print the §8.7.1 report, exit non-zero on any failure. */
|
|
147
|
+
async function testCmd(path, filter, capabilities = []) {
|
|
148
|
+
const results = (await testFile(path, capabilities)).filter((r) => matchesFilter(r.name, filter));
|
|
149
|
+
if (results.length === 0) {
|
|
150
|
+
console.log(filter ? `no tests match "${filter}"` : "no tests found");
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
let failed = 0;
|
|
154
|
+
for (const r of results) {
|
|
155
|
+
if (r.pass) {
|
|
156
|
+
console.log(`PASS ${r.name}`);
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
failed++;
|
|
160
|
+
console.log(`FAIL ${r.name}`);
|
|
161
|
+
if (r.expected !== void 0) console.log(` expected: ${r.expected}`);
|
|
162
|
+
if (r.actual !== void 0) console.log(` actual: ${r.actual}`);
|
|
163
|
+
if (r.diffAt !== void 0) {
|
|
164
|
+
const arrow = r.leaf ? ` ${leafStr(r.leaf.expected)} -> ${leafStr(r.leaf.actual)}` : "";
|
|
165
|
+
console.log(` diff at: ${r.diffAt}${arrow}`);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
console.log(`\n${results.length - failed}/${results.length} passed`);
|
|
169
|
+
if (failed > 0) process.exit(1);
|
|
170
|
+
}
|
|
171
|
+
//#endregion
|
|
9
172
|
//#region src/store.ts
|
|
10
173
|
const LAYER_OF = {
|
|
11
174
|
TypeDef: "type",
|
|
@@ -15,7 +178,8 @@ const LAYER_OF = {
|
|
|
15
178
|
TileDef: "tile",
|
|
16
179
|
FnDef: "fn",
|
|
17
180
|
AppDef: "app",
|
|
18
|
-
ThemeDef: "theme"
|
|
181
|
+
ThemeDef: "theme",
|
|
182
|
+
MotionDef: "motion"
|
|
19
183
|
};
|
|
20
184
|
function load(path) {
|
|
21
185
|
const source = readFileSync(path, "utf8");
|
|
@@ -202,9 +366,9 @@ function planFixes(store, errors) {
|
|
|
202
366
|
}
|
|
203
367
|
return patches;
|
|
204
368
|
}
|
|
205
|
-
function fixCmd(path, apply, onlyCode) {
|
|
369
|
+
function fixCmd(path, apply, onlyCode, capabilities = []) {
|
|
206
370
|
const store = load(path);
|
|
207
|
-
const errors = check(store.program);
|
|
371
|
+
const errors = check(store.program, { capabilities });
|
|
208
372
|
if (errors.length === 0) {
|
|
209
373
|
console.log("no errors");
|
|
210
374
|
return;
|
|
@@ -227,13 +391,196 @@ function fixCmd(path, apply, onlyCode) {
|
|
|
227
391
|
for (const p of patches) text = p.apply(text);
|
|
228
392
|
writeFileSync(path, text);
|
|
229
393
|
try {
|
|
230
|
-
const after = check(parse(lex(text)));
|
|
394
|
+
const after = check(parse(lex(text)), { capabilities });
|
|
231
395
|
if (after.length === 0) console.log(`applied ${patches.length} fix(es) — file now clean`);
|
|
232
396
|
else console.log(`applied ${patches.length} fix(es) — ${after.length} error(s) remain`);
|
|
233
397
|
} catch (e) {
|
|
234
398
|
console.error(`fixes broke the file: ${String(e)}`);
|
|
235
399
|
}
|
|
236
400
|
}
|
|
401
|
+
/**
|
|
402
|
+
* Render a string as a Kumiki source literal, or null if it needs an escape the
|
|
403
|
+
* lexer can't represent. The lexer supports only `\n` / `\t` / `\r` / `\"` /
|
|
404
|
+
* `\\` (lexer.ts) — emitting a JSON `\uXXXX` (e.g. for a control char) would
|
|
405
|
+
* produce an invalid `.kumiki` file, so we bail rather than write garbage.
|
|
406
|
+
*/
|
|
407
|
+
function kumikiStringLit(s) {
|
|
408
|
+
let out = "\"";
|
|
409
|
+
for (const ch of s) {
|
|
410
|
+
const code = ch.codePointAt(0) ?? 0;
|
|
411
|
+
if (ch === "\\") out += "\\\\";
|
|
412
|
+
else if (ch === "\"") out += "\\\"";
|
|
413
|
+
else if (ch === "\n") out += "\\n";
|
|
414
|
+
else if (ch === " ") out += "\\t";
|
|
415
|
+
else if (ch === "\r") out += "\\r";
|
|
416
|
+
else if (code < 32) return null;
|
|
417
|
+
else out += ch;
|
|
418
|
+
}
|
|
419
|
+
return `${out}"`;
|
|
420
|
+
}
|
|
421
|
+
/** 1-based line number of a character offset in `source`. */
|
|
422
|
+
function lineOfOffset(source, offset) {
|
|
423
|
+
let line = 1;
|
|
424
|
+
const end = Math.min(offset, source.length);
|
|
425
|
+
for (let i = 0; i < end; i++) if (source[i] === "\n") line++;
|
|
426
|
+
return line;
|
|
427
|
+
}
|
|
428
|
+
/**
|
|
429
|
+
* A deterministic patch from a failing test, when one is provable: the failing
|
|
430
|
+
* leaf is a string whose *actual* value appears verbatim, exactly once, as a
|
|
431
|
+
* source string literal **in implementation code** (tile / reducer), not in a
|
|
432
|
+
* `test` body. `excludedLineRanges` are the 1-based inclusive line spans of the
|
|
433
|
+
* file's `test` definitions; a match inside one is skipped, because patching a
|
|
434
|
+
* test's own `given` / `expect` data would mutate the fixture into passing
|
|
435
|
+
* without touching any production definition. Returns null when no such patch
|
|
436
|
+
* exists — the caller reports the diff instead.
|
|
437
|
+
*/
|
|
438
|
+
function planTestPatch(source, r, excludedLineRanges = []) {
|
|
439
|
+
if (r.pass || !r.leaf) return null;
|
|
440
|
+
const { expected, actual } = r.leaf;
|
|
441
|
+
if (typeof actual !== "string" || typeof expected !== "string" || actual === expected) return null;
|
|
442
|
+
const actualLit = kumikiStringLit(actual);
|
|
443
|
+
const expectedLit = kumikiStringLit(expected);
|
|
444
|
+
if (actualLit === null || expectedLit === null) return null;
|
|
445
|
+
const inExcluded = (offset) => {
|
|
446
|
+
const line = lineOfOffset(source, offset);
|
|
447
|
+
return excludedLineRanges.some(([lo, hi]) => line >= lo && line <= hi);
|
|
448
|
+
};
|
|
449
|
+
const hits = [];
|
|
450
|
+
for (let idx = source.indexOf(actualLit); idx !== -1; idx = source.indexOf(actualLit, idx + 1)) if (!inExcluded(idx)) hits.push(idx);
|
|
451
|
+
if (hits.length !== 1) return null;
|
|
452
|
+
const hit = hits[0];
|
|
453
|
+
const at = r.diffAt ?? "(leaf)";
|
|
454
|
+
return {
|
|
455
|
+
code: "TEST",
|
|
456
|
+
message: `test "${r.name}" failed at ${at}`,
|
|
457
|
+
description: `replace ${actualLit} with ${expectedLit} (from failing test "${r.name}" @ ${at})`,
|
|
458
|
+
apply: (text) => text.slice(0, hit) + expectedLit + text.slice(hit + actualLit.length)
|
|
459
|
+
};
|
|
460
|
+
}
|
|
461
|
+
/** 1-based inclusive line spans of every `test` definition in `store`. */
|
|
462
|
+
function testBodyLineRanges(store) {
|
|
463
|
+
return store.defs.filter((e) => e.def.kind === "TestDef").map((e) => [e.range.startLine, e.range.endLine]);
|
|
464
|
+
}
|
|
465
|
+
async function fixFromTest(path, testName, apply, capabilities = []) {
|
|
466
|
+
const store = load(path);
|
|
467
|
+
const compileErrors = check(store.program, { capabilities });
|
|
468
|
+
let compileFixes = 0;
|
|
469
|
+
if (compileErrors.length > 0) {
|
|
470
|
+
const patches = planFixes(store, compileErrors);
|
|
471
|
+
if (patches.length === 0) {
|
|
472
|
+
console.log(`(no auto-patch available) — test "${testName}" is blocked by ${compileErrors.length} compile error(s):`);
|
|
473
|
+
for (const e of compileErrors) console.error(` ${e.code} ${e.message}`);
|
|
474
|
+
return {
|
|
475
|
+
ok: false,
|
|
476
|
+
status: "no-patch"
|
|
477
|
+
};
|
|
478
|
+
}
|
|
479
|
+
if (!apply) {
|
|
480
|
+
console.log(`test "${testName}" is blocked by compile errors; proposed fixes (dry-run):`);
|
|
481
|
+
for (const p of patches) {
|
|
482
|
+
console.log(` ${p.code} ${p.message}`);
|
|
483
|
+
console.log(` fix: ${p.description}`);
|
|
484
|
+
}
|
|
485
|
+
return {
|
|
486
|
+
ok: true,
|
|
487
|
+
status: "compile-proposed",
|
|
488
|
+
compileFixes: patches.length
|
|
489
|
+
};
|
|
490
|
+
}
|
|
491
|
+
let text = readFileSync(path, "utf8");
|
|
492
|
+
for (const p of patches) text = p.apply(text);
|
|
493
|
+
writeFileSync(path, text);
|
|
494
|
+
compileFixes = patches.length;
|
|
495
|
+
let remaining;
|
|
496
|
+
try {
|
|
497
|
+
remaining = check(parse(lex(text)), { capabilities });
|
|
498
|
+
} catch (e) {
|
|
499
|
+
console.log(`applied ${compileFixes} compile fix(es) but they broke the file (${String(e)}); cannot run "${testName}"`);
|
|
500
|
+
return {
|
|
501
|
+
ok: false,
|
|
502
|
+
status: "compile-remaining",
|
|
503
|
+
compileFixes
|
|
504
|
+
};
|
|
505
|
+
}
|
|
506
|
+
if (remaining.length > 0) {
|
|
507
|
+
console.log(`applied ${compileFixes} compile fix(es) — ${remaining.length} error(s) remain; cannot run "${testName}"`);
|
|
508
|
+
return {
|
|
509
|
+
ok: false,
|
|
510
|
+
status: "compile-remaining",
|
|
511
|
+
compileFixes
|
|
512
|
+
};
|
|
513
|
+
}
|
|
514
|
+
console.log(`applied ${compileFixes} compile fix(es) — file now compiles`);
|
|
515
|
+
}
|
|
516
|
+
let before;
|
|
517
|
+
try {
|
|
518
|
+
before = await testFile(path, capabilities);
|
|
519
|
+
} catch (e) {
|
|
520
|
+
console.error(`could not run tests: ${String(e)}`);
|
|
521
|
+
return {
|
|
522
|
+
ok: false,
|
|
523
|
+
status: "no-patch",
|
|
524
|
+
...compileFixes ? { compileFixes } : {}
|
|
525
|
+
};
|
|
526
|
+
}
|
|
527
|
+
const target = before.find((r) => r.name === testName);
|
|
528
|
+
if (!target) {
|
|
529
|
+
const have = before.map((r) => r.name).join(", ") || "none";
|
|
530
|
+
console.error(`no test named "${testName}" (have: ${have})`);
|
|
531
|
+
return {
|
|
532
|
+
ok: false,
|
|
533
|
+
status: "not-found",
|
|
534
|
+
...compileFixes ? { compileFixes } : {}
|
|
535
|
+
};
|
|
536
|
+
}
|
|
537
|
+
if (target.pass) {
|
|
538
|
+
console.log(`test "${testName}" passes — nothing to fix`);
|
|
539
|
+
return {
|
|
540
|
+
ok: true,
|
|
541
|
+
status: "already-pass",
|
|
542
|
+
pass: true,
|
|
543
|
+
...compileFixes ? { compileFixes } : {}
|
|
544
|
+
};
|
|
545
|
+
}
|
|
546
|
+
const curSource = readFileSync(path, "utf8");
|
|
547
|
+
const patch = planTestPatch(curSource, target, testBodyLineRanges(load(path)));
|
|
548
|
+
if (!patch) {
|
|
549
|
+
console.log(`(no auto-patch available) for failing test "${testName}":`);
|
|
550
|
+
if (target.expected !== void 0) console.log(` expected: ${target.expected}`);
|
|
551
|
+
if (target.actual !== void 0) console.log(` actual: ${target.actual}`);
|
|
552
|
+
if (target.diffAt !== void 0) console.log(` diff at: ${target.diffAt}`);
|
|
553
|
+
return {
|
|
554
|
+
ok: false,
|
|
555
|
+
status: "no-patch",
|
|
556
|
+
...compileFixes ? { compileFixes } : {}
|
|
557
|
+
};
|
|
558
|
+
}
|
|
559
|
+
if (!apply) {
|
|
560
|
+
console.log(`proposed fix for "${testName}" (dry-run):`);
|
|
561
|
+
console.log(` ${patch.description}`);
|
|
562
|
+
return {
|
|
563
|
+
ok: true,
|
|
564
|
+
status: "proposed",
|
|
565
|
+
patch,
|
|
566
|
+
...compileFixes ? { compileFixes } : {}
|
|
567
|
+
};
|
|
568
|
+
}
|
|
569
|
+
writeFileSync(path, patch.apply(curSource));
|
|
570
|
+
const after = await testFile(path, capabilities);
|
|
571
|
+
const nowPass = after.find((r) => r.name === testName)?.pass === true;
|
|
572
|
+
const regressed = after.filter((r) => !r.pass && before.find((b) => b.name === r.name)?.pass === true).map((r) => r.name);
|
|
573
|
+
console.log(`applied fix — test "${testName}" now ${nowPass ? "PASSES" : "still FAILS"}`);
|
|
574
|
+
if (regressed.length > 0) console.log(` WARNING: ${regressed.length} other test(s) regressed: ${regressed.join(", ")}`);
|
|
575
|
+
return {
|
|
576
|
+
ok: nowPass && regressed.length === 0,
|
|
577
|
+
status: "applied",
|
|
578
|
+
pass: nowPass,
|
|
579
|
+
patch,
|
|
580
|
+
...compileFixes ? { compileFixes } : {},
|
|
581
|
+
...regressed.length ? { regressed } : {}
|
|
582
|
+
};
|
|
583
|
+
}
|
|
237
584
|
//#endregion
|
|
238
585
|
//#region src/mutate.ts
|
|
239
586
|
const ULID_ALPHABET = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
|
|
@@ -414,117 +761,4 @@ function assemble(layer, name, body) {
|
|
|
414
761
|
}
|
|
415
762
|
}
|
|
416
763
|
//#endregion
|
|
417
|
-
|
|
418
|
-
let domReady = false;
|
|
419
|
-
function ensureDom() {
|
|
420
|
-
if (domReady) return;
|
|
421
|
-
const dom = new JSDOM("<!doctype html><html><body></body></html>", { url: "http://localhost/" });
|
|
422
|
-
const g = globalThis;
|
|
423
|
-
const w = dom.window;
|
|
424
|
-
for (const key of [
|
|
425
|
-
"window",
|
|
426
|
-
"document",
|
|
427
|
-
"navigator",
|
|
428
|
-
"location",
|
|
429
|
-
"history",
|
|
430
|
-
"localStorage",
|
|
431
|
-
"sessionStorage",
|
|
432
|
-
"HTMLElement",
|
|
433
|
-
"HTMLInputElement",
|
|
434
|
-
"HTMLSelectElement",
|
|
435
|
-
"HTMLTextAreaElement",
|
|
436
|
-
"Element",
|
|
437
|
-
"Node",
|
|
438
|
-
"Event",
|
|
439
|
-
"MouseEvent",
|
|
440
|
-
"CustomEvent",
|
|
441
|
-
"KeyboardEvent",
|
|
442
|
-
"CSS",
|
|
443
|
-
"getComputedStyle"
|
|
444
|
-
]) {
|
|
445
|
-
if (w[key] === void 0) continue;
|
|
446
|
-
try {
|
|
447
|
-
g[key] = w[key];
|
|
448
|
-
} catch {
|
|
449
|
-
Object.defineProperty(g, key, {
|
|
450
|
-
value: w[key],
|
|
451
|
-
configurable: true,
|
|
452
|
-
writable: true
|
|
453
|
-
});
|
|
454
|
-
}
|
|
455
|
-
}
|
|
456
|
-
domReady = true;
|
|
457
|
-
}
|
|
458
|
-
async function loadApp(source) {
|
|
459
|
-
const result = compile(source, {
|
|
460
|
-
runtimeSpecifier: "ignored",
|
|
461
|
-
bundle: true,
|
|
462
|
-
readRuntimeBundle: nodeRuntimeBundleReader
|
|
463
|
-
});
|
|
464
|
-
if (result.kind !== "ok") throw new Error(`compile failed:\n${result.errors.map((e) => `${e.code} ${e.message}`).join("\n")}`);
|
|
465
|
-
const patched = result.js.replace(/mount\(App, document\.getElementById\("root"\)\);?/, "");
|
|
466
|
-
const file = join(mkdtempSync(join(tmpdir(), "kumiki-smoke-")), "app.mjs");
|
|
467
|
-
writeFileSync(file, patched);
|
|
468
|
-
await import(pathToFileURL(file).href);
|
|
469
|
-
const app = globalThis.__kumikiApp;
|
|
470
|
-
if (!app) throw new Error("compiled module did not expose __kumikiApp");
|
|
471
|
-
return app;
|
|
472
|
-
}
|
|
473
|
-
/** Compile + mount + exercise a Kumiki source string; return the smoke report. */
|
|
474
|
-
async function smokeSource(source) {
|
|
475
|
-
ensureDom();
|
|
476
|
-
const app = await loadApp(source);
|
|
477
|
-
const doc = globalThis.document;
|
|
478
|
-
const root = doc.createElement("div");
|
|
479
|
-
doc.body.appendChild(root);
|
|
480
|
-
try {
|
|
481
|
-
return await smoke(app, root, { settleMs: 20 });
|
|
482
|
-
} finally {
|
|
483
|
-
root.remove();
|
|
484
|
-
}
|
|
485
|
-
}
|
|
486
|
-
async function smokeFile(path) {
|
|
487
|
-
return smokeSource(readFileSync(path, "utf8"));
|
|
488
|
-
}
|
|
489
|
-
/** CLI entry: print a human-readable report and exit non-zero on failure. */
|
|
490
|
-
async function smokeCmd(path) {
|
|
491
|
-
const report = await smokeFile(path);
|
|
492
|
-
if (report.ok) {
|
|
493
|
-
console.log(`ok — mounted, rendered, ${report.interactions} interaction(s), no runtime errors`);
|
|
494
|
-
return;
|
|
495
|
-
}
|
|
496
|
-
console.error(`runtime smoke failed (mounted=${report.mounted}, rendered=${report.rendered}, interactions=${report.interactions}):`);
|
|
497
|
-
for (const i of report.issues) console.error(` [${i.phase}] ${i.message}${i.trigger ? ` (on ${i.trigger})` : ""}`);
|
|
498
|
-
process.exit(1);
|
|
499
|
-
}
|
|
500
|
-
/** Compile + mount + drive a scenario; return the structured trace. */
|
|
501
|
-
async function runScenarioSource(source, scenario) {
|
|
502
|
-
ensureDom();
|
|
503
|
-
const app = await loadApp(source);
|
|
504
|
-
const doc = globalThis.document;
|
|
505
|
-
const root = doc.createElement("div");
|
|
506
|
-
doc.body.appendChild(root);
|
|
507
|
-
try {
|
|
508
|
-
return await runScenario(app, root, scenario, { settleMs: 20 });
|
|
509
|
-
} finally {
|
|
510
|
-
root.remove();
|
|
511
|
-
}
|
|
512
|
-
}
|
|
513
|
-
/** CLI entry: run a scenario JSON file against a .kumiki file; print the trace. */
|
|
514
|
-
async function runCmd(kumikiPath, scenarioPath) {
|
|
515
|
-
const scenario = JSON.parse(readFileSync(scenarioPath, "utf8"));
|
|
516
|
-
const report = await runScenarioSource(readFileSync(kumikiPath, "utf8"), scenario);
|
|
517
|
-
for (let i = 0; i < report.steps.length; i++) {
|
|
518
|
-
const s = report.steps[i];
|
|
519
|
-
if (!s) continue;
|
|
520
|
-
const head = `step ${i}${s.label ? ` (${s.label})` : ""}${s.action ? `: ${s.action}` : ""}`;
|
|
521
|
-
const status = s.errors.length === 0 && s.failures.length === 0 ? "ok" : "FAIL";
|
|
522
|
-
console.log(`[${status}] ${head}`);
|
|
523
|
-
for (const e of s.errors) console.log(` error: ${e}`);
|
|
524
|
-
for (const f of s.failures) console.log(` assert: ${f}`);
|
|
525
|
-
}
|
|
526
|
-
console.log(report.ok ? "\nscenario passed" : "\nscenario FAILED");
|
|
527
|
-
if (!report.ok) process.exit(1);
|
|
528
|
-
}
|
|
529
|
-
//#endregion
|
|
530
|
-
export { viewWithDeps as _, smokeSource as a, renameDef as c, planFixes as d, directDeps as f, viewDef as g, load as h, smokeFile as i, replaceDef as l, listDefs as m, runScenarioSource as n, addDef as o, findReferences as p, smokeCmd as r, removeDef as s, runCmd as t, fixCmd as u };
|
|
764
|
+
export { smokeCmd as _, fixCmd as a, testCmd as b, planTestPatch as c, listDefs as d, load as f, runScenarioSource as g, runCmd as h, replaceDef as i, directDeps as l, viewWithDeps as m, removeDef as n, fixFromTest as o, viewDef as p, renameDef as r, planFixes as s, addDef as t, findReferences as u, smokeFile as v, smokeSource as y };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kumikijs/cli",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Kumiki CLI — build, check, and AI-edit (list/view/add/replace/remove/rename/fix) Kumiki sources.",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -28,23 +28,28 @@
|
|
|
28
28
|
"exports": {
|
|
29
29
|
".": {
|
|
30
30
|
"types": "./dist/index.d.ts",
|
|
31
|
-
"
|
|
31
|
+
"import": "./dist/index.js"
|
|
32
32
|
},
|
|
33
|
-
"./kumiki": "./
|
|
33
|
+
"./kumiki": "./dist/kumiki.js"
|
|
34
34
|
},
|
|
35
35
|
"files": [
|
|
36
36
|
"dist"
|
|
37
37
|
],
|
|
38
38
|
"publishConfig": {
|
|
39
39
|
"access": "public",
|
|
40
|
-
"provenance": true
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
40
|
+
"provenance": true
|
|
41
|
+
},
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"jsdom": "^29.1.1",
|
|
44
|
+
"@kumikijs/compiler": "0.2.1",
|
|
45
|
+
"@kumikijs/runtime": "0.2.1"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@types/jsdom": "^28.0.3",
|
|
49
|
+
"@types/node": "^25.9.1",
|
|
50
|
+
"tsx": "^4.22.3",
|
|
51
|
+
"typescript": "^6.0.3",
|
|
52
|
+
"vitest": "^4.1.7"
|
|
48
53
|
},
|
|
49
54
|
"scripts": {
|
|
50
55
|
"build": "tsdown",
|
|
@@ -52,17 +57,5 @@
|
|
|
52
57
|
"test": "vitest run",
|
|
53
58
|
"lint": "biome check src test",
|
|
54
59
|
"kumiki": "tsx src/kumiki.ts"
|
|
55
|
-
},
|
|
56
|
-
"dependencies": {
|
|
57
|
-
"@kumikijs/compiler": "workspace:*",
|
|
58
|
-
"@kumikijs/runtime": "workspace:*",
|
|
59
|
-
"jsdom": "catalog:"
|
|
60
|
-
},
|
|
61
|
-
"devDependencies": {
|
|
62
|
-
"@types/jsdom": "^28.0.3",
|
|
63
|
-
"@types/node": "catalog:",
|
|
64
|
-
"tsx": "catalog:",
|
|
65
|
-
"typescript": "catalog:",
|
|
66
|
-
"vitest": "catalog:"
|
|
67
60
|
}
|
|
68
|
-
}
|
|
61
|
+
}
|