Skip to content

Commit 1fc5dda

Browse files
committed
test(commands): add frontmatter engine tests and TLA+ spec
1 parent 04ea407 commit 1fc5dda

5 files changed

Lines changed: 51 additions & 1 deletion

File tree

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
SPECIFICATION Spec
2+
CONSTANTS
3+
Variant = "NoBomStrip"
4+
INVARIANTS TypeOK NoExecutableEngine
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
SPECIFICATION Spec
2+
CONSTANTS
3+
Variant = "None"
4+
INVARIANTS TypeOK NoExecutableEngine
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
SPECIFICATION Spec
2+
CONSTANTS
3+
Variant = "Fixed"
4+
INVARIANTS TypeOK NoExecutableEngine
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---- MODULE CommandFrontmatter ----
2+
\* Models parseCommandFrontmatter (src/services/command/commands.ts).
3+
\* Both callers, scanCommandDirectory and tryLoadCommand, use it. The property test covers both.
4+
\* Source: the header language in a workspace command file. Sink: the gray-matter engine call.
5+
\* Failure: a command file header selects an executable engine and the extension runs its code.
6+
\* Invariant: NoExecutableEngine. gray-matter is an oracle. Only the header language is modeled.
7+
\* Expect: Fixed holds. None fails at once. NoBomStrip fails with a BOM and an executable header.
8+
\* Result: Fixed holds in 6 states. None fails in 1 state. NoBomStrip fails in 1 state, with a BOM.
9+
\* Replay: gray-matter runs a js header in the real library. The guard in the code stops it.
10+
\* Not modeled: the YAML and JSON parsers. The command body.
11+
\* Cost: TLC runs in under 1 second. Agent time is not measured.
12+
\* Review: 1 covered (bot thread on double BOM, PR 2455), 0 added, 0 gap.
13+
\* Replay: two BOMs do not run code in gray-matter. It is a false alarm. A test case stays.
14+
15+
CONSTANT Variant \* "Fixed", "None" or "NoBomStrip"
16+
17+
VARIABLE in
18+
19+
\* "exec" = js or javascript in any case. "data" = yaml, yml, json or no language.
20+
\* "other" = any other name. gray-matter finds no engine for it.
21+
Inputs == [bom : BOOLEAN, lang : {"data", "exec", "other"}]
22+
23+
\* The guard reads the header language. Without the BOM strip it misses the header.
24+
GuardSeesHeader(i) == Variant = "Fixed" \/ (Variant = "NoBomStrip" /\ ~i.bom)
25+
Rejected(i) == GuardSeesHeader(i) /\ i.lang # "data"
26+
Executed(i) == i.lang = "exec" /\ ~Rejected(i)
27+
28+
TypeOK == in \in Inputs
29+
30+
Init == in \in Inputs
31+
Next == UNCHANGED in
32+
Spec == Init /\ [][Next]_in
33+
34+
\* Safety: no input reaches an executable engine.
35+
NoExecutableEngine == ~Executed(in)
36+
37+
====

‎src/services/command/__tests__/frontmatter-commands.spec.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,7 @@ Deploy the app.`
516516
})
517517
})
518518

519+
// Invariant NoExecutableEngine (docs/architecture/tla/CommandFrontmatter.tla): no header runs code.
519520
// Exercise the real parser through both public loading paths.
520521
describe.each(["discovery", "individual"])("%s frontmatter security", (entryPoint) => {
521522
async function load(content: string) {
@@ -527,7 +528,7 @@ describe.each(["discovery", "individual"])("%s frontmatter security", (entryPoin
527528
: await getCommand("/test/cwd", "security-probe")
528529
}
529530

530-
it.each(["javascript", "js", "JS", "JavaScript", " javascript ", "\uFEFF---js"])(
531+
it.each(["javascript", "js", "JS", "JavaScript", " javascript ", "\uFEFF---js", "\uFEFF\uFEFF---javascript"])(
531532
"does not execute %s frontmatter",
532533
async (header) => {
533534
const execute = vi.fn(() => ({ description: "Executed" }))

0 commit comments

Comments
 (0)