From ea43502a1080b06b5e8043825b4c1bcb4e2ed902 Mon Sep 17 00:00:00 2001 From: vreshch Date: Fri, 14 Aug 2026 18:52:21 +0200 Subject: [PATCH] chore(e2e): tag suite traffic with x-client-type: test --- e2e/client-type.ts | 7 +++++++ e2e/helpers.ts | 6 +++++- e2e/mcp-contract.test.ts | 7 ++++++- e2e/mcp-daemon.test.ts | 7 ++++++- playwright.config.ts | 2 ++ 5 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 e2e/client-type.ts diff --git a/e2e/client-type.ts b/e2e/client-type.ts new file mode 100644 index 0000000..038ecbe --- /dev/null +++ b/e2e/client-type.ts @@ -0,0 +1,7 @@ +// Estate test-traffic contract: the edge classifier keys on this exact header to keep e2e out of real-user metrics. +export const CLIENT_TYPE_HEADER = 'x-client-type'; +export const CLIENT_TYPE_TEST = 'test'; + +export const testClientHeader = (): Record => ({ + [CLIENT_TYPE_HEADER]: CLIENT_TYPE_TEST, +}); diff --git a/e2e/helpers.ts b/e2e/helpers.ts index 7045820..5cc23e1 100644 --- a/e2e/helpers.ts +++ b/e2e/helpers.ts @@ -14,6 +14,7 @@ import { createServer } from 'node:net'; import { tmpdir } from 'node:os'; import { join } from 'node:path'; import { expect, request as apiRequest, type APIRequestContext } from '@playwright/test'; +import { testClientHeader } from './client-type.js'; export const TARGET_FQDN = process.env['AGENTAGE_SITE_FQDN'] ?? 'dev.agentage.io'; export const AUTH_URL = `https://auth.${TARGET_FQDN}`; @@ -150,7 +151,10 @@ export const testAccount = (): TestAccount => { // Better Auth 403s cookie-bearing POSTs without a same-origin Origin header. export const newBrowserContext = (): Promise => - apiRequest.newContext({ baseURL: AUTH_URL, extraHTTPHeaders: { Origin: AUTH_URL } }); + apiRequest.newContext({ + baseURL: AUTH_URL, + extraHTTPHeaders: { Origin: AUTH_URL, ...testClientHeader() }, + }); const sleep = (ms: number): Promise => new Promise((r) => setTimeout(r, ms)); diff --git a/e2e/mcp-contract.test.ts b/e2e/mcp-contract.test.ts index 6455bd3..eab9db7 100644 --- a/e2e/mcp-contract.test.ts +++ b/e2e/mcp-contract.test.ts @@ -3,6 +3,7 @@ import { existsSync, readFileSync } from 'node:fs'; import { join } from 'node:path'; import { expect, test } from '@playwright/test'; import { assertCliBuilt, createCliMachine, freePort, type CliMachine } from './helpers.js'; +import { testClientHeader } from './client-type.js'; // Frozen MCP contract behavior tier. mcp-daemon.test.ts proves the tool surface exists (6 tools, // dual-channel output); this proves the BEHAVIORS a bad @agentage/server-memory or @@ -28,7 +29,11 @@ const rpc = async ( ): Promise<{ result?: ToolResult; error?: { message: string } }> => { const res = await fetch(`http://127.0.0.1:${port}/mcp`, { method: 'POST', - headers: { 'Content-Type': 'application/json', Accept: 'application/json, text/event-stream' }, + headers: { + 'Content-Type': 'application/json', + Accept: 'application/json, text/event-stream', + ...testClientHeader(), + }, body: JSON.stringify({ jsonrpc: '2.0', id: 1, method, params }), }); expect(res.ok, `POST /mcp ${method} -> ${res.status}`).toBe(true); diff --git a/e2e/mcp-daemon.test.ts b/e2e/mcp-daemon.test.ts index 7e457b8..7877045 100644 --- a/e2e/mcp-daemon.test.ts +++ b/e2e/mcp-daemon.test.ts @@ -2,6 +2,7 @@ import { existsSync, readFileSync } from 'node:fs'; import { join } from 'node:path'; import { expect, test } from '@playwright/test'; import { assertCliBuilt, createCliMachine, freePort, type CliMachine } from './helpers.js'; +import { testClientHeader } from './client-type.js'; // M3 daemon MCP tier: the daemon exposes the frozen 6 memory__* tools at POST /mcp (stateless // Streamable HTTP). An ephemeral port + isolated AGENTAGE_CONFIG_DIR keep it off the real daemon / @@ -36,7 +37,11 @@ interface RpcResult { const mcpRpc = async (port: number, method: string, params: unknown): Promise => { const res = await fetch(`http://127.0.0.1:${port}/mcp`, { method: 'POST', - headers: { 'Content-Type': 'application/json', Accept: 'application/json, text/event-stream' }, + headers: { + 'Content-Type': 'application/json', + Accept: 'application/json, text/event-stream', + ...testClientHeader(), + }, body: JSON.stringify({ jsonrpc: '2.0', id: 1, method, params }), }); expect(res.ok, `POST /mcp ${method} -> ${res.status}`).toBe(true); diff --git a/playwright.config.ts b/playwright.config.ts index d358107..d8d8d1c 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -1,4 +1,5 @@ import { defineConfig } from '@playwright/test'; +import { testClientHeader } from './e2e/client-type.js'; export default defineConfig({ testDir: './e2e', @@ -8,4 +9,5 @@ export default defineConfig({ retries: process.env['CI'] ? 1 : 0, workers: 1, reporter: process.env['CI'] ? [['list'], ['html', { open: 'never' }]] : 'list', + use: { extraHTTPHeaders: { ...testClientHeader() } }, });