Skip to content

Commit fd22d90

Browse files
refactor(source-control): forges handle their own listing and SSH host quirks
Two flags still made the shared pull request service compensate for one forge, and the order that decides which forge owns a URL or remote was written twice. GitHub search can answer for a renamed repository with silence. `listsAcrossMayOmitRepositories` had the service track which repositories search had shown, for how long, and on which slice. The GitHub adapter now returns the repositories it cannot vouch for as `unresolved`, and the service reads those on their own without knowing why. The adapter decides with a cached check of whether search has any pull request for the repository, kept for an hour; a repository with no open pull requests is no longer read on its own on every listing. A Forgejo SSH remote names an alias, not the web server. `sshRemoteHidesWebHost` had the service rewrite a recognised Forgejo provider to "unknown" to force discovery, then take the web host from the result. Source control providers now have an optional `resolveRemoteWebHost`; Forgejo answers it from the login that serves the remote, and the service uses whatever host it returns. The definitions and their precedence now live in a small `@t3tools/source-control-definitions` package that the server and clients both import, and a server test checks its driver list matches them. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent bdbc3af commit fd22d90

21 files changed

Lines changed: 763 additions & 300 deletions

‎apps/server/package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
"@t3tools/source-control-azure-devops": "workspace:*",
5252
"@t3tools/source-control-bitbucket": "workspace:*",
5353
"@t3tools/source-control-core": "workspace:*",
54+
"@t3tools/source-control-definitions": "workspace:*",
5455
"@t3tools/source-control-forgejo": "workspace:*",
5556
"@t3tools/source-control-gitcafe": "workspace:*",
5657
"@t3tools/source-control-github": "workspace:*",

‎apps/server/src/pullRequest/PullRequestService.test.ts‎

Lines changed: 113 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ import * as SqlitePersistence from "../persistence/Sqlite.ts";
2727
import * as PullRequestFilesViewed from "../persistence/PullRequestFilesViewed.ts";
2828
import * as RepositoryIdentityResolver from "../project/RepositoryIdentityResolver.ts";
2929
import * as SourceControlProviderRegistry from "../sourceControl/SourceControlProviderRegistry.ts";
30+
import type { SourceControlProvider } from "@t3tools/source-control-core/server/SourceControlProvider";
31+
import { isSshRemoteUrl } from "@t3tools/shared/sourceControl";
3032
import * as SourceControlRateLimit from "@t3tools/source-control-core/server/SourceControlRateLimit";
3133
import { fakePullRequestProvider } from "@t3tools/source-control-testing/fakeSourceControlDriver";
3234
import {
@@ -170,6 +172,26 @@ const keyedByCanonicalKey = {
170172
repositoryKey: ({ canonicalKey }: { readonly canonicalKey: string }) => canonicalKey,
171173
};
172174

175+
/** A host whose SSH remotes name an alias, so discovery says which server serves them. */
176+
const sshAliasHost = {
177+
resolveRemoteWebHost: ({ cwd, context, resolveContext }) =>
178+
isSshRemoteUrl(context.remoteUrl)
179+
? resolveContext({
180+
cwd,
181+
context: {
182+
...context,
183+
provider: { kind: SourceControlProviderKind.make("unknown"), name: "", baseUrl: "" },
184+
},
185+
}).pipe(
186+
Effect.map((resolved) =>
187+
resolved === null || resolved.provider.kind === "unknown"
188+
? null
189+
: new URL(resolved.provider.baseUrl).host,
190+
),
191+
)
192+
: Effect.succeed(null),
193+
} as SourceControlProvider["Service"];
194+
173195
function makeService(input: {
174196
readonly settings?: ServerSettings;
175197
readonly projects: ReadonlyArray<OrchestrationProjectShell>;
@@ -193,6 +215,10 @@ function makeService(input: {
193215
resolveLink: () => undefined,
194216
resolveHandle:
195217
input.resolveHandle ?? (() => Effect.die("Unexpected provider refinement")),
218+
get: (kind) =>
219+
Effect.succeed(
220+
kind === "forgejo" ? sshAliasHost : ({} as SourceControlProvider["Service"]),
221+
),
196222
}),
197223
Layer.mock(ProjectService.ProjectService)({
198224
listShells: (options) =>
@@ -1526,6 +1552,52 @@ it.effect("routes explicit Forgejo HTTP authorities through SSH checkouts after
15261552
}),
15271553
);
15281554

1555+
it.effect("names an SSH remote's web host from a later checkout when the first cannot", () =>
1556+
Effect.gen(function* () {
1557+
const hosts: Array<string> = [];
1558+
const service = yield* makeService({
1559+
projects: ["/first", "/second"].map((workspaceRoot, index) =>
1560+
project({
1561+
id: `p${index}`,
1562+
title: `checkout ${index}`,
1563+
workspaceRoot,
1564+
repository: "team/repo",
1565+
provider: SourceControlProviderKind.make("forgejo"),
1566+
host: "ssh.code.example",
1567+
remoteUrl: "[email protected]:team/repo.git",
1568+
}),
1569+
),
1570+
providers: [
1571+
fakePullRequestProvider(SourceControlProviderKind.make("forgejo"), {
1572+
listChangeRequests: (input) => {
1573+
hosts.push(input.host);
1574+
return Effect.succeed({ items: [], truncated: false, continues: true });
1575+
},
1576+
}),
1577+
],
1578+
resolveHandle: ({ cwd, context }) =>
1579+
Effect.succeed({
1580+
context:
1581+
cwd === "/first"
1582+
? context!
1583+
: {
1584+
...context!,
1585+
provider: {
1586+
kind: SourceControlProviderKind.make("forgejo"),
1587+
name: "Forgejo",
1588+
baseUrl: "http://code.example:3000",
1589+
},
1590+
},
1591+
provider: undefined as never,
1592+
}),
1593+
});
1594+
1595+
yield* service.list({ state: "open" });
1596+
1597+
assert.deepStrictEqual(hosts, ["code.example:3000"]);
1598+
}),
1599+
);
1600+
15291601
it.effect("rejects a different Forgejo HTTP port for an HTTP checkout", () =>
15301602
Effect.gen(function* () {
15311603
const service = yield* makeService({
@@ -2191,7 +2263,6 @@ it.effect("carries every repository of a slice on from the oldest row in it", ()
21912263
],
21922264
providers: [
21932265
fakePullRequestProvider(SourceControlProviderKind.make("github"), {
2194-
listsAcrossMayOmitRepositories: true,
21952266
listChangeRequestsAcross: () =>
21962267
Effect.succeed({
21972268
items: [
@@ -2200,6 +2271,7 @@ it.effect("carries every repository of a slice on from the oldest row in it", ()
22002271
batchedChangeRequest(3, "acme/web", "2026-07-02T00:00:00Z"),
22012272
],
22022273
truncated: true,
2274+
unresolved: ["acme/docs"],
22032275
}),
22042276
}),
22052277
],
@@ -2283,51 +2355,49 @@ it.effect("reads a workspace larger than one search in chunks, and merges them",
22832355
assert.strictEqual(result.entries.length, 101);
22842356
}),
22852357
);
2286-
it.effect(
2287-
"asks on its own for a repository a search answered nothing for, where searches can omit one",
2288-
() =>
2289-
Effect.gen(function* () {
2290-
const separately: string[] = [];
2291-
const service = yield* makeService({
2292-
projects: [
2293-
project({ id: "p1", title: "web", workspaceRoot: "/a", repository: "acme/web" }),
2294-
project({ id: "p2", title: "docs", workspaceRoot: "/b", repository: "acme/docs" }),
2295-
],
2296-
providers: [
2297-
fakePullRequestProvider(SourceControlProviderKind.make("github"), {
2298-
listsAcrossMayOmitRepositories: true,
2299-
listChangeRequests: ({ repository }) => {
2300-
separately.push(repository);
2301-
return repository === "acme/docs"
2302-
? Effect.fail(requestFailed)
2303-
: Effect.succeed({ items: [], truncated: false, continues: true });
2304-
},
2305-
listChangeRequestsAcross: () =>
2306-
Effect.succeed({
2307-
items: [batchedChangeRequest(1, "acme/web", "2026-07-03T00:00:00Z")],
2308-
truncated: false,
2309-
}),
2310-
}),
2311-
],
2312-
});
2358+
it.effect("asks on its own for a repository a search could not vouch for", () =>
2359+
Effect.gen(function* () {
2360+
const separately: string[] = [];
2361+
const service = yield* makeService({
2362+
projects: [
2363+
project({ id: "p1", title: "web", workspaceRoot: "/a", repository: "acme/web" }),
2364+
project({ id: "p2", title: "docs", workspaceRoot: "/b", repository: "acme/docs" }),
2365+
],
2366+
providers: [
2367+
fakePullRequestProvider(SourceControlProviderKind.make("github"), {
2368+
listChangeRequests: ({ repository }) => {
2369+
separately.push(repository);
2370+
return repository === "acme/docs"
2371+
? Effect.fail(requestFailed)
2372+
: Effect.succeed({ items: [], truncated: false, continues: true });
2373+
},
2374+
listChangeRequestsAcross: () =>
2375+
Effect.succeed({
2376+
items: [batchedChangeRequest(1, "acme/web", "2026-07-03T00:00:00Z")],
2377+
truncated: false,
2378+
unresolved: ["acme/docs"],
2379+
}),
2380+
}),
2381+
],
2382+
});
23132383

2314-
const result = yield* service.list({ state: "open" });
2384+
const result = yield* service.list({ state: "open" });
23152385

2316-
assert.deepStrictEqual(separately, ["acme/docs"]);
2317-
assert.deepStrictEqual(result.errors, [
2318-
{
2319-
projectId: "p2" as ProjectId,
2320-
projectTitle: "docs",
2321-
message: "acme/docs could not be read.",
2322-
},
2323-
]);
2324-
assert.deepStrictEqual(
2325-
result.entries.map((entry) => entry.number),
2326-
[1],
2327-
);
2328-
}),
2386+
assert.deepStrictEqual(separately, ["acme/docs"]);
2387+
assert.deepStrictEqual(result.errors, [
2388+
{
2389+
projectId: "p2" as ProjectId,
2390+
projectTitle: "docs",
2391+
message: "acme/docs could not be read.",
2392+
},
2393+
]);
2394+
assert.deepStrictEqual(
2395+
result.entries.map((entry) => entry.number),
2396+
[1],
2397+
);
2398+
}),
23292399
);
2330-
it.effect("believes a search's silence about a repository where searches cover every one", () =>
2400+
it.effect("believes a search's silence about a repository it vouches for", () =>
23312401
Effect.gen(function* () {
23322402
const separately: string[] = [];
23332403
const service = yield* makeService({

0 commit comments

Comments
 (0)