Skip to content

fix: avoid Cypress socket errors in layout intercepts#4318

Merged
olemartinorg merged 1 commit into
mainfrom
fix/cypress-layout-intercept-socket-close
Jul 6, 2026
Merged

fix: avoid Cypress socket errors in layout intercepts#4318
olemartinorg merged 1 commit into
mainfrom
fix/cypress-layout-intercept-socket-close

Conversation

@olemartinorg

@olemartinorg olemartinorg commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Description

Updates the Cypress layout intercept helper used by several frontend tests so it mutates backend layout responses in the before:response hook instead of replying with a rewritten response.

This is intended to reduce sporadic PDF test failures where Cypress reports Socket closed before finished writing response for cancelled or abandoned intercepted requests. The error matches an open upstream Cypress issue: cypress-io/cypress#26248.

The recurring failure has been observed in test/e2e/integration/frontend-test/pdf.ts, specifically the "should generate PDF for changename step" test. The failure has been seen repeatedly in tt02 runs for GET **/api/layouts/changename, while the other PDF tests have not shown the same pattern.

No application functionality is changed.

Related Issue(s)

None.

Verification/QA

  • Manual functionality testing
    • I have tested these changes manually
    • Creator of the original issue (or service owner) has been contacted for manual testing (or will be contacted when released in alpha)
    • No testing done/necessary
  • Automated tests
    • Unit test(s) have been added/updated
    • Cypress E2E test(s) have been added/updated
    • No automatic tests are needed here (no functional changes/additions)
    • I want someone to help me make some tests
  • UU/WCAG (follow these guidelines until we have our own)
    • I have tested with a screen reader/keyboard navigation/automated wcag validator
    • No testing done/necessary (no DOM/visual changes)
    • I want someone to help me perform accessibility testing
  • User documentation @ altinn-studio-docs
    • Has been added/updated
    • No functionality has been changed/added, so no documentation is needed
    • I will do that later/have created an issue
  • Support in Altinn Studio
    • Issue(s) created for support in Studio
    • This change/feature does not require any changes to Altinn Studio
  • Sprint board
    • The original issue (or this PR itself) has been added to the Team Apps project and to the current sprint board
    • I don't have permissions to do that, please help me out
  • Labels
    • I have added a kind/* and backport* label to this PR for proper release notes grouping
    • I don't have permissions to add labels, please help me out

Summary by CodeRabbit

  • Tests
    • Improved the reliability of end-to-end layout interception during automated testing.
    • Made response handling more resilient when working with different response body formats.

@olemartinorg olemartinorg moved this to 🔎 In review in Team Altinn Studio Jul 3, 2026
@olemartinorg olemartinorg added ignore-for-release Pull requests to be ignored in release notes backport-ignore This PR is a new feature and should not be cherry-picked onto release branches squad/utforming Issues that belongs to the named squad. labels Jul 3, 2026
@coderabbitai

coderabbitai Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The interceptLayout Cypress command in the e2e test support file was refactored to rewrite response bodies using a before:response event handler instead of req.reply, adjusting body parsing and output assignment accordingly.

Changes

interceptLayout Response Handling

Layer / File(s) Summary
Switch to before:response handler
test/e2e/support/custom.ts
Replaces req.reply(...) with req.on('before:response', ...), conditionally parses res.body (string vs object), applies the same mutator/wholeLayoutMutator logic, and assigns the result back via res.body = JSON.stringify(set).

Estimated code review effort: 1 (Trivial) | ~5 minutes

Related issues: None found in the provided context.

Related PRs: None found in the provided context.

Suggested labels: test, e2e

Suggested reviewers: None specified.

🐰 A tiny hop, a small rewrite,
before:response now sees the light,
bodies parsed, mutated with care,
JSON strings sent through the air.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and clearly describes the main change to Cypress layout intercepts.
Description check ✅ Passed The description follows the template well and includes summary, issue status, and verification details.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ 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 fix/cypress-layout-intercept-socket-close

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.

@JamalAlabdullah JamalAlabdullah left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
test/e2e/support/custom.ts (1)

525-525: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

set is implicitly typed any.

res.body is typed any by Cypress's CyHttpMessages.BaseMessage, so set (and downstream usages like Object.values(set)) carry no type safety. This predates this change (same gap existed with req.reply), but since the line is being touched, consider specifying the response generic (e.g. req.on<Record<string, ILayoutFile>>('before:response', ...) if supported by the Cypress version, or an explicit local type annotation) to avoid any propagating through the mutation logic.

As per coding guidelines, "Avoid using any or type casting (as type) in TypeScript; instead, improve typing by removing such casts and anys to maintain proper type safety."

🤖 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 `@test/e2e/support/custom.ts` at line 525, The touched response parsing in
custom.ts currently lets `set` inherit `any` from `res.body`, so the mutation
logic loses type safety. Update the `before:response` handling around
`req.on`/`req.reply` to use a concrete response type or an explicit local
annotation for the parsed body (for example, a record of layout files) so `set`
and downstream `Object.values(set)` remain strongly typed without `any`
propagation.

Source: Coding guidelines

🤖 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.

Nitpick comments:
In `@test/e2e/support/custom.ts`:
- Line 525: The touched response parsing in custom.ts currently lets `set`
inherit `any` from `res.body`, so the mutation logic loses type safety. Update
the `before:response` handling around `req.on`/`req.reply` to use a concrete
response type or an explicit local annotation for the parsed body (for example,
a record of layout files) so `set` and downstream `Object.values(set)` remain
strongly typed without `any` propagation.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 0c4f42cf-b65b-457b-943b-cd25f067e9af

📥 Commits

Reviewing files that changed from the base of the PR and between 4ba1915 and be3ffe8.

📒 Files selected for processing (1)
  • test/e2e/support/custom.ts

@olemartinorg olemartinorg changed the title Avoid Cypress socket errors in layout intercepts fix: avoid Cypress socket errors in layout intercepts Jul 6, 2026
@olemartinorg olemartinorg merged commit fec105c into main Jul 6, 2026
14 of 16 checks passed
@olemartinorg olemartinorg deleted the fix/cypress-layout-intercept-socket-close branch July 6, 2026 09:20
@github-project-automation github-project-automation Bot moved this from 🔎 In review to ✅ Done in Team Altinn Studio Jul 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-ignore This PR is a new feature and should not be cherry-picked onto release branches ignore-for-release Pull requests to be ignored in release notes squad/utforming Issues that belongs to the named squad.

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

2 participants