diff --git a/app/editor.py b/app/editor.py index 9901205..a96424b 100644 --- a/app/editor.py +++ b/app/editor.py @@ -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 "" diff --git a/docs/04-architecture.md b/docs/04-architecture.md index d2d8692..53748da 100644 --- a/docs/04-architecture.md +++ b/docs/04-architecture.md @@ -319,7 +319,7 @@ images//_new. # AI 生成的新封面 ### 6.4 登录检测 -- 打开卖家中心,重定向到登录页或缺会话 Cookie(`SPC_ST`/`SPC_U`)→ 未登录;不自动登录,提示人工登录。 +- 无 Shopee tab 时打开卖家中心根地址 `https:///`(默认 `https://seller.shopee.tw/`),重定向到登录页或缺会话 Cookie(`SPC_ST`/`SPC_U`)→ 未登录;不自动登录,提示人工登录。 ## 七、CDP 已验证事实(务必遵守) diff --git a/docs/api.md b/docs/api.md index e27f81e..464b719 100644 --- a/docs/api.md +++ b/docs/api.md @@ -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:///`(默认 `https://seller.shopee.tw/`)用于检测/人工登录。判断规则:最终 URL 是登录页 → `LOGIN_PAGE`;缺少 `SPC_ST`/`SPC_U` → `NO_SESSION_COOKIE`;有会话 Cookie → 已登录。 ## ai 模块(`app/ai.py`,待建,外部 AI,服务商待定) diff --git a/docs/current-state.md b/docs/current-state.md index 7d64f26..2d0b751 100644 --- a/docs/current-state.md +++ b/docs/current-state.md @@ -21,7 +21,7 @@ - 账号↔任务绑定:以 Excel“别名”列为权威;未匹配略过,结束弹窗汇总。 - 执行:多账号串行、单条失败继续;③ 点击「开始更新」后弹窗确认当前筛选范围和任务数量,确认后逐条点「更新」提交线上。 - AI:服务商待定;生成内容直接用于更新,本地留档+回写 Excel 供追溯。 -- 登录:人工登录 + 程序检测,不自动登录;首次未配账号/未登录时 ① ③ 禁用并引导去④。 +- 登录:人工登录 + 程序检测,不自动登录;无 Shopee tab 时检测入口为 `https:///`(默认 `https://seller.shopee.tw/`);首次未配账号/未登录时 ① ③ 禁用并引导去④。 ## 当前目录要点 diff --git a/progress.md b/progress.md index 6b6f826..05d6b8c 100644 --- a/progress.md +++ b/progress.md @@ -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:///portal/` 改为 `https:///`,默认即 `https://seller.shopee.tw/`;更新 `tests/test_editor_login.py`、`docs/api.md`、`docs/04-architecture.md`、`docs/current-state.md`。 +- 决策:商品编辑页 URL 仍保持 `/portal/product/?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)。 diff --git a/tests/test_editor_login.py b/tests/test_editor_login.py index 12dba6f..2db38a9 100644 --- a/tests/test_editor_login.py +++ b/tests/test_editor_login.py @@ -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", )