import assert from "node:assert/strict";
import fs from "node:fs";
import path from "node:path";

const root = process.cwd();
const checks = [
  {
    label: "仓库页面",
    file: path.join(root, "src/views/InventoryLedgerView.vue")
  },
  {
    label: "发货台账页面",
    file: path.join(root, "src/views/DeliveryManagementView.vue")
  },
  {
    label: "物流校验服务",
    file: path.join(root, "../backend/app/services/logistics.py")
  },
  {
    label: "仓库照片上传接口",
    file: path.join(root, "../backend/app/api/routes/inventory.py")
  }
];

for (const check of checks) {
  const source = fs.readFileSync(check.file, "utf8");
  assert.doesNotMatch(source, /订单照片/, `${check.label}不应再显示“订单照片”`);
  assert.match(source, /辅助照片/, `${check.label}应显示“辅助照片”`);
}

for (const relativePath of [
  "src",
  "../backend/app"
]) {
  const findCommand = `rg -n "订单照片" ${JSON.stringify(path.join(root, relativePath))} --glob '!dist/**' --glob '!**/node_modules/**'`;
  const { execSync } = await import("node:child_process");
  let output = "";
  try {
    output = execSync(findCommand, { encoding: "utf8" });
  } catch (error) {
    output = error.status === 1 ? "" : String(error.stdout || error.message || "");
  }
  assert.equal(output.trim(), "", `系统源码不应再残留“订单照片”：${output}`);
}

console.log("auxiliary photo label checks passed");
