mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-12-02 09:03:37 +01:00
test: update tests left stale by logging and metadata changes
- large-repository-tree: queued jobs now carry a logJobId trace id (structured logging); assert it instead of an exact job payload. - repository-activity: FileModel.exists() is chained with .hint() since #951; stub it with a query-like object. - performance-integration: staged markers are cleared through File.collection.updateMany since #951, so the old Model.updateMany stub never injected the interruption. - performance-worker: workers report fixed codes only, so a regex timeout surfaces as anonymization_deadline_exceeded; the elapsed bound still proves the 1s regex deadline applied. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
23384dad92
commit
7bc4475b02
4 files changed
+16
-9
No files matched your search
@@ -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) }]] ) {
|
||||
|
||||
@@ -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"]);
|
||||
|
||||
@@ -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; }
|
||||
|
||||
@@ -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"));
|
||||
|
||||
Reference in new issue
Block a user