Skip to content

test(davinci-client): add polling e2e tests#634

Open
ancheetah wants to merge 1 commit into
mainfrom
SDKS-4929-polling-e2e
Open

test(davinci-client): add polling e2e tests#634
ancheetah wants to merge 1 commit into
mainfrom
SDKS-4929-polling-e2e

Conversation

@ancheetah
Copy link
Copy Markdown
Collaborator

@ancheetah ancheetah commented May 14, 2026

JIRA Ticket

https://pingidentity.atlassian.net/browse/SDKS-4929

Description

Core Change: New E2E Polling Test Suite

e2e/davinci-suites/src/polling.test.ts — 5 Playwright tests across two polling scenarios:

Challenge Polling (3 tests)

  • Magic link success — opens the link in a second browser context to complete the challenge
  • Timeout on exhausted retries — lets 5 retries × 2s interval expire, asserts Error: timedOut
  • Expired challenge — waits 20s for expiry before polling, asserts Error: expired

Continue Polling (2 tests)

  • QR code scan simulation success — polls twice, asserts Message: Done
  • Timeout on exhausted retries — exceeds maxRetries (3), asserts Error: timedOut

Supporting Changes

File Change
e2e/davinci-app/server-configs.ts New DaVinci client config for polling flows (SDK Web Team tenant)
e2e/davinci-app/main.ts Fixed error display: only shows when clientInfo.status === 'error'; error div styled red inline
e2e/davinci-app/index.html Removed static #error-div (now created dynamically)
e2e/davinci-app/style.css Added .error { color: red; } utility class
lefthook.yml Reordered pre-commit hooks (format now runs after interface-mapping)
e2e/davinci-suites/src/protect.test.ts Added explicit string[] type annotations (TypeScript strictness)

Summary by CodeRabbit

  • New Features

    • Added polling functionality with support for Challenge and Continue polling flows.
    • Added new tenant configuration for enhanced authentication options.
  • Bug Fixes

    • Improved error handling and display reliability.
  • Tests

    • Added comprehensive end-to-end test coverage for polling scenarios.

Review Change Stack

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 14, 2026

⚠️ No Changeset found

Latest commit: b9b8645

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 14, 2026

📝 Walkthrough

Walkthrough

This PR establishes infrastructure and comprehensive e2e tests for polling flows. It refactors error handling in the davinci app to support dynamic error display, adds a new polling tenant configuration, and introduces extensive Playwright test coverage for Challenge and Continue polling scenarios with timeout and expiry handling.

Changes

Polling Feature Tests and Infrastructure

Layer / File(s) Summary
Polling app infrastructure and configuration
e2e/davinci-app/index.html, e2e/davinci-app/style.css, e2e/davinci-app/main.ts, e2e/davinci-app/server-configs.ts
Form template is simplified to an empty form element; error-div is now dynamically created and populated in renderForm when clientInfo?.status === 'error'; new .error CSS class provides red text styling; and a new polling tenant configuration with OpenID discovery endpoint is registered.
Polling e2e test suites
e2e/davinci-suites/src/polling.test.ts
Challenge Polling suite tests success via magic-link extraction, timeout after retry exhaustion (counting /status POST requests), and challenge expiry handling. Continue Polling suite tests QR-code scan simulation success and timeout behavior with repeated polling starts.
Supporting test and configuration updates
e2e/davinci-suites/src/protect.test.ts, lefthook.yml
Requests array in protect component tests is explicitly typed as string[] in both Custom HTML and P1 Forms test cases; pre-commit format command is reordered to run after the interface-mapping validator.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • ForgeRock/ping-javascript-sdk#575: Fixes client headers used during challenge polling requests, which directly impacts the /status endpoint polling behavior tested in this PR's new polling test suite.

Suggested reviewers

  • cerebrl
  • ryanbas21
  • SteinGabriel

Poem

🐰 A polling trail through the browser's maze,
With tests that track each retry phase,
From magic links to timeout's end,
Each error caught, each flow a friend—
The SDK hops and tests unfold! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: adding polling e2e tests to the davinci-client.
Description check ✅ Passed The PR description includes the required JIRA ticket link and a comprehensive description of all changes with clear organization and supporting details.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch SDKS-4929-polling-e2e

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@nx-cloud
Copy link
Copy Markdown
Contributor

nx-cloud Bot commented May 14, 2026

View your CI Pipeline Execution ↗ for commit b9b8645

Command Status Duration Result
nx run-many -t build --no-agents ✅ Succeeded 2s View ↗
nx affected -t build lint test typecheck e2e-ci ✅ Succeeded 2m 44s View ↗

☁️ Nx Cloud last updated this comment at 2026-05-14 22:50:07 UTC

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (1)
e2e/davinci-app/style.css (1)

84-86: ⚡ Quick win

The .error class is defined but not used.

The error display in main.ts (Line 196) uses inline styling (errorDiv.style.color = 'red') instead of applying this CSS class. Consider either using the class or removing it.

♻️ Proposed refactor to use the CSS class

In main.ts, replace the inline style with the class:

-      if (errorDiv && clientInfo?.status === 'error') {
-        errorDiv.style.color = 'red';
+      if (errorDiv && clientInfo?.status === 'error') {
+        errorDiv.classList.add('error');
         errorDiv.innerHTML = `
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@e2e/davinci-app/style.css` around lines 84 - 86, The .error CSS rule is
defined but not used; update main.ts to stop using inline styling and instead
apply the CSS class by replacing the inline assignment (errorDiv.style.color =
'red') with adding the class (e.g., errorDiv.classList.add('error')) so the
.error style is used, or if you prefer to keep inline styles remove the .error
rule from style.css; change references to the DOM element named errorDiv in
main.ts accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@e2e/davinci-app/main.ts`:
- Around line 193-200: The current code always appends a div via
formEl.appendChild(...) and uses innerHTML to render
davinciClient.getError()?.message, causing an unnecessary empty `#error-div` when
no error and an XSS risk; change the logic to only create/append the error
element when clientInfo?.status === 'error' and set its content with textContent
(or equivalent safe API) using davinciClient.getError()?.message to avoid HTML
injection, and remove the unconditional append so no empty div remains when not
in error state.

In `@e2e/davinci-suites/src/polling.test.ts`:
- Line 83: The test's assertion passes a boolean to expect causing it to always
succeed; change the assertion to use a Jest matcher on the actual value (e.g.,
replace the current expect(numPollRequests === maxRetries) with an assertion
like expect(numPollRequests).toBe(maxRetries) or
expect(numPollRequests).toEqual(maxRetries)) so the test actually verifies that
numPollRequests equals maxRetries (refer to the variables numPollRequests and
maxRetries in polling.test.ts).
- Line 122: The assertion currently passes a boolean expression into expect
(expect(numPollRequests === 0)) which evaluates before expect and thus the test
always passes; update the assertion to pass the value and use a matcher—replace
the incorrect call with expect(numPollRequests).toBe(0) (or another appropriate
matcher) so the test actually asserts that numPollRequests equals zero.

---

Nitpick comments:
In `@e2e/davinci-app/style.css`:
- Around line 84-86: The .error CSS rule is defined but not used; update main.ts
to stop using inline styling and instead apply the CSS class by replacing the
inline assignment (errorDiv.style.color = 'red') with adding the class (e.g.,
errorDiv.classList.add('error')) so the .error style is used, or if you prefer
to keep inline styles remove the .error rule from style.css; change references
to the DOM element named errorDiv in main.ts accordingly.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 31270dcd-6665-4f0f-acd5-cfca75a226d8

📥 Commits

Reviewing files that changed from the base of the PR and between 207e275 and b9b8645.

📒 Files selected for processing (7)
  • e2e/davinci-app/index.html
  • e2e/davinci-app/main.ts
  • e2e/davinci-app/server-configs.ts
  • e2e/davinci-app/style.css
  • e2e/davinci-suites/src/polling.test.ts
  • e2e/davinci-suites/src/protect.test.ts
  • lefthook.yml

Comment thread e2e/davinci-app/main.ts
Comment on lines +193 to 200
const errorDiv = document.createElement('div');
formEl.appendChild(errorDiv).setAttribute('id', 'error-div');
if (errorDiv && clientInfo?.status === 'error') {
errorDiv.style.color = 'red';
errorDiv.innerHTML = `
<div>${davinciClient.getError()?.message}</div>
<p><strong>Error</strong>: ${davinciClient.getError()?.message}</p>
`;
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Potential XSS vulnerability and unnecessary DOM element creation.

Two concerns:

  1. XSS Risk: The error message is inserted via innerHTML without sanitization. If davinciClient.getError()?.message can contain user-controlled input, this creates an XSS vulnerability.

  2. Empty Element: The errorDiv is always appended to the DOM (Line 194) but only populated when status === 'error' (Line 195). This leaves an empty div#error-div in the DOM for non-error states.

🔒 Proposed fix to address both concerns
     const error = davinciClient.getError();
-    if (error) {
+    if (error && clientInfo?.status === 'error') {
       const errorDiv = document.createElement('div');
       formEl.appendChild(errorDiv).setAttribute('id', 'error-div');
-      if (errorDiv && clientInfo?.status === 'error') {
-        errorDiv.style.color = 'red';
-        errorDiv.innerHTML = `
-          <p><strong>Error</strong>: ${davinciClient.getError()?.message}</p>
-        `;
-      }
+      errorDiv.style.color = 'red';
+      
+      const paragraph = document.createElement('p');
+      const strong = document.createElement('strong');
+      strong.textContent = 'Error';
+      paragraph.appendChild(strong);
+      paragraph.appendChild(document.createTextNode(': ' + (error.message || '')));
+      errorDiv.appendChild(paragraph);
     }

This fix:

  • Only creates the error div when actually needed
  • Uses textContent instead of innerHTML to prevent XSS
🧰 Tools
🪛 ast-grep (0.42.2)

[warning] 196-198: Direct modification of innerHTML or outerHTML properties detected. Modifying these properties with unsanitized user input can lead to XSS vulnerabilities. Use safe alternatives or sanitize content first.
Context: errorDiv.innerHTML = <p><strong>Error</strong>: ${davinciClient.getError()?.message}</p>
Note: [CWE-79] Improper Neutralization of Input During Web Page Generation [REFERENCES]
- https://owasp.org/www-community/xss-filter-evasion-cheatsheet
- https://cwe.mitre.org/data/definitions/79.html

(dom-content-modification)


[warning] 196-198: Direct HTML content assignment detected. Modifying innerHTML, outerHTML, or using document.write with unsanitized content can lead to XSS vulnerabilities. Use secure alternatives like textContent or sanitize HTML with libraries like DOMPurify.
Context: errorDiv.innerHTML = <p><strong>Error</strong>: ${davinciClient.getError()?.message}</p>
Note: [CWE-79] Improper Neutralization of Input During Web Page Generation [REFERENCES]
- https://www.dhairyashah.dev/posts/why-innerhtml-is-a-bad-idea-and-how-to-avoid-it/
- https://cwe.mitre.org/data/definitions/79.html

(unsafe-html-content-assignment)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@e2e/davinci-app/main.ts` around lines 193 - 200, The current code always
appends a div via formEl.appendChild(...) and uses innerHTML to render
davinciClient.getError()?.message, causing an unnecessary empty `#error-div` when
no error and an XSS risk; change the logic to only create/append the error
element when clientInfo?.status === 'error' and set its content with textContent
(or equivalent safe API) using davinciClient.getError()?.message to avoid HTML
injection, and remove the unconditional append so no empty div remains when not
in error state.

});

// Check max retry count
expect(numPollRequests === maxRetries);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

Incorrect assertion - test will always pass.

The assertion expect(numPollRequests === maxRetries) evaluates to a boolean and passes it to expect(), which will always succeed. This doesn't actually assert the condition.

🐛 Proposed fix
     // Check max retry count
-    expect(numPollRequests === maxRetries);
+    expect(numPollRequests).toBe(maxRetries);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
expect(numPollRequests === maxRetries);
expect(numPollRequests).toBe(maxRetries);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@e2e/davinci-suites/src/polling.test.ts` at line 83, The test's assertion
passes a boolean to expect causing it to always succeed; change the assertion to
use a Jest matcher on the actual value (e.g., replace the current
expect(numPollRequests === maxRetries) with an assertion like
expect(numPollRequests).toBe(maxRetries) or
expect(numPollRequests).toEqual(maxRetries)) so the test actually verifies that
numPollRequests equals maxRetries (refer to the variables numPollRequests and
maxRetries in polling.test.ts).

await expect(page.getByText('Error: expired')).toBeVisible();

// Check poll count
expect(numPollRequests === 0);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

Incorrect assertion - test will always pass.

Same issue as Line 83: expect(numPollRequests === 0) evaluates the boolean expression first and passes it to expect(), which will always succeed.

🐛 Proposed fix
     // Check poll count
-    expect(numPollRequests === 0);
+    expect(numPollRequests).toBe(0);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
expect(numPollRequests === 0);
expect(numPollRequests).toBe(0);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@e2e/davinci-suites/src/polling.test.ts` at line 122, The assertion currently
passes a boolean expression into expect (expect(numPollRequests === 0)) which
evaluates before expect and thus the test always passes; update the assertion to
pass the value and use a matcher—replace the incorrect call with
expect(numPollRequests).toBe(0) (or another appropriate matcher) so the test
actually asserts that numPollRequests equals zero.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 14, 2026

Open in StackBlitz

@forgerock/davinci-client

pnpm add https://pkg.pr.new/@forgerock/davinci-client@634

@forgerock/device-client

pnpm add https://pkg.pr.new/@forgerock/device-client@634

@forgerock/journey-client

pnpm add https://pkg.pr.new/@forgerock/journey-client@634

@forgerock/oidc-client

pnpm add https://pkg.pr.new/@forgerock/oidc-client@634

@forgerock/protect

pnpm add https://pkg.pr.new/@forgerock/protect@634

@forgerock/sdk-types

pnpm add https://pkg.pr.new/@forgerock/sdk-types@634

@forgerock/sdk-utilities

pnpm add https://pkg.pr.new/@forgerock/sdk-utilities@634

@forgerock/iframe-manager

pnpm add https://pkg.pr.new/@forgerock/iframe-manager@634

@forgerock/sdk-logger

pnpm add https://pkg.pr.new/@forgerock/sdk-logger@634

@forgerock/sdk-oidc

pnpm add https://pkg.pr.new/@forgerock/sdk-oidc@634

@forgerock/sdk-request-middleware

pnpm add https://pkg.pr.new/@forgerock/sdk-request-middleware@634

@forgerock/storage

pnpm add https://pkg.pr.new/@forgerock/storage@634

commit: b9b8645

@github-actions
Copy link
Copy Markdown
Contributor

Deployed a2d8ffb to https://ForgeRock.github.io/ping-javascript-sdk/pr-634/a2d8ffb78754d428123b778dd7b8ca01f1988d1a branch gh-pages in ForgeRock/ping-javascript-sdk

@github-actions
Copy link
Copy Markdown
Contributor

📦 Bundle Size Analysis

📦 Bundle Size Analysis

🚨 Significant Changes

🔻 @forgerock/device-client - 0.0 KB (-10.0 KB, -100.0%)
🔻 @forgerock/journey-client - 0.0 KB (-91.9 KB, -100.0%)

➖ No Changes

@forgerock/storage - 1.5 KB
@forgerock/sdk-request-middleware - 4.5 KB
@forgerock/iframe-manager - 2.4 KB
@forgerock/sdk-oidc - 4.8 KB
@forgerock/sdk-logger - 1.6 KB
@forgerock/sdk-types - 7.9 KB
@forgerock/davinci-client - 53.5 KB
@forgerock/protect - 144.6 KB
@forgerock/device-client - 10.0 KB
@forgerock/sdk-utilities - 11.2 KB
@forgerock/oidc-client - 25.2 KB
@forgerock/journey-client - 91.9 KB


14 packages analyzed • Baseline from latest main build

Legend

🆕 New package
🔺 Size increased
🔻 Size decreased
➖ No change

ℹ️ How bundle sizes are calculated
  • Current Size: Total gzipped size of all files in the package's dist directory
  • Baseline: Comparison against the latest build from the main branch
  • Files included: All build outputs except source maps and TypeScript build cache
  • Exclusions: .map, .tsbuildinfo, and .d.ts.map files

🔄 Updated automatically on each push to this PR

@ancheetah ancheetah requested review from cerebrl and ryanbas21 May 15, 2026 14:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant