fix: add missing 0pt platform clients + registry services, wire test/typecheck scripts

The 0pt data-engine build has been broken on main since 2026-07-08 (commit
c897311). document-capture-service.ts, document-extraction-service.ts,
source-query-service.ts, external-writeback-service.ts (and, more recently,
dataset-iceberg-mapping-service.ts, iceberg-write-service.ts,
source-rate-policy-service.ts) all import six platform client modules and two
registry services that were never committed: src/clients/{aud0,cl0ud,n0d,
st0re}-client.ts, src/services/{dataset,source}-service.ts, plus
src/types/{dataset,source}.ts. `next build` failed with 17 "Module not found"
errors, and every route under app/api/0pt/* returned HTTP 500 in dev with the
Turbopack compile error leaked straight into the JSON response body.

This adds the missing files, following the same fetch-based client shape
already established by src/clients/st0re-lakehouse-client.ts (thin interface,
HTTP implementation, deterministic in-memory mock used when no base URL is
configured) and the same "pure core, thin in-memory registry, AUD0-evented
mutation" shape the existing SourceRatePolicyService/DatasetIcebergMappingService
already use for DatasetService/SourceService. Each new client mock is
documented as a mock/degrade path, never a fabricated success, per this
repo's CLAUDE.md honesty doctrine.

Also wires up "typecheck" and "test" npm scripts (tsc --noEmit / vitest run)
and adds vitest as a devDependency -- previously `pnpm test` failed
immediately with ERR_PNPM_NO_SCRIPT even though 13 test files (~89 cases)
already existed under tests/p0/.

Verified: `pnpm run typecheck` clean, `pnpm run test` 88 passed / 1 todo
(pre-existing live-ST0RE-only skip), `pnpm run build` exits 0 (39/39 routes
compiled, only the pre-existing intentional optional `mssql` import warning
remains). Re-verified live on port 4097: GET /api/0pt/sources/rate-policies,
GET /api/0pt/lakehouse/mappings, POST /api/0pt/documents/capture, GET
/api/0pt/documents/[id]/extraction, and both GET/POST
/api/0pt/sources/[id]/query now return real application responses (200/400/405)
instead of HTTP 500 with a leaked compile error.

Co-Authored-By: Claude Opus 5 <[email protected]>
This commit is contained in:
Simon Axelsson
2026-07-14 01:16:50 +02:00
co-authored by Claude Opus 5
parent 35b6ec63bf
commit 01cc225ffc
14 changed files with 1711 additions and 3 deletions
+53
View File
@@ -0,0 +1,53 @@
// 0pt.source.schema.v1
//
// A registered data Source that a capability (0pt.query_source today;
// 0pt.create_source / crawl-time source registration in the future) can act
// against. This is a DIFFERENT, newer entity than the static provenance
// catalog in docs/03-data-model.md's `dim_source` table (the ~9-row list of
// national registries served today by GET /api/sources) -- this Source is a
// per-tenant registration of something 0pt can actually connect to (a
// database, a web target, a file drop, an API), carrying an `adapter_id`
// that tells a service layer (e.g. SourceQueryService) which concrete
// adapter implementation to use. See docs/P0_QUERY_SOURCE_FLOW.md and
// src/services/source-query-service.ts, the first real consumer.
//
// `access` mirrors dim_source.access (docs/03-data-model.md) so a Source
// registered here can still be reported against the same legal-sourcing
// vocabulary CLAUDE.md §1 requires everywhere in this repo.
export type SourceType = "web" | "api" | "database" | "file";
export type SourceStatus = "active" | "paused" | "deprecated";
export interface Source {
source_id: string;
tenant_id: string;
project_id: string;
source_type: SourceType;
name: string;
/**
* Identifies which concrete adapter implementation this source is queried
* through (e.g. "fabric_onelake_sql" -- src/adapters/fabric-onelake-adapter.ts).
* Required for source_type "database"; optional/unused for other types
* until they grow a synchronous query path of their own.
*/
adapter_id?: string;
/** Mirrors dim_source.access (docs/03-data-model.md): api | bulk | authorized_web | licensed. */
access?: "api" | "bulk" | "authorized_web" | "licensed";
status: SourceStatus;
correlation_id?: string;
created_at: string;
updated_at?: string;
}
export interface CreateSourceInput {
source_id: string;
tenant_id: string;
project_id: string;
source_type: SourceType;
name: string;
adapter_id?: string;
access?: "api" | "bulk" | "authorized_web" | "licensed";
status?: SourceStatus;
correlation_id?: string;
}