fix(recovery): restore source removed by production documentation merge
This commit is contained in:
@@ -0,0 +1,182 @@
|
||||
/**
|
||||
* Contract tests for the OpenMetadata projection adapter and the Feast
|
||||
* online-features adapter (Master-DoD §10 Metadata + Feature capability)
|
||||
* against recording provider doubles. These pin the wire shapes; they do NOT
|
||||
* claim INTEGRATION_TESTED status (no live OM/Feast in this pass — see
|
||||
* STATUS.md).
|
||||
*/
|
||||
import { describe, it, expect, afterEach } from "vitest";
|
||||
import { OpenMetadataAdapter, MetadataProjectionService } from "@/src/metadata/openmetadata-adapter";
|
||||
import { FeatureService } from "@/src/features/feast-adapter";
|
||||
import { createN0dClient } from "@/src/clients/n0d-client";
|
||||
import type { Dataset } from "@/src/types/dataset";
|
||||
import { startContractServer, type ContractServer } from "./contract-test-server";
|
||||
|
||||
let server: ContractServer | undefined;
|
||||
afterEach(async () => {
|
||||
await server?.close();
|
||||
server = undefined;
|
||||
});
|
||||
|
||||
const DATASET: Dataset = {
|
||||
dataset_id: "ds_companies",
|
||||
tenant_id: "t_a",
|
||||
project_id: "p_1",
|
||||
name: "Companies",
|
||||
dataset_type: "curated",
|
||||
status: "active",
|
||||
created_at: "2026-08-31T00:00:00.000Z",
|
||||
};
|
||||
|
||||
describe("OpenMetadata projection adapter (projection, never canonical)", () => {
|
||||
it("PUTs a createOrUpdate table entity to /api/v1/tables with the projection disclaimer", async () => {
|
||||
server = await startContractServer([
|
||||
{ method: "PUT", path: "/api/v1/tables", status: 200, respond: (r) => r.body as object },
|
||||
]);
|
||||
const adapter = new OpenMetadataAdapter({ baseUrl: server.baseUrl, token: "om-bot-token" });
|
||||
const projection = new MetadataProjectionService(adapter, "0pt.default.datasets");
|
||||
await projection.projectDataset(DATASET);
|
||||
|
||||
const req = server.requests[0];
|
||||
expect(req.method).toBe("PUT");
|
||||
expect(req.headers.authorization).toBe("Bearer om-bot-token");
|
||||
const body = req.body as Record<string, unknown>;
|
||||
expect(body.name).toBe("ds_companies");
|
||||
expect(body.databaseSchema).toBe("0pt.default.datasets");
|
||||
expect(String(body.description)).toContain("PROJECTION");
|
||||
expect(String(body.description)).toContain("0pt:dataset:ds_companies");
|
||||
expect(Array.isArray(body.columns)).toBe(true);
|
||||
});
|
||||
|
||||
it("projectAll (the §42 rebuild path) collects per-dataset failures instead of aborting", async () => {
|
||||
let calls = 0;
|
||||
server = await startContractServer([
|
||||
{
|
||||
method: "PUT",
|
||||
path: "/api/v1/tables",
|
||||
status: 200,
|
||||
respond: (r) => {
|
||||
calls++;
|
||||
if ((r.body as { name?: string }).name === "ds_broken") {
|
||||
// The double can't vary status per call; throwing here simulates a body-level failure path
|
||||
// via a 200-with-garbage that the adapter tolerates, so use a separate route trick instead.
|
||||
}
|
||||
return r.body as object;
|
||||
},
|
||||
},
|
||||
]);
|
||||
const adapter = new OpenMetadataAdapter({ baseUrl: server.baseUrl });
|
||||
const projection = new MetadataProjectionService(adapter);
|
||||
const result = await projection.projectAll(
|
||||
[DATASET, { ...DATASET, dataset_id: "ds_two" }],
|
||||
new Map()
|
||||
);
|
||||
expect(calls).toBe(2);
|
||||
expect(result.projected).toBe(2);
|
||||
expect(result.failures).toEqual([]);
|
||||
});
|
||||
|
||||
it("an unreachable OpenMetadata surfaces as a per-dataset failure in projectAll (projection loss ≠ crash)", async () => {
|
||||
const adapter = new OpenMetadataAdapter({ baseUrl: "http://127.0.0.1:9", timeoutMs: 300 });
|
||||
const projection = new MetadataProjectionService(adapter);
|
||||
const result = await projection.projectAll([DATASET], new Map());
|
||||
expect(result.projected).toBe(0);
|
||||
expect(result.failures).toHaveLength(1);
|
||||
expect(result.failures[0].dataset_id).toBe("ds_companies");
|
||||
});
|
||||
});
|
||||
|
||||
describe("Feast adapter (online path wire contract + delegation contracts)", () => {
|
||||
function registeredService(feastUrl?: string) {
|
||||
const svc = new FeatureService({ feastServerUrl: feastUrl, n0dClient: createN0dClient() });
|
||||
svc.registerFeatureView({
|
||||
feature_view: "company_stats",
|
||||
tenant_id: "t_a",
|
||||
project_id: "p_1",
|
||||
entities: ["org_nr"],
|
||||
features: [{ name: "employee_count", dtype: "int64" }],
|
||||
source_dataset_ref: "0pt:dataset:ds_companies",
|
||||
});
|
||||
return svc;
|
||||
}
|
||||
|
||||
it("POSTs Feast's documented get-online-features body (view:feature refs + entities)", async () => {
|
||||
server = await startContractServer([
|
||||
{
|
||||
method: "POST",
|
||||
path: "/get-online-features",
|
||||
status: 200,
|
||||
respond: () => ({
|
||||
metadata: { feature_names: ["org_nr", "employee_count"] },
|
||||
results: [
|
||||
{ values: ["5560360793"], statuses: ["PRESENT"] },
|
||||
{ values: [1000], statuses: ["PRESENT"] },
|
||||
],
|
||||
}),
|
||||
},
|
||||
]);
|
||||
const svc = registeredService(server.baseUrl);
|
||||
const res = await svc.getOnlineFeatures({
|
||||
tenant_id: "t_a",
|
||||
feature_view: "company_stats",
|
||||
features: ["employee_count"],
|
||||
entities: { org_nr: ["5560360793"] },
|
||||
});
|
||||
const body = server.requests[0].body as Record<string, unknown>;
|
||||
expect(body.features).toEqual(["company_stats:employee_count"]);
|
||||
expect(body.entities).toEqual({ org_nr: ["5560360793"] });
|
||||
expect(res.feature_names).toContain("employee_count");
|
||||
});
|
||||
|
||||
it("registry versioning: re-registering a view bumps its version and keeps history", () => {
|
||||
const svc = registeredService();
|
||||
const v2 = svc.registerFeatureView({
|
||||
feature_view: "company_stats",
|
||||
tenant_id: "t_a",
|
||||
project_id: "p_1",
|
||||
entities: ["org_nr"],
|
||||
features: [
|
||||
{ name: "employee_count", dtype: "int64" },
|
||||
{ name: "revenue", dtype: "float64" },
|
||||
],
|
||||
source_dataset_ref: "0pt:dataset:ds_companies",
|
||||
});
|
||||
expect(v2.version).toBe(2);
|
||||
expect(svc.getFeatureViewVersions("t_a", "company_stats").map((v) => v.version)).toEqual([1, 2]);
|
||||
// Tenant gate.
|
||||
expect(() => svc.getFeatureView("t_b", "company_stats")).toThrowError(/not found/);
|
||||
});
|
||||
|
||||
it("materialize/get-historical are N0D delegation contracts, never local fakes", async () => {
|
||||
const svc = registeredService();
|
||||
const job = await svc.materialize({
|
||||
tenant_id: "t_a",
|
||||
project_id: "p_1",
|
||||
feature_view: "company_stats",
|
||||
start_time: "2026-08-01T00:00:00Z",
|
||||
end_time: "2026-08-31T00:00:00Z",
|
||||
});
|
||||
expect(job.job_type).toBe("0pt.features.materialize");
|
||||
|
||||
const hist = await svc.getHistorical({
|
||||
tenant_id: "t_a",
|
||||
project_id: "p_1",
|
||||
feature_view: "company_stats",
|
||||
features: ["employee_count"],
|
||||
entity_df_artifact_ref: "st0re:artifact:art_entities",
|
||||
});
|
||||
expect(hist.job_type).toBe("0pt.features.get_historical");
|
||||
});
|
||||
|
||||
it("online path without a configured Feast server fails hard (no silent fake features)", async () => {
|
||||
const svc = registeredService();
|
||||
await expect(
|
||||
svc.getOnlineFeatures({
|
||||
tenant_id: "t_a",
|
||||
feature_view: "company_stats",
|
||||
features: ["employee_count"],
|
||||
entities: { org_nr: ["1"] },
|
||||
})
|
||||
).rejects.toMatchObject({ code: "DEPENDENCY_UNAVAILABLE" });
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user