来源仓库:jxc/ai-fresh-delivery 来源提交:f0b1a180e2deb7e4673b9d1c8542619f7bc0f73d 快照树: 09f679334ff38f0ff25e907961c94a8223bcaedd(与来源 HEAD 工作树逐字节一致,3801 个文件) 按约定本仓库不带任何历史提交:来源仓库的历史中含真实凭据 (生产 SSH 私钥 deploy/id_rsa_tencent、server/.env、.env.tencent/.env.production/.env.gitea、 deploy/小程序AppSecret.txt,其中 MP_APPSECRET / S3 AccessKey 经哈希比对与线上同值), 整包推送会把这些凭据永久带入本仓库,故只取「当前版本」的单提交快照。 供应商系统后续开发自本提交开始。
62 lines
3.0 KiB
TypeScript
62 lines
3.0 KiB
TypeScript
import { readFileSync } from 'node:fs';
|
|
import { describe, expect, it } from 'vitest';
|
|
|
|
const read = (relative: string) =>
|
|
readFileSync(new URL(relative, import.meta.url), 'utf8');
|
|
|
|
describe('P0 order list readonly contract', () => {
|
|
it('returns persisted status and contains no write SQL', () => {
|
|
const source = read('../src/services/orderManagementQueryService.ts');
|
|
expect(source).toContain('order_status: storedStatus');
|
|
expect(source).not.toMatch(/\b(?:INSERT|UPDATE|DELETE)\b/i);
|
|
expect(source).not.toContain('toPersist');
|
|
});
|
|
|
|
it('removes the unused display side-effect resolver', () => {
|
|
const source = read('../src/services/orderStatusDisplayService.ts');
|
|
expect(source).not.toContain('resolveDisplayOrderStatuses');
|
|
expect(source).not.toContain('prunePrematurePendingInspectionsForIncompletePreps');
|
|
});
|
|
|
|
it('locks and audits explicit reconciliation changes', () => {
|
|
const source = read('../src/services/orderStatusReconcileService.ts');
|
|
expect(source).toContain('withOrderAdvisoryLock(code');
|
|
expect(source).toContain("operationType: 'order_status_reconcile'");
|
|
expect(source).toContain("operatorName: 'system'");
|
|
});
|
|
});
|
|
|
|
describe('P0 tenant referential integrity contract', () => {
|
|
it('keeps the orphan audit script read-only and fail-closed', () => {
|
|
const source = read('../scripts/audit-tenant-referential-integrity.mjs');
|
|
expect(source).toContain("await client.query('BEGIN READ ONLY')");
|
|
expect(source).toContain('process.exitCode = report.violations > 0');
|
|
expect(source).not.toMatch(/\b(?:INSERT|UPDATE|DELETE)\s+(?:INTO|FROM|\w)/i);
|
|
});
|
|
|
|
it('purges order tree children before deleting the order', () => {
|
|
const source = read('../src/services/orderDeleteService.ts');
|
|
const picking = source.indexOf("deleteOrderItemDependants(client, 'picking_items'");
|
|
const fulfillments = source.indexOf("'order_item_fulfillments'");
|
|
const returns = source.indexOf("'order_item_returns'", fulfillments);
|
|
const items = source.indexOf("deleteByOrderCode(client, 'order_items'");
|
|
const order = source.indexOf('DELETE FROM orders WHERE order_code');
|
|
expect(picking).toBeGreaterThan(0);
|
|
expect(fulfillments).toBeGreaterThan(picking);
|
|
expect(returns).toBeGreaterThan(fulfillments);
|
|
expect(items).toBeGreaterThan(returns);
|
|
expect(order).toBeGreaterThan(items);
|
|
});
|
|
|
|
it('adds only the three same-schema core FKs as NOT VALID', () => {
|
|
const migration = read('../../migrations/20260908_tenant_core_foreign_keys.sql');
|
|
expect(migration.match(/FOREIGN KEY \(/g)).toHaveLength(3);
|
|
expect(migration.match(/ON DELETE CASCADE NOT VALID/g)).toHaveLength(3);
|
|
expect(migration).toContain('REFERENCES %I.orders(order_code)');
|
|
expect(migration).toContain('REFERENCES %I.order_items(id)');
|
|
expect(migration).toContain('REFERENCES %I.picking_tasks(pick_code)');
|
|
expect(migration).toContain('ensure_tenant_core_foreign_keys(v_schema)');
|
|
expect(migration).not.toMatch(/REFERENCES\s+(?:public|legacy_public)\./);
|
|
});
|
|
});
|