Merge pull request #16307 from overleaf/ab-split-tests-never-throw

[web] Guarantee split test assignments can never throw and cleanup boilterplate error handling

GitOrigin-RevId: ab50abde6e0632c5a9625b5c3d3e98f3383cc56c
This commit is contained in:
Alexandre Bourdin
2024-01-19 09:05:14 +00:00
committed by Copybot
parent 29d41497ef
commit 3b9eb4e8aa
5 changed files with 149 additions and 317 deletions
@@ -542,78 +542,31 @@ const ProjectController = {
req,
res,
'project-share-modal-paywall',
{},
() => {
// do not fail editor load if assignment fails
cb()
}
cb
)
},
sharingModalNullTest(cb) {
// null test targeting logged in users, for front-end side
SplitTestHandler.getAssignment(
req,
res,
'null-test-share-modal',
{},
() => {
// do not fail editor load if assignment fails
cb()
}
)
SplitTestHandler.getAssignment(req, res, 'null-test-share-modal', cb)
},
pdfjsAssignment(cb) {
SplitTestHandler.getAssignment(
req,
res,
'pdfjs-40',
{},
(error, assignment) => {
// do not fail editor load if assignment fails
if (error) {
cb(null, { variant: 'default' })
} else {
cb(null, assignment)
}
}
)
SplitTestHandler.getAssignment(req, res, 'pdfjs-40', cb)
},
latexLogParserAssignment(cb) {
SplitTestHandler.getAssignment(
req,
res,
'latex-log-parser',
(error, assignment) => {
// do not fail editor load if assignment fails
if (error) {
cb(null, { variant: 'default' })
} else {
cb(null, assignment)
}
}
)
SplitTestHandler.getAssignment(req, res, 'latex-log-parser', cb)
},
trackPdfDownloadAssignment(cb) {
SplitTestHandler.getAssignment(req, res, 'track-pdf-download', () => {
// We'll pick up the assignment from the res.locals assignment.
cb()
})
SplitTestHandler.getAssignment(req, res, 'track-pdf-download', cb)
},
pdfCachingModeAssignment(cb) {
SplitTestHandler.getAssignment(req, res, 'pdf-caching-mode', () => {
// We'll pick up the assignment from the res.locals assignment.
cb()
})
SplitTestHandler.getAssignment(req, res, 'pdf-caching-mode', cb)
},
pdfCachingPrefetchingAssignment(cb) {
SplitTestHandler.getAssignment(
req,
res,
'pdf-caching-prefetching',
() => {
// We'll pick up the assignment from the res.locals assignment.
cb()
}
cb
)
},
pdfCachingPrefetchLargeAssignment(cb) {
@@ -621,10 +574,7 @@ const ProjectController = {
req,
res,
'pdf-caching-prefetch-large',
() => {
// We'll pick up the assignment from the res.locals assignment.
cb()
}
cb
)
},
pdfCachingCachedUrlLookupAssignment(cb) {
@@ -632,10 +582,7 @@ const ProjectController = {
req,
res,
'pdf-caching-cached-url-lookup',
() => {
// We'll pick up the assignment from the res.locals assignment.
cb()
}
cb
)
},
tableGeneratorPromotionAssignment(cb) {
@@ -643,52 +590,17 @@ const ProjectController = {
req,
res,
'table-generator-promotion',
() => {
// We'll pick up the assignment from the res.locals assignment.
cb()
}
cb
)
},
personalAccessTokenAssignment(cb) {
SplitTestHandler.getAssignment(
req,
res,
'personal-access-token',
(error, assignment) => {
// do not fail editor load if assignment fails
if (error) {
cb(null, { variant: 'default' })
} else {
cb(null, assignment)
}
}
)
SplitTestHandler.getAssignment(req, res, 'personal-access-token', cb)
},
idePageAssignment(cb) {
SplitTestHandler.getAssignment(
req,
res,
'ide-page',
(error, assignment) => {
// do not fail editor load if assignment fails
if (error) {
cb(null, { variant: 'default' })
} else {
cb(null, assignment)
}
}
)
SplitTestHandler.getAssignment(req, res, 'ide-page', cb)
},
writefullIntegrationAssignment(cb) {
SplitTestHandler.getAssignment(
req,
res,
'writefull-integration',
() => {
// We'll pick up the assignment from the res.locals assignment.
cb()
}
)
SplitTestHandler.getAssignment(req, res, 'writefull-integration', cb)
},
projectTags(cb) {
if (!userId) {
@@ -326,19 +326,13 @@ async function projectListPage(req, res, next) {
)
}
}
try {
// The assignment will be picked up via 'ol-splitTestVariants' in react.
await SplitTestHandler.promises.getAssignment(
req,
res,
'download-pdf-dashboard'
)
} catch (err) {
logger.error(
{ err },
'failed to get "download-pdf-dashboard" split test assignment'
)
}
// The assignment will be picked up via 'ol-splitTestVariants' in react.
await SplitTestHandler.promises.getAssignment(
req,
res,
'download-pdf-dashboard'
)
const hasPaidAffiliation = userAffiliations.some(
affiliation => affiliation.licence && affiliation.licence !== 'free'
@@ -370,18 +364,11 @@ async function projectListPage(req, res, next) {
}
}
try {
await SplitTestHandler.promises.getAssignment(
req,
res,
'writefull-integration'
)
} catch (err) {
logger.warn(
{ err },
'failed to get "writefull-integration" split test assignment'
)
}
await SplitTestHandler.promises.getAssignment(
req,
res,
'writefull-integration'
)
let showInrGeoBanner, inrGeoBannerSplitTestName
let inrGeoBannerVariant = 'default'
@@ -390,63 +377,35 @@ async function projectListPage(req, res, next) {
if (usersBestSubscription?.type === 'free') {
const { currencyCode, countryCode } =
await GeoIpLookup.promises.getCurrencyCode(req.ip)
let inrGeoPricingVariant = 'default'
try {
// Split test is kept active, but all users geolocated in India can
// now use the INR currency (See #13507)
const inrGeoPricingAssignment =
await SplitTestHandler.promises.getAssignment(
req,
res,
'geo-pricing-inr'
)
inrGeoPricingVariant = inrGeoPricingAssignment.variant
} catch (error) {
logger.error(
{ err: error },
'Failed to get geo-pricing-inr split test assignment'
)
}
try {
const latamGeoPricingAssignment =
await SplitTestHandler.promises.getAssignment(
req,
res,
'geo-pricing-latam'
)
showLATAMBanner =
latamGeoPricingAssignment.variant === 'latam' &&
['BR', 'MX', 'CO', 'CL', 'PE'].includes(countryCode)
// LATAM Banner needs to know which currency to display
if (showLATAMBanner) {
recommendedCurrency = currencyCode
}
} catch (error) {
logger.error(
{ err: error },
'Failed to get geo-pricing-latam split test assignment'
// Split test is kept active, but all users geolocated in India can
// now use the INR currency (See #13507)
const { variant: inrGeoPricingVariant } =
await SplitTestHandler.promises.getAssignment(req, res, 'geo-pricing-inr')
const latamGeoPricingAssignment =
await SplitTestHandler.promises.getAssignment(
req,
res,
'geo-pricing-latam'
)
showLATAMBanner =
latamGeoPricingAssignment.variant === 'latam' &&
['BR', 'MX', 'CO', 'CL', 'PE'].includes(countryCode)
// LATAM Banner needs to know which currency to display
if (showLATAMBanner) {
recommendedCurrency = currencyCode
}
if (countryCode === 'IN') {
inrGeoBannerSplitTestName =
inrGeoPricingVariant === 'inr'
? 'geo-banners-inr-2'
: 'geo-banners-inr-1'
try {
const geoBannerAssignment =
await SplitTestHandler.promises.getAssignment(
req,
res,
inrGeoBannerSplitTestName
)
showInrGeoBanner = true
inrGeoBannerVariant = geoBannerAssignment.variant
} catch (error) {
logger.error(
{ err: error },
`Failed to get INR geo banner lookup or assignment (${inrGeoBannerSplitTestName})`
)
}
const geoBannerAssignment = await SplitTestHandler.promises.getAssignment(
req,
res,
inrGeoBannerSplitTestName
)
showInrGeoBanner = true
inrGeoBannerVariant = geoBannerAssignment.variant
}
}