Address workspace diff review findings

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
DottaandPaperclip committed 2026-05-15 13:28:59 -05:00
1 parent 4c98a35b8c
commit af5f646e51
12 files changed
+68 -39

No files matched your search

@@ -91,6 +91,7 @@ describe("workspaceDiffService", () => {
await fs.rm(path.join(repoRoot, "delete-me.txt"));
await fs.writeFile(path.join(repoRoot, "binary.bin"), Buffer.from([0, 1, 2, 3, 4, 5]));
await fs.writeFile(path.join(repoRoot, "untracked.txt"), "brand new\n", "utf8");
await fs.writeFile(path.join(repoRoot, "empty-untracked.txt"), "", "utf8");
await fs.writeFile(path.join(repoRoot, "oversized.txt"), "x".repeat(WORKSPACE_DIFF_CAPS.maxFileBytes + 1), "utf8");
const diff = await workspaceDiffService().getDiff(createWorkspace(repoRoot), workingTreeQuery());
@@ -126,6 +127,13 @@ describe("workspaceDiffService", () => {
additions: 1,
});
expect(byPath.get("untracked.txt")?.patches[0]?.patch).toContain("+brand new");
expect(byPath.get("empty-untracked.txt")?.patches[0]?.patch).toBe([
"diff --git a/empty-untracked.txt b/empty-untracked.txt",
"new file mode 100644",
"--- /dev/null",
"+++ b/empty-untracked.txt",
"",
].join("\n"));
expect(byPath.get("binary.bin")).toMatchObject({
binary: true,
unstaged: true,
@@ -571,6 +571,11 @@ export function buildHostServices(
*/
const ensurePluginAvailableForCompany = async (_companyId: string) => {};
const ensureDeclaredCapability = (capability: import("@paperclipai/shared").PluginCapability) => {
if (!options.manifest || options.manifest.capabilities.includes(capability)) return;
throw new Error(`Missing required capability: ${capability}`);
};
const getLocalFolderDeclaration = (folderKey: string) =>
requireLocalFolderDeclaration(options.manifest?.localFolders, folderKey);
@@ -1227,6 +1232,7 @@ export function buildHostServices(
if (!projectWorkspace) {
throw new Error("Workspace not found");
}
ensureDeclaredCapability("project.workspaces.read");
return workspaceDiff.getDiff({
id: projectWorkspace.id,
companyId: projectWorkspace.companyId,
+5 -8
View File
@@ -442,17 +442,16 @@ function countAddedLines(content: string) {
function buildUntrackedPatch(filePath: string, content: string) {
const lines = content.length === 0 ? [] : content.split("\n");
if (lines.length > 0 && lines[lines.length - 1] === "") lines.pop();
const hunkLines = lines.map((line) => `+${line}`).join("\n");
const lineCount = countAddedLines(content);
return [
const header = [
`diff --git a/${filePath} b/${filePath}`,
"new file mode 100644",
"--- /dev/null",
`+++ b/${filePath}`,
`@@ -0,0 +1,${lineCount} @@`,
hunkLines,
"",
].join("\n");
];
if (lineCount === 0) return `${header.join("\n")}\n`;
const hunkLines = lines.map((line) => `+${line}`).join("\n");
return [...header, `@@ -0,0 +1,${lineCount} @@`, hunkLines, ""].join("\n");
}
async function buildUntrackedFilePatch(input: {
@@ -674,8 +673,6 @@ export function workspaceDiffService() {
return {
workspaceId: workspace.id,
companyId: workspace.companyId,
repoRoot,
cwd,
view: query.view,
baseRef,
headSha: await resolveHeadSha(cwd),