Просмотр исходного кода

fix caching of minted output files in TL2025 (#31455)

GitOrigin-RevId: b82df4d9c7898332b310fd956c5f002bf5b20e39
Brian Gough 6 месяцев назад
Родитель
Сommit
f3e8601cba

+ 1 - 1
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

+ 3 - 0
services/clsi/test/acceptance/fixtures/examples/minted/checks.json

@@ -0,0 +1,3 @@
+{
+  "mustNotDeleteRegex": "minted"
+}

+ 42 - 1
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 () {