Setting the file. One moment. Workflow Guardrails Test · PR To Video · heygen-com/hyperframes · Skills Docs(opens in a new tab)
scripts/workflow-guardrails.test.mjs
JavaScript·198 lines·8 KB
8
import
{ buildFramePackets }
from
"./frame-packets.mjs"
;
9import { hasCliCommand } from "./preflight.mjs";
10
11function write(path, contents) {
12 mkdirSync(dirname(path), { recursive: true });
13 writeFileSync(path, contents);
14}
15
16test("default project directory is durable and outside the caller repository", () => {
17 const caller = mkdtempSync(join(tmpdir(), "p2v-caller-"));
18 const cache = mkdtempSync(join(tmpdir(), "p2v-cache-"));
19 const result = resolvePrToVideoProjectDir({
20 pr: "https://github.com/EveryInc/compound-engineering-plugin/pull/1092",
21 cwd: caller,
22 env: { XDG_CACHE_HOME: cache, HOME: homedir() },
23 });
24
25 assert.equal(
26 result,
27 join(
28 cache,
29 "hyperframes",
30 "pr-to-video",
31 "everyinc",
32 "compound-engineering-plugin",
33 "compound-engineering-plugin-pr-1092",
34 ),
35 );
36 assert.ok(isAbsolute(result));
37 assert.ok(relative(caller, result).startsWith(".."));
38});
39
40test("explicit project directory is preserved exactly after absolute resolution", () => {
41 const caller = mkdtempSync(join(tmpdir(), "p2v-explicit-caller-"));
42 assert.equal(
43 resolvePrToVideoProjectDir({
44 pr: "EveryInc/compound-engineering-plugin#1092",
45 cwd: caller,
46 explicitDir: "../my-video",
47 env: {},
48 }),
49 resolve(caller, "../my-video"),
50 );
51});
52
53test("distinct owner and repository segments cannot collide in the durable cache", () => {
54 const cache = mkdtempSync(join(tmpdir(), "p2v-cache-collision-"));
55 const first = resolvePrToVideoProjectDir({
56 pr: "foo-bar/baz#1",
57 env: { XDG_CACHE_HOME: cache },
58 });
59 const second = resolvePrToVideoProjectDir({
60 pr: "foo/bar-baz#1",
61 env: { XDG_CACHE_HOME: cache },
62 });
63
64 assert.notEqual(first, second);
65});
66
67test("PR parsing sanitizes owner and repository path traversal", () => {
68 assert.deepEqual(
69 parsePrReference("https://github.com/EveryInc/compound-engineering-plugin/pull/1092"),
70 {
71 owner: "everyinc",
72 repo: "compound-engineering-plugin",
73 number: 1092,
74 },
75 );
76 assert.throws(() => parsePrReference("../../outside#1092"), /valid GitHub PR reference/i);
77});
78
79test("#1092 packets contain selected excerpts but never the full diff", () => {
80 const project = mkdtempSync(join(tmpdir(), "p2v-packets-"));
81 const largeDiff = `diff --git a/noise b/noise\n${"+unselected noise\n".repeat(10_000)}`;
82 write(join(project, "capture", "diff.patch"), largeDiff);
83 write(join(project, "frame.md"), "# compact frame tokens\n");
84 write(
85 join(project, "STORYBOARD.md"),
86 `---\nformat: 1920x1080\n---\n\n## Frame 1 — Diff\n\n- duration: 4s\n- src: compositions/frames/01-diff.html\n- focal: code-diff\n- blueprint: compose\n- rules: text-reveal\n\n### Source excerpt\n\n\`\`\`diff\n-oldCall()\n+newCall({ attested: true })\n\`\`\`\n\n## Frame 2 — Impact\n\n- duration: 3s\n- src: compositions/frames/02-impact.html\n- blueprint: dataviz-countup\n- rules: counting-dynamic-scale\n`,
87 );
88
89 const result = buildFramePackets({
90 projectDir: project,
91 storyboardPath: join(project, "STORYBOARD.md"),
92 outDir: join(project, ".hyperframes", "frame-packets"),
93 maxPacketBytes: 32_000,
94 });
95
96 assert.equal(result.length, 2);
97 const codePacket = readFileSync(result[0].path, "utf8");
98 assert.match(codePacket, /newCall\(\{ attested: true \}\)/);
99 assert.doesNotMatch(codePacket, /unselected noise/);
100 assert.doesNotMatch(codePacket, /code-scroll/);
101 assert.ok(Buffer.byteLength(codePacket) < 32_000);
102 assert.ok(result.every((packet) => packet.path.endsWith(".md")));
103
104 const role = readFileSync(join(project, ".hyperframes", "frame-packets", "_role.md"), "utf8");
105 assert.match(role, /# Frame worker — core contract/);
106 assert.match(role, /# Frame worker — PR-to-video delta/);
107});
108
109test("packet validation is atomic and leaves no partial output on overflow", () => {
110 const project = mkdtempSync(join(tmpdir(), "p2v-packets-atomic-"));
111 const outDir = join(project, ".hyperframes", "frame-packets");
112 write(join(project, "frame.md"), "# frame\n");
113 write(
114 join(project, "STORYBOARD.md"),
115 `---\nformat: 1920x1080\n---\n\n## Frame 1 — Intro\n\n- duration: 2s\n- src: compositions/frames/01-intro.html\n\n## Frame 2 — Diff\n\n- duration: 4s\n- src: compositions/frames/02-diff.html\n- focal: code-diff\n\n### Source excerpt\n\n\`\`\`diff\n${"+oversized line\n".repeat(300)}\`\`\`\n`,
116 );
117
118 assert.throws(
119 () => buildFramePackets({ projectDir: project, outDir, maxPacketBytes: 2_000 }),
120 /limit 2000/,
121 );
122 assert.equal(existsSync(outDir), false);
123});
124
125test("code frames without an upstream-selected excerpt fail before dispatch", () => {
126 const project = mkdtempSync(join(tmpdir(), "p2v-packets-missing-"));
127 write(join(project, "frame.md"), "# frame\n");
128 write(
129 join(project, "STORYBOARD.md"),
130 `---\nformat: 1920x1080\n---\n\n## Frame 1 — Diff\n\n- duration: 4s\n- src: compositions/frames/01-diff.html\n- focal: code-diff\n`,
131 );
132
133 assert.throws(
134 () =>
135 buildFramePackets({
136 projectDir: project,
137 storyboardPath: join(project, "STORYBOARD.md"),
138 outDir: join(project, ".hyperframes", "frame-packets"),
139 }),
140 /Source excerpt/i,
141 );
142});
143
144// The other half of this skill's frame-packets delta. The excerpt guard above is
145// pinned; the code-vocabulary injection was not — deleting `codeVocabularySection`
146// outright left all 455 skills tests green, so the section a code worker reads to
147// pick its registry block could have been dropped silently.
148test("a code frame carries the vocabulary excerpt for the block it names", () => {
149 const project = mkdtempSync(join(tmpdir(), "p2v-packets-vocab-"));
150 write(join(project, "frame.md"), "# frame\n");
151 write(
152 join(project, "STORYBOARD.md"),
153 `---\nformat: 1920x1080\n---\n\n## Frame 1 — Diff\n\n- duration: 4s\n- src: compositions/frames/01-diff.html\n- focal: code-diff\n\n### Source excerpt\n\n\`\`\`diff\n-oldCall()\n+newCall()\n\`\`\`\n`,
154 );
155
156 const [packet] = buildFramePackets({ projectDir: project });
157 const contents = readFileSync(packet.path, "utf8");
158
159 assert.match(contents, /## Code block excerpt \(code-diff\)/);
160 assert.match(contents, /`code-diff`/);
161});
162
163test("a code block the vocabulary does not describe still names itself for install", () => {
164 const project = mkdtempSync(join(tmpdir(), "p2v-packets-vocab-miss-"));
165 write(join(project, "frame.md"), "# frame\n");
166 write(
167 join(project, "STORYBOARD.md"),
168 `---\nformat: 1920x1080\n---\n\n## Frame 1 — Diff\n\n- duration: 4s\n- src: compositions/frames/01-diff.html\n- focal: code-not-in-the-vocabulary\n\n### Source excerpt\n\n\`\`\`diff\n-oldCall()\n+newCall()\n\`\`\`\n`,
169 );
170
171 const [packet] = buildFramePackets({ projectDir: project });
172
173 assert.match(
174 readFileSync(packet.path, "utf8"),
175 /## Code block\n\nUse registry block `code-not-in-the-vocabulary`\./,
176 );
177});
178
179test("a mechanism frame gets no code-block section at all", () => {
180 const project = mkdtempSync(join(tmpdir(), "p2v-packets-mechanism-"));
181 write(join(project, "frame.md"), "# frame\n");
182 write(
183 join(project, "STORYBOARD.md"),
184 `---\nformat: 1920x1080\n---\n\n## Frame 1 — Mechanism\n\n- duration: 4s\n- src: compositions/frames/01-mechanism.html\n- focal: the request-lifecycle flow\n`,
185 );
186
187 const [packet] = buildFramePackets({ projectDir: project });
188
189 assert.doesNotMatch(readFileSync(packet.path, "utf8"), /## Code block/);
190});
191
192test("CLI capability detection rejects skills newer than the available command surface", () => {
193 const stableHelp = `Project:\n lint Validate a composition\n snapshot Capture frames\n\nUnknown command check`;
194 const currentHelp = `Project:\n lint Validate a composition\n check Run the full project validation gate\n snapshot Capture frames`;
195
196 assert.equal(hasCliCommand(stableHelp, "check"), false);
197 assert.equal(hasCliCommand(currentHelp, "check"), true);
198});