Skip to content

fix(social-layer): add start_time to event query, type, and ordering - #49

Open
pastarita wants to merge 1 commit into
p2p-lanes:mainfrom
pastarita:fix/social-layer-event-start-time
Open

fix(social-layer): add start_time to event query, type, and ordering#49
pastarita wants to merge 1 commit into
p2p-lanes:mainfrom
pastarita:fix/social-layer-event-start-time

Conversation

@pastarita

Copy link
Copy Markdown

Summary

The Social Layer Event was modeled and fetched with an end_time but no start_time — the field was absent in both the GraphQL query and the TypeScript types. As a result, the profile event lists (ProfileStats) could never order events chronologically and fell back to raw array order (.slice(-3).reverse()). The omission was silent: the missing field read as undefined and TypeScript couldn't flag it because the type agreed with the bug.

Full write-up and the test plan are included in docs/issues/.

Changes

Fix

  • Extract EVENTS_QUERY / PROFILES_QUERY into src/app/api/socialLayer/queries.ts (no next/server import) so they're unit-testable; add start_time to both.
  • Add start_time to the Event and ProfileEvent interfaces (src/types/StatsSocialLayer.ts).
  • Add pure helpers sortEventsByStartDesc / recentEventsByStart (src/helpers/events.ts) that order by start_time descending and push missing/invalid timestamps last (never crash, never NaN-poison the order).
  • Use the helper for both the Events Hosted and Events Attended lists in ProfileStats.tsx, replacing the array-order workaround.

Tests — run with npm test (Node's built-in runner on TS, zero new dependencies, no node_modules required):

  • tests/socialLayer.queries.test.ts — query projection (TC-A*)
  • tests/events.helper.test.ts — ordering behaviour incl. missing/invalid/empty (TC-C*)
  • tests/types.assert.ts — compile-time type contract via tsc --noEmit (TC-B*)
  • package.json: add test and test:types scripts
  • tsconfig.json: exclude the runtime *.test.ts files from tsc (they use Node's native TS loader, which requires explicit .ts import extensions incompatible with the bundler config). The no-extension types.assert.ts stays type-checked.

Docs

  • docs/issues/social-layer-event-missing-start-time.md — identification, investigation trace, root-cause & impact analysis, proposed fixes, evidence index.
  • docs/issues/social-layer-event-start-time.test-plan.md — test-criterion set, automation/agentic execution protocol, pass/fail gates, traceability matrix.

Verification

Gate Command Result
Unit suite npm test ✅ 11/11 pass
Type contract npx tsc --noEmit ✅ changed code clean¹
Lint npm run lint ✅ warnings only, none in changed files
Build npm run build ⚠️ not run locally²

¹ One pre-existing, unrelated error remains (src/constants/config.tsicon.png), untouched by this PR — a standalone-tsc image-types artifact that next build resolves.
² sharp couldn't build native bindings in the dev sandbox; CI/Vercel build is unaffected.

⚠️ One thing to confirm before merge

start_time is the symmetric counterpart to the already-present end_time, and matches the canonical Social Layer events schema. However, the live Hasura endpoint (hasura-graph.fly.dev) was unreachable from the dev environment, so I could not introspect it to confirm the exact column name. If the source column is named differently (e.g. start_at), only the two query strings in queries.ts need to match it. A maintainer with schema access should verify.

The Social Layer Event was modeled and fetched with end_time but no
start_time, in both the GraphQL query and the TS types. Downstream UI
could therefore never order events chronologically and fell back to raw
array order (.slice(-3).reverse()). The omission was silent: the missing
field read as undefined and TypeScript could not flag it.

Changes:
- Extract EVENTS_QUERY/PROFILES_QUERY into socialLayer/queries.ts (no
  next/server import) so they are unit-testable; add start_time to both.
- Add start_time to the Event and ProfileEvent interfaces.
- Add pure helpers sortEventsByStartDesc / recentEventsByStart that order
  by start_time desc and push missing/invalid timestamps last.
- Use the helper for both the Events Hosted and Events Attended lists in
  ProfileStats, replacing the array-order workaround.

Tests (node --test, zero new deps):
- tests/socialLayer.queries.test.ts  - query projection (TC-A*)
- tests/events.helper.test.ts         - ordering behaviour (TC-C*)
- tests/types.assert.ts               - compile-time type contract (TC-B*)
- add npm scripts: test, test:types

Docs: issue report + test plan/automation protocol under docs/issues/.

NOTE: start_time is the symmetric counterpart to the existing end_time;
the live Hasura 'events' schema field name should be confirmed by a
maintainer (endpoint was unreachable from the dev environment).
@vercel

vercel Bot commented Jun 1, 2026

Copy link
Copy Markdown

@pastarita is attempting to deploy a commit to the p2planes Team on Vercel.

A member of the Team first needs to authorize it.

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.

1 participant