When implementing API-facing features, ensure request/response contracts are consistent across all code paths, correctly shaped for the upstream/downstream API, and complete under pagination/time-windowing.
Rules: 1) Keep serialization/parsing round-trips structurally identical
2) Validate upstream API method signatures and data fields
as unknown as ... casts.3) Make state transitions scope-safe; don’t mix per-item windows with global cursor side effects
4) Ensure pagination/windowing is complete (no permanent omission)
maxPages: 1/small page limits when correctness requires fetching all items in the time window.gh api --paginate), handle multi-page/NDJSON responses by flattening correctly and testing multi-page cases.Example patterns:
export function parseSessionId(pathname: string) { // Mirror writer: anchor to the last occurrence if writer used last-match logic. return pathname.match(/\/session\/([^/]+)\/?$/)?.[1]; }
// Test: expect(parseSessionId(buildSessionPathname(‘/app/session/’, ‘real-id’))) === ‘real-id’
- Avoid wrong-typed external calls by removing casts and using correct method signatures:
```ts
// Prefer typed signatures; do not do api.Issues.show(chatId, { issueIId: ... })
// If SDK says show(issueId, { projectId }), pass issueId as number and projectId as string.
const windowSince = this.cursor.lastProcessedAt; // authoritative
// ...when scanning trigger events, treat created_at <= windowSince as lower-bound
Adopting these rules prevents silent drops, permanent omissions, and contract drift—common failure modes in API integration code.
Enter the URL of a public GitHub repository