cache-payload.snapshot.test.ts 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /**
  2. * Golden snapshots of the prompt surfaces this plugin injects into the
  3. * provider payload prefix.
  4. *
  5. * Any byte change to these surfaces invalidates the provider prompt cache
  6. * for every existing session the next time it sends a request — the change
  7. * may still be worth it, but it must be deliberate, not incidental. When one
  8. * of these tests fails:
  9. *
  10. * 1. Confirm the payload change is intentional and worth a one-time,
  11. * fleet-wide cache re-warm (cost + latency on the first request of
  12. * every active session).
  13. * 2. Update the snapshot with `bun test --update-snapshots` and let the
  14. * snapshot diff document the cache impact in the PR.
  15. *
  16. * Never update these snapshots to silence a failure you can't explain.
  17. */
  18. import { describe, expect, test } from 'bun:test';
  19. import { buildOrchestratorPrompt } from '../agents/orchestrator';
  20. import { PHASE_REMINDER } from '../config/constants';
  21. import {
  22. buildHistory,
  23. createPipeline,
  24. FIXTURE_NOW,
  25. renderTurn,
  26. SESSION_ID,
  27. } from './cache-safety-harness.test';
  28. describe('cache-impact snapshots (update deliberately — see file header)', () => {
  29. test('phase reminder text', () => {
  30. expect(PHASE_REMINDER).toMatchSnapshot();
  31. });
  32. test('orchestrator system prompt', () => {
  33. const prompt = buildOrchestratorPrompt(new Set());
  34. // Deterministic across invocations — a mismatch here means something
  35. // volatile (time, randomness, environment) leaked into the prompt.
  36. expect(buildOrchestratorPrompt(new Set())).toBe(prompt);
  37. expect(prompt).toMatchSnapshot();
  38. });
  39. test('transformed payload for the canonical conversation fixture', async () => {
  40. const pipeline = createPipeline();
  41. pipeline.board.registerLaunch({
  42. taskID: 'task-snapshot',
  43. parentSessionID: SESSION_ID,
  44. agent: 'explorer',
  45. description: 'snapshot fixture job',
  46. now: FIXTURE_NOW,
  47. });
  48. const history = buildHistory();
  49. const output = await renderTurn(pipeline, history, history.length - 1);
  50. expect(output.messages).toMatchSnapshot();
  51. });
  52. });