build(release): stage local macOS v0.1.0 distribution
This commit is contained in:
Vendored
+1
@@ -3,6 +3,7 @@
|
||||
interface ImportMetaEnv {
|
||||
readonly VITE_BUILD_CHANNEL?: "dev" | "main" | "release" | "local";
|
||||
readonly VITE_BUILD_COMMIT?: string;
|
||||
readonly VITE_DESKTOP_SERVER_URL?: string;
|
||||
}
|
||||
|
||||
interface ImportMeta {
|
||||
|
||||
@@ -2,6 +2,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import {
|
||||
DESKTOP_SERVER_URL_CHANGED_EVENT,
|
||||
DESKTOP_SERVER_URL_KEY,
|
||||
getDefaultDesktopServerUrl,
|
||||
getDesktopServerUrl,
|
||||
normalizeDesktopServerUrl,
|
||||
setDesktopServerUrl,
|
||||
@@ -31,6 +32,7 @@ const createMemoryStorage = (): Storage => {
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
vi.stubEnv("VITE_DESKTOP_SERVER_URL", "");
|
||||
Object.defineProperty(window, "localStorage", {
|
||||
value: createMemoryStorage(),
|
||||
configurable: true,
|
||||
@@ -40,6 +42,7 @@ beforeEach(() => {
|
||||
afterEach(() => {
|
||||
window.localStorage.clear();
|
||||
setTauriRuntime(false);
|
||||
vi.unstubAllEnvs();
|
||||
});
|
||||
|
||||
describe("desktop server config", () => {
|
||||
@@ -70,6 +73,23 @@ describe("desktop server config", () => {
|
||||
expect(listener).toHaveBeenCalledOnce();
|
||||
});
|
||||
|
||||
it("uses the build-time default while allowing a persisted manual override", () => {
|
||||
vi.stubEnv("VITE_DESKTOP_SERVER_URL", "https://default.ctms.example.com");
|
||||
|
||||
expect(getDefaultDesktopServerUrl()).toBe("https://default.ctms.example.com/");
|
||||
expect(getDesktopServerUrl()).toBe("https://default.ctms.example.com/");
|
||||
|
||||
setDesktopServerUrl("https://manual.ctms.example.com");
|
||||
expect(getDesktopServerUrl()).toBe("https://manual.ctms.example.com/");
|
||||
});
|
||||
|
||||
it("ignores an invalid build-time default", () => {
|
||||
vi.stubEnv("VITE_DESKTOP_SERVER_URL", "http://public.ctms.example.com");
|
||||
|
||||
expect(getDefaultDesktopServerUrl()).toBeNull();
|
||||
expect(getDesktopServerUrl()).toBeNull();
|
||||
});
|
||||
|
||||
it("requires a server URL only inside the Tauri runtime", () => {
|
||||
expect(shouldRequireDesktopServerUrl()).toBe(false);
|
||||
setTauriRuntime(true);
|
||||
@@ -77,4 +97,11 @@ describe("desktop server config", () => {
|
||||
setDesktopServerUrl("https://ctms.example.com");
|
||||
expect(shouldRequireDesktopServerUrl()).toBe(false);
|
||||
});
|
||||
|
||||
it("does not require first-run configuration when a valid build-time default exists", () => {
|
||||
vi.stubEnv("VITE_DESKTOP_SERVER_URL", "https://default.ctms.example.com");
|
||||
setTauriRuntime(true);
|
||||
|
||||
expect(shouldRequireDesktopServerUrl()).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -51,13 +51,22 @@ export const normalizeDesktopServerUrl = (value: string): DesktopServerUrlValida
|
||||
return { ok: true, url: `${parsed.origin}/` };
|
||||
};
|
||||
|
||||
export const getDesktopServerUrl = (): string | null => {
|
||||
export const getDefaultDesktopServerUrl = (): string | null => {
|
||||
const configured = import.meta.env.VITE_DESKTOP_SERVER_URL?.trim();
|
||||
if (!configured) return null;
|
||||
const result = normalizeDesktopServerUrl(configured);
|
||||
return result.ok ? result.url : null;
|
||||
};
|
||||
|
||||
const getStoredDesktopServerUrl = (): string | null => {
|
||||
const stored = getStorage()?.getItem(DESKTOP_SERVER_URL_KEY);
|
||||
if (!stored) return null;
|
||||
const result = normalizeDesktopServerUrl(stored);
|
||||
return result.ok ? result.url : null;
|
||||
};
|
||||
|
||||
export const getDesktopServerUrl = (): string | null => getStoredDesktopServerUrl() || getDefaultDesktopServerUrl();
|
||||
|
||||
export const hasDesktopServerUrl = (): boolean => Boolean(getDesktopServerUrl());
|
||||
|
||||
export const setDesktopServerUrl = (value: string): DesktopServerUrlValidationResult => {
|
||||
@@ -74,7 +83,7 @@ export const setDesktopServerUrl = (value: string): DesktopServerUrlValidationRe
|
||||
export const clearDesktopServerUrl = (): void => {
|
||||
const previous = getDesktopServerUrl();
|
||||
getStorage()?.removeItem(DESKTOP_SERVER_URL_KEY);
|
||||
emitServerUrlChanged(previous, null);
|
||||
emitServerUrlChanged(previous, getDesktopServerUrl());
|
||||
};
|
||||
|
||||
export const shouldRequireDesktopServerUrl = (): boolean => isTauriRuntime() && !hasDesktopServerUrl();
|
||||
|
||||
@@ -2,6 +2,7 @@ export { clientRuntime, type ClientRuntime, type RuntimeCapabilities } from "./c
|
||||
export {
|
||||
clearDesktopServerUrl,
|
||||
DESKTOP_SERVER_URL_CHANGED_EVENT,
|
||||
getDefaultDesktopServerUrl,
|
||||
getDesktopServerUrl,
|
||||
hasDesktopServerUrl,
|
||||
normalizeDesktopServerUrl,
|
||||
|
||||
Reference in New Issue
Block a user