import assert from "node:assert/strict";
import { readFile } from "node:fs/promises";
import test from "node:test";

const workflowUrl = new URL(
  "../../../.gitea/workflows/domestic-test.yml",
  import.meta.url,
);
const deployScriptUrl = new URL(
  "../../server/deploy-domestic-test-archive.sh",
  import.meta.url,
);

test("domestic frontend workflow is manual and registry-free", async () => {
  const workflow = await readFile(workflowUrl, "utf8");

  assert.match(workflow, /workflow_dispatch:/);
  assert.doesNotMatch(workflow, /\bpush:/);
  assert.doesNotMatch(workflow, /REGISTRY_IMAGE/);
  assert.match(workflow, /docker save/);
  assert.match(workflow, /DOMESTIC_TEST_SSH_PRIVATE_KEY_B64/);
  assert.match(workflow, /base64 -d/);
});

test("domestic frontend workflow pins the China test API and isolated port", async () => {
  const workflow = await readFile(workflowUrl, "utf8");
  const deployScript = await readFile(deployScriptUrl, "utf8");

  assert.match(workflow, /https:\/\/testapi\.banlv-ai\.com/);
  assert.match(workflow, /wss:\/\/testapi\.banlv-ai\.com\/ws/);
  assert.match(workflow, /9135/);
  assert.match(deployScript, /127\.0\.0\.1:\$HOST_PORT/);
  assert.match(deployScript, /cozsweet-frontend-domestic-test/);
});
