@@ -35,6 +35,7 @@ import * as WorkspacePaths from "../workspace/WorkspacePaths.ts";
3535import { assetFileResponse } from "../http.ts" ;
3636import { ASSET_ROUTE_PREFIX , issueAssetUrl , readMcpAppHtml , resolveAsset } from "./AssetAccess.ts" ;
3737import * as NativeAppIconResolver from "./NativeAppIconResolver.ts" ;
38+ import * as RepositoryIdentityResolver from "../project/RepositoryIdentityResolver.ts" ;
3839import { symlinksSupported } from "@t3tools/shared/testing/symlinks" ;
3940import { fakeSourceControlDriverInstance } from "@t3tools/source-control-testing/fakeSourceControlDriver" ;
4041import * as BuiltInDrivers from "../sourceControl/builtInDrivers.ts" ;
@@ -1471,8 +1472,37 @@ describe("AssetAccess", () => {
14711472 } ) . pipe ( Effect . provide ( layerTest ) ) ,
14721473 ) ;
14731474
1475+ it . effect ( "preserves the change request repository through RPC decoding and signed media" , ( ) =>
1476+ Effect . gen ( function * ( ) {
1477+ const decodeAssetCreateUrlInput = Schema . decodeEffect ( AssetCreateUrlInput ) ;
1478+ const resource = {
1479+ _tag : SOURCE_CONTROL_MEDIA_ASSET ,
1480+ cwd : "/personal-fork" ,
1481+ url : "https://github.com/user-attachments/assets/1a1842fb-6383-492f-873c-57aa0033fa6c" ,
1482+ repository : "enterprise/private" ,
1483+ } ;
1484+ const input = yield * decodeAssetCreateUrlInput ( { resource } ) ;
1485+ const issued = yield * issueAssetUrl ( input ) ;
1486+ const suffix = issued . relativeUrl . slice ( `${ ASSET_ROUTE_PREFIX } /` . length ) ;
1487+ const separator = suffix . indexOf ( "/" ) ;
1488+ const resolved = yield * resolveAsset ( suffix . slice ( 0 , separator ) , suffix . slice ( separator + 1 ) ) ;
1489+
1490+ expect ( resolved ) . toEqual ( {
1491+ kind : "source-control-media" ,
1492+ url : resource . url ,
1493+ cwd : resource . cwd ,
1494+ repository : resource . repository ,
1495+ expiresAt : issued . expiresAt ,
1496+ } ) ;
1497+ } ) . pipe ( Effect . provide ( layerTest ) ) ,
1498+ ) ;
1499+
14741500 it . effect ( "serves a host's credentialed media through that host's driver" , ( ) => {
1475- const fetched : Array < { url : string ; headers : Readonly < Record < string , string > > } > = [ ] ;
1501+ const fetched : Array < {
1502+ url : string ;
1503+ headers : Readonly < Record < string , string > > ;
1504+ repository ?: string ;
1505+ } > = [ ] ;
14761506 const url = "https://github.com/owner/repo/blob/main/docs/shot.png" ;
14771507 const media = sourceControlDefinitions . mediaUrl ( url ) ! ;
14781508 const layerDrivers = Layer . succeed ( BuiltInDrivers . SourceControlDrivers , [
@@ -1491,6 +1521,17 @@ describe("AssetAccess", () => {
14911521 } ) ,
14921522 } ,
14931523 ] ) ;
1524+ // Clients that predate `repository` get the checkout's.
1525+ const layerIdentities = Layer . mock ( RepositoryIdentityResolver . RepositoryIdentityResolver ) ( {
1526+ resolve : ( ) =>
1527+ Effect . succeed ( {
1528+ canonicalKey : "github.com/owner/repo" ,
1529+ locator : { source : "git-remote" , remoteName : "origin" , remoteUrl : "" } ,
1530+ provider : media . definition . kind ,
1531+ owner : "owner" ,
1532+ name : "repo" ,
1533+ } ) ,
1534+ } ) ;
14941535 return Effect . gen ( function * ( ) {
14951536 const decodeAssetCreateUrlInput = Schema . decodeEffect ( AssetCreateUrlInput ) ;
14961537
@@ -1514,12 +1555,21 @@ describe("AssetAccess", () => {
15141555 range : "bytes=0-4" ,
15151556 cookie : "session" ,
15161557 } ) ;
1517- expect ( fetched ) . toEqual ( [ { url : media . fetchUrl , headers : { range : "bytes=0-4" } } ] ) ;
1558+ expect ( fetched ) . toEqual ( [
1559+ { url : media . fetchUrl , headers : { range : "bytes=0-4" } , repository : "owner/repo" } ,
1560+ ] ) ;
15181561 expect ( response . status ) . toBe ( 206 ) ;
15191562 // The upstream sent no type, so it comes from the file name the host gave the media.
15201563 expect ( response . headers [ "content-type" ] ) . toBe ( "image/png" ) ;
15211564 expect ( response . headers [ "content-length" ] ) . toBe ( "5" ) ;
1522- } ) . pipe ( Effect . provide ( Layer . merge ( layerTest , layerDrivers ) ) , Effect . scoped ) ;
1565+
1566+ // A pull request's own repository wins over the checkout it is shown in.
1567+ yield * sourceControlMediaResponse ( { ...asset , repository : "enterprise/private" } , { } ) ;
1568+ expect ( fetched . at ( - 1 ) ?. repository ) . toBe ( "enterprise/private" ) ;
1569+ } ) . pipe (
1570+ Effect . provide ( Layer . mergeAll ( layerTest , layerDrivers , layerIdentities ) ) ,
1571+ Effect . scoped ,
1572+ ) ;
15231573 } ) ;
15241574
15251575 it . effect ( "refuses media no host keeps behind a credential, without echoing the URL" , ( ) =>
0 commit comments