Skip to content

armgit / alook

Public Imported from GitHub
0

Multi-Agent Collaboration for Team and Friends

fix: add workspace scoping to setPendingUpdateVersion and clearPendingUpdateVersion

Gus7b8b4d8730b8
diff --git a/src/shared/src/db/queries/machine.ts b/src/shared/src/db/queries/machine.ts
index b13ab4877..844e5e724 100644
--- a/src/shared/src/db/queries/machine.ts
+++ b/src/shared/src/db/queries/machine.ts
@@ -102,24 +102,30 @@ export async function deleteMachine(
export async function setPendingUpdateVersion(
db: Database,
daemonId: string,
+ workspaceId: string,
version: string
) {
const now = new Date().toISOString();
await db
.update(machine)
.set({ pendingUpdateVersion: version, updatedAt: now })
- .where(eq(machine.daemonId, daemonId));
+ .where(
+ and(eq(machine.daemonId, daemonId), eq(machine.workspaceId, workspaceId))
+ );
}
export async function clearPendingUpdateVersion(
db: Database,
- daemonId: string
+ daemonId: string,
+ workspaceId: string
) {
const now = new Date().toISOString();
await db
.update(machine)
.set({ pendingUpdateVersion: null, updatedAt: now })
- .where(eq(machine.daemonId, daemonId));
+ .where(
+ and(eq(machine.daemonId, daemonId), eq(machine.workspaceId, workspaceId))
+ );
}
export async function setPendingRescan(
diff --git a/src/web/src/app/api/daemon/tasks/poll/route.test.ts b/src/web/src/app/api/daemon/tasks/poll/route.test.ts
index a3b9a45d1..13eb9ec5c 100644
--- a/src/web/src/app/api/daemon/tasks/poll/route.test.ts
+++ b/src/web/src/app/api/daemon/tasks/poll/route.test.ts
@@ -351,7 +351,7 @@ describe("POST /api/daemon/tasks/poll", () => {
expect(res.status).toBe(200);
expect(body.pending_update).toBeUndefined();
- expect(mockClearPendingUpdateVersion).toHaveBeenCalledWith({}, "d1");
+ expect(mockClearPendingUpdateVersion).toHaveBeenCalledWith({}, "d1", "w1");
});
it("does not attach pending_update when cli_version is missing (backward compat)", async () => {
diff --git a/src/web/src/app/api/daemon/tasks/poll/route.ts b/src/web/src/app/api/daemon/tasks/poll/route.ts
index 8c1719f46..6e9259350 100644
--- a/src/web/src/app/api/daemon/tasks/poll/route.ts
+++ b/src/web/src/app/api/daemon/tasks/poll/route.ts
@@ -202,7 +202,7 @@ export const POST = withAuth(async (req: NextRequest, ctx) => {
let pendingUpdate: { version: string } | undefined;
if (machineRow?.pendingUpdateVersion && body.cli_version) {
if (semverGte(body.cli_version, machineRow.pendingUpdateVersion)) {
- await queries.machine.clearPendingUpdateVersion(db, body.daemon_id);
+ await queries.machine.clearPendingUpdateVersion(db, body.daemon_id, ctx.workspaceId);
broadcastToUser(ctx.userId, {
type: "runtime.status",
daemonId: body.daemon_id,
diff --git a/src/web/src/app/api/runtimes/[runtimeId]/update/route.test.ts b/src/web/src/app/api/runtimes/[runtimeId]/update/route.test.ts
index ace0f526b..cdf607f74 100644
--- a/src/web/src/app/api/runtimes/[runtimeId]/update/route.test.ts
+++ b/src/web/src/app/api/runtimes/[runtimeId]/update/route.test.ts
@@ -92,7 +92,7 @@ describe("POST /api/runtimes/[runtimeId]/update", () => {
expect(res.status).toBe(200);
expect(body.pending_update_version).toBe("1.0.0");
- expect(mockSetPendingUpdateVersion).toHaveBeenCalledWith({}, "d1", "1.0.0");
+ expect(mockSetPendingUpdateVersion).toHaveBeenCalledWith({}, "d1", "w1", "1.0.0");
});
it("returns 404 for non-existent runtime", async () => {
@@ -146,7 +146,7 @@ describe("DELETE /api/runtimes/[runtimeId]/update", () => {
const res = await DELETE(makeReq("DELETE", "rt1", "w1"));
expect(res.status).toBe(204);
- expect(mockClearPendingUpdateVersion).toHaveBeenCalledWith({}, "d1");
+ expect(mockClearPendingUpdateVersion).toHaveBeenCalledWith({}, "d1", "w1");
});
it("returns 404 for non-existent runtime", async () => {
diff --git a/src/web/src/app/api/runtimes/[runtimeId]/update/route.ts b/src/web/src/app/api/runtimes/[runtimeId]/update/route.ts
index e1a6ac168..2bb320a45 100644
--- a/src/web/src/app/api/runtimes/[runtimeId]/update/route.ts
+++ b/src/web/src/app/api/runtimes/[runtimeId]/update/route.ts
@@ -27,7 +27,7 @@ export const POST = withAuth(async (req: NextRequest, ctx) => {
const result = await fetchLatestCliVersion();
if (!result) return writeError("failed to fetch latest CLI version from npm", 502);
- await queries.machine.setPendingUpdateVersion(db, runtime.daemonId, result.version);
+ await queries.machine.setPendingUpdateVersion(db, runtime.daemonId, ws.workspaceId, result.version);
return writeJSON({ pending_update_version: result.version });
});
@@ -49,7 +49,7 @@ export const DELETE = withAuth(async (req: NextRequest, ctx) => {
);
if (!runtime) return writeError("runtime not found", 404);
- await queries.machine.clearPendingUpdateVersion(db, runtime.daemonId);
+ await queries.machine.clearPendingUpdateVersion(db, runtime.daemonId, ws.workspaceId);
return new Response(null, { status: 204 });
});