refactor(stage1): 删除已证实无引用的死代码

按 import 图可达性分析(从 main.tsx / server index+local / vite.config 出发)
删除 0 引用的文件,删除后可达性分析 UNREACHABLE 归零。

- 删旧氢能实现:PrototypeBoard / HydrogenBiV2App / prototype-adapter /
  prototype-source 全部 / HydrogenView+Overview+Daily+Settlement+BoardChrome+
  StationBoard / hydrogen-overview / hydrogen-daily
- 删死 CSS 4 个(约 12k 行)、删死 vendor 残留(自挂载 index.tsx、AccessGate、SdDatePicker)
- 删 server/mileage-db.ts(含硬编码凭据的死模块)
- DailyRangeControls:移除从未被传入的 vehicleScope/onVehicleScopeChange 死分支
- tsconfig:移除指向已删除/不存在路径的 exclude

测试 146 -> 131(删掉的 3 个测试文件覆盖的是被删的死代码)。
lint / test / build 全绿。
This commit is contained in:
dsh-agent
2026-09-11 10:11:33 +08:00
parent 89dca5c5a4
commit 3daa9808ce
51 changed files with 18 additions and 34286 deletions
@@ -1,148 +0,0 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import type { HydrogenOverviewResponse } from '../api.js';
import {
buildCustomerDrillPayload,
buildMetricDrillPayload,
buildMonthDrillPayload,
buildRegionDrillPayload,
buildStationDrillPayload,
deriveOverviewMetrics,
formatKg,
formatRelative,
formatYuan,
} from './model.js';
const drillKpi = {
yearKg: 10_000,
yearFee: 80_000,
yearRevenue: 75_000,
yearProfit: 15_000,
ourYearKg: 4_000,
ourYearFee: 20_000,
customerYearKg: 6_000,
monthKg: 1_000,
monthFee: 8_000,
monthRevenue: 7_500,
monthProfit: 1_500,
todayKg: 100,
todayFee: 800,
todayRevenue: 750,
todayProfit: 150,
lingniuBornKg: 0,
lingniuBornFee: 0,
};
test('重量和金额单位保持现有阈值及负数格式', () => {
assert.deepEqual(formatKg(999.5), { value: '999.50', unit: 'Kg' });
assert.deepEqual(formatKg(1000), { value: '1.00', unit: 'T' });
assert.deepEqual(formatYuan(9999), { value: '9,999', unit: '元' });
assert.deepEqual(formatYuan(12345), { value: '1.23', unit: '万元' });
assert.deepEqual(formatYuan(-100_000_000), { value: '-1.00', unit: '亿元' });
});
test('相对更新时间保持秒、分钟、小时和未来时间边界', () => {
const now = new Date(2026, 7, 13, 12, 0, 0).getTime();
assert.equal(formatRelative(now + 60_000, now), '刚刚');
assert.equal(formatRelative(now - 30_000, now), '30 秒前');
assert.equal(formatRelative(now - 5 * 60_000, now), '5 分钟前');
assert.equal(formatRelative(now - 3 * 60 * 60_000, now), '3 小时前');
});
test('总览派生指标保持月份顺序、动能、集中度和收益率口径', () => {
const data = {
kpi: {
yearKg: 1000,
yearFee: 0,
yearProfit: -50,
ourYearKg: 0,
customerYearKg: 0,
ourYearFee: 0,
yearRevenue: 500,
monthKg: 0,
monthFee: 0,
monthRevenue: 0,
monthProfit: 0,
todayKg: 0,
todayFee: 0,
todayRevenue: 0,
todayProfit: 0,
lingniuBornKg: 0,
lingniuBornFee: 0,
},
top5: [{ id: 1, rank: 1, name: 'A', kg: 600, fee: 100, share: 0.6 }],
regions: [],
monthly: [
{ month: '2026-01', kg: 100, fee: 20, revenue: 30, profit: 10 },
{ month: '2026-02', kg: 150, fee: 30, revenue: 40, profit: 10 },
],
customers: [],
stations: [
{ id: 1, name: 'A', kg: 600, share: 0.6, revenue: 300, revenueShare: 0.6 },
{ id: 2, name: 'B', kg: 400, share: 0.4, revenue: 200, revenueShare: 0.4 },
],
availableYears: [2026],
year: 2026,
latestLedgerTime: '2026-08-17 21:50:09',
filter: { stationId: null, vehicleScope: 'all', verifyScope: 'all' },
} satisfies HydrogenOverviewResponse;
const metrics = deriveOverviewMetrics(data);
assert.equal(metrics.monthAvgKg, 125);
assert.equal(metrics.bestMonth?.month, '2026-02');
assert.equal(metrics.latestMonth?.month, '2026-02');
assert.equal(metrics.monthMomentum, 50);
assert.equal(metrics.top5Share, 60);
assert.equal(metrics.customerGrossMarginPct, -10);
assert.equal(metrics.stationAvgKg, 500);
assert.deepEqual(metrics.monthlyDual.map(item => item.monthLabel), ['1月', '2月']);
});
test('KPI 下钻只使用真实汇总口径且保留客户单毛利语义', () => {
const payload = buildMetricDrillPayload(drillKpi, 'yearProfit');
assert.equal(payload.title, '客户单毛利');
assert.equal(payload.metrics[0]?.label, '客户单毛利');
assert.equal(payload.metrics[0]?.value, '¥1.5 万元');
assert.equal(payload.rows.length, 0);
assert.match(payload.emptyMessage ?? '', /未返回站点、客户、车牌及单笔订单层级/);
});
test('月度下钻按接口返回的羚牛与外部车辆加氢量拆分', () => {
const payload = buildMonthDrillPayload({
month: '2026-08',
kg: 1_000,
lingniuKg: 700,
externalKg: 300,
fee: 4_500,
revenue: 5_000,
profit: 500,
});
assert.equal(payload.rows[0]?.category, '羚牛车辆');
assert.equal(payload.rows[0]?.share, '70.0%');
assert.equal(payload.rows[1]?.share, '30.0%');
assert.equal(payload.metrics[3]?.label, '客户单毛利');
});
test('省级区域下钻仅关联同省真实站点,市级缺少映射时明确空态', () => {
const stations = [
{ id: 1, name: '嘉兴站', province: '浙江', kg: 600, revenue: 1_000, share: 0.6, revenueShare: 0.5 },
{ id: 2, name: '广州站', province: '广东', kg: 400, revenue: 1_000, share: 0.4, revenueShare: 0.5 },
];
const provincePayload = buildRegionDrillPayload({ region: '浙江', kg: 600, share: 0.6 }, stations, 'province');
assert.equal(provincePayload.rows.length, 1);
assert.equal(provincePayload.rows[0]?.station, '嘉兴站');
const cityPayload = buildRegionDrillPayload({ region: '嘉兴', kg: 600, share: 0.6 }, stations, 'city');
assert.equal(cityPayload.rows.length, 0);
assert.match(cityPayload.emptyMessage ?? '', /未返回城市字段/);
});
test('站点与客户弹层提供汇总指标及真实事件入口', () => {
const stationPayload = buildStationDrillPayload({ id: 9, name: '测试站', province: '广东', kg: 900, revenue: 3_000, share: 0.3, revenueShare: 0.4 });
assert.equal(stationPayload.primaryActionLabel, '进入单站视图');
assert.equal(stationPayload.metrics[0]?.value, '900.00 Kg');
const customerPayload = buildCustomerDrillPayload({ name: '测试客户', payer: 'customer', kg: 500, cost: 2_000, revenue: 2_500 });
assert.equal(customerPayload.metrics[3]?.label, '价差');
assert.equal(customerPayload.metrics[3]?.value, '¥500 元');
});