SniperGold_ML/tests/golden/common.py
Chiki Bum 0d5ca3c197 P3-DATA-ENGINE-002: Data Engine v1 implementation + qualification suite (QUALIFIED)
Implements the frozen P3_DATA_ENGINE_V1_SPEC (SHA 84bf0f217ffba51197112a6bbacbcc297058e04b5ca47f0459028fe33e0321e5).
Components: engine/ producer (certify, chunkmap, parse, canonical, worker,
dispatcher, aggregate, storage, journal, checkpoint, lock, evidence, manifest,
run_complete, dataset_builder, cli) + engine/verify independent verifier
(vparse, vaggregate, vinvariants, vcompare); headless CLI sniper-data; golden
corpus G01-G17; unit/property/adversarial/mutation/legacy-diff/CLI suites.

Qualification verdict: QUALIFIED (all 9 mandatory gates pass; independent
verifier accepted). Spec, governance record, and legacy checkpoint untouched.
G-14 NOT AUTHORIZED honored; no real-data processing, no pilot, no workload 46,
no chunk 760 access.
2026-09-07 14:15:25 +07:00

128 lines
No EOL
4.3 KiB
Python

"""Golden corpus layer definitions (spec 19, G01-G17).
Case inputs live in tests/golden/cases/*.txt (committed; the repo ignores
*.csv so fixtures use .txt). Expected outputs live in
tests/golden/expected/*.json. Expected content ids are computed with the
INDEPENDENT verifier (engine.verify.vparse) and anchored by hand-computed
primitive values (epoch ms / micro prices); the runner then requires
producer == verifier == expected.
"""
# Hand-computed anchors (independent truth for tiny inputs):
# 2023-01-02 03:04:05.100 UTC -> 1672628645100 ms
# 2023-01-01 00:00:00.000 UTC -> 1672531200000 ms
# "100.000000" * 1e6 = 100_000_000 ; "100.000100" = 100_000_100
ANCHOR_TS = 1672628645100
ANCHOR_TS_2023_01_01 = 1672531200000
ANCHOR_BID = 100000000
ANCHOR_ASK = 100000100
GOLDEN_TIMEFRAMES = ["M1", "M5", "M15", "M30", "H1"]
# Default golden config (test-established tz offset = 0 UTC; has_volume False)
def golden_cfg(chunk_bytes=25_165_824, tz_offset=0):
return {
"source_tz_offset_minutes": tz_offset,
"has_volume": False,
"timeframes": list(GOLDEN_TIMEFRAMES),
"chunk_bytes_nominal": chunk_bytes,
"workload_bytes_nominal": 536_870_912,
}
G01_ROWS = [
"2023.01.02 03:04:05.100,100.000000,100.000100",
"2023.01.02 03:04:05.200,100.000100,100.000200",
"2023.01.02 03:04:05.300,100.000200,100.000300",
"2023.01.02 03:04:05.400,100.000300,100.000400",
]
G03_ROWS = [
"datetime,bid,ask",
"2023.01.02 03:04:05.100,100.000000,100.000100",
"2023.01.02 03:04:05.200,100.000100,100.000200",
]
G05_ROWS = list(G01_ROWS) # 45 chars + LF = 46 bytes per line
G07_ROWS = [
"2023.13.01 00:00:00.000,100.000000,100.000100",
"2023.01.01 25:00:00.000,100.000000,100.000100",
"garbage,100.000000,100.000100",
"2023.01.01 00:00:00.000,100.000000,100.000100",
"1999.12.31 23:59:59.999,100.000000,100.000100",
]
G08_ROWS = [
"2023.01.01 00:00:00.000,abc,100.000100",
"2023.01.01 00:00:01.000,-1.5,100.000100",
"2023.01.01 00:00:02.000,1.23456789,100.000100",
"2023.01.01 00:00:03.000,0.000000,100.000100",
"2023.01.01 00:00:04.000,100.000000,100.000100",
]
G09_ROWS = [
"2023.01.01 00:00:00.000,100.000100,100.000000",
"2023.01.01 00:00:01.000,100.000000,100.000100",
]
G10_ROWS = [
"2023.01.01 00:00:00.000,100.000000,100.000100",
"2023.01.01 00:00:00.000,100.000000,100.000100",
"2023.01.01 00:00:01.000,100.000000,100.000100",
]
G11_ROWS = [
"2023.01.01 00:00:00.000,100.000000,100.000100",
"2023.01.01 00:00:01.000,100.000100,100.000200",
"2023.01.01 00:00:02.000,100.000200,100.000300",
]
G12_ROWS = [
"2023.01.01 00:00:03.000,100.000300,100.000400",
"2023.01.01 00:00:02.000,100.000100,100.000200",
"2023.01.01 00:00:04.000,100.000000,100.000100",
]
G17_ROWS = [
"1672628645100|100000000|100000100|1",
]
def case_bytes(case_id):
"""Return the case input bytes, exactly as committed."""
if case_id == "G01":
return ("\r\n".join(G01_ROWS) + "\r\n").encode("utf-8")
if case_id == "G02":
return ("\n".join(G01_ROWS) + "\n").encode("utf-8")
if case_id == "G03":
return ("\n".join(G03_ROWS) + "\n").encode("utf-8")
if case_id == "G04":
return ("\n".join(G01_ROWS[:2]) + "\n").encode("utf-8")
if case_id in ("G05", "G13"):
return ("\n".join(G05_ROWS) + "\n").encode("utf-8")
if case_id == "G06":
return ("\n".join(G05_ROWS) + "\n").encode("utf-8")
if case_id == "G07":
return ("\n".join(G07_ROWS) + "\n").encode("utf-8")
if case_id == "G08":
return ("\n".join(G08_ROWS) + "\n").encode("utf-8")
if case_id == "G09":
return ("\n".join(G09_ROWS) + "\n").encode("utf-8")
if case_id == "G10":
return ("\n".join(G10_ROWS) + "\n").encode("utf-8")
if case_id == "G11":
return ("\n".join(G11_ROWS) + "\n").encode("utf-8")
if case_id == "G12":
return ("\n".join(G12_ROWS) + "\n").encode("utf-8")
if case_id == "G17":
return ("\n".join(G17_ROWS) + "\n").encode("utf-8")
raise KeyError(case_id)
def case_chunk_nominal(case_id):
if case_id in ("G05", "G13"):
return 46 # exact boundary on line end (G05) / multi-chunk (G13)
if case_id == "G06":
return 40 # boundary lands inside a line
return 25_165_824