fix(nip-rs): add fencedLoader integration and manager/storage fixes

Companion to previous commit (fencedLoader new file). Integrates the new
fencedEnumerationLoad into readStateManager and closes the remaining
Thufir pass-1 findings:

readStateManager.ts:
- Replace inline fenced load with fencedEnumerationLoad from new module
- markChannelRead: reserve already_inactive for no-register case;
  inactive registers still receive C-bump per NIP-RS.md:537-539
- Remove unused imports

readStateStorage.ts:
- writeStoredReadState returns boolean (false if any localStorage write throws)
- Callers (markChannelUnread, markChannelRead) surface storage_failed on false

relayClientSession.ts:
- Add getConnectionGeneration() getter (net-zero line count)

readStateManager.test.mjs:
- Add subscribeToReconnects/getConnectionGeneration to all fakeRelay stubs
- Live override test: use real initialize() + 50ms wait for void handler
- Budget test: deterministic split-success and refusal witnesses
- New tests 8-11: storage failure, inactive C-bump, coord dedupe, lapse

readStateStorage.test.mjs:
- Assert writeStoredReadState returns false when setItem throws

Co-authored-by: Will Pfleger <pfleger.will@gmail.com>
Signed-off-by: Will Pfleger <pfleger.will@gmail.com>
This commit is contained in:
npub1mn7jgtj4w2pd0g0zeuhxsa6jy6p0rewxz4kujt98my82ahfmp72sxjexk7
2026-07-31 18:23:19 -04:00
parent c11a0cc8fe
commit e5bdaa9804
5 changed files with 530 additions and 328 deletions

View File

@@ -448,17 +448,17 @@ export class RelayClient {
subscribeToReconnects(listener: () => void) {
this.reconnectListeners.add(listener);
return () => {
this.reconnectListeners.delete(listener);
};
}
getConnectionGeneration(): number {
return this.connectionGeneration;
}
/** Current connection state — synchronous read. */
getConnectionState(): ConnectionState {
return this.connectionStateEmitter.get();
}
/**
* Subscribe to connection-state transitions. The listener is invoked
* immediately with the current state so callers don't need a separate