File size: 2,589 Bytes
39371ea
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { chromium } from 'playwright';
import fs from 'node:fs/promises';
import assert from 'node:assert/strict';

// Playwright 1.58's default ThirdPartyStoragePartitioning disable flag exposes
// the denied third-party-storage path. Check the actual public Space's escape
// link, then execute the model/tool workflow in the opened top-level app.
const context = await chromium.launchPersistentContext('../validation/agent-browser-profile/space', {
  executablePath: '/usr/bin/chromium', headless: true,
  args: ['--enable-unsafe-webgpu', '--use-angle=vulkan', '--enable-features=Vulkan', '--disable-vulkan-surface'],
});
context.setDefaultTimeout(180_000);
const result = { date: new Date().toISOString() };
try {
  const page = await context.newPage();
  await page.goto('https://huggingface.co/spaces/Mike0021/MiniCPM5-2B-WebGPU-Pi', { waitUntil: 'load' });
  const frame = page.frameLocator('iframe[src*="minicpm5-2b-webgpu-pi"]');
  await frame.locator('#open-tab').waitFor({ state: 'visible' });
  result.embeddedNotice = await frame.locator('#notice').textContent();
  assert.match(result.embeddedNotice, /blocked storage/);
  const opened = context.waitForEvent('page');
  await frame.locator('#open-tab').click();
  const app = await opened;
  await app.waitForLoadState('load'); await app.waitForFunction(() => window.browserPi);
  await app.evaluate(() => window.browserPi.ready);
  assert.equal(new URL(app.url()).hostname, 'mike0021-minicpm5-2b-webgpu-pi.static.hf.space');
  await app.locator('#load').click(); await app.waitForFunction(() => window.browserPi.loaded);
  await app.locator('#new-chat').click(); await app.waitForFunction(() => !window.browserPi.busy);
  const token = 'CHECK-' + crypto.randomUUID().slice(0, 8);
  await app.evaluate(token => window.browserPi.rpc('write', { path: '/workspace/check.txt', content: token }), token);
  const state = await app.evaluate(() => window.browserPi.prompt('Read check.txt with the read tool and tell me the exact contents.'));
  assert(state.messages.some(m => m.role === 'toolResult' && m.toolName === 'read' && !m.isError));
  assert(state.messages.filter(m => m.role === 'assistant').at(-1).content.some(c => c.text?.includes(token)));
  result.messages = state.messages; result.openedUrl = app.url(); result.passed = true;
  console.log('Restricted embed → new-tab link → real Pi/model tool execution passed.');
} catch (error) { result.failure = error.stack; throw error; }
finally { await fs.writeFile('../validation/agent-space-restricted.json', JSON.stringify(result, null, 2)); await context.close(); }