deploy-invalidation.integration.test.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Integration test for CLAUDE.md §7.3 — when the deploymentId changes for
  2. // an existing project, the next invocation must retire the old isolate
  3. // and cold-start a fresh one against the new bundle. We assert that two
  4. // invocations against the same projectId (but different deploymentIds)
  5. // produce two distinct PIDs, and that each invocation returns the value
  6. // from its own bundle (so we know the new deployment really took effect).
  7. import { describe, expect, test } from 'bun:test';
  8. import { runTwoSequentialInvocations } from './test-helpers.js';
  9. describe('deploy invalidation (integration)', () => {
  10. test('changing deploymentId retires the old isolate and respawns fresh', async () => {
  11. const { first, second, pidsObserved, cleanup } = await runTwoSequentialInvocations({
  12. first: {
  13. fnName: 'v',
  14. deploymentId: 'd1',
  15. fnSource: `
  16. import { query } from '@briven/cli/server';
  17. export const v = query(async () => 'A');
  18. `,
  19. },
  20. second: {
  21. fnName: 'v',
  22. deploymentId: 'd2',
  23. fnSource: `
  24. import { query } from '@briven/cli/server';
  25. export const v = query(async () => 'B');
  26. `,
  27. },
  28. });
  29. try {
  30. expect(first.ok).toBe(true);
  31. expect(second.ok).toBe(true);
  32. if (first.ok) expect(first.value).toBe('A');
  33. if (second.ok) expect(second.value).toBe('B');
  34. expect(pidsObserved.length).toBeGreaterThanOrEqual(2);
  35. // Two distinct PIDs prove the second invocation got a fresh isolate.
  36. const unique = new Set(pidsObserved);
  37. expect(unique.size).toBe(2);
  38. } finally {
  39. await cleanup();
  40. }
  41. }, 60_000);
  42. });