1+ import { realpathSync } from "node:fs" ;
2+
13import * as NodeServices from "@effect/platform-node/NodeServices" ;
24import { expect , it } from "@effect/vitest" ;
35import { Duration , Effect , FileSystem , Layer } from "effect" ;
@@ -10,6 +12,10 @@ import {
1012 RepositoryIdentityResolverLive ,
1113} from "./RepositoryIdentityResolver.ts" ;
1214
15+ const normalizePathSeparators = ( value : string ) => value . replaceAll ( "\\" , "/" ) ;
16+ const normalizeResolvedPath = ( value : string ) =>
17+ normalizePathSeparators ( realpathSync . native ( value ) ) ;
18+
1319const git = ( cwd : string , args : ReadonlyArray < string > ) =>
1420 Effect . promise ( ( ) => runProcess ( "git" , [ "-C" , cwd , ...args ] ) ) ;
1521
@@ -41,13 +47,35 @@ it.layer(NodeServices.layer)("RepositoryIdentityResolverLive", (it) => {
4147
4248 expect ( identity ) . not . toBeNull ( ) ;
4349 expect ( identity ?. canonicalKey ) . toBe ( "github.com/marcodehq/marcode" ) ;
50+ expect ( normalizeResolvedPath ( identity ?. rootPath ?? "" ) ) . toBe ( normalizeResolvedPath ( cwd ) ) ;
4451 expect ( identity ?. displayName ) . toBe ( "marcodehq/marcode" ) ;
4552 expect ( identity ?. provider ) . toBe ( "github" ) ;
4653 expect ( identity ?. owner ) . toBe ( "marcodehq" ) ;
4754 expect ( identity ?. name ) . toBe ( "marcode" ) ;
4855 } ) . pipe ( Effect . provide ( RepositoryIdentityResolverLive ) ) ,
4956 ) ;
5057
58+ it . effect ( "returns the git top-level root path when resolving from a nested workspace" , ( ) =>
59+ Effect . gen ( function * ( ) {
60+ const fileSystem = yield * FileSystem . FileSystem ;
61+ const repoRoot = yield * fileSystem . makeTempDirectoryScoped ( {
62+ prefix : "marcode-repository-identity-nested-root-test-" ,
63+ } ) ;
64+ const nestedWorkspace = `${ repoRoot } /packages/web` ;
65+
66+ yield * fileSystem . makeDirectory ( nestedWorkspace , { recursive : true } ) ;
67+ yield * git ( repoRoot , [ "init" ] ) ;
68+ yield * git ( repoRoot , [ "remote" , "add" , "origin" , "git@github.com:MarCodeHQ/marcode.git" ] ) ;
69+
70+ const resolver = yield * RepositoryIdentityResolver ;
71+ const identity = yield * resolver . resolve ( nestedWorkspace ) ;
72+
73+ expect ( identity ) . not . toBeNull ( ) ;
74+ expect ( identity ?. canonicalKey ) . toBe ( "github.com/marcodehq/marcode" ) ;
75+ expect ( normalizeResolvedPath ( identity ?. rootPath ?? "" ) ) . toBe ( normalizeResolvedPath ( repoRoot ) ) ;
76+ } ) . pipe ( Effect . provide ( RepositoryIdentityResolverLive ) ) ,
77+ ) ;
78+
5179 it . effect ( "returns null for non-git folders and repos without remotes" , ( ) =>
5280 Effect . gen ( function * ( ) {
5381 const fileSystem = yield * FileSystem . FileSystem ;
@@ -69,24 +97,24 @@ it.layer(NodeServices.layer)("RepositoryIdentityResolverLive", (it) => {
6997 } ) . pipe ( Effect . provide ( RepositoryIdentityResolverLive ) ) ,
7098 ) ;
7199
72- it . effect ( "prefers upstream over origin when both remotes are configured " , ( ) =>
100+ it . effect ( "prefers origin over upstream so forks surface their own name " , ( ) =>
73101 Effect . gen ( function * ( ) {
74102 const fileSystem = yield * FileSystem . FileSystem ;
75103 const cwd = yield * fileSystem . makeTempDirectoryScoped ( {
76- prefix : "marcode-repository-identity-upstream -test-" ,
104+ prefix : "marcode-repository-identity-origin-priority -test-" ,
77105 } ) ;
78106
79107 yield * git ( cwd , [ "init" ] ) ;
80- yield * git ( cwd , [ "remote" , "add" , "origin" , "git@github.com:julius /marcode.git" ] ) ;
108+ yield * git ( cwd , [ "remote" , "add" , "origin" , "git@github.com:tyulyukov /marcode.git" ] ) ;
81109 yield * git ( cwd , [ "remote" , "add" , "upstream" , "git@github.com:MarCodeHQ/marcode.git" ] ) ;
82110
83111 const resolver = yield * RepositoryIdentityResolver ;
84112 const identity = yield * resolver . resolve ( cwd ) ;
85113
86114 expect ( identity ) . not . toBeNull ( ) ;
87- expect ( identity ?. locator . remoteName ) . toBe ( "upstream " ) ;
88- expect ( identity ?. canonicalKey ) . toBe ( "github.com/marcodehq /marcode" ) ;
89- expect ( identity ?. displayName ) . toBe ( "marcodehq /marcode" ) ;
115+ expect ( identity ?. locator . remoteName ) . toBe ( "origin " ) ;
116+ expect ( identity ?. canonicalKey ) . toBe ( "github.com/tyulyukov /marcode" ) ;
117+ expect ( identity ?. displayName ) . toBe ( "tyulyukov /marcode" ) ;
90118 } ) . pipe ( Effect . provide ( RepositoryIdentityResolverLive ) ) ,
91119 ) ;
92120
0 commit comments