# UAT Results: Policy Source Tracking in Persistent Mode

**Date:** 2026-02-04
**Tester:** Claude (automated)
**Aphoria Version:** 0.1.0 + PackSourceStore + Ingestor Deadlock Fix + Bless Export Fix

## Executive Summary

**PASS** - The policy source tracking feature works correctly. All identified issues have been fixed.

## Test Results

### Success Criteria (from UAT Plan)

| Criterion | Expected | Status | Notes |
|-----------|----------|--------|-------|
| Import stores pack source | Entry in PackSourceStore per assertion | **PASS** | Verified via unit test |
| Conflict shows policy_source | `ConflictingSource.policy_source` populated | **PASS** | `check_conflicts()` looks up store |
| Pack name correct | Matches exported pack name | **PASS** | "Persistent Test Pack" retrieved |
| Pack version correct | Matches exported version | **PASS** | "3.0.0" retrieved |
| Issuer hex correct | 8 chars (4 bytes of pubkey) | **PASS** | `issuer_hex.len() == 8` asserted |
| Persistence survives restart | Reopen LocalEpisteme, data present | **PASS** | Test reopens and queries successfully |

### Unit Tests

| Test | Result | Time |
|------|--------|------|
| `test_policy_source_info_in_conflict` (ephemeral) | **PASS** | 0.7s |
| `test_persistent_mode_policy_source_tracking` | **PASS** | 0.7s |
| `pack_source_store::test_set_and_get_pack_source` | **PASS** | 0.5s |
| `pack_source_store::test_different_subjects_isolated` | **PASS** | 0.5s |
| `pack_source_store::test_overwrite_pack_source` | **PASS** | 0.5s |
| `pack_source_store::test_get_nonexistent_pack_source` | **PASS** | 0.5s |

### CLI Commands (Deadlock Fix Verified)

| Command | Before Fix | After Fix | Status |
|---------|------------|-----------|--------|
| `aphoria bless` | Hung forever | 0.3s | **PASS** |
| `aphoria policy export` | Hung forever | 0.3s | **PASS** |
| `aphoria policy import` | Hung forever | 0.3s | **PASS** |
| `aphoria scan --persist` | Hung forever | 0.3s | **PASS** |

## Issues Found

### Issue 1: CLI Deadlock (FIXED)

**Root Cause:** Background ingestor task held worker mutex for entire `run()` loop, blocking `process_pending()`.

**Fix Applied:** Changed `crates/stemedb-ingest/src/ingestor.rs` to use per-iteration locking.

**Status:** ✅ RESOLVED

### Issue 2: Bless→Export Workflow Gap (FIXED)

**Symptom:** `aphoria bless` creates assertions with predicate "enabled", but `aphoria policy export` only exported assertions with predicate "acknowledged".

**Impact:** `bless` → `export` produced a pack with 0 assertions.

**Fix Applied:**
1. Modified `ingest_claims()` in `local.rs` to track blessed claims (where `claim.file == "aphoria_bless"`) in predicate index under key "blessed"
2. Added `fetch_blessed_assertions()` method to retrieve blessed assertions
3. Updated `export_policy()` in `policy_ops.rs` to include both acknowledged AND blessed assertions

**Status:** ✅ RESOLVED

## Verification Commands

```bash
# Run unit tests
cargo test --package aphoria test_persistent_mode_policy_source_tracking
# Result: ok. 1 passed

# Verify CLI no longer hangs
time aphoria bless "code://test/policy" --predicate enabled --value true --reason "Test"
# Result: 0.3s (was hanging forever)

time aphoria policy import some.pack
# Result: 0.3s (was hanging forever)

# Verify bless→export workflow
aphoria bless "code://test/tls/enabled" --predicate enabled --value true --reason "TLS must be enabled"
aphoria policy export --name "Test Pack" --output test-export.pack
# Result logs show:
#   Fetched acknowledgment assertions count=0
#   Fetched blessed assertions count=1
#   Collected assertions for export acknowledged=0 blessed=1 total=1
```

## Files Modified

1. **`crates/stemedb-storage/src/pack_source_store.rs`** - New module (PackSourceStore)
2. **`crates/stemedb-storage/src/key_codec/subject_keys.rs`** - Added `pack_source_key()`
3. **`crates/stemedb-storage/src/lib.rs`** - Export PackSourceStore
4. **`applications/aphoria/src/episteme/local.rs`** - Wire pack_source_store, track blessed claims, add `fetch_blessed_assertions()`
5. **`applications/aphoria/src/policy_ops.rs`** - Store pack source on import, export both acknowledged AND blessed assertions
6. **`crates/stemedb-ingest/src/ingestor.rs`** - Fix deadlock (per-iteration locking)

## Conclusion

**Policy Source Tracking: PASS**
- Feature works correctly when Trust Packs contain assertions
- Pack sources are stored on import and retrieved during conflict detection
- All unit tests pass

**CLI Deadlock: FIXED**
- All CLI commands complete in < 0.3s
- No longer hangs on bless/export/import/scan

**Bless→Export Workflow: FIXED**
- `bless` + `export` now works correctly
- Blessed assertions tracked in predicate index under "blessed" key
- Export includes both acknowledged and blessed assertions
- Verified: `bless` → `export` produces pack with 1 assertion (was 0)

---

**Status: APPROVED FOR MERGE**

All features complete and working:
- Policy source tracking in persistent mode
- CLI deadlock fixed
- Bless→export workflow fixed
