ConusAI vendor v0.1.0-dev.20261027+ab5c16b3

This commit is contained in:
ConusAI vendor v0.1.0-dev.20261027+ab5c16b3
2026-10-27 16:27:41 +00:00
commit 9ccb6229e8
159 changed files with 4293 additions and 0 deletions
+61
View File
@@ -0,0 +1,61 @@
import { expect, test, type Page } from '@playwright/test'
// Showcase D23: register() in instrumentation.ts starts the OTLP exporters when the platform
// injects OTEL_EXPORTER_OTLP_ENDPOINT, and every server action logs through shared/api/observe's
// logger(). This proves the whole chain against a real `next start` production server (not dev,
// not a mock of register()): a log a server action emits reaches the fake platform's
// /otel/v1/logs route within the exporter's 5 s batch interval.
const platform = 'http://127.0.0.1:4010'
interface LogRecordJson {
body?: { stringValue?: string }
attributes?: Array<{ key: string; value: { stringValue?: string } }>
}
type OtelState = { otel: { logs: Array<{ authorization: string | null; body: { resourceLogs: Array<{ scopeLogs: Array<{ logRecords: LogRecordJson[] }> }> } }> } }
async function otelLogRecords(): Promise<LogRecordJson[]> {
const response = await fetch(`${platform}/__e2e/state`)
const state = (await response.json()) as OtelState
return state.otel.logs.flatMap((post) => post.body.resourceLogs.flatMap((r) => r.scopeLogs.flatMap((s) => s.logRecords)))
}
function attr(record: LogRecordJson, key: string): string | undefined {
return record.attributes?.find((kv) => kv.key === key)?.value.stringValue
}
async function createNote(page: Page, title: string): Promise<void> {
await page.goto('/')
await page.getByLabel('Title').fill(title)
await page.getByLabel('Body').fill('observability e2e')
await page.getByRole('button', { name: 'Create note' }).click()
await expect(page.getByRole('heading', { name: title })).toBeVisible()
}
test('a note.created server action log reaches the OTLP receiver within the batch interval', async ({ page }) => {
const title = `otlp ${Date.now()}-${Math.random().toString(36).slice(2, 7)}`
await createNote(page, title)
await expect
.poll(
async () => (await otelLogRecords()).some((r) => r.body?.stringValue === 'note.created' && attr(r, 'outcome') === 'ok'),
// BatchExporter's default flush interval is 5 s (exporter.ts); this allows one full
// interval plus slack for the request round trip and CI scheduling jitter.
{ timeout: 9_000 },
)
.toBe(true)
})
test('the OTLP request carries the deployment token, not the public client', async ({ page }) => {
const title = `otlp-auth ${Date.now()}-${Math.random().toString(36).slice(2, 7)}`
await createNote(page, title)
await expect
.poll(async () => (await otelLogRecords()).some((r) => r.body?.stringValue === 'note.created'), { timeout: 9_000 })
.toBe(true)
const response = await fetch(`${platform}/__e2e/state`)
const state = (await response.json()) as OtelState
expect(state.otel.logs.every((post) => post.authorization === 'Bearer e2e-deployment-token')).toBe(true)
})
+40
View File
@@ -0,0 +1,40 @@
import { expect, test } from '@playwright/test'
// Proves, against a real production build (next build + next start, plan D18), that a
// visit actually uploads a session replay segment — not just that the SDK is configured
// to try. instrumentation-client.ts's /api/_conusai/* calls are same-origin and answered
// by the platform's edge on a real deployment (docs/how-to/use-platform-analytics-in-an-
// app.md §"Why this works"); this app has no edge in front of it here, so the test stands
// in for it with the minimum the SDK needs: a session id from /ids, and a place to post
// the envelope. This caught the stage regression (2026-10-11, showcase plan D24) where
// mode: 'always' alone produced zero /api/_conusai/envelope requests because replay is a
// 'consented' item and the default consent mode never sends those.
const SESSION_ID = '11111111-1111-1111-1111-111111111111'
test('a visit uploads a session replay segment within 15 s on a production build', async ({ page }) => {
let envelopePosts = 0
// Analytics, vitals and errors also call the same-origin /api/_conusai/* paths; answer
// them all generically so the run is quiet and deterministic, except the two the
// recorder actually needs.
await page.route('**/api/_conusai/**', (route) => {
const url = route.request().url()
if (url.includes('/api/_conusai/ids')) {
return route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ v: 1, session_id: SESSION_ID }) })
}
if (url.includes('/api/_conusai/envelope')) {
envelopePosts += 1
return route.fulfill({ status: 200, contentType: 'application/json', body: '{}' })
}
return route.fulfill({ status: 200, contentType: 'application/json', body: '{}' })
})
await page.goto('/')
await page.getByLabel('Title').click()
await page.mouse.wheel(0, 200)
await page.goto('/audit')
await page.goto('/')
await expect.poll(() => envelopePosts, { timeout: 15_000, message: 'no POST to /api/_conusai/envelope (replay segment)' }).toBeGreaterThan(0)
})
+122
View File
@@ -0,0 +1,122 @@
import AxeBuilder from '@axe-core/playwright'
import { expect, test, type Page } from '@playwright/test'
// The end-to-end run of the showcase (plan S4.8): a note, an attachment, the audit
// entry and usage on the platform, the enable cards, accessibility and the Core Web
// Vitals budgets. The platform is the fake in e2e/fake-platform.mjs.
const platform = 'http://127.0.0.1:4010'
type PlatformState = {
audit: Array<{ action: string; resource_id: string | null }>
usage: Array<{ idempotency_key: string; meter: string }>
}
async function platformState(): Promise<PlatformState> {
const response = await fetch(`${platform}/__e2e/state`)
return (await response.json()) as PlatformState
}
function uniqueTitle(label: string): string {
return `${label} ${Date.now()}-${Math.random().toString(36).slice(2, 7)}`
}
async function createNote(page: Page, title: string): Promise<void> {
await page.goto('/')
await page.getByLabel('Title').fill(title)
await page.getByLabel('Body').fill('written by the end-to-end run')
await page.getByRole('button', { name: 'Create note' }).click()
await expect(page.getByRole('heading', { name: title })).toBeVisible()
}
test('a note is audited on the platform and listed on the audit page', async ({ page }) => {
const title = uniqueTitle('audited')
await createNote(page, title)
await expect
.poll(async () => (await platformState()).audit.some((event) => event.action === 'note.created'), { timeout: 15_000 })
.toBe(true)
await page.goto('/audit')
await expect(page.getByText('note.created').first()).toBeVisible()
})
test('an attachment moves the usage meter and is metered on the platform', async ({ page }) => {
const title = uniqueTitle('attached')
await createNote(page, title)
const meter = page.getByText(/uploads, \d+ bytes stored/)
await expect(meter).toHaveText(/^0 uploads, 0 bytes stored$/)
const usageBefore = (await platformState()).usage.length
const note = page.getByRole('listitem').filter({ hasText: title })
await note.getByLabel('Attachment').setInputFiles({
name: 'notes.txt',
mimeType: 'text/plain',
buffer: Buffer.from('sixteen bytes!!!'),
})
await note.getByRole('button', { name: 'Attach', exact: true }).click()
await expect(meter).toHaveText(/^1 uploads, 16 bytes stored$/)
await expect
.poll(async () => (await platformState()).usage.length, { timeout: 15_000 })
.toBeGreaterThan(usageBefore)
// The attachment downloads through the app: the platform's blob URL needs the
// deployment token, which the browser does not have.
const href = await note.getByRole('link', { name: 'notes.txt' }).getAttribute('href')
expect(href).toMatch(/^\/files\/[0-9a-f-]+$/)
const download = await page.request.get(href ?? '')
expect(download.status()).toBe(200)
expect(await download.text()).toBe('sixteen bytes!!!')
})
test('each optional module without its variables shows its enable card', async ({ page }) => {
await page.goto('/')
await expect(page.getByText(/to enable this\.$/)).toHaveCount(5)
await expect(page.getByText('Link KV Store to enable this.')).toBeVisible()
await expect(page.getByText(/uploads left this minute/)).toHaveCount(0)
})
for (const path of ['/', '/audit', '/platform']) {
test(`axe finds no serious or critical issues on ${path}`, async ({ page }) => {
await page.goto(path)
const results = await new AxeBuilder({ page }).analyze()
const blocking = results.violations
.filter((violation) => violation.impact === 'serious' || violation.impact === 'critical')
.map((violation) => `${violation.id} (${violation.nodes.length} node(s))`)
expect(blocking).toEqual([])
})
}
test('the dashboard meets the Core Web Vitals budgets: LCP at most 2.5 s, INP at most 200 ms', async ({ page }) => {
await page.addInitScript(() => {
const vitals = window as unknown as { lcp: number; inp: number }
vitals.lcp = 0
vitals.inp = 0
new PerformanceObserver((list) => {
for (const entry of list.getEntries()) vitals.lcp = entry.startTime
}).observe({ type: 'largest-contentful-paint', buffered: true })
// Event Timing entries carry the interaction id and the duration INP is built from.
new PerformanceObserver((list) => {
for (const entry of list.getEntries() as Array<PerformanceEntry & { interactionId?: number }>) {
if ((entry.interactionId ?? 0) > 0) vitals.inp = Math.max(vitals.inp, entry.duration)
}
}).observe({ type: 'event', buffered: true, durationThreshold: 16 } as PerformanceObserverInit)
})
await page.goto('/', { waitUntil: 'load' })
await page.getByLabel('Title').fill(uniqueTitle('vitals'))
await page.getByLabel('Body').fill('an interaction for the input delay budget')
await page.getByRole('button', { name: 'Create note' }).click()
await expect(page.getByText('an interaction for the input delay budget')).toBeVisible()
const vitals = await page.evaluate(() => {
const measured = window as unknown as { lcp: number; inp: number }
return { lcp: measured.lcp, inp: measured.inp }
})
expect(vitals.lcp).toBeGreaterThan(0)
expect(vitals.lcp).toBeLessThanOrEqual(2500)
expect(vitals.inp).toBeLessThanOrEqual(200)
})