Vote for your favorite SkillMD. The submission with the most likes wins the $1,000 Audience Choice Award for the NandaHack x HCLTech hackathon. Voting is open through September 25.Vote now →
in reviewhumanPR #133Trust

feat: add structured receipt field to Evidence type

feat: add structured receipt field to Evidence type

Author

Anurag17-2005 avatar

@Anurag17-2005

github profile →
Status
In review
Opened on
Jul 9
Branch
hackathon/anurag-structured-receipt-field

Description

The pitch.

 feat: add structured receipt field to Evidence type

Fixes #64

Problem: Evidence type had no structured payload field for receipts.
Trust plugins (agent_receipts, parc) were forced to smuggle receipts
as JSON strings in the 'detail' field, requiring every consumer to
try-parse and handle decode failures.

Solution: Add optional 'receipt: dict[str, Any] | None' field to Evidence.
- Backward compatible: defaults to None, existing code unchanged
- agent_receipts now prefers receipt field over detail JSON parsing
- Falls back to detail field for legacy Evidence objects
- Plain text detail still works (heuristic path)

Changes:
- nest_core/types.py: Added receipt field with documentation
- agent_receipts.py: Updated report() to check receipt field first
- test_plugins.py: Added 8 tests covering all code paths:
  * Structured receipt field with valid receipts (new path)
  * Receipt preferred over detail when both present
  * Discriminating test proving field ordering
  * None receipt falls back to detail
  * Plain text detail still works
  * Empty fields use heuristic
  * Backward compatibility verified

---

## Submission Statement

**This is my primary NandaHack Phase 1 submission.**

PR #129 (Reputation Validator Fix) is a supplementary bug fix for issue #98 that I'm contributing alongside this main submission.

---

## Reviewer Feedback Addressed

All 4 points from the initial review have been addressed:

1. ✅ **Valid receipt tests**: Added 8 comprehensive tests using `_receipt()` and `_corroborated()` helpers. Tests verify actual receipt processing (score > 0) vs heuristic fallback.

2. ✅ **Scenarios updated**: 
   - `parc_migration.py` line 228: uses `receipt=receipt`
   - `parc_migration.py` line 311: kept `detail=json.dumps(receipt)` as fallback test
   - `receipt_reputation.py`: uses `receipt=receipt_dict`

3. ✅ **Documentation fixed**:
   - Updated `agent_receipts.py` module docstring (removed "has no receipt field")
   - Removed v0.2.0 version claim from Evidence docstring
   - Added examples for both structured and legacy usage

4. ✅ **CI verified**: All checks pass

---
 ## CI Output

``` 
make ci-local

All checks passed!
===== 1158 passed, 1 skipped, 1 deselected, 1 warning in 97.94s (0:01:37) =====
ci-local: all 5 checks passed. Safe to push.
```

Try it

Open PR on GitHubView diff

Checkout locally

git fetch origin pull/133/head:pr-133
git checkout pr-133