Files
MailUI4Agents/plugins/dsh-mail-bridge/test/mail-session-id.test.mjs
JianFeeeee 429149e118 chore(format): 撤销误入提交的整体重排,并关闭本仓库的格式化器
# 发生了什么

pi-lens 内置「安全格式化」:它会自动安装 biome 并对**编辑过的文件**跑
`biome format --write`。本机原先没有任何 biome 配置,于是 biome 用它自己的
默认值 —— tab 缩进 + 双引号 —— 把文件整体重写。

我在 19a3161 那次提交里用了 `git add -A`,把这批与功能无关的重排一起扫了进去:
约 7000 行改动散落在 20 个文件上,使那次提交无法审查,还掩盖了
server/internal/handler/permission.go 的一处删行(实为文件末尾空行,无代码丢失)。

# 为什么是「关掉」而不是「配置成我们的风格」

试过把缩进/引号/lineWidth 全部对齐本仓库习惯(biome.json + space/2/single/
lineWidth 120):`biome format --write` 仍然改动 17 个文件。原因是本仓库从未按
biome 的规则排版过 —— 注释按语义换行、数组与调用按可读性手工折行,
这些无法由格式化器还原。也就是说只要格式化器开着,每次编辑都会产生与内容无关的
大面积 diff,把真正的改动埋掉。

因此 biome.jsonc 里 formatter 与 linter 都关闭:本仓库的静态检查由
tsc / go vet / tree-sitter / ast-grep 与各自测试套件承担,不引入会改动无关行的
自动修复。

(pi-lens 这一版把 format 服务的 enabled 硬编码为 true,没有配置开关,
所以只能在仓库侧用 biome 配置让它不动文件;已验证 `biome format --write`
对这些文件零改动。)

# 本提交内容

把 19a3161 里除「有意改动」外的 20 个文件还原到重排前的样子。
19a3161 中真正有意的改动是 deploy/install.sh 的扩展注册与
plugins/pi-mail-bridge/extension/index.ts 新文件,两者原样保留。

验证:Go 全量、三桥插件(320/362/409)、前端 196 全绿;
`biome format --write` 对还原后的文件零改动。
2026-09-11 12:03:51 +08:00

65 lines
2.6 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.

/**
* 邮件会话 → DSH 会话 id 的派生约定。
*
* 这组函数存在的原因是一个具体的静默失效:插件重启后 `sessionMap` 为空,
* 人在 WebUI 改档位的 `session_update` 找不到目标会话就被忽略,
* 运行时仍按旧档位执行 —— 人以为自己收紧了权限。
*/
import { test } from 'node:test';
import assert from 'node:assert/strict';
import {
dshSessionIdForMail,
matchesMailSession,
pickMailSession,
} from '../lib/mail-session-id.js';
test('首次尝试的 id 是 mail-<邮件会话 id>', () => {
assert.equal(dshSessionIdForMail('abc-123'), 'mail-abc-123');
});
test('匹配首次尝试的 id', () => {
assert.equal(matchesMailSession('mail-abc', 'abc'), true);
});
test('匹配模型降级重试的 -r<i>', () => {
assert.equal(matchesMailSession('mail-abc-r1', 'abc'), true);
assert.equal(matchesMailSession('mail-abc-r12', 'abc'), true);
});
test('不匹配别的会话(前缀相同也不行)', () => {
assert.equal(matchesMailSession('mail-abcdef', 'abc'), false, 'mail-abc 的前缀不能吃掉 mail-abcdef');
assert.equal(matchesMailSession('mail-abd', 'abc'), false);
assert.equal(matchesMailSession('other-abc', 'abc'), false);
assert.equal(matchesMailSession('', 'abc'), false);
});
test('不匹配非数字后缀(避免误吞其它会话)', () => {
assert.equal(matchesMailSession('mail-abc-rx', 'abc'), false);
assert.equal(matchesMailSession('mail-abc-r', 'abc'), false);
assert.equal(matchesMailSession('mail-abc-retry', 'abc'), false);
});
test('pickMailSession 优先首次尝试,而不是数组顺序', () => {
// 数组顺序可能来自 ctx.agents.list(),与尝试顺序无关
assert.equal(pickMailSession(['mail-abc-r2', 'mail-abc-r1', 'mail-abc'], 'abc'), 'mail-abc');
});
test('pickMailSession 没有首次尝试时取序号最小的重试', () => {
assert.equal(pickMailSession(['mail-abc-r3', 'mail-abc-r1', 'mail-abc-r2'], 'abc'), 'mail-abc-r1');
});
test('pickMailSession 找不到时返回 undefined调用方据此跳过', () => {
assert.equal(pickMailSession(['other-1', 'mail-def'], 'abc'), undefined);
assert.equal(pickMailSession([], 'abc'), undefined);
assert.equal(pickMailSession(undefined, 'abc'), undefined);
});
test('接管的平台会话推不出 id不能被误判成邮件会话', () => {
// 平台自己生成的 id如 DSH 界面里开的会话)与邮件会话无关,
// 匹配函数必须说「不是」,否则会给错误的会话改档位。
assert.equal(matchesMailSession('session-7f3a91', 'abc'), false);
assert.equal(pickMailSession(['session-7f3a91'], 'abc'), undefined);
});