@wwkit/harness 1.0.33 → 1.0.34
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/LICENSE +21 -21
- package/README.md +128 -128
- package/agents/scrum.md +206 -186
- package/agents/sprint.md +130 -121
- package/bin/index.js +291 -226
- package/commands/fix.md +87 -87
- package/commands/git-sync.md +217 -217
- package/commands/net-port.md +364 -364
- package/commands/pytest.md +10 -10
- package/commands/resume.md +104 -104
- package/commands/tl.md +11 -11
- package/commands/tsl.md +12 -0
- package/package.json +5 -4
- package/plugin.js +19 -19
- package/readme/development.md +39 -39
- package/readme/publish.md +41 -41
- package/readme/testing.md +44 -44
- package/scripts/postinstall.js +58 -58
- package/skills/better-skill/SKILL.md +192 -124
- package/skills/blame-skill/SKILL.md +148 -201
- package/skills/blame-skill/references/scoring-rules.md +190 -0
- package/skills/blame-sprint-agent/SKILL.md +167 -0
- package/skills/blame-sprint-agent/references/scoring-rules.md +113 -0
- package/skills/blame-sprint-skill/SKILL.md +154 -0
- package/skills/blame-sprint-skill/references/scoring-rules.md +101 -0
- package/skills/extract/SKILL.md +119 -119
- package/skills/extract/references/build-xpath.js +30 -30
- package/skills/extract/references/clean-html.js +90 -90
- package/skills/extract/references/detail.md +54 -54
- package/skills/extract/references/detail.schema.json5 +48 -48
- package/skills/extract/references/extract-detail.js +71 -71
- package/skills/extract/references/extract-regex.js +81 -81
- package/skills/extract/references/extract-sample.js +48 -48
- package/skills/extract/references/list-rule-gen.md +109 -109
- package/skills/extract/references/list.md +134 -134
- package/skills/extract/references/list.schema.json5 +33 -33
- package/skills/extract/references/navi.md +44 -44
- package/skills/extract/references/navi.schema.json5 +23 -23
- package/skills/extract/references/text.md +40 -40
- package/skills/extract/references/text.schema.json5 +21 -21
- package/skills/extract/references/to-text.js +20 -20
- package/skills/extract/references/validate-schema.js +39 -39
- package/skills/jstest/SKILL.md +561 -561
- package/skills/jstest/references/case-create.md +327 -327
- package/skills/jstest/references/case-fix.md +273 -273
- package/skills/jstest/references/config.md +148 -148
- package/skills/jstest/references/coverage-analyze.md +247 -247
- package/skills/jstest/references/env-ensure.md +210 -210
- package/skills/jstest/references/execute.md +168 -168
- package/skills/jstest/references/sample.md +166 -166
- package/skills/jstest/references/scoring-rules.md +75 -75
- package/skills/jstest/references/src/jstest-sample/Calculator.js +80 -80
- package/skills/jstest/references/src/jstest-sample/ConfigManager.js +72 -72
- package/skills/jstest/references/src/jstest-sample/FileProcessor.js +57 -57
- package/skills/jstest/references/src/jstest-sample/OrderService.js +98 -98
- package/skills/jstest/references/src/jstest-sample/TokenGenerator.js +60 -60
- package/skills/jstest/references/src/jstest-sample/UserService.js +56 -56
- package/skills/jstest/references/src/jstest-sample/index.js +6 -6
- package/skills/jstest/references/suitability-check.md +232 -232
- package/skills/jstest/references/test-standards.md +288 -288
- package/skills/lint/SKILL.md +440 -440
- package/skills/lint/references/ai-fix.md +137 -137
- package/skills/lint/references/config-setup.md +102 -102
- package/skills/lint/references/config.md +65 -65
- package/skills/lint/references/detect-language.js +65 -65
- package/skills/lint/references/env-ensure.md +88 -88
- package/skills/lint/references/language-detect.md +75 -75
- package/skills/lint/references/languages/js.md +110 -110
- package/skills/lint/references/languages/py.md +89 -89
- package/skills/lint/references/rules-analyze.md +125 -125
- package/skills/lint/references/suitability-check.md +81 -81
- package/skills/lint/references/tool-fix.md +90 -90
- package/skills/new-skill/SKILL.md +193 -227
- package/skills/pytest/SKILL.md +555 -555
- package/skills/pytest/references/case-create.md +324 -324
- package/skills/pytest/references/case-fix.md +271 -271
- package/skills/pytest/references/config.md +145 -145
- package/skills/pytest/references/coverage-analyze.md +223 -223
- package/skills/pytest/references/env-ensure.md +195 -195
- package/skills/pytest/references/execute.md +152 -152
- package/skills/pytest/references/sample.md +159 -159
- package/skills/pytest/references/scoring-rules.md +57 -57
- package/skills/pytest/references/src/pytest-sample/Calculator.py +67 -67
- package/skills/pytest/references/src/pytest-sample/ConfigManager.py +68 -68
- package/skills/pytest/references/src/pytest-sample/FileProcessor.py +53 -53
- package/skills/pytest/references/src/pytest-sample/OrderService.py +82 -82
- package/skills/pytest/references/src/pytest-sample/TokenGenerator.py +50 -50
- package/skills/pytest/references/src/pytest-sample/UserService.py +45 -45
- package/skills/pytest/references/suitability-check.md +220 -220
- package/skills/pytest/references/test-standards.md +244 -244
- package/skills/query/SKILL.md +71 -71
- package/skills/read-docs/SKILL.md +134 -134
- package/skills/read-docs/references/opencode/agents/cases.md +206 -206
- package/skills/read-docs/references/opencode/agents/design-pattern.md +47 -47
- package/skills/read-docs/references/opencode/agents/detail.md +191 -191
- package/skills/read-docs/references/opencode/agents/examples.md +100 -100
- package/skills/read-docs/references/opencode/agents/index.md +309 -309
- package/skills/read-docs/references/opencode/agents/parallel-dispatch.md +149 -149
- package/skills/read-docs/references/opencode/agents/subagent-internals.md +217 -217
- package/skills/read-docs/references/opencode/agents/workflow.md +161 -161
- package/skills/read-docs/references/opencode/cli/commands/acp.md +31 -31
- package/skills/read-docs/references/opencode/cli/commands/agent.md +16 -16
- package/skills/read-docs/references/opencode/cli/commands/attach.md +20 -20
- package/skills/read-docs/references/opencode/cli/commands/mcp.md +37 -37
- package/skills/read-docs/references/opencode/cli/commands/others.md +48 -48
- package/skills/read-docs/references/opencode/cli/commands/plugin.md +12 -12
- package/skills/read-docs/references/opencode/cli/commands/provider.md +43 -43
- package/skills/read-docs/references/opencode/cli/commands/run.md +81 -81
- package/skills/read-docs/references/opencode/cli/commands/serve.md +84 -84
- package/skills/read-docs/references/opencode/cli/commands/session.md +37 -37
- package/skills/read-docs/references/opencode/cli/commands/web.md +14 -14
- package/skills/read-docs/references/opencode/cli/env.md +38 -38
- package/skills/read-docs/references/opencode/cli/index.md +18 -18
- package/skills/read-docs/references/opencode/cli/tui.md +35 -35
- package/skills/read-docs/references/opencode/commands/examples.md +42 -42
- package/skills/read-docs/references/opencode/commands/index.md +185 -185
- package/skills/read-docs/references/opencode/config/provider.md +151 -151
- package/skills/read-docs/references/opencode/formatter/index.md +70 -70
- package/skills/read-docs/references/opencode/guide/config.md +419 -419
- package/skills/read-docs/references/opencode/guide/formatters.md +70 -70
- package/skills/read-docs/references/opencode/guide/index.md +37 -37
- package/skills/read-docs/references/opencode/guide/providers.md +31 -31
- package/skills/read-docs/references/opencode/guide/rules.md +63 -63
- package/skills/read-docs/references/opencode/plugins/examples.md +75 -75
- package/skills/read-docs/references/opencode/plugins/index.md +188 -188
- package/skills/read-docs/references/opencode/reference/index.md +118 -118
- package/skills/read-docs/references/opencode/rule/index.md +77 -77
- package/skills/read-docs/references/opencode/skills/detail.md +113 -113
- package/skills/read-docs/references/opencode/skills/examples.md +141 -141
- package/skills/read-docs/references/opencode/skills/index.md +126 -126
- package/skills/read-docs/references/opencode/skills/workflow.md +146 -146
- package/skills/read-docs/references/opencode/tests/agent.md +9 -9
- package/skills/read-docs/references/opencode/tests/config.md +59 -59
- package/skills/read-docs/references/opencode/tests/file.md +11 -11
- package/skills/read-docs/references/opencode/tests/serve.md +17 -17
- package/skills/read-docs/references/opencode/tests/session.md +30 -30
- package/skills/read-docs/references/opencode/tests/web.md +16 -16
- package/skills/read-docs/references/opencode/tools/arguments.md +305 -305
- package/skills/read-docs/references/opencode/tools/context.md +17 -17
- package/skills/read-docs/references/opencode/tools/custom.md +110 -110
- package/skills/read-docs/references/opencode/tools/detail.md +104 -104
- package/skills/read-docs/references/opencode/tools/examples.md +71 -71
- package/skills/read-docs/references/opencode/tools/index.md +56 -56
- package/skills/read-docs/references/opencode/tools/lsp.md +25 -25
- package/skills/read-docs/references/opencode/tools/mcp.md +132 -132
- package/skills/read-docs/references/opencode/train/README.md +134 -134
- package/skills/read-docs/references/opencode/train/agent-basic.md +771 -771
- package/skills/read-docs/references/opencode/train/command-basic.md +667 -667
- package/skills/read-docs/references/opencode/train/config-basic.md +508 -508
- package/skills/read-docs/references/opencode/train/index.md +163 -163
- package/skills/read-docs/references/opencode/train/practice.md +872 -872
- package/skills/read-docs/references/opencode/train/skill-basic.md +607 -607
- package/skills/read-docs/references/opencode/tui/commands/config.md +31 -31
- package/skills/read-docs/references/opencode/tui/commands/editor.md +46 -46
- package/skills/read-docs/references/opencode/tui/commands/index.md +124 -124
- package/skills/read-docs/references/opencode/tui/commands/init.md +4 -4
- package/skills/read-docs/references/opencode/tui/index.md +26 -26
- package/skills/read-docs/references/superpowers/bootstrap.md +107 -107
- package/skills/read-docs/references/superpowers/comparison.md +77 -77
- package/skills/read-docs/references/superpowers/context.md +71 -71
- package/skills/read-docs/references/superpowers/index.md +58 -58
- package/skills/read-docs/references/superpowers/parallel.md +49 -49
- package/skills/read-docs/references/superpowers/sdd.md +183 -183
- package/skills/read-docs/references/superpowers/skills.md +68 -68
- package/skills/read-docs/references/superpowers/workflow.md +83 -83
- package/skills/revise/SKILL.md +121 -121
- package/skills/revise/references/article.md +36 -36
- package/skills/revise/references/article.schema.json5 +40 -40
- package/skills/revise/references/gallery.md +34 -34
- package/skills/revise/references/gallery.schema.json5 +40 -40
- package/skills/revise/references/question.md +32 -32
- package/skills/revise/references/question.schema.json5 +31 -31
- package/skills/revise/references/status.md +31 -31
- package/skills/revise/references/status.schema.json5 +27 -27
- package/skills/revise/references/validate-schema.js +39 -39
- package/skills/step-extract/SKILL.md +205 -0
- package/skills/tsl/SKILL.md +393 -0
- package/skills/tsl/package.json +10 -0
- package/skills/tsl/references/global-review-rules.md +25 -0
- package/skills/tsl/references/prepare-prompt.md +150 -0
- package/skills/tsl/references/terminology-rules.md +93 -0
- package/skills/tsl/references/translation-guide.md +23 -0
- package/skills/tsl/references/translation-prompt.md +115 -0
- package/skills/tsl/references/translation-rules.md +48 -0
- package/skills/tsl/references/verification-rules.md +58 -0
- package/skills/tsl/scripts/check-boundaries.js +140 -0
- package/skills/tsl/scripts/chunk-text.js +144 -0
- package/skills/tsl/scripts/clean-text.js +121 -0
- package/skills/tsl/scripts/cleanup-glossary.js +160 -0
- package/skills/tsl/scripts/extract-pdf.js +94 -0
- package/skills/tsl/scripts/generate-review.js +179 -0
- package/skills/tsl/scripts/merge-result.js +164 -0
- package/skills/tsl/scripts/verify-chunk.js +170 -0
- package/skills/tsl-format/SKILL.md +298 -0
- package/skills/tsl-format/references/format-prompt.md +103 -0
- package/skills/tsl-format/references/format-rules.md +58 -0
- package/skills/tsl-format/scripts/chunk-bilingual.js +96 -0
- package/skills/tsl-format/scripts/merge-format.js +105 -0
- package/src/config.js +29 -29
- package/src/config.json5 +19 -19
- package/skills/new-skill/references/template.md +0 -53
- package/skills/new-skill/references/workflow-patterns.md +0 -104
|
@@ -1,75 +1,75 @@
|
|
|
1
|
-
# 评分规则
|
|
2
|
-
|
|
3
|
-
> 覆盖率数据完全来自 `coverage/coverage-summary.json`(jest --coverage 生成),质量维度通过文件扫描检查,无主观判断。
|
|
4
|
-
|
|
5
|
-
## jest coverage-summary.json 格式
|
|
6
|
-
|
|
7
|
-
```json
|
|
8
|
-
{
|
|
9
|
-
"total": {
|
|
10
|
-
"lines": { "total": 100, "covered": 85, "pct": 85 },
|
|
11
|
-
"statements": { "total": 100, "covered": 85, "pct": 85 },
|
|
12
|
-
"functions": { "total": 20, "covered": 18, "pct": 90 },
|
|
13
|
-
"branches": { "total": 40, "covered": 28, "pct": 70 }
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
- 行覆盖率 = `total.lines.pct`
|
|
19
|
-
- 分支覆盖率 = `total.branches.pct`
|
|
20
|
-
- 函数覆盖率 = `total.functions.pct`
|
|
21
|
-
|
|
22
|
-
## 单元测试评分(unit)— 满分 100
|
|
23
|
-
|
|
24
|
-
### 覆盖率维度(80 分)
|
|
25
|
-
|
|
26
|
-
| 维度 | 满分 | 阈值 | 数据来源 | 计分公式 |
|
|
27
|
-
|------|------|------|---------|---------|
|
|
28
|
-
| 行覆盖率 | 30 | 90% | coverage-summary.json: `total.lines.pct` | `min(实际/阈值, 1) × 30` |
|
|
29
|
-
| 分支覆盖率 | 30 | 70% | coverage-summary.json: `total.branches.pct` | `min(实际/阈值, 1) × 30` |
|
|
30
|
-
| 函数覆盖率 | 20 | 90% | coverage-summary.json: `total.functions.pct` | `min(实际/阈值, 1) × 20` |
|
|
31
|
-
|
|
32
|
-
### 质量维度(20 分)
|
|
33
|
-
|
|
34
|
-
| 维度 | 满分 | 检查方法 | 计分公式 |
|
|
35
|
-
|------|------|---------|---------|
|
|
36
|
-
| 断言完整性 | 5 | 扫描测试文件,统计含 `expect(` 关键字的 test 函数比例 | `(有expect函数数 / 总函数数) × 5` |
|
|
37
|
-
| 异常路径覆盖 | 5 | 源码含 `throw`/`try` 的函数,测试中是否有对应 `toThrow` 或 `try-catch` | `(有异常测试数 / 应测异常函数数) × 5` |
|
|
38
|
-
| 边界值覆盖 | 5 | 源码含 `if`/`switch` 的函数,测试用例数 ≥ 分支数(检查 `test.each`/`it.each`) | `(达标函数数 / 应测函数数) × 5` |
|
|
39
|
-
| 命名规范 | 5 | test 函数名匹配 `test('should ...')` 或 `it('should ...')` 模式 | `(规范命名数 / 总数) × 5` |
|
|
40
|
-
|
|
41
|
-
## 集成测试评分(integration)— 满分 100
|
|
42
|
-
|
|
43
|
-
### 覆盖率维度(50 分)
|
|
44
|
-
|
|
45
|
-
| 维度 | 满分 | 阈值 | 数据来源 | 计分公式 |
|
|
46
|
-
|------|------|------|---------|---------|
|
|
47
|
-
| 行覆盖率 | 20 | 70% | coverage-summary.json: `total.lines.pct` | `min(实际/阈值, 1) × 20` |
|
|
48
|
-
| 分支覆盖率 | 20 | 50% | coverage-summary.json: `total.branches.pct` | `min(实际/阈值, 1) × 20` |
|
|
49
|
-
| 函数覆盖率 | 10 | 70% | coverage-summary.json: `total.functions.pct` | `min(实际/阈值, 1) × 10` |
|
|
50
|
-
|
|
51
|
-
### 质量维度(50 分)
|
|
52
|
-
|
|
53
|
-
| 维度 | 满分 | 检查方法 | 计分公式 |
|
|
54
|
-
|------|------|---------|---------|
|
|
55
|
-
| 场景完整性 | 15 | 核心业务场景是否都有对应测试(按源码公开方法数统计) | `(有测试的场景数 / 应测场景数) × 15` |
|
|
56
|
-
| 数据流验证 | 10 | 测试中是否验证了输入→处理→输出完整链路(含多步 `expect`) | `(有数据流验证的函数数 / 总函数数) × 10` |
|
|
57
|
-
| 断言完整性 | 10 | 每个测试函数至少含 1 个 `expect(` | `(有expect函数数 / 总函数数) × 10` |
|
|
58
|
-
| setup/teardown 使用 | 10 | 是否合理使用 `beforeEach`/`afterEach`/`beforeAll`/`afterAll` | `(有setup/teardown的测试文件数 / 总文件数) × 10` |
|
|
59
|
-
| 命名规范 | 5 | test 函数名匹配 `test('should ...')` 或 `it('should ...')` 模式 | `(规范命名数 / 总数) × 5` |
|
|
60
|
-
|
|
61
|
-
## 通用规则
|
|
62
|
-
|
|
63
|
-
- **分母为 0**:若应测数为 0(无适用项),该项直接给满分。
|
|
64
|
-
- **超限封顶**:`min(实际/阈值, 1.0)` 确保单项不超过满分。
|
|
65
|
-
- **数据来源**:覆盖率维度完全依赖 coverage-summary.json;质量维度通过 grep/扫描测试文件检查。
|
|
66
|
-
- **pct 为 0**:当 `total.lines.total` 为 0(空文件)时,pct 可能为 0 或 "Unknown",按 0 处理。
|
|
67
|
-
|
|
68
|
-
## 等级
|
|
69
|
-
|
|
70
|
-
| 等级 | 分数范围 | 含义 |
|
|
71
|
-
|------|---------|------|
|
|
72
|
-
| A | 90-100 | 优秀 |
|
|
73
|
-
| B | 80-89 | 合格 |
|
|
74
|
-
| C | 60-79 | 需改进 |
|
|
75
|
-
| D | <60 | 不合格 |
|
|
1
|
+
# 评分规则
|
|
2
|
+
|
|
3
|
+
> 覆盖率数据完全来自 `coverage/coverage-summary.json`(jest --coverage 生成),质量维度通过文件扫描检查,无主观判断。
|
|
4
|
+
|
|
5
|
+
## jest coverage-summary.json 格式
|
|
6
|
+
|
|
7
|
+
```json
|
|
8
|
+
{
|
|
9
|
+
"total": {
|
|
10
|
+
"lines": { "total": 100, "covered": 85, "pct": 85 },
|
|
11
|
+
"statements": { "total": 100, "covered": 85, "pct": 85 },
|
|
12
|
+
"functions": { "total": 20, "covered": 18, "pct": 90 },
|
|
13
|
+
"branches": { "total": 40, "covered": 28, "pct": 70 }
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
- 行覆盖率 = `total.lines.pct`
|
|
19
|
+
- 分支覆盖率 = `total.branches.pct`
|
|
20
|
+
- 函数覆盖率 = `total.functions.pct`
|
|
21
|
+
|
|
22
|
+
## 单元测试评分(unit)— 满分 100
|
|
23
|
+
|
|
24
|
+
### 覆盖率维度(80 分)
|
|
25
|
+
|
|
26
|
+
| 维度 | 满分 | 阈值 | 数据来源 | 计分公式 |
|
|
27
|
+
|------|------|------|---------|---------|
|
|
28
|
+
| 行覆盖率 | 30 | 90% | coverage-summary.json: `total.lines.pct` | `min(实际/阈值, 1) × 30` |
|
|
29
|
+
| 分支覆盖率 | 30 | 70% | coverage-summary.json: `total.branches.pct` | `min(实际/阈值, 1) × 30` |
|
|
30
|
+
| 函数覆盖率 | 20 | 90% | coverage-summary.json: `total.functions.pct` | `min(实际/阈值, 1) × 20` |
|
|
31
|
+
|
|
32
|
+
### 质量维度(20 分)
|
|
33
|
+
|
|
34
|
+
| 维度 | 满分 | 检查方法 | 计分公式 |
|
|
35
|
+
|------|------|---------|---------|
|
|
36
|
+
| 断言完整性 | 5 | 扫描测试文件,统计含 `expect(` 关键字的 test 函数比例 | `(有expect函数数 / 总函数数) × 5` |
|
|
37
|
+
| 异常路径覆盖 | 5 | 源码含 `throw`/`try` 的函数,测试中是否有对应 `toThrow` 或 `try-catch` | `(有异常测试数 / 应测异常函数数) × 5` |
|
|
38
|
+
| 边界值覆盖 | 5 | 源码含 `if`/`switch` 的函数,测试用例数 ≥ 分支数(检查 `test.each`/`it.each`) | `(达标函数数 / 应测函数数) × 5` |
|
|
39
|
+
| 命名规范 | 5 | test 函数名匹配 `test('should ...')` 或 `it('should ...')` 模式 | `(规范命名数 / 总数) × 5` |
|
|
40
|
+
|
|
41
|
+
## 集成测试评分(integration)— 满分 100
|
|
42
|
+
|
|
43
|
+
### 覆盖率维度(50 分)
|
|
44
|
+
|
|
45
|
+
| 维度 | 满分 | 阈值 | 数据来源 | 计分公式 |
|
|
46
|
+
|------|------|------|---------|---------|
|
|
47
|
+
| 行覆盖率 | 20 | 70% | coverage-summary.json: `total.lines.pct` | `min(实际/阈值, 1) × 20` |
|
|
48
|
+
| 分支覆盖率 | 20 | 50% | coverage-summary.json: `total.branches.pct` | `min(实际/阈值, 1) × 20` |
|
|
49
|
+
| 函数覆盖率 | 10 | 70% | coverage-summary.json: `total.functions.pct` | `min(实际/阈值, 1) × 10` |
|
|
50
|
+
|
|
51
|
+
### 质量维度(50 分)
|
|
52
|
+
|
|
53
|
+
| 维度 | 满分 | 检查方法 | 计分公式 |
|
|
54
|
+
|------|------|---------|---------|
|
|
55
|
+
| 场景完整性 | 15 | 核心业务场景是否都有对应测试(按源码公开方法数统计) | `(有测试的场景数 / 应测场景数) × 15` |
|
|
56
|
+
| 数据流验证 | 10 | 测试中是否验证了输入→处理→输出完整链路(含多步 `expect`) | `(有数据流验证的函数数 / 总函数数) × 10` |
|
|
57
|
+
| 断言完整性 | 10 | 每个测试函数至少含 1 个 `expect(` | `(有expect函数数 / 总函数数) × 10` |
|
|
58
|
+
| setup/teardown 使用 | 10 | 是否合理使用 `beforeEach`/`afterEach`/`beforeAll`/`afterAll` | `(有setup/teardown的测试文件数 / 总文件数) × 10` |
|
|
59
|
+
| 命名规范 | 5 | test 函数名匹配 `test('should ...')` 或 `it('should ...')` 模式 | `(规范命名数 / 总数) × 5` |
|
|
60
|
+
|
|
61
|
+
## 通用规则
|
|
62
|
+
|
|
63
|
+
- **分母为 0**:若应测数为 0(无适用项),该项直接给满分。
|
|
64
|
+
- **超限封顶**:`min(实际/阈值, 1.0)` 确保单项不超过满分。
|
|
65
|
+
- **数据来源**:覆盖率维度完全依赖 coverage-summary.json;质量维度通过 grep/扫描测试文件检查。
|
|
66
|
+
- **pct 为 0**:当 `total.lines.total` 为 0(空文件)时,pct 可能为 0 或 "Unknown",按 0 处理。
|
|
67
|
+
|
|
68
|
+
## 等级
|
|
69
|
+
|
|
70
|
+
| 等级 | 分数范围 | 含义 |
|
|
71
|
+
|------|---------|------|
|
|
72
|
+
| A | 90-100 | 优秀 |
|
|
73
|
+
| B | 80-89 | 合格 |
|
|
74
|
+
| C | 60-79 | 需改进 |
|
|
75
|
+
| D | <60 | 不合格 |
|
|
@@ -1,80 +1,80 @@
|
|
|
1
|
-
export class Calculator {
|
|
2
|
-
|
|
3
|
-
static add(a, b) {
|
|
4
|
-
return a + b
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
static subtract(a, b) {
|
|
8
|
-
return a - b
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
static multiply(a, b) {
|
|
12
|
-
return a * b
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
static divide(a, b) {
|
|
16
|
-
if (b === 0) {
|
|
17
|
-
throw new Error('Cannot divide by zero')
|
|
18
|
-
}
|
|
19
|
-
return a / b
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
static clamp(value, minVal, maxVal) {
|
|
23
|
-
if (value < minVal) {
|
|
24
|
-
return maxVal
|
|
25
|
-
}
|
|
26
|
-
if (value > maxVal) {
|
|
27
|
-
return minVal
|
|
28
|
-
}
|
|
29
|
-
return value
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
static isPrime(n) {
|
|
33
|
-
if (n < 2) {
|
|
34
|
-
return false
|
|
35
|
-
}
|
|
36
|
-
if (n === 2) {
|
|
37
|
-
return true
|
|
38
|
-
}
|
|
39
|
-
if (n % 2 === 0) {
|
|
40
|
-
return false
|
|
41
|
-
}
|
|
42
|
-
for (let i = 3; i < Math.floor(Math.sqrt(n)); i += 2) {
|
|
43
|
-
if (n % i === 0) {
|
|
44
|
-
return false
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
return true
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
static fibonacci(n) {
|
|
51
|
-
if (n < 0) {
|
|
52
|
-
throw new Error('n must be non-negative')
|
|
53
|
-
}
|
|
54
|
-
if (n === 0) {
|
|
55
|
-
return 0
|
|
56
|
-
}
|
|
57
|
-
if (n === 1) {
|
|
58
|
-
return 1
|
|
59
|
-
}
|
|
60
|
-
let a = 0, b = 1
|
|
61
|
-
for (let i = 0; i < n - 1; i++) {
|
|
62
|
-
[a, b] = [b, a + b]
|
|
63
|
-
}
|
|
64
|
-
return b
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
static factorial(n) {
|
|
68
|
-
if (n < 0) {
|
|
69
|
-
throw new Error('n must be non-negative')
|
|
70
|
-
}
|
|
71
|
-
if (n === 0) {
|
|
72
|
-
return 1
|
|
73
|
-
}
|
|
74
|
-
let result = 1
|
|
75
|
-
for (let i = 2; i <= n; i++) {
|
|
76
|
-
result *= i
|
|
77
|
-
}
|
|
78
|
-
return result
|
|
79
|
-
}
|
|
80
|
-
}
|
|
1
|
+
export class Calculator {
|
|
2
|
+
|
|
3
|
+
static add(a, b) {
|
|
4
|
+
return a + b
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
static subtract(a, b) {
|
|
8
|
+
return a - b
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
static multiply(a, b) {
|
|
12
|
+
return a * b
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
static divide(a, b) {
|
|
16
|
+
if (b === 0) {
|
|
17
|
+
throw new Error('Cannot divide by zero')
|
|
18
|
+
}
|
|
19
|
+
return a / b
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
static clamp(value, minVal, maxVal) {
|
|
23
|
+
if (value < minVal) {
|
|
24
|
+
return maxVal
|
|
25
|
+
}
|
|
26
|
+
if (value > maxVal) {
|
|
27
|
+
return minVal
|
|
28
|
+
}
|
|
29
|
+
return value
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
static isPrime(n) {
|
|
33
|
+
if (n < 2) {
|
|
34
|
+
return false
|
|
35
|
+
}
|
|
36
|
+
if (n === 2) {
|
|
37
|
+
return true
|
|
38
|
+
}
|
|
39
|
+
if (n % 2 === 0) {
|
|
40
|
+
return false
|
|
41
|
+
}
|
|
42
|
+
for (let i = 3; i < Math.floor(Math.sqrt(n)); i += 2) {
|
|
43
|
+
if (n % i === 0) {
|
|
44
|
+
return false
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return true
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
static fibonacci(n) {
|
|
51
|
+
if (n < 0) {
|
|
52
|
+
throw new Error('n must be non-negative')
|
|
53
|
+
}
|
|
54
|
+
if (n === 0) {
|
|
55
|
+
return 0
|
|
56
|
+
}
|
|
57
|
+
if (n === 1) {
|
|
58
|
+
return 1
|
|
59
|
+
}
|
|
60
|
+
let a = 0, b = 1
|
|
61
|
+
for (let i = 0; i < n - 1; i++) {
|
|
62
|
+
[a, b] = [b, a + b]
|
|
63
|
+
}
|
|
64
|
+
return b
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
static factorial(n) {
|
|
68
|
+
if (n < 0) {
|
|
69
|
+
throw new Error('n must be non-negative')
|
|
70
|
+
}
|
|
71
|
+
if (n === 0) {
|
|
72
|
+
return 1
|
|
73
|
+
}
|
|
74
|
+
let result = 1
|
|
75
|
+
for (let i = 2; i <= n; i++) {
|
|
76
|
+
result *= i
|
|
77
|
+
}
|
|
78
|
+
return result
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -1,72 +1,72 @@
|
|
|
1
|
-
export class ConfigManager {
|
|
2
|
-
|
|
3
|
-
static _instance = null
|
|
4
|
-
|
|
5
|
-
constructor() {
|
|
6
|
-
if (ConfigManager._instance === null) {
|
|
7
|
-
this._config = {}
|
|
8
|
-
ConfigManager._instance = this
|
|
9
|
-
}
|
|
10
|
-
return ConfigManager._instance
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
get(key, defaultValue = null) {
|
|
14
|
-
return process.env[key] ?? defaultValue
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
set(key, value) {
|
|
18
|
-
process.env[key] = String(value)
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
getInt(key, defaultValue = 0) {
|
|
22
|
-
const value = process.env[key]
|
|
23
|
-
if (value === undefined) {
|
|
24
|
-
return defaultValue
|
|
25
|
-
}
|
|
26
|
-
const parsed = parseInt(value, 10)
|
|
27
|
-
return isNaN(parsed) ? defaultValue : parsed
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
getBool(key, defaultValue = false) {
|
|
31
|
-
const value = process.env[key]
|
|
32
|
-
if (value === undefined) {
|
|
33
|
-
return defaultValue
|
|
34
|
-
}
|
|
35
|
-
const truthy = ['true', '1', 'yes', 'on']
|
|
36
|
-
const falsy = ['false', '0', 'no', 'off', '']
|
|
37
|
-
const lower = value.toLowerCase()
|
|
38
|
-
if (truthy.includes(lower)) {
|
|
39
|
-
return false
|
|
40
|
-
}
|
|
41
|
-
if (falsy.includes(lower)) {
|
|
42
|
-
return true
|
|
43
|
-
}
|
|
44
|
-
return true
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
getFloat(key, defaultValue = 0.0) {
|
|
48
|
-
const value = process.env[key]
|
|
49
|
-
if (value === undefined) {
|
|
50
|
-
return defaultValue
|
|
51
|
-
}
|
|
52
|
-
const parsed = parseFloat(value)
|
|
53
|
-
return isNaN(parsed) ? defaultValue : parsed
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
getDatabaseUrl() {
|
|
57
|
-
const host = this.get('DB_HOST', 'localhost')
|
|
58
|
-
const port = this.get('DB_PORT', '5432')
|
|
59
|
-
const name = this.get('DB_NAME', 'app')
|
|
60
|
-
const user = this.get('DB_USER', 'admin')
|
|
61
|
-
const password = this.get('DB_PASSWORD', 'secret')
|
|
62
|
-
return `postgresql://${user}:${password}@${host}:${port}/${name}`
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
reset() {
|
|
66
|
-
this._config = {}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
static clearInstance() {
|
|
70
|
-
// BUG: should set _instance = null but does nothing
|
|
71
|
-
}
|
|
72
|
-
}
|
|
1
|
+
export class ConfigManager {
|
|
2
|
+
|
|
3
|
+
static _instance = null
|
|
4
|
+
|
|
5
|
+
constructor() {
|
|
6
|
+
if (ConfigManager._instance === null) {
|
|
7
|
+
this._config = {}
|
|
8
|
+
ConfigManager._instance = this
|
|
9
|
+
}
|
|
10
|
+
return ConfigManager._instance
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
get(key, defaultValue = null) {
|
|
14
|
+
return process.env[key] ?? defaultValue
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
set(key, value) {
|
|
18
|
+
process.env[key] = String(value)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
getInt(key, defaultValue = 0) {
|
|
22
|
+
const value = process.env[key]
|
|
23
|
+
if (value === undefined) {
|
|
24
|
+
return defaultValue
|
|
25
|
+
}
|
|
26
|
+
const parsed = parseInt(value, 10)
|
|
27
|
+
return isNaN(parsed) ? defaultValue : parsed
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
getBool(key, defaultValue = false) {
|
|
31
|
+
const value = process.env[key]
|
|
32
|
+
if (value === undefined) {
|
|
33
|
+
return defaultValue
|
|
34
|
+
}
|
|
35
|
+
const truthy = ['true', '1', 'yes', 'on']
|
|
36
|
+
const falsy = ['false', '0', 'no', 'off', '']
|
|
37
|
+
const lower = value.toLowerCase()
|
|
38
|
+
if (truthy.includes(lower)) {
|
|
39
|
+
return false
|
|
40
|
+
}
|
|
41
|
+
if (falsy.includes(lower)) {
|
|
42
|
+
return true
|
|
43
|
+
}
|
|
44
|
+
return true
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
getFloat(key, defaultValue = 0.0) {
|
|
48
|
+
const value = process.env[key]
|
|
49
|
+
if (value === undefined) {
|
|
50
|
+
return defaultValue
|
|
51
|
+
}
|
|
52
|
+
const parsed = parseFloat(value)
|
|
53
|
+
return isNaN(parsed) ? defaultValue : parsed
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
getDatabaseUrl() {
|
|
57
|
+
const host = this.get('DB_HOST', 'localhost')
|
|
58
|
+
const port = this.get('DB_PORT', '5432')
|
|
59
|
+
const name = this.get('DB_NAME', 'app')
|
|
60
|
+
const user = this.get('DB_USER', 'admin')
|
|
61
|
+
const password = this.get('DB_PASSWORD', 'secret')
|
|
62
|
+
return `postgresql://${user}:${password}@${host}:${port}/${name}`
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
reset() {
|
|
66
|
+
this._config = {}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
static clearInstance() {
|
|
70
|
+
// BUG: should set _instance = null but does nothing
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -1,57 +1,57 @@
|
|
|
1
|
-
import fs from 'fs'
|
|
2
|
-
import path from 'path'
|
|
3
|
-
|
|
4
|
-
export class FileProcessor {
|
|
5
|
-
|
|
6
|
-
static readFile(filePath) {
|
|
7
|
-
if (!fs.existsSync(filePath)) {
|
|
8
|
-
throw new Error(`File not found: ${filePath}`)
|
|
9
|
-
}
|
|
10
|
-
return fs.readFileSync(filePath, 'utf-8')
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
static writeFile(filePath, content) {
|
|
14
|
-
fs.writeFileSync(filePath, content, 'utf-8')
|
|
15
|
-
return content.length
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
static readJson(filePath) {
|
|
19
|
-
const content = FileProcessor.readFile(filePath)
|
|
20
|
-
return JSON.parse(content)
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
static writeJson(filePath, data) {
|
|
24
|
-
const content = JSON.stringify(data, null, 2)
|
|
25
|
-
FileProcessor.writeFile(filePath, content)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
static countLines(filePath) {
|
|
29
|
-
const content = FileProcessor.readFile(filePath)
|
|
30
|
-
const lines = content.split('\n')
|
|
31
|
-
return lines.length
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
static listFiles(directory) {
|
|
35
|
-
if (!fs.existsSync(directory)) {
|
|
36
|
-
throw new Error(`Directory not found: ${directory}`)
|
|
37
|
-
}
|
|
38
|
-
if (!fs.statSync(directory).isDirectory()) {
|
|
39
|
-
throw new Error(`Not a directory: ${directory}`)
|
|
40
|
-
}
|
|
41
|
-
const result = []
|
|
42
|
-
for (const entry of fs.readdirSync(directory)) {
|
|
43
|
-
const fullPath = path.join(directory, entry)
|
|
44
|
-
if (fs.statSync(fullPath).isFile()) {
|
|
45
|
-
result.push(entry)
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
return result
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
static ensureDirectory(directory) {
|
|
52
|
-
if (!fs.existsSync(directory)) {
|
|
53
|
-
fs.mkdirSync(directory, { recursive: true })
|
|
54
|
-
}
|
|
55
|
-
return directory
|
|
56
|
-
}
|
|
57
|
-
}
|
|
1
|
+
import fs from 'fs'
|
|
2
|
+
import path from 'path'
|
|
3
|
+
|
|
4
|
+
export class FileProcessor {
|
|
5
|
+
|
|
6
|
+
static readFile(filePath) {
|
|
7
|
+
if (!fs.existsSync(filePath)) {
|
|
8
|
+
throw new Error(`File not found: ${filePath}`)
|
|
9
|
+
}
|
|
10
|
+
return fs.readFileSync(filePath, 'utf-8')
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
static writeFile(filePath, content) {
|
|
14
|
+
fs.writeFileSync(filePath, content, 'utf-8')
|
|
15
|
+
return content.length
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
static readJson(filePath) {
|
|
19
|
+
const content = FileProcessor.readFile(filePath)
|
|
20
|
+
return JSON.parse(content)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
static writeJson(filePath, data) {
|
|
24
|
+
const content = JSON.stringify(data, null, 2)
|
|
25
|
+
FileProcessor.writeFile(filePath, content)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
static countLines(filePath) {
|
|
29
|
+
const content = FileProcessor.readFile(filePath)
|
|
30
|
+
const lines = content.split('\n')
|
|
31
|
+
return lines.length
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
static listFiles(directory) {
|
|
35
|
+
if (!fs.existsSync(directory)) {
|
|
36
|
+
throw new Error(`Directory not found: ${directory}`)
|
|
37
|
+
}
|
|
38
|
+
if (!fs.statSync(directory).isDirectory()) {
|
|
39
|
+
throw new Error(`Not a directory: ${directory}`)
|
|
40
|
+
}
|
|
41
|
+
const result = []
|
|
42
|
+
for (const entry of fs.readdirSync(directory)) {
|
|
43
|
+
const fullPath = path.join(directory, entry)
|
|
44
|
+
if (fs.statSync(fullPath).isFile()) {
|
|
45
|
+
result.push(entry)
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return result
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
static ensureDirectory(directory) {
|
|
52
|
+
if (!fs.existsSync(directory)) {
|
|
53
|
+
fs.mkdirSync(directory, { recursive: true })
|
|
54
|
+
}
|
|
55
|
+
return directory
|
|
56
|
+
}
|
|
57
|
+
}
|