126 lines · 5.8 KB
import { describe, expect, mock, test } from "bun:test";
import { Database } from "bun:sqlite";

const ran: string[] = [];
mock.module("../ci/cache-api", () => ({
  ABANDONED_RESERVATION_MS: 3_600_000,
  IDLE_EVICTION_MS: 604_800_000,
  evictIdleCachesForRepo: async () => void ran.push("caches"),
}));
mock.module("../ci/job-token", () => ({
  JOB_TOKEN_MARKER_TTL_MS: 86_400_000,
  purgeExpiredJobTokensForRepo: async () => void ran.push("job-tokens"),
}));
mock.module("../ci/runner-api", () => ({
  STALE_RUNNER_MS: 180_000,
  reapStaleRunnerJobsForRepo: async () => void ran.push("stale-runner-jobs"),
}));
mock.module("../ci/workflow-index", () => ({
  fireDueSchedulesForRepo: async () => {
    ran.push("schedules");
    throw new Error("boom");
  },
}));
mock.module("../attachments", () => ({
  ATTACHMENT_ORPHAN_GRACE_MS: 604_800_000,
  sweepOrphanedAttachmentsForRepo: async () => void ran.push("attachments"),
}));
mock.module("../git/pull-bridge", () => ({
  MAX_CLEANUP_ATTEMPTS: 12,
  UNSWEPT_CLOSED_PULLS: "i.state = 'closed' AND p.repo_id != p.head_repo_id AND p.refs_swept_at IS NULL",
  dropHiddenRefsForRepo: async () => void ran.push("hidden-refs"),
  sweepClosedPullRefsForRepo: async () => void ran.push("closed-pull-refs"),
}));
mock.module("../integrations/retention", () => ({ WEBHOOK_DELIVERY_RETENTION_MS: 2_592_000_000 }));
mock.module("../activity-index", () => ({ indexActivity: async () => void ran.push("activity-index") }));
mock.module("../metering/scope-gauges", () => ({ publishScopeGauges: async () => void ran.push("gauges") }));
mock.module("../sites/metering", () => ({
  ROLLUP_GRACE_MS: 600_000,
  rollupScopeSiteUsage: async () => void ran.push("site-usage-rollup"),
}));