fix(recovery): restore source removed by production documentation merge

This commit is contained in:
2026-11-10 03:42:10 +01:00
parent 585bdd4b44
commit 3d2fc6f913
957 changed files with 115754 additions and 0 deletions
@@ -0,0 +1,112 @@
{
"generated_at": "2026-09-06T20:53:00.409Z",
"clickhouse_version": "24.8.14.39",
"query": "SELECT toString(t) AS tenant_id, toInt64(n) AS n, toFloat64(v) AS v, b AS flag,\n toDateTime64(ts, 3, 'UTC') AS ts\nFROM (\n SELECT arrayJoin([\n ('t_alpha', 1, 1.5, true, '2026-01-01 00:00:00.000'),\n ('t_beta', 2, 2.5, false, '2026-06-15 08:09:10.123'),\n ('t_gamma', 3, 3.25, true, '2026-09-06 12:34:56.789')\n ]) AS tup, tup.1 AS t, tup.2 AS n, tup.3 AS v, tup.4 AS b, tup.5 AS ts\n)",
"directions": {
"clickhouse -> arrow -> pyarrow/duckdb": {
"pyarrow_version": "25.0.1",
"duckdb_version": "1.5.5",
"schema": [
{
"name": "tenant_id",
"type": "string"
},
{
"name": "n",
"type": "int64"
},
{
"name": "v",
"type": "double"
},
{
"name": "flag",
"type": "bool"
},
{
"name": "ts",
"type": "timestamp[ms, tz=UTC]"
}
],
"num_rows": 3,
"pyarrow_values": {
"tenant_id": ["t_alpha", "t_beta", "t_gamma"],
"n": [1, 2, 3],
"v": [1.5, 2.5, 3.25],
"flag": [true, false, true],
"ts": [
"2026-01-01 00:00:00+00:00",
"2026-06-15 08:09:10.123000+00:00",
"2026-09-06 12:34:56.789000+00:00"
]
},
"duckdb_types": [
["tenant_id", "VARCHAR"],
["n", "BIGINT"],
["v", "DOUBLE"],
["flag", "BOOLEAN"],
["ts", "TIMESTAMP WITH TIME ZONE"]
],
"duckdb_rows": [
["t_alpha", "1", "1.5", "True", "2026-01-01 00:00:00+00:00"],
["t_beta", "2", "2.5", "False", "2026-06-15 08:09:10.123000+00:00"],
["t_gamma", "3", "3.25", "True", "2026-09-06 12:34:56.789000+00:00"]
]
},
"0pt encoder -> arrow -> pyarrow/duckdb": {
"pyarrow_version": "25.0.1",
"duckdb_version": "1.5.5",
"schema": [
{
"name": "tenant_id",
"type": "string"
},
{
"name": "n",
"type": "int64"
},
{
"name": "v",
"type": "double"
},
{
"name": "flag",
"type": "bool"
},
{
"name": "ts",
"type": "timestamp[ms, tz=UTC]"
}
],
"num_rows": 3,
"pyarrow_values": {
"tenant_id": ["t_alpha", "t_beta", "t_gamma"],
"n": [1, 2, 3],
"v": [1.5, 2.5, 3.25],
"flag": [true, false, true],
"ts": [
"2026-01-01 00:00:00+00:00",
"2026-06-15 08:09:10.123000+00:00",
"2026-09-06 12:34:56.789000+00:00"
]
},
"duckdb_types": [
["tenant_id", "VARCHAR"],
["n", "BIGINT"],
["v", "DOUBLE"],
["flag", "BOOLEAN"],
["ts", "TIMESTAMP WITH TIME ZONE"]
],
"duckdb_rows": [
["t_alpha", "1", "1.5", "True", "2026-01-01 00:00:00+00:00"],
["t_beta", "2", "2.5", "False", "2026-06-15 08:09:10.123000+00:00"],
["t_gamma", "3", "3.25", "True", "2026-09-06 12:34:56.789000+00:00"]
]
}
},
"byte_sizes": {
"clickhouse_encoded": 968,
"opt_encoded": 864
},
"verdict": "PASS — pyarrow and DuckDB read identical values and types from BOTH encoders"
}
@@ -0,0 +1,149 @@
{
"generated_at": "2026-09-06T20:44:16.335Z",
"clickhouse_version": "24.8.14.39",
"database": "opt_bench_mtqa56j3",
"fixtures": {
"saas": {
"events": 5400000,
"tenants": 200,
"metrics": 12,
"days": 90,
"seed_ms": 22912
},
"vehiq": {
"vehicles_under_test": 2000000,
"decoy_vehicles": 2000000,
"seed_ms": 31960
},
"on_disk": [
{
"table": "giant_everything",
"rows": 9400000,
"bytes": 84015753
},
{
"table": "opt_analytics_event",
"rows": 5400000,
"bytes": 60158827
},
{
"table": "opt_dataset_projection",
"rows": 4000000,
"bytes": 48936260
},
{
"table": "opt_metric_daily",
"rows": 37800,
"bytes": 86181
}
]
},
"measurements": [
{
"label": "SaaS dashboard panel: 90-day metric total for ONE tenant (purpose-built event table)",
"runs": 12,
"p50_ms": 48.8,
"p95_ms": 72.24,
"min_ms": 31.36,
"max_ms": 72.24,
"rows_read": 40960,
"bytes_read": 75216
},
{
"label": "SAME question against ONE GIANT TABLE (time-leading sort key)",
"runs": 12,
"p50_ms": 174.38,
"p95_ms": 320.61,
"min_ms": 142.41,
"max_ms": 320.61,
"rows_read": 5400000,
"bytes_read": 165330000
},
{
"label": "SaaS time series: daily series for ONE tenant from the AggregatingMergeTree rollup",
"runs": 12,
"p50_ms": 37.98,
"p95_ms": 60.34,
"min_ms": 22.25,
"max_ms": 60.34,
"rows_read": 21416,
"bytes_read": 42832
},
{
"label": "SAME time series computed from raw events instead of the rollup",
"runs": 12,
"p50_ms": 32.55,
"p95_ms": 85.96,
"min_ms": 22.03,
"max_ms": 85.96,
"rows_read": 40960,
"bytes_read": 75216
},
{
"label": "SaaS group-by: one tenant sliced by a dimension",
"runs": 12,
"p50_ms": 44.45,
"p95_ms": 317.18,
"min_ms": 22.92,
"max_ms": 317.18,
"rows_read": 40960,
"bytes_read": 75216
},
{
"label": "VehIQ point lookup: one vehicle by key, tenant-scoped (purpose-built projection)",
"runs": 12,
"p50_ms": 49.25,
"p95_ms": 89.99,
"min_ms": 28.31,
"max_ms": 89.99,
"rows_read": 8192,
"bytes_read": 761856
},
{
"label": "SAME point lookup against ONE GIANT TABLE",
"runs": 12,
"p50_ms": 236.6,
"p95_ms": 1227.93,
"min_ms": 174.21,
"max_ms": 1227.93,
"rows_read": 7401152,
"bytes_read": 196760496
},
{
"label": "VehIQ aggregate: average asking price by make for ONE tenant across 2M vehicles",
"runs": 8,
"p50_ms": 389.57,
"p95_ms": 16748.19,
"min_ms": 189.51,
"max_ms": 16748.19,
"rows_read": 2000000,
"bytes_read": 256400000
},
{
"label": "SAME aggregate against ONE GIANT TABLE",
"runs": 8,
"p50_ms": 680.82,
"p95_ms": 756.4,
"min_ms": 410.57,
"max_ms": 756.4,
"rows_read": 7401152,
"bytes_read": 447184368
}
],
"notes": [
"Fixtures are synthetic and generated in-server with numbers(); no production or b0ts data was read or written.",
"Each timing is the p50/p95 of repeated runs after one warm-up, measured client-side over HTTP on the same host.",
"The 'ONE GIANT TABLE' rows are the counterfactual BI-P010 warns against, measured rather than asserted."
],
"index_pruning": {
"purpose_built_event_table": {
"read": 5,
"total": 660
},
"one_giant_table": {
"read": 660,
"total": 1149
},
"note": "Granules read/total for the SAME question. The tenant-leading ORDER BY is what turns the forced tenant predicate (BI-P011) into a primary-key range scan instead of a full scan."
}
}
@@ -0,0 +1,64 @@
# Live probe: the only ClickHouse in the estate (2026-09-06)
Read-only inspection over the tailnet (`[email protected]`, siax-server7).
Nothing was written, altered or deleted. Only server metadata
(`system.databases`, `system.tables`, `system.columns`, `system.users`,
`system.row_policies`) was read — **no table content, no person data**.
## What is there
```
version() 26.7.1.1278
process clickhouse-server (native, not a container)
listening 127.0.0.1:8123/9000 and 10.100.0.5:8123/9000
databases INFORMATION_SCHEMA, default, information_schema,
opt_scraped, system
users default, b0ts, b0ts_writer, b0ts_reader
row policies 0
settings profiles default, readonly
```
`opt_scraped`: 51 tables, 407 793 471 rows in total. Largest by row count:
```
vehicles ReplacingMergeTree 104 759 599
cz_owners MergeTree 90 979 084
vehicle_details_v2 ReplacingMergeTree 50 987 449
cz_vehicles_full MergeTree 38 222 160
vehicle_history MergeTree 28 421 783
vehicle_price_history MergeTree 20 475 073
...
persons ReplacingMergeTree 9 457
persons_meta ReplacingMergeTree 9 457
```
## Three findings that change what can be claimed
1. **There is no `opt_analytics` database anywhere on this server.** The
`ClickHouseAnalytics` capability in this repo — described upstream as "an
existing working implementation" — has never been run against a deployed
instance. It works (it is exercised against real ClickHouse in CI and in
this branch's evidence), but it is not in production.
2. **This server is the b0ts scraping plane, and this module is prohibited
from touching it.** `src/analytics/clickhouse-analytics.ts`'s own header
states the boundary: never the b0ts ClickHouse pipelines
(Ratsit / person-PII, separate legal case) and never quarantined
`market='sverige'`/`'norge'` data (written DPIA prohibition). `opt_scraped`
holds exactly that, `persons`/`cz_owners` included. The briefing note that
"ClickHouse runs on server7 and holds 40M+ real Swedish vehicle rows" is
accurate about the server and, on inspection, describes the plane 0pt
analytics may not use.
3. **It could not satisfy BI-P011 even if it were available.** There is not a
single column named `tenant_id` or `project_id` anywhere on the server, and
there are zero row policies. There is nothing to force a predicate on.
## Consequence for BI-P009 … BI-P012
The canonical OLAP provider needs a **new, separate** ClickHouse for
`opt_analytics` — its own instance or at minimum its own database with
restricted users — before any of this reaches production. Every proof in this
branch was therefore run against disposable
`clickhouse/clickhouse-server:24.8` containers created and torn down by the
test/benchmark scripts.
+109
View File
@@ -0,0 +1,109 @@
BI-P002..BI-P012 — measured test transcript
===========================================
host: Linux 6.8.0-139-generic x86_64 node: v24.18.0 date(UTC): 2026-09-06T20:53:23Z
clickhouse under test: clickhouse/clickhouse-server:24.8 (disposable container, created and torn down by this run)
postgres under test: postgres:16-alpine (disposable container)
### 1. BI-P009 regression guard WITH the forced tenant predicate REMOVED (must be RED)
× BI-P009 regression guard: the forced tenant predicate > PRESERVED ClickHouseAnalytics still emits tenant_id = {tenant:String} on the wire 163ms
✓ BI-P009 regression guard: the forced tenant predicate > PRESERVED ClickHouseAnalytics still refuses a blank tenant_id 36ms
✓ BI-P009 regression guard: the forced tenant predicate > PRESERVED ClickHouseAnalytics still refuses a hostile group_by identifier 1ms
× BI-P009 regression guard: the forced tenant predicate > every statement the NEW compiler produces contains the forced predicate 34ms
✓ BI-P009 regression guard: the forced tenant predicate > the NEW compiler fails closed on a blank/absent tenant instead of emitting an unfiltered query 33ms
✓ BI-P009 regression guard: the forced tenant predicate > the constant itself is the predicate, so deleting the forcing cannot pass silently 1ms
⎯⎯⎯⎯⎯⎯⎯ Failed Tests 2 ⎯⎯⎯⎯⎯⎯⎯
Test Files 1 failed (1)
Tests 2 failed | 4 passed (6)
### 2. The same suite with the forcing RESTORED (must be GREEN)
✓ tests/analytics/tenant-predicate-regression.test.ts (6 tests) 85ms
Test Files 1 passed (1)
Tests 6 passed (6)
(working tree restored: 0 lines of diff in the preserved file)
### 3. BI-P011 tenant isolation against a LIVE disposable ClickHouse (hole shown OPEN, then CLOSED)
✓ tests/integration/analytics-tenant-isolation.integration.test.ts > BI-P011 tenant isolation against a LIVE ClickHouse > HOLE, layer 2 REMOVED: the same query WITHOUT the forced predicate returns t_beta's rows to t_alpha 49ms
✓ tests/integration/analytics-tenant-isolation.integration.test.ts > BI-P011 tenant isolation against a LIVE ClickHouse > CLOSED, layer 2 PRESENT: the compiled query returns t_alpha's 50 and never t_beta's 50000 60ms
✓ tests/integration/analytics-tenant-isolation.integration.test.ts > BI-P011 tenant isolation against a LIVE ClickHouse > tenant A querying tenant B's dataset id gets ZERO rows, not B's rows 23ms
✓ tests/integration/analytics-tenant-isolation.integration.test.ts > BI-P011 tenant isolation against a LIVE ClickHouse > a forged dataset id yields an empty result, never an error that leaks existence 22ms
✓ tests/integration/analytics-tenant-isolation.integration.test.ts > BI-P011 tenant isolation against a LIVE ClickHouse > a tenant with no data at all sees zero, not everyone's aggregate 24ms
✓ tests/integration/analytics-tenant-isolation.integration.test.ts > BI-P011 tenant isolation against a LIVE ClickHouse > group-by results carry only this tenant's dimension values 66ms
✓ tests/integration/analytics-tenant-isolation.integration.test.ts > BI-P011 tenant isolation against a LIVE ClickHouse > SQL/dimension/filter injection through the live path changes nothing 74ms
✓ tests/integration/analytics-tenant-isolation.integration.test.ts > BI-P011 tenant isolation against a LIVE ClickHouse > raw SQL attempt: the analyst-SQL surface is refused, not silently executed 1ms
✓ tests/integration/analytics-tenant-isolation.integration.test.ts > BI-P011 tenant isolation against a LIVE ClickHouse > HOLE, layer 3 ABSENT: an unrestricted user with no predicate sees every tenant 42ms
✓ tests/integration/analytics-tenant-isolation.integration.test.ts > BI-P011 tenant isolation against a LIVE ClickHouse > CLOSED, layer 3 PRESENT: the restricted user runs the SAME predicate-free statement and sees ONE tenant 200ms
✓ tests/integration/analytics-tenant-isolation.integration.test.ts > BI-P011 tenant isolation against a LIVE ClickHouse > the restricted user cannot write, and cannot reach a table it was not granted 90ms
✓ tests/integration/analytics-tenant-isolation.integration.test.ts > BI-P011 tenant isolation against a LIVE ClickHouse > every analytics table's sorting key LEADS with tenant_id (what makes the predicate cheap) 143ms
✓ tests/integration/analytics-tenant-isolation.integration.test.ts > BI-P011 tenant isolation against a LIVE ClickHouse > the tenant value never appears in the statement text the server receives 149ms
Test Files 1 passed (1)
Tests 13 passed (13)
### 4. BI-P009/BI-P010 provider + schema against the same LIVE ClickHouse
✓ tests/integration/analytics-engine-clickhouse.integration.test.ts > BI-P009/BI-P010 ClickHouse provider against a LIVE server > health() reports the live server's version 30ms
✓ tests/integration/analytics-engine-clickhouse.integration.test.ts > BI-P009/BI-P010 ClickHouse provider against a LIVE server > BI-P010: four purpose-built tables exist, NOT one giant table 12ms
✓ tests/integration/analytics-engine-clickhouse.integration.test.ts > BI-P009/BI-P010 ClickHouse provider against a LIVE server > BI-P010: the tables use different engines and different sort keys — the split is real 30ms
✓ tests/integration/analytics-engine-clickhouse.integration.test.ts > BI-P009/BI-P010 ClickHouse provider against a LIVE server > BI-P010: TTL and LowCardinality are actually applied, not just written in a comment 22ms
✓ tests/integration/analytics-engine-clickhouse.integration.test.ts > BI-P009/BI-P010 ClickHouse provider against a LIVE server > BI-P010: the materialized view actually populates the rollup 92ms
✓ tests/integration/analytics-engine-clickhouse.integration.test.ts > BI-P009/BI-P010 ClickHouse provider against a LIVE server > executeMetric returns grouped rows keyed by the CALLER-FACING dimension name 48ms
✓ tests/integration/analytics-engine-clickhouse.integration.test.ts > BI-P009/BI-P010 ClickHouse provider against a LIVE server > estimateQuery gets a real EXPLAIN ESTIMATE from the server and compares it to the budget 15ms
✓ tests/integration/analytics-engine-clickhouse.integration.test.ts > BI-P009/BI-P010 ClickHouse provider against a LIVE server > estimateQuery REFUSES a query whose estimate exceeds a tightened quota 11ms
✓ tests/integration/analytics-engine-clickhouse.integration.test.ts > BI-P009/BI-P010 ClickHouse provider against a LIVE server > explain() proves the forced predicate reaches the PRIMARY KEY, pruning parts 15ms
✓ tests/integration/analytics-engine-clickhouse.integration.test.ts > BI-P009/BI-P010 ClickHouse provider against a LIVE server > cancelQuery issues a real KILL QUERY the server accepts 33ms
✓ tests/integration/analytics-engine-clickhouse.integration.test.ts > BI-P009/BI-P010 ClickHouse provider against a LIVE server > ingestProjection writes the SERVING tier with the identity's tenant, ignoring any row-level claim 33ms
✓ tests/integration/analytics-engine-clickhouse.integration.test.ts > BI-P009/BI-P010 ClickHouse provider against a LIVE server > refreshProjection makes a re-ingest idempotent (ReplacingMergeTree + OPTIMIZE FINAL) 58ms
✓ tests/integration/analytics-engine-clickhouse.integration.test.ts > BI-P009/BI-P010 ClickHouse provider against a LIVE server > the PRESERVED ClickHouseAnalytics path still ingests and answers through the engine 35ms
Test Files 1 passed (1)
Tests 13 passed (13)
### 5. BI-P012 resource governance / query bomb against the same LIVE ClickHouse
✓ tests/integration/analytics-resource-governance.integration.test.ts > BI-P012 resource governance against a LIVE ClickHouse > max_rows_to_read terminates a read bomb (CH code 158 TOO_MANY_ROWS) 60ms
✓ tests/integration/analytics-resource-governance.integration.test.ts > BI-P012 resource governance against a LIVE ClickHouse > max_bytes_to_read terminates a scan bomb (CH code 307 TOO_MANY_BYTES) 26ms
✓ tests/integration/analytics-resource-governance.integration.test.ts > BI-P012 resource governance against a LIVE ClickHouse > max_execution_time terminates a slow bomb (CH code 159 TIMEOUT_EXCEEDED) 1014ms
✓ tests/integration/analytics-resource-governance.integration.test.ts > BI-P012 resource governance against a LIVE ClickHouse > max_result_rows terminates a result bomb and does NOT return a partial result 422ms
✓ tests/integration/analytics-resource-governance.integration.test.ts > BI-P012 resource governance against a LIVE ClickHouse > max_memory_usage terminates a memory bomb (CH code 241 MEMORY_LIMIT_EXCEEDED) 84ms
✓ tests/integration/analytics-resource-governance.integration.test.ts > BI-P012 resource governance against a LIVE ClickHouse > readonly=1 means the query text cannot re-raise its own limits 37ms
✓ tests/integration/analytics-resource-governance.integration.test.ts > BI-P012 resource governance against a LIVE ClickHouse > readonly=1 blocks writes through the query surface 26ms
✓ tests/integration/analytics-resource-governance.integration.test.ts > BI-P012 resource governance against a LIVE ClickHouse > an unrelated tenant stays within its declared SLO WHILE a query bomb is in flight 8163ms
✓ tests/integration/analytics-resource-governance.integration.test.ts > BI-P012 resource governance against a LIVE ClickHouse > the per-tenant concurrency gate refuses the N+1st in-flight query for THAT tenant only 220ms
Test Files 1 passed (1)
Tests 9 passed (9)
### 6. BI-P005 Arrow interop with ClickHouse's own Arrow C++ implementation
✓ tests/integration/analytics-arrow-clickhouse.integration.test.ts > BI-P005 Arrow IPC against a LIVE ClickHouse > THEIR encoder, OUR reader: ClickHouse ArrowStream decodes with the expected schema and row count 106ms
✓ tests/integration/analytics-arrow-clickhouse.integration.test.ts > BI-P005 Arrow IPC against a LIVE ClickHouse > WITHOUT output_format_arrow_string_as_string, ClickHouse emits Binary — the semantic loss the setting prevents 42ms
✓ tests/integration/analytics-arrow-clickhouse.integration.test.ts > BI-P005 Arrow IPC against a LIVE ClickHouse > OUR encoder, THEIR reader: ClickHouse INSERTs our Arrow and returns every value unchanged 76ms
✓ tests/integration/analytics-arrow-clickhouse.integration.test.ts > BI-P005 Arrow IPC against a LIVE ClickHouse > full circle: ClickHouse -> Arrow -> our decoder -> ClickHouse yields identical rows 281ms
✓ tests/integration/analytics-arrow-clickhouse.integration.test.ts > BI-P005 Arrow IPC against a LIVE ClickHouse > a large result survives the round trip (batching/offsets are not only correct for three rows) 690ms
Test Files 1 passed (1)
Tests 5 passed (5)
### 7. BI-P002 domain model against a LIVE disposable Postgres (restore drill + immutability)
✓ tests/analytics/analytics-domain-postgres.realinfra.test.ts > BI-P002 analytics domain model against a LIVE Postgres > restore drill: sql/008 applies cleanly on top of the replayed chain 6ms
✓ tests/analytics/analytics-domain-postgres.realinfra.test.ts > BI-P002 analytics domain model against a LIVE Postgres > all nineteen entity tables really exist after the restore 125ms
✓ tests/analytics/analytics-domain-postgres.realinfra.test.ts > BI-P002 analytics domain model against a LIVE Postgres > replaying sql/008 a second time is a no-op, not an error 253ms
✓ tests/analytics/analytics-domain-postgres.realinfra.test.ts > BI-P002 analytics domain model against a LIVE Postgres > persists a dataset and reads it back through the repository 27ms
✓ tests/analytics/analytics-domain-postgres.realinfra.test.ts > BI-P002 analytics domain model against a LIVE Postgres > TENANT ISOLATION: t_beta cannot read t_alpha's dataset, even with the exact id 7ms
✓ tests/analytics/analytics-domain-postgres.realinfra.test.ts > BI-P002 analytics domain model against a LIVE Postgres > TENANT ISOLATION: a version cannot be minted against another tenant's dataset 4ms
✓ tests/analytics/analytics-domain-postgres.realinfra.test.ts > BI-P002 analytics domain model against a LIVE Postgres > dataset versions are monotonic and carry the contract hash 136ms
✓ tests/analytics/analytics-domain-postgres.realinfra.test.ts > BI-P002 analytics domain model against a LIVE Postgres > IMMUTABILITY is enforced by the DATABASE: UPDATE and DELETE on a version row are refused 27ms
✓ tests/analytics/analytics-domain-postgres.realinfra.test.ts > BI-P002 analytics domain model against a LIVE Postgres > all four immutable entities refuse an UPDATE, not just the one that was tested first 638ms
✓ tests/analytics/analytics-domain-postgres.realinfra.test.ts > BI-P002 analytics domain model against a LIVE Postgres > a metric version after the first must state WHY the number changed meaning 123ms
✓ tests/analytics/analytics-domain-postgres.realinfra.test.ts > BI-P002 analytics domain model against a LIVE Postgres > a DatasetGrant without a purpose is refused by the DATABASE (purpose limitation) 134ms
✓ tests/analytics/analytics-domain-postgres.realinfra.test.ts > BI-P002 analytics domain model against a LIVE Postgres > a BIApplicationBinding without a purpose is refused too, and carries no credential column 40ms
✓ tests/analytics/analytics-domain-postgres.realinfra.test.ts > BI-P002 analytics domain model against a LIVE Postgres > the dimension catalog is tenant-scoped and FAILS CLOSED for a tenant with none 111ms
✓ tests/analytics/analytics-domain-postgres.realinfra.test.ts > BI-P002 analytics domain model against a LIVE Postgres > a dimension whose physical field is not identifier-safe is refused by the DATABASE 3ms
✓ tests/analytics/analytics-domain-postgres.realinfra.test.ts > BI-P002 analytics domain model against a LIVE Postgres > the repository refuses to act without a verified tenant scope 1ms
Test Files 1 passed (1)
Tests 15 passed (15)
### 8. Repository gates (the same commands .gitea/workflows/ci.yml runs)
TYPECHECK_EXIT=0
Test Files 54 passed | 9 skipped (63)
Tests 463 passed | 80 skipped (543)
TEST_EXIT=0
BUILD_EXIT=0
lint (ADVISORY in CI, continue-on-error): 12 pre-existing errors in tests/p0/* — ZERO in any file this branch adds.
### 9. Scope check
src/analytics/clickhouse-analytics.ts diff vs main: 0 lines (0 = preserved untouched)
.gitea/workflows diff vs main: 0 lines (0 = no protected file touched)
+107
View File
@@ -0,0 +1,107 @@
{
"duckdb_version": "1.5.5",
"recorded_at": "2026-09-07T01:15:40.775Z",
"parquet": {
"SE": 394.5,
"NO": 105.5
},
"csv": {
"rows": 3,
"includes_quoted_value": true
},
"injection_attempt": {
"matched_rows": 0,
"note": "escaped as data; 0 rows, not 3"
},
"iceberg": {
"read_by": "iceberg_scan on the exact metadata JSON",
"note": "an exact metadata file is a SNAPSHOT reference; DuckDB refuses to glob for the latest version by default, and that refusal is correct — globbing can read uncommitted data",
"totals": {
"NO": 20,
"SE": 40
}
},
"symlink_escape_refused": true,
"sandbox_bypass_attempts": [
{
"id": "read-etc-passwd",
"succeeded": false,
"engine_message": "\"Permission Error: Cannot access file \\\"/etc/passwd\\\" - file system operations are disabled by configuration\\n\\nLINE 1: SELECT * FROM read_c"
},
{
"id": "read-etc-shadow",
"succeeded": false,
"engine_message": "\"Permission Error: Cannot access file \\\"/etc/shadow\\\" - file system operations are disabled by configuration\\n\\nLINE 1: SELECT * FROM read_c"
},
{
"id": "traversal-from-mount",
"succeeded": false,
"engine_message": "\"Permission Error: Cannot access file \\\"/tmp/claude-1000/-/987b696c-9462-4fac-b1c0-4e07bad73920/scratchpad/w-0pt-bi/tests/fixtures/duckdb/.."
},
{
"id": "glob-root",
"succeeded": false,
"engine_message": "\"Permission Error: Cannot access file \\\"/etc/*\\\" - file system operations are disabled by configuration\\n\\nLINE 1: SELECT * FROM read_csv('/"
},
{
"id": "http-exfiltration",
"succeeded": false,
"engine_message": "\"Permission Error: Cannot access file \\\"https://example.com/a.csv\\\" - file system operations are disabled by configuration\\n\\nLINE 1: SELECT"
},
{
"id": "s3-read",
"succeeded": false,
"engine_message": "\"Permission Error: Cannot access file \\\"s3://bucket/a.parquet\\\" - file system operations are disabled by configuration\\n\\nLINE 1: SELECT * F"
},
{
"id": "attach-external-db",
"succeeded": false,
"engine_message": "\"Permission Error: Cannot access file \\\"/tmp/duckdb_escape.db\\\" - file system operations are disabled by configuration\""
},
{
"id": "attach-etc",
"succeeded": false,
"engine_message": "\"Permission Error: Cannot access file \\\"/etc/passwd\\\" - file system operations are disabled by configuration\""
},
{
"id": "copy-out-of-mount",
"succeeded": false,
"engine_message": "\"Permission Error: Cannot access file \\\"/tmp/duckdb_escape.csv\\\" - file system operations are disabled by configuration\""
},
{
"id": "read-parquet-outside",
"succeeded": false,
"engine_message": "\"Permission Error: Cannot access file \\\"/root/x.parquet\\\" - file system operations are disabled by configuration\\n\\nLINE 1: SELECT * FROM re"
},
{
"id": "json-outside",
"succeeded": false,
"engine_message": "\"Permission Error: Cannot access file \\\"/etc/hosts\\\" - file system operations are disabled by configuration\\n\\nLINE 1: SELECT * FROM read_js"
}
],
"counterfactual_mounted_file_readable": true,
"naive_allowed_directories_is_a_noop": {
"statements": [
"SET allowed_directories=['/tmp/claude-1000/-/987b696c-9462-4fac-b1c0-4e07bad73920/scratchpad/w-0pt-bi/tests/fixtures/duckdb']"
],
"read_etc_passwd_succeeded": true,
"note": "allowed_directories alone appears in duckdb_settings() and looks like a sandbox. It permits /etc/passwd and outbound HTTP. Only enable_external_access=false binds it."
},
"reconfiguration_refused": [
{
"statement": "SET allowed_directories=['/etc']",
"refused": true,
"engine_message": "\"Invalid Input Error: Cannot change configuration option \\\"allowed_directories\\\" - the configuration has been locked\""
},
{
"statement": "SET enable_external_access=true",
"refused": true,
"engine_message": "\"Invalid Input Error: Cannot change configuration option \\\"enable_external_access\\\" - the configuration has been locked\""
},
{
"statement": "SET lock_configuration=false",
"refused": true,
"engine_message": "\"Invalid Input Error: Cannot change configuration option \\\"lock_configuration\\\" - the configuration has been locked\""
}
]
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,29 @@
{
"clickhouse_version": "24.8.14.39",
"recorded_at": "2026-09-07T01:15:40.234Z",
"counterfactual_still_running_after_2s": true,
"cancellation": {
"rows_read_before_cancel": 4227318261,
"elapsed_ms_to_verified_stop": 162,
"verified_stopped": true,
"clickhouse_query_log_type": "ExceptionWhileProcessing",
"clickhouse_exception_code": 394
},
"budget_in_flight": {
"budget_max_rows_scanned": 1000000,
"observed_rows_read_at_cancel": 153318696,
"observed_elapsed_ms_at_cancel": 55,
"polls_before_breach": 1,
"overshoot_factor": 153,
"overshoot_note": "in-flight enforcement is granular to the poll interval; the query overshot the window by this factor before the poll that caught it. A bound, not a hard cap.",
"cancellation_verified": true,
"clickhouse_exception_code": 394,
"charged_for_work_done_before_cancel": true
},
"advisory_posture_is_declared": {
"admission": "estimate is compared to the remaining window before the query starts",
"in_flight": "NOT ENFORCED — this budget is advisory. A query that exceeds its estimate runs to completion.",
"across_replicas": "window spend is per-process — with N replicas a tenant can spend up to N times this budget",
"binding": false
}
}
+33
View File
@@ -0,0 +1,33 @@
{
"clickhouse_version": "24.8.14.39",
"recorded_at": "2026-09-07T01:15:45.657Z",
"not_null": {
"evaluated": 118,
"violations": 5
},
"range": {
"violations": 3
},
"distribution": {
"violations": 4
},
"unique": {
"violations": 11,
"breakdown": "6 rows on dup_0/dup_1, plus 5 rows sharing the empty-string key"
},
"empty_dataset": {
"raw_counts_from_clickhouse": {
"violations": 0,
"evaluated": 0
},
"verdict_passed": false,
"note": "a real engine returns zero violations over zero rows; the provider refuses to call that a pass"
},
"tenant_isolation": {
"base_table_rows": 618,
"alpha_evaluated": 118,
"alpha_violations": 5,
"beta_evaluated": 500,
"beta_violations": 500
}
}
+62
View File
@@ -0,0 +1,62 @@
{
"prompt": "BI-P029",
"title": "Golden metric parity: 0pt metric compiler vs an independent spec-driven renderer",
"recorded_at": "2026-09-07T06:23:27.839Z",
"clickhouse_version": "26.3.10.60",
"golden_metric": {
"id": "m_revenue",
"name": "net_revenue",
"definition_filters": [
{
"dimension": "channel",
"operator": "ne",
"values": [
"internal"
]
}
],
"semantic_model": {
"model_id": "sm_sales",
"version": 1,
"hash": "c5b9cac1b5fdcfbfb89a1e960b946a9b33b8c29dc14fe9a304c134f7a0fb73a7"
}
},
"expected_from_typescript": {
"SE": 1250,
"NO": 400,
"DK": 125.5
},
"regression_guarded": {
"description": "the same request compiled WITHOUT the metric definition filters — what 0pt returned before this change",
"result": {
"DK": 3458.5,
"NO": 8177,
"SE": 11249
}
},
"path_a": {
"compiler": "0pt compileRequestToClickHouse",
"aggregate": "sumIf",
"result": {
"DK": 125.5,
"NO": 400,
"SE": 1250
}
},
"path_b": {
"compiler": "MetricFlowProvider.compile + independent renderer",
"aggregate": "sum(if(...))",
"result": {
"DK": 125.5,
"NO": 400,
"SE": 1250
}
},
"tolerance": "1e-9 relative",
"verdict": "PASS",
"still_open": [
"MetricFlow itself was not executed (no Python runtime provisioned for this repo)",
"the Superset integration path is not implemented",
"the AI Analyst path (inf0#29) has not been compared against this provider"
]
}
@@ -0,0 +1,42 @@
{
"recorded_at": "2026-09-07T01:50:09.216Z",
"postgres_version": "16.15",
"guard_present": {
"partial_unique_index_present": true,
"transactions_committed": 1,
"rejections": [
{
"code": "23505",
"constraint": "opt_analytics_dashboard_release_one_published"
}
],
"published_releases_after": [
{
"release_id": "rel_1",
"version": 1
}
]
},
"guard_absent": {
"partial_unique_index_present": false,
"transactions_committed": 2,
"rejections": [],
"published_releases_after": [
{
"release_id": "rel_1",
"version": 1
},
{
"release_id": "rel_2",
"version": 2
}
]
},
"verdict": {
"counterfactual_produced_two_live_dashboards": true,
"guard_left_exactly_one": true,
"loser_error_code": "23505",
"application_check_alone_is_sufficient": false,
"note": "DashboardReleaseService.publish() reads for a live release before writing. Both sessions in guard_absent passed that check and both committed. The partial unique index is what holds."
}
}
+173
View File
@@ -0,0 +1,173 @@
{
"prompt": "BI-P103",
"title": "First measured BI SLO baselines",
"recorded_at": "2026-09-07T06:26:43.457Z",
"host_note": "One idle host, local ClickHouse, warm page cache, single-threaded client. A floor for the shape of the distribution on this fixture — not a production SLA.",
"clickhouse_version": "26.3.10.60",
"fixture": {
"rows": 400000,
"table": "slo_fact",
"partitions": "MergeTree ORDER BY (tenant_id, bucket, ts)"
},
"workload": {
"cold_dashboard_queries": 120,
"cached_dashboard_queries": 120,
"exploration_queries": 220,
"report_queries": 0
},
"window": {
"from": "2026-09-07T06:26:39.422Z",
"to": "2026-09-07T06:26:43.447Z"
},
"catalogue_size": 11,
"fully_measured": false,
"unresolved_queries": 0,
"summary": {
"met": 7,
"breached": 0,
"insufficient_data": 1,
"not_measurable_here": 3,
"measured_fraction": 0.6363636363636364
},
"results": [
{
"objective_id": "dash.availability",
"workload": "interactive_dashboard",
"kind": "availability",
"status": "met",
"target": 0.995,
"unit": "ratio",
"observed": 1,
"sample_size": 240,
"low_confidence": false,
"detail": "0 failed of 240 terminal queries"
},
{
"objective_id": "dash.p95_first_query",
"workload": "interactive_dashboard",
"kind": "latency_p95_first",
"status": "met",
"target": 3000,
"unit": "ms",
"observed": 8.893520999999964,
"sample_size": 120,
"low_confidence": false,
"detail": "p95 over 120 samples"
},
{
"objective_id": "dash.p95_cached",
"workload": "interactive_dashboard",
"kind": "latency_p95_cached",
"status": "met",
"target": 400,
"unit": "ms",
"observed": 0.024498999999877924,
"sample_size": 120,
"low_confidence": false,
"detail": "p95 over 120 samples"
},
{
"objective_id": "dash.error_rate",
"workload": "interactive_dashboard",
"kind": "error_rate",
"status": "met",
"target": 0.005,
"unit": "ratio",
"observed": 0,
"sample_size": 240,
"low_confidence": false,
"detail": "0 failed of 240 terminal queries"
},
{
"objective_id": "dash.freshness",
"workload": "interactive_dashboard",
"kind": "freshness",
"status": "not_measurable_here",
"target": 900,
"unit": "seconds",
"sample_size": 0,
"low_confidence": false,
"detail": "measured from analytics_freshness_watermark; BI usage events cannot answer it — Data age is a property of the DATASET (BI-P026 freshness, BI-P105 watermark), not of a usage event. Usage events cannot measure it and this evaluator does not pretend to."
},
{
"objective_id": "explore.p95",
"workload": "exploration",
"kind": "latency_p95",
"status": "met",
"target": 10000,
"unit": "ms",
"observed": 17.072708000000148,
"sample_size": 220,
"low_confidence": false,
"detail": "p95 over 220 samples"
},
{
"objective_id": "explore.p99",
"workload": "exploration",
"kind": "latency_p99",
"status": "met",
"target": 60000,
"unit": "ms",
"observed": 21.640736000000288,
"sample_size": 220,
"low_confidence": false,
"detail": "p99 over 220 samples"
},
{
"objective_id": "explore.max_result",
"workload": "exploration",
"kind": "max_result_rows",
"status": "met",
"target": 1000000,
"unit": "rows",
"observed": 96,
"sample_size": 220,
"low_confidence": false,
"detail": "largest result seen in the window"
},
{
"objective_id": "explore.timeout",
"workload": "exploration",
"kind": "timeout",
"status": "not_measurable_here",
"target": 300,
"unit": "seconds",
"sample_size": 0,
"low_confidence": false,
"detail": "measured from engine_configuration; BI usage events cannot answer it — The configured ceiling (BI-P012 settings profile), not an observation."
},
{
"objective_id": "report.completion_sla",
"workload": "report",
"kind": "completion_sla",
"status": "insufficient_data",
"target": 900000,
"unit": "ms",
"sample_size": 0,
"low_confidence": false,
"detail": "no report_generated events"
},
{
"objective_id": "report.delivery_sla",
"workload": "report",
"kind": "delivery_sla",
"status": "not_measurable_here",
"target": 300000,
"unit": "ms",
"sample_size": 0,
"low_confidence": false,
"detail": "measured from n0tify_delivery_receipt; BI usage events cannot answer it — Produced is not delivered. aud0 has no delivery event; the receipt is N0TIFY's, so this objective is declared and reported unmeasured rather than proxied by completion."
}
],
"measured_but_narrower_than_production": [
"dash.p95_cached is the IN-PROCESS reference cache (InMemoryResultCache). A Valkey deployment adds a network round trip, so 0.03 ms here is a floor and not the number a user will see.",
"Every latency is the ENGINE round trip only: no HTTP layer, no CL0UD authorization, no serialization to the caller. The end-to-end p95 is larger by whatever those cost.",
"One tenant, one client, no concurrency. Contention is not represented."
],
"not_measured_and_why": [
"dash.freshness — a property of the DATASET (BI-P026 watermark), not of a usage event",
"explore.timeout — the configured BI-P012 ceiling, not an observation",
"report.completion_sla — nothing in 0pt emits aud0.report_generated yet, so the sample is 0",
"report.delivery_sla — delivery is N0TIFY's receipt; aud0 has no delivery event"
]
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,75 @@
{
"clickhouse_version": "26.3.10.60",
"recorded_at": "2026-09-07T01:55:42.821Z",
"source_rows": 2000000,
"after_backfill": {
"verdict": "match",
"buckets_compared": 48,
"revenue_total": {
"source": 801571002,
"aggregate": 801571002,
"delta": 0
}
},
"performance": {
"note": "ClickHouse caches marks and pages between repetitions, so these are WARM numbers on one host with nothing else running. They describe this shape of query on this data, not a system property.",
"repetitions": 9,
"base_table_ms": {
"n": 9,
"min": 48.70366200000012,
"p50": 76.67811500000016,
"p95": 115.04416399999991,
"max": 115.04416399999991,
"spread_ratio": 2.36
},
"pre_aggregate_ms": {
"n": 9,
"min": 15.281603999999788,
"p50": 22.727642999999944,
"p95": 84.41279499999973,
"max": 84.41279499999973,
"spread_ratio": 5.52
},
"speedup_p50": 3.4,
"speedup_range_min_max": [0.6, 7.5]
},
"gdpr_erasure_drill": {
"mutation": "ALTER TABLE sales DELETE WHERE tenant_id='t_alpha' AND customer_id < 250",
"verdict": "drifted",
"buckets_compared": 48,
"revenue_true_after_erasure": 761580554,
"revenue_pre_aggregate_would_report": 801571002,
"revenue_overstatement": 39990448,
"revenue_overstatement_pct": 5.251,
"worst_bucket": {
"key": "2026-08-28|FI",
"metric": "revenue",
"source_value": 15830779,
"aggregate_value": 16699145,
"absolute_delta": 868366,
"relative_delta": 0.05485301765630106
},
"guarded_router_decision": {
"source": "base_table",
"refusal": "state_not_serving",
"detail": "materialization state is \"drifted\""
},
"staleness_only_router_would_serve": true,
"staleness_seconds_at_decision": 1,
"note": "The aggregate was NOT stale by any clock: it had just been refreshed, and every freshness check passed. Only the source comparison caught it. This is why staleness alone is not a correctness guarantee."
},
"after_rebuild": {
"verdict": "match",
"revenue_total": {
"source": 761580554,
"aggregate": 761580554,
"delta": 0
},
"routing": {
"source": "materialization",
"materialization_id": "mv_sales_daily",
"target_ref": "opt_p105_mtql9p2f.sales_daily",
"staleness_seconds": 0
}
}
}
+50
View File
@@ -0,0 +1,50 @@
{
"$comment": [
"GOV-06 substantiation record for siax.repo.json's `operationalState`.",
"",
"WHY THIS FILE EXISTS: `operationalState` is a claim about the world, and",
"scripts/siax-doctor.mjs cannot check the world from CI (no network, and a",
"check that needs the internet is a check that goes red for the wrong",
"reason). What the doctor CAN do offline is refuse to accept the claim",
"unless it is backed by a dated, machine-readable probe result that agrees",
"with it. That is this file. Setting operationalState to \"running\" while",
"the probes below say 402/404 now fails `pnpm siax:doctor`.",
"",
"HOW TO REFRESH: `node scripts/siax-doctor.mjs --live --write-evidence`",
"(opt-in, needs network). Or edit by hand from a real probe -- but the",
"doctor cross-checks `ok` against `httpStatus`, so a hand-written",
"`ok: true` next to a 402 is itself a failure."
],
"control": "GOV-06",
"operationalState": "running",
"checkedAt": "2026-09-22T19:08:50Z",
"method": "scripts/siax-doctor.mjs --live --write-evidence (fetch, 15000ms timeout)",
"probes": [
{
"fqdn": "0pt.app",
"env": "prod",
"url": "https://0pt.app/api/health",
"httpStatus": 200,
"ok": true,
"note": "server: unknown"
},
{
"fqdn": "api.0pt.app",
"env": "prod",
"url": "https://api.0pt.app/api/health",
"httpStatus": 200,
"ok": true,
"note": "server: unknown"
}
],
"securityHeadersObserved": {
"content-security-policy": "default-src 'self'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'; img-src 'self' data: blob:; font-src 'self' data:; connect-src 'self'; frame-src 'none'; frame-ancestors 'none'; form-action 'self'; base-uri 'self'; object-src 'none'",
"strict-transport-security": "max-age=63072000; includeSubDomains; preload",
"x-frame-options": "DENY",
"x-content-type-options": "nosniff",
"referrer-policy": "strict-origin-when-cross-origin"
},
"runtimeEvidence": {
"$comment": "Runtime-state 2026-09-15 (inuti SIAX Cloud, ej publikt routat): Coolify-app 54 shxd6lepxuxfsjsp0ath3z1g pa server6; container healthy; /api/health {ok:true, db:ok}; /api/ready HTTP 200 {ready:true}; security headers (HSTS/XFO/CSP) observerade; egen Postgres (0pt-edge-postgres, uuid xh70k0qa0cyju840zsvsgoze, migrations 001-013 = 60 tabeller, icke-superuser-roll 0pt_app NOBYPASSRLS); backup-cron 03:15 motor + 03:05 edge-DB; 0pt.app-DNS-cutover kvar hos Simon."
}
}