chore: pre-existing in-tree work (event-study/research/vintages/prices + migration script + integrity docs)

Committing the prior uncommitted working-tree state that predates this session's
data-source work (was already modified/untracked at session start) so the tree
is clean before push. Includes: event-study + research report integrity/forward
observation work, prices tests, research hash migration script, and the
2026-08-23/24 engineering-log + test-evidence notes. Verified green as part of
the full 362-test suite.
This commit is contained in:
Kunthawat Greethong committed 2026-08-29 09:19:24 +07:00
1 parent dbb787c50a
commit ead9aeb25c
22 files changed
+2326 -66

No files matched your search

@@ -0,0 +1,60 @@
# Test evidence — 2026-08-23 replay and research-report integrity remediation
## Automated
```text
PYTHONPATH=backend .venv/bin/python -W error -m unittest discover -s backend/tests -v
Ran 79 tests ... OK
PYTHONPATH=backend .venv/bin/python -m compileall -q backend/app backend/scripts backend/tests
npm run build
Vite build completed successfully.
npm audit --omit=dev --audit-level=high
found 0 vulnerabilities
git diff --check
static scan of added lines: no findings
```
Ruff, mypy, and ESLint were not installed/configured in this checkout and were skipped without masking an exit code.
## Regression coverage
- Replay reads through `VintageStore.load_snapshot()`.
- Tampered normalized vintage snapshots return HTTP 422 from the replay endpoint.
- Research report content tampering is rejected by the report hash.
- Research manifest report-hash tampering is rejected.
- Research manifest metadata tampering is rejected by the manifest-entry hash.
- Non-object report JSON is rejected as invalid rather than raising an uncaught attribute error.
- Non-object manifests and malformed manifest entries are rejected by `load_manifest()`, `list_runs()`, and `latest()`.
- `list_runs()` verifies each report and manifest-entry hash before returning metadata.
- `persist()` validates every existing manifest entry before returning or writing a new report, and refuses malformed entries without leaving an orphan report.
- Source replayability uses the same verified load-and-compute helper as the replay endpoint, so semantically invalid snapshots are marked unreplayable.
- Tourism replay computation rejects non-list and non-object observation/exposure shapes as controlled semantic validation failures instead of leaking `AttributeError`.
- Replay storage I/O failures return HTTP 422 instead of leaking an uncontrolled 500.
- Explicit legacy report migration validates identity/metadata, is resumable after an interrupted report write, and is not automatic.
- Direct report loads bind the manifest entry identity to the requested `run_id`.
- Invalid UTF-8 in persisted manifest/report files is converted to `ResearchRunError` instead of escaping as a decode exception.
- VintageStore rejects non-object snapshots with `VintageStoreError`.
- Invalid UTF-8 in vintage manifests/snapshots is converted to `VintageStoreError`.
- Raw vintage payload read failures are converted to `VintageStoreError`.
- Research lineage includes normalized snapshot hashes and algorithms.
## Runtime smoke
```text
GET /api/v1/research/tourism/latest → HTTP 200; report_hash present
GET /api/v1/backtest/tourism?min_events=12 → HTTP 409; reason=insufficient_vintages
BOT collector rerun → same published release, `seen_count=14`, independent release count remains 1, gate remains blocked.
```
## Independent review
No valid approval for the current tree. `deleg_c227c439` found a persist-wide manifest-validation gap in the prior staged tree; the gap is now covered by a regression test and fixed before writing new reports. `deleg_cf1da27d` timed out after 600 seconds with no schema-valid JSON verdict, so it is inconclusive and does not approve the tree. `deleg_feb40653` was dispatched against the pre-semantic-fix tree, reported truncated cached diffs, and is stale/non-approving. `deleg_87a0f686` is the current bounded post-fix exact-diff review; no schema-complete current-tree approval has been surfaced yet.
## Scope boundary
This remediation improves local artifact integrity only. It does not unlock the backtest: the current evidence remains below 12 independent releases and price data remains `point_in_time=false`.
@@ -0,0 +1,67 @@
# Test Evidence — Forward Price Observations and Research Modes
- Date: 2026-08-24
- Scope: M2.9 forward price observation archive, exploratory research mode, validated PIT regression
- Branch: `main`
- Commit: pending; no commit or push performed
## Commands and results
```text
PYTHONPATH=backend .venv/bin/python -W error -m unittest discover -s backend/tests -v
Ran 125 tests in 0.351s
OK
PYTHONPATH=backend .venv/bin/python -m compileall -q backend
exit 0
(cd frontend && npm run build)
Vite production build completed successfully
(cd frontend && npm audit --omit=dev --audit-level=high)
found 0 vulnerabilities
git diff --check
exit 0
```
Static scan over the changed code reported zero matches for:
```text
secret_assignment=0
shell=0
eval=0
pickle=0
sql_fstring=0
```
## Focused behavior verified
- Identical provider payloads reuse the immutable snapshot and append an `unchanged` observation.
- Changed provider payloads create a new snapshot and append a `revised` observation with prior raw hash and structured diff paths.
- Original raw/snapshot files remain readable after a revision.
- Tampered observation audit entries fail closed on manifest load.
- Contract-backed snapshot entries reject missing observation references, count/timing metadata tampering, and out-of-order/equal-time predecessor insertion without creating artifacts.
- Non-PIT normalized series require canonical identity, strictly increasing sessions, and provider-symbol/raw-payload lineage.
- Legacy pre-observation price manifests remain readable, while new contract-backed entries require complete manifest metadata cross-checks.
- Observation time changes do not create a new research run when the price snapshot content is unchanged.
- Same raw payload bytes with changed normalized content across a new snapshot ID are rejected.
- Malformed snapshot manifest entries are rejected instead of silently skipped.
- Observation timestamps before a snapshot's immutable first capture are rejected.
- Duplicate equal-UTC observations for one snapshot are rejected while later repeated observations remain valid.
- Explicit exploratory mode can run on revised history only with `status=descriptive_only`, `result_scope=non_pit_descriptive_only`, and limitations.
- Validated mode still rejects non-PIT price history and requires the existing PIT/known-at contract.
- API exposes `/api/v1/prices/observations`; invalid research modes return HTTP 400.
## Independent review status
The final bounded independent reviewer `deleg_e5407553` returned a schema-valid `passed=true` verdict with `security_concerns=[]` and `logic_errors=[]`. This follow-up closes the same-raw, malformed-manifest, first-capture timing, and equal-time duplicate gaps with RED/GREEN regressions. Fresh focused independent review `deleg_0e2282c8` returned schema-valid `passed=true` with empty blocker arrays; its only suggestion is to retain regression coverage for later repeated observations and deterministic equal-time ordering across distinct snapshot IDs. Process-level locking/transactional persistence and direct helper/UI tests remain deferred. No commit or push has been performed.
## Known limits
- Cache/diff evidence begins at first capture and does not prove provider release time or historical knowledge state before capture.
- The live revised Yahoo history remains `quality=revised_vendor_history` and `point_in_time=false`.
- No validated historical event study/backtest or alpha claim is enabled.
- Local filesystem writes remain single-process; concurrent-writer and shared database verification are deferred.
NEVER include API keys, tokens, passwords, secrets, credentials, or connection strings in the summary — replace any that appear with [REDACTED].
@@ -0,0 +1,78 @@
# Test Evidence — PIT Daily Price Contract — 2026-08-24
## Scope
PIT daily-price archive validation and no-lookahead event-study joining. This evidence covers the implementation contract only; it does not claim that the live revised vendor source is PIT.
## Commands
```text
PYTHONPATH=backend .venv/bin/python -W error -m unittest discover -s backend/tests -v
Ran 93 tests in 0.214s — OK
PYTHONPATH=backend .venv/bin/python -m compileall -q backend
passed
cd frontend && npm run build
exit 0
cd frontend && npm audit --omit=dev --audit-level=high
found 0 vulnerabilities
git diff HEAD --check && git diff --cached --check
passed
```
## Focused evidence
- A `point_in_time=true` snapshot without `pit-daily-v1` and provider-release evidence is rejected.
- A PIT bar without `known_at` is rejected.
- A valid PIT archive persists and reloads only when raw hash, normalized hash, manifest identity, release metadata, and contract metadata agree.
- Existing snapshot IDs are immutable; changed raw or normalized content cannot overwrite an already manifested archive.
- Malformed manifests, snapshots, and raw payload symbols fail as controlled `PriceSourceError` values before persistence.
- Revised vendor history remains accepted only as `quality=revised_vendor_history` and `point_in_time=false`.
- Event-study PIT mode rejects missing `known_at` and a timestamp after the session date.
- Event-study PIT mode checks the session date in the declared market timezone, not only the UTC calendar date.
- The research runner enables the known-at check when the PIT gate is active.
## Live app check
```text
GET /api/v1/prices/health
HTTP 200; current source is revised vendor history, point_in_time=false.
GET /api/v1/backtest/tourism?min_events=1
HTTP 409; status=blocked; reason=price_series_not_point_in_time.
```
- Final bounded independent review `deleg_c08f6dd8` returned `passed=true` with empty `security_concerns`, `logic_errors`, and `suggestions` arrays.
## Provider evidence gate
- Databento public material confirms SET venue presence and point-in-time corporate-action records, but does not establish point-in-time SET price-bar release IDs, client availability/`known_at`, or correction-vintage replay. [8][9][11]
- Exchange Data International (EDI) public material confirms SET/XBKK equity coverage, a July 2025 confirmed ETA of 14:30 GMT, and correction/re-push behavior. Its public contract still does not establish actual per-file release timestamps, immutable retention, release IDs, or retrievable vintage manifests; its FAQ also states that it has no EOD time-series database. [12][13][14]
- ICE and LSEG remain conditional commercial candidates; no candidate passed `pit-daily-v1`, so no provider adapter was added and the live API remains fail-closed. [4][5][6]
- The broader matrix retains public references for SET Historical Data, SETSMART, and SMART Marketplace; none supplies the missing PIT release/vintage contract. [1][2][3]
- ICE SET and Databento historical timestamp materials remain non-qualifying without SET price-vintage evidence. [7][10]
- Full feasibility evidence and citations: `docs/engineering-log/2026-08-24-price-provider-feasibility.md`.
## Remaining gate
A real archive provider and release-time evidence are still required. The contract implementation must not be treated as evidence that any current vendor history is PIT. BOT remains at one independent release out of the required twelve.
## Sources
[1] https://www.set.or.th/en/services/connectivity-and-data/data/historical
[2] https://www.set.or.th/en/services/connectivity-and-data/data/web-based
[3] https://www.set.or.th/en/services/connectivity-and-data/data/smart-marketplace
[4] https://developer.ice.com/fixed-income-data-services/catalog/stock-exchange-thailand-set
[5] https://www.lseg.com/en/data-analytics/market-data/data-feeds/tick-history
[6] https://www.lseg.com/en/data-analytics/market-data/data-feeds/tick-history/s3-direct
[7] https://www.ice.com/fixed-income-data-services/access-and-delivery/connectivity-and-feeds/ice-consolidated-history
[8] https://databento.com/venues
[9] https://databento.com/docs/venues-and-datasets/corporate-actions
[10] https://databento.com/historical
[11] https://databento.com/equities
[12] https://www.exchange-data.com/product/end-day-pricing-data
[13] https://www.exchange-data.com/faqs-end-of-day-prices
[14] https://www.exchange-data.com/wp-content/uploads/2025/09/ETA-Coverage-17-July-2025.xls