Skip to content

Commit 7bec24a

Browse files
test(agents): exercise real workspace repository resolution
1 parent 0628643 commit 7bec24a

1 file changed

Lines changed: 31 additions & 19 deletions

File tree

‎apps/server/src/orchestration-v2/RuntimePolicy.test.ts‎

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -161,29 +161,41 @@ it.layer(layerTest)("RuntimePolicyV2", (it) => {
161161

162162
const tokenReads: Array<string | null | undefined> = [];
163163
const repositoryReads: Array<string> = [];
164-
const identityFor = (owner: string, host = "github.com") => ({
165-
canonicalKey: `${host}/${owner}/web`,
166-
locator: {
167-
source: "git-remote" as const,
168-
remoteName: "origin",
169-
remoteUrl: `git@${host}:${owner}/web.git`,
170-
},
171-
owner,
172-
name: "web",
173-
});
174164

175165
const layerWithAccounts = layerTest.pipe(
176166
Layer.provide(
177167
Layer.mergeAll(
178-
Layer.mock(RepositoryIdentityResolver.RepositoryIdentityResolver)({
179-
resolve: (cwd) =>
180-
Effect.sync(() => {
181-
repositoryReads.push(cwd);
182-
return cwd === "/enterprise-worktree"
183-
? identityFor("acme", "github.acme-corp.example")
184-
: identityFor(cwd === "/project-worktree" ? "acme" : "someone");
168+
Layer.effect(
169+
RepositoryIdentityResolver.RepositoryIdentityResolver,
170+
RepositoryIdentityResolver.make(),
171+
).pipe(
172+
Layer.provide(
173+
Layer.mock(ProcessRunner.ProcessRunner)({
174+
run: ({ args }) =>
175+
Effect.sync(() => {
176+
const cwd = args[1] ?? "";
177+
if (args.includes("rev-parse")) repositoryReads.push(cwd);
178+
const host =
179+
cwd === "/enterprise-worktree" ? "github.acme-corp.example" : "github.com";
180+
const owner = cwd === "/project-root" ? "someone" : "acme";
181+
return {
182+
stdout: args.includes("rev-parse")
183+
? `${cwd}\n`
184+
: args.includes("remote")
185+
? `origin\thttps://${host}/${owner}/web.git (fetch)\n`
186+
: "",
187+
stderr: "",
188+
code: ChildProcessSpawner.ExitCode(0),
189+
timedOut: false,
190+
stdoutTruncated: false,
191+
stderrTruncated: false,
192+
stdoutInvalidUtf8: false,
193+
stderrInvalidUtf8: false,
194+
};
195+
}),
185196
}),
186-
}),
197+
),
198+
),
187199
Layer.mock(GitHubCredentials.GitHubCredentials)({
188200
accountFor: (_host, repository) =>
189201
Effect.succeed(repository === "acme/web" ? "work" : undefined),
@@ -245,7 +257,7 @@ it.layer(layerWithAccounts)("RuntimePolicyV2 with GitHub accounts", (it) => {
245257
});
246258
assert.isUndefined(enterprise.environment);
247259
assert.deepEqual(tokenReads, ["acme/web"]);
248-
}),
260+
}).pipe(Effect.provideService(HostProcess.Environment, {})),
249261
);
250262
});
251263

0 commit comments

Comments
 (0)