mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-06-02 13:49:00 +02:00
b831a0b3f7
* [clsi-lb] forward ?clsiserverid=cache requests to clsi-cache * [web] use clsi-cache in frontend * [web] upgrade compile from cache to full compile when triggered inflight * [web] fix pdf-js-viewer.spec.tsx tests -- add ?clsiserverid=foo to url * [web] fix renamed reference after merge * [web] fix download of other output files and use specific build * [web] consolidate validation of filename into ClsiCacheHandler * [web] remove unused projectName from getLatestBuildFromCache * [web] avoid hitting the same clsi-cache instance first all the time * [web] update documentation GitOrigin-RevId: d48265a7ba89d6731092640e1492bc9f103f5c33
200 lines
4.7 KiB
TypeScript
200 lines
4.7 KiB
TypeScript
import { v4 as uuid } from 'uuid'
|
|
|
|
const outputFiles = () => {
|
|
const build = uuid()
|
|
|
|
return [
|
|
{
|
|
path: 'output.pdf',
|
|
build,
|
|
url: `/build/${build}/output.pdf`,
|
|
type: 'pdf',
|
|
},
|
|
{
|
|
path: 'output.bbl',
|
|
build,
|
|
url: `/build/${build}/output.bbl`,
|
|
type: 'bbl',
|
|
},
|
|
{
|
|
path: 'output.bib',
|
|
build,
|
|
url: `/build/${build}/output.bib`,
|
|
type: 'bib',
|
|
},
|
|
{
|
|
path: 'example.txt',
|
|
build,
|
|
url: `/build/${build}/example.txt`,
|
|
type: 'txt',
|
|
},
|
|
{
|
|
path: 'output.log',
|
|
build,
|
|
url: `/build/${build}/output.log`,
|
|
type: 'log',
|
|
},
|
|
{
|
|
path: 'output.blg',
|
|
build,
|
|
url: `/build/${build}/output.blg`,
|
|
type: 'blg',
|
|
},
|
|
]
|
|
}
|
|
|
|
export const interceptCompile = ({
|
|
prefix = 'compile',
|
|
times = 1,
|
|
cached = false,
|
|
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(),
|
|
},
|
|
}
|
|
).as(`${prefix}-cached`)
|
|
cy.intercept(
|
|
{ method: 'POST', pathname: '/project/*/compile', times },
|
|
{
|
|
body: {
|
|
status: 'unavailable',
|
|
clsiServerId: 'foo',
|
|
compileGroup: 'priority',
|
|
pdfDownloadDomain: 'https://clsi.test-overleaf.com',
|
|
outputFiles: [],
|
|
},
|
|
}
|
|
).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(
|
|
{ pathname: '/build/*/output.pdf', times },
|
|
{ fixture: `build/${outputPDFFixture},null` }
|
|
).as(`${prefix}-pdf`)
|
|
|
|
cy.intercept(
|
|
{ pathname: '/build/*/output.log', times },
|
|
{ fixture: 'build/output.log' }
|
|
).as(`${prefix}-log`)
|
|
|
|
cy.intercept(
|
|
{ pathname: '/build/*/output.blg', times },
|
|
{ fixture: 'build/output.blg' }
|
|
).as(`${prefix}-blg`)
|
|
}
|
|
|
|
export const waitForCompile = ({
|
|
prefix = 'compile',
|
|
pdf = false,
|
|
cached = false,
|
|
} = {}) => {
|
|
if (cached) {
|
|
cy.wait(`@${prefix}-cached`)
|
|
} else {
|
|
cy.wait(`@${prefix}`)
|
|
}
|
|
cy.wait(`@${prefix}-log`)
|
|
.its('request.query.clsiserverid')
|
|
.should('eq', cached ? 'cache' : 'foo') // straight from cache if cached
|
|
cy.wait(`@${prefix}-blg`)
|
|
.its('request.query.clsiserverid')
|
|
.should('eq', cached ? 'cache' : 'foo') // straight from cache if cached
|
|
if (pdf) {
|
|
cy.wait(`@${prefix}-pdf`)
|
|
.its('request.query.clsiserverid')
|
|
.should('eq', 'foo') // always from VM first
|
|
}
|
|
return cy.wrap(null)
|
|
}
|
|
|
|
export const interceptDeferredCompile = (beforeResponse?: () => void) => {
|
|
const { promise, resolve } = Promise.withResolvers<void>()
|
|
|
|
cy.intercept(
|
|
{ method: 'POST', url: '/project/*/compile*', times: 1 },
|
|
req => {
|
|
if (beforeResponse) {
|
|
beforeResponse()
|
|
}
|
|
|
|
// only reply once the Promise is resolved
|
|
promise.then(() => {
|
|
req.reply({
|
|
body: {
|
|
status: 'success',
|
|
clsiServerId: 'foo',
|
|
compileGroup: 'priority',
|
|
pdfDownloadDomain: 'https://clsi.test-overleaf.com',
|
|
outputFiles: [
|
|
{
|
|
path: 'output.pdf',
|
|
build: '123',
|
|
url: '/build/123/output.pdf',
|
|
type: 'pdf',
|
|
},
|
|
{
|
|
path: 'output.log',
|
|
build: '123',
|
|
url: '/build/123/output.log',
|
|
type: 'log',
|
|
},
|
|
{
|
|
path: 'output.blg',
|
|
build: '123',
|
|
url: '/build/123/output.blg',
|
|
type: 'log',
|
|
},
|
|
],
|
|
},
|
|
})
|
|
})
|
|
|
|
return promise
|
|
}
|
|
).as('compile')
|
|
|
|
cy.intercept(
|
|
{ pathname: '/build/*/output.pdf', times: 1 },
|
|
{ fixture: 'build/output.pdf,null' }
|
|
).as(`compile-pdf`)
|
|
|
|
cy.intercept(
|
|
{ pathname: '/build/*/output.log', times: 1 },
|
|
{ fixture: 'build/output.log' }
|
|
).as(`compile-log`)
|
|
|
|
cy.intercept(
|
|
{ pathname: '/build/*/output.blg', times: 1 },
|
|
{ fixture: 'build/output.blg' }
|
|
).as(`compile-blg`)
|
|
|
|
return cy.wrap(resolve)
|
|
}
|