ConusAI vendor 81941888f

This commit is contained in:
ConusAI vendor 81941888f
2026-10-07 08:47:51 +00:00
commit c3c6526952
135 changed files with 13010 additions and 0 deletions
+96
View File
@@ -0,0 +1,96 @@
// A stand-in for the ConusAI platform's routes the showcase calls (plan S4.8), so the
// end-to-end run needs no platform. It keeps what the app sends in memory, reads it
// back the way the platform does, and exposes that state under /__e2e/state for the
// tests. It is not a platform: no tenancy, no auth beyond the bearer header's presence.
import { createServer } from 'node:http'
import { gunzipSync } from 'node:zlib'
const PORT = 4010
const state = { audit: [], usage: [], blobs: [] }
const catalog = {
redis: { display_name: 'Redis', description: 'Counts uploads per visitor each minute.' },
nats: { display_name: 'NATS', description: 'Announces new notes live to subscribers.' },
qdrant: { display_name: 'Qdrant', description: 'Finds similar notes by vector search.' },
git: { display_name: 'Git & Packages', description: 'Installs packages from the platform registry.' },
s3: { display_name: 'S3', description: 'Exports your notes to an S3 bucket.' },
}
function send(res, status, body) {
res.writeHead(status, { 'content-type': 'application/json' })
res.end(JSON.stringify(body))
}
async function readBody(req) {
const chunks = []
for await (const chunk of req) chunks.push(chunk)
const raw = Buffer.concat(chunks)
return req.headers['content-encoding'] === 'gzip' ? gunzipSync(raw) : raw
}
const server = createServer(async (req, res) => {
const url = new URL(req.url ?? '/', `http://127.0.0.1:${PORT}`)
// CONUSAI_API_URL is the platform base ending in /api, and the SDKs append only their
// route. Strip exactly one /api: a request for /api/api/... then matches no route.
const path = url.pathname.startsWith('/api/') ? url.pathname.slice(4) : url.pathname
const method = req.method ?? 'GET'
if (method === 'GET' && path === '/__e2e/health') return send(res, 200, { ok: true })
if (method === 'GET' && path === '/__e2e/state') return send(res, 200, state)
if (method === 'GET' && path === '/.well-known/conusai.json') {
return send(res, 200, { name: 'ConusAI e2e platform', version: 'e2e' })
}
const service = path.match(/^\/v1\/service-types\/([a-z0-9_-]+)$/)
if (method === 'GET' && service) {
const entry = catalog[service[1]]
if (!entry) return send(res, 404, { title: 'unknown service type' })
return send(res, 200, { service_type: service[1], category: 'e2e', color: '#000000', capabilities: {}, ...entry })
}
if (method === 'POST' && path === '/_conusai/audit') {
const body = JSON.parse((await readBody(req)).toString('utf8'))
for (const event of body.events) {
state.audit.push({
id: state.audit.length + 1,
action: event.action,
outcome: event.outcome ?? 'success',
occurred_at: event.occurred_at ?? new Date().toISOString(),
resource_type: event.target?.type ?? null,
resource_id: event.target?.id ?? null,
})
}
return send(res, 202, { accepted: body.events.length, duplicates: 0, redacted: [] })
}
if (method === 'GET' && path === '/_conusai/audit/events') {
const items = [...state.audit].reverse()
return send(res, 200, { items, next_cursor: null, has_more: false })
}
if (method === 'POST' && path === '/_conusai/usage/events') {
const body = JSON.parse((await readBody(req)).toString('utf8'))
state.usage.push(...body.events)
return send(res, 202, { accepted: body.events.length, duplicates: 0, rejected: [] })
}
if (method === 'POST' && path === '/blob') {
const bytes = await readBody(req)
const pathname = url.searchParams.get('pathname') ?? 'blob'
const info = {
url: `http://127.0.0.1:${PORT}/api/blob/${pathname}`,
pathname,
contentType: req.headers['content-type'] ?? 'application/octet-stream',
size: bytes.length,
uploadedAt: new Date().toISOString(),
}
state.blobs.push(info)
return send(res, 200, info)
}
return send(res, 404, { title: 'not found', path })
})
server.listen(PORT, '127.0.0.1', () => {
console.log(`fake platform listening on ${PORT}`)
})
+114
View File
@@ -0,0 +1,114 @@
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)
})
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 Redis 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)
})