@mycadet/cli 0.13.0-dev.202610201855.522ff0d → 0.13.0-dev.202610211419.6a397d7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,29 +2,75 @@
2
2
  * Pins the environment-to-cloud-hub mapping in one place. Both consumers
3
3
  * (the Capacitor shell's `server.url` and the CLI remote-web edge's
4
4
  * `hubUrl`) read this helper, so this matrix is the single behavioral pin
5
- * for the served URLs. (The remote-web edge additionally folds local → dev
6
- * at its own site: clients served through a tunnel cannot reach the local
7
- * seed's loopback.)
5
+ * for the served URLs. The helper reads `VITE_ENVIRONMENT` and
6
+ * `CADET_ENVIRONMENT` itself — under bun `import.meta.env` surfaces the
7
+ * process env live, so these cases drive both by setting/restoring them.
8
+ * (The remote-web edge additionally folds local → dev at its own site:
9
+ * clients served through a tunnel cannot reach the local seed's loopback.)
8
10
  */
9
11
 
10
- import { describe, expect, test } from "bun:test";
12
+ import { readFileSync } from "node:fs";
13
+
14
+ import { afterEach, describe, expect, test } from "bun:test";
11
15
 
12
16
  import { cloudAssistantHubUrl, SEEDS } from "../index.js";
13
17
 
14
18
  describe("cloudAssistantHubUrl", () => {
15
- test("every known environment resolves to its own web origin", () => {
19
+ const original = {
20
+ vite: process.env.VITE_ENVIRONMENT,
21
+ cadet: process.env.CADET_ENVIRONMENT,
22
+ };
23
+
24
+ afterEach(() => {
25
+ for (const [key, value] of Object.entries(original)) {
26
+ if (value === undefined) delete process.env[key];
27
+ else process.env[key] = value;
28
+ }
29
+ });
30
+
31
+ test("VITE_ENVIRONMENT picks its own web origin (the build-time inlined var)", () => {
16
32
  for (const name of ["production", "staging", "dev", "test", "local"]) {
17
- expect(cloudAssistantHubUrl(name)).toBe(
18
- `${SEEDS[name].webUrl}/assistant`,
19
- );
33
+ process.env.VITE_ENVIRONMENT = name;
34
+ delete process.env.CADET_ENVIRONMENT;
35
+ expect(cloudAssistantHubUrl()).toBe(`${SEEDS[name].webUrl}/assistant`);
20
36
  }
21
37
  });
22
38
 
23
- test("unknown environments fall back to the dev SPA", () => {
24
- for (const name of ["unknown-env", undefined]) {
25
- expect(cloudAssistantHubUrl(name)).toBe(
26
- "https://dev.mycadet.ai/assistant",
27
- );
39
+ test("CADET_ENVIRONMENT picks its own web origin (the runtime var)", () => {
40
+ for (const name of ["production", "staging", "dev", "test", "local"]) {
41
+ process.env.CADET_ENVIRONMENT = name;
42
+ delete process.env.VITE_ENVIRONMENT;
43
+ expect(cloudAssistantHubUrl()).toBe(`${SEEDS[name].webUrl}/assistant`);
28
44
  }
29
45
  });
46
+
47
+ test("CADET_ENVIRONMENT wins when both are set (the runtime contract)", () => {
48
+ process.env.VITE_ENVIRONMENT = "production";
49
+ process.env.CADET_ENVIRONMENT = "staging";
50
+ expect(cloudAssistantHubUrl()).toBe(`${SEEDS.staging.webUrl}/assistant`);
51
+ });
52
+
53
+ test("unset and unknown environments fall back to the dev SPA", () => {
54
+ for (const set of [
55
+ () => {
56
+ delete process.env.VITE_ENVIRONMENT;
57
+ delete process.env.CADET_ENVIRONMENT;
58
+ },
59
+ () => {
60
+ delete process.env.CADET_ENVIRONMENT;
61
+ process.env.VITE_ENVIRONMENT = "unknown-env";
62
+ },
63
+ ]) {
64
+ set();
65
+ expect(cloudAssistantHubUrl()).toBe("https://dev.mycadet.ai/assistant");
66
+ }
67
+ });
68
+ });
69
+
70
+ test("seeds.ts stays loadable by Capacitor's single-file TS config loader", () => {
71
+ // The loader transpiles the file to CJS; an import-meta reference can't be
72
+ // transpiled and makes Node execute the CJS output as ESM (`exports is not
73
+ // defined`), which took down the iOS Capacitor sync in CI.
74
+ const src = readFileSync(new URL("../seeds.ts", import.meta.url), "utf8");
75
+ expect(src).not.toContain("import.meta");
30
76
  });
@@ -1,3 +1,7 @@
1
+ // Loaded standalone by Capacitor's single-file TS config loader — keep
2
+ // imports type-only and keep this file free of the import-meta meta-property:
3
+ // the loader transpiles this file to CJS, where that syntax is illegal and
4
+ // makes Node misroute the result as ESM.
1
5
  import type { EnvironmentDefinition, PortMap } from "./types.js";
2
6
 
3
7
  /**
@@ -24,30 +28,24 @@ function portBlock(base: number): PortMap {
24
28
  };
25
29
  }
26
30
 
27
- /**
28
- * Base URL of the cloud-hosted assistant SPA (the "hub") for a deployment
29
- * environment: always `${SEEDS[env].webUrl}/assistant`. The Capacitor boot
30
- * bundle stamps this into baked mobile builds as `handoffUrl`, and the CLI's
31
- * remote-web edge stamps it into the served config as `hubUrl`, so the
32
- * environment-to-hub mapping lives here exactly once. Unknown environment
33
- * names fall back to the dev SPA defensively.
34
- *
35
- * The `/assistant` suffix is deliberate: booting on the bare host lands on
36
- * the marketing page, whose CTA redirects to `mycadet.ai/assistant` and
37
- * bounces non-prod shells off their own host.
38
- *
39
- * NOTE: this module is loaded by Capacitor's single-file TS config loader
40
- * (via the `@mycadet/environments/seeds` subpath), which cannot follow the
41
- * package index's `.js`-suffixed runtime re-exports. Keep this file's
42
- * imports type-only so it stays loadable on its own.
43
- */
44
- export function cloudWebUrl(envName: string | undefined): string {
31
+ /** Web origin for the current environment (CADET_ENVIRONMENT or VITE_ENVIRONMENT; unknown falls back to dev). */
32
+ export function cloudWebUrl(): string {
33
+ // globalThis.process reads the same env under bun/node while staying
34
+ // crash-free in browser bundles (no bare `process` reference) — and free
35
+ // of import-meta syntax, which the Capacitor config loader can't transpile.
36
+ const env = (
37
+ globalThis as unknown as {
38
+ process?: { env?: Record<string, string | undefined> };
39
+ }
40
+ ).process?.env;
41
+ const envName = env?.CADET_ENVIRONMENT ?? env?.VITE_ENVIRONMENT;
45
42
  const seed = (envName && SEEDS[envName]) || SEEDS.dev;
46
43
  return seed.webUrl;
47
44
  }
48
45
 
49
- export function cloudAssistantHubUrl(envName: string | undefined): string {
50
- return `${cloudWebUrl(envName)}/assistant`;
46
+ /** The cloud assistant hub — booting at the bare host bounces non-prod shells. */
47
+ export function cloudAssistantHubUrl(): string {
48
+ return `${cloudWebUrl()}/assistant`;
51
49
  }
52
50
 
53
51
  /**
@@ -2,29 +2,75 @@
2
2
  * Pins the environment-to-cloud-hub mapping in one place. Both consumers
3
3
  * (the Capacitor shell's `server.url` and the CLI remote-web edge's
4
4
  * `hubUrl`) read this helper, so this matrix is the single behavioral pin
5
- * for the served URLs. (The remote-web edge additionally folds local → dev
6
- * at its own site: clients served through a tunnel cannot reach the local
7
- * seed's loopback.)
5
+ * for the served URLs. The helper reads `VITE_ENVIRONMENT` and
6
+ * `CADET_ENVIRONMENT` itself — under bun `import.meta.env` surfaces the
7
+ * process env live, so these cases drive both by setting/restoring them.
8
+ * (The remote-web edge additionally folds local → dev at its own site:
9
+ * clients served through a tunnel cannot reach the local seed's loopback.)
8
10
  */
9
11
 
10
- import { describe, expect, test } from "bun:test";
12
+ import { readFileSync } from "node:fs";
13
+
14
+ import { afterEach, describe, expect, test } from "bun:test";
11
15
 
12
16
  import { cloudAssistantHubUrl, SEEDS } from "../index.js";
13
17
 
14
18
  describe("cloudAssistantHubUrl", () => {
15
- test("every known environment resolves to its own web origin", () => {
19
+ const original = {
20
+ vite: process.env.VITE_ENVIRONMENT,
21
+ cadet: process.env.CADET_ENVIRONMENT,
22
+ };
23
+
24
+ afterEach(() => {
25
+ for (const [key, value] of Object.entries(original)) {
26
+ if (value === undefined) delete process.env[key];
27
+ else process.env[key] = value;
28
+ }
29
+ });
30
+
31
+ test("VITE_ENVIRONMENT picks its own web origin (the build-time inlined var)", () => {
16
32
  for (const name of ["production", "staging", "dev", "test", "local"]) {
17
- expect(cloudAssistantHubUrl(name)).toBe(
18
- `${SEEDS[name].webUrl}/assistant`,
19
- );
33
+ process.env.VITE_ENVIRONMENT = name;
34
+ delete process.env.CADET_ENVIRONMENT;
35
+ expect(cloudAssistantHubUrl()).toBe(`${SEEDS[name].webUrl}/assistant`);
20
36
  }
21
37
  });
22
38
 
23
- test("unknown environments fall back to the dev SPA", () => {
24
- for (const name of ["unknown-env", undefined]) {
25
- expect(cloudAssistantHubUrl(name)).toBe(
26
- "https://dev.mycadet.ai/assistant",
27
- );
39
+ test("CADET_ENVIRONMENT picks its own web origin (the runtime var)", () => {
40
+ for (const name of ["production", "staging", "dev", "test", "local"]) {
41
+ process.env.CADET_ENVIRONMENT = name;
42
+ delete process.env.VITE_ENVIRONMENT;
43
+ expect(cloudAssistantHubUrl()).toBe(`${SEEDS[name].webUrl}/assistant`);
28
44
  }
29
45
  });
46
+
47
+ test("CADET_ENVIRONMENT wins when both are set (the runtime contract)", () => {
48
+ process.env.VITE_ENVIRONMENT = "production";
49
+ process.env.CADET_ENVIRONMENT = "staging";
50
+ expect(cloudAssistantHubUrl()).toBe(`${SEEDS.staging.webUrl}/assistant`);
51
+ });
52
+
53
+ test("unset and unknown environments fall back to the dev SPA", () => {
54
+ for (const set of [
55
+ () => {
56
+ delete process.env.VITE_ENVIRONMENT;
57
+ delete process.env.CADET_ENVIRONMENT;
58
+ },
59
+ () => {
60
+ delete process.env.CADET_ENVIRONMENT;
61
+ process.env.VITE_ENVIRONMENT = "unknown-env";
62
+ },
63
+ ]) {
64
+ set();
65
+ expect(cloudAssistantHubUrl()).toBe("https://dev.mycadet.ai/assistant");
66
+ }
67
+ });
68
+ });
69
+
70
+ test("seeds.ts stays loadable by Capacitor's single-file TS config loader", () => {
71
+ // The loader transpiles the file to CJS; an import-meta reference can't be
72
+ // transpiled and makes Node execute the CJS output as ESM (`exports is not
73
+ // defined`), which took down the iOS Capacitor sync in CI.
74
+ const src = readFileSync(new URL("../seeds.ts", import.meta.url), "utf8");
75
+ expect(src).not.toContain("import.meta");
30
76
  });
@@ -1,3 +1,7 @@
1
+ // Loaded standalone by Capacitor's single-file TS config loader — keep
2
+ // imports type-only and keep this file free of the import-meta meta-property:
3
+ // the loader transpiles this file to CJS, where that syntax is illegal and
4
+ // makes Node misroute the result as ESM.
1
5
  import type { EnvironmentDefinition, PortMap } from "./types.js";
2
6
 
3
7
  /**
@@ -24,30 +28,24 @@ function portBlock(base: number): PortMap {
24
28
  };
25
29
  }
26
30
 
27
- /**
28
- * Base URL of the cloud-hosted assistant SPA (the "hub") for a deployment
29
- * environment: always `${SEEDS[env].webUrl}/assistant`. The Capacitor boot
30
- * bundle stamps this into baked mobile builds as `handoffUrl`, and the CLI's
31
- * remote-web edge stamps it into the served config as `hubUrl`, so the
32
- * environment-to-hub mapping lives here exactly once. Unknown environment
33
- * names fall back to the dev SPA defensively.
34
- *
35
- * The `/assistant` suffix is deliberate: booting on the bare host lands on
36
- * the marketing page, whose CTA redirects to `mycadet.ai/assistant` and
37
- * bounces non-prod shells off their own host.
38
- *
39
- * NOTE: this module is loaded by Capacitor's single-file TS config loader
40
- * (via the `@mycadet/environments/seeds` subpath), which cannot follow the
41
- * package index's `.js`-suffixed runtime re-exports. Keep this file's
42
- * imports type-only so it stays loadable on its own.
43
- */
44
- export function cloudWebUrl(envName: string | undefined): string {
31
+ /** Web origin for the current environment (CADET_ENVIRONMENT or VITE_ENVIRONMENT; unknown falls back to dev). */
32
+ export function cloudWebUrl(): string {
33
+ // globalThis.process reads the same env under bun/node while staying
34
+ // crash-free in browser bundles (no bare `process` reference) — and free
35
+ // of import-meta syntax, which the Capacitor config loader can't transpile.
36
+ const env = (
37
+ globalThis as unknown as {
38
+ process?: { env?: Record<string, string | undefined> };
39
+ }
40
+ ).process?.env;
41
+ const envName = env?.CADET_ENVIRONMENT ?? env?.VITE_ENVIRONMENT;
45
42
  const seed = (envName && SEEDS[envName]) || SEEDS.dev;
46
43
  return seed.webUrl;
47
44
  }
48
45
 
49
- export function cloudAssistantHubUrl(envName: string | undefined): string {
50
- return `${cloudWebUrl(envName)}/assistant`;
46
+ /** The cloud assistant hub — booting at the bare host bounces non-prod shells. */
47
+ export function cloudAssistantHubUrl(): string {
48
+ return `${cloudWebUrl()}/assistant`;
51
49
  }
52
50
 
53
51
  /**