@@ -23,6 +23,8 @@ import * as Stream from "effect/Stream";
2323import { TestClock } from "effect/testing" ;
2424import { ChildProcessSpawner } from "effect/process" ;
2525import { expect } from "vite-plus/test" ;
26+ import { HostProcessEnvironment } from "@t3tools/shared/hostProcess" ;
27+ import { symlinksSupported } from "@t3tools/shared/testing/symlinks" ;
2628import type {
2729 ChangeRequest ,
2830 GitActionProgressEvent ,
@@ -285,6 +287,36 @@ function createBareRemote(): Effect.Effect<
285287 } ) ;
286288}
287289
290+ /**
291+ * A repository whose project uses `db-migrations` from the skill library under `home` and `solo`
292+ * from a folder of its own, linked into `.agents/skills` and, for the library skill, also into
293+ * `.claude/skills`. It is committed, so a worktree has the same files but none of the links.
294+ */
295+ function repoWithLibrarySkill ( ) {
296+ return Effect . gen ( function * ( ) {
297+ const fileSystem = yield * FileSystem . FileSystem ;
298+ const home = yield * makeTempDir ( "t3code-skill-home-" ) ;
299+ const cwd = yield * makeTempDir ( "t3code-git-manager-" ) ;
300+ yield * initRepo ( cwd ) ;
301+ const entry = NodePath . join ( home , ".agents/skill-library/db-migrations" ) ;
302+ yield * fileSystem . makeDirectory ( entry , { recursive : true } ) ;
303+ yield * fileSystem . writeFileString (
304+ NodePath . join ( entry , "SKILL.md" ) ,
305+ "---\nname: db-migrations\n---\n" ,
306+ ) ;
307+ yield * fileSystem . makeDirectory ( NodePath . join ( cwd , "elsewhere/solo" ) , { recursive : true } ) ;
308+ for ( const folder of [ ".agents/skills" , ".claude/skills" ] ) {
309+ yield * fileSystem . makeDirectory ( NodePath . join ( cwd , folder ) , { recursive : true } ) ;
310+ yield * fileSystem . symlink ( entry , NodePath . join ( cwd , folder , "db-migrations" ) ) ;
311+ }
312+ yield * fileSystem . symlink (
313+ NodePath . join ( cwd , "elsewhere/solo" ) ,
314+ NodePath . join ( cwd , ".agents/skills/solo" ) ,
315+ ) ;
316+ return { home, cwd, entry } ;
317+ } ) ;
318+ }
319+
288320function configureRemote (
289321 cwd : string ,
290322 remoteName : string ,
@@ -4868,6 +4900,128 @@ it.layer(layerGitManagerTest)("GitManager", (it) => {
48684900 } ) ,
48694901 ) ;
48704902
4903+ it . effect . skipIf ( ! symlinksSupported ) (
4904+ "links a project's library skills into a new worktree, and leaves its other links behind" ,
4905+ ( ) =>
4906+ Effect . gen ( function * ( ) {
4907+ const fileSystem = yield * FileSystem . FileSystem ;
4908+ const { home, cwd, entry } = yield * repoWithLibrarySkill ( ) ;
4909+ const { manager } = yield * makeManager ( ) ;
4910+ const worktree = NodePath . join ( yield * makeTempDir ( "t3code-git-worktrees-" ) , "feature" ) ;
4911+
4912+ const created = yield * manager
4913+ . createWorktree ( {
4914+ cwd,
4915+ path : worktree ,
4916+ refName : "main" ,
4917+ newRefName : "feature/library-links" ,
4918+ } )
4919+ . pipe ( Effect . provideService ( HostProcessEnvironment , { HOME : home } ) ) ;
4920+
4921+ expect ( created . worktree . path ) . toBe ( worktree ) ;
4922+ for ( const folder of [ ".agents/skills" , ".claude/skills" ] ) {
4923+ expect ( yield * fileSystem . readLink ( NodePath . join ( worktree , folder , "db-migrations" ) ) ) . toBe (
4924+ entry ,
4925+ ) ;
4926+ }
4927+ // A link to something other than the library is the project's own business.
4928+ expect ( yield * fileSystem . exists ( NodePath . join ( worktree , ".agents/skills/solo" ) ) ) . toBe (
4929+ false ,
4930+ ) ;
4931+ } ) ,
4932+ ) ;
4933+
4934+ it . effect . skipIf ( ! symlinksSupported ) (
4935+ "links a project's library skills into the worktree of a pull request thread" ,
4936+ ( ) =>
4937+ Effect . gen ( function * ( ) {
4938+ const fileSystem = yield * FileSystem . FileSystem ;
4939+ const { home, cwd, entry } = yield * repoWithLibrarySkill ( ) ;
4940+ const remoteDir = yield * createBareRemote ( ) ;
4941+ yield * runGit ( cwd , [ "remote" , "add" , "origin" , remoteDir ] ) ;
4942+ yield * runGit ( cwd , [ "push" , "-u" , "origin" , "main" ] ) ;
4943+ yield * runGit ( cwd , [ "checkout" , "-b" , "feature/pr-links" ] ) ;
4944+ yield * fileSystem . writeFileString ( NodePath . join ( cwd , "pr.txt" ) , "pr\n" ) ;
4945+ yield * runGit ( cwd , [ "add" , "pr.txt" ] ) ;
4946+ yield * runGit ( cwd , [ "commit" , "-m" , "PR branch" ] ) ;
4947+ yield * runGit ( cwd , [ "push" , "-u" , "origin" , "feature/pr-links" ] ) ;
4948+ yield * runGit ( cwd , [ "push" , "origin" , "HEAD:refs/pull/78/head" ] ) ;
4949+ yield * runGit ( cwd , [ "checkout" , "main" ] ) ;
4950+ const { manager } = yield * makeManager ( {
4951+ ghScenario : {
4952+ pullRequest : {
4953+ number : 78 ,
4954+ title : "Library links PR" ,
4955+ url : "https://github.com/pingdotgg/codething-mvp/pull/78" ,
4956+ baseRefName : "main" ,
4957+ headRefName : "feature/pr-links" ,
4958+ state : "open" ,
4959+ } ,
4960+ } ,
4961+ } ) ;
4962+
4963+ const result = yield * preparePullRequestThread ( manager , {
4964+ cwd,
4965+ reference : "78" ,
4966+ mode : "worktree" ,
4967+ } ) . pipe ( Effect . provideService ( HostProcessEnvironment , { HOME : home } ) ) ;
4968+
4969+ expect ( result . worktreePath ) . not . toBeNull ( ) ;
4970+ expect (
4971+ yield * fileSystem . readLink (
4972+ NodePath . join ( result . worktreePath as string , ".agents/skills/db-migrations" ) ,
4973+ ) ,
4974+ ) . toBe ( entry ) ;
4975+ } ) ,
4976+ ) ;
4977+
4978+ it . effect . skipIf ( ! symlinksSupported ) (
4979+ "makes the worktree all the same when the library links can't be made" ,
4980+ ( ) =>
4981+ Effect . gen ( function * ( ) {
4982+ const fileSystem = yield * FileSystem . FileSystem ;
4983+ const { home, cwd } = yield * repoWithLibrarySkill ( ) ;
4984+ // On this branch `.agents` is a file, so no folder can be made under it.
4985+ yield * runGit ( cwd , [ "checkout" , "-q" , "-b" , "agents-file" ] ) ;
4986+ yield * fileSystem . remove ( NodePath . join ( cwd , ".agents" ) , { recursive : true } ) ;
4987+ yield * fileSystem . writeFileString ( NodePath . join ( cwd , ".agents" ) , "not a folder\n" ) ;
4988+ yield * runGit ( cwd , [ "add" , "-A" ] ) ;
4989+ yield * runGit ( cwd , [ "commit" , "-q" , "-m" , "agents is a file" ] ) ;
4990+ yield * runGit ( cwd , [ "checkout" , "-q" , "main" ] ) ;
4991+ yield * fileSystem . makeDirectory ( NodePath . join ( cwd , ".agents/skills" ) , { recursive : true } ) ;
4992+ yield * fileSystem . symlink (
4993+ NodePath . join ( home , ".agents/skill-library/db-migrations" ) ,
4994+ NodePath . join ( cwd , ".agents/skills/db-migrations" ) ,
4995+ ) ;
4996+ const { manager } = yield * makeManager ( ) ;
4997+ const worktree = NodePath . join ( yield * makeTempDir ( "t3code-git-worktrees-" ) , "feature" ) ;
4998+ const warnings : string [ ] = [ ] ;
4999+ const logger = Logger . make < unknown , void > ( ( { message } ) => {
5000+ warnings . push ( String ( message ) ) ;
5001+ } ) ;
5002+
5003+ const created = yield * manager
5004+ . createWorktree ( {
5005+ cwd,
5006+ path : worktree ,
5007+ refName : "agents-file" ,
5008+ newRefName : "feature/no-links" ,
5009+ } )
5010+ . pipe (
5011+ Effect . provideService ( HostProcessEnvironment , { HOME : home } ) ,
5012+ Effect . provideService ( Logger . CurrentLoggers , new Set ( [ logger ] ) ) ,
5013+ ) ;
5014+
5015+ expect ( created . worktree . path ) . toBe ( worktree ) ;
5016+ expect (
5017+ warnings . filter ( ( line ) => line . includes ( "could not link library skills" ) ) . length ,
5018+ ) . toBe ( 1 ) ;
5019+ expect ( yield * fileSystem . readFileString ( NodePath . join ( worktree , ".agents" ) ) ) . toBe (
5020+ "not a folder\n" ,
5021+ ) ;
5022+ } ) ,
5023+ ) ;
5024+
48715025 it . effect ( "prepares pull request threads in worktree mode on the PR head branch" , ( ) =>
48725026 Effect . gen ( function * ( ) {
48735027 const repoDir = yield * makeTempDir ( "t3code-git-manager-" ) ;
0 commit comments