Files
dify/knowledge-fs/apps/admin/lib/trace-summary.test.ts
Jyong 4ee43b8afc chore: migrate knowledge-fs source tree
Import the committed KnowledgeFS snapshot dc4072ee302317145612087ce7440851dc329fd0 under knowledge-fs/ without its Git history, local IDE settings, or build artifacts.
2026-07-20 04:54:20 -04:00

76 lines
2.1 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { createTraceSummary } from "./trace-summary";
describe("createTraceSummary", () => {
it("summarizes route, recall, filters, rerank, and evidence steps", () => {
const summary = createTraceSummary({
steps: [
{ attributes: { mode: "hybrid" }, name: "route.select" },
{ attributes: { count: 42 }, name: "recall.candidates" },
{ attributes: { permission: "tenant", tags: "release" }, name: "filters.apply" },
{ attributes: { provider: "cohere", topK: 8 }, name: "rerank.apply" },
{ attributes: { citations: 3 }, name: "evidence.bundle" },
],
});
expect(summary).toEqual({
evidence: "3 citations",
filters: "permission=tenant, tags=release",
recallCandidates: 42,
rerank: "cohere top 8",
route: "hybrid",
});
});
it("summarizes live query.generate traces from hybrid retrieval metadata", () => {
const summary = createTraceSummary({
steps: [
{
attributes: {
citations: [{ label: "node:node-1" }],
evidenceBundle: {
items: [
{
citations: [{ documentAssetId: "asset-1" }],
},
],
},
metrics: {
denseCandidates: 0,
ftsCandidates: 1,
fusedCandidates: 1,
},
mode: "fast",
plan: {
rerankCandidateLimit: 0,
resolvedMode: "fast",
},
},
name: "query.generate",
},
],
});
expect(summary).toEqual({
evidence: "1 citations",
filters: "none",
recallCandidates: 1,
rerank: "disabled top 0",
route: "fast",
});
});
it("bounds trace step scans before the UI can retain very large traces", () => {
expect(() =>
createTraceSummary({
maxSteps: 1,
steps: [
{ attributes: {}, name: "route.select" },
{ attributes: {}, name: "recall.candidates" },
],
}),
).toThrow("Trace summary exceeds maxSteps=1");
});
});