启动时等库:PostgreSQL 还连不上(和库的容器一起起、库还在初始化)时按退避重试(1、2、4、5、5… 秒),每次照实打一条「应用库还没就绪」,最多等 AGENTLAB_DB_STARTUP_TIMEOUT(缺省 90)秒再把最后一次的错抛出去;密码不对、库不存在这种等也没用的(SQLSTATE 28、3D、42 类)立刻抛;SQLite 不等。新增 python -m app.ops(部署脚本在容器里以镜像用户调的几件小事,只用标准库):内置 PostgreSQL 的密码文件和 pgpass(0600,已有就沿用,密码不打印)、数据目录用哪种库的状态(sqlite / builtin / migrating)、SQLite 库的一致备份(备份接口,含 -wal 里的)和只留最近 N 份。copy-to-postgres 连不上目标库、库报错时一句话说清楚、退出码 1,不再甩一屏调用栈

This commit is contained in:
ThearchyHelios
2026-10-19 13:43:32 +08:00
parent 451c05aacb
commit 93cd32bc97
7 changed files with 491 additions and 0 deletions
+11
View File
@@ -182,6 +182,17 @@ def test_the_command_needs_a_target(tmp_path, monkeypatch, capsys):
assert "只认 PostgreSQL" in capsys.readouterr().err
def test_an_unreachable_target_is_reported_in_one_line(tmp_path, capsys):
"""目标库连不上(库的容器没起来、被停了):一句话说清楚、退出码 1,不甩一屏调用栈(deploy.sh migrate-to-postgres 照它回退)。"""
import sqlite3
sqlite3.connect(tmp_path / "agentlab.db").execute("CREATE TABLE t (x)").connection.close()
for extra, what in (([], "没有导入完"), (["--dry-run"], "没有核对完")):
assert to_postgres.main([str(tmp_path), "postgresql+asyncpg://u:p@127.0.0.1:1/agentlab", *extra]) == 1
err = capsys.readouterr().err
assert err.startswith(what) and "Traceback" not in err and len(err.strip().splitlines()) == 1
def test_the_dispatcher_knows_its_commands(capsys):
from app.db.__main__ import main