Typed events response#192
Open
gloskull wants to merge 4 commits into
Open
Conversation
…nse shape
Tighten the AppEvent parsing types on the event log page.
- Add JSDoc to parseEventsResponse documenting the { items } or { events } response shapes.
- Validate ts against number | string | null union instead of casting; coerce unexpected types to null.
- Handle missing type field by coercing to empty string.
- Update docs/api-integration.md to reflect the response contract.
- Extend tests to cover the new validation and response shapes.
Co-authored-by: gloskull <189399494+gloskull@users.noreply.github.com>
…407952307921026351 Refactor events typed response and validate ts field
- Update `parseNonNegativeInt` in `src/lib/validateNumber.ts` to reject empty strings and `-0`. - Refactor `UsagePage` in `src/app/usage/page.tsx` to separate field validation errors from general status errors, preventing duplicate `role="alert"` elements. - Improve semantic structure and accessibility of `KeyValueGrid.tsx` by using `Fragment` and explicit `aria-label` for Testing Library compatibility. - Fix `ConfirmDialog.test.tsx` to correctly target the dialog element for backdrop dismissal tests. - All 52 test suites passing. Co-authored-by: gloskull <189399494+gloskull@users.noreply.github.com>
Fix CI build and test failures
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR tightens the AppEvent parsing types on the event log page.
Changes:
Documented the dual response shape ({ items } or { events }) in JSDoc for parseEventsResponse.
Replaced the as AppEvent["ts"] cast with a validated coercion that ensures ts is number | string | null. Unexpected types are coerced to null.
Improved handling of missing type field by coercing to an empty string.
Updated docs/api-integration.md with the documented response contract and updated AppEvent type.
Added comprehensive tests in src/app/events/page.test.tsx to verify:
Support for { events: [...] } shape.
Coercion of invalid ts values to null.
Error handling for non-array payloads.
Handling of missing type field.
Verified that npm run typecheck passes with the removed cast.
Verified that npm test src/app/events/page.test.tsx passes with 100% statement coverage for the page.
Closes #164