Skip to content

Commit f053d33

Browse files
donjorrsi-pr-agent
authored andcommitted
refactor(upstream-fixes): fork GitHub issue and attachment paths use upstream's request policy after pingdotgg#19224
Fork-Domain: upstream-fixes Fork-Tier: bugfix Fork-Upstreamable: no
1 parent 7d1a2aa commit f053d33

10 files changed

Lines changed: 313 additions & 96 deletions

‎apps/server/src/githubIssue/GitHubIssueService.fork.test.ts‎

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
// Fork-owned: the light read the linked-issue sync uses (RSI-Software/t3code-hyprws#1451).
22
// The harness mirrors `GitHubIssueService.test.ts`, which owns the list, detail, and state tests.
33
import { assert, describe, it, vi } from "@effect/vitest";
4-
import type { OrchestrationProjectShell, ProjectId } from "@t3tools/contracts";
4+
import {
5+
SourceControlProviderKind,
6+
type OrchestrationProjectShell,
7+
type ProjectId,
8+
} from "@t3tools/contracts";
59
import * as Effect from "effect/Effect";
610
import * as Layer from "effect/Layer";
711
import * as Option from "effect/Option";
812

913
import * as ProjectService from "../project/ProjectService.ts";
1014
import * as RepositoryIdentityResolver from "../project/RepositoryIdentityResolver.ts";
11-
import * as GitHubApi from "@t3tools/source-control-github/server/GitHubApi";
15+
import * as GitHubRequestPolicy from "@t3tools/source-control-github/server/GitHubRequestPolicy";
16+
import * as GitHubIssueGraphQl from "./gitHubIssueGraphQl.fork.ts";
1217
import * as GitHubIssueService from "./GitHubIssueService.ts";
1318
import { SUB_ISSUE_REASONS_QUERY } from "./subIssueCloseReasons.fork.ts";
1419

@@ -24,7 +29,7 @@ function project(id: string): OrchestrationProjectShell {
2429
remoteName: "origin",
2530
remoteUrl: "https://github.com/acme/web.git",
2631
},
27-
provider: "github",
32+
provider: SourceControlProviderKind.make("github"),
2833
displayName: "acme/web",
2934
owner: "acme",
3035
name: "web",
@@ -38,12 +43,12 @@ function project(id: string): OrchestrationProjectShell {
3843

3944
function makeService(
4045
projects: ReadonlyArray<OrchestrationProjectShell>,
41-
graphql: GitHubApi.GitHubApi["Service"]["graphql"],
46+
graphql: GitHubIssueGraphQl.GitHubIssueGraphQl["Service"]["graphql"],
4247
) {
4348
return GitHubIssueService.make.pipe(
4449
Effect.provide(
4550
Layer.mergeAll(
46-
Layer.mock(GitHubApi.GitHubApi)({ graphql }),
51+
Layer.mock(GitHubIssueGraphQl.GitHubIssueGraphQl)({ graphql }),
4752
Layer.mock(ProjectService.ProjectService)({
4853
listShells: () => Effect.succeed(projects),
4954
getShell: (projectId) =>
@@ -61,7 +66,7 @@ function makeService(
6166
describe("GitHubIssueService summary", () => {
6267
it.effect("reads only the fields a linked-issue sync stores", () =>
6368
Effect.gen(function* () {
64-
const graphql = vi.fn<GitHubApi.GitHubApi["Service"]["graphql"]>(() =>
69+
const graphql = vi.fn<GitHubIssueGraphQl.GitHubIssueGraphQl["Service"]["graphql"]>(() =>
6570
Effect.succeed(
6671
JSON.stringify({
6772
data: {
@@ -134,7 +139,9 @@ describe("GitHubIssueService detail sub-issue reasons", () => {
134139
state: "OPEN",
135140
};
136141

137-
const makeDetailService = (graphql: GitHubApi.GitHubApi["Service"]["graphql"]) =>
142+
const makeDetailService = (
143+
graphql: GitHubIssueGraphQl.GitHubIssueGraphQl["Service"]["graphql"],
144+
) =>
138145
makeService([project("p1")], graphql).pipe(
139146
Effect.flatMap((service) =>
140147
service.detail({ projectId: "p1" as ProjectId, repository: "acme/web", number: 42 }),
@@ -145,7 +152,7 @@ describe("GitHubIssueService detail sub-issue reasons", () => {
145152
Effect.gen(function* () {
146153
const payload = JSON.parse(detailPayload([]));
147154
payload.data.repository.issue.parent = { ...openChild, title: "Parent tracker" };
148-
const graphql = vi.fn<GitHubApi.GitHubApi["Service"]["graphql"]>(() =>
155+
const graphql = vi.fn<GitHubIssueGraphQl.GitHubIssueGraphQl["Service"]["graphql"]>(() =>
149156
Effect.succeed(JSON.stringify(payload)),
150157
);
151158
const detail = yield* makeDetailService(graphql);
@@ -166,7 +173,7 @@ describe("GitHubIssueService detail sub-issue reasons", () => {
166173
it.effect("uses advanced search for issue types and preserves an older ranked issue", () =>
167174
Effect.gen(function* () {
168175
const row = JSON.parse(detailPayload([])).data.repository.issue;
169-
const graphql = vi.fn<GitHubApi.GitHubApi["Service"]["graphql"]>(() =>
176+
const graphql = vi.fn<GitHubIssueGraphQl.GitHubIssueGraphQl["Service"]["graphql"]>(() =>
170177
Effect.succeed(
171178
JSON.stringify({
172179
data: {
@@ -203,7 +210,7 @@ describe("GitHubIssueService detail sub-issue reasons", () => {
203210

204211
it.effect("attaches a closed child's reason with exactly one graphql read", () =>
205212
Effect.gen(function* () {
206-
const graphql = vi.fn<GitHubApi.GitHubApi["Service"]["graphql"]>((call) =>
213+
const graphql = vi.fn<GitHubIssueGraphQl.GitHubIssueGraphQl["Service"]["graphql"]>((call) =>
207214
call.query.includes("subIssues(first:100)")
208215
? Effect.succeed(
209216
JSON.stringify({
@@ -232,7 +239,7 @@ describe("GitHubIssueService detail sub-issue reasons", () => {
232239

233240
it.effect("skips the graphql read when no sub-issue is closed", () =>
234241
Effect.gen(function* () {
235-
const graphql = vi.fn<GitHubApi.GitHubApi["Service"]["graphql"]>(() =>
242+
const graphql = vi.fn<GitHubIssueGraphQl.GitHubIssueGraphQl["Service"]["graphql"]>(() =>
236243
Effect.succeed(detailPayload([openChild])),
237244
);
238245
const detail = yield* makeDetailService(graphql);
@@ -246,10 +253,10 @@ describe("GitHubIssueService detail sub-issue reasons", () => {
246253

247254
it.effect("keeps the detail when the graphql read fails, reason unknown", () =>
248255
Effect.gen(function* () {
249-
const graphql = vi.fn<GitHubApi.GitHubApi["Service"]["graphql"]>((call) =>
256+
const graphql = vi.fn<GitHubIssueGraphQl.GitHubIssueGraphQl["Service"]["graphql"]>((call) =>
250257
call.query.includes("subIssues(first:100)")
251258
? Effect.fail(
252-
new GitHubApi.GitHubApiResponseError({
259+
new GitHubRequestPolicy.GitHubApiResponseError({
253260
host: "github.com",
254261
operation: "subIssueCloseReasons",
255262
status: 500,

‎apps/server/src/githubIssue/GitHubIssueService.test.ts‎

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
import { assert, describe, it, vi } from "@effect/vitest";
2-
import type { OrchestrationProjectShell, ProjectId } from "@t3tools/contracts";
2+
import {
3+
SourceControlProviderKind,
4+
type OrchestrationProjectShell,
5+
type ProjectId,
6+
} from "@t3tools/contracts";
37
import * as Effect from "effect/Effect";
48
import * as Layer from "effect/Layer";
59
import * as Option from "effect/Option";
610

711
import * as ProjectService from "../project/ProjectService.ts";
812
import * as RepositoryIdentityResolver from "../project/RepositoryIdentityResolver.ts";
9-
import * as GitHubApi from "@t3tools/source-control-github/server/GitHubApi";
13+
import * as GitHubRequestPolicy from "@t3tools/source-control-github/server/GitHubRequestPolicy";
14+
import * as GitHubIssueGraphQl from "./gitHubIssueGraphQl.fork.ts";
1015
import * as GitHubCredentials from "@t3tools/source-control-github/server/GitHubCredentials";
1116
import * as GitHubIssueService from "./GitHubIssueService.ts";
1217

@@ -32,7 +37,7 @@ function project(input: {
3237
remoteName: "origin",
3338
remoteUrl: `https://${host}/${repository}.git`,
3439
},
35-
provider: input.provider ?? "github",
40+
provider: SourceControlProviderKind.make(input.provider ?? "github"),
3641
displayName: repository,
3742
owner,
3843
name,
@@ -85,12 +90,12 @@ const issueIdAnswer = (id: string) =>
8590

8691
function makeService(
8792
projects: ReadonlyArray<OrchestrationProjectShell>,
88-
graphql: GitHubApi.GitHubApi["Service"]["graphql"],
93+
graphql: GitHubIssueGraphQl.GitHubIssueGraphQl["Service"]["graphql"],
8994
) {
9095
return GitHubIssueService.make.pipe(
9196
Effect.provide(
9297
Layer.mergeAll(
93-
Layer.mock(GitHubApi.GitHubApi)({ graphql }),
98+
Layer.mock(GitHubIssueGraphQl.GitHubIssueGraphQl)({ graphql }),
9499
Layer.mock(ProjectService.ProjectService)({
95100
listShells: () => Effect.succeed(projects),
96101
getShell: (projectId) =>
@@ -108,7 +113,7 @@ function makeService(
108113
describe("GitHubIssueService", () => {
109114
it.effect("composes the search qualifiers while discovering only GitHub projects", () =>
110115
Effect.gen(function* () {
111-
const graphql = vi.fn<GitHubApi.GitHubApi["Service"]["graphql"]>(() =>
116+
const graphql = vi.fn<GitHubIssueGraphQl.GitHubIssueGraphQl["Service"]["graphql"]>(() =>
112117
searchAnswer([issueRow(2), issueRow(1)]),
113118
);
114119
const service = yield* makeService(
@@ -141,7 +146,9 @@ describe("GitHubIssueService", () => {
141146

142147
it.effect("sends sort:updated-desc when no user query is present", () =>
143148
Effect.gen(function* () {
144-
const graphql = vi.fn<GitHubApi.GitHubApi["Service"]["graphql"]>(() => searchAnswer([]));
149+
const graphql = vi.fn<GitHubIssueGraphQl.GitHubIssueGraphQl["Service"]["graphql"]>(() =>
150+
searchAnswer([]),
151+
);
145152
const service = yield* makeService(
146153
[project({ id: "p1", title: "web", workspaceRoot: "/web" })],
147154
graphql,
@@ -156,7 +163,9 @@ describe("GitHubIssueService", () => {
156163

157164
it.effect("routes Enterprise repositories to their host", () =>
158165
Effect.gen(function* () {
159-
const graphql = vi.fn<GitHubApi.GitHubApi["Service"]["graphql"]>(() => searchAnswer([]));
166+
const graphql = vi.fn<GitHubIssueGraphQl.GitHubIssueGraphQl["Service"]["graphql"]>(() =>
167+
searchAnswer([]),
168+
);
160169
const service = yield* makeService(
161170
[
162171
project({
@@ -181,7 +190,7 @@ describe("GitHubIssueService", () => {
181190

182191
it.effect("applies project filtering before repository de-duplication", () =>
183192
Effect.gen(function* () {
184-
const graphql = vi.fn<GitHubApi.GitHubApi["Service"]["graphql"]>(() =>
193+
const graphql = vi.fn<GitHubIssueGraphQl.GitHubIssueGraphQl["Service"]["graphql"]>(() =>
185194
searchAnswer([issueRow(7)]),
186195
);
187196
const service = yield* makeService(
@@ -199,7 +208,7 @@ describe("GitHubIssueService", () => {
199208

200209
it.effect("sorts mixed timezone offsets by instant and limits globally", () =>
201210
Effect.gen(function* () {
202-
const graphql = vi.fn<GitHubApi.GitHubApi["Service"]["graphql"]>((call) =>
211+
const graphql = vi.fn<GitHubIssueGraphQl.GitHubIssueGraphQl["Service"]["graphql"]>((call) =>
203212
Effect.succeed(
204213
JSON.stringify({
205214
data: {
@@ -232,7 +241,7 @@ describe("GitHubIssueService", () => {
232241

233242
it.effect("marks a per-repository overflow as truncated", () =>
234243
Effect.gen(function* () {
235-
const graphql = vi.fn<GitHubApi.GitHubApi["Service"]["graphql"]>(() =>
244+
const graphql = vi.fn<GitHubIssueGraphQl.GitHubIssueGraphQl["Service"]["graphql"]>(() =>
236245
searchAnswer([issueRow(3), issueRow(2), issueRow(1)]),
237246
);
238247
const service = yield* makeService(
@@ -247,7 +256,7 @@ describe("GitHubIssueService", () => {
247256

248257
it.effect("carries each row's true comment count from the search answer", () =>
249258
Effect.gen(function* () {
250-
const graphql = vi.fn<GitHubApi.GitHubApi["Service"]["graphql"]>(() =>
259+
const graphql = vi.fn<GitHubIssueGraphQl.GitHubIssueGraphQl["Service"]["graphql"]>(() =>
251260
searchAnswer([issueRow(5), { ...issueRow(6), comments: { totalCount: 12 } }]),
252261
);
253262
const service = yield* makeService(
@@ -264,10 +273,10 @@ describe("GitHubIssueService", () => {
264273

265274
it.effect("keeps healthy rows when one host is unauthenticated", () =>
266275
Effect.gen(function* () {
267-
const graphql = vi.fn<GitHubApi.GitHubApi["Service"]["graphql"]>((call) =>
276+
const graphql = vi.fn<GitHubIssueGraphQl.GitHubIssueGraphQl["Service"]["graphql"]>((call) =>
268277
call.host === "ghe.acme.dev"
269278
? Effect.fail(
270-
new GitHubApi.GitHubApiAuthenticationError({
279+
new GitHubRequestPolicy.GitHubApiAuthenticationError({
271280
host: call.host,
272281
operation: "listIssues",
273282
}),
@@ -299,9 +308,9 @@ describe("GitHubIssueService", () => {
299308

300309
it.effect("returns project errors when every repository fails", () =>
301310
Effect.gen(function* () {
302-
const graphql = vi.fn<GitHubApi.GitHubApi["Service"]["graphql"]>(() =>
311+
const graphql = vi.fn<GitHubIssueGraphQl.GitHubIssueGraphQl["Service"]["graphql"]>(() =>
303312
Effect.fail(
304-
new GitHubApi.GitHubApiAuthenticationError({
313+
new GitHubRequestPolicy.GitHubApiAuthenticationError({
305314
host: "github.com",
306315
operation: "listIssues",
307316
}),
@@ -319,7 +328,7 @@ describe("GitHubIssueService", () => {
319328

320329
it.effect("degrades malformed repository output", () =>
321330
Effect.gen(function* () {
322-
const graphql = vi.fn<GitHubApi.GitHubApi["Service"]["graphql"]>(() =>
331+
const graphql = vi.fn<GitHubIssueGraphQl.GitHubIssueGraphQl["Service"]["graphql"]>(() =>
323332
Effect.succeed("not-json"),
324333
);
325334
const service = yield* makeService(
@@ -334,7 +343,7 @@ describe("GitHubIssueService", () => {
334343

335344
it.effect("fails the whole read when the host has no credential at all", () =>
336345
Effect.gen(function* () {
337-
const graphql = vi.fn<GitHubApi.GitHubApi["Service"]["graphql"]>(() =>
346+
const graphql = vi.fn<GitHubIssueGraphQl.GitHubIssueGraphQl["Service"]["graphql"]>(() =>
338347
Effect.fail(new GitHubCredentials.GitHubCliMissingError({ host: "github.com" })),
339348
);
340349
const service = yield* makeService(
@@ -348,7 +357,7 @@ describe("GitHubIssueService", () => {
348357

349358
it.effect("uses the selected project to read an issue from another repository", () =>
350359
Effect.gen(function* () {
351-
const graphql = vi.fn<GitHubApi.GitHubApi["Service"]["graphql"]>(() =>
360+
const graphql = vi.fn<GitHubIssueGraphQl.GitHubIssueGraphQl["Service"]["graphql"]>(() =>
352361
issueAnswer({
353362
...issueRow(42),
354363
body: "Cross-repository issue",
@@ -376,7 +385,7 @@ describe("GitHubIssueService", () => {
376385
Effect.gen(function* () {
377386
// The read window is the newest 100 comments; totalCount says how many exist in full.
378387
const nodes = Array.from({ length: 100 }, (_, index) => commentNode(index + 2));
379-
const graphql = vi.fn<GitHubApi.GitHubApi["Service"]["graphql"]>(() =>
388+
const graphql = vi.fn<GitHubIssueGraphQl.GitHubIssueGraphQl["Service"]["graphql"]>(() =>
380389
issueAnswer({
381390
...issueRow(42),
382391
body: "Body",
@@ -403,7 +412,7 @@ describe("GitHubIssueService", () => {
403412

404413
it.effect("loads issue detail and normalizes comment count", () =>
405414
Effect.gen(function* () {
406-
const graphql = vi.fn<GitHubApi.GitHubApi["Service"]["graphql"]>(() =>
415+
const graphql = vi.fn<GitHubIssueGraphQl.GitHubIssueGraphQl["Service"]["graphql"]>(() =>
407416
issueAnswer({
408417
...issueRow(42),
409418
body: "Visible issue body",
@@ -440,7 +449,7 @@ describe("GitHubIssueService", () => {
440449

441450
it.effect("closes with a reason and reopens without one", () =>
442451
Effect.gen(function* () {
443-
const graphql = vi.fn<GitHubApi.GitHubApi["Service"]["graphql"]>((call) =>
452+
const graphql = vi.fn<GitHubIssueGraphQl.GitHubIssueGraphQl["Service"]["graphql"]>((call) =>
444453
String(call.query).includes("closeIssue")
445454
? Effect.succeed(JSON.stringify({ data: { closeIssue: { issue: { id: "node-1" } } } }))
446455
: String(call.query).includes("reopenIssue")
@@ -472,9 +481,9 @@ describe("GitHubIssueService", () => {
472481

473482
it.effect("reports an unauthenticated close with the host to log in to", () =>
474483
Effect.gen(function* () {
475-
const graphql = vi.fn<GitHubApi.GitHubApi["Service"]["graphql"]>(() =>
484+
const graphql = vi.fn<GitHubIssueGraphQl.GitHubIssueGraphQl["Service"]["graphql"]>(() =>
476485
Effect.fail(
477-
new GitHubApi.GitHubApiAuthenticationError({
486+
new GitHubRequestPolicy.GitHubApiAuthenticationError({
478487
host: "ghe.acme.dev",
479488
operation: "closeIssueId",
480489
}),

‎apps/server/src/githubIssue/GitHubIssueService.ts‎

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@ import {
1414
GitHubIssueCliMissingError as GitHubIssueCliMissingErrorClass,
1515
GitHubIssueCliUnauthenticatedError as GitHubIssueCliUnauthenticatedErrorClass,
1616
GitHubIssueOperationError as GitHubIssueOperationErrorClass,
17-
pullRequestHostOf,
18-
SourceControlProviderKind,
1917
} from "@t3tools/contracts";
20-
import { sourceControlRepositorySelector } from "@t3tools/shared/sourceControl";
2118
import * as Context from "effect/Context";
2219
import * as Effect from "effect/Effect";
2320
import * as Layer from "effect/Layer";
@@ -26,7 +23,9 @@ import * as Schema from "effect/Schema";
2623

2724
import * as ProjectService from "../project/ProjectService.ts";
2825
import * as RepositoryIdentityResolver from "../project/RepositoryIdentityResolver.ts";
29-
import * as GitHubApi from "@t3tools/source-control-github/server/GitHubApi";
26+
import { sourceControlDefinitions } from "../sourceControl/sourceControlDefinitions.ts";
27+
import type * as GitHubRequestPolicy from "@t3tools/source-control-github/server/GitHubRequestPolicy";
28+
import * as GitHubIssueGraphQl from "./gitHubIssueGraphQl.fork.ts";
3029
import {
3130
decodeParsedGitHubIssueDetail,
3231
decodeParsedGitHubIssueList,
@@ -173,7 +172,7 @@ function authCommandForHost(host: string): string {
173172
}
174173

175174
function fromApiError(operation: string, host: string) {
176-
return (error: GitHubApi.GitHubApiError): GitHubIssueError => {
175+
return (error: GitHubRequestPolicy.GitHubApiError): GitHubIssueError => {
177176
// No credential at all is the missing-binary world's "nothing to authenticate with": the
178177
// whole read fails rather than degrading, the way a missing `gh` once did.
179178
if (error._tag === "GitHubCliMissingError") {
@@ -223,7 +222,7 @@ function toRawIssue(row: GraphQlIssueRowType): Record<string, unknown> {
223222
}
224223

225224
export const make = Effect.gen(function* () {
226-
const api = yield* GitHubApi.GitHubApi;
225+
const api = yield* GitHubIssueGraphQl.GitHubIssueGraphQl;
227226
const projectService = yield* ProjectService.ProjectService;
228227
const repositoryIdentities = yield* RepositoryIdentityResolver.RepositoryIdentityResolver;
229228

@@ -262,12 +261,9 @@ export const make = Effect.gen(function* () {
262261
// duplicate earlier in the snapshot can hide the project the caller explicitly selected.
263262
if (projectId !== undefined && project.id !== projectId) continue;
264263
if (project.repositoryIdentity?.provider !== "github") continue;
265-
const repository = sourceControlRepositorySelector(project.repositoryIdentity);
264+
const repository = sourceControlDefinitions.repositorySelector(project.repositoryIdentity);
266265
if (repository === null) continue;
267-
const host = pullRequestHostOf(
268-
project.repositoryIdentity,
269-
SourceControlProviderKind.make("github"),
270-
);
266+
const host = sourceControlDefinitions.changeRequestHost(project.repositoryIdentity, "github");
271267
const key = `${host}/${repository}`.toLowerCase();
272268
if (seen.has(key)) continue;
273269
seen.add(key);

0 commit comments

Comments
 (0)