chore: convert chrome_policy_check to TypeScript#33625
Conversation
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
❌ 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.
| import Debug from 'debug' | ||
| import * as errors from '../errors' | ||
| import os from 'os' | ||
| import { enumerateValues, HKEY, RegistryValue } from 'registry-js' |
There was a problem hiding this comment.
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.
Triggered by project rule: Overview
Reviewed by Cursor Bugbot for commit c144555. Configure here.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Unable to authenticate your request. Please make sure to connect your GitHub account to Cursor. Go to Cursor
There was a problem hiding this comment.
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.
c144555 to
66202d4
Compare
66202d4 to
05666f1
Compare
|
Released in This comment thread has been locked. If you are still experiencing this issue after upgrading to |


Summary
packages/server/lib/util/chrome_policy_check.jsand replaced it with a fully-typedchrome_policy_check.tstest/unit/util/chrome_policy_check.js→.ts, switching fromrequire()to ES module imports anddescribein place ofcontextpackages/server/lib/modes/run.tsto use the namedrunexport from the new moduleChanges
chrome_policy_check.ts(new, replaces.js)require()RegistryValueWithPathintersection type (RegistryValue & { fullPath: string }) to properly extend the readonlyregistry-jsunion type instead of mutating it in placePOLICY_KEYSasstring[]andPOLICY_HKEYSasHKEY[]warnIfPolicyMatchesparameters —warningNameusesParameters<typeof errors.get>[0]to satisfy thekeyof AllCypressErrorObjconstraint without importing the large union directly.find().get()(which TS cannot type-check correctly) with_.find()?.fullPathand a type-predicate.filter()getAllPoliciesnow spreads eachRegistryValueinto a newRegistryValueWithPathobject instead of mutating the readonly entryos.platform() !== 'win32') is expressed as an early return inside the exportedrun()function rather than a top-levelifblock with atry/catcharound a dynamicrequire()modes/run.tsrunexport and calls it directly asrunChromePolicyCheck()(theonWarningcallback is now wired internally via the module'srunexport)test/unit/util/chrome_policy_check.tscontext→describe(consistent with the rest of the test suite)Test plan
packages/server/test/unit/util/chrome_policy_check.tscover all three branches (policy matched, no policy,enumerateValuesthrows)yarn workspace @packages/server test-unit -- packages/server/test/unit/util/chrome_policy_check.tsto verifyMade with Cursor
Note
Medium Risk
Mostly a type/interop refactor, but it changes module loading behavior by importing
registry-jsat module scope, which could affect startup on non-Windows environments if the dependency is not fully cross-platform.Overview
Refactors
chrome_policy_checkby replacing the old CommonJSchrome_policy_check.js(with dynamic, Windows-onlyrequire) with a typedchrome_policy_check.tsthat exportsrun/getRunnerand builds registry policy paths without mutatingregistry-jsvalues.Updates run mode (
lib/modes/run.ts) to call the new namedrunexport 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.