| 1 | import { filterComposerPullRequestMatches } from "@t3tools/shared/composerPullRequestMatches"; |
| 2 | import { describe, expect, it } from "@effect/vitest"; |
| 3 | import { EnvironmentId, ThreadId } from "@t3tools/contracts"; |
| 4 | |
| 5 | import { buildCheckpointDiffTargets, normalizeComposerPathSearchQuery } from "./queryTargets"; |
| 6 | |
| 7 | describe("appQueries", () => { |
| 8 | it("normalizes composer path search input", () => { |
| 9 | expect(normalizeComposerPathSearchQuery(" src/app ")).toBe("src/app"); |
| 10 | expect(normalizeComposerPathSearchQuery(null)).toBe(""); |
| 11 | }); |
| 12 | |
| 13 | it("routes the first turn range through the full-thread diff query", () => { |
| 14 | const environmentId = EnvironmentId.make("environment-a"); |
| 15 | const threadId = ThreadId.make("thread-a"); |
| 16 | |
| 17 | expect( |
| 18 | buildCheckpointDiffTargets({ |
| 19 | environmentId, |
| 20 | threadId, |
| 21 | fromTurnCount: 0, |
| 22 | toTurnCount: 4, |
| 23 | ignoreWhitespace: true, |
| 24 | }), |
| 25 | ).toEqual({ |
| 26 | fullThread: { |
| 27 | environmentId, |
| 28 | input: { |
| 29 | threadId, |
| 30 | toTurnCount: 4, |
| 31 | ignoreWhitespace: true, |
| 32 | }, |
| 33 | }, |
| 34 | turn: null, |
| 35 | }); |
| 36 | }); |
| 37 | |
| 38 | it("routes later ranges through the incremental turn diff query", () => { |
| 39 | const environmentId = EnvironmentId.make("environment-a"); |
| 40 | const threadId = ThreadId.make("thread-a"); |
| 41 | |
| 42 | expect( |
| 43 | buildCheckpointDiffTargets({ |
| 44 | environmentId, |
| 45 | threadId, |
| 46 | fromTurnCount: 3, |
| 47 | toTurnCount: 4, |
| 48 | ignoreWhitespace: false, |
| 49 | }), |
| 50 | ).toEqual({ |
| 51 | fullThread: null, |
| 52 | turn: { |
| 53 | environmentId, |
| 54 | input: { |
| 55 | threadId, |
| 56 | fromTurnCount: 3, |
| 57 | toTurnCount: 4, |
| 58 | ignoreWhitespace: false, |
| 59 | }, |
| 60 | }, |
| 61 | }); |
| 62 | }); |
| 63 | }); |
| 64 | |
| 65 | it("keeps an older exact PR in the mobile menu ahead of twenty newer substring matches", () => { |
| 66 | const exact = { |
| 67 | number: 42, |
| 68 | projectId: "project", |
| 69 | repository: "example/repo", |
| 70 | updatedAt: "2025-01-01", |
| 71 | }; |
| 72 | const recent = Array.from({ length: 25 }, (_, index) => ({ |
| 73 | ...exact, |
| 74 | number: 4200 + index, |
| 75 | updatedAt: "2026-01-01", |
| 76 | })); |
| 77 | const matches = filterComposerPullRequestMatches({ |
| 78 | entries: [exact, ...recent, exact], |
| 79 | projectId: exact.projectId, |
| 80 | repository: exact.repository, |
| 81 | query: "42", |
| 82 | limit: 20, |
| 83 | }); |
| 84 | expect(matches).toHaveLength(20); |
| 85 | expect(matches[0]).toEqual(exact); |
| 86 | expect(matches.filter((entry) => entry.number === 42)).toHaveLength(1); |
| 87 | }); |