[273] Temp-Ordner: Arbeitsordner immer aufräumen (CLI render/blend/cycles, Tauri/Electron-Brücke, Start-Aufräumen > 24 h), Tests mit makeTmpDir und eigenem TMPDIR samt Wächter
This commit is contained in:
36 files changed
+411
-63
No files matched your search
+3
-3
@@ -1,14 +1,13 @@
|
||||
// dossier-cli (Phase C): importiert nur src/core, und die Befehle laufen headless gegen das
|
||||
// Beispielprojekt (inkl. der echten WASM-Pakete aus src/engine/pkg*).
|
||||
import { describe, expect, it, beforeAll, vi } from "vitest";
|
||||
import { existsSync, mkdtempSync, readFileSync, writeFileSync, readdirSync, statSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { existsSync, readFileSync, writeFileSync, readdirSync, statSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import { run } from "./main";
|
||||
import { projectToModel3d, serializeProject } from "../core";
|
||||
import { sampleProject } from "../model/sampleProject";
|
||||
|
||||
const dir = mkdtempSync(join(tmpdir(), "dossier-cli-"));
|
||||
const dir = makeTmpDir("dossier-cli-");
|
||||
const file = join(dir, "demo.obp");
|
||||
|
||||
beforeAll(() => {
|
||||
@@ -250,6 +249,7 @@ describe("dossier-cli", () => {
|
||||
});
|
||||
|
||||
import { handleMessage } from "./mcp";
|
||||
import { makeTmpDir } from "../test/tmpDir";
|
||||
|
||||
describe("MCP-Server", () => {
|
||||
it("initialize, tools/list, project_info, apply_ops mit Validierung", async () => {
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
// dossier-cli convert ([C4]): Format nach Endung, Rundreisen über echte Dateien, --cmd mit {last}.
|
||||
import { describe, expect, it, beforeAll } from "vitest";
|
||||
import { existsSync, mkdtempSync, readFileSync, writeFileSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import { run } from "./main";
|
||||
import { parseProjectFile, serializeProject, sampleProject } from "../core";
|
||||
import { makeTmpDir } from "../test/tmpDir";
|
||||
|
||||
const dir = mkdtempSync(join(tmpdir(), "dossier-convert-"));
|
||||
const dir = makeTmpDir("dossier-convert-");
|
||||
const p = (name: string) => join(dir, name);
|
||||
const obp = p("demo.obp");
|
||||
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
// dossier-cli import-mesh und convert mit Mesh-Eingabe: Rundreise über echte Dateien (glb, gltf, obj+mtl, stl).
|
||||
import { beforeAll, describe, expect, it } from "vitest";
|
||||
import { mkdtempSync, readFileSync, writeFileSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { readFileSync, writeFileSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import { run } from "./main";
|
||||
import { parseProjectFile, sampleProject, serializeProject } from "../core";
|
||||
import type { Project } from "../core";
|
||||
import { makeTmpDir } from "../test/tmpDir";
|
||||
|
||||
const dir = mkdtempSync(join(tmpdir(), "dossier-import-mesh-"));
|
||||
const dir = makeTmpDir("dossier-import-mesh-");
|
||||
const p = (name: string) => join(dir, name);
|
||||
const obp = p("demo.obp");
|
||||
|
||||
|
||||
+21
-1
@@ -72,7 +72,7 @@
|
||||
//
|
||||
// WASM-Pakete (src/engine/pkg*) werden aus DOSSIER_WASM_DIR bzw. `<repo>/src/engine` gelesen.
|
||||
|
||||
import { existsSync, mkdirSync, mkdtempSync, readFileSync, statSync, writeFileSync } from "node:fs";
|
||||
import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, statSync, writeFileSync } from "node:fs";
|
||||
import { spawn } from "node:child_process";
|
||||
import { deflateSync, inflateSync } from "node:zlib";
|
||||
import { tmpdir } from "node:os";
|
||||
@@ -799,10 +799,29 @@ function localTextureLoader(): TextureLoader {
|
||||
};
|
||||
}
|
||||
|
||||
/** [273] Sicherheitsnetz: Arbeitsordner auch bei Ctrl-C/SIGTERM und `process.exit` löschen (Normalfall: `cleanup` des Ablaufs). */
|
||||
const exitDirs = new Set<string>();
|
||||
let exitHooked = false;
|
||||
function removeOnExit(dir: string): void {
|
||||
if (!exitHooked) {
|
||||
exitHooked = true;
|
||||
process.on("exit", () => {
|
||||
for (const d of exitDirs) rmSync(d, { recursive: true, force: true });
|
||||
});
|
||||
for (const sig of ["SIGINT", "SIGTERM"] as const) process.once(sig, () => process.exit(sig === "SIGINT" ? 130 : 143));
|
||||
}
|
||||
exitDirs.add(dir);
|
||||
}
|
||||
|
||||
/** [211] Blender als Kindprozess (Node): Programmdatei suchen, Arbeitsordner im Temp-Ordner, Ausgabe zeilenweise. */
|
||||
function nodeBlenderHost(keep: boolean): BlenderHost {
|
||||
let dir = "";
|
||||
return {
|
||||
// [273] Ordner nach dem Lauf löschen (auch bei Fehler, Ablauf in blenderRender.ts); `--keep` behält ihn.
|
||||
async cleanup(d) {
|
||||
if (!keep) rmSync(d, { recursive: true, force: true });
|
||||
exitDirs.delete(d);
|
||||
},
|
||||
async find(custom) {
|
||||
const c = custom?.trim();
|
||||
if (c) {
|
||||
@@ -817,6 +836,7 @@ function nodeBlenderHost(keep: boolean): BlenderHost {
|
||||
},
|
||||
async prepare(files) {
|
||||
dir = mkdtempSync(join(tmpdir(), "dossier-render-"));
|
||||
if (!keep) removeOnExit(dir);
|
||||
for (const f of files) {
|
||||
const target = join(dir, f.path);
|
||||
mkdirSync(dirname(target), { recursive: true });
|
||||
|
||||
@@ -2,16 +2,16 @@
|
||||
// Kommandozeile prüft, Cycles-Zeilen ausgibt und ein PNG neben scene.json schreibt. Ein echter Blender-Lauf
|
||||
// steht nicht in der Testsuite (Beschreibung in TODO.md [211]).
|
||||
import { describe, expect, it, beforeAll, vi } from "vitest";
|
||||
import { chmodSync, existsSync, mkdtempSync, readFileSync, writeFileSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { chmodSync, existsSync, readFileSync, writeFileSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import { spawnSync } from "node:child_process";
|
||||
import { run } from "./main";
|
||||
import { serializeProject } from "../core";
|
||||
import { sampleProject } from "../model/sampleProject";
|
||||
import { makeExr } from "../export/cyclesExr.testutil";
|
||||
import { makeTmpDir } from "../test/tmpDir";
|
||||
|
||||
const dir = mkdtempSync(join(tmpdir(), "dossier-cli-render-"));
|
||||
const dir = makeTmpDir("dossier-cli-render-");
|
||||
const file = join(dir, "demo.obp");
|
||||
const fake = join(dir, "blender-fake");
|
||||
const fakeBlend = join(dir, "blender-fake-blend");
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
// [273] Arbeitsordner von `render`/`blend` (Blender und Cycles): nach Erfolg UND Fehler weg, ausser bei `--keep`.
|
||||
// Eigener TMPDIR je Test, damit nachgezählt werden kann, was die CLI liegen lässt (Ersatzprogramme wie in render.test.ts).
|
||||
import { afterEach, beforeAll, describe, expect, it, vi } from "vitest";
|
||||
import { chmodSync, readdirSync, rmSync, writeFileSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import { run } from "./main";
|
||||
import { serializeProject } from "../core";
|
||||
import { sampleProject } from "../model/sampleProject";
|
||||
import { makeExr } from "../export/cyclesExr.testutil";
|
||||
import { makeTmpDir } from "../test/tmpDir";
|
||||
|
||||
const dir = makeTmpDir("dossier-cli-cleanup-");
|
||||
const file = join(dir, "demo.obp");
|
||||
const okBlender = join(dir, "blender-ok");
|
||||
const failBlender = join(dir, "blender-fail");
|
||||
const okCycles = join(dir, "cycles-ok");
|
||||
const failCycles = join(dir, "cycles-fail");
|
||||
const realTmp = process.env.TMPDIR;
|
||||
|
||||
beforeAll(() => {
|
||||
process.env.DOSSIER_WASM_DIR = join(process.cwd(), "src", "engine");
|
||||
writeFileSync(file, serializeProject(sampleProject));
|
||||
const exr = join(dir, "fake.exr");
|
||||
writeFileSync(exr, makeExr(8, 4, new Float32Array(8 * 4 * 3).fill(0.4), true));
|
||||
const script = (name: string, body: string) => {
|
||||
writeFileSync(name, `#!/bin/sh\n${body}\n`);
|
||||
chmodSync(name, 0o755);
|
||||
};
|
||||
script(okBlender, `for a in "$@"; do scene="$a"; done\nprintf '\\211PNG\\r\\n\\032\\n' > "$(dirname "$scene")/render.png"\nprintf 'BLENDER-v405' > "$(dirname "$scene")/dossier.blend"\necho "DOSSIER_DONE x"`);
|
||||
script(failBlender, `echo "DOSSIER_ERROR kaputt"\nexit 1`);
|
||||
script(okCycles, `for a in "$@"; do [ "$p" = "--output" ] && out="$a"; p="$a"; done\ncp "${exr}" "$out"`);
|
||||
script(failCycles, `echo "boom"\nexit 2`);
|
||||
});
|
||||
|
||||
/** Läuft in eigenem leeren TMPDIR und gibt zurück, was dort nach dem Lauf liegt. */
|
||||
async function leftover(argv: string[]): Promise<{ code: number; left: string[] }> {
|
||||
const t = makeTmpDir("dossier-cli-tmp-");
|
||||
process.env.TMPDIR = t;
|
||||
const err = vi.spyOn(process.stderr, "write").mockImplementation(() => true);
|
||||
try {
|
||||
const code = await run(argv);
|
||||
return { code, left: readdirSync(t) };
|
||||
} finally {
|
||||
err.mockRestore();
|
||||
process.env.TMPDIR = realTmp;
|
||||
rmSync(t, { recursive: true, force: true });
|
||||
}
|
||||
}
|
||||
|
||||
afterEach(() => {
|
||||
process.env.TMPDIR = realTmp;
|
||||
});
|
||||
|
||||
const small = ["--samples", "8", "--size", "8x4", "--cpu"];
|
||||
|
||||
describe("[273] CLI räumt Arbeitsordner auf", () => {
|
||||
it("render (Blender) Erfolg: kein Ordner übrig", async () => {
|
||||
const r = await leftover([file, "render", "--out", join(dir, "a.png"), ...small, "--blender", okBlender]);
|
||||
expect(r.code).toBe(0);
|
||||
expect(r.left).toEqual([]);
|
||||
}, 60_000);
|
||||
|
||||
it("render (Blender) Fehler: kein Ordner übrig", async () => {
|
||||
const r = await leftover([file, "render", "--out", join(dir, "b.png"), ...small, "--blender", failBlender]);
|
||||
expect(r.code).toBe(1);
|
||||
expect(r.left).toEqual([]);
|
||||
}, 60_000);
|
||||
|
||||
it("blend Erfolg und Fehler: kein Ordner übrig", async () => {
|
||||
expect((await leftover([file, "blend", "--out", join(dir, "c.blend"), ...small, "--blender", okBlender])).left).toEqual([]);
|
||||
const f = await leftover([file, "blend", "--out", join(dir, "d.blend"), ...small, "--blender", failBlender]);
|
||||
expect(f.code).toBe(1);
|
||||
expect(f.left).toEqual([]);
|
||||
}, 60_000);
|
||||
|
||||
it("render --engine cycles Erfolg und Fehler: kein Ordner übrig", async () => {
|
||||
const ok = await leftover([":musterhaus-komplex", "render", "--engine", "cycles", "--cycles", okCycles, "--out", join(dir, "e.png"), ...small]);
|
||||
expect(ok.code).toBe(0);
|
||||
expect(ok.left).toEqual([]);
|
||||
const bad = await leftover([":musterhaus-komplex", "render", "--engine", "cycles", "--cycles", failCycles, "--out", join(dir, "f.png"), ...small]);
|
||||
expect(bad.code).toBe(1);
|
||||
expect(bad.left).toEqual([]);
|
||||
}, 120_000);
|
||||
|
||||
it("--keep behält den Arbeitsordner", async () => {
|
||||
const r = await leftover([file, "render", "--out", join(dir, "g.png"), ...small, "--blender", okBlender, "--keep"]);
|
||||
expect(r.code).toBe(0);
|
||||
expect(r.left).toHaveLength(1);
|
||||
expect(r.left[0]).toMatch(/^dossier-render-/);
|
||||
}, 60_000);
|
||||
});
|
||||
@@ -526,6 +526,8 @@ export interface BlenderHost {
|
||||
launch(exe: string, args: string[]): Promise<void>;
|
||||
/** Pfad zu `dir/rel`. */
|
||||
join(dir: string, rel: string): string;
|
||||
/** [273] Arbeitsordner samt Inhalt löschen (nach Erfolg und Fehler; bei `--keep` und für „In Blender öffnen" nicht aufgerufen). */
|
||||
cleanup?(dir: string): Promise<void>;
|
||||
}
|
||||
|
||||
export class BlenderMissingError extends Error {
|
||||
@@ -561,10 +563,22 @@ export interface RenderResult {
|
||||
}
|
||||
|
||||
/** Gemeinsamer Ablauf: Paket auspacken, Blender im Hintergrund laufen lassen, Fortschritt melden, Ergebnisdatei lesen. */
|
||||
async function runJob(host: BlenderHost, pkg: RenderPackage, opts: RenderRunOptions, outputRel: string, missingText: string): Promise<{ exe: string; bytes: Uint8Array; dir: string; path: string }> {
|
||||
async function runJob(host: BlenderHost, pkg: RenderPackage, opts: RenderRunOptions, outputRel: string, missingText: string, keepDir = false): Promise<{ exe: string; bytes: Uint8Array; dir: string; path: string }> {
|
||||
const exe = await host.find(opts.blenderPath);
|
||||
if (!exe) throw new BlenderMissingError();
|
||||
const dir = await host.prepare([...pkg.files, { path: "render_dossier.py", bytes: new TextEncoder().encode(opts.script) }]);
|
||||
let ok = false;
|
||||
try {
|
||||
const r = await runIn(host, dir, exe, pkg, opts, outputRel, missingText);
|
||||
ok = true;
|
||||
return r;
|
||||
} finally {
|
||||
// [273] Arbeitsordner immer löschen (Erfolg, Fehler, Abbruch); nur „In Blender öffnen" braucht ihn danach noch.
|
||||
if (!(ok && keepDir)) await host.cleanup?.(dir).catch(() => undefined);
|
||||
}
|
||||
}
|
||||
|
||||
async function runIn(host: BlenderHost, dir: string, exe: string, pkg: RenderPackage, opts: RenderRunOptions, outputRel: string, missingText: string): Promise<{ exe: string; bytes: Uint8Array; dir: string; path: string }> {
|
||||
const scenePath = host.join(dir, "scene.json");
|
||||
let stage = "import";
|
||||
let error = "";
|
||||
@@ -645,7 +659,7 @@ export async function runBlenderSave(host: BlenderHost, pkg: RenderPackage, opts
|
||||
* speichert sie dort über „Speichern unter".
|
||||
*/
|
||||
export async function runBlenderOpen(host: BlenderHost, pkg: RenderPackage, opts: RenderRunOptions): Promise<{ dir: string; path: string }> {
|
||||
const r = await runJob(host, pkg, opts, requireSave(pkg), "Blender hat keine .blend-Datei geschrieben");
|
||||
const r = await runJob(host, pkg, opts, requireSave(pkg), "Blender hat keine .blend-Datei geschrieben", true);
|
||||
await host.launch(r.exe, blendOpenArgs(r.path));
|
||||
return { dir: r.dir, path: r.path };
|
||||
}
|
||||
|
||||
@@ -128,6 +128,8 @@ export interface CyclesHost {
|
||||
spawn(exe: string, args: string[], onLine: (line: string) => void): { done: Promise<number>; cancel(): void };
|
||||
readFile(path: string): Promise<Uint8Array>;
|
||||
join(dir: string, rel: string): string;
|
||||
/** [273] Arbeitsordner samt Inhalt löschen (nach Erfolg und Fehler; bei `--keep` nicht aufgerufen). */
|
||||
cleanup?(dir: string): Promise<void>;
|
||||
}
|
||||
|
||||
export class CyclesMissingError extends Error {
|
||||
@@ -192,6 +194,15 @@ export async function runCyclesRender(host: CyclesHost, pkg: CyclesPackage, opts
|
||||
const exe = await host.find(opts.cyclesPath);
|
||||
if (!exe) throw new CyclesMissingError();
|
||||
const dir = await host.prepare(pkg.files);
|
||||
try {
|
||||
return await runCyclesIn(host, dir, exe, pkg, opts);
|
||||
} finally {
|
||||
// [273] Arbeitsordner immer löschen (Erfolg, Fehler, Abbruch).
|
||||
await host.cleanup?.(dir).catch(() => undefined);
|
||||
}
|
||||
}
|
||||
|
||||
async function runCyclesIn(host: CyclesHost, dir: string, exe: string, pkg: CyclesPackage, opts: CyclesRunOptions): Promise<CyclesResult> {
|
||||
const out = host.join(dir, "render.exr");
|
||||
const total = pkg.info.samples;
|
||||
const messages: string[] = [];
|
||||
|
||||
@@ -6,8 +6,7 @@
|
||||
import "../engine/fileioWasm.setup";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { spawnSync } from "node:child_process";
|
||||
import { mkdtempSync, writeFileSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { writeFileSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import { buildPlanDwg, buildPlanDxf, buildPlanDxfBinary, collectPlanDrawing } from "./exportDxf";
|
||||
import { countByType, libreDwgReader, readDxf } from "./cadReadBack.testutil";
|
||||
@@ -16,6 +15,7 @@ import { sampleProject } from "../model/sampleProject";
|
||||
import { generatePlan } from "../plan/generatePlan";
|
||||
import { flattenCategories } from "../model/types";
|
||||
import type { Drawing2D, Project } from "../model/types";
|
||||
import { makeTmpDir } from "../test/tmpDir";
|
||||
|
||||
const hasEzdxf = spawnSync("python3", ["-c", "import ezdxf"]).status === 0;
|
||||
const allCodes = (p: Project) => new Set(flattenCategories(p.layers).map((l) => l.code));
|
||||
@@ -62,7 +62,7 @@ interface Ez {
|
||||
}
|
||||
|
||||
function ezdxf(name: string, data: string | Uint8Array): { status: number | null; r: Ez; err: string } {
|
||||
const dir = mkdtempSync(join(tmpdir(), "dossier-cad-"));
|
||||
const dir = makeTmpDir("dossier-cad-");
|
||||
const file = join(dir, `${name}.dxf`);
|
||||
writeFileSync(file, data);
|
||||
const p = spawnSync("python3", ["scripts/validate-dxf.py", file], { encoding: "utf8", timeout: 60_000 });
|
||||
|
||||
@@ -6,8 +6,7 @@
|
||||
import "../engine/fileioWasm.setup";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { spawnSync } from "node:child_process";
|
||||
import { mkdtempSync, writeFileSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { writeFileSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import { buildPlanDxf, buildPlanDxfBinary } from "./exportDxf";
|
||||
import { sampleProject } from "../model/sampleProject";
|
||||
@@ -16,6 +15,7 @@ import type { Plan } from "../plan/generatePlan";
|
||||
import { flattenCategories } from "../model/types";
|
||||
import type { Project } from "../model/types";
|
||||
import { projectToWorldCoords } from "../model/geoRebase";
|
||||
import { makeTmpDir } from "../test/tmpDir";
|
||||
|
||||
const hasEzdxf = spawnSync("python3", ["-c", "import ezdxf"]).status === 0;
|
||||
|
||||
@@ -51,7 +51,7 @@ interface EzResult {
|
||||
}
|
||||
|
||||
function ezdxfRead(name: string, dxf: string | Uint8Array): { status: number | null; result: EzResult | null; err: string } {
|
||||
const dir = mkdtempSync(join(tmpdir(), "dossier-dxf-"));
|
||||
const dir = makeTmpDir("dossier-dxf-");
|
||||
const file = join(dir, `${name}.dxf`);
|
||||
writeFileSync(file, dxf);
|
||||
const r = spawnSync("python3", ["scripts/validate-dxf.py", file], { encoding: "utf8", timeout: 60_000 });
|
||||
|
||||
@@ -5,14 +5,14 @@
|
||||
import "../engine/fileioWasm.setup";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { spawnSync } from "node:child_process";
|
||||
import { mkdtempSync, writeFileSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { writeFileSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import { buildPlanDxf, buildPlanDxfBinary } from "./exportDxf";
|
||||
import { sampleProject } from "../model/sampleProject";
|
||||
import { generatePlan } from "../plan/generatePlan";
|
||||
import { flattenCategories } from "../model/types";
|
||||
import type { Project } from "../model/types";
|
||||
import { makeTmpDir } from "../test/tmpDir";
|
||||
|
||||
const hasEzdxf = spawnSync("python3", ["-c", "import ezdxf"]).status === 0;
|
||||
|
||||
@@ -32,7 +32,7 @@ interface Res {
|
||||
}
|
||||
|
||||
function ezdxf(name: string, bytes: string | Uint8Array): Res {
|
||||
const dir = mkdtempSync(join(tmpdir(), "dossier-dxf-"));
|
||||
const dir = makeTmpDir("dossier-dxf-");
|
||||
const file = join(dir, `${name}.dxf`);
|
||||
writeFileSync(file, bytes);
|
||||
const r = spawnSync("python3", ["scripts/validate-dxf.py", file], { encoding: "utf8", timeout: 60_000, maxBuffer: 256 * 1024 * 1024 });
|
||||
|
||||
@@ -5,8 +5,7 @@
|
||||
import "../engine/fileioWasm.setup";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { spawnSync } from "node:child_process";
|
||||
import { mkdtempSync, writeFileSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { writeFileSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import { buildPlanDwg, buildPlanDxf } from "./exportDxf";
|
||||
import { countByType, readDxf } from "./cadReadBack.testutil";
|
||||
@@ -14,6 +13,7 @@ import { parseDxf } from "../io/dxfParser";
|
||||
import { buildComplexSampleProject } from "../model/sampleProjectComplex";
|
||||
import { collectVisibleCodes } from "../model/types";
|
||||
import { viewportLevelPlan } from "../plan/viewportPlan";
|
||||
import { makeTmpDir } from "../test/tmpDir";
|
||||
|
||||
const hasEzdxf = spawnSync("python3", ["-c", "import ezdxf"]).status === 0;
|
||||
const p = buildComplexSampleProject();
|
||||
@@ -42,7 +42,7 @@ describe.each([
|
||||
|
||||
it.skipIf(!hasEzdxf)(`${label}: ezdxf liest ohne Auditor-Fehler`, async () => {
|
||||
const plan = await viewportLevelPlan(p, levelId, codes, "mittel", 100, true, false);
|
||||
const dir = mkdtempSync(join(tmpdir(), "dossier-dxf-"));
|
||||
const dir = makeTmpDir("dossier-dxf-");
|
||||
const file = join(dir, `${levelId}.dxf`);
|
||||
writeFileSync(file, buildPlanDxf(plan, p, { scaleDenominator: 100, levelId }));
|
||||
const r = spawnSync("python3", ["scripts/validate-dxf.py", file], { encoding: "utf8", timeout: 60_000, maxBuffer: 256 * 1024 * 1024 });
|
||||
|
||||
@@ -3,14 +3,14 @@
|
||||
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { spawnSync } from "node:child_process";
|
||||
import { mkdtempSync, writeFileSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { writeFileSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import "../engine/fileioWasm.setup";
|
||||
import { exportIfcSpf } from "./exportIfc";
|
||||
import { importIfcInto, inspectIfc } from "../io/importView.testutil";
|
||||
import { sampleProject } from "../model/sampleProject";
|
||||
import type { Project, Room } from "../model/types";
|
||||
import { makeTmpDir } from "../test/tmpDir";
|
||||
|
||||
const hasIfcOpenShell = spawnSync("python3", ["-c", "import ifcopenshell, ifcopenshell.util.classification, ifcopenshell.validate, _pytest"]).status === 0;
|
||||
|
||||
@@ -151,7 +151,7 @@ for s in m.by_type("IfcBuildingStorey"):
|
||||
print(json.dumps(out))
|
||||
`;
|
||||
const run = (name: string, ifc: string) => {
|
||||
const dir = mkdtempSync(join(tmpdir(), "dossier-ifc-cls-"));
|
||||
const dir = makeTmpDir("dossier-ifc-cls-");
|
||||
const file = join(dir, `${name}.ifc`);
|
||||
writeFileSync(file, ifc);
|
||||
const r = spawnSync("python3", ["-c", PY, file], { encoding: "utf8", timeout: 120_000 });
|
||||
|
||||
@@ -7,8 +7,7 @@
|
||||
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { spawnSync } from "node:child_process";
|
||||
import { mkdtempSync, writeFileSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { writeFileSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import "../engine/fileioWasm.setup";
|
||||
import { exportIfcSpf, type IfcExportOptions } from "./exportIfc";
|
||||
@@ -17,11 +16,12 @@ import { buildComplexSampleProject } from "../model/sampleProjectComplex";
|
||||
import { buildWettbewerbSampleProject } from "../model/sampleProjectWettbewerb";
|
||||
import type { Drawing2D, Project } from "../model/types";
|
||||
import { roomBook } from "./roomBook";
|
||||
import { makeTmpDir } from "../test/tmpDir";
|
||||
|
||||
const hasIfcOpenShell = spawnSync("python3", ["-c", "import ifcopenshell, ifcopenshell.validate, ifcopenshell.util.shape, _pytest"]).status === 0;
|
||||
|
||||
function writeIfc(name: string, ifc: string): string {
|
||||
const file = join(mkdtempSync(join(tmpdir(), "dossier-ifc-fp-")), `${name}.ifc`);
|
||||
const file = join(makeTmpDir("dossier-ifc-fp-"), `${name}.ifc`);
|
||||
writeFileSync(file, ifc);
|
||||
return file;
|
||||
}
|
||||
|
||||
@@ -2,13 +2,13 @@
|
||||
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { spawnSync } from "node:child_process";
|
||||
import { mkdtempSync, writeFileSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { writeFileSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import "../engine/fileioWasm.setup";
|
||||
import { exportIfcSpf } from "./exportIfc";
|
||||
import { sampleProject } from "../model/sampleProject";
|
||||
import type { Drawing2D, Project } from "../model/types";
|
||||
import { makeTmpDir } from "../test/tmpDir";
|
||||
|
||||
const hasIfcOpenShell = spawnSync("python3", ["-c", "import ifcopenshell, ifcopenshell.validate, _pytest"]).status === 0;
|
||||
|
||||
@@ -51,7 +51,7 @@ describe("IfcGrid im Export [112]", () => {
|
||||
|
||||
it.skipIf(!hasIfcOpenShell)("ifcopenshell: gültig, Achsen lesbar (rechtwinklig und radial)", () => {
|
||||
for (const [name, p] of [["ortho", gridProject()], ["radial", gridProject(true)]] as const) {
|
||||
const dir = mkdtempSync(join(tmpdir(), "dossier-ifc-grid-"));
|
||||
const dir = makeTmpDir("dossier-ifc-grid-");
|
||||
const file = join(dir, `${name}.ifc`);
|
||||
writeFileSync(file, exportIfcSpf(p));
|
||||
const r = spawnSync("python3", ["scripts/validate-ifc.py", file], { encoding: "utf8", timeout: 120_000 });
|
||||
|
||||
@@ -8,14 +8,14 @@
|
||||
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { spawnSync } from "node:child_process";
|
||||
import { mkdtempSync, writeFileSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { writeFileSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import "../engine/fileioWasm.setup";
|
||||
import { exportIfcSpf } from "./exportIfc";
|
||||
import { importIfcInto, inspectIfc } from "../io/importView.testutil";
|
||||
import { emptyProject, sampleProject } from "../model/sampleProject";
|
||||
import type { Project } from "../model/types";
|
||||
import { makeTmpDir } from "../test/tmpDir";
|
||||
|
||||
const hasIfcOpenShell = spawnSync("python3", ["-c", "import ifcopenshell, ifcopenshell.validate, _pytest"]).status === 0;
|
||||
const bytesOf = (s: string) => new TextEncoder().encode(s);
|
||||
@@ -181,7 +181,7 @@ describe("IFC2x3-Export: eigener Import liest dasselbe wie bei IFC4", () => {
|
||||
// ── ifcopenshell ────────────────────────────────────────────────────────────
|
||||
|
||||
function writeIfc(name: string, ifc: string): string {
|
||||
const dir = mkdtempSync(join(tmpdir(), "dossier-ifc2x3-"));
|
||||
const dir = makeTmpDir("dossier-ifc2x3-");
|
||||
const file = join(dir, `${name}.ifc`);
|
||||
writeFileSync(file, ifc);
|
||||
return file;
|
||||
|
||||
@@ -4,13 +4,13 @@
|
||||
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { spawnSync } from "node:child_process";
|
||||
import { mkdtempSync, writeFileSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { writeFileSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import "../engine/fileioWasm.setup";
|
||||
import { exportIfcSpf } from "./exportIfc";
|
||||
import { sampleProject } from "../model/sampleProject";
|
||||
import type { Column, Project, Stair } from "../model/types";
|
||||
import { makeTmpDir } from "../test/tmpDir";
|
||||
|
||||
const hasIfcOpenShell = spawnSync("python3", ["-c", "import ifcopenshell, ifcopenshell.validate, numpy"]).status === 0;
|
||||
|
||||
@@ -31,7 +31,7 @@ function project(): Project {
|
||||
}
|
||||
|
||||
function writeIfc(name: string, ifc: string): string {
|
||||
const dir = mkdtempSync(join(tmpdir(), "dossier-qto-"));
|
||||
const dir = makeTmpDir("dossier-qto-");
|
||||
const file = join(dir, `${name}.ifc`);
|
||||
writeFileSync(file, ifc);
|
||||
return file;
|
||||
|
||||
@@ -4,8 +4,7 @@
|
||||
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { spawnSync } from "node:child_process";
|
||||
import { mkdtempSync, writeFileSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { writeFileSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import "../engine/fileioWasm.setup";
|
||||
import { exportIfcSpf, ifcGuid } from "./exportIfc";
|
||||
@@ -13,11 +12,12 @@ import { wallMeshVolumes } from "./meshScene.testutil";
|
||||
import { emptyProject, sampleProject } from "../model/sampleProject";
|
||||
import { buildComplexSampleProject } from "../model/sampleProjectComplex";
|
||||
import type { Project } from "../model/types";
|
||||
import { makeTmpDir } from "../test/tmpDir";
|
||||
|
||||
const hasIfcOpenShell = spawnSync("python3", ["-c", "import ifcopenshell, ifcopenshell.validate, _pytest"]).status === 0;
|
||||
|
||||
function writeIfc(name: string, ifc: string): string {
|
||||
const dir = mkdtempSync(join(tmpdir(), "dossier-ifc-"));
|
||||
const dir = makeTmpDir("dossier-ifc-");
|
||||
const file = join(dir, `${name}.ifc`);
|
||||
writeFileSync(file, ifc);
|
||||
return file;
|
||||
|
||||
@@ -9,8 +9,7 @@
|
||||
import "../engine/fileioWasm.setup";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { spawnSync } from "node:child_process";
|
||||
import { existsSync, mkdtempSync, readdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { existsSync, readdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import { exportIfcSpf, ifcGuid } from "../export/exportIfc";
|
||||
import { sampleProject } from "../model/sampleProject";
|
||||
@@ -20,6 +19,7 @@ import { wallMeshVolumes } from "../export/meshScene.testutil";
|
||||
import { formatIfcReport, handleIfcWorkerRequest, type IfcWorkerRequest } from "./ifcImport";
|
||||
import { importIfcInto, inspectIfc, type IfcProductView as IfcProduct } from "./importView.testutil";
|
||||
import type { Project } from "../model/types";
|
||||
import { makeTmpDir } from "../test/tmpDir";
|
||||
|
||||
function volume(pos: ArrayLike<number>, idx: ArrayLike<number>): number {
|
||||
let v = 0;
|
||||
@@ -298,7 +298,7 @@ async function compare(file: string, rel: (p: IfcProduct) => number): Promise<st
|
||||
|
||||
describe.skipIf(!hasIfcOpenShell)("IFC-Import gegen ifcopenshell", { timeout: 120_000 }, () => {
|
||||
it("Demo-Haus: gleiche Bauteile, gleiches Volumen je Bauteil", async () => {
|
||||
const dir = mkdtempSync(join(tmpdir(), "dossier-ifcimp-"));
|
||||
const dir = makeTmpDir("dossier-ifcimp-");
|
||||
const file = join(dir, "demo-haus.ifc");
|
||||
writeFileSync(file, exportIfcSpf(sampleProject));
|
||||
const problems = await compare(file, () => 1e-6);
|
||||
@@ -310,7 +310,7 @@ describe.skipIf(!hasIfcOpenShell)("IFC-Import gegen ifcopenshell", { timeout: 12
|
||||
id: "S2", type: "column" as const, floorId: "eg", categoryCode: "50", position: { x: 1, y: 1 },
|
||||
profile: { kind: "round" as const, radius: 0.15 }, rotation: 0, height: 2.5,
|
||||
};
|
||||
const dir = mkdtempSync(join(tmpdir(), "dossier-ifcimp-"));
|
||||
const dir = makeTmpDir("dossier-ifcimp-");
|
||||
const file = join(dir, "stuetze.ifc");
|
||||
writeFileSync(file, exportIfcSpf({ ...sampleProject, columns: [col] }));
|
||||
const problems = await compare(file, (p) => (p.ifcClass === "IfcColumn" ? 0.03 : 1e-6));
|
||||
|
||||
@@ -14,6 +14,8 @@ import type { BlenderHost } from "../core";
|
||||
export interface DossierBlenderApi {
|
||||
find: (custom?: string) => Promise<string | null>;
|
||||
prepare: (files: { path: string; bytes: Uint8Array }[]) => Promise<string>;
|
||||
/** [273] Arbeitsordner löschen. */
|
||||
cleanup: (dir: string) => Promise<void>;
|
||||
start: (jobId: string, exe: string, args: string[]) => Promise<void>;
|
||||
cancel: (jobId: string) => void;
|
||||
readFile: (path: string) => Promise<Uint8Array>;
|
||||
@@ -86,6 +88,7 @@ async function tauriHost(): Promise<BlenderHost> {
|
||||
return { done, cancel: () => void invoke("blender_cancel", { jobId }).catch(() => undefined) };
|
||||
},
|
||||
readFile: (path) => fs.readFile(path),
|
||||
cleanup: (dir) => fs.remove(dir, { recursive: true }),
|
||||
launch: (exe, args) => invoke<void>("blender_open", { exe, args }),
|
||||
join,
|
||||
};
|
||||
@@ -96,6 +99,7 @@ function electronHost(api: DossierBlenderApi): BlenderHost {
|
||||
return {
|
||||
find: (custom) => api.find(custom?.trim() || undefined),
|
||||
prepare: (files) => api.prepare(files),
|
||||
cleanup: (dir) => api.cleanup(dir),
|
||||
spawn(exe, args, onLine) {
|
||||
const jobId = newJobId();
|
||||
let resolveExit!: (code: number) => void;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
// [215] Cycles-Paket: Namensschema (Bau, Gitea-Release, App-Bau), Einbindung ins AppImage (extraResources) und in die Workflows.
|
||||
import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import { createRequire } from "node:module";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { makeTmpDir } from "../test/tmpDir";
|
||||
|
||||
const req = createRequire(import.meta.url);
|
||||
const root = join(__dirname, "..", "..");
|
||||
@@ -53,7 +53,7 @@ describe("AppImage: Cycles als extraResources", () => {
|
||||
expect(pack.packConfig("1").extraResources).toBeUndefined();
|
||||
});
|
||||
it("Ordnerwahl: --cycles, Umgebung, build/cycles; fehlendes Programm / Pflicht", () => {
|
||||
const d = mkdtempSync(join(tmpdir(), "dossier-cypack-"));
|
||||
const d = makeTmpDir("dossier-cypack-");
|
||||
try {
|
||||
expect(pack.resolveCyclesDir(d, [], {})).toBeNull();
|
||||
expect(() => pack.resolveCyclesDir(d, [], { DOSSIER_REQUIRE_CYCLES: "1" })).toThrow(/Cycles fehlt/);
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
// [273] Arbeitsordner der Blender-/Cycles-Brücke im Electron-Hauptprozess (scripts/electron-blender.cjs): Löschen eines
|
||||
// einzelnen Auftragsordners und Aufräumen alter Ordner beim Start (nur eigenes Präfix, nur ältere als die Frist).
|
||||
import { existsSync, mkdirSync, rmSync, utimesSync, writeFileSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { createRequire } from "node:module";
|
||||
import { afterAll, describe, expect, it } from "vitest";
|
||||
import { makeTmpDir } from "../test/tmpDir";
|
||||
|
||||
const bl = createRequire(import.meta.url)("../../scripts/electron-blender.cjs") as {
|
||||
prepareJobDir: (files: { path: string; bytes: Uint8Array }[]) => string;
|
||||
removeJobDir: (p: unknown) => void;
|
||||
sweepOldJobDirs: (root: string, maxAgeMs: number, now?: number) => number;
|
||||
insideRenderDir: (p: string) => boolean;
|
||||
};
|
||||
|
||||
// prepareJobDir legt die Wurzel `<TMPDIR>/dossier-render` an; sie gehört dem Test.
|
||||
afterAll(() => rmSync(join(tmpdir(), "dossier-render"), { recursive: true, force: true }));
|
||||
|
||||
const DAY = 24 * 3600 * 1000;
|
||||
|
||||
describe("removeJobDir", () => {
|
||||
it("löscht einen Arbeitsordner samt Inhalt, nie die Wurzel oder Fremdes", () => {
|
||||
const d = bl.prepareJobDir([{ path: "a/b.txt", bytes: new Uint8Array([1]) }]);
|
||||
expect(existsSync(join(d, "a", "b.txt"))).toBe(true);
|
||||
bl.removeJobDir(d);
|
||||
expect(existsSync(d)).toBe(false);
|
||||
bl.removeJobDir(d); // zweites Mal: kein Fehler
|
||||
for (const bad of [join(tmpdir(), "dossier-render"), tmpdir(), "/etc", "", 7, join(tmpdir(), "dossier-render", "..")]) expect(() => bl.removeJobDir(bad)).toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
describe("sweepOldJobDirs", () => {
|
||||
it("entfernt nur Ordner älter als die Frist, lässt neue und Fremdes stehen", () => {
|
||||
const root = makeTmpDir("dossier-sweep-");
|
||||
const now = Date.now();
|
||||
const old = join(root, "alt");
|
||||
const fresh = join(root, "neu");
|
||||
mkdirSync(old);
|
||||
mkdirSync(fresh);
|
||||
writeFileSync(join(old, "scene.json"), "{}");
|
||||
const past = new Date(now - 2 * DAY);
|
||||
utimesSync(old, past, past);
|
||||
expect(bl.sweepOldJobDirs(root, DAY, now)).toBe(1);
|
||||
expect(existsSync(old)).toBe(false);
|
||||
expect(existsSync(fresh)).toBe(true);
|
||||
});
|
||||
it("fehlende Wurzel: 0, kein Fehler", () => {
|
||||
expect(bl.sweepOldJobDirs(join(makeTmpDir("dossier-sweep-"), "nix"), DAY)).toBe(0);
|
||||
});
|
||||
});
|
||||
@@ -3,7 +3,7 @@ import { chmodSync, existsSync, mkdirSync, mkdtempSync, rmSync, writeFileSync }
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { createRequire } from "node:module";
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
import { afterAll, afterEach, describe, expect, it } from "vitest";
|
||||
|
||||
type Job = { jobId: string; line?: string; code?: number };
|
||||
const cy = createRequire(import.meta.url)("../../scripts/electron-cycles.cjs") as {
|
||||
@@ -21,6 +21,7 @@ const scene = () => {
|
||||
dirs.push(d);
|
||||
return d;
|
||||
};
|
||||
afterAll(() => rmSync(root, { recursive: true, force: true }));
|
||||
afterEach(() => {
|
||||
for (const d of dirs.splice(0)) rmSync(d, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
// Atomares Schreiben im Electron-Hauptprozess ([116], scripts/electron-files.cjs) — gleiche Garantien wie atomic_save.rs.
|
||||
|
||||
import { mkdtempSync, mkdirSync, readFileSync, existsSync, writeFileSync, rmSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { mkdirSync, readFileSync, existsSync, writeFileSync, rmSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import { createRequire } from "node:module";
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
import { makeTmpDir } from "../test/tmpDir";
|
||||
|
||||
const { writeAtomic, backupExists } = createRequire(import.meta.url)("../../scripts/electron-files.cjs") as {
|
||||
writeAtomic: (file: string, text: string, keepBackup: boolean) => void;
|
||||
@@ -13,7 +13,7 @@ const { writeAtomic, backupExists } = createRequire(import.meta.url)("../../scri
|
||||
|
||||
const dirs: string[] = [];
|
||||
const tmp = () => {
|
||||
const d = mkdtempSync(join(tmpdir(), "dossier-efiles-"));
|
||||
const d = makeTmpDir("dossier-efiles-");
|
||||
dirs.push(d);
|
||||
return d;
|
||||
};
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
// („Cannot find module './electron-files.cjs'“). Dazu: Buildnummer ([261]) aus dem gebauten `dist` ins Paket.
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { createRequire } from "node:module";
|
||||
import { readFileSync, mkdtempSync, writeFileSync, rmSync } from "node:fs";
|
||||
import { readFileSync, writeFileSync, rmSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import { tmpdir } from "node:os";
|
||||
import { makeTmpDir } from "../test/tmpDir";
|
||||
|
||||
const root = join(__dirname, "..", "..");
|
||||
const read = (rel: string) => readFileSync(join(root, rel), "utf8");
|
||||
@@ -64,7 +64,7 @@ describe("[170][261] Buildnummer im Linux-Paket", () => {
|
||||
expect(packConfig("261116.3", "1.0.0").extraMetadata).toEqual({ dossierBuild: "261116.3", version: "1.0.0" });
|
||||
});
|
||||
it("Buildnummer kommt aus dem gebauten dist (build-info.json), nicht neu berechnet", () => {
|
||||
const dir = mkdtempSync(join(tmpdir(), "dossier-dist-"));
|
||||
const dir = makeTmpDir("dossier-dist-");
|
||||
try {
|
||||
expect(readDistBuild(dir)).toBeNull();
|
||||
writeFileSync(join(dir, "build-info.json"), JSON.stringify({ version: "1.0.0-beta.1", build: "261116.2" }));
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
// [273] Temp-Ordner in Tests: immer wieder aufräumen. `makeTmpDir` legt einen Ordner an und löscht ihn nach der Testdatei
|
||||
// (afterAll), `withTmpDir` nach dem Aufruf (auch bei Fehler). Kein `mkdtempSync(join(tmpdir(), …))` mehr direkt in Tests.
|
||||
import { mkdtempSync, rmSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { afterAll } from "vitest";
|
||||
|
||||
const made: string[] = [];
|
||||
|
||||
function removeAll(): void {
|
||||
for (const d of made.splice(0)) rmSync(d, { recursive: true, force: true });
|
||||
}
|
||||
|
||||
// Beim Import (Sammelphase der Testdatei) eintragen: ein afterAll im laufenden Test würde nie ausgeführt.
|
||||
afterAll(removeAll);
|
||||
|
||||
/** Neuer Temp-Ordner mit Präfix; wird am Ende der Testdatei gelöscht. */
|
||||
export function makeTmpDir(prefix: string): string {
|
||||
const d = mkdtempSync(join(tmpdir(), prefix));
|
||||
made.push(d);
|
||||
return d;
|
||||
}
|
||||
|
||||
/** Temp-Ordner nur für `fn`; danach gelöscht (auch bei Fehler). */
|
||||
export async function withTmpDir<T>(prefix: string, fn: (dir: string) => T | Promise<T>): Promise<T> {
|
||||
const d = mkdtempSync(join(tmpdir(), prefix));
|
||||
try {
|
||||
return await fn(d);
|
||||
} finally {
|
||||
rmSync(d, { recursive: true, force: true });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
// [273] vitest-globalSetup: die Testläufe bekommen einen eigenen TMPDIR. Am Ende wird nachgezählt: was Tests dort liegen
|
||||
// lassen, wird gemeldet (Lauf schlägt fehl) und trotzdem gelöscht — so wächst /tmp nie.
|
||||
import { mkdtempSync, readdirSync, rmSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
|
||||
let root = "";
|
||||
let before: string | undefined;
|
||||
|
||||
export function setup(): void {
|
||||
before = process.env.TMPDIR;
|
||||
root = mkdtempSync(join(tmpdir(), "dossier-vitest-"));
|
||||
process.env.TMPDIR = root;
|
||||
}
|
||||
|
||||
export function teardown(): void {
|
||||
if (before === undefined) delete process.env.TMPDIR;
|
||||
else process.env.TMPDIR = before;
|
||||
let left: string[] = [];
|
||||
try {
|
||||
left = readdirSync(root);
|
||||
} catch {
|
||||
// schon weg
|
||||
}
|
||||
rmSync(root, { recursive: true, force: true });
|
||||
if (left.length > 0) {
|
||||
throw new Error(`[273] Tests haben ${left.length} Temp-Ordner/-Dateien liegen lassen (src/test/tmpDir.ts nutzen): ${left.slice(0, 20).join(", ")}`);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user