Remove legacy key/password aliases and clean up workspace
Drop the Hose key/password compatibility path from the config schema, credential reads, CLI messages, tests, and docs; appKey/appSecurity are now the only accepted fields. Isolate seal-renew tests from the real enterprises directory so renewals never write local config. Remove the tracked pkg/ report spec and local artifacts, and rewrite .gitignore with complete sections.
This commit is contained in:
1 parent
8d6b65d3d5
commit
35f761e8a0
18 files changed
+106
-940
No files matched your search
+38
-14
@@ -1,37 +1,61 @@
|
|||||||
node_modules/
|
# ---------------------------------------------------------------------------
|
||||||
|
# OS & editor noise
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
._*
|
||||||
|
Thumbs.db
|
||||||
|
Desktop.ini
|
||||||
|
*.swp
|
||||||
|
.idea/
|
||||||
|
.vscode/
|
||||||
|
*.tsbuildinfo
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# Dependencies
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
node_modules/
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
# Build outputs
|
# Build outputs
|
||||||
dist/bin/
|
# ---------------------------------------------------------------------------
|
||||||
|
dist/
|
||||||
build/
|
build/
|
||||||
|
coverage/
|
||||||
|
|
||||||
# Local runtime caches and system noise (regenerate at any time)
|
# ---------------------------------------------------------------------------
|
||||||
|
# Local caches and tool state (regenerate at any time)
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
.cache/
|
.cache/
|
||||||
.mimosa/
|
.mimosa/
|
||||||
.apifox/
|
.apifox/
|
||||||
tmp/
|
tmp/
|
||||||
|
*.log
|
||||||
|
|
||||||
# Local runtime state (rule snapshots, bridge, reports) — never committed
|
# ---------------------------------------------------------------------------
|
||||||
|
# Local runtime state (never committed)
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
.local/
|
.local/
|
||||||
/reports/
|
/reports/
|
||||||
|
|
||||||
# WorkBuddy workspace data (memory logs, project state) — keep on disk, never commit
|
|
||||||
.workbuddy/
|
.workbuddy/
|
||||||
|
|
||||||
# Developer-only build-time credentials for compile-time injection — never committed
|
# ---------------------------------------------------------------------------
|
||||||
.env.langfuse
|
# Secrets and build-time credentials (never committed)
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
.env
|
.env
|
||||||
.env.*
|
.env.*
|
||||||
!.env.example
|
!.env.example
|
||||||
*.pem
|
*.pem
|
||||||
*.key
|
*.key
|
||||||
|
|
||||||
# Local drafts for repo-gh & AI Agents
|
# ---------------------------------------------------------------------------
|
||||||
|
# Local drafts, one-off harnesses, and review notes
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
.drafts/*
|
.drafts/*
|
||||||
!.drafts/.gitkeep
|
!.drafts/.gitkeep
|
||||||
|
|
||||||
# ZCode session plan artifacts (workspace-local, never committed)
|
|
||||||
.zcode/plans/
|
|
||||||
|
|
||||||
# One-off export harnesses dropped in scripts/ while exporting
|
|
||||||
scripts/export-*.ts
|
scripts/export-*.ts
|
||||||
|
*.local.md
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# ZCode session artifacts
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
.zcode/plans/
|
||||||
@@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
Bun + TypeScript CLI for pulling Seal enterprise approval context from provider credentials.
|
Bun + TypeScript CLI for pulling Seal enterprise approval context from provider credentials.
|
||||||
|
|
||||||
The first provider is Hose/合思: `key`, `password`, `corpId`, `staffId`, and an optional Hose domain. The provider exchanges those credentials for a Seal enterprise session, then the Seal domain tools can read and maintain approval rules, approval documents, and approval style preferences.
|
The first provider is Hose/合思: `appKey`, `appSecurity`, `corpId`, `staffId`, and an optional Hose domain. The provider exchanges those credentials for a Seal enterprise session, then the Seal domain tools can read and maintain approval rules, approval documents, and approval style preferences.
|
||||||
|
|
||||||
Seal-native enterprise pages can be added with a Seal Bearer token.
|
Seal-native enterprise pages can be added with a Seal Bearer token.
|
||||||
|
|
||||||
@@ -217,8 +217,8 @@ Use `seal-use auth diagnose --corp <corpId>` when login fails in stateless mode.
|
|||||||
"source": {
|
"source": {
|
||||||
"type": "hose",
|
"type": "hose",
|
||||||
"domain": "https://app.ekuaibao.com",
|
"domain": "https://app.ekuaibao.com",
|
||||||
"key": "hose-app-key",
|
"appKey": "hose-app-key",
|
||||||
"password": "hose-app-security",
|
"appSecurity": "hose-app-security",
|
||||||
"staffId": "hose-staff-id",
|
"staffId": "hose-staff-id",
|
||||||
"corpId": "hose-corp-id"
|
"corpId": "hose-corp-id"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,190 +0,0 @@
|
|||||||
# 【模板企业】8月AI审核准确率报告
|
|
||||||
|
|
||||||
| 报告信息 | 内容 |
|
|
||||||
| --- | --- |
|
|
||||||
| 报告编号 | RPT-202608-A3F8C2 |
|
|
||||||
| 客户名称 | 模板企业 |
|
|
||||||
| 统计期间 | 2026-08-01 ~ 2026-08-31 |
|
|
||||||
| 报告状态 | 草稿 |
|
|
||||||
| 生成日期 | 2026-09-23 |
|
|
||||||
|
|
||||||
> **摘要**:以模板企业授权的 240 笔已完成历史审批单据为样本,对 AI 审核结论与人工审核结论进行全量复核。AI 审核准确率 **92.08%**,人工审核准确率 **83.33%**。AI 还在人工已同意的单据中额外识别出 **40 笔**存在风险。
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 1. 审核测试结果
|
|
||||||
|
|
||||||
### 1.1 数据来源与范围
|
|
||||||
|
|
||||||
| 项目 | 内容 |
|
|
||||||
| --- | --- |
|
|
||||||
| 数据来源 | 客户授权的已完成历史审批单据 |
|
|
||||||
| 统计期间 | 2026-08-01 ~ 2026-08-31 期间单据 |
|
|
||||||
| 单据模板 | 涵盖一般费用报销单【发票】-个人报销、一般费用报销单【发票】-对外支付、一般费用报销单【收据】-个人报销、差旅报销单-定额、采购付款单等 **16 类**业务单据模板 |
|
|
||||||
| 样本总量 | **240 张**(100 张同意 + 100 张驳回 + 40 张建议复核) |
|
|
||||||
|
|
||||||
### 1.2 核心准确率结论
|
|
||||||
|
|
||||||
基于已经给定的规则库:
|
|
||||||
|
|
||||||
| 审核方式 | 准确率 |
|
|
||||||
| --- | --- |
|
|
||||||
| AI 审核 | **92.08%** |
|
|
||||||
| 人工审核 | **83.33%** |
|
|
||||||
|
|
||||||
AI 审核准确率的计算方式:
|
|
||||||
|
|
||||||
$$ \text{AI 审核准确率} = \frac{\text{依规判定正确单数}}{\text{样本总量}} = \frac{221}{240} = 92.08\% $$
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
*图 1 · AI 与人工审核准确率对比*
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 2. AI 失准分析(学习优化空间)
|
|
||||||
|
|
||||||
在全量 **240 单**的深度稽核中,AI 依规综合正确 **221 单(92.08%)**,综合失准共 **19 单(7.92%)**。失准主要由以下三个维度构成。
|
|
||||||
|
|
||||||
### 2.1 失准构成总览
|
|
||||||
|
|
||||||
| 维度 | 失准类型 | 占比 | 单数 |
|
|
||||||
| --- | --- | --- | --- |
|
|
||||||
| TOP 1 | 规则执行与判定偏差 | 47.4% | 9 张 |
|
|
||||||
| TOP 2 | 数据与附件识别问题 | 26.3% | 5 张 |
|
|
||||||
| TOP 3 | 费用明细查重冲突 | 26.3% | 5 张 |
|
|
||||||
| 合计 | — | 100% | 19 张 |
|
|
||||||
|
|
||||||
### 2.2 TOP 1 · 规则执行与判定偏差(9 张 / 47.4%)
|
|
||||||
|
|
||||||
**解决方案**:严格校准规则触发后动作,按规则执行。
|
|
||||||
|
|
||||||
| 单号 | 问题描述 |
|
|
||||||
| --- | --- |
|
|
||||||
| FP260001 | 规则仅核验支付凭证金额一致性,不要求个人代垫的收款方必须是公司,AI 误要求 |
|
|
||||||
| CD260002 | 连续三日均为工作日(周一至周三),AI 误认为有周末未扣减问题 |
|
|
||||||
| FP260003 | 费用承担主体命中豁免白名单,AI 未执行豁免逻辑导致驳回 |
|
|
||||||
|
|
||||||
*(节选 3 例,全量 9 张)*
|
|
||||||
|
|
||||||
### 2.3 TOP 2 · 数据与附件识别问题(5 张 / 26.3%)
|
|
||||||
|
|
||||||
**解决方案**:持续优化识别模型,提升多附件文字解析稳定性。
|
|
||||||
|
|
||||||
| 单号 | 问题描述 |
|
|
||||||
| --- | --- |
|
|
||||||
| SJ260004 | 手写收据金额 243 元被 OCR 误识别为 2433 元,导致金额不符误驳回 |
|
|
||||||
| FP260005 | 微信红包支付记录清晰完整,AI 误判定为无关凭据导致误驳回 |
|
|
||||||
| SG260006 | 已完整包含福利品发放人员统计表 Excel 文件,AI 因多附件漏提取误判缺件驳回 |
|
|
||||||
|
|
||||||
*(节选 3 例,全量 5 张)*
|
|
||||||
|
|
||||||
### 2.4 TOP 3 · 费用明细查重冲突(5 张 / 26.3%)
|
|
||||||
|
|
||||||
**解决方案**:已去掉跨批次相似费用冲突的默认判定,可按需配置此功能。
|
|
||||||
|
|
||||||
| 单号 | 问题描述 |
|
|
||||||
| --- | --- |
|
|
||||||
| CGD260007 | 跨批次存在历史同类辅料费用,提示疑似冲突转人工 |
|
|
||||||
| FP260008 | 跨批次云产品疑似同类费用冲突转人工 |
|
|
||||||
| FP260009 | 发票金额 180 元(1% 普票),远未达到 500 元专票强制门槛,AI 过度怀疑是否存在专票协议转人工 |
|
|
||||||
|
|
||||||
*(节选 3 例,全量 5 张)*
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 3. AI 发现的潜在风险
|
|
||||||
|
|
||||||
在人工审核同意的单据中,有部分单据被 AI 发现存在风险,问题 TOP 3 如下。
|
|
||||||
|
|
||||||
### 3.1 风险构成总览
|
|
||||||
|
|
||||||
| 维度 | 风险类型 | 占比 | 单数 |
|
|
||||||
| --- | --- | --- | --- |
|
|
||||||
| TOP 1 | 缺失要求凭证 | 57.5% | 23 张 |
|
|
||||||
| TOP 2 | 大额预付与采购口径偏差 | 22.5% | 9 张 |
|
|
||||||
| TOP 3 | 票据合规与专票强制违规 | 20.0% | 8 张 |
|
|
||||||
| 合计 | — | 100% | 40 张 |
|
|
||||||
|
|
||||||
### 3.2 TOP 1 · 缺失要求凭证(23 张 / 57.5%)
|
|
||||||
|
|
||||||
| 单号 | 问题描述 |
|
|
||||||
| --- | --- |
|
|
||||||
| FP260011 | 改衣费未附改衣明细表 |
|
|
||||||
| FP260012 | 咨询费报销资料不全 |
|
|
||||||
| FP260013 | 专利代理费未列明发明名称且缺少缴费通知书 |
|
|
||||||
|
|
||||||
*(节选 3 例,全量 23 张)*
|
|
||||||
|
|
||||||
### 3.3 TOP 2 · 大额预付与采购口径偏差(9 张 / 22.5%)
|
|
||||||
|
|
||||||
| 单号 | 问题描述 |
|
|
||||||
| --- | --- |
|
|
||||||
| YF260014 | 大额预付款单未关联申购单 / 申请单 |
|
|
||||||
| CGA260015 | 采购预付款单明细采购订单号与合同号不一致 |
|
|
||||||
| CGD260016 | 采购付款单品类为上装类但发票明细为服装加工费,业务勾稽不符 |
|
|
||||||
|
|
||||||
*(节选 3 例,全量 9 张)*
|
|
||||||
|
|
||||||
### 3.4 TOP 3 · 票据合规与专票强制违规(8 张 / 20.0%)
|
|
||||||
|
|
||||||
| 单号 | 问题描述 |
|
|
||||||
| --- | --- |
|
|
||||||
| FP260017 / FP260018 / FP260019 | 发票类对外支付模板未上传正规发票,上传非正规微信截图或洗衣取衣单据 |
|
|
||||||
| FP260020 | 高税率业务金额超 500 元未开具增值税专用发票且无免专票佐证 |
|
|
||||||
| FP260021 | 完税证明纳税人名称与费用承担公司主体不一致 |
|
|
||||||
|
|
||||||
*(节选 3 条,全量 8 张)*
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 4. 综合效益
|
|
||||||
|
|
||||||
| 维度 | 结论 | 关键数据 |
|
|
||||||
| --- | --- | --- |
|
|
||||||
| 准确度 | 除去 AI 无法形成可靠判断而转失败的单据,AI 在既定规则范围内的准确率已赶超人工审批 | **92.08%** |
|
|
||||||
| 时效 | AI 审核单张单据平均耗时赶超人工处理时效 | 平均 **445.4 秒** |
|
|
||||||
| 风险拦截 | 在人工审核通过的单据中,AI 有效防堵无票支付、大额无合同预付、税票违规等税务与资金安全隐患 | 40 笔 |
|
|
||||||
| 工作量 | 协助财务人员弥补遗漏、关注单据重点信息,大幅释放财务人员精力,专注于更有价值的工作 | — |
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 5. 审核分歧与复核归因
|
|
||||||
|
|
||||||
在全量 **240 单**的深度复核中,AI 审核决策与人工实际审批结果存在分歧的单据共 **3 笔**(占全量样本 **1.25%**)。对分歧单据的复核定性与主要原因归类如下:
|
|
||||||
|
|
||||||
| 原因分类 | 占比 | 单数 | 核心说明 |
|
|
||||||
| --- | --- | --- | --- |
|
|
||||||
| 线下口头要求/未在线配置规则 | 66.7% | 2 张 | 单据凭证齐全且符合现行线上规则,主要因经办人主动撤回、无理由终止或财务执行未上线的口头标准,AI 依既定规则放行 |
|
|
||||||
| AI 识别或规则理解偏差 | 33.3% | 1 张 | 单据缺少必要发票凭据,AI 未能正确识别缺件卡口放行,已纳入模型调优与规则修复样本 |
|
|
||||||
| 合计 | 100% | 3 张 | — |
|
|
||||||
|
|
||||||
**分歧分析与后续建议**:
|
|
||||||
|
|
||||||
1. **规则覆盖与口径统一**:存在分歧的单据中,绝大多数(**66.7%**,2 笔)并非 AI 判定缺陷,而是企业内部存在线下口头补充管控要求。建议根据实际管理需要,将此类管控标准沉淀并补充至线上规则库。
|
|
||||||
2. **算法与识别调优**:对于真实失准单据(仅 **1 笔**,占全量 **0.42%**),已归入模型样本库进行针对性专项训练。
|
|
||||||
|
|
||||||
> 📌 **注**:分歧单据的逐单编号、审核比对意见与复核裁决记录,已完整收录于配套交付的《明细台账.xlsx》中,可供业务与审计部门按单查验核对。
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 6. 支撑数据与交付材料
|
|
||||||
|
|
||||||
### 6.1 分模板准确率与自动审批率
|
|
||||||
|
|
||||||
全量 N = 240:
|
|
||||||
|
|
||||||
| 单据模板 | AI 准确率 | 人工准确率 | 自动审批率 | 人工同意:驳回 | AI&人工都准确比例 |
|
|
||||||
| --- | --- | --- | --- | --- | --- |
|
|
||||||
| 一般费用报销单【发票】- 个人报销 | 92.86% | 87.14% | 45.71% | 70(57:13) | 80.00% |
|
|
||||||
| 一般费用报销单【发票】- 对外支付 | 92.19% | 75.00% | 42.19% | 64(50:14) | 67.19% |
|
|
||||||
| 一般费用报销单【收据】- 个人报销 | 93.94% | 93.94% | 48.48% | 33(20:13) | 87.88% |
|
|
||||||
| 差旅报销单-定额 | 81.82% | 100.00% | 31.82% | 22(19:3) | 81.82% |
|
|
||||||
| 预付款单 | 100.00% | 42.86% | 14.29% | 7(7:0) | 42.86% |
|
|
||||||
| **全量样本总体(N=240)** | **92.08%** | **83.33%** | **41.67%** | **240(185:55)** | **75.42%** |
|
|
||||||
|
|
||||||
*(其余 10 类模板从略,实际报告列出全量 16 类)*
|
|
||||||
|
|
||||||
### 6.2 跑批原始数据与交付台账
|
|
||||||
|
|
||||||
见同目录配套交付的《明细台账.xlsx》及《明细台账.csv》(完整收录本月全量跑批单据、AI 审核意见、人工审批结论及逐笔复核定性台账)。
|
|
||||||
@@ -1,64 +0,0 @@
|
|||||||
# AI 审核报告编制与校验规范
|
|
||||||
|
|
||||||
本目录提供标准的 AI 审核报告 Markdown 模板与配套的离线校验脚本。
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 一、标准模板与章节规范
|
|
||||||
|
|
||||||
报告应以 Markdown 格式编写(可参考同目录下的 [`example-report.md`](example-report.md))。
|
|
||||||
|
|
||||||
### 1. 核心必填章节(按大标题名称识别)
|
|
||||||
核心章节通过 `##` 大标题名称自动识别与归属,包含以下板块:
|
|
||||||
|
|
||||||
| 核心大标题名称 | 说明与要求 |
|
|
||||||
| :--- | :--- |
|
|
||||||
| **开篇「报告信息」表** | 文档顶部表格,必填 5 项:`报告编号`、`客户名称`、`统计期间`、`报告状态`、`生成日期`,均不可为空。 |
|
|
||||||
| **`审核测试结果`** | 汇总效能指标、AI 与人工准确率结论、LaTeX 计算公式(`$$ \text{AI 审核准确率} = \frac{A}{B} = C\% $$`)与对比图表。 |
|
|
||||||
| **`AI 失准分析`** | 包含失准构成总览表、TOP 1~N 典型错判案例表格与调优方案。 |
|
|
||||||
| **`AI 发现的潜在风险`** | 包含潜在风险总览表、TOP 1~N 真实拦截案例表格(如凭证缺失、比价缺失、超期等)。 |
|
|
||||||
| **`综合效益`** | 时效、准确度、风险拦截笔数宏观总结表(纯内部核对时可按需裁剪)。 |
|
|
||||||
| **`审核分歧与复核归因`** | 人机分歧分类统计表(如“未在线配置规则”与“识别偏差”)与管理建议。 |
|
|
||||||
| **`支撑数据与交付材料`** | 分模板统计表与说明。 |
|
|
||||||
|
|
||||||
### 2. 中间自定义插入章节
|
|
||||||
* 如需针对特定部门、专项费用做深入穿透,允许在任意位置插入自定义章节(例如 `## 2. 营销业务线专项分析`)。
|
|
||||||
* **规则**:大标题序号从 1 开始自然连续递增(1, 2, 3, 4, 5...);自定义插入的章节内容不受业务规则限制,写什么格式都直接放行。
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 二、核心格式规范
|
|
||||||
|
|
||||||
为保证文档严谨自洽,报告编写需满足以下格式守则:
|
|
||||||
|
|
||||||
1. **纯净 Markdown 语法**:
|
|
||||||
* 严禁在开头使用 YAML Frontmatter(`---`),元数据请统一写在开篇「报告信息」表中;
|
|
||||||
* 严禁残留草稿占位标记(如 `<!--slot:xxx-->`、`{{variable}}` 等);
|
|
||||||
* 代码块(```)必须成对闭合。
|
|
||||||
2. **表格结构**:
|
|
||||||
* 表格每行单元格数量必须严格与表头对齐;
|
|
||||||
* 表头文字保持纯文本,禁止包含加粗符号(`**`);
|
|
||||||
* 案例表格推荐使用纯净紧凑的 2 列格式(`| 单号 | 问题描述 |`),无需手工填写长链接。
|
|
||||||
3. **数学总账守恒**:
|
|
||||||
* 失准总览表与潜在风险总览表中,各 TOP 行的单数相加必须严格等于「合计」行单数,百分比相加必须等于 100%(误差 $\le 0.15\%$);
|
|
||||||
* 各子小节标题中声明的张数(如 `### 2.2 TOP 1 · xxx(9 张 / 47.4%)`)必须与总览表该行单数完全一致;
|
|
||||||
* LaTeX 公式中的算术计算必须成立(如 $\frac{221}{240} = 92.08\%$),且公式中的数字在正文中有对应出处。
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 三、校验脚本使用说明
|
|
||||||
|
|
||||||
同目录下已提供独立的 Python 校验脚本 [`validate.py`](validate.py)(纯 Python 标准库编写,无需安装任何第三方库)。
|
|
||||||
|
|
||||||
### 运行校验
|
|
||||||
```bash
|
|
||||||
python3 validate.py example-report.md
|
|
||||||
```
|
|
||||||
|
|
||||||
* **校验通过**:终端输出绿色通过提示,退出码为 `0`;
|
|
||||||
* **校验未通过**:终端会明确打印出具体报错的行号、错误代码及修复指南,退出码为 `1`。
|
|
||||||
|
|
||||||
支持输出 JSON 格式供程序化调用:
|
|
||||||
```bash
|
|
||||||
python3 validate.py example-report.md --json
|
|
||||||
```
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
<svg xmlns="http://www.w3.org/2000/svg" width="960" height="400" viewBox="0 0 960 400" font-family="-apple-system, BlinkMacSystemFont, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', Arial, sans-serif">
|
|
||||||
<defs>
|
|
||||||
<!-- 精确交集透镜裁剪路径 -->
|
|
||||||
<clipPath id="left-circle-clip">
|
|
||||||
<circle cx="410" cy="160" r="135"/>
|
|
||||||
</clipPath>
|
|
||||||
</defs>
|
|
||||||
|
|
||||||
<rect width="960" height="400" fill="#ffffff"/>
|
|
||||||
|
|
||||||
<!-- Left Circle: Pastel Blue -->
|
|
||||||
<circle cx="410" cy="160" r="135" fill="#b9deff"/>
|
|
||||||
|
|
||||||
<!-- Right Circle: Pastel Mint -->
|
|
||||||
<circle cx="550" cy="160" r="135" fill="#d2ede8"/>
|
|
||||||
|
|
||||||
<!-- Distinct Intersection Lens: Perfect blend tone (#9ed4eb) -->
|
|
||||||
<circle cx="550" cy="160" r="135" clip-path="url(#left-circle-clip)" fill="#9ed4eb"/>
|
|
||||||
|
|
||||||
<!-- Left Text Block (Horizontally centered lines) -->
|
|
||||||
<g text-anchor="middle" fill="#111111">
|
|
||||||
<text x="140" y="146" font-size="18"><tspan letter-spacing="1.5px">AI</tspan><tspan letter-spacing="0px">审核准确</tspan></text>
|
|
||||||
<text x="140" y="176" font-size="18">(总准确率92.08%)</text>
|
|
||||||
</g>
|
|
||||||
<!-- Left dashed line: comfortable gap from text, extends into circle -->
|
|
||||||
<line x1="245" y1="160" x2="310" y2="160" stroke="#222222" stroke-width="1.8" stroke-dasharray="6,4.5"/>
|
|
||||||
|
|
||||||
<!-- Left percentage -->
|
|
||||||
<text x="348" y="160" font-size="22" fill="#111111" text-anchor="middle" dominant-baseline="central">16.66%</text>
|
|
||||||
|
|
||||||
<!-- Overlap percentage (in intersection lens) -->
|
|
||||||
<text x="480" y="160" font-size="22" fill="#111111" text-anchor="middle" dominant-baseline="central">75.42%</text>
|
|
||||||
|
|
||||||
<!-- Right percentage -->
|
|
||||||
<text x="612" y="160" font-size="22" fill="#111111" text-anchor="middle" dominant-baseline="central">7.91%</text>
|
|
||||||
|
|
||||||
<!-- Right dashed line -->
|
|
||||||
<line x1="650" y1="160" x2="715" y2="160" stroke="#222222" stroke-width="1.8" stroke-dasharray="6,4.5"/>
|
|
||||||
|
|
||||||
<!-- Right Text Block (Horizontally centered lines) -->
|
|
||||||
<g text-anchor="middle" fill="#111111">
|
|
||||||
<text x="820" y="146" font-size="18">人工审核准确</text>
|
|
||||||
<text x="820" y="176" font-size="18">(总准确率83.33%)</text>
|
|
||||||
</g>
|
|
||||||
|
|
||||||
<!-- Bottom vertical dashed pointer -->
|
|
||||||
<line x1="480" y1="215" x2="480" y2="305" stroke="#222222" stroke-width="1.8" stroke-dasharray="6,4.5"/>
|
|
||||||
|
|
||||||
<!-- Bottom label: refined kerning on AI and comfortable character spacing -->
|
|
||||||
<text x="480" y="338" font-size="18" fill="#111111" text-anchor="middle" dominant-baseline="central"><tspan letter-spacing="2px">AI</tspan><tspan letter-spacing="1px">与人工都准确</tspan></text>
|
|
||||||
</svg>
|
|
||||||
|
Before Width: | Height: | Size: 2.5 KiB |
@@ -1,190 +0,0 @@
|
|||||||
# 【模板企业】8月AI审核准确率报告
|
|
||||||
|
|
||||||
| 报告信息 | 内容 |
|
|
||||||
| --- | --- |
|
|
||||||
| 报告编号 | RPT-202608-A3F8C2 |
|
|
||||||
| 客户名称 | 模板企业 |
|
|
||||||
| 统计期间 | 2026-08-01 ~ 2026-08-31 |
|
|
||||||
| 报告状态 | 草稿 |
|
|
||||||
| 生成日期 | 2026-09-23 |
|
|
||||||
|
|
||||||
> **摘要**:以模板企业授权的 240 笔已完成历史审批单据为样本,对 AI 审核结论与人工审核结论进行全量复核。AI 审核准确率 **92.08%**,人工审核准确率 **83.33%**。AI 还在人工已同意的单据中额外识别出 **40 笔**存在风险。
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 1. 审核测试结果
|
|
||||||
|
|
||||||
### 1.1 数据来源与范围
|
|
||||||
|
|
||||||
| 项目 | 内容 |
|
|
||||||
| --- | --- |
|
|
||||||
| 数据来源 | 客户授权的已完成历史审批单据 |
|
|
||||||
| 统计期间 | 2026-08-01 ~ 2026-08-31 期间单据 |
|
|
||||||
| 单据模板 | 涵盖一般费用报销单【发票】-个人报销、一般费用报销单【发票】-对外支付、一般费用报销单【收据】-个人报销、差旅报销单-定额、采购付款单等 **16 类**业务单据模板 |
|
|
||||||
| 样本总量 | **240 张**(100 张同意 + 100 张驳回 + 40 张建议复核) |
|
|
||||||
|
|
||||||
### 1.2 核心准确率结论
|
|
||||||
|
|
||||||
基于已经给定的规则库:
|
|
||||||
|
|
||||||
| 审核方式 | 准确率 |
|
|
||||||
| --- | --- |
|
|
||||||
| AI 审核 | **92.08%** |
|
|
||||||
| 人工审核 | **83.33%** |
|
|
||||||
|
|
||||||
AI 审核准确率的计算方式:
|
|
||||||
|
|
||||||
$$ \text{AI 审核准确率} = \frac{\text{依规判定正确单数}}{\text{样本总量}} = \frac{221}{240} = 92.08\% $$
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
*图 1 · AI 与人工审核准确率对比*
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 2. AI 失准分析(学习优化空间)
|
|
||||||
|
|
||||||
在全量 **240 单**的深度稽核中,AI 依规综合正确 **221 单(92.08%)**,综合失准共 **19 单(7.92%)**。失准主要由以下三个维度构成。
|
|
||||||
|
|
||||||
### 2.1 失准构成总览
|
|
||||||
|
|
||||||
| 维度 | 失准类型 | 占比 | 单数 |
|
|
||||||
| --- | --- | --- | --- |
|
|
||||||
| TOP 1 | 规则执行与判定偏差 | 47.4% | 9 张 |
|
|
||||||
| TOP 2 | 数据与附件识别问题 | 26.3% | 5 张 |
|
|
||||||
| TOP 3 | 费用明细查重冲突 | 26.3% | 5 张 |
|
|
||||||
| 合计 | — | 100% | 19 张 |
|
|
||||||
|
|
||||||
### 2.2 TOP 1 · 规则执行与判定偏差(9 张 / 47.4%)
|
|
||||||
|
|
||||||
**解决方案**:严格校准规则触发后动作,按规则执行。
|
|
||||||
|
|
||||||
| 单号 | 问题描述 |
|
|
||||||
| --- | --- |
|
|
||||||
| FP260001 | 规则仅核验支付凭证金额一致性,不要求个人代垫的收款方必须是公司,AI 误要求 |
|
|
||||||
| CD260002 | 连续三日均为工作日(周一至周三),AI 误认为有周末未扣减问题 |
|
|
||||||
| FP260003 | 费用承担主体命中豁免白名单,AI 未执行豁免逻辑导致驳回 |
|
|
||||||
|
|
||||||
*(节选 3 例,全量 9 张)*
|
|
||||||
|
|
||||||
### 2.3 TOP 2 · 数据与附件识别问题(5 张 / 26.3%)
|
|
||||||
|
|
||||||
**解决方案**:持续优化识别模型,提升多附件文字解析稳定性。
|
|
||||||
|
|
||||||
| 单号 | 问题描述 |
|
|
||||||
| --- | --- |
|
|
||||||
| SJ260004 | 手写收据金额 243 元被 OCR 误识别为 2433 元,导致金额不符误驳回 |
|
|
||||||
| FP260005 | 微信红包支付记录清晰完整,AI 误判定为无关凭据导致误驳回 |
|
|
||||||
| SG260006 | 已完整包含福利品发放人员统计表 Excel 文件,AI 因多附件漏提取误判缺件驳回 |
|
|
||||||
|
|
||||||
*(节选 3 例,全量 5 张)*
|
|
||||||
|
|
||||||
### 2.4 TOP 3 · 费用明细查重冲突(5 张 / 26.3%)
|
|
||||||
|
|
||||||
**解决方案**:已去掉跨批次相似费用冲突的默认判定,可按需配置此功能。
|
|
||||||
|
|
||||||
| 单号 | 问题描述 |
|
|
||||||
| --- | --- |
|
|
||||||
| CGD260007 | 跨批次存在历史同类辅料费用,提示疑似冲突转人工 |
|
|
||||||
| FP260008 | 跨批次云产品疑似同类费用冲突转人工 |
|
|
||||||
| FP260009 | 发票金额 180 元(1% 普票),远未达到 500 元专票强制门槛,AI 过度怀疑是否存在专票协议转人工 |
|
|
||||||
|
|
||||||
*(节选 3 例,全量 5 张)*
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 3. AI 发现的潜在风险
|
|
||||||
|
|
||||||
在人工审核同意的单据中,有部分单据被 AI 发现存在风险,问题 TOP 3 如下。
|
|
||||||
|
|
||||||
### 3.1 风险构成总览
|
|
||||||
|
|
||||||
| 维度 | 风险类型 | 占比 | 单数 |
|
|
||||||
| --- | --- | --- | --- |
|
|
||||||
| TOP 1 | 缺失要求凭证 | 57.5% | 23 张 |
|
|
||||||
| TOP 2 | 大额预付与采购口径偏差 | 22.5% | 9 张 |
|
|
||||||
| TOP 3 | 票据合规与专票强制违规 | 20.0% | 8 张 |
|
|
||||||
| 合计 | — | 100% | 40 张 |
|
|
||||||
|
|
||||||
### 3.2 TOP 1 · 缺失要求凭证(23 张 / 57.5%)
|
|
||||||
|
|
||||||
| 单号 | 问题描述 |
|
|
||||||
| --- | --- |
|
|
||||||
| FP260011 | 改衣费未附改衣明细表 |
|
|
||||||
| FP260012 | 咨询费报销资料不全 |
|
|
||||||
| FP260013 | 专利代理费未列明发明名称且缺少缴费通知书 |
|
|
||||||
|
|
||||||
*(节选 3 例,全量 23 张)*
|
|
||||||
|
|
||||||
### 3.3 TOP 2 · 大额预付与采购口径偏差(9 张 / 22.5%)
|
|
||||||
|
|
||||||
| 单号 | 问题描述 |
|
|
||||||
| --- | --- |
|
|
||||||
| YF260014 | 大额预付款单未关联申购单 / 申请单 |
|
|
||||||
| CGA260015 | 采购预付款单明细采购订单号与合同号不一致 |
|
|
||||||
| CGD260016 | 采购付款单品类为上装类但发票明细为服装加工费,业务勾稽不符 |
|
|
||||||
|
|
||||||
*(节选 3 例,全量 9 张)*
|
|
||||||
|
|
||||||
### 3.4 TOP 3 · 票据合规与专票强制违规(8 张 / 20.0%)
|
|
||||||
|
|
||||||
| 单号 | 问题描述 |
|
|
||||||
| --- | --- |
|
|
||||||
| FP260017 / FP260018 / FP260019 | 发票类对外支付模板未上传正规发票,上传非正规微信截图或洗衣取衣单据 |
|
|
||||||
| FP260020 | 高税率业务金额超 500 元未开具增值税专用发票且无免专票佐证 |
|
|
||||||
| FP260021 | 完税证明纳税人名称与费用承担公司主体不一致 |
|
|
||||||
|
|
||||||
*(节选 3 条,全量 8 张)*
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 4. 综合效益
|
|
||||||
|
|
||||||
| 维度 | 结论 | 关键数据 |
|
|
||||||
| --- | --- | --- |
|
|
||||||
| 准确度 | 除去 AI 无法形成可靠判断而转失败的单据,AI 在既定规则范围内的准确率已赶超人工审批 | **92.08%** |
|
|
||||||
| 时效 | AI 审核单张单据平均耗时赶超人工处理时效 | 平均 **445.4 秒** |
|
|
||||||
| 风险拦截 | 在人工审核通过的单据中,AI 有效防堵无票支付、大额无合同预付、税票违规等税务与资金安全隐患 | 40 笔 |
|
|
||||||
| 工作量 | 协助财务人员弥补遗漏、关注单据重点信息,大幅释放财务人员精力,专注于更有价值的工作 | — |
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 5. 审核分歧与复核归因
|
|
||||||
|
|
||||||
在全量 **240 单**的深度复核中,AI 审核决策与人工实际审批结果存在分歧的单据共 **3 笔**(占全量样本 **1.25%**)。对分歧单据的复核定性与主要原因归类如下:
|
|
||||||
|
|
||||||
| 原因分类 | 占比 | 单数 | 核心说明 |
|
|
||||||
| --- | --- | --- | --- |
|
|
||||||
| 线下口头要求/未在线配置规则 | 66.7% | 2 张 | 单据凭证齐全且符合现行线上规则,主要因经办人主动撤回、无理由终止或财务执行未上线的口头标准,AI 依既定规则放行 |
|
|
||||||
| AI 识别或规则理解偏差 | 33.3% | 1 张 | 单据缺少必要发票凭据,AI 未能正确识别缺件卡口放行,已纳入模型调优与规则修复样本 |
|
|
||||||
| 合计 | 100% | 3 张 | — |
|
|
||||||
|
|
||||||
**分歧分析与后续建议**:
|
|
||||||
|
|
||||||
1. **规则覆盖与口径统一**:存在分歧的单据中,绝大多数(**66.7%**,2 笔)并非 AI 判定缺陷,而是企业内部存在线下口头补充管控要求。建议根据实际管理需要,将此类管控标准沉淀并补充至线上规则库。
|
|
||||||
2. **算法与识别调优**:对于真实失准单据(仅 **1 笔**,占全量 **0.42%**),已归入模型样本库进行针对性专项训练。
|
|
||||||
|
|
||||||
> 📌 **注**:分歧单据的逐单编号、审核比对意见与复核裁决记录,已完整收录于配套交付的《明细台账.xlsx》中,可供业务与审计部门按单查验核对。
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 6. 支撑数据与交付材料
|
|
||||||
|
|
||||||
### 6.1 分模板准确率与自动审批率
|
|
||||||
|
|
||||||
全量 N = 240:
|
|
||||||
|
|
||||||
| 单据模板 | AI 准确率 | 人工准确率 | 自动审批率 | 人工同意:驳回 | AI&人工都准确比例 |
|
|
||||||
| --- | --- | --- | --- | --- | --- |
|
|
||||||
| 一般费用报销单【发票】- 个人报销 | 92.86% | 87.14% | 45.71% | 70(57:13) | 80.00% |
|
|
||||||
| 一般费用报销单【发票】- 对外支付 | 92.19% | 75.00% | 42.19% | 64(50:14) | 67.19% |
|
|
||||||
| 一般费用报销单【收据】- 个人报销 | 93.94% | 93.94% | 48.48% | 33(20:13) | 87.88% |
|
|
||||||
| 差旅报销单-定额 | 81.82% | 100.00% | 31.82% | 22(19:3) | 81.82% |
|
|
||||||
| 预付款单 | 100.00% | 42.86% | 14.29% | 7(7:0) | 42.86% |
|
|
||||||
| **全量样本总体(N=240)** | **92.08%** | **83.33%** | **41.67%** | **240(185:55)** | **75.42%** |
|
|
||||||
|
|
||||||
*(其余 10 类模板从略,实际报告列出全量 16 类)*
|
|
||||||
|
|
||||||
### 6.2 跑批原始数据与交付台账
|
|
||||||
|
|
||||||
见同目录配套交付的《明细台账.xlsx》及《明细台账.csv》(完整收录本月全量跑批单据、AI 审核意见、人工审批结论及逐笔复核定性台账)。
|
|
||||||
@@ -1,374 +0,0 @@
|
|||||||
#!/usr/bin/env python3
|
|
||||||
"""
|
|
||||||
AI 审核报告(Markdown)独立校验器
|
|
||||||
Independent Markdown Validator for AI Audit Reports
|
|
||||||
|
|
||||||
特点:
|
|
||||||
- 零外部依赖:纯 Python 标准库(Python 3.8+),跨平台开箱即用
|
|
||||||
- 核心章节按大标题名称硬匹配,中间插入的自定义章节直接放行
|
|
||||||
- 严格守护格式合规与数学总账守恒
|
|
||||||
|
|
||||||
用法:
|
|
||||||
python3 validate.py <report.md>
|
|
||||||
python3 validate.py <report.md> --json
|
|
||||||
"""
|
|
||||||
|
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
import re
|
|
||||||
import json
|
|
||||||
from pathlib import Path
|
|
||||||
from typing import List, Dict, Any, Optional, Tuple
|
|
||||||
|
|
||||||
REQUIRED_INFO_ROWS = ["报告编号", "客户名称", "统计期间", "报告状态", "生成日期"]
|
|
||||||
FORBIDDEN_MARKS = [
|
|
||||||
(re.compile(r"<!--slot:"), "slot 标记"),
|
|
||||||
(re.compile(r"<!--/slot"), "slot 闭合"),
|
|
||||||
(re.compile(r"<!--@"), "@table/@block 区域标记"),
|
|
||||||
(re.compile(r"<!-- render:stop"), "render:stop 标记"),
|
|
||||||
(re.compile(r"\{\{"), "{{槽位}}"),
|
|
||||||
]
|
|
||||||
|
|
||||||
class ReportIssue:
|
|
||||||
def __init__(self, level: str, code: str, message: str, line: Optional[int] = None):
|
|
||||||
self.level = level # "ERROR" | "WARN"
|
|
||||||
self.code = code
|
|
||||||
self.message = message
|
|
||||||
self.line = line
|
|
||||||
|
|
||||||
def to_dict(self) -> Dict[str, Any]:
|
|
||||||
d: Dict[str, Any] = {"level": self.level, "code": self.code, "message": self.message}
|
|
||||||
if self.line is not None:
|
|
||||||
d["line"] = self.line
|
|
||||||
return d
|
|
||||||
|
|
||||||
|
|
||||||
class TableRow:
|
|
||||||
def __init__(self, line_num: int, cells: List[str]):
|
|
||||||
self.line_num = line_num
|
|
||||||
self.cells = cells
|
|
||||||
|
|
||||||
|
|
||||||
class ParsedTable:
|
|
||||||
def __init__(self, line_num: int, header: List[str], rows: List[TableRow]):
|
|
||||||
self.line_num = line_num
|
|
||||||
self.header = header
|
|
||||||
self.rows = rows
|
|
||||||
|
|
||||||
|
|
||||||
def split_cells(line: str) -> List[str]:
|
|
||||||
text = line.strip()
|
|
||||||
if text.startswith("|"):
|
|
||||||
text = text[1:]
|
|
||||||
if text.endswith("|") and not text.endswith(r"\|"):
|
|
||||||
text = text[:-1]
|
|
||||||
# Split on unescaped pipe
|
|
||||||
raw_cells = re.split(r"(?<!\\)\|", text)
|
|
||||||
return [c.replace(r"\|", "|").strip() for c in raw_cells]
|
|
||||||
|
|
||||||
|
|
||||||
def parse_tables(lines: List[str]) -> List[ParsedTable]:
|
|
||||||
result: List[ParsedTable] = []
|
|
||||||
i = 0
|
|
||||||
while i < len(lines):
|
|
||||||
line = lines[i].strip()
|
|
||||||
if i + 1 < len(lines):
|
|
||||||
separator = lines[i + 1].strip()
|
|
||||||
if line.startswith("|") and "-" in separator and re.match(r"^[|\-: ]+$", separator):
|
|
||||||
header = split_cells(line)
|
|
||||||
table = ParsedTable(line_num=i + 1, header=header, rows=[])
|
|
||||||
i += 2
|
|
||||||
while i < len(lines) and lines[i].strip().startswith("|"):
|
|
||||||
table.rows.append(TableRow(line_num=i + 1, cells=split_cells(lines[i])))
|
|
||||||
i += 1
|
|
||||||
result.append(table)
|
|
||||||
continue
|
|
||||||
i += 1
|
|
||||||
return result
|
|
||||||
|
|
||||||
|
|
||||||
def extract_numeric(text: str, is_percent: bool = False) -> Optional[float]:
|
|
||||||
pattern = r"(\d+(?:\.\d+)?)\s*%" if is_percent else r"(\d+(?:\.\d+)?)"
|
|
||||||
m = re.search(pattern, text)
|
|
||||||
if m:
|
|
||||||
try:
|
|
||||||
return float(m.group(1))
|
|
||||||
except ValueError:
|
|
||||||
return None
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
def validate_report(filepath: str) -> Dict[str, Any]:
|
|
||||||
path = Path(filepath).resolve()
|
|
||||||
if not path.is_file():
|
|
||||||
return {
|
|
||||||
"file": str(path),
|
|
||||||
"valid": False,
|
|
||||||
"tables": 0,
|
|
||||||
"figures": 0,
|
|
||||||
"issues": [{"level": "ERROR", "code": "FS001", "message": f"文件不存在: {filepath}"}],
|
|
||||||
}
|
|
||||||
|
|
||||||
with open(path, "r", encoding="utf-8") as f:
|
|
||||||
text = f.read().replace("\r\n", "\n").replace("\r", "\n")
|
|
||||||
|
|
||||||
lines = text.split("\n")
|
|
||||||
issues: List[ReportIssue] = []
|
|
||||||
|
|
||||||
def add_error(code: str, message: str, line: Optional[int] = None):
|
|
||||||
issues.append(ReportIssue(level="ERROR", code=code, message=message, line=line))
|
|
||||||
|
|
||||||
# 1. 纯净性:严禁 Frontmatter 和 模板草稿占位标记
|
|
||||||
if text.startswith("---\n"):
|
|
||||||
add_error("FM001", "文件以 YAML frontmatter 开头;元数据请放正文开头的「报告信息」表格中", line=1)
|
|
||||||
for pattern, name in FORBIDDEN_MARKS:
|
|
||||||
for idx, l in enumerate(lines, start=1):
|
|
||||||
if pattern.search(l):
|
|
||||||
add_error("MK001", f"出现模板未渲染痕迹({name}),交付文件应为纯 Markdown 文档", line=idx)
|
|
||||||
|
|
||||||
# 2. 代码围栏成对闭合
|
|
||||||
fences = [idx for idx, l in enumerate(lines, start=1) if l.strip().startswith("```")]
|
|
||||||
if len(fences) % 2 != 0:
|
|
||||||
add_error("MD001", f"代码围栏为奇数(共 {len(fences)} 个),存在未闭合代码块", line=fences[-1] if fences else None)
|
|
||||||
|
|
||||||
# 3. 表格结构规范(列对齐、表头无加粗)
|
|
||||||
parsed_tables = parse_tables(lines)
|
|
||||||
for table in parsed_tables:
|
|
||||||
header_len = len(table.header)
|
|
||||||
for row in table.rows:
|
|
||||||
if len(row.cells) != header_len:
|
|
||||||
add_error("TB001", f"第 {row.line_num} 行表格列数 {len(row.cells)} ≠ 表头 {header_len} 列", line=row.line_num)
|
|
||||||
for cell in table.header:
|
|
||||||
if "**" in cell:
|
|
||||||
add_error("TB002", f"第 {table.line_num} 行表头含有加粗标记 **(表头应保持纯文本)", line=table.line_num)
|
|
||||||
|
|
||||||
# 4. 标题层级与章节序号连续性
|
|
||||||
previous_level = 0
|
|
||||||
numbered_h2s: List[Tuple[int, str, int]] = [] # (chapter_num, full_heading, line_num)
|
|
||||||
chapters: List[Dict[str, Any]] = []
|
|
||||||
|
|
||||||
for idx, l in enumerate(lines, start=1):
|
|
||||||
m = re.match(r"^(#{1,6})\s+(.*)$", l)
|
|
||||||
if not m:
|
|
||||||
continue
|
|
||||||
level = len(m.group(1))
|
|
||||||
heading_text = m.group(2).strip()
|
|
||||||
if previous_level > 0 and level > previous_level + 1:
|
|
||||||
add_error("HD001", f"标题层级跳级(从 H{previous_level} 直接跳到 H{level}):{heading_text[:40]}", line=idx)
|
|
||||||
previous_level = level
|
|
||||||
|
|
||||||
if level == 2:
|
|
||||||
num_match = re.match(r"^(\d+)\.", heading_text)
|
|
||||||
if num_match:
|
|
||||||
numbered_h2s.append((int(num_match.group(1)), heading_text, idx))
|
|
||||||
chapters.append({"heading": heading_text, "start_line": idx, "line_num": idx})
|
|
||||||
|
|
||||||
# 检查大标题数字是否严格连续递增:1, 2, 3...
|
|
||||||
if numbered_h2s:
|
|
||||||
seen_nums = [item[0] for item in numbered_h2s]
|
|
||||||
expected_nums = list(range(1, len(seen_nums) + 1))
|
|
||||||
if seen_nums != expected_nums:
|
|
||||||
add_error("HD002", f"## 大章节编号应自 1 开始连续递增,期望 {expected_nums},实际 {seen_nums}", line=numbered_h2s[0][2])
|
|
||||||
|
|
||||||
# 为每个大章节划分文本切片(从当前 ## 到下一个 ##)
|
|
||||||
for i, chap in enumerate(chapters):
|
|
||||||
start_idx = chap["start_line"] - 1
|
|
||||||
end_idx = chapters[i + 1]["start_line"] - 1 if i + 1 < len(chapters) else len(lines)
|
|
||||||
chap["text"] = "\n".join(lines[start_idx:end_idx])
|
|
||||||
|
|
||||||
def find_chapter_by_keyword(kw: str) -> Optional[Dict[str, Any]]:
|
|
||||||
for c in chapters:
|
|
||||||
if kw in c["heading"]:
|
|
||||||
return c
|
|
||||||
return None
|
|
||||||
|
|
||||||
def by_header_in_scope(keyword: str, scope_lines: Optional[List[str]] = None) -> Optional[ParsedTable]:
|
|
||||||
target_tables = parse_tables(scope_lines) if scope_lines is not None else parsed_tables
|
|
||||||
for t in target_tables:
|
|
||||||
header_str = "".join(t.header).replace(" ", "")
|
|
||||||
if keyword in header_str:
|
|
||||||
return t
|
|
||||||
return None
|
|
||||||
|
|
||||||
# 5. 开篇「报告信息」表完备性
|
|
||||||
info_table = by_header_in_scope("报告信息")
|
|
||||||
if not info_table:
|
|
||||||
add_error("INFO001", "缺少开篇「报告信息」表(必须包含客户名称、期间、报告编号等元数据)")
|
|
||||||
else:
|
|
||||||
existing_keys = {r.cells[0] for r in info_table.rows if r.cells}
|
|
||||||
missing_keys = [k for k in REQUIRED_INFO_ROWS if k not in existing_keys]
|
|
||||||
if missing_keys:
|
|
||||||
add_error("INFO001", f"「报告信息」表缺少必要字段:{', '.join(missing_keys)}", line=info_table.line_num)
|
|
||||||
empty_keys = [r.cells[0] for r in info_table.rows if len(r.cells) > 1 and not r.cells[1].strip()]
|
|
||||||
if empty_keys:
|
|
||||||
add_error("INFO002", f"「报告信息」表以下字段值为空:{', '.join(empty_keys)}", line=info_table.line_num)
|
|
||||||
|
|
||||||
# 6. 本地图片资产存活性
|
|
||||||
figure_count = 0
|
|
||||||
for idx, l in enumerate(lines, start=1):
|
|
||||||
for img_match in re.finditer(r"!\[[^\]]*\]\(([^)]+)\)", l):
|
|
||||||
figure_count += 1
|
|
||||||
src = img_match.group(1).strip()
|
|
||||||
if src.startswith("http://") or src.startswith("https://") or src.startswith("data:"):
|
|
||||||
continue
|
|
||||||
# 解码 URL 编码的中文路径
|
|
||||||
try:
|
|
||||||
import urllib.parse
|
|
||||||
decoded_src = urllib.parse.unquote(src)
|
|
||||||
except Exception:
|
|
||||||
decoded_src = src
|
|
||||||
target_path = (path.parent / decoded_src).resolve()
|
|
||||||
if not target_path.exists():
|
|
||||||
add_error("IMG001", f"本地引用的图片文件不存在:{src}", line=idx)
|
|
||||||
|
|
||||||
# 7. 核心业务章节硬匹配校验与数学总账守恒
|
|
||||||
|
|
||||||
# 7.1 【AI 失准分析】核心章节
|
|
||||||
mismatch_chapter = find_chapter_by_keyword("失准")
|
|
||||||
if mismatch_chapter:
|
|
||||||
c_lines = mismatch_chapter["text"].split("\n")
|
|
||||||
table = by_header_in_scope("失准类型", c_lines)
|
|
||||||
if table:
|
|
||||||
tops = []
|
|
||||||
totals = []
|
|
||||||
for r in table.rows:
|
|
||||||
if len(r.cells) > 3:
|
|
||||||
if r.cells[0].startswith("TOP"):
|
|
||||||
tops.append({"name": r.cells[0], "count": extract_numeric(r.cells[3])})
|
|
||||||
elif r.cells[0] in ["合计", "总计", "—"]:
|
|
||||||
totals.append(extract_numeric(r.cells[3]))
|
|
||||||
if tops and totals and totals[0] is not None and all(t["count"] is not None for t in tops):
|
|
||||||
s = sum(t["count"] for t in tops if t["count"] is not None)
|
|
||||||
if s != totals[0]:
|
|
||||||
add_error("NM001", f"失准类型各维度单数之和 {s} ≠ 合计 {totals[0]}", line=table.line_num)
|
|
||||||
base = totals[0]
|
|
||||||
for r in table.rows:
|
|
||||||
if len(r.cells) >= 4 and r.cells[0].startswith("TOP"):
|
|
||||||
share = extract_numeric(r.cells[2], is_percent=True)
|
|
||||||
count = extract_numeric(r.cells[3])
|
|
||||||
if share is not None and count is not None and base > 0:
|
|
||||||
calc_share = (count / base) * 100
|
|
||||||
if abs(calc_share - share) > 0.15:
|
|
||||||
add_error("NM003", f"失准类型「{r.cells[1]}」占比 {share}% ≠ {int(count)}/{int(base)} = {calc_share:.1f}%", line=r.line_num)
|
|
||||||
# 校验小节标题张数与总览表严格一致
|
|
||||||
for top in tops:
|
|
||||||
esc = re.escape(top["name"])
|
|
||||||
m = re.search(rf"###\s*\S*\s*{esc}[^(\n]*((\d+)\s*张", mismatch_chapter["text"])
|
|
||||||
if m and top["count"] is not None:
|
|
||||||
c_in_h = int(m.group(1))
|
|
||||||
if c_in_h != int(top["count"]):
|
|
||||||
add_error("NM001", f"失准分析 {top['name']} 小节标题写 {c_in_h} 张,总览表写 {int(top['count'])} 张")
|
|
||||||
|
|
||||||
# 7.2 【AI 发现的潜在风险】核心章节
|
|
||||||
risk_chapter = find_chapter_by_keyword("风险")
|
|
||||||
if risk_chapter:
|
|
||||||
c_lines = risk_chapter["text"].split("\n")
|
|
||||||
table = by_header_in_scope("风险类型", c_lines)
|
|
||||||
if table:
|
|
||||||
tops = []
|
|
||||||
totals = []
|
|
||||||
for r in table.rows:
|
|
||||||
if len(r.cells) > 3:
|
|
||||||
if r.cells[0].startswith("TOP"):
|
|
||||||
tops.append({"name": r.cells[0], "count": extract_numeric(r.cells[3])})
|
|
||||||
elif r.cells[0] in ["合计", "总计", "—"]:
|
|
||||||
totals.append(extract_numeric(r.cells[3]))
|
|
||||||
if tops and totals and totals[0] is not None and all(t["count"] is not None for t in tops):
|
|
||||||
s = sum(t["count"] for t in tops if t["count"] is not None)
|
|
||||||
if s != totals[0]:
|
|
||||||
add_error("NM002", f"风险类型各维度单数之和 {s} ≠ 合计 {totals[0]}", line=table.line_num)
|
|
||||||
base = totals[0]
|
|
||||||
for r in table.rows:
|
|
||||||
if len(r.cells) >= 4 and r.cells[0].startswith("TOP"):
|
|
||||||
share = extract_numeric(r.cells[2], is_percent=True)
|
|
||||||
count = extract_numeric(r.cells[3])
|
|
||||||
if share is not None and count is not None and base > 0:
|
|
||||||
calc_share = (count / base) * 100
|
|
||||||
if abs(calc_share - share) > 0.15:
|
|
||||||
add_error("NM003", f"风险类型「{r.cells[1]}」占比 {share}% ≠ {int(count)}/{int(base)} = {calc_share:.1f}%", line=r.line_num)
|
|
||||||
for top in tops:
|
|
||||||
esc = re.escape(top["name"])
|
|
||||||
m = re.search(rf"###\s*\S*\s*{esc}[^(\n]*((\d+)\s*张", risk_chapter["text"])
|
|
||||||
if m and top["count"] is not None:
|
|
||||||
c_in_h = int(m.group(1))
|
|
||||||
if c_in_h != int(top["count"]):
|
|
||||||
add_error("NM002", f"潜在风险 {top['name']} 小节标题写 {c_in_h} 张,总览表写 {int(top['count'])} 张")
|
|
||||||
|
|
||||||
# 7.3 【审核分歧与复核归因】核心章节
|
|
||||||
diverged_chapter = find_chapter_by_keyword("分歧") or find_chapter_by_keyword("复核归因")
|
|
||||||
if diverged_chapter:
|
|
||||||
c_lines = diverged_chapter["text"].split("\n")
|
|
||||||
table = by_header_in_scope("原因分类", c_lines)
|
|
||||||
if table:
|
|
||||||
count_idx = -1
|
|
||||||
for ci, col in enumerate(table.header):
|
|
||||||
if "单数" in col:
|
|
||||||
count_idx = ci
|
|
||||||
break
|
|
||||||
if count_idx >= 0:
|
|
||||||
rows = [r.cells for r in table.rows]
|
|
||||||
non_totals = [r for r in rows if r and r[0] not in ["合计", "总计", "—"]]
|
|
||||||
total_row = next((r for r in rows if r and r[0] in ["合计", "总计", "—"]), None)
|
|
||||||
s = sum(extract_numeric(r[count_idx]) or 0 for r in non_totals if len(r) > count_idx)
|
|
||||||
if total_row and len(total_row) > count_idx:
|
|
||||||
tv = extract_numeric(total_row[count_idx])
|
|
||||||
if tv is not None and s != tv:
|
|
||||||
add_error("NM004", f"原因分类各维度单数之和 {s} ≠ 合计 {tv}", line=table.line_num)
|
|
||||||
|
|
||||||
# 7.4 LaTeX 公式算术自洽
|
|
||||||
formula_lines = [l for l in lines if l.strip().startswith("$$")]
|
|
||||||
outside_text = "\n".join([l for l in lines if not l.strip().startswith("$$")])
|
|
||||||
for fl in formula_lines:
|
|
||||||
for frac_match in re.finditer(r"\\frac\{(\d+)\}\{(\d+)\}\s*=\s*([\d.]+)\\%", fl):
|
|
||||||
a = int(frac_match.group(1))
|
|
||||||
b = int(frac_match.group(2))
|
|
||||||
pct_val = float(frac_match.group(3))
|
|
||||||
if b > 0:
|
|
||||||
real_pct = (a / b) * 100
|
|
||||||
if abs(real_pct - pct_val) > 0.05:
|
|
||||||
add_error("NM005", f"公式 \\frac{{{a}}}{{{b}}} = {pct_val}% 算术不成立(实为 {real_pct:.2f}%)")
|
|
||||||
for num_token in re.findall(r"\d+(?:\.\d+)?", fl):
|
|
||||||
if num_token not in outside_text:
|
|
||||||
add_error("NM005", f"公式中的数值 {num_token} 在正文别处找不到,可能与实际数据脱节")
|
|
||||||
|
|
||||||
return {
|
|
||||||
"file": str(path),
|
|
||||||
"valid": len(issues) == 0,
|
|
||||||
"tables": len(parsed_tables),
|
|
||||||
"figures": figure_count,
|
|
||||||
"issues": [i.to_dict() for i in issues],
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
|
||||||
if len(sys.argv) < 2 or sys.argv[1] in ["-h", "--help"]:
|
|
||||||
print("用法: python3 validate.py <report.md> [--json]")
|
|
||||||
print("说明: 离线静态校验 AI 审核报告 Markdown 文档的结构纯净度与数学总账守恒。")
|
|
||||||
sys.exit(0)
|
|
||||||
|
|
||||||
target_file = sys.argv[1]
|
|
||||||
is_json = "--json" in sys.argv
|
|
||||||
|
|
||||||
result = validate_report(target_file)
|
|
||||||
|
|
||||||
if is_json:
|
|
||||||
print(json.dumps(result, ensure_ascii=False, indent=2))
|
|
||||||
else:
|
|
||||||
status_symbol = "✅" if result["valid"] else "❌"
|
|
||||||
print(f"\n{status_symbol} 报告文件: {result['file']}")
|
|
||||||
print(f"📊 识别表格: {result['tables']} 个 | 配图资产: {result['figures']} 个")
|
|
||||||
|
|
||||||
if result["valid"]:
|
|
||||||
print("🎉 恭喜!报告结构完全合规,所有分类总览表、小节张数与数学公式严密闭环,无任何格式缺陷。\n")
|
|
||||||
sys.exit(0)
|
|
||||||
else:
|
|
||||||
print(f"⚠️ 发现 {len(result['issues'])} 项格式或勾稽问题,必须修正后方可交付:\n")
|
|
||||||
for i, issue in enumerate(result["issues"], 1):
|
|
||||||
loc = f" [第 {issue['line']} 行]" if "line" in issue else ""
|
|
||||||
print(f" {i}. [{issue['code']}]{loc} {issue['message']}")
|
|
||||||
print("\n💡 提示:请根据上述提示调整对应行的数字或表格结构,直至校验通过。\n")
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
main()
|
|
||||||
@@ -154,7 +154,7 @@ flowchart TD
|
|||||||
- 对账知识库文档(覆盖更新已有文档、创建新文档、删除测试环境多余文档);
|
- 对账知识库文档(覆盖更新已有文档、创建新文档、删除测试环境多余文档);
|
||||||
- 清空测试环境旧草稿规则,灌入生产企业当前草稿规则并重算 code;
|
- 清空测试环境旧草稿规则,灌入生产企业当前草稿规则并重算 code;
|
||||||
- **自动同步合思集成**:
|
- **自动同步合思集成**:
|
||||||
- 从本地 source 读入 `appKey`/`appSecurity`(兼容 `key`/`password`);
|
- 从本地 source 读入 `appKey`/`appSecurity`;
|
||||||
- 截取企业名前缀并附加 `(Seal测)`(严格受控于 13 字符限制,例如 `钰泰半导体(Seal测)`);
|
- 截取企业名前缀并附加 `(Seal测)`(严格受控于 13 字符限制,例如 `钰泰半导体(Seal测)`);
|
||||||
- 强制将审批模式设为 `assisted`;
|
- 强制将审批模式设为 `assisted`;
|
||||||
- 自动去重:若生产有多个相同 `corporationId` 的集成(如全自动与辅助),在测试环境自动合并为单条辅助集成;
|
- 自动去重:若生产有多个相同 `corporationId` 的集成(如全自动与辅助),在测试环境自动合并为单条辅助集成;
|
||||||
|
|||||||
@@ -175,11 +175,11 @@ export async function handleAuthCommand(action: string | undefined, corp: CorpCo
|
|||||||
2
|
2
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
const appKey = corp.source.appKey ?? corp.source.key;
|
const appKey = corp.source.appKey;
|
||||||
const appSecurity = corp.source.appSecurity ?? corp.source.password;
|
const appSecurity = corp.source.appSecurity;
|
||||||
if (!appKey || !appSecurity) {
|
if (!appKey || !appSecurity) {
|
||||||
throw validationError(
|
throw validationError(
|
||||||
`缺少合思凭证:企业「${corp.name}」(id: ${corp.id}) 未配置 appKey/appSecurity(或 key/password),无法向合思 OpenAPI 签发 accessToken。`
|
`缺少合思凭证:企业「${corp.name}」(id: ${corp.id}) 未配置 appKey/appSecurity,无法向合思 OpenAPI 签发 accessToken。`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
const force =
|
const force =
|
||||||
@@ -237,8 +237,8 @@ async function diagnoseAuth(corp: CorpConfig) {
|
|||||||
|
|
||||||
clearCorpTokenCache(corp.id);
|
clearCorpTokenCache(corp.id);
|
||||||
const source = corp.source;
|
const source = corp.source;
|
||||||
const appKey = source.appKey ?? source.key;
|
const appKey = source.appKey;
|
||||||
const appSecurity = source.appSecurity ?? source.password;
|
const appSecurity = source.appSecurity;
|
||||||
const sealUrl = (corp.seal.url ?? source.sealUrl ?? `https://${source.corpId.toLowerCase()}.sealai.cc`).replace(/\/+$/, "");
|
const sealUrl = (corp.seal.url ?? source.sealUrl ?? `https://${source.corpId.toLowerCase()}.sealai.cc`).replace(/\/+$/, "");
|
||||||
const uid = source.staffId.includes(":") ? source.staffId : `${source.corpId}:${source.staffId}`;
|
const uid = source.staffId.includes(":") ? source.staffId : `${source.corpId}:${source.staffId}`;
|
||||||
const stages: Array<Record<string, unknown>> = [];
|
const stages: Array<Record<string, unknown>> = [];
|
||||||
@@ -255,7 +255,7 @@ async function diagnoseAuth(corp: CorpConfig) {
|
|||||||
{
|
{
|
||||||
name: "hose.openapi",
|
name: "hose.openapi",
|
||||||
ok: false,
|
ok: false,
|
||||||
error: "Hose source requires appKey/key and appSecurity/password"
|
error: "Hose source requires appKey and appSecurity"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -739,9 +739,10 @@ describe("sync-test hosecloud integration auto-sync", () => {
|
|||||||
expect(writtenIntegrations[0].apiOrigin).toBe("wechat");
|
expect(writtenIntegrations[0].apiOrigin).toBe("wechat");
|
||||||
});
|
});
|
||||||
|
|
||||||
test("supports key/password fallback in source config when appKey/appSecurity are omitted", async () => {
|
test("rejects legacy key/password source config instead of falling back", async () => {
|
||||||
const { enterprises } = setupHoseTestEnv();
|
const { enterprises } = setupHoseTestEnv();
|
||||||
// Overwrite hose-prod.json to use key / password instead of appKey / appSecurity
|
// Legacy key/password aliases are no longer part of the schema; the file
|
||||||
|
// must be skipped on load rather than silently used for sync.
|
||||||
const prodCorpWithKeyPassword = JSON.parse(readFileSync(join(enterprises, "hose-prod.json"), "utf-8"));
|
const prodCorpWithKeyPassword = JSON.parse(readFileSync(join(enterprises, "hose-prod.json"), "utf-8"));
|
||||||
delete prodCorpWithKeyPassword.source.appKey;
|
delete prodCorpWithKeyPassword.source.appKey;
|
||||||
delete prodCorpWithKeyPassword.source.appSecurity;
|
delete prodCorpWithKeyPassword.source.appSecurity;
|
||||||
@@ -749,25 +750,8 @@ describe("sync-test hosecloud integration auto-sync", () => {
|
|||||||
prodCorpWithKeyPassword.source.password = "fallback-secret-012";
|
prodCorpWithKeyPassword.source.password = "fallback-secret-012";
|
||||||
writeFileSync(join(enterprises, "hose-prod.json"), JSON.stringify(prodCorpWithKeyPassword, null, 2));
|
writeFileSync(join(enterprises, "hose-prod.json"), JSON.stringify(prodCorpWithKeyPassword, null, 2));
|
||||||
|
|
||||||
await runCli(["corps", "bind-test", "hose-prod", "hose-test", "--confirm"]);
|
const result = await runCli(["corps", "get", "hose-prod"]);
|
||||||
|
expect(result.isError).toBe(true);
|
||||||
let capturedBody: any;
|
|
||||||
mockHoseSyncRequests({
|
|
||||||
onConfigWrite: (isProd, body) => {
|
|
||||||
if (!isProd) capturedBody = body;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
const result = await runCli(["corps", "sync-test", "hose-prod", "--yes"]);
|
|
||||||
expect(result.isError).toBe(false);
|
|
||||||
|
|
||||||
const parsed = JSON.parse(result.stdout);
|
|
||||||
expect(parsed.hosecloudSync.skipped).toBe(false);
|
|
||||||
expect(parsed.hosecloudSync.synced).toHaveLength(1);
|
|
||||||
|
|
||||||
const writtenIntegration = capturedBody?.integrations?.find((i: any) => i.type === "hosecloud");
|
|
||||||
expect(writtenIntegration?.apiKey).toBe("fallback-key-789");
|
|
||||||
expect(writtenIntegration?.apiSecret).toBe("fallback-secret-012");
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -409,8 +409,8 @@ export async function showCorpKeysAction(targetCorpId: string | undefined, optio
|
|||||||
throw new CliError(`【合思子域专享能力】当前企业「${corp.name}」(id: ${corp.id}) 为原生 Seal (${corp.source.type}) 租户,非合思 (Hose/合思云/易快报) 渠道企业。\n` +
|
throw new CliError(`【合思子域专享能力】当前企业「${corp.name}」(id: ${corp.id}) 为原生 Seal (${corp.source.type}) 租户,非合思 (Hose/合思云/易快报) 渠道企业。\n` +
|
||||||
"OpenAPI 密钥查询与提权能力专属于合思生态租户(用于从合思协助链接或合思凭据中提取开发者密钥提升权限等级),非合思渠道企业不支持此能力。", 2);
|
"OpenAPI 密钥查询与提权能力专属于合思生态租户(用于从合思协助链接或合思凭据中提取开发者密钥提升权限等级),非合思渠道企业不支持此能力。", 2);
|
||||||
}
|
}
|
||||||
const appKey = corp.source.appKey ?? corp.source.key;
|
const appKey = corp.source.appKey;
|
||||||
const appSecurity = corp.source.appSecurity ?? corp.source.password;
|
const appSecurity = corp.source.appSecurity;
|
||||||
if (!reveal) console.error("💡 [合思子域] 接入密码默认脱敏,附加 --reveal (或 -r) 可查看完整 appSecurity 明文。\n");
|
if (!reveal) console.error("💡 [合思子域] 接入密码默认脱敏,附加 --reveal (或 -r) 可查看完整 appSecurity 明文。\n");
|
||||||
else console.error("⚠️ [合思子域] 正在以明文展示合思 appSecurity 接入密码,请妥善保管敏感凭据。\n");
|
else console.error("⚠️ [合思子域] 正在以明文展示合思 appSecurity 接入密码,请妥善保管敏感凭据。\n");
|
||||||
printJson({
|
printJson({
|
||||||
|
|||||||
@@ -20,14 +20,14 @@ export function resolveCorpSealUrl(corp: CorpConfig): string | undefined {
|
|||||||
|
|
||||||
export function formatSafeSourceDetail(source: SealSource) {
|
export function formatSafeSourceDetail(source: SealSource) {
|
||||||
if (source.type === "hose") {
|
if (source.type === "hose") {
|
||||||
const key = source.appKey ?? source.key;
|
const key = source.appKey;
|
||||||
return {
|
return {
|
||||||
type: "hose",
|
type: "hose",
|
||||||
domain: source.domain,
|
domain: source.domain,
|
||||||
corpId: source.corpId,
|
corpId: source.corpId,
|
||||||
staffId: source.staffId,
|
staffId: source.staffId,
|
||||||
appKey: maskSecret(key),
|
appKey: maskSecret(key),
|
||||||
hasAppSecurity: Boolean(source.appSecurity ?? source.password),
|
hasAppSecurity: Boolean(source.appSecurity),
|
||||||
hasCloseToken: Boolean(source.closeToken),
|
hasCloseToken: Boolean(source.closeToken),
|
||||||
closeTokenExpiresIn: source.closeToken ? source.expiresIn : undefined,
|
closeTokenExpiresIn: source.closeToken ? source.expiresIn : undefined,
|
||||||
closeTokenExpiresAt: source.closeToken ? source.expiresAt : undefined,
|
closeTokenExpiresAt: source.closeToken ? source.expiresAt : undefined,
|
||||||
|
|||||||
@@ -274,8 +274,8 @@ function hoseClient(source: HoseSealSource): KyInstance {
|
|||||||
|
|
||||||
async function fetchHoseOpenapiToken(source: HoseSealSource): Promise<TokenEntry> {
|
async function fetchHoseOpenapiToken(source: HoseSealSource): Promise<TokenEntry> {
|
||||||
const client = hoseClient(source);
|
const client = hoseClient(source);
|
||||||
const appKey = source.appKey ?? source.key;
|
const appKey = source.appKey;
|
||||||
const appSecurity = source.appSecurity ?? source.password;
|
const appSecurity = source.appSecurity;
|
||||||
|
|
||||||
if (!appKey || !appSecurity) {
|
if (!appKey || !appSecurity) {
|
||||||
throw new Error("Hose source has no OpenAPI credentials; the configured closeToken is only valid for Hose web-session APIs");
|
throw new Error("Hose source has no OpenAPI credentials; the configured closeToken is only valid for Hose web-session APIs");
|
||||||
|
|||||||
@@ -16,8 +16,10 @@ import {
|
|||||||
} from "./token-store.js";
|
} from "./token-store.js";
|
||||||
|
|
||||||
const originalFetch = globalThis.fetch;
|
const originalFetch = globalThis.fetch;
|
||||||
|
const ORIGINAL_ENTERPRISES_DIR = process.env.SEAL_USE_ENTERPRISES_DIR;
|
||||||
let tempDir: string;
|
let tempDir: string;
|
||||||
let storePath: string;
|
let storePath: string;
|
||||||
|
let enterprisesDir: string;
|
||||||
|
|
||||||
const fixtureCorp: CorpConfig = {
|
const fixtureCorp: CorpConfig = {
|
||||||
id: "test-delegate-corp",
|
id: "test-delegate-corp",
|
||||||
@@ -47,7 +49,12 @@ describe("seal-renew: 原生 Seal 协助授权长效续期与会话池救险", (
|
|||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
tempDir = mkdtempSync(join(tmpdir(), "seal-renew-test-"));
|
tempDir = mkdtempSync(join(tmpdir(), "seal-renew-test-"));
|
||||||
storePath = join(tempDir, "tokens.json");
|
storePath = join(tempDir, "tokens.json");
|
||||||
|
enterprisesDir = join(tempDir, "enterprises");
|
||||||
process.env.SEAL_USE_TOKEN_STORE = storePath;
|
process.env.SEAL_USE_TOKEN_STORE = storePath;
|
||||||
|
// renewNativeSealSession writes the renewed token back through
|
||||||
|
// saveCorpConfig; keep that write inside the sandbox so tests never
|
||||||
|
// touch the real ~/.config/seal-use/enterprises directory.
|
||||||
|
process.env.SEAL_USE_ENTERPRISES_DIR = enterprisesDir;
|
||||||
clearSealToken(fixtureCorp.id);
|
clearSealToken(fixtureCorp.id);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -55,6 +62,11 @@ describe("seal-renew: 原生 Seal 协助授权长效续期与会话池救险", (
|
|||||||
globalThis.fetch = originalFetch;
|
globalThis.fetch = originalFetch;
|
||||||
clearSealToken(fixtureCorp.id);
|
clearSealToken(fixtureCorp.id);
|
||||||
delete process.env.SEAL_USE_TOKEN_STORE;
|
delete process.env.SEAL_USE_TOKEN_STORE;
|
||||||
|
if (ORIGINAL_ENTERPRISES_DIR === undefined) {
|
||||||
|
delete process.env.SEAL_USE_ENTERPRISES_DIR;
|
||||||
|
} else {
|
||||||
|
process.env.SEAL_USE_ENTERPRISES_DIR = ORIGINAL_ENTERPRISES_DIR;
|
||||||
|
}
|
||||||
rmSync(tempDir, { recursive: true, force: true });
|
rmSync(tempDir, { recursive: true, force: true });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -8,10 +8,33 @@ import {
|
|||||||
import { isCorpActive } from "./active.js";
|
import { isCorpActive } from "./active.js";
|
||||||
|
|
||||||
describe("CorpConfigSchema", () => {
|
describe("CorpConfigSchema", () => {
|
||||||
test("accepts Hose key/password aliases", () => {
|
test("accepts Hose appKey/appSecurity credentials", () => {
|
||||||
const config = CorpConfigSchema.parse({
|
const config = CorpConfigSchema.parse({
|
||||||
id: "corp-local",
|
id: "corp-local",
|
||||||
name: "Local Corp",
|
name: "Local Corp",
|
||||||
|
source: {
|
||||||
|
type: "hose",
|
||||||
|
domain: "https://app.ekuaibao.com",
|
||||||
|
appKey: "app-key",
|
||||||
|
appSecurity: "app-security",
|
||||||
|
corpId: "ID01",
|
||||||
|
staffId: "ID01:STAFF01"
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(config.source.type).toBe("hose");
|
||||||
|
if (config.source.type !== "hose") {
|
||||||
|
throw new Error("expected hose source");
|
||||||
|
}
|
||||||
|
expect(config.source.appKey).toBe("app-key");
|
||||||
|
expect(config.source.appSecurity).toBe("app-security");
|
||||||
|
expect(config.auth.refreshTtl).toBe(300);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("rejects legacy key/password aliases", () => {
|
||||||
|
const result = CorpConfigSchema.safeParse({
|
||||||
|
id: "corp-legacy",
|
||||||
|
name: "Legacy Corp",
|
||||||
source: {
|
source: {
|
||||||
type: "hose",
|
type: "hose",
|
||||||
domain: "https://app.ekuaibao.com",
|
domain: "https://app.ekuaibao.com",
|
||||||
@@ -22,13 +45,7 @@ describe("CorpConfigSchema", () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(config.source.type).toBe("hose");
|
expect(result.success).toBe(false);
|
||||||
if (config.source.type !== "hose") {
|
|
||||||
throw new Error("expected hose source");
|
|
||||||
}
|
|
||||||
expect(config.source.key).toBe("app-key");
|
|
||||||
expect(config.source.password).toBe("app-security");
|
|
||||||
expect(config.auth.refreshTtl).toBe(300);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("requires a Hose key and secret", () => {
|
test("requires a Hose key and secret", () => {
|
||||||
|
|||||||
@@ -11,8 +11,6 @@ export const HoseSealSourceSchema = z.object({
|
|||||||
domain: z.string().url().default("https://app.ekuaibao.com"),
|
domain: z.string().url().default("https://app.ekuaibao.com"),
|
||||||
appKey: z.string().optional(),
|
appKey: z.string().optional(),
|
||||||
appSecurity: z.string().optional(),
|
appSecurity: z.string().optional(),
|
||||||
key: z.string().optional(),
|
|
||||||
password: z.string().optional(),
|
|
||||||
closeToken: z.string().optional(),
|
closeToken: z.string().optional(),
|
||||||
expiresIn: z.number().int().positive().optional(),
|
expiresIn: z.number().int().positive().optional(),
|
||||||
expiresAt: IsoSecondTimestampSchema.optional(),
|
expiresAt: IsoSecondTimestampSchema.optional(),
|
||||||
@@ -20,19 +18,19 @@ export const HoseSealSourceSchema = z.object({
|
|||||||
corpId: z.string(),
|
corpId: z.string(),
|
||||||
sealUrl: z.string().url().optional()
|
sealUrl: z.string().url().optional()
|
||||||
}).superRefine((source, ctx) => {
|
}).superRefine((source, ctx) => {
|
||||||
if (!source.closeToken && !source.appKey && !source.key) {
|
if (!source.closeToken && !source.appKey) {
|
||||||
ctx.addIssue({
|
ctx.addIssue({
|
||||||
code: "custom",
|
code: "custom",
|
||||||
path: ["appKey"],
|
path: ["appKey"],
|
||||||
message: "Hose source requires appKey/key or closeToken"
|
message: "Hose source requires appKey or closeToken"
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!source.closeToken && !source.appSecurity && !source.password) {
|
if (!source.closeToken && !source.appSecurity) {
|
||||||
ctx.addIssue({
|
ctx.addIssue({
|
||||||
code: "custom",
|
code: "custom",
|
||||||
path: ["appSecurity"],
|
path: ["appSecurity"],
|
||||||
message: "Hose source requires appSecurity/password or closeToken"
|
message: "Hose source requires appSecurity or closeToken"
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -42,11 +42,11 @@ export async function executeEbotApprovalCallback(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const appKey = corp.source.appKey ?? corp.source.key;
|
const appKey = corp.source.appKey;
|
||||||
const appSecurity = corp.source.appSecurity ?? corp.source.password;
|
const appSecurity = corp.source.appSecurity;
|
||||||
if (!appKey || !appSecurity) {
|
if (!appKey || !appSecurity) {
|
||||||
throw validationError(
|
throw validationError(
|
||||||
`缺少合思凭证:企业「${corp.name}」(id: ${corp.id}) 未配置 appKey/appSecurity(或 key/password),无法换取 accessToken 执行审批回调。`
|
`缺少合思凭证:企业「${corp.name}」(id: ${corp.id}) 未配置 appKey/appSecurity,无法换取 accessToken 执行审批回调。`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -318,9 +318,9 @@ interface HosecloudSyncResult {
|
|||||||
|
|
||||||
async function syncHosecloudIntegrationsToTest(prodCorp: CorpConfig, testCorp: CorpConfig, prodClient: KyInstance, testClient: KyInstance): Promise<HosecloudSyncResult> {
|
async function syncHosecloudIntegrationsToTest(prodCorp: CorpConfig, testCorp: CorpConfig, prodClient: KyInstance, testClient: KyInstance): Promise<HosecloudSyncResult> {
|
||||||
if (prodCorp.source.type !== "hose") return { skipped: true, reason: "prod source is not hose; no hosecloud credentials available" };
|
if (prodCorp.source.type !== "hose") return { skipped: true, reason: "prod source is not hose; no hosecloud credentials available" };
|
||||||
const appKey = (prodCorp.source.appKey ?? prodCorp.source.key)?.trim();
|
const appKey = prodCorp.source.appKey?.trim();
|
||||||
const appSecurity = (prodCorp.source.appSecurity ?? prodCorp.source.password)?.trim();
|
const appSecurity = prodCorp.source.appSecurity?.trim();
|
||||||
if (!appKey || !appSecurity) return { skipped: true, reason: "prod hose source missing appKey/appSecurity (or key/password)" };
|
if (!appKey || !appSecurity) return { skipped: true, reason: "prod hose source missing appKey/appSecurity" };
|
||||||
const [prodPref, testPref] = await Promise.all([
|
const [prodPref, testPref] = await Promise.all([
|
||||||
api.getApprovalStylePreferences(prodClient, prodCorp.seal.endpoints.approvalStylePreferences),
|
api.getApprovalStylePreferences(prodClient, prodCorp.seal.endpoints.approvalStylePreferences),
|
||||||
api.getApprovalStylePreferences(testClient, testCorp.seal.endpoints.approvalStylePreferences)
|
api.getApprovalStylePreferences(testClient, testCorp.seal.endpoints.approvalStylePreferences)
|
||||||
|
|||||||
Reference in new issue
Block a user