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(view): a refused account read answers the star line too [N26,H5]

Corey Olson203a93d60e79
diff --git a/src/cockpit.js b/src/cockpit.js
index f0d4ded8..7020d6d3 100644
--- a/src/cockpit.js
+++ b/src/cockpit.js
@@ -340,8 +340,9 @@ function starLine(list) {
show();
};
if (hosted.relaySession && !starLinked.linked && !starLinked.reading) {
- // The page's own read of the account, when it made one since the line last looked, answers the line: the line
- // reads the account itself only when the page made no such read, so a listing never brings a second one (#817).
+ // The page's own read of the account, when it made one since the line last looked, answers the line, refused
+ // or not: the line reads the account itself only when the page made no such read, so a listing never brings a
+ // second one (#817).
if (linkedSeen && linkedSeen.at > starLinked.at) learn(linkedSeen.reply);
else if (Date.now() - starLinked.at > 2500) {
starLinked = { at: Date.now(), linked: false, reading: true };
@@ -1030,13 +1031,19 @@ async function jsonRequest(path, body, base, headers, cache) {
let relayEngine = null;
/** The account's linked boards: a same-origin read that declares the relay's engine, as every relay request does. */
-// The account's last answer and when it came, for the star line, which reuses it rather than asking again (#817).
+// The account's last read and when it ended, answered or refused, for the star line, which reuses it rather than
+// asking again (#817): a refusal is an answer too, "not linked", and is not asked again straight away.
let linkedSeen = null;
async function linkedList() {
relayEngine ??= await import('/relay/engine.js').then((engine) => String(engine.ENGINE_VERSION), () => '');
- const reply = await jsonRequest('/api/v1/boards', undefined, '', relayEngine ? { 'x-pullboard-engine': relayEngine } : {}, 'no-store');
- linkedSeen = { at: Date.now(), reply };
- return reply;
+ try {
+ const reply = await jsonRequest('/api/v1/boards', undefined, '', relayEngine ? { 'x-pullboard-engine': relayEngine } : {}, 'no-store');
+ linkedSeen = { at: Date.now(), reply };
+ return reply;
+ } catch (error) {
+ linkedSeen = { at: Date.now(), reply: null };
+ throw error;
+ }
}
/**
diff --git a/test/cockpit/relay.test.js b/test/cockpit/relay.test.js
index ccb648c0..77507b6f 100644
--- a/test/cockpit/relay.test.js
+++ b/test/cockpit/relay.test.js
@@ -2067,6 +2067,14 @@ test('the star line shows once to a signed-in person and stays dismissed [N26]',
await chrome.send('Page.navigate', { url: star.live.link.href }).then(() => chrome.waitFor('!!data?.project'));
assert.equal(await chrome.stable("document.querySelector('#star-line') === null && !document.body.textContent.includes('GitHub star')"), true, 'the local view never carries the star line');
for (const file of ['src/cli.js', 'src/mcp.js', 'src/help.js']) assert.ok(!readFileSync(new URL('../../' + file, import.meta.url), 'utf8').includes('GitHub star'), file + ' never prints the star line');
+ // The account read is refused while this machine's view still answers: the refusal answers the line too, "not
+ // linked", and the line never asks again on its own (#817).
+ star.state.refused = true;
+ await page.open('/in-local', 'no', []);
+ assert.ok(star.requests.get('/api/v1/boards') >= 1, 'the page read the account and was refused');
+ assert.equal(await page.shown(), null, 'a refused account read shows no star line');
+ assert.equal(await chrome.stable('window.__starReads'), 0, 'and the line makes no read of its own after the refusal');
+ star.state.refused = false;
await page.open('/in-local', 'no', []);
assert.equal(await page.shown(), null, 'a signed-in person with an unlinked local-only board sees no star line');
await page.open('/in', 'no');
diff --git a/test/cockpit/star-line.js b/test/cockpit/star-line.js
index b1786653..55c5da0b 100644
--- a/test/cockpit/star-line.js
+++ b/test/cockpit/star-line.js
@@ -13,7 +13,8 @@ import { press } from './stable.js';
export { STAR_TEXT, starRepository } from '../../src/view/star.js';
/**
- * Start the fixture. `state.account` is the account's linked list as the relay serves it; `state.relay` says whether
+ * Start the fixture. `state.account` is the account's linked list as the relay serves it, or a 401 while `state.refused`
+ * holds, as for a session the relay no longer accepts; `state.relay` says whether
* the relay transport lists the board; `requests` counts each path asked for.
*
* @returns {Promise<{origin: string, live: object, board: object, state: {account: object[], relay: boolean}, requests: Map<string, number>, script: string, close: () => Promise<void>}>}
@@ -23,7 +24,7 @@ export async function starLineFixture() {
project(box, 'star-line');
const live = await startView(box);
const board = (await (await fetchLive(live.base + '/api/v1/boards', { headers: { 'x-pullboard-key': live.key } })).json()).boards[0];
- const state = { account: [], relay: false };
+ const state = { account: [], relay: false, refused: false };
const requests = new Map();
/** The hosted page as the relay serves it, signed in or not. */
const page = (relaySession) => cockpitPage('', { readOnly: true, requests: relaySession, transportModule: '/star-transport.js', apiHeaders: {}, stylesheet: '/view.css', hostedLocal: true, relaySession, signIn: '/auth/github/start' });
@@ -37,6 +38,7 @@ export async function starLineFixture() {
if (url.pathname === '/star-transport.js') return send('text/javascript', "export async function createTransport() { return { async request(path) { return (await fetch('/relay' + path)).json(); } }; }");
if (url.pathname === '/view.css') return send('text/css', readFileSync(new URL('../../src/view.css', import.meta.url), 'utf8'));
// The account's linked list: metadata only, read by the page on its own origin.
+ if (url.pathname === '/api/v1/boards' && state.refused) return send('application/json', JSON.stringify({ error: { code: 'AUTH_REQUIRED', message: 'Sign in.' } }), 401);
if (url.pathname === '/api/v1/boards') return send('application/json', JSON.stringify({ version: 1, boards: state.account }));
if (url.pathname === '/lv/local/protocol') return send('application/json', JSON.stringify({ version: 1, apiVersion: 1, hostedOrigin: origin }));
// This machine's view answers reads and streams through the fixture, with its key.