sandboxed-compiles.spec.ts 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. import { ensureUserExists, login } from './helpers/login'
  2. import { createProject } from './helpers/project'
  3. import { isExcludedBySharding, startWith } from './helpers/config'
  4. import { throttledRecompile, stopCompile } from './helpers/compile'
  5. import { v4 as uuid } from 'uuid'
  6. import { waitUntilScrollingFinished } from './helpers/waitUntilScrollingFinished'
  7. import { beforeWithReRunOnTestRetry } from './helpers/beforeWithReRunOnTestRetry'
  8. const LABEL_TEX_LIVE_VERSION = 'TeX Live version'
  9. describe('SandboxedCompiles', function () {
  10. const enabledVars = {
  11. SANDBOXED_COMPILES: 'true',
  12. ALL_TEX_LIVE_DOCKER_IMAGE_NAMES: '2023,2022',
  13. }
  14. describe('enabled in Server Pro', function () {
  15. if (isExcludedBySharding('PRO_CUSTOM_2')) return
  16. startWith({
  17. pro: true,
  18. vars: enabledVars,
  19. resetData: true,
  20. })
  21. ensureUserExists({ email: 'user@example.com' })
  22. beforeEach(function () {
  23. login('user@example.com')
  24. })
  25. it('should offer TexLive images and switch the compiler', function () {
  26. createProject('sandboxed')
  27. const recompile = throttledRecompile()
  28. cy.log('wait for compile')
  29. cy.get('.pdf-viewer').should('contain.text', 'sandboxed')
  30. cy.log('Check which compiler version was used, expect 2023')
  31. cy.get('[aria-label="View logs"]').click()
  32. cy.findByText(/This is pdfTeX, Version .+ \(TeX Live 2023\) /)
  33. cy.log('Switch TeXLive version from 2023 to 2022')
  34. cy.findByRole('navigation', {
  35. name: /Project actions/i,
  36. })
  37. .findByRole('button', { name: /Menu/i })
  38. .click()
  39. cy.findByText(LABEL_TEX_LIVE_VERSION)
  40. .parent()
  41. .findByText('2023')
  42. .parent()
  43. .select('2022')
  44. cy.get('.left-menu-modal-backdrop').click()
  45. cy.log('Trigger compile with other TeX Live version')
  46. recompile()
  47. cy.log('Check which compiler version was used, expect 2022')
  48. cy.get('[aria-label="View logs"]').click()
  49. cy.findByText(/This is pdfTeX, Version .+ \(TeX Live 2022\) /)
  50. })
  51. checkSyncTeX()
  52. checkXeTeX()
  53. checkRecompilesAfterErrors()
  54. checkStopCompile()
  55. })
  56. function checkStopCompile() {
  57. it('users can stop a running compile', function () {
  58. login('user@example.com')
  59. createProject('test-project')
  60. // create an infinite loop in the main document
  61. // this will cause the compile to run indefinitely
  62. cy.findByText('\\maketitle').parent().click()
  63. cy.findByText('\\maketitle')
  64. .parent()
  65. .type('\n\\def\\x{{}Hello!\\par\\x}\\x')
  66. cy.log('Start compile')
  67. // We need to start the compile manually because we do not want to wait for it to finish
  68. cy.findByText('Recompile').click()
  69. // Now stop the compile and kill the latex process
  70. stopCompile({ delay: 1000 })
  71. cy.get('.logs-pane')
  72. .invoke('text')
  73. .should('match', /PDF Rendering Error|Compilation cancelled/)
  74. // Check that the previous compile is not running in the background by
  75. // disabling the infinite loop and recompiling
  76. cy.findByText('\\def').parent().click()
  77. cy.findByText('\\def').parent().type('{home}disabled loop% ')
  78. cy.findByText('Recompile').click()
  79. cy.get('.pdf-viewer').should('contain.text', 'disabled loop')
  80. cy.get('.logs-pane').should(
  81. 'not.contain.text',
  82. 'A previous compile is still running'
  83. )
  84. })
  85. }
  86. function checkSyncTeX() {
  87. describe('SyncTeX', function () {
  88. let projectName: string
  89. beforeEach(function () {
  90. projectName = `Project ${uuid()}`
  91. createProject(projectName)
  92. const recompile = throttledRecompile()
  93. cy.findByText('\\maketitle').parent().click()
  94. cy.findByText('\\maketitle')
  95. .parent()
  96. .type(
  97. `\n\\pagebreak\n\\section{{}Section A}\n\\pagebreak\n\\section{{}Section B}\n\\pagebreak`
  98. )
  99. recompile()
  100. cy.log('wait for pdf-rendering')
  101. cy.get('.pdf-viewer').within(() => {
  102. cy.findByText(projectName)
  103. })
  104. })
  105. it('should sync to code', function () {
  106. cy.log('navigate to \\maketitle using double click in PDF')
  107. cy.get('.pdf-viewer').within(() => {
  108. cy.findByText(projectName).dblclick()
  109. })
  110. cy.get('.cm-activeLine').should('have.text', '\\maketitle')
  111. cy.log('navigate to Section A using double click in PDF')
  112. cy.get('.pdf-viewer').within(() => {
  113. cy.findByText('Section A').dblclick()
  114. })
  115. cy.get('.cm-activeLine').should('have.text', '\\section{Section A}')
  116. cy.log('navigate to Section B using arrow button')
  117. cy.get('.pdfjs-viewer-inner')
  118. .should('have.prop', 'scrollTop')
  119. .as('start')
  120. cy.get('.pdf-viewer').within(() => {
  121. cy.findByText('Section B').scrollIntoView()
  122. })
  123. cy.get('@start').then((start: any) => {
  124. waitUntilScrollingFinished('.pdfjs-viewer-inner', start)
  125. })
  126. // The sync button is swapped as the position in the PDF changes.
  127. // Cypress appears to click on a button that references a stale position.
  128. // Adding a cy.wait() statement is the most reliable "fix" so far :/
  129. cy.wait(1000)
  130. cy.get('[aria-label^="Go to PDF location in code"]').click()
  131. cy.get('.cm-activeLine').should('have.text', '\\section{Section B}')
  132. })
  133. it('should sync to pdf', function () {
  134. cy.log('zoom in')
  135. cy.findByText('45%').click()
  136. cy.findByText('400%').click()
  137. cy.log('scroll to top')
  138. cy.get('.pdfjs-viewer-inner').scrollTo('top')
  139. waitUntilScrollingFinished('.pdfjs-viewer-inner', -1).as('start')
  140. cy.log('navigate to title')
  141. cy.findByText('\\maketitle').parent().click()
  142. cy.get('[aria-label="Go to code location in PDF"]').click()
  143. cy.get('@start').then((start: any) => {
  144. waitUntilScrollingFinished('.pdfjs-viewer-inner', start)
  145. .as('title')
  146. .should('be.greaterThan', start)
  147. })
  148. cy.log('navigate to Section A')
  149. cy.findByRole('textbox', { name: /Source Editor editing/i }).within(
  150. () => cy.findByText('Section A').click()
  151. )
  152. cy.get('[aria-label="Go to code location in PDF"]').click()
  153. cy.get('@title').then((title: any) => {
  154. waitUntilScrollingFinished('.pdfjs-viewer-inner', title)
  155. .as('sectionA')
  156. .should('be.greaterThan', title)
  157. })
  158. cy.log('navigate to Section B')
  159. cy.findByRole('textbox', { name: /Source Editor editing/i }).within(
  160. () => cy.findByText('Section B').click()
  161. )
  162. cy.get('[aria-label="Go to code location in PDF"]').click()
  163. cy.get('@sectionA').then((title: any) => {
  164. waitUntilScrollingFinished('.pdfjs-viewer-inner', title)
  165. .as('sectionB')
  166. .should('be.greaterThan', title)
  167. })
  168. })
  169. })
  170. }
  171. function checkRecompilesAfterErrors() {
  172. it('recompiles even if there are Latex errors', function () {
  173. login('user@example.com')
  174. createProject('test-project')
  175. const recompile = throttledRecompile()
  176. cy.findByText('\\maketitle').parent().click()
  177. cy.findByText('\\maketitle')
  178. .parent()
  179. .type('\n\\fakeCommand{} \n\\section{{}Test Section}')
  180. recompile()
  181. recompile()
  182. cy.get('.pdf-viewer').should('contain.text', 'Test Section')
  183. cy.get('.logs-pane').should('not.contain.text', 'No PDF')
  184. })
  185. }
  186. function checkXeTeX() {
  187. it('should be able to use XeLaTeX', function () {
  188. createProject('XeLaTeX')
  189. const recompile = throttledRecompile()
  190. cy.log('wait for compile')
  191. cy.get('.pdf-viewer').should('contain.text', 'XeLaTeX')
  192. cy.log('Check which compiler was used, expect pdfLaTeX')
  193. cy.get('[aria-label="View logs"]').click()
  194. cy.findByText(/This is pdfTeX/)
  195. cy.log('Switch compiler to from pdfLaTeX to XeLaTeX')
  196. cy.findByRole('navigation', {
  197. name: /Project actions/i,
  198. })
  199. .findByRole('button', { name: /Menu/i })
  200. .click()
  201. cy.findByText('Compiler')
  202. .parent()
  203. .findByText('pdfLaTeX')
  204. .parent()
  205. .select('XeLaTeX')
  206. cy.get('.left-menu-modal-backdrop').click()
  207. cy.log('Trigger compile with other compiler')
  208. recompile()
  209. cy.log('Check which compiler was used, expect XeLaTeX')
  210. cy.get('[aria-label="View logs"]').click()
  211. cy.findByText(/This is XeTeX/)
  212. })
  213. }
  214. function checkUsesDefaultCompiler() {
  215. beforeEach(function () {
  216. login('user@example.com')
  217. })
  218. it('should not offer TexLive images and use default compiler', function () {
  219. createProject('sandboxed')
  220. cy.log('wait for compile')
  221. cy.get('.pdf-viewer').should('contain.text', 'sandboxed')
  222. cy.log('Check which compiler version was used, expect 2025')
  223. cy.get('[aria-label="View logs"]').click()
  224. cy.findByText(/This is pdfTeX, Version .+ \(TeX Live 2025\) /)
  225. cy.log('Check that there is no TeX Live version toggle')
  226. cy.findByRole('navigation', {
  227. name: /Project actions/i,
  228. })
  229. .findByRole('button', { name: /Menu/i })
  230. .click()
  231. cy.findByText('Word Count') // wait for lazy loading
  232. cy.findByText(LABEL_TEX_LIVE_VERSION).should('not.exist')
  233. })
  234. }
  235. describe('disabled in Server Pro', function () {
  236. if (isExcludedBySharding('PRO_DEFAULT_2')) return
  237. startWith({ pro: true })
  238. ensureUserExists({ email: 'user@example.com' })
  239. beforeEach(function () {
  240. login('user@example.com')
  241. })
  242. checkUsesDefaultCompiler()
  243. checkSyncTeX()
  244. checkXeTeX()
  245. checkRecompilesAfterErrors()
  246. checkStopCompile()
  247. })
  248. // https://github.com/overleaf/internal/issues/20216
  249. describe.skip('unavailable in CE', function () {
  250. if (isExcludedBySharding('CE_CUSTOM_1')) return
  251. startWith({ pro: false, vars: enabledVars, resetData: true })
  252. ensureUserExists({ email: 'user@example.com' })
  253. beforeEach(function () {
  254. login('user@example.com')
  255. })
  256. checkUsesDefaultCompiler()
  257. checkSyncTeX()
  258. checkXeTeX()
  259. checkRecompilesAfterErrors()
  260. checkStopCompile()
  261. })
  262. })