Skip to content

test: cover indexer top-up/completion paths; fix labels and page state - #1940

Merged
K1NGD4VID merged 7 commits into
LabsCrypt:mainfrom
MFrancis-dev:test/issues-632-1085-1761-1763
Nov 21, 2026
Merged

K1NGD4VID merged 7 commits into
LabsCrypt:mainfrom
MFrancis-dev:test/issues-632-1085-1761-1763

Conversation

@MFrancis-dev

Copy link
Copy Markdown
Contributor

Scope

Four issues assigned to me, one branch, rebased onto main at 5b93cc9.

Issue Change
#632 The template-name input in the dashboard settings tab gets an id and a real <label htmlFor>; the bare aria-label is gone. New DashboardSettings.test.tsx asserts that association, then walks every input, textarea and select in the rendered form so a future control without an id fails the gate.
#1085 New frontend/src/hooks/useAsyncPageData.ts returns one derived view state (awaiting / error / loading / empty / ready, resolved in that priority order) from the fetch flags. activity-content.tsx and incoming-content.tsx both consume it, so the two pages cannot drift apart. 11 hook tests (including an independent expectation over all 16 flag combinations) plus a new 7-test suite for incoming, which had none; the pre-existing src/__tests__/activity-content.test.tsx still passes unchanged.
#1761 New backend/tests/stream-topped-up-rate.test.ts (26 tests) for stream_topped_up.
#1763 New backend/tests/stream-completed-event.test.ts (23 tests) for stream_completed, including the completion/withdrawal interleavings.

Production code changed only in DashboardSettings.tsx and the two page components. No config, lockfile, coverage threshold, or CI file was touched.

What the two indexer suites pin

Both drive the public worker.processEvent(event) entry point against a hoisted in-memory prisma fake with snapshot/rollback semantics, so the assertions are about stored rows, broadcast payloads and the thrown error contract rather than about internals.

stream_topped_up (#1761):

  • end-time math startTime + deposited / rate + totalPausedDuration for a normal rate, a rate that leaves fractional runway (truncates toward zero), both halves of the i128, values past Number.MAX_SAFE_INTEGER, and rate = 0 (null end time)
  • the stored ratePerSecond is the only rate input: the handler never rewrites it, and a stream_rate_modified event leaves it alone
  • depositedAmount and the one TOPPED_UP StreamEvent row per top-up
  • dedup: a second delivery of the same txHash does not re-apply the amount, and a row the indexer already wrote (non-zero ledger position) stays untouched
  • the marker reconciliation fix(backend): one top-up writer, honest status codes, one envelope #1932 introduced: when the API writer got there first and left ledgerSequence = 0, the indexer writes through the skip, assigns the chain's absolute total rather than adding its own delta, and fills the ledger position into the existing row instead of writing a second one
  • the row lock is taken exactly once, before any amount is written
  • a body missing amount or new_deposited_amount rejects with StreamToppedUp #<id>: missing body fields before any write

stream_completed (#1763):

  • the chain total_withdrawn is assigned to withdrawnAmount (not added to it), isActive goes false, one COMPLETED row keyed on txHash + eventType, ledger close time as the stamp
  • ordering: completion before the final withdrawal and completion after it produce different stored totals (finding 5 below)
  • replay: the event row is not duplicated
  • dependency failures: a missing Stream row rejects before the dedup guard, and an event-row write failure rolls the whole transaction back
  • the SSE payload carries the decoded recipient and the cumulative total

Behaviour found while characterising these paths

Not changed here. Each one is asserted as current behaviour so that a future change is a deliberate one.

  1. stream_topped_up carries new_end_time (StreamToppedUpEvent in contracts/stream_contract/src/events.rs) and the worker ignores it, deriving the value in projectedEndTime. Derivation is the single-writer design from fix(backend): one top-up writer, honest status codes, one envelope #1932, so this is a question rather than a bug report: if the contract's projection and the backend's ever disagree, the UI shows the backend number and nothing alerts.
  2. handleStreamToppedUp stamps Math.floor(Date.now() / 1000) while every other handler in the file stamps getEventLedgerTimestamp(event). Two clocks, one column, so a replay or backfill writes a different timestamp than the live pass did.
  3. processEvent's switch has no case for stream_refueled (StreamRefueledEvent) or stream_rate_modified (StreamRateModifiedEvent). Both fall through default: and are dropped silently, even though the contract emits them.
  4. handleStreamCompleted performs its stream.update before the dedup guard and broadcasts SSE after the transaction returns, so a replayed completion re-writes the row and re-notifies connected clients even though it correctly does not duplicate the event row.
  5. tokens_withdrawn increments withdrawnAmount; stream_completed assigns it. If a withdrawal is indexed after the completion (RPC retry or replay of an earlier transaction), the stored total ends up above the chain-authoritative one - the test that pins this lands on 1600 for a stream whose on-chain total is 1000.

#632's file citation is stale

The issue points at frontend/src/components/dashboard/dashboard-view.tsx lines 879 and 922-934. That file no longer contains a single <label>: the wizard it describes was split into frontend/src/components/stream-creation/, and those steps (RecipientStep, AmountStep, ScheduleStep, TemplateStep, TopUpModal, BatchStreamWizard) already pair htmlFor with id. Of the controls the issue enumerates, the only one still unlabelled today is the template-name input in the settings tab, which is what the first commit fixes. BatchStreamWizard does have per-row inputs in table cells with no label element; that is a different form, so it is left alone here.

Gates

Ran the job set that .github/workflows/ci.yml triggers for a frontend/** + backend/** diff, on Node 22.23.3 (.nvmrc says 22), against a throwaway Postgres on 127.0.0.1:55443 using the workflow's own DATABASE_URL shape. Each command ran unpiped with its exit code captured:

npm ci --dry-run --ignore-scripts                     rc=0
frontend  npm run lint                                rc=0
frontend  npm run test:coverage                       rc=0   104 files, 1129 passed | 1 skipped
                                                               71.77 stmts / 80.81 branch / 75.37 funcs / 71.77 lines   (floors 50/75/65/50)
frontend  npm run build                               rc=0
frontend  bash ./scripts/check-bundle-size.sh         rc=0
backend   npx prisma generate                         rc=0
backend   npx prisma migrate deploy                   rc=0
backend   npm run build                               rc=0
drift     npm run codegen:openapi (backend)
          npm run codegen:api-types (frontend)
          git diff --exit-code -- backend/swagger/flowfi.openapi.json
                                    frontend/src/lib/api-types.generated.ts
                                                      rc=0
backend   npx vitest run --coverage --reporter=basic  rc=0   96 files, 1295 passed | 6 skipped
                                                               79.4 stmts / 82.79 branch / 77.92 funcs / 79.4 lines    (floors 60/60/60/60)
docs-encoding (md utf-8 + mojibake)                   rc=0

New files individually: stream-topped-up-rate.test.ts 26 passed, stream-completed-event.test.ts 23 passed, useAsyncPageData.test.tsx 11 passed, incoming-content.test.tsx 7 passed, DashboardSettings.test.tsx 3 passed.

Proof that the new tests can fail

Eleven regressions were injected one at a time into the code the two backend suites cover; every one was killed, and git diff -- src was empty afterwards:

Injected change Tests failing
projectedEndTime drops totalPausedDuration 1
projectedEndTime returns startTime instead of null at zero rate 1
the dedup guard is bypassed, so a replay re-applies 2
lockStreamForUpdate call removed from the top-up path 1
top-up stamps ledger time instead of processing time 3
completion writes a total that is not the chain value 9
completion stamps processing time instead of ledger time 3
projectedEndTime returns a constant, i.e. trusts the chain 10
top-up missing-body guard bypassed 2
a marker row is treated as already indexed (never reconciled) 3
reconciliation leaves the marker's ledger position unfilled 1

Notes for review

Closes #632
Closes #1085
Closes #1761
Closes #1763

… label (LabsCrypt#632)

The settings-tab "Create Stream" panel named its only control with `aria-label`,
so there was no label element to anchor and no id for tests to target. Give the
input an id plus an sr-only sibling label so the accessible name comes from a
real association, with no layout change.

The issue cites `dashboard-view.tsx:879` and recipient/token/amount at 922-934.
That wizard moved and already pairs htmlFor with ids; the template-name input is
the gap that remains in this form.
…ing (LabsCrypt#1085)

Page shells duplicated a chain of ad-hoc booleans (hydrated? connected?
loading? error? empty?) and each page ordered them slightly differently,
so a finished-but-errored query could render the empty state. One hook
derives the five mutually exclusive states in a documented priority order
and the two pages that had drifted now consume it.
…ards (LabsCrypt#1761)

The top-up handler recomputes the deposit, the derived end time and the
pause-adjusted duration in one expression, and nothing tested the
arithmetic: a regression in the divisor, the pause term or the i128
decode would have silently extended or shortened live streams. These
tests drive processEvent, so they also pin the dedup guard, the
missing-field rejections, the transaction rollback and the exact SSE
payload.
…r time (LabsCrypt#1763)

Completion writes the chain's total instead of accumulating withdrawals,
which is the only place the two can disagree — and the dedup guard runs
after the stream update, so a redelivery re-writes the row. Both
behaviours were undocumented. These tests pin the override, the
ledger-close timestamp precedence with its wall-clock fallback, and the
sentinel failure that must not fail the event.
backend/tsconfig.json compiles tests/ with noUncheckedIndexedAccess and the
frontend build type-checks its test files, so an unchecked [0] read and an
unused React import each fail `npm run build` rather than the test run.
LabsCrypt#1932 moved the top-up writes behind applyToppedUpEvent, which takes the
stream row lock through $executeRaw and selects only the columns it needs,
and started storing the event timestamp as a BigInt. The fake client has to
mirror that seam or the suite describes a shape the worker no longer has.
…ypt#1932

The API writer and the indexer share one dedup key, and the marker row the
API leaves behind (ledgerSequence 0) is the only case where the indexer
writes through a skip. Nothing pinned which of the two branches a given
existing row takes.
@K1NGD4VID
K1NGD4VID merged commit 695f8d9 into LabsCrypt:main Nov 21, 2026
16 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

2 participants