From 4e7cde2342f7c2b430fe11c1130887da8a5a06b0 Mon Sep 17 00:00:00 2001 From: _Kerman Date: Fri, 10 Jul 2026 15:20:52 +0800 Subject: [PATCH] chore(agent-core-v2): tidy misplaced and throwaway test files - Remove resume-debug.test.ts: a one-off diagnosis script with a hardcoded local path, not a real test. - Move streamTiming.test.ts to app/model/modelImpl.test.ts: it only exercises buildStreamTiming in app/model/modelImpl.ts. - Rename wire/store.test.ts to wire/wireServiceImpl.test.ts to match the module it covers (there is no store.ts in src). --- .../agent/wireRecord/resume-debug.test.ts | 124 ------------------ .../model/modelImpl.test.ts} | 0 ...{store.test.ts => wireServiceImpl.test.ts} | 0 3 files changed, 124 deletions(-) delete mode 100644 packages/agent-core-v2/test/agent/wireRecord/resume-debug.test.ts rename packages/agent-core-v2/test/{agent/llmRequester/streamTiming.test.ts => app/model/modelImpl.test.ts} (100%) rename packages/agent-core-v2/test/wire/{store.test.ts => wireServiceImpl.test.ts} (100%) diff --git a/packages/agent-core-v2/test/agent/wireRecord/resume-debug.test.ts b/packages/agent-core-v2/test/agent/wireRecord/resume-debug.test.ts deleted file mode 100644 index 7850ad723..000000000 --- a/packages/agent-core-v2/test/agent/wireRecord/resume-debug.test.ts +++ /dev/null @@ -1,124 +0,0 @@ -/** - * One-off diagnosis: for a handful of mismatching wire logs, print the field- - * level diff between restore(original) and restore(redump) at the first - * diverging record, so we can pin the non-idempotent transform in the source. - * - * Run: - * pnpm exec vitest run test/resume-debug.test.ts - */ - -import { - existsSync, - mkdirSync, - readdirSync, - writeFileSync, -} from 'node:fs'; -import { dirname, join } from 'node:path'; - -import { describe, expect, it } from 'vitest'; - -import { SyncDescriptor } from '#/_base/di/descriptors'; -import { TestInstantiationService } from '#/_base/di/test'; -import { IBootstrapService } from '#/app/bootstrap/bootstrap'; -import { - AGENT_WIRE_PROTOCOL_VERSION, - type PersistedWireRecord, -} from '#/agent/wireRecord/wireRecord'; -import { AgentWireRecordService } from '#/agent/wireRecord/wireRecordService'; -import { AppendLogStore } from '#/persistence/backends/node-fs/appendLogStore'; -import { FileStorageService } from '#/persistence/backends/node-fs/fileStorageService'; -import { IAppendLogStore } from '#/persistence/interface/appendLogStore'; -import { IFileSystemStorageService } from '#/persistence/interface/storage'; - -import { stubBootstrap } from '../../app/bootstrap/stubs'; - -const DST = '/Users/moonshot/Projects/kimi-code-mini-bench/.vitest-results/resume-roundtrip-clean'; -const SESSIONS = join(DST, 'sessions'); -const REDUMP = join(DST, '_redump-debug'); - -const TARGETS: readonly { relPath: string; index: number }[] = [ - { relPath: 'wd_.code-workspace_073f548f415a/session_787c5c32-6420-4742-8614-d456aa6bef4f/agents/main', index: 41 }, - { relPath: 'wd_kimi-code-di-v4_e5415428af7c/session_18d1e696-c7d1-49f9-81c3-d1e3446f9f75/agents/main', index: 5 }, - { relPath: 'wd_openclaw_a1dc20dc2ea8/session_00636111-25bb-4a2b-b7de-7d67993db403/agents/main', index: 0 }, - { relPath: 'wd_kimi-code-di-v3_bfc63729a762/session_13ea953e-27a6-4905-b204-55fbc4410a91/agents/main', index: 25 }, -]; - -function fieldDiff( - a: Record, - b: Record, -): Record { - const keys = new Set([...Object.keys(a), ...Object.keys(b)]); - const diff: Record = {}; - for (const key of keys) { - if (JSON.stringify(a[key]) !== JSON.stringify(b[key])) { - diff[key] = { r1: a[key], r2: b[key] }; - } - } - return diff; -} - -function originalFirstRecordType(relPath: string): string | undefined { - const file = join(SESSIONS, relPath, 'wire.jsonl'); - try { - const lines = require('node:fs').readFileSync(file, 'utf8').split('\n').filter((l: string) => l.length > 0); - const meta = JSON.parse(lines[0]); - return `metadata.protocol_version=${meta.protocol_version}, firstDataRecord=${lines[1] ? JSON.parse(lines[1]).type : '(none)'}`; - } catch (e) { - return `read-error: ${String(e)}`; - } -} - -describe('resume round-trip diff diagnosis', () => { - it('prints field-level diff at the first diverging record', async () => { - const bootstrap = stubBootstrap(DST); - const storage = new FileStorageService(DST); - const ix = new TestInstantiationService(); - ix.stub(IFileSystemStorageService, storage); - ix.stub(IBootstrapService, bootstrap); - ix.set(IAppendLogStore, new SyncDescriptor(AppendLogStore)); - const log = ix.get(IAppendLogStore) as InstanceType; - - for (const { relPath, index } of TARGETS) { - const agentHomedir = join(SESSIONS, relPath); - console.log('\n=================================================='); - console.log(`target: ${relPath} (firstDiff@${index})`); - console.log(`original: ${originalFirstRecordType(relPath)}`); - - const wire1 = new AgentWireRecordService({ homedir: agentHomedir }, bootstrap, undefined, log); - await wire1.restore(); - const r1 = wire1.getRecords(); - - const redumpHomedir = join(REDUMP, relPath); - const redumpFile = join(redumpHomedir, 'wire.jsonl'); - mkdirSync(dirname(redumpFile), { recursive: true }); - writeFileSync( - redumpFile, - [ - JSON.stringify({ type: 'metadata', protocol_version: AGENT_WIRE_PROTOCOL_VERSION, created_at: 1 }), - ...r1.map((record) => JSON.stringify(record)), - ].join('\n') + '\n', - ); - - const wire2 = new AgentWireRecordService({ homedir: redumpHomedir }, bootstrap, undefined, log); - await wire2.restore(); - const r2 = wire2.getRecords(); - - expect(r2.length).toBe(r1.length); - - const a = r1[index] as Record | undefined; - const b = r2[index] as Record | undefined; - if (a === undefined || b === undefined) { - console.log(`r1[${index}] type=${String(a?.['type'])}, r2[${index}] type=${String(b?.['type'])} (one side undefined)`); - continue; - } - const diff = fieldDiff(a, b); - console.log(`r1[${index}].type=${String(a['type'])}, r2[${index}].type=${String(b['type'])}`); - console.log(`changed fields: ${Object.keys(diff).join(', ') || '(none)'}`); - for (const [key, value] of Object.entries(diff)) { - console.log(`--- field "${key}" ---`); - console.log('r1:', JSON.stringify(value.r1)?.slice(0, 600)); - console.log('r2:', JSON.stringify(value.r2)?.slice(0, 600)); - } - } - }, 120_000); -}); diff --git a/packages/agent-core-v2/test/agent/llmRequester/streamTiming.test.ts b/packages/agent-core-v2/test/app/model/modelImpl.test.ts similarity index 100% rename from packages/agent-core-v2/test/agent/llmRequester/streamTiming.test.ts rename to packages/agent-core-v2/test/app/model/modelImpl.test.ts diff --git a/packages/agent-core-v2/test/wire/store.test.ts b/packages/agent-core-v2/test/wire/wireServiceImpl.test.ts similarity index 100% rename from packages/agent-core-v2/test/wire/store.test.ts rename to packages/agent-core-v2/test/wire/wireServiceImpl.test.ts