Skip to content

audit: [collection]/[...slug].astro re-implements the statement schema as 50 lines of hand-rolled guards; ordering logic exists 3× with inconsistent tiebreakers #38

Description

@tkowalczyk

Evidence

1. Schema duplication with silent-degradation failure mode. src/pages/[collection]/[...slug].astro:36-64 defines isRecord/isTruncatedWallet/isStatementData — a hand-rolled re-statement of statementSchema. The collection already validated entry.data against the Zod schema at sync time. If the guard drifts from the schema (next schema change), isStatementData returns false and the page silently drops the entire metrics block (statement = null → no dl, no top-wallets table) while still returning 200 — exactly the class of quiet failure a credibility site can't afford. This violates the repo's own deep-modules rule (schema = the one interface; pages should consume it, not mirror it).

2. Ordering triplicated, and the tiebreakers disagree. Live consequence (verified on prod): /statements lists monthly first (sort-newest-first.ts: period_end desc, id desc) while RSS lists weekly first (feeds/sort.ts: date desc, collection asc, slug asc) for the same two 2026-05-31 entries; latest.ts re-implements the pick a third time. Same data, different canonical order per surface.

TDD plan (failing tests first)

  1. src/lib/statement-format/statement-data.ts: asStatementData(data: unknown): Statement | null implemented as statementSchema.safeParse (or a narrowing on the already-typed CollectionEntry<"statements">["data"]), exporting the inferred type. Tests FIRST:
    • every fixture that passes statementSchema is accepted (drift impossible by construction)
    • the function and schema share one type (compile-time, satisfies)
    • decide + test the failure mode: log-and-render-without-metrics is current behavior; consider throwing in dev so drift is loud
  2. Collapse ordering: sortStatementsNewestFirst stays the single comparator; pickLatestStatement becomes sorted[0] ?? null (its doc already promises head-equivalence — make it true by construction); feeds sortEntries documents why its tiebreaker differs (cross-collection) or aligns the same-date tiebreaker with the statements surface. Tests: same-date weekly+monthly fixture must order identically on /statements, RSS, llms.txt, sitemap (one shared fixture asserted across the three generators + the statement sort).
  3. Net deletion target: ~60 lines from the page frontmatter.

Acceptance criteria

AC Test
No structural type-guard logic left in page frontmatter review (page imports asStatementData)
Schema change cannot silently blank the metrics block drift test above
One documented ordering for same-date entries across all surfaces cross-surface fixture test

Metadata

Metadata

Assignees

No one assigned

    Labels

    afkAgent-grabbable: implementable without further inputenhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions