Files
Jyotisha/frontend/tests/personal-report-agent-telemetry.test.ts
T
Jesse_Chen ef1bd6dfa9 feat(report): give the writer a static interpretation guide
The report writer had no interpretation methodology at all: a local agent
calling the jyotish skill can read the reference library, the report model
could read nothing. It could only restate the bundle.

- frontend/src/lib/report-interpretation-packs/ holds one general pack and
  one pack per report theme, distilled from the in-repo reference guides.
  They constrain wording and reasoning discipline (term modernisation,
  how to talk about relative strength and SAV scores, the reasoning errors
  to avoid, the banned phrasings) and never assert a chart fact.
- The general pack rides INSIDE the cached system message so the cached
  prefix stays byte-identical across sections; the chapter pack follows it
  and summary calls get the general pack only.
- Skill jyotish-personal-report goes to 1.1.0 (1.0.0 deprecated): the
  contract now names interpretiveFacts and themeNarrativeSeeds as a
  bounded fact layer and states that the knowledge pack is not a fact
  source and cannot raise certainty.
- Telemetry records interpretiveFactCount and knowledgePackCharacters as
  numbers only; the counter never throws so telemetry cannot break a run.

Tests lock every theme resolving a pack, the 3,000 character budget, a
forbidden-substring scan (paths, module names, vendor names, artefact
names), the byte-stable cache prefix, and that no evidence id or date
appears in the static content.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016P5RoqzmUQEbeC2qjAkeGr
2026-09-01 20:35:02 +00:00

97 lines
3.6 KiB
TypeScript

import assert from "node:assert/strict";
import test from "node:test";
import { Agent } from "@mastra/core/agent";
import { createPersonalReportAgent } from "../src/mastra/personal-report.ts";
const model = {
specificationVersion: "v2",
provider: "telemetry-test",
modelId: "telemetry-test",
} as never;
function testModel() {
return {
id: "telemetry-test",
label: "Telemetry test",
description: "Telemetry test",
creditCost: 0,
isDefault: false,
mode: "openai" as const,
model,
};
}
test("personal report telemetry records each truncated attempt without private payloads", async () => {
const originalGenerate = Agent.prototype.generate;
const originalInfo = console.info;
const logs: unknown[][] = [];
let calls = 0;
Agent.prototype.generate = (async function () {
calls += 1;
return {
object: {},
usage: Promise.resolve({ inputTokens: 11, outputTokens: 3, totalTokens: 14 }),
finishReason: Promise.resolve("length"),
};
}) as never;
console.info = (...args: unknown[]) => logs.push(args);
try {
const agent = createPersonalReportAgent(testModel());
await assert.rejects(agent.generate({} as never, {} as never));
} finally {
Agent.prototype.generate = originalGenerate;
console.info = originalInfo;
}
assert.equal(calls, 2);
const telemetry = logs
.filter(([label]) => label === "[personal-report-agent]")
.map(([, payload]) => JSON.parse(String(payload)) as Record<string, unknown>);
assert.equal(telemetry.length, 2);
assert.deepEqual(telemetry.map((entry) => entry.finishReason), ["length", "length"]);
assert.deepEqual(telemetry.map((entry) => entry.repairAttempted), [false, true]);
assert.deepEqual(telemetry.map((entry) => entry.outputTokens), [3, 3]);
assert.equal("prompt" in telemetry[0], false);
assert.equal("bundle" in telemetry[0], false);
assert.equal("report" in telemetry[0], false);
});
test("telemetry carries interpretive and knowledge-pack sizes as numbers only", async () => {
const originalGenerate = Agent.prototype.generate;
const originalInfo = console.info;
const logs: unknown[][] = [];
Agent.prototype.generate = (async function () {
return {
object: {},
usage: Promise.resolve({ inputTokens: 11, outputTokens: 3, totalTokens: 14 }),
finishReason: Promise.resolve("length"),
};
}) as never;
console.info = (...args: unknown[]) => logs.push(args);
try {
const agent = createPersonalReportAgent(testModel());
await assert.rejects(agent.generateSection!(
{ interpretiveFacts: { yogas: [{}, {}], functionalRoles: [{}], shadbalaRanking: [], savScores: [{}], convergenceDomains: [], currentDasha: {}, savTotal: 337 } } as never,
{ id: "theme-wealth", kind: "thematic", theme: "wealth", disposition: "write", evidenceRefs: [], targetCharacters: { min: 1, max: 2 } } as never,
[],
));
} finally {
Agent.prototype.generate = originalGenerate;
console.info = originalInfo;
}
const telemetry = logs
.filter(([label]) => label === "[personal-report-agent]")
.map(([, payload]) => JSON.parse(String(payload)) as Record<string, unknown>);
assert.ok(telemetry.length >= 1);
assert.equal(telemetry[0].interpretiveFactCount, 6);
assert.equal(typeof telemetry[0].knowledgePackCharacters, "number");
assert.ok((telemetry[0].knowledgePackCharacters as number) > 500);
// The metrics are sizes, not payloads: no seed text or fact text may appear.
const serialized = JSON.stringify(telemetry[0]);
assert.ok(!serialized.includes("宫"));
assert.ok(!serialized.includes("yogakaraka"));
});