import { describe, expect, it, vi } from "vitest";
import {
  humanPacingDelayMs,
  RPA_HUMAN_PACING_MAX_MS,
  RPA_HUMAN_PACING_MIN_MS,
} from "@/lib/rpa/human-pacing";

describe("human-pacing", () => {
  it("默认延迟在 100~300ms", () => {
    vi.stubEnv("RPA_HUMAN_PACING", "");
    for (let i = 0; i < 20; i += 1) {
      const ms = humanPacingDelayMs();
      expect(ms).toBeGreaterThanOrEqual(RPA_HUMAN_PACING_MIN_MS);
      expect(ms).toBeLessThanOrEqual(RPA_HUMAN_PACING_MAX_MS);
    }
    vi.unstubAllEnvs();
  });

  it("RPA_HUMAN_PACING=false 时返回 0", () => {
    vi.stubEnv("RPA_HUMAN_PACING", "false");
    expect(humanPacingDelayMs()).toBe(0);
    vi.unstubAllEnvs();
  });
});
