Files
SupplierSystem/server/tests/deliveryLocationFilter.test.ts
T
Ubuntu deb3e72750
CI / server typecheck + tests (push) Canceled after 0s
CI / web typecheck + tests + miniprogram syntax (push) Canceled after 0s
CI / eslint (观察项,C7 骨架) (push) Canceled after 0s
CI / npm audit (critical 硬拦) (push) Canceled after 0s
chore: 以 AI 生鲜配送系统 当前版本作为 SupplierSystem 起点
来源仓库: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 经哈希比对与线上同值),
整包推送会把这些凭据永久带入本仓库,故只取「当前版本」的单提交快照。
供应商系统后续开发自本提交开始。
2026-10-08 17:35:43 +08:00

105 lines
3.4 KiB
TypeScript

import { readFileSync } from 'fs';
import { createRequire } from 'module';
import { describe, expect, it } from 'vitest';
const require = createRequire(import.meta.url);
const filter = require('../../miniprogram/utils/deliveryLocationFilter.js') as {
createLocationReportFilter: () => { last: unknown; recent: unknown[] };
shouldAcceptLocationReport: (
state: unknown,
point: { lat: number; lng: number; accuracy?: number | null },
nowMs: number
) => { accept: boolean; nextState: unknown };
};
const TRAIL = `
1,11:52:29,30.3952919,104.1035121
2,11:52:50,30.3952040,104.1034342
3,11:53:08,30.3953380,104.1035411
4,11:53:58,30.3954839,104.1035411
5,11:54:28,30.3947686,104.1034871
6,11:54:43,30.3949186,104.1040262
7,11:54:58,30.3948486,104.1040001
8,11:55:13,30.3947767,104.1039922
9,11:55:28,30.3946718,104.1039271
10,11:55:43,30.3946696,104.1038650
11,11:56:13,30.3947146,104.1038300
12,11:56:28,30.3945497,104.1034182
13,11:56:43,30.3945747,104.1033900
14,11:56:58,30.3941048,104.1028971
15,11:57:28,30.3917795,104.1026619
16,11:57:43,30.3906863,104.1022700
17,11:58:13,30.3889388,104.1007563
18,11:58:43,30.3882756,104.0979085
19,11:59:13,30.3882430,104.0951804
20,11:59:43,30.3896075,104.0927512
21,11:59:58,30.3899542,104.0916382
22,12:00:28,30.3901478,104.0890015
23,12:00:58,30.3953380,104.1035411
24,12:01:14,30.3953380,104.1035411
25,12:01:30,30.3953380,104.1035411
26,12:01:46,30.3953380,104.1035411
27,12:02:02,30.3953380,104.1035411
28,12:02:20,30.3953380,104.1035411
29,12:02:36,30.3953380,104.1035411
30,12:02:52,30.3953380,104.1035411
31,12:03:08,30.3953380,104.1035411
32,12:03:33,30.3953380,104.1035411
33,12:03:54,30.3953380,104.1035411
34,12:04:09,30.3945204,104.0751392
`.trim().split('\n').map((line) => {
const [seq, clock, lat, lng] = line.split(',');
const [hh, mm, ss] = clock.split(':').map(Number);
return {
seq: Number(seq),
t: ((hh * 60 + mm) * 60 + ss) * 1000,
lat: Number(lat),
lng: Number(lng),
};
});
describe('deliveryLocationFilter', () => {
it('drops freeze, teleport, and snap-back on the 34-point sample', () => {
let state = filter.createLocationReportFilter();
const accepted: number[] = [];
const rejected: number[] = [];
for (const row of TRAIL) {
const decision = filter.shouldAcceptLocationReport(
state,
{ lat: row.lat, lng: row.lng },
row.t
);
state = decision.nextState;
if (decision.accept) accepted.push(row.seq);
else rejected.push(row.seq);
}
expect(accepted[0]).toBe(1);
expect(accepted).toContain(22);
expect(accepted).toContain(34);
expect(accepted).not.toContain(13);
expect(rejected).toEqual(expect.arrayContaining([13, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33]));
expect(rejected).not.toContain(34);
expect(accepted).not.toContain(23);
});
it('rejects coarse accuracy', () => {
const first = filter.shouldAcceptLocationReport(
filter.createLocationReportFilter(),
{ lat: 30.39, lng: 104.09, accuracy: 250 },
1000
);
expect(first.accept).toBe(false);
});
});
describe('deliveryLocation wiring', () => {
it('filters in emit path', () => {
const locUtil = readFileSync(
new URL('../../miniprogram/utils/deliveryLocation.js', import.meta.url),
'utf8'
);
expect(locUtil).toMatch(/shouldAcceptLocationReport/);
expect(locUtil).toMatch(/resetLocationReportState/);
});
});