feat(foundation): Wave 3 integrity/persistence/build fixes
CI (SIAX Cloud) / security (push) Failing after 28s
CI (SIAX Cloud) / quality (push) Failing after 38s

This commit is contained in:
SIAX Foundation Bot
2026-07-25 13:54:36 +02:00
parent bd5e309851
commit 844220d9f5
18 changed files with 2616 additions and 38 deletions
+98
View File
@@ -0,0 +1,98 @@
/**
* src/clients/aud0-client.ts
* ===========================
* 0pt's thin client for emitting append-only events + lineage edges to AUD0
* (the SIAX Cloud system of record). Two methods:
* - ingestEvent -> POST {baseUrl}/v1/aud0/events
* - ingestLineageEvent -> POST {baseUrl}/v1/aud0/lineage/events
*
* Convention (identical to cl0ud-client.ts / n0d-client.ts / st0re-client.ts
* / st0re-lakehouse-client.ts): when no base URL is configured the client is
* a NO-OP — it does not attempt any network call. AUD0 is a best-effort,
* out-of-band audit sink for 0pt; a missing AUD0_URL (unit tests, local dev)
* must not turn every capability call into a failed fetch to `undefined`.
* When a base URL IS configured, events are POSTed as-is (the event object is
* the wire body) with `Content-Type: application/json`.
*/
export interface Aud0Event {
event_id: string;
event_type: string;
tenant_id: string;
project_id: string;
actor_id: string;
app_id: string;
capability_id: string;
resource_type: string;
resource_id: string;
/** Risk level L0–L5 per the SIAX Cloud risk taxonomy. */
risk_level: string;
payload: Record<string, unknown>;
created_at: string;
correlation_id?: string;
}
export interface Aud0LineageEvent {
lineage_event_id: string;
tenant_id: string;
project_id: string;
app_id: string;
capability_id: string;
source_type: string;
source_id: string;
target_type: string;
target_id: string;
/** e.g. "produced" | "derived_from" | "stored_as". */
lineage_type: string;
metadata: Record<string, unknown>;
created_at: string;
correlation_id?: string;
}
export interface Aud0Client {
ingestEvent(event: Aud0Event): Promise<void>;
ingestLineageEvent(event: Aud0LineageEvent): Promise<void>;
}
export function createAud0Client(baseUrl?: string): Aud0Client {
if (!baseUrl) return new NoopAud0Client();
return new HttpAud0Client(baseUrl);
}
/** No AUD0_URL configured: audit emission is a no-op (see module doc comment). */
class NoopAud0Client implements Aud0Client {
async ingestEvent(_event: Aud0Event): Promise<void> {
/* intentional no-op */
}
async ingestLineageEvent(_event: Aud0LineageEvent): Promise<void> {
/* intentional no-op */
}
}
class HttpAud0Client implements Aud0Client {
private readonly baseUrl: string;
constructor(baseUrl: string) {
// Normalize so `${baseUrl}/v1/...` never produces a double slash.
this.baseUrl = baseUrl.replace(/\/+$/, "");
}
async ingestEvent(event: Aud0Event): Promise<void> {
await this.post("/v1/aud0/events", event);
}
async ingestLineageEvent(event: Aud0LineageEvent): Promise<void> {
await this.post("/v1/aud0/lineage/events", event);
}
private async post(path: string, body: unknown): Promise<void> {
const res = await fetch(`${this.baseUrl}${path}`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(body),
});
if (!res.ok) {
throw new Error(`AUD0 ${path} error: ${res.status} ${await res.text().catch(() => "")}`);
}
}
}
+79
View File
@@ -0,0 +1,79 @@
/**
* src/clients/cl0ud-client.ts
* ============================
* 0pt's client for the CL0UD control-plane policy decision point:
* evaluatePolicy -> POST {baseUrl}/v1/cl0ud/policies/evaluate
*
* Every side-effecting 0pt capability re-consults CL0UD before acting (per
* docs/PRODUCT_PLAN.md §4.1), so this is the single choke point for that.
*
* Convention (identical to aud0-client.ts / n0d-client.ts / st0re-client.ts):
* when no base URL is configured the client runs in LOCAL PASS-THROUGH mode —
* it returns a deterministic `allow` decision WITHOUT any network call, so
* unit tests and local dev are hermetic. This is a dev-mode default only; any
* real deployment MUST set CL0UD_URL so decisions come from the real policy
* engine. The pass-through never invents a `deny`/`approval_required` — it
* only ever allows, and it stamps a clearly local-looking decision id.
*/
import crypto from "crypto";
export type PolicyDecision = "allow" | "deny" | "approval_required";
export interface EvaluatePolicyInput {
tenant_id: string;
project_id: string;
actor_id: string;
capability_id: string;
resource_type: string;
resource_id: string;
/** Risk level L0–L5 per the SIAX Cloud risk taxonomy. */
risk_level: string;
correlation_id?: string;
}
export interface PolicyResult {
decision: PolicyDecision;
decision_id: string;
reason?: string;
}
export interface Cl0udClient {
evaluatePolicy(input: EvaluatePolicyInput): Promise<PolicyResult>;
}
export function createCl0udClient(baseUrl?: string): Cl0udClient {
if (!baseUrl) return new LocalAllowCl0udClient();
return new HttpCl0udClient(baseUrl);
}
/** No CL0UD_URL configured: allow-only local pass-through (see module doc comment). */
class LocalAllowCl0udClient implements Cl0udClient {
async evaluatePolicy(_input: EvaluatePolicyInput): Promise<PolicyResult> {
return { decision: "allow", decision_id: `pdec_local_${crypto.randomUUID()}` };
}
}
class HttpCl0udClient implements Cl0udClient {
private readonly baseUrl: string;
constructor(baseUrl: string) {
this.baseUrl = baseUrl.replace(/\/+$/, "");
}
async evaluatePolicy(input: EvaluatePolicyInput): Promise<PolicyResult> {
const res = await fetch(`${this.baseUrl}/v1/cl0ud/policies/evaluate`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(input),
});
if (!res.ok) {
throw new Error(`CL0UD policy evaluate error: ${res.status} ${await res.text().catch(() => "")}`);
}
const body = (await res.json()) as Partial<PolicyResult>;
return {
decision: (body.decision ?? "deny") as PolicyDecision,
decision_id: body.decision_id ?? `pdec_${crypto.randomUUID()}`,
reason: body.reason,
};
}
}
+84
View File
@@ -0,0 +1,84 @@
/**
* src/clients/n0d-client.ts
* ==========================
* 0pt's client for REQUESTING heavy compute jobs from N0D (the Compute OS).
* 0pt never executes heavy work in-process — it submits an N0D job and holds
* only the returned `job_id` (docs/11-lakehouse-write-plan.md item 7,
* docs/P0_QUERY_SOURCE_FLOW.md):
* createJob -> POST {baseUrl}/v1/n0d/jobs
*
* Convention (identical to aud0-client.ts / cl0ud-client.ts / st0re-client.ts
* / st0re-lakehouse-client.ts): when no base URL is configured the client
* returns a deterministic in-memory MOCK job (id prefixed "mock_job_") with
* NO network call, so unit tests stay hermetic. A real deployment sets
* N0D_URL to submit against the live scheduler.
*/
import crypto from "crypto";
export interface CreateJobInput {
tenant_id: string;
project_id: string;
job_type: string;
capability_id: string;
requested_by_app_id: string;
requested_by_actor_id: string;
input_artifact_ids?: string[];
input_dataset_ids?: string[];
output_artifact_type: string;
requires_backbone: boolean;
requires_gpu: boolean;
required_node_roles: string[];
resource_profile: string;
/** Risk level L0–L5 per the SIAX Cloud risk taxonomy. */
risk_level: string;
correlation_id?: string;
}
export type N0dJobState = "queued" | "running" | "succeeded" | "failed" | "cancelled";
export interface N0dJob extends CreateJobInput {
job_id: string;
state: N0dJobState;
created_at: string;
}
export interface N0dClient {
createJob(input: CreateJobInput): Promise<N0dJob>;
}
export function createN0dClient(baseUrl?: string): N0dClient {
if (!baseUrl) return new MockN0dClient();
return new HttpN0dClient(baseUrl);
}
/** No N0D_URL configured: returns a deterministic mock job (see module doc comment). */
class MockN0dClient implements N0dClient {
async createJob(input: CreateJobInput): Promise<N0dJob> {
return {
...input,
job_id: `mock_job_${crypto.randomUUID()}`,
state: "queued",
created_at: new Date().toISOString(),
};
}
}
class HttpN0dClient implements N0dClient {
private readonly baseUrl: string;
constructor(baseUrl: string) {
this.baseUrl = baseUrl.replace(/\/+$/, "");
}
async createJob(input: CreateJobInput): Promise<N0dJob> {
const res = await fetch(`${this.baseUrl}/v1/n0d/jobs`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(input),
});
if (!res.ok) {
throw new Error(`N0D create-job error: ${res.status} ${await res.text().catch(() => "")}`);
}
return (await res.json()) as N0dJob;
}
}
+93
View File
@@ -0,0 +1,93 @@
/**
* src/clients/st0re-client.ts
* ============================
* 0pt's client for the generic ST0RE Artifact registry (snake_case wire
* shape), distinct from `./st0re-lakehouse-client.ts` (the camelCase
* /v1/st0re/lakehouse/* table registry). This one registers an artifact's
* METADATA — a pointer to where the bytes live (provider/bucket/key/region)
* plus content-type/size/checksum/retention/PII/residency:
* createArtifact -> POST {baseUrl}/v1/st0re/artifacts
*
* KNOWN GAP (documented in src/adapters/local-blob-store.ts): ST0RE does not
* yet expose a raw-bytes upload endpoint for 0pt to call, so the actual bytes
* are persisted by LocalBlobStore (interim) and only the resulting location
* is registered here as metadata.
*
* Convention (identical to aud0-client.ts / cl0ud-client.ts / n0d-client.ts /
* st0re-lakehouse-client.ts): when no base URL is configured the client
* returns a deterministic in-memory MOCK artifact (id prefixed
* "mock_artifact_") with NO network call, so unit tests stay hermetic. A real
* deployment sets ST0RE_URL to register against the live artifact registry.
*/
import crypto from "crypto";
export interface St0reObjectLocation {
provider: string;
bucket: string;
key: string;
region?: string;
}
export interface CreateArtifactInput {
tenant_id: string;
project_id: string;
artifact_type: string;
app_id: string;
produced_by: string;
object_location: St0reObjectLocation;
content_type: string;
size_bytes: number;
checksum_sha256: string;
/** "none" | "low" | "medium" | "high" — kept as string to stay tolerant of ST0RE's own vocabulary. */
pii_level: string;
retention_policy: string;
data_residency: string;
/** Risk level L0–L5 per the SIAX Cloud risk taxonomy. */
risk_level: string;
correlation_id?: string;
}
export interface St0reArtifact extends CreateArtifactInput {
artifact_id: string;
created_at: string;
}
export interface St0reClient {
createArtifact(input: CreateArtifactInput): Promise<St0reArtifact>;
}
export function createSt0reClient(baseUrl?: string): St0reClient {
if (!baseUrl) return new MockSt0reClient();
return new HttpSt0reClient(baseUrl);
}
/** No ST0RE_URL configured: returns a deterministic mock artifact (see module doc comment). */
class MockSt0reClient implements St0reClient {
async createArtifact(input: CreateArtifactInput): Promise<St0reArtifact> {
return {
...input,
artifact_id: `mock_artifact_${crypto.randomUUID()}`,
created_at: new Date().toISOString(),
};
}
}
class HttpSt0reClient implements St0reClient {
private readonly baseUrl: string;
constructor(baseUrl: string) {
this.baseUrl = baseUrl.replace(/\/+$/, "");
}
async createArtifact(input: CreateArtifactInput): Promise<St0reArtifact> {
const res = await fetch(`${this.baseUrl}/v1/st0re/artifacts`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(input),
});
if (!res.ok) {
throw new Error(`ST0RE create-artifact error: ${res.status} ${await res.text().catch(() => "")}`);
}
return (await res.json()) as St0reArtifact;
}
}
+112
View File
@@ -0,0 +1,112 @@
/**
* src/services/dataset-service.ts
* ================================
* Owns 0pt.dataset.schema.v1 — the registry of 0pt datasets (raw / enriched /
* curated / feature outputs). In-memory reference implementation (same
* convention as the other 0pt services in this repo; a real deployment backs
* this with `opt_datasets`).
*
* Consumed by:
* - dataset-iceberg-mapping-service.ts (getDataset -> does the dataset exist
* before we map it to an Iceberg table?)
* - iceberg-write-service.ts (getDataset -> guard the write path)
*
* Registering a dataset emits a best-effort AUD0 `0pt.dataset_registered`
* event; with no AUD0_URL configured that emission is a no-op (see
* aud0-client.ts), so this stays hermetic in tests and local dev.
*/
import { createAud0Client, type Aud0Client } from "../clients/aud0-client";
export type DatasetType = "raw" | "enriched" | "curated" | "feature" | "derived";
export type DatasetStatus = "active" | "deprecated" | "archived";
export interface Dataset {
dataset_id: string;
tenant_id: string;
project_id: string;
name: string;
dataset_type: DatasetType;
description?: string;
status: DatasetStatus;
correlation_id?: string;
created_at: string;
updated_at?: string;
created_by?: string;
}
export interface RegisterDatasetInput {
dataset_id: string;
tenant_id: string;
project_id: string;
name: string;
dataset_type: DatasetType;
description?: string;
status?: DatasetStatus;
correlation_id?: string;
created_by?: string;
}
export class DatasetService {
private datasets: Map<string, Dataset> = new Map();
private aud0: Aud0Client;
constructor(aud0BaseUrl?: string) {
this.aud0 = createAud0Client(aud0BaseUrl);
}
async registerDataset(input: RegisterDatasetInput): Promise<Dataset> {
if (this.datasets.has(input.dataset_id)) {
throw new Error(`Dataset ${input.dataset_id} already exists`);
}
if (!input.name) {
throw new Error("name is required");
}
const now = new Date().toISOString();
const dataset: Dataset = {
dataset_id: input.dataset_id,
tenant_id: input.tenant_id,
project_id: input.project_id,
name: input.name,
dataset_type: input.dataset_type,
description: input.description,
status: input.status ?? "active",
correlation_id: input.correlation_id,
created_at: now,
created_by: input.created_by,
};
this.datasets.set(dataset.dataset_id, dataset);
await this.aud0.ingestEvent({
event_id: `evt_0pt_dataset_registered_${dataset.dataset_id}`,
event_type: "0pt.dataset_registered",
tenant_id: dataset.tenant_id,
project_id: dataset.project_id,
actor_id: dataset.created_by ?? "system",
app_id: "0pt",
capability_id: "0pt.register_dataset",
resource_type: "dataset",
resource_id: dataset.dataset_id,
risk_level: "L2",
payload: { dataset_type: dataset.dataset_type, name: dataset.name },
created_at: now,
correlation_id: dataset.correlation_id,
});
return dataset;
}
async getDataset(datasetId: string): Promise<Dataset> {
const dataset = this.datasets.get(datasetId);
if (!dataset) throw new Error(`Dataset ${datasetId} not found`);
return dataset;
}
async listDatasets(filter?: { tenant_id?: string; project_id?: string; dataset_type?: DatasetType }): Promise<Dataset[]> {
let results = Array.from(this.datasets.values());
if (filter?.tenant_id) results = results.filter((d) => d.tenant_id === filter.tenant_id);
if (filter?.project_id) results = results.filter((d) => d.project_id === filter.project_id);
if (filter?.dataset_type) results = results.filter((d) => d.dataset_type === filter.dataset_type);
return results;
}
}
+85
View File
@@ -0,0 +1,85 @@
/**
* src/services/source-service.ts
* ===============================
* Owns 0pt.source.schema.v1 — the registry of upstream data sources
* (databases, crawl domains, APIs, file drops). In-memory reference
* implementation (same convention as the other 0pt services in this repo:
* each API route file constructs its own instance; a real deployment backs
* this with `opt_sources` — sql/002_p0_dataset_quality.sql).
*
* Consumed by:
* - source-query-service.ts (getSource -> is this source queryable?)
* - source-rate-policy-service.ts (getSource -> does the source exist?)
*
* Registering a source emits a best-effort AUD0 `0pt.source_registered`
* event; with no AUD0_URL configured that emission is a no-op (see
* aud0-client.ts), so this stays hermetic in tests and local dev.
*/
import { createAud0Client, type Aud0Client } from "../clients/aud0-client";
import type { CreateSourceInput, Source } from "../types/source";
export class SourceService {
private sources: Map<string, Source> = new Map();
private aud0: Aud0Client;
constructor(aud0BaseUrl?: string) {
this.aud0 = createAud0Client(aud0BaseUrl);
}
async createSource(input: CreateSourceInput): Promise<Source> {
if (this.sources.has(input.source_id)) {
throw new Error(`Source ${input.source_id} already exists`);
}
if (!input.name) {
throw new Error("name is required");
}
const now = new Date().toISOString();
const source: Source = {
source_id: input.source_id,
tenant_id: input.tenant_id,
project_id: input.project_id,
source_type: input.source_type,
name: input.name,
adapter_id: input.adapter_id,
description: input.description,
status: input.status ?? "active",
correlation_id: input.correlation_id,
created_at: now,
created_by: input.created_by,
};
this.sources.set(source.source_id, source);
await this.aud0.ingestEvent({
event_id: `evt_0pt_source_registered_${source.source_id}`,
event_type: "0pt.source_registered",
tenant_id: source.tenant_id,
project_id: source.project_id,
actor_id: source.created_by ?? "system",
app_id: "0pt",
capability_id: "0pt.register_source",
resource_type: "source",
resource_id: source.source_id,
risk_level: "L2",
payload: { source_type: source.source_type, adapter_id: source.adapter_id ?? null, name: source.name },
created_at: now,
correlation_id: source.correlation_id,
});
return source;
}
async getSource(sourceId: string): Promise<Source> {
const source = this.sources.get(sourceId);
if (!source) throw new Error(`Source ${sourceId} not found`);
return source;
}
async listSources(filter?: { tenant_id?: string; project_id?: string; source_type?: Source["source_type"] }): Promise<Source[]> {
let results = Array.from(this.sources.values());
if (filter?.tenant_id) results = results.filter((s) => s.tenant_id === filter.tenant_id);
if (filter?.project_id) results = results.filter((s) => s.project_id === filter.project_id);
if (filter?.source_type) results = results.filter((s) => s.source_type === filter.source_type);
return results;
}
}
+45
View File
@@ -0,0 +1,45 @@
/**
* src/types/source.ts
* =====================
* 0pt.source.schema.v1 — a registered upstream data source (a database, a
* crawlable web domain, an API, a file drop, …). Owned by SourceService
* (src/services/source-service.ts); referenced by SourceRatePolicy
* (src/types/source-rate-policy.ts) and by the synchronous query path
* (src/services/source-query-service.ts), which reads `source_type` +
* `adapter_id` to decide whether a Source is queryable.
*
* `adapter_id` is the seam that lets a "database" source name the concrete
* driver 0pt should use for it (today only "fabric_onelake_sql" is wired on
* the synchronous path — see source-query-service.ts).
*/
export type SourceType = "database" | "file" | "web" | "api" | "stream" | "manual";
export type SourceStatus = "active" | "paused" | "archived";
export interface Source {
source_id: string;
tenant_id: string;
project_id: string;
source_type: SourceType;
name: string;
/** Concrete driver id for this source, e.g. "fabric_onelake_sql". Optional: not every source is directly queryable. */
adapter_id?: string;
description?: string;
status: SourceStatus;
correlation_id?: string;
created_at: string;
updated_at?: string;
created_by?: string;
}
export interface CreateSourceInput {
source_id: string;
tenant_id: string;
project_id: string;
source_type: SourceType;
name: string;
adapter_id?: string;
description?: string;
status?: SourceStatus;
correlation_id?: string;
created_by?: string;
}