fix(webui): keep missing pasted paths silent (#6408)
* fix(attachments): keep missing pasted paths silent * fix(webui): limit missing-path silence to paste inspection
This commit is contained in:
1 parent
06f3981962
commit
9cff5a90cc
2 files changed
+26
-30
No files matched your search
@@ -1582,8 +1582,9 @@ export function ThreadComposer({
|
|||||||
setPathInspection((current) => current?.generation === generation ? { ...current, attachment } : current);
|
setPathInspection((current) => current?.generation === generation ? { ...current, attachment } : current);
|
||||||
}).catch((error: unknown) => {
|
}).catch((error: unknown) => {
|
||||||
if (generation !== pathCheckGeneration.current || pathCheckScope.current !== scopeIdentity) return;
|
if (generation !== pathCheckGeneration.current || pathCheckScope.current !== scopeIdentity) return;
|
||||||
setInlineError(error instanceof Error ? error.message : t("message.attachmentUnavailable"));
|
|
||||||
setPathInspection(null);
|
setPathInspection(null);
|
||||||
|
if (error instanceof Error && "status" in error && error.status === 404) return;
|
||||||
|
setInlineError(error instanceof Error ? error.message : t("message.attachmentUnavailable"));
|
||||||
});
|
});
|
||||||
}, [interactionDisabled, onAttachmentPaste, onInspectAttachment, rawSelection, replaceMentionInput, scopeIdentity, t, value]);
|
}, [interactionDisabled, onAttachmentPaste, onInspectAttachment, rawSelection, replaceMentionInput, scopeIdentity, t, value]);
|
||||||
|
|
||||||
|
|||||||
@@ -372,30 +372,6 @@ describe("ThreadComposer — attachments", () => {
|
|||||||
expect(onSend).toHaveBeenCalledTimes(1);
|
expect(onSend).toHaveBeenCalledTimes(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("keeps a plain-text paste untouched without adding a chip", async () => {
|
|
||||||
const onSend = vi.fn();
|
|
||||||
render(<ThreadComposer onSend={onSend} />);
|
|
||||||
const textarea = screen.getByLabelText(/message input/i);
|
|
||||||
|
|
||||||
fireEvent.paste(textarea, {
|
|
||||||
clipboardData: {
|
|
||||||
files: [],
|
|
||||||
items: [
|
|
||||||
{
|
|
||||||
kind: "string",
|
|
||||||
type: "text/plain",
|
|
||||||
getAsFile: () => null,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
types: ["text/plain"],
|
|
||||||
getData: () => "some pasted text",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(screen.queryByTestId("composer-chip")).toBeNull();
|
|
||||||
expect(encodeImage).not.toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
it("surfaces an inline error when encoding fails", async () => {
|
it("surfaces an inline error when encoding fails", async () => {
|
||||||
const file = pngFile("bad.png");
|
const file = pngFile("bad.png");
|
||||||
encodeImage.mockResolvedValueOnce({
|
encodeImage.mockResolvedValueOnce({
|
||||||
@@ -548,18 +524,37 @@ describe("local attachment paths and video ingress", () => {
|
|||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("keeps failed path text and attachment draft, and does not consume prose or URLs", async () => {
|
it.each([
|
||||||
const inspect = vi.fn().mockRejectedValue(new Error("file not found"));
|
[404, "file not found"],
|
||||||
|
[403, "file is outside the current workspace"],
|
||||||
|
] as const)("retains pasted text on %s, showing only actionable errors", async (status, message) => {
|
||||||
|
const inspect = vi.fn().mockRejectedValue(Object.assign(new Error(message), { status }));
|
||||||
render(<ThreadComposer onSend={vi.fn()} onInspectAttachment={inspect} />);
|
render(<ThreadComposer onSend={vi.fn()} onInspectAttachment={inspect} />);
|
||||||
const input = screen.getByLabelText(/message input/i);
|
const input = screen.getByLabelText(/message input/i);
|
||||||
fireEvent.paste(input, { clipboardData: { items: [], getData: () => "./missing.mp4" } });
|
fireEvent.paste(input, { clipboardData: { items: [], getData: () => "./missing.mp4" } });
|
||||||
await waitFor(() => expect(screen.getByText("file not found")).toBeInTheDocument());
|
await waitFor(() => expect(screen.getByRole("button", { name: /send message/i })).toBeEnabled());
|
||||||
expect(input).toHaveValue("./missing.mp4");
|
expect(input).toHaveValue("./missing.mp4");
|
||||||
for (const text of ["look at ./missing.mp4 please", "https://host/clip.mp4", "const path = './clip.mp4'", "line one\n./clip.mp4"]) {
|
if (status === 404) expect(screen.queryByRole("alert")).not.toBeInTheDocument();
|
||||||
fireEvent.paste(input, { clipboardData: { items: [], getData: () => text } });
|
else expect(screen.getByRole("alert")).toHaveTextContent(message);
|
||||||
|
for (const text of ["some pasted text", "look at ./missing.mp4 please", "https://host/clip.mp4", "const path = './clip.mp4'", "line one\n./clip.mp4"]) {
|
||||||
|
fireEvent.paste(input, {
|
||||||
|
clipboardData: {
|
||||||
|
files: [],
|
||||||
|
items: [
|
||||||
|
{
|
||||||
|
kind: "string",
|
||||||
|
type: "text/plain",
|
||||||
|
getAsFile: () => null,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
types: ["text/plain"],
|
||||||
|
getData: () => text,
|
||||||
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
expect(inspect).toHaveBeenCalledTimes(1);
|
expect(inspect).toHaveBeenCalledTimes(1);
|
||||||
expect(screen.queryByTestId("composer-chip")).not.toBeInTheDocument();
|
expect(screen.queryByTestId("composer-chip")).not.toBeInTheDocument();
|
||||||
|
expect(encodeImage).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("does not charge large local documents against a picked document's upload budget", async () => {
|
it("does not charge large local documents against a picked document's upload budget", async () => {
|
||||||
|
|||||||
Reference in new issue
Block a user