diff --git a/test/large-repository-tree.test.js b/test/large-repository-tree.test.js index 91877ae..07488c6 100644 --- a/test/large-repository-tree.test.js +++ b/test/large-repository-tree.test.js @@ -361,7 +361,9 @@ const uri = process.env.PERFORMANCE_MONGO_URI; expect(saved.githubAccess.revision).not.to.equal("old-access"); expect(saved.anonymizeDate.getTime()).to.be.greaterThan(1); expect(saved.options.terms).to.deep.equal(["after"]); expect(await File.countDocuments({ repoId: row.repoId })).to.equal(0); expect(await Path.countDocuments({ repoId: row.repoId })).to.equal(0); - expect(jobs).to.have.length(1); expect(jobs[0][1]).to.deep.equal({ repoId: row.repoId }); + expect(jobs).to.have.length(1); + const { logJobId, ...jobData } = jobs[0][1]; + expect(jobData).to.deep.equal({ repoId: row.repoId }); expect(logJobId).to.match(/^[a-f0-9-]{36}$/); }); for (const [label, change] of [...changedSnapshots, ["settings revision", { settingsSavedAt: new Date(1) }]] ) { diff --git a/test/performance-integration.test.js b/test/performance-integration.test.js index b71ac06..d0f4b27 100644 --- a/test/performance-integration.test.js +++ b/test/performance-integration.test.js @@ -996,13 +996,14 @@ const uri = process.env.PERFORMANCE_MONGO_URI; const row = await Repo.create({ repoId: "active-staged", status: "ready", statusDate: new Date(), lastView: new Date(), treeGeneration: "old", source: { type: "GitHubStream" }, options: { expirationMode: "never" } }); await File.create({ repoId: row.repoId, treeGeneration: "old", path: "", name: "old.txt" }); - const repo = new Repository(row), updateMany = File.updateMany; + // Completion clears markers through the driver collection (clearStagedRowsInBatches). + const repo = new Repository(row), updateMany = File.collection.updateMany; Object.defineProperty(repo, "source", { get: () => ({ getFiles: async () => [{ path: "", name: "active.txt", size: 1 }] }) }); - File.updateMany = function (filter, ...args) { - if (filter.treeStaged) return { exec: async () => { throw Error("marker cleanup interrupted"); } }; + File.collection.updateMany = function (filter, ...args) { + if (filter.treeStaged) return Promise.reject(Error("marker cleanup interrupted")); return updateMany.call(this, filter, ...args); }; - try { await repo.files({ force: true }); } finally { File.updateMany = updateMany; } + try { await repo.files({ force: true }); } finally { File.collection.updateMany = updateMany; } expect(await File.countDocuments({ treeStaged: true })).to.equal(1); await require("../src/server/schedule").runRepositoryStatusCheck(); expect((await File.find({ repoId: row.repoId })).map(file => file.name)).to.deep.equal(["active.txt"]); diff --git a/test/performance-worker.test.js b/test/performance-worker.test.js index 5f5b8bb..672455e 100644 --- a/test/performance-worker.test.js +++ b/test/performance-worker.test.js @@ -88,7 +88,9 @@ describe("large anonymization resources", function () { maxOutput: 1000000, context: { mask: "XXXX", hostname: "localhost" } }, text.length, controller.signal); } catch (error) { failure = error; } expect(failure).to.be.instanceOf(Error); - expect(failure.message).to.match(/timed out after 1000ms/); + // Workers report fixed codes only; the elapsed bound proves the 1s regex deadline, + // not the 15s pool deadline that reports the same code, stopped the job. + expect(failure.message).to.equal("anonymization_deadline_exceeded"); expect(Date.now() - started).to.be.lessThan(8000); let exists = true; try { await fs.access(output); } catch (error) { if (error.code === "ENOENT") exists = false; else throw error; } diff --git a/test/repository-activity.test.js b/test/repository-activity.test.js index bb8d78d..869e788 100644 --- a/test/repository-activity.test.js +++ b/test/repository-activity.test.js @@ -207,11 +207,13 @@ describe("repository activity dates", () => { }); } } + // FileModel.exists() returns a Mongoose query; production code chains .hint(). + const missingFile = () => Object.assign(Promise.resolve(null), { hint() { return this; } }); it("returns publication and settings dates independently of the older source commit", async () => { const repo = repository(); auth(repo); repo.model.settingsSavedAt = new Date("2026-03-01"); repo.model.publishedAt = new Date("2026-02-01"); - stub(Files, "exists", async () => null); + stub(Files, "exists", missingFile); let body; await handler("repository-public", "/:repoId/options", "get")({}, { header: () => {}, json: value => { body = value; } }); expect(body.lastUpdateDate).to.deep.equal(repo.model.settingsSavedAt); @@ -220,7 +222,7 @@ describe("repository activity dates", () => { }); it("does not invent publication or settings dates for legacy repositories", async () => { const repo = repository(); auth(repo); - stub(Files, "exists", async () => null); + stub(Files, "exists", missingFile); let body; await handler("repository-public", "/:repoId/options", "get")({}, { header: () => {}, json: value => { body = value; } }); expect(body.publishedAt).to.equal(undefined); @@ -232,7 +234,7 @@ describe("repository activity dates", () => { const repo = repository(); auth(repo); repo.model.options.expirationMode = "remove"; repo.model.options.expirationDate = new Date("2099-01-01"); - stub(Files, "exists", async () => null); + stub(Files, "exists", missingFile); let body; await handler("repository-public", "/:repoId/options", "get")({}, { header: () => {}, json: value => { body = value; } }); expect(body.expirationDate).to.deep.equal(new Date("2099-01-01"));