Skip to content

Commit 0cafced

Browse files
SDK-8048: add forceHttp1 only for the affected Cypress versions (16.1.0 to 16.2.0)
The extension service-worker bug is a regression from cypress-io/cypress#34762 (16.1.0), reported as #35127 and fixed by #34958 in 16.2.1. Builds asking for 16.2.1+ or 16.0.x no longer get forceHttp1. "16" and "16.latest" still do while 16.2.0 is the only Cypress 16 Rails offers. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent faff373 commit 0cafced

3 files changed

Lines changed: 36 additions & 11 deletions

File tree

‎bin/helpers/capabilityHelper.js‎

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,28 @@ const isAboveAccessibilityCypressMajor = (cypressVersion) => {
2020
return major !== undefined && major > Constants.MAX_CYPRESS_MAJOR_FOR_ACCESSIBILITY;
2121
};
2222

23+
const versionParts = (version) => String(version).split('.').map((n) => Number(n));
24+
25+
const isBefore = (version, other) => {
26+
const a = versionParts(version), b = versionParts(other);
27+
for (let i = 0; i < 3; i++) {
28+
if ((a[i] || 0) !== (b[i] || 0)) return (a[i] || 0) < (b[i] || 0);
29+
}
30+
return false;
31+
};
32+
33+
// True for an accessibility build whose Cypress has the extension service-worker bug.
34+
// "16" and "16.latest" name no minor, so Rails picks it: they count while 16.2.0 is the only
35+
// Cypress 16 Rails offers. Once Rails offers 16.2.1+, drop that branch.
36+
const needsForceHttp1ForAccessibility = (cypressVersion) => {
37+
const [firstAffected, firstFixed] = Constants.ACCESSIBILITY_FORCE_HTTP1_CYPRESS_RANGE;
38+
const value = String(cypressVersion).trim().toLowerCase();
39+
const exact = value.match(/^(\d+)\.(\d+)\.(\d+)$/);
40+
if (exact) return !isBefore(value, firstAffected) && isBefore(value, firstFixed);
41+
const majorOnly = value.match(/^(\d+)(\.latest)?$/);
42+
return !!majorOnly && Number(majorOnly[1]) === versionParts(firstAffected)[0];
43+
};
44+
2345
// Adds forceHttp1=true to the run's Cypress config unless the user already set forceHttp1
2446
// (either way), keeping every other key they passed.
2547
const withForceHttp1 = (config) => {
@@ -160,10 +182,9 @@ const caps = (bsConfig, zip) => {
160182
runSettings = Object.assign({}, runSettings, { cypress_version: String(Constants.DEFAULT_CYPRESS_MAJOR_FOR_ACCESSIBILITY) });
161183
logger.info(Constants.userMessages.ACCESSIBILITY_CYPRESS_VERSION_PINNED);
162184
}
163-
// Accessibility scans on Cypress 16 only complete with forceHttp1 (see the constant).
164-
const requestedMajor = cypressMajor(runSettings.cypress_version);
165-
if (isAccessibilityOn(bsConfig) && requestedMajor !== undefined
166-
&& requestedMajor >= Constants.MIN_CYPRESS_MAJOR_NEEDING_FORCE_HTTP1_FOR_ACCESSIBILITY) {
185+
// Accessibility scans on the affected Cypress 16 versions only complete with forceHttp1.
186+
if (isAccessibilityOn(bsConfig) && !Utils.isUndefined(runSettings.cypress_version)
187+
&& needsForceHttp1ForAccessibility(runSettings.cypress_version)) {
167188
const config = withForceHttp1(runSettings.config);
168189
if (config !== runSettings.config) {
169190
runSettings = Object.assign({}, runSettings, { config });

‎bin/helpers/constants.js‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ const userMessages = {
8989
ACCESSIBILITY_CYPRESS_VERSION_PINNED:
9090
"Accessibility builds without a cypress_version run on the latest Cypress 15.",
9191
ACCESSIBILITY_FORCE_HTTP1_SET:
92-
"Accessibility on Cypress 16 needs Cypress's HTTP/1.1 proxy, so this build runs with forceHttp1=true.",
92+
"Accessibility on Cypress 16.1.0-16.2.0 needs Cypress's HTTP/1.1 proxy, so this build runs with forceHttp1=true.",
9393
CYPRESS_VERSION_CHANGED:
9494
"Your build will run using Cypress <actualVersion> instead of Cypress <preferredVersion>.<frameworkUpgradeMessage> Read more about supported versions here: http://browserstack.com/docs/automate/cypress/supported-versions",
9595
LOCAL_START_FAILED: "Local Testing setup failed.",
@@ -454,10 +454,11 @@ const MAX_CYPRESS_MAJOR_FOR_ACCESSIBILITY = 16;
454454
// Major an accessibility build asks for when it names no cypress_version. Stays on 15 while
455455
// Rails' own default does, so an unpinned build keeps today's Cypress.
456456
const DEFAULT_CYPRESS_MAJOR_FOR_ACCESSIBILITY = 15;
457-
// From this major the a11y extension's service worker never starts in Cypress's default network
458-
// mode (cypress-io/cypress#35127, fixed in 16.2.1), so scans time out unless forceHttp1 is on.
459-
// SDK-8048 preprod A/B on 16.2.0: scan step 25.6s without it, 4.2s with it.
460-
const MIN_CYPRESS_MAJOR_NEEDING_FORCE_HTTP1_FOR_ACCESSIBILITY = 16;
457+
// Cypress versions where the a11y extension's service worker never starts, so every scan times
458+
// out unless forceHttp1 is on: [first affected, first fixed). Regression from cypress-io/cypress#34762
459+
// (16.1.0), reported as cypress-io/cypress#35127, fixed by #34958 in 16.2.1.
460+
// SDK-8048 preprod A/B on 16.2.0: scan step 25.6s without forceHttp1, 4.2s with it.
461+
const ACCESSIBILITY_FORCE_HTTP1_CYPRESS_RANGE = ['16.1.0', '16.2.1'];
461462

462463
const CYPRESS_CUSTOM_ERRORS_TO_PRINT_KEY = "custom_errors_to_print";
463464

@@ -526,7 +527,7 @@ module.exports = Object.freeze({
526527
SPEC_TIMEOUT_LIMIT,
527528
MAX_CYPRESS_MAJOR_FOR_ACCESSIBILITY,
528529
DEFAULT_CYPRESS_MAJOR_FOR_ACCESSIBILITY,
529-
MIN_CYPRESS_MAJOR_NEEDING_FORCE_HTTP1_FOR_ACCESSIBILITY,
530+
ACCESSIBILITY_FORCE_HTTP1_CYPRESS_RANGE,
530531
CYPRESS_CUSTOM_ERRORS_TO_PRINT_KEY,
531532
CYPRESS_V9_AND_OLDER_TYPE,
532533
CYPRESS_V10_AND_ABOVE_TYPE,

‎test/unit/bin/helpers/capabilityHelper.js‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ describe("capabilityHelper.js", () => {
141141
});
142142
});
143143

144-
["16", "16.2.0", "16.latest"].forEach((version) => {
144+
["16", "16.latest", "16.1.0", "16.1.1", "16.2.0"].forEach((version) => {
145145
it(`adds forceHttp1=true for accessibility on cypress_version ${version}`, () => {
146146
return sentRunSettings({ accessibility: true, cypress_version: version }).then(({ sent, bsConfig }) => {
147147
chai.assert.equal(sent.config, "forceHttp1=true");
@@ -169,6 +169,9 @@ describe("capabilityHelper.js", () => {
169169
["accessibility on, no version (pinned to 15)", { accessibility: true }],
170170
["accessibility off, Cypress 16", { accessibility: false, cypress_version: "16.2.0" }],
171171
["accessibility on, cypress_version latest", { accessibility: true, cypress_version: "latest" }],
172+
["accessibility on, Cypress 16.2.1 (fixed)", { accessibility: true, cypress_version: "16.2.1" }],
173+
["accessibility on, Cypress 16.3.0 (fixed)", { accessibility: true, cypress_version: "16.3.0" }],
174+
["accessibility on, Cypress 16.0.0 (before the regression)", { accessibility: true, cypress_version: "16.0.0" }],
172175
].forEach(([name, runSettings]) => {
173176
it(`does not add forceHttp1 for ${name}`, () => {
174177
return sentRunSettings(runSettings).then(({ sent }) => {

0 commit comments

Comments
 (0)