compact-checkpoint-pin.spec.ts 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /**
  2. * Behavioral half of the compaction-checkpoint drift trap.
  3. *
  4. * `TranscriptAdapter` pins its plugin literal to the seam's own declaration at
  5. * compile time through a type-only import of `dsh-compact/checkpoint`, so
  6. * renaming the seam's plugin already fails `tsc`. This spec covers the same
  7. * drift from the other side — end to end through the adapter, driving it with a
  8. * checkpoint built from the canonical `COMPACT_CHECKPOINT_SOURCE` value and
  9. * checking the seam's own predicate agrees. Both values come from the
  10. * cordis-free checkpoint leaf, so the client test program never loads the host
  11. * package root or its `Context` merges.
  12. */
  13. import { COMPACT_CHECKPOINT_SOURCE, isCompactCheckpointSource } from '@deepseek-ai/dsh-compact/checkpoint'
  14. import { createUserMessage } from '@deepseek-ai/dsh-llm'
  15. import { describe, expect, it } from 'vitest'
  16. import type { SessionEvent } from '@deepseek-ai/dsh-session/types'
  17. import { TranscriptAdapter } from '../src/client/sessions/transcript-adapter.ts'
  18. /** A replacement user message stamped with the seam's own canonical source. */
  19. function canonicalCheckpoint(seq: number): SessionEvent {
  20. return {
  21. type: 'user/message',
  22. seq,
  23. time: 1_700_000_000_000 + seq,
  24. surfaceOp: { op: 'replace', start: 0, end: 0 },
  25. sourceEventSeqs: [0],
  26. data: createUserMessage({
  27. content: [{ type: 'text', text: '<context_checkpoint>model only</context_checkpoint>' }],
  28. source: COMPACT_CHECKPOINT_SOURCE,
  29. }),
  30. } as unknown as SessionEvent
  31. }
  32. describe('compaction checkpoint recognition', () => {
  33. it('recognizes a checkpoint carrying the seam-canonical source', () => {
  34. const adapter = new TranscriptAdapter()
  35. adapter.reset([canonicalCheckpoint(1)])
  36. expect(adapter.nodes()).toEqual([{ kind: 'compaction', seq: 1, time: 1_700_000_000_001, summary: null }])
  37. })
  38. it("agrees with the seam's own predicate on the source it recognizes", () => {
  39. // Both sides answer the same question about the same value: if the seam
  40. // renames its plugin, this equality is what breaks.
  41. const checkpoint = canonicalCheckpoint(1)
  42. expect(checkpoint.type === 'user/message' && isCompactCheckpointSource(checkpoint.data.source)).toBe(true)
  43. expect(COMPACT_CHECKPOINT_SOURCE).toEqual({ kind: 'plugin', plugin: 'compact' })
  44. })
  45. })