diff --git a/host.py b/host.py index eea399b..81d77d3 100644 --- a/host.py +++ b/host.py @@ -2694,8 +2694,11 @@ def main(): print(json.dumps({"error": str(e)}, ensure_ascii=False)) raise SystemExit(1) elif args.cmd == "thread-unarchive": + # 与 archive 一致:不 resume,直接调 thread/unarchive。 + # 已归档 thread 先 resume 会失败(thread/resume 报错 → + # CLI 退出 1 → 服务端回 502),而 unarchive 本身只认 + # threadId,不需要先恢复会话。 try: - srv.resume_thread(args.thread_id) resp = srv.request("thread/unarchive", {"threadId": args.thread_id}, timeout=60) diff --git a/tests/test_host_thread_cli.py b/tests/test_host_thread_cli.py index 7a0c1d1..64b1e8b 100644 --- a/tests/test_host_thread_cli.py +++ b/tests/test_host_thread_cli.py @@ -151,7 +151,7 @@ class ThreadCliTest(unittest.TestCase): calls = self._calls_before_close(fake) self.assertEqual(calls, [("archive", "th-1")]) - def test_unarchive_resume_first(self): + def test_unarchive_no_resume(self): fake = FakeServer() code, out, _ = self._run( fake, ["thread-unarchive", "--thread-id", "th-1"]) @@ -159,7 +159,21 @@ class ThreadCliTest(unittest.TestCase): self.assertEqual(json.loads(out), {"thread": {"id": "th-1"}}) calls = self._calls_before_close(fake) self.assertEqual(calls, [ - ("resume", "th-1"), + ("request", "thread/unarchive", {"threadId": "th-1"}), + ]) + + def test_unarchive_resume_failure_does_not_block(self): + # 回归:已归档 thread 的 resume 会失败;unarchive 不再调 + # resume,所以 resume 失败也不应挡住 unarchive(此前 + # resume 抛错 → CLI 退出 1 → 服务端回 502)。 + fake = FakeServer() + fake.resume_error = True + code, out, _ = self._run( + fake, ["thread-unarchive", "--thread-id", "th-1"]) + self.assertEqual(code, 0) + self.assertEqual(json.loads(out), {"thread": {"id": "th-1"}}) + calls = self._calls_before_close(fake) + self.assertEqual(calls, [ ("request", "thread/unarchive", {"threadId": "th-1"}), ])