From b3aad9d80f1a78fa9236eb664abb00afb57d6ea9 Mon Sep 17 00:00:00 2001 From: Arunavo Ray Date: Thu, 16 Jul 2026 21:35:56 +0530 Subject: [PATCH] test: make org ids order-independent in bulk-mirror destination tests The previous call-order counter diverged between the mocked flow and the assertions when bun re-instantiates mock factories (green on bun 1.3.6 locally, red on 1.3.13 in CI). Ids are now a pure function of the org name. --- src/lib/gitea-org-mirror-destination.test.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/lib/gitea-org-mirror-destination.test.ts b/src/lib/gitea-org-mirror-destination.test.ts index 2679cef..3dd40f7 100644 --- a/src/lib/gitea-org-mirror-destination.test.ts +++ b/src/lib/gitea-org-mirror-destination.test.ts @@ -27,11 +27,13 @@ let httpPostCalls: Array<{ url: string; payload: any }> = []; /** Every org get-or-create: orgName -> deterministic id. */ let orgCreateCalls: string[] = []; -const ORG_IDS: Record = {}; -let nextOrgId = 100; +// Deterministic id derived purely from the name — must not depend on call +// order: bun may re-instantiate mock factories, so an order-dependent counter +// can diverge between the mocked flow and the test's assertions. function orgIdFor(name: string): number { - if (!(name in ORG_IDS)) ORG_IDS[name] = nextOrgId++; - return ORG_IDS[name]; + let h = 0; + for (const c of name) h = (h * 31 + c.charCodeAt(0)) % 100_000; + return 100 + h; } // ---------------------------------------------------------------------------