Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Studio: make Recipes lint validators run on Windows and under a gitignored temp root (#15929)

Daniel Han2a75436966a7
diff --git a/studio/backend/core/data_recipe/oxc-validator/validate.mjs b/studio/backend/core/data_recipe/oxc-validator/validate.mjs
index 6682e581e8e..66ca0e71409 100644
--- a/studio/backend/core/data_recipe/oxc-validator/validate.mjs
+++ b/studio/backend/core/data_recipe/oxc-validator/validate.mjs
@@ -28,6 +28,12 @@ const OXLINT_MIN_TIMEOUT_MS = 1_000;
const TOOL_DIR = dirname(fileURLToPath(import.meta.url));
// Lint with the shipped empty config only: never one found next to or above the snippets.
const OXLINT_CONFIG_PATH = join(TOOL_DIR, "oxlintrc.json");
+// Windows cannot run the extensionless .bin/oxlint shim (spawn only tries .com/.exe there) and
+// refuses the .cmd one without a shell, so run oxlint's bin entry with this Node instead.
+const IS_WINDOWS = process.platform === "win32";
+const OXLINT_ENTRY = join(TOOL_DIR, "node_modules", "oxlint", "bin", "oxlint");
+// Windows caps a whole command line at 32,767 chars and batch_size is unbounded: lint in chunks.
+const OXLINT_FILE_ARGS_MAX_CHARS = 24_000;
function mapLang(value) {
const normalized = String(value || "").trim().toLowerCase();
@@ -394,58 +400,73 @@ function runLintBatch(entries, budgetMs) {
const entryByIndex = new Map(entries.map((entry) => [entry.index, entry]));
const tempDir = mkdtempSync(join(tmpdir(), "oxlint-"));
try {
+ // Named files: a folder walk skips a temp dir under any ignoring .gitignore. Relative = short args.
+ const chunks = [[]];
+ let chunkChars = 0;
for (const entry of entries) {
const ext = LANG_TO_EXT[entry.lang] ?? "js";
- const filePath = join(tempDir, `snippet_${entry.index}.${ext}`);
- writeFileSync(filePath, entry.code, "utf8");
+ const name = `snippet_${entry.index}.${ext}`;
+ writeFileSync(join(tempDir, name), entry.code, "utf8");
+ if (chunkChars + name.length + 1 > OXLINT_FILE_ARGS_MAX_CHARS) {
+ chunks.push([]);
+ chunkChars = 0;
+ }
+ chunks[chunks.length - 1].push(name);
+ chunkChars += name.length + 1;
}
- const oxlintBin = join(TOOL_DIR, "node_modules", ".bin", "oxlint");
- const oxlintArgs = [
+ const oxlintBin = IS_WINDOWS
+ ? process.execPath
+ : join(TOOL_DIR, "node_modules", ".bin", "oxlint");
+ const oxlintBaseArgs = [
+ ...(IS_WINDOWS ? [OXLINT_ENTRY] : []),
"--config",
OXLINT_CONFIG_PATH,
"--disable-nested-config",
...OXLINT_SUPPRESSED_RULES.flatMap((rule) => ["-A", rule]),
"--format",
"json",
- tempDir,
];
- const timeoutMs = Math.floor(budgetMs - OXLINT_BUDGET_MARGIN_MS - performance.now());
- if (timeoutMs < OXLINT_MIN_TIMEOUT_MS) {
- return fallbackLintResults(entries, "oxlint skipped: validation budget exhausted");
- }
- const exec = spawnSync(oxlintBin, oxlintArgs, {
- encoding: "utf8",
- cwd: TOOL_DIR,
- timeout: timeoutMs,
- // SIGTERM is ignorable, and spawnSync then waits out the child regardless.
- killSignal: "SIGKILL",
- });
- if (exec.error) {
- return fallbackLintResults(
- entries,
- `oxlint execution failed: ${exec.error.message}`,
- );
- }
- const stdout = String(exec.stdout || "").trim();
- if (!stdout) {
- const stderr = String(exec.stderr || "").trim();
- return fallbackLintResults(
- entries,
- stderr || "oxlint returned empty output",
- );
- }
+ const rawDiagnostics = [];
+ for (const names of chunks) {
+ const timeoutMs = Math.floor(budgetMs - OXLINT_BUDGET_MARGIN_MS - performance.now());
+ if (timeoutMs < OXLINT_MIN_TIMEOUT_MS) {
+ return fallbackLintResults(entries, "oxlint skipped: validation budget exhausted");
+ }
+ const oxlintArgs = [...oxlintBaseArgs, ...names];
+ const exec = spawnSync(oxlintBin, oxlintArgs, {
+ encoding: "utf8",
+ cwd: tempDir,
+ timeout: timeoutMs,
+ // SIGTERM is ignorable, and spawnSync then waits out the child regardless.
+ killSignal: "SIGKILL",
+ });
+ if (exec.error) {
+ return fallbackLintResults(
+ entries,
+ `oxlint execution failed: ${exec.error.message}`,
+ );
+ }
+ const stdout = String(exec.stdout || "").trim();
+ if (!stdout) {
+ const stderr = String(exec.stderr || "").trim();
+ return fallbackLintResults(
+ entries,
+ stderr || "oxlint returned empty output",
+ );
+ }
- let parsed;
- try {
- parsed = JSON.parse(stdout);
- } catch {
- return fallbackLintResults(entries, "oxlint JSON parse failed");
+ let parsed;
+ try {
+ parsed = JSON.parse(stdout);
+ } catch {
+ return fallbackLintResults(entries, "oxlint JSON parse failed");
+ }
+ if (Array.isArray(parsed?.diagnostics)) {
+ rawDiagnostics.push(...parsed.diagnostics);
+ }
}
- const rawDiagnostics = Array.isArray(parsed?.diagnostics)
- ? parsed.diagnostics
- : [];
const byIndex = new Map();
for (const diag of rawDiagnostics) {
diff --git a/studio/backend/tests/test_local_callable_validators.py b/studio/backend/tests/test_local_callable_validators.py
index a15f6232a98..01d027cfce9 100644
--- a/studio/backend/tests/test_local_callable_validators.py
+++ b/studio/backend/tests/test_local_callable_validators.py
@@ -84,6 +84,22 @@ def test_the_wrapper_kills_oxlint_against_the_remaining_caller_budget():
assert 'killSignal: "SIGKILL"' in options.group(1)
+@real_oxlint
+def test_windows_launches_oxlint_through_its_bin_entry():
+ source = validators._OXC_RUNNER_PATH.read_text(encoding = "utf-8")
+ entry = re.search(r"const OXLINT_ENTRY = join\(TOOL_DIR, ([^)]*)\);", source)
+ assert entry, "validate.mjs must name oxlint's bin entry for Windows"
+ parts = [part.strip().strip('"') for part in entry.group(1).split(",")]
+ package_dir = validators._OXC_TOOL_DIR / "node_modules" / "oxlint"
+ package = json.loads((package_dir / "package.json").read_text(encoding = "utf-8"))
+ bin_field = package["bin"]
+ bin_path = bin_field["oxlint"] if isinstance(bin_field, dict) else bin_field
+ assert validators._OXC_TOOL_DIR.joinpath(*parts) == (package_dir / bin_path).resolve(
+ strict = False
+ )
+ assert "process.execPath" in source
+
+
@real_oxlint
@pytest.mark.parametrize("depth", [0, 1, 2])
@pytest.mark.parametrize("config_name", ["oxlint.config.ts", ".oxlintrc.json"])
@@ -117,3 +133,36 @@ def test_oxlint_never_loads_a_config_planted_around_the_snippets(
assert not marker.exists()
# Pinned to the shipped, empty config: the default rules still report.
assert [result["code"] for result in results] == ["eslint(no-debugger)"]
+
+
+@real_oxlint
+def test_oxlint_lints_snippets_under_a_gitignored_temp_root(monkeypatch, tmp_path):
+ subprocess.run(["git", "init", "-q", str(tmp_path)], check = True)
+ (tmp_path / ".gitignore").write_text("*\n", encoding = "utf-8")
+ oxc_tmp = tmp_path / "studio" / "oxc-validator"
+ oxc_tmp.mkdir(parents = True)
+ monkeypatch.setattr(validators, "oxc_validator_tmp_root", lambda: oxc_tmp)
+
+ results = validators._run_oxc_batch(
+ node_lang = "js",
+ validation_mode = "lint",
+ code_shape = "module",
+ code_values = ["debugger;\n", "export const x = 1;\n"],
+ )
+
+ assert [result["code"] for result in results] == ["eslint(no-debugger)", None]
+
+
+@real_oxlint
+def test_oxlint_lints_a_batch_longer_than_one_command_line(monkeypatch, tmp_path):
+ monkeypatch.setattr(validators, "oxc_validator_tmp_root", lambda: tmp_path)
+ codes = ["debugger;\n", "export const x = 1;\n"] * 1500
+
+ results = validators._run_oxc_batch(
+ node_lang = "js",
+ validation_mode = "lint",
+ code_shape = "module",
+ code_values = codes,
+ )
+
+ assert [result["code"] for result in results] == ["eslint(no-debugger)", None] * 1500