完善借款、编号、付款与预算并发及验收(09-06-release-gate-integrity)

汇总已落盘的借款本金与还款、兼容历史编号的周期化编号、付款责任与回单核验、报销进度和排序、PWA/采购事务、错误原因与日期校验及ERP退役。
统一共享预算池锁序和锁后判断,恢复差旅原预算选择,补原因码固定夹具及反向完整性检查。
纳入配套迁移、测试、受管QA、分层验收合同、规约及任务记录;原始证据留在ignored artifacts。

关联任务:09-17-company-loan-principal-repayment、09-17-erp-exclusive-retirement、09-18-reimbursement-periodic-numbering、09-08-reimbursement-payment-closeout、09-18-local-concurrency-product-fixes、09-19-budget-pool-concurrency、09-05-error-explainability-payment-readiness。
预算补审由Claude定向验证2文件928项通过,原4446/28及r6结果仍仅对应各自历史输入;本轮未重跑测试。
完整新候选门禁、R1真实入口接入与12项公网义务仍开放。生产编号未启用、差旅仍冻结;不推送、不部署,不宣称发布资格。
这个提交包含在:
2026-09-19 13:11:04 +08:00
父节点 729d90576f
当前提交 1f8d5b658a
共修改 367 个文件,包含 21079 行新增和 12287 行删除
@@ -1,3 +1,4 @@
const { enableNumbering } = require("../helpers/activeNumbering");
const Fastify = require("fastify");
const { AppError } = require("../../../src/utils/AppError");
@@ -64,8 +65,9 @@ async function buildApp(options = {}) {
cost_center_id: COST_CENTER_ID,
supplier_id: SUPPLIER_ID,
document_category_id: DOCUMENT_CATEGORY_ID,
budget_pool_id: null,
budget_pool_id: options.explicitPool ? options.pool.id : null,
request_no: null,
numbering_version: options.numberingVersion ?? 1,
title: "R6 采购提交热修测试",
reason: null,
currency_code: "CNY",
@@ -92,6 +94,8 @@ async function buildApp(options = {}) {
const tx = {
$queryRaw: vi.fn(async () => [purchaseRequest]),
budgetPool: { findUnique: vi.fn(async () => options.pool ?? null), update: vi.fn() },
budgetLedgerEntry: { findMany: vi.fn(async () => []), create: vi.fn() },
legalEntity: {
findUnique: vi.fn(async () => ({
id: LEGAL_ENTITY_ID,
@@ -173,6 +177,7 @@ async function buildApp(options = {}) {
},
};
if (options.activeNumbering) enableNumbering(tx);
const prisma = {
$transaction: vi.fn(async (callback) => callback(tx)),
auditLog: {
@@ -251,6 +256,28 @@ describe("purchase request submit budget precheck gate", () => {
resolveRecipientsForAssigneeMock.mockResolvedValue([]);
});
it.each([false, true].flatMap(enabled => [false, true].map(explicitPool => ({ enabled, explicitPool }))))(
'blocks the latest pool usage inside the submit transaction: %j', async ({ enabled, explicitPool }) => {
const pool = { id: 'bbbbbbbb-bbbb-4bbb-8bbb-bbbbbbbbbbbb', status: 'active', archived_at: null,
allocated_amount: '100.00', used_amount: '60.00' };
resolveApplicableBudgetPoolByContextMock.mockResolvedValue(pool);
resolveEntityPrecheckMock.mockResolvedValue(buildPrecheck(enabled ? { decision: 'block',
blockingReasons: [{ code: 'budget_exceeded' }] } : {}));
const { app, tx } = await buildApp({ pool, explicitPool, budgetControlMode: 'block', budgetPrecheckEnabled: enabled });
try {
const response = await app.inject({ method: 'POST', url: `/api/purchase-requests/${PURCHASE_REQUEST_ID}/submit` });
expect(response.statusCode).toBe(409);
expect(response.json().error.details.reasonCode).toBe('purchase_request.precheck_blocked');
expect(resolveEntityPrecheckMock).toHaveBeenCalledWith(expect.objectContaining({ prisma: tx, budgetPoolForWrite: pool }));
expect(resolveApplicableBudgetPoolByContextMock).toHaveBeenCalledWith(tx, expect.any(Object),
{ forUpdate: true, additionalPoolIds: [explicitPool ? pool.id : null] });
expect(tx.purchaseRequestItem.aggregate.mock.invocationCallOrder[0]).toBeLessThan(resolveEntityPrecheckMock.mock.invocationCallOrder[0]);
expect(tx.workflowInstance.create).not.toHaveBeenCalled();
expect(tx.budgetLedgerEntry.create).not.toHaveBeenCalled();
expect(tx.budgetPool.update).not.toHaveBeenCalled();
} finally { await app.close(); }
});
it("does not 500 when no budget pool exists and budget precheck is disabled", async () => {
resolveEntityPrecheckMock.mockResolvedValue(
buildPrecheck({
@@ -289,3 +316,14 @@ describe("purchase request submit budget precheck gate", () => {
await app.close();
});
});
it.each([1, 2])("submits a stored v%s purchase draft under active policy without reclassifying it", async (version) => {
const { app, tx } = await buildApp({ activeNumbering: true, numberingVersion: version });
try {
const response = await app.inject({ method: "POST", url: `/api/purchase-requests/${PURCHASE_REQUEST_ID}/submit` });
expect(response.statusCode).toBe(200);
const data = tx.purchaseRequest.update.mock.calls.find(([arg]) => arg.data.request_no)?.[0].data;
expect(data.request_no).toMatch(version === 1 ? /^CG-\d{8}-0001$/ : /^CG-\d{4}-0001$/);
expect(tx.businessNumberPolicy.findUnique).not.toHaveBeenCalled();
} finally { await app.close(); }
});