fix: 修复真实验收中的企业范围与草稿复制问题
显式企业身份核验只访问指定企业,避免回退到全量查询。 复制只清空源单存在的发票与附件字段,避免通用模板拒绝未知属性。 补充隔离回归与指定测试企业验收记录,测试数据已清理。 验证:929 项测试通过,类型检查及版本一致性检查通过。
This commit is contained in:
1 parent
6249feee23
commit
613fe3476c
8 files changed
+108
-14
No files matched your search
@@ -2,9 +2,9 @@
|
||||
|
||||
## 交付范围
|
||||
|
||||
在用户确认四阶段整改方案后,以 `bb70362` 为基线实施。本轮解决已确认的 7 项问题,保留既有业务层公开函数签名和公共 SDK 初始化结构;没有修改真实企业数据,没有推送、合并、发布或替换全局安装。
|
||||
在用户确认四阶段整改方案后,以 `bb70362` 为基线实施。本轮解决已确认的 7 项问题,保留既有业务层公开函数签名和公共 SDK 初始化结构。离线整改完成后,按用户追加授权在「沈玥妍测试企业」进行真实服务验收,并补齐验收发现的两处轻量修复;交付通过 PR 合入主分支,不发布版本或替换全局安装。
|
||||
|
||||
分阶段本地提交:A 为 `9916936`,B 为 `51fb54d`,C 为 `55d31e2`;D 包含 SDK 示例、文档、架构验证和本报告。
|
||||
分阶段本地提交:A 为 `9916936`,B 为 `51fb54d`,C 为 `55d31e2`;D 为 `6249fee`,包含 SDK 示例、文档、架构验证和本报告。真实服务验收补丁另行提交。
|
||||
|
||||
## 实际修改与前后行为
|
||||
|
||||
@@ -50,15 +50,37 @@ hose-use workflow refresh-chooses <pipelineId> --platform-id=<platformId> --corp
|
||||
| B:单据契约 | 911 通过 / 0 失败 | 通过 |
|
||||
| C:保存与重放 | 922 通过 / 0 失败 | 通过 |
|
||||
| 最终:文档、示例和边界 | **926 通过 / 0 失败,119 文件,4379 次断言** | 通过 |
|
||||
| 真实验收补丁后 | **929 通过 / 0 失败,120 文件,4392 次断言** | 通过 |
|
||||
|
||||
- 相对整改前 892 项,新增 34 项测试。验证涵盖歧义时无换票/写请求、精确 ID/物理键正例、单据错误响应、计划失败不送审、部分保存和恢复、认证重放次数/请求体,以及 README SDK 示例编译。
|
||||
- 相对整改前 892 项,新增 37 项测试。验证涵盖歧义时无换票/写请求、精确 ID/物理键正例、单据错误响应、计划失败不送审、部分保存和恢复、认证重放次数/请求体、身份查询企业范围、复制时不注入字段,以及 README SDK 示例编译。
|
||||
- 最终 `bun run check:version` 通过,版本保持 `0.8.21`;`git diff --check` 通过;实际 CLI 帮助包含 `refresh-chooses`。
|
||||
- 全量测试使用临时配置、账号、Token/协助会话文件、企业目录和 SQLite 路径;网络测试均为假接口或测试内回环服务。测试流程包含既有插件重新打包与源码/插件冒烟验证。
|
||||
- 本地验证日志保存在 Git 忽略目录 `.drafts/review-20261029/`:最终日志为 `phase-d-final/tests.log`、`phase-d-final/typecheck.log`。原始审查复现材料保留,不覆盖历史结果。
|
||||
- 本地验证日志保存在 Git 忽略目录 `.drafts/review-20261029/`:离线整改日志为 `phase-d-final/`,真实验收补丁的最终全量日志为 `live-final/tests.log`、`live-final/typecheck.log`。原始审查复现材料保留,不覆盖历史结果。
|
||||
|
||||
## 指定测试企业真实验收与补丁
|
||||
|
||||
业务写入均使用当前源码 CLI,显式指定「沈玥妍测试企业」并采用无状态企业选择;原始响应和临时脚本仅保存在 Git 忽略目录 `.drafts/live-smoke-20261029/`,不提交租户载荷或凭证。
|
||||
|
||||
| 验收项 | 实际结果 |
|
||||
|---|---|
|
||||
| 模板及写前校验 | 读取 58 个模板;缺少收款人、租户必填字段及超长标题均在创建前拒绝;使用可用差旅模板完成正例 |
|
||||
| 草稿生命周期 | 0.01 元草稿创建、复制预演、真实复制(不保留附件)、校验、删除预演和真实删除全部通过;未提交审批 |
|
||||
| 工作流正常保存 | 在测试应用创建一个始终停用的独立工作流;保存成功并同步版本,旧版本草稿再次保存被拒绝,定向刷新预演和执行通过 |
|
||||
| 工作流部分成功恢复 | 真实主 PUT 成功后,仅在本地注入一次 chooses 失败响应;返回非零、`partial`、`remoteSaved: true`,本地版本同步;返回的恢复命令真实执行成功,主保存仅一次。此失败响应是注入场景,不是服务端自然故障 |
|
||||
| 清理 | 删除全部 4 张本轮创建的草稿(含前两次失败复制留下的源草稿)及独立工作流;原有 15 个工作流的 ID、状态、更新时间与基线一致 |
|
||||
| 身份查询范围 | 修复后真实执行 `corps whoami --corp=...`,结果只包含指定测试企业 |
|
||||
|
||||
验收暴露的问题与实际修复:
|
||||
|
||||
1. [whoami.ts](../../src/cli/commands/corps/whoami.ts) 原来忽略显式 `--corp`,首次身份核验读取了本地名录中的 27 个企业身份,超出了本次测试范围;已向用户说明并停止该路径,未在其他企业执行审批或业务数据写入。现按已解析企业过滤,无效企业拒绝回退全量,不带参数仍保留全量视图。新增 [范围回归](../../src/cli/commands/corps/whoami-scope.test.ts),覆盖指定、无参数、无效和离线模式。
|
||||
2. [copy.ts](../../src/domains/bill/copy.ts) 原来无条件添加 `u_发票总金额`、发票及附件字段,真实通用模板先后拒绝了自定义属性和附件属性。现只清空源单已有的对应字段;[传输契约回归](../../src/domains/bill/write-contract.test.ts) 验证请求不再注入这些属性,真实创建到复制、删除的闭环通过。
|
||||
3. [SDK 示例测试](../../scripts/sdk-example.test.ts) 统一虚拟源文件路径比较,兼容不同路径分隔符;本地编译通过,未单独运行 Windows 环境。
|
||||
|
||||
这些补丁未扩大既定业务功能,修复了真实验收中发现的查询范围和模板兼容问题。
|
||||
|
||||
## 未覆盖及重点复查
|
||||
|
||||
- 未执行真实企业的创建、复制、删除、送审、协助换票或工作流保存;真实服务端响应变体、租户必填规则与权限仍需在测试企业独立验收。
|
||||
- 真实验收覆盖上述指定测试企业和模板;未执行送审、审批、付款、协助员工换票或工作流发布/运行。员工歧义、字段歧义、持续鉴权失败等场景由隔离回归覆盖,其他租户响应变体与权限未逐一验收。
|
||||
- 重点复查行为收紧:过去会选第一人的同名请求、会选首字段的歧义赋值、缺失必填字段的创建,以及缺少有效 ID 的写入响应,现在均会拒绝。
|
||||
- 使用者应处理新增的工作流部分成功状态与异常;它仍是非零退出,但 `remoteSaved: true` 表示主数据已经提交。若未指定 `--in-place`,需要调用者保留返回版本或重新读取远端。
|
||||
- 公共 SDK 仍复用 CLI helper;此次保持兼容,仅修正示例。全面提取独立 SDK 运行时不在本轮方案中。
|
||||
|
||||
@@ -13,7 +13,7 @@ test("DataLink 公共 SDK 的 README 示例与实际导出一同编译", () => {
|
||||
const options: ts.CompilerOptions = { noEmit: true, strict: true, skipLibCheck: true, module: ts.ModuleKind.ESNext, moduleResolution: ts.ModuleResolutionKind.Bundler, target: ts.ScriptTarget.ESNext, types: ["bun"] };
|
||||
const host = ts.createCompilerHost(options);
|
||||
const original = host.getSourceFile;
|
||||
host.getSourceFile = (name, ...args) => name === file ? ts.createSourceFile(file, source, ts.ScriptTarget.ESNext, true) : original(name, ...args);
|
||||
host.getSourceFile = (name, ...args) => resolve(name) === file ? ts.createSourceFile(file, source, ts.ScriptTarget.ESNext, true) : original(name, ...args);
|
||||
const diagnostics = ts.getPreEmitDiagnostics(ts.createProgram([file], options, host));
|
||||
expect(diagnostics.map(d => ts.flattenDiagnosticMessageText(d.messageText, "\n"))).toEqual([]);
|
||||
}, 15000);
|
||||
@@ -36,3 +36,5 @@
|
||||
`hose-use mcp [serve]` 在当前进程启动服务,不派生 Bun 或访问源码脚本;MCP 调用继续只通过 `hose_cli` 分发,流式终端回调不会被注入协议通道。
|
||||
|
||||
`update --dry-run` 返回源码或二进制更新计划,不请求发布源、不执行 git/依赖安装、不替换二进制或同步技能;`update check` 和发布历史查询保留只读查询行为。
|
||||
|
||||
`corps whoami --corp=<id>` 只在线核验指定企业,不再遍历全部本地名录;不带 `--corp` 时保留全企业视图,`--offline` 仍不发起网络请求。
|
||||
@@ -0,0 +1,54 @@
|
||||
import { afterEach, expect, test } from "bun:test";
|
||||
import { mkdtempSync, rmSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { handleWhoami } from "./whoami.js";
|
||||
import { saveCorpConfig } from "../../../core/config/loader.js";
|
||||
import { CorpConfigSchema } from "../../../core/config/types.js";
|
||||
import { CorpContext } from "../../../core/config/manager.js";
|
||||
import { parseArgs } from "../../parser.js";
|
||||
import type { CliRuntime } from "../../types.js";
|
||||
|
||||
const originalFetch = globalThis.fetch;
|
||||
const originalEnv = { ...process.env };
|
||||
const directories: string[] = [];
|
||||
afterEach(() => {
|
||||
globalThis.fetch = originalFetch;
|
||||
process.env = { ...originalEnv };
|
||||
for (const dir of directories.splice(0)) rmSync(dir, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
function fixture() {
|
||||
const dir = mkdtempSync(join(tmpdir(), "hose-whoami-scope-"));
|
||||
directories.push(dir);
|
||||
process.env.HOSE_ENTERPRISES_DIR = dir;
|
||||
process.env.HOSE_USER_ENTERPRISES_DIR = dir;
|
||||
process.env.HOSE_CONFIG_FILE = join(dir, "config.json");
|
||||
const corps = ["one", "two"].map(id => CorpConfigSchema.parse({ id, name: id, source: "manual", baseUrl: "https://tenant.invalid", credentials: { accessToken: "fake", corpId: id, staffId: `staff-${id}` } }));
|
||||
for (const corp of corps) saveCorpConfig(corp, dir);
|
||||
const requests: string[] = [];
|
||||
globalThis.fetch = (async (input: Request) => {
|
||||
requests.push(new URL(input.url).searchParams.get("corpId")!);
|
||||
return Response.json({ value: { staff: { name: "Test Staff" } } });
|
||||
}) as unknown as typeof fetch;
|
||||
const runtime: CliRuntime = { corpContext: new CorpContext(corps, { stateful: false }), selectedCorp: corps[0]!, jsonMode: true };
|
||||
return { runtime, requests };
|
||||
}
|
||||
|
||||
test("显式企业只查询该企业;不带企业时保留全企业身份查看", async () => {
|
||||
const f = fixture();
|
||||
const selected = await handleWhoami(parseArgs(["corps", "whoami", "--corp=one", "--json"]), f.runtime);
|
||||
expect(f.requests).toEqual(["one"]);
|
||||
expect(JSON.parse(selected.stdout).corporations.map((c: { id: string }) => c.id)).toEqual(["one"]);
|
||||
f.requests.length = 0;
|
||||
await handleWhoami(parseArgs(["corps", "whoami", "--json"]), f.runtime);
|
||||
expect(f.requests.sort()).toEqual(["one", "two"]);
|
||||
});
|
||||
|
||||
test("无效企业不退回全量查询;离线模式不请求网络", async () => {
|
||||
const f = fixture();
|
||||
await expect(handleWhoami(parseArgs(["corps", "whoami", "--corp=missing"]), { ...f.runtime, selectedCorp: null })).rejects.toThrow("未找到企业");
|
||||
const result = await handleWhoami(parseArgs(["corps", "whoami", "--corp=one", "--offline", "--json"]), f.runtime);
|
||||
expect(JSON.parse(result.stdout).corporations).toHaveLength(1);
|
||||
expect(f.requests).toEqual([]);
|
||||
});
|
||||
@@ -1,6 +1,7 @@
|
||||
import { loadCorpConfigs } from "../../../core/config/loader.js";
|
||||
import { createSessionClient } from "../../../core/http/session-client.js";
|
||||
import { booleanOption } from "../../parser.js";
|
||||
import { booleanOption, stringOption } from "../../parser.js";
|
||||
import { NotFoundError } from "../../../core/errors.js";
|
||||
import { formatSourceLabel, printJson, printTable } from "../../printer.js";
|
||||
import type { CliParsedArgs, CliResult, CliRuntime } from "../../types.js";
|
||||
|
||||
@@ -46,7 +47,10 @@ async function mapLimit<T, R>(items: T[], limit: number, fn: (item: T) => Promis
|
||||
|
||||
export async function handleWhoami(parsed: CliParsedArgs, runtime: CliRuntime): Promise<CliResult> {
|
||||
const offline = booleanOption(parsed.options, ["offline", "cached"]);
|
||||
const corps = runtime.corpContext.listCorps();
|
||||
const allCorps = runtime.corpContext.listCorps();
|
||||
const explicitCorp = stringOption(parsed.options, ["corp"]);
|
||||
if (explicitCorp && !runtime.selectedCorp) throw new NotFoundError(`未找到企业: ${explicitCorp}`);
|
||||
const corps = explicitCorp ? allCorps.filter((corp) => corp.id === runtime.selectedCorp!.id) : allCorps;
|
||||
const configs = new Map<string, any>();
|
||||
for (const config of loadCorpConfigs()) {
|
||||
configs.set(config.id, config);
|
||||
|
||||
@@ -65,6 +65,7 @@ src/domains/bill/
|
||||
10. **纯接口复制 (`copyBillAsDraft`)**:
|
||||
- 读取服务端最新的 `flow.form`;
|
||||
- 清空发票绑定(`invoiceForm.invoices`)、明细与单据发票总额归零、剔除 `detailStatus`;
|
||||
- 只重置源单实际包含的发票字段,不向通用模板注入 `u_发票总金额` 等租户自定义属性。
|
||||
- 重算报销/支付金额,附件默认保留;
|
||||
- `POST /api/flow/v1/flows` 创建新草稿(`name: freeflow.edit`),默认不提交。
|
||||
11. **草稿删除 (`deleteBillDraft`)**:
|
||||
|
||||
@@ -81,20 +81,20 @@ export function buildBillCopyForm(
|
||||
amountSum += moneyNumber(ft.amount);
|
||||
|
||||
// 复制不携带发票绑定;发票总额归零
|
||||
ft.invoice = "0";
|
||||
ft.invoiceForm = { type: "exist", invoices: [] };
|
||||
ft.u_发票总金额 = zeroMoney(ft.u_发票总金额);
|
||||
if (ft.invoice !== undefined) ft.invoice = "0";
|
||||
if (ft.invoiceForm !== undefined) ft.invoiceForm = { type: "exist", invoices: [] };
|
||||
if (ft.u_发票总金额 !== undefined) ft.u_发票总金额 = zeroMoney(ft.u_发票总金额);
|
||||
delete ft.detailStatus;
|
||||
|
||||
if (!keepAttachments) {
|
||||
if (!keepAttachments && ft.attachments !== undefined) {
|
||||
ft.attachments = [];
|
||||
}
|
||||
}
|
||||
|
||||
form.u_发票总金额 = zeroMoney(form.u_发票总金额);
|
||||
if (form.u_发票总金额 !== undefined) form.u_发票总金额 = zeroMoney(form.u_发票总金额);
|
||||
form.expenseMoney = { ...(form.expenseMoney ?? {}), standard: amountSum.toFixed(2) };
|
||||
form.payMoney = { ...(form.payMoney ?? {}), standard: (amountSum - moneyNumber(form.writtenOffMoney)).toFixed(2) };
|
||||
if (!keepAttachments) {
|
||||
if (!keepAttachments && form.attachments !== undefined) {
|
||||
form.attachments = [];
|
||||
}
|
||||
|
||||
|
||||
@@ -61,6 +61,17 @@ function fixture(options: {
|
||||
}
|
||||
|
||||
describe("bill API write contracts", () => {
|
||||
test("复制通用模板不注入源单没有的发票或租户自定义字段", async () => {
|
||||
const { client, writes } = fixture();
|
||||
await copyBillAsDraft(client, "corp", "f", { keepAttachments: false });
|
||||
expect(writes).toHaveLength(1);
|
||||
expect(writes[0].json.form).not.toHaveProperty("u_发票总金额");
|
||||
expect(writes[0].json.form.details[0].feeTypeForm).not.toHaveProperty("u_发票总金额");
|
||||
expect(writes[0].json.form.details[0].feeTypeForm).not.toHaveProperty("invoice");
|
||||
expect(writes[0].json.form.details[0].feeTypeForm).not.toHaveProperty("invoiceForm");
|
||||
expect(writes[0].json.form).not.toHaveProperty("attachments");
|
||||
expect(writes[0].json.form.details[0].feeTypeForm).not.toHaveProperty("attachments");
|
||||
});
|
||||
test("创建和预演均拒绝缺失明细规格、必填明细与过长表头,不发起创建", async () => {
|
||||
for (const options of [{ missingDetailSpec: true }, { detailRequired: "u_项目" }, { titleMaxLength: 1 }]) {
|
||||
const { client, writes } = fixture(options);
|
||||
|
||||
Reference in new issue
Block a user