@open-mercato/ai-assistant 0.10.1-develop.7866.1.71cf6e2699 → 0.10.1-develop.7874.1.67e097d23a

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- [build:ai-assistant] found 249 entry points
1
+ [build:ai-assistant] found 250 entry points
2
2
  [build:ai-assistant] built successfully
@@ -0,0 +1,138 @@
1
+ import { test, expect } from "@playwright/test";
2
+ import { build } from "esbuild";
3
+ import path from "node:path";
4
+ import { fileURLToPath } from "node:url";
5
+ import { createRequire } from "node:module";
6
+ const canary = "https://ai-image-canary.invalid/pixel?data=inert";
7
+ const typedParts = [
8
+ ["product", "imageUrl"],
9
+ ["person", "avatarUrl"],
10
+ ["company", "logoUrl"]
11
+ ].map(([kind, field]) => ({
12
+ componentId: `open-mercato.${kind}-card`,
13
+ payload: { name: `Visible typed ${kind}`, [field]: canary, kind: "deal" }
14
+ }));
15
+ const content = [
16
+ "**Visible answer**",
17
+ `![Inline image](${canary})`,
18
+ `![Reference image][canary]
19
+
20
+ [canary]: ${canary}`,
21
+ "![Relative image](/canary?data=inert)",
22
+ "![Protocol image](//ai-image-canary.invalid/pixel?data=inert)",
23
+ `<img src="${canary}" alt="Raw HTML image">`,
24
+ "| Detail | Value |\n| --- | --- |\n| Status | Available |",
25
+ "[Ordinary link](https://example.invalid/details)",
26
+ ...[
27
+ ["product", "imageUrl"],
28
+ ["product", "image"],
29
+ ["person", "avatarUrl"],
30
+ ["person", "avatar"],
31
+ ["company", "logoUrl"],
32
+ ["company", "logo"]
33
+ ].map(([kind, field], index) => {
34
+ const payload = JSON.stringify({ name: `Visible ${kind} ${index}`, [field]: canary });
35
+ return index % 2 === 0 ? `\`\`\`open-mercato:${kind}
36
+ ${payload}
37
+ \`\`\`` : `open-mercato:${kind} ${payload}`;
38
+ })
39
+ ].join("\n\n");
40
+ let bundle;
41
+ test.beforeAll(async () => {
42
+ const require2 = createRequire(import.meta.url);
43
+ const sourceRoot = (packageName) => path.resolve(path.dirname(require2.resolve(packageName)), "../src");
44
+ const result = await build({
45
+ bundle: true,
46
+ write: false,
47
+ platform: "browser",
48
+ format: "iife",
49
+ jsx: "automatic",
50
+ define: { "process.env.NODE_ENV": '"production"', "process.env": "{}" },
51
+ alias: {
52
+ "@open-mercato/ui": sourceRoot("@open-mercato/ui"),
53
+ "@open-mercato/shared": sourceRoot("@open-mercato/shared"),
54
+ "@open-mercato/ai-assistant": sourceRoot("@open-mercato/ai-assistant")
55
+ },
56
+ stdin: {
57
+ resolveDir: path.dirname(fileURLToPath(import.meta.url)),
58
+ loader: "tsx",
59
+ contents: `
60
+ import * as React from 'react'
61
+ import { createRoot } from 'react-dom/client'
62
+ import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
63
+ import { I18nProvider } from '@open-mercato/shared/lib/i18n/context'
64
+ import { AiChat } from '@open-mercato/ui/ai/AiChat'
65
+ import { AiMessageContent } from '@open-mercato/ui/ai/AiMessageContent'
66
+ import '@open-mercato/ui/ai/records/registry'
67
+ const content = ${JSON.stringify(content)}
68
+ const uiParts = ${JSON.stringify(typedParts)}
69
+ createRoot(document.getElementById('root')).render(
70
+ <QueryClientProvider client={new QueryClient()}>
71
+ <I18nProvider locale="en" dict={{}}>
72
+ {location.search === '?chat'
73
+ ? <AiChat agentId="image-policy.test" conversationId="image-policy" initialMessages={[{ role: 'assistant', content }]} uiParts={uiParts} />
74
+ : <AiMessageContent content={content} />}
75
+ </I18nProvider>
76
+ </QueryClientProvider>
77
+ )
78
+ `
79
+ }
80
+ });
81
+ bundle = result.outputFiles[0].text;
82
+ });
83
+ for (const surface of ["chat", "standalone"]) {
84
+ test(`TC-AI-IMAGE-001: ${surface} makes no requests for model-supplied images`, async ({ page }, testInfo) => {
85
+ const imageRequests = [];
86
+ const errors = [];
87
+ page.on("pageerror", (error) => errors.push(error.message));
88
+ await page.route("**/*", async (route) => {
89
+ const url = new URL(route.request().url());
90
+ if (url.hostname === "ai-image-canary.invalid" || url.pathname === "/canary") {
91
+ imageRequests.push(url.href);
92
+ await route.abort();
93
+ } else if (url.pathname.startsWith("/api/")) {
94
+ await route.fulfill({ json: {
95
+ providers: [],
96
+ allowRuntimeModelOverride: false,
97
+ conversation: { conversationId: "image-policy", isOwner: true },
98
+ messages: [{ id: "answer", role: "assistant", content, uiParts: typedParts, attachmentIds: [], files: [] }]
99
+ } });
100
+ } else {
101
+ await route.fulfill({ contentType: "text/html", body: '<div id="root"></div>' });
102
+ }
103
+ });
104
+ await page.goto(`http://ai-image-policy.test/?${surface}`);
105
+ await page.evaluate((url) => {
106
+ const image = document.createElement("img");
107
+ image.src = url;
108
+ document.body.append(image);
109
+ }, canary);
110
+ await expect.poll(() => imageRequests.length).toBe(1);
111
+ await page.locator("body > img").evaluate((image) => image.remove());
112
+ imageRequests.length = 0;
113
+ await page.addScriptTag({ content: bundle });
114
+ const answer = page.locator("[data-ai-message-content]");
115
+ await expect.poll(async () => ({ text: await page.locator("#root").innerText(), errors })).toMatchObject({ text: expect.stringContaining("Visible answer"), errors: [] });
116
+ await expect(answer.getByText("Visible answer", { exact: true })).toBeVisible();
117
+ await expect(answer.getByText("Visible product 0", { exact: true })).toBeVisible();
118
+ await expect(answer.getByText("Visible person 3", { exact: true })).toBeVisible();
119
+ await expect(answer.getByText("Visible company 5", { exact: true })).toBeVisible();
120
+ await expect(answer.getByRole("table")).toBeVisible();
121
+ await expect(answer.getByRole("link", { name: "Ordinary link" })).toHaveAttribute("href", "https://example.invalid/details");
122
+ if (surface === "chat") {
123
+ for (const kind of ["product", "person", "company"]) {
124
+ await expect(page.locator("#root").getByText(`Visible typed ${kind}`, { exact: true })).toHaveCount(2);
125
+ }
126
+ }
127
+ await page.waitForLoadState("networkidle");
128
+ expect(errors).toEqual([]);
129
+ expect(imageRequests).toEqual([]);
130
+ await expect(page.locator("#root img")).toHaveCount(0);
131
+ await expect(answer).toContainText("Inline image");
132
+ await expect(answer).toContainText("Reference image");
133
+ const screenshotPath = testInfo.outputPath(`${surface}-image-policy.png`);
134
+ await page.screenshot({ path: screenshotPath });
135
+ await testInfo.attach(`${surface}-image-policy`, { path: screenshotPath, contentType: "image/png" });
136
+ });
137
+ }
138
+ //# sourceMappingURL=TC-AI-IMAGE-001.spec.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/modules/ai_assistant/__integration__/TC-AI-IMAGE-001.spec.ts"],
4
+ "sourcesContent": ["import { test, expect } from '@playwright/test'\nimport { build } from 'esbuild'\nimport path from 'node:path'\nimport { fileURLToPath } from 'node:url'\nimport { createRequire } from 'node:module'\n\nconst canary = 'https://ai-image-canary.invalid/pixel?data=inert'\nconst typedParts = [\n ['product', 'imageUrl'],\n ['person', 'avatarUrl'],\n ['company', 'logoUrl'],\n].map(([kind, field]) => ({\n componentId: `open-mercato.${kind}-card`,\n payload: { name: `Visible typed ${kind}`, [field]: canary, kind: 'deal' },\n}))\nconst content = [\n '**Visible answer**',\n `![Inline image](${canary})`,\n `![Reference image][canary]\\n\\n[canary]: ${canary}`,\n '![Relative image](/canary?data=inert)',\n '![Protocol image](//ai-image-canary.invalid/pixel?data=inert)',\n `<img src=\"${canary}\" alt=\"Raw HTML image\">`,\n '| Detail | Value |\\n| --- | --- |\\n| Status | Available |',\n '[Ordinary link](https://example.invalid/details)',\n ...[\n ['product', 'imageUrl'],\n ['product', 'image'],\n ['person', 'avatarUrl'],\n ['person', 'avatar'],\n ['company', 'logoUrl'],\n ['company', 'logo'],\n ].map(([kind, field], index) => {\n const payload = JSON.stringify({ name: `Visible ${kind} ${index}`, [field]: canary })\n return index % 2 === 0\n ? `\\`\\`\\`open-mercato:${kind}\\n${payload}\\n\\`\\`\\``\n : `open-mercato:${kind} ${payload}`\n }),\n].join('\\n\\n')\n\nlet bundle: string\n\ntest.beforeAll(async () => {\n const require = createRequire(import.meta.url)\n const sourceRoot = (packageName: string) => path.resolve(path.dirname(require.resolve(packageName)), '../src')\n const result = await build({\n bundle: true,\n write: false,\n platform: 'browser',\n format: 'iife',\n jsx: 'automatic',\n define: { 'process.env.NODE_ENV': '\"production\"', 'process.env': '{}' },\n alias: {\n '@open-mercato/ui': sourceRoot('@open-mercato/ui'),\n '@open-mercato/shared': sourceRoot('@open-mercato/shared'),\n '@open-mercato/ai-assistant': sourceRoot('@open-mercato/ai-assistant'),\n },\n stdin: {\n resolveDir: path.dirname(fileURLToPath(import.meta.url)),\n loader: 'tsx',\n contents: `\n import * as React from 'react'\n import { createRoot } from 'react-dom/client'\n import { QueryClient, QueryClientProvider } from '@tanstack/react-query'\n import { I18nProvider } from '@open-mercato/shared/lib/i18n/context'\n import { AiChat } from '@open-mercato/ui/ai/AiChat'\n import { AiMessageContent } from '@open-mercato/ui/ai/AiMessageContent'\n import '@open-mercato/ui/ai/records/registry'\n const content = ${JSON.stringify(content)}\n const uiParts = ${JSON.stringify(typedParts)}\n createRoot(document.getElementById('root')).render(\n <QueryClientProvider client={new QueryClient()}>\n <I18nProvider locale=\"en\" dict={{}}>\n {location.search === '?chat'\n ? <AiChat agentId=\"image-policy.test\" conversationId=\"image-policy\" initialMessages={[{ role: 'assistant', content }]} uiParts={uiParts} />\n : <AiMessageContent content={content} />}\n </I18nProvider>\n </QueryClientProvider>\n )\n `,\n },\n })\n bundle = result.outputFiles[0].text\n})\n\nfor (const surface of ['chat', 'standalone']) {\n test(`TC-AI-IMAGE-001: ${surface} makes no requests for model-supplied images`, async ({ page }, testInfo) => {\n const imageRequests: string[] = []\n const errors: string[] = []\n page.on('pageerror', (error) => errors.push(error.message))\n await page.route('**/*', async (route) => {\n const url = new URL(route.request().url())\n if (url.hostname === 'ai-image-canary.invalid' || url.pathname === '/canary') {\n imageRequests.push(url.href)\n await route.abort()\n } else if (url.pathname.startsWith('/api/')) {\n await route.fulfill({ json: {\n providers: [],\n allowRuntimeModelOverride: false,\n conversation: { conversationId: 'image-policy', isOwner: true },\n messages: [{ id: 'answer', role: 'assistant', content, uiParts: typedParts, attachmentIds: [], files: [] }],\n } })\n } else {\n await route.fulfill({ contentType: 'text/html', body: '<div id=\"root\"></div>' })\n }\n })\n await page.goto(`http://ai-image-policy.test/?${surface}`)\n await page.evaluate((url) => {\n const image = document.createElement('img')\n image.src = url\n document.body.append(image)\n }, canary)\n await expect.poll(() => imageRequests.length).toBe(1)\n await page.locator('body > img').evaluate((image) => image.remove())\n imageRequests.length = 0\n\n await page.addScriptTag({ content: bundle })\n const answer = page.locator('[data-ai-message-content]')\n await expect.poll(async () => ({ text: await page.locator('#root').innerText(), errors }))\n .toMatchObject({ text: expect.stringContaining('Visible answer'), errors: [] })\n await expect(answer.getByText('Visible answer', { exact: true })).toBeVisible()\n await expect(answer.getByText('Visible product 0', { exact: true })).toBeVisible()\n await expect(answer.getByText('Visible person 3', { exact: true })).toBeVisible()\n await expect(answer.getByText('Visible company 5', { exact: true })).toBeVisible()\n await expect(answer.getByRole('table')).toBeVisible()\n await expect(answer.getByRole('link', { name: 'Ordinary link' })).toHaveAttribute('href', 'https://example.invalid/details')\n if (surface === 'chat') {\n for (const kind of ['product', 'person', 'company']) {\n await expect(page.locator('#root').getByText(`Visible typed ${kind}`, { exact: true })).toHaveCount(2)\n }\n }\n await page.waitForLoadState('networkidle')\n expect(errors).toEqual([])\n expect(imageRequests).toEqual([])\n await expect(page.locator('#root img')).toHaveCount(0)\n await expect(answer).toContainText('Inline image')\n await expect(answer).toContainText('Reference image')\n const screenshotPath = testInfo.outputPath(`${surface}-image-policy.png`)\n await page.screenshot({ path: screenshotPath })\n await testInfo.attach(`${surface}-image-policy`, { path: screenshotPath, contentType: 'image/png' })\n })\n}\n"],
5
+ "mappings": "AAAA,SAAS,MAAM,cAAc;AAC7B,SAAS,aAAa;AACtB,OAAO,UAAU;AACjB,SAAS,qBAAqB;AAC9B,SAAS,qBAAqB;AAE9B,MAAM,SAAS;AACf,MAAM,aAAa;AAAA,EACjB,CAAC,WAAW,UAAU;AAAA,EACtB,CAAC,UAAU,WAAW;AAAA,EACt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Q;AACtB,iBAAW,QAAQ,CAAC,WAAW,UAAU,SAAS,GAAG;AACnD,cAAM,OAAO,KAAK,QAAQ,OAAO,EAAE,UAAU,iBAAiB,IAAI,IAAI,EAAE,OAAO,KAAK,CAAC,CAAC,EAAE,YAAY,CAAC;AAAA,MACvG;AAAA,IACF;AACA,UAAM,KAAK,iBAAiB,aAAa;AACzC,WAAO,MAAM,EAAE,QAAQ,CAAC,CAAC;AACzB,WAAO,aAAa,EAAE,QAAQ,CAAC,CAAC;AAChC,UAAM,OAAO,KAAK,QAAQ,WAAW,CAAC,EAAE,YAAY,CAAC;AACrD,UAAM,OAAO,MAAM,EAAE,cAAc,cAAc;AACjD,UAAM,OAAO,MAAM,EAAE,cAAc,iBAAiB;AACpD,UAAM,iBAAiB,SAAS,WAAW,GAAG,OAAO,mBAAmB;AACxE,UAAM,KAAK,WAAW,EAAE,MAAM,eAAe,CAAC;AAC9C,UAAM,SAAS,OAAO,GAAG,OAAO,iBAAiB,EAAE,MAAM,gBAAgB,aAAa,YAAY,CAAC;AAAA,EACrG,CAAC;AACH;",
6
+ "names": ["require"]
7
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-mercato/ai-assistant",
3
- "version": "0.10.1-develop.7866.1.71cf6e2699",
3
+ "version": "0.10.1-develop.7874.1.67e097d23a",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "engines": {
@@ -103,16 +103,16 @@
103
103
  "zod-to-json-schema": "^3.25.2"
104
104
  },
105
105
  "peerDependencies": {
106
- "@open-mercato/shared": "0.10.1-develop.7866.1.71cf6e2699",
107
- "@open-mercato/ui": "0.10.1-develop.7866.1.71cf6e2699",
106
+ "@open-mercato/shared": "0.10.1-develop.7874.1.67e097d23a",
107
+ "@open-mercato/ui": "0.10.1-develop.7874.1.67e097d23a",
108
108
  "react": "^19.0.0",
109
109
  "react-dom": "^19.0.0",
110
110
  "zod": ">=3.23.0"
111
111
  },
112
112
  "devDependencies": {
113
- "@open-mercato/cli": "0.10.1-develop.7866.1.71cf6e2699",
114
- "@open-mercato/shared": "0.10.1-develop.7866.1.71cf6e2699",
115
- "@open-mercato/ui": "0.10.1-develop.7866.1.71cf6e2699",
113
+ "@open-mercato/cli": "0.10.1-develop.7874.1.67e097d23a",
114
+ "@open-mercato/shared": "0.10.1-develop.7874.1.67e097d23a",
115
+ "@open-mercato/ui": "0.10.1-develop.7874.1.67e097d23a",
116
116
  "@types/react": "^19.2.18",
117
117
  "@types/react-dom": "^19.2.5",
118
118
  "react": "19.2.8",
@@ -0,0 +1,141 @@
1
+ import { test, expect } from '@playwright/test'
2
+ import { build } from 'esbuild'
3
+ import path from 'node:path'
4
+ import { fileURLToPath } from 'node:url'
5
+ import { createRequire } from 'node:module'
6
+
7
+ const canary = 'https://ai-image-canary.invalid/pixel?data=inert'
8
+ const typedParts = [
9
+ ['product', 'imageUrl'],
10
+ ['person', 'avatarUrl'],
11
+ ['company', 'logoUrl'],
12
+ ].map(([kind, field]) => ({
13
+ componentId: `open-mercato.${kind}-card`,
14
+ payload: { name: `Visible typed ${kind}`, [field]: canary, kind: 'deal' },
15
+ }))
16
+ const content = [
17
+ '**Visible answer**',
18
+ `![Inline image](${canary})`,
19
+ `![Reference image][canary]\n\n[canary]: ${canary}`,
20
+ '![Relative image](/canary?data=inert)',
21
+ '![Protocol image](//ai-image-canary.invalid/pixel?data=inert)',
22
+ `<img src="${canary}" alt="Raw HTML image">`,
23
+ '| Detail | Value |\n| --- | --- |\n| Status | Available |',
24
+ '[Ordinary link](https://example.invalid/details)',
25
+ ...[
26
+ ['product', 'imageUrl'],
27
+ ['product', 'image'],
28
+ ['person', 'avatarUrl'],
29
+ ['person', 'avatar'],
30
+ ['company', 'logoUrl'],
31
+ ['company', 'logo'],
32
+ ].map(([kind, field], index) => {
33
+ const payload = JSON.stringify({ name: `Visible ${kind} ${index}`, [field]: canary })
34
+ return index % 2 === 0
35
+ ? `\`\`\`open-mercato:${kind}\n${payload}\n\`\`\``
36
+ : `open-mercato:${kind} ${payload}`
37
+ }),
38
+ ].join('\n\n')
39
+
40
+ let bundle: string
41
+
42
+ test.beforeAll(async () => {
43
+ const require = createRequire(import.meta.url)
44
+ const sourceRoot = (packageName: string) => path.resolve(path.dirname(require.resolve(packageName)), '../src')
45
+ const result = await build({
46
+ bundle: true,
47
+ write: false,
48
+ platform: 'browser',
49
+ format: 'iife',
50
+ jsx: 'automatic',
51
+ define: { 'process.env.NODE_ENV': '"production"', 'process.env': '{}' },
52
+ alias: {
53
+ '@open-mercato/ui': sourceRoot('@open-mercato/ui'),
54
+ '@open-mercato/shared': sourceRoot('@open-mercato/shared'),
55
+ '@open-mercato/ai-assistant': sourceRoot('@open-mercato/ai-assistant'),
56
+ },
57
+ stdin: {
58
+ resolveDir: path.dirname(fileURLToPath(import.meta.url)),
59
+ loader: 'tsx',
60
+ contents: `
61
+ import * as React from 'react'
62
+ import { createRoot } from 'react-dom/client'
63
+ import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
64
+ import { I18nProvider } from '@open-mercato/shared/lib/i18n/context'
65
+ import { AiChat } from '@open-mercato/ui/ai/AiChat'
66
+ import { AiMessageContent } from '@open-mercato/ui/ai/AiMessageContent'
67
+ import '@open-mercato/ui/ai/records/registry'
68
+ const content = ${JSON.stringify(content)}
69
+ const uiParts = ${JSON.stringify(typedParts)}
70
+ createRoot(document.getElementById('root')).render(
71
+ <QueryClientProvider client={new QueryClient()}>
72
+ <I18nProvider locale="en" dict={{}}>
73
+ {location.search === '?chat'
74
+ ? <AiChat agentId="image-policy.test" conversationId="image-policy" initialMessages={[{ role: 'assistant', content }]} uiParts={uiParts} />
75
+ : <AiMessageContent content={content} />}
76
+ </I18nProvider>
77
+ </QueryClientProvider>
78
+ )
79
+ `,
80
+ },
81
+ })
82
+ bundle = result.outputFiles[0].text
83
+ })
84
+
85
+ for (const surface of ['chat', 'standalone']) {
86
+ test(`TC-AI-IMAGE-001: ${surface} makes no requests for model-supplied images`, async ({ page }, testInfo) => {
87
+ const imageRequests: string[] = []
88
+ const errors: string[] = []
89
+ page.on('pageerror', (error) => errors.push(error.message))
90
+ await page.route('**/*', async (route) => {
91
+ const url = new URL(route.request().url())
92
+ if (url.hostname === 'ai-image-canary.invalid' || url.pathname === '/canary') {
93
+ imageRequests.push(url.href)
94
+ await route.abort()
95
+ } else if (url.pathname.startsWith('/api/')) {
96
+ await route.fulfill({ json: {
97
+ providers: [],
98
+ allowRuntimeModelOverride: false,
99
+ conversation: { conversationId: 'image-policy', isOwner: true },
100
+ messages: [{ id: 'answer', role: 'assistant', content, uiParts: typedParts, attachmentIds: [], files: [] }],
101
+ } })
102
+ } else {
103
+ await route.fulfill({ contentType: 'text/html', body: '<div id="root"></div>' })
104
+ }
105
+ })
106
+ await page.goto(`http://ai-image-policy.test/?${surface}`)
107
+ await page.evaluate((url) => {
108
+ const image = document.createElement('img')
109
+ image.src = url
110
+ document.body.append(image)
111
+ }, canary)
112
+ await expect.poll(() => imageRequests.length).toBe(1)
113
+ await page.locator('body > img').evaluate((image) => image.remove())
114
+ imageRequests.length = 0
115
+
116
+ await page.addScriptTag({ content: bundle })
117
+ const answer = page.locator('[data-ai-message-content]')
118
+ await expect.poll(async () => ({ text: await page.locator('#root').innerText(), errors }))
119
+ .toMatchObject({ text: expect.stringContaining('Visible answer'), errors: [] })
120
+ await expect(answer.getByText('Visible answer', { exact: true })).toBeVisible()
121
+ await expect(answer.getByText('Visible product 0', { exact: true })).toBeVisible()
122
+ await expect(answer.getByText('Visible person 3', { exact: true })).toBeVisible()
123
+ await expect(answer.getByText('Visible company 5', { exact: true })).toBeVisible()
124
+ await expect(answer.getByRole('table')).toBeVisible()
125
+ await expect(answer.getByRole('link', { name: 'Ordinary link' })).toHaveAttribute('href', 'https://example.invalid/details')
126
+ if (surface === 'chat') {
127
+ for (const kind of ['product', 'person', 'company']) {
128
+ await expect(page.locator('#root').getByText(`Visible typed ${kind}`, { exact: true })).toHaveCount(2)
129
+ }
130
+ }
131
+ await page.waitForLoadState('networkidle')
132
+ expect(errors).toEqual([])
133
+ expect(imageRequests).toEqual([])
134
+ await expect(page.locator('#root img')).toHaveCount(0)
135
+ await expect(answer).toContainText('Inline image')
136
+ await expect(answer).toContainText('Reference image')
137
+ const screenshotPath = testInfo.outputPath(`${surface}-image-policy.png`)
138
+ await page.screenshot({ path: screenshotPath })
139
+ await testInfo.attach(`${surface}-image-policy`, { path: screenshotPath, contentType: 'image/png' })
140
+ })
141
+ }