Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions tests/test_pgvector_config_roundtrip.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
"""Regression tests for issue #831 — reloading results fails validation.

After a pgvector run that used an empty password (local trust/peer auth), the
saved result JSON carries ``password: ""``. When the results page rehydrates the
config via ``db.config_cls(**task_config["db_config"])`` (models.TestResult.
read_file), ``DBConfig.not_empty_field`` rejected the empty password with
``Value error, Empty field(s): password``. The same shape breaks the sibling
postgres-connection-string configs (pgvectorscale, alloydb).

These tests do not require a live database — they exercise the exact
reconstruction step read_file performs on the saved db_config dict.

Usage:
pytest tests/test_pgvector_config_roundtrip.py -v
"""

from __future__ import annotations

from typing import TYPE_CHECKING

import pytest

from vectordb_bench.backend.clients import DB
from vectordb_bench.backend.clients.alloydb.config import AlloyDBConfig
from vectordb_bench.backend.clients.pgvector.config import PgVectorConfig
from vectordb_bench.backend.clients.pgvectorscale.config import PgVectorScaleConfig

if TYPE_CHECKING:
from vectordb_bench.backend.clients.api import DBConfig

# The postgres-connection-string family that shares the DBConfig empty-field guard.
PG_FAMILY = [
(DB.PgVector, PgVectorConfig),
(DB.PgVectorScale, PgVectorScaleConfig),
(DB.AlloyDB, AlloyDBConfig),
]
PG_FAMILY_IDS = ["pgvector", "pgvectorscale", "alloydb"]


@pytest.mark.parametrize(("db", "config_cls"), PG_FAMILY, ids=PG_FAMILY_IDS)
def test_reload_with_empty_password_present(db: DB, config_cls: type[DBConfig]):
"""A saved config with password="" must rehydrate (issue #831)."""
saved = {"db_label": "", "password": "", "version": "", "note": ""}
cfg = db.config_cls(**saved)
assert isinstance(cfg, config_cls)
assert cfg.password.get_secret_value() == ""


@pytest.mark.parametrize(("db", "config_cls"), PG_FAMILY, ids=PG_FAMILY_IDS)
def test_reload_with_password_absent(db: DB, config_cls: type[DBConfig]):
"""Older result files omit subclass fields entirely — still rehydrate."""
saved = {"db_label": "", "version": "", "note": ""}
cfg = db.config_cls(**saved)
assert isinstance(cfg, config_cls)
assert cfg.password.get_secret_value() == ""
assert cfg.db_name # non-empty default so downstream connection strings hold


def test_non_credential_empty_field_still_rejected():
"""Negative control: the empty-field guard must still fire for other fields."""
with pytest.raises(ValueError, match=r"Empty field.*host"):
PgVectorConfig(db_label="", password="x", version="", note="", host="") # noqa: S106
10 changes: 7 additions & 3 deletions vectordb_bench/backend/clients/alloydb/config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from abc import abstractmethod
from collections.abc import Mapping, Sequence
from typing import Any, LiteralString, TypedDict
from typing import Any, ClassVar, LiteralString, TypedDict

from pydantic import BaseModel, SecretStr

Expand All @@ -21,11 +21,15 @@ class AlloyDBConfigDict(TypedDict):


class AlloyDBConfig(DBConfig):
# An empty password is valid (local trust/peer auth), and it is what a
# reloaded result carries when the run used no password — don't reject it.
_extra_empty_skip: ClassVar[frozenset[str]] = frozenset({"password"})

user_name: SecretStr = SecretStr("postgres")
password: SecretStr
password: SecretStr = SecretStr("")
host: str = "localhost"
port: int = 5432
db_name: str
db_name: str = "postgres"

def to_dict(self) -> AlloyDBConfigDict:
user_str = self.user_name.get_secret_value()
Expand Down
8 changes: 6 additions & 2 deletions vectordb_bench/backend/clients/pgvector/config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from abc import abstractmethod
from collections.abc import Mapping, Sequence
from typing import Any, LiteralString, TypedDict
from typing import Any, ClassVar, LiteralString, TypedDict

from pydantic import BaseModel, SecretStr

Expand All @@ -21,8 +21,12 @@ class PgVectorConfigDict(TypedDict):


class PgVectorConfig(DBConfig):
# An empty password is valid (local trust/peer auth), and it is what a
# reloaded result carries when the run used no password — don't reject it.
_extra_empty_skip: ClassVar[frozenset[str]] = frozenset({"password"})

user_name: SecretStr = "postgres"
password: SecretStr
password: SecretStr = SecretStr("")
host: str = "localhost"
port: int = 5432
db_name: str = "vectordb"
Expand Down
10 changes: 7 additions & 3 deletions vectordb_bench/backend/clients/pgvectorscale/config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from abc import abstractmethod
from typing import LiteralString, TypedDict
from typing import ClassVar, LiteralString, TypedDict

from pydantic import BaseModel, SecretStr

Expand All @@ -20,11 +20,15 @@ class PgVectorScaleConfigDict(TypedDict):


class PgVectorScaleConfig(DBConfig):
# An empty password is valid (local trust/peer auth), and it is what a
# reloaded result carries when the run used no password — don't reject it.
_extra_empty_skip: ClassVar[frozenset[str]] = frozenset({"password"})

user_name: SecretStr = SecretStr("postgres")
password: SecretStr
password: SecretStr = SecretStr("")
host: str = "localhost"
port: int = 5432
db_name: str
db_name: str = "vectordb"

def to_dict(self) -> PgVectorScaleConfigDict:
user_str = self.user_name.get_secret_value()
Expand Down