useSlashCommands.test.ts 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. import { describe, expect, it, beforeEach } from "vitest";
  2. import { selectWorkspaceZCodeState, useZCodeSessionStore } from "../src/store/zcodeSessionStore.js";
  3. describe("useSlashCommands", () => {
  4. beforeEach(() => {
  5. useZCodeSessionStore.setState((state) => ({
  6. ...state,
  7. workspaces: {},
  8. }));
  9. });
  10. it("remote workspace 会按 workspaceIdentity 读取 slash commands", () => {
  11. const workspacePath = "/root";
  12. const workspaceIdentity = "remote:ssh:demo:22:root:/root";
  13. useZCodeSessionStore.getState().setSlashCommands(
  14. workspacePath,
  15. [{ name: "remote-command", description: "remote command" }],
  16. workspaceIdentity,
  17. );
  18. const identityCommands = selectWorkspaceZCodeState(
  19. useZCodeSessionStore.getState(),
  20. workspacePath,
  21. workspaceIdentity,
  22. ).slashCommands;
  23. const pathOnlyCommands = selectWorkspaceZCodeState(useZCodeSessionStore.getState(), workspacePath).slashCommands;
  24. expect(identityCommands.map((command) => command.name)).toEqual(["remote-command"]);
  25. expect(pathOnlyCommands).toEqual([]);
  26. });
  27. });