Files
Jyotisha/frontend/tests/consultation-technique-audit.test.ts
T
Jesse_Chen 8010245981
Independent Staging Quality Gate / validate (push) Failing after 6m42s
Independent Staging Quality Gate / publish (push) Has been skipped
feat(product): present consult and rectification in local skill form
Default ayanamsa to Raman with true_pushya support, attach governed Raman packets, restore Path C questionnaires and eight-method verification copy, and keep unique-minute confirmation blocked.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-20 21:42:47 +08:00

114 lines
6.0 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
import test from "node:test";
import { agentExecutionReceiptSchema } from "../src/lib/consultation-agent-events.ts";
import {
displayTechniqueAuditLabel,
displayTechniqueAuditNote,
normalizeTechniqueAuditRows,
resolveTechniqueAuditRows,
splitSpokenAnswerAndTechniqueAudit,
techniqueAuditStatusLabel,
} from "../src/lib/consultation-technique-audit.ts";
const disclosureSource = readFileSync(new URL("../src/components/technique-audit-disclosure.tsx", import.meta.url), "utf8");
const contentSource = readFileSync(new URL("../src/components/chat-message-content.tsx", import.meta.url), "utf8");
const toolsSource = readFileSync(new URL("../src/mastra/consultation-tools.ts", import.meta.url), "utf8");
const routeSource = readFileSync(new URL("../src/app/api/consult/route.ts", import.meta.url), "utf8");
const globalStyles = readFileSync(new URL("../src/app/globals.css", import.meta.url), "utf8");
const spoken = [
"今天适合推进沟通,不适合拍板承诺。",
"",
"| 适合推进 | 需要避开 |",
"|---|---|",
"| 汇报、提案、写作 | 冲动承诺、夸大其词 |",
"",
"给一个现在就能做的行动。",
].join("\n");
const auditTable = [
"| 技法 | 状态 | 说明 |",
"|---|---|---|",
"| VedAstro 云状态 | 阻塞 | 未经核验的官方云证据,置信度封顶 |",
"| 功能吉凶星 | 已执行 | 功能属性与自然属性冲突时降置信 |",
"| 问卦盘(Prashna | 不适用 | 本轮为本命咨询 |",
].join("\n");
test("a complete technique audit table stays in the spoken body and is also parsed for the folded copy", () => {
const full = `${spoken}\n\n${auditTable}`;
const split = splitSpokenAnswerAndTechniqueAudit(full);
assert.equal(split.complete, true);
assert.equal(split.spoken, full);
assert.equal(split.spoken.includes("适合推进"), true);
assert.equal(split.spoken.includes("技法"), true);
assert.deepEqual(split.rows, [
{ technique: "VedAstro 云状态", status: "blocked", note: "未经核验的官方云证据,置信度封顶" },
{ technique: "功能吉凶星", status: "executed", note: "功能属性与自然属性冲突时降置信" },
{ technique: "问卦盘(Prashna", status: "not_applicable", note: "本轮为本命咨询" },
]);
});
test("an incomplete streaming audit table is hidden rather than shown as pipes", () => {
const split = splitSpokenAnswerAndTechniqueAudit(`${spoken}\n\n| 技法 | 状态 | 说明 |\n|---|---|---|\n| VedAstro 云状态 | 阻塞 |`);
assert.equal(split.complete, false);
assert.equal(split.spoken, spoken);
assert.deepEqual(split.rows, []);
});
test("delivered receipt rows fill the folded table when the spoken answer has no dump", () => {
const delivered = normalizeTechniqueAuditRows([
{ technique: "VedAstro Cloud State", status: "blocked", boundary: "confidence_capped_without_verified_official_cloud" },
{ technique: "Formal Vargas D1D60", status: "executed", boundary: "20/20 named traditional charts; remaining D-N are separate" },
{ technique: "Western transits", status: "used", note: "layer_not_materialized" },
]);
assert.deepEqual(delivered, [
{ technique: "VedAstro Cloud State", status: "blocked", note: "confidence_capped_without_verified_official_cloud" },
{ technique: "Formal Vargas D1D60", status: "executed", note: "20/20 named traditional charts; remaining D-N are separate" },
{ technique: "Western transits", status: "executed", note: "layer_not_materialized" },
]);
assert.equal(displayTechniqueAuditLabel("VedAstro Cloud State"), "VedAstro 云状态");
assert.equal(displayTechniqueAuditLabel("Western transits"), "西洋行运");
assert.equal(displayTechniqueAuditNote("confidence_capped_without_verified_official_cloud"), "未经核验的官方云证据,置信度封顶");
assert.equal(displayTechniqueAuditNote("20/20 named traditional charts; remaining D-N are separate"), "20/20 传统命名分盘");
assert.equal(displayTechniqueAuditNote("layer_not_materialized"), "本层未物化");
assert.equal(displayTechniqueAuditNote("unmapped_machine_key"), "");
assert.equal(techniqueAuditStatusLabel("blocked"), "阻塞");
const split = splitSpokenAnswerAndTechniqueAudit(spoken);
assert.deepEqual(resolveTechniqueAuditRows(split, delivered), delivered);
});
test("the public receipt may carry the audit rows and still rejects internal diagnostics", () => {
const receipt = agentExecutionReceiptSchema.parse({
runId: "run",
runtime: "mastra-agentic",
skill: { name: "jyotish-vedic-astrology", loaded: true, referenceReads: 0, methodologySections: 0 },
steps: [{ sequence: 1, kind: "skill", name: "jyotish-vedic-astrology", status: "completed" }],
workflow: { route: "timing", status: "ready", preciseTiming: "allowed", missingLayers: [] },
techniqueAuditTable: [
{ technique: "Narayana Dasha", status: "executed", note: "本轮无独立当前读数" },
],
});
assert.equal(receipt.techniqueAuditTable?.[0]?.technique, "Narayana Dasha");
assert.throws(() => agentExecutionReceiptSchema.parse({
...receipt,
techniqueAuditTable: [{ technique: "Narayana Dasha", status: "used" }],
}));
});
test("the folded audit control stays closed and never remounts the internal panel", () => {
assert.match(disclosureSource, /<details className="technique-audit">/);
assert.doesNotMatch(disclosureSource, /<details[^>]*\sopen/);
assert.doesNotMatch(disclosureSource, /EvidenceAuditPanel/);
assert.doesNotMatch(disclosureSource, /techniqueTruth|workflowReceipt|rawReceipt/);
assert.match(contentSource, /splitSpokenAnswerAndTechniqueAudit/);
assert.match(contentSource, /TechniqueAuditDisclosure/);
assert.match(toolsSource, /ctx\.state\.techniqueAuditTable = normalizeTechniqueAuditRows/);
assert.match(routeSource, /techniqueAuditTable: state\.techniqueAuditTable/);
assert.match(globalStyles, /\.markdown-table/);
assert.match(globalStyles, /\.technique-audit >/);
assert.match(globalStyles, /\.markdown-table th,/);
});