Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions apps/web/src/components/ChatMarkdown.permissions.browser.test.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { MISSING_FILE_ACCESS_MESSAGE } from "@t3tools/client-runtime/state/assets";
import {
AuthOrchestrationOperateScope,
EnvironmentId,
Expand Down Expand Up @@ -25,6 +26,12 @@ const state = vi.hoisted(() => ({
openExternal: vi.fn(),
copy: vi.fn(),
pullRequests: [] as ThreadPullRequestLink[],
fileAccess: { canReadFiles: true, isPending: false, error: null as string | null },
}));

vi.mock(import("../state/filesystem"), async (original) => ({
...(await original()),
useFilesystemReadAccess: () => state.fileAccess,
}));

vi.mock(import("../state/use-atom-query-runner"), async (original) => ({
Expand Down Expand Up @@ -130,6 +137,7 @@ function setup() {
state.allowed = true;
state.listeners.clear();
state.pullRequests = [];
state.fileAccess = { canReadFiles: true, isPending: false, error: null };
state.openEditor.mockReset().mockResolvedValue(AsyncResult.success(undefined));
state.link.mockReset().mockResolvedValue(AsyncResult.success(undefined));
state.unlink.mockReset().mockResolvedValue(AsyncResult.success(undefined));
Expand Down Expand Up @@ -278,3 +286,14 @@ it.each(["link-to-thread", "unlink-from-thread"])(
);
},
);

it("explains missing file access for a host video instead of offering a retry", async () => {
using _setup = setup();
state.fileAccess = { canReadFiles: false, isPending: false, error: null };
await using screen = await renderMarkdown("![Demo](/tmp/demo.mp4)");
await expect.element(screen.getByText(/Video unavailable · Demo/)).toBeVisible();
await expect
.element(screen.getByText(MISSING_FILE_ACCESS_MESSAGE, { exact: false }))
.toBeVisible();
await expect.element(screen.getByRole("button", { name: "Retry video" })).not.toBeInTheDocument();
});
18 changes: 10 additions & 8 deletions apps/web/src/components/chat/ChatMarkdownMedia.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ export function ChatMarkdownVideo(props: {
readonly copyMarkdown: string | undefined;
readonly originalUrl?: string | undefined;
readonly sourceFailed?: boolean | undefined;
readonly unavailableDetail?: string | undefined;
readonly style?: CSSProperties | undefined;
readonly mediaIdentity?: string | undefined;
readonly actionsSource?: MediaActionSource | undefined;
Expand All @@ -291,6 +292,7 @@ export function ChatMarkdownVideo(props: {
key={props.mediaIdentity ?? props.copyMarkdown ?? props.src}
src={props.src}
sourceFailed={props.sourceFailed}
unavailableDetail={props.unavailableDetail}
label={props.alt}
originalUrl={props.originalUrl}
style={props.style}
Expand Down Expand Up @@ -373,6 +375,10 @@ export const ChatMarkdownAssetImage = memo(function ChatMarkdownAssetImage(props
: fallbackSrc === undefined
? null
: fallbackSrc + (props.srcFragment ?? "");
const missingFileAccess =
assetUrl._tag === "Failure" &&
assetUrl.reason === "missing-file-access" &&
fallbackSrc === undefined;
const knownSize = assetUrl._tag === "Success" ? assetUrl.imageDimensions : undefined;
const maxHeightRem = props.maxHeightRem ?? 30;
const style =
Expand Down Expand Up @@ -408,12 +414,14 @@ export const ChatMarkdownAssetImage = memo(function ChatMarkdownAssetImage(props
<ChatMarkdownVideo
src={src}
sourceFailed={assetUrl._tag === "Failure" && fallbackSrc === undefined}
unavailableDetail={missingFileAccess ? MISSING_FILE_ACCESS_MESSAGE : undefined}
alt={props.alt}
copyMarkdown={props.copyMarkdown}
originalUrl={props.originalUrl}
style={props.style}
mediaIdentity={JSON.stringify([props.environmentId, props.resource, props.srcFragment])}
onRetry={refreshAssetUrl}
// Retrying cannot grant the missing permission.
onRetry={missingFileAccess ? undefined : refreshAssetUrl}
actionsSource={actionsSource}
/>
);
Expand All @@ -424,13 +432,7 @@ export const ChatMarkdownAssetImage = memo(function ChatMarkdownAssetImage(props
key={JSON.stringify([props.environmentId, props.resource, props.srcFragment])}
src={src}
sourceFailed={assetUrl._tag === "Failure" && fallbackSrc === undefined}
unavailableDetail={
assetUrl._tag === "Failure" &&
assetUrl.reason === "missing-file-access" &&
fallbackSrc === undefined
? MISSING_FILE_ACCESS_MESSAGE
: undefined
}
unavailableDetail={missingFileAccess ? MISSING_FILE_ACCESS_MESSAGE : undefined}
alt={props.alt}
copyMarkdown={props.copyMarkdown}
standalone={props.standalone ?? true}
Expand Down
8 changes: 6 additions & 2 deletions apps/web/src/components/media/MediaVideoPlayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { MediaActions, type MediaActionSource } from "./MediaActions";
interface MediaVideoPlayerProps {
readonly src: string | null;
readonly label: string;
readonly unavailableDetail?: string | undefined;
readonly sourceFailed?: boolean | undefined;
readonly originalUrl?: string | undefined;
readonly revision?: string | null | undefined;
Expand All @@ -31,6 +32,7 @@ interface MediaVideoPlayerProps {
export function MediaVideoPlayer({
src: latestSrc,
label,
unavailableDetail,
sourceFailed = false,
originalUrl,
revision = null,
Expand Down Expand Up @@ -132,13 +134,15 @@ export function MediaVideoPlayer({
<span
role="alert"
className={cn(
"flex aspect-video max-h-full w-full flex-col items-center justify-center gap-3 rounded-lg border border-border/40 bg-muted/40 p-4 text-center text-sm text-muted-foreground",
"flex aspect-video w-full flex-col items-center justify-center gap-3 rounded-lg border border-border/40 bg-muted/40 p-4 text-center text-sm text-muted-foreground",
// Narrow authored videos are too small for the explanation, so let the card grow.
!unavailableDetail && "max-h-full",
stateClassName,
)}
>
<span className="inline-flex items-center gap-1.5">
<TriangleAlertIcon aria-hidden className="size-3.5 shrink-0" />
Video unavailable{label ? ` · ${label}` : ""}
{["Video unavailable", label, unavailableDetail].filter(Boolean).join(" · ")}
</span>
<span className="flex flex-wrap items-center justify-center gap-2">
{latestSrc !== null || onRetry ? (
Expand Down
Loading