@kevlns/xlmerge 2.0.3 → 2.0.4
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.
package/AGENTS.md
CHANGED
|
@@ -156,6 +156,8 @@ cd <npm 包目录>
|
|
|
156
156
|
python -m unittest discover -s python/tests -v
|
|
157
157
|
```
|
|
158
158
|
|
|
159
|
+
后台审阅用 `xlmerge launch`。`xlmerge status --manifest <file>` 查询原服务,`xlmerge cancel --manifest <file>` 请求停止并检查 stopConfirmed;身份不一致拒绝停止。通过 v-cli 结构化执行时,launch/resolve 返回 accepted 与 handle;status/cancel 使用原 handle,后台进程继续持有工程租约,停止前不重放启动。
|
|
160
|
+
|
|
159
161
|
## 结果验证
|
|
160
162
|
|
|
161
163
|
核对原始错误、任务身份、停止状态及实际产物。只报告已经完成的验证,模拟测试与真实执行分别说明。
|
package/package.json
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
5
|
import json
|
|
6
|
+
import os
|
|
7
|
+
import uuid
|
|
6
8
|
import sys
|
|
7
9
|
import threading
|
|
8
10
|
import webbrowser
|
|
@@ -16,6 +18,7 @@ if str(SCRIPT_DIR) not in sys.path:
|
|
|
16
18
|
sys.path.insert(0, str(SCRIPT_DIR))
|
|
17
19
|
|
|
18
20
|
from xlsx_conflict import ConflictError, _build_commit_message, apply_manifest, load_manifest
|
|
21
|
+
from session import save_session
|
|
19
22
|
from prepare_progress import preparation_context, PreparationCancelled, checkpoint
|
|
20
23
|
|
|
21
24
|
|
|
@@ -73,6 +76,9 @@ def serve(manifest_path: Path | str, *, open_browser: bool = True, port: int = 0
|
|
|
73
76
|
status = {'state': 'preparing' if prepare_repo else 'ready', 'phase': '开始解析',
|
|
74
77
|
'file': '', 'fileDone': 0, 'fileTotal': 0, 'sheet': '', 'sheetDone': 0, 'sheetTotal': 0, 'side': ''}
|
|
75
78
|
|
|
79
|
+
receipt = {"sessionId": uuid.uuid4().hex, "pid": os.getpid(), "manifest": str(manifest_path), "state": "running"}
|
|
80
|
+
receipt_file = manifest_path.parent / "session.json"
|
|
81
|
+
|
|
76
82
|
def report(progress):
|
|
77
83
|
with lock:
|
|
78
84
|
status.update(progress)
|
|
@@ -109,6 +115,11 @@ def serve(manifest_path: Path | str, *, open_browser: bool = True, port: int = 0
|
|
|
109
115
|
with lock:
|
|
110
116
|
return _json(dict(status))
|
|
111
117
|
|
|
118
|
+
@app.get("/api/session")
|
|
119
|
+
def session_status():
|
|
120
|
+
with lock:
|
|
121
|
+
return _json({**receipt, "progress": dict(status)})
|
|
122
|
+
|
|
112
123
|
@app.get("/api/diff")
|
|
113
124
|
def diff():
|
|
114
125
|
if manifest is None:
|
|
@@ -141,6 +152,7 @@ def serve(manifest_path: Path | str, *, open_browser: bool = True, port: int = 0
|
|
|
141
152
|
message=(payload.get("message") or "").strip() or None,
|
|
142
153
|
)
|
|
143
154
|
if result["success"]:
|
|
155
|
+
receipt.update(state="completed", result=result)
|
|
144
156
|
state["resolved"] = True
|
|
145
157
|
threading.Timer(2.0, state["server"].shutdown).start()
|
|
146
158
|
return _json(result, 200 if result["success"] else 500)
|
|
@@ -153,6 +165,10 @@ def serve(manifest_path: Path | str, *, open_browser: bool = True, port: int = 0
|
|
|
153
165
|
|
|
154
166
|
@app.post("/api/shutdown")
|
|
155
167
|
def shutdown():
|
|
168
|
+
_payload()
|
|
169
|
+
identity = request.headers.get("X-Xlmerge-Session")
|
|
170
|
+
if identity is not None and identity != receipt["sessionId"]:
|
|
171
|
+
return _json({"success": False, "error": "审阅身份不一致"}, 409)
|
|
156
172
|
with lock:
|
|
157
173
|
if status['state'] == 'preparing':
|
|
158
174
|
cancelled.set()
|
|
@@ -169,11 +185,19 @@ def serve(manifest_path: Path | str, *, open_browser: bool = True, port: int = 0
|
|
|
169
185
|
if worker:
|
|
170
186
|
worker.start()
|
|
171
187
|
url = f"http://127.0.0.1:{server.server_port}"
|
|
188
|
+
receipt["url"] = url
|
|
189
|
+
save_session(receipt_file, receipt)
|
|
172
190
|
print(f"MERGE_SERVER_URL={url}", flush=True)
|
|
173
191
|
if open_browser:
|
|
174
192
|
webbrowser.open(url)
|
|
175
193
|
try:
|
|
176
194
|
server.serve_forever()
|
|
177
195
|
finally:
|
|
196
|
+
cancelled.set()
|
|
197
|
+
if worker:
|
|
198
|
+
worker.join()
|
|
178
199
|
server.server_close()
|
|
200
|
+
if receipt["state"] != "completed":
|
|
201
|
+
receipt["state"] = "failed" if status["state"] == "failed" else "cancelled"
|
|
202
|
+
save_session(receipt_file, receipt)
|
|
179
203
|
return bool(state["resolved"])
|
|
@@ -151,6 +151,10 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
151
151
|
serve_parser.add_argument('--prepare', action='store_true', help=argparse.SUPPRESS)
|
|
152
152
|
serve_parser.add_argument('--path', help=argparse.SUPPRESS)
|
|
153
153
|
|
|
154
|
+
for action in ("status", "cancel"):
|
|
155
|
+
control = subparsers.add_parser(action, help="查询或停止原审阅服务。")
|
|
156
|
+
control.add_argument("--manifest", required=True)
|
|
157
|
+
|
|
154
158
|
apply_parser = subparsers.add_parser("apply", help="Apply a decisions JSON without launching the UI.")
|
|
155
159
|
apply_parser.add_argument("--manifest", required=True)
|
|
156
160
|
apply_parser.add_argument("--decisions", required=True)
|
|
@@ -164,6 +168,11 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
164
168
|
_configure_stdio()
|
|
165
169
|
args = build_parser().parse_args(argv)
|
|
166
170
|
try:
|
|
171
|
+
if args.command in ("status", "cancel"):
|
|
172
|
+
from session import inspect_session
|
|
173
|
+
result = inspect_session(args.manifest, cancel=args.command == "cancel")
|
|
174
|
+
_print(result)
|
|
175
|
+
return 0 if result["ok"] else 1
|
|
167
176
|
# serve/apply 仅依赖 manifest(其 repoRoot 在 apply_manifest 内部解析),
|
|
168
177
|
# 可在非 git 目录下运行;其余公开命令需要前置解析仓库。
|
|
169
178
|
if args.command in ("detect", "filter", "prepare", "resolve", "launch"):
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"""审阅服务的持久化身份与完成回执。"""
|
|
2
|
+
import json
|
|
3
|
+
import os
|
|
4
|
+
import uuid
|
|
5
|
+
import time
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from urllib.request import Request, urlopen
|
|
8
|
+
from urllib.parse import urlparse
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def save_session(file, data):
|
|
12
|
+
file = Path(file)
|
|
13
|
+
file.parent.mkdir(parents=True, exist_ok=True)
|
|
14
|
+
temp = file.with_name(file.name + '.' + uuid.uuid4().hex + '.tmp')
|
|
15
|
+
temp.write_text(json.dumps(data, ensure_ascii=False), encoding='utf-8')
|
|
16
|
+
os.replace(temp, file)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def inspect_session(manifest, cancel=False):
|
|
20
|
+
file = Path(manifest).resolve().parent / 'session.json'
|
|
21
|
+
original = json.loads(file.read_text(encoding='utf-8'))
|
|
22
|
+
if str(Path(original['manifest']).resolve()) != str(Path(manifest).resolve()):
|
|
23
|
+
raise ValueError('审阅身份与清单不一致')
|
|
24
|
+
if original['state'] in ('completed', 'cancelled', 'failed'):
|
|
25
|
+
return {**original, 'ok': True, 'stopConfirmed': True}
|
|
26
|
+
url = urlparse(original['url'])
|
|
27
|
+
if url.scheme != 'http' or url.hostname != '127.0.0.1' or not url.port or url.path:
|
|
28
|
+
raise ValueError('审阅服务地址无效')
|
|
29
|
+
try:
|
|
30
|
+
live = json.load(urlopen(original['url'] + '/api/session', timeout=3))
|
|
31
|
+
if live.get('sessionId') != original['sessionId'] or live.get('pid') != original['pid']:
|
|
32
|
+
raise ValueError('审阅服务身份变化,拒绝操作')
|
|
33
|
+
if not cancel:
|
|
34
|
+
return {**live, 'ok': True, 'stopConfirmed': False}
|
|
35
|
+
req = Request(original['url'] + '/api/shutdown', data=b'{}', headers={'X-Xlmerge-Session': original['sessionId']}, method='POST')
|
|
36
|
+
with urlopen(req, timeout=3):
|
|
37
|
+
pass
|
|
38
|
+
deadline = time.monotonic() + 5
|
|
39
|
+
while time.monotonic() < deadline:
|
|
40
|
+
settled = json.loads(file.read_text(encoding='utf-8'))
|
|
41
|
+
if settled['state'] in ('completed', 'cancelled', 'failed'):
|
|
42
|
+
return {**settled, 'ok': True, 'stopConfirmed': True}
|
|
43
|
+
time.sleep(.1)
|
|
44
|
+
return {**live, 'ok': True, 'state': 'cancelling', 'stopConfirmed': False}
|
|
45
|
+
except OSError as exc:
|
|
46
|
+
settled = json.loads(file.read_text(encoding='utf-8'))
|
|
47
|
+
if settled['state'] in ('completed', 'cancelled', 'failed'):
|
|
48
|
+
return {**settled, 'ok': True, 'stopConfirmed': True}
|
|
49
|
+
return {**original, 'ok': False, 'state': 'unknown', 'stopConfirmed': False, 'error': str(exc)}
|
package/v-cli.plugin.json
CHANGED
|
@@ -242,6 +242,57 @@
|
|
|
242
242
|
"commits-by-default",
|
|
243
243
|
"pushes-only-with-flag"
|
|
244
244
|
]
|
|
245
|
+
},
|
|
246
|
+
{
|
|
247
|
+
"path": [
|
|
248
|
+
"status"
|
|
249
|
+
],
|
|
250
|
+
"usage": "xlmerge status --manifest <file>",
|
|
251
|
+
"description": "查询原审阅服务。",
|
|
252
|
+
"arguments": [],
|
|
253
|
+
"options": [
|
|
254
|
+
{
|
|
255
|
+
"flags": "--manifest <file>",
|
|
256
|
+
"description": "原审阅清单路径,必须与 session.json 身份一致。"
|
|
257
|
+
}
|
|
258
|
+
],
|
|
259
|
+
"output": {
|
|
260
|
+
"format": "json",
|
|
261
|
+
"description": "返回审阅身份、状态、完成回执及 stopConfirmed;unknown 不代表已停止。"
|
|
262
|
+
},
|
|
263
|
+
"exitCodes": {
|
|
264
|
+
"0": "查询或停止请求完成。",
|
|
265
|
+
"1": "身份、连接或状态不可确认。"
|
|
266
|
+
},
|
|
267
|
+
"safety": [
|
|
268
|
+
"read-only"
|
|
269
|
+
]
|
|
270
|
+
},
|
|
271
|
+
{
|
|
272
|
+
"path": [
|
|
273
|
+
"cancel"
|
|
274
|
+
],
|
|
275
|
+
"usage": "xlmerge cancel --manifest <file>",
|
|
276
|
+
"description": "请求停止原审阅服务并等待回执。",
|
|
277
|
+
"arguments": [],
|
|
278
|
+
"options": [
|
|
279
|
+
{
|
|
280
|
+
"flags": "--manifest <file>",
|
|
281
|
+
"description": "原审阅清单路径,必须与 session.json 身份一致。"
|
|
282
|
+
}
|
|
283
|
+
],
|
|
284
|
+
"output": {
|
|
285
|
+
"format": "json",
|
|
286
|
+
"description": "返回审阅身份、状态、完成回执及 stopConfirmed;unknown 不代表已停止。"
|
|
287
|
+
},
|
|
288
|
+
"exitCodes": {
|
|
289
|
+
"0": "查询或停止请求完成。",
|
|
290
|
+
"1": "身份、连接或状态不可确认。"
|
|
291
|
+
},
|
|
292
|
+
"safety": [
|
|
293
|
+
"binds-loopback",
|
|
294
|
+
"no-commit"
|
|
295
|
+
]
|
|
245
296
|
}
|
|
246
297
|
]
|
|
247
298
|
}
|