mirror of
https://github.com/nexu-io/open-design.git
synced 2026-10-27 09:51:12 +01:00
* refactor(ci): align tools-pack sources with scope boundaries * refactor(tools-pack): unify test source imports * fix(tools-pack): resolve workspace root from package Generated-By: looper 0.11.2 (runner=fixer, agent=codex) * test(tools-pack): exercise bundled CLI directly --------- Co-authored-by: Looper <looper@noreply.github.com>
238 lines
10 KiB
TypeScript
238 lines
10 KiB
TypeScript
import { afterEach, describe, expect, it } from "vitest";
|
|
import { join, resolve } from "node:path";
|
|
|
|
import { resolveToolPackConfig, WORKSPACE_ROOT } from "@/config/index.js";
|
|
|
|
const savedTelemetryRelayUrl = process.env.OPEN_DESIGN_TELEMETRY_RELAY_URL;
|
|
const savedPosthogKey = process.env.POSTHOG_KEY;
|
|
const savedPosthogHost = process.env.POSTHOG_HOST;
|
|
const savedAmrProfile = process.env.OPEN_DESIGN_AMR_PROFILE;
|
|
const savedVelaWebUrl = process.env.OD_VELA_WEB_URL;
|
|
const savedVelaWebUrlProd = process.env.OD_VELA_WEB_URL_PROD;
|
|
const savedVelaWebUrlTest = process.env.OD_VELA_WEB_URL_TEST;
|
|
const savedVelaWebUrlFeatureTest = process.env.OD_VELA_WEB_URL_FEATURE_TEST;
|
|
|
|
afterEach(() => {
|
|
if (savedVelaWebUrl == null) {
|
|
delete process.env.OD_VELA_WEB_URL;
|
|
} else {
|
|
process.env.OD_VELA_WEB_URL = savedVelaWebUrl;
|
|
}
|
|
if (savedVelaWebUrlProd == null) delete process.env.OD_VELA_WEB_URL_PROD;
|
|
else process.env.OD_VELA_WEB_URL_PROD = savedVelaWebUrlProd;
|
|
if (savedVelaWebUrlTest == null) delete process.env.OD_VELA_WEB_URL_TEST;
|
|
else process.env.OD_VELA_WEB_URL_TEST = savedVelaWebUrlTest;
|
|
if (savedVelaWebUrlFeatureTest == null) delete process.env.OD_VELA_WEB_URL_FEATURE_TEST;
|
|
else process.env.OD_VELA_WEB_URL_FEATURE_TEST = savedVelaWebUrlFeatureTest;
|
|
if (savedTelemetryRelayUrl == null) {
|
|
delete process.env.OPEN_DESIGN_TELEMETRY_RELAY_URL;
|
|
} else {
|
|
process.env.OPEN_DESIGN_TELEMETRY_RELAY_URL = savedTelemetryRelayUrl;
|
|
}
|
|
if (savedPosthogKey == null) {
|
|
delete process.env.POSTHOG_KEY;
|
|
} else {
|
|
process.env.POSTHOG_KEY = savedPosthogKey;
|
|
}
|
|
if (savedPosthogHost == null) {
|
|
delete process.env.POSTHOG_HOST;
|
|
} else {
|
|
process.env.POSTHOG_HOST = savedPosthogHost;
|
|
}
|
|
if (savedAmrProfile == null) {
|
|
delete process.env.OPEN_DESIGN_AMR_PROFILE;
|
|
} else {
|
|
process.env.OPEN_DESIGN_AMR_PROFILE = savedAmrProfile;
|
|
}
|
|
});
|
|
|
|
describe("resolveToolPackConfig AMR profile", () => {
|
|
it("bakes OPEN_DESIGN_AMR_PROFILE into packaged config when set at build time", () => {
|
|
process.env.OPEN_DESIGN_AMR_PROFILE = "feature-test";
|
|
const config = resolveToolPackConfig("mac", { namespace: "amr-profile-test" });
|
|
expect(config.amrProfile).toBe("feature-test");
|
|
});
|
|
|
|
it("rejects unsupported AMR profiles before packaging", () => {
|
|
process.env.OPEN_DESIGN_AMR_PROFILE = "staging";
|
|
expect(() => resolveToolPackConfig("mac")).toThrow(
|
|
/OPEN_DESIGN_AMR_PROFILE must be prod, test, feature-test, or local/,
|
|
);
|
|
});
|
|
});
|
|
|
|
describe("resolveToolPackConfig Vela CLI requirement", () => {
|
|
it("defaults to optional Vela CLI bundling", () => {
|
|
const config = resolveToolPackConfig("mac", { namespace: "vela-optional-test" });
|
|
expect(config.requireVelaCli).toBe(false);
|
|
});
|
|
|
|
it("reads --require-vela-cli from build options", () => {
|
|
const config = resolveToolPackConfig("mac", {
|
|
namespace: "vela-required-test",
|
|
requireVelaCli: true,
|
|
});
|
|
expect(config.requireVelaCli).toBe(true);
|
|
});
|
|
});
|
|
|
|
describe("resolveToolPackConfig win build target", () => {
|
|
it("accepts the portable zip target and rejects unsupported values", () => {
|
|
expect(resolveToolPackConfig("win", { to: "zip" }).to).toBe("zip");
|
|
expect(resolveToolPackConfig("win", { to: "all" }).to).toBe("all");
|
|
expect(resolveToolPackConfig("win", { to: "nsis" }).to).toBe("nsis");
|
|
expect(() => resolveToolPackConfig("win", { to: "dmg" })).toThrow(/unsupported win --to target: dmg/);
|
|
});
|
|
});
|
|
|
|
describe("resolveToolPackConfig cache root", () => {
|
|
it("keeps the default cache outside custom tools-pack roots", () => {
|
|
const config = resolveToolPackConfig("win", {
|
|
dir: "C:\\odqa-release-4ch",
|
|
namespace: "cache-root-test",
|
|
});
|
|
|
|
expect(config.roots.toolPackRoot).toBe(resolve("C:\\odqa-release-4ch"));
|
|
expect(config.roots.cacheRoot).toBe(resolve(join(WORKSPACE_ROOT, ".tmp", "tools-pack", "cache")));
|
|
});
|
|
|
|
it("uses an explicit cache-dir when supplied", () => {
|
|
const config = resolveToolPackConfig("win", {
|
|
cacheDir: "C:\\odqa-tools-pack-cache",
|
|
dir: "C:\\odqa-release-4ch",
|
|
namespace: "cache-root-test",
|
|
});
|
|
|
|
expect(config.roots.toolPackRoot).toBe(resolve("C:\\odqa-release-4ch"));
|
|
expect(config.roots.cacheRoot).toBe(resolve("C:\\odqa-tools-pack-cache"));
|
|
});
|
|
});
|
|
|
|
describe("resolveToolPackConfig namespace defaults", () => {
|
|
it("keeps ordinary local builds on the default namespace", () => {
|
|
expect(resolveToolPackConfig("mac").namespace).toBe("default");
|
|
expect(resolveToolPackConfig("win", { appVersion: "0.8.0" }).namespace).toBe("default");
|
|
});
|
|
|
|
it("defaults prerelease mac builds to their release channel namespace", () => {
|
|
expect(resolveToolPackConfig("mac", { appVersion: "0.8.0-beta.4" }).namespace).toBe("release-beta");
|
|
expect(resolveToolPackConfig("mac", { appVersion: "0.8.0-preview.4" }).namespace).toBe("release-preview");
|
|
expect(resolveToolPackConfig("mac", { appVersion: "0.8.0-prerelease.4" }).namespace).toBe("release-prerelease");
|
|
});
|
|
|
|
it("defaults prerelease non-mac builds to platform-specific release channel namespaces", () => {
|
|
expect(resolveToolPackConfig("win", { appVersion: "0.8.0-beta.4" }).namespace).toBe("release-beta-win");
|
|
expect(resolveToolPackConfig("linux", { appVersion: "0.8.0-preview.4" }).namespace).toBe("release-preview-linux");
|
|
expect(resolveToolPackConfig("win", { appVersion: "0.8.0-prerelease.4" }).namespace).toBe("release-prerelease-win");
|
|
});
|
|
|
|
it("keeps an explicit namespace ahead of the prerelease channel default", () => {
|
|
expect(resolveToolPackConfig("mac", { appVersion: "0.8.0-beta.4", namespace: "custom-beta" }).namespace).toBe(
|
|
"custom-beta",
|
|
);
|
|
});
|
|
});
|
|
|
|
describe("resolveToolPackConfig telemetry relay", () => {
|
|
it("reads and normalizes OPEN_DESIGN_TELEMETRY_RELAY_URL for packaged config", () => {
|
|
process.env.OPEN_DESIGN_TELEMETRY_RELAY_URL = "https://telemetry.open-design.ai/api/langfuse//";
|
|
const config = resolveToolPackConfig("mac", { namespace: "telemetry-test" });
|
|
expect(config.telemetryRelayUrl).toBe("https://telemetry.open-design.ai/api/langfuse");
|
|
});
|
|
|
|
it("rejects invalid telemetry relay URLs", () => {
|
|
process.env.OPEN_DESIGN_TELEMETRY_RELAY_URL = "not-a-url";
|
|
expect(() => resolveToolPackConfig("mac")).toThrow(
|
|
/OPEN_DESIGN_TELEMETRY_RELAY_URL must be an absolute https URL/,
|
|
);
|
|
});
|
|
|
|
it("rejects plaintext telemetry relay URLs for packaged config", () => {
|
|
process.env.OPEN_DESIGN_TELEMETRY_RELAY_URL = "http://telemetry.open-design.ai/api/langfuse";
|
|
expect(() => resolveToolPackConfig("mac")).toThrow(
|
|
/OPEN_DESIGN_TELEMETRY_RELAY_URL must use https/,
|
|
);
|
|
});
|
|
});
|
|
|
|
describe("resolveToolPackConfig PostHog analytics", () => {
|
|
it("bakes POSTHOG_KEY into packaged config when set at build time", () => {
|
|
process.env.POSTHOG_KEY = "phc_test_abc123";
|
|
process.env.POSTHOG_HOST = "https://us.i.posthog.com";
|
|
const config = resolveToolPackConfig("mac", { namespace: "analytics-test" });
|
|
expect(config.posthogKey).toBe("phc_test_abc123");
|
|
expect(config.posthogHost).toBe("https://us.i.posthog.com");
|
|
});
|
|
|
|
it("omits POSTHOG_KEY for fork builds that lack the secret", () => {
|
|
delete process.env.POSTHOG_KEY;
|
|
delete process.env.POSTHOG_HOST;
|
|
const config = resolveToolPackConfig("mac", { namespace: "analytics-test" });
|
|
expect(config.posthogKey).toBeUndefined();
|
|
expect(config.posthogHost).toBeUndefined();
|
|
});
|
|
|
|
it("rejects POSTHOG_KEY values that contain whitespace", () => {
|
|
process.env.POSTHOG_KEY = "phc_test abc";
|
|
expect(() => resolveToolPackConfig("mac")).toThrow(
|
|
/POSTHOG_KEY contains whitespace/,
|
|
);
|
|
});
|
|
|
|
it("rejects invalid POSTHOG_HOST URLs", () => {
|
|
process.env.POSTHOG_KEY = "phc_test_abc";
|
|
process.env.POSTHOG_HOST = "not-a-url";
|
|
expect(() => resolveToolPackConfig("mac")).toThrow(/POSTHOG_HOST must be an absolute URL/);
|
|
});
|
|
|
|
it("strips trailing slashes from POSTHOG_HOST", () => {
|
|
process.env.POSTHOG_KEY = "phc_test_abc";
|
|
process.env.POSTHOG_HOST = "https://eu.i.posthog.com///";
|
|
const config = resolveToolPackConfig("mac");
|
|
expect(config.posthogHost).toBe("https://eu.i.posthog.com");
|
|
});
|
|
});
|
|
|
|
// The vela web origin of an internal (non-public) environment must never be a
|
|
// literal in this public repository. It is injected at packaging time from a CI
|
|
// secret keyed by AMR profile, exactly like POSTHOG_KEY, and flows on into
|
|
// open-design-config.json -> the packaged daemon spawn env (OD_VELA_WEB_URL).
|
|
describe("resolveToolPackConfig vela web origin", () => {
|
|
it("bakes every supplied profile origin for runtime environment switching", () => {
|
|
process.env.OD_VELA_WEB_URL_PROD = "https://prod.example.invalid";
|
|
process.env.OD_VELA_WEB_URL_TEST = "https://test.example.invalid/";
|
|
process.env.OD_VELA_WEB_URL_FEATURE_TEST = "https://feature.example.invalid";
|
|
const config = resolveToolPackConfig("mac", { namespace: "vela-web-test" });
|
|
expect(config.velaWebUrls).toEqual({
|
|
prod: "https://prod.example.invalid",
|
|
test: "https://test.example.invalid",
|
|
"feature-test": "https://feature.example.invalid",
|
|
});
|
|
});
|
|
|
|
it("bakes OD_VELA_WEB_URL into packaged config when set at build time", () => {
|
|
process.env.OD_VELA_WEB_URL = "https://vela.example.invalid";
|
|
const config = resolveToolPackConfig("mac", { namespace: "vela-web-test" });
|
|
expect(config.velaWebUrl).toBe("https://vela.example.invalid");
|
|
});
|
|
|
|
it("omits the vela web origin for builds without the secret", () => {
|
|
delete process.env.OD_VELA_WEB_URL;
|
|
const config = resolveToolPackConfig("mac", { namespace: "vela-web-test" });
|
|
expect(config.velaWebUrl).toBeUndefined();
|
|
});
|
|
|
|
it("strips trailing slashes so the daemon can append console paths", () => {
|
|
process.env.OD_VELA_WEB_URL = "https://vela.example.invalid///";
|
|
const config = resolveToolPackConfig("mac", { namespace: "vela-web-test" });
|
|
expect(config.velaWebUrl).toBe("https://vela.example.invalid");
|
|
});
|
|
|
|
it("rejects a vela web origin that is not an absolute http(s) URL", () => {
|
|
process.env.OD_VELA_WEB_URL = "vela.example.invalid";
|
|
expect(() => resolveToolPackConfig("mac")).toThrow(
|
|
/OD_VELA_WEB_URL must be an absolute URL/,
|
|
);
|
|
});
|
|
});
|