Thanks to visit codestin.com
Credit goes to github.com

Skip to content

chore: convert chrome_policy_check to TypeScript#33625

Merged
AtofStryker merged 1 commit into
developfrom
chore/convert_chrome_policy_ts
Apr 20, 2026
Merged

chore: convert chrome_policy_check to TypeScript#33625
AtofStryker merged 1 commit into
developfrom
chore/convert_chrome_policy_ts

Conversation

@AtofStryker
Copy link
Copy Markdown
Collaborator

@AtofStryker AtofStryker commented Apr 17, 2026

Summary

  • Deleted packages/server/lib/util/chrome_policy_check.js and replaced it with a fully-typed chrome_policy_check.ts
  • Converted the test file test/unit/util/chrome_policy_check.js.ts, switching from require() to ES module imports and describe in place of context
  • Updated the import in packages/server/lib/modes/run.ts to use the named run export from the new module

Changes

chrome_policy_check.ts (new, replaces .js)

  • Uses ES module imports instead of require()
  • Adds a local RegistryValueWithPath intersection type (RegistryValue & { fullPath: string }) to properly extend the readonly registry-js union type instead of mutating it in place
  • Types POLICY_KEYS as string[] and POLICY_HKEYS as HKEY[]
  • Types warnIfPolicyMatches parameters — warningName uses Parameters<typeof errors.get>[0] to satisfy the keyof AllCypressErrorObj constraint without importing the large union directly
  • Replaces the lodash chain .find().get() (which TS cannot type-check correctly) with _.find()?.fullPath and a type-predicate .filter()
  • getAllPolicies now spreads each RegistryValue into a new RegistryValueWithPath object instead of mutating the readonly entry
  • The platform guard (os.platform() !== 'win32') is expressed as an early return inside the exported run() function rather than a top-level if block with a try/catch around a dynamic require()

modes/run.ts

  • Updates the import to use the named run export and calls it directly as runChromePolicyCheck() (the onWarning callback is now wired internally via the module's run export)

test/unit/util/chrome_policy_check.ts

  • Converted from CommonJS to ES module imports
  • contextdescribe (consistent with the rest of the test suite)

Test plan

  • Existing unit tests in packages/server/test/unit/util/chrome_policy_check.ts cover all three branches (policy matched, no policy, enumerateValues throws)
  • Run yarn workspace @packages/server test-unit -- packages/server/test/unit/util/chrome_policy_check.ts to verify

Made with Cursor


Note

Medium Risk
Mostly a type/interop refactor, but it changes module loading behavior by importing registry-js at module scope, which could affect startup on non-Windows environments if the dependency is not fully cross-platform.

Overview
Refactors chrome_policy_check by replacing the old CommonJS chrome_policy_check.js (with dynamic, Windows-only require) with a typed chrome_policy_check.ts that exports run/getRunner and builds registry policy paths without mutating registry-js values.

Updates run mode (lib/modes/run.ts) to call the new named run export for Chromium browsers, and converts the unit spec to ES module imports to validate the runner behavior (policies found, none found, and exception handling).

Reviewed by Cursor Bugbot for commit 05666f1. Bugbot is set up for automated code reviews on this repo. Configure here.

@AtofStryker AtofStryker self-assigned this Apr 17, 2026
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit c144555. Configure here.

Comment thread packages/server/lib/util/chrome_policy_check.ts
import Debug from 'debug'
import * as errors from '../errors'
import os from 'os'
import { enumerateValues, HKEY, RegistryValue } from 'registry-js'
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Static import of Windows-only native module crashes non-Windows

High Severity

The top-level import { enumerateValues, HKEY, RegistryValue } from 'registry-js' is evaluated at module load time on all platforms. Since registry-js is a Windows-only native addon listed in optionalDependencies, it won't be installed on macOS/Linux. This will throw a MODULE_NOT_FOUND error when run.ts imports this module, crashing the server. The old code used a conditional dynamic require() inside a platform check with a try/catch to avoid this.

Fix in Cursor Fix in Web

Triggered by project rule: Overview

Reviewed by Cursor Bugbot for commit c144555. Configure here.

Copy link
Copy Markdown
Collaborator Author

@AtofStryker AtofStryker Apr 17, 2026

Choose a reason for hiding this comment

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

Can you confirm this with documentation references? At a glance, https://www.npmjs.com/package/registry-js doesn't look to be a native add on, but uses the windows registry APIs when invoked, which is gated behind our check.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Unable to authenticate your request. Please make sure to connect your GitHub account to Cursor. Go to Cursor

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Can you confirm this with documentation references? At a glance, https://www.npmjs.com/package/registry-js doesn't look to be a native add on, but uses the windows registry APIs when invoked, which is gated behind our check.

@cypress
Copy link
Copy Markdown

cypress Bot commented Apr 17, 2026

cypress    Run #69986

Run Properties:  status check canceled Cancelled #69986  •  git commit 05666f1507: chore: convert chrome_policy_check to TypeScript
Project cypress
Branch Review chore/convert_chrome_policy_ts
Run status status check canceled Cancelled #69986
Run duration 44m 50s
Commit git commit 05666f1507: chore: convert chrome_policy_check to TypeScript
Committer Bill Glesias
View all properties for this run ↗︎

Test results
Tests that failed  Failures 7
Tests that were flaky  Flaky 2
Tests that did not run due to a developer annotating a test with .skip  Pending 7
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 508
View all changes introduced in this branch ↗︎

Warning

Partial Report: The results for the Application Quality reports may be incomplete.

UI Coverage  62.34%
  Untested elements 27  
  Tested elements 48  
Accessibility  98.99%
  Failed rules  0 critical   3 serious   1 moderate   0 minor
  Failed elements 19  

Tests for review

Failed  cypress\e2e\config-files-error-handling.cy.ts • 1 failed test • launchpad-e2e

View Output

Test Artifacts
setupNodeEvents > handles multiple config errors and then recovers Test Replay Screenshots
Failed  cypress\e2e\runner\retries.experimentalRetries.mochaEvents.cy.ts • 2 failed tests • app-e2e

View Output

Test Artifacts
... > does not try to serialize error with err.actual as DOM node Test Replay Screenshots
... > does not try to serialize error with err.actual as DOM node Test Replay Screenshots
Failed  cypress\e2e\runner\runner.ui.cy.ts • 2 failed tests • app-e2e

View Output

Test Artifacts
src/cypress/runner > tests finish with correct state > no tests Test Replay Screenshots
src/cypress/runner > other specs > file with empty suites only displays no tests found Test Replay Screenshots
Failed  cypress\e2e\cypress-origin-communicator.cy.ts • 2 failed tests • app-e2e

View Output

Test Artifacts
Cypress In Cypress Origin Communicator > primary origin memory leak prevention > cleans up the primaryOriginCommunicator events when navigating away from the /specs to /runs Test Replay Screenshots
Cypress In Cypress Origin Communicator > primary origin memory leak prevention > cleans up the primaryOriginCommunicator events when navigating to run a different spec Test Replay Screenshots
Failed  cypress\e2e\runner\sessions.ui.cy.ts • 0 failed tests • app-e2e

View Output

Test Artifacts

The first 5 failed specs are shown, see all 47 specs in Cypress Cloud.

Flakiness  cypress\e2e\config-warning.cy.ts • 1 flaky test • launchpad-e2e

View Output

Test Artifacts
baseUrl > should add baseUrl warning when going from good to bad config Test Replay Screenshots
Flakiness  cypress\e2e\cypress-origin-communicator.cy.ts • 1 flaky test • app-e2e

View Output

Test Artifacts
Cypress In Cypress Origin Communicator > primary origin memory leak prevention > cleans up the primaryOriginCommunicator events when navigating away from the /specs to /settings Test Replay Screenshots

@AtofStryker AtofStryker marked this pull request as draft April 17, 2026 16:40
@AtofStryker AtofStryker force-pushed the chore/convert_chrome_policy_ts branch from c144555 to 66202d4 Compare April 17, 2026 16:54
@AtofStryker AtofStryker marked this pull request as ready for review April 17, 2026 16:54
@AtofStryker AtofStryker force-pushed the chore/convert_chrome_policy_ts branch from 66202d4 to 05666f1 Compare April 17, 2026 18:15
@AtofStryker AtofStryker merged commit 7a74773 into develop Apr 20, 2026
126 of 134 checks passed
@AtofStryker AtofStryker deleted the chore/convert_chrome_policy_ts branch April 20, 2026 18:56
@cypress-bot
Copy link
Copy Markdown
Contributor

cypress-bot Bot commented Apr 21, 2026

Released in 15.14.1.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v15.14.1, please open a new issue.

@cypress-bot cypress-bot Bot locked as resolved and limited conversation to collaborators Apr 21, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants