Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions cli/tests/architecture/throwaway-profile-wiring.arch.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { describe, expect, it } from "vitest";
import mutation from "../../vitest.mutation.config.js";
import workspace from "../../vitest.workspace.js";

const SETUP = "./tests/helpers/throwaway-profile.ts";
const RUNS_SOURCE = ["unit", "integration"];

function projectsRunningSource(
projects: readonly unknown[]
): { name: string; globalSetup: unknown }[] {
return projects.flatMap((project) => {
const test = (project as { test?: { name?: string; globalSetup?: unknown } }).test;
return test?.name && RUNS_SOURCE.includes(test.name)
? [{ name: test.name, globalSetup: test.globalSetup }]
: [];
});
}

describe("every project that runs the source sees a throwaway profile", () => {
it.each([
["the suite", projectsRunningSource(workspace)],
["a mutation run", projectsRunningSource(mutation.test?.projects ?? [])],
])(
"%s declares the throwaway-profile setup on its unit and integration projects",
(_run, projects) => {
expect(projects.map((p) => p.name).sort()).toStrictEqual(["integration", "unit"]);
for (const project of projects) expect(project.globalSetup, project.name).toContain(SETUP);
}
);
});
14 changes: 14 additions & 0 deletions cli/tests/helpers/throwaway-profile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { mkdtempSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";

/** Set in the main process before any worker exists: a worker thread's own env never reaches `os.homedir()`, so only this leaves a mutant no real profile to write. */
export function setup(): () => void {
const home = mkdtempSync(join(tmpdir(), "aidd-test-profile-"));
process.env.HOME = home;
process.env.USERPROFILE = home;
process.env.APPDATA = join(home, "AppData", "Roaming");
for (const key of ["AIDD_USER_CONFIG_DIR", "AIDD_TELEMETRY_DIR", "XDG_CONFIG_HOME"])
delete process.env[key];
return () => rmSync(home, { recursive: true, force: true });
}
18 changes: 18 additions & 0 deletions cli/tests/helpers/throwaway-profile.unit.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { homedir, tmpdir } from "node:os";
import { describe, expect, it } from "vitest";
import { resolveAiddConfigDir, resolveHomeDir } from "../../src/kernel/reading/home-dir.js";
import { userConfigDir } from "../../src/runtime/user-config-dir.js";

describe("the profile a test run sees", () => {
it("is a home under the temp directory, whichever route resolves it", () => {
for (const resolved of [homedir(), resolveHomeDir(), resolveAiddConfigDir(), userConfigDir()]) {
expect(resolved.startsWith(tmpdir()), resolved).toBe(true);
}
});

it("carries no override that points outside that home", () => {
for (const key of ["AIDD_USER_CONFIG_DIR", "AIDD_TELEMETRY_DIR", "XDG_CONFIG_HOME"]) {
expect(process.env[key], key).toBeUndefined();
}
});
});
2 changes: 2 additions & 0 deletions cli/vitest.mutation.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export default defineConfig({
include: ["tests/**/*.unit.test.ts"],
globals: false,
environment: "node",
globalSetup: ["./tests/helpers/throwaway-profile.ts"],
},
},
{
Expand All @@ -36,6 +37,7 @@ export default defineConfig({
include: ["tests/**/*.integration.test.ts"],
globals: false,
environment: "node",
globalSetup: ["./tests/helpers/throwaway-profile.ts"],
testTimeout: 60000,
},
},
Expand Down
10 changes: 8 additions & 2 deletions cli/vitest.workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ export default defineWorkspace([
include: ["tests/**/*.unit.test.ts"],
globals: false,
environment: "node",
globalSetup: ["./tests/helpers/sweep-stale-temp-dirs.ts"],
globalSetup: [
"./tests/helpers/sweep-stale-temp-dirs.ts",
"./tests/helpers/throwaway-profile.ts",
],
},
},
{
Expand All @@ -31,7 +34,10 @@ export default defineWorkspace([
globals: false,
environment: "node",
testTimeout: 60000,
globalSetup: ["./tests/helpers/sweep-stale-temp-dirs.ts"],
globalSetup: [
"./tests/helpers/sweep-stale-temp-dirs.ts",
"./tests/helpers/throwaway-profile.ts",
],
},
},
{
Expand Down