@louisultra/dsh-verymath 0.3.2 → 0.3.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.
Files changed (34) hide show
  1. package/CHANGELOG.md +170 -0
  2. package/README.md +37 -6
  3. package/README_EN.md +37 -6
  4. package/UPSTREAM.json +1 -1
  5. package/docs/examples/README.md +5 -5
  6. package/lib/core/error.d.ts +7 -0
  7. package/lib/core/error.js +9 -0
  8. package/lib/core/glossary.d.ts +43 -9
  9. package/lib/core/glossary.js +216 -33
  10. package/lib/core/graph.d.ts +18 -1
  11. package/lib/core/graph.js +43 -6
  12. package/lib/core/index.d.ts +22 -3
  13. package/lib/core/index.js +49 -5
  14. package/lib/core/paper.d.ts +17 -3
  15. package/lib/core/paper.js +43 -12
  16. package/lib/index.d.ts +20 -0
  17. package/lib/index.js +20 -0
  18. package/lib/tool/index.d.ts +23 -0
  19. package/lib/tool/index.js +211 -65
  20. package/package.json +25 -24
  21. package/skills/math-glossary/SKILL.md +1 -0
  22. package/skills/after-ocr/tests/test_scripts.py +0 -84
  23. package/skills/lean-formalization/lean-runtime/tests/fixtures/after_bad.lean +0 -4
  24. package/skills/lean-formalization/lean-runtime/tests/fixtures/after_statement_changed.lean +0 -4
  25. package/skills/lean-formalization/lean-runtime/tests/fixtures/before.lean +0 -4
  26. package/skills/lean-formalization/lean-runtime/tests/fixtures/failure.lean +0 -7
  27. package/skills/lean-formalization/lean-runtime/tests/test_check_lean_project.py +0 -59
  28. package/skills/lean-formalization/lean-runtime/tests/test_cli.py +0 -377
  29. package/skills/lean-formalization/lean-runtime/tests/test_common_config.py +0 -84
  30. package/skills/lean-formalization/lean-runtime/tests/test_configure_lean.py +0 -138
  31. package/skills/lean-formalization/lean-runtime/tests/test_detect_sorry.py +0 -24
  32. package/skills/lean-formalization/lean-runtime/tests/test_direct_task.py +0 -69
  33. package/skills/lean-formalization/lean-runtime/tests/test_numina_runtime.py +0 -168
  34. package/skills/lean-formalization/lean-runtime/tests/test_validate_patch.py +0 -29
@@ -1,84 +0,0 @@
1
- #!/usr/bin/env python3
2
- """after-ocr 辅助脚本的最小回归测试。"""
3
-
4
- from __future__ import annotations
5
-
6
- import importlib.util
7
- import tempfile
8
- import unittest
9
- from pathlib import Path
10
-
11
-
12
- ROOT = Path(__file__).resolve().parents[1]
13
-
14
-
15
- def load_module(name: str, path: Path):
16
- spec = importlib.util.spec_from_file_location(name, path)
17
- if spec is None or spec.loader is None:
18
- raise RuntimeError(f"无法加载模块:{path}")
19
- module = importlib.util.module_from_spec(spec)
20
- spec.loader.exec_module(module)
21
- return module
22
-
23
-
24
- scanner = load_module("after_ocr_scanner", ROOT / "scripts" / "scan_markdown_ocr.py")
25
- merger = load_module("after_ocr_merger", ROOT / "scripts" / "merge_audit_logs.py")
26
-
27
-
28
- class ScannerTests(unittest.TestCase):
29
- def test_detects_core_candidate_rules(self):
30
- source = """# 示例
31
- $$ \\sinx + \\operatorname*{m a x} + \\text{sup} p + \\mathbb{D} + \\tilde{7} + K_{80} \\
32
- \\begin{aligned} a &= b \\end{array}
33
- called $tangent space$
34
- """
35
- with tempfile.TemporaryDirectory() as directory:
36
- path = Path(directory) / "sample.md"
37
- path.write_text(source, encoding="utf-8")
38
- findings, summary = scanner.scan(path)
39
-
40
- rules = {item["rule"] for item in findings}
41
- self.assertIn("operator-glued", rules)
42
- self.assertIn("spaced-operator", rules)
43
- self.assertIn("split-support", rules)
44
- self.assertIn("distribution-space-font", rules)
45
- self.assertIn("accented-digit", rules)
46
- self.assertIn("epsilon-index-as-digits", rules)
47
- self.assertIn("plain-words-in-inline-math", rules)
48
- self.assertIn("environment-mismatch", rules)
49
- self.assertIn("unclosed-display-math", rules)
50
- self.assertEqual(summary["lines"], 4)
51
-
52
-
53
- class MergerTests(unittest.TestCase):
54
- def test_preserves_canonical_category_and_merges_same_position(self):
55
- template = """# 审校日志
56
-
57
- - Markdown:`/tmp/source.md`
58
-
59
- ### AO-X-{pass_name}-001
60
-
61
- - 位置:`/tmp/source.md:12`
62
- - 类别:`MATH_OCR_SYMBOL`
63
- - 严重度:中
64
- - 置信度:高
65
- - 当前内容:`x`
66
- - 问题:符号错误
67
- - 建议修复:改为 `y`
68
- - 证据:上下文一致性
69
- """
70
- with tempfile.TemporaryDirectory() as directory:
71
- first = Path(directory) / "a.md"
72
- second = Path(directory) / "b.md"
73
- first.write_text(template.format(pass_name="A"), encoding="utf-8")
74
- second.write_text(template.format(pass_name="B"), encoding="utf-8")
75
- records = merger.parse_log(first) + merger.parse_log(second)
76
- rendered = merger.render(records, [first, second])
77
-
78
- self.assertEqual([record["category"] for record in records], ["MATH_OCR_SYMBOL"] * 2)
79
- self.assertIn("多轮共同命中的位置:1", rendered)
80
- self.assertIn("`MATH_OCR_SYMBOL`:2", rendered)
81
-
82
-
83
- if __name__ == "__main__":
84
- unittest.main()
@@ -1,4 +0,0 @@
1
- import Mathlib
2
-
3
- theorem add_zero_nat (n : Nat) : n + 0 = n := by
4
- sorry
@@ -1,4 +0,0 @@
1
- import Mathlib
2
-
3
- theorem add_zero_nat (n : Nat) : n + 0 = n + 0 := by
4
- rfl
@@ -1,4 +0,0 @@
1
- import Mathlib
2
-
3
- theorem add_zero_nat (n : Nat) : n + 0 = n := by
4
- exact Nat.add_zero n
@@ -1,7 +0,0 @@
1
- import Mathlib
2
-
3
- theorem target_theorem (n : Nat) : n + 0 = n := by
4
- sorry
5
-
6
- theorem other_theorem (n : Nat) : 0 + n = n := by
7
- exact Nat.zero_add n
@@ -1,59 +0,0 @@
1
- from __future__ import annotations
2
-
3
- import sys
4
- import tempfile
5
- import unittest
6
- from pathlib import Path
7
- from unittest.mock import patch
8
-
9
- SCRIPT_DIR = Path(__file__).resolve().parents[1] / "scripts"
10
- sys.path.insert(0, str(SCRIPT_DIR))
11
-
12
- from check_lean_project import check_project, find_project_root, read_mathlib_revision, read_toolchain # noqa: E402
13
-
14
-
15
- class CheckLeanProjectTests(unittest.TestCase):
16
- def test_finds_project_root_and_versions(self) -> None:
17
- with tempfile.TemporaryDirectory() as tmp:
18
- root = (Path(tmp) / "proj").resolve()
19
- nested = root / "A" / "B"
20
- nested.mkdir(parents=True)
21
- (root / "lean-toolchain").write_text("leanprover/lean4:v4.26.0\n", encoding="utf-8")
22
- (root / "lakefile.toml").write_text(
23
- 'name = "proj"\n\n[[require]]\nname = "mathlib"\nscope = "leanprover-community"\nrev = "v4.26.0"\n',
24
- encoding="utf-8",
25
- )
26
- target = nested / "T.lean"
27
- target.write_text("example : True := by trivial\n", encoding="utf-8")
28
-
29
- self.assertEqual(find_project_root(target), root)
30
- self.assertEqual(read_toolchain(root), "leanprover/lean4:v4.26.0")
31
- self.assertEqual(read_mathlib_revision(root), "v4.26.0")
32
-
33
- result = check_project(root, skip_build=True)
34
- self.assertTrue(result["ok"])
35
- self.assertEqual(result["status"], "ok_skip_build")
36
-
37
- def test_build_uses_discovered_lake_binary(self) -> None:
38
- with tempfile.TemporaryDirectory() as tmp:
39
- root = Path(tmp)
40
- (root / "lean-toolchain").write_text("leanprover/lean4:v4.28.0\n", encoding="utf-8")
41
- (root / "lakefile.toml").write_text('name = "proj"\n', encoding="utf-8")
42
-
43
- with patch("check_lean_project.find_tool", return_value="/custom/bin/lake"), \
44
- patch("check_lean_project.run_command", return_value={
45
- "ok": True,
46
- "returncode": 0,
47
- "stdout": "",
48
- "stderr": "",
49
- "command": ["/custom/bin/lake", "build"],
50
- }) as run:
51
- result = check_project(root)
52
-
53
- self.assertTrue(result["ok"])
54
- run.assert_called_once()
55
- self.assertEqual(run.call_args.args[0], ["/custom/bin/lake", "build"])
56
-
57
-
58
- if __name__ == "__main__":
59
- unittest.main()
@@ -1,377 +0,0 @@
1
- from __future__ import annotations
2
-
3
- import json
4
- import os
5
- import subprocess
6
- import sys
7
- import tempfile
8
- import unittest
9
- from pathlib import Path
10
-
11
- SKILL_ROOT = Path(__file__).resolve().parents[1]
12
- SKILLS_ROOT = SKILL_ROOT.parent
13
- sys.path.insert(0, str(SKILL_ROOT / "scripts"))
14
-
15
- from ai4m_lean import EXIT_LEAN_FAILED, _exit_code # noqa: E402
16
- from common import CANONICAL_LEAN_TOOLCHAIN # noqa: E402
17
- from verify_delivery import _lean_setup_entrypoint_check, _package_hygiene, _root_discovery_boundary_check # noqa: E402
18
-
19
- CLI = SKILL_ROOT / "scripts" / "ai4m_lean.py"
20
- FIXTURES = Path(__file__).resolve().parent / "fixtures"
21
-
22
-
23
- class CliTests(unittest.TestCase):
24
- def test_dry_run_prove_outputs_coding_agent_task(self) -> None:
25
- with tempfile.TemporaryDirectory() as tmp:
26
- root = Path(tmp)
27
- workspace = root / ".ai4math" / "lean-workspace"
28
- workspace.mkdir(parents=True)
29
- (workspace / "lean-toolchain").write_text("leanprover/lean4:v4.28.0\n", encoding="utf-8")
30
- (workspace / "lakefile.toml").write_text('name = "lean_workspace"\n', encoding="utf-8")
31
- target = root / "Failure.lean"
32
- target.write_text((FIXTURES / "failure.lean").read_text(encoding="utf-8"), encoding="utf-8")
33
-
34
- result = subprocess.run(
35
- [
36
- sys.executable,
37
- str(CLI),
38
- "prove",
39
- "--cwd",
40
- str(root),
41
- "--file",
42
- str(target),
43
- "--dry-run",
44
- ],
45
- text=True,
46
- capture_output=True,
47
- check=False,
48
- env={**os.environ, "AI4MATH_LEAN_WORKSPACE": str(workspace), "AI4MATH_NUMINA_HOME": str(root / "shared-ai4math" / "numina-runtime")},
49
- )
50
- self.assertEqual(result.returncode, 0, result.stderr)
51
- payload = json.loads(result.stdout)
52
- self.assertEqual(payload["status"], "dry_run")
53
- self.assertEqual(payload["agent_mode"], "coding-agent")
54
- self.assertEqual(payload["backend"], "none")
55
- self.assertIn("direct_workflow", payload)
56
- self.assertNotIn("command", payload)
57
-
58
- def test_check_skip_build_outputs_json(self) -> None:
59
- with tempfile.TemporaryDirectory() as tmp:
60
- root = Path(tmp)
61
- (root / "lean-toolchain").write_text("leanprover/lean4:v4.26.0\n", encoding="utf-8")
62
- (root / "lakefile.toml").write_text('name = "proj"\n', encoding="utf-8")
63
- result = subprocess.run(
64
- [sys.executable, str(CLI), "check", "--cwd", str(root), "--skip-build"],
65
- text=True,
66
- capture_output=True,
67
- check=False,
68
- )
69
- self.assertEqual(result.returncode, 0, result.stderr)
70
- payload = json.loads(result.stdout)
71
- self.assertTrue(payload["ok"])
72
- self.assertEqual(payload["toolchain"], "leanprover/lean4:v4.26.0")
73
-
74
- def test_smoke_test_dry_run_uses_bundled_target(self) -> None:
75
- with tempfile.TemporaryDirectory() as tmp:
76
- root = Path(tmp)
77
- result = subprocess.run(
78
- [sys.executable, str(CLI), "smoke-test", "--cwd", str(root), "--dry-run"],
79
- text=True,
80
- capture_output=True,
81
- check=False,
82
- env={**os.environ, "AI4MATH_HOME": str(root / "shared-ai4math"), "AI4MATH_LEAN_WORKSPACE": ""},
83
- )
84
- self.assertEqual(result.returncode, 0, result.stderr)
85
- payload = json.loads(result.stdout)
86
- self.assertTrue(payload["ok"])
87
- self.assertEqual(payload["status"], "dry_run")
88
- self.assertTrue(payload["smoke_file"].endswith("examples/smoke/LocalLeanSmoke.lean"))
89
- self.assertFalse(payload["external_api_call"])
90
-
91
- def test_doctor_outputs_tool_report(self) -> None:
92
- result = subprocess.run(
93
- [sys.executable, str(CLI), "doctor", "--cwd", str(SKILL_ROOT)],
94
- text=True,
95
- capture_output=True,
96
- check=False,
97
- env={**os.environ, "AI4MATH_HOME": str(SKILL_ROOT / ".test-ai4math-home"), "AI4MATH_NUMINA_HOME": ""},
98
- )
99
- self.assertEqual(result.returncode, 0, result.stderr)
100
- payload = json.loads(result.stdout)
101
- self.assertTrue(payload["ok"])
102
- self.assertIn("tools", payload)
103
- self.assertIn("readiness", payload)
104
- self.assertIn("numina", payload)
105
- self.assertIn("readiness", payload["numina"])
106
-
107
- def test_configure_setup_numina_dry_run_outputs_official_upstream(self) -> None:
108
- with tempfile.TemporaryDirectory() as tmp:
109
- root = Path(tmp)
110
- result = subprocess.run(
111
- [
112
- sys.executable,
113
- str(CLI),
114
- "configure",
115
- "--cwd",
116
- str(root),
117
- "--setup-numina",
118
- "--project-name",
119
- "demo_project",
120
- "--dry-run",
121
- ],
122
- text=True,
123
- capture_output=True,
124
- check=False,
125
- env={**os.environ, "AI4MATH_HOME": str(root / "shared-ai4math"), "AI4MATH_NUMINA_HOME": ""},
126
- )
127
- self.assertEqual(result.returncode, 0, result.stderr)
128
- payload = json.loads(result.stdout)
129
- self.assertIn("numina", payload)
130
- self.assertEqual(payload["numina"]["status"], "dry_run")
131
- commands = [action["command"] for action in payload["numina"]["actions"]]
132
- self.assertIn("https://github.com/project-numina/numina-lean-agent", str(commands))
133
- self.assertIn(["./setup.sh", "demo_project"], commands)
134
-
135
- def test_configure_create_workspace_dry_run_defaults_to_canonical_toolchain(self) -> None:
136
- with tempfile.TemporaryDirectory() as tmp:
137
- root = Path(tmp)
138
- result = subprocess.run(
139
- [
140
- sys.executable,
141
- str(CLI),
142
- "configure",
143
- "--cwd",
144
- str(root),
145
- "--create-workspace",
146
- "--dry-run",
147
- ],
148
- text=True,
149
- capture_output=True,
150
- check=False,
151
- env={
152
- **os.environ,
153
- "AI4MATH_HOME": str(root / "shared-ai4math"),
154
- "AI4MATH_LEAN_WORKSPACE": "",
155
- "AI4MATH_LEAN_TOOLCHAIN": "",
156
- },
157
- )
158
- self.assertIn(result.returncode, {0, 4}, result.stderr)
159
- payload = json.loads(result.stdout)
160
- command = payload["workspace_actions"][0]["command"]
161
- self.assertEqual(command[1:4], ["run", CANONICAL_LEAN_TOOLCHAIN, "lake"])
162
-
163
- def test_lean_workspace_deploy_failure_uses_lean_exit_code(self) -> None:
164
- self.assertEqual(
165
- _exit_code({"ok": False, "status": "lean_workspace_setup_failed"}),
166
- EXIT_LEAN_FAILED,
167
- )
168
-
169
- def test_verify_delivery_package_checks(self) -> None:
170
- result = subprocess.run(
171
- [sys.executable, str(CLI), "verify-delivery", "--cwd", str(SKILL_ROOT)],
172
- text=True,
173
- capture_output=True,
174
- check=False,
175
- )
176
- self.assertEqual(result.returncode, 0, result.stderr)
177
- payload = json.loads(result.stdout)
178
- self.assertTrue(payload["ok"])
179
- self.assertEqual(payload["status"], "delivery_ready")
180
- self.assertIn("verify-delivery", payload["commands"]["available"])
181
- self.assertTrue(payload["checks"]["lean_setup_entrypoint"])
182
- self.assertFalse(payload["lean_setup_entrypoint"]["missing_phrases"])
183
-
184
- def test_root_discovery_does_not_steal_setup_only_tasks(self) -> None:
185
- boundary = _root_discovery_boundary_check()
186
- self.assertTrue(boundary["ok"], boundary)
187
- self.assertFalse(boundary["root_setup_only_trigger_hits"])
188
-
189
- def test_lean_setup_entrypoint_uses_sibling_helper_layout(self) -> None:
190
- setup = _lean_setup_entrypoint_check()
191
- self.assertTrue(setup["ok"], setup)
192
- self.assertTrue(setup["helper_script_exists"], setup)
193
- self.assertFalse(setup["repo_root_command_hits"], setup)
194
-
195
- def test_two_public_skills_share_hidden_runtime_layer(self) -> None:
196
- runtime_root = SKILLS_ROOT / "lean-runtime"
197
- runtime_cli = runtime_root / "scripts" / "ai4m_lean.py"
198
- setup_text = (SKILLS_ROOT / "lean-setup" / "SKILL.md").read_text(encoding="utf-8")
199
- formalization_text = (SKILLS_ROOT / "lean-formalization" / "SKILL.md").read_text(encoding="utf-8")
200
-
201
- self.assertTrue(runtime_cli.exists())
202
- self.assertIn("../lean-runtime/scripts/ai4m_lean.py", setup_text)
203
- self.assertIn("../lean-runtime/scripts/ai4m_lean.py", formalization_text)
204
- self.assertNotIn("../lean-formalization/scripts/ai4m_lean.py", setup_text)
205
-
206
- def test_lean_setup_offers_default_names_for_isolated_setup(self) -> None:
207
- text = (SKILL_ROOT.parent / "lean-setup" / "SKILL.md").read_text(encoding="utf-8")
208
- self.assertIn("When creating an isolated test directory or workspace", text)
209
- self.assertIn("suggest a safe default name", text)
210
- self.assertIn("use the default if the user has no naming preference", text)
211
-
212
- def test_lean_setup_guides_next_step_after_successful_setup(self) -> None:
213
- text = (SKILL_ROOT.parent / "lean-setup" / "SKILL.md").read_text(encoding="utf-8")
214
- self.assertIn("After successful setup or smoke-test validation", text)
215
- self.assertIn("Offer a short next-step menu", text)
216
- self.assertIn("inspect an existing Lean/Lake project", text)
217
- self.assertIn("repair a Lean file or complete `sorry`", text)
218
- self.assertIn("formalize a natural-language or LaTeX theorem", text)
219
- self.assertIn("mention optional Numina only when the user explicitly asks", text)
220
-
221
- def test_lean_setup_distinguishes_core_and_mathlib_readiness(self) -> None:
222
- text = (SKILL_ROOT.parent / "lean-setup" / "SKILL.md").read_text(encoding="utf-8")
223
- openai_yaml = (SKILL_ROOT.parent / "lean-setup" / "agents" / "openai.yaml").read_text(encoding="utf-8")
224
- runtime_config = (SKILL_ROOT / "references" / "lean_runtime_configuration.md").read_text(encoding="utf-8")
225
-
226
- for phrase in [
227
- "Lean core ready",
228
- "mathlib ready",
229
- "partial readiness",
230
- "`import Mathlib` tasks are blocked",
231
- "Do not present this as full mathlib workspace readiness.",
232
- "Do not recommend formalization, `sorry` completion, or Numina as the default next step while mathlib is missing.",
233
- "git ls-remote https://github.com/leanprover-community/mathlib4.git HEAD",
234
- "Remove-Item -Recurse -Force .lake\\packages\\mathlib",
235
- ]:
236
- self.assertIn(phrase, text)
237
-
238
- for phrase in [
239
- "区分 Lean core ready 和 mathlib ready",
240
- "mathlib 未完成时不要把正式形式化、sorry completion 或 Numina 作为默认下一步",
241
- ]:
242
- self.assertIn(phrase, openai_yaml)
243
-
244
- for phrase in [
245
- "Partial Readiness",
246
- "Lean core ready",
247
- "mathlib ready",
248
- "degraded mode",
249
- ]:
250
- self.assertIn(phrase, runtime_config)
251
-
252
- def test_optional_backend_language_is_adapter_first_and_not_numina_locked(self) -> None:
253
- repo_root = SKILLS_ROOT.parent
254
- texts = [
255
- (SKILLS_ROOT / "lean-formalization" / "SKILL.md").read_text(encoding="utf-8"),
256
- (SKILL_ROOT / "references" / "numina_runtime.md").read_text(encoding="utf-8"),
257
- ]
258
- readme_path = repo_root / "README.md"
259
- readme_zh_path = repo_root / "README.zh-CN.md"
260
- if readme_path.exists():
261
- texts.append(readme_path.read_text(encoding="utf-8"))
262
-
263
- for text in texts:
264
- self.assertIn("adapter-first", text)
265
- self.assertIn("Built-in recommended adapter: official Numina Lean Agent runtime", text)
266
- self.assertIn("Numina and Archon are recommended adapter candidates, not defaults or hard requirements", text)
267
- self.assertIn("Other Lean-specialist backends may be connected by the coding agent through the backend adapter checklist", text)
268
- self.assertIn("do not call any backend until deployment, readiness checks, invocation, validation, and failure triage are documented", text)
269
- self.assertNotIn("Official Numina is the only currently supported deployable backend adapter", text)
270
- self.assertNotIn("Currently supported optional backend: official Numina Lean Agent runtime", text)
271
- self.assertNotIn("supported-optional-backend-adapter", text)
272
-
273
- if readme_zh_path.exists():
274
- readme_zh = readme_zh_path.read_text(encoding="utf-8")
275
- self.assertIn("adapter-first", readme_zh)
276
- self.assertIn("当前内置推荐 adapter:official Numina Lean Agent runtime", readme_zh)
277
- self.assertIn("Numina 和 Archon 是推荐 adapter candidates,不是默认项或硬依赖", readme_zh)
278
- self.assertIn("其他 Lean-specialist backend 可由 coding agent 按 backend adapter checklist 接入", readme_zh)
279
- self.assertIn("不要调用任何 backend", readme_zh)
280
-
281
- def test_related_work_references_include_archon(self) -> None:
282
- repo_root = SKILLS_ROOT.parent
283
- readme_text = (repo_root / "README.md").read_text(encoding="utf-8")
284
- readme_zh_text = (repo_root / "README.zh-CN.md").read_text(encoding="utf-8")
285
-
286
- self.assertIn("## Related Work and Public References", readme_text)
287
- self.assertIn("- [Archon](https://github.com/frenzymath/Archon)", readme_text)
288
- self.assertIn("## 相关工作与公开参考", readme_zh_text)
289
- self.assertIn("- [Archon](https://github.com/frenzymath/Archon)", readme_zh_text)
290
-
291
- def test_release_branch_and_default_helper_commands_are_consistent(self) -> None:
292
- repo_root = SKILLS_ROOT.parent
293
- agent_text = (repo_root / ".agent.md").read_text(encoding="utf-8")
294
- example_text = (repo_root / "examples" / "lean-setup-add-zero.md").read_text(encoding="utf-8")
295
- example_zh_text = (repo_root / "examples" / "lean-setup-add-zero.zh-CN.md").read_text(encoding="utf-8")
296
- readme_text = (repo_root / "README.md").read_text(encoding="utf-8")
297
- readme_zh_text = (repo_root / "README.zh-CN.md").read_text(encoding="utf-8")
298
-
299
- self.assertIn("Default branch: `main`", agent_text)
300
- self.assertNotIn("feature/numina-runtime-delivery", agent_text)
301
- self.assertIn("Branch: main", example_text)
302
- self.assertIn("分支:main", example_zh_text)
303
- self.assertIn("Default local validation", readme_text)
304
- self.assertIn("Optional adapter setup", readme_text)
305
- self.assertIn("默认本地验证", readme_zh_text)
306
- self.assertIn("可选 adapter 设置", readme_zh_text)
307
-
308
- def test_distilled_lean_agent_capability_layer_is_documented(self) -> None:
309
- capability_map = SKILL_ROOT / "references" / "lean_agent_capability_map.md"
310
- mcp_adapter = SKILL_ROOT / "references" / "lean_lsp_mcp_adapter.md"
311
- formalization_text = (SKILLS_ROOT / "lean-formalization" / "SKILL.md").read_text(encoding="utf-8")
312
- direct_workflow = (SKILL_ROOT / "references" / "direct_lean_workflow.md").read_text(encoding="utf-8")
313
-
314
- self.assertTrue(capability_map.exists())
315
- self.assertTrue(mcp_adapter.exists())
316
- cap_text = capability_map.read_text(encoding="utf-8")
317
- mcp_text = mcp_adapter.read_text(encoding="utf-8")
318
-
319
- for phrase in [
320
- "distilled Lean-agent capability layer",
321
- "distilled default",
322
- "adapter recipe",
323
- "retrieve-before-inventing",
324
- "bounded proof attempts",
325
- "failed-route memory",
326
- "lean_lsp_mcp_adapter.md",
327
- ]:
328
- self.assertIn(phrase, cap_text)
329
-
330
- for phrase in [
331
- "Support status: `adapter_recipe`",
332
- "project-numina/lean-lsp-mcp",
333
- "LEAN_PROJECT_PATH",
334
- "lean_multi_attempt",
335
- "Never accept an MCP result as final proof",
336
- "lake build",
337
- ]:
338
- self.assertIn(phrase, mcp_text)
339
-
340
- self.assertIn("This skill must act as a distilled Lean-agent capability layer", formalization_text)
341
- self.assertIn("lean_agent_capability_map.md", formalization_text)
342
- self.assertIn("lean_lsp_mcp_adapter.md", formalization_text)
343
- self.assertIn("default distilled Lean-agent workflow", direct_workflow)
344
- self.assertIn("Retrieve before inventing", direct_workflow)
345
-
346
- def test_mcp_adapter_safety_policy_is_documented(self) -> None:
347
- mcp_text = (SKILL_ROOT / "references" / "lean_lsp_mcp_adapter.md").read_text(encoding="utf-8")
348
-
349
- for phrase in [
350
- "Default transport: `stdio` only.",
351
- "`lean_run_code` is default-deny",
352
- "Do not expose HTTP/SSE on `0.0.0.0` or a public interface.",
353
- "HTTP/SSE requires explicit approval, `127.0.0.1`, and a bearer token.",
354
- "External theorem search is local-only unless the user approves the remote service and data disclosure.",
355
- "Review any existing project-scoped `.mcp.json` before enabling it.",
356
- "Set `LEAN_PROJECT_PATH` in every MCP client configuration.",
357
- "`uvx lean-lsp-mcp` is unpinned; record the resolved version or audited commit in setup evidence.",
358
- ]:
359
- self.assertIn(phrase, mcp_text)
360
-
361
- def test_package_hygiene_scans_lean_setup_entrypoint(self) -> None:
362
- generated = SKILL_ROOT.parent / "lean-setup" / "__pycache__" / "sentinel.pyc"
363
- generated.parent.mkdir(exist_ok=True)
364
- try:
365
- generated.write_bytes(b"placeholder")
366
- hygiene = _package_hygiene()
367
- self.assertIn("lean-setup/__pycache__/sentinel.pyc", hygiene["generated_files"])
368
- finally:
369
- generated.unlink(missing_ok=True)
370
- try:
371
- generated.parent.rmdir()
372
- except OSError:
373
- pass
374
-
375
-
376
- if __name__ == "__main__":
377
- unittest.main()
@@ -1,84 +0,0 @@
1
- from __future__ import annotations
2
-
3
- import sys
4
- import tempfile
5
- import unittest
6
- from pathlib import Path
7
- from unittest.mock import patch
8
-
9
- SCRIPTS = Path(__file__).resolve().parents[1] / "scripts"
10
- sys.path.insert(0, str(SCRIPTS))
11
-
12
- from common import CANONICAL_LEAN_TOOLCHAIN, ai4math_home, expand_path, load_toml, read_config, read_env_local, write_env_local # noqa: E402
13
-
14
-
15
- class CommonConfigTests(unittest.TestCase):
16
- def test_load_toml_has_python39_fallback(self) -> None:
17
- with tempfile.TemporaryDirectory() as tmp:
18
- path = Path(tmp) / "config.toml"
19
- path.write_text(
20
- '[agent]\nmode = "coding-agent"\nbackend = "none"\n'
21
- '[lean]\nreuse_managed_workspace = true\n',
22
- encoding="utf-8",
23
- )
24
- with patch("common.tomllib", None):
25
- data = load_toml(path)
26
-
27
- self.assertEqual(data["agent"]["backend"], "none")
28
- self.assertTrue(data["lean"]["reuse_managed_workspace"])
29
-
30
- def test_expand_path_preserves_symlink_text(self) -> None:
31
- with tempfile.TemporaryDirectory() as tmp:
32
- root = Path(tmp)
33
- real = root / "real-python"
34
- link = root / "venv-python"
35
- real.touch()
36
- link.symlink_to(real)
37
-
38
- self.assertEqual(expand_path(str(link), root), link)
39
-
40
- def test_ai4math_home_honors_environment_override(self) -> None:
41
- with tempfile.TemporaryDirectory() as tmp:
42
- root = Path(tmp)
43
- custom = root / "shared-ai4math"
44
-
45
- with patch.dict("os.environ", {"AI4MATH_HOME": str(custom)}, clear=False):
46
- result = ai4math_home(root)
47
-
48
- self.assertEqual(result, custom)
49
-
50
- def test_default_config_uses_canonical_toolchain(self) -> None:
51
- with tempfile.TemporaryDirectory() as tmp:
52
- root = Path(tmp)
53
-
54
- with patch.dict("os.environ", {"AI4MATH_LEAN_TOOLCHAIN": ""}, clear=False):
55
- config = read_config(root)
56
-
57
- self.assertEqual(config["lean"]["preferred_toolchain"], CANONICAL_LEAN_TOOLCHAIN)
58
-
59
- def test_environment_can_override_canonical_toolchain(self) -> None:
60
- with tempfile.TemporaryDirectory() as tmp:
61
- root = Path(tmp)
62
- override = "leanprover/lean4:v4.26.0"
63
-
64
- with patch.dict("os.environ", {"AI4MATH_LEAN_TOOLCHAIN": override}, clear=False):
65
- config = read_config(root)
66
-
67
- self.assertEqual(config["lean"]["preferred_toolchain"], override)
68
-
69
- def test_write_env_local_updates_values_and_is_ignored(self) -> None:
70
- with tempfile.TemporaryDirectory() as tmp:
71
- root = Path(tmp)
72
-
73
- write_env_local(root, {"AI4MATH_SAMPLE_TOKEN": "secret one"})
74
- write_env_local(root, {"AI4MATH_SAMPLE_TOKEN": "secret two", "AI4MATH_SAMPLE_MODE": "local"})
75
-
76
- env = read_env_local(root)
77
- self.assertEqual(env["AI4MATH_SAMPLE_TOKEN"], "secret two")
78
- self.assertEqual(env["AI4MATH_SAMPLE_MODE"], "local")
79
- self.assertEqual((root / ".ai4math" / ".env.local").read_text().count("AI4MATH_SAMPLE_TOKEN"), 1)
80
- self.assertIn(".env.local", (root / ".ai4math" / ".gitignore").read_text())
81
-
82
-
83
- if __name__ == "__main__":
84
- unittest.main()