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

Merge pull request #604 from sharelatex/bg-fix-root-doc-in-incremental-compile

fix root doc in incremental compile
Brian Gough 9 лет назад
Родитель
Сommit
28a80cf23d

+ 11 - 3
services/web/app/coffee/Features/Compile/ClsiManager.coffee

@@ -173,6 +173,13 @@ module.exports = ClsiManager =
 				options = _.clone(options)
 				options.syncType = "incremental"
 				options.syncState = projectStateHash
+				# create stub doc entries for any possible root docs, if not
+				# present in the docupdater. This allows finaliseRequest to
+				# identify the root doc.
+				possibleRootDocIds = [options.rootDoc_id, project.rootDoc_id]
+				for rootDoc_id in possibleRootDocIds when rootDoc_id?
+					path = docPath[rootDoc_id]
+					docs[path] ?= {_id: rootDoc_id, path: path}
 				ClsiManager._finaliseRequest project_id, options, project, docs, [], callback
 
 	_buildRequestFromMongo: (project_id, options, project, projectStateHash, callback = (error, request) ->) ->
@@ -199,9 +206,10 @@ module.exports = ClsiManager =
 
 		for path, doc of docs
 			path = path.replace(/^\//, "") # Remove leading /
-			resources.push
-				path:    path
-				content: doc.lines.join("\n")
+			if doc.lines? # add doc to resources unless it is just a stub entry
+				resources.push
+					path:    path
+					content: doc.lines.join("\n")
 			if project.rootDoc_id? and doc._id.toString() == project.rootDoc_id.toString()
 				rootResourcePath = path
 			if options.rootDoc_id? and doc._id.toString() == options.rootDoc_id.toString()

+ 13 - 0
services/web/test/UnitTests/coffee/Compile/ClsiManagerTests.coffee

@@ -273,6 +273,19 @@ describe "ClsiManager", ->
 						}]
 				)
 
+
+			describe "when the root doc is set and not in the docupdater", ->
+				beforeEach (done) ->
+					@ClsiStateManager.computeHash = sinon.stub().callsArgWith(2, null, @project_state_hash = "01234567890abcdef")
+					@DocumentUpdaterHandler.getProjectDocsIfMatch = sinon.stub().callsArgWith(2, null, [{_id:@doc_1._id, lines:  @doc_1.lines, v: 123}])
+					@ProjectEntityHandler.getAllDocPathsFromProject = sinon.stub().callsArgWith(1, null, {"mock-doc-id-1":"main.tex", "mock-doc-id-2":"/chapters/chapter1.tex"})
+					@ClsiManager._buildRequest @project_id, {timeout:100, incrementalCompilesEnabled:true, rootDoc_id:"mock-doc-id-2"}, (error, request) =>
+						@request = request
+						done()
+
+				it "should still change the root path", ->
+					@request.compile.rootResourcePath.should.equal "chapters/chapter1.tex"
+
 		describe "when root doc override is valid", ->
 			beforeEach (done) ->
 				@ClsiManager._buildRequest @project_id, {rootDoc_id:"mock-doc-id-2"}, (error, request) =>