@mmapp/react-compiler 0.1.0-alpha.1 → 0.1.0-alpha.5
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/ATOM-PIPELINE.md +144 -0
- package/README.md +88 -40
- package/dist/babel/index.js +2814 -277
- package/dist/babel/index.mjs +2 -2
- package/dist/chunk-3USIFFE4.mjs +2190 -0
- package/dist/chunk-45YMGEVT.mjs +186 -0
- package/dist/chunk-4FN2AISW.mjs +148 -0
- package/dist/chunk-4OPI5L7G.mjs +2593 -0
- package/dist/chunk-4RYTKOOJ.mjs +186 -0
- package/dist/chunk-52XHYD2V.mjs +214 -0
- package/dist/chunk-5GUFFFGL.mjs +148 -0
- package/dist/chunk-5RKTOVR5.mjs +244 -0
- package/dist/chunk-5YDMOO4X.mjs +214 -0
- package/dist/chunk-64ZWEMLJ.mjs +148 -0
- package/dist/chunk-6XP4KSWQ.mjs +2190 -0
- package/dist/chunk-72QWL54I.mjs +175 -0
- package/dist/chunk-7B4TRI7C.mjs +4835 -0
- package/dist/chunk-7ZKGHTNB.mjs +4952 -0
- package/dist/chunk-CIESM3BP.mjs +33 -0
- package/dist/chunk-DE3ZGQAC.mjs +148 -0
- package/dist/chunk-DMCY3BBG.mjs +1933 -0
- package/dist/chunk-DPIK3PJS.mjs +244 -0
- package/dist/chunk-E5IVH4RE.mjs +186 -0
- package/dist/chunk-E6FZNUR5.mjs +4953 -0
- package/dist/chunk-EJRBDQDP.mjs +2607 -0
- package/dist/chunk-ELO4TXJL.mjs +186 -0
- package/dist/chunk-EO6SYNCG.mjs +175 -0
- package/dist/chunk-FKRO52XH.mjs +3446 -0
- package/dist/chunk-FL4YAKU6.mjs +4941 -0
- package/dist/chunk-FYT47UBU.mjs +5076 -0
- package/dist/chunk-GCLGPOJZ.mjs +148 -0
- package/dist/chunk-GXB4JOP7.mjs +5072 -0
- package/dist/chunk-HFXOUMTD.mjs +175 -0
- package/dist/chunk-HWIZ47US.mjs +214 -0
- package/dist/chunk-IB7MNPQL.mjs +4953 -0
- package/dist/chunk-ICSIHQCG.mjs +148 -0
- package/dist/chunk-J7JUAHS4.mjs +186 -0
- package/dist/chunk-JLA5VNQ3.mjs +186 -0
- package/dist/chunk-JQLWFCTM.mjs +214 -0
- package/dist/chunk-KFJJCQAL.mjs +148 -0
- package/dist/chunk-KJUIIEQE.mjs +186 -0
- package/dist/chunk-KNWTHRVQ.mjs +175 -0
- package/dist/chunk-KSG4XSZF.mjs +175 -0
- package/dist/chunk-LF5N6DOU.mjs +175 -0
- package/dist/chunk-LJQCM2IM.mjs +214 -0
- package/dist/chunk-NTB7OEX2.mjs +2918 -0
- package/dist/chunk-NW6555WJ.mjs +186 -0
- package/dist/chunk-OMZE6VLQ.mjs +214 -0
- package/dist/chunk-OPJKP747.mjs +7506 -0
- package/dist/chunk-P4BR7WVO.mjs +2190 -0
- package/dist/chunk-QQHVYH2X.mjs +244 -0
- package/dist/chunk-S5QLWLLT.mjs +186 -0
- package/dist/chunk-SCWGT2FY.mjs +2190 -0
- package/dist/chunk-SMKJUSB3.mjs +2190 -0
- package/dist/chunk-THFYE5ZX.mjs +244 -0
- package/dist/chunk-VCAY2KGM.mjs +175 -0
- package/dist/chunk-WBYMW4NQ.mjs +3450 -0
- package/dist/chunk-WECAV6QB.mjs +148 -0
- package/dist/chunk-WMKBXUCE.mjs +3228 -0
- package/dist/chunk-XAJ5BKKL.mjs +4947 -0
- package/dist/chunk-XG2X7AEA.mjs +175 -0
- package/dist/chunk-XG7Z23NQ.mjs +148 -0
- package/dist/chunk-XWZAOCQ7.mjs +2607 -0
- package/dist/chunk-Y6MA7ULW.mjs +148 -0
- package/dist/chunk-YMS7Q7LG.mjs +214 -0
- package/dist/chunk-ZA37XTGA.mjs +175 -0
- package/dist/cli/index.js +13189 -6838
- package/dist/cli/index.mjs +140 -22
- package/dist/codemod/cli.mjs +1 -1
- package/dist/codemod/index.mjs +1 -1
- package/dist/config-PL24KEWL.mjs +219 -0
- package/dist/dev-server-RmGHIntF.d.mts +113 -0
- package/dist/dev-server-RmGHIntF.d.ts +113 -0
- package/dist/dev-server.d.mts +1 -1
- package/dist/dev-server.d.ts +1 -1
- package/dist/dev-server.js +4135 -440
- package/dist/dev-server.mjs +5 -5
- package/dist/envelope.js +2812 -275
- package/dist/envelope.mjs +3 -3
- package/dist/index.d.mts +161 -2
- package/dist/index.d.ts +161 -2
- package/dist/index.js +4429 -428
- package/dist/index.mjs +217 -9
- package/{src/cli/init.ts → dist/init-7JQMAAXS.mjs} +70 -95
- package/dist/init-DQDX3QK6.mjs +369 -0
- package/dist/init-EHO4VQ22.mjs +369 -0
- package/dist/init-UC3FWPIW.mjs +367 -0
- package/dist/init-UNSMVKIK.mjs +366 -0
- package/dist/init-UNV5XIDE.mjs +367 -0
- package/dist/project-compiler-2P4N4DR7.mjs +10 -0
- package/dist/project-compiler-D2LCC27O.mjs +10 -0
- package/dist/project-compiler-EJ3GANJE.mjs +10 -0
- package/dist/project-compiler-LOQKVRZJ.mjs +10 -0
- package/dist/project-compiler-OP2VVGJQ.mjs +10 -0
- package/dist/project-compiler-RQ6OQKRM.mjs +10 -0
- package/dist/project-compiler-VWNNCHGO.mjs +10 -0
- package/dist/project-compiler-XVAAU4C5.mjs +10 -0
- package/dist/project-compiler-YES5FGMD.mjs +10 -0
- package/dist/project-compiler-ZKMQDLGU.mjs +10 -0
- package/dist/project-decompiler-FLXCEJHS.mjs +7 -0
- package/dist/project-decompiler-US7GAVIC.mjs +7 -0
- package/dist/project-decompiler-VLPR22QF.mjs +7 -0
- package/dist/pull-FUS5QYZS.mjs +109 -0
- package/dist/pull-LD5ENLGY.mjs +109 -0
- package/dist/pull-P44LDRWB.mjs +109 -0
- package/dist/testing/index.js +2822 -285
- package/dist/testing/index.mjs +2 -2
- package/dist/verify-SEIXUGN4.mjs +1833 -0
- package/dist/vite/index.js +2815 -278
- package/dist/vite/index.mjs +3 -3
- package/examples/uber-app/app/admin/fleet.tsx +19 -19
- package/package.json +16 -6
- package/compile-blueprint-chat.mjs +0 -99
- package/compile-blueprint-glass-console.mjs +0 -98
- package/compile-chat-defs.mjs +0 -92
- package/examples/uber-app/tests/payment.test.tsx +0 -129
- package/examples/uber-app/tests/ride-flow.test.tsx +0 -123
- package/package.json.backup +0 -86
- package/scripts/decompile.ts +0 -226
- package/scripts/seed-auth.ts +0 -267
- package/scripts/seed-uber.ts +0 -248
- package/scripts/validate-uber.ts +0 -119
- package/seed-blueprint-chat.mjs +0 -444
- package/seed-blueprint-glass-console.mjs +0 -445
- package/seed-compiled.mjs +0 -318
- package/src/RoundTripValidator.ts +0 -400
- package/src/__tests__/atom-rendering-coverage.test.ts +0 -680
- package/src/__tests__/auth-module-compilation.test.ts +0 -247
- package/src/__tests__/auth-template-compilation.test.ts +0 -589
- package/src/__tests__/change-extractor.test.ts +0 -142
- package/src/__tests__/cli-pull.test.ts +0 -73
- package/src/__tests__/cli-test.test.ts +0 -72
- package/src/__tests__/component-extractor.test.ts +0 -331
- package/src/__tests__/context-extractor.test.ts +0 -145
- package/src/__tests__/decompiler.test.ts +0 -718
- package/src/__tests__/define-blueprint.test.ts +0 -133
- package/src/__tests__/definition-validator.test.ts +0 -519
- package/src/__tests__/during-extractor.test.ts +0 -152
- package/src/__tests__/effect-extractor.test.ts +0 -107
- package/src/__tests__/event-emission.test.ts +0 -127
- package/src/__tests__/examples.test.ts +0 -236
- package/src/__tests__/full-blueprint-coverage.test.ts +0 -1221
- package/src/__tests__/golden-suite.test.ts +0 -403
- package/src/__tests__/grammar-island-extractor.test.ts +0 -289
- package/src/__tests__/instance-key.test.ts +0 -82
- package/src/__tests__/ir-migration.test.ts +0 -255
- package/src/__tests__/lock-file.test.ts +0 -117
- package/src/__tests__/model-extractor.test.ts +0 -195
- package/src/__tests__/model-field-acl.test.ts +0 -237
- package/src/__tests__/model-hooks.test.ts +0 -130
- package/src/__tests__/model-ref-resolution.test.ts +0 -268
- package/src/__tests__/model-roundtrip.test.ts +0 -502
- package/src/__tests__/model-runtime.test.ts +0 -112
- package/src/__tests__/model-transitions.test.ts +0 -183
- package/src/__tests__/nrt-action-trace.test.ts +0 -391
- package/src/__tests__/pipeline-hardening.test.ts +0 -413
- package/src/__tests__/project-compiler.test.ts +0 -546
- package/src/__tests__/project-decompiler.test.ts +0 -343
- package/src/__tests__/query-compilation.test.ts +0 -145
- package/src/__tests__/round-trip/PLAN.md +0 -158
- package/src/__tests__/round-trip/README.md +0 -52
- package/src/__tests__/round-trip/RESULTS.md +0 -86
- package/src/__tests__/round-trip/fixtures/data-heavy/main.workflow.tsx +0 -55
- package/src/__tests__/round-trip/fixtures/data-heavy/mm.config.ts +0 -11
- package/src/__tests__/round-trip/fixtures/data-heavy/models/contact.ts +0 -54
- package/src/__tests__/round-trip/fixtures/full-workflow/main.workflow.tsx +0 -79
- package/src/__tests__/round-trip/fixtures/full-workflow/mm.config.ts +0 -12
- package/src/__tests__/round-trip/fixtures/full-workflow/models/order.ts +0 -50
- package/src/__tests__/round-trip/fixtures/simple-crud/main.workflow.tsx +0 -25
- package/src/__tests__/round-trip/fixtures/simple-crud/mm.config.ts +0 -11
- package/src/__tests__/round-trip/fixtures/simple-crud/models/task.ts +0 -32
- package/src/__tests__/round-trip/fixtures/view-heavy/main.workflow.tsx +0 -79
- package/src/__tests__/round-trip/fixtures/view-heavy/mm.config.ts +0 -10
- package/src/__tests__/round-trip/round-trip.test.ts +0 -2598
- package/src/__tests__/round-trip-ir.test.ts +0 -300
- package/src/__tests__/round-trip.test.ts +0 -1212
- package/src/__tests__/route-merging.test.ts +0 -372
- package/src/__tests__/router-composition.test.ts +0 -489
- package/src/__tests__/router-extractor.test.ts +0 -176
- package/src/__tests__/server-action-extractor.test.ts +0 -128
- package/src/__tests__/smart-type-inference.test.ts +0 -365
- package/src/__tests__/source-envelope.test.ts +0 -284
- package/src/__tests__/source-fidelity.test.ts +0 -516
- package/src/__tests__/state-extractor.test.ts +0 -115
- package/src/__tests__/strict-mode.test.ts +0 -227
- package/src/__tests__/transition-effect-extractor.test.ts +0 -119
- package/src/__tests__/transition-extractor.test.ts +0 -68
- package/src/__tests__/ts-to-expression.test.ts +0 -462
- package/src/__tests__/type-generator.test.ts +0 -201
- package/src/__tests__/uber-validation.test.ts +0 -502
- package/src/action-compiler.ts +0 -361
- package/src/babel/emitters/experience-transform.ts +0 -199
- package/src/babel/emitters/ir-to-tsx-emitter.ts +0 -110
- package/src/babel/emitters/pure-form-emitter.ts +0 -1023
- package/src/babel/emitters/runtime-glue-emitter.ts +0 -39
- package/src/babel/extractors/change-extractor.ts +0 -199
- package/src/babel/extractors/component-extractor.ts +0 -907
- package/src/babel/extractors/computed-extractor.ts +0 -262
- package/src/babel/extractors/context-extractor.ts +0 -277
- package/src/babel/extractors/during-extractor.ts +0 -295
- package/src/babel/extractors/effect-extractor.ts +0 -340
- package/src/babel/extractors/event-extractor.ts +0 -235
- package/src/babel/extractors/grammar-island-extractor.ts +0 -302
- package/src/babel/extractors/model-extractor.ts +0 -1018
- package/src/babel/extractors/router-extractor.ts +0 -303
- package/src/babel/extractors/server-action-extractor.ts +0 -173
- package/src/babel/extractors/server-action-hook-extractor.ts +0 -72
- package/src/babel/extractors/server-state-extractor.ts +0 -88
- package/src/babel/extractors/state-extractor.ts +0 -214
- package/src/babel/extractors/transition-effect-extractor.ts +0 -176
- package/src/babel/extractors/transition-extractor.ts +0 -143
- package/src/babel/index.ts +0 -24
- package/src/babel/transpilers/ts-to-expression.ts +0 -674
- package/src/babel/visitor.ts +0 -807
- package/src/cli/auth.ts +0 -255
- package/src/cli/build.ts +0 -288
- package/src/cli/deploy.ts +0 -206
- package/src/cli/index.ts +0 -328
- package/src/cli/installer.ts +0 -261
- package/src/cli/lock-file.ts +0 -94
- package/src/cli/mmrc.ts +0 -22
- package/src/cli/pull.ts +0 -172
- package/src/cli/registry-client.ts +0 -175
- package/src/cli/test.ts +0 -397
- package/src/cli/type-generator.ts +0 -243
- package/src/codemod/__tests__/forward.test.ts +0 -239
- package/src/codemod/__tests__/reverse.test.ts +0 -145
- package/src/codemod/__tests__/round-trip.test.ts +0 -137
- package/src/codemod/annotation.ts +0 -97
- package/src/codemod/classify.ts +0 -197
- package/src/codemod/cli.ts +0 -207
- package/src/codemod/control-flow.ts +0 -409
- package/src/codemod/forward.ts +0 -244
- package/src/codemod/import-manager.ts +0 -171
- package/src/codemod/index.ts +0 -120
- package/src/codemod/reverse.ts +0 -197
- package/src/codemod/rules.ts +0 -174
- package/src/codemod/state-transform.ts +0 -126
- package/src/decompiler/ast-builder.ts +0 -538
- package/src/decompiler/config-generator.ts +0 -151
- package/src/decompiler/index.ts +0 -315
- package/src/decompiler/project-decompiler.ts +0 -1776
- package/src/decompiler/project.ts +0 -862
- package/src/decompiler/split-strategy.ts +0 -140
- package/src/decompiler/state-emitter.ts +0 -1053
- package/src/decompiler/sx-emitter.ts +0 -318
- package/src/decompiler/workspace-hydrator.ts +0 -189
- package/src/dev-server.ts +0 -238
- package/src/envelope/fs-tree.ts +0 -217
- package/src/envelope/source-envelope.ts +0 -264
- package/src/envelope.ts +0 -315
- package/src/incremental-compiler.ts +0 -401
- package/src/index.ts +0 -99
- package/src/model-compiler.ts +0 -277
- package/src/project-compiler.ts +0 -1629
- package/src/route-extractor.ts +0 -333
- package/src/testing/index.ts +0 -32
- package/src/testing/snapshot.ts +0 -252
- package/src/testing/test-utils.ts +0 -226
- package/src/types.ts +0 -68
- package/src/vite/index.ts +0 -288
- package/test-compile.mjs +0 -142
- package/tsconfig.json +0 -25
- package/tsup.config.ts +0 -23
- package/vitest.config.ts +0 -9
|
@@ -1,2598 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Bidirectional Compiler Verification Suite
|
|
3
|
-
*
|
|
4
|
-
* Verifies that compilation is perfectly bidirectional:
|
|
5
|
-
* Source → compile → IR → decompile → Source' → compile → IR' → decompile → Source''
|
|
6
|
-
*
|
|
7
|
-
* Key invariants:
|
|
8
|
-
* 1. IR semantic equality: IR ≈ IR' (structural deep-equal, ignoring order)
|
|
9
|
-
* 2. Source stabilization: Source' === Source'' (exact string match on second pass)
|
|
10
|
-
*
|
|
11
|
-
* If compile→decompile→compile→decompile does not stabilize, the compiler has a bug.
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
import { describe, it, expect } from 'vitest';
|
|
15
|
-
import * as fs from 'fs';
|
|
16
|
-
import * as path from 'path';
|
|
17
|
-
import { compileProject } from '../../project-compiler';
|
|
18
|
-
import type { ProjectCompilationResult } from '../../project-compiler';
|
|
19
|
-
import { decompileProjectEnhanced } from '../../decompiler/project-decompiler';
|
|
20
|
-
import { decompile } from '../../decompiler';
|
|
21
|
-
import type { DecompilerInput } from '../../decompiler';
|
|
22
|
-
import type { IRWorkflowDefinition } from '@mindmatrix/player-core';
|
|
23
|
-
|
|
24
|
-
// =============================================================================
|
|
25
|
-
// Helpers
|
|
26
|
-
// =============================================================================
|
|
27
|
-
|
|
28
|
-
const FIXTURES_DIR = path.resolve(__dirname, 'fixtures');
|
|
29
|
-
|
|
30
|
-
/** Reads all .ts/.tsx files in a directory tree into a Record<relativePath, content>. */
|
|
31
|
-
function readProjectFiles(rootDir: string): Record<string, string> {
|
|
32
|
-
const files: Record<string, string> = {};
|
|
33
|
-
|
|
34
|
-
function walk(dir: string, prefix: string) {
|
|
35
|
-
if (!fs.existsSync(dir)) return;
|
|
36
|
-
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
37
|
-
for (const entry of entries) {
|
|
38
|
-
const relPath = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
39
|
-
const fullPath = path.join(dir, entry.name);
|
|
40
|
-
if (entry.isDirectory()) {
|
|
41
|
-
if (['node_modules', 'dist', '.git'].includes(entry.name)) continue;
|
|
42
|
-
walk(fullPath, relPath);
|
|
43
|
-
} else if (entry.isFile()) {
|
|
44
|
-
if (entry.name.endsWith('.tsx') || entry.name.endsWith('.ts')) {
|
|
45
|
-
files[relPath] = fs.readFileSync(fullPath, 'utf-8');
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
walk(rootDir, '');
|
|
52
|
-
return files;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Performs the full bidirectional round-trip test for a fixture.
|
|
57
|
-
*
|
|
58
|
-
* Steps:
|
|
59
|
-
* 1. Read source files → fileMap
|
|
60
|
-
* 2. Compile: compileProject(fileMap) → IR + childDefinitions
|
|
61
|
-
* 3. Decompile: decompileProjectEnhanced(IR) → outputFiles
|
|
62
|
-
* 4. Re-compile: compileProject(outputFiles) → IR2
|
|
63
|
-
* 5. Compare IR vs IR2 (semantic equality)
|
|
64
|
-
* 6. Re-decompile: decompileProjectEnhanced(IR2) → outputFiles2
|
|
65
|
-
* 7. Compare outputFiles vs outputFiles2 (string equality)
|
|
66
|
-
*/
|
|
67
|
-
interface RoundTripReport {
|
|
68
|
-
fixtureName: string;
|
|
69
|
-
|
|
70
|
-
// Phase 1: Initial compilation
|
|
71
|
-
compileSuccess: boolean;
|
|
72
|
-
compileErrors: string[];
|
|
73
|
-
ir1: IRWorkflowDefinition | null;
|
|
74
|
-
childDefs1: IRWorkflowDefinition[];
|
|
75
|
-
|
|
76
|
-
// Phase 2: Decompile
|
|
77
|
-
decompileSuccess: boolean;
|
|
78
|
-
outputFiles1: Record<string, string>;
|
|
79
|
-
|
|
80
|
-
// Phase 3: Re-compile
|
|
81
|
-
recompileSuccess: boolean;
|
|
82
|
-
recompileErrors: string[];
|
|
83
|
-
ir2: IRWorkflowDefinition | null;
|
|
84
|
-
|
|
85
|
-
// Phase 4: IR Semantic equality
|
|
86
|
-
irDiffs: IRDiff[];
|
|
87
|
-
irMatch: boolean;
|
|
88
|
-
|
|
89
|
-
// Phase 5: Re-decompile
|
|
90
|
-
outputFiles2: Record<string, string>;
|
|
91
|
-
|
|
92
|
-
// Phase 6: Source stabilization (string equality)
|
|
93
|
-
sourceStabilized: boolean;
|
|
94
|
-
sourceDiffs: SourceDiff[];
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
interface IRDiff {
|
|
98
|
-
path: string;
|
|
99
|
-
expected: unknown;
|
|
100
|
-
actual: unknown;
|
|
101
|
-
severity: 'error' | 'warning';
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
interface SourceDiff {
|
|
105
|
-
file: string;
|
|
106
|
-
type: 'missing_in_pass2' | 'extra_in_pass2' | 'content_mismatch';
|
|
107
|
-
details?: string;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
function performRoundTrip(fixtureName: string): RoundTripReport {
|
|
111
|
-
const fixtureDir = path.join(FIXTURES_DIR, fixtureName);
|
|
112
|
-
const report: RoundTripReport = {
|
|
113
|
-
fixtureName,
|
|
114
|
-
compileSuccess: false,
|
|
115
|
-
compileErrors: [],
|
|
116
|
-
ir1: null,
|
|
117
|
-
childDefs1: [],
|
|
118
|
-
decompileSuccess: false,
|
|
119
|
-
outputFiles1: {},
|
|
120
|
-
recompileSuccess: false,
|
|
121
|
-
recompileErrors: [],
|
|
122
|
-
ir2: null,
|
|
123
|
-
irDiffs: [],
|
|
124
|
-
irMatch: false,
|
|
125
|
-
outputFiles2: {},
|
|
126
|
-
sourceStabilized: false,
|
|
127
|
-
sourceDiffs: [],
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
// Step 1: Read fixture source files
|
|
131
|
-
const sourceFiles = readProjectFiles(fixtureDir);
|
|
132
|
-
|
|
133
|
-
// Step 2: Compile (pass 1)
|
|
134
|
-
let result1: ProjectCompilationResult;
|
|
135
|
-
try {
|
|
136
|
-
result1 = compileProject(sourceFiles);
|
|
137
|
-
report.compileSuccess = true;
|
|
138
|
-
report.compileErrors = result1.errors.map(e => `${e.file}: ${e.message}`);
|
|
139
|
-
report.ir1 = result1.ir;
|
|
140
|
-
report.childDefs1 = result1.childDefinitions;
|
|
141
|
-
} catch (err) {
|
|
142
|
-
report.compileErrors = [(err as Error).message];
|
|
143
|
-
return report;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
// Step 3: Decompile (pass 1)
|
|
147
|
-
try {
|
|
148
|
-
const decompInput: DecompilerInput = {
|
|
149
|
-
...result1.ir,
|
|
150
|
-
childDefinitions: result1.childDefinitions,
|
|
151
|
-
experience: result1.ir.experience as any,
|
|
152
|
-
};
|
|
153
|
-
const decompResult = decompileProjectEnhanced(decompInput);
|
|
154
|
-
report.decompileSuccess = true;
|
|
155
|
-
|
|
156
|
-
for (const file of decompResult.files) {
|
|
157
|
-
report.outputFiles1[file.path] = file.content;
|
|
158
|
-
}
|
|
159
|
-
} catch (err) {
|
|
160
|
-
report.compileErrors.push(`Decompile failed: ${(err as Error).message}`);
|
|
161
|
-
return report;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
// Step 4: Re-compile (pass 2) — compile the decompiled output
|
|
165
|
-
let result2: ProjectCompilationResult;
|
|
166
|
-
try {
|
|
167
|
-
result2 = compileProject(report.outputFiles1);
|
|
168
|
-
report.recompileSuccess = true;
|
|
169
|
-
report.recompileErrors = result2.errors.map(e => `${e.file}: ${e.message}`);
|
|
170
|
-
report.ir2 = result2.ir;
|
|
171
|
-
} catch (err) {
|
|
172
|
-
report.recompileErrors = [(err as Error).message];
|
|
173
|
-
return report;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
// Step 5: Compare IR1 vs IR2 (semantic equality)
|
|
177
|
-
report.irDiffs = compareIRSemantic(result1.ir, result2.ir);
|
|
178
|
-
report.irMatch = report.irDiffs.filter(d => d.severity === 'error').length === 0;
|
|
179
|
-
|
|
180
|
-
// Step 6: Re-decompile (pass 2) — decompile IR2
|
|
181
|
-
try {
|
|
182
|
-
const decompInput2: DecompilerInput = {
|
|
183
|
-
...result2.ir,
|
|
184
|
-
childDefinitions: result2.childDefinitions,
|
|
185
|
-
experience: result2.ir.experience as any,
|
|
186
|
-
};
|
|
187
|
-
const decompResult2 = decompileProjectEnhanced(decompInput2);
|
|
188
|
-
|
|
189
|
-
for (const file of decompResult2.files) {
|
|
190
|
-
report.outputFiles2[file.path] = file.content;
|
|
191
|
-
}
|
|
192
|
-
} catch (err) {
|
|
193
|
-
report.recompileErrors.push(`Re-decompile failed: ${(err as Error).message}`);
|
|
194
|
-
return report;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
// Step 7: Compare outputFiles1 vs outputFiles2 (string equality)
|
|
198
|
-
report.sourceDiffs = compareSourceFiles(report.outputFiles1, report.outputFiles2);
|
|
199
|
-
report.sourceStabilized = report.sourceDiffs.length === 0;
|
|
200
|
-
|
|
201
|
-
return report;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
// =============================================================================
|
|
205
|
-
// IR Semantic Comparison
|
|
206
|
-
// =============================================================================
|
|
207
|
-
|
|
208
|
-
function compareIRSemantic(ir1: IRWorkflowDefinition, ir2: IRWorkflowDefinition): IRDiff[] {
|
|
209
|
-
const diffs: IRDiff[] = [];
|
|
210
|
-
|
|
211
|
-
// Slug
|
|
212
|
-
if (ir1.slug !== ir2.slug) {
|
|
213
|
-
diffs.push({ path: 'slug', expected: ir1.slug, actual: ir2.slug, severity: 'error' });
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
// Version
|
|
217
|
-
if (ir1.version !== ir2.version) {
|
|
218
|
-
diffs.push({ path: 'version', expected: ir1.version, actual: ir2.version, severity: 'error' });
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
// Category (may be string or array — use JSON comparison for arrays)
|
|
222
|
-
if (JSON.stringify(ir1.category) !== JSON.stringify(ir2.category)) {
|
|
223
|
-
diffs.push({ path: 'category', expected: ir1.category, actual: ir2.category, severity: 'error' });
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
// Fields (by name)
|
|
227
|
-
compareFieldsSemantic(diffs, ir1.fields, ir2.fields);
|
|
228
|
-
|
|
229
|
-
// States (by name)
|
|
230
|
-
compareStatesSemantic(diffs, ir1.states, ir2.states);
|
|
231
|
-
|
|
232
|
-
// Transitions (by name)
|
|
233
|
-
compareTransitionsSemantic(diffs, ir1.transitions, ir2.transitions);
|
|
234
|
-
|
|
235
|
-
// Experience tree existence
|
|
236
|
-
const hasExp1 = !!ir1.experience;
|
|
237
|
-
const hasExp2 = !!ir2.experience;
|
|
238
|
-
if (hasExp1 !== hasExp2) {
|
|
239
|
-
diffs.push({
|
|
240
|
-
path: 'experience',
|
|
241
|
-
expected: hasExp1 ? 'present' : 'absent',
|
|
242
|
-
actual: hasExp2 ? 'present' : 'absent',
|
|
243
|
-
severity: 'error',
|
|
244
|
-
});
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
if (hasExp1 && hasExp2) {
|
|
248
|
-
compareExperienceSemantic(diffs, 'experience', ir1.experience!, ir2.experience!);
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
return diffs;
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
function compareFieldsSemantic(
|
|
255
|
-
diffs: IRDiff[],
|
|
256
|
-
fields1: IRWorkflowDefinition['fields'],
|
|
257
|
-
fields2: IRWorkflowDefinition['fields'],
|
|
258
|
-
): void {
|
|
259
|
-
const map1 = new Map(fields1.map(f => [f.name, f]));
|
|
260
|
-
const map2 = new Map(fields2.map(f => [f.name, f]));
|
|
261
|
-
|
|
262
|
-
// Fields in IR1 but not IR2
|
|
263
|
-
for (const [name] of map1) {
|
|
264
|
-
if (!map2.has(name)) {
|
|
265
|
-
diffs.push({
|
|
266
|
-
path: `fields[${name}]`,
|
|
267
|
-
expected: name,
|
|
268
|
-
actual: undefined,
|
|
269
|
-
severity: 'error',
|
|
270
|
-
});
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
// Fields in IR2 but not IR1
|
|
275
|
-
for (const [name] of map2) {
|
|
276
|
-
if (!map1.has(name)) {
|
|
277
|
-
diffs.push({
|
|
278
|
-
path: `fields[${name}]`,
|
|
279
|
-
expected: undefined,
|
|
280
|
-
actual: name,
|
|
281
|
-
severity: 'warning',
|
|
282
|
-
});
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
// Common fields: compare type
|
|
287
|
-
for (const [name, f1] of map1) {
|
|
288
|
-
const f2 = map2.get(name);
|
|
289
|
-
if (!f2) continue;
|
|
290
|
-
|
|
291
|
-
if (f1.type !== f2.type && !isCompatibleFieldType(f1.type, f2.type)) {
|
|
292
|
-
diffs.push({
|
|
293
|
-
path: `fields[${name}].type`,
|
|
294
|
-
expected: f1.type,
|
|
295
|
-
actual: f2.type,
|
|
296
|
-
severity: 'warning',
|
|
297
|
-
});
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
function isCompatibleFieldType(t1: string, t2: string): boolean {
|
|
303
|
-
const stringTypes = new Set(['text', 'rich_text', 'email', 'url', 'phone', 'color', 'select']);
|
|
304
|
-
const numberTypes = new Set(['number', 'currency', 'percentage', 'rating', 'duration']);
|
|
305
|
-
if (stringTypes.has(t1) && stringTypes.has(t2)) return true;
|
|
306
|
-
if (numberTypes.has(t1) && numberTypes.has(t2)) return true;
|
|
307
|
-
return false;
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
function compareStatesSemantic(
|
|
311
|
-
diffs: IRDiff[],
|
|
312
|
-
states1: IRWorkflowDefinition['states'],
|
|
313
|
-
states2: IRWorkflowDefinition['states'],
|
|
314
|
-
): void {
|
|
315
|
-
const map1 = new Map(states1.map(s => [s.name, s]));
|
|
316
|
-
const map2 = new Map(states2.map(s => [s.name, s]));
|
|
317
|
-
|
|
318
|
-
// States with actions in IR1 must exist in IR2
|
|
319
|
-
for (const [name, s1] of map1) {
|
|
320
|
-
const hasActions = s1.on_enter.length > 0 || s1.on_exit.length > 0 || s1.during.length > 0;
|
|
321
|
-
const s2 = map2.get(name);
|
|
322
|
-
|
|
323
|
-
if (!s2 && hasActions) {
|
|
324
|
-
diffs.push({
|
|
325
|
-
path: `states[${name}]`,
|
|
326
|
-
expected: name,
|
|
327
|
-
actual: undefined,
|
|
328
|
-
severity: 'error',
|
|
329
|
-
});
|
|
330
|
-
continue;
|
|
331
|
-
}
|
|
332
|
-
if (!s2) continue;
|
|
333
|
-
|
|
334
|
-
// Compare action counts
|
|
335
|
-
if (s1.on_enter.length !== s2.on_enter.length) {
|
|
336
|
-
diffs.push({
|
|
337
|
-
path: `states[${name}].on_enter.length`,
|
|
338
|
-
expected: s1.on_enter.length,
|
|
339
|
-
actual: s2.on_enter.length,
|
|
340
|
-
severity: s1.on_enter.length > 0 ? 'error' : 'warning',
|
|
341
|
-
});
|
|
342
|
-
}
|
|
343
|
-
if (s1.on_exit.length !== s2.on_exit.length) {
|
|
344
|
-
diffs.push({
|
|
345
|
-
path: `states[${name}].on_exit.length`,
|
|
346
|
-
expected: s1.on_exit.length,
|
|
347
|
-
actual: s2.on_exit.length,
|
|
348
|
-
severity: s1.on_exit.length > 0 ? 'error' : 'warning',
|
|
349
|
-
});
|
|
350
|
-
}
|
|
351
|
-
if (s1.during.length !== s2.during.length) {
|
|
352
|
-
diffs.push({
|
|
353
|
-
path: `states[${name}].during.length`,
|
|
354
|
-
expected: s1.during.length,
|
|
355
|
-
actual: s2.during.length,
|
|
356
|
-
severity: s1.during.length > 0 ? 'error' : 'warning',
|
|
357
|
-
});
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
function compareTransitionsSemantic(
|
|
363
|
-
diffs: IRDiff[],
|
|
364
|
-
trans1: IRWorkflowDefinition['transitions'],
|
|
365
|
-
trans2: IRWorkflowDefinition['transitions'],
|
|
366
|
-
): void {
|
|
367
|
-
if (trans1.length !== trans2.length) {
|
|
368
|
-
diffs.push({
|
|
369
|
-
path: 'transitions.length',
|
|
370
|
-
expected: trans1.length,
|
|
371
|
-
actual: trans2.length,
|
|
372
|
-
severity: 'error',
|
|
373
|
-
});
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
const map1 = new Map(trans1.map(t => [t.name, t]));
|
|
377
|
-
const map2 = new Map(trans2.map(t => [t.name, t]));
|
|
378
|
-
|
|
379
|
-
for (const [name, t1] of map1) {
|
|
380
|
-
const t2 = map2.get(name);
|
|
381
|
-
if (!t2) {
|
|
382
|
-
diffs.push({
|
|
383
|
-
path: `transitions[${name}]`,
|
|
384
|
-
expected: name,
|
|
385
|
-
actual: undefined,
|
|
386
|
-
severity: 'error',
|
|
387
|
-
});
|
|
388
|
-
continue;
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
// Compare 'to' state
|
|
392
|
-
if (t1.to !== t2.to) {
|
|
393
|
-
diffs.push({
|
|
394
|
-
path: `transitions[${name}].to`,
|
|
395
|
-
expected: t1.to,
|
|
396
|
-
actual: t2.to,
|
|
397
|
-
severity: 'error',
|
|
398
|
-
});
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
// Compare 'from' states (order-independent)
|
|
402
|
-
const from1 = [...(Array.isArray(t1.from) ? t1.from : [t1.from])].sort();
|
|
403
|
-
const from2 = [...(Array.isArray(t2.from) ? t2.from : [t2.from])].sort();
|
|
404
|
-
if (JSON.stringify(from1) !== JSON.stringify(from2)) {
|
|
405
|
-
diffs.push({
|
|
406
|
-
path: `transitions[${name}].from`,
|
|
407
|
-
expected: from1,
|
|
408
|
-
actual: from2,
|
|
409
|
-
severity: 'error',
|
|
410
|
-
});
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
// Compare roles (order-independent)
|
|
414
|
-
const roles1 = [...(t1.roles ?? [])].sort();
|
|
415
|
-
const roles2 = [...(t2.roles ?? [])].sort();
|
|
416
|
-
if (JSON.stringify(roles1) !== JSON.stringify(roles2)) {
|
|
417
|
-
diffs.push({
|
|
418
|
-
path: `transitions[${name}].roles`,
|
|
419
|
-
expected: roles1,
|
|
420
|
-
actual: roles2,
|
|
421
|
-
severity: 'error',
|
|
422
|
-
});
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
// Compare required_fields (order-independent)
|
|
426
|
-
const req1 = [...(t1.required_fields ?? [])].sort();
|
|
427
|
-
const req2 = [...(t2.required_fields ?? [])].sort();
|
|
428
|
-
if (JSON.stringify(req1) !== JSON.stringify(req2)) {
|
|
429
|
-
diffs.push({
|
|
430
|
-
path: `transitions[${name}].required_fields`,
|
|
431
|
-
expected: req1,
|
|
432
|
-
actual: req2,
|
|
433
|
-
severity: 'error',
|
|
434
|
-
});
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
function compareExperienceSemantic(
|
|
440
|
-
diffs: IRDiff[],
|
|
441
|
-
prefix: string,
|
|
442
|
-
node1: any,
|
|
443
|
-
node2: any,
|
|
444
|
-
): void {
|
|
445
|
-
// Experience tree restructuring (Router/Route/NavLinks) is by design for multi-file
|
|
446
|
-
// projects. The decompiler extracts pages and the compiler composes them into
|
|
447
|
-
// Router/Route structure. These diffs are reported as warnings, not errors —
|
|
448
|
-
// source stabilization (pass N+1 = pass N) is the authoritative convergence test.
|
|
449
|
-
const severity: 'warning' | 'error' = 'warning';
|
|
450
|
-
|
|
451
|
-
// Compare component name
|
|
452
|
-
if (node1.component !== node2.component) {
|
|
453
|
-
diffs.push({
|
|
454
|
-
path: `${prefix}.component`,
|
|
455
|
-
expected: node1.component,
|
|
456
|
-
actual: node2.component,
|
|
457
|
-
severity,
|
|
458
|
-
});
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
// Compare children count
|
|
462
|
-
const children1 = node1.children ?? [];
|
|
463
|
-
const children2 = node2.children ?? [];
|
|
464
|
-
if (children1.length !== children2.length) {
|
|
465
|
-
diffs.push({
|
|
466
|
-
path: `${prefix}.children.length`,
|
|
467
|
-
expected: children1.length,
|
|
468
|
-
actual: children2.length,
|
|
469
|
-
severity,
|
|
470
|
-
});
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
// Recurse into children
|
|
474
|
-
const minLen = Math.min(children1.length, children2.length);
|
|
475
|
-
for (let i = 0; i < minLen; i++) {
|
|
476
|
-
compareExperienceSemantic(diffs, `${prefix}.children[${i}]`, children1[i], children2[i]);
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
// =============================================================================
|
|
481
|
-
// Source File Comparison (String Equality)
|
|
482
|
-
// =============================================================================
|
|
483
|
-
|
|
484
|
-
function compareSourceFiles(
|
|
485
|
-
files1: Record<string, string>,
|
|
486
|
-
files2: Record<string, string>,
|
|
487
|
-
): SourceDiff[] {
|
|
488
|
-
const diffs: SourceDiff[] = [];
|
|
489
|
-
|
|
490
|
-
// Files in pass 1 but not pass 2
|
|
491
|
-
for (const file of Object.keys(files1)) {
|
|
492
|
-
if (!(file in files2)) {
|
|
493
|
-
diffs.push({ file, type: 'missing_in_pass2' });
|
|
494
|
-
}
|
|
495
|
-
}
|
|
496
|
-
|
|
497
|
-
// Files in pass 2 but not pass 1
|
|
498
|
-
for (const file of Object.keys(files2)) {
|
|
499
|
-
if (!(file in files1)) {
|
|
500
|
-
diffs.push({ file, type: 'extra_in_pass2' });
|
|
501
|
-
}
|
|
502
|
-
}
|
|
503
|
-
|
|
504
|
-
// Content comparison for common files
|
|
505
|
-
for (const file of Object.keys(files1)) {
|
|
506
|
-
if (file in files2) {
|
|
507
|
-
if (files1[file] !== files2[file]) {
|
|
508
|
-
// Build a simple diff summary
|
|
509
|
-
const lines1 = files1[file].split('\n');
|
|
510
|
-
const lines2 = files2[file].split('\n');
|
|
511
|
-
const diffLines: string[] = [];
|
|
512
|
-
const maxLines = Math.max(lines1.length, lines2.length);
|
|
513
|
-
for (let i = 0; i < maxLines && diffLines.length < 10; i++) {
|
|
514
|
-
if (lines1[i] !== lines2[i]) {
|
|
515
|
-
diffLines.push(
|
|
516
|
-
` L${i + 1}: "${(lines1[i] ?? '(missing)').slice(0, 80)}" vs "${(lines2[i] ?? '(missing)').slice(0, 80)}"`,
|
|
517
|
-
);
|
|
518
|
-
}
|
|
519
|
-
}
|
|
520
|
-
diffs.push({
|
|
521
|
-
file,
|
|
522
|
-
type: 'content_mismatch',
|
|
523
|
-
details: diffLines.join('\n'),
|
|
524
|
-
});
|
|
525
|
-
}
|
|
526
|
-
}
|
|
527
|
-
}
|
|
528
|
-
|
|
529
|
-
return diffs;
|
|
530
|
-
}
|
|
531
|
-
|
|
532
|
-
// =============================================================================
|
|
533
|
-
// Single-file round-trip helper (for inline test sources)
|
|
534
|
-
// =============================================================================
|
|
535
|
-
|
|
536
|
-
interface SingleFileRoundTripResult {
|
|
537
|
-
compileSuccess: boolean;
|
|
538
|
-
ir1: IRWorkflowDefinition | null;
|
|
539
|
-
decompileCode1: string;
|
|
540
|
-
ir2: IRWorkflowDefinition | null;
|
|
541
|
-
decompileCode2: string;
|
|
542
|
-
irMatch: boolean;
|
|
543
|
-
irDiffs: IRDiff[];
|
|
544
|
-
sourceStabilized: boolean;
|
|
545
|
-
sourceDiff: string;
|
|
546
|
-
}
|
|
547
|
-
|
|
548
|
-
function singleFileRoundTrip(
|
|
549
|
-
source: string,
|
|
550
|
-
filename: string = 'test.workflow.tsx',
|
|
551
|
-
): SingleFileRoundTripResult {
|
|
552
|
-
const result: SingleFileRoundTripResult = {
|
|
553
|
-
compileSuccess: false,
|
|
554
|
-
ir1: null,
|
|
555
|
-
decompileCode1: '',
|
|
556
|
-
ir2: null,
|
|
557
|
-
decompileCode2: '',
|
|
558
|
-
irMatch: false,
|
|
559
|
-
irDiffs: [],
|
|
560
|
-
sourceStabilized: false,
|
|
561
|
-
sourceDiff: '',
|
|
562
|
-
};
|
|
563
|
-
|
|
564
|
-
// Pass 1: compile source → IR
|
|
565
|
-
const fileMap = { [filename]: source };
|
|
566
|
-
let compile1: ProjectCompilationResult;
|
|
567
|
-
try {
|
|
568
|
-
compile1 = compileProject(fileMap);
|
|
569
|
-
result.compileSuccess = true;
|
|
570
|
-
result.ir1 = compile1.ir;
|
|
571
|
-
} catch {
|
|
572
|
-
return result;
|
|
573
|
-
}
|
|
574
|
-
|
|
575
|
-
// Decompile IR → source code
|
|
576
|
-
const decompInput1: DecompilerInput = {
|
|
577
|
-
...compile1.ir,
|
|
578
|
-
experience: compile1.ir.experience as any,
|
|
579
|
-
};
|
|
580
|
-
const decomp1 = decompile(decompInput1, { includeAnnotation: true });
|
|
581
|
-
result.decompileCode1 = decomp1.code;
|
|
582
|
-
|
|
583
|
-
// Pass 2: compile decompiled source → IR2
|
|
584
|
-
let compile2: ProjectCompilationResult;
|
|
585
|
-
try {
|
|
586
|
-
compile2 = compileProject({ [filename]: decomp1.code });
|
|
587
|
-
result.ir2 = compile2.ir;
|
|
588
|
-
} catch {
|
|
589
|
-
return result;
|
|
590
|
-
}
|
|
591
|
-
|
|
592
|
-
// Compare IR1 vs IR2
|
|
593
|
-
result.irDiffs = compareIRSemantic(compile1.ir, compile2.ir);
|
|
594
|
-
result.irMatch = result.irDiffs.filter(d => d.severity === 'error').length === 0;
|
|
595
|
-
|
|
596
|
-
// Decompile IR2 → source code (pass 2)
|
|
597
|
-
const decompInput2: DecompilerInput = {
|
|
598
|
-
...compile2.ir,
|
|
599
|
-
experience: compile2.ir.experience as any,
|
|
600
|
-
};
|
|
601
|
-
const decomp2 = decompile(decompInput2, { includeAnnotation: true });
|
|
602
|
-
result.decompileCode2 = decomp2.code;
|
|
603
|
-
|
|
604
|
-
// String comparison
|
|
605
|
-
result.sourceStabilized = decomp1.code === decomp2.code;
|
|
606
|
-
if (!result.sourceStabilized) {
|
|
607
|
-
const lines1 = decomp1.code.split('\n');
|
|
608
|
-
const lines2 = decomp2.code.split('\n');
|
|
609
|
-
const diffs: string[] = [];
|
|
610
|
-
const maxLen = Math.max(lines1.length, lines2.length);
|
|
611
|
-
for (let i = 0; i < maxLen && diffs.length < 15; i++) {
|
|
612
|
-
if (lines1[i] !== lines2[i]) {
|
|
613
|
-
diffs.push(`L${i + 1}: pass1="${(lines1[i] ?? '').slice(0, 80)}" pass2="${(lines2[i] ?? '').slice(0, 80)}"`);
|
|
614
|
-
}
|
|
615
|
-
}
|
|
616
|
-
result.sourceDiff = diffs.join('\n');
|
|
617
|
-
}
|
|
618
|
-
|
|
619
|
-
return result;
|
|
620
|
-
}
|
|
621
|
-
|
|
622
|
-
// =============================================================================
|
|
623
|
-
// Fixture: simple-crud
|
|
624
|
-
// =============================================================================
|
|
625
|
-
|
|
626
|
-
describe('round-trip: simple-crud', () => {
|
|
627
|
-
let report: RoundTripReport;
|
|
628
|
-
|
|
629
|
-
beforeAll(() => {
|
|
630
|
-
report = performRoundTrip('simple-crud');
|
|
631
|
-
});
|
|
632
|
-
|
|
633
|
-
it('should compile the fixture successfully', () => {
|
|
634
|
-
expect(report.compileSuccess).toBe(true);
|
|
635
|
-
if (report.compileErrors.length > 0) {
|
|
636
|
-
console.log('Compile errors:', report.compileErrors);
|
|
637
|
-
}
|
|
638
|
-
});
|
|
639
|
-
|
|
640
|
-
it('should decompile successfully', () => {
|
|
641
|
-
expect(report.decompileSuccess).toBe(true);
|
|
642
|
-
});
|
|
643
|
-
|
|
644
|
-
it('should re-compile decompiled output successfully', () => {
|
|
645
|
-
expect(report.recompileSuccess).toBe(true);
|
|
646
|
-
if (report.recompileErrors.length > 0) {
|
|
647
|
-
console.log('Re-compile errors:', report.recompileErrors);
|
|
648
|
-
}
|
|
649
|
-
});
|
|
650
|
-
|
|
651
|
-
it('should preserve slug through round trip', () => {
|
|
652
|
-
expect(report.ir1).not.toBeNull();
|
|
653
|
-
expect(report.ir2).not.toBeNull();
|
|
654
|
-
// Slug may differ between original source slug and decompiled slug
|
|
655
|
-
// since decompiled mm.config.ts is not generated for single-tier projects.
|
|
656
|
-
// Check that IR2 has a slug at least.
|
|
657
|
-
expect(report.ir2!.slug).toBeTruthy();
|
|
658
|
-
});
|
|
659
|
-
|
|
660
|
-
it('should preserve fields through round trip', () => {
|
|
661
|
-
const fieldDiffs = report.irDiffs.filter(
|
|
662
|
-
d => d.path.startsWith('fields') && d.severity === 'error',
|
|
663
|
-
);
|
|
664
|
-
if (fieldDiffs.length > 0) {
|
|
665
|
-
console.log('Field diffs:', JSON.stringify(fieldDiffs, null, 2));
|
|
666
|
-
}
|
|
667
|
-
expect(fieldDiffs).toEqual([]);
|
|
668
|
-
});
|
|
669
|
-
|
|
670
|
-
it('should preserve transitions through round trip', () => {
|
|
671
|
-
const transDiffs = report.irDiffs.filter(
|
|
672
|
-
d => d.path.startsWith('transitions') && d.severity === 'error',
|
|
673
|
-
);
|
|
674
|
-
if (transDiffs.length > 0) {
|
|
675
|
-
console.log('Transition diffs:', JSON.stringify(transDiffs, null, 2));
|
|
676
|
-
}
|
|
677
|
-
expect(transDiffs).toEqual([]);
|
|
678
|
-
});
|
|
679
|
-
|
|
680
|
-
it('should preserve experience tree through round trip', () => {
|
|
681
|
-
const expDiffs = report.irDiffs.filter(
|
|
682
|
-
d => d.path.startsWith('experience') && d.severity === 'error',
|
|
683
|
-
);
|
|
684
|
-
if (expDiffs.length > 0) {
|
|
685
|
-
console.log('Experience diffs:', JSON.stringify(expDiffs, null, 2));
|
|
686
|
-
}
|
|
687
|
-
expect(expDiffs).toEqual([]);
|
|
688
|
-
});
|
|
689
|
-
|
|
690
|
-
it('should produce decompiled output files', () => {
|
|
691
|
-
expect(Object.keys(report.outputFiles1).length).toBeGreaterThan(0);
|
|
692
|
-
// Should have at least a main workflow file
|
|
693
|
-
const hasMain = Object.keys(report.outputFiles1).some(
|
|
694
|
-
f => f.includes('.workflow.tsx'),
|
|
695
|
-
);
|
|
696
|
-
expect(hasMain).toBe(true);
|
|
697
|
-
});
|
|
698
|
-
|
|
699
|
-
it('should stabilize source on second pass (Source\' === Source\'\')', () => {
|
|
700
|
-
if (!report.sourceStabilized) {
|
|
701
|
-
console.log('Source stabilization failures:');
|
|
702
|
-
for (const diff of report.sourceDiffs) {
|
|
703
|
-
console.log(` ${diff.file}: ${diff.type}`);
|
|
704
|
-
if (diff.details) {
|
|
705
|
-
console.log(diff.details);
|
|
706
|
-
}
|
|
707
|
-
}
|
|
708
|
-
}
|
|
709
|
-
expect(report.sourceStabilized).toBe(true);
|
|
710
|
-
});
|
|
711
|
-
});
|
|
712
|
-
|
|
713
|
-
// =============================================================================
|
|
714
|
-
// Fixture: full-workflow
|
|
715
|
-
// =============================================================================
|
|
716
|
-
|
|
717
|
-
describe('round-trip: full-workflow', () => {
|
|
718
|
-
let report: RoundTripReport;
|
|
719
|
-
|
|
720
|
-
beforeAll(() => {
|
|
721
|
-
report = performRoundTrip('full-workflow');
|
|
722
|
-
});
|
|
723
|
-
|
|
724
|
-
it('should compile the fixture successfully', () => {
|
|
725
|
-
expect(report.compileSuccess).toBe(true);
|
|
726
|
-
});
|
|
727
|
-
|
|
728
|
-
it('should decompile successfully', () => {
|
|
729
|
-
expect(report.decompileSuccess).toBe(true);
|
|
730
|
-
});
|
|
731
|
-
|
|
732
|
-
it('should re-compile decompiled output successfully', () => {
|
|
733
|
-
expect(report.recompileSuccess).toBe(true);
|
|
734
|
-
if (report.recompileErrors.length > 0) {
|
|
735
|
-
console.log('Re-compile errors:', report.recompileErrors);
|
|
736
|
-
}
|
|
737
|
-
});
|
|
738
|
-
|
|
739
|
-
it('should preserve fields through round trip', () => {
|
|
740
|
-
const fieldDiffs = report.irDiffs.filter(
|
|
741
|
-
d => d.path.startsWith('fields') && d.severity === 'error',
|
|
742
|
-
);
|
|
743
|
-
if (fieldDiffs.length > 0) {
|
|
744
|
-
console.log('Field diffs:', JSON.stringify(fieldDiffs, null, 2));
|
|
745
|
-
}
|
|
746
|
-
expect(fieldDiffs).toEqual([]);
|
|
747
|
-
});
|
|
748
|
-
|
|
749
|
-
it('should preserve transitions through round trip', () => {
|
|
750
|
-
const transDiffs = report.irDiffs.filter(
|
|
751
|
-
d => d.path.startsWith('transitions') && d.severity === 'error',
|
|
752
|
-
);
|
|
753
|
-
if (transDiffs.length > 0) {
|
|
754
|
-
console.log('Transition diffs:', JSON.stringify(transDiffs, null, 2));
|
|
755
|
-
}
|
|
756
|
-
expect(transDiffs).toEqual([]);
|
|
757
|
-
});
|
|
758
|
-
|
|
759
|
-
it('should preserve states with effects through round trip', () => {
|
|
760
|
-
const stateDiffs = report.irDiffs.filter(
|
|
761
|
-
d => d.path.startsWith('states') && d.severity === 'error',
|
|
762
|
-
);
|
|
763
|
-
if (stateDiffs.length > 0) {
|
|
764
|
-
console.log('State diffs:', JSON.stringify(stateDiffs, null, 2));
|
|
765
|
-
}
|
|
766
|
-
expect(stateDiffs).toEqual([]);
|
|
767
|
-
});
|
|
768
|
-
|
|
769
|
-
it('should preserve experience tree through round trip', () => {
|
|
770
|
-
const expDiffs = report.irDiffs.filter(
|
|
771
|
-
d => d.path.startsWith('experience') && d.severity === 'error',
|
|
772
|
-
);
|
|
773
|
-
if (expDiffs.length > 0) {
|
|
774
|
-
console.log('Experience diffs:', JSON.stringify(expDiffs, null, 2));
|
|
775
|
-
}
|
|
776
|
-
expect(expDiffs).toEqual([]);
|
|
777
|
-
});
|
|
778
|
-
|
|
779
|
-
it('should stabilize source on second pass', () => {
|
|
780
|
-
if (!report.sourceStabilized) {
|
|
781
|
-
console.log('Source stabilization failures:');
|
|
782
|
-
for (const diff of report.sourceDiffs) {
|
|
783
|
-
console.log(` ${diff.file}: ${diff.type}`);
|
|
784
|
-
if (diff.details) {
|
|
785
|
-
console.log(diff.details);
|
|
786
|
-
}
|
|
787
|
-
}
|
|
788
|
-
}
|
|
789
|
-
expect(report.sourceStabilized).toBe(true);
|
|
790
|
-
});
|
|
791
|
-
});
|
|
792
|
-
|
|
793
|
-
// =============================================================================
|
|
794
|
-
// Fixture: data-heavy
|
|
795
|
-
// =============================================================================
|
|
796
|
-
|
|
797
|
-
describe('round-trip: data-heavy', () => {
|
|
798
|
-
let report: RoundTripReport;
|
|
799
|
-
|
|
800
|
-
beforeAll(() => {
|
|
801
|
-
report = performRoundTrip('data-heavy');
|
|
802
|
-
});
|
|
803
|
-
|
|
804
|
-
it('should compile the fixture successfully', () => {
|
|
805
|
-
expect(report.compileSuccess).toBe(true);
|
|
806
|
-
});
|
|
807
|
-
|
|
808
|
-
it('should decompile successfully', () => {
|
|
809
|
-
expect(report.decompileSuccess).toBe(true);
|
|
810
|
-
});
|
|
811
|
-
|
|
812
|
-
it('should re-compile decompiled output successfully', () => {
|
|
813
|
-
expect(report.recompileSuccess).toBe(true);
|
|
814
|
-
if (report.recompileErrors.length > 0) {
|
|
815
|
-
console.log('Re-compile errors:', report.recompileErrors);
|
|
816
|
-
}
|
|
817
|
-
});
|
|
818
|
-
|
|
819
|
-
it('should preserve fields through round trip', () => {
|
|
820
|
-
const fieldDiffs = report.irDiffs.filter(
|
|
821
|
-
d => d.path.startsWith('fields') && d.severity === 'error',
|
|
822
|
-
);
|
|
823
|
-
if (fieldDiffs.length > 0) {
|
|
824
|
-
console.log('Field diffs:', JSON.stringify(fieldDiffs, null, 2));
|
|
825
|
-
}
|
|
826
|
-
expect(fieldDiffs).toEqual([]);
|
|
827
|
-
});
|
|
828
|
-
|
|
829
|
-
it('should preserve states with effects (on_enter, on_exit, during)', () => {
|
|
830
|
-
const stateDiffs = report.irDiffs.filter(
|
|
831
|
-
d => d.path.startsWith('states') && d.severity === 'error',
|
|
832
|
-
);
|
|
833
|
-
if (stateDiffs.length > 0) {
|
|
834
|
-
console.log('State diffs:', JSON.stringify(stateDiffs, null, 2));
|
|
835
|
-
}
|
|
836
|
-
expect(stateDiffs).toEqual([]);
|
|
837
|
-
});
|
|
838
|
-
|
|
839
|
-
it('should preserve transitions through round trip', () => {
|
|
840
|
-
const transDiffs = report.irDiffs.filter(
|
|
841
|
-
d => d.path.startsWith('transitions') && d.severity === 'error',
|
|
842
|
-
);
|
|
843
|
-
if (transDiffs.length > 0) {
|
|
844
|
-
console.log('Transition diffs:', JSON.stringify(transDiffs, null, 2));
|
|
845
|
-
}
|
|
846
|
-
expect(transDiffs).toEqual([]);
|
|
847
|
-
});
|
|
848
|
-
|
|
849
|
-
it('should stabilize source on second pass', () => {
|
|
850
|
-
if (!report.sourceStabilized) {
|
|
851
|
-
console.log('Source stabilization failures:');
|
|
852
|
-
for (const diff of report.sourceDiffs) {
|
|
853
|
-
console.log(` ${diff.file}: ${diff.type}`);
|
|
854
|
-
if (diff.details) {
|
|
855
|
-
console.log(diff.details);
|
|
856
|
-
}
|
|
857
|
-
}
|
|
858
|
-
}
|
|
859
|
-
expect(report.sourceStabilized).toBe(true);
|
|
860
|
-
});
|
|
861
|
-
});
|
|
862
|
-
|
|
863
|
-
// =============================================================================
|
|
864
|
-
// Fixture: view-heavy
|
|
865
|
-
// =============================================================================
|
|
866
|
-
|
|
867
|
-
describe('round-trip: view-heavy', () => {
|
|
868
|
-
let report: RoundTripReport;
|
|
869
|
-
|
|
870
|
-
beforeAll(() => {
|
|
871
|
-
report = performRoundTrip('view-heavy');
|
|
872
|
-
});
|
|
873
|
-
|
|
874
|
-
it('should compile the fixture successfully', () => {
|
|
875
|
-
expect(report.compileSuccess).toBe(true);
|
|
876
|
-
});
|
|
877
|
-
|
|
878
|
-
it('should decompile successfully', () => {
|
|
879
|
-
expect(report.decompileSuccess).toBe(true);
|
|
880
|
-
});
|
|
881
|
-
|
|
882
|
-
it('should re-compile decompiled output successfully', () => {
|
|
883
|
-
expect(report.recompileSuccess).toBe(true);
|
|
884
|
-
if (report.recompileErrors.length > 0) {
|
|
885
|
-
console.log('Re-compile errors:', report.recompileErrors);
|
|
886
|
-
}
|
|
887
|
-
});
|
|
888
|
-
|
|
889
|
-
it('should preserve fields through round trip', () => {
|
|
890
|
-
const fieldDiffs = report.irDiffs.filter(
|
|
891
|
-
d => d.path.startsWith('fields') && d.severity === 'error',
|
|
892
|
-
);
|
|
893
|
-
if (fieldDiffs.length > 0) {
|
|
894
|
-
console.log('Field diffs:', JSON.stringify(fieldDiffs, null, 2));
|
|
895
|
-
}
|
|
896
|
-
expect(fieldDiffs).toEqual([]);
|
|
897
|
-
});
|
|
898
|
-
|
|
899
|
-
it('should preserve experience tree structure', () => {
|
|
900
|
-
const expDiffs = report.irDiffs.filter(
|
|
901
|
-
d => d.path.startsWith('experience') && d.severity === 'error',
|
|
902
|
-
);
|
|
903
|
-
if (expDiffs.length > 0) {
|
|
904
|
-
console.log('Experience diffs:', JSON.stringify(expDiffs, null, 2));
|
|
905
|
-
}
|
|
906
|
-
expect(expDiffs).toEqual([]);
|
|
907
|
-
});
|
|
908
|
-
|
|
909
|
-
it('should stabilize source on second pass', () => {
|
|
910
|
-
if (!report.sourceStabilized) {
|
|
911
|
-
console.log('Source stabilization failures:');
|
|
912
|
-
for (const diff of report.sourceDiffs) {
|
|
913
|
-
console.log(` ${diff.file}: ${diff.type}`);
|
|
914
|
-
if (diff.details) {
|
|
915
|
-
console.log(diff.details);
|
|
916
|
-
}
|
|
917
|
-
}
|
|
918
|
-
}
|
|
919
|
-
expect(report.sourceStabilized).toBe(true);
|
|
920
|
-
});
|
|
921
|
-
});
|
|
922
|
-
|
|
923
|
-
// =============================================================================
|
|
924
|
-
// Single-file round-trip tests (inline sources)
|
|
925
|
-
// =============================================================================
|
|
926
|
-
|
|
927
|
-
describe('round-trip: single-file inline', () => {
|
|
928
|
-
describe('minimal counter', () => {
|
|
929
|
-
const source = `
|
|
930
|
-
/**
|
|
931
|
-
* @workflow slug="counter" version="1.0.0" category="workflow"
|
|
932
|
-
*/
|
|
933
|
-
import { useState } from 'react';
|
|
934
|
-
import { useTransition, Stack, Heading, Button } from '@mindmatrix/react';
|
|
935
|
-
|
|
936
|
-
export default function Counter() {
|
|
937
|
-
const [count, setCount] = useState(0);
|
|
938
|
-
|
|
939
|
-
useTransition('increment', { from: 'idle', to: 'idle' });
|
|
940
|
-
useTransition('reset', { from: 'idle', to: 'idle' });
|
|
941
|
-
|
|
942
|
-
return (
|
|
943
|
-
<Stack sx={{ gap: 8 }}>
|
|
944
|
-
<Heading>Count: {count}</Heading>
|
|
945
|
-
<Button onClick={() => setCount(count + 1)}>+1</Button>
|
|
946
|
-
<Button onClick={() => setCount(0)}>Reset</Button>
|
|
947
|
-
</Stack>
|
|
948
|
-
);
|
|
949
|
-
}
|
|
950
|
-
`;
|
|
951
|
-
|
|
952
|
-
it('should compile and decompile successfully', () => {
|
|
953
|
-
const result = singleFileRoundTrip(source, 'counter.workflow.tsx');
|
|
954
|
-
expect(result.compileSuccess).toBe(true);
|
|
955
|
-
expect(result.ir1).not.toBeNull();
|
|
956
|
-
expect(result.ir2).not.toBeNull();
|
|
957
|
-
});
|
|
958
|
-
|
|
959
|
-
it('should preserve IR semantically', () => {
|
|
960
|
-
const result = singleFileRoundTrip(source, 'counter.workflow.tsx');
|
|
961
|
-
const errors = result.irDiffs.filter(d => d.severity === 'error');
|
|
962
|
-
if (errors.length > 0) {
|
|
963
|
-
console.log('IR diffs:', JSON.stringify(errors, null, 2));
|
|
964
|
-
}
|
|
965
|
-
expect(errors).toEqual([]);
|
|
966
|
-
});
|
|
967
|
-
|
|
968
|
-
it('should stabilize source on second pass', () => {
|
|
969
|
-
const result = singleFileRoundTrip(source, 'counter.workflow.tsx');
|
|
970
|
-
if (!result.sourceStabilized) {
|
|
971
|
-
console.log('Source diff:\n' + result.sourceDiff);
|
|
972
|
-
console.log('\n--- Pass 1 output ---\n' + result.decompileCode1);
|
|
973
|
-
console.log('\n--- Pass 2 output ---\n' + result.decompileCode2);
|
|
974
|
-
}
|
|
975
|
-
expect(result.sourceStabilized).toBe(true);
|
|
976
|
-
});
|
|
977
|
-
});
|
|
978
|
-
|
|
979
|
-
describe('fields and state effects', () => {
|
|
980
|
-
const source = `
|
|
981
|
-
/**
|
|
982
|
-
* @workflow slug="task-tracker" version="1.0.0" category="workflow"
|
|
983
|
-
*/
|
|
984
|
-
import { useState } from 'react';
|
|
985
|
-
import { useOnEnter, useOnExit, useTransition, Stack, Text } from '@mindmatrix/react';
|
|
986
|
-
|
|
987
|
-
export default function TaskTracker() {
|
|
988
|
-
const [taskName, setTaskName] = useState('');
|
|
989
|
-
const [isComplete, setIsComplete] = useState(false);
|
|
990
|
-
const [progress, setProgress] = useState(0);
|
|
991
|
-
|
|
992
|
-
useOnEnter('active', () => {
|
|
993
|
-
setProgress(0);
|
|
994
|
-
});
|
|
995
|
-
|
|
996
|
-
useOnExit('active', () => {
|
|
997
|
-
setIsComplete(true);
|
|
998
|
-
});
|
|
999
|
-
|
|
1000
|
-
useTransition('start', { from: 'idle', to: 'active' });
|
|
1001
|
-
useTransition('complete', { from: 'active', to: 'done' });
|
|
1002
|
-
|
|
1003
|
-
return (
|
|
1004
|
-
<Stack>
|
|
1005
|
-
<Text>{taskName}: {progress}%</Text>
|
|
1006
|
-
</Stack>
|
|
1007
|
-
);
|
|
1008
|
-
}
|
|
1009
|
-
`;
|
|
1010
|
-
|
|
1011
|
-
it('should compile and preserve fields', () => {
|
|
1012
|
-
const result = singleFileRoundTrip(source, 'task.workflow.tsx');
|
|
1013
|
-
expect(result.compileSuccess).toBe(true);
|
|
1014
|
-
const fieldErrors = result.irDiffs.filter(
|
|
1015
|
-
d => d.path.startsWith('fields') && d.severity === 'error',
|
|
1016
|
-
);
|
|
1017
|
-
expect(fieldErrors).toEqual([]);
|
|
1018
|
-
});
|
|
1019
|
-
|
|
1020
|
-
it('should preserve state effects', () => {
|
|
1021
|
-
const result = singleFileRoundTrip(source, 'task.workflow.tsx');
|
|
1022
|
-
const stateErrors = result.irDiffs.filter(
|
|
1023
|
-
d => d.path.startsWith('states') && d.severity === 'error',
|
|
1024
|
-
);
|
|
1025
|
-
if (stateErrors.length > 0) {
|
|
1026
|
-
console.log('State diffs:', JSON.stringify(stateErrors, null, 2));
|
|
1027
|
-
}
|
|
1028
|
-
expect(stateErrors).toEqual([]);
|
|
1029
|
-
});
|
|
1030
|
-
|
|
1031
|
-
it('should stabilize source on second pass', () => {
|
|
1032
|
-
const result = singleFileRoundTrip(source, 'task.workflow.tsx');
|
|
1033
|
-
if (!result.sourceStabilized) {
|
|
1034
|
-
console.log('Source diff:\n' + result.sourceDiff);
|
|
1035
|
-
}
|
|
1036
|
-
expect(result.sourceStabilized).toBe(true);
|
|
1037
|
-
});
|
|
1038
|
-
});
|
|
1039
|
-
|
|
1040
|
-
describe('transitions with roles and required fields', () => {
|
|
1041
|
-
const source = `
|
|
1042
|
-
/**
|
|
1043
|
-
* @workflow slug="approval-flow" version="1.0.0" category="workflow"
|
|
1044
|
-
*/
|
|
1045
|
-
import { useState } from 'react';
|
|
1046
|
-
import { useTransition, Stack, Text, Button } from '@mindmatrix/react';
|
|
1047
|
-
|
|
1048
|
-
export default function ApprovalFlow() {
|
|
1049
|
-
const [status, setStatus] = useState('');
|
|
1050
|
-
const [amount, setAmount] = useState(0);
|
|
1051
|
-
|
|
1052
|
-
const submit = useTransition('submit', {
|
|
1053
|
-
from: 'draft',
|
|
1054
|
-
to: 'pending',
|
|
1055
|
-
requiredFields: ['amount'],
|
|
1056
|
-
roles: ['submitter'],
|
|
1057
|
-
});
|
|
1058
|
-
|
|
1059
|
-
const approve = useTransition('approve', {
|
|
1060
|
-
from: 'pending',
|
|
1061
|
-
to: 'approved',
|
|
1062
|
-
roles: ['approver'],
|
|
1063
|
-
});
|
|
1064
|
-
|
|
1065
|
-
const reject = useTransition('reject', {
|
|
1066
|
-
from: 'pending',
|
|
1067
|
-
to: 'rejected',
|
|
1068
|
-
roles: ['approver'],
|
|
1069
|
-
});
|
|
1070
|
-
|
|
1071
|
-
return (
|
|
1072
|
-
<Stack sx={{ gap: 8 }}>
|
|
1073
|
-
<Text>Amount: {amount}</Text>
|
|
1074
|
-
<Text>Status: {status}</Text>
|
|
1075
|
-
<Button onClick={() => submit.fire()}>Submit</Button>
|
|
1076
|
-
<Button onClick={() => approve.fire()}>Approve</Button>
|
|
1077
|
-
<Button onClick={() => reject.fire()}>Reject</Button>
|
|
1078
|
-
</Stack>
|
|
1079
|
-
);
|
|
1080
|
-
}
|
|
1081
|
-
`;
|
|
1082
|
-
|
|
1083
|
-
it('should preserve transitions with roles and required fields', () => {
|
|
1084
|
-
const result = singleFileRoundTrip(source, 'approval.workflow.tsx');
|
|
1085
|
-
expect(result.compileSuccess).toBe(true);
|
|
1086
|
-
|
|
1087
|
-
const transErrors = result.irDiffs.filter(
|
|
1088
|
-
d => d.path.startsWith('transitions') && d.severity === 'error',
|
|
1089
|
-
);
|
|
1090
|
-
if (transErrors.length > 0) {
|
|
1091
|
-
console.log('Transition diffs:', JSON.stringify(transErrors, null, 2));
|
|
1092
|
-
}
|
|
1093
|
-
expect(transErrors).toEqual([]);
|
|
1094
|
-
});
|
|
1095
|
-
|
|
1096
|
-
it('should stabilize source on second pass', () => {
|
|
1097
|
-
const result = singleFileRoundTrip(source, 'approval.workflow.tsx');
|
|
1098
|
-
if (!result.sourceStabilized) {
|
|
1099
|
-
console.log('Source diff:\n' + result.sourceDiff);
|
|
1100
|
-
}
|
|
1101
|
-
expect(result.sourceStabilized).toBe(true);
|
|
1102
|
-
});
|
|
1103
|
-
});
|
|
1104
|
-
|
|
1105
|
-
describe('complex JSX tree with sx styles', () => {
|
|
1106
|
-
const source = `
|
|
1107
|
-
/**
|
|
1108
|
-
* @workflow slug="styled-view" version="1.0.0" category="workflow"
|
|
1109
|
-
*/
|
|
1110
|
-
import { useState } from 'react';
|
|
1111
|
-
import { Stack, Row, Heading, Text, Button } from '@mindmatrix/react';
|
|
1112
|
-
|
|
1113
|
-
export default function StyledView() {
|
|
1114
|
-
const [title, setTitle] = useState('Hello');
|
|
1115
|
-
const [count, setCount] = useState(0);
|
|
1116
|
-
|
|
1117
|
-
return (
|
|
1118
|
-
<Stack sx={{ gap: 16, p: 24, bg: '#ffffff' }}>
|
|
1119
|
-
<Heading sx={{ fontSize: 24, fontWeight: 'bold', color: '#1a1a1a' }}>{title}</Heading>
|
|
1120
|
-
<Row sx={{ gap: 8, alignItems: 'center' }}>
|
|
1121
|
-
<Text sx={{ fontSize: 14, color: '#64748b' }}>Count: {count}</Text>
|
|
1122
|
-
<Button onClick={() => setCount(count + 1)} sx={{ colorScheme: 'blue' }}>Increment</Button>
|
|
1123
|
-
</Row>
|
|
1124
|
-
</Stack>
|
|
1125
|
-
);
|
|
1126
|
-
}
|
|
1127
|
-
`;
|
|
1128
|
-
|
|
1129
|
-
it('should preserve JSX structure and styles', () => {
|
|
1130
|
-
const result = singleFileRoundTrip(source, 'styled.workflow.tsx');
|
|
1131
|
-
expect(result.compileSuccess).toBe(true);
|
|
1132
|
-
|
|
1133
|
-
const expErrors = result.irDiffs.filter(
|
|
1134
|
-
d => d.path.startsWith('experience') && d.severity === 'error',
|
|
1135
|
-
);
|
|
1136
|
-
if (expErrors.length > 0) {
|
|
1137
|
-
console.log('Experience diffs:', JSON.stringify(expErrors, null, 2));
|
|
1138
|
-
}
|
|
1139
|
-
expect(expErrors).toEqual([]);
|
|
1140
|
-
});
|
|
1141
|
-
|
|
1142
|
-
it('should stabilize source on second pass', () => {
|
|
1143
|
-
const result = singleFileRoundTrip(source, 'styled.workflow.tsx');
|
|
1144
|
-
if (!result.sourceStabilized) {
|
|
1145
|
-
console.log('Source diff:\n' + result.sourceDiff);
|
|
1146
|
-
console.log('\n--- Pass 1 ---\n' + result.decompileCode1);
|
|
1147
|
-
console.log('\n--- Pass 2 ---\n' + result.decompileCode2);
|
|
1148
|
-
}
|
|
1149
|
-
expect(result.sourceStabilized).toBe(true);
|
|
1150
|
-
});
|
|
1151
|
-
});
|
|
1152
|
-
|
|
1153
|
-
describe('conditional rendering with Show', () => {
|
|
1154
|
-
const source = `
|
|
1155
|
-
/**
|
|
1156
|
-
* @workflow slug="conditional-view" version="1.0.0" category="workflow"
|
|
1157
|
-
*/
|
|
1158
|
-
import { useState } from 'react';
|
|
1159
|
-
import { Stack, Text, Show, Button } from '@mindmatrix/react';
|
|
1160
|
-
|
|
1161
|
-
export default function ConditionalView() {
|
|
1162
|
-
const [visible, setVisible] = useState(false);
|
|
1163
|
-
const [message, setMessage] = useState('Hello');
|
|
1164
|
-
|
|
1165
|
-
return (
|
|
1166
|
-
<Stack>
|
|
1167
|
-
<Button onClick={() => setVisible(!visible)}>Toggle</Button>
|
|
1168
|
-
<Show when={visible}>
|
|
1169
|
-
<Text>{message}</Text>
|
|
1170
|
-
</Show>
|
|
1171
|
-
</Stack>
|
|
1172
|
-
);
|
|
1173
|
-
}
|
|
1174
|
-
`;
|
|
1175
|
-
|
|
1176
|
-
it('should preserve Show conditional rendering', () => {
|
|
1177
|
-
const result = singleFileRoundTrip(source, 'conditional.workflow.tsx');
|
|
1178
|
-
expect(result.compileSuccess).toBe(true);
|
|
1179
|
-
});
|
|
1180
|
-
|
|
1181
|
-
it('should stabilize source on second pass', () => {
|
|
1182
|
-
const result = singleFileRoundTrip(source, 'conditional.workflow.tsx');
|
|
1183
|
-
if (!result.sourceStabilized) {
|
|
1184
|
-
console.log('Source diff:\n' + result.sourceDiff);
|
|
1185
|
-
}
|
|
1186
|
-
expect(result.sourceStabilized).toBe(true);
|
|
1187
|
-
});
|
|
1188
|
-
});
|
|
1189
|
-
|
|
1190
|
-
describe('useOnChange and useOnEvent', () => {
|
|
1191
|
-
const source = `
|
|
1192
|
-
/**
|
|
1193
|
-
* @workflow slug="event-demo" version="1.0.0" category="workflow"
|
|
1194
|
-
*/
|
|
1195
|
-
import { useState } from 'react';
|
|
1196
|
-
import { useOnChange, useOnEvent, Stack, Text } from '@mindmatrix/react';
|
|
1197
|
-
|
|
1198
|
-
export default function EventDemo() {
|
|
1199
|
-
const [value, setValue] = useState('');
|
|
1200
|
-
const [lastEvent, setLastEvent] = useState('');
|
|
1201
|
-
|
|
1202
|
-
useOnChange('value', () => {
|
|
1203
|
-
setLastEvent('value changed');
|
|
1204
|
-
});
|
|
1205
|
-
|
|
1206
|
-
useOnEvent('external:update', () => {
|
|
1207
|
-
setLastEvent('external update received');
|
|
1208
|
-
});
|
|
1209
|
-
|
|
1210
|
-
return (
|
|
1211
|
-
<Stack>
|
|
1212
|
-
<Text>Value: {value}</Text>
|
|
1213
|
-
<Text>Last event: {lastEvent}</Text>
|
|
1214
|
-
</Stack>
|
|
1215
|
-
);
|
|
1216
|
-
}
|
|
1217
|
-
`;
|
|
1218
|
-
|
|
1219
|
-
it('should preserve useOnChange and useOnEvent hooks', () => {
|
|
1220
|
-
const result = singleFileRoundTrip(source, 'events.workflow.tsx');
|
|
1221
|
-
expect(result.compileSuccess).toBe(true);
|
|
1222
|
-
|
|
1223
|
-
// Check that on_event subscriptions survive
|
|
1224
|
-
const eventDiffs = result.irDiffs.filter(
|
|
1225
|
-
d => d.severity === 'error',
|
|
1226
|
-
);
|
|
1227
|
-
if (eventDiffs.length > 0) {
|
|
1228
|
-
console.log('Diffs:', JSON.stringify(eventDiffs, null, 2));
|
|
1229
|
-
}
|
|
1230
|
-
});
|
|
1231
|
-
|
|
1232
|
-
it('should stabilize source on second pass', () => {
|
|
1233
|
-
const result = singleFileRoundTrip(source, 'events.workflow.tsx');
|
|
1234
|
-
if (!result.sourceStabilized) {
|
|
1235
|
-
console.log('Source diff:\n' + result.sourceDiff);
|
|
1236
|
-
}
|
|
1237
|
-
expect(result.sourceStabilized).toBe(true);
|
|
1238
|
-
});
|
|
1239
|
-
});
|
|
1240
|
-
|
|
1241
|
-
describe('useRole declarations', () => {
|
|
1242
|
-
const source = `
|
|
1243
|
-
/**
|
|
1244
|
-
* @workflow slug="role-demo" version="1.0.0" category="workflow"
|
|
1245
|
-
*/
|
|
1246
|
-
import { useState } from 'react';
|
|
1247
|
-
import { useRole, Stack, Text, Show } from '@mindmatrix/react';
|
|
1248
|
-
|
|
1249
|
-
export default function RoleDemo() {
|
|
1250
|
-
const [data, setData] = useState('');
|
|
1251
|
-
|
|
1252
|
-
const isAdmin = useRole('admin');
|
|
1253
|
-
const isEditor = useRole('editor');
|
|
1254
|
-
|
|
1255
|
-
return (
|
|
1256
|
-
<Stack>
|
|
1257
|
-
<Text>Data: {data}</Text>
|
|
1258
|
-
</Stack>
|
|
1259
|
-
);
|
|
1260
|
-
}
|
|
1261
|
-
`;
|
|
1262
|
-
|
|
1263
|
-
it('should preserve role declarations', () => {
|
|
1264
|
-
const result = singleFileRoundTrip(source, 'roles.workflow.tsx');
|
|
1265
|
-
expect(result.compileSuccess).toBe(true);
|
|
1266
|
-
});
|
|
1267
|
-
|
|
1268
|
-
it('should stabilize source on second pass', () => {
|
|
1269
|
-
const result = singleFileRoundTrip(source, 'roles.workflow.tsx');
|
|
1270
|
-
if (!result.sourceStabilized) {
|
|
1271
|
-
console.log('Source diff:\n' + result.sourceDiff);
|
|
1272
|
-
}
|
|
1273
|
-
expect(result.sourceStabilized).toBe(true);
|
|
1274
|
-
});
|
|
1275
|
-
});
|
|
1276
|
-
});
|
|
1277
|
-
|
|
1278
|
-
// =============================================================================
|
|
1279
|
-
// Comprehensive pattern coverage: every atom, hook, and pattern
|
|
1280
|
-
// =============================================================================
|
|
1281
|
-
|
|
1282
|
-
describe('round-trip: pattern coverage', () => {
|
|
1283
|
-
|
|
1284
|
-
// ---------------------------------------------------------------------------
|
|
1285
|
-
// Layout atoms: Grid, Column, Divider, Spacer, Card, Section
|
|
1286
|
-
// ---------------------------------------------------------------------------
|
|
1287
|
-
describe('layout atoms (Grid, Column, Divider, Card, Section)', () => {
|
|
1288
|
-
const source = `
|
|
1289
|
-
/**
|
|
1290
|
-
* @workflow slug="layout-demo" version="1.0.0" category="workflow"
|
|
1291
|
-
*/
|
|
1292
|
-
import { useState } from 'react';
|
|
1293
|
-
import { Grid, Column, Row, Divider, Spacer, Card, Section, Stack, Text } from '@mindmatrix/react';
|
|
1294
|
-
|
|
1295
|
-
export default function LayoutDemo() {
|
|
1296
|
-
const [title, setTitle] = useState('Dashboard');
|
|
1297
|
-
|
|
1298
|
-
return (
|
|
1299
|
-
<Stack sx={{ gap: 16 }}>
|
|
1300
|
-
<Card sx={{ p: 16 }}>
|
|
1301
|
-
<Text>{title}</Text>
|
|
1302
|
-
</Card>
|
|
1303
|
-
<Divider />
|
|
1304
|
-
<Grid sx={{ gap: 8 }}>
|
|
1305
|
-
<Column><Text>Col 1</Text></Column>
|
|
1306
|
-
<Column><Text>Col 2</Text></Column>
|
|
1307
|
-
</Grid>
|
|
1308
|
-
<Section>
|
|
1309
|
-
<Row sx={{ gap: 4 }}>
|
|
1310
|
-
<Text>Left</Text>
|
|
1311
|
-
<Spacer />
|
|
1312
|
-
<Text>Right</Text>
|
|
1313
|
-
</Row>
|
|
1314
|
-
</Section>
|
|
1315
|
-
</Stack>
|
|
1316
|
-
);
|
|
1317
|
-
}
|
|
1318
|
-
`;
|
|
1319
|
-
|
|
1320
|
-
it('should compile and stabilize', () => {
|
|
1321
|
-
const result = singleFileRoundTrip(source, 'layout.workflow.tsx');
|
|
1322
|
-
expect(result.compileSuccess).toBe(true);
|
|
1323
|
-
if (!result.sourceStabilized) {
|
|
1324
|
-
console.log('Layout diff:\n' + result.sourceDiff);
|
|
1325
|
-
}
|
|
1326
|
-
expect(result.sourceStabilized).toBe(true);
|
|
1327
|
-
});
|
|
1328
|
-
|
|
1329
|
-
it('should preserve component tree structure', () => {
|
|
1330
|
-
const result = singleFileRoundTrip(source, 'layout.workflow.tsx');
|
|
1331
|
-
const errors = result.irDiffs.filter(d => d.severity === 'error');
|
|
1332
|
-
expect(errors).toEqual([]);
|
|
1333
|
-
});
|
|
1334
|
-
});
|
|
1335
|
-
|
|
1336
|
-
// ---------------------------------------------------------------------------
|
|
1337
|
-
// Form atoms: TextInput, Select with options
|
|
1338
|
-
// ---------------------------------------------------------------------------
|
|
1339
|
-
describe('form atoms (TextInput, Select)', () => {
|
|
1340
|
-
const source = `
|
|
1341
|
-
/**
|
|
1342
|
-
* @workflow slug="form-demo" version="1.0.0" category="workflow"
|
|
1343
|
-
*/
|
|
1344
|
-
import { useState } from 'react';
|
|
1345
|
-
import { Stack, Text, TextInput, Select, Button } from '@mindmatrix/react';
|
|
1346
|
-
|
|
1347
|
-
export default function FormDemo() {
|
|
1348
|
-
const [name, setName] = useState('');
|
|
1349
|
-
const [color, setColor] = useState('red');
|
|
1350
|
-
|
|
1351
|
-
return (
|
|
1352
|
-
<Stack sx={{ gap: 8 }}>
|
|
1353
|
-
<TextInput value={name} label="Name" placeholder="Enter name" />
|
|
1354
|
-
<Select value={color} label="Color" options={["red", "green", "blue"]} />
|
|
1355
|
-
<Button label="Submit" onClick={() => setName('')} />
|
|
1356
|
-
<Text>Selected: {color}</Text>
|
|
1357
|
-
</Stack>
|
|
1358
|
-
);
|
|
1359
|
-
}
|
|
1360
|
-
`;
|
|
1361
|
-
|
|
1362
|
-
it('should compile and stabilize', () => {
|
|
1363
|
-
const result = singleFileRoundTrip(source, 'form.workflow.tsx');
|
|
1364
|
-
expect(result.compileSuccess).toBe(true);
|
|
1365
|
-
if (!result.sourceStabilized) {
|
|
1366
|
-
console.log('Form diff:\n' + result.sourceDiff);
|
|
1367
|
-
}
|
|
1368
|
-
expect(result.sourceStabilized).toBe(true);
|
|
1369
|
-
});
|
|
1370
|
-
});
|
|
1371
|
-
|
|
1372
|
-
// ---------------------------------------------------------------------------
|
|
1373
|
-
// Each (list rendering) — the .map() pattern
|
|
1374
|
-
// ---------------------------------------------------------------------------
|
|
1375
|
-
describe('Each list rendering', () => {
|
|
1376
|
-
const source = `
|
|
1377
|
-
/**
|
|
1378
|
-
* @workflow slug="list-demo" version="1.0.0" category="workflow"
|
|
1379
|
-
*/
|
|
1380
|
-
import { useState } from 'react';
|
|
1381
|
-
import { Stack, Text, Each, Button } from '@mindmatrix/react';
|
|
1382
|
-
|
|
1383
|
-
export default function ListDemo() {
|
|
1384
|
-
const [count, setCount] = useState(0);
|
|
1385
|
-
|
|
1386
|
-
return (
|
|
1387
|
-
<Stack sx={{ gap: 4 }}>
|
|
1388
|
-
<Text>Count: {count}</Text>
|
|
1389
|
-
<Each items={$instance.tasks} as="task">
|
|
1390
|
-
<Text>{task.name}</Text>
|
|
1391
|
-
</Each>
|
|
1392
|
-
<Button label="Add" onClick={() => setCount(count + 1)} />
|
|
1393
|
-
</Stack>
|
|
1394
|
-
);
|
|
1395
|
-
}
|
|
1396
|
-
`;
|
|
1397
|
-
|
|
1398
|
-
it('should compile and stabilize', () => {
|
|
1399
|
-
const result = singleFileRoundTrip(source, 'list.workflow.tsx');
|
|
1400
|
-
expect(result.compileSuccess).toBe(true);
|
|
1401
|
-
if (!result.sourceStabilized) {
|
|
1402
|
-
console.log('Each diff:\n' + result.sourceDiff);
|
|
1403
|
-
}
|
|
1404
|
-
expect(result.sourceStabilized).toBe(true);
|
|
1405
|
-
});
|
|
1406
|
-
});
|
|
1407
|
-
|
|
1408
|
-
// ---------------------------------------------------------------------------
|
|
1409
|
-
// Image, Badge, Icon atoms
|
|
1410
|
-
// ---------------------------------------------------------------------------
|
|
1411
|
-
describe('media atoms (Image, Badge, Icon)', () => {
|
|
1412
|
-
const source = `
|
|
1413
|
-
/**
|
|
1414
|
-
* @workflow slug="media-demo" version="1.0.0" category="workflow"
|
|
1415
|
-
*/
|
|
1416
|
-
import { useState } from 'react';
|
|
1417
|
-
import { Stack, Row, Image, Badge, Icon, Text } from '@mindmatrix/react';
|
|
1418
|
-
|
|
1419
|
-
export default function MediaDemo() {
|
|
1420
|
-
const [status, setStatus] = useState('active');
|
|
1421
|
-
|
|
1422
|
-
return (
|
|
1423
|
-
<Stack sx={{ gap: 8 }}>
|
|
1424
|
-
<Row sx={{ gap: 4, alignItems: 'center' }}>
|
|
1425
|
-
<Image src="https://example.com/avatar.png" alt="Avatar" sx={{ width: 40, height: 40, borderRadius: '50%' }} />
|
|
1426
|
-
<Text>User Name</Text>
|
|
1427
|
-
<Badge variant="success" label={status} />
|
|
1428
|
-
</Row>
|
|
1429
|
-
<Row sx={{ gap: 4 }}>
|
|
1430
|
-
<Icon name="settings" />
|
|
1431
|
-
<Icon name="bell" />
|
|
1432
|
-
</Row>
|
|
1433
|
-
</Stack>
|
|
1434
|
-
);
|
|
1435
|
-
}
|
|
1436
|
-
`;
|
|
1437
|
-
|
|
1438
|
-
it('should compile and stabilize', () => {
|
|
1439
|
-
const result = singleFileRoundTrip(source, 'media.workflow.tsx');
|
|
1440
|
-
expect(result.compileSuccess).toBe(true);
|
|
1441
|
-
if (!result.sourceStabilized) {
|
|
1442
|
-
console.log('Media diff:\n' + result.sourceDiff);
|
|
1443
|
-
}
|
|
1444
|
-
expect(result.sourceStabilized).toBe(true);
|
|
1445
|
-
});
|
|
1446
|
-
});
|
|
1447
|
-
|
|
1448
|
-
// ---------------------------------------------------------------------------
|
|
1449
|
-
// Modal atom
|
|
1450
|
-
// ---------------------------------------------------------------------------
|
|
1451
|
-
describe('Modal atom', () => {
|
|
1452
|
-
const source = `
|
|
1453
|
-
/**
|
|
1454
|
-
* @workflow slug="modal-demo" version="1.0.0" category="workflow"
|
|
1455
|
-
*/
|
|
1456
|
-
import { useState } from 'react';
|
|
1457
|
-
import { Stack, Text, Button, Modal } from '@mindmatrix/react';
|
|
1458
|
-
|
|
1459
|
-
export default function ModalDemo() {
|
|
1460
|
-
const [open, setOpen] = useState(false);
|
|
1461
|
-
|
|
1462
|
-
return (
|
|
1463
|
-
<Stack>
|
|
1464
|
-
<Button label="Open" onClick={() => setOpen(true)} />
|
|
1465
|
-
<Modal open={open} title="Confirm">
|
|
1466
|
-
<Text>Are you sure?</Text>
|
|
1467
|
-
<Button label="Close" onClick={() => setOpen(false)} />
|
|
1468
|
-
</Modal>
|
|
1469
|
-
</Stack>
|
|
1470
|
-
);
|
|
1471
|
-
}
|
|
1472
|
-
`;
|
|
1473
|
-
|
|
1474
|
-
it('should compile and stabilize', () => {
|
|
1475
|
-
const result = singleFileRoundTrip(source, 'modal.workflow.tsx');
|
|
1476
|
-
expect(result.compileSuccess).toBe(true);
|
|
1477
|
-
if (!result.sourceStabilized) {
|
|
1478
|
-
console.log('Modal diff:\n' + result.sourceDiff);
|
|
1479
|
-
}
|
|
1480
|
-
expect(result.sourceStabilized).toBe(true);
|
|
1481
|
-
});
|
|
1482
|
-
});
|
|
1483
|
-
|
|
1484
|
-
// ---------------------------------------------------------------------------
|
|
1485
|
-
// Multi-action event handler ($action.seq)
|
|
1486
|
-
// ---------------------------------------------------------------------------
|
|
1487
|
-
describe('multi-action event handlers', () => {
|
|
1488
|
-
const source = `
|
|
1489
|
-
/**
|
|
1490
|
-
* @workflow slug="multi-action" version="1.0.0" category="workflow"
|
|
1491
|
-
*/
|
|
1492
|
-
import { useState } from 'react';
|
|
1493
|
-
import { Stack, Text, Button } from '@mindmatrix/react';
|
|
1494
|
-
|
|
1495
|
-
export default function MultiAction() {
|
|
1496
|
-
const [count, setCount] = useState(0);
|
|
1497
|
-
const [message, setMessage] = useState('');
|
|
1498
|
-
|
|
1499
|
-
return (
|
|
1500
|
-
<Stack>
|
|
1501
|
-
<Text>{message}: {count}</Text>
|
|
1502
|
-
<Button label="Do Both" onClick={() => { setCount(count + 1); setMessage('incremented'); }} />
|
|
1503
|
-
</Stack>
|
|
1504
|
-
);
|
|
1505
|
-
}
|
|
1506
|
-
`;
|
|
1507
|
-
|
|
1508
|
-
it('should compile and stabilize', () => {
|
|
1509
|
-
const result = singleFileRoundTrip(source, 'multi.workflow.tsx');
|
|
1510
|
-
expect(result.compileSuccess).toBe(true);
|
|
1511
|
-
if (!result.sourceStabilized) {
|
|
1512
|
-
console.log('Multi-action diff:\n' + result.sourceDiff);
|
|
1513
|
-
}
|
|
1514
|
-
expect(result.sourceStabilized).toBe(true);
|
|
1515
|
-
});
|
|
1516
|
-
});
|
|
1517
|
-
|
|
1518
|
-
// ---------------------------------------------------------------------------
|
|
1519
|
-
// Link with navigation
|
|
1520
|
-
// ---------------------------------------------------------------------------
|
|
1521
|
-
describe('Link atom', () => {
|
|
1522
|
-
const source = `
|
|
1523
|
-
/**
|
|
1524
|
-
* @workflow slug="link-demo" version="1.0.0" category="workflow"
|
|
1525
|
-
*/
|
|
1526
|
-
import { useState } from 'react';
|
|
1527
|
-
import { Stack, Link, Text } from '@mindmatrix/react';
|
|
1528
|
-
|
|
1529
|
-
export default function LinkDemo() {
|
|
1530
|
-
const [page, setPage] = useState('home');
|
|
1531
|
-
|
|
1532
|
-
return (
|
|
1533
|
-
<Stack sx={{ gap: 8 }}>
|
|
1534
|
-
<Link to="/about" label="About" />
|
|
1535
|
-
<Link to="/settings" label="Settings" />
|
|
1536
|
-
<Text>Current: {page}</Text>
|
|
1537
|
-
</Stack>
|
|
1538
|
-
);
|
|
1539
|
-
}
|
|
1540
|
-
`;
|
|
1541
|
-
|
|
1542
|
-
it('should compile and stabilize', () => {
|
|
1543
|
-
const result = singleFileRoundTrip(source, 'link.workflow.tsx');
|
|
1544
|
-
expect(result.compileSuccess).toBe(true);
|
|
1545
|
-
if (!result.sourceStabilized) {
|
|
1546
|
-
console.log('Link diff:\n' + result.sourceDiff);
|
|
1547
|
-
}
|
|
1548
|
-
expect(result.sourceStabilized).toBe(true);
|
|
1549
|
-
});
|
|
1550
|
-
});
|
|
1551
|
-
|
|
1552
|
-
// ---------------------------------------------------------------------------
|
|
1553
|
-
// Nested conditionals: Show inside Show
|
|
1554
|
-
// ---------------------------------------------------------------------------
|
|
1555
|
-
describe('nested Show conditionals', () => {
|
|
1556
|
-
const source = `
|
|
1557
|
-
/**
|
|
1558
|
-
* @workflow slug="nested-cond" version="1.0.0" category="workflow"
|
|
1559
|
-
*/
|
|
1560
|
-
import { useState } from 'react';
|
|
1561
|
-
import { Stack, Text, Show, Button } from '@mindmatrix/react';
|
|
1562
|
-
|
|
1563
|
-
export default function NestedCond() {
|
|
1564
|
-
const [loggedIn, setLoggedIn] = useState(false);
|
|
1565
|
-
const [isAdmin, setIsAdmin] = useState(false);
|
|
1566
|
-
|
|
1567
|
-
return (
|
|
1568
|
-
<Stack>
|
|
1569
|
-
<Show when={loggedIn}>
|
|
1570
|
-
<Text>Welcome!</Text>
|
|
1571
|
-
<Show when={isAdmin}>
|
|
1572
|
-
<Text>Admin Panel</Text>
|
|
1573
|
-
</Show>
|
|
1574
|
-
</Show>
|
|
1575
|
-
<Show when={!loggedIn}>
|
|
1576
|
-
<Text>Please log in</Text>
|
|
1577
|
-
</Show>
|
|
1578
|
-
<Button label="Toggle" onClick={() => setLoggedIn(!loggedIn)} />
|
|
1579
|
-
</Stack>
|
|
1580
|
-
);
|
|
1581
|
-
}
|
|
1582
|
-
`;
|
|
1583
|
-
|
|
1584
|
-
it('should compile and stabilize', () => {
|
|
1585
|
-
const result = singleFileRoundTrip(source, 'nested.workflow.tsx');
|
|
1586
|
-
expect(result.compileSuccess).toBe(true);
|
|
1587
|
-
if (!result.sourceStabilized) {
|
|
1588
|
-
console.log('Nested cond diff:\n' + result.sourceDiff);
|
|
1589
|
-
}
|
|
1590
|
-
expect(result.sourceStabilized).toBe(true);
|
|
1591
|
-
});
|
|
1592
|
-
});
|
|
1593
|
-
|
|
1594
|
-
// ---------------------------------------------------------------------------
|
|
1595
|
-
// useQuery data hook
|
|
1596
|
-
// ---------------------------------------------------------------------------
|
|
1597
|
-
describe('useQuery data hook', () => {
|
|
1598
|
-
const source = `
|
|
1599
|
-
/**
|
|
1600
|
-
* @workflow slug="query-demo" version="1.0.0" category="workflow"
|
|
1601
|
-
*/
|
|
1602
|
-
import { useState } from 'react';
|
|
1603
|
-
import { useQuery, Stack, Text } from '@mindmatrix/react';
|
|
1604
|
-
|
|
1605
|
-
export default function QueryDemo() {
|
|
1606
|
-
const [search, setSearch] = useState('');
|
|
1607
|
-
const { data: items } = useQuery('items');
|
|
1608
|
-
|
|
1609
|
-
return (
|
|
1610
|
-
<Stack>
|
|
1611
|
-
<Text>Search: {search}</Text>
|
|
1612
|
-
<Text>Results: {items}</Text>
|
|
1613
|
-
</Stack>
|
|
1614
|
-
);
|
|
1615
|
-
}
|
|
1616
|
-
`;
|
|
1617
|
-
|
|
1618
|
-
it('should compile and stabilize', () => {
|
|
1619
|
-
const result = singleFileRoundTrip(source, 'query.workflow.tsx');
|
|
1620
|
-
expect(result.compileSuccess).toBe(true);
|
|
1621
|
-
if (!result.sourceStabilized) {
|
|
1622
|
-
console.log('Query diff:\n' + result.sourceDiff);
|
|
1623
|
-
}
|
|
1624
|
-
expect(result.sourceStabilized).toBe(true);
|
|
1625
|
-
});
|
|
1626
|
-
});
|
|
1627
|
-
|
|
1628
|
-
// ---------------------------------------------------------------------------
|
|
1629
|
-
// DataGrid atom
|
|
1630
|
-
// ---------------------------------------------------------------------------
|
|
1631
|
-
describe('DataGrid atom', () => {
|
|
1632
|
-
const source = `
|
|
1633
|
-
/**
|
|
1634
|
-
* @workflow slug="grid-demo" version="1.0.0" category="workflow"
|
|
1635
|
-
*/
|
|
1636
|
-
import { useState } from 'react';
|
|
1637
|
-
import { Stack, DataGrid, Text } from '@mindmatrix/react';
|
|
1638
|
-
|
|
1639
|
-
export default function GridDemo() {
|
|
1640
|
-
const [page, setPage] = useState(1);
|
|
1641
|
-
|
|
1642
|
-
return (
|
|
1643
|
-
<Stack>
|
|
1644
|
-
<Text>Page: {page}</Text>
|
|
1645
|
-
<DataGrid source="orders" columns={["id", "name", "status"]} pageSize={10} />
|
|
1646
|
-
</Stack>
|
|
1647
|
-
);
|
|
1648
|
-
}
|
|
1649
|
-
`;
|
|
1650
|
-
|
|
1651
|
-
it('should compile and stabilize', () => {
|
|
1652
|
-
const result = singleFileRoundTrip(source, 'datagrid.workflow.tsx');
|
|
1653
|
-
expect(result.compileSuccess).toBe(true);
|
|
1654
|
-
if (!result.sourceStabilized) {
|
|
1655
|
-
console.log('DataGrid diff:\n' + result.sourceDiff);
|
|
1656
|
-
}
|
|
1657
|
-
expect(result.sourceStabilized).toBe(true);
|
|
1658
|
-
});
|
|
1659
|
-
});
|
|
1660
|
-
|
|
1661
|
-
// ---------------------------------------------------------------------------
|
|
1662
|
-
// Multiple field types: boolean, number, select
|
|
1663
|
-
// ---------------------------------------------------------------------------
|
|
1664
|
-
describe('diverse field types', () => {
|
|
1665
|
-
const source = `
|
|
1666
|
-
/**
|
|
1667
|
-
* @workflow slug="field-types" version="1.0.0" category="workflow"
|
|
1668
|
-
*/
|
|
1669
|
-
import { useState } from 'react';
|
|
1670
|
-
import { Stack, Text } from '@mindmatrix/react';
|
|
1671
|
-
|
|
1672
|
-
export default function FieldTypes() {
|
|
1673
|
-
const [name, setName] = useState('');
|
|
1674
|
-
const [age, setAge] = useState(0);
|
|
1675
|
-
const [active, setActive] = useState(true);
|
|
1676
|
-
const [tags, setTags] = useState<string[]>([]);
|
|
1677
|
-
|
|
1678
|
-
return (
|
|
1679
|
-
<Stack>
|
|
1680
|
-
<Text>Name: {name}</Text>
|
|
1681
|
-
<Text>Age: {age}</Text>
|
|
1682
|
-
<Text>Active: {active}</Text>
|
|
1683
|
-
</Stack>
|
|
1684
|
-
);
|
|
1685
|
-
}
|
|
1686
|
-
`;
|
|
1687
|
-
|
|
1688
|
-
it('should preserve all field types', () => {
|
|
1689
|
-
const result = singleFileRoundTrip(source, 'types.workflow.tsx');
|
|
1690
|
-
expect(result.compileSuccess).toBe(true);
|
|
1691
|
-
expect(result.ir1).not.toBeNull();
|
|
1692
|
-
|
|
1693
|
-
// Verify field types are preserved
|
|
1694
|
-
const fieldNames = result.ir1!.fields.map(f => f.name);
|
|
1695
|
-
expect(fieldNames).toContain('name');
|
|
1696
|
-
expect(fieldNames).toContain('age');
|
|
1697
|
-
expect(fieldNames).toContain('active');
|
|
1698
|
-
expect(fieldNames).toContain('tags');
|
|
1699
|
-
|
|
1700
|
-
const nameField = result.ir1!.fields.find(f => f.name === 'name');
|
|
1701
|
-
const ageField = result.ir1!.fields.find(f => f.name === 'age');
|
|
1702
|
-
const activeField = result.ir1!.fields.find(f => f.name === 'active');
|
|
1703
|
-
const tagsField = result.ir1!.fields.find(f => f.name === 'tags');
|
|
1704
|
-
expect(nameField!.type).toBe('text');
|
|
1705
|
-
expect(ageField!.type).toBe('number');
|
|
1706
|
-
expect(activeField!.type).toBe('boolean');
|
|
1707
|
-
expect(tagsField!.type).toBe('multi_select');
|
|
1708
|
-
});
|
|
1709
|
-
|
|
1710
|
-
it('should stabilize source on second pass', () => {
|
|
1711
|
-
const result = singleFileRoundTrip(source, 'types.workflow.tsx');
|
|
1712
|
-
if (!result.sourceStabilized) {
|
|
1713
|
-
console.log('Field types diff:\n' + result.sourceDiff);
|
|
1714
|
-
}
|
|
1715
|
-
expect(result.sourceStabilized).toBe(true);
|
|
1716
|
-
});
|
|
1717
|
-
});
|
|
1718
|
-
|
|
1719
|
-
// ---------------------------------------------------------------------------
|
|
1720
|
-
// Nullable field types: useState<T | null>
|
|
1721
|
-
// ---------------------------------------------------------------------------
|
|
1722
|
-
describe('nullable field types', () => {
|
|
1723
|
-
const source = `
|
|
1724
|
-
/**
|
|
1725
|
-
* @workflow slug="nullable-fields" version="1.0.0" category="workflow"
|
|
1726
|
-
*/
|
|
1727
|
-
import { useState } from 'react';
|
|
1728
|
-
import { Stack, Text } from '@mindmatrix/react';
|
|
1729
|
-
|
|
1730
|
-
export default function NullableFields() {
|
|
1731
|
-
const [name, setName] = useState<string | null>(null);
|
|
1732
|
-
const [count, setCount] = useState<number | null>(null);
|
|
1733
|
-
const [data, setData] = useState<{ key: string } | null>(null);
|
|
1734
|
-
|
|
1735
|
-
return (
|
|
1736
|
-
<Stack>
|
|
1737
|
-
<Text>Name: {name}</Text>
|
|
1738
|
-
<Text>Count: {count}</Text>
|
|
1739
|
-
</Stack>
|
|
1740
|
-
);
|
|
1741
|
-
}
|
|
1742
|
-
`;
|
|
1743
|
-
|
|
1744
|
-
it('should preserve nullable field types', () => {
|
|
1745
|
-
const result = singleFileRoundTrip(source, 'nullable.workflow.tsx');
|
|
1746
|
-
expect(result.compileSuccess).toBe(true);
|
|
1747
|
-
expect(result.ir1).not.toBeNull();
|
|
1748
|
-
|
|
1749
|
-
const nameField = result.ir1!.fields.find(f => f.name === 'name');
|
|
1750
|
-
const countField = result.ir1!.fields.find(f => f.name === 'count');
|
|
1751
|
-
const dataField = result.ir1!.fields.find(f => f.name === 'data');
|
|
1752
|
-
expect(nameField!.type).toBe('text');
|
|
1753
|
-
expect(countField!.type).toBe('number');
|
|
1754
|
-
expect(dataField!.type).toBe('json');
|
|
1755
|
-
});
|
|
1756
|
-
|
|
1757
|
-
it('should stabilize source on second pass', () => {
|
|
1758
|
-
const result = singleFileRoundTrip(source, 'nullable.workflow.tsx');
|
|
1759
|
-
if (!result.sourceStabilized) {
|
|
1760
|
-
console.log('Nullable diff:\n' + result.sourceDiff);
|
|
1761
|
-
}
|
|
1762
|
-
expect(result.sourceStabilized).toBe(true);
|
|
1763
|
-
});
|
|
1764
|
-
});
|
|
1765
|
-
|
|
1766
|
-
// ---------------------------------------------------------------------------
|
|
1767
|
-
// Enum/select field via union type
|
|
1768
|
-
// ---------------------------------------------------------------------------
|
|
1769
|
-
describe('enum/select field via union type', () => {
|
|
1770
|
-
const source = `
|
|
1771
|
-
/**
|
|
1772
|
-
* @workflow slug="enum-demo" version="1.0.0" category="workflow"
|
|
1773
|
-
*/
|
|
1774
|
-
import { useState } from 'react';
|
|
1775
|
-
import { Stack, Text } from '@mindmatrix/react';
|
|
1776
|
-
|
|
1777
|
-
export default function EnumDemo() {
|
|
1778
|
-
const [status, setStatus] = useState<"active" | "inactive" | "pending">('active');
|
|
1779
|
-
|
|
1780
|
-
return (
|
|
1781
|
-
<Stack>
|
|
1782
|
-
<Text>Status: {status}</Text>
|
|
1783
|
-
</Stack>
|
|
1784
|
-
);
|
|
1785
|
-
}
|
|
1786
|
-
`;
|
|
1787
|
-
|
|
1788
|
-
it('should preserve select field with options', () => {
|
|
1789
|
-
const result = singleFileRoundTrip(source, 'enum.workflow.tsx');
|
|
1790
|
-
expect(result.compileSuccess).toBe(true);
|
|
1791
|
-
expect(result.ir1).not.toBeNull();
|
|
1792
|
-
|
|
1793
|
-
const statusField = result.ir1!.fields.find(f => f.name === 'status');
|
|
1794
|
-
expect(statusField!.type).toBe('select');
|
|
1795
|
-
// Options should be preserved
|
|
1796
|
-
const options = (statusField as any)?.validation?.options;
|
|
1797
|
-
expect(options).toEqual(['active', 'inactive', 'pending']);
|
|
1798
|
-
});
|
|
1799
|
-
|
|
1800
|
-
it('should stabilize source on second pass', () => {
|
|
1801
|
-
const result = singleFileRoundTrip(source, 'enum.workflow.tsx');
|
|
1802
|
-
if (!result.sourceStabilized) {
|
|
1803
|
-
console.log('Enum diff:\n' + result.sourceDiff);
|
|
1804
|
-
}
|
|
1805
|
-
expect(result.sourceStabilized).toBe(true);
|
|
1806
|
-
});
|
|
1807
|
-
});
|
|
1808
|
-
|
|
1809
|
-
// ---------------------------------------------------------------------------
|
|
1810
|
-
// Markdown and ScrollArea atoms
|
|
1811
|
-
// ---------------------------------------------------------------------------
|
|
1812
|
-
describe('Markdown and ScrollArea atoms', () => {
|
|
1813
|
-
const source = `
|
|
1814
|
-
/**
|
|
1815
|
-
* @workflow slug="markdown-demo" version="1.0.0" category="workflow"
|
|
1816
|
-
*/
|
|
1817
|
-
import { useState } from 'react';
|
|
1818
|
-
import { Stack, Markdown, ScrollArea, Text } from '@mindmatrix/react';
|
|
1819
|
-
|
|
1820
|
-
export default function MarkdownDemo() {
|
|
1821
|
-
const [content, setContent] = useState('# Hello');
|
|
1822
|
-
|
|
1823
|
-
return (
|
|
1824
|
-
<Stack>
|
|
1825
|
-
<ScrollArea sx={{ maxHeight: 300 }}>
|
|
1826
|
-
<Markdown content={content} />
|
|
1827
|
-
</ScrollArea>
|
|
1828
|
-
<Text>Characters: {content}</Text>
|
|
1829
|
-
</Stack>
|
|
1830
|
-
);
|
|
1831
|
-
}
|
|
1832
|
-
`;
|
|
1833
|
-
|
|
1834
|
-
it('should compile and stabilize', () => {
|
|
1835
|
-
const result = singleFileRoundTrip(source, 'markdown.workflow.tsx');
|
|
1836
|
-
expect(result.compileSuccess).toBe(true);
|
|
1837
|
-
if (!result.sourceStabilized) {
|
|
1838
|
-
console.log('Markdown diff:\n' + result.sourceDiff);
|
|
1839
|
-
}
|
|
1840
|
-
expect(result.sourceStabilized).toBe(true);
|
|
1841
|
-
});
|
|
1842
|
-
});
|
|
1843
|
-
|
|
1844
|
-
// ---------------------------------------------------------------------------
|
|
1845
|
-
// Multiple transitions with auto-fire
|
|
1846
|
-
// ---------------------------------------------------------------------------
|
|
1847
|
-
describe('auto transitions', () => {
|
|
1848
|
-
const source = `
|
|
1849
|
-
/**
|
|
1850
|
-
* @workflow slug="auto-trans" version="1.0.0" category="workflow"
|
|
1851
|
-
*/
|
|
1852
|
-
import { useState } from 'react';
|
|
1853
|
-
import { useTransition, Stack, Text } from '@mindmatrix/react';
|
|
1854
|
-
|
|
1855
|
-
export default function AutoTrans() {
|
|
1856
|
-
const [phase, setPhase] = useState('init');
|
|
1857
|
-
|
|
1858
|
-
useTransition('start', { from: 'init', to: 'processing', auto: true });
|
|
1859
|
-
useTransition('finish', { from: 'processing', to: 'done' });
|
|
1860
|
-
|
|
1861
|
-
return (
|
|
1862
|
-
<Stack>
|
|
1863
|
-
<Text>Phase: {phase}</Text>
|
|
1864
|
-
</Stack>
|
|
1865
|
-
);
|
|
1866
|
-
}
|
|
1867
|
-
`;
|
|
1868
|
-
|
|
1869
|
-
it('should preserve auto flag on transitions', () => {
|
|
1870
|
-
const result = singleFileRoundTrip(source, 'auto.workflow.tsx');
|
|
1871
|
-
expect(result.compileSuccess).toBe(true);
|
|
1872
|
-
expect(result.ir1).not.toBeNull();
|
|
1873
|
-
|
|
1874
|
-
const startTrans = result.ir1!.transitions.find(t => t.name === 'start');
|
|
1875
|
-
expect(startTrans).toBeDefined();
|
|
1876
|
-
expect(startTrans!.auto).toBe(true);
|
|
1877
|
-
});
|
|
1878
|
-
|
|
1879
|
-
it('should stabilize source on second pass', () => {
|
|
1880
|
-
const result = singleFileRoundTrip(source, 'auto.workflow.tsx');
|
|
1881
|
-
if (!result.sourceStabilized) {
|
|
1882
|
-
console.log('Auto diff:\n' + result.sourceDiff);
|
|
1883
|
-
}
|
|
1884
|
-
expect(result.sourceStabilized).toBe(true);
|
|
1885
|
-
});
|
|
1886
|
-
});
|
|
1887
|
-
|
|
1888
|
-
// ---------------------------------------------------------------------------
|
|
1889
|
-
// useWhileIn (during state)
|
|
1890
|
-
// ---------------------------------------------------------------------------
|
|
1891
|
-
describe('useWhileIn state effect', () => {
|
|
1892
|
-
const source = `
|
|
1893
|
-
/**
|
|
1894
|
-
* @workflow slug="while-in" version="1.0.0" category="workflow"
|
|
1895
|
-
*/
|
|
1896
|
-
import { useState } from 'react';
|
|
1897
|
-
import { useWhileIn, useTransition, Stack, Text } from '@mindmatrix/react';
|
|
1898
|
-
|
|
1899
|
-
export default function WhileIn() {
|
|
1900
|
-
const [count, setCount] = useState(0);
|
|
1901
|
-
|
|
1902
|
-
useWhileIn('active', () => {
|
|
1903
|
-
setCount(count + 1);
|
|
1904
|
-
});
|
|
1905
|
-
|
|
1906
|
-
useTransition('activate', { from: 'idle', to: 'active' });
|
|
1907
|
-
|
|
1908
|
-
return (
|
|
1909
|
-
<Stack>
|
|
1910
|
-
<Text>Count: {count}</Text>
|
|
1911
|
-
</Stack>
|
|
1912
|
-
);
|
|
1913
|
-
}
|
|
1914
|
-
`;
|
|
1915
|
-
|
|
1916
|
-
it('should compile and stabilize', () => {
|
|
1917
|
-
const result = singleFileRoundTrip(source, 'whilein.workflow.tsx');
|
|
1918
|
-
expect(result.compileSuccess).toBe(true);
|
|
1919
|
-
if (!result.sourceStabilized) {
|
|
1920
|
-
console.log('WhileIn diff:\n' + result.sourceDiff);
|
|
1921
|
-
}
|
|
1922
|
-
expect(result.sourceStabilized).toBe(true);
|
|
1923
|
-
});
|
|
1924
|
-
});
|
|
1925
|
-
|
|
1926
|
-
// ---------------------------------------------------------------------------
|
|
1927
|
-
// defineModel format (model file round-trip)
|
|
1928
|
-
// ---------------------------------------------------------------------------
|
|
1929
|
-
describe('defineModel format', () => {
|
|
1930
|
-
it('should round-trip a defineModel file', () => {
|
|
1931
|
-
const modelSource = `
|
|
1932
|
-
import { defineModel } from "@mindmatrix/react";
|
|
1933
|
-
|
|
1934
|
-
export interface OrderFields {
|
|
1935
|
-
amount: number;
|
|
1936
|
-
customer: string;
|
|
1937
|
-
status?: string;
|
|
1938
|
-
}
|
|
1939
|
-
|
|
1940
|
-
export default defineModel({
|
|
1941
|
-
slug: 'order',
|
|
1942
|
-
version: '1.0.0',
|
|
1943
|
-
category: 'data',
|
|
1944
|
-
fields: {
|
|
1945
|
-
amount: { type: 'number', required: true },
|
|
1946
|
-
customer: { type: 'string', required: true },
|
|
1947
|
-
status: { type: 'string' },
|
|
1948
|
-
},
|
|
1949
|
-
states: {
|
|
1950
|
-
draft: { type: 'initial' },
|
|
1951
|
-
submitted: {},
|
|
1952
|
-
approved: {},
|
|
1953
|
-
},
|
|
1954
|
-
transitions: {
|
|
1955
|
-
submit: { from: 'draft', to: 'submitted' },
|
|
1956
|
-
approve: { from: 'submitted', to: 'approved' },
|
|
1957
|
-
},
|
|
1958
|
-
});
|
|
1959
|
-
`;
|
|
1960
|
-
|
|
1961
|
-
const files = { 'models/order.ts': modelSource };
|
|
1962
|
-
const r1 = compileProject(files);
|
|
1963
|
-
expect(r1.errors.filter(e => e.severity === 'error')).toHaveLength(0);
|
|
1964
|
-
|
|
1965
|
-
// Verify fields were extracted
|
|
1966
|
-
expect(r1.ir.fields.length).toBeGreaterThanOrEqual(3);
|
|
1967
|
-
const amountField = r1.ir.fields.find(f => f.name === 'amount');
|
|
1968
|
-
expect(amountField).toBeDefined();
|
|
1969
|
-
expect(amountField!.required).toBe(true);
|
|
1970
|
-
|
|
1971
|
-
// Verify states were extracted
|
|
1972
|
-
expect(r1.ir.states.length).toBeGreaterThanOrEqual(3);
|
|
1973
|
-
const draftState = r1.ir.states.find(s => s.name === 'draft');
|
|
1974
|
-
expect(draftState).toBeDefined();
|
|
1975
|
-
expect(draftState!.type).toBe('START');
|
|
1976
|
-
|
|
1977
|
-
// Verify transitions
|
|
1978
|
-
expect(r1.ir.transitions.length).toBeGreaterThanOrEqual(2);
|
|
1979
|
-
});
|
|
1980
|
-
});
|
|
1981
|
-
|
|
1982
|
-
// ---------------------------------------------------------------------------
|
|
1983
|
-
// Slot atom (composition point)
|
|
1984
|
-
// ---------------------------------------------------------------------------
|
|
1985
|
-
describe('Slot atom', () => {
|
|
1986
|
-
const source = `
|
|
1987
|
-
/**
|
|
1988
|
-
* @workflow slug="slot-demo" version="1.0.0" category="workflow"
|
|
1989
|
-
*/
|
|
1990
|
-
import { useState } from 'react';
|
|
1991
|
-
import { Stack, Slot, Text } from '@mindmatrix/react';
|
|
1992
|
-
|
|
1993
|
-
export default function SlotDemo() {
|
|
1994
|
-
const [label, setLabel] = useState('content');
|
|
1995
|
-
|
|
1996
|
-
return (
|
|
1997
|
-
<Stack>
|
|
1998
|
-
<Text>Header</Text>
|
|
1999
|
-
<Slot name="main" />
|
|
2000
|
-
<Text>Footer</Text>
|
|
2001
|
-
</Stack>
|
|
2002
|
-
);
|
|
2003
|
-
}
|
|
2004
|
-
`;
|
|
2005
|
-
|
|
2006
|
-
it('should compile and stabilize', () => {
|
|
2007
|
-
const result = singleFileRoundTrip(source, 'slot.workflow.tsx');
|
|
2008
|
-
expect(result.compileSuccess).toBe(true);
|
|
2009
|
-
if (!result.sourceStabilized) {
|
|
2010
|
-
console.log('Slot diff:\n' + result.sourceDiff);
|
|
2011
|
-
}
|
|
2012
|
-
expect(result.sourceStabilized).toBe(true);
|
|
2013
|
-
});
|
|
2014
|
-
});
|
|
2015
|
-
});
|
|
2016
|
-
|
|
2017
|
-
// =============================================================================
|
|
2018
|
-
// Existing example round-trip tests
|
|
2019
|
-
// =============================================================================
|
|
2020
|
-
|
|
2021
|
-
describe('round-trip: existing examples', () => {
|
|
2022
|
-
const EXAMPLES_DIR = path.resolve(__dirname, '../../../examples');
|
|
2023
|
-
|
|
2024
|
-
it('should round-trip counter.workflow.tsx', () => {
|
|
2025
|
-
const source = fs.readFileSync(path.join(EXAMPLES_DIR, 'counter.workflow.tsx'), 'utf-8');
|
|
2026
|
-
const result = singleFileRoundTrip(source, 'counter.workflow.tsx');
|
|
2027
|
-
expect(result.compileSuccess).toBe(true);
|
|
2028
|
-
expect(result.ir1).not.toBeNull();
|
|
2029
|
-
expect(result.ir2).not.toBeNull();
|
|
2030
|
-
|
|
2031
|
-
const errors = result.irDiffs.filter(d => d.severity === 'error');
|
|
2032
|
-
if (errors.length > 0) {
|
|
2033
|
-
console.log('Counter IR errors:', JSON.stringify(errors, null, 2));
|
|
2034
|
-
}
|
|
2035
|
-
// IR should be semantically equivalent
|
|
2036
|
-
expect(errors).toEqual([]);
|
|
2037
|
-
|
|
2038
|
-
// Source should stabilize
|
|
2039
|
-
if (!result.sourceStabilized) {
|
|
2040
|
-
console.log('Counter source diff:\n' + result.sourceDiff);
|
|
2041
|
-
}
|
|
2042
|
-
expect(result.sourceStabilized).toBe(true);
|
|
2043
|
-
});
|
|
2044
|
-
|
|
2045
|
-
it('should round-trip todo-app.workflow.tsx', () => {
|
|
2046
|
-
const source = fs.readFileSync(path.join(EXAMPLES_DIR, 'todo-app.workflow.tsx'), 'utf-8');
|
|
2047
|
-
const result = singleFileRoundTrip(source, 'todo-app.workflow.tsx');
|
|
2048
|
-
expect(result.compileSuccess).toBe(true);
|
|
2049
|
-
|
|
2050
|
-
const errors = result.irDiffs.filter(d => d.severity === 'error');
|
|
2051
|
-
if (errors.length > 0) {
|
|
2052
|
-
console.log('Todo IR errors:', JSON.stringify(errors, null, 2));
|
|
2053
|
-
}
|
|
2054
|
-
|
|
2055
|
-
if (!result.sourceStabilized) {
|
|
2056
|
-
console.log('Todo source diff:\n' + result.sourceDiff);
|
|
2057
|
-
}
|
|
2058
|
-
expect(result.sourceStabilized).toBe(true);
|
|
2059
|
-
});
|
|
2060
|
-
|
|
2061
|
-
it('should round-trip dashboard.workflow.tsx', () => {
|
|
2062
|
-
const source = fs.readFileSync(path.join(EXAMPLES_DIR, 'dashboard.workflow.tsx'), 'utf-8');
|
|
2063
|
-
const result = singleFileRoundTrip(source, 'dashboard.workflow.tsx');
|
|
2064
|
-
expect(result.compileSuccess).toBe(true);
|
|
2065
|
-
|
|
2066
|
-
const errors = result.irDiffs.filter(d => d.severity === 'error');
|
|
2067
|
-
if (errors.length > 0) {
|
|
2068
|
-
console.log('Dashboard IR errors:', JSON.stringify(errors, null, 2));
|
|
2069
|
-
}
|
|
2070
|
-
|
|
2071
|
-
if (!result.sourceStabilized) {
|
|
2072
|
-
console.log('Dashboard source diff:\n' + result.sourceDiff);
|
|
2073
|
-
}
|
|
2074
|
-
expect(result.sourceStabilized).toBe(true);
|
|
2075
|
-
});
|
|
2076
|
-
|
|
2077
|
-
it('should round-trip authentication multi-file project', () => {
|
|
2078
|
-
const fixtureDir = path.join(EXAMPLES_DIR, 'authentication');
|
|
2079
|
-
if (!fs.existsSync(fixtureDir)) {
|
|
2080
|
-
console.log('Skipping: authentication example not found');
|
|
2081
|
-
return;
|
|
2082
|
-
}
|
|
2083
|
-
|
|
2084
|
-
const files = readProjectFiles(fixtureDir);
|
|
2085
|
-
const compile1 = compileProject(files);
|
|
2086
|
-
expect(compile1.errors.filter(e => e.severity === 'error')).toHaveLength(0);
|
|
2087
|
-
|
|
2088
|
-
// Decompile
|
|
2089
|
-
const decompInput: DecompilerInput = {
|
|
2090
|
-
...compile1.ir,
|
|
2091
|
-
childDefinitions: compile1.childDefinitions,
|
|
2092
|
-
experience: compile1.ir.experience as any,
|
|
2093
|
-
};
|
|
2094
|
-
const decomp1 = decompileProjectEnhanced(decompInput);
|
|
2095
|
-
expect(decomp1.files.length).toBeGreaterThan(0);
|
|
2096
|
-
|
|
2097
|
-
// Re-compile
|
|
2098
|
-
const recompileFiles: Record<string, string> = {};
|
|
2099
|
-
for (const file of decomp1.files) {
|
|
2100
|
-
recompileFiles[file.path] = file.content;
|
|
2101
|
-
}
|
|
2102
|
-
const compile2 = compileProject(recompileFiles);
|
|
2103
|
-
|
|
2104
|
-
// Compare IR
|
|
2105
|
-
const diffs = compareIRSemantic(compile1.ir, compile2.ir);
|
|
2106
|
-
const errors = diffs.filter(d => d.severity === 'error');
|
|
2107
|
-
if (errors.length > 0) {
|
|
2108
|
-
console.log('Auth IR errors:', JSON.stringify(errors, null, 2));
|
|
2109
|
-
}
|
|
2110
|
-
|
|
2111
|
-
// Re-decompile
|
|
2112
|
-
const decompInput2: DecompilerInput = {
|
|
2113
|
-
...compile2.ir,
|
|
2114
|
-
childDefinitions: compile2.childDefinitions,
|
|
2115
|
-
experience: compile2.ir.experience as any,
|
|
2116
|
-
};
|
|
2117
|
-
const decomp2 = decompileProjectEnhanced(decompInput2);
|
|
2118
|
-
|
|
2119
|
-
// Check stabilization
|
|
2120
|
-
const files1: Record<string, string> = {};
|
|
2121
|
-
for (const f of decomp1.files) files1[f.path] = f.content;
|
|
2122
|
-
const files2: Record<string, string> = {};
|
|
2123
|
-
for (const f of decomp2.files) files2[f.path] = f.content;
|
|
2124
|
-
|
|
2125
|
-
const sourceDiffs = compareSourceFiles(files1, files2);
|
|
2126
|
-
if (sourceDiffs.length > 0) {
|
|
2127
|
-
console.log('Auth source diffs:');
|
|
2128
|
-
for (const d of sourceDiffs) {
|
|
2129
|
-
console.log(` ${d.file}: ${d.type}`);
|
|
2130
|
-
if (d.details) console.log(d.details);
|
|
2131
|
-
}
|
|
2132
|
-
}
|
|
2133
|
-
expect(sourceDiffs).toEqual([]);
|
|
2134
|
-
});
|
|
2135
|
-
});
|
|
2136
|
-
|
|
2137
|
-
// =============================================================================
|
|
2138
|
-
// Comprehensive diagnostics test (always runs, reports everything)
|
|
2139
|
-
// =============================================================================
|
|
2140
|
-
|
|
2141
|
-
describe('round-trip: diagnostic summary', () => {
|
|
2142
|
-
it('should produce a full diagnostic report for all fixtures', () => {
|
|
2143
|
-
const fixtures = ['simple-crud', 'full-workflow', 'data-heavy', 'view-heavy'];
|
|
2144
|
-
const reports: RoundTripReport[] = [];
|
|
2145
|
-
|
|
2146
|
-
for (const fixture of fixtures) {
|
|
2147
|
-
const report = performRoundTrip(fixture);
|
|
2148
|
-
reports.push(report);
|
|
2149
|
-
}
|
|
2150
|
-
|
|
2151
|
-
// Print summary
|
|
2152
|
-
console.log('\n============================================');
|
|
2153
|
-
console.log(' ROUND-TRIP DIAGNOSTIC SUMMARY');
|
|
2154
|
-
console.log('============================================\n');
|
|
2155
|
-
|
|
2156
|
-
for (const report of reports) {
|
|
2157
|
-
const irErrors = report.irDiffs.filter(d => d.severity === 'error').length;
|
|
2158
|
-
const irWarnings = report.irDiffs.filter(d => d.severity === 'warning').length;
|
|
2159
|
-
|
|
2160
|
-
console.log(`${report.fixtureName}:`);
|
|
2161
|
-
console.log(` Compile: ${report.compileSuccess ? 'PASS' : 'FAIL'}`);
|
|
2162
|
-
console.log(` Decompile: ${report.decompileSuccess ? 'PASS' : 'FAIL'}`);
|
|
2163
|
-
console.log(` Re-compile: ${report.recompileSuccess ? 'PASS' : 'FAIL'}`);
|
|
2164
|
-
console.log(` IR match: ${report.irMatch ? 'PASS' : `FAIL (${irErrors} errors, ${irWarnings} warnings)`}`);
|
|
2165
|
-
console.log(` Source stable: ${report.sourceStabilized ? 'PASS' : `FAIL (${report.sourceDiffs.length} diffs)`}`);
|
|
2166
|
-
console.log(` Output files: ${Object.keys(report.outputFiles1).join(', ')}`);
|
|
2167
|
-
|
|
2168
|
-
if (!report.irMatch) {
|
|
2169
|
-
for (const diff of report.irDiffs.filter(d => d.severity === 'error')) {
|
|
2170
|
-
console.log(` IR ERROR: ${diff.path} — expected: ${JSON.stringify(diff.expected)}, got: ${JSON.stringify(diff.actual)}`);
|
|
2171
|
-
}
|
|
2172
|
-
}
|
|
2173
|
-
|
|
2174
|
-
if (!report.sourceStabilized) {
|
|
2175
|
-
for (const diff of report.sourceDiffs) {
|
|
2176
|
-
console.log(` SOURCE: ${diff.file} — ${diff.type}`);
|
|
2177
|
-
if (diff.details) {
|
|
2178
|
-
for (const line of diff.details.split('\n').slice(0, 5)) {
|
|
2179
|
-
console.log(` ${line}`);
|
|
2180
|
-
}
|
|
2181
|
-
}
|
|
2182
|
-
}
|
|
2183
|
-
}
|
|
2184
|
-
|
|
2185
|
-
console.log('');
|
|
2186
|
-
}
|
|
2187
|
-
|
|
2188
|
-
// At minimum, all fixtures should compile
|
|
2189
|
-
for (const report of reports) {
|
|
2190
|
-
expect(report.compileSuccess).toBe(true);
|
|
2191
|
-
}
|
|
2192
|
-
});
|
|
2193
|
-
});
|
|
2194
|
-
|
|
2195
|
-
// =============================================================================
|
|
2196
|
-
// Real Blueprint Round-Trip Tests
|
|
2197
|
-
// =============================================================================
|
|
2198
|
-
|
|
2199
|
-
const BLUEPRINTS_DIR = path.resolve(__dirname, '../../../../');
|
|
2200
|
-
|
|
2201
|
-
/** Read project files from a real blueprint package. */
|
|
2202
|
-
function readBlueprintFiles(blueprintName: string): Record<string, string> {
|
|
2203
|
-
const rootDir = path.join(BLUEPRINTS_DIR, blueprintName);
|
|
2204
|
-
const files: Record<string, string> = {};
|
|
2205
|
-
|
|
2206
|
-
function walk(dir: string, prefix: string) {
|
|
2207
|
-
if (!fs.existsSync(dir)) return;
|
|
2208
|
-
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
2209
|
-
for (const entry of entries) {
|
|
2210
|
-
const relPath = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
2211
|
-
const fullPath = path.join(dir, entry.name);
|
|
2212
|
-
if (entry.isDirectory()) {
|
|
2213
|
-
if (['node_modules', 'tests', 'dist', '.git'].includes(entry.name)) continue;
|
|
2214
|
-
walk(fullPath, relPath);
|
|
2215
|
-
} else if (entry.isFile()) {
|
|
2216
|
-
if (entry.name.endsWith('.tsx') || entry.name.endsWith('.ts')) {
|
|
2217
|
-
if (entry.name.endsWith('.test.tsx') || entry.name.endsWith('.test.ts')) continue;
|
|
2218
|
-
if (entry.name === 'tsconfig.json') continue;
|
|
2219
|
-
files[relPath] = fs.readFileSync(fullPath, 'utf-8');
|
|
2220
|
-
}
|
|
2221
|
-
}
|
|
2222
|
-
}
|
|
2223
|
-
}
|
|
2224
|
-
|
|
2225
|
-
walk(rootDir, '');
|
|
2226
|
-
return files;
|
|
2227
|
-
}
|
|
2228
|
-
|
|
2229
|
-
/**
|
|
2230
|
-
* Performs a full bidirectional round-trip for a real blueprint package.
|
|
2231
|
-
* Same 7-step pipeline as performRoundTrip but reads from packages/ instead of fixtures/.
|
|
2232
|
-
*/
|
|
2233
|
-
function performBlueprintRoundTrip(blueprintName: string): RoundTripReport {
|
|
2234
|
-
const report: RoundTripReport = {
|
|
2235
|
-
fixtureName: blueprintName,
|
|
2236
|
-
compileSuccess: false,
|
|
2237
|
-
compileErrors: [],
|
|
2238
|
-
ir1: null,
|
|
2239
|
-
childDefs1: [],
|
|
2240
|
-
decompileSuccess: false,
|
|
2241
|
-
outputFiles1: {},
|
|
2242
|
-
recompileSuccess: false,
|
|
2243
|
-
recompileErrors: [],
|
|
2244
|
-
ir2: null,
|
|
2245
|
-
irDiffs: [],
|
|
2246
|
-
irMatch: false,
|
|
2247
|
-
outputFiles2: {},
|
|
2248
|
-
sourceStabilized: false,
|
|
2249
|
-
sourceDiffs: [],
|
|
2250
|
-
};
|
|
2251
|
-
|
|
2252
|
-
// Step 1: Read blueprint source files
|
|
2253
|
-
const sourceFiles = readBlueprintFiles(blueprintName);
|
|
2254
|
-
if (Object.keys(sourceFiles).length === 0) {
|
|
2255
|
-
report.compileErrors.push('No source files found');
|
|
2256
|
-
return report;
|
|
2257
|
-
}
|
|
2258
|
-
|
|
2259
|
-
// Step 2: Compile (pass 1)
|
|
2260
|
-
let result1: ReturnType<typeof compileProject>;
|
|
2261
|
-
try {
|
|
2262
|
-
result1 = compileProject(sourceFiles);
|
|
2263
|
-
report.compileSuccess = true;
|
|
2264
|
-
report.compileErrors = result1.errors.map(e => `${e.file}: ${e.message}`);
|
|
2265
|
-
report.ir1 = result1.ir;
|
|
2266
|
-
report.childDefs1 = result1.childDefinitions;
|
|
2267
|
-
} catch (err) {
|
|
2268
|
-
report.compileErrors = [(err as Error).message];
|
|
2269
|
-
return report;
|
|
2270
|
-
}
|
|
2271
|
-
|
|
2272
|
-
// Step 3: Decompile (pass 1)
|
|
2273
|
-
try {
|
|
2274
|
-
const decompInput: DecompilerInput = {
|
|
2275
|
-
...result1.ir,
|
|
2276
|
-
childDefinitions: result1.childDefinitions,
|
|
2277
|
-
experience: result1.ir.experience as any,
|
|
2278
|
-
};
|
|
2279
|
-
const decompResult = decompileProjectEnhanced(decompInput);
|
|
2280
|
-
report.decompileSuccess = true;
|
|
2281
|
-
|
|
2282
|
-
for (const file of decompResult.files) {
|
|
2283
|
-
report.outputFiles1[file.path] = file.content;
|
|
2284
|
-
}
|
|
2285
|
-
} catch (err) {
|
|
2286
|
-
report.compileErrors.push(`Decompile failed: ${(err as Error).message}`);
|
|
2287
|
-
return report;
|
|
2288
|
-
}
|
|
2289
|
-
|
|
2290
|
-
// Step 4: Re-compile (pass 2)
|
|
2291
|
-
let result2: ReturnType<typeof compileProject>;
|
|
2292
|
-
try {
|
|
2293
|
-
result2 = compileProject(report.outputFiles1);
|
|
2294
|
-
report.recompileSuccess = true;
|
|
2295
|
-
report.recompileErrors = result2.errors.map(e => `${e.file}: ${e.message}`);
|
|
2296
|
-
report.ir2 = result2.ir;
|
|
2297
|
-
} catch (err) {
|
|
2298
|
-
report.recompileErrors = [(err as Error).message];
|
|
2299
|
-
return report;
|
|
2300
|
-
}
|
|
2301
|
-
|
|
2302
|
-
// Step 5: Compare IR1 vs IR2
|
|
2303
|
-
report.irDiffs = compareIRSemantic(result1.ir, result2.ir);
|
|
2304
|
-
report.irMatch = report.irDiffs.filter(d => d.severity === 'error').length === 0;
|
|
2305
|
-
|
|
2306
|
-
// Step 6: Re-decompile (pass 2)
|
|
2307
|
-
try {
|
|
2308
|
-
const decompInput2: DecompilerInput = {
|
|
2309
|
-
...result2.ir,
|
|
2310
|
-
childDefinitions: result2.childDefinitions,
|
|
2311
|
-
experience: result2.ir.experience as any,
|
|
2312
|
-
};
|
|
2313
|
-
const decompResult2 = decompileProjectEnhanced(decompInput2);
|
|
2314
|
-
|
|
2315
|
-
for (const file of decompResult2.files) {
|
|
2316
|
-
report.outputFiles2[file.path] = file.content;
|
|
2317
|
-
}
|
|
2318
|
-
} catch (err) {
|
|
2319
|
-
report.recompileErrors.push(`Re-decompile failed: ${(err as Error).message}`);
|
|
2320
|
-
return report;
|
|
2321
|
-
}
|
|
2322
|
-
|
|
2323
|
-
// Step 7: Compare outputFiles1 vs outputFiles2
|
|
2324
|
-
report.sourceDiffs = compareSourceFiles(report.outputFiles1, report.outputFiles2);
|
|
2325
|
-
report.sourceStabilized = report.sourceDiffs.length === 0;
|
|
2326
|
-
|
|
2327
|
-
return report;
|
|
2328
|
-
}
|
|
2329
|
-
|
|
2330
|
-
// ---------------------------------------------------------------------------
|
|
2331
|
-
// blueprint-auth
|
|
2332
|
-
// ---------------------------------------------------------------------------
|
|
2333
|
-
|
|
2334
|
-
describe('round-trip: blueprint-auth', () => {
|
|
2335
|
-
let report: RoundTripReport;
|
|
2336
|
-
|
|
2337
|
-
beforeAll(() => {
|
|
2338
|
-
report = performBlueprintRoundTrip('blueprint-auth');
|
|
2339
|
-
});
|
|
2340
|
-
|
|
2341
|
-
it('should compile successfully', () => {
|
|
2342
|
-
expect(report.compileSuccess).toBe(true);
|
|
2343
|
-
});
|
|
2344
|
-
|
|
2345
|
-
it('should decompile successfully', () => {
|
|
2346
|
-
expect(report.decompileSuccess).toBe(true);
|
|
2347
|
-
});
|
|
2348
|
-
|
|
2349
|
-
it('should re-compile decompiled output successfully', () => {
|
|
2350
|
-
expect(report.recompileSuccess).toBe(true);
|
|
2351
|
-
if (report.recompileErrors.length > 0) {
|
|
2352
|
-
console.log('Re-compile errors:', report.recompileErrors);
|
|
2353
|
-
}
|
|
2354
|
-
});
|
|
2355
|
-
|
|
2356
|
-
it('should preserve fields through round trip', () => {
|
|
2357
|
-
const fieldDiffs = report.irDiffs.filter(
|
|
2358
|
-
d => d.path.startsWith('fields') && d.severity === 'error',
|
|
2359
|
-
);
|
|
2360
|
-
if (fieldDiffs.length > 0) {
|
|
2361
|
-
console.log('Field diffs:', JSON.stringify(fieldDiffs, null, 2));
|
|
2362
|
-
}
|
|
2363
|
-
expect(fieldDiffs).toEqual([]);
|
|
2364
|
-
});
|
|
2365
|
-
|
|
2366
|
-
it('should preserve transitions through round trip', () => {
|
|
2367
|
-
const transDiffs = report.irDiffs.filter(
|
|
2368
|
-
d => d.path.startsWith('transitions') && d.severity === 'error',
|
|
2369
|
-
);
|
|
2370
|
-
if (transDiffs.length > 0) {
|
|
2371
|
-
console.log('Transition diffs:', JSON.stringify(transDiffs, null, 2));
|
|
2372
|
-
}
|
|
2373
|
-
expect(transDiffs).toEqual([]);
|
|
2374
|
-
});
|
|
2375
|
-
|
|
2376
|
-
it('should preserve states with effects through round trip', () => {
|
|
2377
|
-
const stateDiffs = report.irDiffs.filter(
|
|
2378
|
-
d => d.path.startsWith('states') && d.severity === 'error',
|
|
2379
|
-
);
|
|
2380
|
-
if (stateDiffs.length > 0) {
|
|
2381
|
-
console.log('State diffs:', JSON.stringify(stateDiffs, null, 2));
|
|
2382
|
-
}
|
|
2383
|
-
expect(stateDiffs).toEqual([]);
|
|
2384
|
-
});
|
|
2385
|
-
|
|
2386
|
-
it('should stabilize source on second pass', () => {
|
|
2387
|
-
if (!report.sourceStabilized) {
|
|
2388
|
-
console.log('Source stabilization failures:');
|
|
2389
|
-
for (const diff of report.sourceDiffs) {
|
|
2390
|
-
console.log(` ${diff.file}: ${diff.type}`);
|
|
2391
|
-
if (diff.details) {
|
|
2392
|
-
console.log(diff.details);
|
|
2393
|
-
}
|
|
2394
|
-
}
|
|
2395
|
-
}
|
|
2396
|
-
expect(report.sourceStabilized).toBe(true);
|
|
2397
|
-
});
|
|
2398
|
-
});
|
|
2399
|
-
|
|
2400
|
-
// ---------------------------------------------------------------------------
|
|
2401
|
-
// blueprint-employee-salary-tracking
|
|
2402
|
-
// ---------------------------------------------------------------------------
|
|
2403
|
-
|
|
2404
|
-
describe('round-trip: blueprint-employee-salary-tracking', () => {
|
|
2405
|
-
let report: RoundTripReport;
|
|
2406
|
-
|
|
2407
|
-
beforeAll(() => {
|
|
2408
|
-
report = performBlueprintRoundTrip('blueprint-employee-salary-tracking');
|
|
2409
|
-
});
|
|
2410
|
-
|
|
2411
|
-
it('should compile successfully', () => {
|
|
2412
|
-
expect(report.compileSuccess).toBe(true);
|
|
2413
|
-
});
|
|
2414
|
-
|
|
2415
|
-
it('should decompile successfully', () => {
|
|
2416
|
-
expect(report.decompileSuccess).toBe(true);
|
|
2417
|
-
});
|
|
2418
|
-
|
|
2419
|
-
it('should re-compile decompiled output successfully', () => {
|
|
2420
|
-
expect(report.recompileSuccess).toBe(true);
|
|
2421
|
-
if (report.recompileErrors.length > 0) {
|
|
2422
|
-
console.log('Re-compile errors:', report.recompileErrors);
|
|
2423
|
-
}
|
|
2424
|
-
});
|
|
2425
|
-
|
|
2426
|
-
it('should preserve fields through round trip', () => {
|
|
2427
|
-
const fieldDiffs = report.irDiffs.filter(
|
|
2428
|
-
d => d.path.startsWith('fields') && d.severity === 'error',
|
|
2429
|
-
);
|
|
2430
|
-
if (fieldDiffs.length > 0) {
|
|
2431
|
-
console.log('Field diffs:', JSON.stringify(fieldDiffs, null, 2));
|
|
2432
|
-
}
|
|
2433
|
-
expect(fieldDiffs).toEqual([]);
|
|
2434
|
-
});
|
|
2435
|
-
|
|
2436
|
-
it('should preserve transitions through round trip', () => {
|
|
2437
|
-
const transDiffs = report.irDiffs.filter(
|
|
2438
|
-
d => d.path.startsWith('transitions') && d.severity === 'error',
|
|
2439
|
-
);
|
|
2440
|
-
if (transDiffs.length > 0) {
|
|
2441
|
-
console.log('Transition diffs:', JSON.stringify(transDiffs, null, 2));
|
|
2442
|
-
}
|
|
2443
|
-
expect(transDiffs).toEqual([]);
|
|
2444
|
-
});
|
|
2445
|
-
|
|
2446
|
-
it('should preserve states with effects through round trip', () => {
|
|
2447
|
-
const stateDiffs = report.irDiffs.filter(
|
|
2448
|
-
d => d.path.startsWith('states') && d.severity === 'error',
|
|
2449
|
-
);
|
|
2450
|
-
if (stateDiffs.length > 0) {
|
|
2451
|
-
console.log('State diffs:', JSON.stringify(stateDiffs, null, 2));
|
|
2452
|
-
}
|
|
2453
|
-
expect(stateDiffs).toEqual([]);
|
|
2454
|
-
});
|
|
2455
|
-
|
|
2456
|
-
it('should stabilize source on second pass', () => {
|
|
2457
|
-
if (!report.sourceStabilized) {
|
|
2458
|
-
console.log('Source stabilization failures:');
|
|
2459
|
-
for (const diff of report.sourceDiffs) {
|
|
2460
|
-
console.log(` ${diff.file}: ${diff.type}`);
|
|
2461
|
-
if (diff.details) {
|
|
2462
|
-
console.log(diff.details);
|
|
2463
|
-
}
|
|
2464
|
-
}
|
|
2465
|
-
}
|
|
2466
|
-
expect(report.sourceStabilized).toBe(true);
|
|
2467
|
-
});
|
|
2468
|
-
});
|
|
2469
|
-
|
|
2470
|
-
// ---------------------------------------------------------------------------
|
|
2471
|
-
// blueprint-glass-console
|
|
2472
|
-
// ---------------------------------------------------------------------------
|
|
2473
|
-
|
|
2474
|
-
describe('round-trip: blueprint-glass-console', () => {
|
|
2475
|
-
let report: RoundTripReport;
|
|
2476
|
-
|
|
2477
|
-
beforeAll(() => {
|
|
2478
|
-
report = performBlueprintRoundTrip('blueprint-glass-console');
|
|
2479
|
-
});
|
|
2480
|
-
|
|
2481
|
-
it('should compile successfully', () => {
|
|
2482
|
-
expect(report.compileSuccess).toBe(true);
|
|
2483
|
-
});
|
|
2484
|
-
|
|
2485
|
-
it('should decompile successfully', () => {
|
|
2486
|
-
expect(report.decompileSuccess).toBe(true);
|
|
2487
|
-
});
|
|
2488
|
-
|
|
2489
|
-
it('should re-compile decompiled output successfully', () => {
|
|
2490
|
-
expect(report.recompileSuccess).toBe(true);
|
|
2491
|
-
if (report.recompileErrors.length > 0) {
|
|
2492
|
-
console.log('Re-compile errors:', report.recompileErrors);
|
|
2493
|
-
}
|
|
2494
|
-
});
|
|
2495
|
-
|
|
2496
|
-
it('should preserve fields through round trip', () => {
|
|
2497
|
-
const fieldDiffs = report.irDiffs.filter(
|
|
2498
|
-
d => d.path.startsWith('fields') && d.severity === 'error',
|
|
2499
|
-
);
|
|
2500
|
-
if (fieldDiffs.length > 0) {
|
|
2501
|
-
console.log('Field diffs:', JSON.stringify(fieldDiffs, null, 2));
|
|
2502
|
-
}
|
|
2503
|
-
expect(fieldDiffs).toEqual([]);
|
|
2504
|
-
});
|
|
2505
|
-
|
|
2506
|
-
it('should preserve transitions through round trip', () => {
|
|
2507
|
-
const transDiffs = report.irDiffs.filter(
|
|
2508
|
-
d => d.path.startsWith('transitions') && d.severity === 'error',
|
|
2509
|
-
);
|
|
2510
|
-
if (transDiffs.length > 0) {
|
|
2511
|
-
console.log('Transition diffs:', JSON.stringify(transDiffs, null, 2));
|
|
2512
|
-
}
|
|
2513
|
-
expect(transDiffs).toEqual([]);
|
|
2514
|
-
});
|
|
2515
|
-
|
|
2516
|
-
it('should preserve states with effects through round trip', () => {
|
|
2517
|
-
const stateDiffs = report.irDiffs.filter(
|
|
2518
|
-
d => d.path.startsWith('states') && d.severity === 'error',
|
|
2519
|
-
);
|
|
2520
|
-
if (stateDiffs.length > 0) {
|
|
2521
|
-
console.log('State diffs:', JSON.stringify(stateDiffs, null, 2));
|
|
2522
|
-
}
|
|
2523
|
-
expect(stateDiffs).toEqual([]);
|
|
2524
|
-
});
|
|
2525
|
-
|
|
2526
|
-
it('should stabilize source on second pass', () => {
|
|
2527
|
-
if (!report.sourceStabilized) {
|
|
2528
|
-
console.log('Source stabilization failures:');
|
|
2529
|
-
for (const diff of report.sourceDiffs) {
|
|
2530
|
-
console.log(` ${diff.file}: ${diff.type}`);
|
|
2531
|
-
if (diff.details) {
|
|
2532
|
-
console.log(diff.details);
|
|
2533
|
-
}
|
|
2534
|
-
}
|
|
2535
|
-
}
|
|
2536
|
-
expect(report.sourceStabilized).toBe(true);
|
|
2537
|
-
});
|
|
2538
|
-
});
|
|
2539
|
-
|
|
2540
|
-
// ---------------------------------------------------------------------------
|
|
2541
|
-
// Real blueprint diagnostic summary
|
|
2542
|
-
// ---------------------------------------------------------------------------
|
|
2543
|
-
|
|
2544
|
-
describe('round-trip: real blueprint diagnostic summary', () => {
|
|
2545
|
-
it('should produce a full diagnostic report for all real blueprints', () => {
|
|
2546
|
-
const blueprints = [
|
|
2547
|
-
'blueprint-auth',
|
|
2548
|
-
'blueprint-employee-salary-tracking',
|
|
2549
|
-
'blueprint-glass-console',
|
|
2550
|
-
];
|
|
2551
|
-
const reports: RoundTripReport[] = [];
|
|
2552
|
-
|
|
2553
|
-
for (const bp of blueprints) {
|
|
2554
|
-
reports.push(performBlueprintRoundTrip(bp));
|
|
2555
|
-
}
|
|
2556
|
-
|
|
2557
|
-
console.log('\n============================================');
|
|
2558
|
-
console.log(' REAL BLUEPRINT ROUND-TRIP DIAGNOSTIC');
|
|
2559
|
-
console.log('============================================\n');
|
|
2560
|
-
|
|
2561
|
-
for (const report of reports) {
|
|
2562
|
-
const irErrors = report.irDiffs.filter(d => d.severity === 'error').length;
|
|
2563
|
-
const irWarnings = report.irDiffs.filter(d => d.severity === 'warning').length;
|
|
2564
|
-
|
|
2565
|
-
console.log(`${report.fixtureName}:`);
|
|
2566
|
-
console.log(` Compile: ${report.compileSuccess ? 'PASS' : 'FAIL'}`);
|
|
2567
|
-
console.log(` Decompile: ${report.decompileSuccess ? 'PASS' : 'FAIL'}`);
|
|
2568
|
-
console.log(` Re-compile: ${report.recompileSuccess ? 'PASS' : 'FAIL'}`);
|
|
2569
|
-
console.log(` IR match: ${report.irMatch ? 'PASS' : `FAIL (${irErrors} errors, ${irWarnings} warnings)`}`);
|
|
2570
|
-
console.log(` Source stable: ${report.sourceStabilized ? 'PASS' : `FAIL (${report.sourceDiffs.length} diffs)`}`);
|
|
2571
|
-
console.log(` Output files: ${Object.keys(report.outputFiles1).join(', ')}`);
|
|
2572
|
-
|
|
2573
|
-
if (!report.irMatch) {
|
|
2574
|
-
for (const diff of report.irDiffs.filter(d => d.severity === 'error')) {
|
|
2575
|
-
console.log(` IR ERROR: ${diff.path} — expected: ${JSON.stringify(diff.expected)}, got: ${JSON.stringify(diff.actual)}`);
|
|
2576
|
-
}
|
|
2577
|
-
}
|
|
2578
|
-
|
|
2579
|
-
if (!report.sourceStabilized) {
|
|
2580
|
-
for (const diff of report.sourceDiffs) {
|
|
2581
|
-
console.log(` SOURCE: ${diff.file} — ${diff.type}`);
|
|
2582
|
-
if (diff.details) {
|
|
2583
|
-
for (const line of diff.details.split('\n').slice(0, 5)) {
|
|
2584
|
-
console.log(` ${line}`);
|
|
2585
|
-
}
|
|
2586
|
-
}
|
|
2587
|
-
}
|
|
2588
|
-
}
|
|
2589
|
-
|
|
2590
|
-
console.log('');
|
|
2591
|
-
}
|
|
2592
|
-
|
|
2593
|
-
// All blueprints should compile
|
|
2594
|
-
for (const report of reports) {
|
|
2595
|
-
expect(report.compileSuccess).toBe(true);
|
|
2596
|
-
}
|
|
2597
|
-
});
|
|
2598
|
-
});
|