Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/cli/src/controllers/app-env-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export async function findVariableByNaturalKey(
resolved: ResolvedEnvApiScope,
signal: AbortSignal,
): Promise<RawEnvironmentVariable | null> {
// Filter by branchId server-side — the list pages at 100, so client-side-only filtering drops branch rows past page 1.
const { data, error, response } = await client.GET(
"/v1/environment-variables",
{
Expand All @@ -41,6 +42,9 @@ export async function findVariableByNaturalKey(
projectId,
class: resolved.apiTarget.class,
key,
...(resolved.apiTarget.branchId !== null
? { branchId: resolved.apiTarget.branchId }
: {}),
},
},
signal,
Expand Down
61 changes: 61 additions & 0 deletions packages/cli/tests/app-env.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -944,6 +944,67 @@ describe("env update", () => {
);
});

it("scopes the branch-override lookup by branchId so it survives pagination", async () => {
const client = createMockClient();
client.envGET
.mockResolvedValueOnce({
data: {
data: [makeBranchRow()],
pagination: { hasMore: false, nextCursor: null },
},
response: { status: 200 },
})
.mockResolvedValueOnce({
data: {
data: [
makeVariableRow({
id: "envvar_branch",
key: "DATABASE_URL",
class: "preview",
branchId: "br_feature",
}),
],
pagination: { hasMore: false, nextCursor: null },
},
response: { status: 200 },
});
client.PATCH.mockResolvedValueOnce({
data: {
data: makeVariableRow({
id: "envvar_branch",
key: "DATABASE_URL",
class: "preview",
branchId: "br_feature",
}),
},
response: { status: 200 },
});

const { controllers, createTempCwd, createTestCommandContext } =
await loadControllers(client, "proj_123");
const cwd = await createTempCwd();
await writeLocalPin(cwd);
const { context } = await createTestCommandContext({ cwd });

await controllers.runEnvUpdate(context, "DATABASE_URL=postgresql://new", {
branchName: "feature/foo",
});

expect(client.GET).toHaveBeenCalledWith(
"/v1/environment-variables",
expect.objectContaining({
params: {
query: expect.objectContaining({
projectId: "proj_123",
class: "preview",
key: "DATABASE_URL",
branchId: "br_feature",
}),
},
}),
);
});

it("updates variables from a dotenv file via PATCH", async () => {
const client = createMockClient();
client.envGET
Expand Down
Loading