Multi-Agent Collaboration for Team and Friends
TypeScript agent-automationagent-orchestrationagent-workflowai-agentsai-collaborationai-memoryai-workforceautonomous-agentsclaude-codeclaude-code-skillscodexcoding-agentmulti-agentmultiple-agentone-person-businessone-person-companyone-person-teamopencodesolopreneur
fix(test): fix e2e afterAll timeout and ECONNRESET flakiness
Gener376b3d736e0d
diff --git a/src/web/src/test/e2e/daemon-lifecycle.test.ts b/src/web/src/test/e2e/daemon-lifecycle.test.tsindex d0e454825..8e51acb30 100644--- a/src/web/src/test/e2e/daemon-lifecycle.test.ts+++ b/src/web/src/test/e2e/daemon-lifecycle.test.ts@@ -2,7 +2,7 @@ import { describe, it, expect, beforeAll, afterAll } from "vitest"import { randomUUID } from "crypto"import { seedTestData, cleanupTestData, type TestSeed } from "../helpers/seed"import { tokenRequest } from "../helpers/auth"-import { sql, sqlQuery } from "../helpers/db"+import { sqlQuery, sqlBatch } from "../helpers/db"let seed: TestSeed@@ -108,11 +108,12 @@ describe("daemon lifecycle", () => {expect(rows[0]?.last_seen_at).toBeNull()})- // Cleanup the registered runtime and machineafterAll(() => {try {- sql(`DELETE FROM agent_runtime WHERE daemon_id = '${daemonId}'`)- sql(`DELETE FROM machine WHERE daemon_id = '${daemonId}'`)+ sqlBatch([+ `DELETE FROM agent_runtime WHERE daemon_id = '${daemonId}'`,+ `DELETE FROM machine WHERE daemon_id = '${daemonId}'`,+ ])} catch { /* ignore */ }})})diff --git a/src/web/src/test/e2e/email.test.ts b/src/web/src/test/e2e/email.test.tsindex b2beebe04..25a7ae078 100644--- a/src/web/src/test/e2e/email.test.ts+++ b/src/web/src/test/e2e/email.test.ts@@ -3,8 +3,7 @@ import { randomUUID } from "crypto"import { seedTestData, cleanupTestData, type TestSeed } from "../helpers/seed"import { tokenRequest } from "../helpers/auth"import { sql, sqlQuery } from "../helpers/db"--const EMAIL_WORKER_URL = process.env.EMAIL_WORKER_URL ?? "http://localhost:8787"+import { postEmail, postEmailRaw } from "../helpers/email"let seed: TestSeed@@ -13,22 +12,6 @@ beforeAll(() => {})afterAll(() => cleanupTestData(seed))-/** Build a minimal RFC 5322 email with Message-ID (required by wrangler) */-function rawEmail(from: string, to: string, subject: string, body: string): string {- const msgId = `<${randomUUID()}@e2e.test>`- return [- `From: ${from}`,- `To: ${to}`,- `Subject: ${subject}`,- `Message-ID: ${msgId}`,- `Date: ${new Date().toUTCString()}`,- `MIME-Version: 1.0`,- `Content-Type: text/plain; charset=utf-8`,- "",- body,- ].join("\r\n")-}-/** Poll D1 until at least one email row matches, or timeout */async function waitForEmail(agentId: string,@@ -54,15 +37,7 @@ describe("email receive (inbound)", () => {const to = `${seed.agentEmailHandle}@alook.ai`const subject = "E2E whitelisted test"- const res = await fetch(- `${EMAIL_WORKER_URL}/cdn-cgi/handler/email?from=${encodeURIComponent(from)}&to=${encodeURIComponent(to)}`,- {- method: "POST",- headers: { "Content-Type": "application/json" },- body: rawEmail(from, to, subject, "Hello from e2e"),- },- )- // wrangler returns 200 for accepted emails+ const res = await postEmail(from, to, subject, "Hello from e2e")expect(res.status).toBe(200)const row = await waitForEmail(seed.agentId, from)@@ -76,14 +51,7 @@ describe("email receive (inbound)", () => {const to = `${seed.agentEmailHandle}@alook.ai`const subject = "E2E non-whitelisted test"- await fetch(- `${EMAIL_WORKER_URL}/cdn-cgi/handler/email?from=${encodeURIComponent(from)}&to=${encodeURIComponent(to)}`,- {- method: "POST",- headers: { "Content-Type": "application/json" },- body: rawEmail(from, to, subject, "Stranger email"),- },- )+ await postEmail(from, to, subject, "Stranger email")const row = await waitForEmail(seed.agentId, from)expect(row).not.toBeNull()@@ -96,14 +64,7 @@ describe("email receive (inbound)", () => {const to = "[email protected]"const subject = "E2E unknown handle"- await fetch(- `${EMAIL_WORKER_URL}/cdn-cgi/handler/email?from=${encodeURIComponent(from)}&to=${encodeURIComponent(to)}`,- {- method: "POST",- headers: { "Content-Type": "application/json" },- body: rawEmail(from, to, subject, "Should be rejected"),- },- )+ await postEmail(from, to, subject, "Should be rejected")// Small wait to ensure nothing is writtenawait new Promise((r) => setTimeout(r, 1000))@@ -140,10 +101,7 @@ describe("email threading (inbound)", () => {"Thread test body",].join("\r\n")- await fetch(- `${EMAIL_WORKER_URL}/cdn-cgi/handler/email?from=${encodeURIComponent(from)}&to=${encodeURIComponent(to)}`,- { method: "POST", headers: { "Content-Type": "application/json" }, body: raw },- )+ await postEmailRaw(from, to, raw)const row = await waitForEmail(seed.agentId, from, 5000)expect(row).not.toBeNull()diff --git a/src/web/src/test/e2e/whitelist-bypass.test.ts b/src/web/src/test/e2e/whitelist-bypass.test.tsindex 59eef0c2b..456540ce0 100644--- a/src/web/src/test/e2e/whitelist-bypass.test.ts+++ b/src/web/src/test/e2e/whitelist-bypass.test.ts@@ -1,6 +1,7 @@import { describe, it, expect, beforeAll, afterAll } from "vitest"import { seedTestData, cleanupTestData, type TestSeed } from "../helpers/seed"import { sql, sqlQuery } from "../helpers/db"+import { postEmail } from "../helpers/email"import { randomUUID } from "crypto"let seed: TestSeed@@ -20,23 +21,6 @@ afterAll(() => {})describe("whitelist bypass for same-workspace agents", () => {- const EMAIL_WORKER_URL = process.env.EMAIL_WORKER_URL ?? "http://localhost:8787"-- function rawEmail(from: string, to: string, subject: string, body: string): string {- const msgId = `<${randomUUID()}@e2e.test>`- return [- `From: ${from}`,- `To: ${to}`,- `Subject: ${subject}`,- `Message-ID: ${msgId}`,- `Date: ${new Date().toUTCString()}`,- `MIME-Version: 1.0`,- `Content-Type: text/plain; charset=utf-8`,- "",- body,- ].join("\r\n")- }-async function waitForEmail(agentId: string,fromEmail: string,@@ -54,26 +38,16 @@ describe("whitelist bypass for same-workspace agents", () => {}it("same-workspace agent email is treated as whitelisted (bypass)", async () => {- // Create a second agent in the same workspace with its own email handleconst siblingAgentId = `ag_${nanoid()}`const siblingHandle = `e2e-sib-${nanoid()}`const now = new Date().toISOString()sql(`INSERT INTO agent (id, workspace_id, name, runtime_id, email_handle, owner_id, created_at, updated_at) VALUES ('${siblingAgentId}', '${seed.workspaceId}', 'Sibling Agent', '${seed.runtimeId}', '${siblingHandle}', '${seed.userId}', '${now}', '${now}')`)try {- // Sibling agent emails the seed agent — sibling is NOT in seed agent's whitelistconst from = `${siblingHandle}@alook.ai`const to = `${seed.agentEmailHandle}@alook.ai`- const subject = "E2E bypass test"-- const res = await fetch(- `${EMAIL_WORKER_URL}/cdn-cgi/handler/email?from=${encodeURIComponent(from)}&to=${encodeURIComponent(to)}`,- {- method: "POST",- headers: { "Content-Type": "application/json" },- body: rawEmail(from, to, subject, "Hello from sibling"),- },- )++ const res = await postEmail(from, to, "E2E bypass test", "Hello from sibling")expect(res.status).toBe(200)const row = await waitForEmail(seed.agentId, from)@@ -87,16 +61,8 @@ describe("whitelist bypass for same-workspace agents", () => {it("agent emailing itself is treated as whitelisted", async () => {const from = `${seed.agentEmailHandle}@alook.ai`const to = `${seed.agentEmailHandle}@alook.ai`- const subject = "E2E self-email test"-- const res = await fetch(- `${EMAIL_WORKER_URL}/cdn-cgi/handler/email?from=${encodeURIComponent(from)}&to=${encodeURIComponent(to)}`,- {- method: "POST",- headers: { "Content-Type": "application/json" },- body: rawEmail(from, to, subject, "Hello self"),- },- )++ const res = await postEmail(from, to, "E2E self-email test", "Hello self")expect(res.status).toBe(200)const row = await waitForEmail(seed.agentId, from)@@ -105,20 +71,11 @@ describe("whitelist bypass for same-workspace agents", () => {})it("different-workspace agent email is NOT treated as whitelisted", async () => {- // seedOther is in a different workspace — its agent email should not bypassconst from = `${seedOther.agentEmailHandle}@alook.ai`const to = `${seed.agentEmailHandle}@alook.ai`- const subject = "E2E cross-workspace test"-- const res = await fetch(- `${EMAIL_WORKER_URL}/cdn-cgi/handler/email?from=${encodeURIComponent(from)}&to=${encodeURIComponent(to)}`,- {- method: "POST",- headers: { "Content-Type": "application/json" },- body: rawEmail(from, to, subject, "Cross workspace"),- },- )- // May be 200 (stored but rejected) or rejected++ await postEmail(from, to, "E2E cross-workspace test", "Cross workspace")+const row = await waitForEmail(seed.agentId, from)expect(row).not.toBeNull()expect(row!.is_whitelisted).toBe(0)@@ -127,16 +84,8 @@ describe("whitelist bypass for same-workspace agents", () => {it("@alook.ai email with nonexistent handle is NOT whitelisted", async () => {const from = `nonexistent-handle-${nanoid()}@alook.ai`const to = `${seed.agentEmailHandle}@alook.ai`- const subject = "E2E nonexistent handle test"- await fetch(- `${EMAIL_WORKER_URL}/cdn-cgi/handler/email?from=${encodeURIComponent(from)}&to=${encodeURIComponent(to)}`,- {- method: "POST",- headers: { "Content-Type": "application/json" },- body: rawEmail(from, to, subject, "Ghost agent"),- },- )+ await postEmail(from, to, "E2E nonexistent handle test", "Ghost agent")const row = await waitForEmail(seed.agentId, from)expect(row).not.toBeNull()@@ -144,19 +93,10 @@ describe("whitelist bypass for same-workspace agents", () => {})it("regular whitelist entries still work (existing behavior)", async () => {- // [email protected] is in the whitelist — should still be whitelistedconst from = `${seed.userId}@test.local`const to = `${seed.agentEmailHandle}@alook.ai`- const subject = "E2E regular whitelist test"-- const res = await fetch(- `${EMAIL_WORKER_URL}/cdn-cgi/handler/email?from=${encodeURIComponent(from)}&to=${encodeURIComponent(to)}`,- {- method: "POST",- headers: { "Content-Type": "application/json" },- body: rawEmail(from, to, subject, "Regular whitelisted"),- },- )++ const res = await postEmail(from, to, "E2E regular whitelist test", "Regular whitelisted")expect(res.status).toBe(200)const row = await waitForEmail(seed.agentId, from)@@ -167,16 +107,8 @@ describe("whitelist bypass for same-workspace agents", () => {it("non-whitelisted non-agent email is rejected (existing behavior)", async () => {const from = "[email protected]"const to = `${seed.agentEmailHandle}@alook.ai`- const subject = "E2E stranger test"- await fetch(- `${EMAIL_WORKER_URL}/cdn-cgi/handler/email?from=${encodeURIComponent(from)}&to=${encodeURIComponent(to)}`,- {- method: "POST",- headers: { "Content-Type": "application/json" },- body: rawEmail(from, to, subject, "Stranger"),- },- )+ await postEmail(from, to, "E2E stranger test", "Stranger")const row = await waitForEmail(seed.agentId, from)expect(row).not.toBeNull()@@ -184,7 +116,6 @@ describe("whitelist bypass for same-workspace agents", () => {})it("sender that is both whitelisted AND same-workspace agent is whitelisted", async () => {- // Create a sibling agent and also add it to the whitelistconst siblingAgentId = `ag_${nanoid()}`const siblingHandle = `e2e-both-${nanoid()}`const now = new Date().toISOString()@@ -195,16 +126,8 @@ describe("whitelist bypass for same-workspace agents", () => {try {const from = `${siblingHandle}@alook.ai`const to = `${seed.agentEmailHandle}@alook.ai`- const subject = "E2E both paths test"-- const res = await fetch(- `${EMAIL_WORKER_URL}/cdn-cgi/handler/email?from=${encodeURIComponent(from)}&to=${encodeURIComponent(to)}`,- {- method: "POST",- headers: { "Content-Type": "application/json" },- body: rawEmail(from, to, subject, "Both paths"),- },- )++ const res = await postEmail(from, to, "E2E both paths test", "Both paths")expect(res.status).toBe(200)const row = await waitForEmail(seed.agentId, from)diff --git a/src/web/src/test/helpers/auth.ts b/src/web/src/test/helpers/auth.tsindex b8e24e193..eaf4b9cea 100644--- a/src/web/src/test/helpers/auth.ts+++ b/src/web/src/test/helpers/auth.ts@@ -1,24 +1,6 @@-const APP_URL = process.env.APP_URL ?? "http://localhost:3000"-const MAX_RETRIES = 3-const RETRY_DELAY_MS = 300+import { fetchWithRetry } from "./fetch"-async function fetchWithRetry(url: string, init: RequestInit): Promise<Response> {- for (let attempt = 1; attempt <= MAX_RETRIES; attempt++) {- try {- return await fetch(url, init)- } catch (e) {- const isRetryable =- e instanceof TypeError &&- (e.message.includes("fetch failed") || e.message.includes("socket"))- if (attempt < MAX_RETRIES && isRetryable) {- await new Promise((r) => setTimeout(r, RETRY_DELAY_MS * attempt))- continue- }- throw e- }- }- throw new Error("unreachable")-}+const APP_URL = process.env.APP_URL ?? "http://localhost:3000"/*** Sign up a new user via Better Auth.diff --git a/src/web/src/test/helpers/db.ts b/src/web/src/test/helpers/db.tsindex de1d18d30..00d7c4cfc 100644--- a/src/web/src/test/helpers/db.ts+++ b/src/web/src/test/helpers/db.ts@@ -1,5 +1,9 @@import { execSync } from "child_process"import { resolve } from "path"+import { writeFileSync, unlinkSync } from "fs"+import { tmpdir } from "os"+import { join } from "path"+import { randomUUID } from "crypto"const WEB_DIR = resolve(import.meta.dirname, "../../..")const MAX_RETRIES = 3@@ -42,3 +46,16 @@ export function sqlQuery<T = Record<string, unknown>>(query: string): T[] {const parsed = JSON.parse(raw)return parsed[0]?.results ?? []}++/**+ * Execute multiple SQL statements in a single wrangler invocation via --file.+ */+export function sqlBatch(queries: string[]): void {+ const file = join(tmpdir(), `e2e-batch-${randomUUID()}.sql`)+ try {+ writeFileSync(file, queries.join(";\n") + ";")+ execWithRetry(`npx wrangler d1 execute alook-app --local --file "${file}"`)+ } finally {+ try { unlinkSync(file) } catch {}+ }+}diff --git a/src/web/src/test/helpers/email.ts b/src/web/src/test/helpers/email.tsnew file mode 100644index 000000000..5a485ee21--- /dev/null+++ b/src/web/src/test/helpers/email.ts@@ -0,0 +1,58 @@+import { randomUUID } from "crypto"+import { fetchWithRetry } from "./fetch"++const EMAIL_WORKER_URL = process.env.EMAIL_WORKER_URL ?? "http://localhost:8787"++export function rawEmail(from: string, to: string, subject: string, body: string): string {+ const msgId = `<${randomUUID()}@e2e.test>`+ return [+ `From: ${from}`,+ `To: ${to}`,+ `Subject: ${subject}`,+ `Message-ID: ${msgId}`,+ `Date: ${new Date().toUTCString()}`,+ `MIME-Version: 1.0`,+ `Content-Type: text/plain; charset=utf-8`,+ "",+ body,+ ].join("\r\n")+}++export function rawEmailWithHeaders(+ from: string,+ to: string,+ subject: string,+ body: string,+ headers: Record<string, string>,+): string {+ const lines = [+ `From: ${from}`,+ `To: ${to}`,+ `Subject: ${subject}`,+ ...Object.entries(headers).map(([k, v]) => `${k}: ${v}`),+ `Date: ${new Date().toUTCString()}`,+ `MIME-Version: 1.0`,+ `Content-Type: text/plain; charset=utf-8`,+ "",+ body,+ ]+ return lines.join("\r\n")+}++export async function postEmail(from: string, to: string, subject: string, body: string): Promise<Response> {+ const url = `${EMAIL_WORKER_URL}/cdn-cgi/handler/email?from=${encodeURIComponent(from)}&to=${encodeURIComponent(to)}`+ return fetchWithRetry(url, {+ method: "POST",+ headers: { "Content-Type": "application/json" },+ body: rawEmail(from, to, subject, body),+ })+}++export async function postEmailRaw(from: string, to: string, rawBody: string): Promise<Response> {+ const url = `${EMAIL_WORKER_URL}/cdn-cgi/handler/email?from=${encodeURIComponent(from)}&to=${encodeURIComponent(to)}`+ return fetchWithRetry(url, {+ method: "POST",+ headers: { "Content-Type": "application/json" },+ body: rawBody,+ })+}diff --git a/src/web/src/test/helpers/fetch.test.ts b/src/web/src/test/helpers/fetch.test.tsnew file mode 100644index 000000000..0746e99cf--- /dev/null+++ b/src/web/src/test/helpers/fetch.test.ts@@ -0,0 +1,95 @@+import { describe, it, expect, vi } from "vitest"+import { isRetryableError, fetchWithRetry } from "./fetch"++describe("isRetryableError", () => {+ it("detects ECONNRESET on err.cause (Node.js fetch wrapper)", () => {+ const inner = new Error("read ECONNRESET") as NodeJS.ErrnoException+ inner.code = "ECONNRESET"+ inner.errno = -54+ inner.syscall = "read"+ const outer = new TypeError("fetch failed", { cause: inner })+ expect(isRetryableError(outer)).toBe(true)+ })++ it("detects ECONNRESET directly on err.code", () => {+ const err = new Error("read ECONNRESET") as NodeJS.ErrnoException+ err.code = "ECONNRESET"+ expect(isRetryableError(err)).toBe(true)+ })++ it("detects TypeError with 'fetch failed' message", () => {+ expect(isRetryableError(new TypeError("fetch failed"))).toBe(true)+ })++ it("rejects plain Error without retryable indicators", () => {+ expect(isRetryableError(new Error("something else"))).toBe(false)+ })++ it("rejects non-Error values", () => {+ expect(isRetryableError("string error")).toBe(false)+ expect(isRetryableError(null)).toBe(false)+ expect(isRetryableError(42)).toBe(false)+ })++ it("rejects TypeError with non-fetch message", () => {+ expect(isRetryableError(new TypeError("Cannot read property"))).toBe(false)+ })+})++describe("fetchWithRetry", () => {+ it("returns response on first success", async () => {+ const mockResponse = new Response("ok", { status: 200 })+ const mockFetch = vi.spyOn(globalThis, "fetch").mockResolvedValueOnce(mockResponse)++ const res = await fetchWithRetry("http://test", { method: "GET" })+ expect(res).toBe(mockResponse)+ expect(mockFetch).toHaveBeenCalledTimes(1)++ mockFetch.mockRestore()+ })++ it("retries on ECONNRESET then succeeds", async () => {+ const inner = new Error("read ECONNRESET") as NodeJS.ErrnoException+ inner.code = "ECONNRESET"+ const econnErr = new TypeError("fetch failed", { cause: inner })+ const mockResponse = new Response("ok", { status: 200 })++ const mockFetch = vi.spyOn(globalThis, "fetch")+ .mockRejectedValueOnce(econnErr)+ .mockResolvedValueOnce(mockResponse)++ const res = await fetchWithRetry("http://test", { method: "GET" })+ expect(res).toBe(mockResponse)+ expect(mockFetch).toHaveBeenCalledTimes(2)++ mockFetch.mockRestore()+ })++ it("throws after max retries exhausted", async () => {+ const makeErr = () => {+ const inner = new Error("read ECONNRESET") as NodeJS.ErrnoException+ inner.code = "ECONNRESET"+ return new TypeError("fetch failed", { cause: inner })+ }++ const mockFetch = vi.spyOn(globalThis, "fetch")+ .mockRejectedValueOnce(makeErr())+ .mockRejectedValueOnce(makeErr())+ .mockRejectedValueOnce(makeErr())++ await expect(fetchWithRetry("http://test", { method: "GET" })).rejects.toThrow("fetch failed")+ expect(mockFetch).toHaveBeenCalledTimes(3)++ mockFetch.mockRestore()+ })++ it("throws immediately on non-retryable error", async () => {+ const mockFetch = vi.spyOn(globalThis, "fetch")+ .mockRejectedValueOnce(new Error("DNS resolution failed"))++ await expect(fetchWithRetry("http://test", { method: "GET" })).rejects.toThrow("DNS resolution failed")+ expect(mockFetch).toHaveBeenCalledTimes(1)++ mockFetch.mockRestore()+ })+})diff --git a/src/web/src/test/helpers/fetch.ts b/src/web/src/test/helpers/fetch.tsnew file mode 100644index 000000000..9674df1ba--- /dev/null+++ b/src/web/src/test/helpers/fetch.ts@@ -0,0 +1,30 @@+const MAX_RETRIES = 3+const BASE_DELAY_MS = 300++export function isRetryableError(err: unknown): boolean {+ if (!(err instanceof Error)) return false++ if ((err as NodeJS.ErrnoException).code === "ECONNRESET") return true++ const cause = (err as Error & { cause?: Error }).cause+ if (cause && (cause as NodeJS.ErrnoException).code === "ECONNRESET") return true++ if (err instanceof TypeError && err.message.includes("fetch failed")) return true++ return false+}++export async function fetchWithRetry(url: string, init: RequestInit): Promise<Response> {+ for (let attempt = 1; attempt <= MAX_RETRIES; attempt++) {+ try {+ return await fetch(url, init)+ } catch (err: unknown) {+ if (attempt < MAX_RETRIES && isRetryableError(err)) {+ await new Promise((r) => setTimeout(r, BASE_DELAY_MS * attempt))+ continue+ }+ throw err+ }+ }+ throw new Error("unreachable")+}diff --git a/src/web/src/test/helpers/seed.ts b/src/web/src/test/helpers/seed.tsindex d5bccca82..e7b5c626d 100644--- a/src/web/src/test/helpers/seed.ts+++ b/src/web/src/test/helpers/seed.ts@@ -1,5 +1,5 @@import { randomUUID } from "crypto"-import { sql } from "./db"+import { sql, sqlBatch } from "./db"export interface TestSeed {userId: string@@ -54,24 +54,25 @@ export function seedTestData(): TestSeed {* Clean up all test data created by seedTestData.*/export function cleanupTestData(seed: TestSeed) {- // Delete in reverse dependency order, cleaning up all data in the workspaceconst ws = seed.workspaceId- sql(`DELETE FROM task_message WHERE task_id IN (SELECT id FROM agent_task_queue WHERE workspace_id = '${ws}')`)- sql(`DELETE FROM agent_task_queue WHERE workspace_id = '${ws}'`)- sql(`DELETE FROM message WHERE conversation_id IN (SELECT id FROM conversation WHERE workspace_id = '${ws}')`)- sql(`DELETE FROM conversation WHERE workspace_id = '${ws}'`)- sql(`DELETE FROM emails WHERE agent_id IN (SELECT id FROM agent WHERE workspace_id = '${ws}')`)- sql(`DELETE FROM agent_whitelist WHERE agent_id IN (SELECT id FROM agent WHERE workspace_id = '${ws}')`)- sql(`DELETE FROM agent_access WHERE workspace_id = '${ws}'`)- sql(`DELETE FROM agent_pin WHERE workspace_id = '${ws}'`)- sql(`DELETE FROM workspace_invite WHERE workspace_id = '${ws}'`)- sql(`DELETE FROM agent WHERE workspace_id = '${ws}'`)- sql(`DELETE FROM agent_runtime WHERE workspace_id = '${ws}'`)- sql(`DELETE FROM machine WHERE workspace_id = '${ws}'`)- sql(`DELETE FROM machine_token WHERE workspace_id = '${ws}'`)- sql(`DELETE FROM member WHERE workspace_id = '${ws}'`)- sql(`DELETE FROM workspace WHERE id = '${ws}'`)- sql(`DELETE FROM "user" WHERE id = '${seed.userId}'`)+ sqlBatch([+ `DELETE FROM task_message WHERE task_id IN (SELECT id FROM agent_task_queue WHERE workspace_id = '${ws}')`,+ `DELETE FROM agent_task_queue WHERE workspace_id = '${ws}'`,+ `DELETE FROM message WHERE conversation_id IN (SELECT id FROM conversation WHERE workspace_id = '${ws}')`,+ `DELETE FROM conversation WHERE workspace_id = '${ws}'`,+ `DELETE FROM emails WHERE agent_id IN (SELECT id FROM agent WHERE workspace_id = '${ws}')`,+ `DELETE FROM agent_whitelist WHERE agent_id IN (SELECT id FROM agent WHERE workspace_id = '${ws}')`,+ `DELETE FROM agent_access WHERE workspace_id = '${ws}'`,+ `DELETE FROM agent_pin WHERE workspace_id = '${ws}'`,+ `DELETE FROM workspace_invite WHERE workspace_id = '${ws}'`,+ `DELETE FROM agent WHERE workspace_id = '${ws}'`,+ `DELETE FROM agent_runtime WHERE workspace_id = '${ws}'`,+ `DELETE FROM machine WHERE workspace_id = '${ws}'`,+ `DELETE FROM machine_token WHERE workspace_id = '${ws}'`,+ `DELETE FROM member WHERE workspace_id = '${ws}'`,+ `DELETE FROM workspace WHERE id = '${ws}'`,+ `DELETE FROM "user" WHERE id = '${seed.userId}'`,+ ])}export interface SecondaryUser {