@mmapp/player-core 0.1.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +1436 -0
- package/dist/index.d.ts +1436 -0
- package/dist/index.js +4828 -0
- package/dist/index.mjs +4762 -0
- package/package.json +35 -0
- package/package.json.backup +35 -0
- package/src/__tests__/actions.test.ts +187 -0
- package/src/__tests__/blueprint-e2e.test.ts +706 -0
- package/src/__tests__/blueprint-test-runner.test.ts +680 -0
- package/src/__tests__/core-functions.test.ts +78 -0
- package/src/__tests__/dsl-compiler.test.ts +1382 -0
- package/src/__tests__/dsl-grammar.test.ts +1682 -0
- package/src/__tests__/events.test.ts +200 -0
- package/src/__tests__/expression.test.ts +296 -0
- package/src/__tests__/failure-policies.test.ts +110 -0
- package/src/__tests__/frontend-context.test.ts +182 -0
- package/src/__tests__/integration.test.ts +256 -0
- package/src/__tests__/security.test.ts +190 -0
- package/src/__tests__/state-machine.test.ts +450 -0
- package/src/__tests__/testing-engine.test.ts +671 -0
- package/src/actions/dispatcher.ts +80 -0
- package/src/actions/index.ts +7 -0
- package/src/actions/types.ts +25 -0
- package/src/dsl/compiler/component-mapper.ts +289 -0
- package/src/dsl/compiler/field-mapper.ts +187 -0
- package/src/dsl/compiler/index.ts +82 -0
- package/src/dsl/compiler/manifest-compiler.ts +76 -0
- package/src/dsl/compiler/symbol-table.ts +214 -0
- package/src/dsl/compiler/utils.ts +48 -0
- package/src/dsl/compiler/view-compiler.ts +286 -0
- package/src/dsl/compiler/workflow-compiler.ts +600 -0
- package/src/dsl/index.ts +66 -0
- package/src/dsl/ir-migration.ts +221 -0
- package/src/dsl/ir-types.ts +416 -0
- package/src/dsl/lexer.ts +579 -0
- package/src/dsl/parser.ts +115 -0
- package/src/dsl/types.ts +256 -0
- package/src/events/event-bus.ts +68 -0
- package/src/events/index.ts +9 -0
- package/src/events/pattern-matcher.ts +61 -0
- package/src/events/types.ts +27 -0
- package/src/expression/evaluator.ts +676 -0
- package/src/expression/functions.ts +214 -0
- package/src/expression/index.ts +13 -0
- package/src/expression/types.ts +64 -0
- package/src/index.ts +61 -0
- package/src/state-machine/index.ts +16 -0
- package/src/state-machine/interpreter.ts +319 -0
- package/src/state-machine/types.ts +89 -0
- package/src/testing/action-trace.ts +209 -0
- package/src/testing/blueprint-test-runner.ts +214 -0
- package/src/testing/graph-walker.ts +249 -0
- package/src/testing/index.ts +69 -0
- package/src/testing/nrt-comparator.ts +199 -0
- package/src/testing/nrt-types.ts +230 -0
- package/src/testing/test-actions.ts +645 -0
- package/src/testing/test-compiler.ts +278 -0
- package/src/testing/test-runner.ts +444 -0
- package/src/testing/types.ts +231 -0
- package/src/validation/definition-validator.ts +812 -0
- package/src/validation/index.ts +13 -0
- package/tsconfig.json +26 -0
- package/vitest.config.ts +8 -0
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Testing OS Types — test declarations for the player-core engine.
|
|
3
|
+
*
|
|
4
|
+
* All types are JSON-serializable, enabling:
|
|
5
|
+
* - LLM generation of test programs
|
|
6
|
+
* - Database storage of test suites
|
|
7
|
+
* - Cross-platform execution (browser, iOS, Node)
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { PlayerWorkflowDefinition } from '../state-machine/types';
|
|
11
|
+
import type { ActionHandlerFn } from '../actions/types';
|
|
12
|
+
|
|
13
|
+
// =============================================================================
|
|
14
|
+
// Static Analysis
|
|
15
|
+
// =============================================================================
|
|
16
|
+
|
|
17
|
+
/** A node in the workflow state graph */
|
|
18
|
+
export interface StateNode {
|
|
19
|
+
name: string;
|
|
20
|
+
type: 'START' | 'REGULAR' | 'END' | 'CANCELLED';
|
|
21
|
+
reachable: boolean;
|
|
22
|
+
hasOnEvent: boolean;
|
|
23
|
+
hasOnEnter: boolean;
|
|
24
|
+
hasOnExit: boolean;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** An edge (transition) in the workflow state graph */
|
|
28
|
+
export interface TransitionEdge {
|
|
29
|
+
name: string;
|
|
30
|
+
from: string;
|
|
31
|
+
to: string;
|
|
32
|
+
auto: boolean;
|
|
33
|
+
hasConditions: boolean;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** A path through the state graph */
|
|
37
|
+
export interface GraphPath {
|
|
38
|
+
states: string[];
|
|
39
|
+
transitions: string[];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Summary statistics for a workflow definition */
|
|
43
|
+
export interface AnalysisSummary {
|
|
44
|
+
totalStates: number;
|
|
45
|
+
totalTransitions: number;
|
|
46
|
+
reachableStates: number;
|
|
47
|
+
terminalPaths: number;
|
|
48
|
+
cycles: number;
|
|
49
|
+
unreachableStates: number;
|
|
50
|
+
deadEndStates: number;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Full static analysis result for a workflow definition */
|
|
54
|
+
export interface AnalysisResult {
|
|
55
|
+
states: StateNode[];
|
|
56
|
+
edges: TransitionEdge[];
|
|
57
|
+
terminalPaths: GraphPath[];
|
|
58
|
+
cycles: GraphPath[];
|
|
59
|
+
unreachableStates: string[];
|
|
60
|
+
deadEndStates: string[];
|
|
61
|
+
summary: AnalysisSummary;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// =============================================================================
|
|
65
|
+
// Test Program (JSON-serializable, LLM-generable, DB-storable)
|
|
66
|
+
// =============================================================================
|
|
67
|
+
|
|
68
|
+
/** A complete test program with scenarios */
|
|
69
|
+
export interface TestProgram {
|
|
70
|
+
name: string;
|
|
71
|
+
definitionSlug: string;
|
|
72
|
+
definitions: Record<string, PlayerWorkflowDefinition>;
|
|
73
|
+
scenarios: TestScenario[];
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** Instance declaration for multi-instance scenarios */
|
|
77
|
+
export interface TestInstance {
|
|
78
|
+
id: string;
|
|
79
|
+
definitionSlug: string;
|
|
80
|
+
initialData?: Record<string, unknown>;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** A test scenario with steps */
|
|
84
|
+
export interface TestScenario {
|
|
85
|
+
name: string;
|
|
86
|
+
tags?: string[];
|
|
87
|
+
instances?: TestInstance[];
|
|
88
|
+
connectEventBuses?: boolean;
|
|
89
|
+
steps: TestStep[];
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** A single test step: action + assertions */
|
|
93
|
+
export interface TestStep {
|
|
94
|
+
name: string;
|
|
95
|
+
instanceId?: string;
|
|
96
|
+
action:
|
|
97
|
+
| { type: 'transition'; name: string; data?: Record<string, unknown> }
|
|
98
|
+
| { type: 'set_field'; field: string; value: unknown }
|
|
99
|
+
| { type: 'publish_event'; topic: string; payload?: Record<string, unknown> }
|
|
100
|
+
| { type: 'assert_only' };
|
|
101
|
+
assertions: TestAssertion[];
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** A single assertion to verify after an action */
|
|
105
|
+
export interface TestAssertion {
|
|
106
|
+
target: 'state' | 'status' | 'state_data' | 'available_transitions';
|
|
107
|
+
instanceId?: string;
|
|
108
|
+
path?: string;
|
|
109
|
+
operator: 'eq' | 'neq' | 'gt' | 'gte' | 'lt' | 'lte' | 'contains' | 'truthy' | 'falsy';
|
|
110
|
+
expected: unknown;
|
|
111
|
+
label?: string;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// =============================================================================
|
|
115
|
+
// Results
|
|
116
|
+
// =============================================================================
|
|
117
|
+
|
|
118
|
+
/** Result of a single assertion */
|
|
119
|
+
export interface AssertionResult {
|
|
120
|
+
passed: boolean;
|
|
121
|
+
assertion: TestAssertion;
|
|
122
|
+
actual: unknown;
|
|
123
|
+
error?: string;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** Result of a single step */
|
|
127
|
+
export interface StepResult {
|
|
128
|
+
stepName: string;
|
|
129
|
+
passed: boolean;
|
|
130
|
+
assertionResults: AssertionResult[];
|
|
131
|
+
durationMs: number;
|
|
132
|
+
error?: string;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** Result of a single scenario */
|
|
136
|
+
export interface ScenarioResult {
|
|
137
|
+
scenarioName: string;
|
|
138
|
+
passed: boolean;
|
|
139
|
+
stepResults: StepResult[];
|
|
140
|
+
durationMs: number;
|
|
141
|
+
error?: string;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** Result of a complete test program */
|
|
145
|
+
export interface TestProgramResult {
|
|
146
|
+
passed: boolean;
|
|
147
|
+
scenarioResults: ScenarioResult[];
|
|
148
|
+
durationMs: number;
|
|
149
|
+
analysis?: AnalysisResult;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// =============================================================================
|
|
153
|
+
// Config
|
|
154
|
+
// =============================================================================
|
|
155
|
+
|
|
156
|
+
/** Configuration for the in-process test runner */
|
|
157
|
+
export interface TestRunnerConfig {
|
|
158
|
+
actionHandlers?: Record<string, ActionHandlerFn>;
|
|
159
|
+
onStepComplete?: (scenarioIdx: number, step: StepResult) => void;
|
|
160
|
+
onScenarioComplete?: (result: ScenarioResult) => void;
|
|
161
|
+
abortSignal?: AbortSignal;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// =============================================================================
|
|
165
|
+
// API Test Adapter — platform-agnostic interface for HTTP + WS
|
|
166
|
+
// =============================================================================
|
|
167
|
+
|
|
168
|
+
/** Snapshot of a server-side workflow instance */
|
|
169
|
+
export interface ApiInstanceSnapshot {
|
|
170
|
+
id: string;
|
|
171
|
+
currentState: string;
|
|
172
|
+
status: string;
|
|
173
|
+
stateData: Record<string, unknown>;
|
|
174
|
+
availableTransitions: string[];
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** Result of triggering a transition via API */
|
|
178
|
+
export interface ApiTransitionResult {
|
|
179
|
+
success: boolean;
|
|
180
|
+
fromState: string;
|
|
181
|
+
toState: string;
|
|
182
|
+
error?: string;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Adapter interface for the API test runner.
|
|
187
|
+
* Platform-agnostic — implement with fetch, axios, or any HTTP client.
|
|
188
|
+
* The server (NestJS backend) is the MM Player; the adapter is the client.
|
|
189
|
+
*/
|
|
190
|
+
export interface ApiTestAdapter {
|
|
191
|
+
// Instance lifecycle
|
|
192
|
+
createInstance(params: {
|
|
193
|
+
definitionSlug: string;
|
|
194
|
+
stateData?: Record<string, unknown>;
|
|
195
|
+
entityType?: string;
|
|
196
|
+
entityId?: string;
|
|
197
|
+
}): Promise<ApiInstanceSnapshot>;
|
|
198
|
+
|
|
199
|
+
startInstance(instanceId: string): Promise<ApiInstanceSnapshot>;
|
|
200
|
+
|
|
201
|
+
deleteInstance(instanceId: string): Promise<void>;
|
|
202
|
+
|
|
203
|
+
// Actions
|
|
204
|
+
triggerTransition(
|
|
205
|
+
instanceId: string,
|
|
206
|
+
transitionName: string,
|
|
207
|
+
data?: Record<string, unknown>,
|
|
208
|
+
): Promise<ApiTransitionResult>;
|
|
209
|
+
|
|
210
|
+
updateStateData(
|
|
211
|
+
instanceId: string,
|
|
212
|
+
data: Record<string, unknown>,
|
|
213
|
+
): Promise<ApiInstanceSnapshot>;
|
|
214
|
+
|
|
215
|
+
// Query
|
|
216
|
+
getInstance(instanceId: string): Promise<ApiInstanceSnapshot>;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/** Configuration for the API test runner */
|
|
220
|
+
export interface ApiTestRunnerConfig {
|
|
221
|
+
adapter: ApiTestAdapter;
|
|
222
|
+
/** Delay (ms) after actions to let EventRouter settle cross-instance reactions. Default: 200 */
|
|
223
|
+
settleDelayMs?: number;
|
|
224
|
+
/** Delete instances after scenario completes. Default: true */
|
|
225
|
+
cleanupInstances?: boolean;
|
|
226
|
+
onStepComplete?: (scenarioIdx: number, step: StepResult) => void;
|
|
227
|
+
onScenarioComplete?: (result: ScenarioResult) => void;
|
|
228
|
+
/** Called when a real instance is created on the server */
|
|
229
|
+
onInstanceCreated?: (testInstanceId: string, serverId: string) => void;
|
|
230
|
+
abortSignal?: AbortSignal;
|
|
231
|
+
}
|