@louisultra/dsh-verymath 0.3.2 → 0.3.3
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/CHANGELOG.md +45 -0
- package/README.md +8 -3
- package/README_EN.md +8 -3
- package/lib/index.d.ts +20 -0
- package/lib/index.js +20 -0
- package/lib/tool/index.d.ts +9 -0
- package/lib/tool/index.js +68 -19
- package/package.json +25 -24
- package/skills/after-ocr/tests/test_scripts.py +0 -84
- package/skills/lean-formalization/lean-runtime/tests/fixtures/after_bad.lean +0 -4
- package/skills/lean-formalization/lean-runtime/tests/fixtures/after_statement_changed.lean +0 -4
- package/skills/lean-formalization/lean-runtime/tests/fixtures/before.lean +0 -4
- package/skills/lean-formalization/lean-runtime/tests/fixtures/failure.lean +0 -7
- package/skills/lean-formalization/lean-runtime/tests/test_check_lean_project.py +0 -59
- package/skills/lean-formalization/lean-runtime/tests/test_cli.py +0 -377
- package/skills/lean-formalization/lean-runtime/tests/test_common_config.py +0 -84
- package/skills/lean-formalization/lean-runtime/tests/test_configure_lean.py +0 -138
- package/skills/lean-formalization/lean-runtime/tests/test_detect_sorry.py +0 -24
- package/skills/lean-formalization/lean-runtime/tests/test_direct_task.py +0 -69
- package/skills/lean-formalization/lean-runtime/tests/test_numina_runtime.py +0 -168
- package/skills/lean-formalization/lean-runtime/tests/test_validate_patch.py +0 -29
|
@@ -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()
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
import sys
|
|
4
|
-
import tempfile
|
|
5
|
-
import unittest
|
|
6
|
-
import os
|
|
7
|
-
from pathlib import Path
|
|
8
|
-
from unittest.mock import patch
|
|
9
|
-
|
|
10
|
-
SCRIPTS = Path(__file__).resolve().parents[1] / "scripts"
|
|
11
|
-
sys.path.insert(0, str(SCRIPTS))
|
|
12
|
-
|
|
13
|
-
from common import CANONICAL_LEAN_TOOLCHAIN, load_toml # noqa: E402
|
|
14
|
-
from configure_lean import configure, inspect_environment # noqa: E402
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
class ConfigureLeanTests(unittest.TestCase):
|
|
18
|
-
def test_existing_lean_project_is_coding_agent_ready(self) -> None:
|
|
19
|
-
with tempfile.TemporaryDirectory() as tmp:
|
|
20
|
-
root = Path(tmp)
|
|
21
|
-
target = root / "Main.lean"
|
|
22
|
-
(root / "lean-toolchain").write_text("leanprover/lean4:v4.28.0\n", encoding="utf-8")
|
|
23
|
-
(root / "lakefile.toml").write_text('name = "proj"\n', encoding="utf-8")
|
|
24
|
-
target.write_text("example : True := by trivial\n", encoding="utf-8")
|
|
25
|
-
|
|
26
|
-
with patch.dict(os.environ, {"AI4MATH_HOME": str(root / "shared-ai4math")}, clear=False):
|
|
27
|
-
os.environ["AI4MATH_LEAN_WORKSPACE"] = ""
|
|
28
|
-
result = inspect_environment(root, target=target)
|
|
29
|
-
|
|
30
|
-
self.assertTrue(result["ok"])
|
|
31
|
-
self.assertEqual(result["agent"]["mode"], "coding-agent")
|
|
32
|
-
self.assertEqual(result["agent"]["backend"], "none")
|
|
33
|
-
self.assertFalse(result["agent"]["numina_required"])
|
|
34
|
-
self.assertEqual(result["agent"]["numina_runtime"], "built_in_recipe")
|
|
35
|
-
self.assertEqual(result["missing_config"], [])
|
|
36
|
-
self.assertIn("numina", result)
|
|
37
|
-
self.assertIn("readiness", result["numina"])
|
|
38
|
-
|
|
39
|
-
def test_save_local_writes_lean_agent_config(self) -> None:
|
|
40
|
-
with tempfile.TemporaryDirectory() as tmp:
|
|
41
|
-
root = Path(tmp)
|
|
42
|
-
|
|
43
|
-
with patch.dict(os.environ, {"AI4MATH_HOME": str(root / "shared-ai4math")}, clear=False):
|
|
44
|
-
os.environ["AI4MATH_LEAN_WORKSPACE"] = ""
|
|
45
|
-
result = configure(root, save_local=True, toolchain="leanprover/lean4:v4.28.0")
|
|
46
|
-
local = load_toml(root / ".ai4math" / "lean_agent.local.toml")
|
|
47
|
-
|
|
48
|
-
self.assertFalse(result["ok"])
|
|
49
|
-
self.assertEqual(result["status"], "missing_config")
|
|
50
|
-
self.assertEqual(local["agent"]["backend"], "none")
|
|
51
|
-
self.assertEqual(local["agent"]["mode"], "coding-agent")
|
|
52
|
-
self.assertEqual(local["lean"]["preferred_toolchain"], "leanprover/lean4:v4.28.0")
|
|
53
|
-
self.assertIn("lean_agent.local.toml", (root / ".ai4math" / ".gitignore").read_text())
|
|
54
|
-
|
|
55
|
-
def test_save_local_defaults_to_canonical_toolchain(self) -> None:
|
|
56
|
-
with tempfile.TemporaryDirectory() as tmp:
|
|
57
|
-
root = Path(tmp)
|
|
58
|
-
|
|
59
|
-
with patch.dict(os.environ, {"AI4MATH_HOME": str(root / "shared-ai4math"), "AI4MATH_LEAN_TOOLCHAIN": ""}, clear=False):
|
|
60
|
-
os.environ["AI4MATH_LEAN_WORKSPACE"] = ""
|
|
61
|
-
result = configure(root, save_local=True)
|
|
62
|
-
local = load_toml(root / ".ai4math" / "lean_agent.local.toml")
|
|
63
|
-
|
|
64
|
-
self.assertFalse(result["ok"])
|
|
65
|
-
self.assertEqual(local["lean"]["preferred_toolchain"], CANONICAL_LEAN_TOOLCHAIN)
|
|
66
|
-
|
|
67
|
-
def test_create_workspace_dry_run_uses_canonical_toolchain(self) -> None:
|
|
68
|
-
with tempfile.TemporaryDirectory() as tmp:
|
|
69
|
-
root = Path(tmp)
|
|
70
|
-
|
|
71
|
-
with patch.dict(os.environ, {"AI4MATH_HOME": str(root / "shared-ai4math"), "AI4MATH_LEAN_TOOLCHAIN": ""}, clear=False), \
|
|
72
|
-
patch("configure_lean.find_tool", side_effect=lambda tool: f"/usr/bin/{tool}"):
|
|
73
|
-
os.environ["AI4MATH_LEAN_WORKSPACE"] = ""
|
|
74
|
-
result = configure(root, create_workspace=True, dry_run=True)
|
|
75
|
-
|
|
76
|
-
self.assertEqual(result["workspace_actions"][0]["command"], [
|
|
77
|
-
"/usr/bin/elan",
|
|
78
|
-
"run",
|
|
79
|
-
CANONICAL_LEAN_TOOLCHAIN,
|
|
80
|
-
"lake",
|
|
81
|
-
"new",
|
|
82
|
-
"lean_workspace",
|
|
83
|
-
"math",
|
|
84
|
-
])
|
|
85
|
-
|
|
86
|
-
def test_complete_managed_workspace_is_reused_without_rebuild(self) -> None:
|
|
87
|
-
with tempfile.TemporaryDirectory() as tmp:
|
|
88
|
-
root = Path(tmp)
|
|
89
|
-
workspace = root / "shared-ai4math" / "lean-workspace"
|
|
90
|
-
workspace.mkdir(parents=True)
|
|
91
|
-
(workspace / "lean-toolchain").write_text(f"{CANONICAL_LEAN_TOOLCHAIN}\n", encoding="utf-8")
|
|
92
|
-
(workspace / "lakefile.toml").write_text('name = "lean_workspace"\n', encoding="utf-8")
|
|
93
|
-
(workspace / "lake-manifest.json").write_text('{"packages":[]}\n', encoding="utf-8")
|
|
94
|
-
(workspace / ".lake").mkdir()
|
|
95
|
-
|
|
96
|
-
with patch.dict(os.environ, {"AI4MATH_HOME": str(root / "shared-ai4math"), "AI4MATH_LEAN_TOOLCHAIN": ""}, clear=False), \
|
|
97
|
-
patch("configure_lean.run_command") as run_command:
|
|
98
|
-
os.environ["AI4MATH_LEAN_WORKSPACE"] = ""
|
|
99
|
-
result = configure(root, create_workspace=True)
|
|
100
|
-
|
|
101
|
-
self.assertTrue(result["ok"])
|
|
102
|
-
self.assertEqual(result["workspace_actions"][0]["command"], ["reuse", str(workspace)])
|
|
103
|
-
run_command.assert_not_called()
|
|
104
|
-
|
|
105
|
-
def test_workspace_creation_failure_is_reported_as_lean_setup_failure(self) -> None:
|
|
106
|
-
with tempfile.TemporaryDirectory() as tmp:
|
|
107
|
-
root = Path(tmp)
|
|
108
|
-
|
|
109
|
-
with patch.dict(os.environ, {"AI4MATH_HOME": str(root / "shared-ai4math")}, clear=False), \
|
|
110
|
-
patch("configure_lean.find_tool", return_value="/usr/bin/lake"), \
|
|
111
|
-
patch("configure_lean.run_command", return_value={
|
|
112
|
-
"ok": False,
|
|
113
|
-
"returncode": 1,
|
|
114
|
-
"stdout": "",
|
|
115
|
-
"stderr": "download failed",
|
|
116
|
-
"command": ["/usr/bin/lake", "new", "lean_workspace", "math"],
|
|
117
|
-
}):
|
|
118
|
-
os.environ["AI4MATH_LEAN_WORKSPACE"] = ""
|
|
119
|
-
result = configure(root, create_workspace=True)
|
|
120
|
-
|
|
121
|
-
self.assertFalse(result["ok"])
|
|
122
|
-
self.assertEqual(result["status"], "lean_workspace_setup_failed")
|
|
123
|
-
self.assertIn("retry configure --create-workspace", result["recommended_next_action"])
|
|
124
|
-
|
|
125
|
-
def test_configure_setup_numina_requires_project_name(self) -> None:
|
|
126
|
-
with tempfile.TemporaryDirectory() as tmp:
|
|
127
|
-
root = Path(tmp)
|
|
128
|
-
with patch.dict(os.environ, {"AI4MATH_HOME": str(root / "shared-ai4math")}, clear=False):
|
|
129
|
-
os.environ["AI4MATH_LEAN_WORKSPACE"] = ""
|
|
130
|
-
result = configure(root, setup_numina=True, dry_run=True)
|
|
131
|
-
|
|
132
|
-
self.assertFalse(result["numina"]["ok"])
|
|
133
|
-
self.assertEqual(result["numina"]["status"], "missing_project_name")
|
|
134
|
-
self.assertIn("--project-name", result["numina"]["recommended_next_action"])
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
if __name__ == "__main__":
|
|
138
|
-
unittest.main()
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
import sys
|
|
4
|
-
import unittest
|
|
5
|
-
from pathlib import Path
|
|
6
|
-
|
|
7
|
-
SCRIPT_DIR = Path(__file__).resolve().parents[1] / "scripts"
|
|
8
|
-
sys.path.insert(0, str(SCRIPT_DIR))
|
|
9
|
-
|
|
10
|
-
from detect_sorry import scan_text # noqa: E402
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
class DetectSorryTests(unittest.TestCase):
|
|
14
|
-
def test_detects_sorry_and_ignores_line_comment(self) -> None:
|
|
15
|
-
result = scan_text("theorem t : True := by\n trivial\n-- sorry\n", source="x.lean")
|
|
16
|
-
self.assertTrue(result["ok"])
|
|
17
|
-
|
|
18
|
-
result = scan_text("theorem t : True := by\n sorry\n", source="x.lean")
|
|
19
|
-
self.assertFalse(result["ok"])
|
|
20
|
-
self.assertEqual(result["findings"][0]["kind"], "sorry")
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
if __name__ == "__main__":
|
|
24
|
-
unittest.main()
|