Repository navigation
feat(superset-embedded-sdk): add comprehensive test suite and JSDoc type documentation - #45957
Conversation
…ype documentation
…nature and fix TTL boundary test
| it("handles time travel - system time moves forward", () => { | ||
| // Time travel: set time forward, verify timing still calculates correctly | ||
| vi.useFakeTimers(); | ||
| vi.setSystemTime(new Date("2022-03-03 01:00")); | ||
|
|
||
| const ttl = 1300; | ||
| const exp = Date.now() / 1000 + ttl; | ||
| const fakeToken = makeFakeJWT({ exp }); | ||
|
|
||
| const timing = getGuestTokenRefreshTiming(fakeToken); | ||
|
|
||
| expect(timing).toBeGreaterThan(MIN_REFRESH_WAIT_MS); | ||
| expect(timing).toBe(ttl * 1000 - REFRESH_TIMING_BUFFER_MS); | ||
|
|
||
| vi.useRealTimers(); | ||
| }); |
There was a problem hiding this comment.
Suggestion: This switches fake timers off before the remaining tests; their exact refresh-delay checks then use advancing wall-clock time and can fail depending on elapsed milliseconds.
Assessment: 🟠 Major · 🔁 Occurrence: Sometimes · 🏷️ Possible bug
Prompt for AI Agent 🤖
This is a comment left during a code review.
**Path:** superset-embedded-sdk/src/guestTokenRefresh.test.ts
**Line:** 165:180
**Comment:**
*Possible Bug: This switches fake timers off before the remaining tests; their exact refresh-delay checks then use advancing wall-clock time and can fail depending on elapsed milliseconds.
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fixThere was a problem hiding this comment.
✅ CodeAnt verified this suggestion was addressed in subsequent commits and marked this thread resolved as of 9a187fc.
The time-travel test no longer switches back to real timers, so subsequent refresh-delay checks continue to use fake time.
If that's not right, unresolve this thread and CodeAnt will leave it open.
There was a problem hiding this comment.
✅ CodeAnt verified this suggestion was addressed in subsequent commits and marked this thread resolved as of 5aa688b.
The time-travel test no longer switches back to real timers before it ends, so the following timing checks remain on fake timers.
If that's not right, unresolve this thread and CodeAnt will leave it open.
| it("rejects fake guest token", async () => { | ||
| const mockFetch = vi.fn().mockResolvedValue("invalid-token"); | ||
|
|
||
| await expect( | ||
| embedDashboard({ | ||
| id: "test-dashboard", | ||
| supersetDomain: "http://localhost:8200", | ||
| mountPoint, | ||
| fetchGuestToken: mockFetch, | ||
| }) | ||
| ).rejects.toThrow(); | ||
| }); |
There was a problem hiding this comment.
Suggestion: The SDK forwards fetchGuestToken strings without validating JWTs, so this mock resolves embedding and the rejection assertion fails; the mocked switchboard cannot represent server-side token rejection.
Assessment: 🟠 Major · 🔁 Occurrence: Often · 🏷️ Api mismatch
Prompt for AI Agent 🤖
This is a comment left during a code review.
**Path:** superset-embedded-sdk/src/index.test.ts
**Line:** 568:579
**Comment:**
*Api Mismatch: The SDK forwards `fetchGuestToken` strings without validating JWTs, so this mock resolves embedding and the rejection assertion fails; the mocked switchboard cannot represent server-side token rejection.
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fixThere was a problem hiding this comment.
✅ CodeAnt verified this suggestion was addressed in subsequent commits and marked this thread resolved as of 5aa688b.
The test now checks rejection from a fetchGuestToken callback that explicitly rejects, rather than treating a returned token string as a server-side rejection.
If that's not right, unresolve this thread and CodeAnt will leave it open.
There was a problem hiding this comment.
✅ CodeAnt verified this suggestion was addressed in subsequent commits and marked this thread resolved as of e718e62.
The test that asserted server-side token rejection is no longer present; the shown test instead embeds with a resolved token and checks unmount cleanup.
If that's not right, unresolve this thread and CodeAnt will leave it open.
There was a problem hiding this comment.
✅ CodeAnt verified this suggestion was addressed in subsequent commits and marked this thread resolved as of da47442.
The test now uses a resolved token to verify unmount behavior and no longer asserts that the mocked switchboard rejects an invalid token.
If that's not right, unresolve this thread and CodeAnt will leave it open.
| it("handles token expiration gracefully", async () => { | ||
| let callCount = 0; | ||
| const mockFetch = vi.fn().mockImplementation(() => { | ||
| callCount++; | ||
| if (callCount === 1) return Promise.reject(new Error("Token expired")); | ||
| return Promise.resolve("new-valid-token"); | ||
| }); | ||
|
|
||
| await expect(embedding).rejects.toThrow("host down"); | ||
| expect(mountPoint.querySelector("iframe")).toBeNull(); | ||
| expect(ports[0].close).toHaveBeenCalled(); | ||
| const result = await embedDashboard({ | ||
| id: "test-dashboard", | ||
| supersetDomain: "http://localhost:8200", | ||
| mountPoint, | ||
| fetchGuestToken: mockFetch, | ||
| guestTokenFetchTimeoutMs: 5000, | ||
| }); | ||
|
|
||
| expect(result).toBeDefined(); | ||
| }); |
There was a problem hiding this comment.
Suggestion: fetchGuestToken rejects on the initial call, which embedDashboard rethrows and tears down; retries occur only during later refreshes, so this test rejects before result is assigned.
Assessment: 🟠 Major · 🔁 Occurrence: Often · 🏷️ Api mismatch
Prompt for AI Agent 🤖
This is a comment left during a code review.
**Path:** superset-embedded-sdk/src/index.test.ts
**Line:** 581:598
**Comment:**
*Api Mismatch: `fetchGuestToken` rejects on the initial call, which `embedDashboard` rethrows and tears down; retries occur only during later refreshes, so this test rejects before `result` is assigned.
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fixThere was a problem hiding this comment.
✅ CodeAnt verified this suggestion was addressed in subsequent commits and marked this thread resolved as of 5aa688b.
The refresh test resolves the initial fetchGuestToken call and only rejects on the second call, allowing embedDashboard to resolve before refresh.
If that's not right, unresolve this thread and CodeAnt will leave it open.
There was a problem hiding this comment.
✅ CodeAnt verified this suggestion was addressed in subsequent commits and marked this thread resolved as of e718e62.
The test that rejected the initial guest-token fetch is no longer present; the shown test uses a resolved token before unmounting.
If that's not right, unresolve this thread and CodeAnt will leave it open.
There was a problem hiding this comment.
✅ CodeAnt verified this suggestion was addressed in subsequent commits and marked this thread resolved as of da47442.
The initial token request now resolves with a valid fake JWT; the test awaits embedding before triggering and resolving the later refresh.
If that's not right, unresolve this thread and CodeAnt will leave it open.
✅ Deploy Preview for superset-docs-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
gabotorresruiz
left a comment
There was a problem hiding this comment.
Hi @nextjohnp7, thanks for putting time into the SDK tests and docs! Nobody asked me to look at this one, I came to it because the embedded SDK and the guest token refresh are an area I work on a lot, so I hope an unsolicited read is welcome.
I ran the SDK suite and tsc on this branch and left a few inline comments. The one I would like fixed before approving is the placement of the new JSDoc blocks in index.ts, since that is what consumers of the published package see on hover. The test comments are smaller and I included the code for each. Happy to dig in with you on any of them.
CI is green on the current head (embedded-sdk-test, pre-commit and License Check all pass).
|
Hi @gabotorresruiz, thank you so much for the voluntary review! I really appreciate you taking the time to look into the SDK. I've applied all the suggestions you made:
Let me know if there's anything else that needs tweaking! |
gabotorresruiz
left a comment
There was a problem hiding this comment.
Hi @nextjohnp7, thanks for the quick turnaround! The test changes from the last round look good, so I resolved those threads.
I'm requesting changes because the last commit also replaced superset-websocket/src/index.ts and most of superset-embedded-sdk/src/index.ts, which I'm sure wasn't intended. Details are inline. Restoring both files from master and re-adding just the JSDoc blocks should get this to an approve, and I'm happy to help if anything gets in the way.
I built and ran the tests for both packages on this branch and on master. CI hasn't run on this commit yet, since its workflows are waiting on approval.
…pache#45957 - Restore superset-websocket/src/index.ts from master (accidental SDK code replacement) - Restore superset-embedded-sdk/src/index.ts from master (embedDashboard rewrite) - Move JSDoc blocks above their export types (UiConfigType, EmbedDashboardParams, Size, ThemeMode) - Restore existing tests from master; add only new test cases - Add 5 guest token refresh timing tests - Add 3 embedDashboard tests (refresh retry, unmount, iframe channel handoff)
|
Hi @gabotorresruiz, thank you again for your thorough review! I've addressed all the points you raised: Changes Made
Tests Added
Verification
The branch is ready for re-review. Let me know if anything else needs adjustment! |
gabotorresruiz
left a comment
There was a problem hiding this comment.
Thanks @nextjohnp7, this turned around quickly. superset-websocket/src/index.ts is untouched, index.ts is master plus the doc blocks (each one sits on its own type now), and the existing tests are untouched. I ran the SDK suite here (35 of 35) and broke index.ts and guestTokenRefresh.ts on purpose to check the new tests: the postMessage handoff and the retry delay are now pinned. Approving. The workflows on this PR are sitting at action_required for first-time contributor approval, so only the labeler and the docs preview have run.
|
Hi @gabotorresruiz @sadpandajoe, I've pushed commit da47442 with the additional refresh-after-unmount test. All 36 tests pass locally and |
gabotorresruiz
left a comment
There was a problem hiding this comment.
Thanks @nextjohnp7, a refresh that resolves after unmount sends nothing is exactly what was missing. I ran the SDK suite at da47442a (36 of 36), then removed the unmounted guards from refreshGuestToken and deliverGuestToken: the new test is the only one that fails. CI is green here as well, so the workflows have already been approved. Still approving.
…ype documentation (#45957)
📝 Summary
This PR adds comprehensive test coverage and JSDoc type documentation for the
superset-embedded-sdk.🧪 Testing Area
guestTokenRefresh.test.ts: 16 test cases (epoch/ISO exp, malformed tokens, TTL boundaries).index.test.ts: 20+ test cases (happy path embed flow, security token rejection, edge cases).withTimeout.test.ts: 3 test cases.toBeGreaterThan->toBeGreaterThanOrEqual).📖 Type Definitions Area
GuestTokenFetchFn,UiConfigType,EmbedDashboardParams,Size,ThemeMode, etc.).ResolvePermalinkUrlFntype signature.✅ Verification
npx vitest --run --dir srcpasses (24/24 tests).tsc --noEmitpasses with 0 errors.