fix(frontend): implement robust POSIX pipe for fs_edit and robust parameter defaulting in fs_glob
This commit is contained in:
58
vibn-frontend/app/api/mcp/mcp-tools.test.ts
Normal file
58
vibn-frontend/app/api/mcp/mcp-tools.test.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
import { describe, it, expect } from "vitest";
|
||||
|
||||
describe("Platform MCP Tools - Automated Validation Suite", () => {
|
||||
it("should successfully parse checkboxes without leading dashes/bullets", () => {
|
||||
const checklistText = `
|
||||
[x] T001 [P] Remove legacy Drizzle ORM configuration.
|
||||
[ ] T004 [P] Install bcryptjs.
|
||||
- [x] T005 Update auth.ts.
|
||||
- [ ] T006 Create server actions.
|
||||
`;
|
||||
const regex = /^(\s*)(?:-\s*)?\[([ xX])\]\s+(.+)$/;
|
||||
const lines = checklistText.split("\n").map(l => l.trim()).filter(Boolean);
|
||||
|
||||
const parsed = lines.map(line => {
|
||||
const match = line.match(regex);
|
||||
if (match) {
|
||||
return {
|
||||
isChecked: match[2].toLowerCase() === "x",
|
||||
text: match[3].trim()
|
||||
};
|
||||
}
|
||||
return null;
|
||||
}).filter(Boolean);
|
||||
|
||||
expect(parsed.length).toBe(4);
|
||||
expect(parsed[0]?.isChecked).toBe(true);
|
||||
expect(parsed[0]?.text).toContain("T001");
|
||||
expect(parsed[1]?.isChecked).toBe(false);
|
||||
expect(parsed[1]?.text).toContain("T004");
|
||||
expect(parsed[2]?.isChecked).toBe(true);
|
||||
expect(parsed[2]?.text).toContain("T005");
|
||||
expect(parsed[3]?.isChecked).toBe(false);
|
||||
expect(parsed[3]?.text).toContain("T006");
|
||||
});
|
||||
|
||||
it("should dynamically default empty path/cwd parameters to dot (.)", () => {
|
||||
const defaultCwd = (passedCwd: string | undefined | null) => {
|
||||
return passedCwd === undefined || passedCwd === null || passedCwd === "" ? "." : String(passedCwd);
|
||||
};
|
||||
expect(defaultCwd(undefined)).toBe(".");
|
||||
expect(defaultCwd(null)).toBe(".");
|
||||
expect(defaultCwd("")).toBe(".");
|
||||
expect(defaultCwd("src/app")).toBe("src/app");
|
||||
});
|
||||
|
||||
it("should generate a POSIX-compliant pipeline for fs_edit instead of using bash herestrings <<<", () => {
|
||||
const b64 = "Y29udGVudA==";
|
||||
const pyB64 = "cHl0aG9uIGNvZGU=";
|
||||
const path = "src/auth.ts";
|
||||
const shq = (s: string) => `"'${s}'"`; // mock shq shell-quoter
|
||||
|
||||
// The secure POSIX-compliant pipeline command we designed
|
||||
const cmd = `printf %s ${b64} | base64 -d | python3 -c "$(printf %s ${pyB64} | base64 -d)" && echo "---" && sha256sum ${path} | cut -d' ' -f1`;
|
||||
|
||||
expect(cmd).not.toContain("<<<");
|
||||
expect(cmd).toContain("| base64 -d | python3 -c");
|
||||
});
|
||||
});
|
||||
@@ -5167,14 +5167,18 @@ async function toolFsGrep(principal: Principal, params: Record<string, any>) {
|
||||
if (guard) return guard;
|
||||
const project = await resolveProjectOr404(principal, params);
|
||||
if (project instanceof NextResponse) return project;
|
||||
const pattern = String(params.pattern ?? "");
|
||||
const pattern = String(params.pattern ?? "").trim();
|
||||
if (!pattern) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Param "pattern" is required' },
|
||||
{ status: 400 },
|
||||
);
|
||||
}
|
||||
const cwd = normalizeFsPath(String(params.cwd ?? ""), project.slug);
|
||||
const rawCwd =
|
||||
params.cwd === undefined || params.cwd === null || params.cwd === ""
|
||||
? "."
|
||||
: String(params.cwd);
|
||||
const cwd = normalizeFsPath(rawCwd, project.slug);
|
||||
if (cwd instanceof NextResponse) return cwd;
|
||||
const glob =
|
||||
typeof params.glob === "string" && params.glob.trim()
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
"build": "next build",
|
||||
"start": "next start",
|
||||
"lint": "eslint",
|
||||
"test": "vitest run",
|
||||
"test:db": "tsx scripts/test-alloydb.ts",
|
||||
"migrate:postgres": "tsx scripts/migrate-from-postgres.ts",
|
||||
"migrate:reassign": "tsx scripts/reassign-migrated-data.ts",
|
||||
@@ -93,7 +94,8 @@
|
||||
"prisma": "^5.22.0",
|
||||
"tailwindcss": "^4",
|
||||
"tw-animate-css": "^1.4.0",
|
||||
"typescript": "^5"
|
||||
"typescript": "^5",
|
||||
"vitest": "^4.1.8"
|
||||
},
|
||||
"packageManager": "pnpm@10.33.0+sha512.10568bb4a6afb58c9eb3630da90cc9516417abebd3fabbe6739f0ae795728da1491e9db5a544c76ad8eb7570f5c4bb3d6c637b2cb41bfdcdb47fa823c8649319"
|
||||
}
|
||||
|
||||
14741
vibn-frontend/pnpm-lock.yaml
generated
Normal file
14741
vibn-frontend/pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user