Skip to content

Commit 752bcc7

Browse files
author
wildleo91
committed
test(ring-1-day-2-chunk-1): dispatch integrity + simple POST happy paths
Ring 1 Day 2 chunk 1 — 26 new tests, all passing. Total suite 720 (was 694). tests/integration/test_dispatch_integrity.py (new) — 16 tests: Read-only contract tests for the GET_ACTIONS and POST_ACTIONS dispatch tables. No fixture overhead. Catches an entire class of silent wiring bugs: - Tables exist + non-empty (2) - Entry shape: (roles, method_name) where roles is None or a collection of strings, method_name is a string (2) - Method resolution: every method_name resolves to a callable on the handler instance (2) - Naming convention: every method follows _action_<name> (2) - No duplicate names across or within tables (3) - RBAC tier hard-list — superadmin/admin/edit actions pinned to the right tier; weakening fails the test (3) - Public actions allow-list — every action with roles=None must be on a hardcoded allow-list with documented rationale (2). Catches the regression where a destructive action silently loses its role tier. Discovery during writing: roles are Set[str], not tuple. Test adjusted; this is the kind of contract clarification that test- writing surfaces. tests/integration/test_post_happy_paths.py (new) — 10 tests: Each test issues a real POST against the test container and asserts the FULL response shape, not just top-level keys. Uses container_state fixture for state-mutating tests. Tier 1 (no preconditions) — 7 tests: - mark_notifications_read — success flag - save_col_widths — success flag + round-trip via GET - log_event — csv_exported / csv_imported / audit_exported - set_trash_retention — config file persisted Tier 2 (preconditions) — 3 tests: - create_csv — full shape (success, csv_file echo, message) - create_rule — full shape (success, detection_rule echo, message) - save_csv (small edit) — including the pending_approvals deep contract that pins all 8 build-641 fields. Same projection drift as build-641 in this endpoint would fail this test. API contract discoveries: - create_csv and create_rule both take detection_rule (not rule_name) — pinned in test fixtures so it's self-documenting - save_csv requires detection_rule + headers + rows + expected_*; test now follows the proper sequence: GET mapping → resolve rule → GET csv_content → POST save_csv Day 2 continues with more happy paths + error paths.
1 parent bb87c32 commit 752bcc7

3 files changed

Lines changed: 895 additions & 0 deletions

File tree

docs/RING_FINDINGS.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,3 +382,74 @@ after Ring 0 — net +8 from the new fixture smoke tests.
382382
Container snapshot+restore cost confirmed at ~3 seconds per
383383
fixture-using test (well within the 2-4 second budget). Total
384384
suite runtime: 31.5 seconds.
385+
386+
### Day 2 (chunk 1) — dispatch integrity + simple POST happy paths
387+
388+
**Status**: in progress (chunk 1 done; chunks 2+ continue Day 2-3).
389+
390+
#### `tests/integration/test_dispatch_integrity.py` (new) — 16 tests
391+
392+
Pins the structural invariants of ``GET_ACTIONS`` and
393+
``POST_ACTIONS``. Read-only, no fixture overhead. Covers:
394+
395+
- Tables exist + are non-empty dicts (2 tests)
396+
- Every entry has the right shape (roles + method_name) (2 tests)
397+
- Every method_name resolves to a callable on the handler (2 tests)
398+
- Every method_name follows ``_action_<name>`` naming (2 tests)
399+
- No action name in both tables, no duplicate method_names (3 tests)
400+
- **RBAC tier hard-list** — known-superadmin/admin/edit actions
401+
pinned to the right tier; weakening a tier fails the test
402+
(3 tests)
403+
- **Public actions allow-list** — every action with ``roles=None``
404+
must be on a hardcoded allow-list with a documented rationale
405+
(2 tests). Catches the regression where a destructive action
406+
silently loses its role tier.
407+
408+
Discovery during test development: my initial assumption was that
409+
roles were tuples — they're actually ``Set[str]``. Test was
410+
adjusted; this is exactly the kind of contract clarification
411+
that test-writing surfaces.
412+
413+
#### `tests/integration/test_post_happy_paths.py` (new) — 10 tests
414+
415+
Each test issues a real POST against the test container and
416+
asserts the FULL response shape, not just top-level keys. Uses
417+
``container_state`` fixture for state-mutating tests.
418+
419+
Tier 1 (no preconditions) — 7 tests:
420+
- ``mark_notifications_read`` — success flag
421+
- ``save_col_widths`` — success flag + round-trip via GET (2 tests)
422+
- ``log_event`` — csv_exported / csv_imported / audit_exported
423+
variants (3 tests)
424+
- ``set_trash_retention`` — config file written with new value
425+
426+
Tier 2 (preconditions needed) — 3 tests:
427+
- ``create_csv`` — full response shape (success, csv_file echo,
428+
message)
429+
- ``create_rule`` — full response shape (success, detection_rule
430+
echo, message)
431+
- ``save_csv`` (small edit, no approval) — including the
432+
``pending_approvals`` deep contract that pins all 8 fields
433+
(build-641 fence). If the same projection drift recurs in
434+
``save_csv``'s embedded pending_approvals, this test fails.
435+
436+
Field-name discoveries during test writing (good signal — pins
437+
the actual API contract):
438+
- ``create_csv`` and ``create_rule`` both take ``detection_rule``
439+
(not ``rule_name``). The mapping CSV stores ``rule_name`` as
440+
the column header but the API uses ``detection_rule``
441+
consistently. Documenting this in the test fence makes it
442+
self-pinning.
443+
- ``save_csv`` requires ``detection_rule`` AND ``headers`` AND
444+
``rows`` AND ``expected_mtime`` AND ``expected_content_hash``.
445+
Missing any returns 400. Test now follows the proper sequence:
446+
GET mapping → resolve rule → GET csv_content → POST save_csv.
447+
448+
#### Day 2 chunk 1 summary
449+
450+
26 new tests, all passing. Total suite: **720 tests** (was 694).
451+
Total runtime: ~46 seconds (15 of those are the new docker tests).
452+
453+
Continuing Day 2-3 with: more POST happy paths (purge_trash,
454+
restore_from_trash, save_as_default, submit_approval, etc.), then
455+
POST error paths and approval workflow.

0 commit comments

Comments
 (0)