fix: 整合本地单据校验与离线身份修复
从旧审查分支选择仍未进入主分支的单据修复,保留主分支较新的工作流与插件分发实现。 兼容费用类型包装树,统一创建预演与执行,修正核销净支付,并将真实规格校验接入复制及送审。 注册 whoami 离线参数,补充写入契约和完整入口回归,保留旧分支与工作区。 验证:bun test 876 pass / 0 fail;bun run check、check:version、git diff --check 通过。
This commit is contained in:
1 parent
c2d36733fb
commit
ebeec98f6d
12 files changed
+369
-54
No files matched your search
@@ -29,7 +29,7 @@ export const COMMAND_METADATA: Record<string, CliCommandMetadata> = {
|
||||
"env"
|
||||
],
|
||||
"commandAliases": {},
|
||||
flags: { }
|
||||
flags: { ...flagList("offline cached", "boolean") }
|
||||
},
|
||||
"aipro": {
|
||||
"summary": "AI PRO 确定性审批仲裁",
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
import { expect, test } from "bun:test";
|
||||
import { handleCreate } from "./create.js";
|
||||
import { parseArgs } from "../../parser.js";
|
||||
|
||||
test("create dry-run resolves the same available fee as execution and never posts", async () => {
|
||||
const writes: any[] = [];
|
||||
const client = {
|
||||
get: (url: string) => ({ json: async () => url.includes("specifications/")
|
||||
? { items: [{ id: "spec", name: "模板", components: [{ field: "title" }] }] }
|
||||
: url.includes("staffs/me") ? { value: { staff: { id: "staff", defaultDepartment: "dept" } } }
|
||||
: { items: [{ feeType: { id: "travel", name: "差旅", expenseSpecificationId: "detail" }, children: [] }] } }),
|
||||
post: (_: string, payload: any) => { writes.push(payload.json); return { json: async () => ({ flow: { id: "new" } }) }; },
|
||||
};
|
||||
const base = ["bill", "create", "--template", `spec:${"a".repeat(32)}`, "--json"];
|
||||
const context = (args: string[]) => ({ parsed: parseArgs(args), runtime: { jsonMode: true }, corpId: "corp", getClient: async () => client, requireWriteConfirmation: async () => {} }) as any;
|
||||
const preview = await handleCreate(context([...base, "--dry-run"]));
|
||||
expect(JSON.parse(preview.stdout)).toMatchObject({ dryRun: true, feeType: "差旅" });
|
||||
expect(writes).toEqual([]);
|
||||
await handleCreate(context([...base, "--yes"]));
|
||||
expect(writes[0].form.details[0].feeTypeId).toBe("travel");
|
||||
await expect(handleCreate(context([...base, "--fee-type", "不存在", "--dry-run"]))).rejects.toThrow("费用类型");
|
||||
expect(writes).toHaveLength(1);
|
||||
});
|
||||
@@ -1,4 +1,4 @@
|
||||
import { createBillDraft } from "../../../domains/bill/create.js";
|
||||
import { createBillDraft, prepareBillDraft } from "../../../domains/bill/create.js";
|
||||
import { isDryRun } from "../../mutation.js";
|
||||
import { stringOption } from "../../parser.js";
|
||||
import { printJson } from "../../printer.js";
|
||||
@@ -22,7 +22,8 @@ export async function handleCreate(ctx: BillActionContext): Promise<CliResult> {
|
||||
const feeTypeName = stringOption(parsed.options, ["fee-type", "feeType"]);
|
||||
|
||||
if (isDryRun(parsed, runtime)) {
|
||||
const preview = { template: templateId, title: title ?? "(模板名称)", amount, reason: reason ?? "", feeType: feeTypeName ?? "简单费用" };
|
||||
const prepared = await prepareBillDraft(await ctx.getClient(), corpId, { templateId, title, amount, reason, feeTypeName });
|
||||
const preview = { template: templateId, title: prepared.title, amount: prepared.amount, reason: reason ?? "", feeType: prepared.feeType };
|
||||
if (runtime.jsonMode) {
|
||||
return { stdout: printJson({ dryRun: true, ...preview }, runtime.outputOptions), stderr: "", exitCode: 0 };
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import { getRawBillFlow } from "../../../domains/bill/tools.js";
|
||||
import {
|
||||
formatValidationIssues,
|
||||
validateBillDraft,
|
||||
loadBillValidationOptions,
|
||||
type BillDraftForm,
|
||||
} from "../../../domains/bill/draft-validation.js";
|
||||
import { stringOption } from "../../parser.js";
|
||||
@@ -41,7 +42,7 @@ export async function handleValidate(ctx: BillActionContext): Promise<CliResult>
|
||||
};
|
||||
}
|
||||
|
||||
const issues = validateBillDraft(form);
|
||||
const issues = validateBillDraft(form, await loadBillValidationOptions(await ctx.getClient(), corpId, form));
|
||||
const errors = issues.filter((item) => item.severity === "error");
|
||||
const warnings = issues.filter((item) => item.severity === "warning");
|
||||
const billCode = typeof form.title === "string" ? form.title : target;
|
||||
|
||||
@@ -9,6 +9,13 @@ import { CLI_COMMAND_REGISTRY, findCommandByArea } from "./registry.js";
|
||||
import { runAiProCli } from "../aipro-cli.js";
|
||||
|
||||
describe("strict command options", () => {
|
||||
test("top-level whoami accepts offline flags without changing the command target", () => {
|
||||
for (const flag of ["offline", "cached"]) {
|
||||
const parsed = parseArgs(["whoami", `--${flag}`, "--json"]);
|
||||
expect(parsed.options[flag]).toBe(true);
|
||||
expect(parsed.args).toEqual([]);
|
||||
}
|
||||
});
|
||||
test("rejects misspellings and missing values instead of silently dropping filters", async () => {
|
||||
const typo = await runCli(["bill", "list", "--limitt", "5", "--json"]);
|
||||
expect(typo.exitCode).toBe(2);
|
||||
|
||||
Reference in new issue
Block a user