feat(platform): canonical SIAX context/errors + real-contract clients, no prod mock fallback
- src/platform/: SiaxRequestContext + propagation headers + 12 canonical
error codes (documented mirror of cl0ud packages/contract), SiaxError,
resource refs (st0re:artifact:...), and the §3/§10 dependency-mode guard:
production runtime + unconfigured dependency/store => hard
DEPENDENCY_UNAVAILABLE at construction, never silent mock/in-memory.
- src/clients/: all four platform clients rewritten against the REAL wire
contracts verified on sibling main branches this session:
* cl0ud: POST /api/policy/evaluate ({data} envelope, allow+requiresApproval)
- the old /v1/cl0ud/policies/evaluate path never existed on CL0UD
* st0re: camelCase ArtifactInput on /v1/st0re/artifacts/register incl.
X-Tenant-Id/X-Actor-Id + X-Idempotency-Key - the old snake_case body
would have been a 400 against the live registry
* n0d: required_role + resource_requirements + body idempotency_key +
CloudEvents callback_url per n0d createJobSchema; adds getJob/getJobResult
* aud0: /v1/aud0/openlineage is AUD0's only lineage ingest -
/v1/aud0/lineage/events never existed; legacy shape converts to a
spec-shaped OpenLineage RunEvent (deterministic runId dedup)
- src/lineage/: OpenLineage subset types + LineageEmitter (never-throw,
§16 evidence semantics)
- shared SiaxHttp transport: timeouts, typed SiaxError mapping, context
propagation, no raw upstream bodies in errors
Co-Authored-By: Claude Fable 5 <[email protected]>
This commit is contained in:
co-authored by
Claude Fable 5
parent
00a1b3997d
commit
b7038d7675
@@ -0,0 +1,81 @@
|
||||
/**
|
||||
* src/platform/dependency-mode.ts
|
||||
* ================================
|
||||
* THE production mock-fallback kill switch (Master-DoD §3: "Ingen
|
||||
* production-path faller tyst tillbaka till mock/in-memory", §10: "Production
|
||||
* kan inte falla tillbaka till mock").
|
||||
*
|
||||
* Before this module, every platform client in src/clients/* documented the
|
||||
* same convention: "when no base URL is configured the client runs in
|
||||
* LOCAL/MOCK/NOOP mode". That convention is fine for unit tests and local
|
||||
* dev, and it is EXACTLY the silent-fallback failure mode the Master-DoD
|
||||
* forbids in production. This module centralizes the decision so every
|
||||
* factory makes it the same way:
|
||||
*
|
||||
* - production runtime + no URL → throw SiaxError DEPENDENCY_UNAVAILABLE
|
||||
* at CONSTRUCTION time (fail hard, fail early — not on first call).
|
||||
* - non-production + no URL → the factory may return its local/mock
|
||||
* implementation (hermetic tests, local dev).
|
||||
* - URL configured → real HTTP client, any runtime.
|
||||
*
|
||||
* "Production runtime" means NODE_ENV=production, the same switch the
|
||||
* existing auth layer uses (src/auth/context.ts refuses AUTH_ENFORCE=false
|
||||
* under NODE_ENV=production). There is deliberately NO override that lets
|
||||
* production run on mocks: if a deployment genuinely wants a dependency off,
|
||||
* that is a topology decision expressed by NOT calling the capability, never
|
||||
* by a mock silently answering it.
|
||||
*/
|
||||
import { SiaxError } from "./errors";
|
||||
|
||||
/** True when this process is a production runtime. */
|
||||
export function isProductionRuntime(env: NodeJS.ProcessEnv = process.env): boolean {
|
||||
return env.NODE_ENV === "production";
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve a dependency base URL for a client factory.
|
||||
*
|
||||
* Returns the URL (trimmed, no trailing slash) when configured. Returns
|
||||
* `undefined` when unconfigured in a non-production runtime — the caller may
|
||||
* then use its documented local/mock implementation. THROWS
|
||||
* `SiaxError("DEPENDENCY_UNAVAILABLE")` when unconfigured in production.
|
||||
*/
|
||||
export function resolveDependencyBaseUrl(
|
||||
dependency: string,
|
||||
configuredUrl: string | undefined,
|
||||
env: NodeJS.ProcessEnv = process.env
|
||||
): string | undefined {
|
||||
const url = configuredUrl?.trim();
|
||||
if (url) return url.replace(/\/+$/, "");
|
||||
if (isProductionRuntime(env)) {
|
||||
throw new SiaxError(
|
||||
"DEPENDENCY_UNAVAILABLE",
|
||||
dependency,
|
||||
`no base URL configured for required dependency "${dependency}" in a production runtime; ` +
|
||||
`refusing to fall back to a mock/in-memory implementation (Master-DoD §3/§10)`
|
||||
);
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Same decision for stateful stores (Postgres-backed registries): production
|
||||
* with no DATABASE_URL must fail hard rather than serve an in-memory Map.
|
||||
*/
|
||||
export function resolveStoreMode(
|
||||
store: string,
|
||||
databaseUrl: string | undefined,
|
||||
env: NodeJS.ProcessEnv = process.env
|
||||
): { mode: "postgres"; url: string } | { mode: "memory" } {
|
||||
const url = databaseUrl?.trim();
|
||||
if (url) return { mode: "postgres", url };
|
||||
if (isProductionRuntime(env)) {
|
||||
throw new SiaxError(
|
||||
"DEPENDENCY_UNAVAILABLE",
|
||||
store,
|
||||
`no database configured for persistent store "${store}" in a production runtime; ` +
|
||||
`refusing the in-memory fallback (Master-DoD §3/§10)`
|
||||
);
|
||||
}
|
||||
return { mode: "memory" };
|
||||
}
|
||||
Reference in New Issue
Block a user