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 social publication retry after pre-dispatch veto
Barack Sokullua31178bd851c
diff --git a/package.json b/package.jsonindex fc213b7a0..2ff2fa528 100644--- a/package.json+++ b/package.json@@ -88,7 +88,7 @@"test:upload-owner": "node --test test/page-monitor-upload-owner.mjs","test:shard:quick": "npm run test:cms && npm run test:markdown && npm run test:generative-media && npm run test:systemone && npm run test:systemone:fast && node --test test/browser-dialogs.mjs test/capsolver-cloud-broker.mjs test/captcha-providers.mjs test/captcha-weighted-fallback.mjs test/captcha-hcaptcha-providers.mjs test/captcha-native-providers.mjs test/captcha-runtime-policy.mjs test/captcha-callback-bridge.mjs test/captcha-bridge-registration.mjs test/captcha-aws-recovery.mjs test/captcha-documented-contracts.mjs test/huggingface-signup-recovery.mjs test/trace-full-export.mjs test/feedback-traces.mjs && npm run test:firefox-bidi && npm run test:billing-notice && npm run test:compass-quota && npm run test:provider-limits && npm run test:provider-catalog && npm run test:provider-instances:ui && npm run test:openrouter-capabilities && npm run test:anthropic && npm run test:accessibility-tree-benchmark && npm run test:toolbar-guard && npm run test:cloud-bridge-approval && npm run test:discord && npm run test:pdf-read && npm run test:pdf-selection && npm run test:social-contract && npm run test:safesocial && npm run test:build-unpacked && npm run test:attachment-drop && npm run test:workflow-editor && node --test test/profile-sync-stats.mjs && node --test test/memcode-recall.mjs","test:shard:runtime-unit": "node --test test/agent-lifecycle.mjs test/runtime-startup.mjs test/run-ui-scheduled-lifecycle.mjs test/transport-deadlines.mjs test/cdp-worker-restart.mjs test/cdp-clear-receipt.mjs test/cdp-field-submit-recovery.mjs test/conversation-persistence.mjs test/context-live-tool-group.mjs test/integration-races.mjs test/watch-completion-checkpoint.mjs test/runtime-model-identity.mjs test/provider-message-privacy.mjs test/runtime-task-authority.mjs test/planner-repair-authority.mjs test/runtime-progress-continuation.mjs test/chat-resume-chain.mjs test/chat-resume-completion.mjs test/native-chat-execution-ledger.mjs test/chat-send-dispatch-result.mjs test/chat-reply-dedup-race.mjs test/memcode-lifecycle.mjs test/runtime-peer-review.mjs test/read-continuation-schema.mjs test/completion-submit-acknowledgement.mjs test/completion-live-status.mjs test/completion-iframe-submit.mjs test/completion-semantic-commit.mjs test/completion-diagnostics.mjs test/mastodon-publication.mjs test/calculator.mjs test/chat-recovery-protocol.mjs test/chat-pending-reconciliation.mjs test/semantic-page-retry.mjs test/pdf-detection.mjs test/runtime-lifecycle.mjs test/collection-read-progress.mjs test/network-lifecycle.mjs test/text-write-cancellation.mjs test/trusted-field-preparation.mjs test/draftjs-text.mjs test/rich-text-frameworks.mjs test/firefox-rich-text-readback.mjs test/contenteditable-beforeinput.mjs test/trusted-field-preparation-ownership.mjs test/chat-steering.mjs test/steering-revision-recovery.mjs test/pending-clarification-hydration.mjs test/permission-steering-wakeup.mjs test/pure-calculation-reply.mjs test/pure-calculation-tools.mjs test/page-feedback.mjs test/page-feedback-progress.mjs test/page-feedback-policy.mjs test/page-feedback-transport-races.mjs test/page-feedback-recovery.mjs test/telegram-read-preparation-agent.mjs test/media-download-agent-handler.mjs test/code-scanning-url-recipient.mjs test/apocalypse-comm-parsing.mjs test/apocalypse-scalar-decoding.mjs test/bitgpu-chat-security.mjs test/social-media-url-upgrades.mjs test/downloaded-file-saved-bytes.mjs test/downloaded-file-local-probe.mjs test/formless-verification-recovery.mjs test/file-upload-accept.mjs test/file-upload-accept-agent.mjs test/workflow-route-generic-completion.mjs test/completion-current-execution-evidence.mjs",- "test:shard:browser-a": "node test/ui-content-lifecycle.mjs && node --test test/native-telegram-chat.mjs test/native-telegram-recipient.mjs test/telegram-native-baseline.mjs test/telegram-native-latest.mjs test/native-chat-pre-enter-draft.mjs test/chat-draft-dispatch-ownership.mjs test/native-telegram-alias-preparation.mjs test/telegram-read-preparation-content.mjs test/queued-composer-ownership.mjs test/onboarding-provider-ready.mjs test/workflow-native-targets.mjs test/native-whatsapp-chat.mjs test/native-chat-context-identity.mjs test/native-whatsapp-contact.mjs test/whatsapp-native-bootstrap.mjs test/whatsapp-drawer-identity.mjs test/whatsapp-read-latest.mjs test/whatsapp-read-preparation.mjs test/whatsapp-chat-completion.mjs test/whatsapp-chat-restart.mjs test/chat-goal-lifecycle.mjs test/chat-completion.mjs test/chat-generic-dispatch.mjs test/completion-live-status-browser.mjs test/native-confirmation-visibility.mjs test/read-continuation-browser.mjs test/iframe-preparation-focus.mjs test/contenteditable-literal.mjs test/native-chat-empty-editor.mjs test/native-chat-trusted-clear.mjs test/chat-steering-ui.mjs test/assistant-message-visibility-ui.mjs test/page-monitor-ui.mjs test/page-monitor-dialog.mjs test/page-monitor-dialog-native.mjs test/page-monitor-inline-post.mjs test/bluesky-composer-context.mjs test/page-monitor-anchored.mjs test/page-monitor-upload-owner.mjs test/page-monitor-native-preparation.mjs test/native-preparation-cold.mjs test/page-monitor-navigation.mjs test/page-monitor-main-owner.mjs test/page-monitor-collateral-controls.mjs test/accessibility-tree-scoped-budget.mjs test/ax-reference-origin.mjs test/page-monitor-decorative-hit.mjs test/social-ui-navigation.mjs test/dropdown-menu-inventory.mjs test/page-monitor-passive-progress.mjs test/media-download-binding.mjs test/media-download-capture-integration.mjs test/social-media-downloader-reinjection.mjs test/upload-file-local-state-guidance.mjs",+ "test:shard:browser-a": "node test/ui-content-lifecycle.mjs && node --test test/native-telegram-chat.mjs test/native-telegram-recipient.mjs test/telegram-native-baseline.mjs test/telegram-native-latest.mjs test/native-chat-pre-enter-draft.mjs test/chat-draft-dispatch-ownership.mjs test/native-telegram-alias-preparation.mjs test/telegram-read-preparation-content.mjs test/queued-composer-ownership.mjs test/onboarding-provider-ready.mjs test/workflow-native-targets.mjs test/native-whatsapp-chat.mjs test/native-chat-context-identity.mjs test/native-whatsapp-contact.mjs test/whatsapp-native-bootstrap.mjs test/whatsapp-drawer-identity.mjs test/whatsapp-read-latest.mjs test/whatsapp-read-preparation.mjs test/whatsapp-chat-completion.mjs test/whatsapp-chat-restart.mjs test/chat-goal-lifecycle.mjs test/chat-completion.mjs test/chat-generic-dispatch.mjs test/completion-live-status-browser.mjs test/native-confirmation-visibility.mjs test/native-button-preparation.mjs test/read-continuation-browser.mjs test/iframe-preparation-focus.mjs test/contenteditable-literal.mjs test/native-chat-empty-editor.mjs test/native-chat-trusted-clear.mjs test/chat-steering-ui.mjs test/assistant-message-visibility-ui.mjs test/page-monitor-ui.mjs test/page-monitor-dialog.mjs test/page-monitor-dialog-native.mjs test/page-monitor-inline-post.mjs test/bluesky-composer-context.mjs test/page-monitor-anchored.mjs test/page-monitor-upload-owner.mjs test/page-monitor-native-preparation.mjs test/native-preparation-cold.mjs test/page-monitor-navigation.mjs test/page-monitor-main-owner.mjs test/page-monitor-collateral-controls.mjs test/accessibility-tree-scoped-budget.mjs test/ax-reference-origin.mjs test/page-monitor-decorative-hit.mjs test/social-ui-navigation.mjs test/dropdown-menu-inventory.mjs test/page-monitor-passive-progress.mjs test/media-download-binding.mjs test/media-download-capture-integration.mjs test/social-media-downloader-reinjection.mjs test/upload-file-local-state-guidance.mjs","test:shard:browser-b1": "node test/message-recipient-upload.mjs && node --test test/message-recipient-whatsapp.mjs && node test/quality/integration-mv3.mjs --full-form && node test/quality/literal-calculate-midrun-mv3.mjs && node test/quality/telegram-cold-preparation-mv3.mjs && node test/quality/native-chat-mv3.mjs && node test/quality/native-chat-presubmit-mv3.mjs","test:shard:browser-b2": "node test/quality/whatsapp-contact-matrix.mjs && node test/quality/pdf-detection-mv3.mjs && node test/quality/download-upload-mv3.mjs && node test/quality/downloaded-file-saved-bytes-mv3.mjs && node test/quality/file-upload-accept-mv3.mjs && node test/quality/bulk-resume-mv3.mjs","test:shard:browser-c": "node test/quality/literal-frame-mv3.mjs && node test/quality/mastodon-publication-mv3.mjs && node test/quality/mastodon-deletion-mv3.mjs && node test/quality/anchored-action-mv3.mjs && node test/quality/inline-social-composer-mv3.mjs && node test/quality/bluesky-composer-mv3.mjs && node test/quality/dropdown-menu-matrix.mjs && node test/quality/mastodon-deletion-navigation-mv3.mjs && node test/quality/semantic-navigation-matrix.mjs && node test/quality/workflow-replay-mv3.mjs && node test/quality/generative-media-mv3.mjs && node test/quality/cdp-worker-restart-mv3.mjs",diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.jsindex d90c28979..35cc1a7fd 100644--- a/src/chrome/src/agent/agent.js+++ b/src/chrome/src/agent/agent.js@@ -2074,11 +2074,16 @@ export class Agent extends LoopDetector {if (semanticCommit && !canRecordSemanticCommitDispatch(result)) return null;const before = this._normalizeUrl(beforeUrl || '');const after = this._normalizeUrl(afterUrl || beforeUrl || '');- const explicitlyNotDispatched = result?.dispatched === false || result?.noDispatch === true;+ // Positive input or transport uncertainty takes precedence over a stale+ // no-dispatch flag. Only a proved pre-dispatch veto can release a retry.+ const explicitlyNotDispatched = (result?.dispatched === false || result?.noDispatch === true)+ && result?.dispatched !== true && result?.missingToolResponse !== true+ && result?.outcomeUnknown !== true && result?.nativeInputAcknowledged !== true;const dispatchMayHaveOccurred = !!(result&& (result.dispatched === true+ || result.nativeInputAcknowledged === true|| result.missingToolResponse === true|| result.outcomeUnknown === true|| (result.success !== false && !result.error)@@ -2090,6 +2095,33 @@ export class Agent extends LoopDetector {executionContext,detectedSubmit,);+ const social = this._planExecutionGuards.get(tabId)?.socialPublication;+ const socialAttempt = workflowBinding?.socialPublication;+ if (explicitlyNotDispatched && social && socialAttempt?.contractKey === social.key) {+ // A later veto cannot replace an earlier delivery receipt. Preparation+ // failures are not publication failures and must not lock this action or+ // authorize a fallback to a different destination.+ if (social.outcomes[socialAttempt.actionId]) return null;+ if (result?.formValidationFailed !== true) {+ if (social.dispatch?.key === socialAttempt.key && social.dispatch.actionId === socialAttempt.actionId) {+ const retry = social.retryBypass;+ if (social.dispatch.auditBypassed && retry?.key === socialAttempt.key+ && retry.contractKey === social.key && retry.actionId === socialAttempt.actionId) {+ // A consumed grant from an earlier interrupted attempt is still+ // uncertain. Only this call's private consumption receipt owns it.+ if (retry.consumed && executionContext.socialPublicationAuditRetryConsumed !== retry) return null;+ retry.consumed = false;+ delete social.retryBypassUsed?.[retry.key];+ }+ // Re-observe and revalidate the exact draft before another dispatch.+ social.dispatch = null;+ }+ return null;+ }+ }+ // A rejected preparation on another form or route cannot erase a real+ // earlier submission. Its exact receipt still owns delivery verification.+ if (explicitlyNotDispatched && this._completionSubmitStates.get(tabId)?.dispatched === true) return null;if (workflowBinding?.verificationKind === 'published_resource'&& Array.isArray(detectedSubmit?.publicationResourceUrls)) {workflowBinding.preDispatchPublishedResourceIdentities = this._workflowPublishedResourceIdentities(@@ -2156,7 +2188,6 @@ export class Agent extends LoopDetector {? currentPublication : null,workflowBinding,};- const social = this._planExecutionGuards.get(tabId)?.socialPublication;if (social && workflowBinding?.socialPublication?.contractKey === social.key) {social.outcomes[workflowBinding.socialPublication.actionId] = {status: explicitlyNotDispatched || result?.formValidationFailed === true ? 'failed' : 'pending', cause: 'publish_failed',@@ -14688,7 +14719,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dconst calculationDispatchBlock = this._pureCalculationToolBlock(tabId, fnName, fnArgs, calculationRequestScope);if (!pipelineToolbarPreflight.block && !socialDispatchBlock && !genericChatBlock && !calculationDispatchBlock) {if (detectedSubmitAction?.isSubmit === true && detectedSubmitAction.publicationControl === true) {- this._consumeSocialPublicationAuditRetry(tabId);+ messageRecipientExecutionContext.socialPublicationAuditRetryConsumed = this._consumeSocialPublicationAuditRetry(tabId);}if (fnName === 'calculate') this._rememberPureCalculationAttempt(tabId, fnArgs, calculationRequestScope);callState.invoked = true;@@ -21299,9 +21330,10 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d_consumeSocialPublicationAuditRetry(tabId) {const social = this._planExecutionGuards.get(tabId)?.socialPublication;if (!social?.dispatch?.auditBypassed || !social.retryBypass- || social.retryBypass.key !== social.dispatch.key || social.retryBypass.consumed) return;+ || social.retryBypass.key !== social.dispatch.key || social.retryBypass.consumed) return null;social.retryBypass.consumed = true;(social.retryBypassUsed ||= {})[social.retryBypass.key] = true;+ return social.retryBypass;}_continuedSocialPublicationState(social, retryTaskKey = null) {diff --git a/src/chrome/src/content/content.js b/src/chrome/src/content/content.jsindex 21b473f49..9772b12ea 100644--- a/src/chrome/src/content/content.js+++ b/src/chrome/src/content/content.js@@ -1223,8 +1223,10 @@if (Number.parseFloat(style.opacity || '1') <= 0) {return { visible: false, reason: 'target or an ancestor is fully transparent' };}- if (style.pointerEvents === 'none') {- return { visible: false, reason: 'target or an ancestor does not receive pointer events' };+ // A child can override an ancestor's pointer-events:none. Its own+ // computed value and the physical hit test determine clickability.+ if (node === el && style.pointerEvents === 'none') {+ return { visible: false, reason: 'target does not receive pointer events' };}}} catch {diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.jsindex 375c12ddd..32ff71ad8 100644--- a/src/firefox/src/agent/agent.js+++ b/src/firefox/src/agent/agent.js@@ -1792,11 +1792,16 @@ export class Agent extends LoopDetector {if (semanticCommit && !canRecordSemanticCommitDispatch(result)) return null;const before = this._normalizeUrl(beforeUrl || '');const after = this._normalizeUrl(afterUrl || beforeUrl || '');- const explicitlyNotDispatched = result?.dispatched === false || result?.noDispatch === true;+ // Positive input or transport uncertainty takes precedence over a stale+ // no-dispatch flag. Only a proved pre-dispatch veto can release a retry.+ const explicitlyNotDispatched = (result?.dispatched === false || result?.noDispatch === true)+ && result?.dispatched !== true && result?.missingToolResponse !== true+ && result?.outcomeUnknown !== true && result?.nativeInputAcknowledged !== true;const dispatchMayHaveOccurred = !!(result&& (result.dispatched === true+ || result.nativeInputAcknowledged === true|| result.missingToolResponse === true|| result.outcomeUnknown === true|| (result.success !== false && !result.error)@@ -1808,6 +1813,33 @@ export class Agent extends LoopDetector {executionContext,detectedSubmit,);+ const social = this._planExecutionGuards.get(tabId)?.socialPublication;+ const socialAttempt = workflowBinding?.socialPublication;+ if (explicitlyNotDispatched && social && socialAttempt?.contractKey === social.key) {+ // A later veto cannot replace an earlier delivery receipt. Preparation+ // failures are not publication failures and must not lock this action or+ // authorize a fallback to a different destination.+ if (social.outcomes[socialAttempt.actionId]) return null;+ if (result?.formValidationFailed !== true) {+ if (social.dispatch?.key === socialAttempt.key && social.dispatch.actionId === socialAttempt.actionId) {+ const retry = social.retryBypass;+ if (social.dispatch.auditBypassed && retry?.key === socialAttempt.key+ && retry.contractKey === social.key && retry.actionId === socialAttempt.actionId) {+ // A consumed grant from an earlier interrupted attempt is still+ // uncertain. Only this call's private consumption receipt owns it.+ if (retry.consumed && executionContext.socialPublicationAuditRetryConsumed !== retry) return null;+ retry.consumed = false;+ delete social.retryBypassUsed?.[retry.key];+ }+ // Re-observe and revalidate the exact draft before another dispatch.+ social.dispatch = null;+ }+ return null;+ }+ }+ // A rejected preparation on another form or route cannot erase a real+ // earlier submission. Its exact receipt still owns delivery verification.+ if (explicitlyNotDispatched && this._completionSubmitStates.get(tabId)?.dispatched === true) return null;if (workflowBinding?.verificationKind === 'published_resource'&& Array.isArray(detectedSubmit?.publicationResourceUrls)) {workflowBinding.preDispatchPublishedResourceIdentities = this._workflowPublishedResourceIdentities(@@ -1874,7 +1906,6 @@ export class Agent extends LoopDetector {? currentPublication : null,workflowBinding,};- const social = this._planExecutionGuards.get(tabId)?.socialPublication;if (social && workflowBinding?.socialPublication?.contractKey === social.key) {social.outcomes[workflowBinding.socialPublication.actionId] = {status: explicitlyNotDispatched || result?.formValidationFailed === true ? 'failed' : 'pending', cause: 'publish_failed',@@ -13276,7 +13307,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dconst calculationDispatchBlock = this._pureCalculationToolBlock(tabId, fnName, fnArgs, calculationRequestScope);if (!pipelineToolbarPreflight.block && !socialDispatchBlock && !genericChatBlock && !calculationDispatchBlock) {if (detectedSubmitAction?.isSubmit === true && detectedSubmitAction.publicationControl === true) {- this._consumeSocialPublicationAuditRetry(tabId);+ messageRecipientExecutionContext.socialPublicationAuditRetryConsumed = this._consumeSocialPublicationAuditRetry(tabId);}if (fnName === 'calculate') this._rememberPureCalculationAttempt(tabId, fnArgs, calculationRequestScope);callState.invoked = true;@@ -18945,9 +18976,10 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d_consumeSocialPublicationAuditRetry(tabId) {const social = this._planExecutionGuards.get(tabId)?.socialPublication;if (!social?.dispatch?.auditBypassed || !social.retryBypass- || social.retryBypass.key !== social.dispatch.key || social.retryBypass.consumed) return;+ || social.retryBypass.key !== social.dispatch.key || social.retryBypass.consumed) return null;social.retryBypass.consumed = true;(social.retryBypassUsed ||= {})[social.retryBypass.key] = true;+ return social.retryBypass;}_continuedSocialPublicationState(social, retryTaskKey = null) {diff --git a/test/native-button-preparation.mjs b/test/native-button-preparation.mjsnew file mode 100644index 000000000..3c5a7120c--- /dev/null+++ b/test/native-button-preparation.mjs@@ -0,0 +1,99 @@+import assert from 'node:assert/strict';+import { readFile } from 'node:fs/promises';+import { test } from 'node:test';+import { chromium } from 'playwright';++// Firefox has no CDP/native-button preparation branch. Exercise Chrome's real+// content message handler and AX references; preparation must never click.+const scripts = await Promise.all([+ 'accessibility-tree.js', 'rich-text-toolbar-heuristic.js', 'content.js',+].map(name => readFile(new URL(`../src/chrome/src/content/${name}`, import.meta.url), 'utf8')));++const html = `<!doctype html><style>+ body{margin:20px}#owner{width:280px}button{width:160px;height:44px}+ #label{pointer-events:none}#cover{position:fixed;background:white;z-index:999}+ #nested{display:flex;width:100%;height:100%;align-items:center;justify-content:center}+</style><main id="owner"><h1>Owned local composer</h1>+ <textarea aria-label="Draft">Local fixture draft</textarea>+ <button id="publish" type="button"><span id="label">Post</span></button>+</main><script>window.qaClicks=0;publish.addEventListener('click',()=>qaClicks++);</script>`;++test('Chrome native button preparation respects effective pointer events and actual physical targets', async t => {+ const browser = await chromium.launch({ headless: true });+ try {+ async function fixture(variant) {+ const page = await browser.newPage({ viewport: { width: 800, height: 600 } });+ await page.setContent(html);+ await page.evaluate(() => {+ window.qaListeners = [];+ window.chrome = { runtime: {+ getURL: path => path,+ sendMessage: (_message, callback) => { callback?.({}); return Promise.resolve({}); },+ onMessage: { addListener: listener => qaListeners.push(listener) },+ } };+ window.qaMessage = message => new Promise(resolve => {+ for (const listener of qaListeners) {+ let answered = false;+ const returned = listener(message, {}, value => { answered = true; resolve(value); });+ if (answered || returned === true) return;+ }+ resolve(undefined);+ });+ });+ for (const content of scripts) await page.addScriptTag({ content });+ await page.evaluate(variant => {+ const button = document.querySelector('#publish'), owner = button.parentElement;+ if (variant === 'ancestor-pointer-none') {+ owner.style.pointerEvents = 'none'; button.style.pointerEvents = 'auto';+ } else if (variant === 'target-pointer-none') button.style.pointerEvents = 'none';+ else if (variant === 'cover') {+ const rect = button.getBoundingClientRect(), cover = document.createElement('div');+ cover.id = 'cover';+ Object.assign(cover.style, { left: `${rect.left}px`, top: `${rect.top}px`,+ width: `${rect.width}px`, height: `${rect.height}px` });+ document.body.append(cover);+ } else if (variant === 'nested-control') {+ const control = document.createElement('span');+ control.id = 'nested'; control.setAttribute('role', 'button');+ control.textContent = 'Other action'; button.replaceChildren(control);+ } else if (variant === 'ancestor-display-none') owner.style.display = 'none';+ else if (variant === 'ancestor-visibility-hidden') {+ owner.style.visibility = 'hidden'; button.style.visibility = 'visible';+ } else if (variant === 'ancestor-transparent') owner.style.opacity = '0';+ }, variant);+ return page;+ }++ for (const [variant, allowed] of [+ ['passive-label', true], ['ancestor-pointer-none', true],+ ['cover', false], ['nested-control', false], ['target-pointer-none', false],+ ['ancestor-display-none', false], ['ancestor-visibility-hidden', false],+ ['ancestor-transparent', false],+ ]) await t.test(variant, async () => {+ const page = await fixture(variant);+ try {+ const facts = await page.evaluate(() => {+ const button = document.querySelector('#publish'), rect = button.getBoundingClientRect();+ const hit = document.elementFromPoint(Math.round(rect.left + rect.width / 2),+ Math.round(rect.top + rect.height / 2));+ return { hitId: hit?.id, buttonPointerEvents: getComputedStyle(button).pointerEvents,+ ownerPointerEvents: getComputedStyle(button.parentElement).pointerEvents };+ });+ if (allowed) assert.equal(facts.hitId, 'publish', 'The inert label hits the native button itself.');+ if (variant === 'ancestor-pointer-none') {+ assert.equal(facts.buttonPointerEvents, 'auto'); assert.equal(facts.ownerPointerEvents, 'none');+ } else if (variant === 'cover') assert.equal(facts.hitId, 'cover');+ else if (variant === 'nested-control') assert.equal(facts.hitId, 'nested');+ const result = await page.evaluate(() => window.qaMessage({ target: 'content', action: 'click_ax',+ params: { ref_id: window.__wb_ax_ref(document.querySelector('#publish')),+ _prepareTrustedNativeButton: true, _requireTrustedNativeButton: true } }));+ assert.equal(result?.success, allowed, JSON.stringify(result));+ assert.equal(result.dispatched, false); assert.equal(result.noDispatch, true);+ if (allowed) {+ assert.equal(result.trustedButtonRequired, true); assert.equal(result.tag, 'button');+ }+ assert.equal(await page.evaluate(() => qaClicks), 0, 'Neither preparation nor its veto clicks.');+ } finally { await page.close(); }+ });+ } finally { await browser.close(); }+});diff --git a/test/quality/inline-social-composer-mv3.mjs b/test/quality/inline-social-composer-mv3.mjsindex dc9e50b75..65fd2e039 100644--- a/test/quality/inline-social-composer-mv3.mjs+++ b/test/quality/inline-social-composer-mv3.mjs@@ -29,6 +29,7 @@ const cases = [{ name: 'set_field', tool: 'set_field' },{ name: 'type_ax', tool: 'type_ax' },{ name: 'focus_expansion', tool: 'set_field', focusExpansion: true },+ { name: 'native_preparation_retry', tool: 'set_field', nativePreparationVeto: true },{ name: 'owner_changed', tool: 'set_field', change: 'owner' },{ name: 'account_changed', tool: 'type_ax', change: 'account' },{ name: 'audience_changed', tool: 'set_field', change: 'audience' },@@ -72,7 +73,7 @@ const intent = { request_kind: 'execute', scope_relation: 'new', requires_state_summary: 'Publish exactly one owned local QA post from the current ownedqa account and verify its confirmation.',steps: [{ id: '1', action: 'Read the home composer, write the exact draft once, re-observe Post, publish once and verify the owned confirmation.' }],memory: { use_progress_ledger: false, progress_action: null }, scheduling: null, risks: [] };-let current, context;+let current, context, worker;const blockedRemote = [], submissions = [], summaries = [], auxiliaryRequests = [];const server = http.createServer(async (request, response) => {try {@@ -145,10 +146,33 @@ const server = http.createServer(async (request, response) => {assert.ok(current.beforePost.post, JSON.stringify(observed));current.postReobserved = last?.name === 'get_accessibility_tree';await current.page.evaluate(() => qaChurnFeed());+ if (current.nativePreparationVeto) await current.page.evaluate(() => qaArmPreparationOverlay());current.inferenceChanges++;await new Promise(resolve => setTimeout(resolve, 240));call = { name: 'click_ax', args: { ref_id: current.beforePost.post } };- } else if (step === (current.focusExpansion ? 6 : 4) && !current.change && current.writeResult?.success === true)+ } else if (step === 4 && current.nativePreparationVeto) {+ current.preparationVeto = tools.findLast(tool => tool.name === 'click_ax')?.result;+ current.afterVeto = await current.page.evaluate(() => ({ state: qaSnapshot(), overlay: !!document.getElementById('qa-native-preparation-overlay') }));+ current.vetoLedger = await worker.evaluate(tabId => {+ const guard = inlineFixtureAgent._planExecutionGuards.get(tabId);+ return { outcomes: guard?.socialPublication?.outcomes, dispatch: guard?.socialPublication?.dispatch,+ submitted: inlineFixtureAgent._completionSubmitStates.get(tabId)?.dispatched === true };+ }, current.tabId);+ assert.equal(current.preparationVeto?.noDispatch, true, JSON.stringify(current.preparationVeto));+ assert.equal(current.preparationVeto?.dispatched, false);+ assert.equal(current.afterVeto.overlay, true, 'A real hover-triggered occluder must reach native preparation.');+ assert.deepEqual(current.afterVeto.state.saved, []);+ assert.deepEqual(current.vetoLedger.outcomes, {}); assert.equal(current.vetoLedger.dispatch, null);+ await current.page.evaluate(() => qaClearPreparationOverlay());+ call = { name: 'get_accessibility_tree', args: { filter: 'all' } };+ } else if (step === 5 && current.nativePreparationVeto) {+ const fresh = references(observed?.result);+ assert.equal(last?.name, 'get_accessibility_tree'); assert.ok(fresh.post);+ current.postRetryReobserved = true;+ call = { name: 'click_ax', args: { ref_id: fresh.post } };+ } else if (step === 6 && current.nativePreparationVeto)+ call = { name: 'get_accessibility_tree', args: { filter: 'all' } };+ else if (step === (current.focusExpansion ? 6 : 4) && !current.change && current.writeResult?.success === true)call = { name: 'get_accessibility_tree', args: { filter: 'all' } };else call = { name: 'done', args: { outcome: current.change || current.writeResult?.success !== true ? 'partial' : 'success',summary: current.change ? 'The changed composer was left intact and unsubmitted.' : 'The owned local inline composer regression is finished.' } };@@ -233,6 +257,15 @@ function App(){React.createElement('button',{type:'button','aria-label':'Like feed item '+feedRevision+'-'+index},'Like'))))));}ReactDOM.flushSync(()=>root.render(React.createElement(App)));+window.qaPreparationOverlays=0;+window.qaArmPreparationOverlay=()=>document.querySelector('#post').addEventListener('pointerenter',event=>{+ if(!event.isTrusted)return;+ const rect=event.currentTarget.getBoundingClientRect(),overlay=document.createElement('button');+ overlay.id='qa-native-preparation-overlay';overlay.type='button';overlay.textContent='Owned temporary preparation overlay';+ overlay.style='position:fixed;z-index:100000;left:'+(rect.left-1)+'px;top:'+(rect.top-1)+'px;width:'+(rect.width+2)+'px;height:'+(rect.height+2)+'px';+ document.body.append(overlay);window.qaPreparationOverlays++;+},{once:true});+window.qaClearPreparationOverlay=()=>document.getElementById('qa-native-preparation-overlay')?.remove();for(const type of ['beforeinput','input','paste'])document.querySelector('#app').addEventListener(type,event=>{if(event.target.closest('[data-testid="tweetTextarea_0"]'))qaEvents.push({type,trusted:event.isTrusted,inputType:event.inputType,data:type==='paste'?event.clipboardData?.getData('text/plain'):event.data});@@ -277,7 +310,7 @@ try {}return route.continue();});- const worker = context.serviceWorkers()[0] || await context.waitForEvent('serviceworker', { timeout: 30000 });+ worker = context.serviceWorkers()[0] || await context.waitForEvent('serviceworker', { timeout: 30000 });await worker.evaluate(() => {const fetchOriginal = fetch.bind(globalThis);globalThis.inlineFixtureProbe = { commands: [], transports: [], feedback: [], blocked: [] };@@ -337,7 +370,7 @@ try {assert.equal(initial.headings, 0); assert.equal(initial.formsOrDialogs, 0);const tabId = await harness.evaluate(async url => (await chrome.tabs.query({})).findLast(tab => tab.url === url)?.id, fixtureUrl);assert.ok(tabId);- current = { ...specification, page, marker: `Owned inline regression case ${specification.name}.`, requests: [], calls: [],+ current = { ...specification, page, tabId, marker: `Owned inline regression case ${specification.name}.`, requests: [], calls: [],steps: 0, judges: 0, inferenceChanges: 0 };const probeStart = await worker.evaluate(() => ({ commands: inlineFixtureProbe.commands.length,transports: inlineFixtureProbe.transports.length, feedback: inlineFixtureProbe.feedback.length }));@@ -409,11 +442,18 @@ Re-observe the Post button after writing, click it once, then verify the owned lassert.ok(current.afterWrite.events.some(event => ['beforeinput', 'input'].includes(event.type) && event.trusted));assert.ok(current.afterWrite.events.every(event => event.trusted), 'This single-line draft uses browser-trusted input.');assert.equal(current.postReobserved, true, 'Post must receive an independent current AX read after typing.');- assert.equal(clicks.length, 1);- assert.equal(clicks[0].result.dispatched, true, JSON.stringify(clicks));- if (clicks[0].result.success !== true) {- assert.equal(clicks[0].result.outcomeUnknown, true, JSON.stringify(clicks));- assert.equal(clicks[0].result.retryable, false, 'An acknowledged Post must never be retried after observation is interrupted.');+ assert.equal(clicks.length, specification.nativePreparationVeto ? 2 : 1);+ if (specification.nativePreparationVeto) {+ assert.equal(current.postRetryReobserved, true);+ assert.equal(current.preparationVeto.initialTrustedNativeButton, true, JSON.stringify(current.preparationVeto));+ assert.equal(current.preparationVeto.method, 'cdp-native-button');+ assert.equal(current.vetoLedger.submitted, false); assert.equal(current.afterVeto.state.model, body);+ assert.equal(current.audits, 2, 'The native veto must clear provisional authorization and force a fresh audit.');+ }+ assert.equal(clicks.at(-1).result.dispatched, true, JSON.stringify(clicks));+ if (clicks.at(-1).result.success !== true) {+ assert.equal(clicks.at(-1).result.outcomeUnknown, true, JSON.stringify(clicks));+ assert.equal(clicks.at(-1).result.retryable, false, 'An acknowledged Post must never be retried after observation is interrupted.');}const confirmation = tools.findLast(tool => tool.name === 'get_accessibility_tree')?.result?.pageContent || '';assert.match(confirmation, /Owned local QA post recorded:/, 'A fresh installed-extension read must observe the owned save confirmation.');diff --git a/test/social-publish-contract.mjs b/test/social-publish-contract.mjsindex 8457f68bc..86f1def63 100644--- a/test/social-publish-contract.mjs+++ b/test/social-publish-contract.mjs@@ -1046,6 +1046,143 @@ for (const browser of ['chrome', 'firefox']) {assert.deepEqual(agent._missingSocialPublishTargets(guard),['twitter']);});+ const nativePreparationVeto = () => ({ success: false, method: 'cdp-native-button', initialTrustedNativeButton: true,+ trusted: false, verified: false, nativeInputAcknowledged: false, observationInterrupted: false,+ dispatched: false, noDispatch: true, outcomeUnknown: false, retryable: false,+ error: 'The owned native button changed during preparation. Re-observe before acting.' });++ async function preSubmitFixture(platform = 'twitter') {+ const f = setup(`Post Hello on ${platform === 'twitter' ? 'X' : 'Bluesky'}`, rawContract([rawAction('p1', platform)]));+ f.pageUrl = platform === 'twitter' ? 'https://x.com/compose/post' : 'https://bsky.app/';+ f.agent._currentUrl = async () => f.pageUrl;+ f.detected.publicationSnapshot = snapshot('Hello', platform === 'twitter' ? 'twitter:alice' : 'bluesky:alice.bsky.social');+ f.detected.publicationAccountIdentity = f.detected.publicationSnapshot.account;+ f.detected.frameDocumentIdentity = f.pageUrl + '|owned-native-document';+ f.agent._beginCompletionInvariant(f.tabId);+ assert.equal(await f.agent._workflowPreSubmitDispatchBlock(f.tabId, 'click_ax', { ref_id: 'ref_2001' }, f.detected, f.provider), null);+ const binding = f.agent._workflowSubmitBindingForAttempt(f.tabId, f.pageUrl, {}, f.detected);+ assert.equal(binding.socialPublication.actionId, 'p1');+ f.record = (result, detected = f.detected, name = 'click_ax', args = { ref_id: 'ref_2001' }) => {+ f.agent._recordCompletionToolResult(f.tabId, name, args, result);+ return f.agent._recordCompletionSubmitAttempt(f.tabId, detected, name, args, f.pageUrl, f.pageUrl, result,+ 'owned-native-document', 'owned-native-document');+ };+ return f;+ }++ test(`${browser}: a proven native preparation veto releases publication eligibility and requires a fresh audit`, async () => {+ for (const platform of ['twitter', 'bluesky']) {+ const f = await preSubmitFixture(platform), previousKey = f.guard.socialPublication.dispatch.key;+ assert.equal(f.record(nativePreparationVeto()), null);+ assert.deepEqual(f.guard.socialPublication.outcomes, {}, 'No publication was attempted, so fallback branches cannot acquire a failure receipt.');+ assert.equal(f.guard.socialPublication.dispatch, null, 'Preparation authorization cannot silently survive the veto.');+ assert.deepEqual(api.publicationProgress(f.guard.socialPublication.contract, f.guard.socialPublication.outcomes).eligible, ['p1']);+ assert.notEqual(f.agent._completionSubmitStates.get(f.tabId)?.dispatched, true);+ assert.equal(f.guard.verifiedSubmissionEvidence, false);+ assert.equal(f.calls.filter(call => call.meta.generationName === 'social_publication_authorization').length, 1);+ f.agent._recordCompletionToolResult(f.tabId, 'get_accessibility_tree', {}, { success: true, url: f.pageUrl, pageContent: 'Fresh owned composer with exact Hello draft.' });+ assert.equal(await f.agent._workflowPreSubmitDispatchBlock(f.tabId, 'click_ax', { ref_id: 'ref_2002' }, f.detected, f.provider), null);+ assert.equal(f.guard.socialPublication.dispatch.key, previousKey, 'Even the same unchanged draft needs a new audit after the veto.');+ assert.equal(f.calls.filter(call => call.meta.generationName === 'social_publication_contract').length, 1);+ assert.equal(f.calls.filter(call => call.meta.generationName === 'social_publication_authorization').length, 2);+ f.record({ success: true, dispatched: true }, f.detected, 'click_ax', { ref_id: 'ref_2002' });+ assert.equal(f.guard.socialPublication.outcomes.p1.status, 'pending');+ assert.equal((await f.agent._workflowPreSubmitDispatchBlock(f.tabId, 'click_ax', {}, f.detected, f.provider)).noDispatch, true);+ }+ });++ test(`${browser}: authentic confirmation may recompile after a zero-dispatch veto without inventing delivery`, async () => {+ for (const source of ['option', 'user']) for (const platform of ['twitter', 'bluesky']) {+ const f = await preSubmitFixture(platform), previous = f.guard.socialPublication;+ f.record(nativePreparationVeto());+ const answer = await clarify(f, 'Keep the exact Hello draft and publish it from this current account?', 'Yes, keep Hello and publish from this account', source);+ assert.equal(answer.authorized, true);+ const revised = await f.agent._ensureSocialPublicationContract(f.tabId, f.provider);+ assert.notEqual(revised, previous); assert.deepEqual(revised.outcomes, {});+ assert.equal(f.calls.filter(call => call.meta.generationName === 'social_publication_contract').length, 2);+ assert.equal(await f.agent._workflowPreSubmitDispatchBlock(f.tabId, 'click_ax', { ref_id: 'ref_2002' }, f.detected, f.provider), null);+ assert.equal(f.calls.filter(call => call.meta.generationName === 'social_publication_authorization').length, 2);+ assert.notEqual(f.agent._completionSubmitStates.get(f.tabId)?.dispatched, true);+ assert.equal(f.guard.workflowTerminalEvidence, null);+ }+ });++ test(`${browser}: dispatched, ambiguous and conflicting native outcomes never become retryable zero-dispatch`, async () => {+ for (const result of [+ { success: true, dispatched: true },+ { success: false, outcomeUnknown: true, missingToolResponse: true, error: 'Native response was lost.' },+ { ...nativePreparationVeto(), dispatched: true },+ { ...nativePreparationVeto(), outcomeUnknown: true },+ { ...nativePreparationVeto(), missingToolResponse: true },+ { ...nativePreparationVeto(), nativeInputAcknowledged: true },+ ]) {+ const f = await preSubmitFixture();+ f.record(result); const previous = f.guard.socialPublication;+ assert.equal(previous.outcomes.p1.status, 'pending', JSON.stringify(result));+ assert.deepEqual(api.publicationProgress(previous.contract, previous.outcomes).eligible, []);+ await clarify(f, 'Should I retry the uncertain publication?', 'Yes', 'option');+ assert.equal(await f.agent._ensureSocialPublicationContract(f.tabId, f.provider), previous);+ assert.equal((await f.agent._workflowPreSubmitDispatchBlock(f.tabId, 'click_ax', {}, f.detected, f.provider)).noDispatch, true);+ assert.equal(f.calls.filter(call => call.meta.generationName === 'social_publication_contract').length, 1);+ assert.equal(f.calls.filter(call => call.meta.generationName === 'social_publication_authorization').length, 1);+ }+ });++ test(`${browser}: later zero-dispatch preparation preserves the previous pending publication receipt`, async () => {+ for (const { detected, pageUrl } of [+ { detected: { isSubmit: true, publicationControl: false } },+ { detected: { isSubmit: false, resolvedNonSubmitTarget: true } },+ { detected: null },+ { detected: { isSubmit: true, publicationControl: false }, pageUrl: 'https://ordinary.example/settings' },+ ]) {+ const f = await preSubmitFixture();+ const submit = f.record({ success: false, dispatched: true, outcomeUnknown: true, error: 'Owned native click outcome is unknown.' });+ const frozen = structuredClone(submit), outcomes = structuredClone(f.guard.socialPublication.outcomes);+ if (pageUrl) f.pageUrl = pageUrl;+ f.record(nativePreparationVeto(), detected);+ assert.equal(f.agent._completionSubmitStates.get(f.tabId), submit, 'A failed preparation cannot replace an older potentially dispatched submit.');+ assert.deepEqual(submit, frozen); assert.deepEqual(f.guard.socialPublication.outcomes, outcomes);+ f.pageUrl = 'https://x.com/compose/post';+ assert.equal((await f.agent._workflowPreSubmitDispatchBlock(f.tabId, 'click_ax', {}, f.detected, f.provider)).noDispatch, true);+ }+ });++ test(`${browser}: zero dispatch restores only the matching consumed audit Retry, never an uncertain prior attempt`, async () => {+ for (const mode of ['zero-dispatch', 'uncertain', 'prior-consumed', 'forged-receipt']) {+ const f = await failedAuditFixture(), grant = f.failure.failureRecovery;+ assert.equal(f.agent._grantSocialPublicationAuditRetry(f.tabId, grant), true);+ assert.equal(await f.agent._workflowPreSubmitDispatchBlock(f.tabId, 'click_ax', {}, f.detected, f.provider), null);+ f.agent._beginCompletionInvariant(f.tabId);+ const consumed = f.agent._consumeSocialPublicationAuditRetry(f.tabId);+ assert.equal(consumed, f.guard.socialPublication.retryBypass);+ assert.equal(f.guard.socialPublication.retryBypass.consumed, true);+ const record = (result, receipt) => f.agent._recordCompletionSubmitAttempt(f.tabId, f.detected, 'click_ax', {},+ 'https://x.com/compose/post', 'https://x.com/compose/post', result, '', '',+ { ...(receipt ? { socialPublicationAuditRetryConsumed: receipt } : {}) });+ if (mode === 'uncertain') record({ success: false, dispatched: true, outcomeUnknown: true, error: 'Native acknowledgement lost.' }, consumed);+ const previousSubmit = f.agent._completionSubmitStates.get(f.tabId);+ const dispatch = f.guard.socialPublication.dispatch;+ assert.equal(record(nativePreparationVeto(), mode === 'zero-dispatch' ? consumed : mode === 'forged-receipt' ? { ...consumed } : null), null);+ if (mode !== 'zero-dispatch') {+ assert.equal(f.agent._completionSubmitStates.get(f.tabId), previousSubmit);+ assert.equal(f.guard.socialPublication.dispatch, dispatch, 'A grant consumed by another attempt cannot be restored from a later veto.');+ assert.equal(f.guard.socialPublication.retryBypass.consumed, true);+ assert.equal(f.guard.socialPublication.retryBypassUsed[grant.publicationKey], true);+ if (mode === 'uncertain') assert.equal(f.guard.socialPublication.outcomes.p1.status, 'pending');+ else assert.deepEqual(f.guard.socialPublication.outcomes, {});+ assert.equal((await f.agent._workflowPreSubmitDispatchBlock(f.tabId, 'click_ax', {}, f.detected, f.provider)).noDispatch, true);+ } else {+ assert.equal(f.guard.socialPublication.dispatch, null);+ assert.equal(f.guard.socialPublication.retryBypass.consumed, false);+ assert.notEqual(f.guard.socialPublication.retryBypassUsed[grant.publicationKey], true);+ f.agent._recordCompletionToolResult(f.tabId, 'get_accessibility_tree', {}, { success: true, url: 'https://x.com/compose/post', pageContent: 'Fresh unchanged owned composer.' });+ assert.equal(await f.agent._workflowPreSubmitDispatchBlock(f.tabId, 'click_ax', {}, f.detected, f.provider), null);+ assert.equal(f.guard.socialPublication.dispatch.auditBypassed, true);+ assert.equal(f.auditCalls, 2, 'The same explicit audit-bypass grant survives only proven zero dispatch.');+ }+ }+ });+test(`${browser}: the selected provider can compile and audit repeated cross-platform payloads`, async () => {const raw=rawContract([rawAction('p1','twitter'),rawAction('p2','bluesky')],{kind:'all',items:['p1','p2']});raw.actions.forEach((action,index)=>{action.posts[0].body.source.startOccurrence=index+1;});