Skip to content

Autonomous development for real products. Governed agents build from specs you approve, follow the rules you set, and nothing merges until another agent proves it. Your decisions, judgement and taste are the bar that work must clear. Declare your vision and let agents build it.

fix: show pending phone link approvals in browser [H5]

Corey Olson8670d21e4b8f
diff --git a/relay/browser-client.js b/relay/browser-client.js
index 891d73a4..063b8790 100644
--- a/relay/browser-client.js
+++ b/relay/browser-client.js
@@ -110,6 +110,8 @@ export async function createTransport({ onUpdate = () => {}, onOpenBoard = () =>
let browserPaired = false;
let waitingBoards = new Map();
const approvedBoards = new Set();
+ let pendingLinks = [];
+ let pendingLinksFailure = '';
let warnings = [];
let failure = '';
let failureBoard = null;
@@ -161,7 +163,7 @@ export async function createTransport({ onUpdate = () => {}, onOpenBoard = () =>
entry.key = null;
}
paired.clear();
- available = []; waitingBoards.clear(); warnings = []; pair = null;
+ available = []; waitingBoards.clear(); pendingLinks = []; pendingLinksFailure = ''; warnings = []; pair = null;
for (const id of Object.keys(keys)) delete keys[id];
document.querySelector('main')?.replaceChildren();
if (error?.code !== 'DEVICE_REVOKED') { location.replace('/'); return; }
@@ -196,7 +198,8 @@ export async function createTransport({ onUpdate = () => {}, onOpenBoard = () =>
try { state = storedOwnedRequestState(localStorage, key, entry.state?.personRequests); } catch { /* Missing device storage can only hide this device's own notice. */ }
ownedRequestIds.set(id, state.owned);
}
- const lines = noticeLines({ available, paired, ownedRequestIds, waitingBoards, approvedBoards, warnings, failure });
+ const lines = noticeLines({ available, paired, ownedRequestIds, waitingBoards, approvedBoards, pendingLinks, warnings,
+ failure: failure || pendingLinksFailure });
for (const text of lines) {
const paragraph = document.createElement('p');
paragraph.textContent = text;
@@ -480,6 +483,16 @@ export async function createTransport({ onUpdate = () => {}, onOpenBoard = () =>
async function listing() {
const document = await documentAt('/api/v1/boards', denied);
if (accessLost) throw accessError;
+ pendingLinks = [];
+ pendingLinksFailure = '';
+ try {
+ const pending = await documentAt('/api/v1/devices/approvals', denied);
+ pendingLinks = Array.isArray(pending.links) ? pending.links.filter(link => typeof link?.name === 'string' && link.name.trim()) : [];
+ } catch {
+ if (accessLost) throw accessError;
+ pendingLinksFailure = 'Phone approval status could not be checked. Refresh to retry.';
+ }
+ if (accessLost) throw accessError;
const device = await deviceBoardKeyState((path, options) => documentAt(path, denied, options));
if (accessLost) throw accessError;
Object.assign(keys, stored(localStorage, KEYS, {}), device.keys);
diff --git a/relay/browser-notice.js b/relay/browser-notice.js
index d05664c7..7750b233 100644
--- a/relay/browser-notice.js
+++ b/relay/browser-notice.js
@@ -32,13 +32,14 @@ export function storedOwnedRequestState(storage, key, requests) {
}
/** Build truthful device notices from authorized boards and their decrypted pending requests. */
-export function noticeLines({ available, paired, ownedRequestIds = new Map(), waitingBoards = new Map(), approvedBoards = new Set(), warnings = [], failure = '' }) {
+export function noticeLines({ available, paired, ownedRequestIds = new Map(), waitingBoards = new Map(), approvedBoards = new Set(), pendingLinks = [], warnings = [], failure = '' }) {
const lines = [];
const waiting = [...paired.entries()].reduce((count, [id, entry]) => {
const owned = ownedRequestIds.get(id) ?? new Set();
return count + reconcileOwnedRequests(entry.state?.personRequests, owned).waiting.length;
}, 0);
if (waiting) lines.push(`${waiting} request${waiting === 1 ? '' : 's'} from this device ${waiting === 1 ? 'is' : 'are'} waiting for a linked machine to run Pullboard.`);
+ for (const link of pendingLinks) if (typeof link?.name === 'string') lines.push(`${link.name}: waiting for approval on your phone.`);
const pairedRepositories = new Set(available.filter(board => paired.has(board.id)).map(board => board.repository));
for (const board of available.filter(value => !paired.has(value.id))) {
// This phone just approved the link: its key is on the way, so asking to pair would be wrong.
diff --git a/relay/device-http.js b/relay/device-http.js
index 8c2faa08..1c597003 100644
--- a/relay/device-http.js
+++ b/relay/device-http.js
@@ -30,6 +30,10 @@ export function createDeviceHandler({ authenticate, authorizeBoard, boardsFor, d
if (context.account !== account || context.publisher !== who.board || context.machine !== who.machine) throw new Refused('TOKEN_BOARD', 'publish approval only for this authenticated machine and board');
apiJson(res, 200, { approval: devices.requestApproval(account, context, body.sealed) }); return true;
}
+ if (url.pathname === '/api/v1/devices/approvals' && req.method === 'GET') {
+ if (who.kind !== 'session') throw new Refused('HUMAN_REQUIRED', 'sign in as the person to see pending phone approvals');
+ apiJson(res, 200, { links: devices.pendingLinks(account) }); return true;
+ }
const approvalRoute = /^\/api\/v1\/devices\/approvals\/([A-Za-z0-9_-]{1,80})(?:\/(authorize|complete|execute))?$/.exec(url.pathname);
if (approvalRoute) {
if (!['session', 'machine'].includes(who.kind)) throw new Refused('HUMAN_REQUIRED', 'use the phone session or the publishing machine for this approval');
diff --git a/relay/device-store.js b/relay/device-store.js
index d2797e1b..90af8e52 100644
--- a/relay/device-store.js
+++ b/relay/device-store.js
@@ -105,6 +105,12 @@ export function createDeviceStore({ directory, now = Date.now }) {
expireApprovals();
return database().prepare("SELECT * FROM phone_approval WHERE account=? AND device=? AND state='waiting' ORDER BY expires,id").all(account, device).map(approval);
},
+ /** List only the names of unexpired link requests for their signed-in account, never sealed intent. */
+ pendingLinks(account) {
+ expireApprovals();
+ return database().prepare("SELECT context FROM phone_approval WHERE account=? AND action='link' AND state='waiting' ORDER BY expires,id")
+ .all(account).map(row => ({ name: approvalContext(JSON.parse(row.context)).target }));
+ },
/** Persist only the phone-encrypted reply, rejecting expired or twice-completed approval. */
completeApproval(account, id, response) {
if (typeof response !== 'string' || !/^[A-Za-z0-9_-]{1,32000}$/u.test(response)) throw new Refused('PHONE_APPROVAL_CONTEXT', 'send the encrypted phone reply');
diff --git a/test/hosted-shapes.test.js b/test/hosted-shapes.test.js
index 359cb6cf..9259627e 100644
--- a/test/hosted-shapes.test.js
+++ b/test/hosted-shapes.test.js
@@ -912,15 +912,6 @@ const CAUSES = [
'webkit:phone/signed-in/unpaired/oversize/stale-key',
],
},
- {
- item: 985,
- cause: "a paired browser shows the healthy board but never mentions the board waiting for a phone approval",
- cells: [
- 'chromium:board-no-view/signed-in/paired/approval/fresh',
- 'chromium:other-computer/signed-in/paired/approval/fresh',
- 'chromium:phone/signed-in/paired/approval/fresh',
- ],
- },
];
/** The filed defect that covers one failing cell, or undefined. */
@@ -1067,6 +1058,24 @@ async function runCells(engine, built, boardCells, report, ineffective) {
return failures;
}
+test('a board awaiting a phone approval is mentioned on a non-phone paired browser [H5]', {
+ timeout: 180_000,
+}, async (t) => {
+ if (!hostedEngines().some((engine) => engine.name === 'chromium' && engine.available)) return t.skip('Chrome is not installed; set PULLBOARD_CHROME');
+ const engine = await openEngine('chromium');
+ t.after(() => engine.close());
+ const built = await buildBoards(t, 'approval', [engine]);
+ const keys = Object.fromEntries(built.linked.map(({ id, key }) => [id, key]));
+ const boards = built.linked.map(({ id }) => id);
+ const context = await engine.newContext();
+ t.after(() => context.close());
+ const seen = await visit(context, {
+ route: built.front.route(built.pairedSession, null), phone: false,
+ bootstrap: storedScript('fresh', { keys, boards }),
+ }, true);
+ assert.equal(judge({ where: 'other-computer', account: 'signed-in', browser: 'paired', boards: 'approval', stored: 'fresh' }, seen), null, seen.words);
+});
+
test('every listed cause is a filed item covering real cells, each cell once [H5,C7]', () => {
const all = new Set(cells().flatMap((cell) => ['chromium', 'webkit'].map((engine) => `${engine}:${cell.id}`)));
const seen = new Set();
diff --git a/test/relay-device-http.test.js b/test/relay-device-http.test.js
index 2a1dce3a..4ae4e353 100644
--- a/test/relay-device-http.test.js
+++ b/test/relay-device-http.test.js
@@ -8,9 +8,12 @@ import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { test } from 'node:test';
import { createAuthHandler } from '../relay/auth-http.js';
+import { createDeviceHandler } from '../relay/device-http.js';
+import { createDeviceStore } from '../relay/device-store.js';
import { createGitHubClient } from '../relay/github.js';
import { createRelayAuth } from '../relay/auth.js';
import { createRelayHandler } from '../relay/service.js';
+import { Refused } from '../src/refused.js';
import { ENGINE_VERSION } from '../src/machine.js';
import {
authenticateDeviceEnrollment,
@@ -239,3 +242,58 @@ test('relay devices isolate accounts, persist opaque wraps, expire enrollments a
});
assert.equal(oldId.document.error?.code, 'DEVICE_REVOKED', 'a fresh sign-in does not resurrect the tombstoned device id');
});
+
+test('pending phone link names are session-scoped and exclude used or expired approvals [H5,H15,H17]', async (t) => {
+ const root = mkdtempSync(join(tmpdir(), 'pullboard-device-approvals-'));
+ let now = 1_800_000_000_000;
+ const devices = createDeviceStore({ directory: root, now: () => now });
+ const account = '7';
+ const other = '8';
+ const device = 'device-' + 'a'.repeat(32);
+ const publisher = 'b'.repeat(32);
+ devices.register(account, device);
+ devices.register(other, device);
+ /** Make one valid pending phone action with an independently selected account and board. */
+ const context = (id, owner, board, action, target, expires) => ({ id, account: owner, publisher, board, device, action, target,
+ machine: 'machine-one', command: 'pullboard relay on --all', expires });
+ /** Store an encrypted request through the same approval validation used by the relay endpoint. */
+ const add = (value) => devices.requestApproval(value.account, value, 'sealed-intent');
+ add(context('live-link', account, 'c'.repeat(32), 'link', 'fixture/live', now + 60_000));
+ add(context('other-link', other, 'd'.repeat(32), 'link', 'fixture/private', now + 60_000));
+ add(context('used-link', account, 'e'.repeat(32), 'link', 'fixture/used', now + 30_000));
+ devices.completeApproval(account, 'used-link', 'phone-response');
+ add(context('expired-link', account, 'f'.repeat(32), 'link', 'fixture/expired', now + 1));
+ add(context('live-revoke', account, publisher, 'revoke-device', device, now + 60_000));
+ now += 2;
+
+ const server = createServer(createDeviceHandler({
+ authenticate: async (req) => {
+ const cookie = req.headers.cookie;
+ if (cookie === 'revoked=1') throw new Refused('DEVICE_REVOKED', 'revoked');
+ return { kind: cookie === 'machine=1' ? 'machine' : 'session', user: { id: cookie === 'other=1' ? other : account } };
+ },
+ authorizeBoard: async () => {}, boardsFor: async () => [], devices,
+ linkBoard: async () => {}, issueMachine: async () => {}, issueActionGrant: async () => {},
+ consumeActionGrant: async () => {}, revokeToken: async () => {}, deleteBoard: async () => {},
+ }));
+ server.listen(0, '127.0.0.1');
+ await once(server, 'listening');
+ t.after(() => { server.closeAllConnections(); server.close(); devices.close?.(); rmSync(root, { recursive: true, force: true }); });
+ const origin = `http://127.0.0.1:${server.address().port}`;
+ /** Read the public pending-link endpoint as a chosen authenticated principal. */
+ const get = async (cookie) => {
+ const response = await fetch(origin + '/api/v1/devices/approvals', { headers: { cookie } });
+ return { response, document: await response.json() };
+ };
+
+ const own = await get('owner=1');
+ assert.deepEqual(own.document.links, [{ name: 'fixture/live' }], 'only live link-request names leave the account boundary');
+ assert.equal(own.document.links[0].sealed, undefined, 'the browser never receives the sealed intent');
+ assert.deepEqual((await get('other=1')).document.links, [{ name: 'fixture/private' }], 'another signed-in account sees only its own request');
+ const machine = await get('machine=1');
+ assert.equal(machine.response.status, 403);
+ assert.equal(machine.document.error?.code, 'HUMAN_REQUIRED');
+ const revoked = await get('revoked=1');
+ assert.equal(revoked.response.status, 403);
+ assert.equal(revoked.document.error?.code, 'DEVICE_REVOKED');
+});