forked from posecode-dev/posecode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocumentation-contract.test.ts
More file actions
85 lines (78 loc) · 2.92 KB
/
Copy pathdocumentation-contract.test.ts
File metadata and controls
85 lines (78 loc) · 2.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import { readFileSync } from "node:fs";
import { resolve } from "node:path";
import { describe, expect, it } from "vitest";
import {
ACTION_NAMES,
MODES,
MOVEMENT_KINDS,
PROP_TYPES,
RIG_NAMES,
START_POSE_NAMES,
parse,
} from "../packages/posecode-parser/src/index.js";
const specification = readFileSync(resolve(import.meta.dirname, "../spec/SPEC.md"), "utf8");
const authoringGuide = readFileSync(
resolve(import.meta.dirname, "../spec/llm-authoring.md"),
"utf8",
);
const closedVocabulary = [
...MOVEMENT_KINDS,
...RIG_NAMES,
...START_POSE_NAMES,
...PROP_TYPES,
...MODES,
...ACTION_NAMES,
];
describe("authoring documentation contract", () => {
it("keeps every Posecode example in the LLM guide parseable and warning-free", () => {
const fences = [...authoringGuide.matchAll(/^([ \t]*)```posecode[ \t]*\n([\s\S]*?)^\1```[ \t]*$/gm)];
expect(fences.length).toBeGreaterThan(0);
for (const [index, fence] of fences.entries()) {
const indent = fence[1] ?? "";
const source = (fence[2] ?? "")
.split("\n")
.map((line) => line.startsWith(indent) ? line.slice(indent.length) : line)
.join("\n");
const documentSource = source.trimStart().startsWith("posecode ")
? source
: [
'posecode posture "Guide snippet"',
" rig humanoid",
" pose start = standing",
"",
...source.split("\n").map((line) => ` ${line}`),
"",
" repeat 1",
].join("\n");
const { ir, errors, warnings } = parse(documentSource);
expect({ example: index + 1, errors }).toEqual({ example: index + 1, errors: [] });
expect({ example: index + 1, warnings }).toEqual({ example: index + 1, warnings: [] });
expect(ir).not.toBeNull();
}
});
it.each([
["the normative specification", specification],
["the pasteable LLM guide", authoringGuide],
])("keeps the parser's core closed vocabulary in %s", (_label, document) => {
for (const token of closedVocabulary) {
expect(document, `missing parser token: ${token}`).toContain(token);
}
});
it.each([
["the normative specification", specification],
["the pasteable LLM guide", authoringGuide],
])("defines contact behavior and display-only cues in %s", (_label, document) => {
for (const directive of ["ground-lock", "reach", "pin", "grip"]) {
expect(document, `missing contact directive: ${directive}`).toContain(`\`${directive}\``);
}
expect(document).toMatch(/cue[^\n]*(display-only|display only)/i);
});
it.each([
["the normative specification", specification],
["the pasteable LLM guide", authoringGuide],
])("documents scoped, sparse custom start poses in %s", (_label, document) => {
expect(document).toMatch(/pose start = (?:standing|<pose>):/);
expect(document).toMatch(/sparse[^\n]*(overlay|joint)/i);
expect(document).toMatch(/loop-reset|loops/i);
});
});