index.event.test.ts 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import { describe, expect, test } from 'bun:test';
  2. import { handleTaskSessionEvent } from './index-event';
  3. describe('plugin disposal event ordering', () => {
  4. test('invalidates task continuations before multiplexer handling and cleanup', async () => {
  5. const calls: string[] = [];
  6. let releaseCleanup = (): void => {
  7. throw new Error('disposal cleanup did not start');
  8. };
  9. let notifyCleanupStarted = (): void => {};
  10. const cleanupStarted = new Promise<void>((resolve) => {
  11. notifyCleanupStarted = resolve;
  12. });
  13. const eventPromise = handleTaskSessionEvent(
  14. { event: { type: 'server.instance.disposed' } },
  15. async () => {
  16. calls.push('invalidate');
  17. },
  18. async () => {
  19. calls.push('multiplexer');
  20. },
  21. async () => {
  22. calls.push('cleanup');
  23. notifyCleanupStarted();
  24. await new Promise<void>((resolve) => {
  25. releaseCleanup = resolve;
  26. });
  27. },
  28. );
  29. await cleanupStarted;
  30. expect(calls).toEqual(['invalidate', 'multiplexer', 'cleanup']);
  31. releaseCleanup();
  32. await eventPromise;
  33. });
  34. });