Skip to content

Commit bcf6f56

Browse files
committed
Merge remote-tracking branch 'github/main' into fix/scheduler-timezone-short-label
2 parents a9027f9 + a09aef3 commit bcf6f56

16 files changed

Lines changed: 483 additions & 77 deletions

File tree

‎apps/mobile/src/features/pull-requests/PullRequestMarkdown.tsx‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ export function PullRequestMarkdownRepository(props: {
5757
projectId: target.input.projectId,
5858
});
5959
const cwd = project?.workspaceRoot;
60-
const media = cwd ? { environmentId: target.environmentId, cwd } : null;
60+
const media = cwd
61+
? { environmentId: target.environmentId, cwd, repository: target.input.repository }
62+
: null;
6163
return (
6264
<AutolinksContext value={autolinks}>
6365
<LineBreaksContext value={lineBreaks}>

‎apps/mobile/src/features/pull-requests/PullRequestMedia.tsx‎

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import { createContext, useContext, useState } from "react";
2-
import { pullRequestMediaSource, pullRequestImageSource } from "./pullRequestMediaSource";
3-
import { useFilePreviewGallery } from "../../components/FilePreviewGallery";
4-
import { sourceControlClients } from "@t3tools/client-runtime/source-control-clients";
52
import {
6-
SOURCE_CONTROL_MEDIA_ASSET,
7-
type AssetResource,
8-
type EnvironmentId,
9-
} from "@t3tools/contracts";
3+
pullRequestMediaSource,
4+
pullRequestImageSource,
5+
type PullRequestMediaLocation,
6+
} from "./pullRequestMediaSource";
7+
import { useFilePreviewGallery } from "../../components/FilePreviewGallery";
108
import { videoMimeType } from "@t3tools/shared/video";
119
import { Pressable, View } from "react-native";
1210
import { Image } from "expo-image";
@@ -25,25 +23,19 @@ import {
2523

2624
export const PullRequestMediaVisibleContext = createContext(true);
2725

28-
export const PullRequestMediaContext = createContext<{
29-
readonly environmentId: EnvironmentId;
30-
readonly cwd: string;
31-
} | null>(null);
26+
export const PullRequestMediaContext = createContext<PullRequestMediaLocation | null>(null);
3227

3328
export function usePullRequestMediaUrl(url: string) {
3429
const context = useContext(PullRequestMediaContext);
35-
const fetchUrl = sourceControlClients.mediaUrl(url)?.fetchUrl;
36-
const resource: AssetResource | null =
37-
context && fetchUrl
38-
? { _tag: SOURCE_CONTROL_MEDIA_ASSET, cwd: context.cwd, url: fetchUrl }
39-
: null;
30+
const source = pullRequestMediaSource(url, context);
31+
const resource = "resource" in source ? (source.resource ?? null) : null;
4032
const asset = useAssetUrlState(context?.environmentId ?? null, resource);
4133
const refresh = useRefreshAssetUrl(context?.environmentId ?? null, resource);
4234
return {
4335
uri: asset._tag === "Success" ? asset.url : resource ? null : url,
4436
cacheKey: context && resource ? assetImageCacheKey(context.environmentId, resource) : undefined,
4537
unavailable: resource !== null && asset._tag === "Failure",
46-
source: pullRequestMediaSource(url, context),
38+
source,
4739
resolvePlaybackUri: resource ? async () => (await refresh()) ?? null : undefined,
4840
};
4941
}

‎apps/mobile/src/features/pull-requests/pullRequestMediaSource.test.ts‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ import { EnvironmentId } from "@t3tools/contracts";
33
import { filePreviewGallery } from "../../lib/filePreviewGallery";
44
import { pullRequestImageSource } from "./pullRequestMediaSource";
55

6-
const location = { environmentId: EnvironmentId.make("test"), cwd: "/repo" };
6+
const location = {
7+
environmentId: EnvironmentId.make("test"),
8+
cwd: "/repo",
9+
repository: "enterprise/private",
10+
};
711
const url = "https://github.com/user-attachments/assets/abc-123";
812

913
describe("PR media previews", () => {
@@ -13,6 +17,9 @@ describe("PR media previews", () => {
1317
const selected = { ...second, sourceIdentifier: "tapped" };
1418
const gallery = filePreviewGallery(selected, [first, second]);
1519
expect(gallery).toEqual([first, selected]);
16-
expect(gallery.every((item) => "resource" in item)).toBe(true);
20+
expect(gallery).toMatchObject([
21+
{ resource: { url, repository: location.repository } },
22+
{ resource: { url: `${url}-second`, repository: location.repository } },
23+
]);
1724
});
1825
});

‎apps/mobile/src/features/pull-requests/pullRequestMediaSource.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type { FilePreviewItem } from "../../components/FilePreviewModal.types";
55
export interface PullRequestMediaLocation {
66
readonly environmentId: EnvironmentId;
77
readonly cwd: string;
8+
readonly repository?: string;
89
}
910

1011
/** Keep the original resource identity so previewers can resolve and renew its capability. */
@@ -13,7 +14,12 @@ export function pullRequestMediaSource(url: string, location: PullRequestMediaLo
1314
return location && fetchUrl
1415
? {
1516
environmentId: location.environmentId,
16-
resource: { _tag: SOURCE_CONTROL_MEDIA_ASSET, cwd: location.cwd, url: fetchUrl },
17+
resource: {
18+
_tag: SOURCE_CONTROL_MEDIA_ASSET,
19+
cwd: location.cwd,
20+
url: fetchUrl,
21+
...(location.repository ? { repository: location.repository } : {}),
22+
},
1723
}
1824
: { uri: url };
1925
}

‎apps/mobile/src/lib/videoPreviewSource.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ export function mediaVideoThumbnailKey(source: MediaVideoPreviewSource): string
6363
source.environmentId,
6464
source.resource.cwd,
6565
source.resource.url,
66+
source.resource.repository ?? "",
6667
]
6768
: [
6869
"media-video",

‎apps/server/src/assets/AssetAccess.test.ts‎

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import * as WorkspacePaths from "../workspace/WorkspacePaths.ts";
3535
import { assetFileResponse } from "../http.ts";
3636
import { ASSET_ROUTE_PREFIX, issueAssetUrl, readMcpAppHtml, resolveAsset } from "./AssetAccess.ts";
3737
import * as NativeAppIconResolver from "./NativeAppIconResolver.ts";
38+
import * as RepositoryIdentityResolver from "../project/RepositoryIdentityResolver.ts";
3839
import { symlinksSupported } from "@t3tools/shared/testing/symlinks";
3940
import { fakeSourceControlDriverInstance } from "@t3tools/source-control-testing/fakeSourceControlDriver";
4041
import * as BuiltInDrivers from "../sourceControl/builtInDrivers.ts";
@@ -1471,8 +1472,37 @@ describe("AssetAccess", () => {
14711472
}).pipe(Effect.provide(layerTest)),
14721473
);
14731474

1475+
it.effect("preserves the change request repository through RPC decoding and signed media", () =>
1476+
Effect.gen(function* () {
1477+
const decodeAssetCreateUrlInput = Schema.decodeEffect(AssetCreateUrlInput);
1478+
const resource = {
1479+
_tag: SOURCE_CONTROL_MEDIA_ASSET,
1480+
cwd: "/personal-fork",
1481+
url: "https://github.com/user-attachments/assets/1a1842fb-6383-492f-873c-57aa0033fa6c",
1482+
repository: "enterprise/private",
1483+
};
1484+
const input = yield* decodeAssetCreateUrlInput({ resource });
1485+
const issued = yield* issueAssetUrl(input);
1486+
const suffix = issued.relativeUrl.slice(`${ASSET_ROUTE_PREFIX}/`.length);
1487+
const separator = suffix.indexOf("/");
1488+
const resolved = yield* resolveAsset(suffix.slice(0, separator), suffix.slice(separator + 1));
1489+
1490+
expect(resolved).toEqual({
1491+
kind: "source-control-media",
1492+
url: resource.url,
1493+
cwd: resource.cwd,
1494+
repository: resource.repository,
1495+
expiresAt: issued.expiresAt,
1496+
});
1497+
}).pipe(Effect.provide(layerTest)),
1498+
);
1499+
14741500
it.effect("serves a host's credentialed media through that host's driver", () => {
1475-
const fetched: Array<{ url: string; headers: Readonly<Record<string, string>> }> = [];
1501+
const fetched: Array<{
1502+
url: string;
1503+
headers: Readonly<Record<string, string>>;
1504+
repository?: string;
1505+
}> = [];
14761506
const url = "https://github.com/owner/repo/blob/main/docs/shot.png";
14771507
const media = sourceControlDefinitions.mediaUrl(url)!;
14781508
const layerDrivers = Layer.succeed(BuiltInDrivers.SourceControlDrivers, [
@@ -1491,6 +1521,17 @@ describe("AssetAccess", () => {
14911521
}),
14921522
},
14931523
]);
1524+
// Clients that predate `repository` get the checkout's.
1525+
const layerIdentities = Layer.mock(RepositoryIdentityResolver.RepositoryIdentityResolver)({
1526+
resolve: () =>
1527+
Effect.succeed({
1528+
canonicalKey: "github.com/owner/repo",
1529+
locator: { source: "git-remote", remoteName: "origin", remoteUrl: "" },
1530+
provider: media.definition.kind,
1531+
owner: "owner",
1532+
name: "repo",
1533+
}),
1534+
});
14941535
return Effect.gen(function* () {
14951536
const decodeAssetCreateUrlInput = Schema.decodeEffect(AssetCreateUrlInput);
14961537

@@ -1514,12 +1555,21 @@ describe("AssetAccess", () => {
15141555
range: "bytes=0-4",
15151556
cookie: "session",
15161557
});
1517-
expect(fetched).toEqual([{ url: media.fetchUrl, headers: { range: "bytes=0-4" } }]);
1558+
expect(fetched).toEqual([
1559+
{ url: media.fetchUrl, headers: { range: "bytes=0-4" }, repository: "owner/repo" },
1560+
]);
15181561
expect(response.status).toBe(206);
15191562
// The upstream sent no type, so it comes from the file name the host gave the media.
15201563
expect(response.headers["content-type"]).toBe("image/png");
15211564
expect(response.headers["content-length"]).toBe("5");
1522-
}).pipe(Effect.provide(Layer.merge(layerTest, layerDrivers)), Effect.scoped);
1565+
1566+
// A pull request's own repository wins over the checkout it is shown in.
1567+
yield* sourceControlMediaResponse({ ...asset, repository: "enterprise/private" }, {});
1568+
expect(fetched.at(-1)?.repository).toBe("enterprise/private");
1569+
}).pipe(
1570+
Effect.provide(Layer.mergeAll(layerTest, layerDrivers, layerIdentities)),
1571+
Effect.scoped,
1572+
);
15231573
});
15241574

15251575
it.effect("refuses media no host keeps behind a credential, without echoing the URL", () =>

‎apps/server/src/assets/AssetAccess.ts‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ const AssetClaimsSchema = Schema.Union([
169169
/** A host's `fetchUrl`, narrowed at mint time; the signature is what keeps it there. */
170170
url: Schema.String,
171171
cwd: Schema.String,
172+
repository: Schema.optionalKey(Schema.String),
172173
expiresAt: Schema.Number,
173174
}),
174175
]);
@@ -197,6 +198,7 @@ export type ResolvedAsset =
197198
readonly kind: "source-control-media";
198199
readonly url: string;
199200
readonly cwd: string;
201+
readonly repository?: string;
200202
readonly expiresAt: number;
201203
};
202204

@@ -830,11 +832,12 @@ export const issueAssetUrl = Effect.fn("AssetAccess.issueAssetUrl")(function* (i
830832
if (media === null) {
831833
return yield* new AssetSourceControlMediaUrlValidationError({});
832834
}
835+
const { _tag, ...resource } = input.resource;
833836
claims = {
834837
version: 1,
835838
kind: SOURCE_CONTROL_MEDIA_ASSET,
839+
...resource,
836840
url: media.fetchUrl,
837-
cwd: input.resource.cwd,
838841
expiresAt,
839842
};
840843
fileName = media.fileName;
@@ -944,12 +947,8 @@ export const resolveAsset = Effect.fn("AssetAccess.resolveAsset")(function* (
944947
}
945948

946949
if (claims.kind === SOURCE_CONTROL_MEDIA_ASSET) {
947-
return {
948-
kind: "source-control-media",
949-
url: claims.url,
950-
cwd: claims.cwd,
951-
expiresAt: claims.expiresAt,
952-
} satisfies ResolvedAsset;
950+
const { version: _version, ...media } = claims;
951+
return { ...media, kind: "source-control-media" } satisfies ResolvedAsset;
953952
}
954953

955954
if (claims.kind === "tool-output-image") {

‎apps/server/src/assets/sourceControlMediaResponse.ts‎

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as Effect from "effect/Effect";
44
import * as Option from "effect/Option";
55
import { HttpServerResponse } from "effect/http";
66

7+
import * as RepositoryIdentityResolver from "../project/RepositoryIdentityResolver.ts";
78
import * as BuiltInDrivers from "../sourceControl/builtInDrivers.ts";
89
import { sourceControlDefinitions } from "../sourceControl/sourceControlDefinitions.ts";
910

@@ -25,7 +26,12 @@ const SVG_CONTENT_SECURITY_POLICY = "default-src 'none'; style-src 'unsafe-inlin
2526
export const sourceControlMediaResponse = Effect.fn(
2627
"SourceControlMediaResponse.sourceControlMediaResponse",
2728
)(function* (
28-
asset: { readonly url: string; readonly cwd: string; readonly expiresAt: number },
29+
asset: {
30+
readonly url: string;
31+
readonly cwd: string;
32+
readonly repository?: string;
33+
readonly expiresAt: number;
34+
},
2935
requestHeaders: Record<string, string | undefined>,
3036
) {
3137
const remainingSeconds = Math.floor((asset.expiresAt - (yield* Clock.currentTimeMillis)) / 1000);
@@ -46,7 +52,20 @@ export const sourceControlMediaResponse = Effect.fn(
4652
const value = requestHeaders[name];
4753
if (value !== undefined) forwarded[name] = value;
4854
}
49-
const response = yield* fetchMedia({ url: asset.url, headers: forwarded });
55+
// Clients that predate `repository` fall back to the repository checked out at `cwd`.
56+
let repository = asset.repository;
57+
if (repository === undefined) {
58+
const identities = yield* RepositoryIdentityResolver.RepositoryIdentityResolver;
59+
const identity = yield* identities.resolve(asset.cwd);
60+
if (identity?.provider === media.definition.kind && identity.owner && identity.name) {
61+
repository = `${identity.owner}/${identity.name}`;
62+
}
63+
}
64+
const response = yield* fetchMedia({
65+
url: asset.url,
66+
headers: forwarded,
67+
...(repository === undefined ? {} : { repository }),
68+
});
5069
if (response === null) return HttpServerResponse.empty({ status: 502, headers });
5170
// It carries none of the upstream entity headers: a `content-length` with no body behind it
5271
// holds the connection open until the browser gives up on it.

‎apps/web/src/components/ChatMarkdown.tsx‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,8 @@ interface ChatMarkdownProps {
248248
/** Loads media a source control host keeps behind a credential through the server, which holds
249249
`cwd`'s; without it a private repository's uploads load unauthenticated and 404. */
250250
sourceControlMedia?: boolean | undefined;
251+
/** The change request's repository, when it can differ from the checkout at `cwd`. */
252+
sourceControlMediaRepository?: string | undefined;
251253
headingLevelOffset?: number | undefined;
252254
}
253255

@@ -494,6 +496,7 @@ function useChatMarkdownState({
494496
renderContextReference,
495497
headingLevelOffset = 0,
496498
sourceControlMedia = false,
499+
sourceControlMediaRepository,
497500
}: ChatMarkdownProps) {
498501
const resolvedTheme = useRenderedAppearance();
499502
const markdownRef = useRef<HTMLElement>(null);
@@ -891,6 +894,7 @@ function useChatMarkdownState({
891894
expandMedia,
892895
fileLinkChip,
893896
sourceControlMedia,
897+
sourceControlMediaRepository,
894898
renderContextReference,
895899
headingLevelOffset,
896900
imageBaseDir,
@@ -1365,6 +1369,7 @@ const CHAT_MARKDOWN_COMPONENTS = {
13651369
cwd,
13661370
environmentId,
13671371
sourceControlMedia,
1372+
sourceControlMediaRepository,
13681373
imageBaseDir,
13691374
threadRef,
13701375
workspaceMutationId,
@@ -1451,7 +1456,12 @@ const CHAT_MARKDOWN_COMPONENTS = {
14511456
return (
14521457
<ChatMarkdownAssetImage
14531458
environmentId={environmentId}
1454-
resource={{ _tag: SOURCE_CONTROL_MEDIA_ASSET, cwd, url: hostMediaUrl }}
1459+
resource={{
1460+
_tag: SOURCE_CONTROL_MEDIA_ASSET,
1461+
cwd,
1462+
url: hostMediaUrl,
1463+
...(sourceControlMediaRepository ? { repository: sourceControlMediaRepository } : {}),
1464+
}}
14551465
alt={altText}
14561466
kind={kind}
14571467
copyMarkdown={copyMarkdown}

‎apps/web/src/components/pullRequest/PullRequestDetailPanel.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,13 +236,14 @@ function resolvePullRequestReference(
236236
}
237237

238238
function pullRequestMarkdownContext(
239-
detail: Pick<PullRequestDetail, "provider" | "url"> | null,
239+
detail: Pick<PullRequestDetail, "provider" | "url" | "repository"> | null,
240240
threadRef: ScopedThreadRef | null,
241241
) {
242242
return {
243243
remarkPlugins: pullRequestAutolinkPlugins(detail),
244244
lineBreaks: sourceControlClients.find(detail?.provider ?? "")?.hardLineBreaks ?? false,
245245
threadRef,
246+
repository: detail?.repository ?? null,
246247
};
247248
}
248249

0 commit comments

Comments
 (0)