Lines 74-114javascript
76 * Test-only — force the resolved CloudEnv to a known value. Used by
77 * downstream finalize tests (Phase D Task 10) that need a deterministic
78 * egress rate without actually probing IMDS or reading DMI. The
79 * `_for_tests` suffix marks this as not-public-API.
81export function _setResultForTests(env) {
84// Test-only — reset module state.
85export function _resetCloudDetectForTests() {
86 _result = { provider: null, region: null, source: "none" };
87 _backgroundPromise = null;
89// ---------------------------------------------------------------------------
90// Phase 1a — environment variable detection
91// ---------------------------------------------------------------------------
92const _AZ_CA_REGION_RE = /\.([a-z0-9-]+)\.azurecontainerapps\.io$/i;
93function _azureContainerAppsRegion() {
94 for (const name of ["CONTAINER_APP_HOSTNAME", "CONTAINER_APP_ENV_DNS_SUFFIX"]) {
95 const value = process.env[name];
96 if (!value)
HighCloud Metadata Access
Source reaches cloud instance metadata or link-local credential endpoints.
dist/cloud-detect.jsView on unpkg · L94 98 const match = _AZ_CA_REGION_RE.exec(value);
99 if (match && match[1])
100 return match[1].toLowerCase();
104function _detectEnv() {
105 const env = process.env;
106 // ── GPU / ML clouds (zero egress) ───────────────────────────────────────
107 // Detection prevents the universal $0.09/GB default from over-attributing
108 // on platforms whose marketing point is $0 egress.
109 // Modal (modal.com/docs).
110 if (env.MODAL_TASK_ID || env.MODAL_IMAGE_ID) {
111 return { provider: "modal", region: env.MODAL_REGION || null, source: "env" };
113 // RunPod (docs.runpod.io).
114 if (env.RUNPOD_POD_ID || env.RUNPOD_POD_HOSTNAME) {