Skip to content

Commit 3b4f0b9

Browse files
ci(temporal-conformance): PostgreSQL service on pgvector's PG 16 image; merge-queue run on live paths (#37155)
Fixes #37095 Clause-②: no Metadata-protocol: none ## 维护者速读 - 用户能看到什么变化:用户无感。CI 里带数据库的测试任务改用带 pgvector 的 PostgreSQL 镜像(按指纹锁定),新增一条验证向量扩展的测试;按你的裁决 B(记录 7146156389),改到相关文件时合并队列也跑这个任务,PR 阶段仍不跑。 - 为什么做:知识检索的 pgvector 存储需要真实数据库验证;你已定这个任务不设为必过(「#37155 不需要」),所以队列里的这次运行只作提示,变红不挡合并。 - 出错会怎样:坏镜像不会被拦下,会进 main 并让之后的主干运行变红;改回原镜像一行即可撤回。每 30 天约多花 1,550 分钟机器时间(下限)。 - 要你做什么:批准并手工合并。契约审核复审 PASS:记录 7149149161,Head-sha `e6cb50b2549117a8a9cfd7e4c44fc3b6759235df`。可选:合并前在分支 `claude/issue-37095-ci-pgvector` 上手动触发一次 `ci.yml`,看 `Temporal Conformance (live PG + MySQL)` 成功、driver-sql 步骤含 `sql-driver-37095-pgvector-extension.test.ts (2 tests)`;不跑的话,席位在合并后读主干这一跑,变红即回滚。 ## What changes 1. **Image** (`temporal-conformance`'s postgres service): `mirror.gcr.io/library/postgres:16` becomes `mirror.gcr.io/pgvector/pgvector:0.8.7-pg16@sha256:484e838076e04939d27d3e176e91c86eea96236126023be8d3059761122e579f`. - The image is pgvector's own, built `FROM postgres:16-bookworm`, so the PostgreSQL major, the entrypoint, `pg_isready` and `psql` are unchanged. The `vector` extension is built in. - **Registry reachability:** pulled through `mirror.gcr.io`, the repo's convention for every service image (Google's Docker Hub cache, which avoids Docker Hub's anonymous per-IP quota, #22541). On 2026-11-24 `mirror.gcr.io` answered 200 for the tag `0.8.7-pg16` and for the digest itself. - **Pin:** exact tag plus index digest (`tag@sha256`). Docker pulls by the digest, so a re-pushed tag cannot change the server. The digest is the same on mirror.gcr.io and Docker Hub. No other workflow here pins a digest; the review's nit asked for it, and `services.*.image` accepts the form. No actionlint runs in this repo to object. 2. **Merge-queue run on path hits.** The maintainer ruled card What 2 = B (ruling record 7146156389), verbatim: 「B:改成「改到相关文件时,合并队列里也跑这个任务」。这会推翻 #22998 的裁决,每次相关合并都多花分钟数。」 - Before this PR, `temporal-conformance` ran on push to main, schedule and workflow_dispatch only, never on `pull_request` or `merge_group` (#22998, THE TWO SPEEDS). - It now also runs on `merge_group` when the entry's diff touches the new `temporal_live` output of the existing `dorny/paths-filter` step in the `filter` job (the mechanism the ui jobs already use on the queue). - New `if:`: `… && github.event_name != 'pull_request' && (github.event_name != 'merge_group' || needs.filter.outputs.temporal_live != 'false')`. - It fails open like the ui outputs: a queue build whose filter step failed reads `''`, which becomes `'true'`, so the job runs. - `pull_request` stays excluded. Push, schedule and dispatch are unchanged, and the job still reads no queue verdict (`MAIN_ONLY_JOBS`), so a queue hit also runs again on the push that follows. - **Advisory on the queue.** `Temporal Conformance (live PG + MySQL)` is NOT a required context (`scripts/check-required-contexts.mjs` holds it as a #22998 tombstone). A red queue run therefore does not eject the entry: the entry lands and the red shows on `main` (push, the 4-hourly run, the release lane's full-battery read). - This PR adds no `REQUIRED_CONTEXTS` row. Enrolment would be its own maintainer ruling, as #30461 was for dogfood. 3. **`temporal_live` paths:** - `packages/plugins/knowledge-pgvector/**`: the store's package. It does not exist yet; #37100 adds it, and the step that runs its tests is a separate governed edit. - `packages/drivers/driver-sql/**`: the job runs this whole suite against the live servers. - `packages/metadata-protocol/src/**/*live-mysql*` and `…/*live-postgres*`: the same set the step's `live-mysql live-postgres` substrings select, including `live-mysql-database.isolation.test.ts` and the testkit. - `packages/runtime/src/**/cascade-delete-multivalue-lookup-real-driver*`: the file the runtime step selects. - The 22 `packages/services/service-analytics/src/__tests__` files whose live-PostgreSQL cells key on `OS_TEST_POSTGRES_URL` (#21564). No glob selects exactly these, so they are listed, and a new such file must be added by hand: analytics-faces-one-lowering, cube-measure-field-type-door, cube-measure-relationship-path-type, dataset-duration-measure, dataset-tools, home-amount-consolidated-measure, json-stored-door-live-drivers, json-stored-door-undeclared-join, list-at-scalar-operator-both-faces, native-sql-aggregate-policies, native-sql-base-column-qualify, native-sql-boolean-comparand-door, native-sql-empty-sum-order-window, native-sql-measure-number-presentation, native-sql-number-comparand-door, native-sql-offset-only-window, objectql-echo-bucket-enumeration, objectql-echo-date-bucket, objectql-echo-offset-only-window, objectql-face-order-limit, order-key-selected, read-scope-temporal-coercion. - `.github/workflows/ci.yml`. - Left out on purpose: the rest of core, formula, driver-memory, driver-mongodb and service-analytics (the non-SQL leg's server-less tests). Most merges touch them, so including them would run the job on nearly every queue entry. The review accepted this. 4. **Rule text revised** to name the one exception: `ci.yml`'s THE TWO SPEEDS header, the `filter.outputs` comments and the paths-filter step comment, plus `docs/agents/multi-agent-discipline.md` (Two speeds paragraph), which cites ruling record 7146156389. - Still stating the old rule, untouched on purpose: the tombstone prose in `scripts/check-required-contexts.mjs`. It is about the required set, which this PR does not change. 5. **Test:** `packages/drivers/driver-sql/src/sql-driver-37095-pgvector-extension.test.ts`, PG-only, declared through `declareDialectCell(PG_CELL)` like every live driver-sql file: - no URL: a named skip; - `OS_EXPECT_LIVE_DIALECT_MATRIX=1` without a URL: red. - What it does: `CREATE EXTENSION IF NOT EXISTS vector`; reads the extension's schema from `pg_extension` and qualifies the type and operator with it; orders three rows by the pgvector L2 distance operator and checks the distances (0, 1, sqrt 26). - The job's driver-sql step runs this package's whole suite with the URL and the flag. - No adapter code (#37100). - `skip-changeset`: a `*.test.ts` under `src/`, and driver-sql's `files[]` is `dist`, `README.md`, `CHANGELOG.md`. ## Monthly minutes - **Before (advisory, not a gate):** `Temporal Conformance (live PG + MySQL)` success durations over the 15 most recent `schedule` runs: median **~541 s** (max 708 s, n about 16; one API row errored). - **After:** NOT MEASURED. The new image's median and the per-hit cost need the first runs. The expected difference per run is the image pull alone. - **Added queue minutes.** Method: count first-parent commits on `origin/main` that touch the `temporal_live` paths (`git log --first-parent --since --until -- PATHS`), multiplied by the 541 s median. With the revised path list: - **30-day window** 2026-10-25 to 2026-11-24 (checkout deepened to 2026-10-24): 172 of 5275 commits hit, 49 of them `ci.yml`. That is **~1,550 runner-minutes (~26 h) per 30 days**. - **10-day window** 2026-11-14 to 2026-11-24: 51 of 1605 commits hit (only 3 of them `ci.yml`; the `ci.yml` churn was heavier earlier in the month). Scaled to 30 days that is about 153 hits, ~1,380 minutes. - The review's ~1,130 minutes was this same 10-day scaling on the earlier, shorter path list (43 hits). - All of these are lower bounds: re-queued or ejected entries run the job again. Push and schedule minutes are unchanged. ## Tests <details><summary>Live run, PostgreSQL 16.15 + apt pgvector 0.6.0 (local; the CI image's 0.8.7 is not yet exercised)</summary> - URL + `OS_EXPECT_LIVE_DIALECT_MATRIX=1`: - `✓ src/sql-driver-37095-pgvector-extension.test.ts (2 tests)` - `✓ src/live-dialect-matrix.isolation.test.ts (20 tests | 1 skipped)` - VERDICT command-exit 0 - No URL: named skip, exit 0. - No URL, with the flag: exit 1 with the named provisioning failure. - **Negative leg:** a server without the extension: exit 1, `extension "vector" is not available`. A plain `postgres:16` image would give this red. - `pnpm --filter @objectstack/driver-sql typecheck`: exit 0. The new file is in `--listFiles`. - Not re-run on e6cb50b: that commit changes only `ci.yml` and docs. </details> <details><summary>Gates (head e6cb50b)</summary> - `dispatch-gates --commands`: 87 families derived; `--ran`: `87 derived, 84 run, 3 NOT-MEASURED, 0 UNRUN`. - The 3 exit 3 PREREQUISITE NOT MET (they need the whole workspace's `dist/`): `check:dts-closure`, `check:dual-build-cjs-loads`, `check:lean-entry-closure`. CI owns them. - `check:doc-formula-expressions` first exited 3 and was 0 after building formula and lint. - Exit 0 among them: `check:required-contexts`, `check:pm-expected-skips`, `check:stall-guard-budget`, `check:stall-guard-headroom`, `check:shard-attestation`, `scheduled-full-run.mjs --self-test`, `check:nul-bytes`. - `check-governed-merges.mjs --branch`: GOVERNED, landing tier H(人合). readWorkflowDiff, verbatim: `Tier H by content — .github/workflows/ci.yml: a uses: / image not used anywhere on the base tree: mirror.gcr.io/pgvector/pgvector:0.8.7-pg16; an existing job no longer holds uses: mirror.gcr.io/library/postgres:16: temporal-conformance; an if: added or changed in a job that already ran: job:temporal-conformance; a uses: / image dropped from the file: mirror.gcr.io/library/postgres:16`. - `overlap-check`: `VERDICT clean exit 0` against origin/main 49c8e0f. </details> ## Acceptance notes - Docs drift, not changed here: `docs/qa/platform-checklist/areas/integration-system.json` and `docs/adr/0104-field-runtime-value-shape-contract.md` still describe this job's service as `postgres:16`. - Card acceptance "the test passes in that job" is not yet read: on this PR's runs the job is skipped by design. - The first live reading comes from either an operator dispatch of `ci.yml` on this branch (with the maintainer; not triggered here) or this PR's own queue run, because `ci.yml` is on the path list. - That queue run is advisory, so read it before the entry lands; a red there is a revert. ## Read first 1. The temporal-conformance `if:` and the `temporal_live` filter: the governed behaviour change. 2. The postgres `image:` line and its comment. 3. The new test file. **Two-minute check:** open the first run of `Temporal Conformance (live PG + MySQL)` on this change. It should run (not skip), and its driver-sql step should list `✓ src/sql-driver-37095-pgvector-extension.test.ts (2 tests)`. --- _Generated by [Claude Code](https://claude.ai/code/session_01QSeKYpRrYuqSLCvbSk9zrL)_ <!-- signed: repo:objectstack#4 · os-justin · session_01QSeKYpEsWWE9Y5YtSsDgqZ --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 0439a04 commit 3b4f0b9

3 files changed

Lines changed: 188 additions & 15 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 77 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,18 @@ concurrency:
128128
# carries it rather than first on `main`'s push run after it, and the red
129129
# ejects that entry: the context is in the required set again (below).
130130
# `main`'s 4-hourly `schedule` run, its `push` runs and an on-demand
131-
# `workflow_dispatch` carry the FULL BATTERY: all of that plus the three jobs
131+
# `workflow_dispatch` carry the FULL BATTERY: all of that plus the jobs
132132
# below that spell
133133
#
134134
# github.event_name != 'pull_request' && github.event_name != 'merge_group'
135135
#
136-
# in their `if:` — `temporal-conformance`, `dogfood-verify` and
137-
# `ui-published-artifacts`. Nothing is deleted: the jobs moved off the per-PR
138-
# path, the last one never had one (#26717). A red in one of them is a main-red
136+
# in their `if:` — `dogfood-verify` and `ui-published-artifacts` — and
137+
# `temporal-conformance`, which since ruling record 7146156389 (#37095)
138+
# also runs on a `merge_group` entry whose diff hits the filter's
139+
# `temporal_live` paths (never on `pull_request`). It is NOT in the required
140+
# set, so that queue run is advisory: a red does not eject the entry, it
141+
# lands and shows on `main`. Nothing is deleted: the jobs moved off the per-PR
142+
# path, `ui-published-artifacts` never had one (#26717). A red in one of them is a main-red
139143
# for the owning lane, and the publish lane reads the full battery before its
140144
# approval (release.yml's `full-battery` job,
141145
# `scripts/ci/scheduled-full-run.mjs --release-gate`). ⛔ No affected-only
@@ -331,7 +335,7 @@ jobs:
331335
#
332336
# On merge_group the step RUNS (the diff is the queue base_sha against
333337
# the group head, see the step below), but only the three ui outputs
334-
# read it. `docs`, `core` and `crosspkg` stay 'true' there through the
338+
# and `temporal_live` (#37095) read it. `docs`, `core` and `crosspkg` stay 'true' there through the
335339
# `github.event_name != 'merge_group' &&` guard: the queue build is the
336340
# last validation before main, and those jobs run on every entry, as
337341
# they did before the step ran on this event. On any other event the
@@ -340,12 +344,19 @@ jobs:
340344
docs: ${{ github.event_name != 'merge_group' && steps.changes.outputs.docs || 'true' }}
341345
# Read by `test-plan`, `test` (ORed with `crosspkg`) and `build-core`,
342346
# on merge_group / push / schedule by `dogfood`, and on push / schedule
343-
# by `dogfood-verify` and `temporal-conformance` — see the `core` filter
344-
# below and each job's `if:`.
347+
# by `dogfood-verify` and `temporal-conformance` (which on merge_group
348+
# reads `temporal_live` instead, #37095) — see the `core` filter below
349+
# and each job's `if:`.
345350
core: ${{ github.event_name != 'merge_group' && steps.changes.outputs.core || 'true' }}
346351
# Gates the `test` job ONLY, ORed with `core` — see the `crosspkg`
347352
# filter below and the `test` job's `if:` (#9829, #10015).
348353
crosspkg: ${{ github.event_name != 'merge_group' && steps.changes.outputs.crosspkg || 'true' }}
354+
# [#37095] Read by `temporal-conformance` on merge_group ONLY: the queue
355+
# build runs that job when the merged diff touches the paths in the
356+
# `temporal_live` filter below (ruling record 7146156389, which revises
357+
# #22998 for this one job). Every other event ignores it. Fail-open like
358+
# the ui outputs: a queue build whose step failed reads '' → 'true'.
359+
temporal_live: ${{ steps.changes.outputs.temporal_live || 'true' }}
349360
# The objectui tree under `ui/` (objectstack#25677). Three outputs, read
350361
# together by the five `* UI` jobs at the bottom of this file (Type Check
351362
# UI, Test UI, Lint UI, Build & E2E UI and Live E2E UI):
@@ -445,8 +456,10 @@ jobs:
445456
# THE FILTER CONTRACT's half 1 instead: the step is skipped, its outputs
446457
# are the empty string, `|| 'true'` fills them in, and everything runs.
447458
#
448-
# `merge_group` joined the list for the ui outputs alone (#25867; the
449-
# three core-side outputs above ignore the step on that event). Its
459+
# `merge_group` joined the list for the ui outputs (#25867; the
460+
# three core-side outputs above ignore the step on that event), and
461+
# `temporal_live` reads it there too since ruling record 7146156389
462+
# (#37095: `temporal-conformance` runs on a queue entry that hits it). Its
450463
# `continue-on-error` is the fail-open half there: a queue build whose
451464
# base cannot be fetched reads as "run every ui job", never as a red
452465
# `filter` job. On pull_request and push a failure stays red, as before.
@@ -770,6 +783,44 @@ jobs:
770783
- 'packages/lint/**'
771784
- 'packages/sdui-parser/**'
772785
- 'packages/types/**'
786+
# [#37095] What makes the merge queue run `temporal-conformance`
787+
# (ruling record 7146156389): the pgvector store, the driver whose
788+
# whole suite that job runs against the live servers, the
789+
# live-server files its filtered steps select (the two
790+
# metadata-protocol globs spell that step's `live-mysql
791+
# live-postgres` substrings), the service-analytics files whose
792+
# live-PostgreSQL cells key on OS_TEST_POSTGRES_URL (#21564; no glob
793+
# selects exactly these, so they are listed: a NEW such file must
794+
# be added here by hand), and this file.
795+
temporal_live:
796+
- 'packages/plugins/knowledge-pgvector/**'
797+
- 'packages/drivers/driver-sql/**'
798+
- 'packages/metadata-protocol/src/**/*live-mysql*'
799+
- 'packages/metadata-protocol/src/**/*live-postgres*'
800+
- 'packages/runtime/src/**/cascade-delete-multivalue-lookup-real-driver*'
801+
- 'packages/services/service-analytics/src/__tests__/analytics-faces-one-lowering.test.ts'
802+
- 'packages/services/service-analytics/src/__tests__/cube-measure-field-type-door.test.ts'
803+
- 'packages/services/service-analytics/src/__tests__/cube-measure-relationship-path-type.test.ts'
804+
- 'packages/services/service-analytics/src/__tests__/dataset-duration-measure.test.ts'
805+
- 'packages/services/service-analytics/src/__tests__/dataset-tools.test.ts'
806+
- 'packages/services/service-analytics/src/__tests__/home-amount-consolidated-measure.test.ts'
807+
- 'packages/services/service-analytics/src/__tests__/json-stored-door-live-drivers.test.ts'
808+
- 'packages/services/service-analytics/src/__tests__/json-stored-door-undeclared-join.test.ts'
809+
- 'packages/services/service-analytics/src/__tests__/list-at-scalar-operator-both-faces.test.ts'
810+
- 'packages/services/service-analytics/src/__tests__/native-sql-aggregate-policies.test.ts'
811+
- 'packages/services/service-analytics/src/__tests__/native-sql-base-column-qualify.test.ts'
812+
- 'packages/services/service-analytics/src/__tests__/native-sql-boolean-comparand-door.test.ts'
813+
- 'packages/services/service-analytics/src/__tests__/native-sql-empty-sum-order-window.test.ts'
814+
- 'packages/services/service-analytics/src/__tests__/native-sql-measure-number-presentation.test.ts'
815+
- 'packages/services/service-analytics/src/__tests__/native-sql-number-comparand-door.test.ts'
816+
- 'packages/services/service-analytics/src/__tests__/native-sql-offset-only-window.test.ts'
817+
- 'packages/services/service-analytics/src/__tests__/objectql-echo-bucket-enumeration.test.ts'
818+
- 'packages/services/service-analytics/src/__tests__/objectql-echo-date-bucket.test.ts'
819+
- 'packages/services/service-analytics/src/__tests__/objectql-echo-offset-only-window.test.ts'
820+
- 'packages/services/service-analytics/src/__tests__/objectql-face-order-limit.test.ts'
821+
- 'packages/services/service-analytics/src/__tests__/order-key-selected.test.ts'
822+
- 'packages/services/service-analytics/src/__tests__/read-scope-temporal-coercion.test.ts'
823+
- '.github/workflows/ci.yml'
773824
774825
# ── WHICH TEST CORE SHARDS START (#26084) ─────────────────────────────
775826
# The `test` matrix used to be the literal 1..8, so every Test Core run
@@ -2427,22 +2478,35 @@ jobs:
24272478
name: Temporal Conformance (live PG + MySQL)
24282479
needs: filter
24292480
# See THE FILTER CONTRACT on the filter job's outputs (#4928). Full battery
2430-
# only: see THE TWO SPEEDS above `jobs:` (#22998).
2431-
if: ${{ !cancelled() && needs.filter.outputs.core != 'false' && github.event_name != 'pull_request' && github.event_name != 'merge_group' }}
2481+
# (see THE TWO SPEEDS above `jobs:`, #22998), plus the merge queue when the
2482+
# entry's diff hits the `temporal_live` paths ([#37095], ruling record
2483+
# 7146156389). Never on pull_request.
2484+
if: ${{ !cancelled() && needs.filter.outputs.core != 'false' && github.event_name != 'pull_request' && (github.event_name != 'merge_group' || needs.filter.outputs.temporal_live != 'false') }}
24322485
runs-on: ubuntu-latest
24332486
timeout-minutes: 30
24342487
permissions:
24352488
contents: read
24362489

24372490
# Both service images are pulled from mirror.gcr.io, Google's cache of
2438-
# Docker Hub: the same official image, tag and index digest. Pulled from
2491+
# Docker Hub: the same image, tag and index digest. Pulled from
24392492
# Docker Hub directly they ride its anonymous per-IP quota, which shared
24402493
# runner IPs exhaust, and `Initialize containers` then fails before any
24412494
# step runs. A Docker Hub login is no fix: secrets never reach fork PRs
24422495
# (#22541).
24432496
services:
24442497
postgres:
2445-
image: mirror.gcr.io/library/postgres:16
2498+
# [#37095] pgvector's image, not the plain official one: it is
2499+
# `postgres:16` (same major, entrypoint, `pg_isready`, `psql`) with the
2500+
# `vector` extension built in, so the pgvector-backed knowledge store
2501+
# has a real server here. An EXACT tag (pgvector 0.8.7 on PG 16), not
2502+
# the moving `pg16`, AND its index digest (read 2026-11-24, the same on
2503+
# mirror.gcr.io and Docker Hub): with `tag@digest` Docker pulls by the
2504+
# digest, so a re-pushed tag cannot change the server under this job;
2505+
# a new pgvector release reaches it only by a reviewed edit of both.
2506+
# Pinned by `driver-sql`'s sql-driver-37095-pgvector-extension test,
2507+
# which the driver-sql step below runs: an image without the extension
2508+
# fails its CREATE EXTENSION.
2509+
image: mirror.gcr.io/pgvector/pgvector:0.8.7-pg16@sha256:484e838076e04939d27d3e176e91c86eea96236126023be8d3059761122e579f
24462510
env:
24472511
POSTGRES_PASSWORD: postgres
24482512
ports:

‎docs/agents/multi-agent-discipline.md‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,10 @@ A check outside those eleven is advisory and rides through, and an advisory red
134134
of wall per queue entry (median, 2026-11-05); `main`'s scheduled (4-hourly) and push runs
135135
carry the full battery — dogfood, e2e, `Temporal Conformance (live PG + MySQL)` — read by the publish lane before
136136
any approval. Queue runs also carry the three `Dogfood Regression Gate` shards (ruling record
137-
6663883327), so a dogfood red shows on the queue build; `Dogfood Verify CLI`,
138-
Temporal Conformance and `UI Published Artifacts` stay full-battery only. The `Dogfood Regression
137+
6663883327), so a dogfood red shows on the queue build; `Dogfood Verify CLI` and
138+
`UI Published Artifacts` stay full-battery only. One exception: Temporal Conformance also runs on a queue
139+
entry whose diff hits `ci.yml`'s `temporal_live` paths (ruling record 7146156389); it is not a required
140+
context, so that run is advisory and a red lands on `main`. The `Dogfood Regression
139141
Gate` context is in the required set again (ruling record 6669982756), so a dogfood red ejects the entry.
140142

141143
**A push run borrows what the queue ran** (#31519). Every commit the queue lands was tested there on the same
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* [#37095] The live PostgreSQL this package is tested against ships the
5+
* `vector` extension (pgvector).
6+
*
7+
* The `Temporal Conformance (live PG + MySQL)` CI job runs this whole suite
8+
* against its postgres service, and that service is `pgvector/pgvector` (via
9+
* `mirror.gcr.io`) rather than plain `postgres`, so the pgvector-backed
10+
* knowledge store (#37100) has a real server to be tested on. This file is the
11+
* pin on that provisioning: if the image ever goes back to one without the
12+
* extension, `CREATE EXTENSION` fails here and the job turns red, instead of
13+
* the store's live tests quietly becoming skips.
14+
*
15+
* It holds NO adapter code and asserts nothing about one: an extension install,
16+
* one typed column, and the L2 distance operator ordering rows by it.
17+
*
18+
* ## The extension is database-wide; the table is this file's own
19+
*
20+
* An extension lives once per DATABASE, in one schema, and every live file in
21+
* this package shares the database (each owns a schema, #9350). So the install
22+
* is `IF NOT EXISTS` and is never dropped here (another file may be using it),
23+
* and the type and operator are QUALIFIED with whatever schema the extension
24+
* actually sits in — read back from `pg_extension`, not assumed to be ours —
25+
* because a file that installed it first may have put it in its own schema,
26+
* which is not on this session's `search_path`. (Measured: installed from here
27+
* it lands in this file's schema, and the globalSetup's teardown — `drop
28+
* schema … cascade` — takes it away with that schema, so each run installs it
29+
* afresh.)
30+
*
31+
* ## Why this file is PG-only
32+
*
33+
* pgvector is a PostgreSQL extension; SQLite and MySQL have nothing to install.
34+
* The cell list is exactly `pg`, declared through `declareDialectCell`, so an
35+
* unprovisioned run (Test Core, a laptop without a server) is a NAMED skip and,
36+
* under `OS_EXPECT_LIVE_DIALECT_MATRIX=1`, a named failure.
37+
*/
38+
39+
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
40+
import { SqlDriver } from '../src/index.js';
41+
import {
42+
PG_CELL,
43+
currentLiveSchema,
44+
declareDialectCell,
45+
type DialectCell,
46+
} from './live-dialect-matrix.testkit.js';
47+
48+
const MATRIX = 'pgvector extension';
49+
50+
const TABLE = 'os37095_embeddings';
51+
52+
function declarePgvectorSuite(cell: DialectCell): void {
53+
describe(`pgvector extension — ${cell.label} (#37095)`, () => {
54+
let driver: SqlDriver;
55+
let here: string;
56+
/** The schema the extension is installed in, quoted for SQL. */
57+
let ext: string;
58+
59+
beforeAll(async () => {
60+
here = currentLiveSchema();
61+
driver = new SqlDriver(cell.config());
62+
await driver.execute('create extension if not exists vector');
63+
const found: any = await driver.execute(
64+
`select n.nspname as schema, e.extversion as version
65+
from pg_extension e join pg_namespace n on n.oid = e.extnamespace
66+
where e.extname = 'vector'`,
67+
);
68+
expect(found.rows, 'CREATE EXTENSION returned but no `vector` row is in pg_extension').toHaveLength(1);
69+
ext = `"${found.rows[0].schema}"`;
70+
await driver.execute(`drop table if exists "${here}".${TABLE}`);
71+
await driver.execute(`create table "${here}".${TABLE} (id integer primary key, embedding ${ext}.vector(3) not null)`);
72+
await driver.execute(
73+
`insert into "${here}".${TABLE} (id, embedding) values (1, '[1,0,0]'), (2, '[0,3,4]'), (3, '[1,1,0]')`,
74+
);
75+
});
76+
77+
afterAll(async () => {
78+
await driver?.execute(`drop table if exists "${here}".${TABLE}`).catch(() => {});
79+
await driver?.disconnect().catch(() => {});
80+
});
81+
82+
it('the server has the extension installed, with a version', async () => {
83+
const r: any = await driver.execute(`select extversion from pg_extension where extname = 'vector'`);
84+
expect(r.rows[0].extversion).toMatch(/^\d+\.\d+\.\d+$/);
85+
});
86+
87+
it('orders rows by L2 distance to a query vector, and computes that distance', async () => {
88+
const r: any = await driver.execute(
89+
`select id, embedding OPERATOR(${ext}.<->) '[1,0,0]'::${ext}.vector as distance
90+
from "${here}".${TABLE}
91+
order by embedding OPERATOR(${ext}.<->) '[1,0,0]'::${ext}.vector
92+
limit 2`,
93+
);
94+
// Nearest first: the identical vector (0), then [1,1,0] (1). The far
95+
// row [0,3,4] — sqrt(1 + 9 + 16) — is cut by the limit.
96+
expect(r.rows.map((row: any) => row.id)).toEqual([1, 3]);
97+
expect(r.rows.map((row: any) => Number(row.distance))).toEqual([0, 1]);
98+
99+
const far: any = await driver.execute(
100+
`select embedding OPERATOR(${ext}.<->) '[1,0,0]'::${ext}.vector as distance from "${here}".${TABLE} where id = 2`,
101+
);
102+
expect(Number(far.rows[0].distance)).toBeCloseTo(Math.sqrt(26), 6);
103+
});
104+
});
105+
}
106+
107+
declareDialectCell(PG_CELL, MATRIX, declarePgvectorSuite);

0 commit comments

Comments
 (0)