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: surface redacted pre-admission exception in browser-fidelity refusals (#11724)
[._.]/ Adam Eivy4b020319d713
diff --git a/scripts/browser-fidelity.js b/scripts/browser-fidelity.jsindex 7f2019c163..86c3374c27 100644--- a/scripts/browser-fidelity.js+++ b/scripts/browser-fidelity.js@@ -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 { safeFailureReason } from './lib/fidelityDiagnostic.js';const repoRoot = fileURLToPath(new URL('../', import.meta.url));@@ -141,9 +142,10 @@ export async function publishBrowserFidelity({ pr, repository, receiptPath, envcontroller.signal.throwIfAborted();await post('success', `receipt sha256=${browserReceiptDigest(receipt)}`);return { receiptPath: output, diagnosticsPath: diagnostics, context, executed };- } catch {+ } catch (cause) {await post('failure', 'Required browser fidelity failed, changed, or did not complete.').catch(() => {});- throw Object.assign(Error('Browser fidelity was not admitted; local diagnostics were retained.'), { diagnosticsPath: diagnostics });+ throw Object.assign(Error('Browser fidelity was not admitted; local diagnostics were retained.'),+ { diagnosticsPath: diagnostics, reason: safeFailureReason(cause) });} finally {clearTimeout(timer);process.removeListener('SIGINT', abort);@@ -163,6 +165,8 @@ if (isDirectlyInvoked(import.meta.url)) {console.log(`Local diagnostics: ${result.diagnosticsPath}`);} catch (error) {console.error('❌ Browser fidelity was not admitted. Use --pr N on its clean current head with existing trusted gh authentication.');+ const reason = error.reason ?? safeFailureReason(error);+ if (reason) console.error(`Reason: ${reason}`);if (error.diagnosticsPath) console.error(`Local diagnostics retained: ${error.diagnosticsPath}`);process.exitCode = 1;}diff --git a/scripts/browser-fidelity.test.js b/scripts/browser-fidelity.test.jsindex 820780ba32..3d6dbddc4a 100644--- a/scripts/browser-fidelity.test.js+++ b/scripts/browser-fidelity.test.js@@ -94,6 +94,25 @@ describe('local fidelity publication through the existing runner and status bounexpect(f.posts.map(post => post.state)).toEqual(['pending', 'failure']);});+ it('refuses with a redacted underlying reason when a pre-admission operation throws', async () => {+ const f = fixture();+ f.options.toolchain = async () => { throw Error('spawn /Users/alice/bin/chrome failed GITHUB_TOKEN=sup3rs3cretvalue'); };+ const error = await publishBrowserFidelity(f.options).catch(caught => caught);+ expect(error.message).toContain('not admitted');+ expect(error.reason).toContain('spawn <path> failed');+ expect(error.reason).not.toMatch(/alice|sup3rs3cretvalue/);+ expect(f.posts.map(post => post.state)).toEqual(['pending', 'failure']);+ expect(f.run).not.toHaveBeenCalled();+ });++ it('keeps the existing refusal wording and surfaces the runner failure reason', async () => {+ const f = fixture({ outcome: 'failed' });+ const error = await publishBrowserFidelity(f.options).catch(caught => caught);+ expect(error.message).toBe('Browser fidelity was not admitted; local diagnostics were retained.');+ expect(error.reason).toBe('Browser fidelity failed or owned cleanup is unverified.');+ expect(f.posts.map(post => post.state)).toEqual(['pending', 'failure']);+ });+it('fails pending publication after its bounded runner cancellation settles', async () => {vi.useFakeTimers();try {diff --git a/scripts/lib/fidelityDiagnostic.js b/scripts/lib/fidelityDiagnostic.jsnew file mode 100644index 0000000000..d2c3c5b66e--- /dev/null+++ b/scripts/lib/fidelityDiagnostic.js@@ -0,0 +1,22 @@+// Safe one-line reason for a browser-fidelity refusal. The refusal decision never+// depends on this text; it only names what failed without leaking secrets or+// machine-identifying paths into terminal output that may be pasted into issues.+const MAX_REASON = 200;+const REDACTIONS = [+ [/\b(?:gh[pousr]_|github_pat_)[A-Za-z0-9_]{8,}/g, '<token>'],+ [/\b(Bearer|Basic|token)\s+[A-Za-z0-9._~+/=-]{8,}/gi, '$1 <token>'],+ [/\b([\w.-]*(?:token|secret|password|passwd|api[_-]?key|auth|cookie|credential)[\w.-]*)\s*[=:]\s*\S+/gi, '$1=<redacted>'],+ [/[\w.+-]+@[\w-]+(?:\.[\w-]+)+/g, '<email>'],+ [/\b[A-Za-z0-9+/_-]{32,}={0,2}/g, '<redacted>'],+ [/[A-Za-z]:\\[^\s'"]+/g, '<path>'],+ [/(?<![\w.:])\/(?:[^\s'"/]+\/)+[^\s'"/]*/g, '<path>'],+];++export function safeFailureReason(error) {+ const raw = error instanceof Error ? error.message : typeof error === 'string' ? error : '';+ let text = raw.replace(/[^\x20-\x7E]/g, ' ');+ for (const [pattern, replacement] of REDACTIONS) text = text.replace(pattern, replacement);+ text = text.replace(/\s+/g, ' ').trim().slice(0, MAX_REASON);+ const kind = error instanceof Error && error.name && error.name !== 'Error' ? `${error.name}: ` : '';+ return text ? `${kind}${text}` : '';+}diff --git a/scripts/lib/fidelityDiagnostic.test.js b/scripts/lib/fidelityDiagnostic.test.jsnew file mode 100644index 0000000000..67cd1ab65c--- /dev/null+++ b/scripts/lib/fidelityDiagnostic.test.js@@ -0,0 +1,30 @@+import { describe, expect, it } from 'vitest';+import { safeFailureReason } from './fidelityDiagnostic.js';++describe('safeFailureReason', () => {+ it('keeps a plain failure message and its error name', () => {+ expect(safeFailureReason(Error('Fidelity Chrome/FFmpeg toolchain unavailable.'))).toBe('Fidelity Chrome/FFmpeg toolchain unavailable.');+ expect(safeFailureReason(new TypeError('x is not a function'))).toBe('TypeError: x is not a function');+ });++ it.each([+ ['GitHub token', 'request failed with ghp_abcdefghijklmnopqrstuvwxyz0123456789', 'ghp_abcdefgh'],+ ['bearer header', 'bad header Bearer abc123def456ghi789', 'abc123def456'],+ ['key=value secret', 'env GITHUB_TOKEN=sup3rs3cretvalue rejected', 'sup3rs3cretvalue'],+ ['api key', 'api_key: sk-live-12345678', 'sk-live-12345678'],+ ['email', 'account [email protected] denied', '[email protected]'],+ ['long opaque value', `blob ${'Ab1'.repeat(20)}`, 'Ab1Ab1Ab1Ab1'],+ ['posix home path', 'ENOENT /Users/alice/secret-project/receipt.json', 'alice'],+ ['linux home path', 'cannot read /home/bob/.config/gh/hosts.yml', 'bob'],+ ['windows path', 'missing C:\\Users\\carol\\AppData\\x.json', 'carol'],+ ])('redacts %s', (_label, message, secret) => {+ const reason = safeFailureReason(Error(message));+ expect(reason).not.toContain(secret);+ expect(reason.length).toBeGreaterThan(0);+ });++ it('bounds length and returns empty for non-errors', () => {+ expect(safeFailureReason(Error('word '.repeat(200))).length).toBeLessThanOrEqual(200);+ expect(safeFailureReason(undefined)).toBe('');+ });+});