Intelligence, Advanced Charting & Trading Platform
feature/chartnova-multimarket-chart-ws-foundation
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 worker from "./worker.mjs"; |
| 4 | |
| 5 | // No live credentials in this test; SQL results are TEST-ONLY mock observations. |
| 6 | const secret="postgresql://chartnova_history_ro:TEST_ONLY_SECRET@ep-example.aws.neon.tech/neondb?sslmode=require"; |
| 7 | const query=new URLSearchParams({symbol:"EUR_USD_ECB",from:"2026-10-01",to:"2026-10-10", |
| 8 | dataKind:"reference_point",timeframe:"1d",limit:"10"}); |
| 9 | const endpoint="https://app.chartnova.ir/api/v2/history?"+query; |
| 10 | const env=(withSecret=false)=>({MARKET_CACHE:{get:async()=>null,put:async()=>{}},...(withSecret?{CHARTNOVA_HISTORY_DATABASE_URL:secret}:{})}); |
| 11 | test("v2 URL is unavailable unless server-side restricted Neon credential is configured",async()=>{ |
| 12 | const r=await worker.fetch(new Request(endpoint),env()); |
| 13 | assert.equal(r.status,503);assert.equal((await r.json()).error,"history_storage_not_configured"); |
| 14 | }); |
| 15 | test("v2 URL rejects a superuser database connection",async()=>{ |
| 16 | const e=env(true);e.CHARTNOVA_HISTORY_DATABASE_URL=secret.replace("chartnova_history_ro","neondb_owner"); |
| 17 | const r=await worker.fetch(new Request(endpoint),e); |
| 18 | assert.equal(r.status,503); |
| 19 | assert(!JSON.stringify(await r.json()).includes("neondb_owner")); |
| 20 | }); |
| 21 | test("v2 URL reads and sanitizes real-shape public ECB view observations",async()=>{ |
| 22 | const prior=globalThis.fetch;let dbCalls=0; |
| 23 | globalThis.fetch=async(url,options)=>{ |
| 24 | dbCalls++; |
| 25 | assert.equal(url,"https://ep-example.aws.neon.tech/sql"); |
| 26 | assert.equal(options.headers["Neon-Connection-String"],secret); |
| 27 | return Response.json({rows:[{ |
| 28 | symbol:"EUR_USD_ECB",quote_asset:"USD",source:"ecb_exr", |
| 29 | observation_at:"2026-10-09T23:59:59.000Z",price:"1.12",quality:"GOOD", |
| 30 | flags:{source_series:"EXR.D.USD.EUR.SP00.A",license:"ECB/ESCB open statistics; attribution required", |
| 31 | data_kind:"daily_reference_point_not_ohlc",observation_date:"2026-10-09",privateInternalField:"DO_NOT_PUBLISH"}, |
| 32 | fakeDatabaseToken:"DO_NOT_PUBLISH" |
| 33 | }]}); |
| 34 | }; |
| 35 | try{ |
| 36 | const r=await worker.fetch(new Request(endpoint),env(true)); |
| 37 | assert.equal(r.status,200); |
| 38 | const body=await r.text(); |
| 39 | assert(!body.includes("TEST_ONLY_SECRET"));assert(!body.includes("DO_NOT_PUBLISH")); |
| 40 | const data=JSON.parse(body); |
| 41 | assert.equal(data.dataKind,"reference_point");assert.equal(data.rights,"approved_public"); |
| 42 | assert.equal(data.count,1);assert.equal(data.series[0].price,1.12); |
| 43 | assert.equal(dbCalls,1); |
| 44 | }finally{globalThis.fetch=prior} |
| 45 | }); |
| 46 | test("v2 endpoint never pretends ECB rates are OHLC",async()=>{ |
| 47 | const url=new URL(endpoint);url.searchParams.set("dataKind","source_ohlc"); |
| 48 | const r=await worker.fetch(new Request(url),env(true)); |
| 49 | assert.equal(r.status,503); |
| 50 | assert.equal((await r.json()).error,"licensed_history_unavailable"); |
| 51 | }); |