Skip to content

Commit effee6d

Browse files
committed
test(runtime): pin that an unknown metadata.taskless key is tolerated
The generator asked whether a capture survives discovery with an unrecognised key under `metadata.taskless`, before depending on it. The answer is yes, and the honest form of that answer is that it works by ACCIDENT: `assessCaptureRule` checks the fields it needs and never rejects the ones it does not know, and ast-grep treats `metadata` as opaque. Neither is a decision anyone wrote down, so neither was a promise. Verified end to end before claiming it — a capture carrying `metadata.taskless.note` passes `verify` AND still fires under `check`, which is the assertion that matters. A dropped capture verifies clean and finds nothing, and finding nothing is what a passing run looks like. This test holds the tolerance in place. The generator writes a demonstration disclaimer into the rule rather than only into the HTTP response, because a note in an envelope is gone the moment the rule reaches disk — which is exactly when a reader with no memory of asking for a demo needs to know what it is. Confirmed it bites by making the assessor reject unknown keys, the way a schema-based rewrite plausibly would: it fails, and passes again when restored.
1 parent e6c438a commit effee6d

1 file changed

Lines changed: 68 additions & 0 deletions

File tree

‎packages/cli/test/runtime-harness.test.ts‎

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,74 @@ const ECHO_CHECK = `export default async function (root, matches) {
5959
}
6060
`;
6161

62+
/**
63+
* An unknown key under `metadata.taskless` does not drop the capture.
64+
*
65+
* The generator asked before depending on it, which is the right order, and
66+
* the honest answer was that it works by ACCIDENT rather than by design:
67+
* `assessCaptureRule` checks the fields it needs and never rejects the ones it
68+
* does not know, and ast-grep treats `metadata` as opaque. Neither is a
69+
* decision anybody wrote down, so neither is a promise until something holds
70+
* it.
71+
*
72+
* This holds it. The generator carries a demonstration disclaimer as
73+
* `metadata.taskless.note`, written INTO the rule rather than only into the
74+
* HTTP response, because a note in an envelope is gone the moment the rule
75+
* reaches disk — which is exactly when a reader with no memory of asking for a
76+
* demo needs to know what it is.
77+
*
78+
* The assertion is that the capture still MATCHES, not merely that discovery
79+
* accepted it. A capture that is dropped produces no findings, and no findings
80+
* is what a passing run looks like.
81+
*/
82+
describe("an unknown metadata.taskless key", () => {
83+
let cwd: string;
84+
85+
beforeEach(async () => {
86+
cwd = await mkdtemp(join(tmpdir(), "tskl-unknown-meta-"));
87+
});
88+
89+
afterEach(async () => {
90+
await rm(cwd, { recursive: true, force: true });
91+
});
92+
93+
const withNote = [
94+
"id: env-read-abc12345",
95+
"language: typescript",
96+
"rule:",
97+
" pattern: process.env.$NAME",
98+
"metadata:",
99+
" taskless:",
100+
" version: 1",
101+
" kind: runtime",
102+
" name: env-read",
103+
" check: check.ts",
104+
" match: anchor",
105+
' note: "Example rule. May not apply to this repository."',
106+
"",
107+
].join("\n");
108+
109+
it("is discovered, and its capture still matches", async () => {
110+
await writeRuntimeRule(
111+
cwd,
112+
"env-read",
113+
{ "env.yml": withNote },
114+
ECHO_CHECK
115+
);
116+
await writeFile(
117+
join(cwd, "src.ts"),
118+
"const home = process.env.HOME;\n",
119+
"utf8"
120+
);
121+
122+
const rules = await discoverRuntimeRules(cwd);
123+
expect(rules).toHaveLength(1);
124+
125+
const findings = await executeRuntimeRule(cwd, rules[0]!);
126+
expect(findings.length).toBeGreaterThan(0);
127+
});
128+
});
129+
62130
describe("runtime harness", () => {
63131
let root: string;
64132

0 commit comments

Comments
 (0)