mirror of
https://github.com/TencentCloud/Octop.git
synced 2026-10-19 06:10:07 +08:00
* fix: adapt S3/Postgres backends and restore admin storage browse Published octop-harness 1.0.1 plus Octop-side spec mapping and protocol wrap stop expert start and Admin tree listing from failing on the older deepagents_backends surface. Browse now caches the backend session and can preview or download files. Co-authored-by: Cursor <cursoragent@cursor.com> * fix: keep Windows paths valid in storage browse fixtures f-string JSON turns backslashes into illegal escapes, so row_to_backend_spec sees an incomplete filesystem config on Windows CI. Co-authored-by: Cursor <cursoragent@cursor.com> * fix: write browse fixture bytes without Windows newline translation Path.write_text() converts LF to CRLF on Windows, so download assertions saw b'# hello\r\n'. Co-authored-by: Cursor <cursoragent@cursor.com> --------- Co-authored-by: jubaoliang <jubaoliang@tencent.com> Co-authored-by: Cursor <cursoragent@cursor.com>
106 lines
3.0 KiB
Python
106 lines
3.0 KiB
Python
"""Tests for postgres storage-spec mapping onto PostgresConfig fields."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from octop.infra.backend.postgres_spec import (
|
|
normalize_postgres_spec,
|
|
parse_postgres_conninfo,
|
|
split_host_port,
|
|
)
|
|
from octop.infra.db.repos.backends import BackendRow
|
|
|
|
|
|
def test_split_host_port() -> None:
|
|
assert split_host_port("localhost:5432") == ("localhost", 5432)
|
|
assert split_host_port("db.internal") == ("db.internal", None)
|
|
assert split_host_port("[::1]:5432") == ("::1", 5432)
|
|
|
|
|
|
def test_parse_postgres_uri() -> None:
|
|
parsed = parse_postgres_conninfo(
|
|
"postgresql://alice:s3cret@pg.example:5432/app?sslmode=require"
|
|
)
|
|
assert parsed["host"] == "pg.example"
|
|
assert parsed["port"] == 5432
|
|
assert parsed["user"] == "alice"
|
|
assert parsed["password"] == "s3cret"
|
|
assert parsed["database"] == "app"
|
|
assert parsed["sslmode"] == "require"
|
|
|
|
|
|
def test_normalize_postgres_spec_drops_uri_and_unknown_keys() -> None:
|
|
out = normalize_postgres_spec(
|
|
{
|
|
"type": "postgres",
|
|
"connection_string": "postgresql://u:p@localhost/db",
|
|
"table": "files",
|
|
"unknown": "drop-me",
|
|
}
|
|
)
|
|
assert out == {
|
|
"type": "postgres",
|
|
"host": "localhost",
|
|
"user": "u",
|
|
"password": "p",
|
|
"database": "db",
|
|
"table": "files",
|
|
}
|
|
|
|
|
|
def test_mapped_spec_is_accepted_by_postgres_config() -> None:
|
|
from deepagents_backends import PostgresConfig
|
|
|
|
from octop.infra.backend.adapter import row_to_backend_spec
|
|
|
|
row = BackendRow(
|
|
id=1,
|
|
name="pg",
|
|
kind="postgres",
|
|
endpoint="localhost:5432",
|
|
access_key="octop",
|
|
secret_key="secret",
|
|
bucket="octop",
|
|
region="public",
|
|
config_json=None,
|
|
note=None,
|
|
enabled=1,
|
|
created_at=0,
|
|
updated_at=0,
|
|
)
|
|
spec = row_to_backend_spec(row)
|
|
assert spec is not None
|
|
kwargs = {k: v for k, v in spec.items() if k != "type"}
|
|
config = PostgresConfig(**kwargs)
|
|
assert config.host == "localhost"
|
|
assert config.port == 5432
|
|
assert config.user == "octop"
|
|
|
|
|
|
def test_row_discrete_fields_override_uri() -> None:
|
|
from octop.infra.backend.postgres_spec import row_to_postgres_spec
|
|
|
|
row = BackendRow(
|
|
id=1,
|
|
name="pg",
|
|
kind="postgres",
|
|
endpoint="override.example:6543",
|
|
access_key="rowuser",
|
|
secret_key="rowpass",
|
|
bucket="rowdb",
|
|
region="agents",
|
|
config_json='{"connection_string": "postgresql://u:p@localhost/db"}',
|
|
note=None,
|
|
enabled=1,
|
|
created_at=0,
|
|
updated_at=0,
|
|
)
|
|
spec = row_to_postgres_spec(row, {"connection_string": "postgresql://u:p@localhost/db"})
|
|
assert spec is not None
|
|
assert spec["host"] == "override.example"
|
|
assert spec["port"] == 6543
|
|
assert spec["user"] == "rowuser"
|
|
assert spec["password"] == "rowpass"
|
|
assert spec["database"] == "rowdb"
|
|
assert spec["schema"] == "agents"
|
|
assert "connection_string" not in spec
|