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(relay): recover lost-phone revocation [H17]

Corey Olsonb5bf4e3f6323
diff --git a/docs/api.md b/docs/api.md
index 282435fa..111cc638 100644
--- a/docs/api.md
+++ b/docs/api.md
@@ -187,7 +187,7 @@ Only the coordinator sets or edits an item's `--check`. `pullboard check [id]` p
`relay on --all [--url <address>]` returns `{version, linked: [{project, root, board}], failed: [{project, root, reason}], paired, autoLink: true}`. Its status is nonzero when a project failed; successful links remain available. With no paired phone, the command prints one tappable pairing link and QR, then waits in the foreground up to ten minutes. Interruption or expiration leaves completed links intact and exits zero when no link failed. Every explicit invocation signs in afresh; no person session is retained on the Mac. Later project registrations publish one sealed phone-link proposal and keep working locally until its single approval tap. `doctor` and `resume` name the waiting project and its expiry; expiration requires an explicit fresh sign-in rather than silently asking again. `relay off` excludes that project from automatic linking; explicit `relay on` clears the exclusion.
-`relay devices` returns `{version, devices: [{deviceId, label, fingerprint, createdAt}]}` without a private key or credential. `relay revoke <deviceId>` returns `{version, deviceId, revoked: true, notice}` after removing the local recipient and deleting its remote wraps. Native revocation waits for one tap on the paired phone and uses a short-lived, single-use, RAM-only grant for that exact device. A failed or interrupted approval needs an explicit retry. Revocation stops future wrapping; it cannot erase board keys already received.
+`relay devices` returns `{version, devices: [{deviceId, label, fingerprint, createdAt}]}` without a private key or credential. `relay revoke <deviceId>` returns `{version, deviceId, revoked: true, notice}` after removing the local recipient and deleting its remote wraps. Native revocation never asks the target device to approve its own removal. Another paired phone can approve it with a short-lived, single-use, RAM-only grant for that exact target. With no other paired approver or no linked publishing board, the person completes a fresh GitHub device-code sign-in on the computer instead. The authenticated account and relay origin must match the saved enrollment; the fresh session stays in memory and is revoked after the action. Agent terminals are refused before any sign-in or network request. A failed or interrupted approval or sign-in needs an explicit retry. Revocation stops future wrapping; it cannot erase board keys already received.
Phone enrollment uses a one-use `#device=<locator>.<secret>` fragment, removed before sign-in. The secret remains on the phone and Mac. Person-authenticated `/api/v1/devices/session` returns the current account id. `/api/v1/devices/enrollments/:locator` supports POST `{}` to start a ten-minute locator, PUT of the exact public enrollment and MAC, GET of `{version, enrollment}` and DELETE to consume it. A native Mac checks the MAC locally before retaining any recipient. `/api/v1/devices/:deviceId` supports POST `{}` to record an authenticated recipient and DELETE to revoke it. PUT `/api/v1/devices/:deviceId/boards/:boardId` stores `{engine, wrapped}`; GET `/api/v1/devices/:deviceId/boards` returns `{version, wraps: [{board, engine, wrapped}]}` filtered by current board access. `wrapped` is opaque base64url client ciphertext. Enrollment, device listing and direct revocation require a person session. A board-scoped machine credential can PUT only its own board wrap to an already enrolled device. Cookie writes require the exact configured Origin, and all responses are no-store. Device ids and grants belong to the authenticated GitHub account. Revoked ids cannot be registered or uploaded again.
diff --git a/src/help.js b/src/help.js
index ce71173b..0aef3dda 100644
--- a/src/help.js
+++ b/src/help.js
@@ -44,6 +44,7 @@ Set up
keep this command open until pairing finishes; later projects link on registration
pullboard relay devices list paired device ids and their public-key fingerprints
pullboard relay revoke <device> stop future key delivery; already received keys remain known
+ approve on another paired phone, or sign in again with GitHub
pullboard relay tokens list this board's agent token ids, agents and expiry, never credentials
pullboard relay revoke <token-id> revoke one token from that list; other agents keep working
pullboard relay recover --skip <sequence> person-only recovery of one blocked next relay position
diff --git a/src/relay-phone.js b/src/relay-phone.js
index 79d42250..963ccecc 100644
--- a/src/relay-phone.js
+++ b/src/relay-phone.js
@@ -7,8 +7,8 @@ import { requirePersonChannel } from './person.js';
import { Refused } from './refused.js';
/** Select only a phone whose public key was MAC-authenticated into this native machine's roster. */
-export function approvalPhone(state) {
- const device = readRelayMachine().devices.find(entry => entry.account === state.account && entry.url === state.url);
+export function approvalPhone(state, { exclude } = {}) {
+ const device = readRelayMachine().devices.find(entry => entry.account === state.account && entry.url === state.url && entry.deviceId !== exclude);
if (!device) throw new Refused('PHONE_NOT_PAIRED', 'Pair the phone with pullboard relay on --all before requesting this action.');
return device;
}
@@ -16,7 +16,7 @@ export function approvalPhone(state) {
/** Build a sealed immutable proposal; only new-board link replies can have a durable private key. */
export async function phoneProposal(state, action, target, { board = state.board, command, link = false } = {}) {
if (!/^pm_[A-Za-z0-9_-]{43}$/u.test(state.token ?? '')) throw new Refused('RELAY_SESSION', 'Run pullboard relay on --all to replace the old person session with board machine credentials.');
- const phone = approvalPhone(state);
+ const phone = approvalPhone(state, { exclude: action === 'revoke-device' ? target : undefined });
const reply = await createApprovalReply({ link });
const context = approvalContext({ id: randomUUID(), account: state.account, publisher: state.board, board,
device: phone.deviceId, action, target, machine: state.machine,
diff --git a/src/relay-setup.js b/src/relay-setup.js
index ef931dbf..f731b986 100644
--- a/src/relay-setup.js
+++ b/src/relay-setup.js
@@ -88,18 +88,52 @@ async function flushRevocations(session, io) {
}
}
-/** The native device revocation uses the same one-tap grant path as token revocation. */
+/** Recover an unavailable phone using a new provider proof kept only for this foreground action. */
+async function revokeDeviceWithSignIn(device, io) {
+ const controller = new AbortController();
+ /** Cancel the new device flow without retaining a person credential. */
+ const stop = () => controller.abort();
+ process.once('SIGINT', stop); process.once('SIGTERM', stop);
+ let session;
+ try {
+ io.say('Sign in again with GitHub to revoke this device; approval on that device is not needed.');
+ session = await relayMachineSignIn(device.url, io, { signal: controller.signal });
+ if (session.outcome) throw new Refused('DEVICE_REVOKE_CANCELLED',
+ 'GitHub sign-in ' + session.outcome + '; no device was revoked. Run pullboard relay revoke ' + device.deviceId + ' when ready.');
+ if (session.account !== device.account || session.url !== device.url) throw new Refused('DEVICE_ACCOUNT',
+ 'Sign in to the GitHub account that paired this device, then run pullboard relay revoke ' + device.deviceId + ' again.');
+ const reply = await relayDeviceRequest(session, '/api/v1/devices/' + device.deviceId,
+ { method: 'DELETE', signal: controller.signal }, io);
+ if (reply.recorded !== true) throw new Refused('RELAY_RESPONSE',
+ 'The relay did not confirm device revocation; check pullboard relay devices and retry the same revoke command.');
+ updateRelayMachine(state => {
+ state.devices = state.devices.filter(entry => entry.deviceId !== device.deviceId);
+ state.revocations = state.revocations.filter(entry => entry.deviceId !== device.deviceId);
+ });
+ return { deviceId: device.deviceId, revoked: true,
+ notice: 'Revoked device; keys it already received remain known. Board key rotation is separate.' };
+ } finally {
+ process.off('SIGINT', stop); process.off('SIGTERM', stop);
+ if (session?.token) await revokeRelayPersonSession(session, io);
+ }
+}
+
+/** Use another paired phone when available; the device being revoked never approves itself. */
export async function revokeRelayDevice(deviceId, io) {
requirePersonChannel(io.personChannel);
- const device = readRelayMachine().devices.find(entry => entry.deviceId === deviceId);
+ const machine = readRelayMachine();
+ const device = machine.devices.find(entry => entry.deviceId === deviceId);
if (!device) throw new Refused('DEVICE_NOT_ENROLLED', 'Name a paired device from pullboard relay devices.');
- const roots = [io.cwd, ...listApiProjects().map(entry => entry.root)];
- for (const root of roots) {
- let state;
- try { state = relayMachineContext(root); } catch { continue; }
- if (state?.token?.startsWith('pm_') && state.account === device.account && state.url === device.url) return relayRevokeDevice(root, deviceId, io);
+ const otherPhone = machine.devices.some(entry => entry.deviceId !== deviceId && entry.account === device.account && entry.url === device.url);
+ if (otherPhone) {
+ const roots = [io.cwd, ...listApiProjects().map(entry => entry.root)];
+ for (const root of roots) {
+ let state;
+ try { state = relayMachineContext(root); } catch { continue; }
+ if (state?.token?.startsWith('pm_') && state.account === device.account && state.url === device.url) return relayRevokeDevice(root, deviceId, io);
+ }
}
- throw new Refused('RELAY_NOT_LINKED', 'Link a board and pair the phone with pullboard relay on --all.');
+ return revokeDeviceWithSignIn(device, io);
}
/** Link non-excluded registry entries and report an explicit outcome for every registered project. */
diff --git a/test/relay-approval-delivery.test.js b/test/relay-approval-delivery.test.js
index 7004de95..fe6c9e43 100644
--- a/test/relay-approval-delivery.test.js
+++ b/test/relay-approval-delivery.test.js
@@ -5,6 +5,7 @@ import { existsSync, mkdirSync, readFileSync } from 'node:fs';
import { dirname, resolve, join } from 'node:path';
import { test } from 'node:test';
import { relayClientFixture } from './relay-client-fixture.js';
+import { enrollProtocolPhone } from './relay-device-enrollment-fixture.js';
import { findChromeExecutable, startChrome } from './relay-browser-fixture.js';
import { ENGINE_VERSION } from '../src/machine.js';
@@ -370,7 +371,8 @@ test('an approval delivered while the page is busy still becomes a card [H15,H12
'the card is not asserted before actual decryption finishes');
assert.ok((await chrome.evaluate('window.__approvalObservations')).some(poll => poll.ids.includes(render.context.id)),
'the browser received this row before its rendering work completed');
- const renderLater = await startRevocation(box, native, deviceId);
+ const revokedDeviceId = await enrollProtocolPhone(box);
+ const renderLater = await startRevocation(box, native, revokedDeviceId);
assert.equal(await chrome.evaluate(`document.querySelector('#phone-approve-${renderLater.context.id}') === null`), true,
'the second row arrives while the first genuine decrypt is held');
await chrome.evaluate('window.__approvalDecrypt.release()');
@@ -387,7 +389,7 @@ test('an approval delivered while the page is busy still becomes a card [H15,H12
const box = await relayClientFixture(t);
const { chrome, native } = await pairPhone(box, t);
await observeApprovals(chrome);
- const deviceId = JSON.parse(readFileSync(join(box.env.PULLBOARD_HOME, 'relay-machine/state.json'), 'utf8')).devices[0].deviceId;
+ const deviceId = await enrollProtocolPhone(box);
// While one real approval click waits on its authorize response, publish a different action.
const thirdToken = await issueToken(box, 'approval-earlier-action');
const earlier = await startRevocation(box, native, thirdToken.id);
diff --git a/test/relay-device-confirmation.test.js b/test/relay-device-confirmation.test.js
index f25aeef3..bc36691d 100644
--- a/test/relay-device-confirmation.test.js
+++ b/test/relay-device-confirmation.test.js
@@ -2,10 +2,13 @@
import assert from 'node:assert/strict';
import { hostname } from 'node:os';
import { basename } from 'node:path';
+import { join } from 'node:path';
+import { readFileSync } from 'node:fs';
import { test } from 'node:test';
import { DatabaseSync } from 'node:sqlite';
import { relayClientFixture } from './relay-client-fixture.js';
import { findChromeExecutable, startChrome } from './relay-browser-fixture.js';
+import { enrollProtocolPhone } from './relay-device-enrollment-fixture.js';
const CONFIRMATION_PROMPT = 'After sign-in, confirm the link in your browser: ';
const CONFIRMATION_POLL_INTERVAL_MS = 2000;
@@ -116,3 +119,119 @@ test('real Chrome confirms the displayed SSH board intent [P6,H5]', {
test('real Chrome keeps a declined SSH board intent terminal after CLI consumption [P6,H5]', {
skip: !findChromeExecutable() && 'Chrome is not installed',
}, declineTerminalIntent);
+
+/** Wait only for the private command's first management choice, with a finite hang ceiling. */
+async function waitForManagementChoice(box, offset) {
+ const deadline = Date.now() + 20_000; // budget: private request-handshake hang ceiling, not a throughput assertion.
+ while (Date.now() < deadline) {
+ if (box.calls.slice(offset).some(call => call.path === '/auth/device/start' ||
+ call.method === 'POST' && call.path === '/api/v1/devices/approvals')) return;
+ await new Promise(resolve => setTimeout(resolve, 25));
+ }
+ assert.fail('the private command never requested a sign-in or a phone approval');
+}
+
+/** Inspect only counts and public device state, never credential hashes or bearer values. */
+function activeSessionCount(box) {
+ const db = new DatabaseSync(box.authDatabase, { readOnly: true });
+ try { return db.prepare("SELECT COUNT(*) AS count FROM relay_credentials WHERE kind='session' AND revoked=0").get().count; }
+ finally { db.close(); }
+}
+
+/** Read the real relay's public revocation flag for one synthetic fixture device. */
+function deviceRevoked(box, deviceId) {
+ const db = new DatabaseSync(join(box.relayDirectory, 'devices.sqlite'), { readOnly: true });
+ try { return db.prepare('SELECT revoked FROM device WHERE id=?').get(deviceId)?.revoked; }
+ finally { db.close(); }
+}
+
+test('revoking the only approving phone asks for a fresh sign-in instead [H17,E16]', async t => {
+ const box = await relayClientFixture(t);
+ await box.link();
+ const deviceId = await enrollProtocolPhone(box);
+ const machineFile = join(box.env.PULLBOARD_HOME, 'relay-machine/state.json');
+ assert.deepEqual(JSON.parse(readFileSync(machineFile, 'utf8')).devices.map(device => device.deviceId), [deviceId]);
+ assert.equal(deviceRevoked(box, deviceId), 0, 'the private phone is active before revocation');
+ const sessionsBefore = activeSessionCount(box);
+ const offset = box.calls.length;
+ box.providerState.deviceAuthorized = false;
+ const running = box.startCli(['relay', 'revoke', deviceId]);
+ await waitForManagementChoice(box, offset);
+ assert.ok(box.calls.slice(offset).some(call => call.path === '/auth/device/start'),
+ 'the lost phone cannot be the approver: start a fresh GitHub device-code sign-in');
+ await running.waitForOutput('Sign in with GitHub: open ');
+ assert.equal(deviceRevoked(box, deviceId), 0, 'no revocation happens before the fresh sign-in succeeds');
+ assert.equal(box.calls.slice(offset).some(call => call.path === '/api/v1/devices/approvals'), false,
+ 'no approval is sent to the unavailable target phone');
+ box.providerState.deviceAuthorized = true;
+ const result = await running.closed;
+ assert.equal(result.code, 0, 'the person can revoke the only phone after fresh sign-in');
+ assert.equal(JSON.parse(result.stdout).revoked, true);
+ assert.equal(deviceRevoked(box, deviceId), 1, 'the real relay tombstones the device');
+ assert.deepEqual(JSON.parse(readFileSync(machineFile, 'utf8')).devices, [], 'native wrapping no longer trusts the phone');
+ assert.equal(activeSessionCount(box), sessionsBefore, 'the fresh revocation session is revoked instead of retained');
+});
+
+test('an agent cannot revoke a device without the person [H17,E16]', async t => {
+ const box = await relayClientFixture(t);
+ await box.link();
+ const deviceId = await enrollProtocolPhone(box);
+ const offset = box.calls.length;
+ const running = box.startCli(['relay', 'revoke', deviceId], { CODEX_THREAD_ID: 'private-revocation-agent-fixture' });
+ const result = await running.closed;
+ assert.equal(result.code, 1);
+ assert.equal(JSON.parse(result.stdout).error.code, 'B26_PERSON_CHANNEL');
+ assert.equal(box.calls.length, offset, 'the agent cannot start sign-in, request approval, or revoke remotely');
+ assert.equal(deviceRevoked(box, deviceId), 0, 'the real relay device remains active');
+ const machine = JSON.parse(readFileSync(join(box.env.PULLBOARD_HOME, 'relay-machine/state.json'), 'utf8'));
+ assert.deepEqual(machine.devices.map(device => device.deviceId), [deviceId], 'the local roster remains trusted');
+});
+
+
+test('device revocation chooses a different paired approver [H17,E16]', async t => {
+ const box = await relayClientFixture(t);
+ await box.link();
+ const target = await enrollProtocolPhone(box);
+ const other = await enrollProtocolPhone(box);
+ const result = await box.script(`
+ const { relayMachineContext } = await import(${JSON.stringify(new URL('../src/relay.js', import.meta.url).href)});
+ const { phoneProposal } = await import(${JSON.stringify(new URL('../src/relay-phone.js', import.meta.url).href)});
+ const proposal = await phoneProposal(relayMachineContext(process.cwd()), 'revoke-device', ${JSON.stringify(target)});
+ process.stdout.write(JSON.stringify({ approver: proposal.context.device, target: proposal.context.target }));
+ `);
+ assert.equal(result.code, 0);
+ assert.deepEqual(result.document, { approver: other, target }, 'the target cannot approve its own revocation even when it is first in the roster');
+});
+
+test('a fresh sign-in to another account cannot revoke the saved phone [H17,E16]', async t => {
+ const box = await relayClientFixture(t);
+ await box.link();
+ const deviceId = await enrollProtocolPhone(box);
+ const sessionsBefore = activeSessionCount(box);
+ const offset = box.calls.length;
+ box.providerState.accountID = 8;
+ const running = box.startCli(['relay', 'revoke', deviceId]);
+ const result = await running.closed;
+ assert.equal(result.code, 1);
+ assert.equal(JSON.parse(result.stdout).error.code, 'DEVICE_ACCOUNT');
+ assert.equal(box.calls.slice(offset).some(call => call.method === 'DELETE' && call.path === '/api/v1/devices/' + deviceId), false,
+ 'the account mismatch is refused before a device deletion request');
+ assert.equal(deviceRevoked(box, deviceId), 0);
+ assert.equal(activeSessionCount(box), sessionsBefore, 'the mismatched fresh session is also cleaned up');
+ const machine = JSON.parse(readFileSync(join(box.env.PULLBOARD_HOME, 'relay-machine/state.json'), 'utf8'));
+ assert.deepEqual(machine.devices.map(device => device.deviceId), [deviceId]);
+});
+
+test('declining fresh revocation sign-in preserves the paired phone [H17,E16]', async t => {
+ const box = await relayClientFixture(t);
+ await box.link();
+ const deviceId = await enrollProtocolPhone(box);
+ const sessionsBefore = activeSessionCount(box);
+ box.providerState.deviceDeclined = true;
+ const running = box.startCli(['relay', 'revoke', deviceId]);
+ const result = await running.closed;
+ assert.equal(result.code, 1);
+ assert.equal(JSON.parse(result.stdout).error.code, 'DEVICE_REVOKE_CANCELLED');
+ assert.equal(deviceRevoked(box, deviceId), 0);
+ assert.equal(activeSessionCount(box), sessionsBefore);
+});
diff --git a/test/relay-device-enrollment-fixture.js b/test/relay-device-enrollment-fixture.js
new file mode 100644
index 00000000..ded10c0a
--- /dev/null
+++ b/test/relay-device-enrollment-fixture.js
@@ -0,0 +1,36 @@
+/** Pair a private protocol phone through real OAuth, MAC authentication and relay HTTP [H17]. */
+import assert from 'node:assert/strict';
+
+/** Enroll a disposable device without launching Chrome for native management tests. */
+export async function enrollProtocolPhone(box) {
+ const result = await box.script(`
+ const { relayMachineContext, relayMachineSignIn, relayDeviceRequest, revokeRelayPersonSession } = await import(${JSON.stringify(new URL('../src/relay.js', import.meta.url).href)});
+ const { beginDeviceEnrollment, acceptDeviceEnrollment } = await import(${JSON.stringify(new URL('../src/relay-machine.js', import.meta.url).href)});
+ const { createDeviceKeys, signDeviceEnrollment } = await import(${JSON.stringify(new URL('../src/relay-device-keys.js', import.meta.url).href)});
+ const sink = { isTTY: false, write() {} };
+ const io = { cwd: process.cwd(), personChannel: 'terminal', stdout: sink, stderr: sink, say() {}, err() {} };
+ const state = relayMachineContext(process.cwd());
+ const session = await relayMachineSignIn(state.url, io);
+ let deviceId;
+ try {
+ const phone = await createDeviceKeys();
+ const pending = beginDeviceEnrollment(state.board, session);
+ const path = '/api/v1/devices/enrollments/' + pending.locator;
+ await relayDeviceRequest(session, path, { method: 'POST', body: {} }, io);
+ const enrollment = await signDeviceEnrollment(pending.secret, {
+ v: 1, account: session.account, locator: pending.locator, deviceId: phone.deviceId,
+ publicKey: phone.publicKey, label: 'Protocol phone fixture', createdAt: new Date().toISOString(),
+ });
+ await relayDeviceRequest(session, path, { method: 'PUT', body: enrollment }, io);
+ const reply = await relayDeviceRequest(session, path, {}, io);
+ const device = await acceptDeviceEnrollment(reply.enrollment);
+ await relayDeviceRequest(session, '/api/v1/devices/' + device.deviceId, { method: 'POST', body: {} }, io);
+ await relayDeviceRequest(session, path, { method: 'DELETE' }, io);
+ deviceId = device.deviceId;
+ } finally { await revokeRelayPersonSession(session, io); }
+ process.stdout.write(JSON.stringify({ deviceId }));
+ `);
+ assert.equal(result.code, 0, 'the private authenticated protocol enrollment completes');
+ assert.match(result.document.deviceId, /^device-[0-9a-f]{32}$/u);
+ return result.document.deviceId;
+}
diff --git a/test/relay-person-credential.test.js b/test/relay-person-credential.test.js
index 6bb78c1f..7ca983c3 100644
--- a/test/relay-person-credential.test.js
+++ b/test/relay-person-credential.test.js
@@ -7,6 +7,7 @@ import { test } from 'node:test';
import { AGENT_SHELL_MARKERS, SSH_SHELL_MARKERS } from '../src/person.js';
import { ENGINE_VERSION } from '../src/machine.js';
import { relayClientFixture } from './relay-client-fixture.js';
+import { enrollProtocolPhone } from './relay-device-enrollment-fixture.js';
import { findChromeExecutable, startChrome } from './relay-browser-fixture.js';
const CLI = resolve(import.meta.dirname, '../bin/pullboard.js');
@@ -180,7 +181,7 @@ test('same-user agents never act as their person while the phone approves native
assertNoPersonPower(box.root); assertNoPersonPower(box.env.HOME);
});
await t.test('native device revocation needs one phone tap and offline agent unlink always works [H5,H16,H17,B26]', async () => {
- const target = machine.devices[0].deviceId;
+ const target = await enrollProtocolPhone(box);
const revoke = command(box.root, personEnv, ['relay', 'revoke', target]);
t.after(async () => { if (revoke.child.exitCode === null) revoke.child.kill('SIGTERM'); await revoke.done.catch(() => {}); });
await chrome.waitFor("[...document.querySelectorAll('.phone-approval')].some(node => node.textContent.includes(" + JSON.stringify(target) + '))');
@@ -189,6 +190,10 @@ test('same-user agents never act as their person while the phone approves native
await chrome.evaluate("[...document.querySelectorAll('.phone-approval')].find(node => node.textContent.includes(" + JSON.stringify(target) + ')).querySelector("button").click()');
assert.equal((await revoke.done).code, 0);
assert.equal(box.calls.filter(call => call.path.endsWith('/authorize')).length, before + 1);
+ assert.deepEqual(JSON.parse(readFileSync(machineFile)).devices.map(device => device.deviceId), [machine.devices[0].deviceId],
+ 'the approving phone remains paired after it revokes the other target');
+ const lastPhone = await command(box.root, personEnv, ['relay', 'revoke', machine.devices[0].deviceId]).done;
+ assert.equal(lastPhone.code, 0, 'fresh GitHub sign-in removes the last phone without asking it to approve itself');
assert.equal(JSON.parse(readFileSync(machineFile)).devices.length, 0);
await box.stopRelay();
const calls = box.calls.length;
diff --git a/test/relay-setup-once.test.js b/test/relay-setup-once.test.js
index 9f725e6d..5451a99d 100644
--- a/test/relay-setup-once.test.js
+++ b/test/relay-setup-once.test.js
@@ -7,6 +7,7 @@ import { dirname, join, resolve } from 'node:path';
import { test } from 'node:test';
import { createPageStepEvaluator } from './chrome-fixture.js';
import { relayClientFixture } from './relay-client-fixture.js';
+import { enrollProtocolPhone } from './relay-device-enrollment-fixture.js';
import { startChrome, findChromeExecutable } from './relay-browser-fixture.js';
const CLI = resolve(import.meta.dirname, '../bin/pullboard.js');
@@ -342,8 +343,9 @@ test('set up once links three registered boards, later registration and a persis
assert.equal(durableBytes.includes(Buffer.from(raw, 'base64url')), false, 'no raw board-key bytes in relay records');
}
+ const revokedDeviceId = await enrollProtocolPhone(box);
const approvalsBeforeRevoke = box.transit.filter(record => record.method === 'POST' && record.path === '/api/v1/devices/approvals').length;
- const revokeCommand = command(box.root, box.env, ['relay', 'revoke', device.id]);
+ const revokeCommand = command(box.root, box.env, ['relay', 'revoke', revokedDeviceId]);
t.after(async () => { if (revokeCommand.child.exitCode === null) revokeCommand.child.kill('SIGTERM'); await revokeCommand.done.catch(() => {}); });
/** Read the request id for the newly published revocation without adding another wait. */
const revokeRequestId = () => {
@@ -351,20 +353,20 @@ test('set up once links three registered boards, later registration and a persis
const post = approvals.length > approvalsBeforeRevoke ? approvals.at(-1) : null;
return post ? JSON.parse(post.request.toString('utf8')).context.id : 'request pending';
};
- await pageWait(chrome, () => `device revocation approval ${revokeRequestId()}`, `[...document.querySelectorAll('.phone-approval')].some(node => node.textContent.includes(${JSON.stringify(device.id)}))`);
+ await pageWait(chrome, () => `device revocation approval ${revokeRequestId()}`, `[...document.querySelectorAll('.phone-approval')].some(node => node.textContent.includes(${JSON.stringify(revokedDeviceId)}))`);
const revokeId = revokeRequestId();
- const revocationCard = await pageEvaluate(chrome, `read device revocation approval ${revokeId}`, `({text: [...document.querySelectorAll('.phone-approval')].find(node => node.textContent.includes(${JSON.stringify(device.id)})).innerText,
- action: [...document.querySelectorAll('.phone-approval')].find(node => node.textContent.includes(${JSON.stringify(device.id)})).querySelector('button').innerText})`);
- assert.match(revocationCard.text, new RegExp(device.id));
+ const revocationCard = await pageEvaluate(chrome, `read device revocation approval ${revokeId}`, `({text: [...document.querySelectorAll('.phone-approval')].find(node => node.textContent.includes(${JSON.stringify(revokedDeviceId)})).innerText,
+ action: [...document.querySelectorAll('.phone-approval')].find(node => node.textContent.includes(${JSON.stringify(revokedDeviceId)})).querySelector('button').innerText})`);
+ assert.match(revocationCard.text, new RegExp(revokedDeviceId));
assert.equal(revocationCard.action, 'Approve revocation');
const beforeRevokeTap = box.calls.filter(call => call.path.endsWith('/authorize')).length;
- await pageEvaluate(chrome, `tap device revocation approval ${revokeId}`, `[...document.querySelectorAll('.phone-approval')].find(node => node.textContent.includes(${JSON.stringify(device.id)})).querySelector('button').click()`);
+ await pageEvaluate(chrome, `tap device revocation approval ${revokeId}`, `[...document.querySelectorAll('.phone-approval')].find(node => node.textContent.includes(${JSON.stringify(revokedDeviceId)})).querySelector('button').click()`);
const revoked = await revokeCommand.done;
assert.equal(revoked.code, 0);
assert.match(revoked.document.notice, /already received remain known/u);
assert.equal(box.calls.filter(call => call.path.endsWith('/authorize')).length, beforeRevokeTap + 1,
'the named-device revocation uses exactly one explicit phone tap');
- assert.equal(JSON.parse(readFileSync(machineFile, 'utf8')).devices.length, 0);
+ assert.deepEqual(JSON.parse(readFileSync(machineFile, 'utf8')).devices.map(entry => entry.deviceId), [device.id], 'the approving phone remains paired; only the other target is removed');
});