@divmain/jdm-asm 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/ci.yml +53 -0
- package/.oxfmtrc.json +16 -0
- package/.oxlintrc.json +183 -0
- package/AGENTS.md +81 -0
- package/README.md +769 -0
- package/asconfig.json +23 -0
- package/benchmarks/fixtures.ts +111 -0
- package/benchmarks/input-fixtures.ts +80 -0
- package/benchmarks/run.ts +913 -0
- package/benchmarks/worker-pool.ts +223 -0
- package/benchmarks/worker.ts +374 -0
- package/dist/index.d.ts +996 -0
- package/dist/index.js +12239 -0
- package/dist/index.js.map +1 -0
- package/package.json +49 -0
- package/scripts/run-all-tests.ts +220 -0
- package/src/compiler/EXPRESSION_SUBSETS.md +228 -0
- package/src/compiler/asc-compiler.ts +315 -0
- package/src/compiler/ast-types.ts +215 -0
- package/src/compiler/build.ts +56 -0
- package/src/compiler/cache.ts +414 -0
- package/src/compiler/code-generators.ts +211 -0
- package/src/compiler/codegen/index.ts +15 -0
- package/src/compiler/codegen/js-marshal.ts +999 -0
- package/src/compiler/codegen/js-validation.ts +243 -0
- package/src/compiler/codegen.ts +19 -0
- package/src/compiler/compile-time-validation.ts +507 -0
- package/src/compiler/cst-visitor.ts +434 -0
- package/src/compiler/errors.ts +227 -0
- package/src/compiler/expression-parser.ts +536 -0
- package/src/compiler/graph.ts +197 -0
- package/src/compiler/index.ts +199 -0
- package/src/compiler/input-validation.ts +33 -0
- package/src/compiler/marshal-gen.ts +21 -0
- package/src/compiler/nodes/context-resolvers.ts +197 -0
- package/src/compiler/nodes/decision-table.ts +507 -0
- package/src/compiler/nodes/decision.ts +292 -0
- package/src/compiler/nodes/expression-compiler.ts +526 -0
- package/src/compiler/nodes/expression.ts +425 -0
- package/src/compiler/nodes/function.ts +316 -0
- package/src/compiler/nodes/input.ts +60 -0
- package/src/compiler/nodes/switch.ts +547 -0
- package/src/compiler/optimizer.ts +948 -0
- package/src/compiler/orchestrator.ts +352 -0
- package/src/compiler/parser.ts +115 -0
- package/src/compiler/result-selection.ts +161 -0
- package/src/compiler/runtime/index.ts +26 -0
- package/src/compiler/runtime-codegen.ts +211 -0
- package/src/compiler/runtime-validation-codegen.ts +294 -0
- package/src/compiler/runtime.ts +452 -0
- package/src/compiler/schema.ts +245 -0
- package/src/compiler/switch-branch-detection.ts +92 -0
- package/src/compiler/types.ts +136 -0
- package/src/compiler/unary-ast-transforms.ts +148 -0
- package/src/compiler/unary-parser.ts +301 -0
- package/src/compiler/unary-transform.ts +161 -0
- package/src/compiler/utils.ts +27 -0
- package/src/compiler/virtual-fs.ts +90 -0
- package/src/compiler/wasm-instantiate.ts +127 -0
- package/src/index.ts +1 -0
- package/src/runtime/arrays.ts +579 -0
- package/src/runtime/context.ts +189 -0
- package/src/runtime/expressions.ts +1811 -0
- package/src/runtime/index.ts +8 -0
- package/src/runtime/memory.ts +607 -0
- package/src/runtime/strings.ts +260 -0
- package/src/runtime/tables.ts +96 -0
- package/src/runtime/tsconfig.json +4 -0
- package/src/runtime/values.ts +209 -0
- package/test-data/README.md +83 -0
- package/test-data/decision-tables/basic/8k.json +87992 -0
- package/test-data/decision-tables/basic/affiliate-commission-calculator.json +228 -0
- package/test-data/decision-tables/basic/airline-loyalty-points-calculations.json +285 -0
- package/test-data/decision-tables/basic/airline-upgrade-eligibility.json +466 -0
- package/test-data/decision-tables/basic/auto-insurance-premium-calculator.json +412 -0
- package/test-data/decision-tables/basic/booking-personalization-system.json +553 -0
- package/test-data/decision-tables/basic/care-team-assignment-system.json +585 -0
- package/test-data/decision-tables/basic/claim-validation-system.json +307 -0
- package/test-data/decision-tables/basic/clinical-lab-result-interpreter.json +433 -0
- package/test-data/decision-tables/basic/clinical-treatment-protocol.json +474 -0
- package/test-data/decision-tables/basic/credit-limit-adjustment.json +479 -0
- package/test-data/decision-tables/basic/customer-eligibility-engine.json +551 -0
- package/test-data/decision-tables/basic/customer-lifetime-value.json +200 -0
- package/test-data/decision-tables/basic/customer-onboarding-kyc-verification.json +611 -0
- package/test-data/decision-tables/basic/customer-service-escalation.json +191 -0
- package/test-data/decision-tables/basic/decision-table-discounts.json +168 -0
- package/test-data/decision-tables/basic/decision-table-shipping.json +398 -0
- package/test-data/decision-tables/basic/delivery-route-optimizer.json +271 -0
- package/test-data/decision-tables/basic/device-compatibility-checker.json +303 -0
- package/test-data/decision-tables/basic/disaster-relief-fund-allocation.json +296 -0
- package/test-data/decision-tables/basic/dynamic-fx-rate-pricing-system.json +237 -0
- package/test-data/decision-tables/basic/dynamic-marketplace-comission-calculator.json +242 -0
- package/test-data/decision-tables/basic/dynamic-shipping-cost-calculator.json +378 -0
- package/test-data/decision-tables/basic/dynamic-tarrif-engine.json +289 -0
- package/test-data/decision-tables/basic/dynamic-ticket-pricing.json +325 -0
- package/test-data/decision-tables/basic/empty-column-with-space.json +100 -0
- package/test-data/decision-tables/basic/empty-column-without-space.json +100 -0
- package/test-data/decision-tables/basic/environment-compliance-assessment.json +386 -0
- package/test-data/decision-tables/basic/expression-table-map.json +313 -0
- package/test-data/decision-tables/basic/flash-sale-eligibility.json +366 -0
- package/test-data/decision-tables/basic/flight-dispatch-decision-system.json +455 -0
- package/test-data/decision-tables/basic/flight-rebooking-fee-calculator.json +406 -0
- package/test-data/decision-tables/basic/government-assistance.json +299 -0
- package/test-data/decision-tables/basic/grant-funding-distribution.json +307 -0
- package/test-data/decision-tables/basic/hazardous-materials-management-system.json +414 -0
- package/test-data/decision-tables/basic/immigration-eligibility-evaluator.json +765 -0
- package/test-data/decision-tables/basic/import-duties-calculator.json +318 -0
- package/test-data/decision-tables/basic/insurance-agent-commission.json +228 -0
- package/test-data/decision-tables/basic/insurance-coverage-calculator.json +362 -0
- package/test-data/decision-tables/basic/insurance-underwriting-risk.json +321 -0
- package/test-data/decision-tables/basic/international-roaming-policy-manager.json +199 -0
- package/test-data/decision-tables/basic/legacy-plan-management.json +434 -0
- package/test-data/decision-tables/basic/marketplace-listing-verification-system.json +334 -0
- package/test-data/decision-tables/basic/medication-dosage-calculator.json +318 -0
- package/test-data/decision-tables/basic/merch-bags.json +171 -0
- package/test-data/decision-tables/basic/municipal-permit-evaluation-system.json +364 -0
- package/test-data/decision-tables/basic/mvno-partner-enablement.json +313 -0
- package/test-data/decision-tables/basic/partner-revenue-sharing.json +244 -0
- package/test-data/decision-tables/basic/payment-routing-and-fee-calculator.json +475 -0
- package/test-data/decision-tables/basic/policy-discount-calculator.json +307 -0
- package/test-data/decision-tables/basic/policy-eligibility-analyzer.json +299 -0
- package/test-data/decision-tables/basic/product-listing-scoring.json +358 -0
- package/test-data/decision-tables/basic/realtime-fraud-detection.json +235 -0
- package/test-data/decision-tables/basic/regional-compliance-manager.json +278 -0
- package/test-data/decision-tables/basic/returns-and-refund-policy.json +366 -0
- package/test-data/decision-tables/basic/returns-processing-system.json +448 -0
- package/test-data/decision-tables/basic/school-district-resource-allocation.json +282 -0
- package/test-data/decision-tables/basic/seat-map-optimization.json +325 -0
- package/test-data/decision-tables/basic/seller-fee-calculator.json +307 -0
- package/test-data/decision-tables/basic/service-level-agreement-enforcement.json +575 -0
- package/test-data/decision-tables/basic/smart-financial-product-matcher.json +249 -0
- package/test-data/decision-tables/basic/supply-chain-risk.json +316 -0
- package/test-data/decision-tables/basic/table-loop.json +93 -0
- package/test-data/decision-tables/basic/table.json +76 -0
- package/test-data/decision-tables/basic/traffic-violation-penalty-calculator.json +436 -0
- package/test-data/decision-tables/basic/transaction-compliance-classifier.json +525 -0
- package/test-data/decision-tables/basic/vehicle-claims-resolution.json +310 -0
- package/test-data/decision-tables/basic/warehouse-storage-location.json +345 -0
- package/test-data/decision-tables/hit-policy-collect/collect-multiple-matches.json +127 -0
- package/test-data/decision-tables/hit-policy-collect/collect-no-match.json +95 -0
- package/test-data/decision-tables/hit-policy-first/first-match.json +103 -0
- package/test-data/decision-tables/hit-policy-first/no-match.json +95 -0
- package/test-data/decision-tables/hit-policy-output-order/output-order-respected.json +94 -0
- package/test-data/decision-tables/hit-policy-output-order/string-output-order.json +94 -0
- package/test-data/decision-tables/hit-policy-priority/priority-respected.json +86 -0
- package/test-data/decision-tables/hit-policy-rule-order/rule-order-respected.json +94 -0
- package/test-data/decision-tables/hit-policy-unique/all-match-error.json +89 -0
- package/test-data/decision-tables/hit-policy-unique/multiple-match-error.json +89 -0
- package/test-data/decision-tables/hit-policy-unique/no-match.json +88 -0
- package/test-data/decision-tables/hit-policy-unique/unique-match.json +99 -0
- package/test-data/expressions/arithmetic/error-cyclic.json +114 -0
- package/test-data/expressions/arithmetic/error-missing-input.json +54 -0
- package/test-data/expressions/arithmetic/error-missing-output.json +54 -0
- package/test-data/expressions/arithmetic/expression-default.json +93 -0
- package/test-data/expressions/arithmetic/expression-fields.json +94 -0
- package/test-data/expressions/arithmetic/expression-loop.json +94 -0
- package/test-data/expressions/arithmetic/expression-passthrough.json +108 -0
- package/test-data/expressions/arithmetic/expression.json +69 -0
- package/test-data/expressions/arithmetic/nested-request.json +125 -0
- package/test-data/expressions/arithmetic/number-function.json +58 -0
- package/test-data/expressions/arithmetic/test-number-functions.json +68 -0
- package/test-data/expressions/functions/all.json +149 -0
- package/test-data/expressions/functions/avg.json +89 -0
- package/test-data/expressions/functions/filter.json +109 -0
- package/test-data/expressions/functions/flat.json +167 -0
- package/test-data/expressions/functions/map-strings.json +65 -0
- package/test-data/expressions/functions/map.json +73 -0
- package/test-data/expressions/functions/reduce.json +49 -0
- package/test-data/expressions/functions/some.json +175 -0
- package/test-data/expressions/functions/sort-strings.json +97 -0
- package/test-data/expressions/functions/sort.json +97 -0
- package/test-data/expressions/logical/logical-and.json +116 -0
- package/test-data/expressions/logical/logical-complex.json +260 -0
- package/test-data/expressions/logical/logical-not.json +111 -0
- package/test-data/expressions/logical/logical-or.json +123 -0
- package/test-data/expressions/string/string-comparison.json +128 -0
- package/test-data/expressions/string/string-concat.json +106 -0
- package/test-data/expressions/string/string-contains.json +125 -0
- package/test-data/expressions/string/string-endsWith.json +113 -0
- package/test-data/expressions/string/string-indexOf.json +131 -0
- package/test-data/expressions/string/string-join.json +92 -0
- package/test-data/expressions/string/string-lower.json +94 -0
- package/test-data/expressions/string/string-replace.json +130 -0
- package/test-data/expressions/string/string-split.json +101 -0
- package/test-data/expressions/string/string-startsWith.json +113 -0
- package/test-data/expressions/string/string-substring.json +138 -0
- package/test-data/expressions/string/string-trim.json +100 -0
- package/test-data/expressions/string/string-upper.json +94 -0
- package/test-data/other/custom.json +51 -0
- package/test-data/other/customer-input-schema.json +34 -0
- package/test-data/other/customer-output-schema.json +34 -0
- package/test-data/other/passthrough.json +31 -0
- package/test-data/sub-decisions/basic/$nodes-child.json +31 -0
- package/test-data/sub-decisions/basic/$nodes-parent.json +49 -0
- package/test-data/sub-decisions/basic/recursive-table1.json +49 -0
- package/test-data/sub-decisions/basic/recursive-table2.json +49 -0
- package/test-data/sub-decisions/complex-multi/approval-decision.json +31 -0
- package/test-data/sub-decisions/complex-multi/complex-dag.json +175 -0
- package/test-data/sub-decisions/complex-multi/credit-check.json +31 -0
- package/test-data/sub-decisions/complex-multi/customer-segmentation.json +31 -0
- package/test-data/sub-decisions/complex-multi/discount-eligibility.json +31 -0
- package/test-data/sub-decisions/complex-multi/eligibility-check.json +31 -0
- package/test-data/sub-decisions/complex-multi/final-offer.json +31 -0
- package/test-data/sub-decisions/complex-multi/income-verification.json +31 -0
- package/test-data/sub-decisions/complex-multi/linear-chain.json +121 -0
- package/test-data/sub-decisions/complex-multi/pricing-calculation.json +31 -0
- package/test-data/sub-decisions/complex-multi/product-eligibility.json +31 -0
- package/test-data/sub-decisions/complex-multi/risk-assessment.json +31 -0
- package/test-data/sub-decisions/complex-multi/shared-validation.json +31 -0
- package/test-data/sub-decisions/complex-multi/validation.json +31 -0
- package/test-data/sub-decisions/diamond/decision-a.json +31 -0
- package/test-data/sub-decisions/diamond/decision-b.json +31 -0
- package/test-data/sub-decisions/diamond/decision-c.json +31 -0
- package/test-data/sub-decisions/diamond/decision-shared.json +31 -0
- package/test-data/sub-decisions/diamond/diamond-pattern.json +109 -0
- package/test-data/sub-decisions/error-propagation/parent-calls-error.json +44 -0
- package/test-data/sub-decisions/error-propagation/sub-decision-with-error.json +60 -0
- package/test-data/switch-nodes/basic/account-dormancy-management.json +245 -0
- package/test-data/switch-nodes/basic/application-risk-assessment.json +474 -0
- package/test-data/switch-nodes/basic/cellular-data-rollover-system.json +281 -0
- package/test-data/switch-nodes/basic/clinical-pathway-selection.json +454 -0
- package/test-data/switch-nodes/basic/insurance-prior-authorization.json +467 -0
- package/test-data/switch-nodes/basic/last-mile-delivery-assignment.json +373 -0
- package/test-data/switch-nodes/basic/loan-approval.json +469 -0
- package/test-data/switch-nodes/basic/multi-switch.json +498 -0
- package/test-data/switch-nodes/basic/online-checkin-eligibility.json +285 -0
- package/test-data/switch-nodes/basic/order-consolidation-system.json +493 -0
- package/test-data/switch-nodes/basic/seller-approval-workflow.json +383 -0
- package/test-data/switch-nodes/basic/set-fee.json +243 -0
- package/test-data/switch-nodes/basic/shipping-carrier-selector.json +379 -0
- package/test-data/switch-nodes/basic/switch-node.json +167 -0
- package/test-data/switch-nodes/basic/switch-performance-2.json +1307 -0
- package/test-data/switch-nodes/basic/switch-performance.json +691 -0
- package/test-data/switch-nodes/basic/tax-exemption.json +295 -0
- package/test-data/switch-nodes/basic/warehouse-cross-docking.json +313 -0
- package/test-data/switch-nodes/default-cases/switch-with-default.json +134 -0
- package/test-data/zen-reference/$nodes-child.json +69 -0
- package/test-data/zen-reference/$nodes-parent.json +34 -0
- package/test-data/zen-reference/8k.json +87992 -0
- package/test-data/zen-reference/credit-analysis.json +324 -0
- package/test-data/zen-reference/custom.json +51 -0
- package/test-data/zen-reference/customer-input-schema.json +34 -0
- package/test-data/zen-reference/customer-output-schema.json +34 -0
- package/test-data/zen-reference/error-cyclic.json +114 -0
- package/test-data/zen-reference/error-missing-input.json +54 -0
- package/test-data/zen-reference/error-missing-output.json +54 -0
- package/test-data/zen-reference/expression.json +69 -0
- package/test-data/zen-reference/function-v2.json +48 -0
- package/test-data/zen-reference/function.json +46 -0
- package/test-data/zen-reference/graphs/account-dormancy-management.json +245 -0
- package/test-data/zen-reference/graphs/affiliate-commission-calculator.json +228 -0
- package/test-data/zen-reference/graphs/airline-loyalty-points-calculations.json +285 -0
- package/test-data/zen-reference/graphs/airline-upgrade-eligibility.json +466 -0
- package/test-data/zen-reference/graphs/aml.json +537 -0
- package/test-data/zen-reference/graphs/application-risk-assessment.json +474 -0
- package/test-data/zen-reference/graphs/auto-insurance-premium-calculator.json +412 -0
- package/test-data/zen-reference/graphs/booking-personalization-system.json +553 -0
- package/test-data/zen-reference/graphs/care-team-assignment-system.json +585 -0
- package/test-data/zen-reference/graphs/cellular-data-rollover-system.json +281 -0
- package/test-data/zen-reference/graphs/claim-validation-system.json +307 -0
- package/test-data/zen-reference/graphs/clinical-lab-result-interpreter.json +433 -0
- package/test-data/zen-reference/graphs/clinical-pathway-selection.json +454 -0
- package/test-data/zen-reference/graphs/clinical-treatment-protocol.json +474 -0
- package/test-data/zen-reference/graphs/company-analysis.json +390 -0
- package/test-data/zen-reference/graphs/credit-limit-adjustment.json +479 -0
- package/test-data/zen-reference/graphs/customer-eligibility-engine.json +551 -0
- package/test-data/zen-reference/graphs/customer-lifetime-value.json +200 -0
- package/test-data/zen-reference/graphs/customer-onboarding-kyc-verification.json +611 -0
- package/test-data/zen-reference/graphs/customer-service-escalation.json +191 -0
- package/test-data/zen-reference/graphs/decision-table-discounts.json +168 -0
- package/test-data/zen-reference/graphs/decision-table-shipping.json +398 -0
- package/test-data/zen-reference/graphs/delivery-route-optimizer.json +271 -0
- package/test-data/zen-reference/graphs/device-compatibility-checker.json +303 -0
- package/test-data/zen-reference/graphs/disaster-relief-fund-allocation.json +296 -0
- package/test-data/zen-reference/graphs/dynamic-fx-rate-pricing-system.json +237 -0
- package/test-data/zen-reference/graphs/dynamic-marketplace-comission-calculator.json +242 -0
- package/test-data/zen-reference/graphs/dynamic-shipping-cost-calculator.json +378 -0
- package/test-data/zen-reference/graphs/dynamic-tarrif-engine.json +289 -0
- package/test-data/zen-reference/graphs/dynamic-ticket-pricing.json +325 -0
- package/test-data/zen-reference/graphs/empty-column-with-space.json +100 -0
- package/test-data/zen-reference/graphs/empty-column-without-space.json +100 -0
- package/test-data/zen-reference/graphs/environment-compliance-assessment.json +386 -0
- package/test-data/zen-reference/graphs/expression-default.json +93 -0
- package/test-data/zen-reference/graphs/expression-fields.json +94 -0
- package/test-data/zen-reference/graphs/expression-loop.json +94 -0
- package/test-data/zen-reference/graphs/expression-passthrough.json +108 -0
- package/test-data/zen-reference/graphs/expression-table-map.json +313 -0
- package/test-data/zen-reference/graphs/flash-sale-eligibility.json +366 -0
- package/test-data/zen-reference/graphs/flight-dispatch-decision-system.json +455 -0
- package/test-data/zen-reference/graphs/flight-rebooking-fee-calculator.json +406 -0
- package/test-data/zen-reference/graphs/government-assistance.json +299 -0
- package/test-data/zen-reference/graphs/grant-funding-distribution.json +307 -0
- package/test-data/zen-reference/graphs/hazardous-materials-management-system.json +414 -0
- package/test-data/zen-reference/graphs/immigration-eligibility-evaluator.json +765 -0
- package/test-data/zen-reference/graphs/import-duties-calculator.json +318 -0
- package/test-data/zen-reference/graphs/insurance-agent-commission.json +228 -0
- package/test-data/zen-reference/graphs/insurance-breakdown.json +421 -0
- package/test-data/zen-reference/graphs/insurance-coverage-calculator.json +362 -0
- package/test-data/zen-reference/graphs/insurance-prior-authorization.json +467 -0
- package/test-data/zen-reference/graphs/insurance-underwriting-risk.json +321 -0
- package/test-data/zen-reference/graphs/international-roaming-policy-manager.json +199 -0
- package/test-data/zen-reference/graphs/last-mile-delivery-assignment.json +373 -0
- package/test-data/zen-reference/graphs/legacy-plan-management.json +434 -0
- package/test-data/zen-reference/graphs/loan-approval.json +469 -0
- package/test-data/zen-reference/graphs/marketplace-listing-verification-system.json +334 -0
- package/test-data/zen-reference/graphs/medication-dosage-calculator.json +318 -0
- package/test-data/zen-reference/graphs/merch-bags.json +171 -0
- package/test-data/zen-reference/graphs/multi-switch.json +498 -0
- package/test-data/zen-reference/graphs/municipal-permit-evaluation-system.json +364 -0
- package/test-data/zen-reference/graphs/mvno-partner-enablement.json +313 -0
- package/test-data/zen-reference/graphs/nested-request.json +125 -0
- package/test-data/zen-reference/graphs/online-checkin-eligibility.json +285 -0
- package/test-data/zen-reference/graphs/order-consolidation-system.json +493 -0
- package/test-data/zen-reference/graphs/partner-revenue-sharing.json +244 -0
- package/test-data/zen-reference/graphs/payment-routing-and-fee-calculator.json +475 -0
- package/test-data/zen-reference/graphs/policy-discount-calculator.json +307 -0
- package/test-data/zen-reference/graphs/policy-eligibility-analyzer.json +299 -0
- package/test-data/zen-reference/graphs/product-listing-scoring.json +358 -0
- package/test-data/zen-reference/graphs/realtime-fraud-detection.json +235 -0
- package/test-data/zen-reference/graphs/regional-compliance-manager.json +278 -0
- package/test-data/zen-reference/graphs/returns-and-refund-policy.json +366 -0
- package/test-data/zen-reference/graphs/returns-processing-system.json +448 -0
- package/test-data/zen-reference/graphs/school-district-resource-allocation.json +282 -0
- package/test-data/zen-reference/graphs/seat-map-optimization.json +325 -0
- package/test-data/zen-reference/graphs/seller-approval-workflow.json +383 -0
- package/test-data/zen-reference/graphs/seller-fee-calculator.json +307 -0
- package/test-data/zen-reference/graphs/service-level-agreement-enforcement.json +575 -0
- package/test-data/zen-reference/graphs/set-fee.json +243 -0
- package/test-data/zen-reference/graphs/shipping-carrier-selector.json +379 -0
- package/test-data/zen-reference/graphs/smart-financial-product-matcher.json +249 -0
- package/test-data/zen-reference/graphs/supply-chain-risk.json +316 -0
- package/test-data/zen-reference/graphs/table-loop.json +93 -0
- package/test-data/zen-reference/graphs/tax-exemption.json +295 -0
- package/test-data/zen-reference/graphs/traffic-violation-penalty-calculator.json +436 -0
- package/test-data/zen-reference/graphs/transaction-compliance-classifier.json +525 -0
- package/test-data/zen-reference/graphs/vehicle-claims-resolution.json +310 -0
- package/test-data/zen-reference/graphs/warehouse-cross-docking.json +313 -0
- package/test-data/zen-reference/graphs/warehouse-storage-location.json +345 -0
- package/test-data/zen-reference/http-function.json +34 -0
- package/test-data/zen-reference/infinite-function.json +46 -0
- package/test-data/zen-reference/js/imports.js +25 -0
- package/test-data/zen-reference/passthrough.json +31 -0
- package/test-data/zen-reference/recursive-table1.json +49 -0
- package/test-data/zen-reference/recursive-table2.json +49 -0
- package/test-data/zen-reference/sleep-function.json +34 -0
- package/test-data/zen-reference/switch-node.json +167 -0
- package/test-data/zen-reference/switch-performance-2.json +1307 -0
- package/test-data/zen-reference/switch-performance.json +691 -0
- package/test-data/zen-reference/table.json +76 -0
- package/tests/helpers/index.ts +73 -0
- package/tests/helpers/mock-context.ts +231 -0
- package/tests/helpers/round-trip.ts +398 -0
- package/tests/helpers/test-harness-comparison.ts +325 -0
- package/tests/helpers/test-harness-wasm.ts +710 -0
- package/tests/helpers/test-harness.ts +28 -0
- package/tests/helpers/wasm-test.ts +659 -0
- package/tests/integration/compilation-errors.test.ts +864 -0
- package/tests/integration/decision-tables.test.ts +531 -0
- package/tests/integration/edge-cases.test.ts +787 -0
- package/tests/integration/expressions.test.ts +513 -0
- package/tests/integration/function-node-integration.test.ts +182 -0
- package/tests/integration/sub-decisions.test.ts +108 -0
- package/tests/integration/switch-nodes.test.ts +399 -0
- package/tests/integration/unary-or-matching.test.ts +53 -0
- package/tests/integration/wasm-data-types.test.ts +398 -0
- package/tests/integration/wasm-errors.test.ts +199 -0
- package/tests/integration/wasm-execution.test.ts +348 -0
- package/tests/integration/wasm-memory.test.ts +228 -0
- package/tests/scripts/analyze-coverage.ts +166 -0
- package/tests/scripts/categorize-tests.ts +396 -0
- package/tests/scripts/coverage-analysis.ts +836 -0
- package/tests/unit/compiler/cache.test.ts +238 -0
- package/tests/unit/compiler/errors.test.ts +316 -0
- package/tests/unit/compiler/graph-scalability.test.ts +510 -0
- package/tests/unit/compiler/graph.test.ts +878 -0
- package/tests/unit/compiler/input-validation.test.ts +447 -0
- package/tests/unit/compiler/logical-and-parser.test.ts +143 -0
- package/tests/unit/compiler/logical-not-parser.test.ts +107 -0
- package/tests/unit/compiler/logical-or-parser.test.ts +236 -0
- package/tests/unit/compiler/marshal-gen/marshal-gen.test.ts +97 -0
- package/tests/unit/compiler/nodes/decision-table.test.ts +103 -0
- package/tests/unit/compiler/nodes/decision.test.ts +182 -0
- package/tests/unit/compiler/nodes/function-compile.test.ts +204 -0
- package/tests/unit/compiler/nodes/function.test.ts +176 -0
- package/tests/unit/compiler/nodes/input.test.ts +30 -0
- package/tests/unit/compiler/nodes/switch.test.ts +127 -0
- package/tests/unit/compiler/optimizer-cache.test.ts +327 -0
- package/tests/unit/compiler/optimizer-implementation.test.ts +625 -0
- package/tests/unit/compiler/parser.test.ts +508 -0
- package/tests/unit/compiler/runtime-error-cleanup.test.ts +426 -0
- package/tests/unit/compiler/runtime-validation.test.ts +303 -0
- package/tests/unit/compiler/runtime.test.ts +221 -0
- package/tests/unit/compiler/schema/schema.test.ts +248 -0
- package/tests/unit/compiler/unary-ast-transforms.test.ts +245 -0
- package/tsconfig.json +27 -0
- package/tsup.config.ts +11 -0
- package/vitest.config.ts +12 -0
|
@@ -0,0 +1,864 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compilation Error Tests
|
|
3
|
+
*
|
|
4
|
+
* Tests that the compiler fails appropriately for invalid JDM structures.
|
|
5
|
+
* Verifies error messages, error codes, and source location information.
|
|
6
|
+
*
|
|
7
|
+
* This is Phase 7 of the test improvement plan - negative test cases.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { describe, it, expect } from 'vitest';
|
|
11
|
+
import { Type } from '@sinclair/typebox';
|
|
12
|
+
import { compile, type JDMDecision } from '../../src/compiler';
|
|
13
|
+
import { CompilationError, ErrorCode } from '../../src/compiler/errors';
|
|
14
|
+
import { buildGraph, validateGraph } from '../../src/compiler/graph';
|
|
15
|
+
import { parseJDM, NodeType } from '../../src/compiler/parser';
|
|
16
|
+
import { createExpressionJDM } from '../helpers';
|
|
17
|
+
|
|
18
|
+
const defaultInputSchema = Type.Object({ x: Type.Number() });
|
|
19
|
+
const defaultOutputSchema = Type.Object({ result: Type.Number() });
|
|
20
|
+
|
|
21
|
+
describe('Compilation Error Tests', () => {
|
|
22
|
+
describe('Missing Required Nodes', () => {
|
|
23
|
+
it('should throw error when input node is missing', () => {
|
|
24
|
+
const jdm: JDMDecision = {
|
|
25
|
+
nodes: [
|
|
26
|
+
{
|
|
27
|
+
id: 'output-1',
|
|
28
|
+
type: NodeType.OUTPUT,
|
|
29
|
+
position: { x: 0, y: 0 },
|
|
30
|
+
name: 'Response',
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
edges: [],
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const graph = buildGraph(jdm);
|
|
37
|
+
expect(() => validateGraph(graph)).toThrow(CompilationError);
|
|
38
|
+
expect(() => validateGraph(graph)).toThrow(/input node/i);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('should throw error when output node is missing', () => {
|
|
42
|
+
const jdm: JDMDecision = {
|
|
43
|
+
nodes: [
|
|
44
|
+
{
|
|
45
|
+
id: 'input-1',
|
|
46
|
+
type: NodeType.INPUT,
|
|
47
|
+
position: { x: 0, y: 0 },
|
|
48
|
+
name: 'Request',
|
|
49
|
+
},
|
|
50
|
+
],
|
|
51
|
+
edges: [],
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const graph = buildGraph(jdm);
|
|
55
|
+
expect(() => validateGraph(graph)).toThrow(CompilationError);
|
|
56
|
+
expect(() => validateGraph(graph)).toThrow(/output node/i);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('should throw error when multiple input nodes exist', () => {
|
|
60
|
+
const jdm: JDMDecision = {
|
|
61
|
+
nodes: [
|
|
62
|
+
{
|
|
63
|
+
id: 'input-1',
|
|
64
|
+
type: NodeType.INPUT,
|
|
65
|
+
position: { x: 0, y: 0 },
|
|
66
|
+
name: 'Request1',
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
id: 'input-2',
|
|
70
|
+
type: NodeType.INPUT,
|
|
71
|
+
position: { x: 0, y: 100 },
|
|
72
|
+
name: 'Request2',
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
id: 'output-1',
|
|
76
|
+
type: NodeType.OUTPUT,
|
|
77
|
+
position: { x: 200, y: 0 },
|
|
78
|
+
name: 'Response',
|
|
79
|
+
},
|
|
80
|
+
],
|
|
81
|
+
edges: [
|
|
82
|
+
{ id: 'e1', sourceId: 'input-1', targetId: 'output-1', type: 'edge' },
|
|
83
|
+
{ id: 'e2', sourceId: 'input-2', targetId: 'output-1', type: 'edge' },
|
|
84
|
+
],
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
const graph = buildGraph(jdm);
|
|
88
|
+
expect(() => validateGraph(graph)).toThrow(CompilationError);
|
|
89
|
+
expect(() => validateGraph(graph)).toThrow(/input node.*found 2/i);
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
describe('Circular Dependencies', () => {
|
|
94
|
+
it('should throw error for simple cycle between two nodes', () => {
|
|
95
|
+
const jdm: JDMDecision = {
|
|
96
|
+
nodes: [
|
|
97
|
+
{
|
|
98
|
+
id: 'input-1',
|
|
99
|
+
type: NodeType.INPUT,
|
|
100
|
+
position: { x: 0, y: 0 },
|
|
101
|
+
name: 'Request',
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
id: 'expr-1',
|
|
105
|
+
type: NodeType.EXPRESSION,
|
|
106
|
+
position: { x: 100, y: 0 },
|
|
107
|
+
name: 'ExprA',
|
|
108
|
+
content: { expressions: [] },
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
id: 'expr-2',
|
|
112
|
+
type: NodeType.EXPRESSION,
|
|
113
|
+
position: { x: 200, y: 0 },
|
|
114
|
+
name: 'ExprB',
|
|
115
|
+
content: { expressions: [] },
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
id: 'output-1',
|
|
119
|
+
type: NodeType.OUTPUT,
|
|
120
|
+
position: { x: 300, y: 0 },
|
|
121
|
+
name: 'Response',
|
|
122
|
+
},
|
|
123
|
+
],
|
|
124
|
+
edges: [
|
|
125
|
+
{ id: 'e1', sourceId: 'input-1', targetId: 'expr-1', type: 'edge' },
|
|
126
|
+
{ id: 'e2', sourceId: 'expr-1', targetId: 'expr-2', type: 'edge' },
|
|
127
|
+
{ id: 'e3', sourceId: 'expr-2', targetId: 'expr-1', type: 'edge' }, // Creates cycle
|
|
128
|
+
],
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
const graph = buildGraph(jdm);
|
|
132
|
+
expect(() => validateGraph(graph)).toThrow(CompilationError);
|
|
133
|
+
expect(() => validateGraph(graph)).toThrow(/circular/i);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it('should throw error for self-referencing node', () => {
|
|
137
|
+
const jdm: JDMDecision = {
|
|
138
|
+
nodes: [
|
|
139
|
+
{
|
|
140
|
+
id: 'input-1',
|
|
141
|
+
type: NodeType.INPUT,
|
|
142
|
+
position: { x: 0, y: 0 },
|
|
143
|
+
name: 'Request',
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
id: 'expr-1',
|
|
147
|
+
type: NodeType.EXPRESSION,
|
|
148
|
+
position: { x: 100, y: 0 },
|
|
149
|
+
name: 'SelfRef',
|
|
150
|
+
content: { expressions: [] },
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
id: 'output-1',
|
|
154
|
+
type: NodeType.OUTPUT,
|
|
155
|
+
position: { x: 200, y: 0 },
|
|
156
|
+
name: 'Response',
|
|
157
|
+
},
|
|
158
|
+
],
|
|
159
|
+
edges: [
|
|
160
|
+
{ id: 'e1', sourceId: 'input-1', targetId: 'expr-1', type: 'edge' },
|
|
161
|
+
{ id: 'e2', sourceId: 'expr-1', targetId: 'expr-1', type: 'edge' }, // Self-reference
|
|
162
|
+
{ id: 'e3', sourceId: 'expr-1', targetId: 'output-1', type: 'edge' },
|
|
163
|
+
],
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
expect(() => buildGraph(jdm)).toThrow(CompilationError);
|
|
167
|
+
expect(() => buildGraph(jdm)).toThrow(/self-reference/i);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it('should throw error for longer cycle (A -> B -> C -> A)', () => {
|
|
171
|
+
const jdm: JDMDecision = {
|
|
172
|
+
nodes: [
|
|
173
|
+
{
|
|
174
|
+
id: 'input-1',
|
|
175
|
+
type: NodeType.INPUT,
|
|
176
|
+
position: { x: 0, y: 0 },
|
|
177
|
+
name: 'Request',
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
id: 'expr-a',
|
|
181
|
+
type: NodeType.EXPRESSION,
|
|
182
|
+
position: { x: 100, y: 0 },
|
|
183
|
+
name: 'NodeA',
|
|
184
|
+
content: { expressions: [] },
|
|
185
|
+
},
|
|
186
|
+
{
|
|
187
|
+
id: 'expr-b',
|
|
188
|
+
type: NodeType.EXPRESSION,
|
|
189
|
+
position: { x: 200, y: 0 },
|
|
190
|
+
name: 'NodeB',
|
|
191
|
+
content: { expressions: [] },
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
id: 'expr-c',
|
|
195
|
+
type: NodeType.EXPRESSION,
|
|
196
|
+
position: { x: 300, y: 0 },
|
|
197
|
+
name: 'NodeC',
|
|
198
|
+
content: { expressions: [] },
|
|
199
|
+
},
|
|
200
|
+
{
|
|
201
|
+
id: 'output-1',
|
|
202
|
+
type: NodeType.OUTPUT,
|
|
203
|
+
position: { x: 400, y: 0 },
|
|
204
|
+
name: 'Response',
|
|
205
|
+
},
|
|
206
|
+
],
|
|
207
|
+
edges: [
|
|
208
|
+
{ id: 'e1', sourceId: 'input-1', targetId: 'expr-a', type: 'edge' },
|
|
209
|
+
{ id: 'e2', sourceId: 'expr-a', targetId: 'expr-b', type: 'edge' },
|
|
210
|
+
{ id: 'e3', sourceId: 'expr-b', targetId: 'expr-c', type: 'edge' },
|
|
211
|
+
{ id: 'e4', sourceId: 'expr-c', targetId: 'expr-a', type: 'edge' }, // Creates cycle
|
|
212
|
+
],
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
const graph = buildGraph(jdm);
|
|
216
|
+
expect(() => validateGraph(graph)).toThrow(CompilationError);
|
|
217
|
+
expect(() => validateGraph(graph)).toThrow(/circular/i);
|
|
218
|
+
});
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
describe('Invalid Expression Syntax', () => {
|
|
222
|
+
it('should throw error for invalid arithmetic syntax', async () => {
|
|
223
|
+
const jdm = createExpressionJDM([{ key: 'result', value: 'x + + y' }]);
|
|
224
|
+
|
|
225
|
+
await expect(
|
|
226
|
+
compile({
|
|
227
|
+
jdm,
|
|
228
|
+
inputSchema: Type.Object({ x: Type.Number(), y: Type.Number() }),
|
|
229
|
+
outputSchema: defaultOutputSchema,
|
|
230
|
+
}),
|
|
231
|
+
).rejects.toThrow();
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
it('should throw error for unclosed parentheses', async () => {
|
|
235
|
+
const jdm = createExpressionJDM([{ key: 'result', value: '(x + y' }]);
|
|
236
|
+
|
|
237
|
+
await expect(
|
|
238
|
+
compile({
|
|
239
|
+
jdm,
|
|
240
|
+
inputSchema: Type.Object({ x: Type.Number(), y: Type.Number() }),
|
|
241
|
+
outputSchema: defaultOutputSchema,
|
|
242
|
+
}),
|
|
243
|
+
).rejects.toThrow();
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
it('should throw error for unclosed string literal', async () => {
|
|
247
|
+
const jdm = createExpressionJDM([{ key: 'result', value: '"hello' }]);
|
|
248
|
+
|
|
249
|
+
await expect(
|
|
250
|
+
compile({
|
|
251
|
+
jdm,
|
|
252
|
+
inputSchema: Type.Object({}),
|
|
253
|
+
outputSchema: Type.Object({ result: Type.String() }),
|
|
254
|
+
}),
|
|
255
|
+
).rejects.toThrow();
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
it('should throw error for empty expression', async () => {
|
|
259
|
+
const jdm = createExpressionJDM([{ key: 'result', value: '' }]);
|
|
260
|
+
|
|
261
|
+
await expect(
|
|
262
|
+
compile({
|
|
263
|
+
jdm,
|
|
264
|
+
inputSchema: defaultInputSchema,
|
|
265
|
+
outputSchema: defaultOutputSchema,
|
|
266
|
+
}),
|
|
267
|
+
).rejects.toThrow();
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
it('should throw error for whitespace-only expression', async () => {
|
|
271
|
+
const jdm = createExpressionJDM([{ key: 'result', value: ' ' }]);
|
|
272
|
+
|
|
273
|
+
await expect(
|
|
274
|
+
compile({
|
|
275
|
+
jdm,
|
|
276
|
+
inputSchema: defaultInputSchema,
|
|
277
|
+
outputSchema: defaultOutputSchema,
|
|
278
|
+
}),
|
|
279
|
+
).rejects.toThrow();
|
|
280
|
+
});
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
describe('Invalid Edges', () => {
|
|
284
|
+
it('should throw error for edge referencing non-existent source node', () => {
|
|
285
|
+
const jdm: JDMDecision = {
|
|
286
|
+
nodes: [
|
|
287
|
+
{
|
|
288
|
+
id: 'input-1',
|
|
289
|
+
type: NodeType.INPUT,
|
|
290
|
+
position: { x: 0, y: 0 },
|
|
291
|
+
name: 'Request',
|
|
292
|
+
},
|
|
293
|
+
{
|
|
294
|
+
id: 'output-1',
|
|
295
|
+
type: NodeType.OUTPUT,
|
|
296
|
+
position: { x: 200, y: 0 },
|
|
297
|
+
name: 'Response',
|
|
298
|
+
},
|
|
299
|
+
],
|
|
300
|
+
edges: [
|
|
301
|
+
{
|
|
302
|
+
id: 'edge-1',
|
|
303
|
+
sourceId: 'nonexistent-node',
|
|
304
|
+
targetId: 'output-1',
|
|
305
|
+
type: 'edge',
|
|
306
|
+
},
|
|
307
|
+
],
|
|
308
|
+
};
|
|
309
|
+
|
|
310
|
+
expect(() => buildGraph(jdm)).toThrow(CompilationError);
|
|
311
|
+
expect(() => buildGraph(jdm)).toThrow(/non-existent node/i);
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
it('should throw error for edge referencing non-existent target node', () => {
|
|
315
|
+
const jdm: JDMDecision = {
|
|
316
|
+
nodes: [
|
|
317
|
+
{
|
|
318
|
+
id: 'input-1',
|
|
319
|
+
type: NodeType.INPUT,
|
|
320
|
+
position: { x: 0, y: 0 },
|
|
321
|
+
name: 'Request',
|
|
322
|
+
},
|
|
323
|
+
{
|
|
324
|
+
id: 'output-1',
|
|
325
|
+
type: NodeType.OUTPUT,
|
|
326
|
+
position: { x: 200, y: 0 },
|
|
327
|
+
name: 'Response',
|
|
328
|
+
},
|
|
329
|
+
],
|
|
330
|
+
edges: [
|
|
331
|
+
{
|
|
332
|
+
id: 'edge-1',
|
|
333
|
+
sourceId: 'input-1',
|
|
334
|
+
targetId: 'nonexistent-node',
|
|
335
|
+
type: 'edge',
|
|
336
|
+
},
|
|
337
|
+
],
|
|
338
|
+
};
|
|
339
|
+
|
|
340
|
+
expect(() => buildGraph(jdm)).toThrow(CompilationError);
|
|
341
|
+
expect(() => buildGraph(jdm)).toThrow(/non-existent node/i);
|
|
342
|
+
});
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
describe('Function Node Parsing', () => {
|
|
346
|
+
it('should parse function nodes successfully', () => {
|
|
347
|
+
const jdm = {
|
|
348
|
+
nodes: [
|
|
349
|
+
{
|
|
350
|
+
id: 'input-1',
|
|
351
|
+
type: 'inputNode',
|
|
352
|
+
position: { x: 0, y: 0 },
|
|
353
|
+
name: 'Request',
|
|
354
|
+
},
|
|
355
|
+
{
|
|
356
|
+
id: 'func-1',
|
|
357
|
+
type: 'functionNode',
|
|
358
|
+
position: { x: 200, y: 0 },
|
|
359
|
+
name: 'CustomFunction',
|
|
360
|
+
content: { source: 'export const handler = (input) => ({ result: input.x * 2 });' },
|
|
361
|
+
},
|
|
362
|
+
{
|
|
363
|
+
id: 'output-1',
|
|
364
|
+
type: 'outputNode',
|
|
365
|
+
position: { x: 400, y: 0 },
|
|
366
|
+
name: 'Response',
|
|
367
|
+
},
|
|
368
|
+
],
|
|
369
|
+
edges: [
|
|
370
|
+
{ id: 'edge-1', sourceId: 'input-1', targetId: 'func-1', type: 'edge' },
|
|
371
|
+
{ id: 'edge-2', sourceId: 'func-1', targetId: 'output-1', type: 'edge' },
|
|
372
|
+
],
|
|
373
|
+
};
|
|
374
|
+
|
|
375
|
+
// Should parse without error
|
|
376
|
+
const parsed = parseJDM(jdm);
|
|
377
|
+
expect(parsed.nodes.length).toBe(3);
|
|
378
|
+
expect(parsed.nodes[1].type).toBe('functionNode');
|
|
379
|
+
expect(parsed.nodes[1].parsedContent).toBeDefined();
|
|
380
|
+
});
|
|
381
|
+
|
|
382
|
+
it('should throw error for function node with invalid JavaScript syntax', () => {
|
|
383
|
+
const jdm = {
|
|
384
|
+
nodes: [
|
|
385
|
+
{
|
|
386
|
+
id: 'func-1',
|
|
387
|
+
type: 'functionNode',
|
|
388
|
+
position: { x: 200, y: 0 },
|
|
389
|
+
name: 'CustomFunction',
|
|
390
|
+
content: { source: 'this is not valid javascript {{{' },
|
|
391
|
+
},
|
|
392
|
+
],
|
|
393
|
+
edges: [],
|
|
394
|
+
};
|
|
395
|
+
|
|
396
|
+
expect(() => parseJDM(jdm)).toThrow();
|
|
397
|
+
expect(() => parseJDM(jdm)).toThrow('Failed to parse function code');
|
|
398
|
+
});
|
|
399
|
+
});
|
|
400
|
+
|
|
401
|
+
describe('Empty or Malformed JDM Structure', () => {
|
|
402
|
+
it('should throw error for empty nodes array', () => {
|
|
403
|
+
const jdm: JDMDecision = {
|
|
404
|
+
nodes: [],
|
|
405
|
+
edges: [],
|
|
406
|
+
};
|
|
407
|
+
|
|
408
|
+
const graph = buildGraph(jdm);
|
|
409
|
+
expect(() => validateGraph(graph)).toThrow(CompilationError);
|
|
410
|
+
});
|
|
411
|
+
|
|
412
|
+
it('should throw error for invalid JSON string', () => {
|
|
413
|
+
expect(() => parseJDM('{ invalid json }')).toThrow();
|
|
414
|
+
});
|
|
415
|
+
|
|
416
|
+
it('should handle JDM with only input node (no output)', () => {
|
|
417
|
+
const jdm: JDMDecision = {
|
|
418
|
+
nodes: [
|
|
419
|
+
{
|
|
420
|
+
id: 'input-1',
|
|
421
|
+
type: NodeType.INPUT,
|
|
422
|
+
position: { x: 0, y: 0 },
|
|
423
|
+
name: 'Request',
|
|
424
|
+
},
|
|
425
|
+
],
|
|
426
|
+
edges: [],
|
|
427
|
+
};
|
|
428
|
+
|
|
429
|
+
const graph = buildGraph(jdm);
|
|
430
|
+
expect(() => validateGraph(graph)).toThrow(CompilationError);
|
|
431
|
+
expect(() => validateGraph(graph)).toThrow(/output node/i);
|
|
432
|
+
});
|
|
433
|
+
|
|
434
|
+
it('should handle JDM with only output node (no input)', () => {
|
|
435
|
+
const jdm: JDMDecision = {
|
|
436
|
+
nodes: [
|
|
437
|
+
{
|
|
438
|
+
id: 'output-1',
|
|
439
|
+
type: NodeType.OUTPUT,
|
|
440
|
+
position: { x: 0, y: 0 },
|
|
441
|
+
name: 'Response',
|
|
442
|
+
},
|
|
443
|
+
],
|
|
444
|
+
edges: [],
|
|
445
|
+
};
|
|
446
|
+
|
|
447
|
+
const graph = buildGraph(jdm);
|
|
448
|
+
expect(() => validateGraph(graph)).toThrow(CompilationError);
|
|
449
|
+
expect(() => validateGraph(graph)).toThrow(/input node/i);
|
|
450
|
+
});
|
|
451
|
+
});
|
|
452
|
+
|
|
453
|
+
describe('Source Location in Errors', () => {
|
|
454
|
+
it('should include node information in structural errors', () => {
|
|
455
|
+
const jdm: JDMDecision = {
|
|
456
|
+
nodes: [
|
|
457
|
+
{
|
|
458
|
+
id: 'expr-1',
|
|
459
|
+
type: NodeType.EXPRESSION,
|
|
460
|
+
position: { x: 0, y: 0 },
|
|
461
|
+
name: 'OrphanExpression',
|
|
462
|
+
content: { expressions: [] },
|
|
463
|
+
},
|
|
464
|
+
],
|
|
465
|
+
edges: [],
|
|
466
|
+
};
|
|
467
|
+
|
|
468
|
+
const graph = buildGraph(jdm);
|
|
469
|
+
try {
|
|
470
|
+
validateGraph(graph);
|
|
471
|
+
expect.fail('Should have thrown');
|
|
472
|
+
} catch (e) {
|
|
473
|
+
expect(e).toBeInstanceOf(CompilationError);
|
|
474
|
+
// Error should mention missing input/output nodes
|
|
475
|
+
expect((e as Error).message).toMatch(/node/i);
|
|
476
|
+
}
|
|
477
|
+
});
|
|
478
|
+
|
|
479
|
+
it('should include node name in cycle detection errors', () => {
|
|
480
|
+
const jdm: JDMDecision = {
|
|
481
|
+
nodes: [
|
|
482
|
+
{
|
|
483
|
+
id: 'input-1',
|
|
484
|
+
type: NodeType.INPUT,
|
|
485
|
+
position: { x: 0, y: 0 },
|
|
486
|
+
name: 'Request',
|
|
487
|
+
},
|
|
488
|
+
{
|
|
489
|
+
id: 'expr-1',
|
|
490
|
+
type: NodeType.EXPRESSION,
|
|
491
|
+
position: { x: 100, y: 0 },
|
|
492
|
+
name: 'CycleNodeA',
|
|
493
|
+
content: { expressions: [] },
|
|
494
|
+
},
|
|
495
|
+
{
|
|
496
|
+
id: 'expr-2',
|
|
497
|
+
type: NodeType.EXPRESSION,
|
|
498
|
+
position: { x: 200, y: 0 },
|
|
499
|
+
name: 'CycleNodeB',
|
|
500
|
+
content: { expressions: [] },
|
|
501
|
+
},
|
|
502
|
+
{
|
|
503
|
+
id: 'output-1',
|
|
504
|
+
type: NodeType.OUTPUT,
|
|
505
|
+
position: { x: 300, y: 0 },
|
|
506
|
+
name: 'Response',
|
|
507
|
+
},
|
|
508
|
+
],
|
|
509
|
+
edges: [
|
|
510
|
+
{ id: 'e1', sourceId: 'input-1', targetId: 'expr-1', type: 'edge' },
|
|
511
|
+
{ id: 'e2', sourceId: 'expr-1', targetId: 'expr-2', type: 'edge' },
|
|
512
|
+
{ id: 'e3', sourceId: 'expr-2', targetId: 'expr-1', type: 'edge' },
|
|
513
|
+
],
|
|
514
|
+
};
|
|
515
|
+
|
|
516
|
+
const graph = buildGraph(jdm);
|
|
517
|
+
try {
|
|
518
|
+
validateGraph(graph);
|
|
519
|
+
expect.fail('Should have thrown');
|
|
520
|
+
} catch (e) {
|
|
521
|
+
expect(e).toBeInstanceOf(CompilationError);
|
|
522
|
+
const message = (e as Error).message;
|
|
523
|
+
// Should include node names in cycle path
|
|
524
|
+
expect(message).toMatch(/CycleNodeA|CycleNodeB/);
|
|
525
|
+
}
|
|
526
|
+
});
|
|
527
|
+
});
|
|
528
|
+
|
|
529
|
+
describe('Error Code Classification', () => {
|
|
530
|
+
it('should use MULTIPLE_INPUT_NODES code for missing or wrong number of inputs', () => {
|
|
531
|
+
// Note: The graph validation uses MULTIPLE_INPUT_NODES code when input count != 1
|
|
532
|
+
// This includes both 0 inputs and 2+ inputs
|
|
533
|
+
const jdm: JDMDecision = {
|
|
534
|
+
nodes: [
|
|
535
|
+
{
|
|
536
|
+
id: 'output-1',
|
|
537
|
+
type: NodeType.OUTPUT,
|
|
538
|
+
position: { x: 0, y: 0 },
|
|
539
|
+
name: 'Response',
|
|
540
|
+
},
|
|
541
|
+
],
|
|
542
|
+
edges: [],
|
|
543
|
+
};
|
|
544
|
+
|
|
545
|
+
const graph = buildGraph(jdm);
|
|
546
|
+
try {
|
|
547
|
+
validateGraph(graph);
|
|
548
|
+
expect.fail('Should have thrown');
|
|
549
|
+
} catch (e) {
|
|
550
|
+
expect(e).toBeInstanceOf(CompilationError);
|
|
551
|
+
// When input count != 1, MULTIPLE_INPUT_NODES is used (includes 0 case)
|
|
552
|
+
expect((e as CompilationError).code).toBe(ErrorCode.MULTIPLE_INPUT_NODES);
|
|
553
|
+
}
|
|
554
|
+
});
|
|
555
|
+
|
|
556
|
+
it('should use MISSING_OUTPUT_NODE code for missing output', () => {
|
|
557
|
+
const jdm: JDMDecision = {
|
|
558
|
+
nodes: [
|
|
559
|
+
{
|
|
560
|
+
id: 'input-1',
|
|
561
|
+
type: NodeType.INPUT,
|
|
562
|
+
position: { x: 0, y: 0 },
|
|
563
|
+
name: 'Request',
|
|
564
|
+
},
|
|
565
|
+
],
|
|
566
|
+
edges: [],
|
|
567
|
+
};
|
|
568
|
+
|
|
569
|
+
const graph = buildGraph(jdm);
|
|
570
|
+
try {
|
|
571
|
+
validateGraph(graph);
|
|
572
|
+
expect.fail('Should have thrown');
|
|
573
|
+
} catch (e) {
|
|
574
|
+
expect(e).toBeInstanceOf(CompilationError);
|
|
575
|
+
expect((e as CompilationError).code).toBe(ErrorCode.MISSING_OUTPUT_NODE);
|
|
576
|
+
}
|
|
577
|
+
});
|
|
578
|
+
|
|
579
|
+
it('should use MULTIPLE_INPUT_NODES code for multiple inputs', () => {
|
|
580
|
+
const jdm: JDMDecision = {
|
|
581
|
+
nodes: [
|
|
582
|
+
{
|
|
583
|
+
id: 'input-1',
|
|
584
|
+
type: NodeType.INPUT,
|
|
585
|
+
position: { x: 0, y: 0 },
|
|
586
|
+
name: 'Request1',
|
|
587
|
+
},
|
|
588
|
+
{
|
|
589
|
+
id: 'input-2',
|
|
590
|
+
type: NodeType.INPUT,
|
|
591
|
+
position: { x: 0, y: 100 },
|
|
592
|
+
name: 'Request2',
|
|
593
|
+
},
|
|
594
|
+
{
|
|
595
|
+
id: 'output-1',
|
|
596
|
+
type: NodeType.OUTPUT,
|
|
597
|
+
position: { x: 200, y: 0 },
|
|
598
|
+
name: 'Response',
|
|
599
|
+
},
|
|
600
|
+
],
|
|
601
|
+
edges: [],
|
|
602
|
+
};
|
|
603
|
+
|
|
604
|
+
const graph = buildGraph(jdm);
|
|
605
|
+
try {
|
|
606
|
+
validateGraph(graph);
|
|
607
|
+
expect.fail('Should have thrown');
|
|
608
|
+
} catch (e) {
|
|
609
|
+
expect(e).toBeInstanceOf(CompilationError);
|
|
610
|
+
expect((e as CompilationError).code).toBe(ErrorCode.MULTIPLE_INPUT_NODES);
|
|
611
|
+
}
|
|
612
|
+
});
|
|
613
|
+
|
|
614
|
+
it('should use CYCLE_DETECTED code for cycles', () => {
|
|
615
|
+
const jdm: JDMDecision = {
|
|
616
|
+
nodes: [
|
|
617
|
+
{
|
|
618
|
+
id: 'input-1',
|
|
619
|
+
type: NodeType.INPUT,
|
|
620
|
+
position: { x: 0, y: 0 },
|
|
621
|
+
name: 'Request',
|
|
622
|
+
},
|
|
623
|
+
{
|
|
624
|
+
id: 'expr-1',
|
|
625
|
+
type: NodeType.EXPRESSION,
|
|
626
|
+
position: { x: 100, y: 0 },
|
|
627
|
+
name: 'NodeA',
|
|
628
|
+
content: { expressions: [] },
|
|
629
|
+
},
|
|
630
|
+
{
|
|
631
|
+
id: 'expr-2',
|
|
632
|
+
type: NodeType.EXPRESSION,
|
|
633
|
+
position: { x: 200, y: 0 },
|
|
634
|
+
name: 'NodeB',
|
|
635
|
+
content: { expressions: [] },
|
|
636
|
+
},
|
|
637
|
+
{
|
|
638
|
+
id: 'output-1',
|
|
639
|
+
type: NodeType.OUTPUT,
|
|
640
|
+
position: { x: 300, y: 0 },
|
|
641
|
+
name: 'Response',
|
|
642
|
+
},
|
|
643
|
+
],
|
|
644
|
+
edges: [
|
|
645
|
+
{ id: 'e1', sourceId: 'input-1', targetId: 'expr-1', type: 'edge' },
|
|
646
|
+
{ id: 'e2', sourceId: 'expr-1', targetId: 'expr-2', type: 'edge' },
|
|
647
|
+
{ id: 'e3', sourceId: 'expr-2', targetId: 'expr-1', type: 'edge' },
|
|
648
|
+
],
|
|
649
|
+
};
|
|
650
|
+
|
|
651
|
+
const graph = buildGraph(jdm);
|
|
652
|
+
try {
|
|
653
|
+
validateGraph(graph);
|
|
654
|
+
expect.fail('Should have thrown');
|
|
655
|
+
} catch (e) {
|
|
656
|
+
expect(e).toBeInstanceOf(CompilationError);
|
|
657
|
+
expect((e as CompilationError).code).toBe(ErrorCode.CYCLE_DETECTED);
|
|
658
|
+
}
|
|
659
|
+
});
|
|
660
|
+
|
|
661
|
+
it('should use INVALID_EDGE code for invalid edges', () => {
|
|
662
|
+
const jdm: JDMDecision = {
|
|
663
|
+
nodes: [
|
|
664
|
+
{
|
|
665
|
+
id: 'input-1',
|
|
666
|
+
type: NodeType.INPUT,
|
|
667
|
+
position: { x: 0, y: 0 },
|
|
668
|
+
name: 'Request',
|
|
669
|
+
},
|
|
670
|
+
],
|
|
671
|
+
edges: [
|
|
672
|
+
{
|
|
673
|
+
id: 'edge-1',
|
|
674
|
+
sourceId: 'input-1',
|
|
675
|
+
targetId: 'nonexistent',
|
|
676
|
+
type: 'edge',
|
|
677
|
+
},
|
|
678
|
+
],
|
|
679
|
+
};
|
|
680
|
+
|
|
681
|
+
try {
|
|
682
|
+
buildGraph(jdm);
|
|
683
|
+
expect.fail('Should have thrown');
|
|
684
|
+
} catch (e) {
|
|
685
|
+
expect(e).toBeInstanceOf(CompilationError);
|
|
686
|
+
expect((e as CompilationError).code).toBe(ErrorCode.INVALID_EDGE);
|
|
687
|
+
}
|
|
688
|
+
});
|
|
689
|
+
});
|
|
690
|
+
|
|
691
|
+
describe('Decision Table Validation', () => {
|
|
692
|
+
it('should handle decision table with no rules (currently a limitation)', async () => {
|
|
693
|
+
const jdm: JDMDecision = {
|
|
694
|
+
nodes: [
|
|
695
|
+
{
|
|
696
|
+
id: 'input-1',
|
|
697
|
+
type: NodeType.INPUT,
|
|
698
|
+
position: { x: 0, y: 0 },
|
|
699
|
+
name: 'Request',
|
|
700
|
+
},
|
|
701
|
+
{
|
|
702
|
+
id: 'dt-1',
|
|
703
|
+
type: NodeType.DECISION_TABLE,
|
|
704
|
+
position: { x: 200, y: 0 },
|
|
705
|
+
name: 'EmptyTable',
|
|
706
|
+
content: {
|
|
707
|
+
hitPolicy: 'first',
|
|
708
|
+
inputs: [{ id: 'in1', field: 'x', name: 'X' }],
|
|
709
|
+
outputs: [{ id: 'out1', field: 'result', name: 'Result' }],
|
|
710
|
+
rules: [],
|
|
711
|
+
},
|
|
712
|
+
},
|
|
713
|
+
{
|
|
714
|
+
id: 'output-1',
|
|
715
|
+
type: NodeType.OUTPUT,
|
|
716
|
+
position: { x: 400, y: 0 },
|
|
717
|
+
name: 'Response',
|
|
718
|
+
},
|
|
719
|
+
],
|
|
720
|
+
edges: [
|
|
721
|
+
{ id: 'e1', sourceId: 'input-1', targetId: 'dt-1', type: 'edge' },
|
|
722
|
+
{ id: 'e2', sourceId: 'dt-1', targetId: 'output-1', type: 'edge' },
|
|
723
|
+
],
|
|
724
|
+
};
|
|
725
|
+
|
|
726
|
+
// LIMITATION: Empty decision tables currently fail to compile due to code generation
|
|
727
|
+
// producing invalid AssemblyScript (dangling 'else' clause).
|
|
728
|
+
// This documents the current behavior - future improvements could handle this case.
|
|
729
|
+
await expect(
|
|
730
|
+
compile({
|
|
731
|
+
jdm,
|
|
732
|
+
inputSchema: Type.Object({ x: Type.Number() }),
|
|
733
|
+
outputSchema: Type.Object({ result: Type.Optional(Type.Number()) }),
|
|
734
|
+
}),
|
|
735
|
+
).rejects.toThrow();
|
|
736
|
+
});
|
|
737
|
+
|
|
738
|
+
it('should handle decision table with at least one rule', async () => {
|
|
739
|
+
const jdm: JDMDecision = {
|
|
740
|
+
nodes: [
|
|
741
|
+
{
|
|
742
|
+
id: 'input-1',
|
|
743
|
+
type: NodeType.INPUT,
|
|
744
|
+
position: { x: 0, y: 0 },
|
|
745
|
+
name: 'Request',
|
|
746
|
+
},
|
|
747
|
+
{
|
|
748
|
+
id: 'dt-1',
|
|
749
|
+
type: NodeType.DECISION_TABLE,
|
|
750
|
+
position: { x: 200, y: 0 },
|
|
751
|
+
name: 'SimpleTable',
|
|
752
|
+
content: {
|
|
753
|
+
hitPolicy: 'first',
|
|
754
|
+
inputs: [{ id: 'in1', field: 'x', name: 'X' }],
|
|
755
|
+
outputs: [{ id: 'out1', field: 'result', name: 'Result' }],
|
|
756
|
+
rules: [
|
|
757
|
+
{
|
|
758
|
+
_id: 'rule1',
|
|
759
|
+
in1: '', // Empty condition = always matches
|
|
760
|
+
out1: '42',
|
|
761
|
+
},
|
|
762
|
+
],
|
|
763
|
+
},
|
|
764
|
+
},
|
|
765
|
+
{
|
|
766
|
+
id: 'output-1',
|
|
767
|
+
type: NodeType.OUTPUT,
|
|
768
|
+
position: { x: 400, y: 0 },
|
|
769
|
+
name: 'Response',
|
|
770
|
+
},
|
|
771
|
+
],
|
|
772
|
+
edges: [
|
|
773
|
+
{ id: 'e1', sourceId: 'input-1', targetId: 'dt-1', type: 'edge' },
|
|
774
|
+
{ id: 'e2', sourceId: 'dt-1', targetId: 'output-1', type: 'edge' },
|
|
775
|
+
],
|
|
776
|
+
};
|
|
777
|
+
|
|
778
|
+
const result = await compile({
|
|
779
|
+
jdm,
|
|
780
|
+
inputSchema: Type.Object({ x: Type.Number() }),
|
|
781
|
+
outputSchema: Type.Object({ result: Type.Number() }),
|
|
782
|
+
});
|
|
783
|
+
|
|
784
|
+
expect(result.wasm).toBeInstanceOf(Uint8Array);
|
|
785
|
+
});
|
|
786
|
+
});
|
|
787
|
+
|
|
788
|
+
describe('Switch Node Validation', () => {
|
|
789
|
+
it('should handle switch with no conditions', async () => {
|
|
790
|
+
const jdm: JDMDecision = {
|
|
791
|
+
nodes: [
|
|
792
|
+
{
|
|
793
|
+
id: 'input-1',
|
|
794
|
+
type: NodeType.INPUT,
|
|
795
|
+
position: { x: 0, y: 0 },
|
|
796
|
+
name: 'Request',
|
|
797
|
+
},
|
|
798
|
+
{
|
|
799
|
+
id: 'switch-1',
|
|
800
|
+
type: NodeType.SWITCH,
|
|
801
|
+
position: { x: 200, y: 0 },
|
|
802
|
+
name: 'EmptySwitch',
|
|
803
|
+
content: {
|
|
804
|
+
hitPolicy: 'first',
|
|
805
|
+
statements: [],
|
|
806
|
+
},
|
|
807
|
+
},
|
|
808
|
+
{
|
|
809
|
+
id: 'output-1',
|
|
810
|
+
type: NodeType.OUTPUT,
|
|
811
|
+
position: { x: 400, y: 0 },
|
|
812
|
+
name: 'Response',
|
|
813
|
+
},
|
|
814
|
+
],
|
|
815
|
+
edges: [
|
|
816
|
+
{ id: 'e1', sourceId: 'input-1', targetId: 'switch-1', type: 'edge' },
|
|
817
|
+
{ id: 'e2', sourceId: 'switch-1', targetId: 'output-1', type: 'edge' },
|
|
818
|
+
],
|
|
819
|
+
};
|
|
820
|
+
|
|
821
|
+
// Empty switch should compile but produce no output or use default
|
|
822
|
+
const result = await compile({
|
|
823
|
+
jdm,
|
|
824
|
+
inputSchema: Type.Object({ x: Type.Number() }),
|
|
825
|
+
outputSchema: Type.Object({}),
|
|
826
|
+
});
|
|
827
|
+
|
|
828
|
+
expect(result.wasm).toBeInstanceOf(Uint8Array);
|
|
829
|
+
});
|
|
830
|
+
});
|
|
831
|
+
|
|
832
|
+
describe('Compilation Pipeline Errors', () => {
|
|
833
|
+
it('should provide useful error for complex nested expression errors', async () => {
|
|
834
|
+
const jdm = createExpressionJDM([{ key: 'result', value: '((x + y) * (z -))' }]); // Missing operand
|
|
835
|
+
|
|
836
|
+
try {
|
|
837
|
+
await compile({
|
|
838
|
+
jdm,
|
|
839
|
+
inputSchema: Type.Object({ x: Type.Number(), y: Type.Number(), z: Type.Number() }),
|
|
840
|
+
outputSchema: defaultOutputSchema,
|
|
841
|
+
});
|
|
842
|
+
expect.fail('Should have thrown');
|
|
843
|
+
} catch (e) {
|
|
844
|
+
expect(e).toBeDefined();
|
|
845
|
+
// The error should be thrown, exact message depends on parser
|
|
846
|
+
}
|
|
847
|
+
});
|
|
848
|
+
|
|
849
|
+
it('should handle invalid ternary expression', async () => {
|
|
850
|
+
const jdm = createExpressionJDM([{ key: 'result', value: 'x > 0 ? "yes"' }]); // Missing else branch
|
|
851
|
+
|
|
852
|
+
try {
|
|
853
|
+
await compile({
|
|
854
|
+
jdm,
|
|
855
|
+
inputSchema: defaultInputSchema,
|
|
856
|
+
outputSchema: Type.Object({ result: Type.String() }),
|
|
857
|
+
});
|
|
858
|
+
expect.fail('Should have thrown');
|
|
859
|
+
} catch (e) {
|
|
860
|
+
expect(e).toBeDefined();
|
|
861
|
+
}
|
|
862
|
+
});
|
|
863
|
+
});
|
|
864
|
+
});
|