@mmapp/react-compiler 0.1.0-alpha.1 → 0.1.0-alpha.4
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/auth-3UK75242.mjs +17 -0
- package/dist/babel/index.d.mts +2 -2
- package/dist/babel/index.d.ts +2 -2
- package/dist/babel/index.js +2816 -279
- 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-5FTDWKHH.mjs +244 -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-7JRAEFRB.mjs +7510 -0
- package/dist/chunk-7T6Q5KAA.mjs +7506 -0
- package/dist/chunk-7ZKGHTNB.mjs +4952 -0
- package/dist/chunk-ABYPKRSB.mjs +215 -0
- package/dist/chunk-BZEXUPDH.mjs +175 -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-HRYR54PT.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-J3M4GUS7.mjs +161 -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-JRGFBWTN.mjs +2918 -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-O4AUS7EU.mjs +148 -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-R2DD5GTY.mjs +186 -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-UDDTWG5J.mjs +734 -0
- package/dist/chunk-VCAY2KGM.mjs +175 -0
- package/dist/chunk-VLTKQDJ3.mjs +244 -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-WVYY32LD.mjs +939 -0
- package/dist/chunk-XAJ5BKKL.mjs +4947 -0
- package/dist/chunk-XDVM4YHX.mjs +3450 -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-Z2G5RZ4H.mjs +186 -0
- package/dist/chunk-ZA37XTGA.mjs +175 -0
- package/dist/chunk-ZE3KCHBM.mjs +2918 -0
- package/dist/cli/index.js +14720 -7199
- package/dist/cli/index.mjs +224 -183
- package/dist/codemod/cli.js +1 -1
- package/dist/codemod/cli.mjs +2 -2
- package/dist/codemod/index.d.mts +3 -3
- package/dist/codemod/index.d.ts +3 -3
- package/dist/codemod/index.js +1 -1
- package/dist/codemod/index.mjs +2 -2
- package/dist/config-PL24KEWL.mjs +219 -0
- package/dist/deploy-YAJGW6II.mjs +9 -0
- package/dist/dev-server-CrQ041KP.d.mts +79 -0
- package/dist/dev-server-CrQ041KP.d.ts +79 -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 +2 -2
- package/dist/dev-server.d.ts +2 -2
- package/dist/dev-server.js +6424 -1597
- package/dist/dev-server.mjs +5 -5
- package/dist/envelope-ChEkuHij.d.mts +265 -0
- package/dist/envelope-ChEkuHij.d.ts +265 -0
- package/dist/envelope.d.mts +2 -2
- package/dist/envelope.d.ts +2 -2
- package/dist/envelope.js +2814 -277
- package/dist/envelope.mjs +3 -3
- package/dist/index-CEKyyazf.d.mts +104 -0
- package/dist/index-CEKyyazf.d.ts +104 -0
- package/dist/index.d.mts +168 -9
- package/dist/index.d.ts +168 -9
- package/dist/index.js +5606 -681
- package/dist/index.mjs +217 -9
- package/dist/init-7FJENUDK.mjs +407 -0
- 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-NNK32MPG.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-ZB4RUYVL.mjs +10 -0
- package/dist/project-compiler-ZKMQDLGU.mjs +10 -0
- package/dist/project-decompiler-FLXCEJHS.mjs +7 -0
- package/dist/project-decompiler-U55HQUHW.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-KOL2QAYQ.mjs +109 -0
- package/dist/pull-LD5ENLGY.mjs +109 -0
- package/dist/pull-P44LDRWB.mjs +109 -0
- package/dist/seed-KOGEPGOJ.mjs +154 -0
- package/dist/server-VW6UPCHO.mjs +277 -0
- package/dist/testing/index.d.mts +8 -8
- package/dist/testing/index.d.ts +8 -8
- package/dist/testing/index.js +2824 -287
- package/dist/testing/index.mjs +2 -2
- package/dist/verify-BYHUKARQ.mjs +1833 -0
- package/dist/verify-OQDEQYMS.mjs +1833 -0
- package/dist/verify-SEIXUGN4.mjs +1833 -0
- package/dist/vite/index.d.mts +1 -1
- package/dist/vite/index.d.ts +1 -1
- package/dist/vite/index.js +2817 -280
- package/dist/vite/index.mjs +3 -3
- package/examples/authentication/main.workflow.tsx +1 -1
- package/examples/authentication/mm.config.ts +1 -1
- package/examples/authentication/pages/LoginPage.tsx +2 -2
- package/examples/authentication/pages/SignupPage.tsx +2 -2
- package/examples/counter.workflow.tsx +1 -1
- package/examples/dashboard.workflow.tsx +1 -1
- package/examples/invoice-approval/actions/invoice.server.ts +1 -1
- package/examples/invoice-approval/main.workflow.tsx +1 -1
- package/examples/invoice-approval/mm.config.ts +1 -1
- package/examples/invoice-approval/pages/InvoiceDetailPage.tsx +1 -1
- package/examples/invoice-approval/pages/InvoiceFormPage.tsx +1 -1
- package/examples/invoice-approval/pages/InvoiceListPage.tsx +1 -1
- package/examples/todo-app.workflow.tsx +1 -1
- package/examples/uber-app/actions/matching.server.ts +1 -1
- package/examples/uber-app/actions/notifications.server.ts +1 -1
- package/examples/uber-app/actions/payments.server.ts +1 -1
- package/examples/uber-app/actions/pricing.server.ts +1 -1
- package/examples/uber-app/app/admin/analytics.tsx +2 -2
- package/examples/uber-app/app/admin/fleet.tsx +21 -21
- package/examples/uber-app/app/admin/surge-pricing.tsx +2 -2
- package/examples/uber-app/app/driver/dashboard.tsx +2 -2
- package/examples/uber-app/app/driver/earnings.tsx +2 -2
- package/examples/uber-app/app/driver/navigation.tsx +2 -2
- package/examples/uber-app/app/driver/ride-acceptance.tsx +2 -2
- package/examples/uber-app/app/rider/home.tsx +2 -2
- package/examples/uber-app/app/rider/payment-methods.tsx +2 -2
- package/examples/uber-app/app/rider/ride-history.tsx +2 -2
- package/examples/uber-app/app/rider/ride-tracking.tsx +2 -2
- package/examples/uber-app/components/DriverCard.tsx +1 -1
- package/examples/uber-app/components/MapView.tsx +3 -3
- package/examples/uber-app/components/RatingStars.tsx +2 -2
- package/examples/uber-app/components/RideCard.tsx +1 -1
- package/examples/uber-app/mm.config.ts +1 -1
- package/examples/uber-app/workflows/dispute-resolution.workflow.tsx +2 -2
- package/examples/uber-app/workflows/driver-onboarding.workflow.tsx +2 -2
- package/examples/uber-app/workflows/payment-processing.workflow.tsx +2 -2
- package/examples/uber-app/workflows/ride-request.workflow.tsx +2 -2
- package/package.json +10 -4
- 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,1212 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Comprehensive Round-Trip Compiler Tests
|
|
3
|
-
*
|
|
4
|
-
* Validates: original TSX source → compile to IR → decompile back to TSX
|
|
5
|
-
* → output preserves all capabilities.
|
|
6
|
-
*
|
|
7
|
-
* Tests span single-file round-trips (useState, useQuery, transitions, etc.)
|
|
8
|
-
* and multi-file project round-trips (blueprint-uber, blueprint-chat).
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import { describe, it, expect } from 'vitest';
|
|
12
|
-
import * as fs from 'fs';
|
|
13
|
-
import * as path from 'path';
|
|
14
|
-
import { compileProject } from '../project-compiler';
|
|
15
|
-
import { decompile } from '../decompiler';
|
|
16
|
-
import { decompileProjectEnhanced } from '../decompiler/project-decompiler';
|
|
17
|
-
import type { DecompilerInput } from '../decompiler';
|
|
18
|
-
import { validateRoundTrip, compileSource } from '../RoundTripValidator';
|
|
19
|
-
|
|
20
|
-
// =============================================================================
|
|
21
|
-
// Helpers
|
|
22
|
-
// =============================================================================
|
|
23
|
-
|
|
24
|
-
/** Reads all files in a directory tree into a Record<relativePath, content>. */
|
|
25
|
-
function readProjectFiles(rootDir: string): Record<string, string> {
|
|
26
|
-
const files: Record<string, string> = {};
|
|
27
|
-
|
|
28
|
-
function walk(dir: string, prefix: string) {
|
|
29
|
-
if (!fs.existsSync(dir)) return;
|
|
30
|
-
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
31
|
-
for (const entry of entries) {
|
|
32
|
-
const relPath = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
33
|
-
const fullPath = path.join(dir, entry.name);
|
|
34
|
-
if (entry.isDirectory()) {
|
|
35
|
-
if (['node_modules', 'tests', 'dist', '.git'].includes(entry.name)) continue;
|
|
36
|
-
walk(fullPath, relPath);
|
|
37
|
-
} else if (entry.isFile()) {
|
|
38
|
-
if (
|
|
39
|
-
entry.name.endsWith('.tsx') ||
|
|
40
|
-
entry.name.endsWith('.ts')
|
|
41
|
-
) {
|
|
42
|
-
if (entry.name.endsWith('.test.tsx') || entry.name.endsWith('.test.ts')) continue;
|
|
43
|
-
if (entry.name === 'tsconfig.json') continue;
|
|
44
|
-
files[relPath] = fs.readFileSync(fullPath, 'utf-8');
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
walk(rootDir, '');
|
|
51
|
-
return files;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/** Makes a minimal DecompilerInput. */
|
|
55
|
-
function makeDef(overrides: Partial<DecompilerInput> = {}): DecompilerInput {
|
|
56
|
-
return {
|
|
57
|
-
slug: 'test-workflow',
|
|
58
|
-
name: 'Test Workflow',
|
|
59
|
-
version: '1.0.0',
|
|
60
|
-
description: 'A test workflow',
|
|
61
|
-
category: 'workflow',
|
|
62
|
-
fields: [],
|
|
63
|
-
states: [],
|
|
64
|
-
transitions: [],
|
|
65
|
-
roles: [],
|
|
66
|
-
tags: [],
|
|
67
|
-
metadata: {},
|
|
68
|
-
...overrides,
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const UBER_DIR = path.resolve(__dirname, '../../../blueprint-uber');
|
|
73
|
-
const CHAT_DIR = path.resolve(__dirname, '../../../blueprint-chat');
|
|
74
|
-
|
|
75
|
-
// =============================================================================
|
|
76
|
-
// 1. File Structure Preservation Test (blueprint-uber)
|
|
77
|
-
// =============================================================================
|
|
78
|
-
|
|
79
|
-
describe('1. File structure preservation (blueprint-uber)', () => {
|
|
80
|
-
const uberFiles = readProjectFiles(UBER_DIR);
|
|
81
|
-
|
|
82
|
-
it('should read all uber blueprint files', () => {
|
|
83
|
-
expect(Object.keys(uberFiles).length).toBeGreaterThan(10);
|
|
84
|
-
expect(uberFiles['mm.config.ts']).toBeDefined();
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
it('should compile uber blueprint with correct IR metadata', () => {
|
|
88
|
-
const result = compileProject(uberFiles);
|
|
89
|
-
|
|
90
|
-
expect(result.ir.slug).toBe('uber-rideshare');
|
|
91
|
-
expect(result.ir.category).toBe('blueprint');
|
|
92
|
-
expect(result.ir.version).toBe('2.0.0');
|
|
93
|
-
expect(result.ir.fields.length).toBeGreaterThan(0);
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
it('should produce child definitions from workflows and models', () => {
|
|
97
|
-
const result = compileProject(uberFiles);
|
|
98
|
-
expect(result.childDefinitions.length).toBeGreaterThan(0);
|
|
99
|
-
|
|
100
|
-
// Model files produce 'data' category children
|
|
101
|
-
const dataChildren = result.childDefinitions.filter(c => c.category === 'data');
|
|
102
|
-
expect(dataChildren.length).toBeGreaterThan(0);
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
it('should extract route table from app directory pages', () => {
|
|
106
|
-
const result = compileProject(uberFiles);
|
|
107
|
-
expect(result.routeTable.length).toBeGreaterThan(0);
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
it('should extract server actions from *.server.ts files', () => {
|
|
111
|
-
const result = compileProject(uberFiles);
|
|
112
|
-
expect(result.serverActions.length).toBeGreaterThan(0);
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
it('should extract component definitions from components/*.tsx', () => {
|
|
116
|
-
const result = compileProject(uberFiles);
|
|
117
|
-
expect(Object.keys(result.componentDefinitions).length).toBeGreaterThan(0);
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
it('should decompile IR back to project with correct file structure', () => {
|
|
121
|
-
const compiled = compileProject(uberFiles);
|
|
122
|
-
const decompilerInput: DecompilerInput = {
|
|
123
|
-
...compiled.ir,
|
|
124
|
-
experience: (compiled.ir as any).views?.default,
|
|
125
|
-
childDefinitions: compiled.childDefinitions,
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
const decompiled = decompileProjectEnhanced(decompilerInput);
|
|
129
|
-
const paths = decompiled.files.map(f => f.path);
|
|
130
|
-
|
|
131
|
-
expect(decompiled.slug).toBe('uber-rideshare');
|
|
132
|
-
expect(paths).toContain('main.workflow.tsx');
|
|
133
|
-
expect(paths).toContain('mm.config.ts');
|
|
134
|
-
|
|
135
|
-
// Should have model files
|
|
136
|
-
const modelFiles = decompiled.files.filter(f => f.path.startsWith('models/'));
|
|
137
|
-
expect(modelFiles.length).toBeGreaterThan(0);
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
it('should produce mm.config.ts with correct slug', () => {
|
|
141
|
-
const compiled = compileProject(uberFiles);
|
|
142
|
-
const decompilerInput: DecompilerInput = {
|
|
143
|
-
...compiled.ir,
|
|
144
|
-
experience: (compiled.ir as any).views?.default,
|
|
145
|
-
childDefinitions: compiled.childDefinitions,
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
const decompiled = decompileProjectEnhanced(decompilerInput);
|
|
149
|
-
const configFile = decompiled.files.find(f => f.path === 'mm.config.ts');
|
|
150
|
-
expect(configFile).toBeDefined();
|
|
151
|
-
expect(configFile!.content).toContain('uber-rideshare');
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
it('should produce page files in app/ directory structure', () => {
|
|
155
|
-
const compiled = compileProject(uberFiles);
|
|
156
|
-
const decompilerInput: DecompilerInput = {
|
|
157
|
-
...compiled.ir,
|
|
158
|
-
experience: (compiled.ir as any).views?.default,
|
|
159
|
-
childDefinitions: compiled.childDefinitions,
|
|
160
|
-
};
|
|
161
|
-
|
|
162
|
-
const decompiled = decompileProjectEnhanced(decompilerInput);
|
|
163
|
-
const pageFiles = decompiled.files.filter(f => f.path.startsWith('app/'));
|
|
164
|
-
|
|
165
|
-
// If pages were extracted, verify role-based directory structure
|
|
166
|
-
if (pageFiles.length > 0) {
|
|
167
|
-
const roleDirs = new Set(pageFiles.map(f => f.path.split('/')[1]));
|
|
168
|
-
// Should have at least some role-based dirs (rider, driver, admin, or shared)
|
|
169
|
-
expect(roleDirs.size).toBeGreaterThan(0);
|
|
170
|
-
}
|
|
171
|
-
});
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
// =============================================================================
|
|
175
|
-
// 2. useState Round-Trip Test
|
|
176
|
-
// =============================================================================
|
|
177
|
-
|
|
178
|
-
describe('2. useState round-trip', () => {
|
|
179
|
-
const source = `
|
|
180
|
-
/**
|
|
181
|
-
* @workflow slug="counter" version="1.0.0" category="workflow"
|
|
182
|
-
*/
|
|
183
|
-
export default function Counter() {
|
|
184
|
-
const [count, setCount] = useState<number>(0);
|
|
185
|
-
const [name, setName] = useState<string>("hello");
|
|
186
|
-
const [active, setActive] = useState<boolean>(false);
|
|
187
|
-
return <div>{count}</div>;
|
|
188
|
-
}
|
|
189
|
-
`;
|
|
190
|
-
|
|
191
|
-
it('should compile useState to IR fields with correct types and defaults', () => {
|
|
192
|
-
const ir = compileSource(source, 'counter.workflow.tsx');
|
|
193
|
-
expect(ir).not.toBeNull();
|
|
194
|
-
|
|
195
|
-
const countField = ir!.fields.find(f => f.name === 'count');
|
|
196
|
-
expect(countField).toBeDefined();
|
|
197
|
-
expect(countField!.type).toBe('number');
|
|
198
|
-
expect(countField!.default_value).toBe(0);
|
|
199
|
-
|
|
200
|
-
const nameField = ir!.fields.find(f => f.name === 'name');
|
|
201
|
-
expect(nameField).toBeDefined();
|
|
202
|
-
expect(nameField!.default_value).toBe('hello');
|
|
203
|
-
|
|
204
|
-
const activeField = ir!.fields.find(f => f.name === 'active');
|
|
205
|
-
expect(activeField).toBeDefined();
|
|
206
|
-
expect(activeField!.type).toBe('boolean');
|
|
207
|
-
expect(activeField!.default_value).toBe(false);
|
|
208
|
-
});
|
|
209
|
-
|
|
210
|
-
it('should decompile fields back to useState with type annotations', () => {
|
|
211
|
-
const ir = compileSource(source, 'counter.workflow.tsx')!;
|
|
212
|
-
const { code } = decompile(ir as DecompilerInput);
|
|
213
|
-
|
|
214
|
-
expect(code).toContain('useState');
|
|
215
|
-
expect(code).toContain('count');
|
|
216
|
-
expect(code).toContain('setCount');
|
|
217
|
-
expect(code).toContain('useState<number>');
|
|
218
|
-
});
|
|
219
|
-
|
|
220
|
-
it('should preserve all fields through full round trip with no errors', () => {
|
|
221
|
-
const ir = compileSource(source, 'counter.workflow.tsx')!;
|
|
222
|
-
const result = validateRoundTrip(ir as DecompilerInput);
|
|
223
|
-
expect(result.roundTrippedIR).not.toBeNull();
|
|
224
|
-
|
|
225
|
-
const rtFields = result.roundTrippedIR!.fields.map(f => f.name);
|
|
226
|
-
expect(rtFields).toContain('count');
|
|
227
|
-
expect(rtFields).toContain('name');
|
|
228
|
-
expect(rtFields).toContain('active');
|
|
229
|
-
|
|
230
|
-
const errors = result.diffs.filter(d => d.severity === 'error');
|
|
231
|
-
expect(errors).toEqual([]);
|
|
232
|
-
});
|
|
233
|
-
});
|
|
234
|
-
|
|
235
|
-
// =============================================================================
|
|
236
|
-
// 3. useQuery Round-Trip Test
|
|
237
|
-
// =============================================================================
|
|
238
|
-
|
|
239
|
-
describe('3. useQuery round-trip', () => {
|
|
240
|
-
const source = `
|
|
241
|
-
/**
|
|
242
|
-
* @workflow slug="ride-list" version="1.0.0" category="data"
|
|
243
|
-
*/
|
|
244
|
-
export default function RideList() {
|
|
245
|
-
const [filter, setFilter] = useState("all");
|
|
246
|
-
const rides = useQuery("uber-ride", { filter: { status: "active" }, limit: 50 });
|
|
247
|
-
const drivers = useQuery("driver", { orderBy: "rating", order: "desc" });
|
|
248
|
-
return <div>{rides.length}</div>;
|
|
249
|
-
}
|
|
250
|
-
`;
|
|
251
|
-
|
|
252
|
-
it('should compile useQuery to dataSources in IR metadata', () => {
|
|
253
|
-
const ir = compileSource(source, 'ride-list.workflow.tsx');
|
|
254
|
-
expect(ir).not.toBeNull();
|
|
255
|
-
|
|
256
|
-
const dataSources = (ir!.metadata as any)?.dataSources;
|
|
257
|
-
expect(dataSources).toBeDefined();
|
|
258
|
-
expect(dataSources.length).toBe(2);
|
|
259
|
-
|
|
260
|
-
const rideSource = dataSources.find((d: any) => d.slug === 'uber-ride');
|
|
261
|
-
expect(rideSource).toBeDefined();
|
|
262
|
-
expect(rideSource.pageSize).toBe(50);
|
|
263
|
-
|
|
264
|
-
const driverSource = dataSources.find((d: any) => d.slug === 'driver');
|
|
265
|
-
expect(driverSource).toBeDefined();
|
|
266
|
-
expect(driverSource.sort).toContain('rating');
|
|
267
|
-
});
|
|
268
|
-
|
|
269
|
-
it('should decompile dataSources back to useQuery calls', () => {
|
|
270
|
-
const ir = compileSource(source, 'ride-list.workflow.tsx')!;
|
|
271
|
-
const { code } = decompile(ir as DecompilerInput);
|
|
272
|
-
|
|
273
|
-
expect(code).toContain('useQuery');
|
|
274
|
-
expect(code).toContain('uber-ride');
|
|
275
|
-
});
|
|
276
|
-
|
|
277
|
-
it('should preserve fields through round trip alongside data sources', () => {
|
|
278
|
-
const ir = compileSource(source, 'ride-list.workflow.tsx')!;
|
|
279
|
-
const result = validateRoundTrip(ir as DecompilerInput);
|
|
280
|
-
expect(result.roundTrippedIR).not.toBeNull();
|
|
281
|
-
|
|
282
|
-
const rtFields = result.roundTrippedIR!.fields.map(f => f.name);
|
|
283
|
-
expect(rtFields).toContain('filter');
|
|
284
|
-
});
|
|
285
|
-
});
|
|
286
|
-
|
|
287
|
-
// =============================================================================
|
|
288
|
-
// 4. Event Handler Round-Trip Test
|
|
289
|
-
// =============================================================================
|
|
290
|
-
|
|
291
|
-
describe('4. Event handler round-trip (onClick binding)', () => {
|
|
292
|
-
it('should preserve onClick binding in experience tree', () => {
|
|
293
|
-
const def = makeDef({
|
|
294
|
-
slug: 'click-test',
|
|
295
|
-
fields: [
|
|
296
|
-
{ name: 'count', type: 'number', required: false, default_value: 0 },
|
|
297
|
-
],
|
|
298
|
-
experience: {
|
|
299
|
-
id: 'root',
|
|
300
|
-
component: 'Stack',
|
|
301
|
-
children: [
|
|
302
|
-
{
|
|
303
|
-
id: 'btn',
|
|
304
|
-
component: 'Button',
|
|
305
|
-
config: { label: 'Increment' },
|
|
306
|
-
bindings: { onClick: '$action.transition(increment)' },
|
|
307
|
-
},
|
|
308
|
-
],
|
|
309
|
-
},
|
|
310
|
-
transitions: [
|
|
311
|
-
{ name: 'increment', from: ['idle'], to: 'counting', actions: [] },
|
|
312
|
-
],
|
|
313
|
-
});
|
|
314
|
-
|
|
315
|
-
const { code } = decompile(def);
|
|
316
|
-
expect(code).toContain('<Button');
|
|
317
|
-
expect(code).toContain('Increment');
|
|
318
|
-
expect(code).toContain('useTransition');
|
|
319
|
-
expect(code).toContain('increment');
|
|
320
|
-
});
|
|
321
|
-
|
|
322
|
-
it('should round-trip transition referenced in onClick binding', () => {
|
|
323
|
-
const def = makeDef({
|
|
324
|
-
slug: 'click-rt',
|
|
325
|
-
fields: [{ name: 'count', type: 'number', required: false, default_value: 0 }],
|
|
326
|
-
transitions: [{ name: 'inc', from: ['idle'], to: 'active', actions: [] }],
|
|
327
|
-
experience: {
|
|
328
|
-
id: 'root',
|
|
329
|
-
component: 'Button',
|
|
330
|
-
config: { label: 'Click' },
|
|
331
|
-
bindings: { onClick: '$action.transition(inc)' },
|
|
332
|
-
},
|
|
333
|
-
});
|
|
334
|
-
|
|
335
|
-
const result = validateRoundTrip(def);
|
|
336
|
-
expect(result.roundTrippedIR).not.toBeNull();
|
|
337
|
-
expect(result.roundTrippedIR!.transitions.length).toBe(1);
|
|
338
|
-
expect(result.roundTrippedIR!.transitions[0].name).toBe('inc');
|
|
339
|
-
});
|
|
340
|
-
});
|
|
341
|
-
|
|
342
|
-
// =============================================================================
|
|
343
|
-
// 5. Show/When Conditional Test
|
|
344
|
-
// =============================================================================
|
|
345
|
-
|
|
346
|
-
describe('5. Show/when conditional rendering', () => {
|
|
347
|
-
it('should emit Show wrapper for visible_when', () => {
|
|
348
|
-
const def = makeDef({
|
|
349
|
-
slug: 'cond-test',
|
|
350
|
-
experience: {
|
|
351
|
-
id: 'root',
|
|
352
|
-
component: 'Stack',
|
|
353
|
-
children: [
|
|
354
|
-
{
|
|
355
|
-
id: 'admin-panel',
|
|
356
|
-
component: 'Text',
|
|
357
|
-
config: { value: 'Admin Panel' },
|
|
358
|
-
visible_when: '$local.is_admin',
|
|
359
|
-
},
|
|
360
|
-
{
|
|
361
|
-
id: 'always-visible',
|
|
362
|
-
component: 'Text',
|
|
363
|
-
config: { value: 'Always shown' },
|
|
364
|
-
},
|
|
365
|
-
],
|
|
366
|
-
},
|
|
367
|
-
});
|
|
368
|
-
|
|
369
|
-
const { code } = decompile(def);
|
|
370
|
-
expect(code).toContain('<Show');
|
|
371
|
-
expect(code).toContain('when={');
|
|
372
|
-
expect(code).toContain('Admin Panel');
|
|
373
|
-
expect(code).toContain('Always shown');
|
|
374
|
-
});
|
|
375
|
-
|
|
376
|
-
it('should round-trip Show/when with nested content preserving the field', () => {
|
|
377
|
-
const def = makeDef({
|
|
378
|
-
slug: 'show-rt',
|
|
379
|
-
fields: [{ name: 'is_admin', type: 'boolean', required: false, default_value: false }],
|
|
380
|
-
experience: {
|
|
381
|
-
id: 'root',
|
|
382
|
-
component: 'Stack',
|
|
383
|
-
children: [
|
|
384
|
-
{
|
|
385
|
-
id: 'cond',
|
|
386
|
-
component: 'Show',
|
|
387
|
-
bindings: { when: '$local.is_admin' },
|
|
388
|
-
children: [
|
|
389
|
-
{ id: 'inner', component: 'Text', config: { value: 'Secret' } },
|
|
390
|
-
],
|
|
391
|
-
},
|
|
392
|
-
],
|
|
393
|
-
},
|
|
394
|
-
});
|
|
395
|
-
|
|
396
|
-
const result = validateRoundTrip(def);
|
|
397
|
-
expect(result.roundTrippedIR).not.toBeNull();
|
|
398
|
-
expect(
|
|
399
|
-
result.roundTrippedIR!.fields.some(
|
|
400
|
-
f => f.name === 'isAdmin' || f.name === 'is_admin',
|
|
401
|
-
),
|
|
402
|
-
).toBe(true);
|
|
403
|
-
});
|
|
404
|
-
});
|
|
405
|
-
|
|
406
|
-
// =============================================================================
|
|
407
|
-
// 6. Each/Items List Rendering Test
|
|
408
|
-
// =============================================================================
|
|
409
|
-
|
|
410
|
-
describe('6. Each/items list rendering', () => {
|
|
411
|
-
it('should emit Each component in decompiled output', () => {
|
|
412
|
-
const def = makeDef({
|
|
413
|
-
slug: 'list-test',
|
|
414
|
-
experience: {
|
|
415
|
-
id: 'root',
|
|
416
|
-
component: 'Stack',
|
|
417
|
-
children: [
|
|
418
|
-
{
|
|
419
|
-
id: 'todo-list',
|
|
420
|
-
component: 'Each',
|
|
421
|
-
config: { items: '$local.todos' },
|
|
422
|
-
children: [
|
|
423
|
-
{ id: 'item', component: 'Text', bindings: { value: '$item.title' } },
|
|
424
|
-
],
|
|
425
|
-
},
|
|
426
|
-
],
|
|
427
|
-
},
|
|
428
|
-
});
|
|
429
|
-
|
|
430
|
-
const { code } = decompile(def);
|
|
431
|
-
expect(code).toContain('<Each');
|
|
432
|
-
expect(code).toContain('<Text');
|
|
433
|
-
});
|
|
434
|
-
|
|
435
|
-
it('should preserve list component children structure', () => {
|
|
436
|
-
const def = makeDef({
|
|
437
|
-
slug: 'each-test',
|
|
438
|
-
fields: [
|
|
439
|
-
{ name: 'items', type: 'json', required: false, default_value: [] },
|
|
440
|
-
],
|
|
441
|
-
experience: {
|
|
442
|
-
id: 'root',
|
|
443
|
-
component: 'Each',
|
|
444
|
-
config: { items: '$local.items' },
|
|
445
|
-
children: [
|
|
446
|
-
{ id: 'card', component: 'Card', config: { padding: 8 } },
|
|
447
|
-
],
|
|
448
|
-
},
|
|
449
|
-
});
|
|
450
|
-
|
|
451
|
-
const { code } = decompile(def);
|
|
452
|
-
expect(code).toContain('Each');
|
|
453
|
-
expect(code).toContain('Card');
|
|
454
|
-
expect(code).toContain('padding');
|
|
455
|
-
});
|
|
456
|
-
});
|
|
457
|
-
|
|
458
|
-
// =============================================================================
|
|
459
|
-
// 7. Layout Component Test (Stack, Row, Grid)
|
|
460
|
-
// =============================================================================
|
|
461
|
-
|
|
462
|
-
describe('7. Layout component preservation (Stack, Row)', () => {
|
|
463
|
-
it('should preserve Stack with gap and nested children', () => {
|
|
464
|
-
const def = makeDef({
|
|
465
|
-
slug: 'layout-test',
|
|
466
|
-
experience: {
|
|
467
|
-
id: 'root',
|
|
468
|
-
component: 'Stack',
|
|
469
|
-
config: { gap: 16 },
|
|
470
|
-
children: [
|
|
471
|
-
{ id: 'h', component: 'Heading', config: { level: 2, value: 'Title' } },
|
|
472
|
-
{ id: 't', component: 'Text', config: { value: 'Body' } },
|
|
473
|
-
],
|
|
474
|
-
},
|
|
475
|
-
});
|
|
476
|
-
|
|
477
|
-
const { code } = decompile(def);
|
|
478
|
-
expect(code).toContain('<Stack');
|
|
479
|
-
expect(code).toContain('gap={16}');
|
|
480
|
-
expect(code).toContain('<Heading');
|
|
481
|
-
expect(code).toContain('<Text');
|
|
482
|
-
});
|
|
483
|
-
|
|
484
|
-
it('should preserve Row with justify and align props', () => {
|
|
485
|
-
const def = makeDef({
|
|
486
|
-
slug: 'row-test',
|
|
487
|
-
experience: {
|
|
488
|
-
id: 'root',
|
|
489
|
-
component: 'Row',
|
|
490
|
-
config: { justify: 'between', align: 'center' },
|
|
491
|
-
children: [
|
|
492
|
-
{ id: 'a', component: 'Text', config: { value: 'Left' } },
|
|
493
|
-
{ id: 'b', component: 'Text', config: { value: 'Right' } },
|
|
494
|
-
],
|
|
495
|
-
},
|
|
496
|
-
});
|
|
497
|
-
|
|
498
|
-
const { code } = decompile(def);
|
|
499
|
-
expect(code).toContain('<Row');
|
|
500
|
-
expect(code).toContain('justify=');
|
|
501
|
-
expect(code).toContain('align=');
|
|
502
|
-
});
|
|
503
|
-
|
|
504
|
-
it('should round-trip nested Stack > Row > Buttons layout', () => {
|
|
505
|
-
const def = makeDef({
|
|
506
|
-
slug: 'nested-layout',
|
|
507
|
-
fields: [{ name: 'title', type: 'text', required: false, default_value: 'Hello' }],
|
|
508
|
-
experience: {
|
|
509
|
-
id: 'root',
|
|
510
|
-
component: 'Stack',
|
|
511
|
-
config: { gap: 8 },
|
|
512
|
-
children: [
|
|
513
|
-
{
|
|
514
|
-
id: 'row',
|
|
515
|
-
component: 'Row',
|
|
516
|
-
config: { gap: 4 },
|
|
517
|
-
children: [
|
|
518
|
-
{ id: 'btn1', component: 'Button', config: { label: 'Save' } },
|
|
519
|
-
{ id: 'btn2', component: 'Button', config: { label: 'Cancel' } },
|
|
520
|
-
],
|
|
521
|
-
},
|
|
522
|
-
],
|
|
523
|
-
},
|
|
524
|
-
});
|
|
525
|
-
|
|
526
|
-
const result = validateRoundTrip(def);
|
|
527
|
-
expect(result.roundTrippedIR).not.toBeNull();
|
|
528
|
-
expect(result.roundTrippedIR!.fields.length).toBeGreaterThanOrEqual(1);
|
|
529
|
-
});
|
|
530
|
-
});
|
|
531
|
-
|
|
532
|
-
// =============================================================================
|
|
533
|
-
// 8. Transition Test (useTransition)
|
|
534
|
-
// =============================================================================
|
|
535
|
-
|
|
536
|
-
describe('8. useTransition round-trip', () => {
|
|
537
|
-
it('should preserve transition with from/to/roles/required_fields', () => {
|
|
538
|
-
const def = makeDef({
|
|
539
|
-
slug: 'approval',
|
|
540
|
-
transitions: [
|
|
541
|
-
{
|
|
542
|
-
name: 'submit',
|
|
543
|
-
from: ['draft'],
|
|
544
|
-
to: 'pending',
|
|
545
|
-
actions: [],
|
|
546
|
-
roles: ['author'],
|
|
547
|
-
required_fields: ['title', 'body'],
|
|
548
|
-
},
|
|
549
|
-
{
|
|
550
|
-
name: 'approve',
|
|
551
|
-
from: ['pending'],
|
|
552
|
-
to: 'approved',
|
|
553
|
-
actions: [],
|
|
554
|
-
roles: ['reviewer', 'admin'],
|
|
555
|
-
conditions: [{ field: 'score', operator: 'gte', value: 80 }],
|
|
556
|
-
},
|
|
557
|
-
{
|
|
558
|
-
name: 'reject',
|
|
559
|
-
from: ['pending'],
|
|
560
|
-
to: 'rejected',
|
|
561
|
-
actions: [],
|
|
562
|
-
roles: ['reviewer'],
|
|
563
|
-
},
|
|
564
|
-
],
|
|
565
|
-
});
|
|
566
|
-
|
|
567
|
-
const result = validateRoundTrip(def);
|
|
568
|
-
expect(result.roundTrippedIR).not.toBeNull();
|
|
569
|
-
expect(result.roundTrippedIR!.transitions.length).toBe(3);
|
|
570
|
-
|
|
571
|
-
const submit = result.roundTrippedIR!.transitions.find(t => t.name === 'submit');
|
|
572
|
-
expect(submit).toBeDefined();
|
|
573
|
-
expect(submit!.from).toContain('draft');
|
|
574
|
-
expect(submit!.to).toBe('pending');
|
|
575
|
-
expect(submit!.roles).toContain('author');
|
|
576
|
-
expect(submit!.required_fields).toEqual(expect.arrayContaining(['title', 'body']));
|
|
577
|
-
|
|
578
|
-
const approve = result.roundTrippedIR!.transitions.find(t => t.name === 'approve');
|
|
579
|
-
expect(approve).toBeDefined();
|
|
580
|
-
expect(approve!.roles).toContain('reviewer');
|
|
581
|
-
expect(approve!.roles).toContain('admin');
|
|
582
|
-
});
|
|
583
|
-
|
|
584
|
-
it('should preserve auto flag on transitions', () => {
|
|
585
|
-
const def = makeDef({
|
|
586
|
-
slug: 'auto-test',
|
|
587
|
-
transitions: [{
|
|
588
|
-
name: 'auto-advance',
|
|
589
|
-
from: ['waiting'],
|
|
590
|
-
to: 'processing',
|
|
591
|
-
actions: [],
|
|
592
|
-
auto: true,
|
|
593
|
-
}],
|
|
594
|
-
});
|
|
595
|
-
|
|
596
|
-
const result = validateRoundTrip(def);
|
|
597
|
-
expect(result.roundTrippedIR).not.toBeNull();
|
|
598
|
-
const t = result.roundTrippedIR!.transitions.find(t => t.name === 'auto-advance');
|
|
599
|
-
expect(t).toBeDefined();
|
|
600
|
-
expect(t!.auto).toBe(true);
|
|
601
|
-
});
|
|
602
|
-
|
|
603
|
-
it('should preserve multi-from transitions', () => {
|
|
604
|
-
const def = makeDef({
|
|
605
|
-
slug: 'multi-from',
|
|
606
|
-
transitions: [{
|
|
607
|
-
name: 'reset',
|
|
608
|
-
from: ['active', 'paused', 'error'],
|
|
609
|
-
to: 'idle',
|
|
610
|
-
actions: [],
|
|
611
|
-
}],
|
|
612
|
-
});
|
|
613
|
-
|
|
614
|
-
const result = validateRoundTrip(def);
|
|
615
|
-
expect(result.roundTrippedIR).not.toBeNull();
|
|
616
|
-
const reset = result.roundTrippedIR!.transitions.find(t => t.name === 'reset');
|
|
617
|
-
expect(reset).toBeDefined();
|
|
618
|
-
expect(reset!.from.sort()).toEqual(['active', 'error', 'paused']);
|
|
619
|
-
});
|
|
620
|
-
|
|
621
|
-
it('should emit useTransition with correct from/to in decompiled code', () => {
|
|
622
|
-
const def = makeDef({
|
|
623
|
-
slug: 'trans-emit',
|
|
624
|
-
transitions: [
|
|
625
|
-
{ name: 'start', from: ['idle'], to: 'running', actions: [] },
|
|
626
|
-
],
|
|
627
|
-
});
|
|
628
|
-
|
|
629
|
-
const { code } = decompile(def);
|
|
630
|
-
expect(code).toContain('useTransition');
|
|
631
|
-
expect(code).toContain('"start"');
|
|
632
|
-
expect(code).toContain('from: "idle"');
|
|
633
|
-
expect(code).toContain('to: "running"');
|
|
634
|
-
});
|
|
635
|
-
});
|
|
636
|
-
|
|
637
|
-
// =============================================================================
|
|
638
|
-
// 9. Server Action Preservation Test
|
|
639
|
-
// =============================================================================
|
|
640
|
-
|
|
641
|
-
describe('9. Server action preservation (body stored in metadata)', () => {
|
|
642
|
-
it('should emit server action files with preserved function bodies', () => {
|
|
643
|
-
const def = makeDef({
|
|
644
|
-
slug: 'action-test',
|
|
645
|
-
category: 'blueprint',
|
|
646
|
-
fields: Array.from({ length: 8 }, (_, i) => ({
|
|
647
|
-
name: `field_${i}`,
|
|
648
|
-
type: 'text' as const,
|
|
649
|
-
required: false,
|
|
650
|
-
default_value: '',
|
|
651
|
-
})),
|
|
652
|
-
states: Array.from({ length: 3 }, (_, i) => ({
|
|
653
|
-
name: `state_${i}`,
|
|
654
|
-
type: (i === 0 ? 'START' : 'REGULAR') as 'START' | 'REGULAR',
|
|
655
|
-
description: '',
|
|
656
|
-
on_enter: [],
|
|
657
|
-
on_exit: [],
|
|
658
|
-
during: [],
|
|
659
|
-
})),
|
|
660
|
-
metadata: {
|
|
661
|
-
serverActions: [
|
|
662
|
-
{
|
|
663
|
-
name: 'processPayment',
|
|
664
|
-
sourceFile: 'actions/payment.server.ts',
|
|
665
|
-
body: `export async function processPayment(ctx: TransitionContext): Promise<ActionResult> {
|
|
666
|
-
const { instance } = ctx;
|
|
667
|
-
const amount = instance.fields.amount;
|
|
668
|
-
const result = await stripe.charges.create({ amount });
|
|
669
|
-
return { success: true, chargeId: result.id };
|
|
670
|
-
}`,
|
|
671
|
-
async: true,
|
|
672
|
-
description: 'Process a payment via Stripe',
|
|
673
|
-
},
|
|
674
|
-
{
|
|
675
|
-
name: 'sendNotification',
|
|
676
|
-
sourceFile: 'actions/payment.server.ts',
|
|
677
|
-
body: `export async function sendNotification(ctx: TransitionContext): Promise<void> {
|
|
678
|
-
await ctx.env.notify({ message: 'Payment processed', instanceId: ctx.instance.id });
|
|
679
|
-
}`,
|
|
680
|
-
async: true,
|
|
681
|
-
},
|
|
682
|
-
],
|
|
683
|
-
},
|
|
684
|
-
});
|
|
685
|
-
|
|
686
|
-
const result = decompileProjectEnhanced(def);
|
|
687
|
-
const actionFile = result.files.find(f => f.path === 'actions/payment.server.ts');
|
|
688
|
-
expect(actionFile).toBeDefined();
|
|
689
|
-
expect(actionFile!.content).toContain('processPayment');
|
|
690
|
-
expect(actionFile!.content).toContain('sendNotification');
|
|
691
|
-
expect(actionFile!.content).toContain('stripe.charges.create');
|
|
692
|
-
expect(actionFile!.content).toContain('Payment processed');
|
|
693
|
-
});
|
|
694
|
-
|
|
695
|
-
it('should extract server action stubs from http_request state actions', () => {
|
|
696
|
-
const def = makeDef({
|
|
697
|
-
slug: 'http-action',
|
|
698
|
-
fields: Array.from({ length: 20 }, (_, i) => ({
|
|
699
|
-
name: `f${i}`,
|
|
700
|
-
type: 'text' as const,
|
|
701
|
-
required: false,
|
|
702
|
-
default_value: '',
|
|
703
|
-
})),
|
|
704
|
-
states: [{
|
|
705
|
-
name: 'active',
|
|
706
|
-
type: 'REGULAR' as const,
|
|
707
|
-
description: '',
|
|
708
|
-
on_enter: [{
|
|
709
|
-
id: 'a1',
|
|
710
|
-
type: 'http_request',
|
|
711
|
-
mode: 'async' as const,
|
|
712
|
-
config: { url: 'https://api.example.com/webhook', method: 'POST' },
|
|
713
|
-
}],
|
|
714
|
-
on_exit: [],
|
|
715
|
-
during: [],
|
|
716
|
-
}, ...Array.from({ length: 7 }, (_, i) => ({
|
|
717
|
-
name: `s${i}`,
|
|
718
|
-
type: 'REGULAR' as const,
|
|
719
|
-
description: '',
|
|
720
|
-
on_enter: [],
|
|
721
|
-
on_exit: [],
|
|
722
|
-
during: [],
|
|
723
|
-
}))],
|
|
724
|
-
transitions: [],
|
|
725
|
-
});
|
|
726
|
-
|
|
727
|
-
const result = decompileProjectEnhanced(def);
|
|
728
|
-
const actionFile = result.files.find(f => f.path.startsWith('actions/'));
|
|
729
|
-
expect(actionFile).toBeDefined();
|
|
730
|
-
expect(actionFile!.content).toContain('fetch');
|
|
731
|
-
expect(actionFile!.content).toContain('https://api.example.com/webhook');
|
|
732
|
-
});
|
|
733
|
-
});
|
|
734
|
-
|
|
735
|
-
// =============================================================================
|
|
736
|
-
// 10. Component Definition Preservation Test
|
|
737
|
-
// =============================================================================
|
|
738
|
-
|
|
739
|
-
describe('10. Component definition preservation (experience tree in metadata)', () => {
|
|
740
|
-
it('should emit component files from metadata.componentDefinitions', () => {
|
|
741
|
-
const def = makeDef({
|
|
742
|
-
slug: 'comp-test',
|
|
743
|
-
category: 'blueprint',
|
|
744
|
-
fields: Array.from({ length: 8 }, (_, i) => ({
|
|
745
|
-
name: `field_${i}`,
|
|
746
|
-
type: 'text' as const,
|
|
747
|
-
required: false,
|
|
748
|
-
default_value: '',
|
|
749
|
-
})),
|
|
750
|
-
states: Array.from({ length: 3 }, (_, i) => ({
|
|
751
|
-
name: `state_${i}`,
|
|
752
|
-
type: (i === 0 ? 'START' : 'REGULAR') as 'START' | 'REGULAR',
|
|
753
|
-
description: '',
|
|
754
|
-
on_enter: [],
|
|
755
|
-
on_exit: [],
|
|
756
|
-
during: [],
|
|
757
|
-
})),
|
|
758
|
-
metadata: {
|
|
759
|
-
componentDefinitions: {
|
|
760
|
-
UserCard: {
|
|
761
|
-
experience: {
|
|
762
|
-
id: 'card-root',
|
|
763
|
-
component: 'Card',
|
|
764
|
-
config: { padding: 16 },
|
|
765
|
-
children: [
|
|
766
|
-
{ id: 'avatar', component: 'Image', config: { src: '$props.avatarUrl' } },
|
|
767
|
-
{ id: 'name', component: 'Text', config: { value: '$props.name' } },
|
|
768
|
-
{ id: 'role', component: 'Badge', config: { value: '$props.role' } },
|
|
769
|
-
],
|
|
770
|
-
},
|
|
771
|
-
props: ['avatarUrl', 'name', 'role'],
|
|
772
|
-
},
|
|
773
|
-
StatusBadge: {
|
|
774
|
-
experience: {
|
|
775
|
-
id: 'badge-root',
|
|
776
|
-
component: 'Badge',
|
|
777
|
-
config: { variant: 'info' },
|
|
778
|
-
bindings: { value: '$props.status' },
|
|
779
|
-
},
|
|
780
|
-
props: ['status'],
|
|
781
|
-
},
|
|
782
|
-
},
|
|
783
|
-
},
|
|
784
|
-
});
|
|
785
|
-
|
|
786
|
-
const result = decompileProjectEnhanced(def);
|
|
787
|
-
|
|
788
|
-
const userCardFile = result.files.find(f => f.path === 'components/UserCard.tsx');
|
|
789
|
-
expect(userCardFile).toBeDefined();
|
|
790
|
-
expect(userCardFile!.content).toContain('UserCard');
|
|
791
|
-
expect(userCardFile!.content).toContain('UserCardProps');
|
|
792
|
-
expect(userCardFile!.content).toContain('avatarUrl');
|
|
793
|
-
expect(userCardFile!.content).toContain('name');
|
|
794
|
-
expect(userCardFile!.content).toContain('role');
|
|
795
|
-
|
|
796
|
-
const statusBadgeFile = result.files.find(f => f.path === 'components/StatusBadge.tsx');
|
|
797
|
-
expect(statusBadgeFile).toBeDefined();
|
|
798
|
-
expect(statusBadgeFile!.content).toContain('StatusBadge');
|
|
799
|
-
expect(statusBadgeFile!.content).toContain('status');
|
|
800
|
-
});
|
|
801
|
-
});
|
|
802
|
-
|
|
803
|
-
// =============================================================================
|
|
804
|
-
// 11. Model Field Options → Union Type Test
|
|
805
|
-
// =============================================================================
|
|
806
|
-
|
|
807
|
-
describe('11. Model field options → select/union type', () => {
|
|
808
|
-
it('should compile model with union types to fields in IR', () => {
|
|
809
|
-
const files: Record<string, string> = {
|
|
810
|
-
'models/vehicle.ts': `
|
|
811
|
-
/**
|
|
812
|
-
* @workflow slug="vehicle" version="1.0.0" category="data"
|
|
813
|
-
*/
|
|
814
|
-
export interface Vehicle {
|
|
815
|
-
make: string;
|
|
816
|
-
model: string;
|
|
817
|
-
year: number;
|
|
818
|
-
vehicleType: 'sedan' | 'suv' | 'truck' | 'van';
|
|
819
|
-
fuelType: 'gas' | 'electric' | 'hybrid';
|
|
820
|
-
status: 'active' | 'inactive' | 'maintenance';
|
|
821
|
-
}
|
|
822
|
-
export const transitions = {};
|
|
823
|
-
`,
|
|
824
|
-
};
|
|
825
|
-
|
|
826
|
-
const result = compileProject(files);
|
|
827
|
-
expect(result.errors).toHaveLength(0);
|
|
828
|
-
|
|
829
|
-
const fieldNames = result.ir.fields.map(f => f.name);
|
|
830
|
-
expect(fieldNames).toContain('vehicleType');
|
|
831
|
-
expect(fieldNames).toContain('fuelType');
|
|
832
|
-
expect(fieldNames).toContain('status');
|
|
833
|
-
});
|
|
834
|
-
|
|
835
|
-
it('should decompile select fields to useState with string defaults', () => {
|
|
836
|
-
const def = makeDef({
|
|
837
|
-
slug: 'select-test',
|
|
838
|
-
fields: [
|
|
839
|
-
{
|
|
840
|
-
name: 'status',
|
|
841
|
-
type: 'select',
|
|
842
|
-
required: false,
|
|
843
|
-
default_value: 'active',
|
|
844
|
-
validation: { options: ['active', 'inactive', 'archived'] },
|
|
845
|
-
},
|
|
846
|
-
{
|
|
847
|
-
name: 'priority',
|
|
848
|
-
type: 'select',
|
|
849
|
-
required: false,
|
|
850
|
-
default_value: 'medium',
|
|
851
|
-
},
|
|
852
|
-
],
|
|
853
|
-
});
|
|
854
|
-
|
|
855
|
-
const { code } = decompile(def);
|
|
856
|
-
expect(code).toContain('useState');
|
|
857
|
-
expect(code).toContain('status');
|
|
858
|
-
expect(code).toContain('"active"');
|
|
859
|
-
expect(code).toContain('priority');
|
|
860
|
-
expect(code).toContain('"medium"');
|
|
861
|
-
});
|
|
862
|
-
});
|
|
863
|
-
|
|
864
|
-
// =============================================================================
|
|
865
|
-
// 12. Full Blueprint-Uber Round-Trip Test
|
|
866
|
-
// =============================================================================
|
|
867
|
-
|
|
868
|
-
describe('12. Full blueprint-uber round-trip', () => {
|
|
869
|
-
const uberFiles = readProjectFiles(UBER_DIR);
|
|
870
|
-
|
|
871
|
-
it('should compile the full uber project', () => {
|
|
872
|
-
const result = compileProject(uberFiles);
|
|
873
|
-
|
|
874
|
-
expect(result.ir.slug).toBe('uber-rideshare');
|
|
875
|
-
expect(result.ir.fields.length).toBeGreaterThan(0);
|
|
876
|
-
expect(result.childDefinitions.length).toBeGreaterThan(0);
|
|
877
|
-
});
|
|
878
|
-
|
|
879
|
-
it('should decompile uber IR to project with multiple files', () => {
|
|
880
|
-
const compiled = compileProject(uberFiles);
|
|
881
|
-
const decompilerInput: DecompilerInput = {
|
|
882
|
-
...compiled.ir,
|
|
883
|
-
experience: (compiled.ir as any).views?.default,
|
|
884
|
-
childDefinitions: compiled.childDefinitions,
|
|
885
|
-
};
|
|
886
|
-
|
|
887
|
-
const decompiled = decompileProjectEnhanced(decompilerInput);
|
|
888
|
-
|
|
889
|
-
expect(decompiled.files.length).toBeGreaterThan(3);
|
|
890
|
-
|
|
891
|
-
const paths = decompiled.files.map(f => f.path);
|
|
892
|
-
expect(paths).toContain('main.workflow.tsx');
|
|
893
|
-
expect(paths).toContain('mm.config.ts');
|
|
894
|
-
});
|
|
895
|
-
|
|
896
|
-
it('should preserve model files with export interface declarations', () => {
|
|
897
|
-
const compiled = compileProject(uberFiles);
|
|
898
|
-
const decompilerInput: DecompilerInput = {
|
|
899
|
-
...compiled.ir,
|
|
900
|
-
experience: (compiled.ir as any).views?.default,
|
|
901
|
-
childDefinitions: compiled.childDefinitions,
|
|
902
|
-
};
|
|
903
|
-
|
|
904
|
-
const decompiled = decompileProjectEnhanced(decompilerInput);
|
|
905
|
-
const modelFiles = decompiled.files.filter(f => f.path.startsWith('models/'));
|
|
906
|
-
|
|
907
|
-
for (const model of modelFiles) {
|
|
908
|
-
expect(model.content).toContain('export interface');
|
|
909
|
-
}
|
|
910
|
-
});
|
|
911
|
-
|
|
912
|
-
it('should produce compilable main.workflow.tsx with @workflow annotation', () => {
|
|
913
|
-
const compiled = compileProject(uberFiles);
|
|
914
|
-
const decompilerInput: DecompilerInput = {
|
|
915
|
-
...compiled.ir,
|
|
916
|
-
experience: (compiled.ir as any).views?.default,
|
|
917
|
-
childDefinitions: compiled.childDefinitions,
|
|
918
|
-
};
|
|
919
|
-
|
|
920
|
-
const decompiled = decompileProjectEnhanced(decompilerInput);
|
|
921
|
-
const mainFile = decompiled.files.find(f => f.path === 'main.workflow.tsx');
|
|
922
|
-
expect(mainFile).toBeDefined();
|
|
923
|
-
|
|
924
|
-
expect(mainFile!.content).toContain('export default function');
|
|
925
|
-
expect(mainFile!.content).toContain('@workflow');
|
|
926
|
-
expect(mainFile!.content).toContain('uber-rideshare');
|
|
927
|
-
});
|
|
928
|
-
|
|
929
|
-
it('should produce child workflow files for each child definition', () => {
|
|
930
|
-
const compiled = compileProject(uberFiles);
|
|
931
|
-
const decompilerInput: DecompilerInput = {
|
|
932
|
-
...compiled.ir,
|
|
933
|
-
experience: (compiled.ir as any).views?.default,
|
|
934
|
-
childDefinitions: compiled.childDefinitions,
|
|
935
|
-
};
|
|
936
|
-
|
|
937
|
-
const decompiled = decompileProjectEnhanced(decompilerInput);
|
|
938
|
-
const workflowFiles = decompiled.files.filter(
|
|
939
|
-
f => f.path.endsWith('.workflow.tsx') && f.path !== 'main.workflow.tsx',
|
|
940
|
-
);
|
|
941
|
-
|
|
942
|
-
// Each child definition should produce a .workflow.tsx file
|
|
943
|
-
expect(workflowFiles.length).toBe(compiled.childDefinitions.length);
|
|
944
|
-
});
|
|
945
|
-
});
|
|
946
|
-
|
|
947
|
-
// =============================================================================
|
|
948
|
-
// 13. Full Blueprint-Chat Round-Trip Test
|
|
949
|
-
// =============================================================================
|
|
950
|
-
|
|
951
|
-
describe('13. Full blueprint-chat round-trip', () => {
|
|
952
|
-
const chatFiles = readProjectFiles(CHAT_DIR);
|
|
953
|
-
|
|
954
|
-
it('should read all chat blueprint files', () => {
|
|
955
|
-
expect(Object.keys(chatFiles).length).toBeGreaterThan(5);
|
|
956
|
-
expect(chatFiles['mm.config.ts']).toBeDefined();
|
|
957
|
-
});
|
|
958
|
-
|
|
959
|
-
it('should compile the full chat project without total failure', () => {
|
|
960
|
-
const result = compileProject(chatFiles);
|
|
961
|
-
|
|
962
|
-
expect(result.ir).toBeDefined();
|
|
963
|
-
expect(result.ir.fields.length + result.childDefinitions.length).toBeGreaterThan(0);
|
|
964
|
-
});
|
|
965
|
-
|
|
966
|
-
it('should decompile chat IR to project files', () => {
|
|
967
|
-
const compiled = compileProject(chatFiles);
|
|
968
|
-
const decompilerInput: DecompilerInput = {
|
|
969
|
-
...compiled.ir,
|
|
970
|
-
experience: (compiled.ir as any).views?.default,
|
|
971
|
-
childDefinitions: compiled.childDefinitions,
|
|
972
|
-
};
|
|
973
|
-
|
|
974
|
-
const decompiled = decompileProjectEnhanced(decompilerInput);
|
|
975
|
-
|
|
976
|
-
expect(decompiled.files.length).toBeGreaterThan(1);
|
|
977
|
-
const paths = decompiled.files.map(f => f.path);
|
|
978
|
-
expect(paths).toContain('main.workflow.tsx');
|
|
979
|
-
});
|
|
980
|
-
|
|
981
|
-
it('should produce model files for chat data definitions', () => {
|
|
982
|
-
const compiled = compileProject(chatFiles);
|
|
983
|
-
const decompilerInput: DecompilerInput = {
|
|
984
|
-
...compiled.ir,
|
|
985
|
-
experience: (compiled.ir as any).views?.default,
|
|
986
|
-
childDefinitions: compiled.childDefinitions,
|
|
987
|
-
};
|
|
988
|
-
|
|
989
|
-
const decompiled = decompileProjectEnhanced(decompilerInput);
|
|
990
|
-
const modelFiles = decompiled.files.filter(f => f.path.startsWith('models/'));
|
|
991
|
-
|
|
992
|
-
if (modelFiles.length > 0) {
|
|
993
|
-
for (const model of modelFiles) {
|
|
994
|
-
expect(model.content).toContain('export');
|
|
995
|
-
}
|
|
996
|
-
}
|
|
997
|
-
});
|
|
998
|
-
|
|
999
|
-
it('should produce main.workflow.tsx with export default function', () => {
|
|
1000
|
-
const compiled = compileProject(chatFiles);
|
|
1001
|
-
const decompilerInput: DecompilerInput = {
|
|
1002
|
-
...compiled.ir,
|
|
1003
|
-
experience: (compiled.ir as any).views?.default,
|
|
1004
|
-
childDefinitions: compiled.childDefinitions,
|
|
1005
|
-
};
|
|
1006
|
-
|
|
1007
|
-
const decompiled = decompileProjectEnhanced(decompilerInput);
|
|
1008
|
-
const mainFile = decompiled.files.find(f => f.path === 'main.workflow.tsx');
|
|
1009
|
-
expect(mainFile).toBeDefined();
|
|
1010
|
-
expect(mainFile!.content).toContain('export default function');
|
|
1011
|
-
});
|
|
1012
|
-
});
|
|
1013
|
-
|
|
1014
|
-
// =============================================================================
|
|
1015
|
-
// Additional: Combined workflow round-trip (all features)
|
|
1016
|
-
// =============================================================================
|
|
1017
|
-
|
|
1018
|
-
describe('Combined workflow round-trip (all features)', () => {
|
|
1019
|
-
it('should handle complete workflow with fields, states, transitions, experience, events', () => {
|
|
1020
|
-
const def = makeDef({
|
|
1021
|
-
slug: 'order-tracker',
|
|
1022
|
-
category: 'workflow',
|
|
1023
|
-
fields: [
|
|
1024
|
-
{ name: 'status', type: 'text', required: false, default_value: 'draft' },
|
|
1025
|
-
{ name: 'total', type: 'number', required: false, default_value: 0 },
|
|
1026
|
-
{ name: 'items', type: 'number', required: false, default_value: 0 },
|
|
1027
|
-
],
|
|
1028
|
-
states: [
|
|
1029
|
-
{
|
|
1030
|
-
name: 'draft',
|
|
1031
|
-
type: 'START',
|
|
1032
|
-
on_enter: [{ id: 'a1', type: 'set_field', mode: 'auto', config: { field: 'status', value: 'draft' } }],
|
|
1033
|
-
on_exit: [{ id: 'a2', type: 'log_event', mode: 'auto', config: { message: 'Leaving draft' } }],
|
|
1034
|
-
during: [],
|
|
1035
|
-
},
|
|
1036
|
-
{
|
|
1037
|
-
name: 'submitted',
|
|
1038
|
-
type: 'REGULAR',
|
|
1039
|
-
on_enter: [{ id: 'a3', type: 'log_event', mode: 'auto', config: { message: 'Order submitted' } }],
|
|
1040
|
-
on_exit: [],
|
|
1041
|
-
during: [{
|
|
1042
|
-
id: 'd1',
|
|
1043
|
-
type: 'interval',
|
|
1044
|
-
interval_ms: 10000,
|
|
1045
|
-
actions: [{ id: 'a4', type: 'log_event', mode: 'auto', config: { message: 'checking' } }],
|
|
1046
|
-
}],
|
|
1047
|
-
},
|
|
1048
|
-
{
|
|
1049
|
-
name: 'approved',
|
|
1050
|
-
type: 'END',
|
|
1051
|
-
on_enter: [],
|
|
1052
|
-
on_exit: [],
|
|
1053
|
-
during: [],
|
|
1054
|
-
},
|
|
1055
|
-
],
|
|
1056
|
-
transitions: [
|
|
1057
|
-
{ name: 'submit', from: ['draft'], to: 'submitted', actions: [], required_fields: ['total'] },
|
|
1058
|
-
{ name: 'approve', from: ['submitted'], to: 'approved', actions: [], roles: ['admin'] },
|
|
1059
|
-
{ name: 'reject', from: ['submitted'], to: 'draft', actions: [], roles: ['admin'] },
|
|
1060
|
-
],
|
|
1061
|
-
roles: [
|
|
1062
|
-
{ name: 'admin', permissions: ['approve', 'reject'] },
|
|
1063
|
-
{ name: 'submitter', permissions: ['submit'] },
|
|
1064
|
-
],
|
|
1065
|
-
on_event: [
|
|
1066
|
-
{ match: 'order.updated', actions: [{ type: 'set_field', field: 'status', expression: '"updated"' }] },
|
|
1067
|
-
],
|
|
1068
|
-
experience: {
|
|
1069
|
-
id: 'root',
|
|
1070
|
-
component: 'Stack',
|
|
1071
|
-
config: { gap: 16 },
|
|
1072
|
-
children: [
|
|
1073
|
-
{ id: 'h', component: 'Heading', config: { value: 'Order Tracker', level: 2 } },
|
|
1074
|
-
{ id: 'st', component: 'Text', bindings: { value: '$local.status' } },
|
|
1075
|
-
{
|
|
1076
|
-
id: 'actions',
|
|
1077
|
-
component: 'Row',
|
|
1078
|
-
config: { gap: 8 },
|
|
1079
|
-
children: [
|
|
1080
|
-
{ id: 'btn-submit', component: 'Button', config: { label: 'Submit' } },
|
|
1081
|
-
{ id: 'btn-approve', component: 'Button', config: { label: 'Approve' } },
|
|
1082
|
-
],
|
|
1083
|
-
},
|
|
1084
|
-
],
|
|
1085
|
-
},
|
|
1086
|
-
});
|
|
1087
|
-
|
|
1088
|
-
const result = validateRoundTrip(def);
|
|
1089
|
-
expect(result.roundTrippedIR).not.toBeNull();
|
|
1090
|
-
|
|
1091
|
-
// Structural elements preserved
|
|
1092
|
-
expect(result.roundTrippedIR!.slug).toBe('order-tracker');
|
|
1093
|
-
expect(result.roundTrippedIR!.fields.length).toBeGreaterThanOrEqual(3);
|
|
1094
|
-
expect(result.roundTrippedIR!.transitions.length).toBe(3);
|
|
1095
|
-
|
|
1096
|
-
// Transition details
|
|
1097
|
-
const submit = result.roundTrippedIR!.transitions.find(t => t.name === 'submit');
|
|
1098
|
-
expect(submit).toBeDefined();
|
|
1099
|
-
expect(submit!.to).toBe('submitted');
|
|
1100
|
-
expect(submit!.required_fields).toEqual(expect.arrayContaining(['total']));
|
|
1101
|
-
|
|
1102
|
-
const approve = result.roundTrippedIR!.transitions.find(t => t.name === 'approve');
|
|
1103
|
-
expect(approve).toBeDefined();
|
|
1104
|
-
expect(approve!.roles).toContain('admin');
|
|
1105
|
-
|
|
1106
|
-
// State effects
|
|
1107
|
-
const draftState = result.roundTrippedIR!.states.find(s => s.name === 'draft');
|
|
1108
|
-
expect(draftState).toBeDefined();
|
|
1109
|
-
expect(draftState!.on_enter.length).toBeGreaterThan(0);
|
|
1110
|
-
expect(draftState!.on_exit.length).toBeGreaterThan(0);
|
|
1111
|
-
|
|
1112
|
-
const submittedState = result.roundTrippedIR!.states.find(s => s.name === 'submitted');
|
|
1113
|
-
expect(submittedState).toBeDefined();
|
|
1114
|
-
expect(submittedState!.on_enter.length).toBeGreaterThan(0);
|
|
1115
|
-
expect(submittedState!.during.length).toBeGreaterThan(0);
|
|
1116
|
-
|
|
1117
|
-
// No critical errors
|
|
1118
|
-
const errors = result.diffs.filter(d => d.severity === 'error');
|
|
1119
|
-
expect(errors).toEqual([]);
|
|
1120
|
-
});
|
|
1121
|
-
|
|
1122
|
-
it('should produce decompiled TSX with all hook types', () => {
|
|
1123
|
-
const def = makeDef({
|
|
1124
|
-
slug: 'full-hooks',
|
|
1125
|
-
fields: [{ name: 'count', type: 'number', required: false, default_value: 0 }],
|
|
1126
|
-
states: [{
|
|
1127
|
-
name: 'active',
|
|
1128
|
-
type: 'REGULAR',
|
|
1129
|
-
on_enter: [{ id: 'a1', type: 'set_field', mode: 'auto', config: { field: 'count', value: 1 } }],
|
|
1130
|
-
on_exit: [{ id: 'a2', type: 'log_event', mode: 'auto', config: { message: 'exit' } }],
|
|
1131
|
-
during: [{
|
|
1132
|
-
id: 'd1',
|
|
1133
|
-
type: 'interval',
|
|
1134
|
-
interval_ms: 5000,
|
|
1135
|
-
actions: [{ id: 'a3', type: 'log_event', mode: 'auto', config: { message: 'tick' } }],
|
|
1136
|
-
}],
|
|
1137
|
-
}],
|
|
1138
|
-
transitions: [{ name: 'start', from: ['idle'], to: 'active', actions: [] }],
|
|
1139
|
-
metadata: {
|
|
1140
|
-
fieldWatchers: [{
|
|
1141
|
-
id: 'w1',
|
|
1142
|
-
field: 'count',
|
|
1143
|
-
actions: [{ id: 'wa1', type: 'log_event', mode: 'auto', config: { message: 'changed' } }],
|
|
1144
|
-
}],
|
|
1145
|
-
},
|
|
1146
|
-
on_event: [
|
|
1147
|
-
{ match: 'tick', actions: [{ type: 'log_event', field: '', expression: '' }] },
|
|
1148
|
-
],
|
|
1149
|
-
experience: {
|
|
1150
|
-
id: 'root',
|
|
1151
|
-
component: 'Stack',
|
|
1152
|
-
children: [
|
|
1153
|
-
{ id: 't', component: 'Text', bindings: { value: '$local.count' } },
|
|
1154
|
-
],
|
|
1155
|
-
},
|
|
1156
|
-
});
|
|
1157
|
-
|
|
1158
|
-
const { code } = decompile(def);
|
|
1159
|
-
|
|
1160
|
-
expect(code).toContain('useState');
|
|
1161
|
-
expect(code).toContain('useOnEnter');
|
|
1162
|
-
expect(code).toContain('useOnExit');
|
|
1163
|
-
expect(code).toContain('useWhileIn');
|
|
1164
|
-
expect(code).toContain('useTransition');
|
|
1165
|
-
expect(code).toContain('useOnChange');
|
|
1166
|
-
expect(code).toContain('useOnEvent');
|
|
1167
|
-
});
|
|
1168
|
-
});
|
|
1169
|
-
|
|
1170
|
-
// =============================================================================
|
|
1171
|
-
// Additional: Project decompiler assigns correct file roles
|
|
1172
|
-
// =============================================================================
|
|
1173
|
-
|
|
1174
|
-
describe('Project decompiler file roles', () => {
|
|
1175
|
-
it('should assign correct roles to all decompiled files', () => {
|
|
1176
|
-
const def = makeDef({
|
|
1177
|
-
slug: 'role-test',
|
|
1178
|
-
category: 'blueprint',
|
|
1179
|
-
fields: Array.from({ length: 12 }, (_, i) => ({
|
|
1180
|
-
name: `field_${i}`,
|
|
1181
|
-
type: 'text' as const,
|
|
1182
|
-
required: false,
|
|
1183
|
-
default_value: '',
|
|
1184
|
-
})),
|
|
1185
|
-
states: Array.from({ length: 5 }, (_, i) => ({
|
|
1186
|
-
name: `state_${i}`,
|
|
1187
|
-
type: (i === 0 ? 'START' : 'REGULAR') as 'START' | 'REGULAR',
|
|
1188
|
-
description: '',
|
|
1189
|
-
on_enter: [],
|
|
1190
|
-
on_exit: [],
|
|
1191
|
-
during: [],
|
|
1192
|
-
})),
|
|
1193
|
-
transitions: [
|
|
1194
|
-
{ name: 'go', from: ['state_0'], to: 'state_1', actions: [] },
|
|
1195
|
-
],
|
|
1196
|
-
});
|
|
1197
|
-
|
|
1198
|
-
const result = decompileProjectEnhanced(def);
|
|
1199
|
-
|
|
1200
|
-
const mainFile = result.files.find(f => f.path === 'main.workflow.tsx');
|
|
1201
|
-
expect(mainFile).toBeDefined();
|
|
1202
|
-
expect(mainFile!.role).toBe('view-entry');
|
|
1203
|
-
|
|
1204
|
-
const configFile = result.files.find(f => f.path === 'mm.config.ts');
|
|
1205
|
-
expect(configFile).toBeDefined();
|
|
1206
|
-
expect(configFile!.role).toBe('config');
|
|
1207
|
-
|
|
1208
|
-
const modelFile = result.files.find(f => f.path.startsWith('models/'));
|
|
1209
|
-
expect(modelFile).toBeDefined();
|
|
1210
|
-
expect(modelFile!.role).toBe('model');
|
|
1211
|
-
});
|
|
1212
|
-
});
|