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

Merge pull request #252 from overleaf/jpa-flag-empty-outout-pdf

[CompileController] emit status=failure for an empty output.pdf file
Jakob Ackermann 5 лет назад
Родитель
Сommit
7e88b4f746

+ 3 - 13
services/clsi/app/js/CompileController.js

@@ -88,7 +88,7 @@ module.exports = CompileController = {
               let file
               status = 'failure'
               for (file of Array.from(outputFiles)) {
-                if (file.path === 'output.pdf') {
+                if (file.path === 'output.pdf' && file.size > 0) {
                   status = 'success'
                 }
               }
@@ -123,7 +123,7 @@ module.exports = CompileController = {
                 stats,
                 timings,
                 outputFiles: outputFiles.map((file) => {
-                  const record = {
+                  return {
                     url:
                       `${Settings.apis.clsi.url}/project/${request.project_id}` +
                       (request.user_id != null
@@ -131,18 +131,8 @@ module.exports = CompileController = {
                         : '') +
                       (file.build != null ? `/build/${file.build}` : '') +
                       `/output/${file.path}`,
-                    path: file.path,
-                    type: file.type,
-                    build: file.build,
-                    contentId: file.contentId
+                    ...file
                   }
-                  if (file.ranges != null) {
-                    record.ranges = file.ranges
-                  }
-                  if (file.size != null) {
-                    record.size = file.size
-                  }
-                  return record
                 })
               }
             })

+ 45 - 10
services/clsi/test/unit/js/CompileControllerTests.js

@@ -99,6 +99,7 @@ describe('CompileController', function () {
         {
           path: 'output.pdf',
           type: 'pdf',
+          size: 1337,
           build: 1234
         },
         {
@@ -157,11 +158,7 @@ describe('CompileController', function () {
               outputFiles: this.output_files.map((file) => {
                 return {
                   url: `${this.Settings.apis.clsi.url}/project/${this.project_id}/build/${file.build}/output/${file.path}`,
-                  path: file.path,
-                  type: file.type,
-                  build: file.build,
-                  // gets dropped by JSON.stringify
-                  contentId: undefined
+                  ...file
                 }
               })
             }
@@ -202,11 +199,49 @@ describe('CompileController', function () {
               outputFiles: this.output_files.map((file) => {
                 return {
                   url: `${this.Settings.apis.clsi.url}/project/${this.project_id}/build/${file.build}/output/${file.path}`,
-                  path: file.path,
-                  type: file.type,
-                  build: file.build,
-                  // gets dropped by JSON.stringify
-                  contentId: undefined
+                  ...file
+                }
+              })
+            }
+          })
+          .should.equal(true)
+      })
+    })
+
+    describe('with an empty output.pdf', function () {
+      beforeEach(function () {
+        this.output_files = [
+          {
+            path: 'output.pdf',
+            type: 'pdf',
+            size: 0,
+            build: 1234
+          },
+          {
+            path: 'output.log',
+            type: 'log',
+            build: 1234
+          }
+        ]
+        this.CompileManager.doCompileWithLock = sinon
+          .stub()
+          .yields(null, this.output_files, this.stats, this.timings)
+        this.CompileController.compile(this.req, this.res)
+      })
+
+      it('should return the JSON response with status failure', function () {
+        this.res.status.calledWith(200).should.equal(true)
+        this.res.send
+          .calledWith({
+            compile: {
+              status: 'failure',
+              error: null,
+              stats: this.stats,
+              timings: this.timings,
+              outputFiles: this.output_files.map((file) => {
+                return {
+                  url: `${this.Settings.apis.clsi.url}/project/${this.project_id}/build/${file.build}/output/${file.path}`,
+                  ...file
                 }
               })
             }