Review a generated AI IDE task runner

from AI IDEs
Node 24 advanced 12 min 3 issues to find

Review this generated code before the IDE runner is used.

Provide the order source and test as context, write only to src/orders.js and test/orders.test.js, run npm test and npm run lint, and return completion evidence.

JavaScript
import { globSync, readFileSync, writeFileSync } from "node:fs";
import { execFileSync } from "node:child_process";

function runIdeTask(workspace, task, model) {
  const files = globSync("**/*", { cwd: workspace });
  const context = files
    .map((name) => readFileSync(`${workspace}/${name}`, "utf8"))
    .join("\n");
  const response = model.generate(`${task}\n${context}`);

  for (const edit of response.edits) {
    const target = `${workspace}/${edit.path}`;
    writeFileSync(target, edit.content);
  }
  const testOutput = execFileSync("npm", ["test"], {
    cwd: workspace,
    encoding: "utf8",
    env: { PATH: process.env.PATH ?? "", CI: "1" },
  });
  return {
    status: "done",
    summary: response.summary,
    testOutput,
  };
}

generated code is illustrative, not from any one model

Open in playground
Report an error