File size: 2,164 Bytes
edaa6b9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env node
/**
 * Phase 7 tests for quran-md plugin v0.2.0 (node:test, no extra deps).
 * Uses QURAN_MD_LOCAL_DIR pointing at a local data repo checkout.
 */
import test from "node:test";
import assert from "node:assert/strict";
import * as fs from "node:fs";
import * as path from "node:path";
import { spawnSync } from "node:child_process";

const DATA_DIR = process.env.QURAN_MD_LOCAL_DIR || path.resolve("../hf-quran-md-data");
const PLUGIN_ROOT = path.resolve(import.meta.dirname, "..");

function runCli(args, env = {}) {
  const dist = path.join(PLUGIN_ROOT, "dist", "index.js");
  if (!fs.existsSync(dist)) {
    return { status: 2, stdout: "", stderr: "dist/index.js missing — run `npm run build`" };
  }
  return spawnSync(process.execPath, [dist, ...args], {
    encoding: "utf-8",
    env: { ...process.env, QURAN_MD_LOCAL_DIR: DATA_DIR, ...env },
    timeout: 30000,
  });
}

test("CLI verse fetch wraps provenance block", () => {
  const r = runCli(["6:74"]);
  assert.equal(r.status, 0, r.stderr);
  const data = JSON.parse(r.stdout);
  assert.equal(data.verse_key, "6:74");
  assert.ok(data._provenance, "provenance block present");
  assert.ok(data._provenance.grounding_rule.includes("verbatim"), "grounding rule stated");
});

test("CLI sources tool prints license manifest with per-source states", () => {
  const r = runCli(["sources"]);
  assert.equal(r.status, 0, r.stderr);
  const data = JSON.parse(r.stdout);
  assert.ok(data.sources.length >= 20);
  const almizan = data.sources.find((s) => s.id === "tafsir_al_mizan");
  assert.equal(almizan.state, "exclude_until_resolved");
  const almizanEn = data.sources.find((s) => s.id === "tafsir_al_mizan_translation_en");
  assert.equal(almizanEn.state, "exclude_entirely");
});

test("compare_traditions includes positions, data_flags and consensus_level", () => {
  const r = runCli(["6:74"]);
  assert.equal(r.status, 0, r.stderr);
  const data = JSON.parse(r.stdout);
  assert.ok(Array.isArray(data.positions));
  const sunniPos = data.positions.find((p) => p.tradition === "sunni");
  assert.equal(sunniPos.verification, "verified");
  assert.ok(sunniPos.consensus_level);
});