Merge pull request #26637 from overleaf/bg-clsi-fix-process-group-for-local-compiles

fix "stop compile" option for local command runner in CE/SP

GitOrigin-RevId: 7986b505362aaf33ac6e161b3b54458baba1e2e6
This commit is contained in:
Brian Gough
2025-07-11 08:07:11 +00:00
committed by Copybot
parent 85ecef4d96
commit 2f2862ecd7
5 changed files with 101 additions and 1 deletions
@@ -54,6 +54,7 @@ module.exports = CommandRunner = {
cwd: directory,
env,
stdio: ['pipe', 'pipe', 'ignore'],
detached: true,
})
let stdout = ''
@@ -0,0 +1,47 @@
const Client = require('./helpers/Client')
const ClsiApp = require('./helpers/ClsiApp')
const { expect } = require('chai')
describe('Stop compile', function () {
before(function (done) {
this.request = {
options: {
timeout: 100,
}, // seconds
resources: [
{
path: 'main.tex',
content: `\
\\documentclass{article}
\\begin{document}
\\def\\x{Hello!\\par\\x}
\\x
\\end{document}\
`,
},
],
}
this.project_id = Client.randomId()
ClsiApp.ensureRunning(() => {
// start the compile in the background
Client.compile(this.project_id, this.request, (error, res, body) => {
this.compileResult = { error, res, body }
})
// wait for 1 second before stopping the compile
setTimeout(() => {
Client.stopCompile(this.project_id, (error, res, body) => {
this.stopResult = { error, res, body }
setTimeout(done, 1000) // allow time for the compile request to terminate
})
}, 1000)
})
})
it('should force a compile response with an error status', function () {
expect(this.stopResult.error).to.be.null
expect(this.stopResult.res.statusCode).to.equal(204)
expect(this.compileResult.res.statusCode).to.equal(200)
expect(this.compileResult.body.compile.status).to.equal('terminated')
expect(this.compileResult.body.compile.error).to.equal('terminated')
})
})
@@ -42,6 +42,16 @@ module.exports = Client = {
)
},
stopCompile(projectId, callback) {
if (callback == null) {
callback = function () {}
}
return request.post(
{ url: `${this.host}/project/${projectId}/compile/stop` },
callback
)
},
clearCache(projectId, callback) {
if (callback == null) {
callback = function () {}