OpenPanel is an open-source web and product analytics platform, an open-source alternative to Mixpanel with optional self-hosting.
ralph(M15-121): Per-module fixes: packages/core/src/modules/profile - R1 and the findings no rule covers
ralphe42cb8e05011
diff --git a/packages/core/src/modules/profile/profile.routes.test.ts b/packages/core/src/modules/profile/profile.routes.test.tsindex dafa3f07c..bfb67116d 100644--- a/packages/core/src/modules/profile/profile.routes.test.ts+++ b/packages/core/src/modules/profile/profile.routes.test.ts@@ -1,9 +1,10 @@// The three /profile routes end to end through `app.handle()`: status codes// and text bodies match V1's controller byte for byte, and each handler hands-// the service exactly what the controller did. `../../http/client-auth` is a-// P8 stub (always null), so it is mocked like http/auth.test.ts does; the-// service and the geo lookup are mocked so nothing reaches a database. Every-// mock is registered before the subject's first (dynamic) import — AGENTS.md.+// the service exactly what the controller did. `../../http/client-auth`'s+// `authenticateClient` is mocked so the client principal is deterministic,+// same as http/auth.test.ts does; the service and the geo lookup are mocked+// so nothing reaches a database. Every mock is registered before the+// subject's first (dynamic) import — AGENTS.md.import { beforeAll, beforeEach, expect, mock, test } from 'bun:test';import { stubAppDeps } from '../../../test/http-fixtures';diff --git a/packages/core/src/modules/profile/profile.routes.ts b/packages/core/src/modules/profile/profile.routes.tsindex 7001e9ad2..51c5be609 100644--- a/packages/core/src/modules/profile/profile.routes.ts+++ b/packages/core/src/modules/profile/profile.routes.ts@@ -6,13 +6,9 @@// profile id, `400 'No projectId'`, `404 'Not found'`, `400 'Not number'`)// match V1's `reply.status(..).send(..)` byte for byte.//-// NAMED GAP, same as import.routes.ts: not yet reachable. `authenticateClient`-// (http/client-auth.ts) is a P8 stub that always returns null, so `clientAuth`-// 401s every request until it is filled in, and main.ts does not mount-// `publicApiRoutes` until a real `AppDeps` exists. `ingest` is V1's-// `clientHook` (the SDK credential rules); V1's `isBotHook` and-// `subscriptionHook` on this router are P8's too — the ingest module owns-// them, not this one.+// `ingest` is V1's `clientHook` (the SDK credential rules); V1's `isBotHook`+// and `subscriptionHook` on this router live in the ingest module, not this+// one.//// V1 has no request-body schema for these routes (ADR-003: "/profile, /import,// /event and /tools have no request schemas today, and adding them would be adiff --git a/packages/core/src/modules/profile/profile.service.ts b/packages/core/src/modules/profile/profile.service.tsindex c4dd7572d..20ae80bba 100644--- a/packages/core/src/modules/profile/profile.service.ts+++ b/packages/core/src/modules/profile/profile.service.ts@@ -5,7 +5,7 @@// tools, apps/api's controllers, notification.service, the buffers' types)// keep working while V1 runs (DELEGATE PATTERN).//-// Every query is a `sql` fragment (src/profile.sql.ts), converted one at a+// Every query is a `sql` fragment (src/sql.ts), converted one at a// time with a result-set proof each, per ADR-013. `buildFilterWhere` is NOT// converted here: it is the shared filter compiler, out of this task's scope;// src/filter-clauses.ts is the one bridge.@@ -47,9 +47,9 @@ import {profileSessionsQuery,profilesByIdsQuery,profileValuesQuery,-} from './src/profile.sql';+} from './src/sql';-export { profileSearchCondition } from './src/profile.sql';+export { profileSearchCondition } from './src/sql';const PROFILES_CACHE_SECONDS = 60 * 5;const PROPERTY_KEYS_CACHE_SECONDS = 60;diff --git a/packages/core/src/modules/profile/src/profile-metrics-sql.test.ts b/packages/core/src/modules/profile/src/profile-metrics-sql.test.tsindex e805adeaa..d23ff383b 100644--- a/packages/core/src/modules/profile/src/profile-metrics-sql.test.ts+++ b/packages/core/src/modules/profile/src/profile-metrics-sql.test.ts@@ -9,7 +9,7 @@// tag never interpolates, so the hostile value can only appear in the params.import { describe, expect, test } from 'bun:test';-import { profileMetricsQuery } from './profile.sql';+import { profileMetricsQuery } from './sql';const PROJECT_ID = 'test-sql-validation';const PROFILE_ID = 'profile-1';diff --git a/packages/core/src/modules/profile/src/profile.sql.proof.md b/packages/core/src/modules/profile/src/profile.sql.proof.mdindex 6684806b7..b368a3172 100644--- a/packages/core/src/modules/profile/src/profile.sql.proof.md+++ b/packages/core/src/modules/profile/src/profile.sql.proof.md@@ -1,6 +1,6 @@-# profile.sql.ts — V1 → V2 result-set proof (M7-002)+# profile.sql.ts (now src/sql.ts) — V1 → V2 result-set proof (M7-002)-Every query builder in `profile.sql.ts` was executed twice against the same data — once as V1 (the `git HEAD` service/router code, `3300f2a0`) and once as V2 (core's service, which renders the builder) — through one patched ClickHouse client that captured each statement, its `query_params`, `clickhouse_settings`, wall time and the raw JSON response. The two responses were compared on `data` (every row, every column, as JSON) and `meta` (column names and types). Statements without an `ORDER BY` were compared as row sets, because ClickHouse's parallel aggregation returns them in a different order run to run — V1 against itself too.+Every query builder in `src/sql.ts` (`profile.sql.ts` at proof time; renamed under R1, M15-121) was executed twice against the same data — once as V1 (the `git HEAD` service/router code, `3300f2a0`) and once as V2 (core's service, which renders the builder) — through one patched ClickHouse client that captured each statement, its `query_params`, `clickhouse_settings`, wall time and the raw JSON response. The two responses were compared on `data` (every row, every column, as JSON) and `meta` (column names and types). Statements without an `ORDER BY` were compared as row sets, because ClickHouse's parallel aggregation returns them in a different order run to run — V1 against itself too.- **Date**: 2026-09-04. **Data**: local prod-copy `openpanel` (319,499,000 events, static), project `redcollege` unless noted; cases needing rows the prod-copy lacks (`cohort_members`, `events_bots` are empty there) also ran on the isolated `openpanel_test` database with 3,380 events copied from `redcollege` under project `m7-002-proof`, plus seeded cohort/bot rows (deleted afterwards).- **Machine**: single-node ClickHouse 26.1.3.52 on a 4-vCPU box — timings are directional only; production is 2 shards × 2 replicas (`docs/ENVIRONMENT.md`). `rows_read` differences on JOIN statements are ClickHouse's per-run accounting of the right-hand side, not a plan difference: the SQL text is identical up to `{pN:Type}` binding.diff --git a/packages/core/src/modules/profile/src/profile.sql.test.ts b/packages/core/src/modules/profile/src/sql.test.tssimilarity index 99%rename from packages/core/src/modules/profile/src/profile.sql.test.tsrename to packages/core/src/modules/profile/src/sql.test.tsindex 24cb59e5b..8dfe8b8da 100644--- a/packages/core/src/modules/profile/src/profile.sql.test.ts+++ b/packages/core/src/modules/profile/src/sql.test.ts@@ -24,7 +24,7 @@ import {profileSessionsQuery,profilesByIdsQuery,profileValuesQuery,-} from './profile.sql';+} from './sql';const PROJECT_ID = 'proj-1';const PROFILE_ID = 'prof-1';diff --git a/packages/core/src/modules/profile/src/profile.sql.ts b/packages/core/src/modules/profile/src/sql.tssimilarity index 100%rename from packages/core/src/modules/profile/src/profile.sql.tsrename to packages/core/src/modules/profile/src/sql.ts