gitActionMenuCurrentSessionFileScope.test.ts 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import { describe, expect, it } from "vitest";
  2. import type { GitRepositorySummary, ZCodeTaskChangeSummary } from "@zcode/shared";
  3. import type { GitBranchCommitPreviewFile } from "@/git-branch-switcher/display.js";
  4. import { filterCommitPreviewFilesByCurrentSession } from "@/git-action-menu/currentSessionFileScope.js";
  5. function createGitSummary(): GitRepositorySummary {
  6. return {
  7. workspacePath: "/repo/packages/app",
  8. repoRoot: "/repo",
  9. workspaceInRepoPath: "packages/app",
  10. autoRefreshWatchPaths: [],
  11. branchName: "main",
  12. trackingBranchName: null,
  13. headRefType: "branch",
  14. ahead: 0,
  15. behind: 0,
  16. isDirty: true,
  17. isGitAvailable: true,
  18. isRepository: true,
  19. };
  20. }
  21. function createChange(workspaceRelativePath: string): GitBranchCommitPreviewFile {
  22. return {
  23. stagePath: `/repo/packages/app/${workspaceRelativePath}`,
  24. repoRelativePath: `packages/app/${workspaceRelativePath}`,
  25. workspaceRelativePath,
  26. kind: "modified",
  27. added: 1,
  28. removed: 0,
  29. };
  30. }
  31. function createSummary(path: string): ZCodeTaskChangeSummary {
  32. return {
  33. fileCount: 1,
  34. added: 1,
  35. removed: 0,
  36. files: [
  37. {
  38. path,
  39. added: 1,
  40. removed: 0,
  41. writeCount: 1,
  42. lastTurnIndex: 0,
  43. },
  44. ],
  45. };
  46. }
  47. describe("current session commit file scope", () => {
  48. it("filters commit preview files to the current session summary", () => {
  49. const files = [createChange("session.txt"), createChange("unrelated.txt")];
  50. const filtered = filterCommitPreviewFilesByCurrentSession({
  51. files,
  52. summary: createSummary("/repo/packages/app/session.txt"),
  53. gitSummary: createGitSummary(),
  54. workspacePath: "/repo/packages/app",
  55. });
  56. expect(filtered.map((file) => file.workspaceRelativePath)).toEqual(["session.txt"]);
  57. });
  58. it("matches workspace-relative summary paths against repo-relative files", () => {
  59. const files = [createChange("nested/session.txt"), createChange("other.txt")];
  60. const filtered = filterCommitPreviewFilesByCurrentSession({
  61. files,
  62. summary: createSummary("nested/session.txt"),
  63. gitSummary: createGitSummary(),
  64. workspacePath: "/repo/packages/app",
  65. });
  66. expect(filtered.map((file) => file.repoRelativePath)).toEqual([
  67. "packages/app/nested/session.txt",
  68. ]);
  69. });
  70. });