coreWiringFixture.mjs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  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(
  6. outputPath,
  7. `${JSON.stringify({
  8. agentArgs: JSON.parse(process.env.ZCODE_AGENT_SERVER_ARGS_JSON ?? "[]"),
  9. agentCommand: process.env.ZCODE_AGENT_SERVER_COMMAND ?? null,
  10. dataBaseDir: process.env.ZCODE_DATA_BASE_DIR ?? null,
  11. generation,
  12. runtimeRoot: process.env.ZCODE_SERVER_RUNTIME_ROOT ?? null,
  13. })}\n`,
  14. "utf8",
  15. );
  16. process.send?.({
  17. type: "ready",
  18. host: "127.0.0.1",
  19. port: 43123 + generation,
  20. version: process.env.ZCODE_TEST_CORE_VERSION ?? "fixture",
  21. ...(process.env.ZCODE_SERVER_RELEASE_ID
  22. ? { releaseId: process.env.ZCODE_SERVER_RELEASE_ID }
  23. : {}),
  24. generation,
  25. });
  26. process.on("message", (message) => {
  27. if (typeof message === "object" && message !== null && message.command === "shutdown") {
  28. process.send?.({ type: "shutdown-ack" });
  29. process.send?.({ type: "exit", reason: "requested" }, () => process.exit(0));
  30. }
  31. });