strip out code fences (fix gemini occasional mis-format)
This commit is contained in:
@@ -55,6 +55,39 @@ describe("getDyadWriteTags", () => {
|
|||||||
expect(result).toEqual([]);
|
expect(result).toEqual([]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should return a dyad-write tag", () => {
|
||||||
|
const result =
|
||||||
|
getDyadWriteTags(`<dyad-write path="src/components/TodoItem.tsx" description="Creating a component for individual todo items">
|
||||||
|
import React from "react";
|
||||||
|
console.log("TodoItem");
|
||||||
|
</dyad-write>`);
|
||||||
|
expect(result).toEqual([
|
||||||
|
{
|
||||||
|
path: "src/components/TodoItem.tsx",
|
||||||
|
content: `import React from \"react\";
|
||||||
|
console.log(\"TodoItem\");`,
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should strip out code fence (if needed) from a dyad-write tag", () => {
|
||||||
|
const result =
|
||||||
|
getDyadWriteTags(`<dyad-write path="src/components/TodoItem.tsx" description="Creating a component for individual todo items">
|
||||||
|
\`\`\`tsx
|
||||||
|
import React from "react";
|
||||||
|
console.log("TodoItem");
|
||||||
|
\`\`\`
|
||||||
|
</dyad-write>
|
||||||
|
`);
|
||||||
|
expect(result).toEqual([
|
||||||
|
{
|
||||||
|
path: "src/components/TodoItem.tsx",
|
||||||
|
content: `import React from \"react\";
|
||||||
|
console.log(\"TodoItem\");`,
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
it("should return an array of dyad-write tags", () => {
|
it("should return an array of dyad-write tags", () => {
|
||||||
const result = getDyadWriteTags(
|
const result = getDyadWriteTags(
|
||||||
`I'll create a simple todo list app using React, TypeScript, and shadcn/ui components. Let's get started!
|
`I'll create a simple todo list app using React, TypeScript, and shadcn/ui components. Let's get started!
|
||||||
@@ -557,7 +590,7 @@ describe("processFullResponse", () => {
|
|||||||
expect(fs.writeFileSync).toHaveBeenNthCalledWith(
|
expect(fs.writeFileSync).toHaveBeenNthCalledWith(
|
||||||
3,
|
3,
|
||||||
"/mock/user/data/path/mock-app-path/src/components/Button.tsx",
|
"/mock/user/data/path/mock-app-path/src/components/Button.tsx",
|
||||||
"\n import React from 'react';\n export const Button = ({ children }) => <button>{children}</button>;\n "
|
"import React from 'react';\n export const Button = ({ children }) => <button>{children}</button>;"
|
||||||
);
|
);
|
||||||
|
|
||||||
// Verify git operations were called for each file
|
// Verify git operations were called for each file
|
||||||
|
|||||||
@@ -15,7 +15,14 @@ export function getDyadWriteTags(fullResponse: string): {
|
|||||||
let match;
|
let match;
|
||||||
const tags: { path: string; content: string }[] = [];
|
const tags: { path: string; content: string }[] = [];
|
||||||
while ((match = dyadWriteRegex.exec(fullResponse)) !== null) {
|
while ((match = dyadWriteRegex.exec(fullResponse)) !== null) {
|
||||||
tags.push({ path: match[1], content: match[2] });
|
const content = match[2].trim().split("\n");
|
||||||
|
if (content[0].startsWith("```")) {
|
||||||
|
content.shift();
|
||||||
|
}
|
||||||
|
if (content[content.length - 1].startsWith("```")) {
|
||||||
|
content.pop();
|
||||||
|
}
|
||||||
|
tags.push({ path: match[1], content: content.join("\n") });
|
||||||
}
|
}
|
||||||
return tags;
|
return tags;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user