fix(cloud): GH-SOLO a teammate whose grant is still being revoked keeps the workspace from being solo

This commit is contained in:
Neil
2026-11-16 01:01:02 -08:00
parent ce48b4769f
commit 3aa45164f0
2 changed files with 16 additions and 2 deletions
+3 -2
View File
@@ -85,11 +85,12 @@ export async function actingMember(db: D1Database, row: SandboxRow, now: number,
/**
* GH-SOLO: the one person who can use this workspace, or null. From the people set itself (active grantees, plus
* the untransferred owner, who may have no grant row: the create's own pairing code), never from "no expiry".
* Someone else's grant still being issued (their device may be pairing) means not solo.
* Someone else's grant still being issued or revoked (their device may be pairing, or not yet unpaired) means not
* solo.
*/
export async function soloMember(db: D1Database, row: SandboxRow): Promise<string | null> {
const { results } = await db
.prepare(`SELECT DISTINCT user_id, status FROM workspace_grants WHERE sandbox_id = ? AND status IN ('issuing', 'active')`)
.prepare(`SELECT DISTINCT user_id, status FROM workspace_grants WHERE sandbox_id = ? AND status IN ('issuing', 'active', 'revoking')`)
.bind(row.id)
.all<{ user_id: string; status: string }>()
const pick = pickActing(
@@ -132,4 +132,17 @@ describe('the control plane marks a workspace solo only while one person can use
expect(write).toBeGreaterThanOrEqual(0)
expect(drop).toBeGreaterThan(write)
})
it('a teammate whose grant is still being revoked (device not yet unpaired) keeps it from being solo', async () => {
const t = await workspace()
await t.connect('alice', 11)
t.h.raw
.prepare(`INSERT INTO workspace_grants (id, sandbox_id, account_id, user_id, device_kind, device_label, status, created_at) VALUES ('grt_out', ?, 'org:acme', 'bob', 'desktop', 'b', 'revoking', 1)`)
.run(t.id)
const row = (await getSandbox(t.h.env.SANDBOX_DB, t.id))!
expect(await soloMember(t.h.env.SANDBOX_DB, row)).toBeNull()
t.h.raw.prepare(`UPDATE workspace_grants SET status = 'revoked' WHERE id = 'grt_out'`).run()
expect(await soloMember(t.h.env.SANDBOX_DB, row)).toBe('alice')
})
})