feat: surface AIM log response via onResultsLogged callback#123
feat: surface AIM log response via onResultsLogged callback#123devandrepascoa wants to merge 6 commits into
Conversation
logAimResults now awaits the POST and parses the endpoint response instead of
fire-and-forget, returning the parsed body (e.g. { requestId }) or undefined on
failure. SpeedTestEngine exposes a new onResultsLogged callback that fires with
that response after onFinish, letting consumers read the measurement id without
intercepting the engine's fetch. Adds AimLogResponse type and unit tests.
There was a problem hiding this comment.
Summary
This PR surfaces the AIM logging endpoint's response (notably the assigned requestId) to consumers, instead of discarding it.
Changes:
logAimResultsbecomesasync: it nowawaits thePOST, and on a 2xx response parses & returns the JSON body (AimLogResponse). Returnsundefinedon network error, non-OK status, or non-JSON body. Still wrapped so it never throws.- New public
onResultsLoggedcallback onSpeedTestEngine, fired with the parsed response after the log request resolves. - New exported
AimLogResponsetype. #logFinalResultsrewritten from short-circuit&&to an early-return guard, then.then()-chains the callback.- New unit test
tests/unit/logging/logFinalResults.test.ts(5 cases) covering POST, parsed body, non-OK, rejection, and non-JSON.
Verification: I ran pnpm install, pnpm test:unit (98 passing), and pnpm lint (clean) locally — all green. The change is additive and backwards-compatible; the rationale for a separate callback (vs. folding into onFinish) is sound and preserves onFinish semantics.
Overall this is a clean, well-tested change. A few minor points are noted inline — none are blocking.
|
Review posted successfully to PR #123 with 5 inline comments. Here's a recap of my review. Review summaryWhat the PR does: Surfaces the AIM logging endpoint's response (the assigned
Verification: Inline issues flagged (all minor, none blocking):
No commits were pushed. |
Enable AIM logging in the e2e test, intercept the /__results POST to return a
canned { requestId }, and assert engine.onResultsLogged fires with the parsed
response. Other measurement requests still hit the real network. Extend the
eslint compat polyfill allowlist to tests/ so fetch/Promise are permitted.
logAimResults now resolves with { requestId: undefined } on failure instead of
undefined, so onResultsLogged always fires with an AimLogResponse (requestId
undefined when the log request fails) rather than silently not firing.
|
/bonk |
There was a problem hiding this comment.
Summary
Surfaces the AIM logging endpoint's response (notably the assigned requestId) to consumers instead of discarding it.
Changes (current head, incl. commit 29ae2c9):
logAimResultsis nowasync. Itawaits the POST and, on a 2xx, returns the parsed JSON body typed asAimLogResponse. On network error, non-OK status, or non-JSON body it returns{ requestId: undefined }. Still wrapped so it never throws.- New public
onResultsLoggedcallback onSpeedTestEngine, fired with the parsed response after the log request resolves.#logFinalResultsswitched from&&short-circuit to an early-return guard, then.then()-chains the callback. - New exported
AimLogResponsetype. - New unit test
tests/unit/logging/logFinalResults.test.ts(POST, parsed body, non-OK, rejection, non-JSON). - e2e test reworked to point
logAimApiUrlat a stubbed/__resultsand assertonResultsLoggedfires with the stubbedrequestId. - eslint: adds a
tests/**/*.tsblock declaringResponse(and the existing polyfill set) so the e2enew Response(...)usage passeseslint-plugin-compat.
Assessment: The design is sound and backwards-compatible (additive). The latest commit changing logAimResults to always resolve with an AimLogResponse (never undefined) resolves the earlier doc/behavior-mismatch concern: onResultsLogged now fires on every logging attempt, matching the JSDoc. The double-logging concern is also fine — the onFinish setter replaces the constructor's super.onFinish, so logging happens exactly once.
A few minor points inline; none are blocking.
|
Review posted to PR #123 with 5 inline comments: #123 (review) What the PR changesIt surfaces the AIM logging endpoint's response (the assigned
Notable: the review on file is partly staleThe prior
Issues I flagged (all minor, none blocking)
No commits were pushed. |
…timeout) - index.ts: re-export AimLogResponse via the local import instead of a second path re-export. - unit test: assert the formatted logData lands in the POST body. - e2e: bound the onResultsLogged wait with a 15s post-finish timeout so a regression fails fast instead of hanging.
|
/bonk |
|
Thanks @ask-bonk — addressed in ✅ Fixed
✅ Already resolved
❌ Intentionally not changed
|
There was a problem hiding this comment.
Summary
Surfaces the AIM logging endpoint's response (notably the assigned requestId) to consumers, which was previously discarded by the fire-and-forget logAimResults.
Changes (current head fd43cc4):
src/logging/logFinalResults.ts—logAimResultsis nowasync. Itawaits the POST and, on a 2xx, returns the parsed JSON body typed asAimLogResponse; on network error / non-OK / non-JSON it returns{ requestId: undefined }. Still wrapped so it never throws.src/index.ts— new publiconResultsLoggedcallback fired with the parsed response.#logFinalResultsswitched from&&short-circuit to an early-return guard, then.then()-chains the callback. Exports the newAimLogResponsetype.- New unit test
tests/unit/logging/logFinalResults.test.ts(5 cases) — now also asserts the POST body'stotalDurationMs. - e2e test reworked to stub
/__resultsand assertonResultsLoggedfires with the stubbedrequestId, with a 15sPromise.raceguard andtry/finallyfetch restore. eslint.config.js— adds atests/**/*.tsblock declaringResponse.
Verification: Ran locally — pnpm test:unit (98 passing), pnpm lint (clean), pnpm build (succeeds). Design is additive and backwards-compatible; the separate-callback rationale (vs. folding into onFinish) is sound. Double-logging is not an issue — the subclass onFinish setter replaces the constructor's super.onFinish, so logging runs exactly once.
Two prior review points are now resolved at this head and I did not re-raise them: the export duplication (line 16/775 is a single local re-export now) and the e2e fetch-restore leak (handled by try/finally).
A few minor points inline; none are blocking.
|
Review posted to PR #123 with 3 inline comments: #123 (review) What the PR changesSurfaces the AIM logging endpoint's response (the assigned
VerificationRan locally: Issues flagged (all minor, none blocking)
I did not re-raise two earlier points that are resolved at the current head: the No commits were pushed. |
Drop the [key: string]: unknown index signature; the response is only read for requestId.
Browser-compat checks apply to shipped src, not test code (runs in Node + Vitest Chromium). Replaces the parallel tests polyfills list.
The engine already POSTs final results to the AIM endpoint but discarded the response, so consumers had no way to read the
requestIdit assigns. This adds anonResultsLogged(response)callback that fires with that response ({ requestId }) once logging completes — letting speed.cloudflare.com and Radar show/look up a test by its id instead of monkey-patchingwindow.fetch. Kept separate fromonFinish(logging happens after, and is optional/can fail). Additive, backwards-compatible.