import { test, after } from "node:test"; import assert from "node:assert/strict"; import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs"; import os from "node:os"; import path from "node:path"; import { editorSettingsFile } from "./paths.mjs"; // Run with: node --test umtool/lib/editorSettingsFile.test.mjs // // THE SETTINGS FILE THE umtool CLI NAMES TO THE CHILD-ENVIRONMENT GUARD // (lane network-exits, review 4 nit 3): the one common/lib/paths.ts getPaths() // reads in the same process — SETTINGS_FILE, else the workspace found by // walking up from the cwd (8 levels) — and, where getPaths() would find none // (a project directory outside every checkout), the CLI's own checkout's, so // a policy there is never missed. const DIR = mkdtempSync(path.join(os.tmpdir(), "editor-settings-file-")); after(() => rmSync(DIR, { recursive: true, force: true })); const repo = path.join(DIR, "repo"); mkdirSync(path.join(repo, "a", "b"), { recursive: true }); writeFileSync(path.join(repo, "pnpm-workspace.yaml"), ""); const outside = path.join(DIR, "project"); mkdirSync(outside, { recursive: true }); test("SETTINGS_FILE wins, as in getPaths()", () => { assert.equal(editorSettingsFile({ cwd: outside, env: { SETTINGS_FILE: "/x/settings.json" }, fallbackRoot: repo }), "/x/settings.json"); }); test("a cwd inside a checkout names that checkout's file, as getPaths() does", () => { assert.equal(editorSettingsFile({ cwd: path.join(repo, "a", "b"), env: {}, fallbackRoot: "/elsewhere" }), path.join(repo, "settings.json")); }); test("a cwd outside every checkout names the CLI's own checkout's file", () => { assert.equal(editorSettingsFile({ cwd: outside, env: {}, fallbackRoot: repo }), path.join(repo, "settings.json")); });