companion-shell-stress.test.mjs
sha256:65ccb454656ea5acdea0a10e559b78bcde1eb6ff753ecc2911bc99d1c3d7cadd
feat(calendar): enforce agent context tiers in retrieval AP…
Human
minor
⚠ breaking
1 day ago
| 1 | /** |
| 2 | * Tier 4 — STRESS: Phase 5 listener churn and streamed model handling. |
| 3 | */ |
| 4 | |
| 5 | import { describe, it } from 'node:test'; |
| 6 | import assert from 'node:assert/strict'; |
| 7 | import crypto from 'node:crypto'; |
| 8 | import { mkdtemp, rm } from 'node:fs/promises'; |
| 9 | import os from 'node:os'; |
| 10 | import path from 'node:path'; |
| 11 | |
| 12 | import { createOAuthRedirectAttempt } from '../lib/companion-oauth-flow.mjs'; |
| 13 | import { |
| 14 | createRuntimeGroup, |
| 15 | downloadVerifyAndStageModel, |
| 16 | } from '../lib/companion-shell.mjs'; |
| 17 | |
| 18 | function sha256(data) { |
| 19 | return crypto.createHash('sha256').update(data).digest('hex'); |
| 20 | } |
| 21 | |
| 22 | describe('OAuth redirect listener churn', () => { |
| 23 | it('binds and tears down many one-shot listeners on ephemeral loopback ports', async () => { |
| 24 | const ports = new Set(); |
| 25 | for (let i = 0; i < 20; i += 1) { |
| 26 | const attempt = await createOAuthRedirectAttempt({ |
| 27 | expectedState: `state-${i}`, |
| 28 | expectedIssuer: 'https://gateway.knowtation.com/api/v1/auth/native', |
| 29 | timeoutMs: 500, |
| 30 | }); |
| 31 | const redirect = new URL(attempt.redirectUri); |
| 32 | assert.equal(redirect.hostname, '127.0.0.1'); |
| 33 | assert.notEqual(redirect.port, ''); |
| 34 | ports.add(redirect.port); |
| 35 | attempt.close(); |
| 36 | } |
| 37 | assert.ok(ports.size > 1, 'ephemeral bind did not vary across churn'); |
| 38 | }); |
| 39 | }); |
| 40 | |
| 41 | describe('large streamed download stress', () => { |
| 42 | it('streams a multi-megabyte payload in chunks without buffering in the adapter contract', async () => { |
| 43 | const chunk = Buffer.alloc(64 * 1024, 0x61); |
| 44 | const chunks = Array.from({ length: 32 }, () => chunk); |
| 45 | const data = Buffer.concat(chunks); |
| 46 | const tmp = await mkdtemp(path.join(os.tmpdir(), 'knowtation-phase5-stress-')); |
| 47 | try { |
| 48 | let seenChunks = 0; |
| 49 | const runtimeGroup = createRuntimeGroup({ |
| 50 | async download(_url, onChunk) { |
| 51 | for (const c of chunks) { |
| 52 | seenChunks += 1; |
| 53 | onChunk(c); |
| 54 | } |
| 55 | }, |
| 56 | async spawn() { |
| 57 | return { pid: 1, kill: async () => {} }; |
| 58 | }, |
| 59 | async healthCheck() { |
| 60 | return true; |
| 61 | }, |
| 62 | }); |
| 63 | await downloadVerifyAndStageModel({ |
| 64 | runtimeGroup, |
| 65 | tempPath: path.join(tmp, 'large.tmp'), |
| 66 | verifiedPath: path.join(tmp, 'large.gguf'), |
| 67 | spec: { |
| 68 | modelUrl: 'https://cdn.knowtation-models.com/large.gguf', |
| 69 | expectedDigest: sha256(data), |
| 70 | expectedSizeBytes: data.length, |
| 71 | allowedSourceUrls: ['https://cdn.knowtation-models.com/'], |
| 72 | }, |
| 73 | }); |
| 74 | assert.equal(seenChunks, chunks.length); |
| 75 | } finally { |
| 76 | await rm(tmp, { recursive: true, force: true }); |
| 77 | } |
| 78 | }); |
| 79 | }); |
File History
2 commits
sha256:65ccb454656ea5acdea0a10e559b78bcde1eb6ff753ecc2911bc99d1c3d7cadd
feat(calendar): enforce agent context tiers in retrieval AP…
Human
minor
⚠
1 day ago
sha256:9103f98c89257ed2b01c237cea895dabb3e85ea337dccb1161c175e4422355b6
docs: accept Calendar Events v0 spec with Phase 0 security …
Human
1 day ago