test(integration)+ci+docs: live OpenSearch/ClickHouse suites, CI service containers, STATUS.md (§56)
CI (SIAX Cloud) / integration (push) Failing after 22s
CI (SIAX Cloud) / security (push) Successful in 22s
Security Scan (SIAX Cloud) / security (push) Successful in 21s
CI (SIAX Cloud) / quality (push) Successful in 43s
CI (SIAX Cloud) / integration (pull_request) Failing after 3s
CI (SIAX Cloud) / security (pull_request) Successful in 17s
Security Scan (SIAX Cloud) / security (pull_request) Successful in 16s
CI (SIAX Cloud) / quality (pull_request) Successful in 43s

- tests/integration/: 10 tests against REAL OpenSearch 2.11 (tenant
  isolation, purpose/rights filters, generation rebuild/rollback,
  projection-disaster rebuild §68) + REAL ClickHouse 24.8 (tenant-isolated
  metric DSL, TTL schema, injection-surface refusals). Honest skip without
  env - and CI fails hard if the suites skip instead of running.
- .gitea/workflows/ci.yml: new blocking 'integration' job with
  self-identifying service containers (st0re ci.yml's measured
  alias-collision discipline: run-unique cluster.name / credentials,
  getent-enumerated IP selection, no-match = hard fail).
- STATUS.md: full 8-level Master-DoD classification per capability incl.
  the honest gaps blocking PRODUCTION_READY.
- dependency-mode: NEXT_PHASE=phase-production-build is not a serving
  runtime (next build page-data collection must compile; guard re-arms at
  boot) - pinned by contract test.
- docs/02-architecture.md: superseded the accurate-but-now-fixed 'every
  client runs against its mock' paragraph; .env.example: client URLs now
  actually read from env + new P0 backend vars.

Co-Authored-By: Claude Fable 5 <[email protected]>
This commit is contained in:
Simon Axelsson
2026-08-31 16:56:33 +02:00
co-authored by Claude Fable 5
parent b46807da75
commit c47e3b468e
9 changed files with 510 additions and 9 deletions
@@ -41,6 +41,14 @@ describe("resolveDependencyBaseUrl (the §3 kill switch)", () => {
it("configured => normalized URL in any runtime (trailing slashes stripped)", () => {
expect(resolveDependencyBaseUrl("cl0ud", "https://x.example.com///", PROD)).toBe("https://x.example.com");
});
it("the Next BUILD phase is not a production runtime (page-data collection must compile; the guard re-arms at boot)", () => {
const BUILD = { NODE_ENV: "production", NEXT_PHASE: "phase-production-build" } as NodeJS.ProcessEnv;
expect(resolveDependencyBaseUrl("st0re", undefined, BUILD)).toBeUndefined();
// Any other phase value stays armed.
const SERVE = { NODE_ENV: "production", NEXT_PHASE: "phase-production-server" } as NodeJS.ProcessEnv;
expect(() => resolveDependencyBaseUrl("st0re", undefined, SERVE)).toThrowError(SiaxError);
});
});
describe("resolveStoreMode (§3 for stateful registries)", () => {
@@ -0,0 +1,96 @@
/**
* REAL ClickHouse integration test (Master-DoD §48/§50) for the Analytics
* capability. Runs against CLICKHOUSE_URL (+ CLICKHOUSE_AUTH "user:pass"
* when the server requires it); SKIPS HONESTLY when unset.
*
* Proves against the real engine: schema creation with TTL retention,
* JSONEachRow ingest, the closed metric-query DSL, and — the §69-relevant
* part — that the FORCED tenant predicate isolates tenants on real data.
*/
import { describe, it, expect, beforeAll } from "vitest";
import { ClickHouseAnalytics } from "@/src/analytics/clickhouse-analytics";
const CLICKHOUSE_URL = process.env.CLICKHOUSE_URL;
const run = CLICKHOUSE_URL ? describe : describe.skip;
const DB = `opt_itest_${Date.now().toString(36)}`;
run("Analytics capability against a LIVE ClickHouse", () => {
// The skip-variant still evaluates this callback body, so the constructor
// must tolerate the env-less case (the tests themselves never run then).
const analytics = new ClickHouseAnalytics({
baseUrl: CLICKHOUSE_URL ?? "http://skipped.invalid",
basicAuth: process.env.CLICKHOUSE_AUTH,
database: DB,
});
beforeAll(async () => {
expect(await analytics.health()).toBe(true);
await analytics.ensureSchema(30);
// ensureSchema is idempotent (CREATE IF NOT EXISTS).
await analytics.ensureSchema(30);
}, 60_000);
it("ingests events and answers aggregate metric queries", async () => {
const res = await analytics.ingest([
{ tenant_id: "t_alpha", dataset_id: "ds_companies", metric: "rows_ingested", value: 100 },
{ tenant_id: "t_alpha", dataset_id: "ds_companies", metric: "rows_ingested", value: 50 },
{ tenant_id: "t_alpha", dataset_id: "ds_vehicles", metric: "rows_ingested", value: 7 },
{ tenant_id: "t_beta", dataset_id: "ds_companies", metric: "rows_ingested", value: 999 },
]);
expect(res.ingested).toBe(4);
const total = await analytics.queryMetric({
tenant_id: "t_alpha",
metric: "rows_ingested",
aggregate: "sum",
});
expect(total).toEqual([{ value: 157 }]);
const perDataset = await analytics.queryMetric({
tenant_id: "t_alpha",
dataset_id: "ds_companies",
metric: "rows_ingested",
aggregate: "sum",
});
expect(perDataset).toEqual([{ value: 150 }]);
}, 30_000);
it("REAL tenant isolation: t_beta's numbers never leak into t_alpha aggregates", async () => {
const alpha = await analytics.queryMetric({ tenant_id: "t_alpha", metric: "rows_ingested", aggregate: "max" });
expect(alpha[0].value).toBe(100); // NOT 999
const beta = await analytics.queryMetric({ tenant_id: "t_beta", metric: "rows_ingested", aggregate: "sum" });
expect(beta[0].value).toBe(999);
const ghost = await analytics.queryMetric({ tenant_id: "t_gamma", metric: "rows_ingested", aggregate: "count" });
expect(ghost[0].value).toBe(0);
});
it("group-by dimension queries work through the closed DSL", async () => {
await analytics.ingest([
{ tenant_id: "t_alpha", dataset_id: "ds_x", metric: "dq_score", value: 90, dimensions: { severity: "warning" } },
{ tenant_id: "t_alpha", dataset_id: "ds_x", metric: "dq_score", value: 40, dimensions: { severity: "critical" } },
]);
const rows = await analytics.queryMetric({
tenant_id: "t_alpha",
metric: "dq_score",
aggregate: "avg",
group_by: "severity",
});
expect(rows).toHaveLength(2);
expect(rows.find((r) => r.group === "warning")?.value).toBe(90);
});
it("rejects tenant-less queries and invalid group_by identifiers (injection surface closed)", async () => {
await expect(
analytics.queryMetric({ tenant_id: " ", metric: "x", aggregate: "sum" })
).rejects.toMatchObject({ code: "INVALID_REQUEST" });
await expect(
analytics.queryMetric({
tenant_id: "t_alpha",
metric: "x",
aggregate: "sum",
group_by: "sev'; DROP TABLE opt_metric_events; --",
})
).rejects.toMatchObject({ code: "INVALID_REQUEST" });
});
});
@@ -0,0 +1,172 @@
/**
* REAL OpenSearch integration test (Master-DoD §48 "Mocks alone count as
* insufficient", §50 Integration level) for the Search capability.
*
* Runs against a live OpenSearch named by OPENSEARCH_URL (CI: a service
* container; locally: `docker run -e discovery.type=single-node
* -e DISABLE_SECURITY_PLUGIN=true opensearchproject/opensearch:2.11.1`).
* Without OPENSEARCH_URL the suite SKIPS HONESTLY — it never fabricates a
* pass (same convention as tests/p0/iceberg-write-service.realinfra.test.ts).
*
* What it proves against the real engine:
* - index creation with 0pt envelope mappings + bulk indexing
* - tenant isolation and purpose/rights filtering through real queries
* - generation rebuild + atomic alias switch + rollback (§42)
* - full projection-disaster recovery: delete EVERYTHING, rebuild from
* the canonical source, identical results (§68-style, scoped to 0pt)
*/
import { describe, it, expect, beforeAll, afterAll } from "vitest";
import { HttpOpenSearchAdapter } from "@/src/search/opensearch-adapter";
import { SearchService, type DocumentSource } from "@/src/search/search-service";
import type { SearchDocument } from "@/src/search/search-types";
const OPENSEARCH_URL = process.env.OPENSEARCH_URL;
const run = OPENSEARCH_URL ? describe : describe.skip;
const INDEX = `itest-${Date.now().toString(36)}`;
const DOCS: SearchDocument[] = [
{
doc_id: "c1",
tenant_id: "t_alpha",
purpose_tags: ["company_enrichment"],
rights_tags: ["internal", "customer_deliverable"],
source_refs: ["0pt:source:src_bolagsverket"],
payload: { name: "Volvo Personvagnar AB", org_nr: "5561074967", employees: 20000 },
},
{
doc_id: "c2",
tenant_id: "t_alpha",
purpose_tags: ["compliance"],
rights_tags: ["internal"],
payload: { name: "Volvo Lastvagnar AB", org_nr: "5560135508", employees: 15000 },
},
{
doc_id: "c3",
tenant_id: "t_beta",
purpose_tags: ["company_enrichment"],
rights_tags: ["internal"],
payload: { name: "Volvo Cars Retail", org_nr: "5569999999", employees: 300 },
},
];
function source(docs: SearchDocument[]): DocumentSource {
return {
name: "itest:canonical-array",
async *iterate() {
yield* docs;
},
};
}
run("Search capability against a LIVE OpenSearch", () => {
// The skip-variant still evaluates this callback body, so the constructor
// must tolerate the env-less case (the tests themselves never run then).
const adapter = new HttpOpenSearchAdapter({ baseUrl: OPENSEARCH_URL ?? "http://skipped.invalid" });
const search = new SearchService(adapter);
beforeAll(async () => {
const health = await adapter.health();
expect(["green", "yellow"]).toContain(health.status);
search.registerIndexDefinition({
index_name: INDEX,
version: 1,
fields: { name: "text", org_nr: "keyword", employees: "long" },
default_search_fields: ["name"],
});
}, 30_000);
afterAll(async () => {
for (const idx of await adapter.listIndices(`opt-${INDEX}--g*`)) {
await adapter.deleteIndex(idx);
}
});
it("rebuild g1 from canonical source; alias serves it", async () => {
const result = await search.rebuild(INDEX, source(DOCS));
expect(result.new_generation).toBe(1);
expect(result.docs_indexed).toBe(3);
expect(result.switched).toBe(true);
const state = await search.generationState(INDEX);
expect(state.active_generation).toBe(1);
}, 60_000);
it("REAL tenant isolation: t_alpha never sees t_beta documents", async () => {
const alpha = await search.query(INDEX, {
tenant_id: "t_alpha",
purpose: "company_enrichment",
text: "volvo",
});
expect(alpha.hits.map((h) => h.doc_id)).toEqual(["c1"]); // c2 wrong purpose, c3 wrong tenant
const beta = await search.query(INDEX, {
tenant_id: "t_beta",
purpose: "company_enrichment",
text: "volvo",
});
expect(beta.hits.map((h) => h.doc_id)).toEqual(["c3"]);
// Cross-tenant attack shape: a filter cannot break out of the tenant term.
const attack = await search.query(INDEX, {
tenant_id: "t_beta",
purpose: "company_enrichment",
filters: { org_nr: "5561074967" }, // t_alpha's org_nr
});
expect(attack.total).toBe(0);
});
it("purpose + rights filtering hold on the real engine", async () => {
const compliance = await search.query(INDEX, { tenant_id: "t_alpha", purpose: "compliance" });
expect(compliance.hits.map((h) => h.doc_id)).toEqual(["c2"]);
const deliverable = await search.query(INDEX, {
tenant_id: "t_alpha",
purpose: "company_enrichment",
rights_tag: "customer_deliverable",
});
expect(deliverable.hits.map((h) => h.doc_id)).toEqual(["c1"]);
});
it("generation rebuild + switch + rollback (§42)", async () => {
const updated = DOCS.map((d) =>
d.doc_id === "c1" ? { ...d, payload: { ...d.payload, name: "Volvo Personvagnar AB (uppdaterad)" } } : d
);
const r2 = await search.rebuild(INDEX, source(updated));
expect(r2.new_generation).toBe(2);
let res = await search.query(INDEX, { tenant_id: "t_alpha", purpose: "company_enrichment", text: "uppdaterad" });
expect(res.total).toBe(1);
// Rollback to g1 — the old generation still exists and serves the alias.
await search.switchGeneration(INDEX, 1);
res = await search.query(INDEX, { tenant_id: "t_alpha", purpose: "company_enrichment", text: "uppdaterad" });
expect(res.total).toBe(0);
await search.switchGeneration(INDEX, 2);
}, 60_000);
it("projection disaster: delete ALL generations, rebuild from canonical, results identical (§68)", async () => {
for (const idx of await adapter.listIndices(`opt-${INDEX}--g*`)) {
await adapter.deleteIndex(idx);
}
expect(await adapter.listIndices(`opt-${INDEX}--g*`)).toEqual([]);
const rebuilt = await search.rebuild(INDEX, source(DOCS));
expect(rebuilt.docs_indexed).toBe(3);
const res = await search.query(INDEX, { tenant_id: "t_alpha", purpose: "company_enrichment", text: "volvo" });
expect(res.hits.map((h) => h.doc_id)).toEqual(["c1"]);
}, 60_000);
it("incremental indexDocuments into the active generation", async () => {
const out = await search.indexDocuments(INDEX, [
{
doc_id: "c4",
tenant_id: "t_alpha",
purpose_tags: ["company_enrichment"],
rights_tags: ["internal"],
payload: { name: "Polestar Performance AB", org_nr: "5568100000", employees: 2500 },
},
]);
expect(out.indexed).toBe(1);
const state = await search.generationState(INDEX);
await adapter.refresh(search.physicalIndexFor(INDEX, state.active_generation!));
const res = await search.query(INDEX, { tenant_id: "t_alpha", purpose: "company_enrichment", text: "polestar" });
expect(res.total).toBe(1);
});
});