plugin-discovery-session-support.test.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import { describe, expect, it } from "vitest";
  2. import { PLUGIN_DISCOVERY_INPUT } from "@zcode/contracts";
  3. import type { CommandEnvelope } from "@zcode/shared/zcode-protocol-v4";
  4. import {
  5. inputIntentMetadata,
  6. inputIntentMetadataFromCanonical,
  7. } from "../src/zcode-protocol-v4/commands/input-intent.js";
  8. describe("plugin discovery input admission", () => {
  9. it.each(["createSession", "sendText"] as const)(
  10. "keeps %s support on the initiating input only",
  11. (type) => {
  12. const command: CommandEnvelope = {
  13. type,
  14. commandId: "cmd",
  15. sessionId: type === "createSession" ? null : "s",
  16. issuedAt: 0,
  17. clientId: "app",
  18. payload: {},
  19. };
  20. const options = { text: "mail", requestedDelivery: "startNow" as const };
  21. const supported = inputIntentMetadata({ ...command, pluginDiscoveryUi: true }, options);
  22. const legacy = inputIntentMetadata(command, options);
  23. expect(supported[PLUGIN_DISCOVERY_INPUT]).toBe(true);
  24. expect(legacy[PLUGIN_DISCOVERY_INPUT]).toBeUndefined();
  25. expect(JSON.parse(JSON.stringify(supported))).toEqual(JSON.parse(JSON.stringify(legacy)));
  26. expect(
  27. inputIntentMetadataFromCanonical(command, {
  28. ...supported,
  29. text: "retry",
  30. kind: "sendText",
  31. })[PLUGIN_DISCOVERY_INPUT],
  32. ).toBeUndefined();
  33. },
  34. );
  35. });