import { describe, expect, it } from "vitest";
import { normalizeServiceStartCommand } from "./processes.mjs";

describe("runner processes", () => {
  it("strips a single leading exec prefix for backward compatibility", () => {
    expect(normalizeServiceStartCommand("exec node server.mjs")).toBe("node server.mjs");
    expect(normalizeServiceStartCommand("  exec ./node_modules/.bin/next dev -p {port}  ")).toBe(
      "./node_modules/.bin/next dev -p {port}"
    );
  });

  it("leaves plain commands unchanged", () => {
    expect(normalizeServiceStartCommand("node server.mjs")).toBe("node server.mjs");
  });

  it("rejects empty commands", () => {
    expect(() => normalizeServiceStartCommand("   ")).toThrow(
      /Service start command must not be empty/
    );
  });
});
