@@ -10,6 +10,7 @@ import * as Clock from "effect/Clock";
1010import * as Deferred from "effect/Deferred" ;
1111import * as Effect from "effect/Effect" ;
1212import * as Exit from "effect/Exit" ;
13+ import * as FileSystem from "effect/FileSystem" ;
1314import * as Fiber from "effect/Fiber" ;
1415import * as Layer from "effect/Layer" ;
1516import * as Option from "effect/Option" ;
@@ -43,6 +44,7 @@ import * as GitHubPullRequestProvider from "@t3tools/source-control-github/serve
4344import * as GitHubQuota from "@t3tools/source-control-github/server/GitHubQuota" ;
4445import * as TestSourceControlHost from "@t3tools/source-control-testing/TestSourceControlHost" ;
4546import {
47+ PullRequestBaseUrl ,
4648 PullRequestProviderError ,
4749 type ProviderChangeRequest ,
4850 type PullRequestProviderApi ,
@@ -531,16 +533,20 @@ it.effect.each(["forgejo", "azure-devops"] as const)(
531533 const service = yield * makeService ( {
532534 settings : {
533535 ...DEFAULT_SERVER_SETTINGS ,
534- sourceControlHostOverrides : { "code.example.test" : { kind } } ,
536+ sourceControlHostOverrides : {
537+ "code.example.test" : { kind, baseUrl : "https://code.example.test/forge" } ,
538+ } ,
535539 } ,
536540 projects : [ project ( { id : "inbox" , title : "Inbox" , workspaceRoot : "/inbox" } ) ] ,
537541 providers : [
538542 fakeProvider ( SourceControlProviderKind . make ( kind ) , {
539- getChangeRequestSummary : ( input ) => {
540- reads ++ ;
541- assert . strictEqual ( input . host , "code.example.test" ) ;
542- return Effect . succeed ( changeRequest ( 42 , "2026-07-02T00:00:00Z" ) ) ;
543- } ,
543+ getChangeRequestSummary : ( input ) =>
544+ Effect . gen ( function * ( ) {
545+ reads ++ ;
546+ assert . strictEqual ( input . host , "code.example.test" ) ;
547+ assert . strictEqual ( yield * PullRequestBaseUrl , "https://code.example.test/forge" ) ;
548+ return changeRequest ( 42 , "2026-07-02T00:00:00Z" ) ;
549+ } ) ,
544550 } ) ,
545551 ] ,
546552 } ) ;
@@ -715,41 +721,158 @@ it.effect.each(["unknown", "github", "omitted"])(
715721 } ) ,
716722) ;
717723
718- it . effect (
719- "routes a mapped SSH host through its configured web authority without automatic refinement" ,
720- ( ) =>
724+ it . effect . each ( [
725+ {
726+ remoteUrl :
"ssh://[email protected] :2222/team/repo.git" , 727+ repository : "team/repo" ,
728+ mount : "/Forgejo" ,
729+ loginPresent : true ,
730+ } ,
731+ {
732+ remoteUrl : "https://ssh.example.test:2222/Forgejo/team/repo.git" ,
733+ repository : "Forgejo/team/repo" ,
734+ mount : "/Forgejo" ,
735+ loginPresent : true ,
736+ } ,
737+ {
738+ remoteUrl :
"ssh://[email protected] :2222/team/repo.git" , 739+ repository : "team/repo" ,
740+ mount : "" ,
741+ loginPresent : true ,
742+ } ,
743+ {
744+ remoteUrl :
"[email protected] :team/repo.git" , 745+ repository : "team/repo" ,
746+ mount : "/Forgejo" ,
747+ loginPresent : false ,
748+ } ,
749+ ] ) (
750+ "routes mapped $remoteUrl with mount '$mount' through the Forgejo endpoint and login" ,
751+ ( { remoteUrl, repository, mount, loginPresent } ) =>
721752 Effect . gen ( function * ( ) {
753+ const baseUrl = `http://web.example.test:3000${ mount } ` ;
754+ const urls : string [ ] = [ ] ;
755+ const rawPull = {
756+ number : 42 ,
757+ title : "Mounted Forgejo PR" ,
758+ body : null ,
759+ html_url : `${ baseUrl } /team/repo/pulls/42` ,
760+ user : { login : "contributor" } ,
761+ state : "open" ,
762+ merged : false ,
763+ head : { ref : "feature" , sha : "abc" , repo : { full_name : "team/repo" } } ,
764+ base : { ref : "main" , sha : "def" , repo : { full_name : "team/repo" } } ,
765+ created_at : "2026-07-01T00:00:00Z" ,
766+ updated_at : "2026-07-02T00:00:00Z" ,
767+ closed_at : null ,
768+ merged_at : null ,
769+ labels : [ ] ,
770+ } ;
771+ const cli = yield * ForgejoCli . make . pipe (
772+ Effect . provideService (
773+ FileSystem . FileSystem ,
774+ FileSystem . makeNoop ( { exists : ( ) => Effect . succeed ( false ) } ) ,
775+ ) ,
776+ Effect . provideService (
777+ HttpClient . HttpClient ,
778+ HttpClient . make ( ( ) => Effect . die ( "tea handles HTTP" ) ) ,
779+ ) ,
780+ Effect . provide (
781+ TestSourceControlHost . layer ( {
782+ process : {
783+ run : ( input ) => {
784+ assert . strictEqual ( input . command , "tea" ) ;
785+ if ( input . args [ 0 ] === "login" )
786+ return Effect . succeed (
787+ TestSourceControlHost . processOutput (
788+ JSON . stringify ( [
789+ {
790+ name : "unrelated-default" ,
791+ url : "https://web.example.test:3000" ,
792+ user : "wrong" ,
793+ default : "true" ,
794+ } ,
795+ {
796+ name : "other-mount" ,
797+ url : "http://web.example.test:3000/other" ,
798+ user : "wrong" ,
799+ default : "false" ,
800+ } ,
801+ ...( loginPresent
802+ ? [
803+ {
804+ name : "mapped" ,
805+ url : `${ baseUrl } /` ,
806+ user : "viewer" ,
807+ default : "false" ,
808+ } ,
809+ ]
810+ : [ ] ) ,
811+ ] ) ,
812+ ) ,
813+ ) ;
814+ assert . strictEqual ( input . args [ input . args . indexOf ( "--login" ) + 1 ] , "mapped" ) ;
815+ const url = input . args . at ( - 1 ) ! ;
816+ assert . ok ( url . startsWith ( `${ baseUrl } /api/v1/` ) ) ;
817+ urls . push ( url ) ;
818+ return Effect . succeed (
819+ TestSourceControlHost . processOutput (
820+ JSON . stringify (
821+ url . endsWith ( "/user" )
822+ ? { login : "viewer" }
823+ : url . includes ( "?state=" )
824+ ? [ ]
825+ : rawPull ,
826+ ) ,
827+ { stderr : "HTTP/1.1 200 OK\n" } ,
828+ ) ,
829+ ) ;
830+ } ,
831+ } ,
832+ } ) ,
833+ ) ,
834+ ) ;
835+ const provider = yield * ForgejoPullRequestProvider . make . pipe (
836+ Effect . provideService ( ForgejoCli . ForgejoCli , cli ) ,
837+ ) ;
722838 const service = yield * makeService ( {
723839 settings : {
724840 ...DEFAULT_SERVER_SETTINGS ,
725841 sourceControlHostOverrides : {
726- "ssh.example.test:2222" : {
727- kind : "forgejo" ,
728- baseUrl : "http://web.example.test:3000/forgejo" ,
729- } ,
842+ "ssh.example.test:2222" : { kind : "forgejo" , baseUrl } ,
843+ "ssh.example.test" : { kind : "forgejo" , baseUrl } ,
730844 } ,
731845 } ,
732846 projects : [
733847 project ( {
734848 id : "forge" ,
735- title : "SSH forge" ,
849+ title : "mapped forge" ,
736850 workspaceRoot : "/forge" ,
737- repository : "team/repo" ,
851+ repository,
738852 host : "ssh.example.test" ,
739853 provider : "forgejo" ,
740- remoteUrl :
"ssh://[email protected] :2222/team/repo.git" , 741- } ) ,
742- ] ,
743- providers : [
744- fakeProvider ( SourceControlProviderKind . make ( "forgejo" ) , {
745- getChangeRequestSummary : ( input ) => {
746- assert . strictEqual ( input . host , "web.example.test:3000" ) ;
747- return Effect . succeed ( changeRequest ( 42 , "2026-07-02T00:00:00Z" ) ) ;
748- } ,
854+ remoteUrl,
749855 } ) ,
750856 ] ,
857+ providers : [ provider ] ,
751858 } ) ;
752- yield * service . summary (
859+ if ( ! loginPresent ) {
860+ const result = yield * service
861+ . summary (
862+ {
863+ projectId : "forge" as ProjectId ,
864+ host : "web.example.test:3000" ,
865+ repository : "team/repo" ,
866+ number : 42 ,
867+ } ,
868+ { recoverTransientFailure : false } ,
869+ )
870+ . pipe ( Effect . result ) ;
871+ assert . strictEqual ( result . _tag , "Failure" ) ;
872+ assert . deepStrictEqual ( urls , [ ] ) ;
873+ return ;
874+ }
875+ const summary = yield * service . summary (
753876 {
754877 projectId : "forge" as ProjectId ,
755878 host : "web.example.test:3000" ,
@@ -758,6 +881,14 @@ it.effect(
758881 } ,
759882 { recoverTransientFailure : false } ,
760883 ) ;
884+ assert . strictEqual ( summary . title , "Mounted Forgejo PR" ) ;
885+ const listed = yield * service . list ( { state : "open" , involvement : "all" , limit : 10 } ) ;
886+ assert . deepStrictEqual ( listed . errors , [ ] ) ;
887+ assert . deepStrictEqual ( urls , [
888+ `${ baseUrl } /api/v1/repos/team/repo/pulls/42` ,
889+ `${ baseUrl } /api/v1/user` ,
890+ `${ baseUrl } /api/v1/repos/team/repo/pulls?state=open&sort=recentupdate&limit=50&page=1` ,
891+ ] ) ;
761892 } ) ,
762893) ;
763894
0 commit comments