Skip to content
TypeScript

fix(mobile): reject unknown app variants (#23681)

Victor Vogel44e7318c7971
diff --git a/apps/mobile/app.config.test.ts b/apps/mobile/app.config.test.ts
new file mode 100644
index 00000000000..b8111f45587
--- /dev/null
+++ b/apps/mobile/app.config.test.ts
@@ -0,0 +1,33 @@
+import { afterEach, expect, it, vi } from "vite-plus/test";
+
+// Keep config parsing independent of local env files and build credentials.
+vi.mock("../../scripts/lib/public-config.ts", () => ({
+ loadRepoEnv: () => ({ APP_VARIANT: process.env.APP_VARIANT }),
+}));
+
+afterEach(() => {
+ vi.unstubAllEnvs();
+});
+
+async function loadConfig(variant: string | undefined) {
+ vi.resetModules();
+ vi.stubEnv("APP_VARIANT", variant);
+ return (await import("./app.config.ts")).default;
+}
+
+it.each(["prod", ""])("rejects APP_VARIANT=%j before selecting production IDs", async (value) => {
+ await expect(loadConfig(value)).rejects.toThrow(
+ "APP_VARIANT must be development, preview, or production.",
+ );
+});
+
+it.each([
+ [undefined, "com.t3tools.t3code"],
+ ["development", "com.t3tools.t3code.dev"],
+ ["preview", "com.t3tools.t3code.preview"],
+ ["production", "com.t3tools.t3code"],
+])("keeps the iOS and Android identifiers for APP_VARIANT=%j", async (value, identifier) => {
+ const config = await loadConfig(value);
+ expect(config.ios?.bundleIdentifier).toBe(identifier);
+ expect(config.android?.package).toBe(identifier);
+});
diff --git a/apps/mobile/app.config.ts b/apps/mobile/app.config.ts
index ea885f81998..e6d388b9a98 100644
--- a/apps/mobile/app.config.ts
+++ b/apps/mobile/app.config.ts
@@ -108,8 +108,10 @@ function resolveAppVariant(value: string | undefined): AppVariant {
case "preview":
case "production":
return value;
- default:
+ case undefined:
return "production";
+ default:
+ throw new Error("APP_VARIANT must be development, preview, or production.");
}
}