fix(ttsr): flag text-source inference for unlisted file extensions
`omp ttsr test <file>` inferred the match source from the path extension against a hardcoded allowlist (`SOURCE_FILE_EXT`); a supplied source file whose extension was absent silently fell through to the text (prose) context, where tool-scoped rules can never match. The result was a false negative indistinguishable from a non-matching regex, contradicting the documented "a positional that resolves to a file defaults to tool/edit context" contract. - Emit an explanatory note when a resolvable file path is supplied and the source is inferred as `text`, pointing at `--source tool --tool edit`. Surfaced in both text and `--json` output via `TestReport.inferenceNote`. - Extend the allowlist with the .NET family and other common source languages (cs, razor, cshtml, fs, fsx, vb, sh, bash, sql, zig, dart, scala, ex, exs, proto, tf). Left the fall-through default itself unchanged (inverting the test is a behaviour change and a maintainer call). Fixes #6887
This commit is contained in:
@@ -183,6 +183,41 @@ describe("omp ttsr", () => {
|
||||
expect(stdout).toContain("Triggered");
|
||||
expect(stdout).toContain("astCondition");
|
||||
});
|
||||
|
||||
it("infers tool/edit context for a newly-allowlisted .cs file", async () => {
|
||||
captureStreams();
|
||||
const rulePath = await writeTempRule("class", ["tool:edit(*.cs)"]);
|
||||
const snippetPath = await writeTempSnippet("class A {}", "cs");
|
||||
await run({ action: "test", test: { rule: rulePath, file: snippetPath, source: undefined }, json: true });
|
||||
const report = JSON.parse(stdout);
|
||||
expect(report.source).toBe("tool");
|
||||
expect(report.tool).toBe("edit");
|
||||
expect(report.triggered).toHaveLength(1);
|
||||
// A recognized source file needs no context-mismatch note.
|
||||
expect(report.inferenceNote).toBeUndefined();
|
||||
});
|
||||
|
||||
it("emits an inference note when a supplied file path falls through to text source", async () => {
|
||||
captureStreams();
|
||||
const rulePath = await writeTempRule("class", ["tool:edit(*.cs)"]);
|
||||
const snippetPath = await writeTempSnippet("class A {}", "unknownext");
|
||||
await run({ action: "test", test: { rule: rulePath, file: snippetPath, source: undefined }, json: true });
|
||||
const report = JSON.parse(stdout);
|
||||
expect(report.source).toBe("text");
|
||||
expect(report.inferenceNote).toContain(".unknownext");
|
||||
expect(report.inferenceNote).toContain("--source tool --tool edit");
|
||||
// The tool-scoped rule is a false negative here — the note explains why.
|
||||
expect(report.triggered).toHaveLength(0);
|
||||
});
|
||||
|
||||
it("omits the inference note when --source is explicit", async () => {
|
||||
captureStreams();
|
||||
const rulePath = await writeTempRule("class", ["tool:edit(*.cs)"]);
|
||||
const snippetPath = await writeTempSnippet("class A {}", "unknownext");
|
||||
await run({ action: "test", test: { rule: rulePath, file: snippetPath, source: "text" }, json: true });
|
||||
const report = JSON.parse(stdout);
|
||||
expect(report.inferenceNote).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe("list", () => {
|
||||
|
||||
Reference in New Issue
Block a user