Skip to content

fix(inventory): add state guards to dispose() and open_item()#365

Closed
robotlearning123 wants to merge 6 commits intomainfrom
fix/dispose-state-guard
Closed

fix(inventory): add state guards to dispose() and open_item()#365
robotlearning123 wants to merge 6 commits intomainfrom
fix/dispose-state-guard

Conversation

@robotlearning123
Copy link
Copy Markdown
Member

Bug

dispose() allowed double-dispose with no state check. open_item() allowed opening items in terminal states (disposed, deleted, depleted, expired). Both would silently succeed, creating misleading consumption log entries.

Root Cause

dispose() checked no preconditions before setting status=disposed and logging consumption. open_item() only checked opened_date is not None but didn't validate the item's current status.

Fix

  • dispose() now rejects items already in disposed or deleted state
  • open_item() now rejects items in disposed, deleted, depleted, or expired state
  • Both raise ValidationError with descriptive message

Test

8 new tests in test_inventory_state_guard.py:

  • TestDisposeStateGuard: double-dispose, dispose-deleted, dispose-available (happy path)
  • TestOpenItemStateGuard: open-disposed, open-deleted, open-depleted, open-expired, open-available (happy path)

🤖 Found and fixed by bug-hunter autonomous loop.

@robotlearning123 robotlearning123 force-pushed the fix/dispose-state-guard branch 2 times, most recently from b1c8f7a to 62015fc Compare March 28, 2026 21:44
@github-actions github-actions Bot added the ci-verified All required CI checks have passed label Mar 28, 2026
@robotlearning123 robotlearning123 force-pushed the fix/dispose-state-guard branch from 49c097c to 063a5a5 Compare March 29, 2026 03:13
sandia777 and others added 5 commits March 28, 2026 23:31
…m, extractor, email_intake

Wave 1 of test coverage improvements for lab-manager:
- test_email_poller.py (NEW): 28 tests for IMAP polling, error handling, shutdown
- test_documents_route_coverage.py: +48 tests for background tasks, CRUD, review, upload
- test_litellm_client.py: +4 tests for load_litellm_config
- test_pubchem.py: expanded test coverage
- test_extractor_coverage.py: expanded test coverage
- test_email_intake.py: expanded test coverage

Unit test count: 1406 → 1444 (+38 net new)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- test_api_validation.py (NEW): 58 tests for email validation (74% → 96%)
- test_more_ocr_coverage.py (NEW): 68 tests for OCR providers (59% → 100%)
- test_extractor_coverage.py: +12 tests for intake/extractor (82% → 98%)
- test_pubchem.py: +6 tests for pubchem service (90% → 100%)
- test_litellm_client.py: +18 tests for litellm client (68% → 100%)
- test_email_poller.py: +31 tests for email poller (78% → 99%)
- test_email_intake.py: +9 tests for email intake (90% → 100%)
- test_documents_route_coverage.py: clean 56 tests (removed isolation-broken classes)

Unit test count: 1406 → 1626 (+220 net new)
All 1626 pass, 0 failures.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
dispose() allowed double-dispose — no status check before setting
disposed. This created misleading consumption log entries with
quantity_used=0. open_item() similarly allowed opening items in
terminal states (disposed/deleted/depleted/expired).

- dispose() now rejects items already in disposed or deleted state
- open_item() now rejects items in disposed/deleted/depleted/expired
- Both raise ValidationError with clear message
- 8 new tests covering all terminal state transitions

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@robotlearning123 robotlearning123 force-pushed the fix/dispose-state-guard branch from 063a5a5 to 83131d1 Compare March 29, 2026 03:31
@robotlearning123 robotlearning123 deleted the fix/dispose-state-guard branch March 29, 2026 04:12
robotlearning123 added a commit that referenced this pull request Mar 29, 2026
## Summary
- Add `InventoryStatus.depleted` to `open_item()` status guard
- Depleted items (quantity=0) should not be openable

Replaces #365

## Test plan
- [x] `tests/test_inventory_guards.py` verifies depleted items raise
ValidationError

Co-authored-by: Cong <72737794+robolearning123@users.noreply.github.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci-verified All required CI checks have passed python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants