-
Notifications
You must be signed in to change notification settings - Fork 4.9k
fix(pull-requests): render private GitHub images in PR bodies #8446
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Xanacas
wants to merge
5
commits into
pingdotgg:main
Choose a base branch
from
Xanacas:t3code/fix-pr-image-rendering
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1da4829
fix(pull-requests): render private GitHub images in PR bodies
Xanacas 1a12535
fix(server): provide the attachment proxy where route fibers resolve it
Xanacas bd78fb8
test(server): cover GitHubAttachmentProxy redirect resolution
Xanacas fbba68e
fix(clients): fall back to the direct URL when the signed proxy is un…
Xanacas 42a2295
fix(web): keep the standard image fallback on the direct attachment path
Xanacas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,154 @@ | ||
| import * as NodeServices from "@effect/platform-node/NodeServices"; | ||
| import { describe, expect, it } from "@effect/vitest"; | ||
| import * as Effect from "effect/Effect"; | ||
| import * as Layer from "effect/Layer"; | ||
| import * as HttpClient from "effect/unstable/http/HttpClient"; | ||
| import * as HttpClientResponse from "effect/unstable/http/HttpClientResponse"; | ||
|
|
||
| import { ExitCode } from "effect/unstable/process/ChildProcessSpawner"; | ||
|
|
||
| import * as ServerConfig from "../config.ts"; | ||
| import * as GitHubCli from "../sourceControl/GitHubCli.ts"; | ||
| import * as GitHubAttachmentProxy from "./GitHubAttachmentProxy.ts"; | ||
|
|
||
| const ATTACHMENT_URL = "https://github.com/user-attachments/assets/4dcab2ba"; | ||
| const STORAGE_URL = "https://objects.example.test/signed/4dcab2ba"; | ||
|
|
||
| const notImplemented = () => Effect.die("not implemented in this test"); | ||
|
|
||
| const makeGitHubCliLayer = (input: { | ||
| readonly calls: Array<ReadonlyArray<string>>; | ||
| readonly fail?: boolean; | ||
| }) => | ||
| Layer.succeed( | ||
| GitHubCli.GitHubCli, | ||
| GitHubCli.GitHubCli.of({ | ||
| execute: ({ args }) => { | ||
| input.calls.push(args); | ||
| if (input.fail) { | ||
| return Effect.fail( | ||
| new GitHubCli.GitHubCliUnavailableError({ | ||
| command: "gh", | ||
| cwd: "/tmp", | ||
| cause: "gh is not installed", | ||
| }), | ||
| ); | ||
| } | ||
| return Effect.succeed({ | ||
| exitCode: ExitCode(0), | ||
| stdout: "gh-token-1\n", | ||
| stderr: "", | ||
| stdoutTruncated: false, | ||
| stderrTruncated: false, | ||
| }); | ||
| }, | ||
| listOpenPullRequests: notImplemented, | ||
| getPullRequest: notImplemented, | ||
| getRepositoryCloneUrls: notImplemented, | ||
| createRepository: notImplemented, | ||
| createPullRequest: notImplemented, | ||
| getDefaultBranch: notImplemented, | ||
| checkoutPullRequest: notImplemented, | ||
| }), | ||
| ); | ||
|
|
||
| type RecordedRequest = { readonly url: string; readonly authorization: string | undefined }; | ||
|
|
||
| const makeHttpClientLayer = (input: { | ||
| readonly requests: Array<RecordedRequest>; | ||
| readonly status?: number; | ||
| readonly location?: string; | ||
| }) => | ||
| Layer.succeed( | ||
| HttpClient.HttpClient, | ||
| HttpClient.make((request) => | ||
| Effect.sync(() => { | ||
| input.requests.push({ url: request.url, authorization: request.headers["authorization"] }); | ||
| return HttpClientResponse.fromWeb( | ||
| request, | ||
| new Response(null, { | ||
| status: input.status ?? 302, | ||
| headers: input.location === undefined ? {} : { location: input.location }, | ||
| }), | ||
| ); | ||
| }), | ||
| ), | ||
| ); | ||
|
|
||
| const provideProxy = (input: { | ||
| readonly calls?: Array<ReadonlyArray<string>>; | ||
| readonly requests?: Array<RecordedRequest>; | ||
| readonly cliFails?: boolean; | ||
| readonly status?: number; | ||
| readonly location?: string; | ||
| }) => | ||
| Effect.provide( | ||
| GitHubAttachmentProxy.layer.pipe( | ||
| Layer.provide( | ||
| makeGitHubCliLayer({ | ||
| calls: input.calls ?? [], | ||
| ...(input.cliFails !== undefined ? { fail: input.cliFails } : {}), | ||
| }), | ||
| ), | ||
| Layer.provide( | ||
| makeHttpClientLayer({ | ||
| requests: input.requests ?? [], | ||
| ...(input.status !== undefined ? { status: input.status } : {}), | ||
| ...(input.location !== undefined ? { location: input.location } : {}), | ||
| }), | ||
| ), | ||
| Layer.provide(ServerConfig.ServerConfig.layerTest(process.cwd(), { prefix: "t3-gh-proxy-" })), | ||
| Layer.provideMerge(NodeServices.layer), | ||
| ), | ||
| ); | ||
|
|
||
| describe("GitHubAttachmentProxy", () => { | ||
| it.effect("resolves the redirect with the gh token and caches the token read", () => | ||
| Effect.gen(function* () { | ||
| const calls: Array<ReadonlyArray<string>> = []; | ||
| const requests: Array<RecordedRequest> = []; | ||
| yield* Effect.gen(function* () { | ||
| const proxy = yield* GitHubAttachmentProxy.GitHubAttachmentProxy; | ||
| expect(yield* proxy.resolveAttachmentLocation(ATTACHMENT_URL)).toBe(STORAGE_URL); | ||
| expect(yield* proxy.resolveAttachmentLocation(ATTACHMENT_URL)).toBe(STORAGE_URL); | ||
| }).pipe(provideProxy({ calls, requests, location: STORAGE_URL })); | ||
|
|
||
| expect(requests.map((request) => request.authorization)).toEqual([ | ||
| "token gh-token-1", | ||
| "token gh-token-1", | ||
| ]); | ||
| expect(calls).toEqual([["auth", "token", "--hostname", "github.com"]]); | ||
| }), | ||
| ); | ||
|
|
||
| it.effect("still resolves anonymously when no gh token is available", () => | ||
| Effect.gen(function* () { | ||
| const requests: Array<RecordedRequest> = []; | ||
| yield* Effect.gen(function* () { | ||
| const proxy = yield* GitHubAttachmentProxy.GitHubAttachmentProxy; | ||
| expect(yield* proxy.resolveAttachmentLocation(ATTACHMENT_URL)).toBe(STORAGE_URL); | ||
| }).pipe(provideProxy({ requests, cliFails: true, location: STORAGE_URL })); | ||
|
|
||
| expect(requests.map((request) => request.authorization)).toEqual([undefined]); | ||
| }), | ||
| ); | ||
|
|
||
| it.effect("answers null for non-redirect responses and non-https locations", () => | ||
| Effect.gen(function* () { | ||
| yield* Effect.gen(function* () { | ||
| const proxy = yield* GitHubAttachmentProxy.GitHubAttachmentProxy; | ||
| expect(yield* proxy.resolveAttachmentLocation(ATTACHMENT_URL)).toBeNull(); | ||
| }).pipe(provideProxy({ status: 200, location: STORAGE_URL })); | ||
|
|
||
| yield* Effect.gen(function* () { | ||
| const proxy = yield* GitHubAttachmentProxy.GitHubAttachmentProxy; | ||
| expect(yield* proxy.resolveAttachmentLocation(ATTACHMENT_URL)).toBeNull(); | ||
| }).pipe(provideProxy({ location: "http://plain.example.test/asset" })); | ||
|
|
||
| yield* Effect.gen(function* () { | ||
| const proxy = yield* GitHubAttachmentProxy.GitHubAttachmentProxy; | ||
| expect(yield* proxy.resolveAttachmentLocation(ATTACHMENT_URL)).toBeNull(); | ||
| }).pipe(provideProxy({})); | ||
| }), | ||
| ); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 Medium
threads/ThreadFeed.tsx:1635When the signed URL issued for a GitHub attachment returns a load error, the image is rendered as
Image unavailableeven thoughfallbackUriis loadable.fallbackUriis only selected whenuseAssetUrlStatefails before loading; updateThreadMarkdownImageViewto retryfallbackUrifromonErrorbefore marking the image unavailable, matching the web renderer.🤖 Copy this AI Prompt to have your agent fix this: