merge: unify GitHub main into Gitea main (0pt)
CI (SIAX Cloud) / quality (push) Successful in 38s
CI (SIAX Cloud) / security (push) Successful in 17s

Merges github/main (6 commits: 17-bug audit fix, CI quality gate,
.env.example + .gitignore fix, missing platform clients + registry
services, docs accuracy overhaul) into gitea/main (8 commits: Iceberg
write boundary + live ST0RE verification, lakehouse mapping routes,
Waves 1-4 foundational hardening).

16 conflicts. Both sides had independently written the four
src/clients/*.ts and the two registry services, so those are combined
rather than picked:

- st0re-client.ts: GitHub's endpoint wins on evidence. POST goes to
  /v1/st0re/artifacts/register, not /v1/st0re/artifacts -- verified in
  sax3l/st0re src/api/routes/artifacts.ts, where the bare path is a
  GET-only list route. Gitea's URL normalisation, error-body text and
  mock kept.
- n0d-client.ts: field is `status`, not `state`, with N0D's real 13-state
  union -- verified in sax3l/n0d packages/schemas/n0d.job.schema.json,
  which says explicitly not to add "succeeded". Gitea's mock echo,
  URL normalisation and error-body text kept.
- cl0ud-client.ts: Gitea's fail-closed HTTP normalisation kept (a 200
  with no `decision` reads as "deny", not as a silent allow). GitHub's
  PolicyDecision/PolicyDecisionValue naming kept; PolicyResult retained
  as an alias.
- aud0-client.ts: permissive union of both input types (optional
  payload/metadata/correlation_id), GitHub's echo return, Gitea's URL
  normalisation and error-body text, plus a JSON-parse fallback so a
  successful POST with an empty body does not throw.
- dataset-service.ts / source-service.ts: GitHub's record/DTO split and
  event naming (0pt.source_created / 0pt.create_source, which the merged
  docs already reference) plus Gitea's name validation, description /
  created_by fields and actor_id derivation. List filters are the union.
- lakehouse mapping routes: GitHub's shared lakehouse-mapping-registry
  singletons (without which every write 400'd "mapping not found") AND
  Gitea's Zod parseBody validation. Both, not either.
- src/types/source.ts, src/types/dataset.ts: unions of both vocabularies;
  GitHub's `access` legal-sourcing field kept.
- .env.example: GitHub's audited inventory plus Gitea's Zitadel /
  AUTH_ENFORCE block.
- CLAUDE.md, docs/ICEBERG_WRITE_BOUNDARY.md: GitHub's corrections kept,
  Gitea's live-verification kept and marked as superseding the
  "would 400 outright" finding (Gitea had already added the required
  X-Tenant-Id/X-Actor-Id headers).
- pnpm-lock.yaml: regenerated with pnpm 9.15.9, not merged.

Also corrects CLAUDE.md's claim that the banned services/scrapers stack
was "since removed" -- the removal PR is open, not merged, and this
branch inherits that code from Gitea main. Nothing here resurrects,
extends or re-wires any of it; services/scrapers/ is byte-identical to
Gitea main.

Verified on the merged tree: typecheck (src/ + tests/) clean;
17 test files, 121 passed, 1 skipped (the realinfra test skipping
honestly on ST0RE HTTP 401), 0 failures. Gitea main baseline was the
same 121/1; GitHub main baseline could not even `pnpm install`
("packages field missing or empty") -- Gitea's pnpm-workspace.yaml fix
resolves that. Whole-repo `typecheck:app` reports 9 errors, an identical
set to Gitea main's baseline, so it is advisory in both CI workflows
rather than deleted. Lint: 16 problems, identical to Gitea baseline.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Claude (SIAX platform session)
2026-07-28 12:38:01 +02:00
co-authored by Claude Opus 5
58 changed files with 2785 additions and 610 deletions
+85 -52
View File
@@ -1,60 +1,67 @@
/**
* 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`).
* Owns 0pt.dataset.schema.v1 — the registry of 0pt datasets (raw / structured
* / enriched / curated / feature / derived outputs). This is the thing
* `DatasetIcebergMappingService` (src/services/dataset-iceberg-mapping-service.ts)
* and `IcebergWriteService` (src/services/iceberg-write-service.ts) look a
* `dataset_id` up against before pointing an Iceberg table mapping or a write
* at it.
*
* 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)
* Deliberately small: it is a reference/registry entry, NOT dataset content,
* schema, or quality state — see docs/ICEBERG_WRITE_BOUNDARY.md for that
* boundary. In-memory reference implementation (same convention as the other
* 0pt services in this repo; a real deployment backs this with `opt_datasets`).
*
* In-memory scope: each `new DatasetService()` owns its own registry, the same
* pre-existing limitation source-service.ts and every other P0 registry
* service documents (docs/P0_QUERY_SOURCE_FLOW.md's "Known gaps"). Callers
* that need a shared view across API routes pass an existing instance in via
* the `datasetService` constructor option — see
* src/services/lakehouse-mapping-registry.ts, which does exactly that for the
* whole app/api/0pt/lakehouse/mappings route group.
*
* 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";
import type { Dataset, DatasetStatus, DatasetType, CreateDatasetInput } from "../types/dataset";
export type DatasetType = "raw" | "enriched" | "curated" | "feature" | "derived";
export type DatasetStatus = "active" | "deprecated" | "archived";
// Re-exported so the historical `import { Dataset, DatasetType, ... } from
// "./dataset-service"` call shape keeps working alongside the canonical
// `../types/dataset` module.
export type { Dataset, DatasetStatus, DatasetType, CreateDatasetInput };
/** Alias so both historical input-type names resolve to the same shape. */
export type RegisterDatasetInput = CreateDatasetInput;
export interface Dataset {
/**
* Storage shape: nullable columns, exactly as the eventual `opt_datasets`
* table would hold them. `toDataset()` converts back to the `Dataset` DTO.
*/
interface DatasetRecord {
dataset_id: string;
tenant_id: string;
project_id: string;
name: string;
dataset_type: DatasetType;
description?: string;
status: DatasetStatus;
correlation_id?: string;
dataset_type: string;
status: string;
description: string | null;
correlation_id: string | null;
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;
updated_at: string | null;
created_by: string | null;
}
export class DatasetService {
private datasets: Map<string, Dataset> = new Map();
private datasets: Map<string, DatasetRecord> = new Map();
private aud0: Aud0Client;
constructor(aud0BaseUrl?: string) {
this.aud0 = createAud0Client(aud0BaseUrl);
}
async registerDataset(input: RegisterDatasetInput): Promise<Dataset> {
async registerDataset(input: CreateDatasetInput): Promise<Dataset> {
if (this.datasets.has(input.dataset_id)) {
throw new Error(`Dataset ${input.dataset_id} already exists`);
}
@@ -63,50 +70,76 @@ export class DatasetService {
}
const now = new Date().toISOString();
const dataset: Dataset = {
const record: DatasetRecord = {
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,
description: input.description ?? null,
correlation_id: input.correlation_id ?? null,
created_at: now,
created_by: input.created_by,
updated_at: null,
created_by: input.created_by ?? null,
};
this.datasets.set(dataset.dataset_id, dataset);
this.datasets.set(record.dataset_id, record);
// 0pt.dataset_registered -- same "no mutation without an evented trail"
// doctrine every other P0 registry service in this repo follows
// (SourceService.createSource, SourceRatePolicyService.createSourceRatePolicy).
await this.aud0.ingestEvent({
event_id: `evt_0pt_dataset_registered_${dataset.dataset_id}`,
event_id: `evt_0pt_dataset_registered_${record.dataset_id}`,
event_type: "0pt.dataset_registered",
tenant_id: dataset.tenant_id,
project_id: dataset.project_id,
actor_id: dataset.created_by ?? "system",
tenant_id: record.tenant_id,
project_id: record.project_id,
actor_id: record.created_by ?? "system",
app_id: "0pt",
capability_id: "0pt.register_dataset",
resource_type: "dataset",
resource_id: dataset.dataset_id,
resource_id: record.dataset_id,
risk_level: "L2",
payload: { dataset_type: dataset.dataset_type, name: dataset.name },
payload: { name: record.name, dataset_type: record.dataset_type },
created_at: now,
correlation_id: dataset.correlation_id,
correlation_id: record.correlation_id ?? undefined,
});
return dataset;
return this.toDataset(record);
}
async getDataset(datasetId: string): Promise<Dataset> {
const dataset = this.datasets.get(datasetId);
if (!dataset) throw new Error(`Dataset ${datasetId} not found`);
return dataset;
const record = this.datasets.get(datasetId);
if (!record) throw new Error(`Dataset ${datasetId} not found`);
return this.toDataset(record);
}
async listDatasets(filter?: { tenant_id?: string; project_id?: string; dataset_type?: DatasetType }): Promise<Dataset[]> {
async listDatasets(filter?: {
tenant_id?: string;
project_id?: string;
dataset_type?: DatasetType;
status?: DatasetStatus;
}): 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;
if (filter?.tenant_id) results = results.filter((r) => r.tenant_id === filter.tenant_id);
if (filter?.project_id) results = results.filter((r) => r.project_id === filter.project_id);
if (filter?.dataset_type) results = results.filter((r) => r.dataset_type === filter.dataset_type);
if (filter?.status) results = results.filter((r) => r.status === filter.status);
return results.map((r) => this.toDataset(r));
}
private toDataset(r: DatasetRecord): Dataset {
return {
dataset_id: r.dataset_id,
tenant_id: r.tenant_id,
project_id: r.project_id,
name: r.name,
dataset_type: r.dataset_type as DatasetType,
status: r.status as DatasetStatus,
description: r.description ?? undefined,
correlation_id: r.correlation_id ?? undefined,
created_at: r.created_at,
updated_at: r.updated_at ?? undefined,
created_by: r.created_by ?? undefined,
};
}
}
+5 -1
View File
@@ -18,7 +18,11 @@
* `writeExternalRecord` runs, a human has already approved the write -- this
* service still re-checks CL0UD policy (per docs/PRODUCT_PLAN.md section
* 4.1's hard rule that CL0UD is always re-consulted, the same rule
* quality-check-service.ts/document-extraction-service.ts already follow),
* document-extraction-service.ts already follows -- confirmed by grepping
* this repo's src/services/ for evaluatePolicy()/Cl0udClient usage; the
* only other real service that does the same is iceberg-write-service.ts.
* An earlier version of this comment also cited `quality-check-service.ts`
* here; that file does not exist anywhere in this repo),
* but does not itself re-verify the upstream Approval record (ACT0 owns
* approvals; 0pt's own capability boundary is "did CL0UD say yes for THIS
* call", same separation of concerns every other 0pt service in this repo
@@ -0,0 +1,19 @@
import { DatasetService } from "./dataset-service";
import { DatasetIcebergMappingService } from "./dataset-iceberg-mapping-service";
import { IcebergWriteService } from "./iceberg-write-service";
/**
* Shared singleton instances for the lakehouse-mapping route group
* (app/api/0pt/lakehouse/mappings/*). Previously each route file in that
* group instantiated its own DatasetService/DatasetIcebergMappingService/
* IcebergWriteService, so a mapping created via POST /mappings was invisible
* to GET /mappings/{id} and to POST /mappings/{id}/writes within the same
* server process (each held a distinct in-memory Map). Constructing all
* three here once, wired together, and importing them everywhere fixes that
* -- matching the in-memory-per-module convention this repo already uses
* elsewhere (see document-capture-service.ts's own singleton note), just
* applied consistently across this route group instead of per-file.
*/
export const datasetService = new DatasetService();
export const mappingService = new DatasetIcebergMappingService({ datasetService });
export const writeService = new IcebergWriteService({ datasetService, mappingService });
+96 -37
View File
@@ -1,25 +1,53 @@
/**
* 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).
* Owns 0pt.source.schema.v1 — the per-tenant registry of upstream data
* sources (databases, crawl domains, APIs, file drops). This is the registry
* `SourceQueryService.querySource()` (src/services/source-query-service.ts)
* and `SourceRatePolicyService` (src/services/source-rate-policy-service.ts)
* both look a `source_id` up against — see docs/P0_QUERY_SOURCE_FLOW.md.
*
* Consumed by:
* - source-query-service.ts (getSource -> is this source queryable?)
* - source-rate-policy-service.ts (getSource -> does the source exist?)
* Deliberately small and in-memory, same "pure core, thin registry" shape
* every other P0 service in this repo already uses; a real deployment backs
* this with `opt_sources`. In-memory scope: each `new SourceService()` owns
* its own registry — the pre-existing limitation docs/P0_QUERY_SOURCE_FLOW.md's
* "Known gaps" section documents (a Source registered via one API route module
* is not yet visible to another route module in the same running process).
* Callers that need a shared view pass an existing instance in via the
* `sourceService` constructor option, exactly like SourceQueryService and
* SourceRatePolicyService already do.
*
* 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.
* Registering a source emits a best-effort AUD0 `0pt.source_created` event —
* the same "no mutation without an evented trail" doctrine every other P0
* registry service follows. 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";
import type { CreateSourceInput, Source, SourceStatus, SourceType } from "../types/source";
/**
* Storage shape: nullable columns, exactly as the eventual `opt_sources` table
* would hold them. `toSource()` converts back to the `Source` DTO (undefined
* rather than null) so callers never have to handle both.
*/
interface SourceRecord {
source_id: string;
tenant_id: string;
project_id: string;
source_type: string;
name: string;
adapter_id: string | null;
access: string | null;
description: string | null;
status: string;
correlation_id: string | null;
created_at: string;
updated_at: string | null;
created_by: string | null;
}
export class SourceService {
private sources: Map<string, Source> = new Map();
private sources: Map<string, SourceRecord> = new Map();
private aud0: Aud0Client;
constructor(aud0BaseUrl?: string) {
@@ -35,51 +63,82 @@ export class SourceService {
}
const now = new Date().toISOString();
const source: Source = {
const record: SourceRecord = {
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,
adapter_id: input.adapter_id ?? null,
access: input.access ?? null,
description: input.description ?? null,
status: input.status ?? "active",
correlation_id: input.correlation_id,
correlation_id: input.correlation_id ?? null,
created_at: now,
created_by: input.created_by,
updated_at: null,
created_by: input.created_by ?? null,
};
this.sources.set(source.source_id, source);
this.sources.set(record.source_id, record);
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",
event_id: `evt_0pt_source_created_${record.source_id}`,
event_type: "0pt.source_created",
tenant_id: record.tenant_id,
project_id: record.project_id,
actor_id: record.created_by ?? "system",
app_id: "0pt",
capability_id: "0pt.register_source",
capability_id: "0pt.create_source",
resource_type: "source",
resource_id: source.source_id,
resource_id: record.source_id,
risk_level: "L2",
payload: { source_type: source.source_type, adapter_id: source.adapter_id ?? null, name: source.name },
payload: {
source_type: record.source_type,
name: record.name,
adapter_id: record.adapter_id,
access: record.access,
},
created_at: now,
correlation_id: source.correlation_id,
correlation_id: record.correlation_id ?? undefined,
});
return source;
return this.toSource(record);
}
async getSource(sourceId: string): Promise<Source> {
const source = this.sources.get(sourceId);
if (!source) throw new Error(`Source ${sourceId} not found`);
return source;
const record = this.sources.get(sourceId);
if (!record) throw new Error(`Source ${sourceId} not found`);
return this.toSource(record);
}
async listSources(filter?: { tenant_id?: string; project_id?: string; source_type?: Source["source_type"] }): Promise<Source[]> {
async listSources(filter?: {
tenant_id?: string;
project_id?: string;
source_type?: SourceType;
status?: SourceStatus;
}): 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;
if (filter?.tenant_id) results = results.filter((r) => r.tenant_id === filter.tenant_id);
if (filter?.project_id) results = results.filter((r) => r.project_id === filter.project_id);
if (filter?.source_type) results = results.filter((r) => r.source_type === filter.source_type);
if (filter?.status) results = results.filter((r) => r.status === filter.status);
return results.map((r) => this.toSource(r));
}
private toSource(r: SourceRecord): Source {
return {
source_id: r.source_id,
tenant_id: r.tenant_id,
project_id: r.project_id,
source_type: r.source_type as SourceType,
name: r.name,
adapter_id: r.adapter_id ?? undefined,
access: (r.access as Source["access"]) ?? undefined,
description: r.description ?? undefined,
status: r.status as SourceStatus,
correlation_id: r.correlation_id ?? undefined,
created_at: r.created_at,
updated_at: r.updated_at ?? undefined,
created_by: r.created_by ?? undefined,
};
}
}