|
4 | 4 | // the files, so the description now says the tool matches names, never |
5 | 5 | // contents. These tests pin that wording and each matching rule it states, so |
6 | 6 | // the description cannot drift from the behavior again. |
| 7 | +// |
| 8 | +// They also pin what an empty result says (#5553): a bare "No matches found" |
| 9 | +// gave a model nothing to correct a pattern with, so it repeated |
| 10 | +// '*.ext' patterns that cannot reach a subdirectory. The empty result now |
| 11 | +// names the pattern and the directory, restates how the pattern is read, and |
| 12 | +// suggests the '**/' form when the pattern has no '**'. |
7 | 13 |
|
8 | 14 | import fs from "fs/promises"; |
9 | 15 | import path from "path"; |
@@ -62,7 +68,32 @@ describe("search_files description (#896, #3419)", () => { |
62 | 68 | }); |
63 | 69 |
|
64 | 70 | it("does not match a file's contents", async () => { |
65 | | - expect(await search("**/needle")).toEqual(["No matches found"]); |
| 71 | + expect(await search("**/needle")).toEqual([ |
| 72 | + `No matches found for pattern '**/needle' under ${dir}. ` + |
| 73 | + "The pattern is a glob matched case-sensitively against each entry's path " + |
| 74 | + "relative to that directory: it matches names, never file contents.", |
| 75 | + ]); |
| 76 | + }); |
| 77 | + |
| 78 | + it("suggests the '**/' form when an empty search's pattern has no '**'", async () => { |
| 79 | + const result = await call(client, "search_files", { |
| 80 | + path: dir, |
| 81 | + pattern: "app*.md", |
| 82 | + }); |
| 83 | + expect(result.isError).toBeFalsy(); |
| 84 | + const text = textOf(result); |
| 85 | + expect(text).toBe( |
| 86 | + `No matches found for pattern 'app*.md' under ${dir}. ` + |
| 87 | + "The pattern is a glob matched case-sensitively against each entry's path " + |
| 88 | + "relative to that directory: it matches names, never file contents. " + |
| 89 | + "It has no '**', so it only matches at one depth ('*.ext' only directly " + |
| 90 | + "under the directory); try '**/app*.md' to match at any depth.", |
| 91 | + ); |
| 92 | + expect(result.structuredContent).toEqual({ content: text }); |
| 93 | + // The suggested pattern is one that works. |
| 94 | + expect(await search("**/app*.md")).toEqual([ |
| 95 | + path.join(dir, "src", "app.md"), |
| 96 | + ]); |
66 | 97 | }); |
67 | 98 |
|
68 | 99 | it("matches '*.ext' only directly under path", async () => { |
|
0 commit comments