1import { assert, it } from "@effect/vitest";
2
3import { fileLinkPills, gradeFileLinks } from "./file-link-grading.ts";
4
5const cwd = "/home/user/app";
6const files = [
7 "packages/server/src/cloud/http.ts",
8 "packages/web/src/api/http.ts",
9 "packages/server/src/index.ts",
10 "packages/web/src/index.ts",
11 "packages/server/src/ws.ts",
12 "packages/server/docs/report.pdf",
13 "/home/user/work/worker/src/worker.ts",
14];
15
16it("grades pills the way chat resolves them against the thread cwd", () => {
17 const text = [
18 "[http.ts](/home/user/app/packages/server/src/cloud/http.ts#L4)",
19 "`packages/server/src/cloud/http.ts:6` and `cloud/http.ts:6`",
20 "`ws.ts:3`, `index.ts:5`, `src/index.ts`, `src/worker.ts`",
21 "[worker.ts](/home/user/work/worker/src/worker.ts)",
22 "[http](cloud/http.ts#L4), [ws](./ws.ts), `./packages/server/src/ws.ts`, `WS.ts:3`",
23 "[`src/ws.ts`](/home/user/app/packages/server/src/ws.ts), [`src/index.ts` boots it](/home/user/app/packages/server/src/ws.ts)",
24 "`/usr/bin/node`, `git rebase --onto`",
25 "```md\n[example](docs/missing.md) and `src/missing.ts`\n```",
26 "Write links as `[example](docs/missing.md)`.",
27 "[report](docs/report.pdf)",
28 ].join("\n");
29 const pills = Object.fromEntries(
30 fileLinkPills(text, cwd, files).map((pill) => [pill.source, pill.works]),
31 );
32 assert.deepStrictEqual(pills, {
33 "/home/user/app/packages/server/src/cloud/http.ts#L4": true,
34 "/home/user/work/worker/src/worker.ts": true,
35 "packages/server/src/cloud/http.ts:6": true,
36 "cloud/http.ts:6": true,
37 "ws.ts:3": true,
38 "cloud/http.ts#L4": true,
39 "./ws.ts": false,
40 "./packages/server/src/ws.ts": true,
41 "WS.ts:3": true,
42 "docs/report.pdf": false,
43 "index.ts:5": false,
44 "src/index.ts": false,
45 "/home/user/app/packages/server/src/ws.ts": true,
46 "src/worker.ts": false,
47 });
48});
49
50it("grades a workspace outside home directories", () => {
51 const pills = fileLinkPills("`src/main.ts` and `/usr/bin/node`", "/tmp/app", ["src/main.ts"]);
52 assert.deepStrictEqual(
53 pills.map((pill) => [pill.source, pill.works]),
54 [["src/main.ts", true]],
55 );
56});
57
58it("needs a finished answer with enough working pills", () => {
59 const passes = (text: string | undefined, minWorking: number) =>
60 gradeFileLinks({ minWorking }, text, cwd, files).every((check) => check.pass);
61 assert.isTrue(passes("See `packages/server/src/ws.ts`.", 1));
62 assert.isFalse(passes("It rebases the last three commits.", 1));
63 assert.isTrue(passes("It rebases the last three commits.", 0));
64 assert.isFalse(passes(undefined, 0));
65 assert.isFalse(passes("`src/index.ts`", 0));
66});