Files
oh-my-pi/packages/git-tool/test/cache.test.ts
T
can1357 56e760f2bc feat(git-tool): added git-tool package with 22 operations and safety guards
- Added new @oh-my-pi/pi-git-tool package with 22 git operations, safety guards, caching, and GitHub CLI integration.
- Added /wt slash command for git worktree management with create, list, merge, remove, spawn, and parallel operations.
- Added worktree library with collapse strategies (simple, merge-base, rebase) and session tracking for agent tasks.
- Added structured git tool with TypeBox schema exposing gitTool and createGitTool from SDK.
- Added safety policies blocking force push to protected branches and warning on destructive operations.
2026-01-05 15:37:44 +01:00

39 lines
1.3 KiB
TypeScript

import { join } from "node:path";
import { afterEach, beforeEach, describe, expect, it } from "vitest";
import { gitTool } from "../src/git-tool";
import type { StatusResult, ToolResult } from "../src/types";
import { cleanupRepo, createTestRepo, runGit, writeFile } from "./helpers";
let repoDir: string;
let previousCwd: string;
beforeEach(() => {
previousCwd = process.cwd();
repoDir = createTestRepo();
process.chdir(repoDir);
});
afterEach(() => {
process.chdir(previousCwd);
cleanupRepo(repoDir);
});
describe("git-tool cache", () => {
it("invalidates status cache on write operations", async () => {
writeFile(join(repoDir, "file.txt"), "hello");
runGit(["add", "file.txt"], repoDir);
runGit(["commit", "-m", "initial"], repoDir);
writeFile(join(repoDir, "file.txt"), "hello world");
const status1 = (await gitTool({ operation: "status" })) as ToolResult<StatusResult>;
expect(status1.data.modified.map((file) => file.path)).toContain("file.txt");
await gitTool({ operation: "add", paths: ["file.txt"] });
const status2 = (await gitTool({ operation: "status" })) as ToolResult<StatusResult>;
expect(status2.data.staged.map((file) => file.path)).toContain("file.txt");
expect(status2.data.modified.map((file) => file.path)).not.toContain("file.txt");
});
});