fix: address Cubic CLI and agent issues — URL encode, JSONC leading comments, config clone, untracked files, parse error handling, cache path, message-dir dedup
This commit is contained in:
@@ -15,7 +15,11 @@ const execFileSyncMock = mock((file: string, args: string[], _opts: { cwd?: stri
|
||||
}
|
||||
|
||||
if (subcommand === "status") {
|
||||
return " M file.ts\n"
|
||||
return " M file.ts\n?? new-file.ts\n"
|
||||
}
|
||||
|
||||
if (subcommand === "ls-files") {
|
||||
return "new-file.ts\n"
|
||||
}
|
||||
|
||||
throw new Error(`unexpected args: ${args.join(" ")}`)
|
||||
@@ -38,7 +42,7 @@ describe("collectGitDiffStats", () => {
|
||||
|
||||
//#then
|
||||
expect(execSyncMock).not.toHaveBeenCalled()
|
||||
expect(execFileSyncMock).toHaveBeenCalledTimes(2)
|
||||
expect(execFileSyncMock).toHaveBeenCalledTimes(3)
|
||||
|
||||
const [firstCallFile, firstCallArgs, firstCallOpts] = execFileSyncMock.mock
|
||||
.calls[0]! as unknown as [string, string[], { cwd?: string }]
|
||||
@@ -54,6 +58,13 @@ describe("collectGitDiffStats", () => {
|
||||
expect(secondCallOpts.cwd).toBe(directory)
|
||||
expect(secondCallArgs.join(" ")).not.toContain(directory)
|
||||
|
||||
const [thirdCallFile, thirdCallArgs, thirdCallOpts] = execFileSyncMock.mock
|
||||
.calls[2]! as unknown as [string, string[], { cwd?: string }]
|
||||
expect(thirdCallFile).toBe("git")
|
||||
expect(thirdCallArgs).toEqual(["ls-files", "--others", "--exclude-standard"])
|
||||
expect(thirdCallOpts.cwd).toBe(directory)
|
||||
expect(thirdCallArgs.join(" ")).not.toContain(directory)
|
||||
|
||||
expect(result).toEqual([
|
||||
{
|
||||
path: "file.ts",
|
||||
@@ -61,6 +72,12 @@ describe("collectGitDiffStats", () => {
|
||||
removed: 2,
|
||||
status: "modified",
|
||||
},
|
||||
{
|
||||
path: "new-file.ts",
|
||||
added: 0,
|
||||
removed: 0,
|
||||
status: "added",
|
||||
},
|
||||
])
|
||||
})
|
||||
})
|
||||
|
||||
@@ -12,8 +12,6 @@ export function collectGitDiffStats(directory: string): GitFileStat[] {
|
||||
stdio: ["pipe", "pipe", "pipe"],
|
||||
}).trim()
|
||||
|
||||
if (!diffOutput) return []
|
||||
|
||||
const statusOutput = execFileSync("git", ["status", "--porcelain"], {
|
||||
cwd: directory,
|
||||
encoding: "utf-8",
|
||||
@@ -21,8 +19,27 @@ export function collectGitDiffStats(directory: string): GitFileStat[] {
|
||||
stdio: ["pipe", "pipe", "pipe"],
|
||||
}).trim()
|
||||
|
||||
const untrackedOutput = execFileSync("git", ["ls-files", "--others", "--exclude-standard"], {
|
||||
cwd: directory,
|
||||
encoding: "utf-8",
|
||||
timeout: 5000,
|
||||
stdio: ["pipe", "pipe", "pipe"],
|
||||
}).trim()
|
||||
|
||||
const untrackedNumstat = untrackedOutput
|
||||
? untrackedOutput
|
||||
.split("\n")
|
||||
.filter(Boolean)
|
||||
.map((filePath) => `0\t0\t${filePath}`)
|
||||
.join("\n")
|
||||
: ""
|
||||
|
||||
const combinedNumstat = [diffOutput, untrackedNumstat].filter(Boolean).join("\n").trim()
|
||||
|
||||
if (!combinedNumstat) return []
|
||||
|
||||
const statusMap = parseGitStatusPorcelain(statusOutput)
|
||||
return parseGitDiffNumstat(diffOutput, statusMap)
|
||||
return parseGitDiffNumstat(combinedNumstat, statusMap)
|
||||
} catch {
|
||||
return []
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user