fix(snapshot): stabilize all recorder message ids
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
* fixtures and rewrites expected outputs.
|
||||
*/
|
||||
|
||||
import { existsSync } from 'node:fs'
|
||||
import { mkdir, mkdtemp, readFile, readdir, rm, writeFile } from 'node:fs/promises'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { delimiter, join } from 'node:path'
|
||||
@@ -19,6 +20,7 @@ import {
|
||||
normalizeStdout,
|
||||
refreshFixtureReplacements,
|
||||
scrubRequestHeaders,
|
||||
stabilizeFixtureMessageIds,
|
||||
stabilizeRefreshLog,
|
||||
tokenizeSessionFixtureCwd,
|
||||
type HarvestedLog,
|
||||
@@ -230,20 +232,25 @@ describe('TypeScript SDK snapshots over the jsonrpc runtime', () => {
|
||||
const { result, notifications, logs, cwd } = await runScenario(scenario)
|
||||
const ordered = orderLogs(logs, scenario)
|
||||
const actualContext = contextOf(ordered, cwd)
|
||||
const files = fixtureFiles(scenario)
|
||||
|
||||
if (recording) {
|
||||
// Fixtures carry tokenized request headers; llm-replay reads only
|
||||
// assistant output and tool traffic, so scrubbing keeps prompts and
|
||||
// schemas out of the corpus without affecting replay.
|
||||
await mkdir(scenarioDir, { recursive: true })
|
||||
await Promise.all(ordered.map(async (log, index) => {
|
||||
const file = fixtureFiles(scenario)[index]
|
||||
const existing = await Promise.all(files.map(async file => existsSync(file) ? readFile(file, 'utf8') : ''))
|
||||
const fixtures = stabilizeFixtureMessageIds(
|
||||
ordered.map(log => scrubRequestHeaders(tokenizeSessionFixtureCwd(log.content))),
|
||||
existing,
|
||||
)
|
||||
await Promise.all(fixtures.map(async (fixture, index) => {
|
||||
const file = files[index]
|
||||
if (file === undefined) throw new Error(`no fixture path for persisted log ${index}`)
|
||||
await writeFile(file, scrubRequestHeaders(tokenizeSessionFixtureCwd(log.content)))
|
||||
await writeFile(file, fixture)
|
||||
}))
|
||||
}
|
||||
|
||||
const files = fixtureFiles(scenario)
|
||||
let expectedContents = await Promise.all(files.map(file => readFile(file, 'utf8')))
|
||||
|
||||
if (refreshing) {
|
||||
|
||||
@@ -1,10 +1,15 @@
|
||||
import { existsSync } from 'node:fs'
|
||||
import { cp, mkdir, mkdtemp, readFile, readdir, rm, writeFile } from 'node:fs/promises'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { basename, dirname, isAbsolute, join, relative, sep } from 'node:path'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
import { afterAll, describe, expect, it, vi } from 'vitest'
|
||||
import { Context } from 'cordis'
|
||||
import { scrubRequestHeaders, tokenizeSessionFixtureCwd } from '@deepseek-ai/dsh-acp-snapshot'
|
||||
import {
|
||||
scrubRequestHeaders,
|
||||
stabilizeFixtureMessageIds,
|
||||
tokenizeSessionFixtureCwd,
|
||||
} from '@deepseek-ai/dsh-acp-snapshot'
|
||||
import type { Agent } from '@deepseek-ai/dsh-agent'
|
||||
import * as AgentCore from '@deepseek-ai/dsh-agent-spine-demo'
|
||||
import { LocalBashExecutor } from '@deepseek-ai/dsh-bash-local'
|
||||
@@ -484,17 +489,15 @@ async function runScenario(scenario: Scenario): Promise<ScenarioResult> {
|
||||
async function writeRecording(scenario: Scenario, result: ScenarioResult): Promise<void> {
|
||||
const dir = scenarioDir(scenario)
|
||||
await mkdir(dir, { recursive: true })
|
||||
await writeFile(
|
||||
join(dir, 'session.jsonl'),
|
||||
scrubRequestHeaders(tokenizeSessionFixtureCwd(rawSessionLog(result.parent))),
|
||||
)
|
||||
expect(result.children).toHaveLength(scenario.childSessions ?? 0)
|
||||
for (const [index, child] of result.children.entries()) {
|
||||
await writeFile(
|
||||
join(dir, `session.${index + 1}.jsonl`),
|
||||
scrubRequestHeaders(tokenizeSessionFixtureCwd(rawSessionLog(child))),
|
||||
)
|
||||
}
|
||||
const files = [join(dir, 'session.jsonl'), ...childFixturePaths(scenario)]
|
||||
const existing = await Promise.all(files.map(async file => existsSync(file) ? readFile(file, 'utf8') : ''))
|
||||
const fixtures = stabilizeFixtureMessageIds(
|
||||
[result.parent, ...result.children]
|
||||
.map(session => scrubRequestHeaders(tokenizeSessionFixtureCwd(rawSessionLog(session)))),
|
||||
existing,
|
||||
)
|
||||
await Promise.all(fixtures.map((fixture, index) => writeFile(files[index] as string, fixture)))
|
||||
}
|
||||
|
||||
describe('TUI recorded-session terminal snapshots', () => {
|
||||
|
||||
Reference in New Issue
Block a user