feat(data-os): TS/Python quality bridge + provenance fields + fault-injection tests
CI (SIAX Cloud) / security (push) Successful in 23s
Security Scan (SIAX Cloud) / security (push) Successful in 22s
CI (SIAX Cloud) / integration (push) Successful in 29s
CI (SIAX Cloud) / quality (push) Successful in 45s
CI (SIAX Cloud) / security (pull_request) Successful in 27s
CI (SIAX Cloud) / integration (pull_request) Successful in 31s
Security Scan (SIAX Cloud) / security (pull_request) Successful in 29s
CI (SIAX Cloud) / quality (pull_request) Successful in 48s
CI (SIAX Cloud) / security (push) Successful in 23s
Security Scan (SIAX Cloud) / security (push) Successful in 22s
CI (SIAX Cloud) / integration (push) Successful in 29s
CI (SIAX Cloud) / quality (push) Successful in 45s
CI (SIAX Cloud) / security (pull_request) Successful in 27s
CI (SIAX Cloud) / integration (pull_request) Successful in 31s
Security Scan (SIAX Cloud) / security (pull_request) Successful in 29s
CI (SIAX Cloud) / quality (pull_request) Successful in 48s
Continues P010 (branch renamed from feat/p010-source-registry-persistence):
closes the three remaining BEFORE_STATE.md gaps (§2 TS/Python split-brain,
§3 missing provenance fields, §4 untested failure modes), all additive to
the production pipeline — the Python QA filter's delivery decision is
unchanged by any of this.
TS/Python bridge (§2):
- New route surface app/api/0pt/quality/* (rules/runs/issues CRUD +
POST /api/0pt/quality/bridge-run) over the shared QualityService
singleton (src/services/quality.ts), fixing the same "no shared
instance" defect the Source Registry had.
- src/quality/quality-bridge.ts auto-provisions a deterministic,
tenant-scoped baseline rule set on first use so the Python engine never
pre-registers rules through the CRUD surface.
- services/api/workers/quality_bridge.py: the Python-side HTTP client.
Feature-flagged off by default (OPT_QUALITY_BRIDGE_ENABLED), fails open
on any error (never raises into run_job, never changes `delivered`).
Advisory only — real per-row gating against the TS engine isn't
implementable yet (ExpectationEngine returns dataset-level pass/fail
counts + samples, not a per-row boolean array); documented, not faked.
- Live-verified end-to-end: `next dev` (AUTH_ENFORCE=false) + the real
Python pipeline hitting the real brreg.no API, round-tripping through
the real bridge route, receiving a real QualityService score.
Provenance (§3): sources/connectors.py's Provenance dataclass gains
retrieved_at, transform, connector_version, producer, quality,
entity_resolution, artifact_ref (all previously absent from the real
dataflow entirely) via a make_provenance() factory used by every connector.
resolve.py stamps entity_resolution on merged records' provenance (never on
unmerged ones). pipeline.py stamps artifact_ref at delivery and quality
once the bridge succeeds.
Failure tests (§4), real fault injection against real code (services/api,
new pytest + respx suite, not vitest mocks):
- dedup-determinism + duplicate-input + out-of-order: resolve.py under
shuffled/interleaved/exhaustive-permutation input, plus an explicit,
verified test of the one case that IS legitimately order-sensitive
(non-transitive similarity in a greedy clusterer) instead of hiding it.
- schema-evolution: respx-mocked upstream responses with added/removed/
alien-shaped fields through the real brreg connector + pipeline.
- restart: connector exceptions mid-job (including one from respx itself)
never crash run_job.
- backfill: the real property that holds given no persistence layer
exists (replay is compute-idempotent) — NOT a fabricated dedup-store
test.
- CDC-interruption and true backfill/delivery-store idempotency:
explicitly documented as not implementable against this codebase
(no CDC pipeline, no delivery store exist anywhere) via skip markers
with reasons, in tests/test_known_gaps.py, rather than silently
dropped or faked.
Testing: 256/256 vitest (249 pre-existing + 7 new bridge route/service
tests) and 28/28 pytest (2 documented skips) green locally. tsc -p
tsconfig.check.json has zero new errors (14 pre-existing errors, all in
the untracked/unaudited src/fleet, src/graph, src/metrics, src/projections
paths this pass does not touch, per BEFORE_STATE.md).
No PR opened, per instructions.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
07b13bd833
commit
9740e20818
@@ -0,0 +1,96 @@
|
||||
/**
|
||||
* src/quality/quality-bridge.ts
|
||||
* ================================
|
||||
* The TS side of the P010 TS/Python split-brain bridge (BEFORE_STATE.md §2):
|
||||
* the production order pipeline (services/api/workers/pipeline.py) has its
|
||||
* own one-line QA filter and never touches this repo's sophisticated,
|
||||
* versioned QualityService (rule registry, GE delegation, OpenLineage). The
|
||||
* two engines had "noll bryggor mellan sig" -- no HTTP, no shared DB, no N0D
|
||||
* job.
|
||||
*
|
||||
* This module is the ADDITIVE bridge, not a replacement: it lets the Python
|
||||
* engine ask the real QualityService to grade a batch of already-produced
|
||||
* rows and get back a real score/issues, WITHOUT the Python filter's
|
||||
* behavior changing. The Python side (services/api/workers/quality_bridge.py)
|
||||
* calls POST /api/0pt/quality/bridge-run purely for an advisory read today;
|
||||
* it is feature-flagged off by default (OPT_QUALITY_BRIDGE_ENABLED) and
|
||||
* fails open (a bridge error/timeout never blocks or alters delivery) --
|
||||
* see that file's docstring for the full contract and the honest limits on
|
||||
* what "gradual activation" can mean until per-row GE results exist.
|
||||
*
|
||||
* `ensureBaselineRules` auto-provisions one deterministic, tenant-scoped
|
||||
* rule set the first time a (tenant, dataset) pair is seen, so the Python
|
||||
* engine never has to pre-register rules through the CRUD surface just to
|
||||
* get a quality read on an order's delivered rows. The baseline checks are
|
||||
* generic company-record checks (name present, confidence in [0,1]) -- real
|
||||
* GE expectations executed by the local engine, not a stub.
|
||||
*/
|
||||
import { SiaxError } from "../platform/errors";
|
||||
import type { QualityService } from "./quality-service";
|
||||
|
||||
export interface BaselineRuleTarget {
|
||||
tenant_id: string;
|
||||
project_id: string;
|
||||
dataset_id: string;
|
||||
}
|
||||
|
||||
/** Deterministic, globally-unique (tenant + dataset scoped) baseline rule ids. */
|
||||
function baselineRuleIds(target: BaselineRuleTarget): { name: string; confidence: string } {
|
||||
const scope = `${target.tenant_id}__${target.dataset_id}`;
|
||||
return {
|
||||
name: `baseline_name_notnull__${scope}`,
|
||||
confidence: `baseline_confidence_range__${scope}`,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Idempotently ensures the baseline rule set exists for (tenant_id,
|
||||
* dataset_id). Safe to call on every bridge-run -- a NOT_FOUND on getRule
|
||||
* means "create it"; any other error propagates. Never overwrites a rule a
|
||||
* caller already customized (only creates when absent).
|
||||
*/
|
||||
export async function ensureBaselineRules(
|
||||
qualityService: QualityService,
|
||||
target: BaselineRuleTarget
|
||||
): Promise<void> {
|
||||
const ids = baselineRuleIds(target);
|
||||
|
||||
await ensureRule(qualityService, ids.name, target, {
|
||||
name: "baseline: name field present (0pt-quality-bridge)",
|
||||
expectation: { expectation_type: "expect_column_values_to_not_be_null", kwargs: { column: "name" } },
|
||||
severity: "error",
|
||||
});
|
||||
|
||||
await ensureRule(qualityService, ids.confidence, target, {
|
||||
name: "baseline: confidence in [0,1] (0pt-quality-bridge)",
|
||||
expectation: {
|
||||
expectation_type: "expect_column_values_to_be_between",
|
||||
kwargs: { column: "confidence", min_value: 0, max_value: 1 },
|
||||
},
|
||||
severity: "warning",
|
||||
});
|
||||
}
|
||||
|
||||
async function ensureRule(
|
||||
qualityService: QualityService,
|
||||
ruleId: string,
|
||||
target: BaselineRuleTarget,
|
||||
rest: { name: string; expectation: { expectation_type: string; kwargs: Record<string, unknown> }; severity: "info" | "warning" | "error" | "critical" }
|
||||
): Promise<void> {
|
||||
try {
|
||||
qualityService.getRule(ruleId, target.tenant_id);
|
||||
} catch (error: unknown) {
|
||||
if (error instanceof SiaxError && error.code === "NOT_FOUND") {
|
||||
await qualityService.createRule({
|
||||
rule_id: ruleId,
|
||||
tenant_id: target.tenant_id,
|
||||
project_id: target.project_id,
|
||||
dataset_id: target.dataset_id,
|
||||
supplied_by: "0pt-quality-bridge",
|
||||
...rest,
|
||||
});
|
||||
return;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
/**
|
||||
* src/services/quality.ts
|
||||
* =========================
|
||||
* Shared singleton for the quality route group (app/api/0pt/quality/*),
|
||||
* matching src/services/source-registry.ts's precedent: constructing the
|
||||
* service once here (instead of `new QualityService()` per route module)
|
||||
* keeps rules/runs/issues registered via one route visible to another
|
||||
* within the same running process — the same "not even a shared
|
||||
* process-wide singleton" defect BEFORE_STATE.md §1 found and fixed for the
|
||||
* Source Registry would otherwise recur here.
|
||||
*
|
||||
* This is also the seam the Python engine's quality bridge
|
||||
* (services/api/workers/quality_bridge.py) calls through over HTTP —
|
||||
* see app/api/0pt/quality/bridge-run/route.ts.
|
||||
*/
|
||||
import { QualityService } from "../quality/quality-service";
|
||||
|
||||
export const qualityService = new QualityService();
|
||||
@@ -179,3 +179,49 @@ export const requestIcebergWriteSchema = z.object({
|
||||
size_bytes: z.number().int().nonnegative().optional(),
|
||||
heavy: z.boolean().optional(),
|
||||
});
|
||||
|
||||
/** POST /api/0pt/quality/rules -- mirrors CreateQualityRuleInput (src/quality/quality-types.ts). */
|
||||
export const createQualityRuleSchema = z.object({
|
||||
rule_id: z.string().min(1),
|
||||
tenant_id: z.string().min(1),
|
||||
project_id: z.string().min(1),
|
||||
dataset_id: z.string().min(1),
|
||||
name: z.string().min(1),
|
||||
expectation: z.object({
|
||||
expectation_type: z.string().min(1),
|
||||
kwargs: jsonObject,
|
||||
}),
|
||||
severity: z.enum(['info', 'warning', 'error', 'critical']).optional(),
|
||||
supplied_by: z.string().min(1).optional(),
|
||||
});
|
||||
|
||||
/**
|
||||
* POST /api/0pt/quality/runs -- runs the currently-registered active rules
|
||||
* for a dataset against caller-supplied rows (QualityService.runQuality).
|
||||
*/
|
||||
export const createQualityRunSchema = z.object({
|
||||
tenant_id: z.string().min(1),
|
||||
project_id: z.string().min(1),
|
||||
dataset_id: z.string().min(1),
|
||||
dataset_version: z.number().int().optional(),
|
||||
rows: z.array(jsonObject).optional(),
|
||||
correlation_id: z.string().min(1).optional(),
|
||||
});
|
||||
|
||||
/**
|
||||
* POST /api/0pt/quality/bridge-run -- the Python engine's (services/api/workers/pipeline.py)
|
||||
* bridge into the TS QualityService. Auto-provisions a baseline rule set for
|
||||
* the (tenant, dataset) pair the first time it is called, so the engine never
|
||||
* has to pre-register rules through the CRUD surface just to get an advisory
|
||||
* quality read. `rows` is required here (unlike createQualityRunSchema) --
|
||||
* the bridge always runs synchronously against real, already-produced rows;
|
||||
* it never triggers a delegated/no-rows run.
|
||||
*/
|
||||
export const qualityBridgeRunSchema = z.object({
|
||||
tenant_id: z.string().min(1),
|
||||
project_id: z.string().min(1),
|
||||
dataset_id: z.string().min(1),
|
||||
dataset_version: z.number().int().optional(),
|
||||
rows: z.array(jsonObject),
|
||||
correlation_id: z.string().min(1).optional(),
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user