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 {parseHistoryRequest,serveHistoryV2} from "../src/history-api.mjs"; |
| 4 | const root="https://app.chartnova.ir/api/v2/history"; |
| 5 | const req=(query,method="GET")=>new Request(root+query,{method}); |
| 6 | const common="?symbol=BTC_USD&from=2025-10-10&to=2026-10-10&dataKind=source_ohlc&timeframe=1h&limit=2"; |
| 7 | const row=(t)=>({ |
| 8 | symbol:"BTC_USD",unit:"USD_PER_BTC",timeframe:"1h",openTime:t,closeTime:new Date(Date.parse(t)+3600000).toISOString(), |
| 9 | open:"100.0",high:"101.0",low:"99.0",close:"100.5",volume:"0",quality:"DEGRADED",secretProviderToken:"NOT_FOR_PUBLIC" |
| 10 | }); |
| 11 | const response=(rows)=>({source:"binance",unit:"USD_PER_BTC",dataKind:"source_ohlc",rights:"approved_public",attribution:"Binance Exchange test fixture only",rows}); |
| 12 | test("date, symbol, kind, limit, unknown parameter and duplicate input validation",()=>{ |
| 13 | const valid=parseHistoryRequest(new URL(root+common));assert.equal(valid.limit,2); |
| 14 | const malformed=[ |
| 15 | "?symbol=BTC_USD&from=2025-10-10&to=2026-10-10&dataKind=source_ohlc&timeframe=1h&limit=6000", |
| 16 | common+"&symbol=ETH_USD",common+"&extra=SQL",common.replace("BTC_USD","../../root"), |
| 17 | common.replace("source_ohlc","made_up"),common.replace("from=2025-10-10","from=2020-01-01"), |
| 18 | common+"&cursor=garbage",common.replace("2025-10-10","2025-13-10")]; |
| 19 | for(const q of malformed)assert.throws(()=>parseHistoryRequest(new URL(root+q)),undefined,q); |
| 20 | }); |
| 21 | test("unconfigured provider-neutral history never claims live data",async()=>{ |
| 22 | const r=await serveHistoryV2(req(common)); |
| 23 | assert.equal(r.status,503);assert.equal((await r.json()).error,"storage_not_configured"); |
| 24 | }); |
| 25 | test("read-only repository port returns descending page in ascending presentation with cursor",async()=>{ |
| 26 | const dates=["2025-10-12T01:00:00Z","2025-10-12T00:00:00Z","2025-10-11T23:00:00Z"]; |
| 27 | let called; |
| 28 | const r=await serveHistoryV2(req(common),{lookup:async(query)=>{called=query;return response(dates.map(row))}}); |
| 29 | assert.equal(r.status,200); |
| 30 | const json=await r.json(); |
| 31 | assert.equal(json.series.length,2);assert.equal(json.page.hasMore,true); |
| 32 | assert.equal(json.page.nextCursor,new Date(dates[1]).toISOString()); |
| 33 | assert.equal(json.series[0].time,new Date(dates[1]).toISOString());assert.equal(json.series[1].time,new Date(dates[0]).toISOString()); |
| 34 | assert.equal(json.series[0].volume,0); |
| 35 | assert(!JSON.stringify(json).includes("NOT_FOR_PUBLIC")); |
| 36 | assert.equal(called.symbol,"BTC_USD");assert.equal(called.limit,2); |
| 37 | }); |
| 38 | test("unknown license rights or empty data rejected instead of silently rendered",async()=>{ |
| 39 | const a=await serveHistoryV2(req(common),{lookup:async()=>({...response([row("2025-10-11T00:00:00Z")]),rights:"research_only"})}); |
| 40 | assert.equal(a.status,503); |
| 41 | const b=await serveHistoryV2(req(common),{lookup:async()=>response([])}); |
| 42 | assert.equal(b.status,404); |
| 43 | }); |
| 44 | test("cross-symbol, reversed order, excessive rows and invalid OHLC rejected",async()=>{ |
| 45 | const t="2025-10-12T00:00:00Z"; |
| 46 | for(const rows of [ |
| 47 | [{...row(t),symbol:"ETH_USD"}], |
| 48 | [row("2025-10-11T00:00:00Z"),row(t)], |
| 49 | [{...row(t),low:"105"}], |
| 50 | [row(t),row(t)], |
| 51 | [row(t),row(t),row(t),row(t)]] |
| 52 | ){ |
| 53 | const result=await serveHistoryV2(req(common),{lookup:async()=>response(rows)}); |
| 54 | assert.equal(result.status,502); |
| 55 | } |
| 56 | }); |
| 57 | test("CoinGecko-like point data cannot acquire OHLC fields",async()=>{ |
| 58 | const q="?symbol=BTC_USD&from=2025-10-10&to=2026-10-10&dataKind=reference_point&timeframe=1d"; |
| 59 | const ref={symbol:"BTC_USD",unit:"USD_PER_BTC",sourceTimestamp:"2025-10-10T00:00:00Z",price:120,quality:"DEGRADED"}; |
| 60 | const source={source:"coingecko",unit:"USD_PER_BTC",dataKind:"reference_point",rights:"approved_public",attribution:"research fixture",rows:[ref]}; |
| 61 | const a=await serveHistoryV2(req(q),{lookup:async()=>source}); |
| 62 | assert.equal(a.status,200); |
| 63 | const json=await a.json();assert.equal(json.series[0].price,120); |
| 64 | assert.equal(json.series[0].open,undefined); |
| 65 | const b=await serveHistoryV2(req(q),{lookup:async()=>({...source,rows:[{...ref,open:110}]})}); |
| 66 | assert.equal(b.status,502); |
| 67 | }); |
| 68 | test("method not allowed is explicit",async()=>{ |
| 69 | const r=await serveHistoryV2(req(common,"POST")); |
| 70 | assert.equal(r.status,405); |
| 71 | }); |