mirror of
https://github.com/AgentSeal/codeburn.git
synced 2026-07-10 09:39:24 +00:00
Some checks failed
CI / semgrep (push) Has been cancelled
The web server is long-lived, so cache what the per-invocation CLI cannot: - Cache the parsed local payload in-memory (single-flight, 180s TTL matched to the parser session cache, expired entries pruned on write). /api/usage and the local half of /api/devices now return from a Map hit after the first parse. - Prewarm today at startup and inline that payload into index.html as a bootstrap, so the SPA paints today's numbers with no round-trip. Only the local device is embedded; '<' is escaped so a name cannot break the script tag; served no-store; the seeded view refetches at once so live peers appear. - Default the web command and dashboard to today. - Cap the peer connect phase at 3s. req.setTimeout does not abort a stalled TCP connect, so an offline paired device hung ~75s on the OS timeout; it now degrades to an unreachable row in ~3s. The cap clears on TCP connect, so the TLS handshake and the 65s pairing-approval wait are unaffected. Measured: /api/usage 0.0007s warm (was ~0.22s), /api/devices ~3s with an offline peer (was ~75s), first paint instant.
15 lines
688 B
TypeScript
15 lines
688 B
TypeScript
import { describe, it, expect } from 'vitest'
|
|
|
|
import { generateIdentity } from '../../src/sharing/identity.js'
|
|
import { hello } from '../../src/sharing/client.js'
|
|
|
|
describe('peer connect timeout', () => {
|
|
it('fails fast when a peer is unreachable instead of riding the OS connect timeout', async () => {
|
|
const id = await generateIdentity('Test')
|
|
// RFC5737 TEST-NET-1 is reserved and black-holed: the SYN gets no answer,
|
|
// so without the connect-phase cap this would hang ~75s on macOS.
|
|
const start = Date.now()
|
|
await expect(hello({ identity: id, host: '192.0.2.1', port: 7777 })).rejects.toThrow()
|
|
expect(Date.now() - start).toBeLessThan(6000)
|
|
}, 15000)
|
|
})
|