## 别名替换(让 .new 邮件可寻址)
repo/autoalias.go: AutoAliasFor + EnsureSessionAlias
- .new 建完会话立刻给别名(形如 dsh-重构导入路径)
- 名字与主题都要:只用主题跨 Agent 撞名,只用名字看不出聊什么
- sanitizeAliasPart 只留 unicode.IsLetter/IsDigit,其余折 -
- 撞名追加 -2/-3,全占用退 session-<uuid前8位>
- 不复用 SyncSessionAlias:那个假定已存在且跳过 manual
- 条件写入 WHERE alias IS NULL OR '',并发安全
- resolveTarget 的 .new 与默认会话两条路径都调
notifyRecipients 加三个字段(每个收件方拿到自己那个地址的版本):
- session_alias / reply_address / self_address
- 别名为空时退回省略 session 位,绝不写 new
FormatAddress(name,path,session) 空 path 也必须留 @ 与 .
## Agent 侧寻址发现(五个只读端点)
handler/agent_discovery.go:
- /agent/contacts + /agent/contacts/suggest(三段式补全)
- /agent/mail/{id} + /agent/mail/{id}/thread
- /agent/sessions/{id}/participants
- 不复用人类路由:scope 不同、审计需求不同
- 一律只读:归档/改名/权限决策仍只有人能做
repo/participants.go: SessionParticipants 逐封扫 from/to/cc
- Roles 用集合、MailCount 只数发信(0=还没开口的人)
- 发件人 path 不取 from_workspace(那列存的是 Agent 名)
repo.SuggestPaths 重写:mails.to_workspace(按 MAX(created_at) 倒序)
+ agents.workspaces 并集。原只读 workspaces,官方插件传 [] 永远空
## 共用模块(三插件逐字节相同)
lib/addressing.js: formatAddress/roleOf/replyAddressFor/selfAddressFor/participantsOfMail
lib/discovery.js: renderNameSuggestions/renderPathSuggestions/renderSessionSuggestions/
renderParticipants/renderContacts/renderThread
lib/inbox-format.js: renderMail 新增收件人/身份/可投递地址三段
- selfName 参数(兼容旧调用不传的情况)
check-shared-libs.sh 纳入 addressing + discovery
## 插件侧
opencode: suggest_address + list_contacts + session_participants + read_thread + read_mail
dsh: 同上 + forward_mail(此前只有 opencode 有)+ upload_attachment 改真 multipart
pi: 同上(createMailTools 加 agentName 参数)
dsh: ctx.agents.create id collision 改为 readSession 探测后 resume
dsh: 关键路径日志改 console.error(ctx.logger 不进 journalctl)
## 测试
repo: autoalias_test.go 11 + participants_test.go 7 = 18 例
plugins: addressing.test 17 + discovery.test 23 + inbox-format.test 31 = 71 例
go test ./... + npm test(opencode 155 + dsh 173 + pi 199)全绿
端到端验证:admin 发 dsh@....new 抄送 opencode@....new
→ dsh 用 session_participants 取到地址 → send_mail 给 opencode
→ 地址取自工具返回值(.crisp-planet),未手工拼写
81 lines
3.1 KiB
TypeScript
81 lines
3.1 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
||
import { render, screen } from '@testing-library/react';
|
||
import React from 'react';
|
||
|
||
import { BudgetChip } from '../../src/components/WorkCard';
|
||
|
||
/**
|
||
* 往返预算徽标。
|
||
*
|
||
* 它是「这个任务还剩几个来回」的唯一视觉提示,两件事必须对:
|
||
* - 显示的是**剩余**而不是已用(人做决定看的是「还能问几次」)
|
||
* - 0 = 不限时**不显示**,而不是显示「0/0」
|
||
*/
|
||
describe('BudgetChip 预算渲染', () => {
|
||
it('显示剩余数而不是已用数', () => {
|
||
render(React.createElement(BudgetChip, { max: 20, used: 3 }));
|
||
|
||
// 20 个上限、用了 3 个 → 剩 17。显示 3/20 会让人以为快用完了
|
||
expect(screen.getByText('17/20')).toBeInTheDocument();
|
||
});
|
||
|
||
it('max 为 0(不限)时完全不渲染', () => {
|
||
const { container } = render(React.createElement(BudgetChip, { max: 0, used: 0 }));
|
||
|
||
// 「0/0」或「不限」对每张卡片都成立,等于纯噪声
|
||
expect(container.firstChild).toBeNull();
|
||
});
|
||
|
||
it('max 为负数时也不渲染(脏数据兜底)', () => {
|
||
const { container } = render(React.createElement(BudgetChip, { max: -1, used: 0 }));
|
||
expect(container.firstChild).toBeNull();
|
||
});
|
||
|
||
it('用超时剩余按 0 显示,不出现负数', () => {
|
||
render(React.createElement(BudgetChip, { max: 5, used: 8 }));
|
||
|
||
// 「-3/5」看起来像 bug,而实际情形(免配额转发不计数、人手动下调过上限)是合法的
|
||
expect(screen.getByText('0/5')).toBeInTheDocument();
|
||
});
|
||
|
||
it('剩余为 0 时转红并标注「已用尽」', () => {
|
||
render(React.createElement(BudgetChip, { max: 5, used: 5 }));
|
||
|
||
const chip = screen.getByText('0/5').closest('span')!;
|
||
expect(chip.className).toContain('bg-red-100');
|
||
expect(chip.getAttribute('title')).toContain('已用尽');
|
||
});
|
||
|
||
it('剩余 1 个时转橙 —— 那是需要人介入的时刻', () => {
|
||
render(React.createElement(BudgetChip, { max: 20, used: 19 }));
|
||
|
||
const chip = screen.getByText('1/20').closest('span')!;
|
||
// 要么加预算,要么让它收尾;这一步不提示的话下一封信就被挡住了
|
||
expect(chip.className).toContain('bg-orange-100');
|
||
});
|
||
|
||
it('余量充足时用中性灰,不抢注意力', () => {
|
||
render(React.createElement(BudgetChip, { max: 20, used: 2 }));
|
||
|
||
const chip = screen.getByText('18/20').closest('span')!;
|
||
expect(chip.className).toContain('bg-gray-100');
|
||
expect(chip.className).not.toContain('red');
|
||
expect(chip.className).not.toContain('orange');
|
||
});
|
||
|
||
it('title 里带已用/上限,供悬停查看细节', () => {
|
||
render(React.createElement(BudgetChip, { max: 20, used: 7 }));
|
||
|
||
const chip = screen.getByText('13/20').closest('span')!;
|
||
// 徽标上只有剩余,具体用了几个放在 title 里 —— 徽标要窄
|
||
expect(chip.getAttribute('title')).toContain('已用 7/20');
|
||
});
|
||
|
||
it('剩余 2 个时还不转橙(阈值是 <= 1)', () => {
|
||
render(React.createElement(BudgetChip, { max: 10, used: 8 }));
|
||
|
||
const chip = screen.getByText('2/10').closest('span')!;
|
||
expect(chip.className).toContain('bg-gray-100');
|
||
});
|
||
});
|