CI (SIAX Cloud) / integration (push) Successful in 40s
CI (SIAX Cloud) / quality (push) Successful in 55s
CI (SIAX Cloud) / security (push) Successful in 21s
Security Scan (SIAX Cloud) / security (push) Successful in 22s
CI (SIAX Cloud) / integration (pull_request) Successful in 39s
CI (SIAX Cloud) / quality (pull_request) Successful in 54s
Security Scan (SIAX Cloud) / security (pull_request) Successful in 21s
CI (SIAX Cloud) / security (pull_request) Successful in 25s
Two corrections, both of my own errors.
1. SCOPE CREEP, NOW REVERTED. Running `prettier --write` on whole directories
reformatted 18 files this branch had no business touching — the entire
merged BI-P002..P012 core (arrow/, domain/, engine/, repositories/, five
analytics integration suites) and, absurdly,
search-opensearch.integration.test.ts, which has nothing to do with this
work. The changes were purely stylistic quote churn, but they added ~1,400
lines of noise to the diff, made the PR harder to review honestly, and
invited conflicts with the four other lanes working in this estate. All 18
are now byte-identical to origin/main again (verified with `git diff
origin/main --name-only`, which reports nothing for them). Formatting is now
applied only to the files this branch actually owns.
2. A COMMIT MESSAGE THAT DESCRIBED A FIX THAT WAS NOT IN THE CODE. Commit
3ee0230 said the "does NOT ship the Iceberg table" assertion had been moved
from a filesystem check to `git ls-files`. It had not. The patch anchor used
double quotes, prettier had already converted that file to single quotes, so
the replacement silently matched nothing and the script printed its success
line anyway. The suite then passed — but only because I had just deleted the
fixture directory, so the OLD filesystem assertion happened to be true.
That is precisely the failure mode this branch keeps writing tests against:
a green run that means something different from what it appears to mean. The
fix is now genuinely applied and verified the way it should have been the
first time — by running the suite WITH the Iceberg fixture present on disk,
which is the case that previously failed. It passes, and it now also asserts
that the parquet/csv fixtures ARE tracked, so a version shipping no fixture
at all would fail rather than pass vacuously.
957 tests pass with ClickHouse, Postgres and DuckDB live. typecheck, eslint and
prettier clean on the files this branch owns.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
173 lines
6.7 KiB
TypeScript
173 lines
6.7 KiB
TypeScript
/**
|
|
* 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);
|
|
});
|
|
});
|