Files
0pt/tests/p0/iceberg-write-service.realinfra.test.ts
T
admin 0cac0266e0
masterplan-lock / check (push) Successful in 6s
CI (SIAX Cloud) / sonar (pull_request) Skipped
masterplan-lock / check (pull_request) Successful in 4s
CI (SIAX Cloud) / Component conformance (blocking) (pull_request) Successful in 9s
CI (SIAX Cloud) / security (pull_request) Successful in 16s
Security Scan (SIAX Cloud) / security (pull_request) Successful in 17s
CI (SIAX Cloud) / quality (pull_request) Successful in 1m13s
CI (SIAX Cloud) / integration (pull_request) Successful in 1m15s
test(safety): require an isolated opt-in target for ST0RE integration
2026-11-10 03:49:33 +01:00

97 lines
4.4 KiB
TypeScript

import { describe, it, expect, beforeAll, afterAll, vi } from "vitest";
import { DatasetService } from "@/src/services/dataset-service";
import { DatasetIcebergMappingService } from "@/src/services/dataset-iceberg-mapping-service";
import { IcebergWriteService } from "@/src/services/iceberg-write-service";
import { isolatedSt0reFetch, probeSt0reRealinfra, type St0reRealinfraProbe } from "@/tests/support/st0re-realinfra";
/**
* Integration against an isolated local ST0RE test instance only.
* Requires ST0RE_REALINFRA_TESTS=1 and a loopback ST0RE_TEST_URL origin.
* Disabled tests make no HTTP requests; invalid opt-in configuration fails.
* A read-only probe permits an honest skip if the local instance is unreachable.
* Successful runs exercise the real HTTP client without a mock fallback.
*/
const TEST_TENANT = process.env.ST0RE_TEST_TENANT_ID ?? "t_0pt_realinfra_local";
const TEST_PROJECT = "p_0pt_realinfra";
const TEST_ACTOR = "0pt-realinfra-test";
let probe: St0reRealinfraProbe;
beforeAll(async () => {
probe = await probeSt0reRealinfra(process.env, fetch);
if (probe.reachable && probe.target) vi.stubGlobal("fetch", isolatedSt0reFetch(probe.target, fetch));
}, 10000);
afterAll(() => vi.unstubAllGlobals());
describe("IcebergWriteService against an isolated local ST0RE test instance", () => {
it(
"mapDatasetToIcebergTable + requestIcebergWrite register a real namespace/table/snapshot in ST0RE",
async (ctx) => {
if (!probe.reachable || !probe.target) {
console.warn(
`[realinfra] Local ST0RE disabled or unreachable (${probe.reason}) -- skipping honestly, not fabricating success.`
);
ctx.skip();
return;
}
const datasetService = new DatasetService();
const mappingService = new DatasetIcebergMappingService({ datasetService });
const service = new IcebergWriteService({ datasetService, mappingService, st0reBaseUrl: probe.target });
const stamp = Date.now();
const datasetId = `ds_realinfra_local_${stamp}`;
await datasetService.registerDataset({
dataset_id: datasetId,
tenant_id: TEST_TENANT,
project_id: TEST_PROJECT,
name: "0pt isolated local ST0RE test dataset",
dataset_type: "enriched",
});
const mapped = await service.mapDatasetToIcebergTable({
tenant_id: TEST_TENANT,
project_id: TEST_PROJECT,
dataset_id: datasetId,
dataset_iceberg_mapping_id: `dim_realinfra_${stamp}`,
namespace: "0pt_local_test",
table_name: `dim_company_se_local_${stamp}`,
storage_uri: `s3://siax-test-tenants/local/tenants/${TEST_TENANT}/projects/${TEST_PROJECT}/lakehouse/0pt_local_test/dim_company_se_local_${stamp}`,
catalog_ref: `0pt_local_test.dim_company_se_local_${stamp}`,
actor_id: TEST_ACTOR,
correlation_id: `corr_realinfra_${stamp}`,
});
// Real ST0RE issues Postgres UUIDs -- never the mock client's
// "mock_table_<timestamp>" shape. This is the assertion that proves
// this test actually hit the local HTTP path, not the mock fallback.
expect(mapped.iceberg_table_id).not.toContain("mock_table_");
expect(mapped.iceberg_table_id).toMatch(/^[0-9a-f-]{36}$/i);
expect(mapped.namespace_id).not.toContain("mock_ns_");
expect(mapped.namespace_id).toMatch(/^[0-9a-f-]{36}$/i);
expect(mapped.mapping.dataset_id).toBe(datasetId);
// eslint-disable-next-line no-console
console.log(`[realinfra] LOCAL ST0RE table registered: tableId=${mapped.iceberg_table_id} namespaceId=${mapped.namespace_id}`);
const write = await service.requestIcebergWrite({
dataset_iceberg_mapping_id: mapped.mapping.dataset_iceberg_mapping_id,
actor_id: TEST_ACTOR,
correlation_id: `corr_realinfra_write_${stamp}`,
schema_version: "1",
manifest_uri: `s3://siax-test-tenants/local/tenants/${TEST_TENANT}/projects/${TEST_PROJECT}/lakehouse/0pt_local_test/dim_company_se_local_${stamp}/metadata/manifest-1.avro`,
record_count: 1,
size_bytes: 128,
});
expect(write.snapshot_id).not.toContain("mock_snapshot_");
expect(write.snapshot_id).toMatch(/^[0-9a-f-]{36}$/i);
expect(write.iceberg_table_id).toBe(mapped.iceberg_table_id);
// eslint-disable-next-line no-console
console.log(`[realinfra] LOCAL ST0RE snapshot registered: snapshotId=${write.snapshot_id}`);
},
20000
);
});