import assert from "node:assert/strict";
import { test } from "bun:test";

import { runtimeLaneCicdRepoEnsureScript } from "./cleanup";

test("CI/CD repo cache is materialized for local shared render clones", () => {
  const script = runtimeLaneCicdRepoEnsureScript({
    cicdRepo: "/tmp/hwlab-v03-cicd.git",
    cicdRepoLock: "/tmp/hwlab-v03-cicd-repo.lock",
    gitUrl: "https://github.com/pikasTech/HWLAB.git",
    sourceBranch: "v0.3",
    downloadProfile: {
      git: {
        retries: 2,
        timeoutSeconds: 60,
      },
    },
  } as never);

  assert.doesNotMatch(script, /--filter=blob:none/u);
  assert.doesNotMatch(script, /--depth=1/u);
  assert.match(script, /reason=partial-clone-cache/u);
  assert.match(script, /reason=shallow-clone-cache/u);
  assert.match(script, /\[ -f "\$cicd_repo\/shallow" \]/u);
  assert.match(script, /reason=missing-fetched-tree-object/u);
  assert.match(script, /cat-file -e "refs\/remotes\/origin\/\$cicd_branch\^\{tree\}"/u);
  assert.match(script, /remote\.origin\.promisor/u);
  assert.match(script, /remote\.origin\.partialclonefilter/u);
  assert.match(script, /clone --bare --single-branch/u);
});
