Просмотр исходного кода

Cover PTC dispatches through explicit TypeScript SDK profile patch

Tianyi Cui 3 недель назад
Родитель
Сommit
d8d86b7eb8

+ 2 - 2
.agents/notes/implemented/feature/2026-06-15-ptc.i18n.yaml

@@ -2,5 +2,5 @@
 # side as of the last confirmed-consistent state. Both languages carry equal authority;
 # after editing either side, bring the other along and re-record with:
 #   pnpm run verify-translation-pairing --write .agents/notes/implemented/feature/2026-06-15-ptc.md
-2026-06-15-ptc.md: 003213fb4c0b85eb1c7764e5cea48f430d982035
-2026-06-15-ptc.zh.md: 3568748d0ee6a3e477d262e2f3c090557e28d424
+2026-06-15-ptc.md: 94a0fd3492c049ad2ce6fe3634422b1569dc80b8
+2026-06-15-ptc.zh.md: 12e321b111d1b6a63068f4e65fd836ba4918e086

+ 1 - 1
.agents/notes/implemented/feature/2026-06-15-ptc.md

@@ -102,7 +102,7 @@ Deployments switching to `'ptc'` must update any native-only `toolOrder`. Assemb
 - **Worker runtime:** Real-worker tests cover typed binding values and failures, every lossless JSON completion root, invalid and over-limit output, exact combined ledger boundaries, compute and wall budgets, hostile binding traffic, empty environment, and disposal to quiescence. A built-package test runs the worker entry under plain Node.
 - **Registry integration:** Tests cover code generation, all presentation modes, reserved-name and restriction rules, scoped visibility, authoritative assembly rewrites, `toolOrder`, runtime compatibility failures, full-pipeline sub-dispatch, parent-token correlation, serialization, cancellation and queue drain, JSON normalization, error propagation, log events, ordered context deferral across successful and failed programs, outer-block suppression, and HMR cleanup.
 - **With-key e2e:** A real model composes two bash calls in one program; another discovers nested workspace instructions through a PTC mode fs dispatch. The tests verify collapsed request headers, correlated dispatch events, resulting files, deferred context, and model behavior.
-- **Snapshot:** The `ptc-turn`, `both-mode-turn`, and `ptc-workspace-context` fixtures pin SDK text, header tool lists, dispatch events, deferred context, and result cards.
+- **Snapshot:** The `ptc-turn`, `both-mode-turn`, and `ptc-workspace-context` fixtures pin SDK text, header tool lists, dispatch events, deferred context, and result cards. The TypeScript SDK PTC scenario mounts its worker runtime through an explicit test-owned profile patch and pins Session events and JSON-RPC notifications; its expected response and completed-turn checks run before refresh writes.
 
 ## Alternatives considered
 

+ 1 - 1
.agents/notes/implemented/feature/2026-06-15-ptc.zh.md

@@ -102,7 +102,7 @@ SDK 指示模型编写一个所加载运行时语言的异步函数体(默认
 - **Worker 运行时:** 真实 worker 测试覆盖类型化的绑定值与失败、每一种无损 JSON 根类型的完成值、无效和超限输出、精确的组合账本边界、compute 和 wall 预算、恶意绑定流量、空环境以及 dispose 至完全停稳。一个构建后包测试在纯 Node 下运行 worker 入口。
 - **注册表集成:** 测试覆盖代码生成、所有呈现模式、保留名称和限制规则、scoped 可见性、权威组装重写、`toolOrder`、运行时兼容性失败、完整流水线子分发、parent-token 关联、序列化、取消和队列排空、JSON 规范化、错误传播、日志事件、成功与失败程序中的有序上下文延后、外层阻止抑制以及 HMR(热模块替换)清理。
 - **带密钥 e2e:** 真实模型在一个程序中组合两次 bash 调用;另一个模型通过 PTC mode fs 分发发现嵌套的工作区指令。测试验证折叠的请求头、关联的分发事件、结果文件、延后上下文和模型行为。
-- **快照:** `ptc-turn`、`both-mode-turn` 和 `ptc-workspace-context` fixture(测试前置数据)固定 SDK 文本、请求头工具列表、分发事件、延后上下文和结果卡片。
+- **快照:** `ptc-turn`、`both-mode-turn` 和 `ptc-workspace-context` fixture(测试前置数据)固定 SDK 文本、请求头工具列表、分发事件、延后上下文和结果卡片。TypeScript SDK PTC 场景通过测试拥有的显式 profile patch 挂载 worker 运行时,并固定 Session 事件与 JSON-RPC 通知;预期回复和完成轮次检查在 refresh 写入前执行。
 
 ## 曾考虑的替代方案
 

+ 1 - 1
packages/session/session-format-v2-to-v3/src/index.ts

@@ -1,4 +1,4 @@
-/** Released-v2 physical codec and identity streaming migration into v3. */
+/** Released-v2 physical codec and identity-preserving PTC migration into v3. */
 
 export { releasedV2SessionFormatCodec } from '@deepseek-ai/dsh-session-format-v1-to-v2'
 export * from './codec.ts'

Разница между файлами не показана из-за своего большого размера
+ 10 - 0
snapshots/sdk/ptc-turn/notifications.expected.jsonl


+ 1 - 0
snapshots/sdk/ptc-turn/result.expected.json

@@ -0,0 +1 @@
+{"sessionId":"{{sessionId}}","finalResponse":"CODE_ONE+CODE_TWO"}

+ 3 - 0
snapshots/sdk/ptc-turn/runtime.cordis.yml

@@ -0,0 +1,3 @@
+- insert:
+    - id: code-runtime
+      name: '@deepseek-ai/dsh-code-runtime-worker-thread'

Разница между файлами не показана из-за своего большого размера
+ 13 - 0
snapshots/sdk/ptc-turn/session.v3.jsonl


+ 7 - 0
snapshots/sdk/ptc-turn/snapshot.yml

@@ -0,0 +1,7 @@
+version: 1
+scenario: ptc-turn
+profile: sdk
+composition: ptc
+recording: live
+header:
+  class: ptc

+ 19 - 2
snapshots/sdk/sdk.snapshot.ts

@@ -98,6 +98,10 @@ function dirOf(url: string): string {
 }
 
 interface SdkAssertions {
+  /** Additional profile patches applied after the shared composition. */
+  patches?: readonly string[]
+  /** Final response required from a completed turn before updating goldens. */
+  expectedFinalResponse?: string
   /** Environment overrides passed to the runtime subprocess. */
   environment?: Readonly<Record<string, string>>
   /** A separate DSH SDK child whose persisted session joins the evidence. */
@@ -118,6 +122,11 @@ interface SdkAssertions {
 }
 
 const SDK_ASSERTIONS: Readonly<Record<string, SdkAssertions>> = {
+  'ptc-turn': {
+    patches: [fileURLToPath(new URL('./ptc-turn/runtime.cordis.yml', import.meta.url))],
+    expectedFinalResponse: 'CODE_ONE+CODE_TWO',
+    expectedTools: { run_code: ['code', 'description'] },
+  },
   'subagent-dsh-sdk-diagnostic': {
     environment: { DSH_TEST_CHILD_PATCH: dshSdkDiagnosticChildPatch },
   },
@@ -517,9 +526,9 @@ async function runScenario(scenario: CorpusScenario): Promise<{
   const route = modelFromSession(primaryFixture)
   const patchRoot = join(cwd, '.snapshot-patches')
   await mkdir(patchRoot, { recursive: true })
-  const patches = authoredPatches(scenario, !recording)
-    .map((patch, index) => materializeProfilePatch(patch, cwd, patchRoot, index))
   const assertions = SDK_ASSERTIONS[scenario.name] ?? {}
+  const patches = [...authoredPatches(scenario, !recording), ...assertions.patches ?? []]
+    .map((patch, index) => materializeProfilePatch(patch, cwd, patchRoot, index))
   let childSessionsRoot: string | undefined
   let childEnvironment: Record<string, string> = {}
   if (assertions.dshSdkChild !== undefined) {
@@ -774,6 +783,14 @@ describe('TypeScript SDK snapshots over the jsonrpc runtime', () => {
         assertions.dshSdkChild !== undefined,
       )
       const actualContext = contextOf(ordered, cwd)
+      if (assertions.expectedFinalResponse !== undefined) {
+        expect(results.at(-1)?.finalResponse, `${scenario.name}: final response`).toBe(assertions.expectedFinalResponse)
+        const parent = ordered[0]
+        if (parent === undefined) throw new Error(`${scenario.name}: no primary session log`)
+        const turnEnds = records(parent.content).filter(record => record.type === 'turn/end')
+        expect(turnEnds, `${scenario.name}: completed turns`).toHaveLength(results.length)
+        for (const turnEnd of turnEnds) expect(turnEnd).toMatchObject({ data: { reason: { kind: 'completed' } } })
+      }
 
       let expectedContents = await Promise.all(files.map(file => readFile(file, 'utf8')))
 

Некоторые файлы не были показаны из-за большого количества измененных файлов