3686-session-name-event.test.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import { afterEach, describe, expect, it } from "vitest";
  2. import type { ExtensionAPI } from "../../../src/index.ts";
  3. import { createHarness, type Harness } from "../harness.ts";
  4. describe("regression #3686: session name changes emit an event", () => {
  5. const harnesses: Harness[] = [];
  6. afterEach(() => {
  7. while (harnesses.length > 0) {
  8. harnesses.pop()?.cleanup();
  9. }
  10. });
  11. it("emits session_info_changed when AgentSession.setSessionName is called", async () => {
  12. const harness = await createHarness();
  13. harnesses.push(harness);
  14. harness.session.setSessionName("hello world");
  15. expect(harness.sessionManager.getSessionName()).toBe("hello world");
  16. expect(harness.eventsOfType("session_info_changed").map((event) => event.name)).toEqual(["hello world"]);
  17. });
  18. it("emits session_info_changed when an extension calls pi.setSessionName", async () => {
  19. let api: ExtensionAPI | undefined;
  20. const harness = await createHarness({
  21. extensionFactories: [
  22. (pi) => {
  23. api = pi;
  24. },
  25. ],
  26. });
  27. harnesses.push(harness);
  28. api?.setSessionName("from extension");
  29. expect(harness.sessionManager.getSessionName()).toBe("from extension");
  30. expect(harness.eventsOfType("session_info_changed").map((event) => event.name)).toEqual(["from extension"]);
  31. });
  32. });