Skip to content

Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.

fix(hosted-team): a pasted code for an approved team arms the waiting notice (D3)

review272ed1492567
diff --git a/src/renderer/lib/hostedJoin.test.ts b/src/renderer/lib/hostedJoin.test.ts
index d405625c3..0302e2295 100644
--- a/src/renderer/lib/hostedJoin.test.ts
+++ b/src/renderer/lib/hostedJoin.test.ts
@@ -580,6 +580,44 @@ describe('hosted joiner', () => {
expect(h.notices).toEqual([{ kind: 'info', text: 'Waiting for an owner of box to approve this device…', sticky: true }])
})
+ it('D3: a PASTED code for a team this device already has an approved bookmark for arms the notice too', async () => {
+ // Main auto-confirms such a join (the bookmark's approval, for the same host key), so no SAS
+ // prompt comes and no `sasConfirmed` ever fires: the clock must start when the connect resolves.
+ const h = harness([{ hostId: 'H1', label: 'box', approved: true, code: codeFor('H1') }])
+ const j = createHostedJoiner(h.deps)
+ j.joinWithCode(codeFor('H1', 'box'))
+ h.connects[0].resolve('c0')
+ await flush()
+ const waits = h.timers.filter((t) => t.ms === WAITING_NOTICE_DELAY_MS && !t.cleared)
+ expect(waits).toHaveLength(1)
+ waits[0].cleared = true
+ waits[0].fn()
+ expect(h.notices).toEqual([{ kind: 'info', text: 'Waiting for an owner of box to approve this device…', sticky: true }])
+ })
+
+ it('D3: a pasted code for a bookmark that is NOT approved still waits for the SAS confirm', async () => {
+ const h = harness([{ hostId: 'H1', label: 'box', approved: false, code: codeFor('H1') }])
+ const j = createHostedJoiner(h.deps)
+ j.joinWithCode(codeFor('H1', 'box'))
+ h.connects[0].resolve('c0')
+ await flush()
+ expect(h.timers.filter((t) => t.ms === WAITING_NOTICE_DELAY_MS && !t.cleared)).toEqual([])
+ })
+
+ it('D3: a SAS that shows up before the bookmark lookup answers wins — the lookup does not arm the notice', async () => {
+ const h = harness([{ hostId: 'H1', label: 'box', approved: true, code: codeFor('H1') }])
+ let answer!: (l: Array<{ hostId: string; label: string; approved: boolean; code: string }>) => void
+ ;(h.deps.bookmarks as ReturnType<typeof vi.fn>).mockImplementationOnce(() => new Promise((r) => (answer = r)))
+ const j = createHostedJoiner(h.deps)
+ j.joinWithCode(codeFor('H1', 'box'))
+ h.connects[0].resolve('c0')
+ await flush()
+ h.sasCbs.get('c0')!() // the host asked for a comparison after all
+ answer([{ hostId: 'H1', label: 'box', approved: true, code: codeFor('H1') }])
+ await flush()
+ expect(h.timers.filter((t) => t.ms === WAITING_NOTICE_DELAY_MS && !t.cleared)).toEqual([])
+ })
+
it('R41: a bookmarked reconnect arms it when its connect resolves; a SAS that shows up after all disarms it', async () => {
const h = harness([{ hostId: 'H1', label: 'box', approved: true, code: codeFor('H1') }])
const j = createHostedJoiner(h.deps)
diff --git a/src/renderer/lib/hostedJoin.ts b/src/renderer/lib/hostedJoin.ts
index 5fa7bceeb..a9708fa49 100644
--- a/src/renderer/lib/hostedJoin.ts
+++ b/src/renderer/lib/hostedJoin.ts
@@ -161,14 +161,33 @@ export function createHostedJoiner(deps: HostedJoinerDeps): HostedJoiner {
approved = true
disarm()
})
- const unSas = deps.onSas(connectionId, disarm)
+ let sasSeen = false
+ let settled = false
+ const unSas = deps.onSas(connectionId, () => {
+ sasSeen = true
+ disarm()
+ })
if (req.autoConfirm) arm()
+ else {
+ // A PASTED code for a team this device holds an APPROVED bookmark for: main confirms that
+ // join on its own (the bookmark's approval, for the same host key — a hostId derives from
+ // it), so no SAS prompt comes and `sasConfirmed` never fires. Arm when the lookup answers —
+ // unless a SAS showed up first (the host asked for a comparison after all) or the mount has
+ // already settled.
+ void deps.bookmarks().then(
+ (list) => {
+ if (!settled && !sasSeen && list.some((b) => b.hostId === req.hostId && b.approved)) arm()
+ },
+ () => {}
+ )
+ }
let outcome: HostedMountOutcome
try {
outcome = await deps.mount(connectionId, req, { sasConfirmed: arm })
} catch (error) {
outcome = { error, declined: false }
} finally {
+ settled = true
unApproved()
unSas()
disarm()