@@ -27,6 +27,8 @@ import * as SqlitePersistence from "../persistence/Sqlite.ts";
2727import * as PullRequestFilesViewed from "../persistence/PullRequestFilesViewed.ts" ;
2828import * as RepositoryIdentityResolver from "../project/RepositoryIdentityResolver.ts" ;
2929import * as SourceControlProviderRegistry from "../sourceControl/SourceControlProviderRegistry.ts" ;
30+ import type { SourceControlProvider } from "@t3tools/source-control-core/server/SourceControlProvider" ;
31+ import { isSshRemoteUrl } from "@t3tools/shared/sourceControl" ;
3032import * as SourceControlRateLimit from "@t3tools/source-control-core/server/SourceControlRateLimit" ;
3133import { fakePullRequestProvider } from "@t3tools/source-control-testing/fakeSourceControlDriver" ;
3234import {
@@ -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+
173195function 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+
15291601it . 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