import assert from "node:assert/strict";
import { describe, it } from "node:test";
import { readFileSync, readdirSync, statSync } from "node:fs";
import { dirname, extname, join } from "node:path";
import { fileURLToPath } from "node:url";

const __dirname = dirname(fileURLToPath(import.meta.url));
const srcRoot = join(__dirname, "..");

const bannedVisiblePhrases = [
  "lite 模式",
  "当前为内置占位",
  "真实 LLM",
  "当前聊天窗口已就绪",
  "后续在",
  "占位模式",
  "系统会自动生成内部默认工艺",
  "先下载当前仓库类型",
  "导入会生成期初批次",
  "每条明细都会写入库存流水",
  "脑图和组织树共用同一套组织数据",
  "角色用于配置菜单权限",
  "为该人员创建或更新系统账号",
  "新增人员是把基础资料人员挂到当前脑图节点",
  "用于协助其他用户忘记密码",
  "系统会自动保存成新版本",
  "后续小程序报工按",
  "系统会按退货库",
  "理论值只是辅助参考",
  "当前没有可选原材料",
  "每一条明细都会写入库存流水",
  "查看影响范围",
  "点击后系统会锁定当前仓库"
];

function collectSourceFiles(dir) {
  return readdirSync(dir)
    .flatMap((entry) => {
      const fullPath = join(dir, entry);
      const stat = statSync(fullPath);
      if (stat.isDirectory()) {
        return collectSourceFiles(fullPath);
      }
      if (![".vue", ".js"].includes(extname(fullPath)) || fullPath.endsWith(".test.js")) {
        return [];
      }
      return [fullPath];
    });
}

describe("static visible copy audit", () => {
  it("keeps demo-like always-visible helper copy out of the product UI", () => {
    const violations = [];
    for (const filePath of collectSourceFiles(srcRoot)) {
      const source = readFileSync(filePath, "utf8");
      for (const phrase of bannedVisiblePhrases) {
        if (source.includes(phrase)) {
          violations.push(`${filePath.replace(`${srcRoot}/`, "")}: ${phrase}`);
        }
      }
    }

    assert.deepEqual(violations, []);
  });
});
