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): the star line reuses the page read of the account [N26,H5]

Corey Olson9770d880c98e
diff --git a/src/cockpit.js b/src/cockpit.js
index 1adbece3..f0d4ded8 100644
--- a/src/cockpit.js
+++ b/src/cockpit.js
@@ -333,10 +333,20 @@ function starLine(list) {
const line = $('star-line');
if (!line) return list;
const show = () => { line.hidden = !(hosted.relaySession && starLinked.linked && keep(${JSON.stringify(STAR_KEY)}) !== 'dismissed'); };
- if (hosted.relaySession && !starLinked.linked && !starLinked.reading && Date.now() - starLinked.at > 2500) {
- starLinked = { at: Date.now(), linked: false, reading: true };
- linkedList().then((reply) => reply?.boards?.some((board) => typeof board?.id === 'string'), () => false)
- .then((linked) => { starLinked = { at: Date.now(), linked, reading: false }; line.dataset.linked = linked ? 'yes' : 'no'; show(); });
+ const learn = (reply) => {
+ const linked = Boolean(reply?.boards?.some((board) => typeof board?.id === 'string'));
+ starLinked = { at: Date.now(), linked, reading: false };
+ line.dataset.linked = linked ? 'yes' : 'no';
+ 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).
+ if (linkedSeen && linkedSeen.at > starLinked.at) learn(linkedSeen.reply);
+ else if (Date.now() - starLinked.at > 2500) {
+ starLinked = { at: Date.now(), linked: false, reading: true };
+ linkedList().then(learn, () => learn(null));
+ }
}
show();
return list;
@@ -1020,9 +1030,13 @@ 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).
+let linkedSeen = null;
async function linkedList() {
relayEngine ??= await import('/relay/engine.js').then((engine) => String(engine.ENGINE_VERSION), () => '');
- return jsonRequest('/api/v1/boards', undefined, '', relayEngine ? { 'x-pullboard-engine': relayEngine } : {}, 'no-store');
+ const reply = await jsonRequest('/api/v1/boards', undefined, '', relayEngine ? { 'x-pullboard-engine': relayEngine } : {}, 'no-store');
+ linkedSeen = { at: Date.now(), reply };
+ return reply;
}
/**
diff --git a/test/cockpit/relay.test.js b/test/cockpit/relay.test.js
index 07919e13..ccb648c0 100644
--- a/test/cockpit/relay.test.js
+++ b/test/cockpit/relay.test.js
@@ -2056,6 +2056,9 @@ test('the star line shows once to a signed-in person and stays dismissed [N26]',
try {
chrome = await openSnapshotChrome(executable, 'about:blank', profile);
await chrome.send('Page.addScriptToEvaluateOnNewDocument', { source: star.script });
+ // Each account read the star line makes itself. Once the page has read the account, a read from the line reaches
+ // fetch inside the line's own call, so its stack names starLine (#817).
+ await chrome.send('Page.addScriptToEvaluateOnNewDocument', { source: "(() => { const fetchNow = window.fetch.bind(window); window.__starReads = 0; window.fetch = (input, init) => { const address = new URL(String(typeof input === 'string' ? input : input.url), location.href); if (address.origin === location.origin && address.pathname === '/api/v1/boards' && /starLine/.test(new Error().stack || '')) window.__starReads += 1; return fetchNow(input, init); }; })()" });
const page = starSteps(chrome, star);
star.state.account = [linkedBoard]; // Even a linked list that answered a signed-out page would show nothing there.
await chrome.send('Page.navigate', { url: star.origin + '/out' }).then(() => chrome.waitFor("location.pathname === '/out' && !document.querySelector('#local-note').hidden"));
@@ -2070,6 +2073,7 @@ test('the star line shows once to a signed-in person and stays dismissed [N26]',
assert.equal(await page.shown(), null, 'a signed-in person with an empty linked list sees no star line');
await page.open('/in-local', 'yes', [linkedBoard]); // The person links this machine's board: the page reads it locally.
assert.deepEqual(await page.shown(), expected, 'a linked board read locally shows one line, one plain sentence, linking to the repository');
+ assert.equal(await chrome.stable('window.__starReads'), 0, 'the line learns from the read of the account the page already made, and makes no extra read of its own');
assert.equal(star.requests.get('/star-transport.js'), undefined, 'no relay client loads while every linked board is local');
for (const width of [1280, 390]) await proofShot(chrome, 'star-line', width);
await page.dismiss();