File
Blob: test/util/test-indexer.ts
| 1 | /** |
| 2 | * Test helper: indexes a pack file using the streaming indexer. |
| 3 | * |
| 4 | * Replaces the legacy `indexPackOnly` (isomorphic-git) for test seeders. |
| 5 | * Uses a no-op limiter and a minimal logger since tests run in miniflare |
| 6 | * with no real concurrency or subrequest limits. |
| 7 | */ |
| 8 | import { scanPack, resolveDeltasAndWriteIdx } from "@/worker/git/pack/indexer"; |
| 9 | import { createLogger } from "@/worker/common/logger"; |
| 10 | import type { Limiter } from "@/worker/git/operations/limits"; |
| 11 | import type { ResolveResult } from "@/worker/git/pack/indexer/types"; |
| 12 | import type { PackCatalogRow } from "@/worker/do/repo/db/schema"; |
| 13 | |
| 14 | const noopLimiter: Limiter = { run: (_label, fn) => fn() }; |
| 15 | const testLog = createLogger(undefined, { service: "test-seed" }); |
| 16 | |
| 17 | /** |
| 18 | * Index a pack that is already uploaded to R2. |
| 19 | * |
| 20 | * Produces a `.idx` file in R2 and returns the resolve result containing |
| 21 | * `objectCount` and `idxBytes` needed for `pack_catalog` row insertion. |
| 22 | * |
| 23 | * Pass `activeCatalog` when the pack contains REF_DELTA objects whose bases |
| 24 | * live in previously indexed packs. |
| 25 | */ |
| 26 | export async function indexTestPack( |
| 27 | env: Env, |
| 28 | packKey: string, |
| 29 | packSize: number, |
| 30 | activeCatalog?: PackCatalogRow[] |
| 31 | ): Promise<ResolveResult> { |
| 32 | const scanResult = await scanPack({ |
| 33 | env, |
| 34 | packKey, |
| 35 | packSize, |
| 36 | limiter: noopLimiter, |
| 37 | countSubrequest: () => {}, |
| 38 | log: testLog, |
| 39 | }); |
| 40 | return await resolveDeltasAndWriteIdx({ |
| 41 | env, |
| 42 | packKey, |
| 43 | packSize, |
| 44 | limiter: noopLimiter, |
| 45 | countSubrequest: () => {}, |
| 46 | log: testLog, |
| 47 | scanResult, |
| 48 | repoId: "test", |
| 49 | activeCatalog, |
| 50 | }); |
| 51 | } |