/** * read_inbox 必须收窄到**自己那条会话**(用户:「你还是没修好不同 session agent * 收件箱隔离的问题」)。 * * 缺陷:列表按 Agent 列,且 read_inbox 按契约把列出的都标已读 ⇒ A 会话的回合把 * B 会话的未读标掉 ⇒ B 之后按 `?status=unread` 补投时再也看不到那封信(静默丢信)。 * 服务端语义由 server/internal/repo/session_scope_test.go 负责,这里只验接线。 */ import { test } from 'node:test'; import assert from 'node:assert/strict'; import { readFileSync } from 'node:fs'; import { dirname, join } from 'node:path'; import { fileURLToPath } from 'node:url'; const src = readFileSync(join(dirname(fileURLToPath(import.meta.url)), '..', 'index.js'), 'utf8'); test('read_inbox 的 URL 会拼上会话收窄', () => { assert.match(src, /mail\/inbox\?status=\$\{filter\}&limit=\$\{limit\}\$\{scope\}/); assert.match(src, /session_id=\$\{encodeURIComponent\(mailSessionID\)\}/); }); test('★ 会话来源是平台上下文(并发安全),不是模块级变量', () => { assert.match(src, /async execute\(args, context\)/, '工具要接住第二个参数'); assert.match(src, /reverseMap\.get\(String\(context\?\.sessionID/, '经 reverseMap 换邮件会话'); assert.ok(!/let\s+currentMailSessionID/.test(src), '不得用模块级"当前会话"变量'); }); test('★ 判据自检:不带收窄的旧写法必须判红', () => { const old = '`/mail/inbox?status=${filter}&limit=${limit}`'; assert.ok(!/\$\{scope\}/.test(old)); });