Skip to content

armgit / eve

Public Imported from GitHub
0

The Open Framework for Building Agents

fix(eve): publish stacked PR package artifacts (#3599)

Casey Gowrie44e39a394569
diff --git a/apps/package-artifacts/README.md b/apps/package-artifacts/README.md
index 70bce6f27..7e7c926a6 100644
--- a/apps/package-artifacts/README.md
+++ b/apps/package-artifacts/README.md
@@ -16,7 +16,7 @@ Initialize an agent from the current `main` build with:
npm exec --yes --package=https://pkg.eve.dev/main/eve.tgz -- eve init my-agent
```
-A same-repository pull-request build is available after its **Vercel – eve-pkg** deployment succeeds. Fork pull requests and direct branch deployments never build or publish package artifacts. For example:
+A same-repository pull-request build is available after its **Vercel – eve-pkg** deployment succeeds, including when the pull request targets another branch in a stack. Fork pull requests and direct branch deployments never build or publish package artifacts. For example:
```bash
npm exec --yes --package=https://pkg.eve.dev/pr/123/eve.tgz -- eve init my-agent
diff --git a/apps/package-artifacts/lib/deployment-target.mjs b/apps/package-artifacts/lib/deployment-target.mjs
index 00460d636..7fc9f6238 100644
--- a/apps/package-artifacts/lib/deployment-target.mjs
+++ b/apps/package-artifacts/lib/deployment-target.mjs
@@ -57,7 +57,6 @@ async function resolvePullRequest(env, sourceSha, fetchImplementation) {
const branch = env.VERCEL_GIT_COMMIT_REF;
if (typeof branch !== "string" || branch.length === 0) return undefined;
const query = new URLSearchParams({
- base: "main",
head: `${REPOSITORY_OWNER}:${branch}`,
state: "open",
});
@@ -69,7 +68,6 @@ async function resolvePullRequest(env, sourceSha, fetchImplementation) {
function isCurrentPullRequest(pull, sourceSha, branch) {
return (
pull.state === "open" &&
- pull.base?.ref === "main" &&
pull.head?.ref === branch &&
pull.head?.repo?.full_name === REPOSITORY &&
pull.head?.sha === sourceSha
diff --git a/apps/package-artifacts/lib/deployment-target.test.mjs b/apps/package-artifacts/lib/deployment-target.test.mjs
index 8f4380dea..fb1516e7a 100644
--- a/apps/package-artifacts/lib/deployment-target.test.mjs
+++ b/apps/package-artifacts/lib/deployment-target.test.mjs
@@ -39,8 +39,11 @@ describe("Vercel package deployment target", () => {
).resolves.toEqual({ sourceSha: sha, ref: "main", origin: "https://pkg.eve.dev" });
});
- test("publishes same-repository pull requests from the system PR ID", async () => {
- const fetchImplementation = vi.fn().mockResolvedValue(githubResponse(currentPull));
+ test.each([
+ ["main-based", currentPull],
+ ["stacked", { ...currentPull, base: { ref: "feature/base" } }],
+ ])("publishes %s same-repository pull requests from the system PR ID", async (_, pull) => {
+ const fetchImplementation = vi.fn().mockResolvedValue(githubResponse(pull));
await expect(resolveDeploymentTarget(baseEnv, fetchImplementation)).resolves.toEqual({
sourceSha: sha,
ref: "123",
@@ -53,15 +56,18 @@ describe("Vercel package deployment target", () => {
});
test("resolves a PR when its branch deployment started before the PR existed", async () => {
- const fetchImplementation = vi.fn().mockResolvedValue(githubResponse([currentPull]));
+ const fetchImplementation = vi
+ .fn()
+ .mockResolvedValue(githubResponse([{ ...currentPull, base: { ref: "feature/base" } }]));
await expect(
resolveDeploymentTarget({ ...baseEnv, VERCEL_GIT_PULL_REQUEST_ID: "" }, fetchImplementation),
).resolves.toEqual({ sourceSha: sha, ref: "123", origin: "https://pkg.eve.dev" });
const [url] = fetchImplementation.mock.calls[0];
expect(url).toContain("head=vercel%3Afeature%2Fpackage");
+ expect(url).not.toContain("base=");
});
- test("rejects local, fork, direct branch, stale, and non-main PR deployments", async () => {
+ test("rejects local, fork, direct branch, and stale PR deployments", async () => {
await expect(resolveDeploymentTarget({})).resolves.toBeUndefined();
await expect(
resolveDeploymentTarget({ ...baseEnv, VERCEL_GIT_REPO_OWNER: "alice" }),
@@ -75,7 +81,6 @@ describe("Vercel package deployment target", () => {
for (const pull of [
{ ...currentPull, state: "closed" },
- { ...currentPull, base: { ref: "release" } },
{ ...currentPull, head: { ...currentPull.head, sha: "b".repeat(40) } },
]) {
await expect(
diff --git a/apps/package-artifacts/lib/publication-current.mjs b/apps/package-artifacts/lib/publication-current.mjs
index 1a9393fcf..7bfb15b6f 100644
--- a/apps/package-artifacts/lib/publication-current.mjs
+++ b/apps/package-artifacts/lib/publication-current.mjs
@@ -26,7 +26,7 @@ export async function assertCurrentPublicationTarget(
}
const pull = await githubRequest(`/repos/${repository}/pulls/${ref}`, token, fetchImplementation);
- if (pull.state !== "open" || pull.base?.ref !== "main" || pull.head?.sha !== sourceSha) {
+ if (pull.state !== "open" || pull.head?.sha !== sourceSha) {
throw new Error(`Refusing to update PR #${ref} package pointer from stale build ${sourceSha}.`);
}
}
diff --git a/apps/package-artifacts/lib/publication-current.test.mjs b/apps/package-artifacts/lib/publication-current.test.mjs
index ee236b57a..6b1792fc1 100644
--- a/apps/package-artifacts/lib/publication-current.test.mjs
+++ b/apps/package-artifacts/lib/publication-current.test.mjs
@@ -36,26 +36,28 @@ describe("current package publication target", () => {
).rejects.toThrow("stale build");
});
- test("accepts the current open pull request build without a GitHub token", async () => {
- const fetchImplementation = vi
- .fn()
- .mockResolvedValue(response({ state: "open", base: { ref: "main" }, head: { sha } }));
- await expect(
- assertCurrentPublicationTarget({ ...input, token: undefined }, fetchImplementation),
- ).resolves.toBeUndefined();
- expect(fetchImplementation).toHaveBeenCalledWith(
- "https://api.github.com/repos/vercel/eve/pulls/123",
- expect.objectContaining({
- headers: expect.not.objectContaining({ Authorization: expect.anything() }),
- }),
- );
- });
+ test.each(["main", "feature/base"])(
+ "accepts a current open pull request build based on %s without a GitHub token",
+ async (base) => {
+ const fetchImplementation = vi
+ .fn()
+ .mockResolvedValue(response({ state: "open", base: { ref: base }, head: { sha } }));
+ await expect(
+ assertCurrentPublicationTarget({ ...input, token: undefined }, fetchImplementation),
+ ).resolves.toBeUndefined();
+ expect(fetchImplementation).toHaveBeenCalledWith(
+ "https://api.github.com/repos/vercel/eve/pulls/123",
+ expect.objectContaining({
+ headers: expect.not.objectContaining({ Authorization: expect.anything() }),
+ }),
+ );
+ },
+ );
- test("rejects stale, closed, and retargeted pull requests", async () => {
+ test("rejects stale and closed pull requests", async () => {
const invalidPulls = [
{ state: "open", base: { ref: "main" }, head: { sha: "b".repeat(40) } },
{ state: "closed", base: { ref: "main" }, head: { sha } },
- { state: "open", base: { ref: "release" }, head: { sha } },
];
for (const pull of invalidPulls) {
const fetchImplementation = vi.fn().mockResolvedValue(response(pull));