diff --git a/src/cli.ts b/src/cli.ts index 407ef17..ad2ff18 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -45,13 +45,15 @@ program .description("Close a multi-model tmux session") .argument("", "Name of the tmux session to close") .option("-c, --cleanup-worktrees", "Remove worktrees and delete branches", true) + .option("-t, --add-tags", "Create archive tags before deleting branches", true) .option("-f, --force", "Skip confirmation prompts", false) - .action(async (sessionName: string, options: { cleanupWorktrees: boolean; force: boolean }) => { + .action(async (sessionName: string, options: { cleanupWorktrees: boolean; force: boolean; addTags: boolean }) => { try { const result = await closeMultiModel({ sessionName, cleanupWorktrees: options.cleanupWorktrees, force: options.force, + createArchiveTags: options.addTags, }); if (result.success) { diff --git a/src/core/close.ts b/src/core/close.ts index 81cf080..a08ddea 100644 --- a/src/core/close.ts +++ b/src/core/close.ts @@ -96,17 +96,19 @@ export async function closeMultiModel(options: CloseSessionOptions): Promise { expect(executedCommands).toContain(`git worktree remove -f ${worktreePath}`); expect(executedCommands).toContain(`git branch -D opencode/${sanitized}/model`); }); + + test("skip archive tags when flag disabled", async () => { + mockCommandResponses["tmux has-session -t test-session"] = { ok: false, stdout: "", stderr: "" }; + const worktreePath = "/home/user/.local/share/opencode/multi-model/test-session/model"; + const worktreeListOutput = `worktree ${worktreePath}\nbranch refs/heads/opencode/test-session/model`; + mockCommandResponses["git worktree list --porcelain"] = { ok: true, stdout: worktreeListOutput, stderr: "" }; + mockCommandResponses[`git worktree remove -f ${worktreePath}`] = { ok: true, stdout: "", stderr: "" }; + mockCommandResponses["git branch -D opencode/test-session/model"] = { ok: true, stdout: "", stderr: "" }; + mockCommandResponses["rm -rf /home/user/.local/share/opencode/multi-model/test-session"] = { ok: true, stdout: "", stderr: "" }; + + const result = await closeMultiModel({ sessionName: "test-session", cleanupWorktrees: true, force: true, createArchiveTags: false }); + + expect(result.success).toBe(true); + expect(result.cleanupPerformed).toBe(true); + expect(result.worktreesRemoved).toEqual([worktreePath]); + expect(result.branchesDeleted).toEqual(["opencode/test-session/model"]); + expect(result.tagsCreated?.length ?? 0).toBe(0); + // Ensure no tag command was executed + expect(executedCommands.some(cmd => cmd.startsWith("git tag"))).toBe(false); + }); }); +