fix(web): share artifact files instead of URLs

This commit is contained in:
2026-10-21 12:36:06 +01:00
parent 93be42b06e
commit 870c70aefa
10 changed files with 204 additions and 16 deletions
+37 -1
View File
@@ -27,6 +27,14 @@ const image={name:'public/pixel.png',url:'/artifacts/18/1/public/pixel.png',cont
const step={stage:'research',sequence:1,status:'completed',outcome:'success',artifacts:[report,documentFile,image,session],session_id:'ses_fixture',session_export:{html:'session.html',messages:2,status:'complete'}};
const state={url:'ws://'+location.host+'/connect',selectedRunId:18,artifactView:'gallery',runDetail:{id:18,steps:[step]}};
window.routes=[];window.handoffs=[];window.copied=[];
window.shared=[];window.shareMode='success';window.fileReadyActivation=true;
Object.defineProperty(navigator,'userActivation',{configurable:true,value:{get isActive(){return fileReadyActivation;}}});
Object.defineProperty(navigator,'canShare',{configurable:true,value:({files})=>files?.length===1&&files[0] instanceof File});
Object.defineProperty(navigator,'share',{configurable:true,value:async data=>{
if(shareMode==='cancel')throw new DOMException('Canceled','AbortError');
if(shareMode==='deny')throw new DOMException('Denied','NotAllowedError');
const f=data.files[0];shared.push({keys:Object.keys(data),name:f.name,type:f.type,bytes:[...new Uint8Array(await f.arrayBuffer())]});
}});
const rt={state,modal:createModalController(),repo:{},views:{},renderContent:()=>{},selectRun:id=>routes.push(id)};
rt.views.chat=createChatView(rt);rt.views.dialogs=createDialogsView(rt);rt.views.runDetail=createRunDetailView(rt);
const host=document.querySelector('#content');
@@ -84,6 +92,34 @@ try {
await eventually(async()=>(await targets()).some(t=>t.url===origin+'/artifacts/18/1/public/pixel.png'));
assert.equal(await page.evaluate('location.href'),appURL);
assert.equal(await page.evaluate("!!document.querySelector('.artifact-viewer')"),false);
const imageShare='[data-artifact-name="public/pixel.png"] + .artifact-actions [aria-label="Share"]';
await page.click(imageShare);
await eventually(()=>page.evaluate('shared.length===1'));
const file=await page.evaluate('shared[0]');
assert.deepEqual(file.keys,['files']);assert.equal(file.name,'pixel.png');assert.equal(file.type,'image/png');
assert.deepEqual(file.bytes,[...Buffer.from('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII=','base64')]);
await page.evaluate("shareMode='cancel'");await page.click(imageShare);await page.waitForText('Sharing canceled.');
await page.evaluate("shareMode='deny'");await page.click(imageShare);await page.waitForText('Sharing was blocked.');
await page.screenshot(resolve(out,'06-file-share-blocked-mobile.png'));
await page.evaluate("shareMode='success';fileReadyActivation=false");await page.click(imageShare);await page.waitForText('File ready.');
await page.screenshot(resolve(out,'06-file-ready-retap-mobile.png'));
await page.evaluate('fileReadyActivation=true');await page.click(imageShare);await eventually(()=>page.evaluate('shared.length===2'));
await page.click('[data-artifact-name="public/pixel.png"]');await page.waitForSelector('.artifact-viewer');
await page.click('[data-viewer-focus=share]');await eventually(()=>page.evaluate('shared.length===3'));
assert.deepEqual(await page.evaluate('shared[2]'),file,'viewer shares the same file bytes and metadata');
await page.screenshot(resolve(out,'06-viewer-file-share-mobile.png'));
for (const width of [420,1100]) {
await page.resize(width,844);
assert.equal(await page.evaluate('document.documentElement.scrollWidth<=innerWidth'),true);
await page.screenshot(resolve(out,`06-viewer-file-share-${width}.png`));
}
await page.pressKey('Escape');
await page.evaluate('showList()');await page.click('#listFixture .artifact-list-row:last-child [aria-label=Share]');
await eventually(()=>page.evaluate('shared.length===4'));assert.deepEqual(await page.evaluate('shared[3]'),file);
await page.resize(390,844);
await page.evaluate("Object.defineProperty(navigator,'canShare',{configurable:true,value:undefined});showVisit()");
assert.equal(await page.evaluate("document.querySelector('#visitFixture [aria-label=Share]').disabled"),true);
await page.screenshot(resolve(out,'06-file-sharing-unsupported-mobile.png'));
const android = await browser.openPage("about:blank");
await android.emulateTouch(true);
@@ -160,7 +196,7 @@ try {
assert.equal(await android.evaluate("handoffs.length"), 10, "search results must use the same browser hand-off");
assert.equal(await android.evaluate("location.href"), original);
assert.deepEqual(await android.evaluate("routes"), []);
console.log("PASS: images preview on primary gallery/list/visit activation; external icons hand off without opening the viewer; keyboard/focus and mobile fit pass. Other artifact, chat, session, search and viewer browser actions retain safe hand-off. Android OS launch is not tested.");
console.log("PASS: primary image previews, external hand-off, and exact named/typed file-byte sharing from gallery/list/viewer; cancellation, blocked/unsupported sharing and fresh-tap preparation are truthful. Real Chrome uses a stubbed Share API; native OS chooser/delivery and Android OS launch are not tested.");
} finally {
await browser?.close();
await new Promise(r => server.close(r));