Files
nodeagent/tests/unit/ulid.test.mjs
T
jkooe f4c605cc6d test+fix: 单元测试套件 + 两处细节修复
单元测试(新增,node:test 零依赖):
- tests/unit/: ulid / hmac / ed25519 / acl / validate 共 26 项用例
- 覆盖最关键的安全函数:签名验签、ACL 授权、参数校验
- 新增 pnpm test:unit;CI 增加单元测试步骤

细节修复:
1. screen.info 的 scale 硬编码为 1 → 改读注册表 HKCU AppliedDPI,
   真实反映 Windows DPI 缩放(100% -> 1.0, 150% -> 1.5)
2. verify.mjs 升级:支持多设备配置(resolveTarget)+ ed25519 模式 + Hub 中转
   (此前直接用旧的扁平配置 + 仅 psk,配了多设备会取不到 host)

验证:构建 + 类型检查全绿;单元 26/26;E2E 21/21;verify.mjs 13/0/3
2026-09-27 17:04:21 +08:00

29 lines
905 B
JavaScript

import { test } from 'node:test';
import assert from 'node:assert/strict';
import { ulid } from '../../packages/protocol/dist/index.js';
test('ulid:格式为 26 字符 Crockford Base32', () => {
const id = ulid();
assert.equal(id.length, 26);
assert.match(id, /^[0-9A-HJKMNP-TV-Z]+$/, '应只含 Crockford Base32 字符集');
});
test('ulid:大量生成无重复', () => {
const set = new Set();
for (let i = 0; i < 2000; i += 1) set.add(ulid());
assert.equal(set.size, 2000, '2000 个 ULID 应全部唯一');
});
test('ulid:同毫秒与跨毫秒均单调递增', () => {
const a = ulid(1000);
const b = ulid(1000); // 同毫秒
const c = ulid(1001);
assert.ok(a < b, `同毫秒应递增 (${a} vs ${b})`);
assert.ok(b < c, '跨毫秒应递增');
});
test('ulid:时间戳 0 编码为全 0', () => {
const id = ulid(0);
assert.equal(id.slice(0, 10), '0000000000');
});