gitActionMenuCurrentSessionFileScope.test.ts 2.5 KB

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