"use strict";
const assert = require("node:assert/strict");
const fs = require("node:fs");
const path = require("node:path");
const test = require("node:test");

const root = path.resolve(__dirname, "../..");
const read = relative => fs.readFileSync(path.join(root, relative), "utf8");

test("canonical AI and persona entry files route to the domestic map", () => {
  for (const relative of [
    "README.md", "INDEX.hdlp", "QUICKSTART-FOR-GENERAL-AI.md",
    "eternal-lake-heart/heartbeat-core/ZHUYUAN-KEY.hdlp",
    "zero-point/core-channel/GLSV-PERSONA-REMOTE-OPS.hdlp",
  ]) {
    assert.match(read(relative), /guanghulab\.com|LL-DOMESTIC-OPS-ROUTE/);
  }
  const key = read("eternal-lake-heart/heartbeat-core/ZHUYUAN-KEY.hdlp");
  assert.doesNotMatch(key, /zy_gtw_|guanghubingshuo\.com/);
  assert.match(key, /禁止从本路径恢复.*\/exec/);
});

test("code map resolves REPO-001 to domestic and labels the Singapore route legacy", () => {
  const codeMap = read(".code-map");
  assert.match(codeMap, /^REPO-001=https:\/\/guanghulab\.com\/fifth-domain\/bingshuo\/fifth-domain\.git$/m);
  assert.match(codeMap, /^REPO-001-LEGACY-SG=/m);
  assert.match(codeMap, /^FD-REPO-MAP-001=routing\/repository-route-map\.json$/m);
});
