Intelligence, Advanced Charting & Trading Platform
feature/paper-trading-risk-controls-2026-10-14
diagnostics/chartnova-blank-screen-2026-10-15
diagnostics/chartnova-stage2-v27-preview-2026-10-15
docs/chartnova-stage1-reconcile-manifest-2026-10-15
feature/chartnova-ios-widget
feature/chartnova-light-catalog-lazy-series-2026-10-15
feature/chartnova-market-terminal
feature/chartnova-multimarket-chart-ws-foundation
feature/chartnova-neon-direct-history
feature/chartnova-neon-history
feature/paper-trading-risk-controls-2026-10-14
fix/alpha-vantage-live-payload
fix/chartnova-progressive-loading-2026-10-15
fix/live-proof-runner-cwd-2026-10-14
foundation/phase-0
foundation/postgres-core
main
ops/chartnova-emergency-rollback-2026-10-15
phase-1/candle-builder
phase-1/data-proof-artifact
phase-1/data-proof-metrics
phase-1/data-proof-report
phase-1/external-gates-state
phase-1/gold-api-fallback
phase-1/ingestion-pipeline
phase-1/live-proof-runner
phase-1/market-calendar
phase-1/market-domain
phase-1/neon-live-proof
phase-1/persistence-contract
phase-1/postgres-ci
phase-1/provider-adapters
phase-1/provider-recovery
phase-1/quality-propagation
phase-1/spike-detection
phase-1/xau-provider-adapter
risk/chartnova-alert-runtime-atomic-2026-10-22
risk/chartnova-atomic-outbox-2026-10-22
risk/chartnova-seven-track-safety-2026-10-21
safety/p0-triage-2026-10-13
| 1 | import test from "node:test"; |
| 2 | import assert from "node:assert/strict"; |
| 3 | import {routeStreamRequest} from "../../../deploy/chartnova/market-stream-worker.mjs"; |
| 4 | const ORIGIN="https://stream.chartnova.test"; |
| 5 | const TOKEN="t".repeat(64); // test fixture, never a live credential |
| 6 | const symbol="BTC_USD"; |
| 7 | const base={ |
| 8 | symbol,source:"test_provider",unit:"USD_PER_BTC",dataKind:"reference_point",price:"100", |
| 9 | sourceTimestamp:"2026-09-01T10:00:00Z",receivedAt:"2026-09-01T10:00:01Z", |
| 10 | licenseEvidence:"test-evidence-ref",rights:"approved_public",quality:"GOOD", |
| 11 | }; |
| 12 | function env(handler){ |
| 13 | return { |
| 14 | STREAM_INGEST_TOKEN:TOKEN, |
| 15 | STREAM_SYMBOL_ALLOWLIST:symbol, |
| 16 | STREAM_ROOMS:{ |
| 17 | idFromName:name=>name, |
| 18 | get:id=>({fetch:handler??(async()=>Response.json({ok:true,room:id}))}), |
| 19 | }, |
| 20 | }; |
| 21 | } |
| 22 | const request=(path,opts)=>new Request(ORIGIN+path,opts); |
| 23 | test("gateway never accepts unauthenticated direct publish",async()=>{ |
| 24 | const result=await routeStreamRequest(request("/internal/market-update",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(base)}),env()); |
| 25 | assert.equal(result.status,401); |
| 26 | }); |
| 27 | test("wrong rights and invalid payload rejected before Durable Object delivery",async()=>{ |
| 28 | let calls=0;const e=env(async()=>{calls++;return Response.json({ok:true})}); |
| 29 | const unlicensed=await routeStreamRequest(request("/internal/market-update",{method:"POST", |
| 30 | headers:{authorization:"Bearer "+TOKEN,"content-type":"application/json"}, |
| 31 | body:JSON.stringify({...base,rights:"research_only"})}),e); |
| 32 | assert.equal(unlicensed.status,403);assert.equal(calls,0); |
| 33 | const invalid=await routeStreamRequest(request("/internal/market-update",{method:"POST", |
| 34 | headers:{authorization:"Bearer "+TOKEN,"content-type":"application/json"}, |
| 35 | body:JSON.stringify({...base,dataKind:"invalid"})}),e); |
| 36 | assert.equal(invalid.status,422);assert.equal(calls,0); |
| 37 | }); |
| 38 | test("approved private publisher forwards server-only payload to exactly one symbol hub",async()=>{ |
| 39 | let target=null,authorization=null,safeBody=null; |
| 40 | const e=env(async request=>{ |
| 41 | target=new URL(request.url).pathname; |
| 42 | authorization=request.headers.get("x-hub-key"); |
| 43 | safeBody=await request.json(); |
| 44 | return Response.json({ok:true,sequence:1,delivered:0}); |
| 45 | }); |
| 46 | const response=await routeStreamRequest(request("/internal/market-update",{method:"POST", |
| 47 | headers:{authorization:"Bearer "+TOKEN,"content-type":"application/json"}, |
| 48 | body:JSON.stringify(base)}),e); |
| 49 | assert.equal(response.status,200); |
| 50 | assert.equal(target,"/broadcast");assert.equal(authorization,TOKEN); |
| 51 | assert.equal(safeBody.symbol,symbol); |
| 52 | assert.equal(safeBody.price,"100"); |
| 53 | }); |
| 54 | test("public WebSocket requires upgrade and allowlisted subscription",async()=>{ |
| 55 | const a=await routeStreamRequest(request("/stream?symbol=BTC_USD"),env()); |
| 56 | assert.equal(a.status,426); |
| 57 | const b=await routeStreamRequest(request("/stream?symbol=BAD_NAME",{headers:{upgrade:"websocket"}}),env()); |
| 58 | assert.equal(b.status,404); |
| 59 | const c=await routeStreamRequest(request("/stream?symbol=BTC_USD&symbol=BTC_USD",{headers:{upgrade:"websocket"}}),env()); |
| 60 | assert.equal(c.status,400); |
| 61 | }); |
| 62 | test("missing Durable Object binding is safely unavailable",async()=>{ |
| 63 | const e=env();delete e.STREAM_ROOMS; |
| 64 | const r=await routeStreamRequest(request("/stream?symbol=BTC_USD",{headers:{upgrade:"websocket"}}),e); |
| 65 | assert.equal(r.status,503); |
| 66 | }); |