fix: 调整登录检测入口URL

无 Shopee tab 时,登录检测改为打开卖家中心根地址 https://<region_host>/,默认 https://seller.shopee.tw/。

商品编辑 URL 仍保持 /portal/product 路径不变;更新登录检测单测与 API/架构/当前状态/progress 文档。
This commit is contained in:
chengma
2026-06-27 12:05:33 +08:00
parent 6e00b1b093
commit 8fe979942c
6 changed files with 22 additions and 10 deletions
+4 -4
View File
@@ -116,8 +116,8 @@ def _region_host(account=None):
return value.strip("/") or DEFAULT_REGION_HOST
def _portal_url(account):
return f"https://{_region_host(account)}/portal/"
def _seller_home_url(account):
return f"https://{_region_host(account)}/"
def _product_url(account, item_id):
@@ -220,8 +220,8 @@ def login_status(account, timeout=8) -> dict:
pages = [t for t in http_get("/json", host=host) if t.get("type") == "page"]
shopee_page = next((p for p in pages if "shopee" in (p.get("url") or "")), None)
if not shopee_page:
ws = create_tab(_portal_url(account), host=host)
initial_url = _portal_url(account)
ws = create_tab(_seller_home_url(account), host=host)
initial_url = _seller_home_url(account)
cdp = CDP(ws)
else:
initial_url = shopee_page.get("url") or ""
+1 -1
View File
@@ -319,7 +319,7 @@ images/<slug>/<item_id>_new.<ext> # AI 生成的新封面
### 6.4 登录检测
- 打开卖家中心,重定向到登录页或缺会话 Cookie(`SPC_ST`/`SPC_U`)→ 未登录;不自动登录,提示人工登录。
- 无 Shopee tab 时打开卖家中心根地址 `https://<region_host>/`(默认 `https://seller.shopee.tw/`),重定向到登录页或缺会话 Cookie(`SPC_ST`/`SPC_U`)→ 未登录;不自动登录,提示人工登录。
## 七、CDP 已验证事实(务必遵守)
+1 -1
View File
@@ -214,7 +214,7 @@ apply_task(account, task) -> dict # 对已生成任务:换标题+
# -> {committed, error}
```
`login_status()` 不自动登录;无 Shopee tab 时只打开卖家中心用于检测/人工登录。判断规则:最终 URL 是登录页 → `LOGIN_PAGE`;缺少 `SPC_ST`/`SPC_U` → `NO_SESSION_COOKIE`;有会话 Cookie → 已登录。
`login_status()` 不自动登录;无 Shopee tab 时打开卖家中心根地址 `https://<region_host>/`(默认 `https://seller.shopee.tw/`)用于检测/人工登录。判断规则:最终 URL 是登录页 → `LOGIN_PAGE`;缺少 `SPC_ST`/`SPC_U` → `NO_SESSION_COOKIE`;有会话 Cookie → 已登录。
## ai 模块(`app/ai.py`,待建,外部 AI,服务商待定)
+1 -1
View File
@@ -21,7 +21,7 @@
- 账号↔任务绑定:以 Excel“别名”列为权威;未匹配略过,结束弹窗汇总。
- 执行:多账号串行、单条失败继续;③ 点击「开始更新」后弹窗确认当前筛选范围和任务数量,确认后逐条点「更新」提交线上。
- AI:服务商待定;生成内容直接用于更新,本地留档+回写 Excel 供追溯。
- 登录:人工登录 + 程序检测,不自动登录;首次未配账号/未登录时 ① ③ 禁用并引导去④。
- 登录:人工登录 + 程序检测,不自动登录;无 Shopee tab 时检测入口为 `https://<region_host>/`(默认 `https://seller.shopee.tw/`);首次未配账号/未登录时 ① ③ 禁用并引导去④。
## 当前目录要点
+7
View File
@@ -410,3 +410,10 @@
- 验证:`python -m unittest discover -s tests -p "test_gui.py"` 通过(10 tests);`python -m compileall app main.py tests` 通过;`python -m unittest discover -s tests` 通过(49 tests,skipped=1);`py -3 -m compileall app main.py tests` 通过;`py -3 -m unittest discover -s tests` 通过(34 tests,skipped=4,py -3 环境缺 openpyxl/PySide6,相关测试按设计跳过)。
- 注意:本轮未连接真实 Shopee/CDP 实跑采集,`accounts.detect_login()` 与 `editor.collect()` 路径由 mock 覆盖;接 T-204 前建议用测试商品和已登录账号做一次 Tab① 真机采集冒烟。
- 下一步:按任务看板领取 T-204(回写旧字段到原 Excel,含文件锁处理)。
## 【2026-06-27】修正 · 登录检测入口 URL
- 状态:DONE
- 变更:`app/editor.py` 将无 Shopee tab 时的登录检测入口从 `https://<region_host>/portal/` 改为 `https://<region_host>/`,默认即 `https://seller.shopee.tw/`;更新 `tests/test_editor_login.py`、`docs/api.md`、`docs/04-architecture.md`、`docs/current-state.md`。
- 决策:商品编辑页 URL 仍保持 `/portal/product/<item_id>?pageEntry=product_list&ignore-html-cache=1`,本轮只改登录检测/人工登录入口。
- 验证:`python -m unittest discover -s tests -p "test_editor_login.py"` 通过(5 tests);`python -m unittest discover -s tests -p "test_accounts.py"` 通过(8 tests);`python -m compileall app main.py tests` 通过;`python -m unittest discover -s tests` 通过(49 tests,skipped=1);`py -3 -m compileall app main.py tests` 通过;`py -3 -m unittest discover -s tests` 通过(34 tests,skipped=4)。
+8 -3
View File
@@ -5,6 +5,11 @@ from unittest import mock
sys.path.insert(0, os.path.dirname(__file__))
from _helpers import REPO_ROOT
if str(REPO_ROOT) not in sys.path:
sys.path.insert(0, str(REPO_ROOT))
from app import editor
@@ -103,11 +108,11 @@ class EditorLoginTests(unittest.TestCase):
self.assertFalse(status["logged_in"])
self.assertEqual("NO_SESSION_COOKIE", status["reason"])
def test_login_status_opens_portal_when_no_shopee_page(self):
def test_login_status_opens_seller_home_when_no_shopee_page(self):
with mock.patch("app.editor.http_get", return_value=[]), mock.patch(
"app.editor.create_tab", return_value="ws-new"
) as create_tab, self.patch_cdp(
url="https://seller.shopee.tw/portal/",
url="https://seller.shopee.tw/",
cookies=[cookie("SPC_U")],
):
status = editor.login_status(
@@ -117,7 +122,7 @@ class EditorLoginTests(unittest.TestCase):
self.assertTrue(status["logged_in"])
create_tab.assert_called_once_with(
"https://seller.shopee.tw/portal/",
"https://seller.shopee.tw/",
host="127.0.0.1:9222",
)