From f3e8601cbac458de0517934c61e0b28bdfdbbc32 Mon Sep 17 00:00:00 2001 From: Brian Gough Date: Tue, 10 Feb 2026 11:59:34 +0000 Subject: [PATCH] fix caching of minted output files in TL2025 (#31455) GitOrigin-RevId: b82df4d9c7898332b310fd956c5f002bf5b20e39 --- services/clsi/app/js/ResourceWriter.js | 2 +- .../fixtures/examples/minted/checks.json | 3 ++ .../acceptance/js/ExampleDocumentTests.js | 43 ++++++++++++++++++- 3 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 services/clsi/test/acceptance/fixtures/examples/minted/checks.json diff --git a/services/clsi/app/js/ResourceWriter.js b/services/clsi/app/js/ResourceWriter.js index dc74e9f024..61cab57625 100644 --- a/services/clsi/app/js/ResourceWriter.js +++ b/services/clsi/app/js/ResourceWriter.js @@ -252,7 +252,7 @@ export default ResourceWriter = { } if ( path.match(/\.(pygtex|pygstyle)$/) || - path.match(/(^|\/)_minted-[^\/]+\//) + path.match(/(^|\/)_minted(-[^\/]+)?\//) ) { // minted files/directory shouldDelete = false diff --git a/services/clsi/test/acceptance/fixtures/examples/minted/checks.json b/services/clsi/test/acceptance/fixtures/examples/minted/checks.json new file mode 100644 index 0000000000..cdf6ddfcb5 --- /dev/null +++ b/services/clsi/test/acceptance/fixtures/examples/minted/checks.json @@ -0,0 +1,3 @@ +{ + "mustNotDeleteRegex": "minted" +} diff --git a/services/clsi/test/acceptance/js/ExampleDocumentTests.js b/services/clsi/test/acceptance/js/ExampleDocumentTests.js index 192f8fa903..57a86f67c8 100644 --- a/services/clsi/test/acceptance/js/ExampleDocumentTests.js +++ b/services/clsi/test/acceptance/js/ExampleDocumentTests.js @@ -8,6 +8,9 @@ import { promisify } from 'node:util' import ClsiApp from './helpers/ClsiApp.js' import Path from 'node:path' import process from 'node:process' +import ResourceWriter from '../../../app/js/ResourceWriter.js' +import { expect } from 'chai' + const fixturePath = path => { if (path.slice(0, 3) === 'tmp') { return '/tmp/clsi_acceptance_tests' + path.slice(3) @@ -154,9 +157,26 @@ describe('Example Documents', function () { describe(exampleDir, function () { before(function () { this.project_id = Client.randomId() + '_' + exampleDir + this.outputFiles = [] + // Allow each test to provide a configuration file + const checksJsonPath = fixturePath( + Path.join('examples', exampleDir, 'checks.json') + ) + this.checks = {} + const stats = fs.statSync(checksJsonPath, { throwIfNoEntry: false }) + if (stats && stats.isFile()) { + const rawChecks = fs.readFileSync(checksJsonPath, 'utf8') + try { + this.checks = JSON.parse(rawChecks) + } catch (err) { + throw new Error( + `Failed to parse checks.json for example "${exampleDir}" at path "${checksJsonPath}": ${err.message}` + ) + } + } }) - it('should generate the correct pdf', async function () { + it('should generate the correct pdf and output files', async function () { this.timeout(MOCHA_LATEX_TIMEOUT) const body = await Client.compileDirectory( this.project_id, @@ -169,6 +189,27 @@ describe('Example Documents', function () { } const pdf = Client.getOutputFile(body, 'pdf') await downloadAndComparePdf(this.project_id, exampleDir, pdf.url) + + // pass the output files on to subsequent tests + this.outputFiles = body.compile.outputFiles + + if (this.checks.mustNotDeleteRegex) { + const mustNotDeleteRegex = new RegExp( + this.checks.mustNotDeleteRegex + ) + // On subsequent compiles the isExtraneousFile method is used + // to remove unwanted files - this check ensures that we don't + // remove any files that should be kept (e.g. cache files) + const filesToBeRemoved = this.outputFiles.filter(file => + ResourceWriter.isExtraneousFile(file.path) + ) + for (const file of filesToBeRemoved) { + expect( + file.path, + 'should not remove any files that must be cached' + ).to.not.match(mustNotDeleteRegex) + } + } }) it('should generate the correct pdf on the second run as well', async function () {