diff --git a/services/clsi/test/acceptance/js/SimpleLatexFileTests.js b/services/clsi/test/acceptance/js/SimpleLatexFileTests.js index 92b64d145b..6be6b196a6 100644 --- a/services/clsi/test/acceptance/js/SimpleLatexFileTests.js +++ b/services/clsi/test/acceptance/js/SimpleLatexFileTests.js @@ -1,6 +1,7 @@ const Client = require('./helpers/Client') const { fetchNothing } = require('@overleaf/fetch-utils') const ClsiApp = require('./helpers/ClsiApp') +const { expect } = require('chai') describe('Simple LaTeX file', function () { const content = `\ @@ -92,4 +93,40 @@ Hello world }) }) } + + describe('document with shell commands', function () { + before(async function () { + this.project_id = Client.randomId() + this.request = { + resources: [ + { + path: 'main.tex', + content: `\ +\\documentclass{article} +\\begin{document} +Testing system calls: +\\immediate\\write18{/bin/date > date.txt} +The current date from system is: \\input{date.txt} +The current date from popen is: \\input{"|date"} +\\end{document}\ +`, + }, + ], + } + await ClsiApp.ensureRunning() + }) + + it('should compile successfully', async function () { + const body = await Client.compile(this.project_id, this.request) + expect(body).to.exist + expect(body.compile?.status, 'compile status').to.equal('success') + }) + + it('should return the PDF', async function () { + const body = await Client.compile(this.project_id, this.request) + const pdf = Client.getOutputFile(body, 'pdf') + expect(pdf, 'pdf file not produced').to.exist + expect(pdf.type, 'invalid pdf file').to.equal('pdf') + }) + }) }) diff --git a/services/clsi/test/acceptance/js/SmokeTest.js b/services/clsi/test/acceptance/js/SmokeTest.js new file mode 100644 index 0000000000..a5cb31da12 --- /dev/null +++ b/services/clsi/test/acceptance/js/SmokeTest.js @@ -0,0 +1,14 @@ +const Client = require('./helpers/Client') +const ClsiApp = require('./helpers/ClsiApp') +const { expect } = require('chai') + +describe('Smoke Test', function () { + before(async function () { + await ClsiApp.ensureRunning() + }) + + it('should compile the test document and return a response of "OK"', async function () { + const response = await Client.smokeTest() + expect(response).to.equal('OK') + }) +}) diff --git a/services/clsi/test/acceptance/js/helpers/Client.js b/services/clsi/test/acceptance/js/helpers/Client.js index 6b8012e983..1b5b1f9b08 100644 --- a/services/clsi/test/acceptance/js/helpers/Client.js +++ b/services/clsi/test/acceptance/js/helpers/Client.js @@ -1,5 +1,9 @@ const express = require('express') -const { fetchJson, fetchNothing } = require('@overleaf/fetch-utils') +const { + fetchJson, + fetchNothing, + fetchString, +} = require('@overleaf/fetch-utils') const fs = require('node:fs') const fsPromises = require('node:fs/promises') const Settings = require('@overleaf/settings') @@ -177,12 +181,19 @@ async function compileDirectory(projectId, baseDirectory, directory) { return await compile(projectId, req) } +function smokeTest() { + return fetchString(`${host}/smoke_test_force`, { + method: 'GET', + }) +} + module.exports = { randomId, compile, stopCompile, clearCache, getOutputFile, + smokeTest, runFakeFilestoreService, startFakeFilestoreApp, syncFromCode, diff --git a/services/clsi/test/smoke/js/SmokeTests.js b/services/clsi/test/smoke/js/SmokeTests.js index 18aa562a0b..4d280690ca 100644 --- a/services/clsi/test/smoke/js/SmokeTests.js +++ b/services/clsi/test/smoke/js/SmokeTests.js @@ -54,6 +54,9 @@ module.exports = { \\documentclass{article} \\usepackage{tikz} \\usetikzlibrary{calc,fadings,decorations.pathreplacing} +\\usepackage{ifplatform} % test shell escape, conditionals to test which platform is being used +\\usepackage{minted} % to test shell commands +\\usepackage{bashful} % to test shell commands \\begin{document} \\begin{tikzpicture} \\def\\nuPi{3.1459265} @@ -79,6 +82,24 @@ module.exports = { } } \\end{tikzpicture} + +% Test minted (shell commands) +\\begin{minted}{python} +x = 1 + 2 +\\end{minted} + +% Test bashful (shell commands) +\\bash[stdout,stderr] +date +\\END + +% Test system +\\immediate\\write18{/bin/date > date.txt} +\\input date.txt + +% Test popen +\\input{"|date"} + \\end{document}\ `, },