@louisultra/dsh-verymath 0.3.1 → 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 +80 -12
- package/README.md +14 -5
- package/README_EN.md +10 -5
- package/UPSTREAM.json +2 -2
- package/docs/capability-examples.md +581 -0
- package/docs/examples/README.md +32 -0
- package/docs/examples/bad_scan.md +10 -0
- package/docs/examples/broken-proof.lean +9 -0
- package/docs/examples/claims.md +7 -0
- package/docs/examples/knapsack.json +10 -0
- package/docs/examples/matrix.json +1 -0
- package/docs/examples/points.csv +21 -0
- package/docs/examples/qp.json +8 -0
- package/docs/examples/research-ws/project/GOALS.yaml +4 -0
- package/docs/examples/research-ws/workstreams/ws-lsa/report.md +13 -0
- package/docs/examples/research-ws/workstreams/ws-lsa/reviews/r1.json +1 -0
- package/docs/examples/research-ws/workstreams/ws-lsa/status.yaml +1 -0
- package/docs/examples/source.csv +4 -0
- package/lib/core/gates.js +1 -1
- 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 +28 -25
- package/skills/lean-formalization/SKILL.md +4 -3
- 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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"reviewer": "reviewer_independent", "approved": true}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
coordinator: main_agent
|
package/lib/core/gates.js
CHANGED
|
@@ -170,7 +170,7 @@ export async function checkGoalApproval(workspace, goalId) {
|
|
|
170
170
|
else if (!goals.some(goal => String(goal.status ?? '').toLowerCase() === 'approved')) {
|
|
171
171
|
issues.push('No approved goals are recorded.');
|
|
172
172
|
}
|
|
173
|
-
return { gate: 'goal_approval', passed: issues.length === 0, issues, details: { goalId } };
|
|
173
|
+
return { gate: 'goal_approval', passed: issues.length === 0, issues, details: goalId !== undefined ? { goalId } : {} };
|
|
174
174
|
}
|
|
175
175
|
/**
|
|
176
176
|
* Gate 2: every (selected) workstream has report.md, an independent reviewer
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* VeryMath capability plugin for DSH — package entry.
|
|
3
|
+
*
|
|
4
|
+
* The bundle mounts two modules through `cordis.patch.yml`:
|
|
5
|
+
* `./core` (the `ctx.verymath` service: glossary, paper, graph, gates, Sage)
|
|
6
|
+
* and `./tool` (the 14 model-facing tools). This module re-exports both so an
|
|
7
|
+
* `import '@louisultra/dsh-verymath'` gets the same surface as the subpaths.
|
|
8
|
+
*
|
|
9
|
+
* Without this module the package root declared in `package.json` (`main`,
|
|
10
|
+
* `types` and `exports["."]` → `lib/index.js`) is emitted by no build and
|
|
11
|
+
* importing the package by name fails, even though DSH itself loads the
|
|
12
|
+
* `./core` and `./tool` subpaths and therefore never noticed.
|
|
13
|
+
*
|
|
14
|
+
* Upstream: VeryMath AI4Math repositories (MIT). See NOTICE.md and
|
|
15
|
+
* UPSTREAM.json for per-repository provenance.
|
|
16
|
+
*
|
|
17
|
+
* @module @louisultra/dsh-verymath
|
|
18
|
+
*/
|
|
19
|
+
export * as core from './core/index.ts';
|
|
20
|
+
export * as tool from './tool/index.ts';
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* VeryMath capability plugin for DSH — package entry.
|
|
3
|
+
*
|
|
4
|
+
* The bundle mounts two modules through `cordis.patch.yml`:
|
|
5
|
+
* `./core` (the `ctx.verymath` service: glossary, paper, graph, gates, Sage)
|
|
6
|
+
* and `./tool` (the 14 model-facing tools). This module re-exports both so an
|
|
7
|
+
* `import '@louisultra/dsh-verymath'` gets the same surface as the subpaths.
|
|
8
|
+
*
|
|
9
|
+
* Without this module the package root declared in `package.json` (`main`,
|
|
10
|
+
* `types` and `exports["."]` → `lib/index.js`) is emitted by no build and
|
|
11
|
+
* importing the package by name fails, even though DSH itself loads the
|
|
12
|
+
* `./core` and `./tool` subpaths and therefore never noticed.
|
|
13
|
+
*
|
|
14
|
+
* Upstream: VeryMath AI4Math repositories (MIT). See NOTICE.md and
|
|
15
|
+
* UPSTREAM.json for per-repository provenance.
|
|
16
|
+
*
|
|
17
|
+
* @module @louisultra/dsh-verymath
|
|
18
|
+
*/
|
|
19
|
+
export * as core from "./core/index.js";
|
|
20
|
+
export * as tool from "./tool/index.js";
|
package/lib/tool/index.d.ts
CHANGED
|
@@ -17,5 +17,14 @@ export interface Config {
|
|
|
17
17
|
readonly glossaryHome?: string;
|
|
18
18
|
}
|
|
19
19
|
export declare const Config: z<Config>;
|
|
20
|
+
/**
|
|
21
|
+
* Resolve an executable name to an absolute path. Resolving in-process avoids
|
|
22
|
+
* `which`/`where`, which are not both available and which cannot see the TeX
|
|
23
|
+
* fallback directories above. On Windows the `PATHEXT` suffixes are tried.
|
|
24
|
+
* @param name - bare executable name, or a path containing a separator.
|
|
25
|
+
* @param searchDirs - directories probed for a bare name (defaults to PATH plus fallbacks).
|
|
26
|
+
* @returns the resolved absolute path, or undefined when nothing is executable.
|
|
27
|
+
*/
|
|
28
|
+
export declare function resolveExecutable(name: string, searchDirs?: readonly string[]): string | undefined;
|
|
20
29
|
/** Register the VeryMath glossary and paper tools. */
|
|
21
30
|
export declare const apply: (ctx: Context, config?: Config) => void;
|
package/lib/tool/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import z from '@deepseek-ai/schemastery';
|
|
2
2
|
import { defineTool } from '@deepseek-ai/dsh-tools';
|
|
3
3
|
import { spawn } from 'node:child_process';
|
|
4
|
-
import {
|
|
4
|
+
import { accessSync, constants } from 'node:fs';
|
|
5
|
+
import { delimiter, isAbsolute, join, resolve } from 'node:path';
|
|
5
6
|
import { VeryMathError, isVeryMathError } from '@louisultra/dsh-verymath/core';
|
|
6
7
|
import { bundledSkillsDir, checkGate, computeTopology, dependencySummary, findExcerpt, focusClosure, loadManifest, mergeBatches, parsePaperStructure, readCorpusDocWindow, renderMermaid, resolveCorpusRoot, searchSageRefs, termsFor, upsertTerms } from '@louisultra/dsh-verymath/core';
|
|
7
8
|
export const name = 'tool-verymath';
|
|
@@ -111,24 +112,67 @@ function probeCommand(executable, args, timeoutMs = 5_000) {
|
|
|
111
112
|
});
|
|
112
113
|
}
|
|
113
114
|
/**
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
*
|
|
115
|
+
* Directories a TeX distribution installs into without adding them to the
|
|
116
|
+
* inherited PATH. Desktop applications launched from Finder or the Start menu
|
|
117
|
+
* do not read the login shell profile, so MacTeX's `/Library/TeX/texbin` is
|
|
118
|
+
* commonly invisible to a bare `spawn(name)` even when the toolchain is
|
|
119
|
+
* installed. Nothing here is required: an empty result just means PATH decides.
|
|
120
|
+
*/
|
|
121
|
+
function texBinFallbackDirs() {
|
|
122
|
+
return process.platform === 'darwin' ? ['/Library/TeX/texbin'] : [];
|
|
123
|
+
}
|
|
124
|
+
/** Executable search path: the inherited PATH first, then platform fallbacks. */
|
|
125
|
+
function executableSearchDirs() {
|
|
126
|
+
const fromEnv = (process.env.PATH ?? '').split(delimiter).filter((dir) => dir.length > 0);
|
|
127
|
+
return [...new Set([...fromEnv, ...texBinFallbackDirs()])];
|
|
128
|
+
}
|
|
129
|
+
/** Whether `candidate` exists and the current user may execute it. */
|
|
130
|
+
function isExecutableFile(candidate) {
|
|
131
|
+
try {
|
|
132
|
+
accessSync(candidate, constants.X_OK);
|
|
133
|
+
return true;
|
|
134
|
+
}
|
|
135
|
+
catch {
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Resolve an executable name to an absolute path. Resolving in-process avoids
|
|
141
|
+
* `which`/`where`, which are not both available and which cannot see the TeX
|
|
142
|
+
* fallback directories above. On Windows the `PATHEXT` suffixes are tried.
|
|
143
|
+
* @param name - bare executable name, or a path containing a separator.
|
|
144
|
+
* @param searchDirs - directories probed for a bare name (defaults to PATH plus fallbacks).
|
|
145
|
+
* @returns the resolved absolute path, or undefined when nothing is executable.
|
|
146
|
+
*/
|
|
147
|
+
export function resolveExecutable(name, searchDirs = executableSearchDirs()) {
|
|
148
|
+
if (isAbsolute(name) || name.includes('/') || name.includes('\\')) {
|
|
149
|
+
return isExecutableFile(name) ? name : undefined;
|
|
150
|
+
}
|
|
151
|
+
const extensions = process.platform === 'win32'
|
|
152
|
+
? ['', ...(process.env.PATHEXT ?? '.COM;.EXE;.BAT;.CMD').split(';').filter((ext) => ext.length > 0)]
|
|
153
|
+
: [''];
|
|
154
|
+
for (const dir of searchDirs) {
|
|
155
|
+
for (const extension of extensions) {
|
|
156
|
+
const candidate = join(dir, name + extension);
|
|
157
|
+
if (isExecutableFile(candidate))
|
|
158
|
+
return candidate;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return undefined;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Probe the math-beamer TeX toolchain: latexmk and xelatex binaries (resolved on
|
|
165
|
+
* PATH, then in the distribution's own bin directory, followed by a `--version`
|
|
166
|
+
* smoke) and the forest/ctex LaTeX packages (`kpsewhich <name>.sty`, via the
|
|
167
|
+
* `kpsewhich` found the same way). Nothing is installed, compiled, or
|
|
168
|
+
* downloaded; each probe is independent so a partial toolchain reports per-piece
|
|
169
|
+
* detail (mirrors the osqp/sage probe pattern).
|
|
118
170
|
*/
|
|
119
171
|
async function probeBeamerToolchain() {
|
|
120
|
-
const binaries = [
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
const styles = [
|
|
125
|
-
{ name: 'forest' },
|
|
126
|
-
{ name: 'ctex', note: 'required by Chinese/bilingual templates only' },
|
|
127
|
-
];
|
|
128
|
-
const binaryProbes = await Promise.all(binaries.map(async ({ name }) => {
|
|
129
|
-
const which = await probeCommand('/usr/bin/which', [name]).catch(() => undefined);
|
|
130
|
-
const resolved = which !== undefined && which.exitCode === 0 ? which.stdout.trim().split('\n')[0] : undefined;
|
|
131
|
-
const executable = resolved !== undefined && resolved.length > 0 ? resolved : undefined;
|
|
172
|
+
const binaries = ['latexmk', 'xelatex'];
|
|
173
|
+
const styles = ['forest', 'ctex'];
|
|
174
|
+
const binaryProbes = await Promise.all(binaries.map(async (name) => {
|
|
175
|
+
const executable = resolveExecutable(name);
|
|
132
176
|
if (executable === undefined)
|
|
133
177
|
return { name, kind: 'binary', available: false };
|
|
134
178
|
const smoke = await probeCommand(executable, ['--version']).catch(() => undefined);
|
|
@@ -136,8 +180,13 @@ async function probeBeamerToolchain() {
|
|
|
136
180
|
? { name, kind: 'binary', available: true, executable }
|
|
137
181
|
: { name, kind: 'binary', available: false, executable };
|
|
138
182
|
}));
|
|
139
|
-
|
|
140
|
-
|
|
183
|
+
// kpsewhich ships with the distribution, so it lives in the same bin directory
|
|
184
|
+
// as the binaries and needs the same fallback lookup rather than a fixed path.
|
|
185
|
+
const kpsewhich = resolveExecutable('kpsewhich');
|
|
186
|
+
const styleProbes = await Promise.all(styles.map(async (name) => {
|
|
187
|
+
if (kpsewhich === undefined)
|
|
188
|
+
return { name, kind: 'style', available: false };
|
|
189
|
+
const probe = await probeCommand(kpsewhich, [`${name}.sty`]).catch(() => undefined);
|
|
141
190
|
const resolved = probe !== undefined && probe.exitCode === 0 ? probe.stdout.trim().split('\n')[0] : undefined;
|
|
142
191
|
return resolved !== undefined && resolved.length > 0
|
|
143
192
|
? { name, kind: 'style', available: true, executable: resolved }
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@louisultra/dsh-verymath",
|
|
3
|
-
"version": "0.3.
|
|
4
|
-
"description": "VeryMath capabilities for DSH:
|
|
3
|
+
"version": "0.3.3",
|
|
4
|
+
"description": "VeryMath capabilities for DSH: 16 bundled math skills and 14 tools covering paper reading, bilingual glossary, writing, Beamer, optimization, computation, Lean formalization, research workflows, Sage doc lookup and MATLAB. Community plugin for issue ECNU/EduWork#152.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"types": "lib/index.d.ts",
|
|
@@ -17,13 +17,17 @@
|
|
|
17
17
|
"skills/**/*",
|
|
18
18
|
"!**/__pycache__",
|
|
19
19
|
"!**/*.pyc",
|
|
20
|
+
"docs/capability-examples.md",
|
|
21
|
+
"docs/examples/**",
|
|
20
22
|
"cordis.patch.yml",
|
|
21
23
|
"README.md",
|
|
22
24
|
"README_EN.md",
|
|
23
25
|
"LICENSE",
|
|
24
26
|
"NOTICE.md",
|
|
25
27
|
"UPSTREAM.json",
|
|
26
|
-
"CHANGELOG.md"
|
|
28
|
+
"CHANGELOG.md",
|
|
29
|
+
"!**/tests",
|
|
30
|
+
"!**/test"
|
|
27
31
|
],
|
|
28
32
|
"dsh": {
|
|
29
33
|
"bundle": {
|
|
@@ -36,34 +40,33 @@
|
|
|
36
40
|
"test": "vitest run",
|
|
37
41
|
"test:runtime": "node scripts/probe-runtime.mjs",
|
|
38
42
|
"check": "npm run typecheck && npm run build && npm test && npm run test:runtime",
|
|
39
|
-
"test:upstream": "python3 -m unittest discover -s
|
|
43
|
+
"test:upstream": "python3 -m unittest discover -s ../../research/AI4Math-MathTool/skills/math-glossary/tests"
|
|
40
44
|
},
|
|
41
45
|
"engines": {
|
|
42
|
-
"node": ">=24.
|
|
46
|
+
"node": ">=24.22.1"
|
|
43
47
|
},
|
|
44
48
|
"peerDependencies": {
|
|
45
|
-
"@deepseek-ai/cordis": "
|
|
46
|
-
"@deepseek-ai/dsh-fs": ">=0.2.
|
|
47
|
-
"@deepseek-ai/dsh-llm": ">=0.2.
|
|
48
|
-
"@deepseek-ai/dsh-skill": ">=0.2.
|
|
49
|
-
"@deepseek-ai/dsh-tools": ">=0.2.
|
|
50
|
-
"@deepseek-ai/schemastery": "
|
|
49
|
+
"@deepseek-ai/cordis": ">=4.0.5 <4.2.0",
|
|
50
|
+
"@deepseek-ai/dsh-fs": ">=0.2.1-rc.5 <0.3.0-0 || 0.2.2-rc.1",
|
|
51
|
+
"@deepseek-ai/dsh-llm": ">=0.2.1-rc.5 <0.3.0-0 || 0.2.2-rc.1",
|
|
52
|
+
"@deepseek-ai/dsh-skill": ">=0.2.1-rc.5 <0.3.0-0 || 0.2.2-rc.1",
|
|
53
|
+
"@deepseek-ai/dsh-tools": ">=0.2.1-rc.5 <0.3.0-0 || 0.2.2-rc.1",
|
|
54
|
+
"@deepseek-ai/schemastery": ">=3.18.5 <3.19.0 || 3.19.0"
|
|
51
55
|
},
|
|
52
56
|
"devDependencies": {
|
|
53
|
-
"@deepseek-ai/cordis": "4.0
|
|
54
|
-
"@deepseek-ai/
|
|
55
|
-
"@deepseek-ai/
|
|
56
|
-
"@deepseek-ai/dsh-
|
|
57
|
-
"@deepseek-ai/dsh-
|
|
58
|
-
"@deepseek-ai/dsh-
|
|
59
|
-
"@deepseek-ai/dsh-
|
|
60
|
-
"@deepseek-ai/dsh-
|
|
61
|
-
"@deepseek-ai/
|
|
62
|
-
"@
|
|
63
|
-
"@types/
|
|
64
|
-
"
|
|
65
|
-
"
|
|
66
|
-
"vitest": "^4.1.8"
|
|
57
|
+
"@deepseek-ai/cordis": "4.1.0",
|
|
58
|
+
"@deepseek-ai/dsh-fs": "0.2.2-rc.1",
|
|
59
|
+
"@deepseek-ai/dsh-fs-local": "0.2.2-rc.1",
|
|
60
|
+
"@deepseek-ai/dsh-llm": "0.2.2-rc.1",
|
|
61
|
+
"@deepseek-ai/dsh-skill": "0.2.2-rc.1",
|
|
62
|
+
"@deepseek-ai/dsh-system-prompt": "0.2.2-rc.1",
|
|
63
|
+
"@deepseek-ai/dsh-tool-executor-native": "0.2.2-rc.1",
|
|
64
|
+
"@deepseek-ai/dsh-tools": "0.2.2-rc.1",
|
|
65
|
+
"@deepseek-ai/schemastery": "3.19.0",
|
|
66
|
+
"@types/js-yaml": "4.0.9",
|
|
67
|
+
"@types/node": "24.19.2",
|
|
68
|
+
"typescript": "6.0.3",
|
|
69
|
+
"vitest": "4.1.8"
|
|
67
70
|
},
|
|
68
71
|
"keywords": [
|
|
69
72
|
"dsh",
|
|
@@ -9,9 +9,10 @@ description: Use for interactive Lean 4 formal verification by coding agents wit
|
|
|
9
9
|
|
|
10
10
|
- 本技能由 `@louisultra/dsh-verymath` 插件提供;`lean-runtime/` 支撑层随包内嵌于本技能目录
|
|
11
11
|
(上游为兄弟目录;此处按 DSH 技能发现约定调整,所有 `lean-runtime/` 引用改读 `lean-runtime/`)。
|
|
12
|
-
- DSH 工具优先:`verymath_lean_detect_sorry`(无 Lean 也可用的 sorry/admit/axiom
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
- DSH 工具优先:`verymath_lean_detect_sorry`(无 Lean 也可用的 sorry/admit/axiom 纯文本检测)。
|
|
13
|
+
patch 结构安全审查(陈述漂移 + 禁用词)用随包脚本 `python3 lean-runtime/scripts/ai4m_lean.py review`
|
|
14
|
+
经 bash 执行;环境探测用 `ai4m_lean.py doctor` / `env`(同样是 bash)。本插件没有额外的 lean 审查工具。
|
|
15
|
+
- 编译验证(lake build / lake env lean)需要真实 Lean 工具链,先跑 `ai4m_lean.py doctor` 看两级 readiness;
|
|
15
16
|
**elan shim 陷阱**——`.elan/bin` 下的 lean/lake 不可跑 `--version`(会触发 GB 级隐式工具链下载),
|
|
16
17
|
版本一律从项目 `lean-toolchain` 文件读取。
|
|
17
18
|
- mathlib 缓存与共享工作区概念(`${AI4MATH_HOME:-~/.ai4math}/lean-workspace`)继续适用;
|
|
@@ -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,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()
|