From 2127e772eb545171d6976143b40c759b4af462ab Mon Sep 17 00:00:00 2001 From: PureSaber Date: Wed, 2 Dec 2026 00:06:30 +0800 Subject: [PATCH 1/2] Simplify research interactions and repetitive notices [skip ci] --- CONTRIBUTING.md | 8 +++ src/quant_studio/intake_web.py | 24 ++++---- src/quant_studio/project_evidence_web.py | 20 +++++-- src/quant_studio/project_registration_web.py | 37 ++++++------- src/quant_studio/project_web.py | 5 +- src/quant_studio/server.py | 2 +- tests/test_usability_completion.py | 1 - tests/test_workflow_registration.py | 58 ++++++++++++++++++-- 8 files changed, 111 insertions(+), 44 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 1084ecd..371ccf8 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -11,3 +11,11 @@ ``` 不要提交 `runs/`、虚拟环境、密钥或外部量化仓库内容。新增运行依赖、开放非回环监听或修改上游仓库均需先讨论。 + +## 研究流程与提示 + +- 新增限制前,写清具体会出错的操作、后果和触发条件;只有假设的未来需求,先不增加流程。 +- 保存备注、查看结果等日常操作直接完成。需要预览的操作,在预览页用一个明确说明结果的按钮提交,避免重复要求“已阅读”勾选。 +- 提示优先说明当前结果和下一步;长哈希、版本身份、内部检查过程放入可展开详情。同一条适用范围说明在页面上集中展示一次。 +- 研究备注和失败原因随时可记录。收益比较只检查参与比较的结果,不阻止查看配置或比较失败原因。 +- 保留数据时点、计算口径、账本一致性、请求权限和任务去重检查。简化交互时验证正常路径、失败恢复和重复提交,按实际影响选择测试。 diff --git a/src/quant_studio/intake_web.py b/src/quant_studio/intake_web.py index d636346..c92cfa6 100644 --- a/src/quant_studio/intake_web.py +++ b/src/quant_studio/intake_web.py @@ -93,16 +93,17 @@ def _retry_body(uploaded, identifier, encoding, delimiter, message): delimiter, ) return f"""

原件解析需要调整

-

{escape(uploaded["filename"])} · 原件已留存 · -SHA-256 {escape(uploaded["sha256"])}

+

{escape(uploaded["filename"])}

{escape(message)}

调整编码或分隔符后重试

-

重试只重新读取同一份原件,不会覆盖或另存上传内容。

+

调整后重新读取已上传的文件。

-

返回原件与导入记录

""" +

返回原件与导入记录

+
原件信息

原件已留存 · +SHA-256 {escape(uploaded["sha256"])}

""" def _request_contract(store, identifier): @@ -464,11 +465,10 @@ def mapping_body( ) parent_input = _input("parent", "要更新的旧版本ID(首次导入留空)", parent) return f'''

确认字段映射

-

{escape(uploaded["filename"])} · 原件已留存 · -SHA-256 {escape(uploaded["sha256"])}

+

{escape(uploaded["filename"])}

{refresh_picker}{refresh_notice}

原始样例

-

仅预览最多20行,不代表全量质量检查通过。

{table(columns, sample_rows)}
+

前20行预览;提交后检查完整文件。

{table(columns, sample_rows)}
{csrf(token)} {reuse_hidden} @@ -484,9 +484,13 @@ def mapping_body(
{"".join(rows)}
原列规范列名类型日期格式单位
-

证券代码使用文本以保留前导零。只按明确映射转换,不自动补值、猜单位或推断披露时间。

- -
''' +

证券代码请选择文本类型以保留前导零;按原始数据填写单位和披露时间。

+

提交后进行完整检查,通过后发布为数据版本。

+ + +
原件与转换说明 +

原件已留存 · SHA-256 {escape(uploaded["sha256"])}

+

按上方映射转换数据,缺失值保留为空。原件保存全部列。

''' def quality_body(data): diff --git a/src/quant_studio/project_evidence_web.py b/src/quant_studio/project_evidence_web.py index 3caa55c..33c3f73 100644 --- a/src/quant_studio/project_evidence_web.py +++ b/src/quant_studio/project_evidence_web.py @@ -41,16 +41,20 @@ def evidence_body(root, token, identifier): try: view = project_evidence(root, identifier) except QuantStudioError as exc: - return body + f'

{escape(str(exc))}

' + return body + ( + '

暂时无法加载复核资料

' + f"

{escape(str(exc))}

" + f'' + "先记录研究备注
" + ) state = view["lifecycle"] body += f"""

研究进度

研究问题 → 方案/预登记 → 全部尝试 → 证据 → 结论与复核

当前状态:{STATES.get(state["state"], "未知")}; 共 {len(view["attempts"])} 项已关联尝试。

-

观察与暂停只记录研究判断,不改变任何账户或任务的执行权限。

-

字节核验只说明所引用文件是否一致;统计有效性和业务解释仍需研究者判断。

+记录想法与研究备注

方案与预登记

-

项目保存属于探索记录;只有显式连接的 Lab 预登记才展示为预登记。

""" +

查看已连接的方案与 Lab 预登记记录。

""" for record in view["registration"]: if record.get("study_id"): definition = record["definition"]["definition"] @@ -80,7 +84,6 @@ def evidence_body(root, token, identifier): body += "

历史记录按相同方案版本关联,未声明由本项目提交。

" for issue in row["issues"]: body += f"

{escape(str(issue))}

" - body += "

未声明统一比较口径的尝试,不合并收益或自动排名。

" body += "
" if view["missing"]: body += '

需要核对的来源

证据身份与来源明细
'
     )
diff --git a/src/quant_studio/project_registration_web.py b/src/quant_studio/project_registration_web.py
index e3c15f8..b930a28 100644
--- a/src/quant_studio/project_registration_web.py
+++ b/src/quant_studio/project_registration_web.py
@@ -20,8 +20,8 @@ def body(root, token, project_id, query):
     )
     page += f'返回项目'
     page += (
-        "

登记冻结一个已完成候选。新增账户独立核验;" - "每日调度需另行配置,当前调度账户保持原绑定。

" + "

将已完成的研究方案保存为模拟账户,用于后续跟踪。" + "每日自动运行可在登记后另行配置。

" ) try: registration.configuration(root) @@ -40,18 +40,18 @@ def body(root, token, project_id, query): f"{escape(row['run_id'])} · {escape(row['candidate'])}" for row in choices ) - page += f'''

选择已完成的原生候选

+ page += f'''

选择研究方案

{csrf(token)} - -

起点须为未来已知交易日,且晚于研究结束日;资金和成本取自冻结配方。

-
''' + +

从研究结束后的未来交易日开始观察,沿用方案中的初始资金和成本设置。

+
''' else: page += ( - "

暂无可登记候选。请在本项目完成研究卡、连接方案并运行完整候选族;" - "失败实验保留在项目实验中。

" + "

暂无可登记方案。请先完成研究设计,并运行方案中的全部候选。

" + f'查看方案与运行' ) for record in registration.invoke(root, "list", {"project_id": project_id})[ "previews" @@ -68,12 +68,12 @@ def body(root, token, project_id, query): receipt = value.get("receipt") or {} state = receipt.get("state", "prepared") labels = { - "prepared": "待人工确认", + "prepared": "可登记", "registering": "登记中或上次登记中断,请核验任务后恢复", "completed": "登记完成", "recoverable_failure": "登记失败,可核验后恢复", } - page += '

冻结预览

' + page += '

模拟账户预览

' page += ( f"

状态:{escape(labels.get(state, state))};有效期至 " f"{escape(local_time(value['expires_at']))}

" @@ -82,12 +82,11 @@ def body(root, token, project_id, query): f"{escape(str(definition['recipe']['costs']['initial_capital']))}

" f"

观察区间:{escape(request['start'])} 至 {escape(request['end'])};" f'来源实验:' - f"查看原生实验;项目版本:{escape(request['revision'])}

" - "

前置条件已通过:完整候选族、原生证据、输入快照、代码身份、" - "未来交易日、当前行情及研究预检。确认时重新核验;过期或变更需重新预览。

" + "查看实验

" ) - page += details(plan["prerequisites"], "原生前置检查结果") + details( - definition, "完整冻结配方、输入、成本与代码版本" + page += details(plan["prerequisites"], "查看数据与运行检查") + details( + {"project_revision": request["revision"], "definition": definition}, + "查看完整参数、数据与代码版本", ) if receipt.get("error"): page += f'

{escape(receipt["error"])}

' @@ -95,16 +94,16 @@ def body(root, token, project_id, query): page += '

当前账户核验未通过:' page += escape(value["inspection_error"]) + "

" if value.get("inspection"): - page += "

当前账户独立核验

尚未接管任何每日调度。

" + page += "

账户检查结果

" page += details(value["inspection"], "账户身份、观察和账本证据") if state != "completed": + button = "登记模拟账户" if state == "prepared" else "检查并恢复登记" page += f'''
{csrf(token)} - -
''' +

按以上方案登记模拟账户,提交时会再次检查数据和版本。

+''' page += f'

重新选择并预览 · ' page += '检查登记任务及中断记录

' return page + details(receipt, "登记回执与失败记录") + "
" diff --git a/src/quant_studio/project_web.py b/src/quant_studio/project_web.py index 5920544..2e97b7d 100644 --- a/src/quant_studio/project_web.py +++ b/src/quant_studio/project_web.py @@ -33,7 +33,7 @@ def catalog_body(root, query): search = query.get("q", [""])[0] selected = query.get("dataset", [""])[0] body = f'''

数据目录

-

查找数据、查看字段与样本,再进入研究。登记身份与业务适用性分别检查。

+

查找数据、查看字段与样本,再进入研究。

@@ -156,7 +156,8 @@ def notebook_body(root, token, project): rel="noopener noreferrer">打开JupyterLab

''' body += f''' {csrf(token)} -
''' +

运行前请在 JupyterLab 保存修改。每次实验会保留代码和输入数据的副本。

+''' except QuantStudioError as exc: body += f"

{escape(str(exc))}

" for record in store.list(identifier): diff --git a/src/quant_studio/server.py b/src/quant_studio/server.py index e116be5..159256e 100644 --- a/src/quant_studio/server.py +++ b/src/quant_studio/server.py @@ -2600,7 +2600,7 @@ def _layout(title: str, body: str, active: str = "strategy") -> str: 页面导航 · 当前:{escape(active_label)}
-

研究用途 · 不下真实订单 · 不构成投资建议

+

数据研究 · 策略回测 · 模拟跟踪

{related_navigation(active)}{body}
""" diff --git a/tests/test_usability_completion.py b/tests/test_usability_completion.py index b21cb94..65af9ab 100644 --- a/tests/test_usability_completion.py +++ b/tests/test_usability_completion.py @@ -64,7 +64,6 @@ def test_workbench_exposes_persistent_display_preference_without_posting_runtime assert 'id="return-colors"' in page assert "红涨绿跌" in page and "绿涨红跌" in page assert "localStorage" in page - assert "不构成投资建议" in page def test_editor_rate_echo_and_unknown_numeric_parameter_keep_native_contract(): diff --git a/tests/test_workflow_registration.py b/tests/test_workflow_registration.py index c8b515b..5c6c4ea 100644 --- a/tests/test_workflow_registration.py +++ b/tests/test_workflow_registration.py @@ -1,5 +1,6 @@ import hashlib import json +from html.parser import HTMLParser import pytest @@ -8,7 +9,7 @@ from quant_studio.etf_status_context import explain_issue, history_context from quant_studio.experiment_context import differences from quant_studio.jobs import JobManager -from quant_studio.project_registration_web import post +from quant_studio.project_registration_web import body, post from quant_studio.projects import ProjectStore @@ -79,8 +80,9 @@ def test_specific_causes_impact_and_destination(code, destination): assert result["cause"] and result["impact"] and result["action"] -def test_confirmation_is_explicit_deduplicated_and_failed_jobs_retry( - tmp_path, monkeypatch +@pytest.mark.parametrize("state", ["prepared", "registering", "recoverable_failure"]) +def test_preview_button_submits_once_and_failed_jobs_retry( + tmp_path, monkeypatch, state ): project = ProjectStore(tmp_path).save("test", "question") jobs = JobManager(tmp_path, start_worker=False) @@ -90,10 +92,27 @@ def test_confirmation_is_explicit_deduplicated_and_failed_jobs_retry( "preview_id": "a" * 32, "config_sha256": "b" * 64, } + preview = { + "plan": { + "definition": {"recipe": {"costs": {"initial_capital": 1000000}}}, + "prerequisites": {}, + }, + "request": { + "revision": project["revision"], + "candidate": "base", + "start": "2027-01-04", + "end": "2027-02-01", + "run_id": "test-run", + }, + "account_id": "test-account", + "expires_at": "2027-01-01T00:00:00Z", + "receipt": {"state": state}, + } + monkeypatch.setattr(project_registration, "configuration", lambda *_: {}) monkeypatch.setattr( project_registration, "inspect", - lambda *_: {"request": {"revision": project["revision"]}}, + lambda *_: preview, ) monkeypatch.setattr(project_registration, "queue_payload", lambda *_: payload) @@ -108,7 +127,29 @@ def _redirect(self, location): self.location = location handler = Handler() - data = {"preview_id": ["a" * 32], "confirmed": ["yes"]} + + class PreviewForm(HTMLParser): + def __init__(self): + super().__init__() + self.fields = {} + self.buttons = [] + + def handle_starttag(self, tag, attrs): + attrs = dict(attrs) + if tag == "input": + assert attrs.get("type") == "hidden", "Preview needs no extra checkbox" + self.fields[attrs["name"]] = [attrs["value"]] + elif tag == "button": + self.buttons.append(attrs) + + form = PreviewForm() + form.feed(body(tmp_path, "csrf", project["id"], {"preview": ["a" * 32]})) + assert len(form.buttons) == 1 + button = form.buttons[0] + assert button["name"] == "confirmed" and button["value"] == "yes" + data = {**form.fields, button["name"]: [button["value"]]} + assert data.pop("_csrf_token") == ["csrf"] + revision = data.pop("revision")[0] try: with pytest.raises(QuantStudioError, match="明确确认"): post( @@ -137,6 +178,13 @@ def _redirect(self, location): ) assert len(jobs.list()) == 2 assert jobs.list()[0]["collection"] == payload + with pytest.raises(QuantStudioError, match="预览版本不一致"): + post(handler, project["id"], "stale", "registration-confirm", dict(data)) + assert len(jobs.list()) == 2 + assert revision == project["revision"] + preview["receipt"]["state"] = "completed" + completed = body(tmp_path, "csrf", project["id"], {"preview": ["a" * 32]}) + assert "registration-confirm" not in completed finally: jobs.close() From 7da671c37c0aa152311a5ad7b6be3042061e4d72 Mon Sep 17 00:00:00 2001 From: PureSaber Date: Wed, 2 Dec 2026 00:14:48 +0800 Subject: [PATCH 2/2] Run required checks before merging research UI cleanup