coreWiringFixture.mjs 955 B

12345678910111213141516171819202122232425262728
  1. import { appendFile } from "node:fs/promises";
  2. const generation = Number(process.argv[2] ?? 0);
  3. const outputPath = process.env.ZCODE_TEST_WIRING_OUTPUT;
  4. if (!outputPath) throw new Error("ZCODE_TEST_WIRING_OUTPUT is required");
  5. await appendFile(outputPath, `${JSON.stringify({
  6. agentArgs: JSON.parse(process.env.ZCODE_AGENT_SERVER_ARGS_JSON ?? "[]"),
  7. agentCommand: process.env.ZCODE_AGENT_SERVER_COMMAND ?? null,
  8. dataBaseDir: process.env.ZCODE_DATA_BASE_DIR ?? null,
  9. generation,
  10. runtimeRoot: process.env.ZCODE_SERVER_RUNTIME_ROOT ?? null,
  11. })}\n`, "utf8");
  12. process.send?.({
  13. type: "ready",
  14. host: "127.0.0.1",
  15. port: 43123 + generation,
  16. version: "fixture",
  17. generation,
  18. });
  19. process.on("message", (message) => {
  20. if (typeof message === "object" && message !== null && message.command === "shutdown") {
  21. process.send?.({ type: "shutdown-ack" });
  22. process.send?.({ type: "exit", reason: "requested" }, () => process.exit(0));
  23. }
  24. });