From 9daa56becc8badb221276b08087c82405200f958 Mon Sep 17 00:00:00 2001 From: Andrew Rumble Date: Wed, 27 May 2026 15:08:19 +0100 Subject: [PATCH] Merge pull request #33079 from overleaf/ar-remove-request-from-clsi [clsi] remove request library GitOrigin-RevId: 4690c476157fc2829e516d91f688f9424f8c162f --- services/clsi/app.js | 11 +-- services/clsi/package.json | 1 - services/clsi/test/smoke/js/SmokeTests.js | 85 ++++++++++++----------- yarn.lock | 1 - 4 files changed, 53 insertions(+), 45 deletions(-) diff --git a/services/clsi/app.js b/services/clsi/app.js index 5ea9985a79..7e1fb1b760 100644 --- a/services/clsi/app.js +++ b/services/clsi/app.js @@ -196,9 +196,6 @@ function runSmokeTest() { setTimeout(runSmokeTest, INTERVAL) }) } -if (Settings.smokeTest) { - runSmokeTest() -} app.get('/health_check', function (req, res) { if (Settings.processTooOld) { @@ -210,7 +207,10 @@ app.get('/health_check', function (req, res) { smokeTest.sendLastResult(res) }) -app.get('/smoke_test_force', (req, res) => smokeTest.sendNewResult(res)) +app.get( + '/smoke_test_force', + async (req, res, next) => await smokeTest.sendNewResult(res).catch(next) +) app.use(function (error, req, res, next) { if (error instanceof Errors.NotFoundError) { @@ -325,6 +325,9 @@ if (import.meta.main) { logger.fatal({ error }, `Error starting CLSI on ${host}:${port}`) } else { logger.debug(`CLSI starting up, listening on ${host}:${port}`) + if (Settings.smokeTest) { + runSmokeTest() + } } }) diff --git a/services/clsi/package.json b/services/clsi/package.json index 9f32a74802..d6d5210388 100644 --- a/services/clsi/package.json +++ b/services/clsi/package.json @@ -33,7 +33,6 @@ "multer": "2.1.1", "overleaf-editor-core": "workspace:*", "p-limit": "^3.1.0", - "request": "2.88.2", "send": "^0.19.0", "tar-fs": "^3.1.1", "workerpool": "^6.1.5" diff --git a/services/clsi/test/smoke/js/SmokeTests.js b/services/clsi/test/smoke/js/SmokeTests.js index 97618e7d21..707a7ad0e3 100644 --- a/services/clsi/test/smoke/js/SmokeTests.js +++ b/services/clsi/test/smoke/js/SmokeTests.js @@ -1,4 +1,4 @@ -import request from 'request' +import { fetchJson } from '@overleaf/fetch-utils' import Settings from '@overleaf/settings' const buildUrl = path => @@ -7,17 +7,29 @@ const buildUrl = path => const url = buildUrl(`project/smoketest-${process.pid}/compile`) export default { - sendNewResult(res) { - this._run(error => this._sendResponse(res, error)) + async sendNewResult(res) { + let error + try { + await this._run() + } catch (err) { + error = err + } + + this._sendResponse(res, error) }, sendLastResult(res) { this._sendResponse(res, this._lastError) }, triggerRun(cb) { - this._run(error => { - this._lastError = error - cb(error) - }) + this._run() + .then(() => { + this._lastError = null + cb() + }) + .catch(error => { + this._lastError = error + cb(error) + }) }, lastRunSuccessful() { return this._lastError == null @@ -36,19 +48,18 @@ export default { res.contentType('text/plain') res.status(code).send(body) }, - _run(done) { - request.post( - { - url, - json: { - compile: { - options: { - metricsPath: 'health-check', - }, - resources: [ - { - path: 'main.tex', - content: `\ + async _run() { + const body = await fetchJson(url, { + method: 'POST', + json: { + compile: { + options: { + metricsPath: 'health-check', + }, + resources: [ + { + path: 'main.tex', + content: `\ % Membrane-like surface % Author: Yotam Avital \\documentclass{article} @@ -102,28 +113,24 @@ date \\end{document}\ `, - }, - ], - }, + }, + ], }, }, - (error, response, body) => { - if (error) return done(error) - if (!body || !body.compile || !body.compile.outputFiles) { - return done(new Error('response payload incomplete')) - } + }) - let pdfFound = false - let logFound = false - for (const file of body.compile.outputFiles) { - if (file.type === 'pdf') pdfFound = true - if (file.type === 'log') logFound = true - } + if (!body || !body.compile || !body.compile.outputFiles) { + throw new Error('response payload incomplete') + } - if (!pdfFound) return done(new Error('no pdf returned')) - if (!logFound) return done(new Error('no log returned')) - done() - } - ) + let pdfFound = false + let logFound = false + for (const file of body.compile.outputFiles) { + if (file.type === 'pdf') pdfFound = true + if (file.type === 'log') logFound = true + } + + if (!pdfFound) throw new Error('no pdf returned') + if (!logFound) throw new Error('no log returned') }, } diff --git a/yarn.lock b/yarn.lock index 517cfb79b1..a96230256e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6453,7 +6453,6 @@ __metadata: nyc: "npm:^17.1.0" overleaf-editor-core: "workspace:*" p-limit: "npm:^3.1.0" - request: "npm:2.88.2" send: "npm:^0.19.0" sinon: "npm:~9.0.1" sinon-chai: "npm:^3.7.0"