Skip to content

Commit d0dd74b

Browse files
fix(web): simplify stale file suggestion validation
1 parent db906a5 commit d0dd74b

4 files changed

Lines changed: 27 additions & 180 deletions

File tree

‎apps/web/src/components/chat/ChatComposer.tsx‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,6 @@ import {
204204
type TerminalContextDraft,
205205
type TerminalContextSelection,
206206
} from "../../lib/terminalContext";
207-
import { useComposerPathSearch } from "../../lib/composerPathSearchState";
208207
import {
209208
replaceComposerContextReferences,
210209
toKindScopedComposerContextId,
@@ -280,7 +279,7 @@ import {
280279
type EnvironmentQueryTarget,
281280
} from "~/state/pullRequests";
282281
import { useEnvironmentQuery } from "~/state/query";
283-
import { useDebouncedValue } from "~/state/queries";
282+
import { useComposerPathSearch, useDebouncedValue } from "~/state/queries";
284283
import { ProviderModelPicker } from "./ProviderModelPicker";
285284
import { resolveModelPickerSelectedModel } from "./ModelPickerContent";
286285
import {

‎apps/web/src/composer-logic.test.ts‎

Lines changed: 26 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -50,46 +50,37 @@ const citation: AssistantCitation = {
5050
const citationSource = serializeAssistantCitation(citation).replaceAll("+", "%20");
5151

5252
describe("isPathSuggestionCurrent", () => {
53-
const environmentId = EnvironmentId.make("local");
54-
const target = { environmentId, cwd: "/repo", query: "alpha" };
55-
const trigger = detectComposerTrigger("@alpha", 6)!;
56-
57-
it("accepts a suggestion for the current query, workspace, and environment", () => {
58-
expect(isPathSuggestionCurrent(target, trigger, environmentId, target.cwd)).toBe(true);
59-
});
53+
const searchedTarget = {
54+
environmentId: EnvironmentId.make("local"),
55+
cwd: "/repo",
56+
query: "alpha",
57+
};
6058

61-
it("matches the trimmed search query", () => {
59+
it("allows a file suggestion matching the live search", () => {
6260
expect(
63-
isPathSuggestionCurrent(target, { ...trigger, query: " alpha " }, environmentId, target.cwd),
61+
isPathSuggestionCurrent(
62+
searchedTarget,
63+
detectComposerTrigger("@alpha", 6),
64+
searchedTarget.environmentId,
65+
searchedTarget.cwd,
66+
),
6467
).toBe(true);
6568
});
6669

67-
it("rejects a suggestion from the previous query", () => {
68-
const nextTrigger = detectComposerTrigger("@beta", 5);
69-
expect(isPathSuggestionCurrent(target, nextTrigger, environmentId, target.cwd)).toBe(false);
70-
});
71-
72-
it("rejects a suggestion from another workspace", () => {
73-
expect(isPathSuggestionCurrent(target, trigger, environmentId, "/other-repo")).toBe(false);
74-
});
75-
76-
it("rejects a suggestion from another environment", () => {
77-
expect(isPathSuggestionCurrent(target, trigger, EnvironmentId.make("remote"), target.cwd)).toBe(
78-
false,
79-
);
80-
});
81-
82-
it.each(["slash-command", "skill", "pull-request"] as const)(
83-
"rejects a %s trigger even when its query matches",
84-
(kind) => {
85-
expect(isPathSuggestionCurrent(target, { ...trigger, kind }, environmentId, target.cwd)).toBe(
86-
false,
87-
);
88-
},
89-
);
90-
91-
it("rejects a suggestion after the trigger closes", () => {
92-
expect(isPathSuggestionCurrent(target, null, environmentId, target.cwd)).toBe(false);
70+
it.each([
71+
["query", { ...searchedTarget, query: "beta" }],
72+
["cwd", { ...searchedTarget, cwd: "/other-repo" }],
73+
["environment", { ...searchedTarget, environmentId: EnvironmentId.make("remote") }],
74+
] as const)("rejects a visible file suggestion after the live %s changes", (_change, current) => {
75+
const prompt = `@${current.query}`;
76+
expect(
77+
isPathSuggestionCurrent(
78+
searchedTarget,
79+
detectComposerTrigger(prompt, prompt.length),
80+
current.environmentId,
81+
current.cwd,
82+
),
83+
).toBe(false);
9384
});
9485
});
9586

‎apps/web/src/lib/composerPathSearchState.test.tsx‎

Lines changed: 0 additions & 129 deletions
This file was deleted.

‎apps/web/src/lib/composerPathSearchState.ts‎

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)