From 310b76e1eeb26d40dc0c2cd293be45d23bfbbb90 Mon Sep 17 00:00:00 2001 From: adityamishra-hydradb Date: Sat, 5 Dec 2026 13:35:51 +0530 Subject: [PATCH 1/2] Run the Postgres store tests in CI on Postgres 16 and 17 with pg_hydradb Co-Authored-By: Claude Opus 5.5 Signed-off-by: adityamishra-hydradb --- .github/pg-hydradb/Dockerfile | 19 +++++++++++ .github/workflows/ci.yml | 59 +++++++++++++++++++++++++++++++++++ AGENTS.md | 4 +-- 3 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 .github/pg-hydradb/Dockerfile diff --git a/.github/pg-hydradb/Dockerfile b/.github/pg-hydradb/Dockerfile new file mode 100644 index 00000000..074ba853 --- /dev/null +++ b/.github/pg-hydradb/Dockerfile @@ -0,0 +1,19 @@ +ARG PG +FROM postgres:${PG}-bookworm AS build +ARG PG +ARG HYDRADB_REF +RUN apt-get update && apt-get install -y --no-install-recommends build-essential curl \ + ca-certificates pkg-config libclang-dev clang postgresql-server-dev-${PG} \ + && rm -rf /var/lib/apt/lists/* +RUN curl -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal --default-toolchain 1.99.0 +ENV PATH=/root/.cargo/bin:$PATH +RUN test -n "$HYDRADB_REF" && mkdir /src \ + && curl -sSfL "https://codeload.github.com/hydra-db/hydradb/tar.gz/${HYDRADB_REF}" | tar -xz -C /src --strip-components 1 +WORKDIR /src/crates/pg-hydradb +RUN PGRX_PG_CONFIG_PATH=/usr/lib/postgresql/${PG}/bin/pg_config \ + cargo build --release --locked --no-default-features --features pg${PG} + +FROM scratch +COPY --from=build /src/crates/pg-hydradb/target/release/libpg_hydradb.so /lib/pg_hydradb.so +COPY --from=build /src/crates/pg-hydradb/pg_hydradb.control /extension/ +COPY --from=build /src/crates/pg-hydradb/sql/ /extension/ diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cc640e6b..2996ec12 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -329,6 +329,65 @@ jobs: SELFGRAPH_TEST_PREBUILT: "1" SELFGRAPH_PY: python + postgres: + needs: [python-build, typescript-build] + runs-on: ubuntu-latest + timeout-minutes: 45 + strategy: + fail-fast: false + matrix: + pg: ["16", "17"] + env: + PG: ${{ matrix.pg }} + HYDRADB_REF: 58390740c6d7f0b2f572b5c0c0170ef59da4a3c5 + SG_PG_HYDRADB_URI: postgresql://postgres:owner@127.0.0.1:5432/postgres + SELFGRAPH_TEST_STORES: kuzu + steps: + - uses: actions/checkout@v4 + - uses: actions/cache@v4 + id: extension + with: + path: ${{ runner.temp }}/pg-hydradb + key: pg-hydradb-${{ matrix.pg }}-${{ env.HYDRADB_REF }}-${{ hashFiles('.github/pg-hydradb/Dockerfile') }} + - if: steps.extension.outputs.cache-hit != 'true' + run: >- + docker build --build-arg "PG=$PG" --build-arg "HYDRADB_REF=$HYDRADB_REF" + --output "type=local,dest=$RUNNER_TEMP/pg-hydradb" .github/pg-hydradb + - run: | + docker create --name pg -e POSTGRES_PASSWORD=owner -p 5432:5432 "postgres:$PG-bookworm" + docker cp "$RUNNER_TEMP/pg-hydradb/lib/pg_hydradb.so" "pg:/usr/lib/postgresql/$PG/lib/" + docker cp "$RUNNER_TEMP/pg-hydradb/extension/." "pg:/usr/share/postgresql/$PG/extension/" + docker start pg + for i in $(seq 1 30); do docker exec pg pg_isready -q -h 127.0.0.1 -U postgres && break; sleep 2; done + docker exec pg psql -U postgres -h 127.0.0.1 -c "SELECT version()" + - uses: actions/setup-python@v5 + with: + python-version: "3.12" + - uses: astral-sh/setup-uv@d0cc045d04ccac9d8b7881df0226f9e82c39688e # v6 + with: + enable-cache: true + prune-cache: false + cache-suffix: postgres + cache-dependency-glob: pyproject.toml + python-version: "3.12" + - uses: actions/download-artifact@v4 + with: + name: python-dist + path: dist + - run: uv pip install --system "$(ls dist/*.whl)[dev,kuzu,postgres]" + - run: pytest tests/test_pg_hydradb_store.py -v -rs + env: + KUZU_PATH: ${{ runner.temp }}/selfgraph-kuzu + - uses: ./.github/actions/node-deps + - uses: actions/download-artifact@v4 + with: + name: typescript-dist + path: typescript/dist + - run: npx vitest run test/pgHydradbStore.test.ts + working-directory: typescript + env: + SELFGRAPH_TEST_PREBUILT: "1" + backends: if: always() needs: [backends-python, backends-typescript] diff --git a/AGENTS.md b/AGENTS.md index ec774c7f..f7b79b85 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -17,7 +17,7 @@ invariants below. - Wire formats match across the two SDKs: result and schema keys, CLI flags, `SELFGRAPH_*` variables, MCP tool names and arguments, warning codes, error codes and text, and LLM prompts. The conformance pair (`typescript/test/conformance/py_side.py` and `ts_side.ts`) covers the deterministic paths, including `from_tables`, schema term forms, `check_answerable`, synonym seeding, and `graph.tiers`. Extend both sides when you add a deterministic behaviour. LLM tiers are covered by mirrored tests with a fake client, not by conformance. - Run `pre-commit install` once; the hook runs ruff, Biome, and `tsc` on each commit. Lint and format before pushing: `ruff check .` and `ruff format .` (config lives in `pyproject.toml`; CI runs `ruff check` and `ruff format --check`). - In `typescript/`, lint and format with Biome before pushing: `npm run lint` checks and `npm run format` fixes (config lives in `typescript/biome.json`; CI runs `npm run lint`, `typecheck`, `build`, and `test`). -- The test suite lives in `tests/` and needs a graph backend: a Bolt server (Neo4j by default, or Memgraph), FalkorDB, HydraDB, or embedded Kuzu, selected with `SELFGRAPH_TEST_STORE` (or the first entry of `SELFGRAPH_TEST_STORES`, the TypeScript suite's plural selector). Backend connection details accept the TypeScript `SG_*` names first (`SG_NEO4J_URI`, `SG_NEO4J_PASSWORD`, `SG_MEMGRAPH_URI`, `SG_FALKOR_PORT`, `SG_HYDRADB_URI`, `SG_HYDRADB_TOKEN`), then the bare names (`NEO4J_URI`, `NEO4J_AUTH`, `CYPHER_URI`, `FALKOR_PORT`, `HYDRADB_URI`, `HYDRADB_TOKEN`), so one set of variables drives both suites. If you add tests, drive async code with `asyncio.run(...)` and do not add `pytest-asyncio`. Test an LLM or embedder tier with a small fake object that implements `generate` or `embed`, as `tests/test_tiers.py` does; never call a real model. CI runs both suites on embedded Kuzu with the `tokenizer` extra installed. +- The test suite lives in `tests/` and needs a graph backend: a Bolt server (Neo4j by default, or Memgraph), FalkorDB, HydraDB, or embedded Kuzu, selected with `SELFGRAPH_TEST_STORE` (or the first entry of `SELFGRAPH_TEST_STORES`, the TypeScript suite's plural selector). Backend connection details accept the TypeScript `SG_*` names first (`SG_NEO4J_URI`, `SG_NEO4J_PASSWORD`, `SG_MEMGRAPH_URI`, `SG_FALKOR_PORT`, `SG_HYDRADB_URI`, `SG_HYDRADB_TOKEN`), then the bare names (`NEO4J_URI`, `NEO4J_AUTH`, `CYPHER_URI`, `FALKOR_PORT`, `HYDRADB_URI`, `HYDRADB_TOKEN`), so one set of variables drives both suites. If you add tests, drive async code with `asyncio.run(...)` and do not add `pytest-asyncio`. Test an LLM or embedder tier with a small fake object that implements `generate` or `embed`, as `tests/test_tiers.py` does; never call a real model. CI runs both suites on embedded Kuzu with the `tokenizer` extra installed. The Postgres store tests (`tests/test_pg_hydradb_store.py`, `typescript/test/pgHydradbStore.test.ts`) skip unless `SG_PG_HYDRADB_URI` names a Postgres with pg_hydradb; the CI `postgres` job builds pg_hydradb from the hydradb commit pinned in `ci.yml` (`HYDRADB_REF`) and runs them on Postgres 16 and 17. ## Architecture invariant @@ -94,7 +94,7 @@ Cypher. A vector store, GraphRAG, English-to-Cypher, file parsing, and row-level structured input are out of scope for the core. Do not add them or their dependencies to the core. Embeddings are allowed only as a seeding tier over a caller-supplied `Embedder`: the SDK ships no embedding model and stores no vectors. -Schema drafts read table metadata the caller passes, never rows or a database. +Schema drafts read table metadata the caller passes, or a store's own catalog and registry (such as the pg_hydradb tables that `PgHydraDBStore.draft_schema` reads). A draft never reads user rows. ## Commits From 36270c3c362bd1dcb5de4327457c4c6fdbf57c18 Mon Sep 17 00:00:00 2001 From: adityamishra-hydradb Date: Sat, 5 Dec 2026 13:40:27 +0530 Subject: [PATCH 2/2] Run the TypeScript Postgres tests from source without the bundle Co-Authored-By: Claude Opus 5.5 Signed-off-by: adityamishra-hydradb --- .github/workflows/ci.yml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2996ec12..18d3a797 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -330,7 +330,7 @@ jobs: SELFGRAPH_PY: python postgres: - needs: [python-build, typescript-build] + needs: [python-build] runs-on: ubuntu-latest timeout-minutes: 45 strategy: @@ -379,10 +379,6 @@ jobs: env: KUZU_PATH: ${{ runner.temp }}/selfgraph-kuzu - uses: ./.github/actions/node-deps - - uses: actions/download-artifact@v4 - with: - name: typescript-dist - path: typescript/dist - run: npx vitest run test/pgHydradbStore.test.ts working-directory: typescript env: