Skip to content

Open-source AI browser agent for Chrome and Firefox (monorepo) 🧠

fix(social-publish): canonicalize reply resource identity

Emre Sokullu33a436678596
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.js
index 8f007f9c0..a4f72077c 100644
--- a/src/chrome/src/agent/agent.js
+++ b/src/chrome/src/agent/agent.js
@@ -17980,6 +17980,16 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
return copy;
}
+ _sameSocialPublicationResource(platform, left, right) {
+ const workflow = { adapterName: platform };
+ const leftIdentity = this._workflowPublishedResourceIdentity(workflow, left);
+ const rightIdentity = this._workflowPublishedResourceIdentity(workflow, right);
+ // Resource identity deliberately canonicalizes X's x.com/twitter.com host
+ // aliases and ignores presentation-only query/hash fragments. Unknown or
+ // malformed URLs never compare equal.
+ return !!leftIdentity && leftIdentity === rightIdentity;
+ }
+
_socialSnapshotMatchesAction(action, snapshot) {
if (!snapshot?.complete || snapshot.posts?.length !== action.posts.length || !snapshot.account) return false;
const workflow = { adapterName: action.platform };
@@ -17992,7 +18002,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
&& (post.body.kind === 'compose' || exactPublicationText(post.body.value) === exactPublicationText(observed.bodyText))
&& publicationMediaMatches(post.media, observed)
&& observed.context?.kind === post.context.kind
- && (post.context.target === null || this._normalizeUrl(post.context.target) === this._normalizeUrl(observed.context.target));
+ && (post.context.target === null || this._sameSocialPublicationResource(action.platform, post.context.target, observed.context.target));
});
}
@@ -18076,7 +18086,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
const matches = records.filter(record => {
const identity = this._workflowPublishedResourceIdentity(guard.siteWorkflow, record.url);
if (!identity || used.has(identity) || (i === 0 && identity !== binding.publishedResourceIdentity)) return false;
- if (i > 0 && this._normalizeUrl(record.replyToUrl || '') !== this._normalizeUrl(previousUrl)) return false;
+ if (i > 0 && !this._sameSocialPublicationResource(action.platform, record.replyToUrl, previousUrl)) return false;
const author = this._workflowSocialPublicationAccountIdentity(guard.siteWorkflow, record.url);
if (author !== account && !this._workflowSocialAccountAliasProven(guard.siteWorkflow, account, author, record)) return false;
const mediaRecord = this._workflowSocialRecordWithUploadedAttachmentNames(record, binding);
@@ -18086,10 +18096,10 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
&& (i > 0 ? !(record.contextUrls?.length) : post.context.kind === 'post'
? !(record.contextUrls?.length) && !record.replyToUrl
: post.context.kind === 'reply'
- ? this._normalizeUrl(record.replyToUrl || '') === this._normalizeUrl(post.context.target)
+ ? this._sameSocialPublicationResource(action.platform, record.replyToUrl, post.context.target)
&& !(record.contextUrls?.length)
: !record.replyToUrl && (record.contextUrls || []).length === 1
- && this._normalizeUrl(record.contextUrls[0]) === this._normalizeUrl(post.context.target));
+ && this._sameSocialPublicationResource(action.platform, record.contextUrls[0], post.context.target));
});
if (matches.length !== 1) return false;
used.add(this._workflowPublishedResourceIdentity(guard.siteWorkflow, matches[0].url));
diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.js
index a04dc434e..6fbefa52f 100644
--- a/src/firefox/src/agent/agent.js
+++ b/src/firefox/src/agent/agent.js
@@ -15779,6 +15779,16 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
return copy;
}
+ _sameSocialPublicationResource(platform, left, right) {
+ const workflow = { adapterName: platform };
+ const leftIdentity = this._workflowPublishedResourceIdentity(workflow, left);
+ const rightIdentity = this._workflowPublishedResourceIdentity(workflow, right);
+ // Resource identity deliberately canonicalizes X's x.com/twitter.com host
+ // aliases and ignores presentation-only query/hash fragments. Unknown or
+ // malformed URLs never compare equal.
+ return !!leftIdentity && leftIdentity === rightIdentity;
+ }
+
_socialSnapshotMatchesAction(action, snapshot) {
if (!snapshot?.complete || snapshot.posts?.length !== action.posts.length || !snapshot.account) return false;
const workflow = { adapterName: action.platform };
@@ -15791,7 +15801,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
&& (post.body.kind === 'compose' || exactPublicationText(post.body.value) === exactPublicationText(observed.bodyText))
&& publicationMediaMatches(post.media, observed)
&& observed.context?.kind === post.context.kind
- && (post.context.target === null || this._normalizeUrl(post.context.target) === this._normalizeUrl(observed.context.target));
+ && (post.context.target === null || this._sameSocialPublicationResource(action.platform, post.context.target, observed.context.target));
});
}
@@ -15875,7 +15885,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
const matches = records.filter(record => {
const identity = this._workflowPublishedResourceIdentity(guard.siteWorkflow, record.url);
if (!identity || used.has(identity) || (i === 0 && identity !== binding.publishedResourceIdentity)) return false;
- if (i > 0 && this._normalizeUrl(record.replyToUrl || '') !== this._normalizeUrl(previousUrl)) return false;
+ if (i > 0 && !this._sameSocialPublicationResource(action.platform, record.replyToUrl, previousUrl)) return false;
const author = this._workflowSocialPublicationAccountIdentity(guard.siteWorkflow, record.url);
if (author !== account && !this._workflowSocialAccountAliasProven(guard.siteWorkflow, account, author, record)) return false;
const mediaRecord = this._workflowSocialRecordWithUploadedAttachmentNames(record, binding);
@@ -15885,10 +15895,10 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
&& (i > 0 ? !(record.contextUrls?.length) : post.context.kind === 'post'
? !(record.contextUrls?.length) && !record.replyToUrl
: post.context.kind === 'reply'
- ? this._normalizeUrl(record.replyToUrl || '') === this._normalizeUrl(post.context.target)
+ ? this._sameSocialPublicationResource(action.platform, record.replyToUrl, post.context.target)
&& !(record.contextUrls?.length)
: !record.replyToUrl && (record.contextUrls || []).length === 1
- && this._normalizeUrl(record.contextUrls[0]) === this._normalizeUrl(post.context.target));
+ && this._sameSocialPublicationResource(action.platform, record.contextUrls[0], post.context.target));
});
if (matches.length !== 1) return false;
used.add(this._workflowPublishedResourceIdentity(guard.siteWorkflow, matches[0].url));
diff --git a/test/social-publish-contract.mjs b/test/social-publish-contract.mjs
index f02048c79..fda5798de 100644
--- a/test/social-publish-contract.mjs
+++ b/test/social-publish-contract.mjs
@@ -288,23 +288,23 @@ for (const browser of ['chrome', 'firefox']) {
const parent='https://x.com/bob/status/1111111111111111111';
const other='https://x.com/carol/status/3333333333333333333';
const action=rawAction('p1','twitter');action.posts[0].context={kind:'reply',target:ref(parent)};
- for(const mode of ['matching','different','missing','changed']){
+ for(const mode of ['matching','host-alias','different','missing','changed']){
const f=setup(`Reply exactly Hello to ${parent} on X`,rawContract([action]));
f.agent._currentUrl=async()=>parent;
- f.detected.publicationSnapshot.posts[0].context={kind:'reply',target:mode==='different'?other:mode==='missing'?null:parent};
+ f.detected.publicationSnapshot.posts[0].context={kind:'reply',target:mode==='host-alias'?parent.replace('x.com','twitter.com')+'?s=20#reply':mode==='different'?other:mode==='missing'?null:parent};
if(mode==='missing') f.detected.publicationSnapshot.complete=false;
if(mode==='changed') f.agent._detectLikelySubmitAction=async()=>{
const fresh=structuredClone(f.detected);fresh.publicationSnapshot.posts[0].context.target=other;return fresh;
};
const block=await f.agent._workflowPreSubmitDispatchBlock(f.tabId,'click_ax',{},f.detected,f.provider);
- if(mode==='matching'){
+ if(mode==='matching'||mode==='host-alias'){
assert.equal(block,null);
- assert.equal(f.guard.socialPublication.dispatch.snapshot.posts[0].context.target,parent);
+ assert.equal(f.guard.socialPublication.dispatch.snapshot.posts[0].context.target,mode==='host-alias'?parent.replace('x.com','twitter.com')+'?s=20#reply':parent);
} else {
assert.equal(block.noDispatch,true,mode);
assert.equal(f.guard.socialPublication.dispatch,null,mode);
}
- assert.equal(f.calls.length,mode==='matching'||mode==='changed'?2:1,'a missing/wrong parent cannot be supplied by the contract or audit');
+ assert.equal(f.calls.length,mode==='matching'||mode==='host-alias'||mode==='changed'?2:1,'a missing/wrong parent cannot be supplied by the contract or audit');
}
});