@dxos/deus 0.0.0-stage → 0.0.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/LICENSE +105 -0
- package/README.md +24 -2
- package/bin/deus.ts +42 -0
- package/dist/lib/chunk-blocks.mjs +151 -0
- package/dist/lib/chunk-blocks.mjs.map +1 -0
- package/dist/lib/chunk-check.mjs +452 -0
- package/dist/lib/chunk-check.mjs.map +1 -0
- package/dist/lib/chunk-completion.mjs +112 -0
- package/dist/lib/chunk-completion.mjs.map +1 -0
- package/dist/lib/chunk-extension.mjs +396 -0
- package/dist/lib/chunk-extension.mjs.map +1 -0
- package/dist/lib/chunk-parse.mjs +21 -0
- package/dist/lib/chunk-parse.mjs.map +1 -0
- package/dist/lib/cli.mjs +946 -0
- package/dist/lib/cli.mjs.map +1 -0
- package/dist/lib/extension.mjs +4 -0
- package/dist/lib/index.mjs +6 -0
- package/dist/lib/parse.mjs +4 -0
- package/dist/lib/review.mjs +260 -0
- package/dist/lib/review.mjs.map +1 -0
- package/dist/lib/spec-index.mjs +28 -0
- package/dist/lib/spec-index.mjs.map +1 -0
- package/dist/types/bin/deus.d.ts +3 -0
- package/dist/types/bin/deus.d.ts.map +1 -0
- package/dist/types/src/cli/__fixtures__/review/plugin-deps/dx.config.d.ts +8 -0
- package/dist/types/src/cli/__fixtures__/review/plugin-deps/dx.config.d.ts.map +1 -0
- package/dist/types/src/cli/__fixtures__/review/plugin-deps-diverged/dx.config.d.ts +8 -0
- package/dist/types/src/cli/__fixtures__/review/plugin-deps-diverged/dx.config.d.ts.map +1 -0
- package/dist/types/src/cli/__fixtures__/review/plugin-deps-empty/dx.config.d.ts +7 -0
- package/dist/types/src/cli/__fixtures__/review/plugin-deps-empty/dx.config.d.ts.map +1 -0
- package/dist/types/src/cli/__fixtures__/review/plugin-deps-mismatch/dx.config.d.ts +8 -0
- package/dist/types/src/cli/__fixtures__/review/plugin-deps-mismatch/dx.config.d.ts.map +1 -0
- package/dist/types/src/cli/__fixtures__/review/plugin-deps-noplugin/dx.config.d.ts +5 -0
- package/dist/types/src/cli/__fixtures__/review/plugin-deps-noplugin/dx.config.d.ts.map +1 -0
- package/dist/types/src/cli/changelog.d.ts +25 -0
- package/dist/types/src/cli/changelog.d.ts.map +1 -0
- package/dist/types/src/cli/cli.test.d.ts +2 -0
- package/dist/types/src/cli/cli.test.d.ts.map +1 -0
- package/dist/types/src/cli/errors.d.ts +183 -0
- package/dist/types/src/cli/errors.d.ts.map +1 -0
- package/dist/types/src/cli/features.d.ts +58 -0
- package/dist/types/src/cli/features.d.ts.map +1 -0
- package/dist/types/src/cli/git.d.ts +8 -0
- package/dist/types/src/cli/git.d.ts.map +1 -0
- package/dist/types/src/cli/index.d.ts +12 -0
- package/dist/types/src/cli/index.d.ts.map +1 -0
- package/dist/types/src/cli/lint.d.ts +17 -0
- package/dist/types/src/cli/lint.d.ts.map +1 -0
- package/dist/types/src/cli/qa-lint.d.ts +40 -0
- package/dist/types/src/cli/qa-lint.d.ts.map +1 -0
- package/dist/types/src/cli/qa.d.ts +86 -0
- package/dist/types/src/cli/qa.d.ts.map +1 -0
- package/dist/types/src/cli/review.d.ts +38 -0
- package/dist/types/src/cli/review.d.ts.map +1 -0
- package/dist/types/src/cli/spec-index.d.ts +17 -0
- package/dist/types/src/cli/spec-index.d.ts.map +1 -0
- package/dist/types/src/extension/blocks.d.ts +65 -0
- package/dist/types/src/extension/blocks.d.ts.map +1 -0
- package/dist/types/src/extension/check.d.ts +99 -0
- package/dist/types/src/extension/check.d.ts.map +1 -0
- package/dist/types/src/extension/check.test.d.ts +2 -0
- package/dist/types/src/extension/check.test.d.ts.map +1 -0
- package/dist/types/src/extension/code.d.ts +7 -0
- package/dist/types/src/extension/code.d.ts.map +1 -0
- package/dist/types/src/extension/complete.d.ts +6 -0
- package/dist/types/src/extension/complete.d.ts.map +1 -0
- package/dist/types/src/extension/completion.d.ts +10 -0
- package/dist/types/src/extension/completion.d.ts.map +1 -0
- package/dist/types/src/extension/constants.d.ts +6 -0
- package/dist/types/src/extension/constants.d.ts.map +1 -0
- package/dist/types/src/extension/fences.d.ts +10 -0
- package/dist/types/src/extension/fences.d.ts.map +1 -0
- package/dist/types/src/extension/gen/mdl.d.ts +3 -0
- package/dist/types/src/extension/gen/mdl.d.ts.map +1 -0
- package/dist/types/src/extension/gen/mdl.terms.d.ts +2 -0
- package/dist/types/src/extension/gen/mdl.terms.d.ts.map +1 -0
- package/dist/types/src/extension/index.d.ts +8 -0
- package/dist/types/src/extension/index.d.ts.map +1 -0
- package/dist/types/src/extension/language.d.ts +20 -0
- package/dist/types/src/extension/language.d.ts.map +1 -0
- package/dist/types/src/extension/lint.d.ts +8 -0
- package/dist/types/src/extension/lint.d.ts.map +1 -0
- package/dist/types/src/extension/parse.d.ts +6 -0
- package/dist/types/src/extension/parse.d.ts.map +1 -0
- package/dist/types/src/extension/parser.test.d.ts +2 -0
- package/dist/types/src/extension/parser.test.d.ts.map +1 -0
- package/dist/types/src/extension/refs.d.ts +32 -0
- package/dist/types/src/extension/refs.d.ts.map +1 -0
- package/dist/types/src/extension/refs.test.d.ts +2 -0
- package/dist/types/src/extension/refs.test.d.ts.map +1 -0
- package/dist/types/src/extension/syntax.d.ts +12 -0
- package/dist/types/src/extension/syntax.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +3 -0
- package/dist/types/src/index.d.ts.map +1 -0
- package/dist/types/src/review/fields.d.ts +9 -0
- package/dist/types/src/review/fields.d.ts.map +1 -0
- package/dist/types/src/review/index.d.ts +5 -0
- package/dist/types/src/review/index.d.ts.map +1 -0
- package/dist/types/src/review/review.d.ts +70 -0
- package/dist/types/src/review/review.d.ts.map +1 -0
- package/dist/types/src/review/review.test.d.ts +2 -0
- package/dist/types/src/review/review.test.d.ts.map +1 -0
- package/dist/types/src/review/source-key.d.ts +35 -0
- package/dist/types/src/review/source-key.d.ts.map +1 -0
- package/dist/types/src/review/symbol.d.ts +17 -0
- package/dist/types/src/review/symbol.d.ts.map +1 -0
- package/dist/types/src/review/symbol.test.d.ts +2 -0
- package/dist/types/src/review/symbol.test.d.ts.map +1 -0
- package/dist/types/src/spec-index/index.d.ts +3 -0
- package/dist/types/src/spec-index/index.d.ts.map +1 -0
- package/dist/types/src/spec-index/parse.d.ts +11 -0
- package/dist/types/src/spec-index/parse.d.ts.map +1 -0
- package/dist/types/src/spec-index/spec-index.d.ts +21 -0
- package/dist/types/src/spec-index/spec-index.d.ts.map +1 -0
- package/dist/types/src/spec-index/spec-index.test.d.ts +2 -0
- package/dist/types/src/spec-index/spec-index.test.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -0
- package/docs/DESIGN.md +561 -0
- package/docs/IDIOMS.md +265 -0
- package/lang/PLUGIN-.template.mdl +115 -0
- package/lang/app.mdl +200 -0
- package/lang/changelog.mdl +184 -0
- package/lang/core.mdl +203 -0
- package/lang/examples/chess-1.mdl +149 -0
- package/lang/examples/chess-2.mdl +203 -0
- package/lang/examples/chess-3.mdl +231 -0
- package/lang/features.mdl +92 -0
- package/lang/plugin.mdl +59 -0
- package/lang/qa.mdl +383 -0
- package/lang/review.mdl +103 -0
- package/lang/sql.mdl +72 -0
- package/package.json +74 -3
- package/src/cli/__fixtures__/bad-decision.mdl +13 -0
- package/src/cli/__fixtures__/features/CYCLE.mdl +25 -0
- package/src/cli/__fixtures__/features/FEATURES.mdl +47 -0
- package/src/cli/__fixtures__/features/SPEC.mdl +22 -0
- package/src/cli/__fixtures__/features/SPEC.review.mdl +32 -0
- package/src/cli/__fixtures__/features/TASKS.md +5 -0
- package/src/cli/__fixtures__/lint-refs/SPEC.mdl +7 -0
- package/src/cli/__fixtures__/lint-refs/SPEC.review.mdl +7 -0
- package/src/cli/__fixtures__/qa-lint/packages/plugins/plugin-risky/PLUGIN.mdl +29 -0
- package/src/cli/__fixtures__/qa-list/plugin-sample/spec/PLUGIN.mdl +51 -0
- package/src/cli/__fixtures__/review/SPEC.mdl +23 -0
- package/src/cli/__fixtures__/review/SPEC.review.mdl +26 -0
- package/src/cli/__fixtures__/review/plugin-deps/PLUGIN.mdl +9 -0
- package/src/cli/__fixtures__/review/plugin-deps/PLUGIN.review.mdl +13 -0
- package/src/cli/__fixtures__/review/plugin-deps/dx.config.ts +10 -0
- package/src/cli/__fixtures__/review/plugin-deps-diverged/PLUGIN.mdl +9 -0
- package/src/cli/__fixtures__/review/plugin-deps-diverged/PLUGIN.review.mdl +14 -0
- package/src/cli/__fixtures__/review/plugin-deps-diverged/dx.config.ts +10 -0
- package/src/cli/__fixtures__/review/plugin-deps-empty/PLUGIN.mdl +9 -0
- package/src/cli/__fixtures__/review/plugin-deps-empty/PLUGIN.review.mdl +13 -0
- package/src/cli/__fixtures__/review/plugin-deps-empty/dx.config.ts +9 -0
- package/src/cli/__fixtures__/review/plugin-deps-mismatch/PLUGIN.mdl +9 -0
- package/src/cli/__fixtures__/review/plugin-deps-mismatch/PLUGIN.review.mdl +13 -0
- package/src/cli/__fixtures__/review/plugin-deps-mismatch/dx.config.ts +10 -0
- package/src/cli/__fixtures__/review/plugin-deps-noplugin/PLUGIN.mdl +9 -0
- package/src/cli/__fixtures__/review/plugin-deps-noplugin/PLUGIN.review.mdl +13 -0
- package/src/cli/__fixtures__/review/plugin-deps-noplugin/dx.config.ts +7 -0
- package/src/cli/changelog.ts +122 -0
- package/src/cli/cli.test.ts +359 -0
- package/src/cli/errors.ts +23 -0
- package/src/cli/features.ts +320 -0
- package/src/cli/git.ts +35 -0
- package/src/cli/index.ts +27 -0
- package/src/cli/lint.ts +75 -0
- package/src/cli/qa-lint.ts +206 -0
- package/src/cli/qa.ts +300 -0
- package/src/cli/review.ts +359 -0
- package/src/cli/spec-index.ts +54 -0
- package/src/extension/blocks.ts +169 -0
- package/src/extension/check.test.ts +629 -0
- package/src/extension/check.ts +552 -0
- package/src/extension/code.ts +99 -0
- package/src/extension/complete.ts +34 -0
- package/src/extension/completion.ts +64 -0
- package/src/extension/constants.ts +28 -0
- package/src/extension/fences.ts +270 -0
- package/src/extension/gen/mdl.terms.ts +16 -0
- package/src/extension/gen/mdl.ts +16 -0
- package/src/extension/index.ts +25 -0
- package/src/extension/language.ts +33 -0
- package/src/extension/lint.ts +19 -0
- package/src/extension/mdl.grammar +60 -0
- package/src/extension/parse.ts +31 -0
- package/src/extension/parser.test.ts +248 -0
- package/src/extension/refs.test.ts +95 -0
- package/src/extension/refs.ts +94 -0
- package/src/extension/syntax.ts +25 -0
- package/src/index.ts +6 -0
- package/src/review/fields.ts +31 -0
- package/src/review/index.ts +8 -0
- package/src/review/review.test.ts +111 -0
- package/src/review/review.ts +184 -0
- package/src/review/source-key.ts +63 -0
- package/src/review/symbol.test.ts +47 -0
- package/src/review/symbol.ts +96 -0
- package/src/spec-index/index.ts +6 -0
- package/src/spec-index/parse.ts +22 -0
- package/src/spec-index/spec-index.test.ts +56 -0
- package/src/spec-index/spec-index.ts +49 -0
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { describe, test } from 'vitest';
|
|
6
|
+
|
|
7
|
+
import { mdlBlockLanguage } from './syntax.ts';
|
|
8
|
+
|
|
9
|
+
// Parse text and return node names with their matched text, depth-first.
|
|
10
|
+
const parseNodes = (text: string): { name: string; text: string }[] => {
|
|
11
|
+
const tree = mdlBlockLanguage.parser.parse(text);
|
|
12
|
+
const nodes: { name: string; text: string }[] = [];
|
|
13
|
+
const cursor = tree.cursor();
|
|
14
|
+
do {
|
|
15
|
+
nodes.push({ name: cursor.node.type.name, text: text.slice(cursor.from, cursor.to) });
|
|
16
|
+
} while (cursor.next());
|
|
17
|
+
return nodes;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
// Return named rule node names in depth-first order, excluding Block and
|
|
21
|
+
// anonymous punctuation tokens (which start with a non-capital character).
|
|
22
|
+
const nodeNames = (text: string): string[] =>
|
|
23
|
+
parseNodes(text)
|
|
24
|
+
.filter(({ name }) => /^[A-Z]/.test(name) && name !== 'Block')
|
|
25
|
+
.map(({ name }) => name);
|
|
26
|
+
|
|
27
|
+
describe('mdl parser', () => {
|
|
28
|
+
describe('KeyValue', () => {
|
|
29
|
+
test('simple field', ({ expect }) => {
|
|
30
|
+
expect(nodeNames('kind: PieceKind')).toEqual(['KeyValue', 'FieldName', 'TypeExpr', 'TypeAtom', 'TypeName']);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test('optional field', ({ expect }) => {
|
|
34
|
+
expect(nodeNames('piece?: Piece')).toEqual([
|
|
35
|
+
'KeyValue',
|
|
36
|
+
'FieldName',
|
|
37
|
+
'Optional',
|
|
38
|
+
'TypeExpr',
|
|
39
|
+
'TypeAtom',
|
|
40
|
+
'TypeName',
|
|
41
|
+
]);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test('field with inline comment', ({ expect }) => {
|
|
45
|
+
expect(nodeNames('promotion?: PieceKind # only valid for pawn')).toEqual([
|
|
46
|
+
'KeyValue',
|
|
47
|
+
'FieldName',
|
|
48
|
+
'Optional',
|
|
49
|
+
'TypeExpr',
|
|
50
|
+
'TypeAtom',
|
|
51
|
+
'TypeName',
|
|
52
|
+
'Comment',
|
|
53
|
+
]);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test('field with union type', ({ expect }) => {
|
|
57
|
+
expect(nodeNames('status: active | archived')).toEqual([
|
|
58
|
+
'KeyValue',
|
|
59
|
+
'FieldName',
|
|
60
|
+
'TypeExpr',
|
|
61
|
+
'TypeAtom',
|
|
62
|
+
'TypeName',
|
|
63
|
+
'Pipe',
|
|
64
|
+
'TypeAtom',
|
|
65
|
+
'TypeName',
|
|
66
|
+
]);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
test('field with array type', ({ expect }) => {
|
|
70
|
+
expect(nodeNames('moves: Move[]')).toEqual([
|
|
71
|
+
'KeyValue',
|
|
72
|
+
'FieldName',
|
|
73
|
+
'TypeExpr',
|
|
74
|
+
'TypeAtom',
|
|
75
|
+
'ArrayExpr',
|
|
76
|
+
'TypeName',
|
|
77
|
+
]);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
test('field with range', ({ expect }) => {
|
|
81
|
+
expect(nodeNames('rank: 1..8')).toEqual([
|
|
82
|
+
'KeyValue',
|
|
83
|
+
'FieldName',
|
|
84
|
+
'TypeExpr',
|
|
85
|
+
'TypeAtom',
|
|
86
|
+
'NumberRange',
|
|
87
|
+
'Number',
|
|
88
|
+
'Number',
|
|
89
|
+
]);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
test('field with list expression', ({ expect }) => {
|
|
93
|
+
expect(nodeNames('errors: [InvalidMove, WrongTurn, GameOver]')).toEqual([
|
|
94
|
+
'KeyValue',
|
|
95
|
+
'FieldName',
|
|
96
|
+
'TypeExpr',
|
|
97
|
+
'TypeAtom',
|
|
98
|
+
'ListExpr',
|
|
99
|
+
'TypeName',
|
|
100
|
+
'Comma',
|
|
101
|
+
'TypeName',
|
|
102
|
+
'Comma',
|
|
103
|
+
'TypeName',
|
|
104
|
+
]);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
test('field with single-element list', ({ expect }) => {
|
|
108
|
+
expect(nodeNames('requires: [ChessEngine]')).toEqual([
|
|
109
|
+
'KeyValue',
|
|
110
|
+
'FieldName',
|
|
111
|
+
'TypeExpr',
|
|
112
|
+
'TypeAtom',
|
|
113
|
+
'ListExpr',
|
|
114
|
+
'TypeName',
|
|
115
|
+
]);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
test('field with no value', ({ expect }) => {
|
|
119
|
+
// e.g. "fields:" with no inline value — sub-fields follow on next lines.
|
|
120
|
+
expect(nodeNames('fields:')).toEqual(['KeyValue', 'FieldName']);
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
describe('Comment', () => {
|
|
125
|
+
test('standalone comment', ({ expect }) => {
|
|
126
|
+
expect(nodeNames('# only valid for pawn reaching back rank')).toEqual(['Comment']);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
test('comment with leading spaces', ({ expect }) => {
|
|
130
|
+
expect(nodeNames(' # indented comment')).toEqual(['Comment']);
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
describe('multi-line blocks', () => {
|
|
135
|
+
test('type block body', ({ expect }) => {
|
|
136
|
+
const input = ['fields:', ' kind: PieceKind', ' color: Color'].join('\n');
|
|
137
|
+
expect(nodeNames(input)).toEqual([
|
|
138
|
+
'KeyValue',
|
|
139
|
+
'FieldName', // fields: (no value)
|
|
140
|
+
'KeyValue',
|
|
141
|
+
'FieldName',
|
|
142
|
+
'TypeExpr',
|
|
143
|
+
'TypeAtom',
|
|
144
|
+
'TypeName', // kind: PieceKind
|
|
145
|
+
'KeyValue',
|
|
146
|
+
'FieldName',
|
|
147
|
+
'TypeExpr',
|
|
148
|
+
'TypeAtom',
|
|
149
|
+
'TypeName', // color: Color
|
|
150
|
+
]);
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
test('block body with field, comment, and field', ({ expect }) => {
|
|
154
|
+
const input = ['desc: Foo', '# separator', 'req: Bar'].join('\n');
|
|
155
|
+
expect(nodeNames(input)).toEqual([
|
|
156
|
+
'KeyValue',
|
|
157
|
+
'FieldName',
|
|
158
|
+
'TypeExpr',
|
|
159
|
+
'TypeAtom',
|
|
160
|
+
'TypeName', // desc: Foo
|
|
161
|
+
'Comment', // # separator
|
|
162
|
+
'KeyValue',
|
|
163
|
+
'FieldName',
|
|
164
|
+
'TypeExpr',
|
|
165
|
+
'TypeAtom',
|
|
166
|
+
'TypeName', // req: Bar
|
|
167
|
+
]);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
test('union field is present in mixed block', ({ expect }) => {
|
|
171
|
+
const input = ['fields:', ' turn: Color', ' status: active | archived'].join('\n');
|
|
172
|
+
const names = nodeNames(input);
|
|
173
|
+
expect(names.filter((name) => name === 'KeyValue').length).toBe(3);
|
|
174
|
+
expect(names.filter((name) => name === 'Pipe').length).toBe(1);
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
describe('node positions', () => {
|
|
179
|
+
test('FieldName spans the key text', ({ expect }) => {
|
|
180
|
+
const text = 'kind: PieceKind';
|
|
181
|
+
const nodes = parseNodes(text).filter(({ name }) => name === 'FieldName');
|
|
182
|
+
expect(nodes).toHaveLength(1);
|
|
183
|
+
expect(nodes[0].text).toBe('kind');
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
test('TypeExpr spans the value text', ({ expect }) => {
|
|
187
|
+
const text = 'kind: PieceKind';
|
|
188
|
+
const nodes = parseNodes(text).filter(({ name }) => name === 'TypeExpr');
|
|
189
|
+
expect(nodes).toHaveLength(1);
|
|
190
|
+
expect(nodes[0].text).toBe('PieceKind');
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
test('TypeName spans each identifier in a union', ({ expect }) => {
|
|
194
|
+
const text = 'status: active | archived';
|
|
195
|
+
const nodes = parseNodes(text).filter(({ name }) => name === 'TypeName');
|
|
196
|
+
expect(nodes.map(({ text: txt }) => txt)).toEqual(['active', 'archived']);
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
test('Optional spans the ? character', ({ expect }) => {
|
|
200
|
+
const text = 'piece?: Piece';
|
|
201
|
+
const nodes = parseNodes(text).filter(({ name }) => name === 'Optional');
|
|
202
|
+
expect(nodes).toHaveLength(1);
|
|
203
|
+
expect(nodes[0].text).toBe('?');
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
test('Comment spans from # to end of line', ({ expect }) => {
|
|
207
|
+
const text = 'rank: 1..8 # 1 to 8 inclusive';
|
|
208
|
+
const nodes = parseNodes(text).filter(({ name }) => name === 'Comment');
|
|
209
|
+
expect(nodes).toHaveLength(1);
|
|
210
|
+
expect(nodes[0].text).toMatch(/^# 1 to 8 inclusive/);
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
test('NumberRange spans both bounds', ({ expect }) => {
|
|
214
|
+
const text = 'rank: 1..8';
|
|
215
|
+
const nodes = parseNodes(text).filter(({ name }) => name === 'NumberRange');
|
|
216
|
+
expect(nodes).toHaveLength(1);
|
|
217
|
+
expect(nodes[0].text).toBe('1..8');
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
test('ArrayExpr spans TypeName and brackets', ({ expect }) => {
|
|
221
|
+
const text = 'moves: Move[]';
|
|
222
|
+
const nodes = parseNodes(text).filter(({ name }) => name === 'ArrayExpr');
|
|
223
|
+
expect(nodes).toHaveLength(1);
|
|
224
|
+
expect(nodes[0].text).toBe('Move[]');
|
|
225
|
+
});
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
describe('edge cases', () => {
|
|
229
|
+
test('empty input produces no named nodes', ({ expect }) => {
|
|
230
|
+
expect(nodeNames('')).toEqual([]);
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
test('blank lines are skipped', ({ expect }) => {
|
|
234
|
+
expect(nodeNames('kind: PieceKind\n\ncolor: Color')).toEqual([
|
|
235
|
+
'KeyValue',
|
|
236
|
+
'FieldName',
|
|
237
|
+
'TypeExpr',
|
|
238
|
+
'TypeAtom',
|
|
239
|
+
'TypeName',
|
|
240
|
+
'KeyValue',
|
|
241
|
+
'FieldName',
|
|
242
|
+
'TypeExpr',
|
|
243
|
+
'TypeAtom',
|
|
244
|
+
'TypeName',
|
|
245
|
+
]);
|
|
246
|
+
});
|
|
247
|
+
});
|
|
248
|
+
});
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2026 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { describe, test } from 'vitest';
|
|
6
|
+
|
|
7
|
+
import { findSpecRefs, specDependencies } from './refs.ts';
|
|
8
|
+
|
|
9
|
+
const mdl = (...lines: string[]) => ['```mdl', ...lines, '```', ''].join('\n');
|
|
10
|
+
|
|
11
|
+
describe('findSpecRefs', () => {
|
|
12
|
+
test('finds a reference in prose and in an mdl block', ({ expect }) => {
|
|
13
|
+
const text = `See org.dxos.ui.react-ui-canvas#F-9.2 for it.\n\n${mdl('feat F-1: x', ' requires: org.dxos.ui.react-ui-canvas#F-9.2')}`;
|
|
14
|
+
const refs = findSpecRefs(text);
|
|
15
|
+
expect(refs.map(({ id, item }) => ({ id, item }))).toEqual([
|
|
16
|
+
{ id: 'org.dxos.ui.react-ui-canvas', item: 'F-9.2' },
|
|
17
|
+
{ id: 'org.dxos.ui.react-ui-canvas', item: 'F-9.2' },
|
|
18
|
+
]);
|
|
19
|
+
expect(text.slice(refs[0].from, refs[0].to)).toBe('org.dxos.ui.react-ui-canvas#F-9.2');
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
test('excludes trailing sentence punctuation', ({ expect }) => {
|
|
23
|
+
expect(findSpecRefs('see org.a.b#Foo.').map(({ item }) => item)).toEqual(['Foo']);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test('accepts camelCase segments of a plugin id', ({ expect }) => {
|
|
27
|
+
expect(findSpecRefs('the org.dxos.plugin.fileSystem#FileSystem service').map(({ id }) => id)).toEqual([
|
|
28
|
+
'org.dxos.plugin.fileSystem',
|
|
29
|
+
]);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test('ignores github keys and URLs', ({ expect }) => {
|
|
33
|
+
expect(findSpecRefs('github:dxos/dxos/lang/review.mdl#X and https://dxos.org#top')).toEqual([]);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test('ignores references in non-mdl fences', ({ expect }) => {
|
|
37
|
+
const text = '```ts\nconst a = "org.a.b#X";\n```\n\n```\norg.a.b#Y\n```\n';
|
|
38
|
+
expect(findSpecRefs(text)).toEqual([]);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
describe('fences', () => {
|
|
43
|
+
test('ignores refs inside a tilde fence', ({ expect }) => {
|
|
44
|
+
expect(findSpecRefs('~~~ts\norg.a.b#X\n~~~\n')).toEqual([]);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test('a longer outer fence is not closed by an inner fence line', ({ expect }) => {
|
|
48
|
+
const text = '````\n```mdl\n```\norg.a.b#X\n````\norg.a.b#Y\n';
|
|
49
|
+
expect(findSpecRefs(text).map(({ item }) => item)).toEqual(['Y']);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test('an inner info-string line does not close an open fence', ({ expect }) => {
|
|
53
|
+
const text = '```\n```ts\norg.a.b#X\n```\norg.a.b#Y\n';
|
|
54
|
+
expect(findSpecRefs(text).map(({ item }) => item)).toEqual(['Y']);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
describe('specDependencies', () => {
|
|
59
|
+
test('reads uses blocks and the plugin block dependsOn', ({ expect }) => {
|
|
60
|
+
const text = [
|
|
61
|
+
mdl(
|
|
62
|
+
'plugin CanvasPlugin: A canvas.',
|
|
63
|
+
' id: org.dxos.plugin.canvas',
|
|
64
|
+
' dependsOn: [org.dxos.plugin.illustrator, org.dxos.plugin.x]',
|
|
65
|
+
),
|
|
66
|
+
mdl('uses org.dxos.ui.react-ui-canvas: The engine.'),
|
|
67
|
+
].join('\n');
|
|
68
|
+
const deps = specDependencies(text);
|
|
69
|
+
expect(deps.map(({ id, via }) => ({ id, via }))).toEqual([
|
|
70
|
+
{ id: 'org.dxos.plugin.illustrator', via: 'dependsOn' },
|
|
71
|
+
{ id: 'org.dxos.plugin.x', via: 'dependsOn' },
|
|
72
|
+
{ id: 'org.dxos.ui.react-ui-canvas', via: 'uses' },
|
|
73
|
+
]);
|
|
74
|
+
for (const { id, from, to } of deps) {
|
|
75
|
+
expect(text.slice(from, to)).toBe(id);
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
test('reads a block-list dependsOn with offsets', ({ expect }) => {
|
|
80
|
+
const text = mdl(
|
|
81
|
+
'plugin P: A plugin.',
|
|
82
|
+
' id: org.dxos.plugin.p',
|
|
83
|
+
' dependsOn:',
|
|
84
|
+
' - org.dxos.plugin.a # why',
|
|
85
|
+
' - org.dxos.plugin.b',
|
|
86
|
+
' modules:',
|
|
87
|
+
' - M: m',
|
|
88
|
+
);
|
|
89
|
+
const deps = specDependencies(text);
|
|
90
|
+
expect(deps.map(({ id }) => id)).toEqual(['org.dxos.plugin.a', 'org.dxos.plugin.b']);
|
|
91
|
+
for (const { id, from, to } of deps) {
|
|
92
|
+
expect(text.slice(from, to)).toBe(id);
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
});
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2026 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { parseMdlBlocks, scanFenceLines } from './blocks.ts';
|
|
6
|
+
|
|
7
|
+
/** A `<spec id>#<item>` reference, with the offsets of the whole reference text. */
|
|
8
|
+
export type SpecRef = { id: string; item: string; from: number; to: number };
|
|
9
|
+
|
|
10
|
+
/** A spec this one depends on, with the offsets of the id text. */
|
|
11
|
+
export type Dependency = { id: string; via: 'uses' | 'dependsOn'; from: number; to: number };
|
|
12
|
+
|
|
13
|
+
// The lookbehind rejects `github:org/repo/file.mdl#X` keys and URL fragments; the final `\w` drops a sentence period.
|
|
14
|
+
// Segments after the first may be camelCase, as plugin ids are (`org.dxos.plugin.fileSystem`).
|
|
15
|
+
const REF = /(?<![\w/:.#-])([a-z][a-z0-9-]*(?:\.[a-zA-Z0-9-]+)+)#([\w$.-]*\w)/g;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Calls `visit` for each line of prose and of `mdl` fences, with the line's offset in the text.
|
|
19
|
+
* Every other fenced block is skipped, since it holds code rather than spec text.
|
|
20
|
+
*/
|
|
21
|
+
export const scanSpecLines = (text: string, visit: (line: string, offset: number) => void): void =>
|
|
22
|
+
scanFenceLines(text, ({ line, offset, kind, mdl }) => {
|
|
23
|
+
if (kind === 'prose' || (kind === 'body' && mdl)) {
|
|
24
|
+
visit(line, offset);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
/** Finds `<spec id>#<item>` references in prose and in `mdl` fences (comments included). */
|
|
29
|
+
export const findSpecRefs = (text: string): SpecRef[] => {
|
|
30
|
+
const refs: SpecRef[] = [];
|
|
31
|
+
scanSpecLines(text, (line, offset) => {
|
|
32
|
+
for (const match of line.matchAll(REF)) {
|
|
33
|
+
const from = offset + match.index;
|
|
34
|
+
refs.push({ id: match[1], item: match[2], from, to: from + match[0].length });
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
return refs;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const GITHUB_SPEC_KEY = /github:[^\s`'")\]>,]*?\.mdl(?![\w/-]|\.\w)(?:#[\w$.-]*)?/g;
|
|
41
|
+
|
|
42
|
+
/** Finds `github:` keys that point at a `.mdl` file, with the offsets of the whole key. */
|
|
43
|
+
export const findSpecKeys = (text: string): { from: number; to: number }[] => {
|
|
44
|
+
const keys: { from: number; to: number }[] = [];
|
|
45
|
+
scanSpecLines(text, (line, offset) => {
|
|
46
|
+
for (const match of line.matchAll(GITHUB_SPEC_KEY)) {
|
|
47
|
+
keys.push({ from: offset + match.index, to: offset + match.index + match[0].length });
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
return keys;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* The specs this one depends on: every `uses` block id and every entry of the `plugin` block's
|
|
55
|
+
* `dependsOn: [...]`, in document order.
|
|
56
|
+
*/
|
|
57
|
+
export const specDependencies = (text: string): Dependency[] => {
|
|
58
|
+
const deps: Dependency[] = [];
|
|
59
|
+
for (const { type, id, from, body } of parseMdlBlocks(text)) {
|
|
60
|
+
const headerStart = text.indexOf('\n', from) + 1;
|
|
61
|
+
const bodyStart = text.indexOf('\n', headerStart) + 1;
|
|
62
|
+
if (type === 'uses' && id) {
|
|
63
|
+
const idFrom = text.indexOf(id, headerStart + text.slice(headerStart).search(/\S/) + type.length);
|
|
64
|
+
deps.push({ id, via: 'uses', from: idFrom, to: idFrom + id.length });
|
|
65
|
+
} else if (type === 'plugin') {
|
|
66
|
+
let lineFrom = bodyStart;
|
|
67
|
+
let inList = false;
|
|
68
|
+
for (const line of body.split('\n')) {
|
|
69
|
+
const field = line.match(/^[ \t]+dependsOn:[ \t]*(.*?)[ \t]*$/);
|
|
70
|
+
if (field) {
|
|
71
|
+
const inline = field[1].match(/^\[([^\]]*)\]/);
|
|
72
|
+
inList = field[1] === '' || field[1].startsWith('#');
|
|
73
|
+
if (inline) {
|
|
74
|
+
const listFrom = lineFrom + line.indexOf('[', line.indexOf('dependsOn:')) + 1;
|
|
75
|
+
for (const entry of inline[1].matchAll(/[^\s,]+/g)) {
|
|
76
|
+
const idFrom = listFrom + entry.index;
|
|
77
|
+
deps.push({ id: entry[0], via: 'dependsOn', from: idFrom, to: idFrom + entry[0].length });
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
} else if (inList) {
|
|
81
|
+
const item = line.match(/^[ \t]+-[ \t]+([^\s#]+)/);
|
|
82
|
+
if (item) {
|
|
83
|
+
const idFrom = lineFrom + line.indexOf(item[1]);
|
|
84
|
+
deps.push({ id: item[1], via: 'dependsOn', from: idFrom, to: idFrom + item[1].length });
|
|
85
|
+
} else if (line.trim() !== '') {
|
|
86
|
+
inList = false;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
lineFrom += line.length + 1;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return deps;
|
|
94
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2026 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { LRLanguage } from '@codemirror/language';
|
|
6
|
+
|
|
7
|
+
import * as terms from './gen/mdl.terms.ts';
|
|
8
|
+
import { parser } from './gen/mdl.ts';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Language definition for the interior of Spec fenced blocks.
|
|
12
|
+
* Uses the generated Lezer LR parser for structural parsing (completion, linting).
|
|
13
|
+
* Syntax highlighting is handled separately by the regex-based ViewPlugin in fences.ts
|
|
14
|
+
* so that it is immune to LR error-recovery false positives on prose content.
|
|
15
|
+
*/
|
|
16
|
+
export const mdlBlockLanguage = LRLanguage.define({
|
|
17
|
+
name: 'spec-block',
|
|
18
|
+
parser: parser.configure({}),
|
|
19
|
+
languageData: {
|
|
20
|
+
commentTokens: { line: '#' },
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
/** Node type ids of the generated parser, for callers that walk a parse tree (see `QueryDSL.Node`). */
|
|
25
|
+
export const mdlTerms = terms;
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2026 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
const indentOf = (line: string): number => line.length - line.trimStart().length;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The top-level fields of a block body: a field's inline value, or for a `|` block or nested map, its
|
|
9
|
+
* indented lines with the common indent removed.
|
|
10
|
+
*/
|
|
11
|
+
export const parseFields = (body: string): Map<string, { inline?: string; lines: string[] }> => {
|
|
12
|
+
const lines = body.split('\n');
|
|
13
|
+
const contentIndents = lines.filter((line) => line.trim() !== '').map(indentOf);
|
|
14
|
+
const base = contentIndents.length > 0 ? Math.min(...contentIndents) : 0;
|
|
15
|
+
const fields = new Map<string, { inline?: string; lines: string[] }>();
|
|
16
|
+
let current: { inline?: string; lines: string[] } | undefined;
|
|
17
|
+
for (const line of lines) {
|
|
18
|
+
if (line.trim() === '') {
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
const match = indentOf(line) === base && line.trim().match(/^([\w-]+)(\??):(?:\s+(.*))?$/);
|
|
22
|
+
if (match) {
|
|
23
|
+
const inline = match[3]?.trim();
|
|
24
|
+
current = { inline: inline && inline !== '|' && inline !== '>' ? inline : undefined, lines: [] };
|
|
25
|
+
fields.set(match[1], current);
|
|
26
|
+
} else if (current && indentOf(line) > base) {
|
|
27
|
+
current.lines.push(line.trim());
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return fields;
|
|
31
|
+
};
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2026 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { describe, test } from 'vitest';
|
|
6
|
+
|
|
7
|
+
import { parseReview, statusOf, summarizeReview, walkthroughOf } from './review.ts';
|
|
8
|
+
|
|
9
|
+
const fence = (body: string) => ['```mdl', body, '```'].join('\n');
|
|
10
|
+
|
|
11
|
+
const REVIEW = [
|
|
12
|
+
'---',
|
|
13
|
+
'spec: github:dxos/dxos/packages/plugins/plugin-x/PLUGIN.mdl',
|
|
14
|
+
'commit: 0123456789abcdef',
|
|
15
|
+
'date: 2026-10-22',
|
|
16
|
+
'by: agent:claude-code',
|
|
17
|
+
'---',
|
|
18
|
+
'',
|
|
19
|
+
fence(
|
|
20
|
+
[
|
|
21
|
+
'verdict F-1.1: The action is registered.',
|
|
22
|
+
' status: done',
|
|
23
|
+
' evidence: [github:dxos/dxos/packages/plugins/plugin-x/src/a.ts#openThing]',
|
|
24
|
+
' tests: [github:dxos/dxos/packages/plugins/plugin-x/src/a.test.ts#opens]',
|
|
25
|
+
].join('\n'),
|
|
26
|
+
),
|
|
27
|
+
fence(
|
|
28
|
+
['verdict F-1.2: No picker yet.', ' status: missing', ' note: |', ' Nothing calls the dialog.'].join('\n'),
|
|
29
|
+
),
|
|
30
|
+
fence(['verdict Thing: Fields match.', ' status: bogus'].join('\n')),
|
|
31
|
+
].join('\n\n');
|
|
32
|
+
|
|
33
|
+
describe('review', () => {
|
|
34
|
+
test('parses frontmatter and verdicts, dropping unknown statuses', ({ expect }) => {
|
|
35
|
+
const review = parseReview(REVIEW);
|
|
36
|
+
expect(review).toMatchObject({ commit: '0123456789abcdef', by: 'agent:claude-code' });
|
|
37
|
+
expect(review.verdicts).toEqual([
|
|
38
|
+
{
|
|
39
|
+
id: 'F-1.1',
|
|
40
|
+
status: 'done',
|
|
41
|
+
summary: 'The action is registered.',
|
|
42
|
+
evidence: ['github:dxos/dxos/packages/plugins/plugin-x/src/a.ts#openThing'],
|
|
43
|
+
tests: ['github:dxos/dxos/packages/plugins/plugin-x/src/a.test.ts#opens'],
|
|
44
|
+
walkthrough: [],
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
id: 'F-1.2',
|
|
48
|
+
status: 'missing',
|
|
49
|
+
summary: 'No picker yet.',
|
|
50
|
+
evidence: [],
|
|
51
|
+
tests: [],
|
|
52
|
+
walkthrough: [],
|
|
53
|
+
note: 'Nothing calls the dialog.',
|
|
54
|
+
},
|
|
55
|
+
]);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
test('reads evidence wrapped over several lines or as list items', ({ expect }) => {
|
|
59
|
+
const wrapped = fence(
|
|
60
|
+
['verdict T: Ok.', ' status: done', ' evidence:', ' [github:o/r/a.ts#A,', ' github:o/r/b.ts#B]'].join(
|
|
61
|
+
'\n',
|
|
62
|
+
),
|
|
63
|
+
);
|
|
64
|
+
const items = fence(['verdict U: Ok.', ' status: done', ' evidence:', ' - github:o/r/c.ts#C'].join('\n'));
|
|
65
|
+
expect(parseReview(`${wrapped}\n\n${items}`).verdicts.map(({ evidence }) => evidence)).toEqual([
|
|
66
|
+
['github:o/r/a.ts#A', 'github:o/r/b.ts#B'],
|
|
67
|
+
['github:o/r/c.ts#C'],
|
|
68
|
+
]);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test("a walkthrough is the reviewer's steps, or one per evidence key when there are several", ({ expect }) => {
|
|
72
|
+
const review = parseReview(
|
|
73
|
+
[
|
|
74
|
+
fence(
|
|
75
|
+
[
|
|
76
|
+
'verdict op1: Ok.',
|
|
77
|
+
' status: done',
|
|
78
|
+
' evidence: [github:o/r/a.ts#A, github:o/r/b.ts#B]',
|
|
79
|
+
' walkthrough:',
|
|
80
|
+
' - The operation is declared with its schema. github:o/r/a.ts#A',
|
|
81
|
+
' - The handler resolves the checkout',
|
|
82
|
+
' and creates the object. github:o/r/b.ts#B',
|
|
83
|
+
].join('\n'),
|
|
84
|
+
),
|
|
85
|
+
fence(['verdict op2: Ok.', ' status: done', ' evidence: [github:o/r/a.ts#A, github:o/r/c.ts]'].join('\n')),
|
|
86
|
+
fence(['verdict type1: Ok.', ' status: done', ' evidence: [github:o/r/a.ts#T]'].join('\n')),
|
|
87
|
+
].join('\n\n'),
|
|
88
|
+
);
|
|
89
|
+
const [explicit, derived, single] = review.verdicts.map(walkthroughOf);
|
|
90
|
+
expect(explicit).toEqual([
|
|
91
|
+
{ text: 'The operation is declared with its schema', key: 'github:o/r/a.ts#A' },
|
|
92
|
+
{ text: 'The handler resolves the checkout and creates the object', key: 'github:o/r/b.ts#B' },
|
|
93
|
+
]);
|
|
94
|
+
expect(derived).toEqual([
|
|
95
|
+
{ text: '', key: 'github:o/r/a.ts#A' },
|
|
96
|
+
{ text: '', key: 'github:o/r/c.ts' },
|
|
97
|
+
]);
|
|
98
|
+
expect(single).toBeUndefined();
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
test('a feature takes the worst status of its requirements', ({ expect }) => {
|
|
102
|
+
const review = parseReview(REVIEW);
|
|
103
|
+
expect(statusOf(review, 'F-1')).toBe('missing');
|
|
104
|
+
expect(statusOf(review, 'F-1.1')).toBe('done');
|
|
105
|
+
expect(statusOf(review, 'F-2')).toBeUndefined();
|
|
106
|
+
expect(summarizeReview(review)).toEqual([
|
|
107
|
+
{ status: 'done', count: 1 },
|
|
108
|
+
{ status: 'missing', count: 1 },
|
|
109
|
+
]);
|
|
110
|
+
});
|
|
111
|
+
});
|