@@ -157,6 +157,7 @@ it.layer(layerTest)("RuntimePolicyV2", (it) => {
157157} ) ;
158158
159159const tokenReads : Array < string | null | undefined > = [ ] ;
160+ const repositoryReads : Array < string > = [ ] ;
160161const identityFor = ( owner : string , host = "github.com" ) => ( {
161162 canonicalKey : `${ host } /${ owner } /web` ,
162163 locator : {
@@ -173,11 +174,12 @@ const layerWithAccounts = layerTest.pipe(
173174 Layer . mergeAll (
174175 Layer . mock ( RepositoryIdentityResolver . RepositoryIdentityResolver ) ( {
175176 resolve : ( cwd ) =>
176- Effect . succeed (
177- cwd === "/enterprise-worktree"
177+ Effect . sync ( ( ) => {
178+ repositoryReads . push ( cwd ) ;
179+ return cwd === "/enterprise-worktree"
178180 ? identityFor ( "acme" , "github.acme-corp.example" )
179- : identityFor ( cwd === "/project-worktree" ? "acme" : "someone" ) ,
180- ) ,
181+ : identityFor ( cwd === "/project-worktree" ? "acme" : "someone" ) ;
182+ } ) ,
181183 } ) ,
182184 Layer . mock ( GitHubCredentials . GitHubCredentials ) ( {
183185 accountFor : ( _host , repository ) =>
@@ -199,22 +201,34 @@ const layerWithAccounts = layerTest.pipe(
199201) ;
200202
201203it . layer ( layerWithAccounts ) ( "RuntimePolicyV2 with GitHub accounts" , ( it ) => {
202- it . effect ( "hands the agent the token of the account its repository reads as " , ( ) =>
204+ it . effect ( "resolves repository credentials only when opening a provider session " , ( ) =>
203205 Effect . gen ( function * ( ) {
204206 const policy = yield * RuntimePolicy . RuntimePolicyV2 ;
205207 const now = yield * DateTime . now ;
206- const company = yield * policy . resolve ( {
208+ const input = {
207209 thread : makeThread ( { now, worktreePath : "/project-worktree" } ) ,
208210 modelSelection,
211+ } ;
212+ const dispatch = yield * policy . resolve ( input ) ;
213+ assert . equal ( dispatch . cwd , "/project-worktree" ) ;
214+ assert . deepEqual ( repositoryReads , [ ] ) ;
215+ assert . deepEqual ( tokenReads , [ ] ) ;
216+ assert . isUndefined ( dispatch . environment ) ;
217+
218+ const company = yield * policy . resolve ( {
219+ ...input ,
220+ includeEnvironment : true ,
209221 } ) ;
210222 assert . deepEqual ( ProviderAdapter . runtimePolicyEnvironment ( company ) , {
211223 GH_TOKEN : "work-token" ,
212224 } ) ;
213225 assert . notInclude ( JSON . stringify ( company ) , "work-token" ) ;
226+ assert . deepEqual ( repositoryReads , [ "/project-worktree" ] ) ;
214227
215228 const personal = yield * policy . resolve ( {
216229 thread : makeThread ( { now, worktreePath : null } ) ,
217230 modelSelection,
231+ includeEnvironment : true ,
218232 } ) ;
219233 assert . isUndefined ( personal . environment ) ;
220234 assert . deepEqual ( tokenReads , [ "acme/web" ] ) ;
@@ -224,6 +238,7 @@ it.layer(layerWithAccounts)("RuntimePolicyV2 with GitHub accounts", (it) => {
224238 const enterprise = yield * policy . resolve ( {
225239 thread : makeThread ( { now, worktreePath : "/enterprise-worktree" } ) ,
226240 modelSelection,
241+ includeEnvironment : true ,
227242 } ) ;
228243 assert . isUndefined ( enterprise . environment ) ;
229244 assert . deepEqual ( tokenReads , [ "acme/web" ] ) ;
0 commit comments