fix: parse decision center document metadata
This commit is contained in:
@@ -1,4 +1,10 @@
|
||||
import { readFileSync } from "node:fs";
|
||||
import {
|
||||
buildDocTypeTree,
|
||||
docTypeLabels,
|
||||
extractDocMetadata,
|
||||
extractDocNo,
|
||||
} from "../src/components/frontend/src/decision-center.tsx";
|
||||
|
||||
type JsonRecord = Record<string, unknown>;
|
||||
|
||||
@@ -14,19 +20,73 @@ function includesAll(text: string, snippets: string[]): boolean {
|
||||
return snippets.every((snippet) => text.includes(snippet));
|
||||
}
|
||||
|
||||
function assertEqual<T>(actual: T, expected: T, message: string, detail: JsonRecord = {}): void {
|
||||
assertCondition(Object.is(actual, expected), message, { ...detail, actual, expected });
|
||||
}
|
||||
|
||||
function groupCount(records: JsonRecord[], type: string): number {
|
||||
return buildDocTypeTree(records).find((group) => group.type === type)?.nodes.length || 0;
|
||||
}
|
||||
|
||||
export function runDecisionCenterWorkspaceContract(): JsonRecord {
|
||||
const frontend = source("src/components/frontend/src/decision-center.tsx");
|
||||
const css = source("src/components/frontend/public/style.css");
|
||||
|
||||
const titleDcsn = {
|
||||
id: "title-dcsn",
|
||||
title: "DC-DCSN-P0-2026-001 决策记录",
|
||||
tags: [],
|
||||
};
|
||||
const tagGoal = {
|
||||
id: "tag-goal",
|
||||
title: "目标文书",
|
||||
tags: ["doc-no:DC-GOAL-P0-2026-002"],
|
||||
};
|
||||
const bodyRprt = {
|
||||
id: "body-rprt",
|
||||
title: "报告正文",
|
||||
body: "DC-RPRT-P2-2026-003\n\n报告正文第一段。",
|
||||
tags: [],
|
||||
};
|
||||
const tagRetr = {
|
||||
id: "tag-retr",
|
||||
title: "复盘文书",
|
||||
tags: ["doc-type:RETR"],
|
||||
};
|
||||
const structuredPlan = {
|
||||
id: "structured-plan",
|
||||
title: "结构化计划文书",
|
||||
docType: "PLAN",
|
||||
priority: "P1",
|
||||
year: 2026,
|
||||
sequence: 4,
|
||||
};
|
||||
|
||||
assertEqual(extractDocNo(titleDcsn), "DC-DCSN-P0-2026-001", "title prefix must extract complete DCSN doc number");
|
||||
assertEqual(extractDocMetadata(titleDcsn).docType, "DCSN", "title prefix must extract DCSN doc type");
|
||||
assertEqual(extractDocNo(tagGoal), "DC-GOAL-P0-2026-002", "doc-no tag must extract complete GOAL doc number");
|
||||
assertEqual(extractDocMetadata(tagGoal).docType, "GOAL", "doc-no tag must extract GOAL doc type");
|
||||
assertEqual(extractDocNo(bodyRprt), "DC-RPRT-P2-2026-003", "body first paragraph must fallback extract complete RPRT doc number");
|
||||
assertEqual(extractDocMetadata(bodyRprt).priority, "P2", "body fallback must extract RPRT priority");
|
||||
assertEqual(extractDocMetadata(tagRetr).docType, "RETR", "doc-type tag must extract RETR doc type");
|
||||
assertEqual(docTypeLabels.RETR, "复盘", "RETR label must be 复盘");
|
||||
assertEqual(extractDocNo(structuredPlan), "DC-PLAN-P1-2026-004", "structured fields must compose complete PLAN doc number");
|
||||
assertEqual(groupCount([titleDcsn, tagGoal, bodyRprt, tagRetr, structuredPlan], "DCSN"), 1, "DCSN records must be grouped by parsed type");
|
||||
assertEqual(groupCount([titleDcsn, tagGoal, bodyRprt, tagRetr, structuredPlan], "GOAL"), 1, "GOAL records must be grouped by parsed type");
|
||||
assertEqual(groupCount([titleDcsn, tagGoal, bodyRprt, tagRetr, structuredPlan], "RPRT"), 1, "RPRT records must be grouped by parsed type");
|
||||
assertEqual(groupCount([titleDcsn, tagGoal, bodyRprt, tagRetr, structuredPlan], "RETR"), 1, "RETR records must be grouped by parsed type");
|
||||
assertEqual(groupCount([titleDcsn, tagGoal, bodyRprt, tagRetr, structuredPlan], "PLAN"), 1, "PLAN records must be grouped by structured type");
|
||||
|
||||
assertCondition(
|
||||
includesAll(frontend, [
|
||||
"function extractDocNo(record: any): string",
|
||||
"function buildDocTypeTree(records: any[]): Array<{ type: DocTypeCode",
|
||||
"export function extractDocMetadata(record: any): DocMetadata",
|
||||
"export function extractDocNo(record: any): string",
|
||||
"export function buildDocTypeTree(records: any[]): Array<{ type: DocTypeCode",
|
||||
"function buildTagGroups(records: any[]): Array<{ tag: string",
|
||||
"DOC_TYPE_CODES = [\"DCSN\", \"GOAL\", \"PLAN\", \"RPRT\", \"ACTN\", \"ISSU\", \"RETR\", \"RQST\", \"RESP\", \"MINS\"]",
|
||||
"docTypeLabels: Record<DocTypeCode, string>",
|
||||
]),
|
||||
"frontend must implement doc-no extraction, doc-type tree, and tag grouping",
|
||||
"frontend must implement exported doc metadata extraction, doc-type tree, and tag grouping",
|
||||
);
|
||||
|
||||
assertCondition(
|
||||
@@ -118,11 +178,11 @@ export function runDecisionCenterWorkspaceContract(): JsonRecord {
|
||||
|
||||
assertCondition(
|
||||
includesAll(frontend, [
|
||||
"extractDocNo(record)",
|
||||
"title.match(/^([A-Z]{2,5})[-−]?(\\d+)/u)",
|
||||
"doc-no:([A-Z]{2,5})[-−]?(\\d+)",
|
||||
"extractDocMetadata(record)",
|
||||
"recordTagValues(record, \"doc-no\")",
|
||||
"firstBodyWindow(record)",
|
||||
]),
|
||||
"extractDocNo must extract from title prefix and doc-no tag",
|
||||
"extractDocNo must use metadata extraction from title, doc-no tag, and body fallback",
|
||||
);
|
||||
|
||||
assertCondition(
|
||||
@@ -148,7 +208,7 @@ export function runDecisionCenterWorkspaceContract(): JsonRecord {
|
||||
"workspace-css-layout",
|
||||
"workspace-css-components",
|
||||
"three-column-layout-50-percent",
|
||||
"doc-no-regex-from-title",
|
||||
"doc-metadata-fixtures",
|
||||
"type-tag-grouping-toggle",
|
||||
],
|
||||
};
|
||||
@@ -156,4 +216,4 @@ export function runDecisionCenterWorkspaceContract(): JsonRecord {
|
||||
|
||||
if (import.meta.main) {
|
||||
process.stdout.write(`${JSON.stringify(runDecisionCenterWorkspaceContract(), null, 2)}\n`);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user