[clsi-cache] check compiler settings before using compile from cache (#24845)

* [web] provide an actual rootFolder from EditorProviders in tests

- Fixup SocketIOMock and ShareJS mocks to provide the complete interface
- Extend SocketIOMock interface to count event listeners
- Fixup test that did not expect to find a working rootDoc

* [web] expose imageName from ProjectContext

* [clsi-cache] check compiler settings before using compile from cache

* [web] avoid fetching initial compile from clsi-cache in PDF detach tab

GitOrigin-RevId: e3c754a7ceca55f03a317e1bc8ae45ed12cc2f02
This commit is contained in:
Jakob Ackermann
2025-04-16 08:05:35 +00:00
committed by Copybot
parent ef958f97a1
commit 39110d9da9
17 changed files with 416 additions and 72 deletions
@@ -43,26 +43,77 @@ const outputFiles = () => {
]
}
const compileFromCacheResponse = () => {
return {
fromCache: true,
status: 'success',
clsiServerId: 'foo',
compileGroup: 'priority',
pdfDownloadDomain: 'https://clsi.test-overleaf.com',
outputFiles: outputFiles(),
options: {
rootResourcePath: 'main.tex',
imageName: 'texlive-full:2024.1',
compiler: 'pdflatex',
stopOnFirstError: false,
draft: false,
},
}
}
export const interceptCompileFromCacheRequest = ({
times,
promise,
}: {
times: number
promise: Promise<void>
}) => {
return cy.intercept(
{ path: '/project/*/output/cached/output.overleaf.json', times },
async req => {
await promise
req.reply({ body: compileFromCacheResponse() })
}
)
}
export const interceptCompileRequest = ({ times = 1 } = {}) => {
return cy.intercept(
{ method: 'POST', pathname: '/project/*/compile', times },
{
body: {
status: 'success',
clsiServerId: 'foo',
compileGroup: 'priority',
pdfDownloadDomain: 'https://clsi.test-overleaf.com',
outputFiles: outputFiles(),
},
}
)
}
export const interceptCompile = ({
prefix = 'compile',
times = 1,
cached = false,
regular = true,
outputPDFFixture = 'output.pdf',
} = {}) => {
if (cached) {
cy.intercept(
{ pathname: '/project/*/output/cached/output.overleaf.json', times },
{
body: {
fromCache: true,
status: 'success',
clsiServerId: 'foo',
compileGroup: 'priority',
pdfDownloadDomain: 'https://clsi.test-overleaf.com',
outputFiles: outputFiles(),
},
}
{ path: '/project/*/output/cached/output.overleaf.json', times },
{ body: compileFromCacheResponse() }
).as(`${prefix}-cached`)
} else {
cy.intercept(
{ pathname: '/project/*/output/cached/output.overleaf.json', times },
{ statusCode: 404 }
).as(`${prefix}-cached`)
}
if (regular) {
interceptCompileRequest({ times }).as(`${prefix}`)
} else {
cy.intercept(
{ method: 'POST', pathname: '/project/*/compile', times },
{
@@ -75,23 +126,6 @@ export const interceptCompile = ({
},
}
).as(`${prefix}`)
} else {
cy.intercept(
{ pathname: '/project/*/output/cached/output.overleaf.json', times },
{ statusCode: 404 }
).as(`${prefix}-cached`)
cy.intercept(
{ method: 'POST', pathname: '/project/*/compile', times },
{
body: {
status: 'success',
clsiServerId: 'foo',
compileGroup: 'priority',
pdfDownloadDomain: 'https://clsi.test-overleaf.com',
outputFiles: outputFiles(),
},
}
).as(`${prefix}`)
}
cy.intercept(
@@ -114,12 +148,22 @@ export const waitForCompile = ({
prefix = 'compile',
pdf = false,
cached = false,
regular = true,
} = {}) => {
if (cached) {
cy.wait(`@${prefix}-cached`)
} else {
}
if (regular) {
cy.wait(`@${prefix}`)
}
return waitForCompileOutput({ prefix, pdf, cached })
}
export const waitForCompileOutput = ({
prefix = 'compile',
pdf = false,
cached = false,
} = {}) => {
cy.wait(`@${prefix}-log`)
.its('request.query.clsiserverid')
.should('eq', cached ? 'cache' : 'foo') // straight from cache if cached
@@ -1,8 +1,10 @@
import '@testing-library/cypress/add-commands'
import {
interceptCompile,
interceptCompileFromCacheRequest,
waitForCompile,
interceptDeferredCompile,
interceptCompileRequest,
} from './compile'
import { interceptEvents } from './events'
import { interceptAsync } from './intercept-async'
@@ -21,6 +23,8 @@ declare global {
interface Chainable {
interceptAsync: typeof interceptAsync
interceptCompile: typeof interceptCompile
interceptCompileRequest: typeof interceptCompileRequest
interceptCompileFromCacheRequest: typeof interceptCompileFromCacheRequest
interceptEvents: typeof interceptEvents
interceptMetadata: typeof interceptMetadata
waitForCompile: typeof waitForCompile
@@ -36,6 +40,11 @@ declare global {
Cypress.Commands.add('interceptAsync', interceptAsync)
Cypress.Commands.add('interceptCompile', interceptCompile)
Cypress.Commands.add('interceptCompileRequest', interceptCompileRequest)
Cypress.Commands.add(
'interceptCompileFromCacheRequest',
interceptCompileFromCacheRequest
)
Cypress.Commands.add('interceptEvents', interceptEvents)
Cypress.Commands.add('interceptMetadata', interceptMetadata)
Cypress.Commands.add('waitForCompile', waitForCompile)