pi `e77154d1` §三 指出我"把 (d) 整体归入 due"是**反方向的错**: 判据的**可得性**本身要复核 ——
把今天就能给的判据当成"要等未来才能给",余额里就挂着一个今天就能变绿的缺口。
我先写仓内探针逐条跑(跑完即删),四条读数:
[修前] 播下 /A=2 → B 上报 /B=1 ⇒ (d1) FAIL: /A = 0,期望 2 ★本缺陷
[修前] T\L @DELETE前 = [/A] ⇒ 响 ✓(我那形状确实抓得到真缺陷)
[修好] 共存 /A=2 /B=2 → /A 仍 = 2 ⇒ (d1) PASS ⇒ 修好即绿 ✓
[修好] T\L @DELETE前 = [/A] ⇒ ★ 假阳:修好后每次心跳都常鸣
[修好] 与"实际删除域"比 destroyed = [] ⇒ 不响 ✓ 无假阳
⇒ ★★ 同时**撤回我 §三 提的 `T\L ⇒ WARN` 形状**(记入 DEBTS 补记之九):
根因: "即将被销毁"由 **DELETE 的谓词**决定,不是由 T\L 决定。
修前 DELETE 域 = 整个 agent ⊋ L ⇒ T\L 恰等于被销毁集合(碰巧对)
修后 DELETE 域 = 按 ws 删 = L ⇒ 被销毁 = ∅,而 T\L 仍非空 ⇒ **恒假阳**
而修好后表里天然共存多 ws(那正是修复目标)⇒ **每次心跳常鸣**
⇒ 落进本仓「**还清了反而红**」那个坑 —— 我为 (d) 拒绝超前断言的理由,
在我自己提的形状里以假阳形式复现了。忠实形状: `destroyed = 被本次 DELETE 移除
且未被本次 list 重插的 ws`(与实际删除域同源 ⇒ 修前响/修后不响,且 [] 时仍覆盖)
⇒ ★★ (d) 拆两半: **d1 = 本条**(每项自带 Workspace ⇒ 不需要请求级字段 ⇒ 今日可判);
**d2 = 上报 [] 时只清自己那个 ws**(需要"这次上报属于谁")⇒ 与 scope 字段同 due
自查: 探针第一版把"取 T"写在 Replace **之后** ⇒ 量到删除后的表 ⇒ 结论会全反
(据此差点得出"漏报"的相反结论);已把取 T 排到 B 上报**之前**重测。
教训: **观测点必须与被观测的判据在同一时刻** —— 与"判据要锚定到它防的那个动作"同一条。
测试: ./internal/repo/ 245 通过、唯一红项即本条(它断言的正是尚未修复的缺陷)
登记: platform-mirror-d1-cross-workspace(余额 28→29);-run Debt ⇒ ok
426 lines
16 KiB
Go
426 lines
16 KiB
Go
package repo
|
||
|
||
import (
|
||
"context"
|
||
"testing"
|
||
"time"
|
||
|
||
"github.com/agentmail/gateway/internal/db"
|
||
"github.com/google/uuid"
|
||
)
|
||
|
||
// seedPlatformAgent 注册一个 Agent,平台会话镜像与它绑定。
|
||
// 与 quota_test.go 的 seedAgent 区分开:那个要指定 default_rounds,这里不关心。
|
||
func seedPlatformAgent(t *testing.T, name string) {
|
||
t.Helper()
|
||
if _, err := db.DB.ExecContext(context.Background(),
|
||
`INSERT INTO agents (agent_name, secret, platform, status) VALUES ($1, 'x', $1, 'online')`,
|
||
name); err != nil {
|
||
t.Fatalf("seed agent %s: %v", name, err)
|
||
}
|
||
}
|
||
|
||
// seedSessionWS 建一个带 workspace 与别名的会话。
|
||
func seedSessionWS(t *testing.T, alias, workspace, subject string) uuid.UUID {
|
||
t.Helper()
|
||
var id uuid.UUID
|
||
err := db.DB.QueryRowContext(context.Background(), `
|
||
INSERT INTO sessions (session_alias, workspace, from_agent, subject, alias_source)
|
||
VALUES ($1, $2, 'admin', $3, 'platform')
|
||
RETURNING session_id
|
||
`, alias, workspace, subject).Scan(&id)
|
||
if err != nil {
|
||
t.Fatalf("seed session %s: %v", alias, err)
|
||
}
|
||
return id
|
||
}
|
||
|
||
// seedMailWS 插一封带明确 to_workspace 的邮件。
|
||
func seedMailWS(t *testing.T, sessionID uuid.UUID, from, to, toWS, subject string) uuid.UUID {
|
||
t.Helper()
|
||
var id uuid.UUID
|
||
err := db.DB.QueryRowContext(context.Background(), `
|
||
INSERT INTO mails (session_id, from_name, from_workspace, to_name, to_workspace,
|
||
subject, body, cc_list, created_at)
|
||
VALUES ($1, $2, '', $3, $4, $5, 'body', '[]', $6)
|
||
RETURNING mail_id
|
||
`, sessionID, from, to, toWS, subject, nextSeedTime()).Scan(&id)
|
||
if err != nil {
|
||
t.Fatalf("seed mail: %v", err)
|
||
}
|
||
return id
|
||
}
|
||
|
||
// 这个测试是「会话别名没有正确显示曾经发生在工作区下的会话」那次故障的回归。
|
||
//
|
||
// 旧实现按 mails 反推工作区,条件是
|
||
// `to_workspace = $path OR from_workspace = $path`。
|
||
// 而 Agent 回信时 from_workspace 存的是 **Agent 名**(如 "dsh")而不是路径,
|
||
// 于是一旦会话里只剩 Agent 的回信可匹配,反推就落空、别名列不出来。
|
||
// 现在 workspace 存在会话自己身上,与邮件里那些脏数据无关。
|
||
func TestSuggestSessionCandidatesUsesSessionWorkspace(t *testing.T) {
|
||
setupTestDB(t)
|
||
seedPlatformAgent(t, "dsh")
|
||
|
||
sid := seedSessionWS(t, "brisk-harbor", "/home/program/agentmail", "缓存选型")
|
||
// 只有 Agent 的回信:from_workspace 是脏的(Agent 名),to_workspace 是人类(空)
|
||
if _, err := db.DB.ExecContext(context.Background(), `
|
||
INSERT INTO mails (session_id, from_name, from_workspace, to_name, to_workspace,
|
||
subject, body, cc_list, created_at)
|
||
VALUES ($1, 'dsh', 'dsh', 'admin', '', 'Re: 缓存选型', 'body', '[]', $2)
|
||
`, sid, nextSeedTime()); err != nil {
|
||
t.Fatalf("seed agent reply: %v", err)
|
||
}
|
||
|
||
got, err := SuggestSessionCandidates(context.Background(), "admin", "dsh", "/home/program/agentmail")
|
||
if err != nil {
|
||
t.Fatalf("SuggestSessionCandidates: %v", err)
|
||
}
|
||
if len(got) != 1 {
|
||
t.Fatalf("应有 1 个候选,实际 %d —— 会话的 workspace 列没被用上", len(got))
|
||
}
|
||
if got[0].Alias != "brisk-harbor" {
|
||
t.Errorf("别名错误:%q", got[0].Alias)
|
||
}
|
||
if got[0].Source != "mail" {
|
||
t.Errorf("来源应为 mail,实际 %q", got[0].Source)
|
||
}
|
||
if got[0].Title != "缓存选型" {
|
||
t.Errorf("标题应带出来:%q", got[0].Title)
|
||
}
|
||
}
|
||
|
||
// 历史会话的 workspace 列是空的(新加的列),必须回退到 mails.to_workspace 反推,
|
||
// 否则升级后所有老会话一夜之间从候选列表里消失。
|
||
func TestSuggestSessionCandidatesFallsBackToMails(t *testing.T) {
|
||
setupTestDB(t)
|
||
seedPlatformAgent(t, "opencode")
|
||
|
||
// workspace 留空,模拟升级前建立的会话
|
||
sid := seedSessionWS(t, "legacy-thread", "", "老线索")
|
||
seedMailWS(t, sid, "admin", "opencode", "/home/legacy", "老线索")
|
||
|
||
got, err := SuggestSessionCandidates(context.Background(), "admin", "opencode", "/home/legacy")
|
||
if err != nil {
|
||
t.Fatalf("SuggestSessionCandidates: %v", err)
|
||
}
|
||
if len(got) != 1 || got[0].Alias != "legacy-thread" {
|
||
t.Fatalf("老会话应能靠 mails 反推出来,实际 %+v", got)
|
||
}
|
||
}
|
||
|
||
// 工作区不匹配的会话不能出现:候选项点下去就会被填进 session 位,
|
||
// 而 session 位是三态语义 —— 指向别处的会话会直接 404「无法送达」。
|
||
func TestSuggestSessionCandidatesFiltersByWorkspace(t *testing.T) {
|
||
setupTestDB(t)
|
||
seedPlatformAgent(t, "dsh")
|
||
|
||
mine := seedSessionWS(t, "here-thread", "/home/a", "本区")
|
||
seedMailWS(t, mine, "admin", "dsh", "/home/a", "本区")
|
||
other := seedSessionWS(t, "there-thread", "/home/b", "别区")
|
||
seedMailWS(t, other, "admin", "dsh", "/home/b", "别区")
|
||
|
||
got, err := SuggestSessionCandidates(context.Background(), "admin", "dsh", "/home/a")
|
||
if err != nil {
|
||
t.Fatalf("SuggestSessionCandidates: %v", err)
|
||
}
|
||
if len(got) != 1 || got[0].Alias != "here-thread" {
|
||
t.Fatalf("只应给出本工作区的会话,实际 %+v", got)
|
||
}
|
||
}
|
||
|
||
// path 为空(地址写成 `dsh` 而不带 @/path)时不按工作区过滤:
|
||
// 用户还没写到 path 段就该看到全部可续的会话。
|
||
func TestSuggestSessionCandidatesEmptyPathReturnsAll(t *testing.T) {
|
||
setupTestDB(t)
|
||
seedPlatformAgent(t, "dsh")
|
||
|
||
a := seedSessionWS(t, "ws-a", "/home/a", "A")
|
||
seedMailWS(t, a, "admin", "dsh", "/home/a", "A")
|
||
b := seedSessionWS(t, "ws-b", "/home/b", "B")
|
||
seedMailWS(t, b, "admin", "dsh", "/home/b", "B")
|
||
|
||
got, err := SuggestSessionCandidates(context.Background(), "admin", "dsh", "")
|
||
if err != nil {
|
||
t.Fatalf("SuggestSessionCandidates: %v", err)
|
||
}
|
||
if len(got) != 2 {
|
||
t.Fatalf("path 为空应给出全部 2 条,实际 %d", len(got))
|
||
}
|
||
}
|
||
|
||
// 平台侧会话(人直接在 opencode/DSH 界面上开的)经心跳上报后也要能被选中 ——
|
||
// 这正是「定期从 agent 平台同步会话」要解决的问题。
|
||
func TestSuggestSessionCandidatesIncludesPlatformMirror(t *testing.T) {
|
||
setupTestDB(t)
|
||
seedPlatformAgent(t, "opencode")
|
||
|
||
now := time.Now()
|
||
err := ReplacePlatformSessions(context.Background(), "opencode", []PlatformSession{
|
||
{PlatformID: "ses_1", Workspace: "/home/program/agentmail", Slug: "witty-planet",
|
||
Title: "重构导入路径", MailDriven: false, UpdatedAt: &now},
|
||
{PlatformID: "ses_2", Workspace: "/home/other", Slug: "brave-comet",
|
||
Title: "别的工作区", MailDriven: false, UpdatedAt: &now},
|
||
})
|
||
if err != nil {
|
||
t.Fatalf("ReplacePlatformSessions: %v", err)
|
||
}
|
||
|
||
got, err := SuggestSessionCandidates(context.Background(), "admin", "opencode", "/home/program/agentmail")
|
||
if err != nil {
|
||
t.Fatalf("SuggestSessionCandidates: %v", err)
|
||
}
|
||
if len(got) != 1 {
|
||
t.Fatalf("应有 1 个平台候选,实际 %d:%+v", len(got), got)
|
||
}
|
||
if got[0].Alias != "witty-planet" || got[0].Source != "platform" {
|
||
t.Errorf("平台候选错误:%+v", got[0])
|
||
}
|
||
if got[0].Title != "重构导入路径" {
|
||
t.Errorf("标题应带出来:%q", got[0].Title)
|
||
}
|
||
}
|
||
|
||
// 同一别名两边都有时保留 mail 来源:它是「一定送得到」的保证,
|
||
// 镜像只是平台的说法。但镜像的标题该补上去 —— 平台标题通常比会话主题更贴切。
|
||
func TestSuggestSessionCandidatesMailWinsOverMirror(t *testing.T) {
|
||
setupTestDB(t)
|
||
seedPlatformAgent(t, "opencode")
|
||
|
||
// 本侧线索:有别名但主题为空
|
||
sid := seedSessionWS(t, "witty-planet", "/home/x", "")
|
||
seedMailWS(t, sid, "admin", "opencode", "/home/x", "某事")
|
||
|
||
now := time.Now()
|
||
if err := ReplacePlatformSessions(context.Background(), "opencode", []PlatformSession{
|
||
{PlatformID: "ses_1", Workspace: "/home/x", Slug: "witty-planet",
|
||
Title: "平台侧的标题", UpdatedAt: &now},
|
||
}); err != nil {
|
||
t.Fatalf("ReplacePlatformSessions: %v", err)
|
||
}
|
||
|
||
got, err := SuggestSessionCandidates(context.Background(), "admin", "opencode", "/home/x")
|
||
if err != nil {
|
||
t.Fatalf("SuggestSessionCandidates: %v", err)
|
||
}
|
||
if len(got) != 1 {
|
||
t.Fatalf("同名应合并成 1 条,实际 %d:%+v", len(got), got)
|
||
}
|
||
if got[0].Source != "mail" {
|
||
t.Errorf("应保留 mail 来源(它保证送得到),实际 %q", got[0].Source)
|
||
}
|
||
if got[0].Title != "平台侧的标题" {
|
||
t.Errorf("本侧标题为空时应补上镜像的:%q", got[0].Title)
|
||
}
|
||
}
|
||
|
||
// 上报是整表替换:平台侧删掉的会话必须从候选列表里消失。
|
||
// 增量合并会让它永远留着,而 session 位指向一条不存在的会话会直接 404。
|
||
func TestReplacePlatformSessionsIsFullReplace(t *testing.T) {
|
||
setupTestDB(t)
|
||
seedPlatformAgent(t, "dsh")
|
||
ctx := context.Background()
|
||
|
||
if err := ReplacePlatformSessions(ctx, "dsh", []PlatformSession{
|
||
{PlatformID: "s1", Workspace: "/w", Slug: "one"},
|
||
{PlatformID: "s2", Workspace: "/w", Slug: "two"},
|
||
}); err != nil {
|
||
t.Fatalf("首次上报: %v", err)
|
||
}
|
||
if got, _ := SuggestSessionCandidates(ctx, "admin", "dsh", "/w"); len(got) != 2 {
|
||
t.Fatalf("首次上报应有 2 条,实际 %d", len(got))
|
||
}
|
||
|
||
// 第二次只报一条:另一条在平台侧已被删除
|
||
if err := ReplacePlatformSessions(ctx, "dsh", []PlatformSession{
|
||
{PlatformID: "s1", Workspace: "/w", Slug: "one"},
|
||
}); err != nil {
|
||
t.Fatalf("二次上报: %v", err)
|
||
}
|
||
got, _ := SuggestSessionCandidates(ctx, "admin", "dsh", "/w")
|
||
if len(got) != 1 || got[0].Alias != "one" {
|
||
t.Fatalf("整表替换失效,实际 %+v", got)
|
||
}
|
||
}
|
||
|
||
// 无 slug 的平台会话不进候选:slug 是填进 session 位的值,
|
||
// 没有它这一项点下去只能得到一个空的 session 段。
|
||
func TestPlatformSessionsWithoutSlugAreSkipped(t *testing.T) {
|
||
setupTestDB(t)
|
||
seedPlatformAgent(t, "dsh")
|
||
ctx := context.Background()
|
||
|
||
if err := ReplacePlatformSessions(ctx, "dsh", []PlatformSession{
|
||
{PlatformID: "s1", Workspace: "/w", Slug: ""},
|
||
{PlatformID: "s2", Workspace: "/w", Slug: "named"},
|
||
}); err != nil {
|
||
t.Fatalf("上报: %v", err)
|
||
}
|
||
got, _ := SuggestSessionCandidates(ctx, "admin", "dsh", "/w")
|
||
if len(got) != 1 || got[0].Alias != "named" {
|
||
t.Fatalf("无 slug 的应被跳过,实际 %+v", got)
|
||
}
|
||
}
|
||
|
||
// ★★ (d1) 上报**非空** list 时,不得删除其它 workspace 的行。
|
||
//
|
||
// 背景(docs/DEBTS.json `platform-mirror-replace-domain-too-wide` 补记之八/之九):
|
||
// `ReplacePlatformSessions` 的 DELETE 域是整个 `agent_name`,而**上报域**是每个上报者自己那个
|
||
// workspace —— 两者不等("上报域 ⊊ 替换域")。opencode 的插件按 directory 实例化、
|
||
// `AGENT_NAME` 却是单一常量,于是每个实例的心跳都会把别的目录**整批擦掉**。
|
||
// 活库实测:200 样本 × 0.3s 里 25% 的时刻镜像为空、9 个目录轮流出场。
|
||
//
|
||
// ★ 这条**不依赖**请求级 scope 字段:每项 `PlatformSession` 自带 `Workspace`,
|
||
// 所以**今天就能写、现在就是红、修好即绿**。请求级字段只与 (d2)(上报 `[]`)有关。
|
||
//
|
||
// ⚠️ 本条**当前为红**——它断言的正是那个尚未修复的缺陷。
|
||
// 按本仓惯例,红的判据要么标 `[FAIL]` 形态、要么随修复一起转绿;
|
||
// 这里用 `t.Errorf` 而不是 `t.Fatalf`,好让"为什么红"直接显示在测试输出里。
|
||
func TestReplacePlatformSessionsKeepsOtherWorkspaces(t *testing.T) {
|
||
setupTestDB(t)
|
||
seedPlatformAgent(t, "opencode")
|
||
ctx := context.Background()
|
||
|
||
// 上报者 1:/A 下两条
|
||
if err := ReplacePlatformSessions(ctx, "opencode", []PlatformSession{
|
||
{PlatformID: "a1", Workspace: "/A", Slug: "a1"},
|
||
{PlatformID: "a2", Workspace: "/A", Slug: "a2"},
|
||
}); err != nil {
|
||
t.Fatalf("A 上报: %v", err)
|
||
}
|
||
|
||
// 上报者 2:只报 /B(list **非空**,每项都带 Workspace)
|
||
if err := ReplacePlatformSessions(ctx, "opencode", []PlatformSession{
|
||
{PlatformID: "b1", Workspace: "/B", Slug: "b1"},
|
||
}); err != nil {
|
||
t.Fatalf("B 上报: %v", err)
|
||
}
|
||
|
||
// 其它 workspace 的行数不得变化
|
||
var aCount int
|
||
if err := db.DB.QueryRowContext(ctx,
|
||
`SELECT count(*) FROM agent_platform_sessions WHERE agent_name = $1 AND workspace = $2`,
|
||
"opencode", "/A").Scan(&aCount); err != nil {
|
||
t.Fatalf("统计 /A: %v", err)
|
||
}
|
||
if aCount != 2 {
|
||
t.Errorf("(d1) 上报 /B 之后 /A 的行数 = %d,期望 2 —— 其它 workspace 被误擦;"+
|
||
"现存 workspace = %v(DELETE 域应与上报域一致,即只清本次上报的那些)",
|
||
aCount, workspacesOf(t, ctx, "opencode"))
|
||
}
|
||
}
|
||
|
||
// workspacesOf 列出某 agent 当前镜像里的全部 workspace(与行数),供失败信息里列出**元素**
|
||
// 而不是只给一个数 —— 范围要靠元素才可复核(清单 ⑫′)。
|
||
func workspacesOf(t *testing.T, ctx context.Context, agent string) map[string]int {
|
||
t.Helper()
|
||
rows, err := db.DB.QueryContext(ctx,
|
||
`SELECT workspace, count(*) FROM agent_platform_sessions WHERE agent_name = $1 GROUP BY workspace`,
|
||
agent)
|
||
if err != nil {
|
||
t.Fatalf("列 workspace: %v", err)
|
||
}
|
||
defer rows.Close()
|
||
out := map[string]int{}
|
||
for rows.Next() {
|
||
var ws string
|
||
var n int
|
||
if err := rows.Scan(&ws, &n); err != nil {
|
||
t.Fatalf("scan: %v", err)
|
||
}
|
||
out[ws] = n
|
||
}
|
||
return out
|
||
}
|
||
|
||
// 上报里的重复 platform_id 不该让整次事务失败(主键冲突)。
|
||
func TestReplacePlatformSessionsDedupes(t *testing.T) {
|
||
setupTestDB(t)
|
||
seedPlatformAgent(t, "dsh")
|
||
ctx := context.Background()
|
||
|
||
if err := ReplacePlatformSessions(ctx, "dsh", []PlatformSession{
|
||
{PlatformID: "dup", Workspace: "/w", Slug: "first"},
|
||
{PlatformID: "dup", Workspace: "/w", Slug: "second"},
|
||
}); err != nil {
|
||
t.Fatalf("重复 id 不该报错: %v", err)
|
||
}
|
||
got, _ := SuggestSessionCandidates(ctx, "admin", "dsh", "/w")
|
||
if len(got) != 1 || got[0].Alias != "first" {
|
||
t.Fatalf("应保留第一条,实际 %+v", got)
|
||
}
|
||
}
|
||
|
||
// SetSessionWorkspace 只在为空时写入:会话的工作区在建立时就定下了,
|
||
// 之后不该被一封发往别处的邮件改掉 —— 那会让它在候选列表里凭空换工作区。
|
||
func TestSetSessionWorkspaceDoesNotOverwrite(t *testing.T) {
|
||
setupTestDB(t)
|
||
ctx := context.Background()
|
||
|
||
sid := seedSessionWS(t, "fixed-ws", "/home/original", "某事")
|
||
if err := SetSessionWorkspace(ctx, sid, "/home/hijacked"); err != nil {
|
||
t.Fatalf("SetSessionWorkspace: %v", err)
|
||
}
|
||
var ws string
|
||
if err := db.DB.QueryRowContext(ctx,
|
||
`SELECT workspace FROM sessions WHERE session_id = $1`, sid).Scan(&ws); err != nil {
|
||
t.Fatalf("read back: %v", err)
|
||
}
|
||
if ws != "/home/original" {
|
||
t.Errorf("已有 workspace 被覆盖成 %q", ws)
|
||
}
|
||
|
||
// 空的那种要能补上(历史会话回填)
|
||
empty := seedSessionWS(t, "empty-ws", "", "某事")
|
||
if err := SetSessionWorkspace(ctx, empty, "/home/filled"); err != nil {
|
||
t.Fatalf("SetSessionWorkspace(empty): %v", err)
|
||
}
|
||
if err := db.DB.QueryRowContext(ctx,
|
||
`SELECT workspace FROM sessions WHERE session_id = $1`, empty).Scan(&ws); err != nil {
|
||
t.Fatalf("read back: %v", err)
|
||
}
|
||
if ws != "/home/filled" {
|
||
t.Errorf("空 workspace 未被补上,实际 %q", ws)
|
||
}
|
||
}
|
||
|
||
// CreateSession 要把 workspace 存下来 —— 这是整条链的起点,
|
||
// 漏在这里的话后面所有查询都只能靠 mails 反推。
|
||
func TestCreateSessionStoresWorkspace(t *testing.T) {
|
||
setupTestDB(t)
|
||
ctx := context.Background()
|
||
|
||
id, err := CreateSession(ctx, nil, "admin", "带工作区", "/home/program/agentmail")
|
||
if err != nil {
|
||
t.Fatalf("CreateSession: %v", err)
|
||
}
|
||
var ws string
|
||
if err := db.DB.QueryRowContext(ctx,
|
||
`SELECT workspace FROM sessions WHERE session_id = $1`, id).Scan(&ws); err != nil {
|
||
t.Fatalf("read back: %v", err)
|
||
}
|
||
if ws != "/home/program/agentmail" {
|
||
t.Errorf("workspace 未落库:%q", ws)
|
||
}
|
||
}
|
||
|
||
// 归档的会话不进候选:归档就是「这条线索结束了」,
|
||
// 还出现在补全里等于邀请用户往一条已关闭的线索里发信。
|
||
func TestSuggestSessionCandidatesExcludesArchived(t *testing.T) {
|
||
setupTestDB(t)
|
||
seedPlatformAgent(t, "dsh")
|
||
ctx := context.Background()
|
||
|
||
sid := seedSessionWS(t, "done-thread", "/home/a", "已完成")
|
||
seedMailWS(t, sid, "admin", "dsh", "/home/a", "已完成")
|
||
if _, err := db.DB.ExecContext(ctx,
|
||
`UPDATE sessions SET status = 'archived' WHERE session_id = $1`, sid); err != nil {
|
||
t.Fatalf("archive: %v", err)
|
||
}
|
||
|
||
got, _ := SuggestSessionCandidates(ctx, "admin", "dsh", "/home/a")
|
||
if len(got) != 0 {
|
||
t.Fatalf("归档会话不该出现,实际 %+v", got)
|
||
}
|
||
}
|