Skip to content

feat: reputation end-to-end — append then query#276

Merged
ezedike-evan merged 4 commits into
ezedike-evan:mainfrom
Ipramking:fix/issue-133-reputation-e2e
Jun 1, 2026
Merged

feat: reputation end-to-end — append then query#276
ezedike-evan merged 4 commits into
ezedike-evan:mainfrom
Ipramking:fix/issue-133-reputation-e2e

Conversation

@Ipramking
Copy link
Copy Markdown
Contributor

Summary

  • Adds lib/reputation/db.ts — SQLite backend using better-sqlite3 with openDb, appendRow, queryRows
  • Adds tests/reputation-e2e.spec.ts — 7 end-to-end tests using an in-memory SQLite database
  • Full round trip: redact raw intent → append to SQLite → query rows → build scorecards → assert visible in aggregate

Test plan

  • npm test — 7 e2e tests pass
  • Round trip: appended row visible in 7-day scorecard
  • Anchor isolation: row for anchor-a not visible when querying anchor-b
  • Unfilled row reduces fill rate to 0.5
  • Row recorded 20 days ago only appears in 30 and 90-day windows
  • Idempotent append: same intentHash inserted twice counts as 1 row
  • PII fields absent from stored DB row
  • Multiple anchors isolated from each other

Closes #224

Ipramking added 3 commits May 30, 2026 11:27
Closes ezedike-evan#222

- Add lib/reputation/redact.ts with redactIntent() and hashIntent()
- Strip all recipient/PII fields; store only SHA-256 intent hash
- Add tests/reputation-redact.spec.ts with property-based tests
- 1000-run fast-check assertions confirm zero PII fields and zero PII bytes in written row
Closes ezedike-evan#223

- Add lib/reputation/aggregate.ts with aggregate() and buildScorecards()
- Computes fill rate, settle p50/p95, slippage p50/p95 per 7/30/90-day window
- Empty aggregate returns "insufficient_data" state
- Add app/api/reputation/[anchor]/route.ts serving all three scorecards
- Add tests/reputation-aggregate.spec.ts — 19 tests, sample data produces expected aggregates
Closes ezedike-evan#224

- Add lib/reputation/db.ts — SQLite backend (better-sqlite3) with openDb/appendRow/queryRows
- Add tests/reputation-e2e.spec.ts — 7 e2e tests using in-memory SQLite
- Round trip: redact raw intent → appendRow → queryRows → buildScorecards → assert visible in aggregate
- Covers: isolation by anchorId, window boundaries, idempotent append, PII absent from DB row
@vercel
Copy link
Copy Markdown

vercel Bot commented May 30, 2026

@Ipramking is attempting to deploy a commit to the ezedikeevan's projects Team on Vercel.

A member of the Team first needs to authorize it.

@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented May 30, 2026

@Ipramking Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

Copy link
Copy Markdown
Owner

@ezedike-evan ezedike-evan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review — NOT READY TO MERGE (merge conflict + duplicate files)

Thanks for delivering the full e2e stack — the SQLite backend, PII redaction, and round-trip tests are exactly what issue #224 asked for. The implementation is clean and the test isolation (per-anchor, idempotency, window boundaries, PII absence) is comprehensive.

Blocker 1 — Merge conflict

This PR has a merge conflict against main and cannot be merged as-is.

Blocker 2 — Duplicate files from PR #275

This PR includes app/api/reputation/[anchor]/route.ts and lib/reputation/aggregate.ts (and their tests in tests/reputation-aggregate.spec.ts) which are identical to what PR #275 adds. These files will conflict on merge whether #275 goes first or second.

Required fix: Rebase this branch on top of PR #275's branch (or wait for #275 to merge into main, then rebase here). After the rebase, this PR should only carry the net-new files:

  • lib/reputation/db.ts
  • lib/reputation/redact.ts
  • tests/reputation-e2e.spec.ts
  • tests/reputation-redact.spec.ts
  • package.json / package-lock.json (for better-sqlite3 and @types/better-sqlite3)

The duplicated route.ts, aggregate.ts, and reputation-aggregate.spec.ts should be dropped from this branch entirely.

One additional note — better-sqlite3 as devDependency

better-sqlite3 is correctly placed in devDependencies, which is right for test-only use. However, lib/reputation/db.ts sits under lib/ (a path Next.js will include in the production bundle if anything imports it). Please add a comment at the top of db.ts making clear it must never be imported from production app code (only from tests and server-side scripts), or move it to tests/helpers/ so the boundary is structural rather than documented.

Once the rebase is done and the devDependency note is addressed, this will be ready to merge immediately after #275. Please re-request review.

@ezedike-evan
Copy link
Copy Markdown
Owner

Sprint re-review — still blocked.

Duplicate files with #275 (sequencing not resolved).
Both PRs introduce:

  • app/api/reputation/[anchor]/route.ts
  • lib/reputation/aggregate.ts
  • tests/reputation-aggregate.spec.ts

#276 is the intended superset (adds lib/reputation/db.ts, lib/reputation/redact.ts, tests/reputation-e2e.spec.ts, tests/reputation-redact.spec.ts). The correct merge order is #275 first, then this PR — but after #275 merges, you must remove the three duplicate files from this branch's diff (since they'll already be on main) so the diff only contains the net-new db/redact/e2e layer.

Branch is also CONFLICTING against main.

Action items:

Copy link
Copy Markdown
Owner

@ezedike-evan ezedike-evan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed during sprint. The implementation here is clean on its own — but main has since gained a full reputation-aggregate system (computeCorridorAggregate, computeWindowAggregate, groupByCorridor in lib/reputation/aggregate.ts, plus GET /api/reputation/[anchor]) from PRs #364, #365, and #375.

This PR brings a parallel, differently-shaped implementation of the same surface (percentile-based Scorecard/buildScorecards and its own route.ts internals). Merging as-is would leave two competing reputation modules defining the same endpoint and the same conceptual aggregates — an add/add conflict on both aggregate.ts and route.ts that can't be resolved by taking a superset.

This needs a design decision, not a conflict resolution: either (a) rebase onto main and express the percentile/SQLite work as an extension of the existing aggregate.ts API rather than a replacement, or (b) if the percentile approach is preferred, open a focused PR that migrates the existing callers. Happy to merge once it composes with the current reputation surface rather than duplicating it.

- aggregate.ts/route.ts/redact.ts: take main's versions (already contain
  the unified scorecard + corridor-window API from ezedike-evan#275 and ezedike-evan#274)
- keep net-new db.ts (SQLite outcome store) and reputation-e2e.spec.ts
- add better-sqlite3 + @types to devDependencies for db.ts
- drop CODEBASE_EXPLORATION.md (removed on main, stale branch resurrected it)
- fix OutcomeRow cast in e2e test
@ezedike-evan ezedike-evan merged commit 880b8af into ezedike-evan:main Jun 1, 2026
3 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[#133] reputation end-to-end — append then query

2 participants