> ## Documentation Index
> Fetch the complete documentation index at: https://calendar-effects.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# How we know the numbers are right, and what stops mistakes

> docs/architecture/07-checks-and-guardrails.mmd

```mermaid theme={null}
%% Calendar Effects · 7 of 8 · How we know the numbers are right, and what stops mistakes.
%% Paste into Miro: Creation bar > Diagram > Build with code.
flowchart TB
  subgraph THREE["Three independent answers to the same question must agree"]
    stream[("Streaming job output<br/>day by day, with state")]
    direct["scripts/check_streaming.py<br/>recomputes every daily AR and every event CAR<br/>from master with plain numpy, no streaming at all"]
    batch[("Batch answer key<br/>car.py, whole arrays")]
    cs{"check_streaming: OK<br/>95,190 daily rows + 2,280 CARs<br/>equal to about 1e-16"}
    cmp{"scripts/compare_stream_batch.py<br/>rules in src/streaming/compare.py<br/>joins on ticker, event_type, event_date<br/>every column must match within 1e-9<br/>2,280 of 2,280 equal at 38 retailers<br/>600 of 600 on the SFU cluster at 10"}
  end

  subgraph TESTS["tests/ · python3 -m pytest -q · run before every commit"]
    tc["test_contracts · docs and code contracts agree"]
    tcf["test_config · every config row is valid"]
    tcl["test_clean_files · clean tables match their contracts,<br/>cover 2016–2025, carry exactly the calendar's events;<br/>if not, names the script to re-run"]
    tnh["test_no_hardcoding · no ticker, event, year, path<br/>or Kafka setting typed into etl/, src/, scripts/"]
    tev["test_event_calendar + test_expand_events<br/>date rules give the right dates, e.g. Black Friday 2024"]
    tsig["test_streaming_signals · the per-stock logic"]
    tes["test_eventstudy · the batch study"]
    tcmp["test_compare · an empty, cut-short or duplicated stream fails"]
    thook["test_commit_hook · the commit hook itself"]
  end

  subgraph GUARDS["Guardrails around every change"]
    req["require_contract before every save<br/>a script refuses to write a wrong table"]
    hook["Commit hook · .claude/hooks/pre-commit-tests.sh<br/>runs all tests on exactly what a commit contains<br/>blocks the commit if any fail · Claude Code and Cursor"]
    brief["Session brief · .claude/hooks/session-brief.sh<br/>shows STATUS and the newest handoffs<br/>at the start of every Claude session"]
    checker["contract-checker subagent<br/>reviews code that reads or writes a contracted table<br/>its memory is committed for the whole team"]
    team["Team records · docs/STATUS.md · docs/handoffs/<br/>docs/decisions/ · docs/ai-usage/<br/>AGENTS.md rules 1–12 · docs-site/"]
  end

  stream --> cs
  direct --> cs
  stream --> cmp
  batch --> cmp
  TESTS --> hook
  req --> tcl
```

## Guide

```mermaid theme={null}
%% Calendar Effects · Guide 7 · How we know the numbers are right, and what stops mistakes · goes next to diagram 07-checks-and-guardrails.mmd
%% Miro: paste onto a board, or Creation bar > Diagram > Build with code. Read top to bottom.
flowchart TB
  T["GUIDE 7 · CHECKS AND GUARDRAILS<br/>how we know it's right, what stops mistakes"]

  subgraph S1["1 · THREE WAYS TO THE SAME ANSWER"]
    direction LR
    a1["STREAM<br/>day by day, with state"] --> a4{"ALL AGREE<br/>2,280 of 2,280 CARs"}
    a2["DIRECT NUMPY<br/>check_streaming.py"] --> a4
    a3["ANSWER KEY<br/>car.py"] --> a4
  end

  subgraph S2["2 · THE COMPARISON · compare.py"]
    direction TB
    c1["MATCHED ON<br/>ticker · event · event date"]
    c2["MUST AGREE<br/>decimals within 1e-9<br/>dates and counts exactly"]
    c3["FAILS IF<br/>a window is missing or doubled<br/>or the stream is empty"]
    c4["STILL OPEN IS OK<br/>if day +5 is after<br/>the stream's last day"]
  end

  subgraph S3["3 · TESTS ON THE DATA · python3 -m pytest -q · 100+ tests"]
    direction TB
    t1["test_contracts<br/>docs and code agree"]
    t2["test_config<br/>every config row is valid"]
    t3["test_clean_files<br/>tables match their contracts<br/>names the script to re-run"]
    t4["test_event_calendar<br/>rules give the right dates"]
  end

  subgraph S4["4 · TESTS ON THE CODE"]
    direction TB
    t5["test_no_hardcoding<br/>no typed-in tickers,<br/>years or paths"]
    t6["test_streaming_signals<br/>test_eventstudy<br/>the maths on both sides"]
    t7["test_compare<br/>a bad stream must fail"]
    t8["test_commit_hook<br/>the hook itself"]
  end

  subgraph S5["5 · GUARDRAILS ON EVERY CHANGE"]
    direction TB
    g1["require_contract<br/>no script saves a wrong table"]
    g2["COMMIT HOOK<br/>runs the tests on the commit<br/>blocks it if one fails"]
    g3["ONE COMMAND AT A TIME<br/>git add, then git commit"]
  end

  subgraph S6["6 · TEAM RECORDS AND AI HELPERS"]
    direction TB
    m1["STATUS.md<br/>now · next · blocked on"]
    m2["handoffs/<br/>one note per session"]
    m3["decisions/<br/>0001 to 0006"]
    m4["ai-usage/<br/>for the AI Usage Report"]
    m5["CONTRACT-CHECKER<br/>reviews code that<br/>touches a contract"]
  end

  T --> S1 --> S2 --> S3 --> S4 --> S5 --> S6

  classDef head fill:#2C2C2A,stroke:#2C2C2A,color:#FFFFFF
  classDef idea fill:#E6F1FB,stroke:#185FA5,color:#0C447C
  classDef step fill:#E1F5EE,stroke:#0F6E56,color:#085041
  classDef warn fill:#FAECE7,stroke:#993C1D,color:#712B13
  classDef win fill:#EAF3DE,stroke:#3B6D11,color:#27500A
  classDef file fill:#F1EFE8,stroke:#5F5E5A,color:#444441
  class T head
  class a1,a2,a3,g1,g2 step
  class a4 win
  class c1,c2,c4,m5 idea
  class c3,g3 warn
  class t1,t2,t3,t4,t5,t6,t7,t8,m1,m2,m3,m4 file
  style S1 fill:#FFFFFF,stroke:#B4B2A9
  style S2 fill:#FFFFFF,stroke:#B4B2A9
  style S3 fill:#FFFFFF,stroke:#B4B2A9
  style S4 fill:#FFFFFF,stroke:#B4B2A9
  style S5 fill:#FFFFFF,stroke:#B4B2A9
  style S6 fill:#FFFFFF,stroke:#B4B2A9
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.