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 export test sees the full-board request again [N26,A2]

Corey Olson004073c366e9
diff --git a/src/serve.js b/src/serve.js
index 7ba155fd..eab348b0 100644
--- a/src/serve.js
+++ b/src/serve.js
@@ -57,12 +57,15 @@ export function portableSnapshot(value, root, field = '') {
/**
* Export one board through the same API v1 used by the live page, closing its temporary local
* transport before returning. The static page needs neither that transport nor its session key.
+ * Its API reads go through fetchApi, fetchLocal unless a caller passes another; a test passes one
+ * that records each address and then reads through fetchLocal, so it sees the requests the export sends.
*
* @param {string} root
* @param {string} directory
+ * @param {{ fetchApi?: typeof fetchLocal }} [options]
* @returns {Promise<{path: string}>}
*/
-export async function exportView(root, directory) {
+export async function exportView(root, directory, { fetchApi = fetchLocal } = {}) {
const output = resolve(directory);
if (existsSync(output) && (!statSync(output).isDirectory() || readdirSync(output).length)) {
throw new Refused('EXPORT_EXISTS', `snapshot folder ${output} is not empty; use an empty folder`);
@@ -84,7 +87,7 @@ export async function exportView(root, directory) {
const read = async (path) => {
let reply;
try {
- reply = await fetchLocal(address.origin + path, { headers: { 'x-pullboard-key': address.searchParams.get('k') } });
+ reply = await fetchApi(address.origin + path, { headers: { 'x-pullboard-key': address.searchParams.get('k') } });
} catch (error) {
if (!(error instanceof TypeError)) throw error;
throw new Refused('VIEW_UNAVAILABLE', `could not read view at ${address.origin} while exporting; retry when the local view is available`);
diff --git a/test/cockpit/snapshot.test.js b/test/cockpit/snapshot.test.js
index 28ced906..2fb9ffa1 100644
--- a/test/cockpit/snapshot.test.js
+++ b/test/cockpit/snapshot.test.js
@@ -5,6 +5,7 @@ import { createServer, request } from 'node:http';
import { tmpdir } from 'node:os';
import { join, resolve } from 'node:path';
import { test } from 'node:test';
+import { fetchLocal } from '../../src/local-fetch.js';
import { exportView, portableSnapshot } from '../../src/serve.js';
import { machine, project, build, sendBack, fetchLive, startView, accept, boardId, boardOf, assertObservationsEqual, chromeExecutable, browserPause, openSnapshotChrome, closeSnapshotChrome, press, travel, settled, roadmapRow, showing, readRoadmap, openRoadmapParts, serveFolder, proofShot } from './fixture.js';
@@ -686,17 +687,16 @@ test('the export asks for the full board [N26,A2]', { timeout: 90_000 }, // budg
build(box, alpha, 1, 'greeting-fix.html');
accept(box, alpha, 1);
- // The export reads the board through the local API. Record each address it asks for, never its key.
+ // The export reads the board through the local API with fetchLocal. Record each address it asks
+ // for, never its key, and make every read through fetchLocal unchanged.
const asked = [];
- const nativeFetch = globalThis.fetch;
- /** Note the address of each API read, then make the read unchanged. */
- globalThis.fetch = (input, init) => {
- asked.push(new URL(input instanceof Request ? input.url : String(input)));
- return nativeFetch(input, init);
+ /** Note the address of each API read, then read it through the export's own transport. */
+ const fetchApi = (url, init) => {
+ asked.push(new URL(String(url)));
+ return fetchLocal(url, init);
};
const folder = join(box.dir, 'full-board-export');
- try { await exportView(alpha.repo, folder); }
- finally { globalThis.fetch = nativeFetch; }
+ await exportView(alpha.repo, folder, { fetchApi });
const stateReads = asked.filter((url) => url.pathname.endsWith('/state'));
assert.deepEqual(stateReads.map((url) => url.searchParams.get('detail')), ['full'],
`the export reads the state once, asking for detail=full; it asked for ${asked.map((url) => url.pathname + url.search).join(', ')}`);