Files
nodeagent/tests/unit/install-zerotrust.test.mjs
T
jkooe e23788d717 refactor(versioning): 统一版本号 —— semver 为唯一版本号,开发批次代号并入其归属版本
## 问题(皇上指出)
项目里两套编号并行,无法判断哪个是"当前版本":
- **发布版本**(semver):v1.1.0 ~ v1.6.0、v2.0.0
- **开发批次代号**:v1 ~ v26(README 路线表 / 代码注释 / 文档)
时间线证据:v1.1.0 首发(09-29)时批次已推进到 v12.4 —— **二者从来不是一对一**(26 批次只发过 10 版)。

## 规则(新增 docs/VERSIONING.md §0 版本号唯一性规范)
- **唯一版本号 = semver `vX.Y.Z`**,两个来源必须永远一致:git tag 与 package.json(构建期注入 agent)
- **批次代号不是版本号**,不再单独出现;需要区分同版内多批改动时用**功能名**
- 附「批次 → 归属发布版本」映射表(按 tag 时间线与功能内容推定,并注明以 CHANGELOG 为准)

## 统一动作
1. **批次 v23 ~ v26 → v2.0.0**(22 文件 / 53 处)—— 它们确实属于 v2.0.0
2. **臣的批次号 v1.7 / v1.8 → v2.0.0**(27 文件)—— 未单独发版
3. **简写补全三段式**:v1.5 → v1.5.0、v1.6 → v1.6.0
4. **README 路线表**:`**v1**` → `**批次 1**`;表头加「批次 ≠ 版本号」说明并链到 §0;
   补齐批次 16~29 与 **v2.0.0 发布行**;删掉过时的「待办」行(提到的分支早已删除)
5. `docs/VERSIONING.md` 里**故意保留** 3 处批次号 —— 那是规范说明本身

## 保留项(真实发布版本,不动)
v1.1.0 / v1.2.1 / v1.3.0 / v1.4.0~v1.4.3 / v1.5.0 / v1.6.0 / v2.0.0(10 个 tag)

## 验证
- 版本号一致性:package.json = tag = 8 个 workspace = tauri.conf.json = **2.0.0** ✓
- v1.7/v1.8/v23~v26 全仓残留 **3 处**(均在 VERSIONING.md 规范说明中,属预期)
- 7 包构建 · 单测 273 · e2e 30 · ps1-encoding 24 全绿
2026-10-10 14:27:12 +08:00

58 lines
2.8 KiB
JavaScript
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.
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';
import { join } from 'node:path';
import { fileURLToPath } from 'node:url';
/**
* 零信任优先安装(v2.0.0)的**源码断言**。
*
* 为什么用源码断言:install.ps1 是 5.1 脚本,Node 侧无法直接执行它;
* 而这里要守的是「关键决策逻辑不许被误删」—— 一旦有人重构掉 acl 写入或
* 告警文案,测试立刻红。运行时的正确性已在真机用等效片段验证过
* (CASE A ed25519+deny / CASE B psk 无 acl / CASE C 缺字段回退 psk)。
*/
const ROOT = fileURLToPath(new URL('../../', import.meta.url));
const ps1 = readFileSync(join(ROOT, 'scripts', 'install.ps1'), 'utf8');
test('install.ps1 有 ClientAclFile 参数(零信任入口)', () => {
assert.match(ps1, /\[string\]\$ClientAclFile/, '缺少 -ClientAclFile 参数');
});
test('install.ps1 默认探测脚本同目录的 client-acl.json', () => {
assert.match(ps1, /client-acl\.json/, '缺少默认探测路径');
assert.match(ps1, /\$scriptDir/, '应用 $scriptDir 兜底(-Command 调用时 $PSScriptRoot 为空)');
});
test('install.ps1 有 useZeroTrust 判定且 auth_mode 条件化', () => {
assert.match(ps1, /\$useZeroTrust\s*=/, '缺少 useZeroTrust 判定');
assert.match(ps1, /auth_mode\s*=\s*if \(\$useZeroTrust\)/, 'auth_mode 必须按零信任开关条件化');
});
test('零信任分支写入 acl 且 default_effect=deny(兜底拒绝)', () => {
assert.match(ps1, /default_effect\s*=\s*"deny"/, 'default_effect 必须是 deny(未登记一律拒)');
assert.match(ps1, /clients\s*=\s*@\(\$aclEntry\)/, '缺少 clients 数组写入');
});
test('缺 client_id/pubkey 时忽略并回退(不写半截 ACL)', () => {
assert.match(ps1, /-not \$aclEntry\.client_id -or -not \$aclEntry\.pubkey/, '缺少字段校验');
assert.match(ps1, /\$aclEntry = \$null/, '校验失败必须置空以回退');
});
test('psk 路径必须给出醒目安全告警(不能静默降级)', () => {
assert.match(ps1, /SECURITY WARNING/, 'psk 分支缺少醒目告警');
assert.match(ps1, /SELF-REPORTED/, '告警须说明 client_id 可自报这一固有问题');
assert.match(ps1, /nodeagent keygen/, '告警须给出切换命令');
assert.match(ps1, /Yellow/, '告警须用醒目颜色(Yellow)');
});
test('零信任路径给出正确的连接指引(--id + --auth-mode)', () => {
assert.match(ps1, /--auth-mode ed25519/, '缺少 ed25519 连接示例');
assert.match(ps1, /Zero-trust is ON/, '缺少启用确认输出');
});
test('安装写入的 JSON 用 -Depth 6(acl 嵌套不会被截断)', () => {
assert.match(ps1, /ConvertTo-Json -Depth 6/, 'acl 是嵌套结构,Depth 不足会被截成字符串');
});