@auto-engineer/narrative 0.19.1 → 0.20.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.
Files changed (49) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/.turbo/turbo-format.log +4 -0
  3. package/.turbo/turbo-lint.log +4 -0
  4. package/.turbo/turbo-test.log +14 -0
  5. package/.turbo/turbo-type-check.log +4 -0
  6. package/CHANGELOG.md +4 -7
  7. package/dist/src/commands/export-schema-runner.d.ts +3 -0
  8. package/dist/src/commands/export-schema-runner.d.ts.map +1 -0
  9. package/dist/src/commands/export-schema-runner.js +48 -0
  10. package/dist/src/commands/export-schema-runner.js.map +1 -0
  11. package/dist/src/fluent-builder.specs.d.ts +2 -0
  12. package/dist/src/fluent-builder.specs.d.ts.map +1 -0
  13. package/dist/src/fluent-builder.specs.js +28 -0
  14. package/dist/src/fluent-builder.specs.js.map +1 -0
  15. package/dist/src/getNarratives.cache.specs.d.ts +2 -0
  16. package/dist/src/getNarratives.cache.specs.d.ts.map +1 -0
  17. package/dist/src/getNarratives.cache.specs.js +234 -0
  18. package/dist/src/getNarratives.cache.specs.js.map +1 -0
  19. package/dist/src/getNarratives.specs.d.ts +2 -0
  20. package/dist/src/getNarratives.specs.d.ts.map +1 -0
  21. package/dist/src/getNarratives.specs.js +1307 -0
  22. package/dist/src/getNarratives.specs.js.map +1 -0
  23. package/dist/src/id/addAutoIds.specs.d.ts +2 -0
  24. package/dist/src/id/addAutoIds.specs.d.ts.map +1 -0
  25. package/dist/src/id/addAutoIds.specs.js +602 -0
  26. package/dist/src/id/addAutoIds.specs.js.map +1 -0
  27. package/dist/src/id/hasAllIds.specs.d.ts +2 -0
  28. package/dist/src/id/hasAllIds.specs.d.ts.map +1 -0
  29. package/dist/src/id/hasAllIds.specs.js +424 -0
  30. package/dist/src/id/hasAllIds.specs.js.map +1 -0
  31. package/dist/src/model-to-narrative.specs.d.ts +2 -0
  32. package/dist/src/model-to-narrative.specs.d.ts.map +1 -0
  33. package/dist/src/model-to-narrative.specs.js +2437 -0
  34. package/dist/src/model-to-narrative.specs.js.map +1 -0
  35. package/dist/src/narrative-context.specs.d.ts +2 -0
  36. package/dist/src/narrative-context.specs.d.ts.map +1 -0
  37. package/dist/src/narrative-context.specs.js +260 -0
  38. package/dist/src/narrative-context.specs.js.map +1 -0
  39. package/dist/src/schema.d.ts +302 -302
  40. package/dist/src/transformers/model-to-narrative/generators/gwt.specs.d.ts +2 -0
  41. package/dist/src/transformers/model-to-narrative/generators/gwt.specs.d.ts.map +1 -0
  42. package/dist/src/transformers/model-to-narrative/generators/gwt.specs.js +142 -0
  43. package/dist/src/transformers/model-to-narrative/generators/gwt.specs.js.map +1 -0
  44. package/dist/src/transformers/narrative-to-model/type-inference.specs.d.ts +2 -0
  45. package/dist/src/transformers/narrative-to-model/type-inference.specs.d.ts.map +1 -0
  46. package/dist/src/transformers/narrative-to-model/type-inference.specs.js +177 -0
  47. package/dist/src/transformers/narrative-to-model/type-inference.specs.js.map +1 -0
  48. package/dist/tsconfig.tsbuildinfo +1 -1
  49. package/package.json +4 -4
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=gwt.specs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gwt.specs.d.ts","sourceRoot":"","sources":["../../../../../src/transformers/model-to-narrative/generators/gwt.specs.ts"],"names":[],"mappings":""}
@@ -0,0 +1,142 @@
1
+ import ts from 'typescript';
2
+ import { describe, expect, it } from 'vitest';
3
+ import { buildConsolidatedGwtSpecBlock, buildGwtSpecBlock } from './gwt.js';
4
+ function printNode(node) {
5
+ const printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed });
6
+ const sourceFile = ts.createSourceFile('test.ts', '', ts.ScriptTarget.Latest, false, ts.ScriptKind.TS);
7
+ return printer.printNode(ts.EmitHint.Unspecified, node, sourceFile);
8
+ }
9
+ describe('buildGwtSpecBlock', () => {
10
+ it('generates builder chain pattern for when+then (no given)', () => {
11
+ const gwtBlock = {
12
+ when: { commandRef: 'AddTodo', exampleData: { todoId: 'todo-001', description: 'Buy groceries' } },
13
+ then: [
14
+ {
15
+ eventRef: 'TodoAdded',
16
+ exampleData: {
17
+ todoId: 'todo-001',
18
+ description: 'Buy groceries',
19
+ status: 'pending',
20
+ addedAt: '2030-01-01T09:00:00.000Z',
21
+ },
22
+ },
23
+ ],
24
+ ruleDescription: 'todos can be added to the list',
25
+ exampleDescription: 'adds a new todo successfully',
26
+ ruleId: 'r1B2Cp8Y',
27
+ };
28
+ const result = buildGwtSpecBlock(ts, ts.factory, gwtBlock, 'command');
29
+ const code = printNode(result);
30
+ expect(code).toContain('rule("todos can be added to the list"');
31
+ expect(code).toContain('"r1B2Cp8Y"');
32
+ expect(code).toContain('example("adds a new todo successfully")');
33
+ expect(code).toContain('.when<AddTodo>');
34
+ expect(code).toContain('.then<TodoAdded>');
35
+ expect(code).not.toMatch(/example\("[^"]+",\s*\(\)/);
36
+ });
37
+ it('generates builder chain pattern for given+when+then', () => {
38
+ const gwtBlock = {
39
+ given: [
40
+ {
41
+ eventRef: 'TodoAdded',
42
+ exampleData: {
43
+ todoId: 'todo-001',
44
+ description: 'Buy groceries',
45
+ status: 'pending',
46
+ addedAt: '2030-01-01T09:00:00.000Z',
47
+ },
48
+ },
49
+ ],
50
+ when: { commandRef: 'MarkTodoInProgress', exampleData: { todoId: 'todo-001' } },
51
+ then: [
52
+ {
53
+ eventRef: 'TodoMarkedInProgress',
54
+ exampleData: { todoId: 'todo-001', markedAt: '2030-01-01T10:00:00.000Z' },
55
+ },
56
+ ],
57
+ ruleDescription: 'todos can be moved to in progress',
58
+ exampleDescription: 'moves a pending todo to in progress',
59
+ ruleId: 'r2C3Dq9Z',
60
+ };
61
+ const result = buildGwtSpecBlock(ts, ts.factory, gwtBlock, 'command');
62
+ const code = printNode(result);
63
+ expect(code).toContain('example("moves a pending todo to in progress")');
64
+ expect(code).toContain('.given<TodoAdded>');
65
+ expect(code).toContain('.when<MarkTodoInProgress>');
66
+ expect(code).toContain('.then<TodoMarkedInProgress>');
67
+ expect(code).not.toMatch(/example\("[^"]+",\s*\(\)/);
68
+ });
69
+ it('generates builder chain with .and() for multiple given events', () => {
70
+ const gwtBlock = {
71
+ given: [
72
+ {
73
+ eventRef: 'TodoAdded',
74
+ exampleData: { todoId: 'todo-001', description: 'Buy groceries', status: 'pending' },
75
+ },
76
+ {
77
+ eventRef: 'TodoMarkedInProgress',
78
+ exampleData: { todoId: 'todo-001', markedAt: '2030-01-01T10:00:00.000Z' },
79
+ },
80
+ ],
81
+ when: { commandRef: 'MarkTodoComplete', exampleData: { todoId: 'todo-001' } },
82
+ then: [
83
+ {
84
+ eventRef: 'TodoMarkedComplete',
85
+ exampleData: { todoId: 'todo-001', completedAt: '2030-01-01T11:00:00.000Z' },
86
+ },
87
+ ],
88
+ ruleDescription: 'todos can be marked as complete',
89
+ exampleDescription: 'marks an in-progress todo as complete',
90
+ ruleId: 'r3D4Eq0A',
91
+ };
92
+ const result = buildGwtSpecBlock(ts, ts.factory, gwtBlock, 'command');
93
+ const code = printNode(result);
94
+ expect(code).toContain('.given<TodoAdded>');
95
+ expect(code).toContain('.and<TodoMarkedInProgress>');
96
+ expect(code).toContain('.when<MarkTodoComplete>');
97
+ expect(code).toContain('.then<TodoMarkedComplete>');
98
+ expect(code).not.toMatch(/example\("[^"]+",\s*\(\)/);
99
+ });
100
+ it('still wraps example in rule callback', () => {
101
+ const gwtBlock = {
102
+ when: { commandRef: 'AddTodo', exampleData: { todoId: 'todo-001' } },
103
+ then: [{ eventRef: 'TodoAdded', exampleData: { todoId: 'todo-001' } }],
104
+ ruleDescription: 'test rule',
105
+ exampleDescription: 'test example',
106
+ ruleId: 'testId',
107
+ };
108
+ const result = buildGwtSpecBlock(ts, ts.factory, gwtBlock, 'command');
109
+ const code = printNode(result);
110
+ expect(code).toMatch(/rule\([^)]+\)\s*=>/);
111
+ });
112
+ });
113
+ describe('buildConsolidatedGwtSpecBlock', () => {
114
+ it('generates multiple examples with builder chain pattern', () => {
115
+ const rule = { id: 'r3D4Eq0A', description: 'todos can be marked as complete' };
116
+ const gwtBlocks = [
117
+ {
118
+ given: [{ eventRef: 'TodoAdded', exampleData: { todoId: 'todo-001' } }],
119
+ when: { commandRef: 'MarkTodoComplete', exampleData: { todoId: 'todo-001' } },
120
+ then: [{ eventRef: 'TodoMarkedComplete', exampleData: { todoId: 'todo-001' } }],
121
+ exampleDescription: 'marks an in-progress todo as complete',
122
+ },
123
+ {
124
+ given: [{ eventRef: 'TodoAdded', exampleData: { todoId: 'todo-002' } }],
125
+ when: { commandRef: 'MarkTodoComplete', exampleData: { todoId: 'todo-002' } },
126
+ then: [{ eventRef: 'TodoMarkedComplete', exampleData: { todoId: 'todo-002' } }],
127
+ exampleDescription: 'marks a pending todo directly as complete',
128
+ },
129
+ ];
130
+ const result = buildConsolidatedGwtSpecBlock(ts, ts.factory, rule, gwtBlocks, 'command');
131
+ const code = printNode(result);
132
+ expect(code).toContain('rule("todos can be marked as complete"');
133
+ expect(code).toContain('"r3D4Eq0A"');
134
+ expect(code).toContain('example("marks an in-progress todo as complete")');
135
+ expect(code).toContain('example("marks a pending todo directly as complete")');
136
+ expect(code).toContain('.given<TodoAdded>');
137
+ expect(code).toContain('.when<MarkTodoComplete>');
138
+ expect(code).toContain('.then<TodoMarkedComplete>');
139
+ expect(code).not.toMatch(/example\("[^"]+",\s*\(\)/);
140
+ });
141
+ });
142
+ //# sourceMappingURL=gwt.specs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gwt.specs.js","sourceRoot":"","sources":["../../../../../src/transformers/model-to-narrative/generators/gwt.specs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,6BAA6B,EAAE,iBAAiB,EAAiB,MAAM,OAAO,CAAC;A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D,MAAM,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,0BAA0B,CAAC,CAAC;IACvD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=type-inference.specs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type-inference.specs.d.ts","sourceRoot":"","sources":["../../../../src/transformers/narrative-to-model/type-inference.specs.ts"],"names":[],"mappings":""}
@@ -0,0 +1,177 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { narrativesToModel } from './index.js';
3
+ describe('Type inference in narrative-to-model transformer', () => {
4
+ it('should correctly extract command types from when clauses', () => {
5
+ const flows = [
6
+ {
7
+ name: 'Test Flow',
8
+ id: 'FLOW-001',
9
+ slices: [
10
+ {
11
+ id: 'SLICE-001',
12
+ type: 'command',
13
+ name: 'Submit Answer Command',
14
+ client: { specs: [] },
15
+ server: {
16
+ description: 'Submit answer server',
17
+ specs: [
18
+ {
19
+ type: 'gherkin',
20
+ feature: 'Submit Answer Specs',
21
+ rules: [
22
+ {
23
+ id: 'RULE-001',
24
+ name: 'Should accept answer submission',
25
+ examples: [
26
+ {
27
+ name: 'Valid answer submission',
28
+ steps: [
29
+ {
30
+ keyword: 'When',
31
+ text: 'AnswerQuestion',
32
+ docString: {
33
+ questionnaireId: 'q-001',
34
+ participantId: 'participant-abc',
35
+ questionId: 'q1',
36
+ answer: 'Yes',
37
+ },
38
+ },
39
+ {
40
+ keyword: 'Then',
41
+ text: 'QuestionAnswered',
42
+ docString: {
43
+ questionnaireId: 'q-001',
44
+ participantId: 'participant-abc',
45
+ questionId: 'q1',
46
+ answer: 'Yes',
47
+ savedAt: new Date(),
48
+ },
49
+ },
50
+ ],
51
+ },
52
+ ],
53
+ },
54
+ ],
55
+ },
56
+ ],
57
+ },
58
+ },
59
+ {
60
+ id: 'SLICE-002',
61
+ type: 'command',
62
+ name: 'Submit Questionnaire Command',
63
+ client: { specs: [] },
64
+ server: {
65
+ description: 'Submit questionnaire server',
66
+ specs: [
67
+ {
68
+ type: 'gherkin',
69
+ feature: 'Submit Questionnaire Specs',
70
+ rules: [
71
+ {
72
+ id: 'RULE-002',
73
+ name: 'Should submit questionnaire',
74
+ examples: [
75
+ {
76
+ name: 'Valid questionnaire submission',
77
+ steps: [
78
+ {
79
+ keyword: 'When',
80
+ text: 'SubmitQuestionnaire',
81
+ docString: {
82
+ questionnaireId: 'q-001',
83
+ participantId: 'participant-abc',
84
+ },
85
+ },
86
+ {
87
+ keyword: 'Then',
88
+ text: 'QuestionnaireSubmitted',
89
+ docString: {
90
+ questionnaireId: 'q-001',
91
+ participantId: 'participant-abc',
92
+ submittedAt: new Date(),
93
+ },
94
+ },
95
+ ],
96
+ },
97
+ ],
98
+ },
99
+ ],
100
+ },
101
+ ],
102
+ },
103
+ },
104
+ ],
105
+ },
106
+ ];
107
+ const model = narrativesToModel(flows);
108
+ // Should have the correct command messages extracted
109
+ expect(model.messages.some((msg) => msg.name === 'AnswerQuestion')).toBe(true);
110
+ expect(model.messages.some((msg) => msg.name === 'SubmitQuestionnaire')).toBe(true);
111
+ expect(model.messages.some((msg) => msg.name === 'QuestionAnswered')).toBe(true);
112
+ expect(model.messages.some((msg) => msg.name === 'QuestionnaireSubmitted')).toBe(true);
113
+ // Should NOT have InferredType fallback
114
+ expect(model.messages.some((msg) => msg.name === 'InferredType')).toBe(false);
115
+ // Verify the command messages have the correct structure
116
+ const answerQuestionMsg = model.messages.find((msg) => msg.name === 'AnswerQuestion');
117
+ expect(answerQuestionMsg?.type).toBe('command');
118
+ expect(answerQuestionMsg?.fields).toBeDefined();
119
+ const submitQuestionnaireMsg = model.messages.find((msg) => msg.name === 'SubmitQuestionnaire');
120
+ expect(submitQuestionnaireMsg?.type).toBe('command');
121
+ expect(submitQuestionnaireMsg?.fields).toBeDefined();
122
+ });
123
+ it('should handle single object when/then clauses correctly', () => {
124
+ const flows = [
125
+ {
126
+ name: 'Single Object Flow',
127
+ id: 'FLOW-001',
128
+ slices: [
129
+ {
130
+ id: 'SLICE-001',
131
+ type: 'command',
132
+ name: 'Single Object Command',
133
+ client: { specs: [] },
134
+ server: {
135
+ description: 'Single object server',
136
+ specs: [
137
+ {
138
+ type: 'gherkin',
139
+ feature: 'Single Object Specs',
140
+ rules: [
141
+ {
142
+ id: 'RULE-001',
143
+ name: 'Should handle single object',
144
+ examples: [
145
+ {
146
+ name: 'Single object example',
147
+ steps: [
148
+ {
149
+ keyword: 'When',
150
+ text: 'TestCommand',
151
+ docString: { test: 'value' },
152
+ },
153
+ {
154
+ keyword: 'Then',
155
+ text: 'TestEvent',
156
+ docString: { result: 'success' },
157
+ },
158
+ ],
159
+ },
160
+ ],
161
+ },
162
+ ],
163
+ },
164
+ ],
165
+ },
166
+ },
167
+ ],
168
+ },
169
+ ];
170
+ const model = narrativesToModel(flows);
171
+ // Should extract the command and event types from single objects
172
+ expect(model.messages.some((msg) => msg.name === 'TestCommand')).toBe(true);
173
+ expect(model.messages.some((msg) => msg.name === 'TestEvent')).toBe(true);
174
+ expect(model.messages.some((msg) => msg.name === 'InferredType')).toBe(false);
175
+ });
176
+ });
177
+ //# sourceMappingURL=type-inference.specs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type-inference.specs.js","sourceRoot":"","sources":["../../../../src/transformers/narrative-to-model/type-inference.specs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAE9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAE5C,QAAQ,CAAC,kDAAkD,EAAE,GAAG,EAAE;IAChE,EAAE,CAAC,0DAA0D,EAAE,GAAG,EAAE;QAClE,MAAM,KAAK,GAAgB;YACzB;gBACE,IAAI,EAAE,WAAW;gBACjB,EAAE,EAAE,UAAU;gBACd,MAAM,EAAE;oBACN;wBACE,EAAE,EAAE,WAAW;wBACf,IAAI,EA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