Skip to content

Fully autonomous AI Agents system capable of performing complex penetration testing tasks

test(e2e): cover the Files and Screenshots flow tabs

Sergey Kozyrenko10baac43dac7
diff --git a/frontend/e2e/mocks/cassette.ts b/frontend/e2e/mocks/cassette.ts
index cf251b39..c11a1641 100644
--- a/frontend/e2e/mocks/cassette.ts
+++ b/frontend/e2e/mocks/cassette.ts
@@ -45,6 +45,12 @@ export interface RestCassetteEntry extends WorldFlagged {
* entry whose payload matters (login credentials, create/update bodies).
*/
bodySubset?: Record<string, unknown>;
+ /**
+ * Serves `body` verbatim under this content type instead of encoding it as
+ * JSON. Binary endpoints need it: a screenshot `<img>` handed JSON decodes to
+ * a broken image while the request still counts as matched.
+ */
+ contentType?: string;
status?: number;
}
diff --git a/frontend/e2e/mocks/cassettes/flows.ts b/frontend/e2e/mocks/cassettes/flows.ts
index f494cd18..c3d8664c 100644
--- a/frontend/e2e/mocks/cassettes/flows.ts
+++ b/frontend/e2e/mocks/cassettes/flows.ts
@@ -3,6 +3,7 @@ import type { ResultOf } from '@graphql-typed-document-node/core';
import type {
AssistantsDocument,
FlowDocument,
+ FlowFilesDocument,
FlowFragmentFragment,
MessageLogFragmentFragment,
TerminalLogFragmentFragment,
@@ -256,20 +257,75 @@ const TABS_VECTOR_LOG = entity('VectorStoreLog', {
taskId: '11',
});
+export const TABS_SCREENSHOT_ID = '71';
+export const TABS_SCREENSHOT_NAME = 'login-form';
+export const TABS_SCREENSHOT_URL = 'https://e2e.invalid/login-form';
+
+const TABS_SCREENSHOT = entity('Screenshot', {
+ createdAt: T,
+ flowId: '5',
+ id: TABS_SCREENSHOT_ID,
+ name: TABS_SCREENSHOT_NAME,
+ subtaskId: null,
+ taskId: '11',
+ url: TABS_SCREENSHOT_URL,
+});
+
+// The file manager groups by path prefix (uploads/resources/container), so a file
+// seeded outside those roots renders nowhere.
+export const TABS_FILE_NAME = 'scan-report.txt';
+
+const flowFiles: ResultOf<typeof FlowFilesDocument> = {
+ flowFiles: [
+ entity('FlowFile', {
+ id: '1',
+ isDir: false,
+ modifiedAt: T,
+ name: TABS_FILE_NAME,
+ path: `uploads/${TABS_FILE_NAME}`,
+ size: 2048,
+ }),
+ entity('FlowFile', {
+ id: '2',
+ isDir: false,
+ modifiedAt: T,
+ name: 'wordlist.txt',
+ path: 'resources/wordlist.txt',
+ size: 512,
+ }),
+ ],
+};
+
+// 1×1 transparent PNG: the Screenshots tab renders an <img>, and the hermetic gate
+// records every unmatched call, so the blob needs an entry even though no assertion
+// looks at its pixels.
+const PNG_1X1 = Buffer.from(
+ 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg==',
+ 'base64',
+);
+
const flowTabsData: ResultOf<typeof FlowDocument> = {
agentLogs: [TABS_AGENT_LOG],
flow: FLOW_A,
messageLogs: [],
- screenshots: [],
+ screenshots: [TABS_SCREENSHOT],
searchLogs: [TABS_SEARCH_LOG],
tasks: [TABS_TASK],
terminalLogs: [],
vectorStoreLogs: [TABS_VECTOR_LOG],
};
-/** Flow 5 with one populated entry per query-backed detail tab (tasks, agents, searches, vector store). */
+/** Flow 5 with one populated entry per detail tab, including the REST-fed screenshot image. */
export const flowTabsCassette = (): Cassette =>
flowsCassette({
- queries: { flow: [{ data: flowTabsData, variables: { id: '5' } }] },
+ queries: {
+ flow: [{ data: flowTabsData, variables: { id: '5' } }],
+ flowFiles: [{ data: flowFiles, variables: { flowId: '5' } }],
+ },
+ rest: {
+ [`GET /api/v1/flows/5/screenshots/${TABS_SCREENSHOT_ID}/file`]: [
+ { body: PNG_1X1, contentType: 'image/png' },
+ ],
+ },
subscriptions: { messageLogAdded: [{ frames: [], variables: { flowId: '5' } }] },
});
diff --git a/frontend/e2e/mocks/install.ts b/frontend/e2e/mocks/install.ts
index 64e94d53..245a65de 100644
--- a/frontend/e2e/mocks/install.ts
+++ b/frontend/e2e/mocks/install.ts
@@ -50,10 +50,15 @@ export const installMockRoutes = async (page: Page, world: MockWorld): Promise<v
const entry = world.matchRest(request.method(), pathname, body ?? undefined);
if (entry) {
- await route.fulfill({
- json: entry.body ?? {},
- status: entry.status ?? 200,
- });
+ await route.fulfill(
+ entry.contentType
+ ? {
+ body: entry.body as Buffer | string,
+ contentType: entry.contentType,
+ status: entry.status ?? 200,
+ }
+ : { json: entry.body ?? {}, status: entry.status ?? 200 },
+ );
return;
}
diff --git a/frontend/e2e/specs/flows/tabs.spec.ts b/frontend/e2e/specs/flows/tabs.spec.ts
index f456e3a2..7145229f 100644
--- a/frontend/e2e/specs/flows/tabs.spec.ts
+++ b/frontend/e2e/specs/flows/tabs.spec.ts
@@ -1,21 +1,25 @@
import { expect, test } from '../../fixtures/test.ts';
import { expectCleanPage } from '../../helpers/errors.ts';
-import { flowTabsCassette } from '../../mocks/cassettes/flows.ts';
+import {
+ flowTabsCassette,
+ TABS_FILE_NAME,
+ TABS_SCREENSHOT_NAME,
+ TABS_SCREENSHOT_URL,
+} from '../../mocks/cassettes/flows.ts';
-// The query-backed detail tabs were uncovered — only Terminal had a spec. Each
-// marker is unique to its tab's seeded data, so a visible marker proves that tab
-// rendered its content.
const TABS = [
{ marker: 'E2E Task Alpha', name: 'Tasks' },
{ marker: 'E2E agent reconnaissance', name: 'Agents' },
{ marker: 'E2E search for the CVE', name: 'Searches' },
{ marker: 'E2E recall prior findings', name: 'Vector Store' },
+ { marker: TABS_FILE_NAME, name: 'Files' },
+ { marker: TABS_SCREENSHOT_URL, name: 'Screenshots' },
] as const;
test.describe('flow detail tabs', { tag: '@flows' }, () => {
test.use({ cassette: flowTabsCassette() });
- test('each query-backed tab renders its populated content', async ({ page, pageErrorLog }) => {
+ test('each tab renders its populated content', async ({ page, pageErrorLog }) => {
await page.goto('/flows/5');
await expect(page.getByRole('button', { name: 'Flow actions' })).toBeVisible();
@@ -26,4 +30,20 @@ test.describe('flow detail tabs', { tag: '@flows' }, () => {
expectCleanPage(pageErrorLog);
});
+
+ test('the screenshot image decodes from its REST endpoint', async ({ page, pageErrorLog }) => {
+ await page.goto('/flows/5');
+ await expect(page.getByRole('button', { name: 'Flow actions' })).toBeVisible();
+ await page.getByRole('tab', { name: 'Screenshots' }).click();
+
+ const image = page.getByRole('img', { name: TABS_SCREENSHOT_NAME });
+ await image.scrollIntoViewIfNeeded();
+
+ // toBeVisible passes on an undecoded element; only the width proves the blob arrived.
+ await expect
+ .poll(async () => image.evaluate((element: HTMLImageElement) => element.naturalWidth))
+ .toBeGreaterThan(0);
+
+ expectCleanPage(pageErrorLog);
+ });
});