yg-team-cli 2.6.4 → 2.7.1
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/dist/cli.js +911 -21
- package/dist/cli.js.map +1 -1
- package/dist/index.js +906 -21
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -212,6 +212,12 @@ var init_utils = __esm({
|
|
|
212
212
|
static async read(file) {
|
|
213
213
|
return await fs.readFile(file, "utf-8");
|
|
214
214
|
}
|
|
215
|
+
/**
|
|
216
|
+
* 同步读取文件内容
|
|
217
|
+
*/
|
|
218
|
+
static readSync(file) {
|
|
219
|
+
return fs.readFileSync(file, "utf-8");
|
|
220
|
+
}
|
|
215
221
|
/**
|
|
216
222
|
* 写入文件内容(自动创建父目录)
|
|
217
223
|
*/
|
|
@@ -1772,27 +1778,164 @@ var ModuleManager = class {
|
|
|
1772
1778
|
} else if (module.type === "remote") {
|
|
1773
1779
|
await this.generateRemoteSpecPlaceholder(targetPath, module);
|
|
1774
1780
|
addedFiles.push(path5.relative(projectPath, targetPath));
|
|
1781
|
+
} else {
|
|
1782
|
+
await this.generateLocalSpecPlaceholder(targetPath, module);
|
|
1783
|
+
addedFiles.push(path5.relative(projectPath, targetPath));
|
|
1775
1784
|
}
|
|
1776
1785
|
}
|
|
1777
|
-
if (module.
|
|
1786
|
+
if (module.backendFragments) {
|
|
1778
1787
|
const backendJavaDir = path5.join(projectPath, "backend/src/main/java");
|
|
1779
|
-
const
|
|
1788
|
+
const useTemplates = await FileUtils.exists(path5.join(templatesDir, "modules"));
|
|
1780
1789
|
for (const fragment of module.backendFragments) {
|
|
1790
|
+
let sourcePath = null;
|
|
1791
|
+
let targetPath;
|
|
1792
|
+
let content;
|
|
1793
|
+
if (useTemplates) {
|
|
1794
|
+
sourcePath = path5.join(templatesDir, "modules", fragment.source);
|
|
1795
|
+
if (await FileUtils.exists(sourcePath)) {
|
|
1796
|
+
content = await FileUtils.read(sourcePath);
|
|
1797
|
+
}
|
|
1798
|
+
}
|
|
1799
|
+
if (!content) {
|
|
1800
|
+
content = this.generatePlaceholderCode(module, fragment);
|
|
1801
|
+
}
|
|
1802
|
+
if (fragment.target.startsWith("common/")) {
|
|
1803
|
+
const relativePath = fragment.target.replace(/^common\//, "org/yungu/common/");
|
|
1804
|
+
targetPath = path5.join(backendJavaDir, relativePath);
|
|
1805
|
+
} else if (fragment.target.startsWith("config/")) {
|
|
1806
|
+
const mainModule = this.findMainModule(projectPath);
|
|
1807
|
+
if (mainModule) {
|
|
1808
|
+
const relativePath = fragment.target.replace(/^config\//, `${mainModule}/config/`);
|
|
1809
|
+
targetPath = path5.join(backendJavaDir, relativePath);
|
|
1810
|
+
} else {
|
|
1811
|
+
targetPath = path5.join(backendJavaDir, fragment.target);
|
|
1812
|
+
}
|
|
1813
|
+
} else {
|
|
1814
|
+
targetPath = path5.join(backendJavaDir, fragment.target);
|
|
1815
|
+
}
|
|
1816
|
+
await FileUtils.ensureDir(path5.dirname(targetPath));
|
|
1817
|
+
await FileUtils.write(targetPath, content);
|
|
1818
|
+
addedFiles.push(path5.relative(projectPath, targetPath));
|
|
1819
|
+
}
|
|
1820
|
+
}
|
|
1821
|
+
if (module.frontendFragments) {
|
|
1822
|
+
const frontendSrcDir = path5.join(projectPath, "frontend/src");
|
|
1823
|
+
for (const fragment of module.frontendFragments) {
|
|
1781
1824
|
const sourcePath = path5.join(templatesDir, "modules", fragment.source);
|
|
1782
|
-
const targetPath = path5.join(
|
|
1825
|
+
const targetPath = path5.join(frontendSrcDir, fragment.target);
|
|
1783
1826
|
if (await FileUtils.exists(sourcePath)) {
|
|
1784
|
-
await FileUtils.
|
|
1785
|
-
let content = await FileUtils.read(sourcePath);
|
|
1786
|
-
const targetPackage = "org.yungu.common." + path5.dirname(fragment.target).replace(/\//g, ".");
|
|
1787
|
-
content = content.replace(/^package\s+[^;]+;/m, `package ${targetPackage};`);
|
|
1788
|
-
await FileUtils.write(targetPath, content);
|
|
1827
|
+
await FileUtils.copy(sourcePath, targetPath);
|
|
1789
1828
|
addedFiles.push(path5.relative(projectPath, targetPath));
|
|
1790
1829
|
}
|
|
1791
1830
|
}
|
|
1792
|
-
} else if (module.type === "remote") {
|
|
1793
1831
|
}
|
|
1794
1832
|
return addedFiles;
|
|
1795
1833
|
}
|
|
1834
|
+
/**
|
|
1835
|
+
* 查找主模块名 (第一个 service 类型的模块)
|
|
1836
|
+
*/
|
|
1837
|
+
static findMainModule(projectPath) {
|
|
1838
|
+
const settingsPath = path5.join(projectPath, "backend/settings.gradle");
|
|
1839
|
+
const content = FileUtils.readSync(settingsPath);
|
|
1840
|
+
const matches = content.match(/include\s+'([^']+)'/g);
|
|
1841
|
+
if (matches) {
|
|
1842
|
+
for (const match of matches) {
|
|
1843
|
+
const moduleName = match.replace(/include\s+'/, "").replace(/'/, "");
|
|
1844
|
+
if (moduleName !== "common") {
|
|
1845
|
+
return moduleName;
|
|
1846
|
+
}
|
|
1847
|
+
}
|
|
1848
|
+
}
|
|
1849
|
+
return null;
|
|
1850
|
+
}
|
|
1851
|
+
/**
|
|
1852
|
+
* 生成占位符代码
|
|
1853
|
+
*/
|
|
1854
|
+
static generatePlaceholderCode(module, fragment) {
|
|
1855
|
+
const targetPackage = path5.dirname(fragment.target).replace(/\//g, ".");
|
|
1856
|
+
const className = path5.basename(fragment.target, ".java");
|
|
1857
|
+
const moduleName = module.name;
|
|
1858
|
+
const moduleId = module.id;
|
|
1859
|
+
return `package ${targetPackage};
|
|
1860
|
+
|
|
1861
|
+
import lombok.extern.slf4j.Slf4j;
|
|
1862
|
+
|
|
1863
|
+
/**
|
|
1864
|
+
* ${moduleName} - \u5360\u4F4D\u7B26
|
|
1865
|
+
*
|
|
1866
|
+
* \u6B64\u6587\u4EF6\u7531 team-cli \u81EA\u52A8\u751F\u6210\u3002
|
|
1867
|
+
* \u6A21\u5757 ID: ${moduleId}
|
|
1868
|
+
*
|
|
1869
|
+
* \u4F7F\u7528\u8BF4\u660E:
|
|
1870
|
+
* 1. \u8BF7\u6839\u636E\u9879\u76EE\u5B9E\u9645\u9700\u6C42\u5B8C\u5584\u6B64\u6587\u4EF6
|
|
1871
|
+
* 2. \u6216\u53C2\u8003 docs/specs/${moduleId}/spec.md \u83B7\u53D6\u8BE6\u7EC6\u9700\u6C42
|
|
1872
|
+
*/
|
|
1873
|
+
@Slf4j
|
|
1874
|
+
public class ${className} {
|
|
1875
|
+
|
|
1876
|
+
/**
|
|
1877
|
+
* TODO: \u5B9E\u73B0 ${moduleName} \u529F\u80FD
|
|
1878
|
+
*/
|
|
1879
|
+
public void execute() {
|
|
1880
|
+
log.info("${className} - \u6267\u884C\u4E2D...");
|
|
1881
|
+
// \u5728\u6B64\u5B9E\u73B0\u5177\u4F53\u903B\u8F91
|
|
1882
|
+
}
|
|
1883
|
+
}
|
|
1884
|
+
`;
|
|
1885
|
+
}
|
|
1886
|
+
/**
|
|
1887
|
+
* 生成本地模块的 Spec 占位符
|
|
1888
|
+
*/
|
|
1889
|
+
static async generateLocalSpecPlaceholder(targetPath, module) {
|
|
1890
|
+
const content = `# ${module.name}
|
|
1891
|
+
|
|
1892
|
+
## \u529F\u80FD\u6982\u8FF0
|
|
1893
|
+
${module.description}
|
|
1894
|
+
|
|
1895
|
+
## \u4F7F\u7528\u8BF4\u660E
|
|
1896
|
+
|
|
1897
|
+
\u6B64\u6A21\u5757\u4E3A\u4E91\u8C37\u901A\u7528\u6A21\u5757\u7684\u5360\u4F4D\u7B26\u914D\u7F6E\u3002
|
|
1898
|
+
|
|
1899
|
+
### \u914D\u7F6E\u6B65\u9AA4
|
|
1900
|
+
|
|
1901
|
+
1. **\u6DFB\u52A0\u4F9D\u8D56**
|
|
1902
|
+
|
|
1903
|
+
\u5728 \`backend/build.gradle\` \u4E2D\u6DFB\u52A0:
|
|
1904
|
+
|
|
1905
|
+
\`\`\`groovy
|
|
1906
|
+
${module.dependencies ? module.dependencies.map((d) => `implementation '${d}'`).join("\n") : ""}
|
|
1907
|
+
\`\`\`
|
|
1908
|
+
|
|
1909
|
+
2. **\u914D\u7F6E\u6587\u4EF6**
|
|
1910
|
+
|
|
1911
|
+
\u6839\u636E\u9700\u6C42\u914D\u7F6E application.yml:
|
|
1912
|
+
|
|
1913
|
+
\`\`\`yaml
|
|
1914
|
+
# ${module.name} \u914D\u7F6E
|
|
1915
|
+
\`\`\`
|
|
1916
|
+
|
|
1917
|
+
3. **\u5BFC\u5165\u914D\u7F6E\u7C7B**
|
|
1918
|
+
|
|
1919
|
+
\u5728\u4E3B Application \u7C7B\u4E0A\u6DFB\u52A0\u6CE8\u89E3:
|
|
1920
|
+
|
|
1921
|
+
\`\`\`java
|
|
1922
|
+
@SpringBootApplication
|
|
1923
|
+
@ComponentScan("${module.id}")
|
|
1924
|
+
public class Application {
|
|
1925
|
+
// ...
|
|
1926
|
+
}
|
|
1927
|
+
\`\`\`
|
|
1928
|
+
|
|
1929
|
+
4. **\u53C2\u8003\u6587\u6863**
|
|
1930
|
+
|
|
1931
|
+
\u67E5\u770B docs/specs/${module.id}/spec.md \u83B7\u53D6\u8BE6\u7EC6\u5B9E\u73B0\u8BF4\u660E\u3002
|
|
1932
|
+
|
|
1933
|
+
## \u4F9D\u8D56\u5173\u7CFB
|
|
1934
|
+
|
|
1935
|
+
${module.requires ? `\u9700\u8981\u5148\u542F\u7528: ${module.requires.join(", ")}` : "\u65E0\u524D\u7F6E\u4F9D\u8D56"}
|
|
1936
|
+
`;
|
|
1937
|
+
await FileUtils.write(targetPath, content);
|
|
1938
|
+
}
|
|
1796
1939
|
/**
|
|
1797
1940
|
* 生成远程模块的 Spec 占位符
|
|
1798
1941
|
*/
|
|
@@ -4510,9 +4653,30 @@ Generate a complete Spec document with the following sections:
|
|
|
4510
4653
|
\u5217\u51FA\u9700\u8981\u7684\u540E\u7AEF\u6A21\u5757\u7ED3\u6784
|
|
4511
4654
|
|
|
4512
4655
|
## \u9A8C\u6536\u6807\u51C6
|
|
4513
|
-
|
|
4514
|
-
|
|
4515
|
-
|
|
4656
|
+
|
|
4657
|
+
### BDD \u573A\u666F\uFF08\u884C\u4E3A\u9A71\u52A8\u89C6\u89D2\uFF09
|
|
4658
|
+
|
|
4659
|
+
\u8BF7\u4E3A\u6BCF\u4E2A\u4E3B\u8981\u529F\u80FD\u70B9\u751F\u6210 2-4 \u4E2A BDD \u573A\u666F\uFF0C\u683C\u5F0F\u5982\u4E0B\uFF1A
|
|
4660
|
+
|
|
4661
|
+
\`\`\`markdown
|
|
4662
|
+
#### \u573A\u666F 1: [\u573A\u666F\u540D\u79F0]
|
|
4663
|
+
**\u4F5C\u4E3A** [\u7528\u6237\u89D2\u8272]
|
|
4664
|
+
**\u6211\u5E0C\u671B** [\u5B8C\u6210\u7684\u52A8\u4F5C]
|
|
4665
|
+
**\u4EE5\u4FBF** [\u5B9E\u73B0\u7684\u4EF7\u503C]
|
|
4666
|
+
|
|
4667
|
+
- [GIVEN] \u524D\u7F6E\u6761\u4EF6\u63CF\u8FF0
|
|
4668
|
+
- [WHEN] \u7528\u6237\u52A8\u4F5C\u6216 API \u8C03\u7528
|
|
4669
|
+
- [THEN] \u9884\u671F\u7ED3\u679C
|
|
4670
|
+
|
|
4671
|
+
**\u72B6\u6001\u6D41\u8F6C**:
|
|
4672
|
+
- \`\u672A\u767B\u5F55\` \u2192 \`\u767B\u5F55\u4E2D\` \u2192 \`\u5DF2\u767B\u5F55\`
|
|
4673
|
+
\`\`\`
|
|
4674
|
+
|
|
4675
|
+
\u8981\u6C42\uFF1A
|
|
4676
|
+
1. \u6BCF\u4E2A\u573A\u666F\u8986\u76D6\u4E00\u4E2A\u5B8C\u6574\u7684\u7528\u6237\u6D41\u7A0B
|
|
4677
|
+
2. Given/When/Then \u7ED3\u6784\u6E05\u6670
|
|
4678
|
+
3. \u72B6\u6001\u6D41\u8F6C\u6807\u6CE8\u660E\u786E
|
|
4679
|
+
4. \u573A\u666F\u6570\u91CF\u6839\u636E\u529F\u80FD\u590D\u6742\u5EA6\u51B3\u5B9A\uFF08\u7B80\u5355\u529F\u80FD 2-3 \u4E2A\uFF0C\u590D\u6742\u529F\u80FD 4-6 \u4E2A\uFF09
|
|
4516
4680
|
|
|
4517
4681
|
## \u91CC\u7A0B\u7891 (Milestones)
|
|
4518
4682
|
> \u6CE8: \u4F7F\u7528 \`team-cli breakdown ${featureSlug}.md\` \u62C6\u5206\u6B64 spec \u4E3A milestones \u548C todos
|
|
@@ -4527,6 +4691,7 @@ IMPORTANT:
|
|
|
4527
4691
|
3. Priority should be justified based on feature importance
|
|
4528
4692
|
4. Work estimation should be realistic
|
|
4529
4693
|
5. Extract key requirements from the PRD accurately
|
|
4694
|
+
6. BDD scenarios should cover all user flows and edge cases
|
|
4530
4695
|
`;
|
|
4531
4696
|
}
|
|
4532
4697
|
function buildSplitPrdPrompt(prdContent, screenshots, demoRepos) {
|
|
@@ -4938,7 +5103,322 @@ init_logger();
|
|
|
4938
5103
|
import { Command as Command7 } from "commander";
|
|
4939
5104
|
import inquirer6 from "inquirer";
|
|
4940
5105
|
import path12 from "path";
|
|
4941
|
-
|
|
5106
|
+
|
|
5107
|
+
// src/lib/bdd-parser.ts
|
|
5108
|
+
init_esm_shims();
|
|
5109
|
+
var BDDParser = class {
|
|
5110
|
+
static SCENARIO_PATTERN = /^####?\s*场景\s*(\d+)[::]?\s*(.+)$/;
|
|
5111
|
+
static GIVEN_PATTERN = /^\*?\s*-\s*\[GIVEN\]\s*(.+)$/;
|
|
5112
|
+
static WHEN_PATTERN = /^\*?\s*-\s*\[WHEN\]\s*(.+)$/;
|
|
5113
|
+
static THEN_PATTERN = /^\*?\s*-\s*\[THEN\]\s*(.+)$/;
|
|
5114
|
+
static STATE_PATTERN = /^\*?\s*-\s*\[STATE\]\s*(.+)$/;
|
|
5115
|
+
static ROLE_PATTERN = /^\*\*作为\*\*[::]?\s*(.+)$/i;
|
|
5116
|
+
static WANT_PATTERN = /^\*\*我希望\*\*[::]?\s*(.+)$/i;
|
|
5117
|
+
static SO_THAT_PATTERN = /^\*\*以便\*\*[::]?\s*(.+)$/i;
|
|
5118
|
+
static TRANSITION_PATTERN = /`([^`]+)`\s*→\s*`([^`]+)`/;
|
|
5119
|
+
/**
|
|
5120
|
+
* 解析 BDD 场景
|
|
5121
|
+
*/
|
|
5122
|
+
static parseScenarios(content) {
|
|
5123
|
+
const scenarios = [];
|
|
5124
|
+
const lines = content.split("\n");
|
|
5125
|
+
let currentScenario = null;
|
|
5126
|
+
let section = null;
|
|
5127
|
+
let scenarioOrder = 0;
|
|
5128
|
+
for (let i = 0; i < lines.length; i++) {
|
|
5129
|
+
const line = lines[i].trim();
|
|
5130
|
+
const lineNum = i + 1;
|
|
5131
|
+
const scenarioMatch = line.match(this.SCENARIO_PATTERN);
|
|
5132
|
+
if (scenarioMatch) {
|
|
5133
|
+
if (currentScenario && currentScenario.title) {
|
|
5134
|
+
scenarios.push(this.finalizeScenario(currentScenario, scenarioOrder));
|
|
5135
|
+
}
|
|
5136
|
+
scenarioOrder++;
|
|
5137
|
+
currentScenario = {
|
|
5138
|
+
id: `scenario-${scenarioOrder}`,
|
|
5139
|
+
title: scenarioMatch[2].trim(),
|
|
5140
|
+
order: scenarioOrder,
|
|
5141
|
+
given: [],
|
|
5142
|
+
when: [],
|
|
5143
|
+
then: [],
|
|
5144
|
+
stateTransitions: [],
|
|
5145
|
+
relatedApis: [],
|
|
5146
|
+
relatedFeatures: []
|
|
5147
|
+
};
|
|
5148
|
+
section = "title";
|
|
5149
|
+
continue;
|
|
5150
|
+
}
|
|
5151
|
+
if (line.match(/^\*\*作为\*\*[::]?/i)) {
|
|
5152
|
+
const match = line.match(this.ROLE_PATTERN);
|
|
5153
|
+
if (match && currentScenario) {
|
|
5154
|
+
currentScenario.asA = match[1].trim();
|
|
5155
|
+
}
|
|
5156
|
+
continue;
|
|
5157
|
+
}
|
|
5158
|
+
if (line.match(/^\*\*我希望\*\*[::]?/i)) {
|
|
5159
|
+
const match = line.match(this.WANT_PATTERN);
|
|
5160
|
+
if (match && currentScenario) {
|
|
5161
|
+
currentScenario.iWant = match[1].trim();
|
|
5162
|
+
}
|
|
5163
|
+
continue;
|
|
5164
|
+
}
|
|
5165
|
+
if (line.match(/^\*\*以便\*\*[::]?/i)) {
|
|
5166
|
+
const match = line.match(this.SO_THAT_PATTERN);
|
|
5167
|
+
if (match && currentScenario) {
|
|
5168
|
+
currentScenario.soThat = match[1].trim();
|
|
5169
|
+
}
|
|
5170
|
+
continue;
|
|
5171
|
+
}
|
|
5172
|
+
const givenMatch = line.match(this.GIVEN_PATTERN);
|
|
5173
|
+
const whenMatch = line.match(this.WHEN_PATTERN);
|
|
5174
|
+
const thenMatch = line.match(this.THEN_PATTERN);
|
|
5175
|
+
const stateMatch = line.match(this.STATE_PATTERN);
|
|
5176
|
+
if (givenMatch && currentScenario) {
|
|
5177
|
+
currentScenario.given.push({
|
|
5178
|
+
description: givenMatch[1].trim(),
|
|
5179
|
+
type: this.detectConditionType(givenMatch[1]),
|
|
5180
|
+
validation: this.extractValidation(givenMatch[1])
|
|
5181
|
+
});
|
|
5182
|
+
section = "given";
|
|
5183
|
+
continue;
|
|
5184
|
+
}
|
|
5185
|
+
if (whenMatch && currentScenario) {
|
|
5186
|
+
const action = this.parseAction(whenMatch[1].trim());
|
|
5187
|
+
currentScenario.when.push(action);
|
|
5188
|
+
if (action.api) {
|
|
5189
|
+
currentScenario.relatedApis.push(action.api);
|
|
5190
|
+
}
|
|
5191
|
+
section = "when";
|
|
5192
|
+
continue;
|
|
5193
|
+
}
|
|
5194
|
+
if (thenMatch && currentScenario) {
|
|
5195
|
+
currentScenario.then.push({
|
|
5196
|
+
description: thenMatch[1].trim(),
|
|
5197
|
+
type: this.detectResultType(thenMatch[1]),
|
|
5198
|
+
expectedBehavior: this.extractExpectedBehavior(thenMatch[1])
|
|
5199
|
+
});
|
|
5200
|
+
section = "then";
|
|
5201
|
+
continue;
|
|
5202
|
+
}
|
|
5203
|
+
if (stateMatch && currentScenario) {
|
|
5204
|
+
const transition = this.parseStateTransition(stateMatch[1].trim());
|
|
5205
|
+
if (transition) {
|
|
5206
|
+
currentScenario.stateTransitions.push(transition);
|
|
5207
|
+
}
|
|
5208
|
+
section = "state";
|
|
5209
|
+
continue;
|
|
5210
|
+
}
|
|
5211
|
+
if (line && !line.startsWith("#") && !line.startsWith("---") && currentScenario) {
|
|
5212
|
+
const trimmed = line.replace(/^[\s-]*/, "");
|
|
5213
|
+
if (trimmed && section === "given" && currentScenario.given.length > 0) {
|
|
5214
|
+
currentScenario.given[currentScenario.given.length - 1].description += " " + trimmed;
|
|
5215
|
+
} else if (trimmed && section === "when" && currentScenario.when.length > 0) {
|
|
5216
|
+
currentScenario.when[currentScenario.when.length - 1].description += " " + trimmed;
|
|
5217
|
+
} else if (trimmed && section === "then" && currentScenario.then.length > 0) {
|
|
5218
|
+
currentScenario.then[currentScenario.then.length - 1].description += " " + trimmed;
|
|
5219
|
+
}
|
|
5220
|
+
}
|
|
5221
|
+
}
|
|
5222
|
+
if (currentScenario && currentScenario.title) {
|
|
5223
|
+
scenarios.push(this.finalizeScenario(currentScenario, scenarioOrder));
|
|
5224
|
+
}
|
|
5225
|
+
return scenarios;
|
|
5226
|
+
}
|
|
5227
|
+
/**
|
|
5228
|
+
* 从验收标准部分提取 BDD 场景
|
|
5229
|
+
*/
|
|
5230
|
+
static parseFromAcceptanceSection(acceptanceSection) {
|
|
5231
|
+
const bddSectionMatch = acceptanceSection.match(
|
|
5232
|
+
/(?:###\s*BDD[^\n]*|###\s*场景|###\s*行为驱动)[^]*(?=##|$)/i
|
|
5233
|
+
);
|
|
5234
|
+
if (bddSectionMatch) {
|
|
5235
|
+
return this.parseScenarios(bddSectionMatch[0]);
|
|
5236
|
+
}
|
|
5237
|
+
return this.convertFromLegacyCriteria(acceptanceSection);
|
|
5238
|
+
}
|
|
5239
|
+
/**
|
|
5240
|
+
* 从传统验收标准转换
|
|
5241
|
+
*/
|
|
5242
|
+
static convertFromLegacyCriteria(criteria) {
|
|
5243
|
+
const scenarios = [];
|
|
5244
|
+
const lines = criteria.split("\n");
|
|
5245
|
+
let scenarioId = 0;
|
|
5246
|
+
let currentScenario = null;
|
|
5247
|
+
for (const line of lines) {
|
|
5248
|
+
const criteriaMatch = line.match(/^-\s*\[\s*\]\s*(.+)$/);
|
|
5249
|
+
if (criteriaMatch) {
|
|
5250
|
+
if (!currentScenario) {
|
|
5251
|
+
scenarioId++;
|
|
5252
|
+
currentScenario = {
|
|
5253
|
+
id: `scenario-${scenarioId}`,
|
|
5254
|
+
title: `\u573A\u666F ${scenarioId}`,
|
|
5255
|
+
order: scenarioId,
|
|
5256
|
+
given: [],
|
|
5257
|
+
when: [],
|
|
5258
|
+
then: [],
|
|
5259
|
+
stateTransitions: []
|
|
5260
|
+
};
|
|
5261
|
+
}
|
|
5262
|
+
const text = criteriaMatch[1];
|
|
5263
|
+
const normalized = text.toLowerCase();
|
|
5264
|
+
if (normalized.includes("\u5DF2") || normalized.includes("\u6709") || normalized.includes("\u5B58\u5728")) {
|
|
5265
|
+
currentScenario.given.push({
|
|
5266
|
+
description: text,
|
|
5267
|
+
type: "data",
|
|
5268
|
+
validation: "\u68C0\u67E5\u6570\u636E\u5B58\u5728"
|
|
5269
|
+
});
|
|
5270
|
+
} else if (normalized.includes("\u5F53") || normalized.includes("\u63D0\u4EA4") || normalized.includes("\u70B9\u51FB")) {
|
|
5271
|
+
currentScenario.when.push({
|
|
5272
|
+
description: text,
|
|
5273
|
+
trigger: "user"
|
|
5274
|
+
});
|
|
5275
|
+
} else if (normalized.includes("\u5E94") || normalized.includes("\u8FD4\u56DE") || normalized.includes("\u663E\u793A")) {
|
|
5276
|
+
currentScenario.then.push({
|
|
5277
|
+
description: text,
|
|
5278
|
+
type: "response",
|
|
5279
|
+
expectedBehavior: text
|
|
5280
|
+
});
|
|
5281
|
+
}
|
|
5282
|
+
} else if (line.trim() === "" && currentScenario) {
|
|
5283
|
+
scenarios.push(this.finalizeScenario(currentScenario, scenarioId));
|
|
5284
|
+
currentScenario = null;
|
|
5285
|
+
}
|
|
5286
|
+
}
|
|
5287
|
+
if (currentScenario && currentScenario.title) {
|
|
5288
|
+
scenarios.push(this.finalizeScenario(currentScenario, scenarioId));
|
|
5289
|
+
}
|
|
5290
|
+
return scenarios;
|
|
5291
|
+
}
|
|
5292
|
+
/**
|
|
5293
|
+
* 检测条件类型
|
|
5294
|
+
*/
|
|
5295
|
+
static detectConditionType(description) {
|
|
5296
|
+
const lower = description.toLowerCase();
|
|
5297
|
+
if (lower.includes("\u6570\u636E") || lower.includes("\u8BB0\u5F55") || lower.includes("\u8868")) return "data";
|
|
5298
|
+
if (lower.includes("\u72B6\u6001") || lower.includes("\u5DF2") || lower.includes("\u672A")) return "state";
|
|
5299
|
+
return "user";
|
|
5300
|
+
}
|
|
5301
|
+
/**
|
|
5302
|
+
* 检测结果类型
|
|
5303
|
+
*/
|
|
5304
|
+
static detectResultType(description) {
|
|
5305
|
+
const lower = description.toLowerCase();
|
|
5306
|
+
if (lower.includes("\u8FD4\u56DE") || lower.includes("\u54CD\u5E94") || lower.includes("\u72B6\u6001\u7801")) return "response";
|
|
5307
|
+
if (lower.includes("\u72B6\u6001") || lower.includes("\u53D8\u6210") || lower.includes("\u66F4\u65B0")) return "state";
|
|
5308
|
+
if (lower.includes("\u663E\u793A") || lower.includes("\u9875\u9762") || lower.includes("\u754C\u9762")) return "ui";
|
|
5309
|
+
return "data";
|
|
5310
|
+
}
|
|
5311
|
+
/**
|
|
5312
|
+
* 提取验证方式
|
|
5313
|
+
*/
|
|
5314
|
+
static extractValidation(description) {
|
|
5315
|
+
const match = description.match(/\(([^)]+)\)/);
|
|
5316
|
+
return match ? match[1] : "\u68C0\u67E5\u6761\u4EF6\u6EE1\u8DB3";
|
|
5317
|
+
}
|
|
5318
|
+
/**
|
|
5319
|
+
* 提取预期行为
|
|
5320
|
+
*/
|
|
5321
|
+
static extractExpectedBehavior(description) {
|
|
5322
|
+
return description.replace(/^(应该|应|应当|应该会|会)/, "").trim();
|
|
5323
|
+
}
|
|
5324
|
+
/**
|
|
5325
|
+
* 解析动作
|
|
5326
|
+
*/
|
|
5327
|
+
static parseAction(description) {
|
|
5328
|
+
const apiMatch = description.match(/(?:API|POST|GET|PUT|DELETE|PATCH)\s*[::]?\s*`([^`]+)`/i);
|
|
5329
|
+
const uiMatch = description.match(/(?:点击|输入|选择|提交|拖拽)[::]?\s*(.+)/);
|
|
5330
|
+
return {
|
|
5331
|
+
description,
|
|
5332
|
+
api: apiMatch?.[1],
|
|
5333
|
+
uiAction: uiMatch?.[1],
|
|
5334
|
+
trigger: apiMatch ? "api" : "user"
|
|
5335
|
+
};
|
|
5336
|
+
}
|
|
5337
|
+
/**
|
|
5338
|
+
* 解析状态流转
|
|
5339
|
+
*/
|
|
5340
|
+
static parseStateTransition(description) {
|
|
5341
|
+
const arrowMatch = description.match(/`([^`]+)`\s*(?:→|->)\s*`([^`]+)`/);
|
|
5342
|
+
if (arrowMatch) {
|
|
5343
|
+
return {
|
|
5344
|
+
from: arrowMatch[1],
|
|
5345
|
+
trigger: description.split(/→|->/)[1]?.trim() || "\u5B8C\u6210",
|
|
5346
|
+
to: arrowMatch[2]
|
|
5347
|
+
};
|
|
5348
|
+
}
|
|
5349
|
+
const fromMatch = description.match(/(?:从|起始于|开始于)\s*`([^`]+)`/);
|
|
5350
|
+
const toMatch = description.match(/(?:到|变为|结束于)\s*`([^`]+)`/);
|
|
5351
|
+
const triggerMatch = description.match(/通过|当|使用\s*[::]?\s*(.+?)(?:,|$)/);
|
|
5352
|
+
if (fromMatch && toMatch) {
|
|
5353
|
+
return {
|
|
5354
|
+
from: fromMatch[1],
|
|
5355
|
+
trigger: triggerMatch?.[1] || "\u5B8C\u6210",
|
|
5356
|
+
to: toMatch[1]
|
|
5357
|
+
};
|
|
5358
|
+
}
|
|
5359
|
+
return null;
|
|
5360
|
+
}
|
|
5361
|
+
/**
|
|
5362
|
+
* 完成场景构建
|
|
5363
|
+
*/
|
|
5364
|
+
static finalizeScenario(scenario, order) {
|
|
5365
|
+
return {
|
|
5366
|
+
id: scenario.id || `scenario-${order}`,
|
|
5367
|
+
title: scenario.title || `\u573A\u666F ${order}`,
|
|
5368
|
+
order: scenario.order || order,
|
|
5369
|
+
asA: scenario.asA || "\u7528\u6237",
|
|
5370
|
+
iWant: scenario.iWant || "",
|
|
5371
|
+
soThat: scenario.soThat || "",
|
|
5372
|
+
given: scenario.given || [],
|
|
5373
|
+
when: scenario.when || [],
|
|
5374
|
+
then: scenario.then || [],
|
|
5375
|
+
stateTransitions: scenario.stateTransitions || [],
|
|
5376
|
+
relatedApis: scenario.relatedApis || [],
|
|
5377
|
+
relatedFeatures: scenario.relatedFeatures || []
|
|
5378
|
+
};
|
|
5379
|
+
}
|
|
5380
|
+
/**
|
|
5381
|
+
* 生成场景的 Markdown
|
|
5382
|
+
*/
|
|
5383
|
+
static generateMarkdown(scenario) {
|
|
5384
|
+
const lines = [];
|
|
5385
|
+
lines.push(`#### \u573A\u666F ${scenario.order}: ${scenario.title}`);
|
|
5386
|
+
lines.push("");
|
|
5387
|
+
if (scenario.asA) {
|
|
5388
|
+
lines.push(`**\u4F5C\u4E3A** ${scenario.asA}`);
|
|
5389
|
+
}
|
|
5390
|
+
if (scenario.iWant) {
|
|
5391
|
+
lines.push(`**\u6211\u5E0C\u671B** ${scenario.iWant}`);
|
|
5392
|
+
}
|
|
5393
|
+
if (scenario.soThat) {
|
|
5394
|
+
lines.push(`**\u4EE5\u4FBF** ${scenario.soThat}`);
|
|
5395
|
+
}
|
|
5396
|
+
lines.push("");
|
|
5397
|
+
for (const given of scenario.given) {
|
|
5398
|
+
lines.push(`- [GIVEN] ${given.description}`);
|
|
5399
|
+
}
|
|
5400
|
+
lines.push("");
|
|
5401
|
+
for (const when of scenario.when) {
|
|
5402
|
+
lines.push(`- [WHEN] ${when.description}`);
|
|
5403
|
+
}
|
|
5404
|
+
lines.push("");
|
|
5405
|
+
for (const then of scenario.then) {
|
|
5406
|
+
lines.push(`- [THEN] ${then.description}`);
|
|
5407
|
+
}
|
|
5408
|
+
lines.push("");
|
|
5409
|
+
if (scenario.stateTransitions.length > 0) {
|
|
5410
|
+
lines.push("**\u72B6\u6001\u6D41\u8F6C**:");
|
|
5411
|
+
for (const trans of scenario.stateTransitions) {
|
|
5412
|
+
lines.push(`- \`${trans.from}\` \u2192 \`${trans.to}\` (\u89E6\u53D1: ${trans.trigger})`);
|
|
5413
|
+
}
|
|
5414
|
+
lines.push("");
|
|
5415
|
+
}
|
|
5416
|
+
return lines.join("\n");
|
|
5417
|
+
}
|
|
5418
|
+
};
|
|
5419
|
+
|
|
5420
|
+
// src/commands/accept.ts
|
|
5421
|
+
var acceptCommand = new Command7("accept").argument("[spec-file]", "Spec \u6587\u4EF6\u8DEF\u5F84").description("\u9A8C\u6536\u529F\u80FD - \u8D70\u67E5\u6240\u6709\u9700\u6C42\uFF0C\u9A8C\u8BC1\u8054\u8C03\u662F\u5426\u5B8C\u6210").option("--mode <mode>", "\u9A8C\u6536\u6A21\u5F0F: traditional (\u4F20\u7EDF) \u6216 bdd (\u884C\u4E3A\u9A71\u52A8)", "traditional").option("--scenario <id>", "\u6307\u5B9A\u9A8C\u6536\u7684 BDD \u573A\u666F ID").action(async (specFile, options) => {
|
|
4942
5422
|
try {
|
|
4943
5423
|
logger.header("\u9A8C\u6536\u6A21\u5F0F");
|
|
4944
5424
|
logger.newLine();
|
|
@@ -4949,14 +5429,11 @@ var acceptCommand = new Command7("accept").argument("[spec-file]", "Spec \u6587\
|
|
|
4949
5429
|
process.exit(1);
|
|
4950
5430
|
}
|
|
4951
5431
|
logger.success("\u68C0\u6D4B\u5230\u9879\u76EE\u4E0A\u4E0B\u6587");
|
|
4952
|
-
|
|
4953
|
-
|
|
4954
|
-
|
|
4955
|
-
|
|
4956
|
-
|
|
4957
|
-
await handleIssues(result);
|
|
4958
|
-
}
|
|
4959
|
-
await syncSpecStatus(selectedSpec, result);
|
|
5432
|
+
if (options.mode === "bdd") {
|
|
5433
|
+
await runBDDAcceptance(specFile, options.scenario);
|
|
5434
|
+
} else {
|
|
5435
|
+
await runTraditionalAcceptance(specFile);
|
|
5436
|
+
}
|
|
4960
5437
|
logger.header("\u9A8C\u6536\u5B8C\u6210!");
|
|
4961
5438
|
logger.newLine();
|
|
4962
5439
|
} catch (error) {
|
|
@@ -4967,6 +5444,43 @@ var acceptCommand = new Command7("accept").argument("[spec-file]", "Spec \u6587\
|
|
|
4967
5444
|
process.exit(1);
|
|
4968
5445
|
}
|
|
4969
5446
|
});
|
|
5447
|
+
async function runTraditionalAcceptance(defaultSpec) {
|
|
5448
|
+
const selectedSpec = await selectSpec2(defaultSpec);
|
|
5449
|
+
const selectedMilestone = await selectMilestone2(selectedSpec);
|
|
5450
|
+
const result = await runAcceptanceCheck(selectedSpec, selectedMilestone);
|
|
5451
|
+
await generateAcceptanceReport(result);
|
|
5452
|
+
if (result.issues.length > 0) {
|
|
5453
|
+
await handleIssues(result);
|
|
5454
|
+
}
|
|
5455
|
+
await syncSpecStatus(selectedSpec, result);
|
|
5456
|
+
}
|
|
5457
|
+
async function runBDDAcceptance(defaultSpec, scenarioId) {
|
|
5458
|
+
const selectedSpec = await selectSpec2(defaultSpec);
|
|
5459
|
+
const specContent = await FileUtils.read(selectedSpec);
|
|
5460
|
+
const scenarios = BDDParser.parseFromAcceptanceSection(specContent);
|
|
5461
|
+
if (scenarios.length === 0) {
|
|
5462
|
+
logger.warn("\u672A\u627E\u5230 BDD \u573A\u666F\uFF0C\u4F7F\u7528\u4F20\u7EDF\u9A8C\u6536\u6A21\u5F0F");
|
|
5463
|
+
logger.info('\u8BF7\u5148\u8FD0\u884C "team-cli split-prd" \u751F\u6210\u5305\u542B BDD \u573A\u666F\u7684 spec');
|
|
5464
|
+
await runTraditionalAcceptance(selectedSpec);
|
|
5465
|
+
return;
|
|
5466
|
+
}
|
|
5467
|
+
const targetScenarios = scenarioId ? scenarios.filter((s) => s.id === scenarioId || s.title.toLowerCase().includes(scenarioId.toLowerCase())) : scenarios;
|
|
5468
|
+
if (targetScenarios.length === 0) {
|
|
5469
|
+
throw new Error(`\u672A\u627E\u5230\u573A\u666F: ${scenarioId}`);
|
|
5470
|
+
}
|
|
5471
|
+
logger.newLine();
|
|
5472
|
+
logger.info(`\u627E\u5230 ${scenarios.length} \u4E2A BDD \u573A\u666F\uFF0C\u5C06\u9A8C\u6536 ${targetScenarios.length} \u4E2A`);
|
|
5473
|
+
const results = [];
|
|
5474
|
+
for (const scenario of targetScenarios) {
|
|
5475
|
+
logger.newLine();
|
|
5476
|
+
logger.info(`\u9A8C\u6536\u573A\u666F: ${scenario.title}`);
|
|
5477
|
+
const result = await checkBDDScenario(scenario, selectedSpec);
|
|
5478
|
+
results.push(result);
|
|
5479
|
+
printScenarioResult(result);
|
|
5480
|
+
}
|
|
5481
|
+
await generateBDDReport(selectedSpec, results);
|
|
5482
|
+
await syncBDDStatus(selectedSpec, results);
|
|
5483
|
+
}
|
|
4970
5484
|
async function selectSpec2(defaultSpec) {
|
|
4971
5485
|
logger.step("\u6B65\u9AA4 1/4: \u9009\u62E9 spec \u6587\u4EF6...");
|
|
4972
5486
|
logger.newLine();
|
|
@@ -5513,6 +6027,377 @@ async function syncSpecStatus(specFile, result) {
|
|
|
5513
6027
|
}
|
|
5514
6028
|
}
|
|
5515
6029
|
}
|
|
6030
|
+
async function checkBDDScenario(scenario, specFile) {
|
|
6031
|
+
const result = {
|
|
6032
|
+
scenarioId: scenario.id,
|
|
6033
|
+
scenarioTitle: scenario.title,
|
|
6034
|
+
overallStatus: "pending",
|
|
6035
|
+
givenResults: [],
|
|
6036
|
+
whenResults: [],
|
|
6037
|
+
thenResults: [],
|
|
6038
|
+
stateTransitionResults: []
|
|
6039
|
+
};
|
|
6040
|
+
for (const given of scenario.given) {
|
|
6041
|
+
const checkResult = await verifyGivenCondition(given, specFile);
|
|
6042
|
+
result.givenResults.push(checkResult);
|
|
6043
|
+
}
|
|
6044
|
+
for (const when of scenario.when) {
|
|
6045
|
+
const checkResult = await verifyWhenAction(when, specFile);
|
|
6046
|
+
result.whenResults.push(checkResult);
|
|
6047
|
+
}
|
|
6048
|
+
for (const then of scenario.then) {
|
|
6049
|
+
const checkResult = await verifyThenResult(then, specFile);
|
|
6050
|
+
result.thenResults.push(checkResult);
|
|
6051
|
+
}
|
|
6052
|
+
for (const transition of scenario.stateTransitions) {
|
|
6053
|
+
const checkResult = await verifyStateTransition(transition, specFile);
|
|
6054
|
+
result.stateTransitionResults.push(checkResult);
|
|
6055
|
+
}
|
|
6056
|
+
const allResults = [
|
|
6057
|
+
...result.givenResults,
|
|
6058
|
+
...result.whenResults,
|
|
6059
|
+
...result.thenResults,
|
|
6060
|
+
...result.stateTransitionResults
|
|
6061
|
+
];
|
|
6062
|
+
if (allResults.every((r) => r.status === "pass")) {
|
|
6063
|
+
result.overallStatus = "pass";
|
|
6064
|
+
} else if (allResults.some((r) => r.status === "fail")) {
|
|
6065
|
+
result.overallStatus = "fail";
|
|
6066
|
+
} else {
|
|
6067
|
+
result.overallStatus = "pending";
|
|
6068
|
+
}
|
|
6069
|
+
return result;
|
|
6070
|
+
}
|
|
6071
|
+
async function verifyGivenCondition(given, specFile) {
|
|
6072
|
+
switch (given.type) {
|
|
6073
|
+
case "data":
|
|
6074
|
+
return verifyDataCondition(given);
|
|
6075
|
+
case "state":
|
|
6076
|
+
return verifyStateCondition(given);
|
|
6077
|
+
case "user":
|
|
6078
|
+
return verifyUserCondition(given);
|
|
6079
|
+
default:
|
|
6080
|
+
return { condition: given.description, status: "pending" };
|
|
6081
|
+
}
|
|
6082
|
+
}
|
|
6083
|
+
async function verifyDataCondition(given) {
|
|
6084
|
+
const tableMatch = given.description.match(/`?([a-z_]+)`?表/);
|
|
6085
|
+
const fieldMatch = given.description.match(/`?([a-z_]+)`?字段/);
|
|
6086
|
+
if (tableMatch) {
|
|
6087
|
+
const tableName = tableMatch[1];
|
|
6088
|
+
const tableFiles = await FileUtils.findFiles(`**/${tableName}.sql`, "database");
|
|
6089
|
+
const entityFiles = await FileUtils.findFiles(`**/${StringUtils.toPascalCase(tableName)}.java`, "backend/src");
|
|
6090
|
+
if (tableFiles.length > 0 || entityFiles.length > 0) {
|
|
6091
|
+
return {
|
|
6092
|
+
condition: given.description,
|
|
6093
|
+
status: "pass",
|
|
6094
|
+
evidence: tableFiles[0] || entityFiles[0]
|
|
6095
|
+
};
|
|
6096
|
+
}
|
|
6097
|
+
return {
|
|
6098
|
+
condition: given.description,
|
|
6099
|
+
status: "fail",
|
|
6100
|
+
evidence: `\u8868 ${tableName} \u672A\u627E\u5230`
|
|
6101
|
+
};
|
|
6102
|
+
}
|
|
6103
|
+
return { condition: given.description, status: "pending" };
|
|
6104
|
+
}
|
|
6105
|
+
async function verifyStateCondition(given) {
|
|
6106
|
+
const statusMatch = given.description.match(/`([^`]+)`状态/);
|
|
6107
|
+
const stateMatch = given.description.match(/`([^`]+)`/);
|
|
6108
|
+
const statusName = statusMatch?.[1] || stateMatch?.[1];
|
|
6109
|
+
if (statusName) {
|
|
6110
|
+
const enumFiles = [
|
|
6111
|
+
...await FileUtils.findFiles("**/*Status*.java", "backend/src"),
|
|
6112
|
+
...await FileUtils.findFiles("**/*Status*.ts", "frontend/src")
|
|
6113
|
+
];
|
|
6114
|
+
for (const ef of enumFiles) {
|
|
6115
|
+
const content = await FileUtils.read(ef);
|
|
6116
|
+
if (content.includes(statusName)) {
|
|
6117
|
+
return {
|
|
6118
|
+
condition: given.description,
|
|
6119
|
+
status: "pass",
|
|
6120
|
+
evidence: ef
|
|
6121
|
+
};
|
|
6122
|
+
}
|
|
6123
|
+
}
|
|
6124
|
+
return {
|
|
6125
|
+
condition: given.description,
|
|
6126
|
+
status: "fail",
|
|
6127
|
+
evidence: `\u72B6\u6001 ${statusName} \u672A\u627E\u5230`
|
|
6128
|
+
};
|
|
6129
|
+
}
|
|
6130
|
+
return { condition: given.description, status: "pending" };
|
|
6131
|
+
}
|
|
6132
|
+
async function verifyUserCondition(given) {
|
|
6133
|
+
const userMatch = given.description.match(/用户.*?`([^`]+)`/);
|
|
6134
|
+
if (userMatch) {
|
|
6135
|
+
return {
|
|
6136
|
+
condition: given.description,
|
|
6137
|
+
status: "pending",
|
|
6138
|
+
evidence: "\u9700\u8981\u4EBA\u5DE5\u9A8C\u8BC1\u7528\u6237\u72B6\u6001"
|
|
6139
|
+
};
|
|
6140
|
+
}
|
|
6141
|
+
return { condition: given.description, status: "pending" };
|
|
6142
|
+
}
|
|
6143
|
+
async function verifyWhenAction(when, specFile) {
|
|
6144
|
+
if (when.api) {
|
|
6145
|
+
const apiCheck = await verifyApiImplementationByPath(when.api);
|
|
6146
|
+
return {
|
|
6147
|
+
action: when.description,
|
|
6148
|
+
status: apiCheck.status,
|
|
6149
|
+
apiCalled: when.api,
|
|
6150
|
+
responseCode: apiCheck.responseCode
|
|
6151
|
+
};
|
|
6152
|
+
}
|
|
6153
|
+
if (when.uiAction) {
|
|
6154
|
+
const uiCheck = await verifyUIComponent(when.uiAction);
|
|
6155
|
+
return {
|
|
6156
|
+
action: when.description,
|
|
6157
|
+
status: uiCheck.status
|
|
6158
|
+
};
|
|
6159
|
+
}
|
|
6160
|
+
return { action: when.description, status: "pending" };
|
|
6161
|
+
}
|
|
6162
|
+
async function verifyApiImplementationByPath(apiPath) {
|
|
6163
|
+
const apiMatch = apiPath.match(/(GET|POST|PUT|DELETE|PATCH)\s+\/?(.+)/i);
|
|
6164
|
+
if (!apiMatch) {
|
|
6165
|
+
return { status: "pending" };
|
|
6166
|
+
}
|
|
6167
|
+
const method = apiMatch[1].toUpperCase();
|
|
6168
|
+
const path22 = "/" + apiMatch[2];
|
|
6169
|
+
const controllerFiles = await FileUtils.findFiles("**/*Controller.java", "backend/src");
|
|
6170
|
+
for (const cf of controllerFiles) {
|
|
6171
|
+
const content = await FileUtils.read(cf);
|
|
6172
|
+
if (content.includes(`"${path22}"`) || content.includes(`"${path22}/"`)) {
|
|
6173
|
+
const annotationMap = {
|
|
6174
|
+
GET: ["@GetMapping", "@RequestMapping(method = RequestMethod.GET)"],
|
|
6175
|
+
POST: ["@PostMapping", "@RequestMapping(method = RequestMethod.POST)"],
|
|
6176
|
+
PUT: ["@PutMapping", "@RequestMapping(method = RequestMethod.PUT)"],
|
|
6177
|
+
DELETE: ["@DeleteMapping", "@RequestMapping(method = RequestMethod.DELETE)"]
|
|
6178
|
+
};
|
|
6179
|
+
for (const annotation of annotationMap[method] || []) {
|
|
6180
|
+
if (content.includes(annotation)) {
|
|
6181
|
+
return { status: "pass", responseCode: 200 };
|
|
6182
|
+
}
|
|
6183
|
+
}
|
|
6184
|
+
}
|
|
6185
|
+
}
|
|
6186
|
+
return { status: "fail" };
|
|
6187
|
+
}
|
|
6188
|
+
async function verifyUIComponent(uiAction) {
|
|
6189
|
+
const componentFiles = await FileUtils.findFiles("**/*.tsx", "frontend/src");
|
|
6190
|
+
const viewFiles = await FileUtils.findFiles("**/*.vue", "frontend/src");
|
|
6191
|
+
const allFiles = [...componentFiles, ...viewFiles];
|
|
6192
|
+
for (const cf of allFiles) {
|
|
6193
|
+
const content = await FileUtils.read(cf);
|
|
6194
|
+
if (content.includes(uiAction) || content.toLowerCase().includes(uiAction.toLowerCase())) {
|
|
6195
|
+
return { status: "pass" };
|
|
6196
|
+
}
|
|
6197
|
+
}
|
|
6198
|
+
return { status: "pending" };
|
|
6199
|
+
}
|
|
6200
|
+
async function verifyThenResult(then, specFile) {
|
|
6201
|
+
switch (then.type) {
|
|
6202
|
+
case "response":
|
|
6203
|
+
return verifyResponseResult(then);
|
|
6204
|
+
case "state":
|
|
6205
|
+
return verifyStateResult(then);
|
|
6206
|
+
case "data":
|
|
6207
|
+
return verifyDataResult(then);
|
|
6208
|
+
case "ui":
|
|
6209
|
+
return verifyUIResult(then);
|
|
6210
|
+
default:
|
|
6211
|
+
return { result: then.description, status: "pending" };
|
|
6212
|
+
}
|
|
6213
|
+
}
|
|
6214
|
+
async function verifyResponseResult(then) {
|
|
6215
|
+
const codeMatch = then.description.match(/状态码\s*(\d+)/);
|
|
6216
|
+
const tokenMatch = then.description.match(/token/i);
|
|
6217
|
+
if (tokenMatch) {
|
|
6218
|
+
const tokenFiles = await FileUtils.findFiles("**/*Token*.java", "backend/src");
|
|
6219
|
+
if (tokenFiles.length > 0) {
|
|
6220
|
+
return { result: then.description, status: "pass", expectedValue: "JWT Token" };
|
|
6221
|
+
}
|
|
6222
|
+
return { result: then.description, status: "pending" };
|
|
6223
|
+
}
|
|
6224
|
+
if (codeMatch) {
|
|
6225
|
+
return { result: then.description, status: "pending", expectedValue: `HTTP ${codeMatch[1]}` };
|
|
6226
|
+
}
|
|
6227
|
+
return { result: then.description, status: "pending" };
|
|
6228
|
+
}
|
|
6229
|
+
async function verifyStateResult(then) {
|
|
6230
|
+
const stateMatch = then.description.match(/`([^`]+)`/);
|
|
6231
|
+
if (stateMatch) {
|
|
6232
|
+
const stateName = stateMatch[1];
|
|
6233
|
+
const enumFiles = [
|
|
6234
|
+
...await FileUtils.findFiles("**/*Status*.java", "backend/src"),
|
|
6235
|
+
...await FileUtils.findFiles("**/*Status*.ts", "frontend/src")
|
|
6236
|
+
];
|
|
6237
|
+
for (const ef of enumFiles) {
|
|
6238
|
+
const content = await FileUtils.read(ef);
|
|
6239
|
+
if (content.includes(stateName)) {
|
|
6240
|
+
return { result: then.description, status: "pass", expectedValue: stateName };
|
|
6241
|
+
}
|
|
6242
|
+
}
|
|
6243
|
+
return { result: then.description, status: "fail", expectedValue: stateName };
|
|
6244
|
+
}
|
|
6245
|
+
return { result: then.description, status: "pending" };
|
|
6246
|
+
}
|
|
6247
|
+
async function verifyDataResult(then) {
|
|
6248
|
+
return { result: then.description, status: "pending" };
|
|
6249
|
+
}
|
|
6250
|
+
async function verifyUIResult(then) {
|
|
6251
|
+
return { result: then.description, status: "pending" };
|
|
6252
|
+
}
|
|
6253
|
+
async function verifyStateTransition(transition, specFile) {
|
|
6254
|
+
const { from, trigger, to } = transition;
|
|
6255
|
+
const enumFiles = [
|
|
6256
|
+
...await FileUtils.findFiles("**/*Status*.java", "backend/src"),
|
|
6257
|
+
...await FileUtils.findFiles("**/*Status*.ts", "frontend/src"),
|
|
6258
|
+
...await FileUtils.findFiles("**/*State*.ts", "frontend/src")
|
|
6259
|
+
];
|
|
6260
|
+
const fromExists = await checkStateExists(from, enumFiles);
|
|
6261
|
+
const toExists = await checkStateExists(to, enumFiles);
|
|
6262
|
+
if (!fromExists || !toExists) {
|
|
6263
|
+
return {
|
|
6264
|
+
transition: `\`${from}\` \u2192 \`${to}\``,
|
|
6265
|
+
status: "fail",
|
|
6266
|
+
fromState: fromExists ? "\u2713" : "\u2717",
|
|
6267
|
+
toState: toExists ? "\u2713" : "\u2717"
|
|
6268
|
+
};
|
|
6269
|
+
}
|
|
6270
|
+
const serviceFiles = await FileUtils.findFiles("**/*Service*.java", "backend/src");
|
|
6271
|
+
for (const sf of serviceFiles) {
|
|
6272
|
+
const content = await FileUtils.read(sf);
|
|
6273
|
+
const methodPatterns = [
|
|
6274
|
+
new RegExp(`${from}\\s*\u2192\\s*${to}`, "i"),
|
|
6275
|
+
new RegExp(`from\\s*${from}\\s*to\\s*${to}`, "i")
|
|
6276
|
+
];
|
|
6277
|
+
for (const pattern of methodPatterns) {
|
|
6278
|
+
if (pattern.test(content)) {
|
|
6279
|
+
return {
|
|
6280
|
+
transition: `\`${from}\` \u2192 \`${to}\` (${trigger})`,
|
|
6281
|
+
status: "pass",
|
|
6282
|
+
fromState: from,
|
|
6283
|
+
toState: to
|
|
6284
|
+
};
|
|
6285
|
+
}
|
|
6286
|
+
}
|
|
6287
|
+
}
|
|
6288
|
+
return {
|
|
6289
|
+
transition: `\`${from}\` \u2192 \`${to}\` (${trigger})`,
|
|
6290
|
+
status: "pending",
|
|
6291
|
+
fromState: from,
|
|
6292
|
+
toState: to
|
|
6293
|
+
};
|
|
6294
|
+
}
|
|
6295
|
+
async function checkStateExists(state, files) {
|
|
6296
|
+
for (const file of files) {
|
|
6297
|
+
try {
|
|
6298
|
+
const content = await FileUtils.read(file);
|
|
6299
|
+
if (content.includes(state) || content.includes(`"${state}"`)) {
|
|
6300
|
+
return true;
|
|
6301
|
+
}
|
|
6302
|
+
} catch {
|
|
6303
|
+
continue;
|
|
6304
|
+
}
|
|
6305
|
+
}
|
|
6306
|
+
return false;
|
|
6307
|
+
}
|
|
6308
|
+
function printScenarioResult(result) {
|
|
6309
|
+
const icon = result.overallStatus === "pass" ? "\u2713" : result.overallStatus === "fail" ? "\u2717" : "\u25CB";
|
|
6310
|
+
console.log("");
|
|
6311
|
+
console.log(` ${icon} \u573A\u666F: ${result.scenarioTitle}`);
|
|
6312
|
+
const passGiven = result.givenResults.filter((r) => r.status === "pass").length;
|
|
6313
|
+
const passWhen = result.whenResults.filter((r) => r.status === "pass").length;
|
|
6314
|
+
const passThen = result.thenResults.filter((r) => r.status === "pass").length;
|
|
6315
|
+
const passTrans = result.stateTransitionResults.filter((r) => r.status === "pass").length;
|
|
6316
|
+
console.log(` Given: ${passGiven}/${result.givenResults.length}`);
|
|
6317
|
+
console.log(` When: ${passWhen}/${result.whenResults.length}`);
|
|
6318
|
+
console.log(` Then: ${passThen}/${result.thenResults.length}`);
|
|
6319
|
+
console.log(` State: ${passTrans}/${result.stateTransitionResults.length}`);
|
|
6320
|
+
}
|
|
6321
|
+
async function generateBDDReport(specFile, results) {
|
|
6322
|
+
const reportDir = "docs/bdd-reports";
|
|
6323
|
+
await FileUtils.ensureDir(reportDir);
|
|
6324
|
+
const timestamp = (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
|
|
6325
|
+
const specName = path12.basename(specFile, ".md");
|
|
6326
|
+
const reportFile = path12.join(reportDir, `${timestamp}_${specName}_bdd.md`);
|
|
6327
|
+
const lines = [];
|
|
6328
|
+
lines.push("# BDD \u9A8C\u6536\u62A5\u544A");
|
|
6329
|
+
lines.push("");
|
|
6330
|
+
lines.push(`**Spec \u6587\u4EF6**: ${specFile}`);
|
|
6331
|
+
lines.push(`**\u9A8C\u6536\u65F6\u95F4**: ${(/* @__PURE__ */ new Date()).toLocaleString("zh-CN")}`);
|
|
6332
|
+
lines.push(`**\u573A\u666F\u6570\u91CF**: ${results.length}`);
|
|
6333
|
+
lines.push("");
|
|
6334
|
+
lines.push("## \u9A8C\u6536\u6C47\u603B");
|
|
6335
|
+
lines.push("");
|
|
6336
|
+
let totalPass = 0;
|
|
6337
|
+
let totalFail = 0;
|
|
6338
|
+
for (const r of results) {
|
|
6339
|
+
const statusIcon = r.overallStatus === "pass" ? "\u2713" : r.overallStatus === "fail" ? "\u2717" : "\u25CB";
|
|
6340
|
+
const givenIcon = r.givenResults.every((g) => g.status === "pass") ? "\u2713" : r.givenResults.some((g) => g.status === "fail") ? "\u2717" : "\u25CB";
|
|
6341
|
+
const whenIcon = r.whenResults.every((w) => w.status === "pass") ? "\u2713" : r.whenResults.some((w) => w.status === "fail") ? "\u2717" : "\u25CB";
|
|
6342
|
+
const thenIcon = r.thenResults.every((t) => t.status === "pass") ? "\u2713" : r.thenResults.some((t) => t.status === "fail") ? "\u2717" : "\u25CB";
|
|
6343
|
+
const transIcon = r.stateTransitionResults.every((t) => t.status === "pass") ? "\u2713" : r.stateTransitionResults.some((t) => t.status === "fail") ? "\u2717" : "\u25CB";
|
|
6344
|
+
lines.push(`- ${statusIcon} ${r.scenarioTitle} | Given:${givenIcon} When:${whenIcon} Then:${thenIcon} State:${transIcon}`);
|
|
6345
|
+
if (r.overallStatus === "pass") totalPass++;
|
|
6346
|
+
if (r.overallStatus === "fail") totalFail++;
|
|
6347
|
+
}
|
|
6348
|
+
lines.push("");
|
|
6349
|
+
lines.push(`**\u603B\u8BA1**: ${totalPass} \u4E2A\u901A\u8FC7, ${totalFail} \u4E2A\u5931\u8D25, ${results.length - totalPass - totalFail} \u4E2A\u5F85\u9A8C\u8BC1`);
|
|
6350
|
+
lines.push("");
|
|
6351
|
+
lines.push("## \u8BE6\u7EC6\u9A8C\u6536\u7ED3\u679C");
|
|
6352
|
+
lines.push("");
|
|
6353
|
+
for (const r of results) {
|
|
6354
|
+
lines.push(`### \u573A\u666F: ${r.scenarioTitle}`);
|
|
6355
|
+
lines.push("");
|
|
6356
|
+
lines.push("#### GIVEN (\u524D\u7F6E\u6761\u4EF6)");
|
|
6357
|
+
for (const g of r.givenResults) {
|
|
6358
|
+
const icon = g.status === "pass" ? "\u2713" : g.status === "fail" ? "\u2717" : "\u25CB";
|
|
6359
|
+
lines.push(`- ${icon} ${g.condition}`);
|
|
6360
|
+
if (g.evidence) {
|
|
6361
|
+
lines.push(` - \u8BC1\u636E: ${g.evidence}`);
|
|
6362
|
+
}
|
|
6363
|
+
}
|
|
6364
|
+
lines.push("");
|
|
6365
|
+
lines.push("#### WHEN (\u89E6\u53D1\u52A8\u4F5C)");
|
|
6366
|
+
for (const w of r.whenResults) {
|
|
6367
|
+
const icon = w.status === "pass" ? "\u2713" : w.status === "fail" ? "\u2717" : "\u25CB";
|
|
6368
|
+
lines.push(`- ${icon} ${w.action}`);
|
|
6369
|
+
if (w.apiCalled) {
|
|
6370
|
+
lines.push(` - API: ${w.apiCalled}`);
|
|
6371
|
+
}
|
|
6372
|
+
}
|
|
6373
|
+
lines.push("");
|
|
6374
|
+
lines.push("#### THEN (\u9884\u671F\u7ED3\u679C)");
|
|
6375
|
+
for (const t of r.thenResults) {
|
|
6376
|
+
const icon = t.status === "pass" ? "\u2713" : t.status === "fail" ? "\u2717" : "\u25CB";
|
|
6377
|
+
lines.push(`- ${icon} ${t.result}`);
|
|
6378
|
+
}
|
|
6379
|
+
lines.push("");
|
|
6380
|
+
lines.push("#### \u72B6\u6001\u6D41\u8F6C");
|
|
6381
|
+
for (const s of r.stateTransitionResults) {
|
|
6382
|
+
const icon = s.status === "pass" ? "\u2713" : s.status === "fail" ? "\u2717" : "\u25CB";
|
|
6383
|
+
lines.push(`- ${icon} ${s.transition}`);
|
|
6384
|
+
}
|
|
6385
|
+
lines.push("");
|
|
6386
|
+
lines.push("---");
|
|
6387
|
+
lines.push("");
|
|
6388
|
+
}
|
|
6389
|
+
await FileUtils.write(reportFile, lines.join("\n"));
|
|
6390
|
+
logger.success(`BDD \u9A8C\u6536\u62A5\u544A\u5DF2\u751F\u6210: ${reportFile}`);
|
|
6391
|
+
}
|
|
6392
|
+
async function syncBDDStatus(specFile, results) {
|
|
6393
|
+
const allPassed = results.every((r) => r.overallStatus === "pass");
|
|
6394
|
+
if (allPassed) {
|
|
6395
|
+
logger.success("\u6240\u6709 BDD \u573A\u666F\u9A8C\u6536\u901A\u8FC7");
|
|
6396
|
+
} else {
|
|
6397
|
+
const failedCount = results.filter((r) => r.overallStatus === "fail").length;
|
|
6398
|
+
logger.warn(`${failedCount} \u4E2A\u573A\u666F\u9A8C\u6536\u672A\u901A\u8FC7\uFF0C\u9700\u8981\u4FEE\u590D`);
|
|
6399
|
+
}
|
|
6400
|
+
}
|
|
5516
6401
|
|
|
5517
6402
|
// src/commands/add-module.ts
|
|
5518
6403
|
init_esm_shims();
|