Open-source AI browser agent for Chrome and Firefox (monorepo) ðŸ§
JavaScript ai-agentai-agentsai-toolsbrowser-aibrowser-automationbrowser-extensionchrome-aichrome-devtoolschrome-extensionchrome-extensionsfirefox-addonfirefox-addonsfirefox-extensionfirefox-extensionsgemmagemma4minimaxoffline-aioffline-llmqwen
fix(agent): collision-resistant commit message check, evidence-first slash scope
Emre Sokullu0d11e6c5d010
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.jsindex 29e6ce236..e22fe49b7 100644--- a/src/chrome/src/agent/agent.js+++ b/src/chrome/src/agent/agent.js@@ -1726,18 +1726,28 @@ export class Agent extends LoopDetector {const commitMessageRequirement = metadataRequirements.find(requirement => requirement?.field === 'commit_message');const expectedCommitMessage = this._workflowMetadataValue(commitMessageRequirement?.value);- const commitMessageVerified = !commitMessageRequirement || replacementRecordValues.some(record => (- record?.ambiguous !== true- && activeTaskTokenValid- && record?.taskToken === activeTaskToken- && !!record?.readbackSha256- && this._normalizeUrl(record.pageUrl || '') === this._normalizeUrl(pageUrl)- && /^(?:commit-message-input|commit_message)$/i.test(String(- record?.fieldMeta?.id || record?.fieldMeta?.name || '',- ))- && record.expectedLength === expectedCommitMessage.length- && record.expectedFp === this._workflowInventoryFingerprint(expectedCommitMessage)- ));+ // Collision-resistant comparison: replacement records already carry a+ // SHA-256 digest, so require it here too. A 32-bit FNV-1a fingerprint+ // collides practically (e.g. 'PSgOcTcQ' vs '9SHghNQJ'), which would set+ // commitMessageVerified for the wrong message while the raw-file check+ // still reports full success. The sync helper matches _sha256Text; the+ // gate itself stays synchronous.+ const expectedCommitMessageSha256 = commitMessageRequirement+ ? this._sha256TextSync(expectedCommitMessage)+ : '';+ const commitMessageVerified = !commitMessageRequirement+ || (!!expectedCommitMessageSha256 && replacementRecordValues.some(record => (+ record?.ambiguous !== true+ && activeTaskTokenValid+ && record?.taskToken === activeTaskToken+ && !!record?.readbackSha256+ && this._normalizeUrl(record.pageUrl || '') === this._normalizeUrl(pageUrl)+ && /^(?:commit-message-input|commit_message)$/i.test(String(+ record?.fieldMeta?.id || record?.fieldMeta?.name || '',+ ))+ && record.expectedLength === expectedCommitMessage.length+ && record.expectedSha256 === expectedCommitMessageSha256+ )));const githubFileCommit = !metadataIncomplete&& githubEditScope&& verifiedReplacement@@ -2375,6 +2385,23 @@ export class Agent extends LoopDetector {const segments = `${expected.branch}/${expected.path}`.split('/');const attempts = [{ branch: expected.branch, path: expected.path }];if (scopeAmbiguous) {+ // Evidence-first: the observed commit's changed-file list names the+ // true path. Any listed path that is an exact suffix re-partition of+ // the same segments is the true scope by construction — queue those+ // before the positional loop so a short slash branch with a deeply+ // nested file can never be dropped by the attempt cap below. The+ // count is bounded by the segment count (suffixes are distinct) and+ // every fetch keeps the existing 2MB guards.+ for (const blobPath of commitBlobPaths) {+ const blobSegments = String(blobPath).split('/').filter(segment => segment);+ if (!blobSegments.length || blobSegments.length >= segments.length) continue;+ if (segments.slice(segments.length - blobSegments.length).join('/') !== blobPath) continue;+ const branch = segments.slice(0, segments.length - blobSegments.length).join('/');+ if (!branch) continue;+ if (branch === expected.branch && blobPath === expected.path) continue;+ if (attempts.some(attempt => attempt.branch === branch && attempt.path === blobPath)) continue;+ attempts.push({ branch, path: blobPath });+ }for (let cut = segments.length - 1; cut >= 1 && attempts.length < 10; cut -= 1) {const branch = segments.slice(0, cut).join('/');const path = segments.slice(cut).join('/');@@ -13711,6 +13738,65 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dreturn hash.toString(16).padStart(8, '0');}+ // Synchronous SHA-256 over the UTF-8 bytes, matching the async+ // crypto.subtle digest in _sha256Text. Needed in the synchronous+ // submit-binding gate: the requested commit message must be compared by+ // collision-resistant digest (a 32-bit FNV-1a fingerprint collides+ // practically — e.g. 'PSgOcTcQ' vs '9SHghNQJ'), and the gate cannot await.+ _sha256TextSync(value) {+ try {+ const bytes = new TextEncoder().encode(String(value ?? ''));+ const K = [+ 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,+ 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,+ 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,+ 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,+ 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,+ 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,+ 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,+ 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,+ ];+ let h0 = 0x6a09e667; let h1 = 0xbb67ae85; let h2 = 0x3c6ef372; let h3 = 0xa54ff53a;+ let h4 = 0x510e527f; let h5 = 0x9b05688c; let h6 = 0x1f83d9ab; let h7 = 0x5be0cd19;+ const bitLength = bytes.length * 8;+ const paddedLength = (((bytes.length + 8) >> 6) + 1) * 64;+ const padded = new Uint8Array(paddedLength);+ padded.set(bytes);+ padded[bytes.length] = 0x80;+ const view = new DataView(padded.buffer);+ view.setUint32(paddedLength - 4, bitLength >>> 0, false);+ view.setUint32(paddedLength - 8, Math.floor(bitLength / 0x100000000), false);+ const w = new Array(64);+ const rotr = (x, n) => (x >>> n) | (x << (32 - n));+ for (let offset = 0; offset < paddedLength; offset += 64) {+ for (let i = 0; i < 16; i++) w[i] = view.getUint32(offset + i * 4, false);+ for (let i = 16; i < 64; i++) {+ const s0 = rotr(w[i - 15], 7) ^ rotr(w[i - 15], 18) ^ (w[i - 15] >>> 3);+ const s1 = rotr(w[i - 2], 17) ^ rotr(w[i - 2], 19) ^ (w[i - 2] >>> 10);+ w[i] = (w[i - 16] + s0 + w[i - 7] + s1) | 0;+ }+ let a = h0; let b = h1; let c = h2; let d = h3;+ let e = h4; let f = h5; let g = h6; let h = h7;+ for (let i = 0; i < 64; i++) {+ const S1 = rotr(e, 6) ^ rotr(e, 11) ^ rotr(e, 25);+ const ch = (e & f) ^ (~e & g);+ const t1 = (h + S1 + ch + K[i] + w[i]) | 0;+ const S0 = rotr(a, 2) ^ rotr(a, 13) ^ rotr(a, 22);+ const maj = (a & b) ^ (a & c) ^ (b & c);+ const t2 = (S0 + maj) | 0;+ h = g; g = f; f = e; e = (d + t1) | 0;+ d = c; c = b; b = a; a = (t1 + t2) | 0;+ }+ h0 = (h0 + a) | 0; h1 = (h1 + b) | 0; h2 = (h2 + c) | 0; h3 = (h3 + d) | 0;+ h4 = (h4 + e) | 0; h5 = (h5 + f) | 0; h6 = (h6 + g) | 0; h7 = (h7 + h) | 0;+ }+ return [h0, h1, h2, h3, h4, h5, h6, h7]+ .map(word => (word >>> 0).toString(16).padStart(8, '0')).join('');+ } catch {+ return '';+ }+ }+_workflowFormInventoryItems(result = {}, bindingKey = '', documentScope = '', siteWorkflow = null) {const text = [result?.pageContent, result?.text].find(value => typeof value === 'string' && value.trim()) || '';diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.jsindex 4fcf607f5..9500f8dcd 100644--- a/src/firefox/src/agent/agent.js+++ b/src/firefox/src/agent/agent.js@@ -1440,18 +1440,28 @@ export class Agent extends LoopDetector {const commitMessageRequirement = metadataRequirements.find(requirement => requirement?.field === 'commit_message');const expectedCommitMessage = this._workflowMetadataValue(commitMessageRequirement?.value);- const commitMessageVerified = !commitMessageRequirement || replacementRecordValues.some(record => (- record?.ambiguous !== true- && activeTaskTokenValid- && record?.taskToken === activeTaskToken- && !!record?.readbackSha256- && this._normalizeUrl(record.pageUrl || '') === this._normalizeUrl(pageUrl)- && /^(?:commit-message-input|commit_message)$/i.test(String(- record?.fieldMeta?.id || record?.fieldMeta?.name || '',- ))- && record.expectedLength === expectedCommitMessage.length- && record.expectedFp === this._workflowInventoryFingerprint(expectedCommitMessage)- ));+ // Collision-resistant comparison: replacement records already carry a+ // SHA-256 digest, so require it here too. A 32-bit FNV-1a fingerprint+ // collides practically (e.g. 'PSgOcTcQ' vs '9SHghNQJ'), which would set+ // commitMessageVerified for the wrong message while the raw-file check+ // still reports full success. The sync helper matches _sha256Text; the+ // gate itself stays synchronous.+ const expectedCommitMessageSha256 = commitMessageRequirement+ ? this._sha256TextSync(expectedCommitMessage)+ : '';+ const commitMessageVerified = !commitMessageRequirement+ || (!!expectedCommitMessageSha256 && replacementRecordValues.some(record => (+ record?.ambiguous !== true+ && activeTaskTokenValid+ && record?.taskToken === activeTaskToken+ && !!record?.readbackSha256+ && this._normalizeUrl(record.pageUrl || '') === this._normalizeUrl(pageUrl)+ && /^(?:commit-message-input|commit_message)$/i.test(String(+ record?.fieldMeta?.id || record?.fieldMeta?.name || '',+ ))+ && record.expectedLength === expectedCommitMessage.length+ && record.expectedSha256 === expectedCommitMessageSha256+ )));const githubFileCommit = !metadataIncomplete&& githubEditScope&& verifiedReplacement@@ -2089,6 +2099,23 @@ export class Agent extends LoopDetector {const segments = `${expected.branch}/${expected.path}`.split('/');const attempts = [{ branch: expected.branch, path: expected.path }];if (scopeAmbiguous) {+ // Evidence-first: the observed commit's changed-file list names the+ // true path. Any listed path that is an exact suffix re-partition of+ // the same segments is the true scope by construction — queue those+ // before the positional loop so a short slash branch with a deeply+ // nested file can never be dropped by the attempt cap below. The+ // count is bounded by the segment count (suffixes are distinct) and+ // every fetch keeps the existing 2MB guards.+ for (const blobPath of commitBlobPaths) {+ const blobSegments = String(blobPath).split('/').filter(segment => segment);+ if (!blobSegments.length || blobSegments.length >= segments.length) continue;+ if (segments.slice(segments.length - blobSegments.length).join('/') !== blobPath) continue;+ const branch = segments.slice(0, segments.length - blobSegments.length).join('/');+ if (!branch) continue;+ if (branch === expected.branch && blobPath === expected.path) continue;+ if (attempts.some(attempt => attempt.branch === branch && attempt.path === blobPath)) continue;+ attempts.push({ branch, path: blobPath });+ }for (let cut = segments.length - 1; cut >= 1 && attempts.length < 10; cut -= 1) {const branch = segments.slice(0, cut).join('/');const path = segments.slice(cut).join('/');@@ -11511,6 +11538,65 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dreturn hash.toString(16).padStart(8, '0');}+ // Synchronous SHA-256 over the UTF-8 bytes, matching the async+ // crypto.subtle digest in _sha256Text. Needed in the synchronous+ // submit-binding gate: the requested commit message must be compared by+ // collision-resistant digest (a 32-bit FNV-1a fingerprint collides+ // practically — e.g. 'PSgOcTcQ' vs '9SHghNQJ'), and the gate cannot await.+ _sha256TextSync(value) {+ try {+ const bytes = new TextEncoder().encode(String(value ?? ''));+ const K = [+ 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,+ 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,+ 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,+ 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,+ 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,+ 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,+ 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,+ 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,+ ];+ let h0 = 0x6a09e667; let h1 = 0xbb67ae85; let h2 = 0x3c6ef372; let h3 = 0xa54ff53a;+ let h4 = 0x510e527f; let h5 = 0x9b05688c; let h6 = 0x1f83d9ab; let h7 = 0x5be0cd19;+ const bitLength = bytes.length * 8;+ const paddedLength = (((bytes.length + 8) >> 6) + 1) * 64;+ const padded = new Uint8Array(paddedLength);+ padded.set(bytes);+ padded[bytes.length] = 0x80;+ const view = new DataView(padded.buffer);+ view.setUint32(paddedLength - 4, bitLength >>> 0, false);+ view.setUint32(paddedLength - 8, Math.floor(bitLength / 0x100000000), false);+ const w = new Array(64);+ const rotr = (x, n) => (x >>> n) | (x << (32 - n));+ for (let offset = 0; offset < paddedLength; offset += 64) {+ for (let i = 0; i < 16; i++) w[i] = view.getUint32(offset + i * 4, false);+ for (let i = 16; i < 64; i++) {+ const s0 = rotr(w[i - 15], 7) ^ rotr(w[i - 15], 18) ^ (w[i - 15] >>> 3);+ const s1 = rotr(w[i - 2], 17) ^ rotr(w[i - 2], 19) ^ (w[i - 2] >>> 10);+ w[i] = (w[i - 16] + s0 + w[i - 7] + s1) | 0;+ }+ let a = h0; let b = h1; let c = h2; let d = h3;+ let e = h4; let f = h5; let g = h6; let h = h7;+ for (let i = 0; i < 64; i++) {+ const S1 = rotr(e, 6) ^ rotr(e, 11) ^ rotr(e, 25);+ const ch = (e & f) ^ (~e & g);+ const t1 = (h + S1 + ch + K[i] + w[i]) | 0;+ const S0 = rotr(a, 2) ^ rotr(a, 13) ^ rotr(a, 22);+ const maj = (a & b) ^ (a & c) ^ (b & c);+ const t2 = (S0 + maj) | 0;+ h = g; g = f; f = e; e = (d + t1) | 0;+ d = c; c = b; b = a; a = (t1 + t2) | 0;+ }+ h0 = (h0 + a) | 0; h1 = (h1 + b) | 0; h2 = (h2 + c) | 0; h3 = (h3 + d) | 0;+ h4 = (h4 + e) | 0; h5 = (h5 + f) | 0; h6 = (h6 + g) | 0; h7 = (h7 + h) | 0;+ }+ return [h0, h1, h2, h3, h4, h5, h6, h7]+ .map(word => (word >>> 0).toString(16).padStart(8, '0')).join('');+ } catch {+ return '';+ }+ }+_workflowFormInventoryItems(result = {}, bindingKey = '', documentScope = '', siteWorkflow = null) {const text = [result?.pageContent, result?.text].find(value => typeof value === 'string' && value.trim()) || '';diff --git a/test/run.js b/test/run.jsindex 456e415b3..fb2d44e85 100644--- a/test/run.js+++ b/test/run.js@@ -74746,9 +74746,9 @@ test('GitHub edit-file workflow verifies the exact committed raw blob', async ()assert.deepEqual(binding.githubFileCommit.repository, 'example/repo');const replacements = agent._verifiedTextReplacements.get(tabId);const commitRecord = replacements.get('ax:doc:ref_commit_message');- const commitMessageFp = commitRecord.expectedFp;+ const commitMessageSha256 = commitRecord.expectedSha256;agent._currentUrl = async () => editUrl;- commitRecord.expectedFp = '00000000';+ commitRecord.expectedSha256 = '0'.repeat(64);assert.equal(agent._workflowSubmitBindingForAttempt(tabId, editUrl, {}).githubFileCommit, undefined,`${label}: a mismatched requested commit message received a commit binding`);assert.equal(await agent._workflowPreSubmitDispatchBlock(@@ -74787,7 +74787,7 @@ test('GitHub edit-file workflow verifies the exact committed raw blob', async ());assert.equal(blockedSubmit?.noDispatch, true, `${label}: unverified commit metadata reached submission`);assert.equal(blockedSubmit?.recoveryRequired, 'verify_or_restore_field');- commitRecord.expectedFp = commitMessageFp;+ commitRecord.expectedSha256 = commitMessageSha256;workflowGuard.workflowMetadataRequirementsIncomplete = true;workflowGuard.workflowMetadataRequirementsResolved = false;assert.equal((await agent._workflowPreSubmitDispatchBlock(@@ -75433,6 +75433,153 @@ test('focused field_value_digest and live scope cover selectorless writes', asyn}});+test('sync SHA-256 helper matches the async subtle digest', async () => {+ for (const [label, AgentClass] of [['chrome', AgentCh], ['firefox', AgentFx]]) {+ const agent = new AgentClass({});+ // Known vector first, so a broken table fails loudly instead of+ // self-consistently (sync-vs-sync would hide a wrong constant).+ assert.equal(agent._sha256TextSync('abc'),+ 'ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad',+ `${label}: sync SHA-256 mismatches the 'abc' vector`);+ for (const text of ['', 'body', 'Update docs/plan.md', 'PSgOcTcQ', '9SHghNQJ', 'héllo wörld ✓', 'x'.repeat(1000)]) {+ assert.equal(agent._sha256TextSync(text), await agent._sha256Text(text),+ `${label}: sync/async SHA-256 disagree on ${JSON.stringify(text.slice(0, 20))}`);+ }+ }+});++test('commit message gate compares SHA-256, not FNV-1a', async () => {+ for (const [label, AgentClass, resolveJob, tabId] of [+ ['chrome', AgentCh, resolveAdapterWorkflowJob, 9486],+ ['firefox', AgentFx, resolveAdapterWorkflowJobFx, 9487],+ ]) {+ const agent = new AgentClass({});+ // Premise pin: the review's pair really collides under FNV-1a, so a+ // fingerprint-only gate would confuse them.+ assert.equal(agent._workflowInventoryFingerprint('PSgOcTcQ'), agent._workflowInventoryFingerprint('9SHghNQJ'),+ `${label}: FNV-1a collision premise broken`);+ assert.notEqual(await agent._sha256Text('PSgOcTcQ'), await agent._sha256Text('9SHghNQJ'),+ `${label}: SHA-256 collision (essentially impossible)`);+ const pageUrl = 'https://github.com/Example/Repo/edit/main/docs/plan.md';+ agent._planExecutionGuards.set(tabId, {+ enabled: true,+ siteWorkflow: resolveJob(pageUrl, 'edit-file-and-commit'),+ workflowMetadataRequirements: [{ field: 'commit_message', value: 'PSgOcTcQ' }],+ workflowMetadataRequirementsResolved: true,+ });+ agent._taskTokens.set(tabId, 'task-sha-msg');+ const body = '# Doc\n';+ const editorRecord = {+ key: 'ax:doc:ref_editor',+ locatorType: 'ax',+ refId: 'ref_editor',+ documentToken: 'doc',+ pageUrl,+ ambiguous: false,+ expectedLength: body.length,+ expectedSha256: await agent._sha256Text(body),+ expectedFp: agent._workflowInventoryFingerprint(body),+ fieldMeta: { contentEditable: true, ariaLabelledByText: 'Editing file contents' },+ readbackLength: body.length,+ readbackSha256: await agent._sha256Text(body),+ verifiedAt: Date.now(),+ taskToken: 'task-sha-msg',+ };+ const messageRecordFor = async (text) => ({+ key: 'ax:doc:ref_msg',+ locatorType: 'ax',+ refId: 'ref_msg',+ documentToken: 'doc',+ pageUrl,+ ambiguous: false,+ expectedLength: text.length,+ expectedSha256: await agent._sha256Text(text),+ expectedFp: agent._workflowInventoryFingerprint(text),+ fieldMeta: { id: 'commit-message-input', name: 'commit-message-input' },+ readbackLength: text.length,+ readbackSha256: await agent._sha256Text(text),+ verifiedAt: Date.now(),+ taskToken: 'task-sha-msg',+ });+ // Same length, same FNV-1a, different bytes: must not verify.+ agent._verifiedTextReplacements.set(tabId, new Map([+ ['ax:doc:ref_editor', editorRecord],+ ['ax:doc:ref_msg', await messageRecordFor('9SHghNQJ')],+ ]));+ assert.equal(agent._workflowSubmitBindingForAttempt(tabId, pageUrl, {})?.githubFileCommit, undefined,+ `${label}: an FNV-1a colliding commit message authorized a commit`);+ // The exact requested message verifies.+ agent._verifiedTextReplacements.set(tabId, new Map([+ ['ax:doc:ref_editor', editorRecord],+ ['ax:doc:ref_msg', await messageRecordFor('PSgOcTcQ')],+ ]));+ assert.ok(agent._workflowSubmitBindingForAttempt(tabId, pageUrl, {})?.githubFileCommit,+ `${label}: the exact commit message was rejected`);+ }+});++test('slash-branch verification derives candidates from changed-file evidence', async () => {+ const originalFetch = globalThis.fetch;+ const body = '# Deeply nested document\n\nOne complete copy.\n';+ const commitSha = '0123456789abcdef0123456789abcdef01234567';+ const commitUrl = `https://github.com/Example/Repo/commit/${commitSha}`;+ // Branch feature/fix with a 10-segment path: 12 segments total, so the+ // true cut (after segment 2) sits beyond the old end-backward 10-attempt+ // cap and was never fetched even though the commit page lists it.+ const trueBranch = 'feature/fix';+ const truePath = 'a/b/c/d/e/f/g/h/i/plan.md';+ const naiveBranch = 'feature';+ const naivePath = `fix/${truePath}`;+ const naiveUrl = `https://github.com/example/repo/raw/${commitSha}/${naivePath.split('/').map(encodeURIComponent).join('/')}`;+ const trueUrl = `https://github.com/example/repo/raw/${commitSha}/${truePath.split('/').map(encodeURIComponent).join('/')}`;+ const trueBlobUrl = `https://github.com/Example/Repo/blob/${commitSha}/${truePath}`;+ try {+ const seen = [];+ globalThis.fetch = async (url) => {+ seen.push(url);+ if (url === trueUrl) {+ return { ok: true, status: 200, headers: { get: () => String(body.length) }, text: async () => body };+ }+ return { ok: false, status: 404, headers: { get: () => '0' }, text: async () => 'Not Found' };+ };+ for (const [label, AgentClass, tabId] of [+ ['chrome', AgentCh, 9488],+ ['firefox', AgentFx, 9489],+ ]) {+ seen.length = 0;+ const agent = new AgentClass({});+ agent._planExecutionGuards.set(tabId, {+ enabled: true,+ siteWorkflow: { adapterName: 'github', job: { id: 'edit-file-and-commit' } },+ });+ const binding = {+ githubFileCommit: {+ repository: 'example/repo',+ branch: naiveBranch,+ path: naivePath,+ expectedLength: body.length,+ expectedSha256: await agent._sha256Text(body),+ commitMessageVerified: true,+ },+ metadataRequirements: [],+ preDispatchPublishedResourceIdentities: [],+ };+ const pageState = { workflowResourceUrls: [commitUrl, trueBlobUrl] };+ const proof = await agent._githubCommittedFileVerification(+ tabId, pageState, commitUrl, { verifiedFinalSubmit: true, submit: { workflowBinding: binding } },+ );+ assert.equal(proof.verified, true, `${label}: evidenced deep slash-branch scope was not verified`);+ assert.equal(proof.path, truePath);+ assert.equal(binding.githubFileCommit.branch, trueBranch);+ assert.equal(binding.githubFileCommit.path, truePath);+ assert.ok(seen.includes(naiveUrl) && seen.includes(trueUrl),+ `${label}: naive cut and evidenced scope were not both probed`);+ }+ } finally {+ globalThis.fetch = originalFetch;+ }+});+test('Firefox selector debt recovers on exact digest readback', async () => {const originalChrome = globalThis.chrome;const originalBrowser = globalThis.browser;