visionA/visionA-frontend/src/lib/hardware-compat.test.ts
jim800121chen 051994ed54 feat(workspace): 圖片/影片/批次推論 tab + 載入模型到裝置 FlashDialog(前端)
推論工作區前端塔3 + flash 前端(i18n/device-detail 交纏、一批 commit)。

塔3(圖片/影片/批次 tab、複用塊1/2 顯示管線 0 重造):
- media.ts 上傳 helper(XHR image/video/batch)+ media-uploader + media-tab
- workspace-client 3 tab 打開 + activeTab 互斥 camera/media WS
- video seek 用後端 durationSeconds 換算(脫離 fps 耦合、Reviewer M-1 修正)
- 補 tab 切換 WS reset 測試(S-1)
- Reviewer 2 輪通過

flash 前端(載入模型到裝置、補「進工作區前置」缺口,照 POC 移植):
- flash-dialog + flash-progress(選 model + 相容性檢查 + WS 進度)
- flash-store(throw-based ApiError)
- use-flash-progress(onOpen 才 POST 防 race + hasStartedRef 防重連重複)
- hardware-compat(targetChip 單值、寧鬆勿嚴、UX 警示非安全閘)
- device-detail-client 掛 FlashDialog(gate 未改、flash 完 fetchDevice 解鎖)
- Reviewer 0C/0M

契約:same-origin cookie、WS/stream/upload URL 相對路徑無 token、i18n 雙語對稱、
設計 token 不裸色值。全前端 tsc/eslint clean、塔3 30 test + flash 45 test 綠。
(全套 11 failed 全屬 conversion-store 既有 flaky、未觸碰)

follow-up:flash WS 逾時提示(Mi)、--success token(design)、conversion-store flaky 釐清。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-09 06:27:14 +08:00

70 lines
2.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* hardware-compat 單元測試flash UI 契約層)
*
* 驗證重點(契約差異 CtargetChip 單值 + 寧鬆勿嚴):
* - device.type 各種變體正規化成小寫晶片代號
* - 相容比對:相同晶片 → true、不同晶片 → false
* - 寧鬆勿嚴targetChip=unknown / device 無法辨識 → true不擋交 agent 把關)
*/
import { describe, expect, it } from "vitest";
import {
getChipFromDeviceType,
getHardwareLabel,
isModelCompatible,
} from "./hardware-compat";
describe("getChipFromDeviceType", () => {
it.each([
["kneron_kl520", "kl520"],
["kneron_kl720", "kl720"],
["KL520", "kl520"],
["kl630", "kl630"],
["KL-730", "kl730"],
["kl_520", "kl520"],
])("正規化 %s → %s", (input, expected) => {
expect(getChipFromDeviceType(input)).toBe(expected);
});
it("空字串回空字串", () => {
expect(getChipFromDeviceType("")).toBe("");
});
it("無法辨識時回小寫原字串", () => {
expect(getChipFromDeviceType("SomeUnknownDevice")).toBe("someunknowndevice");
});
});
describe("isModelCompatible", () => {
it("相同晶片 → 相容", () => {
expect(isModelCompatible("kl520", "kneron_kl520")).toBe(true);
expect(isModelCompatible("kl720", "KL720")).toBe(true);
});
it("不同晶片 → 不相容", () => {
expect(isModelCompatible("kl520", "kneron_kl720")).toBe(false);
expect(isModelCompatible("kl730", "KL520")).toBe(false);
});
it("寧鬆勿嚴targetChip=unknown → 相容(不擋)", () => {
expect(isModelCompatible("unknown", "kneron_kl520")).toBe(true);
});
it("寧鬆勿嚴device 無法辨識晶片 → 相容(不擋,交 agent 把關)", () => {
expect(isModelCompatible("kl520", "some-weird-device")).toBe(true);
expect(isModelCompatible("kl520", "")).toBe(true);
});
});
describe("getHardwareLabel", () => {
it("辨識到晶片 → 回大寫代號", () => {
expect(getHardwareLabel("kneron_kl520")).toBe("KL520");
expect(getHardwareLabel("kl720")).toBe("KL720");
});
it("無法辨識 → 回原字串", () => {
expect(getHardwareLabel("weird")).toBe("weird");
expect(getHardwareLabel("")).toBe("");
});
});