chore: auto release commit (2026-09-15 01:39:08)
Some checks failed
技能自动化发布 / release (push) Failing after 6s
Some checks failed
技能自动化发布 / release (push) Failing after 6s
This commit is contained in:
@@ -1271,6 +1271,80 @@ def test_enqueue_download_tasks_safe_empty_list() -> tuple[bool, str]:
|
||||
return True, "空列表 no-op OK"
|
||||
|
||||
|
||||
def test_enqueue_download_tasks_safe_auto_create_table_v1_29() -> tuple[bool, str]:
|
||||
"""v1.1.29:用户没跑 init-db 时,首次调用 `_enqueue_download_tasks_safe`
|
||||
不传 conn(owns_conn=True),函数内部 idempotent 创建 download_tasks 表
|
||||
而非抛 "no such table"。
|
||||
"""
|
||||
import os
|
||||
import sqlite3
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
|
||||
from service.platform_collector import _enqueue_download_tasks_safe
|
||||
|
||||
# 1. 临时文件 DB,**只建 contracts 表**(模拟老 DB 没 download_tasks)
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
tmp_db = Path(tmp) / "old.db"
|
||||
# 重定向 JIANGCHANG_DATA_ROOT 或 get_db_path 用临时路径
|
||||
# 这里用 monkeypatch get_db_path + get_connection
|
||||
from util import runtime_paths as rp
|
||||
from db import connection as dbconn
|
||||
|
||||
orig_rp_db_path = rp.get_db_path
|
||||
orig_dbconn_db_path = dbconn.get_db_path
|
||||
rp.get_db_path = lambda: tmp_db # type: ignore[assignment]
|
||||
dbconn.get_db_path = lambda: tmp_db # type: ignore[assignment]
|
||||
try:
|
||||
# 模拟老 DB:只有 contracts 表(v1.1.17 之前 init 过)
|
||||
_tmp_conn = sqlite3.connect(str(tmp_db))
|
||||
try:
|
||||
_tmp_conn.executescript(
|
||||
"""
|
||||
CREATE TABLE contracts (
|
||||
contract_id TEXT PRIMARY KEY,
|
||||
teacher_name TEXT, unit_id TEXT, unit_name TEXT,
|
||||
position TEXT, contract_type TEXT, contract_start TEXT,
|
||||
contract_end TEXT, trial_period_end TEXT,
|
||||
status TEXT DEFAULT '可续聘',
|
||||
last_material_id TEXT, renewed_at TEXT
|
||||
);
|
||||
INSERT INTO contracts
|
||||
(contract_id, teacher_name, unit_id, unit_name,
|
||||
position, contract_type, contract_start,
|
||||
contract_end, trial_period_end)
|
||||
VALUES ('ENQ-CREATE-1', '测试', 'U1', '物理学院',
|
||||
'实验师', '专任教师聘用合同',
|
||||
'2024-01-01', '2026-12-31', '2024-04-01');
|
||||
"""
|
||||
)
|
||||
_tmp_conn.commit()
|
||||
finally:
|
||||
_tmp_conn.close()
|
||||
|
||||
# 2. 不传 conn 调用(owns_conn=True,会走 get_connection → 触发 ensure 建表)
|
||||
summary = _enqueue_download_tasks_safe(["ENQ-CREATE-1"])
|
||||
if summary.get("failed", 0) > 0:
|
||||
return False, f"应自动建表后入队成功,但 failed={summary}"
|
||||
|
||||
# 3. 验证表确实被自动创建了
|
||||
conn = sqlite3.connect(str(tmp_db))
|
||||
try:
|
||||
count = conn.execute(
|
||||
"SELECT COUNT(*) FROM download_tasks"
|
||||
).fetchone()[0]
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
if count != 1:
|
||||
return False, f"download_tasks 应有 1 行,实际 {count}"
|
||||
|
||||
return True, f"ensure 建表 + 入队 OK(enqueued={summary.get('enqueued')})"
|
||||
finally:
|
||||
rp.get_db_path = orig_rp_db_path # type: ignore[assignment]
|
||||
dbconn.get_db_path = orig_dbconn_db_path # type: ignore[assignment]
|
||||
|
||||
|
||||
# ---------- v1.1.19: _wait_for_url_stable + login flow ----------
|
||||
|
||||
|
||||
@@ -1916,6 +1990,7 @@ def main() -> int:
|
||||
_run("download_tasks/enqueue_safe_idempotent", test_enqueue_download_tasks_safe_idempotent)
|
||||
_run("download_tasks/enqueue_safe_fk_failure", test_enqueue_download_tasks_safe_fk_failure)
|
||||
_run("download_tasks/enqueue_safe_empty_list", test_enqueue_download_tasks_safe_empty_list)
|
||||
_run("download_tasks/enqueue_safe_auto_create_table_v1_29", test_enqueue_download_tasks_safe_auto_create_table_v1_29)
|
||||
_run("login_flow/wait_url_stable_immediate", test_wait_for_url_stable_immediate_match)
|
||||
_run("login_flow/wait_url_stable_transition", test_wait_for_url_stable_transition)
|
||||
_run("login_flow/wait_url_stable_timeout", test_wait_for_url_stable_timeout)
|
||||
|
||||
Reference in New Issue
Block a user