From 51eb94a493ce814a283c871f50c343a555def0e6 Mon Sep 17 00:00:00 2001 From: Brian Gough Date: Tue, 12 Sep 2017 13:00:41 +0100 Subject: [PATCH] handle incremental compile without root doc --- .../app/coffee/Features/Compile/ClsiManager.coffee | 14 +++++++++++--- .../coffee/Compile/ClsiManagerTests.coffee | 13 +++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/services/web/app/coffee/Features/Compile/ClsiManager.coffee b/services/web/app/coffee/Features/Compile/ClsiManager.coffee index 7474341e64..1bd641cced 100755 --- a/services/web/app/coffee/Features/Compile/ClsiManager.coffee +++ b/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() diff --git a/services/web/test/UnitTests/coffee/Compile/ClsiManagerTests.coffee b/services/web/test/UnitTests/coffee/Compile/ClsiManagerTests.coffee index a0a3e3d9cc..20d0a69a87 100644 --- a/services/web/test/UnitTests/coffee/Compile/ClsiManagerTests.coffee +++ b/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) =>