3D engine that AI agents drive
Remember a failed update check for a day and assert the check CLI export in the bundle (#907)
Nguyen Xuan And24db2a97669
diff --git a/scripts/build-mcp.mjs b/scripts/build-mcp.mjsindex 666c12fc..9328d05f 100644--- a/scripts/build-mcp.mjs+++ b/scripts/build-mcp.mjs@@ -215,8 +215,11 @@ export async function buildMcp({ outDir = join(root, 'build', 'mcp'), libraryDirthrow new Error(`server.mjs includes scene engine code (${marker}). Import plain data from agent-scene-capabilities.js instead of agent-scene.js.`);}}- if (!server.exports.includes('createAgentMcpServer') || !server.exports.includes('runMcpCli')) {- throw new Error('Node bundle must export createAgentMcpServer and runMcpCli.');+ // bin/67js-mcp.mjs imports each of these from the bundle.+ const requiredExports = ['createAgentMcpServer', 'runMcpCli', 'runCheckUpdateCli'];+ const missingExports = requiredExports.filter(name => !server.exports.includes(name));+ if (missingExports.length > 0) {+ throw new Error(`Node bundle must export ${missingExports.join(', ')}.`);}const licenses = await collectLicenses([...previewChunks.map(({ chunk }) => chunk), server]);const previewEntry = previewChunks.find(({ fileName }) => fileName === PREVIEW_ENTRY_FILE);diff --git a/src/mcp-update-check.js b/src/mcp-update-check.jsindex aa2b2bf3..bf705c6c 100644--- a/src/mcp-update-check.js+++ b/src/mcp-update-check.js@@ -64,7 +64,8 @@ export function updateNoticeText(updateAvailable) {function readCache(cachePath) {try {const cached = JSON.parse(readFileSync(cachePath, 'utf8'));- if (typeof cached.checkedAt === 'number' && STABLE_VERSION.test(cached.latest)) {+ // latest is null after a failed request: the day still counts, so an offline user is asked once a day, not every start.+ if (typeof cached.checkedAt === 'number' && (cached.latest === null || STABLE_VERSION.test(cached.latest))) {return cached;}} catch {@@ -106,7 +107,7 @@ export function startUpdateCheck({const cached = readCache(cachePath);latest = cached?.latest ?? null;if (cached === null || now() - cached.checkedAt >= UPDATE_CHECK_INTERVAL_MS || cached.checkedAt > now()) {- settled = refreshCache({ fetchImpl, now, cachePath, timeoutMs }).then(found => {+ settled = refreshCache({ fetchImpl, now, cachePath, timeoutMs, previousLatest: latest }).then(found => {latest = found ?? latest;}).catch(() => {});}@@ -117,14 +118,11 @@ export function startUpdateCheck({};}-async function refreshCache({ fetchImpl, now, cachePath, timeoutMs }) {+async function refreshCache({ fetchImpl, now, cachePath, timeoutMs, previousLatest }) {const found = await fetchLatestVersion(fetchImpl, timeoutMs);- if (found === null) {- return null;- }try {await mkdir(dirname(cachePath), { recursive: true });- await writeFile(cachePath, JSON.stringify({ checkedAt: now(), latest: found }));+ await writeFile(cachePath, JSON.stringify({ checkedAt: now(), latest: found ?? previousLatest }));} catch {// An unwritable cache only means the next start asks again.}diff --git a/tests/mcp-update-check.test.js b/tests/mcp-update-check.test.jsindex 8b6afb15..2152d986 100644--- a/tests/mcp-update-check.test.js+++ b/tests/mcp-update-check.test.js@@ -98,6 +98,30 @@ test('registry errors, bad bodies and thrown fetches stay silent', async () => {}});+test('a failed request is remembered for a day and keeps the last known version', async () => {+ await withCacheFolder(async cachePath => {+ await startUpdateCheck({ currentVersion: '0.19.0', env: {}, fetchImpl: registryAnswer('0.20.0'), now: () => NOW, cachePath }).settled;+ const offline = countingFetch(async () => { throw new Error('offline'); });+ const later = NOW + UPDATE_CHECK_INTERVAL_MS;+ const failed = startUpdateCheck({ currentVersion: '0.19.0', env: {}, fetchImpl: offline, now: () => later, cachePath });+ await failed.settled;+ assert.equal(failed.current().latest, '0.20.0');+ assert.deepEqual(JSON.parse(await readFile(cachePath, 'utf8')), { checkedAt: later, latest: '0.20.0' });+ const nextStart = startUpdateCheck({ currentVersion: '0.19.0', env: {}, fetchImpl: offline, now: () => later + 1, cachePath });+ await nextStart.settled;+ assert.equal(offline.calls.length, 1, 'no second request on the same day');+ });+ await withCacheFolder(async cachePath => {+ const offline = countingFetch(async () => { throw new Error('offline'); });+ await startUpdateCheck({ currentVersion: '0.19.0', env: {}, fetchImpl: offline, now: () => NOW, cachePath }).settled;+ assert.deepEqual(JSON.parse(await readFile(cachePath, 'utf8')), { checkedAt: NOW, latest: null });+ const nextStart = startUpdateCheck({ currentVersion: '0.19.0', env: {}, fetchImpl: offline, now: () => NOW + 1, cachePath });+ await nextStart.settled;+ assert.equal(nextStart.current(), null);+ assert.equal(offline.calls.length, 1);+ });+});+test('a registry that never answers is cut off at the timeout', async () => {await withCacheFolder(async cachePath => {const hanging = (url, { signal }) => new Promise((resolve, reject) => {