Skip to content

chore: architecture docs, tests consolidated under Tests/, coverage floor 54.7% → 68% - #116

Merged
DoRmAmMu1997 merged 5 commits into
mainfrom
chore/docs-and-tests-restructure
Aug 10, 2026
Merged

chore: architecture docs, tests consolidated under Tests/, coverage floor 54.7% → 68%#116
DoRmAmMu1997 merged 5 commits into
mainfrom
chore/docs-and-tests-restructure

Conversation

@DoRmAmMu1997

@DoRmAmMu1997 DoRmAmMu1997 commented Aug 10, 2026

Copy link
Copy Markdown
Owner

Two structural changes plus a gate tightening. No runtime behaviour is touched ? no strategy, execution, market-data or risk code changed.

1. docs/ is now a real architecture set

The folder held only Superpowers session artefacts (a plan and a spec from one July session, already stale). Those are now gitignored and untracked ? kept on disk, matching the existing .superpowers/ rule that had simply missed this subtree.

In their place:

Path Contents
docs/README.md Index and reading order
docs/hld/system-overview.md Requirements, context, component + thread model, data flow, failure model, trade-offs, what would force a redesign
docs/lld/ 12 component designs
docs/adr/ 11 decision records

The ADRs are retrospective and carry the part that is expensive to reconstruct later ? why an acknowledgement is never treated as a fill, why live trading needs two flags, why the size multiplier is deliberately not global, why the LLM agents own judgement but never sizing or stops. Each one states the options actually considered and what was given up.

The division of labour against existing docs: README.md stays operator setup, CLAUDE.md/AGENTS.md stay agent rules, per-folder Readmes stay folder-local. docs/ answers "how does this fit together, and why".

2. Every test now lives under Tests/, mirroring the source tree

36 test files and 4 conftests moved. Runtime folders now contain only runtime code ? Dependencies/ previously showed 13 test files against 15 runtime modules.

Tests/
??? test_nifty_multi_strategy_master.py     ??? Signal Generators/
??? test_market_data_health.py              ?   ??? CPR AI Agent/
??? Data Extractors/                        ?   ??? CPR Strategy/
??? Dependencies/                           ?   ??? Regime Adaptive Strategy/
    ??? Dhan API/                           ?   ??? SL Hunting AI Agent/
    ??? Flattrade API/                      ?   ??? Subhamoy Strategies/

Every __file__ anchor was rewritten to resolve from the repository root. Each mirrored folder for a spaced-name source folder carries a conftest.py that puts the source folder on sys.path ? never the test folder ? so tests exercise the same import resolution the runner uses.

That narrow scoping is deliberate and is why a flat Tests/ was rejected: Signal Generators/CPR AI Agent/conftest.py inserts only that agent's directory precisely so a test cannot resolve an import production would fail on. One flat conftest would have erased that property for every strategy at once.

Two rules for new tests, documented in the README and CLAUDE.md/AGENTS.md: mirror the source path, and keep the filename unique repository-wide (pytest keys modules by basename ? there are no __init__.py files).

3. Coverage floor raised 54.7% ? 68%

54.7% was the baseline measured before the gate was installed. Hosted CI now measures 69.1%, so the final floor is 68%: a 13.3-point improvement with about 1.1 points of headroom against the environment that actually enforces the gate.

A local machine with neo_api_client and pyotp installed runs seven optional tests that CI's core environment skips and reads about 71.4%. Those tests affect modules outside the broker-adapter threshold table, so passing the adapter's separate 80% budget does not make the repository-wide totals equivalent. The floor must therefore be judged from hosted CI, not from a developer machine with extra optional SDKs.

The floor is documented as one-way: it only ever moves up, and only after a hosted CI run shows headroom.

Verification

Counts were compared exactly, not just checked for green ? a silently uncollected test still looks like a passing build.

Suite Before After
unittest master 487 487
unittest market-data-health 26 26
pytest 1089 1089

Also green locally: ruff, mypy (53 files), compileall, bandit, pre-commit config validation, the branch-enabled coverage run at the new 68% floor, and the per-module policy gate. Verified separately that zero Tests/ files leak into the coverage report ? the omit patterns needed both Tests/* and Tests/**/* because Coverage.py's * does not cross a path separator.

CLAUDE.md and AGENTS.md remain byte-identical after the ## What this project is marker, as test_repository_policy requires.

Note before merging

Tests/test_sl_hunting_schema.py differs between main and the unmerged feat/sl-hunting-knowledge-v4d branch. That PR will hit a rename-vs-edit conflict on the file's new path ? straightforward to resolve, but worth sequencing deliberately.

Follow-up (not in this PR, to keep it surgical)

test_repository_policy.py already fails the build on stale worker-roster claims in README.md, CLAUDE.md, AGENTS.md and the master file. Extending that staleness gate to cover docs/hld/ is recorded as an open item in ADR-0011.

?? Generated with Claude Code

@DoRmAmMu1997 DoRmAmMu1997 changed the title chore: architecture docs, tests consolidated under Tests/, coverage floor 54.7% → 70% chore: architecture docs, tests consolidated under Tests/, coverage floor 54.7% → 68% Aug 10, 2026
@DoRmAmMu1997

Copy link
Copy Markdown
Owner Author

Architecture review follow-up implemented in commit 90d19c0.

Changes made:

  • corrected HLD requirement F5 so it no longer claims unattended restart recovery; partial/lost-response tracking is in-process, while restart exposure is blocked by the account-wide startup audit and requires operator reconciliation
  • documented the distinct exposure scopes: startup is account-wide, shutdown is gated by the runner-owned execution ledger, and the final account-wide audit is advisory for possible manual positions
  • replaced the inaccurate "exactly two shared mutable objects" claim with the actual synchronized boundaries: the shared store/safety aggregate, serialized broker access, lifecycle and shutdown signals, and the optional Telegram queue
  • clarified that CPR RSI/SRSI and geometry values are code-owned invariants covered by focused tests, not env.example settings
  • aligned the lifecycle module docstring and strategy-worker LLD with those contracts
  • corrected the PR title/body from a 70% coverage floor to the final hosted-CI-based 68% floor and documented why local optional SDKs read higher

Verification:

These are documentation/docstring corrections only; no strategy, market-data, risk, or execution behavior changed. PR #117 has also been rebased onto this new #116 head.

DoRmAmMu1997 and others added 5 commits August 10, 2026 21:12
Two structural changes, no runtime behaviour touched.

docs/ — the folder held only Superpowers session artefacts. Those are now
gitignored and untracked (kept on disk), matching the existing .superpowers/
rule, and docs/ carries a committed architecture set instead:

  docs/README.md          index and reading order
  docs/hld/               one high-level design for the whole repository
  docs/lld/               12 low-level designs, one per component
  docs/adr/               11 decision records for choices already in force

The ADRs are retrospective: they record why the safety model looks the way it
does (typed order outcomes, the two-flag live gate, the per-strategy size
multiplier, host-owned gates around the LLM agents), which is the part that is
expensive to reconstruct later.

Tests/ — every test file and test conftest moved into a top-level Tests/ tree
mirroring the source layout, so runtime folders hold only runtime code. Each
mirrored folder for a spaced-name source folder carries a conftest.py that puts
the SOURCE folder on sys.path, never the test folder, preserving the narrow
import scope the co-located conftests had. Path anchors now resolve from the
repository root.

Updated for the new paths: the CI workflow (both jobs), pyproject (Ruff
per-file-ignores and coverage omit), README.md, CLAUDE.md, AGENTS.md and the
per-folder Readmes. CLAUDE.md and AGENTS.md remain byte-identical after the
"What this project is" marker, as test_repository_policy requires.

Verified by exact count rather than by a green run:
  487 master + 26 market-data-health + 1089 pytest = 1602, before and after.
Also green: ruff, mypy (53 files), compileall, bandit, pre-commit config
validation, the branch-enabled coverage run (71.4%, floor 54.7%) with zero
Tests/ files leaking into the report, and the per-module coverage policy gate.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The 54.7% floor was the branch-enabled baseline MAT-110 measured before the
gate was installed. Coverage has grown to 71.4% since, so a floor 17 points
below actual was no longer stopping erosion -- roughly 3,100 statements could
have lost their tests without the build noticing.

Raised to 70.0, which leaves ~1.4 points of real headroom against the measured
71.4%. The per-module budgets are unchanged: 90% for the safety/data-safety
tier, 80% per broker adapter.

On the local-vs-CI question: neo_api_client and pyotp are installed locally but
are NOT in CI's verify job. That does not move the number -- CI already enforces
and passes the 80% budget on kotak_execution.py without the Kotak SDK, because
the adapters are tested through injected doubles rather than the real client.

Updated everywhere the floor is stated so they cannot drift: pyproject,
test_repository_policy's assertion, check_coverage_thresholds' docstring,
README.md, CLAUDE.md, AGENTS.md and docs/lld/testing-and-ci.md. The two agent
guides remain byte-identical after the shared marker.

Documented the one-way rule next to the setting: this floor only ever moves UP,
and only after a run shows headroom. Lowering it to make a red build pass
defeats the gate.

Verified locally: coverage report exits 0 at the new floor (71.4%), the
per-module policy gate passes, ruff clean, and the policy suite passes with the
updated assertion.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…ocal run

The previous commit set the floor to 70.0 on a locally measured 71.4%. CI
reports 69.1%, so the build failed by 0.9 points. The floor is now 68.0, which
leaves ~1.1 points of headroom against the number that actually gates the build.

My reasoning in the previous commit was wrong and is worth recording. I argued
the missing broker SDKs could not move the total, because CI already enforces
and passes the 80% budget on kotak_execution.py without neo_api_client. That
holds for the ADAPTER, but not for everything the SDK gates: CI's verify job
runs "1082 passed, 7 skipped" where a local run with neo_api_client and pyotp
installed runs 1089 passed, 0 skipped. Those 7 tests are worth ~2.3 points of
overall coverage. Enforcing a per-module budget says nothing about the modules
outside that dict.

So the rule is now written next to the setting and in both agent guides: judge
this floor from CI, never from a local run, because a developer machine with the
optional broker SDKs installed reads about 2 points high. CI deliberately
installs core + dev + ai + codex-ai only -- Kotak's official tag pins older
pandas/requests and cannot share the audited core environment -- so the hosted
number is the honest one.

Still a +13.3 point improvement on the 54.7% baseline, and the one-way rule
stands: only move it UP, and only after a CI run shows headroom.

Note the restructure itself was never in question in that failed run: CI
collected 487 master + 26 market-data-health + 1089 (1082 passed, 7 skipped)
across both Python 3.12 and 3.13, matching the pre-move counts exactly, and both
broker-dependency jobs passed. Only fail_under was wrong.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Clarify restart limits, startup versus shutdown exposure scope, shared synchronization boundaries, and CPR code-owned invariants.

Co-authored-by: Codex <codex@openai.com>
Co-authored-by: Codex <codex@openai.com>
@DoRmAmMu1997
DoRmAmMu1997 force-pushed the chore/docs-and-tests-restructure branch from 3ad55b1 to 68ac534 Compare August 10, 2026 15:43
@DoRmAmMu1997
DoRmAmMu1997 merged commit 78ee55d into main Aug 10, 2026
4 checks passed
@DoRmAmMu1997
DoRmAmMu1997 deleted the chore/docs-and-tests-restructure branch August 10, 2026 19:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant