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(test): journeys survive a network service restart [N40,N26]

Corey Olsonaf4651c892bd
diff --git a/test/cockpit/journey-routes.js b/test/cockpit/journey-routes.js
index db9b87a4..21d14212 100644
--- a/test/cockpit/journey-routes.js
+++ b/test/cockpit/journey-routes.js
@@ -24,9 +24,9 @@ export function journeyApiPathKind(pathname) {
* @param {object} chrome - The browser B connection.
* @param {{url: string, headers: object}} asked - The paused request.
* @param {{cookieless?: boolean}|null} condition - The CI stand-in, if any.
- * @param {object[]} pauses - Bounded record of API pauses: path kind and 'paused', 'restored' or 'none'.
+ * @param {object[]} pauses - Bounded record of API pauses: path kind and 'paused', 'restored', 'replanted' or 'none'.
*/
-export async function journeyForwardHeaders(chrome, asked, condition, pauses) {
+export async function journeyForwardHeaders(chrome, asked, condition, pauses, planted = null) {
const address = new URL(asked.url);
const api = address.pathname.startsWith('/api/');
let headers = Object.entries(asked.headers).filter(([name]) => !['host', 'content-length'].includes(name.toLowerCase()));
@@ -37,8 +37,13 @@ export async function journeyForwardHeaders(chrome, asked, condition, pauses) {
const { cookies } = await chrome.send('Network.getCookies', { urls: [asked.url] });
if (cookies.length > 0) { headers.push(['Cookie', cookies.map(({ name, value }) => name + '=' + value).join('; ')]); restored = true; }
}
+ // A restart of Chrome's network service empties its in-memory jar. Production's pb_session is persistent (Max-Age)
+ // and survives once flushed; the fixture's was planted moments ago, so the journey keeps forwarding it, and counts
+ // each time it had to (#902). The document needs it too: the server renders a signed-out page without it.
+ let replanted = false;
+ if (!paused && !restored && planted) { headers.push(['Cookie', planted]); replanted = true; }
if (api && pauses.length < 128) {
- pauses.push({ pathKind: journeyApiPathKind(address.pathname), cookie: paused ? 'paused' : restored ? 'restored' : 'none' });
+ pauses.push({ pathKind: journeyApiPathKind(address.pathname), cookie: paused ? 'paused' : restored ? 'restored' : replanted ? 'replanted' : 'none' });
}
return headers;
}
@@ -75,6 +80,8 @@ export async function routeJourneyOrigins(chrome, site, view, slow = null, pause
let navigatedAt = -Infinity;
// Each harness navigation arms one commit; a commit the page makes on its own never counts (#935 review).
let awaitingCommit = false;
+ // The session cookie this journey planted, forwarded when a network-service restart has emptied the jar (#902).
+ const session = { planted: null };
const listener = ({ data }) => {
const message = JSON.parse(String(data));
// A main-frame commit after the harness navigated replaces the document whose paused reads Chrome then retires.
@@ -90,7 +97,7 @@ export async function routeJourneyOrigins(chrome, site, view, slow = null, pause
if (address.origin === JOURNEY_HOSTED && address.pathname.startsWith('/api/')) {
// Every hosted API request goes on to the owned site, as live streams always did. Answering one by hand raced
// the browser for paged object reads, which then failed at Fetch.fulfillRequest with Invalid InterceptionId (#935).
- const headers = (await journeyForwardHeaders(chrome, asked, slow, pauses)).map(([name, value]) => ({ name, value }));
+ const headers = (await journeyForwardHeaders(chrome, asked, slow, pauses, session.planted)).map(([name, value]) => ({ name, value }));
await chrome.send('Fetch.continueRequest', {
requestId, url: site.base + address.pathname + address.search, headers,
});
@@ -108,7 +115,7 @@ export async function routeJourneyOrigins(chrome, site, view, slow = null, pause
return;
}
if (address.origin !== JOURNEY_HOSTED) throw new Error('unexpected fixture browser origin');
- const headers = Object.fromEntries(await journeyForwardHeaders(chrome, asked, slow, pauses));
+ const headers = Object.fromEntries(await journeyForwardHeaders(chrome, asked, slow, pauses, session.planted));
const response = await fetchLive(site.base + address.pathname + address.search, {
method: asked.method, headers, redirect: 'manual',
...(asked.postData === undefined ? {} : { body: asked.postData }),
@@ -154,6 +161,8 @@ export async function routeJourneyOrigins(chrome, site, view, slow = null, pause
assert.deepEqual(failures, [], `owned hosted and loopback HTTP routes finish without cancelling event streams (orphaned by navigation: ${JSON.stringify(orphaned)})`);
};
/** Navigate the page, marking the moment so requests already paused for the old document are known as orphaned. */
+ /** Record the session cookie the journey planted, as name=value, for forwarding after a jar reset (#902). */
+ stop.plant = (cookie) => { session.planted = cookie; };
stop.navigate = async (url) => {
navigatedAt = performance.now();
awaitingCommit = true;
diff --git a/test/journeys.test.js b/test/journeys.test.js
index 3400a4ea..c0275005 100644
--- a/test/journeys.test.js
+++ b/test/journeys.test.js
@@ -773,7 +773,7 @@ async function journeyRelaySite(box, localOrigin) {
* @param {import('node:test').TestContext} t - The running test.
* @param {{armed: boolean, ms: number}|null} [slow] - The CI stand-in, armed just before B's last visit.
*/
-async function everyBoardJourney(t, slow = null) {
+async function everyBoardJourney(t, slow = null, { restart = false } = {}) {
const executable = findChromeExecutable();
if (!executable) return t.skip('Install Chrome or set PULLBOARD_CHROME to run the two-home hosted journey.');
@@ -844,9 +844,11 @@ async function everyBoardJourney(t, slow = null) {
authTrace = journeyAuthTrace(chromeB);
stopRoutes = await routeJourneyOrigins(chromeB, site, viewB, slow, cookiePauses);
const person = await machineA.phoneSession();
+ // Persistent, as the relay's own pb_session is (Max-Age), so the fixture's sign-in matches what a person has (#902).
assert.equal((await chromeB.send('Network.setCookie', {
- name: 'pb_session', value: person.token, url: JOURNEY_HOSTED, httpOnly: true, sameSite: 'Lax',
+ name: 'pb_session', value: person.token, url: JOURNEY_HOSTED, httpOnly: true, sameSite: 'Lax', expires: Math.floor(Date.now() / 1000) + 86_400,
})).success, true, 'the same fixture person signs in on B without exposing session data to the page');
+ stopRoutes.plant('pb_session=' + person.token);
for (const permissions of [['loopbackNetwork', 'localNetwork', 'localNetworkAccess'], ['localNetworkAccess']]) {
try { await chromeB.send('Browser.grantPermissions', { origin: JOURNEY_HOSTED, permissions }); break; }
catch { /* Chrome versions expose different local-network permission names. */ }
@@ -871,6 +873,14 @@ async function everyBoardJourney(t, slow = null) {
cookiePauses.length = 0;
// The CI condition: a slow first discovery answer, and from here Chrome's paused requests arrive without cookies (#835).
if (slow) Object.assign(slow, { armed: true, cookieless: true });
+ // The macOS CI signature (#902): Chrome's network service restarts and its cookie jar starts empty. Killing it here
+ // makes that happen on every run; Chrome starts a new one before the next request.
+ if (restart) {
+ const before = networkServicePids(profileB) ?? [];
+ assert.ok(before.length > 0, 'the profile has a network service to restart');
+ for (const pid of before) process.kill(pid, 'SIGKILL');
+ await waitFor(() => (networkServicePids(profileB) ?? []).some((pid) => !before.includes(pid)), 'Chrome starts a new network service', 15_000); // budget: hang ceiling for Chrome relaunching its network service.
+ }
await stopRoutes.navigate(JOURNEY_HOSTED + '/');
const rowPredicate = `(${journeySidebarReady.toString()})([...document.querySelectorAll('#proj-list .proj.repo .pname')].map(node => node.textContent.trim()), ${JSON.stringify(JOURNEY_BOARD_NAMES)})`;
const rowObservation = await observeJourneyRows(
@@ -903,6 +913,10 @@ async function everyBoardJourney(t, slow = null) {
'the CI condition sent the session read without its paused cookie, and the stand-in restored it from the jar');
assert.deepEqual(cookiePauses.filter(({ cookie }) => cookie === 'none'), [], 'no hosted API request left without pb_session');
}
+ if (restart) {
+ assert.ok(cookiePauses.some(({ cookie }) => cookie === 'replanted'), 'the restart emptied the jar and the journey forwarded its planted session');
+ assert.deepEqual(cookiePauses.filter(({ cookie }) => cookie === 'none'), [], 'no hosted API request left without pb_session after the restart');
+ }
const pageAnswers = await journeyTrace.snapshot();
try {
for (const [source, boardName] of [['linked', 'fixture/repository'], ['local', 'local-machine-b']]) {
@@ -1010,16 +1024,19 @@ async function everyBoardJourney(t, slow = null) {
test('pullboard.dev shows every board, linked and local [N40]', {
timeout: relayWorkBudgetMs() * 5 + 180_000,
- skip: (!findChromeExecutable() && 'Chrome is not installed')
- || (process.env.CI && !process.env.PULLBOARD_HOSTED_JOURNEYS && '#902: skipped on CI until the hosted page starts its relay transport on every runner; #902 un-skips it; repeat.yml runs it with PULLBOARD_HOSTED_JOURNEYS=1'),
+ skip: (!findChromeExecutable() && 'Chrome is not installed'),
}, (t) => everyBoardJourney(t));
test('pullboard.dev shows every board under the CI condition [N40,N26]', {
timeout: relayWorkBudgetMs() * 5 + 180_000,
- skip: (!findChromeExecutable() && 'Chrome is not installed')
- || (process.env.CI && !process.env.PULLBOARD_HOSTED_JOURNEYS && '#902: skipped on CI until the hosted page starts its relay transport on every runner; #902 un-skips it; repeat.yml runs it with PULLBOARD_HOSTED_JOURNEYS=1'),
+ skip: (!findChromeExecutable() && 'Chrome is not installed'),
}, (t) => everyBoardJourney(t, { armed: false, ms: 3_500 }));
+test('pullboard.dev shows every board after Chrome\'s network service restarts [N40,N26]', {
+ timeout: relayWorkBudgetMs() * 5 + 180_000,
+ skip: (!findChromeExecutable() && 'Chrome is not installed'),
+}, (t) => everyBoardJourney(t, null, { restart: true }));
+
// ---------------------------------------------------------------------------------------------------------------
// The view's main journeys as Gherkin-style scenarios [N26]. Each step is a Given, When or Then; every When is real
// input: a mouse press at the target's centre through the shared press (which refuses a covered target), typed