Skip to content

test(train): unit tests for z0int.train - #281

Draft
kvnloo wants to merge 2 commits into
devfrom
chatgpt/n27-z0int-train
Draft

kvnloo wants to merge 2 commits into
devfrom
chatgpt/n27-z0int-train

Conversation

@kvnloo

@kvnloo kvnloo commented Oct 27, 2026

Copy link
Copy Markdown
Owner

Implements #260.

Changed files

  • tests/test_train_next_action.py (new): hermetic pytest coverage using only NumPy, pytest, stdlib, and z0int; episode/report files remain under tmp_path.
  • src/z0int/train.py: two minimal input-boundary fixes, with no refactor:
    • test_load_xy_ignores_blank_lines: skip blank/whitespace-only JSONL lines before json.loads to avoid a JSONDecodeError.
    • test_main_too_few_episodes: reject 1–100 valid episodes with SystemExit("need more than 100 episodes") before the 100-row confirmation floor would leave an empty training split.

Acceptance checklist mapped to tests

  • test_hash_is_unit_norm_and_deterministic — 96-dimensional norm/determinism/case-folding and 8-dimensional override.
  • test_hash_short_and_empty_text — empty, None, and two-character text each produce one normalized trigram bucket.
  • test_ridge_fit_recovers_identity — unregularized identity fit and output shape.
  • test_load_xy_skips_unknown_family_and_joins_prev — unknown/missing family skip; family IDs, missing user/prev, and joined previous features.
  • test_load_xy_no_valid_rows_exits — both empty file and unknown-only file produce SystemExit("no episodes").
  • test_load_xy_ignores_blank_lines — regression for blank JSONL lines.
  • test_mb_provider_unset — opt-in env unset returns a clear unavailable reason.
  • test_mb_provider_unimportable_and_incomplete — missing module, incomplete provider, and fully populated fake provider resolution.
  • test_main_writes_report_with_time_split — 120 alternating rows, 20/100 split, exact class counts, ridge parameters, baseline accuracy, report file/stdout equality, no MB keys.
  • test_main_mb_unavailable_and_available — missing opt-in provider report and fake fit_fly/predict_fly report with n_kc=12 and seed=1.
  • test_main_too_few_episodes — controlled failure with 1, 50, and 100 rows, no report written.
  • No changes outside the two issue-allowed paths; no deps, lockfiles, or CI edits.
  • Runtime verification of test cases (not executed in this ChatGPT connector-only work).

tests NOT RUN - ChatGPT cannot execute code
tests NOT RUN (written via connector)

Exact test command

pip install -e '.[test]' && python -m pytest -q tests/test_train_next_action.py

No CI/test results or device evidence are asserted.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:verify Tests, mutation, evidence

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant