Skip to content

test: 会话事件写入侧防护回归测试 (refs #8) - #140

Open
spacexun2 wants to merge 1 commit into
NanmiCoder:mainfrom
spacexun2:rebuild/pr-12
Open

test: 会话事件写入侧防护回归测试 (refs #8)#140
spacexun2 wants to merge 1 commit into
NanmiCoder:mainfrom
spacexun2:rebuild/pr-12

Conversation

@spacexun2

Copy link
Copy Markdown
Contributor

说明:重提原 PR #12

本 PR 重新提交原 [#12]。原 PR 于 2026-09-04 因作者的 head fork(spacexun2/dsh-agent-teams)被意外删除,被 GitHub 以 "head repository deleted" 自动关闭——并非内容被否决。现 fork 已重建,分支基于最新 main(1caff61)重放。

改动概述

为 issue #8 的会话事件写入侧防护(session event write-guard)提供离线回归测试,新增独立的 pnpm verify:events 入口:

  • scripts/verify-events.mjs:以 stub 掉的 @deepseek-ai/dsh-session 驱动构建产物 lib/events.js,固化四组行为:①harness 未识别的 agent-teams/* 事件一律不写入 session log;②harness 已识别的第一方类型(如 tool-workflow/run-started)照常写入;③session.append 抛错被 appendTeamEvent 吸收,不外溢;④captainSessionOf 的 fallback 语义(离线 captain 回退到调用者 session,在线 captain 的 live session 优先)。
  • scripts/mock-dsh-session-loader.mjs:ESM loader stub,把 issue session.append 写入不可忽略的自定义事件类型,导致历史会话拒读(SessionFormatUnsupportedError) #8 的场景(只认第一方 tool-workflow/* / agent/* 词汇的 harness)确定性地钉住,不随本地安装的 harness 版本漂移。
  • package.json:新增 "verify:events": "node scripts/verify-events.mjs";按此前决定继续不入聚合 verify 门,其余 verify 链未动。

对当前写入路径的适配(alpha.2 之后)

原 PR 基于 0.1.10 时代写入路径。上游 alpha.2 重构(commit bf50b49 及后续)后,guard 契约保留:src/events.tsappendTeamEvent 仍按 harness KNOWN_SESSION_EVENT_TYPES 决定写入/省略、仍 try/catch 包住 session.append,captainSessionOf 签名与 fallback 语义不变;conversationEvents → uiConversation 的改名发生在 client 侧,不影响本测试面。适配点:事件词汇表更新为当前 src/event-types.ts 的 10 个 agent-teams/* 类型(新增 team-haltedteam-resumedplan-discarded),stub 注释同步(rc.1 起 devDependencies 已安装 @deepseek-ai/*,stub 保留以钉死场景)。

本地验证证据(最新 main + 本分支,Windows / Node v24.16.0)

pnpm build(等价步骤:clean-build.mjs && tsc -p tsconfig.json && tsc -p tsconfig.client.json && tsdown)→ 成功
node scripts/verify-events.mjs
  1/4 out-of-repo event types are never written
    PASS  all 10 agent-teams/* types are omitted from the session log
  2/4 harness-recognized types are still written
    PASS  known first-party type is written
    PASS  unknown custom type is omitted too
  3/4 session write failures are contained
    PASS  append failure does not escape appendTeamEvent
  4/4 captain session resolution
    PASS  offline captain falls back to the caller session
    PASS  live captain session wins over the fallback
  all checks passed  (exit 0)

Refs #8

…standalone verify:events)

Rebased onto main (1caff61, 0.1.16-rc.1): the alpha.2+ write path kept the
guard contract (appendTeamEvent checking the harness KNOWN_SESSION_EVENT_TYPES,
containment of session write failures, captainSessionOf fallback), so the
coverage carries over with the event vocabulary updated to the current 10
agent-teams/* types (adds team-halted, team-resumed, plan-discarded). The
loader stub is kept so the NanmiCoder#8 scenario stays pinned regardless of the
installed harness build; verify:events stays out of the aggregate gate per
the earlier decision.

Refs NanmiCoder#8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant