haoyuan 0.2.0 → 0.2.20261127-1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11,6 +11,7 @@ RUNTIME_FILE = Path(os.getenv("HAOYUAN_RUNTIME_FILE", DATA_DIR / "runtime.json")
11
11
  DEFAULT_API_PORT = 8030
12
12
  DEFAULT_WEB_PORT = 8130
13
13
  PORT_MAX_TRIES = 100
14
+ IS_WINDOWS = os.name == "nt"
14
15
 
15
16
 
16
17
  def read_runtime() -> dict:
@@ -40,9 +41,16 @@ def runtime_port(key: str, fallback: int) -> int:
40
41
 
41
42
  def port_in_use(host: str, port: int) -> bool:
42
43
  probe = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
43
- # 与 uvicorn 监听行为一致:允许复用 TIME_WAIT 端口,避免重启后误判端口占用而漂移
44
- probe.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
45
44
  try:
45
+ if IS_WINDOWS:
46
+ # Windows 的 SO_REUSEADDR 允许绑定已在监听的端口,会把占用误判为空闲,
47
+ # 随后 uvicorn 绑定时报 10048。用独占地址探测才能识别真实占用。
48
+ exclusive = getattr(socket, "SO_EXCLUSIVEADDRUSE", None)
49
+ if exclusive is not None:
50
+ probe.setsockopt(socket.SOL_SOCKET, exclusive, 1)
51
+ else:
52
+ # Unix 下与 uvicorn 一致:允许复用 TIME_WAIT 端口,避免重启后误判端口占用而漂移。
53
+ probe.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
46
54
  probe.bind((host or "127.0.0.1", int(port)))
47
55
  return False
48
56
  except OSError:
@@ -37,3 +37,42 @@ def test_update_runtime_roundtrip(tmp_path, monkeypatch):
37
37
  update_runtime(api_port=8031)
38
38
  update_runtime(web_port=8131, api_port_config=8030)
39
39
  assert read_runtime() == {"api_port": 8031, "web_port": 8131, "api_port_config": 8030}
40
+
41
+
42
+ def test_port_probe_uses_exclusive_addr_on_windows(monkeypatch):
43
+ calls = []
44
+
45
+ class FakeSocket:
46
+ def setsockopt(self, level, opt, value):
47
+ calls.append((level, opt, value))
48
+
49
+ def bind(self, address):
50
+ pass
51
+
52
+ def close(self):
53
+ pass
54
+
55
+ monkeypatch.setattr(runtime, "IS_WINDOWS", True)
56
+ monkeypatch.setattr(runtime.socket, "socket", lambda *args, **kwargs: FakeSocket())
57
+ monkeypatch.setattr(runtime.socket, "SO_EXCLUSIVEADDRUSE", 12345, raising=False)
58
+ assert runtime.port_in_use("127.0.0.1", 8030) is False
59
+ assert calls == [(runtime.socket.SOL_SOCKET, 12345, 1)]
60
+
61
+
62
+ def test_port_probe_uses_reuseaddr_on_unix(monkeypatch):
63
+ calls = []
64
+
65
+ class FakeSocket:
66
+ def setsockopt(self, level, opt, value):
67
+ calls.append((level, opt, value))
68
+
69
+ def bind(self, address):
70
+ pass
71
+
72
+ def close(self):
73
+ pass
74
+
75
+ monkeypatch.setattr(runtime, "IS_WINDOWS", False)
76
+ monkeypatch.setattr(runtime.socket, "socket", lambda *args, **kwargs: FakeSocket())
77
+ assert runtime.port_in_use("127.0.0.1", 8030) is False
78
+ assert calls == [(runtime.socket.SOL_SOCKET, runtime.socket.SO_REUSEADDR, 1)]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "haoyuan",
3
- "version": "0.2.0",
3
+ "version": "0.2.20261127-1",
4
4
  "description": "豪源 · HaoYuan — 个人指挥 AI 实现多个 AI 员工异步并行工作的 AI 工作室",
5
5
  "bin": {
6
6
  "haoyuan": "bin/haoyuan.js"
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "haoyuan-web",
3
- "version": "0.2.0",
3
+ "version": "0.2.20261127-1",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "haoyuan-web",
9
- "version": "0.2.0",
9
+ "version": "0.2.20261127-1",
10
10
  "dependencies": {
11
11
  "dompurify": "^3.2.4",
12
12
  "marked": "^15.0.7",
package/web/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "haoyuan-web",
3
- "version": "0.2.0",
3
+ "version": "0.2.20261127-1",
4
4
  "private": true,
5
5
  "type": "module",
6
6
  "scripts": {