Machine-produced by `pnpm run rescope-vendor --apply` plus the regeneration it prints: `pnpm install` for the lockfile, `pnpm run gen-third-party-notices`, `verify-translation-pairing --write` for the touched bilingual pairs, `gen-doc-graphs`, and one typert snapshot whose ids embed character offsets. `pnpm run rescope-vendor --check` verifies the result. Renames nine vendored packages (cordis, cosmokit, schemastery and the six @cordisjs plugins) and every reference that resolves them: manifest names and dependency keys, module specifiers including declare-module merges, cordis.yml plugin names, tsconfig paths, every Markdown fence, and `docs/` prose. Directory names, upstream versions, and dependency ranges are unchanged, so vendor/README.md still reads as an upstream snapshot; its manifest table gains an upstream-name column so THIRD_PARTY_NOTICES keeps MIT attribution pointed at each fork's origin. The tutorial tier follows the rename end to end: its yaml fences named plugins the Loader can no longer resolve, its `ts ignore-check` fences disagreed with the compiled fences beside them, and its prose quoted both. The contracts that told readers to keep upstream names — the root convention and the vendoring cookbook's tree comment and manifest invariant — now say to rescope instead. Two rules read `@deepseek-ai/` as "another workspace plugin": the client bundle purity gate now names the vendored libraries a browser bundle inlines, and the files where a bare `cordis` is an agent-preset id keep that product data.
89 lines
3.8 KiB
TypeScript
89 lines
3.8 KiB
TypeScript
import { createUserMessage } from '@deepseek-ai/dsh-llm'
|
|
import { mkdtemp, rm, writeFile } from 'node:fs/promises'
|
|
import { tmpdir } from 'node:os'
|
|
import { join } from 'node:path'
|
|
import { afterEach, describe, expect, it } from 'vitest'
|
|
import type { Context } from '@deepseek-ai/cordis'
|
|
import { codingHarness, finalText, SYSTEM_PROMPT, waitForIdle } from './harness.ts'
|
|
import { SessionId } from '@deepseek-ai/dsh-session'
|
|
|
|
/**
|
|
* Key-gated smoke for mid-session compaction. It verifies the compact event
|
|
* pair, replacement of older surface nodes, and a final answer after compaction.
|
|
*/
|
|
// The keyless headless snapshot pins deterministic overflow recovery; this test
|
|
// remains the independent live-provider smoke for organic pressure and summary quality.
|
|
|
|
let workdir: string | undefined
|
|
let ctx: Context | undefined
|
|
|
|
afterEach(async () => {
|
|
await ctx?.fiber.dispose()
|
|
ctx = undefined
|
|
if (workdir !== undefined) await rm(workdir, { recursive: true, force: true })
|
|
workdir = undefined
|
|
})
|
|
|
|
describe.skipIf(!process.env.DEEPSEEK_API_KEY)('compaction: a long session compacts mid-flight and keeps running', () => {
|
|
it('summarizes older history into a checkpoint without breaking the task', async () => {
|
|
workdir = await mkdtemp(join(tmpdir(), 'dsh-compaction-'))
|
|
for (let i = 1; i <= 4; i++) {
|
|
await writeFile(join(workdir, `file${i}.txt`), `This is file number ${i}. `.repeat(50))
|
|
}
|
|
|
|
// Reasoning tokens require a larger generation cap than the retained checkpoint.
|
|
ctx = await codingHarness(workdir, {
|
|
persona: SYSTEM_PROMPT,
|
|
modelContextWindow: 2000,
|
|
compact: {
|
|
thresholdRatio: 0.5,
|
|
retainTokens: 400,
|
|
summarizationProvider: '',
|
|
summarizationModel: '',
|
|
maxTokens: 1024,
|
|
compactionRetries: 1,
|
|
},
|
|
persistenceRoot: join(workdir, '.sessions'),
|
|
})
|
|
const agent = ctx.agentLoop.create(SessionId('e2e-compaction'), { provider: 'deepseek-official', model: 'deepseek-v4-flash' })
|
|
|
|
agent.followup(createUserMessage({
|
|
content: [{
|
|
type: 'text',
|
|
text: 'Read file1.txt, file2.txt, file3.txt, and file4.txt one at a '
|
|
+ 'time using cat (a separate bash command for each). After reading all four, tell me how '
|
|
+ 'many files you read and the number mentioned in file1.txt.',
|
|
}], source: { kind: 'user' } }))
|
|
await waitForIdle(ctx, agent)
|
|
|
|
const events = [...agent.session.events]
|
|
|
|
// A compaction ran: the start…end bracket landed in the real log.
|
|
const starts = events.filter(e => e.type === 'compact/start')
|
|
const ends = events.filter(e => e.type === 'compact/end')
|
|
expect(starts.length).toBeGreaterThan(0)
|
|
expect(ends.length).toBe(starts.length) // every start was released
|
|
|
|
// It succeeded at least once: a `compact/summary` event describing the summary and a
|
|
// replace-op user/message (the surface mutation) both landed.
|
|
const summaries = events.filter(e => e.type === 'compact/summary')
|
|
expect(summaries.length).toBeGreaterThan(0)
|
|
const replaceNode = events.find((e) => {
|
|
const se = e as unknown as { type: string; surfaceOp?: unknown }
|
|
return se.type === 'user/message' && typeof se.surfaceOp === 'object' && se.surfaceOp !== null
|
|
})
|
|
expect(replaceNode).toBeDefined()
|
|
|
|
// The summary shadowed real older nodes (the surface shrank vs. the raw
|
|
// message-producing event count).
|
|
const summaryData = summaries[0]!.data as { shadowedSeqs: number[] }
|
|
expect(summaryData.shadowedSeqs.length).toBeGreaterThan(0)
|
|
|
|
// The conversation survived compaction: the agent produced a final answer
|
|
// that reflects the work (it read four files).
|
|
const answer = finalText(events).toLowerCase()
|
|
expect(answer.length).toBeGreaterThan(0)
|
|
expect(answer).toMatch(/\b(4|four)\b/)
|
|
}, 240_000)
|
|
})
|