fix(coding-agent/core): dropped hashline sections without intermediate operations
- Updated hashline splitting to skip emitting a section when a path header has no following operations. - Added a trimmed non-empty check so only sections with diff content are returned. - Added tests for duplicate and trailing headers to ensure empty header-only chunks are silently dropped.
This commit is contained in:
@@ -108,7 +108,8 @@ export function splitHashlineInputs(input: string, options: SplitHashlineOptions
|
||||
|
||||
const flush = () => {
|
||||
if (currentPath.length === 0) return;
|
||||
sections.push({ path: currentPath, diff: currentLines.join("\n") });
|
||||
const hasOps = currentLines.some(rawLine => stripTrailingCarriageReturn(rawLine).trim().length > 0);
|
||||
if (hasOps) sections.push({ path: currentPath, diff: currentLines.join("\n") });
|
||||
currentLines = [];
|
||||
};
|
||||
|
||||
|
||||
@@ -422,6 +422,16 @@ describe("splitHashlineInput — @ headers", () => {
|
||||
{ path: "b.ts", diff: `+ EOF\n${pl("b")}` },
|
||||
]);
|
||||
});
|
||||
|
||||
it("silently drops a duplicate header with no operations between them", () => {
|
||||
const input = ["@@ src/foo.ts", "@@ src/foo.ts", `+ BOF`, pl("x")].join("\n");
|
||||
expect(splitHashlineInputs(input)).toEqual([{ path: "src/foo.ts", diff: `+ BOF\n${pl("x")}` }]);
|
||||
});
|
||||
|
||||
it("silently drops a trailing header with no operations", () => {
|
||||
const input = ["@@ a.ts", "+ BOF", pl("a"), "@@ b.ts"].join("\n");
|
||||
expect(splitHashlineInputs(input)).toEqual([{ path: "a.ts", diff: `+ BOF\n${pl("a")}` }]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("hashline executor", () => {
|
||||
|
||||
Reference in New Issue
Block a user