mirror of
https://github.com/cline/cline.git
synced 2026-09-19 02:05:44 +08:00
**Branch-Per-Task:** Each repo now has a single Shadow Git repo, with separate branches per task (instead of one Shadow Git repo per task). - **Legacy Support:** Existing Checkpoints remain functional, while all new Checkpoints use branch-per-task. - **Commits:** Legacy tasks commit to legacy Checkpoints; new tasks commit using branch-per-task. - **Diffing & Deletions:** Both legacy and branch-per-task Checkpoints support diffing and deletion. No migration needed—existing tasks stay as-is, and new tasks adopt **branch-per-task** automatically.
74 lines
2.6 KiB
Plaintext
74 lines
2.6 KiB
Plaintext
import * as vscode from "vscode"
|
|
import fs from "fs/promises"
|
|
import path from "path"
|
|
import os from "os"
|
|
import CheckpointTracker from "./CheckpointTracker"
|
|
|
|
export async function createTestEnvironment() {
|
|
// Create temp directory structure
|
|
const tempDir = path.join(os.tmpdir(), `checkpoint-test-${Date.now()}`)
|
|
await fs.mkdir(tempDir, { recursive: true })
|
|
|
|
// Create storage path outside of working directory to avoid submodule issues
|
|
const globalStoragePath = path.join(os.tmpdir(), `storage-${Date.now()}`)
|
|
await fs.mkdir(globalStoragePath, { recursive: true })
|
|
|
|
// Create test file in a subdirectory
|
|
const testDir = path.join(tempDir, "src")
|
|
await fs.mkdir(testDir, { recursive: true })
|
|
const testFilePath = path.join(testDir, "test.txt")
|
|
|
|
// Create .gitignore to prevent git from treating directories as submodules
|
|
await fs.writeFile(path.join(tempDir, ".gitignore"), "storage/\n")
|
|
|
|
// Mock VS Code workspace
|
|
const mockWorkspaceFolders = [
|
|
{
|
|
uri: { fsPath: tempDir },
|
|
name: "test",
|
|
index: 0,
|
|
},
|
|
]
|
|
|
|
const originalDescriptor = Object.getOwnPropertyDescriptor(vscode.workspace, "workspaceFolders")
|
|
Object.defineProperty(vscode.workspace, "workspaceFolders", {
|
|
get: () => mockWorkspaceFolders,
|
|
})
|
|
|
|
// Mock findFiles to return no nested git repos
|
|
const originalFindFiles = vscode.workspace.findFiles
|
|
vscode.workspace.findFiles = async () => []
|
|
|
|
// Mock VS Code configuration
|
|
const originalGetConfiguration = vscode.workspace.getConfiguration
|
|
vscode.workspace.getConfiguration = () =>
|
|
({
|
|
get: (key: string) => (key === "enableCheckpoints" ? true : undefined),
|
|
}) as any
|
|
|
|
return {
|
|
tempDir,
|
|
globalStoragePath,
|
|
testFilePath,
|
|
originalDescriptor,
|
|
originalFindFiles,
|
|
originalGetConfiguration,
|
|
cleanup: async () => {
|
|
// Restore VS Code mocks
|
|
if (originalDescriptor) {
|
|
Object.defineProperty(vscode.workspace, "workspaceFolders", originalDescriptor)
|
|
}
|
|
vscode.workspace.getConfiguration = originalGetConfiguration
|
|
vscode.workspace.findFiles = originalFindFiles
|
|
|
|
// Clean up temp directories
|
|
await fs.rm(tempDir, { recursive: true, force: true })
|
|
await fs.rm(globalStoragePath, { recursive: true, force: true })
|
|
}
|
|
}
|
|
}
|
|
|
|
export async function createTestTracker(globalStoragePath?: string, taskId = "test-task-1") {
|
|
return await CheckpointTracker.create(taskId, globalStoragePath)
|
|
}
|