Skip to content

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

Open
spacexun2 wants to merge 3 commits into
NanmiCoder:mainfrom
spacexun2:test/verify-session-event-write-guard
Open

test: 会话事件写入侧防护回归测试(refs #8)#12
spacexun2 wants to merge 3 commits into
NanmiCoder:mainfrom
spacexun2:test/verify-session-event-write-guard

Conversation

@spacexun2

@spacexun2 spacexun2 commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

摘要(Summary)

#8 的最终修复(aace29c 写入侧防护,现位于 src/events.ts)补回归测试——此前该防护零测试覆盖。已适配 #27 之后的源码构建结构(lib/ 由 pnpm build 产出)。

改动(Affected)

  • scripts/verify-events.mjs(新增):离线回归脚本,7 项断言,与 scripts/verify.mjs 同约定——pnpm build && node scripts/verify-events.mjs(lib/ 缺失时给出明确提示);
  • scripts/mock-dsh-session-loader.mjs(新增):ESM loader 钩子打桩 @deepseek-ai/dsh-session——遵守 .npmrc 的约定@deepseek-ai/* 由 DSH 运行时提供、不安装为依赖),测试逻辑零依赖;
  • package.json:新增独立入口 verify:events不接入发布门禁——仓库处于 pre-release 快速迭代期,如 lib/ → src 构建结构调整;把内部测试留在发布链之外,减少维护税)。

测试内容

  1. 7 种 agent-teams/* 事件全部不写入会话日志(session.append 写入不可忽略的自定义事件类型,导致历史会话拒读(SessionFormatUnsupportedError) #8 核心回归:防写入侧防护被回退);
  2. harness 已识别的 first-party 类型(tool-workflow/*agent/*)照常写入;
  3. 未知自定义类型不写入;
  4. session.append 抛错不外溢
  5. captainSessionOf:captain 离线时回退,在线时优先 captain session。

设计说明

打桩的 KNOWN_SESSION_EVENT_TYPES 模拟"只识别 first-party 类型、不识别 agent-teams/*"的 harness——正是 #8 的场景。若未来 harness 补上注册面/ignorable 写入面(见 #7),第 1 组断言会如预期地要求测试更新(即行为契约变更的信号)。

本地验证(Local Validation)

$ node scripts/verify-events.mjs
dsh-agent-teams session event write-guard regression (#8)
1/4 out-of-repo event types are never written
  PASS  all 7 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

src/events.ts 与测试所加载的 lib 产物防护逻辑经源码逐行比对一致;完整 pnpm build 需 DSH 运行时提供 peer 类型,与仓库约定一致。)

refs #8

The upstream write-guard (aace29c, lib/events.js) that prevents issue NanmiCoder#8
from recurring has no test coverage. Add scripts/verify-events.mjs, which
stubs @deepseek-ai/dsh-session via an ESM loader hook (the repo does not
install @deepseek-ai/* packages per .npmrc), so the guard is pinned in a
clean checkout with zero dependencies:

- all 7 agent-teams/* event types are omitted from the session log
- harness-recognized first-party types are still written
- unknown custom types are omitted
- session.append failures are contained
- captainSessionOf falls back / prefers the live captain session

Wired into the verify gate as verify:events (refs NanmiCoder#8).
@spacexun2
spacexun2 force-pushed the test/verify-session-event-write-guard branch from 5cec352 to 4335447 Compare August 15, 2026 13:28
The repo builds lib/ from src/ (PR NanmiCoder#27), so the offline guard tests now
document the same convention as scripts/verify.mjs: pnpm build first.
The regression test stays available via pnpm verify:events but is not
wired into the publish gate: the repo is pre-release and iterating fast
(e.g. the lib/ -> src build change), and keeping internals tests out of
the release chain minimizes the maintenance tax on the maintainer.
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