import { execFileSync } from "node:child_process";
import { join } from "node:path";

const defaultBinary = process.execPath;
const defaultArgs = [
	join(import.meta.dirname, "..", "..", "dist", "loader.js"),
];
const binary = process.env.SF_SMOKE_BINARY || defaultBinary;
const args = process.env.SF_SMOKE_BINARY
	? ["--help"]
	: [...defaultArgs, "--help"];

const output = execFileSync(binary, args, {
	encoding: "utf8",
	timeout: 30_000,
});

const lower = output.toLowerCase();

if (!lower.includes("sf")) {
	console.error(`Help output does not contain "sf": "${output}"`);
	process.exit(1);
}

if (!lower.includes("usage")) {
	console.error(`Help output does not contain "usage": "${output}"`);
	process.exit(1);
}
