Compare commits

..
Author SHA1 Message Date
tiago-neves 4bd1983645 Merge pull request 'fix(hub): preserve CT225 drift (context_data, resolve endpoints) + npm ci --include=dev (BIT-33336)' (#21) from task/BIT-33336-hotfix-drift-npm-ci into master
CI / Test ingest-api (push) Successful in 22s
CI / Test api (push) Successful in 23s
CI / Lint and typecheck admin-ui (push) Successful in 56s
CI / Validate Docker build (push) Successful in 3m26s
2026-11-25 12:29:28 +00:00
Tiago Neves 6a55df01bc fix(deploy): npm ci --include=dev in webhook-deploy.sh (BIT-33336)
CI / Test ingest-api (pull_request) Successful in 23s
CI / Test api (pull_request) Successful in 24s
CI / Lint and typecheck admin-ui (pull_request) Successful in 1m53s
CI / Validate Docker build (pull_request) Successful in 3m31s
Node 24/npm 11 omits devDependencies (tsc) on plain npm ci. Together with
the CT225 hotfix drift (context_data, resolve endpoints) preserved from
hotfix/ct225-drift-recent-errors.
2026-11-25 12:25:36 +00:00
Tiago Neves 40c646ab4b Merge remote-tracking branch 'origin/hotfix/ct225-drift-recent-errors' into task/BIT-33336-hotfix-drift-npm-ci 2026-11-25 12:25:17 +00:00
David Santos 3abd4ab804 hotfix(hub): preserve production drift — slimContext/context_data + resolve endpoints
Production CT225 has uncommitted changes not in master:
- recentErrors.ts: add slimContext() to trim large context_data blobs
  and expose context_data in the recent-errors response
- admin-ui resolve-by-pattern/route.ts: new endpoint
- admin-ui resolve-fixed-patterns/route.ts: new endpoint

This commit preserves the drift so it can be PR-reviewed and merged
over 7bc04e8 (PR20).

Paperclip-Issue: BIT-33338
2026-11-25 12:18:20 +00:00
spark 7bc04e8e1b Merge pull request 'feat(hub): populate event metadata columns + recent-errors fields (BIT-33316)' (#20) from task/BIT-33316-event-metadata into master
CI / Test ingest-api (push) Successful in 23s
CI / Test api (push) Successful in 26s
CI / Lint and typecheck admin-ui (push) Successful in 56s
CI / Validate Docker build (push) Successful in 3m31s
2026-11-25 05:54:44 +00:00
nelson-baptista 258f0b3cd4 fix(admin-ui): remove duplicate environment field in php-error payload type (BIT-33316)
CI / Test ingest-api (pull_request) Successful in 24s
CI / Test api (pull_request) Successful in 28s
CI / Lint and typecheck admin-ui (pull_request) Successful in 1m55s
CI / Validate Docker build (pull_request) Successful in 3m52s
Paperclip-Issue: BIT-33316
2026-11-25 05:45:28 +00:00
nelson-baptista b757ec671a feat(hub): populate runtime/host/release/request_id columns, honor environment, expose metadata in recent-errors (BIT-33316)
CI / Test ingest-api (pull_request) Successful in 22s
CI / Test api (pull_request) Successful in 25s
CI / Lint and typecheck admin-ui (pull_request) Failing after 2m12s
CI / Validate Docker build (pull_request) Failing after 3m15s
Paperclip-Issue: BIT-33316
2026-11-25 05:10:18 +00:00
spark baac48a632 Merge pull request 'fix(ingest): filter BIT-<id> smoke-test probes in noise policy (BIT-32681)' (#19) from fix/BIT-32681-smoke-probe-noise-filter into master
CI / Test ingest-api (push) Successful in 23s
CI / Test api (push) Successful in 24s
CI / Lint and typecheck admin-ui (push) Successful in 52s
CI / Validate Docker build (push) Successful in 3m23s
2026-11-20 10:03:24 +00:00
nelson-baptista b8ca70709e fix(ingest): filter BIT-<id> smoke-test probes in noise policy (BIT-32681)
CI / Test ingest-api (pull_request) Successful in 24s
CI / Test api (pull_request) Successful in 26s
CI / Lint and typecheck admin-ui (pull_request) Successful in 1m58s
CI / Validate Docker build (pull_request) Successful in 3m33s
Hand-sent pipe-liveness probes referenced by a BIT task id (e.g.
`BIT-32663 smoke test` or `[BIT-30527] ... smoke test`) were not matched
by the ingest noise policy: they lack the reserved `BIT-SMOKE-` token and
the bracket-only fleet-audit regex, so they passed ingest and opened a
false-positive Error Loop issue (BIT-32681 / ERRCLUSTER a513bc4e4505).

- noisePolicy.ts: add `_BIT_ID_SMOKE_PROBE_RE` matching bare and bracketed
  `BIT-<id> ... smoke test` forms; filtered at every severity under the
  existing `bitreport_smoke_marker` rule. Bump ruleset 1.0.7 -> 1.0.8.
- noisePolicy.test.ts: cover bare, bracketed, critical-level, and a
  negative case (`Smoke detector sensor offline` stays unfiltered).
- paperclip_fleet_error_reporting_audit_once.py: relax `_SYNTHETIC_EVENT_RE`
  to the same bare/bracketed shape so ingest and fleet audit agree.
- docs/operations/ingest-hardening-runbook.md: document the new probe shape.

Verified locally: ingest-api vitest 44 passed | 14 skipped; typecheck clean;
reporter context contract ok; fleet audit py_compile ok.

Paperclip-Agent: José Alves (urlKey jos-alves; id 11179220-3cec-4f0f-880d-2771ff64fce8)
Paperclip-Issue: BIT-32681
Paperclip-Run: 64667793-6ac7-404b-80bc-f369f0c4f9e0
2026-11-20 09:42:08 +00:00
spark e01c8f62d5 Merge pull request 'chore(runtime): BIT-31723 upgrade Node 20 → Node 24 LTS + audit PHP/TS code' (#18) from chore/BIT-31723-node24-upgrade into master
CI / Test ingest-api (push) Successful in 41s
CI / Test api (push) Successful in 37s
CI / Lint and typecheck admin-ui (push) Successful in 1m27s
CI / Validate Docker build (push) Successful in 5m23s
2026-10-23 17:38:00 +01:00
11 changed files with 308 additions and 9 deletions

No files matched your search

@@ -38,6 +38,14 @@ interface CrmPhpPayload {
// Paperclip project UUID — used by error loop to route issues to the correct project board column
paperclip_project_id?: unknown;
paperclipProjectId?: unknown;
// telemetry metadata (BIT-33316) — canonical keys + legacy aliases
component?: unknown;
release?: unknown;
release_version?: unknown;
runtime_name?: unknown;
runtime_version?: unknown;
host_name?: unknown;
hostname?: unknown;
}
function safeStr(v: unknown): string {
@@ -103,6 +111,18 @@ export async function POST(request: NextRequest) {
if (project_name) contextData.project_name = project_name;
if (paperclip_project_id) contextData.paperclip_project_id = paperclip_project_id;
const metaPairs: Array<[string, string]> = [
["component", safeStr(body.component)],
["release_version", safeStr(body.release_version || body.release)],
["runtime_name", safeStr(body.runtime_name)],
["runtime_version", safeStr(body.runtime_version)],
["host_name", safeStr(body.host_name || body.hostname)],
["environment", safeStr(body.environment)],
];
for (const [k, v] of metaPairs) {
if (v) contextData[k] = v;
}
// Preserve other top-level diagnostic fields.
const file_path = safeStr(body.file_path);
const line_number = safeStr(body.line_number);
@@ -0,0 +1,47 @@
import type { NextRequest } from "next/server";
import { NextResponse } from "next/server";
export const dynamic = "force-dynamic";
export async function POST(request: NextRequest) {
const rawBase = process.env.ERROR_REPORTING_ADMIN_API_BASE?.trim();
if (!rawBase) {
return NextResponse.json(
{
success: false,
message: "ERROR_REPORTING_ADMIN_API_BASE is not configured.",
},
{ status: 503 },
);
}
const base = rawBase.replace(/\/$/, "");
const target = `${base}/api/error-monitoring/resolve-by-pattern`;
const body = await request.text();
const headers: Record<string, string> = {
Accept: "application/json",
"Content-Type": request.headers.get("Content-Type") ?? "application/json",
};
const cookie = request.headers.get("cookie");
if (cookie) {
headers.Cookie = cookie;
}
const resolveHdr = request.headers.get("x-error-resolve-key");
if (resolveHdr) {
headers["X-Error-Resolve-Key"] = resolveHdr;
}
const upstream = await fetch(target, {
method: "POST",
headers,
body: body || undefined,
cache: "no-store",
});
const text = await upstream.text();
const ct = upstream.headers.get("Content-Type") ?? "application/json; charset=utf-8";
return new NextResponse(text, {
status: upstream.status,
headers: { "Content-Type": ct },
});
}
@@ -0,0 +1,47 @@
import type { NextRequest } from "next/server";
import { NextResponse } from "next/server";
export const dynamic = "force-dynamic";
export async function POST(request: NextRequest) {
const rawBase = process.env.ERROR_REPORTING_ADMIN_API_BASE?.trim();
if (!rawBase) {
return NextResponse.json(
{
success: false,
message: "ERROR_REPORTING_ADMIN_API_BASE is not configured.",
},
{ status: 503 },
);
}
const base = rawBase.replace(/\/$/, "");
const target = `${base}/api/error-monitoring/resolve-fixed-patterns`;
const body = await request.text();
const headers: Record<string, string> = {
Accept: "application/json",
"Content-Type": request.headers.get("Content-Type") ?? "application/json",
};
const cookie = request.headers.get("cookie");
if (cookie) {
headers.Cookie = cookie;
}
const resolveHdr = request.headers.get("x-error-resolve-key");
if (resolveHdr) {
headers["X-Error-Resolve-Key"] = resolveHdr;
}
const upstream = await fetch(target, {
method: "POST",
headers,
body: body || undefined,
cache: "no-store",
});
const text = await upstream.text();
const ct = upstream.headers.get("Content-Type") ?? "application/json; charset=utf-8";
return new NextResponse(text, {
status: upstream.status,
headers: { "Content-Type": ct },
});
}
+43
View File
@@ -65,6 +65,15 @@ function extractFileLine(ctx: Record<string, unknown> | null): { file_path: stri
return { file_path, line_number };
}
function ctxStr(ctx: Record<string, unknown> | null, keys: string[]): string {
if (!ctx) return '';
for (const k of keys) {
const v = ctx[k];
if (typeof v === 'string' && v.trim() !== '') return v.trim();
}
return '';
}
/** Paperclip error loop reads top-level `gitea_repo` on each recent-error row. */
function extractGiteaRepo(ctx: Record<string, unknown> | null): string {
if (!ctx) {
@@ -100,6 +109,29 @@ function parseStatusList(raw: string | undefined): string[] | null {
return parts.length > 0 ? parts : ['open', 'investigating'];
}
function slimContext(ctx: Record<string, unknown> | null): Record<string, unknown> | null {
if (!ctx) return null;
const out: Record<string, unknown> = {};
for (const key of Object.keys(ctx).slice(0, 40)) out[key] = slimContextValue(ctx[key], 0);
return out;
}
function slimContextValue(value: unknown, depth: number): unknown {
if (depth > 3) return '[nested]';
if (typeof value === 'string') return value.length > 1500 ? `${value.slice(0, 1500)}…` : value;
if (value == null || typeof value === 'number' || typeof value === 'boolean') return value;
if (Array.isArray(value)) return value.slice(0, 20).map((item) => slimContextValue(item, depth + 1));
if (typeof value === 'object') {
const nested: Record<string, unknown> = {};
for (const [key, item] of Object.entries(value as Record<string, unknown>).slice(0, 30)) {
nested[key] = slimContextValue(item, depth + 1);
}
return nested;
}
return String(value).slice(0, 500);
}
async function handleRecentErrors(request: FastifyRequest, reply: FastifyReply): Promise<void> {
const db = request.server.db;
@@ -300,9 +332,20 @@ async function handleRecentErrors(request: FastifyRequest, reply: FastifyReply):
if (gitea_repo !== '') {
rowOut.gitea_repo = gitea_repo;
}
const extra: Record<string, string> = {
component: ctxStr(ctx, ['component']),
release_version: ctxStr(ctx, ['release_version', 'release', 'app_version']),
runtime_name: ctxStr(ctx, ['runtime_name', 'runtime']),
host_name: ctxStr(ctx, ['host_name', 'hostname', 'host']),
};
for (const [k, v] of Object.entries(extra)) {
if (v !== '') rowOut[k] = v;
}
if (paperclip_project_id !== '') {
rowOut.paperclip_project_id = paperclip_project_id;
}
const contextData = slimContext(ctx);
if (contextData) rowOut.context_data = contextData;
return rowOut;
});
+4 -4
View File
@@ -27,10 +27,10 @@ git checkout "${_DEPLOY_BRANCH}"
git merge --ff-only "origin/${_DEPLOY_BRANCH}"
echo "webhook-deploy: npm ci + build (ingest-api, admin-ui, collector-worker, api)"
(cd "${_ROOT}/ingest-api" && npm ci && npm run build)
(cd "${_ROOT}/admin-ui" && npm ci && npm run build)
(cd "${_ROOT}/collector-worker" && npm ci && npm run build)
(cd "${_ROOT}/api" && npm ci && npm run build)
(cd "${_ROOT}/ingest-api" && npm ci --include=dev && npm run build)
(cd "${_ROOT}/admin-ui" && npm ci --include=dev && npm run build)
(cd "${_ROOT}/collector-worker" && npm ci --include=dev && npm run build)
(cd "${_ROOT}/api" && npm ci --include=dev && npm run build)
if getent passwd error-reporting >/dev/null 2>&1; then
chown -R error-reporting:error-reporting "${_ROOT}"
+1 -1
View File
@@ -32,7 +32,7 @@ Per-key overrides: set `rate_limit_max` and/or `rate_limit_window_ms` on the key
- Rules live in `ingest-api/src/lib/noisePolicy.ts`; ruleset id: `noise_ruleset_version` in the ingest response.
- **Check:** send a known-noise payload (for example ResizeObserver message at non-fatal level); expect `skipped: true`, `noise_filtered_count` incremented, and no new `er_incidents` row.
- **Check:** send the same pattern at `fatal` / `critical` level; expect **not** skipped (noise rules do not hide critical), **except** when the **message** or **client-provided stacktrace** contains reserved substring `BIT-SMOKE-` (intentional reporter smoke, e.g. wdmi-store `/smoke/wdmi.js`, CRM `/smoke/crm-main.php`, CRM `/smoke/crm.php` direct-forward `BIT-SMOKE-CRM-DIRECT-FWD`) — those are skipped at every level (`rule_id`: `bitreport_smoke_marker`). Matching treats unicode hyphen/minus characters as ASCII `-` (ruleset **1.0.5+**). The exact deploy-probe failure ribbon `BIT-SMOKE error hub ingest live check` (space after `BIT-SMOKE`, see [RUNBOOK_INGEST_DEBUG.md](../RUNBOOK_INGEST_DEBUG.md) §0) is also skipped at every level with the same `rule_id`.
- **Check:** send the same pattern at `fatal` / `critical` level; expect **not** skipped (noise rules do not hide critical), **except** when the **message** or **client-provided stacktrace** contains reserved substring `BIT-SMOKE-` (intentional reporter smoke, e.g. wdmi-store `/smoke/wdmi.js`, CRM `/smoke/crm-main.php`, CRM `/smoke/crm.php` direct-forward `BIT-SMOKE-CRM-DIRECT-FWD`) — those are skipped at every level (`rule_id`: `bitreport_smoke_marker`). Matching treats unicode hyphen/minus characters as ASCII `-` (ruleset **1.0.5+**). The exact deploy-probe failure ribbon `BIT-SMOKE error hub ingest live check` (space after `BIT-SMOKE`, see [RUNBOOK_INGEST_DEBUG.md](../RUNBOOK_INGEST_DEBUG.md) §0) is also skipped at every level with the same `rule_id`. Hand-sent pipe-liveness probes referenced by a BIT task id — `BIT-<id> smoke test` (bare) or `[BIT-<id>] ... smoke test` (bracketed) — are likewise skipped at every level (ruleset **1.0.8+**, BIT-32681), aligning ingest with the fleet audit synthetic-event exclusion.
## Rate limits
+48
View File
@@ -143,6 +143,54 @@ describe("evaluateNoise", () => {
});
});
it("matches bare 'BIT-<id> smoke test' pipe-liveness probe (BIT-32681)", () => {
const _r = evaluateNoise({
level: "error",
message: "BIT-32663 smoke test",
filePathHint: "",
});
expect(_r).toEqual({
matched: true,
ruleId: "bitreport_smoke_marker",
reason: "filtered_intentional_smoke_event",
});
});
it("matches bracketed '[BIT-<id>] ... smoke test' probe (fleet-audit synthetic form)", () => {
const _r = evaluateNoise({
level: "error",
message: "[BIT-30527] paperclip-chat pipe-liveness smoke test",
filePathHint: "",
});
expect(_r).toEqual({
matched: true,
ruleId: "bitreport_smoke_marker",
reason: "filtered_intentional_smoke_event",
});
});
it("suppresses 'BIT-<id> smoke test' probe even at critical level", () => {
const _r = evaluateNoise({
level: "critical",
message: "BIT-32663 smoke test",
filePathHint: "",
});
expect(_r).toEqual({
matched: true,
ruleId: "bitreport_smoke_marker",
reason: "filtered_intentional_smoke_event",
});
});
it("does not match a real error that merely contains 'smoke' without the BIT-<id> probe shape", () => {
const _r = evaluateNoise({
level: "error",
message: "Smoke detector sensor offline",
filePathHint: "",
});
expect(_r).toEqual({ matched: false });
});
it("matches CRM deploy ingest live-check failure ribbon (BIT-931 family)", () => {
const _r = evaluateNoise({
level: "critical",
+17 -1
View File
@@ -4,7 +4,7 @@ import { normalizeLevelToSeverity } from "./normalize.js";
* Versioned ruleset id (document in release notes when rules change).
* Rule inventory and validation steps: `docs/operations/ingest-hardening-runbook.md`.
*/
export const NOISE_RULESET_VERSION = "1.0.7";
export const NOISE_RULESET_VERSION = "1.0.8";
export type NoiseEvaluation =
| { matched: false }
@@ -12,6 +12,15 @@ export type NoiseEvaluation =
const _DEPLOY_INGEST_PROBE_MESSAGE = "BIT-SMOKE error hub ingest live check";
/**
* Hand-sent pipe-liveness probes referenced by a BIT task id (e.g. `BIT-32663 smoke test`
* or `[BIT-30527] paperclip-chat pipe-liveness smoke test`). The fleet audit already
* treats the bracketed form as synthetic (`_SYNTHETIC_EVENT_RE`); ingest must agree so
* these probes do not open Error Loop issues. Matched at every severity, like `BIT-SMOKE-`.
* BIT-32681 / ERRCLUSTER a513bc4e4505.
*/
const _BIT_ID_SMOKE_PROBE_RE = /\[?BIT-\d+\]?\s+.*smoke test/i;
/**
* CRM / editor copy-paste sometimes inserts unicode hyphens (U+2011 etc.) in the reserved
* `BIT-SMOKE-` token; strip ZW* / BOM so probes still match `bitreport_smoke_marker` (BIT-933).
@@ -155,6 +164,13 @@ export function evaluateNoise(input: {
reason: "filtered_intentional_smoke_event",
};
}
if (_BIT_ID_SMOKE_PROBE_RE.test(_msg) || _BIT_ID_SMOKE_PROBE_RE.test(_stack)) {
return {
matched: true,
ruleId: "bitreport_smoke_marker",
reason: "filtered_intentional_smoke_event",
};
}
const _sev = normalizeLevelToSeverity(input.level);
if (_sev === "critical") {
return { matched: false };
@@ -0,0 +1,27 @@
import { describe, expect, it } from "vitest";
import { extractOccurrenceMetadata } from "./processIngestBatch.js";
describe("extractOccurrenceMetadata (BIT-33316)", () => {
it("maps canonical keys", () => {
const m = extractOccurrenceMetadata({}, {
runtime_name: "php", runtime_version: "8.3", host_name: "h1",
release_version: "1.2.3", request_id: "r1", environment: "Staging",
});
expect(m).toEqual({
environment: "staging", runtime_name: "php", runtime_version: "8.3",
host_name: "h1", release_version: "1.2.3", request_id: "r1",
});
});
it("falls back to legacy aliases and production", () => {
const m = extractOccurrenceMetadata({}, { hostname: "h2", app_version: "9" });
expect(m.host_name).toBe("h2");
expect(m.release_version).toBe("9");
expect(m.environment).toBe("production");
expect(m.runtime_name).toBeNull();
});
it("event.environment wins, invalid falls back", () => {
expect(extractOccurrenceMetadata({ environment: "dev" }, { environment: "x" }).environment).toBe("dev");
expect(extractOccurrenceMetadata({}, { environment: "bad env!" }).environment).toBe("production");
expect(extractOccurrenceMetadata({}, null).host_name).toBeNull();
});
});
+49 -2
View File
@@ -232,6 +232,44 @@ export async function processIngestBatch(input: {
}
}
const _META_ENV_RE = /^[A-Za-z0-9._-]{1,32}$/;
function _metaStr(ctx: Record<string, unknown> | null, keys: string[], max: number): string | null {
if (!ctx) return null;
for (const k of keys) {
const v = ctx[k];
if (typeof v === "string" && v.trim() !== "") return v.trim().slice(0, max);
}
return null;
}
/** Canonical keys first, legacy aliases (hostname, app_version, ...) as fallback. BIT-33316. */
export function extractOccurrenceMetadata(
ev: unknown,
ctx: Record<string, unknown> | null,
): {
environment: string;
runtime_name: string | null;
runtime_version: string | null;
host_name: string | null;
release_version: string | null;
request_id: string | null;
} {
const evObj = (ev && typeof ev === "object" ? ev : {}) as Record<string, unknown>;
const rawEnv =
(typeof evObj.environment === "string" ? evObj.environment.trim() : "") ||
_metaStr(ctx, ["environment", "env"], 32) ||
"";
return {
environment: _META_ENV_RE.test(rawEnv) ? rawEnv.toLowerCase() : "production",
runtime_name: _metaStr(ctx, ["runtime_name", "runtime"], 32),
runtime_version: _metaStr(ctx, ["runtime_version"], 32),
host_name: _metaStr(ctx, ["host_name", "hostname", "host"], 128),
release_version: _metaStr(ctx, ["release_version", "release", "app_version"], 64),
request_id: _metaStr(ctx, ["request_id", "requestId"], 128),
};
}
async function _ingestOneEvent(
client: PoolConnection,
input: { ingestKeyId: string; projectId: string; event: IngestEventInput },
@@ -296,11 +334,14 @@ async function _ingestOneEvent(
throw new Error("incident_upsert_failed");
}
const _meta = extractOccurrenceMetadata(_ev, _context);
const [occHeader] = await client.execute<ResultSetHeader>(
`INSERT INTO er_incident_occurrences (
project_id, incident_id, ingest_key_id, occurred_at, level_raw, severity,
message, stack_trace, context_json, schema_version, environment
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'production')`,
message, stack_trace, context_json, schema_version, environment,
runtime_name, runtime_version, host_name, release_version, request_id
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
[
input.projectId,
_incidentRow.id,
@@ -312,6 +353,12 @@ async function _ingestOneEvent(
_stack,
_context === null ? null : JSON.stringify(_context),
_ev.schema_version,
_meta.environment,
_meta.runtime_name,
_meta.runtime_version,
_meta.host_name,
_meta.release_version,
_meta.request_id,
],
);
const _occId = occHeader.insertId;
@@ -43,7 +43,11 @@ from urllib.error import HTTPError, URLError
# hand while investigating a "stale" finding, per BIT-30273/BIT-30527). These are real
# hub rows but not production traffic — counting them as "fresh" masks genuine staleness
# for as long as they remain the newest row for a slug. Excluded from freshness scoring.
_SYNTHETIC_EVENT_RE = re.compile(r"^\[BIT-\d+\]\s+\S+.*smoke test", re.IGNORECASE)
# Accepts both the bracketed form (`[BIT-30527] ... smoke test`) and the bare form
# (`BIT-32663 smoke test`), matching the ingest noise policy `_BIT_ID_SMOKE_PROBE_RE`
# (BIT-32681). Anchored to start so a real error mentioning the phrase mid-sentence is not
# misclassified.
_SYNTHETIC_EVENT_RE = re.compile(r"^\[?BIT-\d+\]?\s+.*smoke test", re.IGNORECASE)
# ---------------------------------------------------------------------------
# Env helpers