Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: reclaim browser-fidelity temp roots and passing diagnostics (#11749)
[._.]/ Adam Eivy2fcbdfd456a2
diff --git a/scripts/browser-fidelity.js b/scripts/browser-fidelity.jsindex 86c3374c27..d3368fc183 100644--- a/scripts/browser-fidelity.js+++ b/scripts/browser-fidelity.js@@ -1,8 +1,8 @@#!/usr/bin/env nodeimport { execFileSync } from 'node:child_process';-import { existsSync, lstatSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, writeFileSync } from 'node:fs';-import { join, resolve } from 'node:path';+import { existsSync, lstatSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync, writeFileSync } from 'node:fs';+import { dirname, join, resolve } from 'node:path';import { createRequire } from 'node:module';import { fileURLToPath } from 'node:url';import { tmpdir, platform, arch } from 'node:os';@@ -10,6 +10,7 @@ import { runNpm, toRunnerPath } from './run-ci-tests.js';import { BROWSER_FIDELITY_FILES, browserTestProfileArgs, assertBrowserProfileExecuted } from './lib/browserTestProfiles.js';import { browserFidelityTarget, browserFidelityContext, browserReceiptDigest, browserFidelityActor } from './lib/browserFidelity.js';import { isDirectlyInvoked } from './lib/directInvocation.js';+import { sweepStaleRunRoots, writeOwnerFile } from './lib/vitestStaleRunRoots.js';import { safeFailureReason } from './lib/fidelityDiagnostic.js';const repoRoot = fileURLToPath(new URL('../', import.meta.url));@@ -100,7 +101,10 @@ export async function publishBrowserFidelity({ pr, repository, receiptPath, envconst user = await request('user');if (user?.login?.toLowerCase() !== browserFidelityActor(repository)) throw Error('Existing GitHub authentication is not a trusted fidelity publisher.');const context = browserFidelityContext(target);+ // Rejected runs retain diagnostics; reclaim those from dead or aged prior runs.+ sweepStaleRunRoots(tmpdir(), { prefix: 'portos-browser-fidelity-' });const root = mkdtempSync(join(tmpdir(), 'portos-browser-fidelity-'));+ writeOwnerFile(root);const diagnostics = join(root, 'diagnostics');mkdirSync(diagnostics);const output = receiptPath ? resolve(receiptPath) : join(root, 'receipt.json');@@ -141,6 +145,9 @@ export async function publishBrowserFidelity({ pr, repository, receiptPath, envassertCheckout(git, target);controller.signal.throwIfAborted();await post('success', `receipt sha256=${browserReceiptDigest(receipt)}`);+ // Admitted: only the receipt is kept. A root holding nothing else goes too.+ rmSync(diagnostics, { recursive: true, force: true });+ if (dirname(output) !== root) rmSync(root, { recursive: true, force: true });return { receiptPath: output, diagnosticsPath: diagnostics, context, executed };} catch (cause) {await post('failure', 'Required browser fidelity failed, changed, or did not complete.').catch(() => {});diff --git a/scripts/browser-fidelity.test.js b/scripts/browser-fidelity.test.jsindex 40e824cecc..29f88615db 100644--- a/scripts/browser-fidelity.test.js+++ b/scripts/browser-fidelity.test.js@@ -1,4 +1,4 @@-import { mkdtempSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';+import { existsSync, mkdtempSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';import { tmpdir } from 'node:os';import { dirname, join } from 'node:path';import { spawnSync } from 'node:child_process';@@ -13,6 +13,7 @@ afterEach(() => { for (const root of roots.splice(0)) rmSync(root, { recursive:function fixture({ outcome = 'passed', changed = false, dirty = false, wrongTree = false } = {}) {const root = mkdtempSync(join(tmpdir(), 'browser-fidelity-contract-')); roots.push(root);const posts = [];+ const seen = {};let finished = false;const request = vi.fn(async (path, body) => {if (body) { posts.push(body); return { state: body.state, context: body.context, creator: { login: 'fixture' } }; }@@ -32,6 +33,7 @@ function fixture({ outcome = 'passed', changed = false, dirty = false, wrongTreeexpect(env.PORTOS_BROWSER_TEST_PROFILE).toBe('fidelity');expect(env.PORTOS_REQUIRE_BROWSER_SUITES).toBe('1');roots.push(dirname(env.PORTOS_CI_DIAGNOSTICS_DIR));+ seen.diagnostics = env.PORTOS_CI_DIAGNOSTICS_DIR;expect(env.PORTOS_CI_BROWSER_OWNER).toBeUndefined();expect(env.CHROME_PATH).toBe('/synthetic/chrome');const dir = join(env.PORTOS_CI_DIAGNOSTICS_DIR, 'portos-vitest-contract');@@ -52,7 +54,7 @@ function fixture({ outcome = 'passed', changed = false, dirty = false, wrongTree() => resolve({ status: 143, interrupted: 'SIGTERM' }), { once: true }));return { status: outcome === 'launcher' ? 1 : 0 };});- return { root, posts, run, options: { pr: 12, repository: 'fixture/PortOS', receiptPath: join(root, 'receipt.json'),+ return { root, posts, run, seen, options: { pr: 12, repository: 'fixture/PortOS', receiptPath: join(root, 'receipt.json'),request, git, run, toolchain: async () => ({ chromePath: '/synthetic/chrome',receipt: { chrome: 'Chrome synthetic', ffmpeg: 'FFmpeg synthetic', renderBackend: { kind: 'unknown' } } }), env: { PATH: process.env.PATH, PORTOS_CI_BROWSER_OWNER: 'unit', GITHUB_TOKEN: 'synthetic credential', OPENAI_API_KEY: 'synthetic key' } } };}@@ -71,6 +73,25 @@ describe('local fidelity publication through the existing runner and status bounexpect(JSON.stringify(receipt)).not.toMatch(/synthetic credential|synthetic key/);});+ it('removes diagnostics and the private root after an admitted run, keeping an external receipt', async () => {+ const f = fixture();+ const result = await publishBrowserFidelity(f.options);+ expect(existsSync(result.receiptPath)).toBe(true);+ expect(existsSync(f.seen.diagnostics)).toBe(false);+ expect(existsSync(dirname(f.seen.diagnostics))).toBe(false);+ });++ it('retains diagnostics for a rejected run, then a later run reclaims the dead-owner root', async () => {+ const failed = fixture({ outcome: 'failed' });+ await expect(publishBrowserFidelity(failed.options)).rejects.toThrow('not admitted');+ expect(existsSync(failed.seen.diagnostics)).toBe(true);+ expect(existsSync(join(dirname(failed.seen.diagnostics), '.owner.pid'))).toBe(true);+ // Simulate the owning process having exited.+ writeFileSync(join(dirname(failed.seen.diagnostics), '.owner.pid'), '2147483646 0\n');+ await publishBrowserFidelity(fixture().options);+ expect(existsSync(dirname(failed.seen.diagnostics))).toBe(false);+ });+it('binds default git identity to the script checkout when invoked from another directory', () => {const foreign = mkdtempSync(join(tmpdir(), 'fidelity-foreign-cwd-')); roots.push(foreign);const entry = new URL('./browser-fidelity.js', import.meta.url).href;