feat(logging): 增强测试框架的日志记录功能

- 在 GenerateSwagger 方法中添加调试日志记录,记录部分运行检查和现有端点的保留情况
- 更新 Action 方法以支持测试模式下的日志缓冲,确保日志记录的准确性
- 删除不再使用的计划文档,简化项目结构
This commit is contained in:
2026-04-04 01:57:10 +08:00
parent 17e1090077
commit 63360f9a14
3 changed files with 43 additions and 69 deletions
+39
View File
@@ -275,6 +275,15 @@ func (that *TestApp) GenerateSwagger(title, version, outputDir string) error {
}
isPartialRun := visitedPaths > 0 && visitedPaths < totalPaths
// #region agent log
func() {
if f, err := os.OpenFile("debug-e1b6ef.log", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644); err == nil {
fmt.Fprintf(f, `{"sessionId":"e1b6ef","hypothesisId":"D","message":"partial_run_check","data":{"proj":"%s","totalPaths":%d,"visitedPaths":%d,"isPartialRun":%v}}`+"\n", projName, totalPaths, visitedPaths, isPartialRun)
f.Close()
}
}()
// #endregion
// 仅部分运行时才加载已有 spec 用于合并,全量运行时清空重建
var existingEndpoints map[string]map[string]interface{}
if isPartialRun {
@@ -302,10 +311,40 @@ func (that *TestApp) GenerateSwagger(title, version, outputDir string) error {
// 部分运行且该路径未被访问 → 保留已有 spec 中的数据
if isPartialRun && !visited[apiPath] {
if existing, ok := existingEndpoints[apiPath]; ok {
// #region agent log
if strings.Contains(apiPath, "batch") {
func() {
if f, err := os.OpenFile("debug-e1b6ef.log", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644); err == nil {
fmt.Fprintf(f, `{"sessionId":"e1b6ef","hypothesisId":"D","message":"kept_existing","data":{"path":"%s"}}`+"\n", apiPath)
f.Close()
}
}()
}
// #endregion
endpoints = append(endpoints, existing)
continue
}
// #region agent log
if strings.Contains(apiPath, "batch") {
func() {
if f, err := os.OpenFile("debug-e1b6ef.log", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644); err == nil {
fmt.Fprintf(f, `{"sessionId":"e1b6ef","hypothesisId":"D","message":"NOT_in_existing_file","data":{"path":"%s"}}`+"\n", apiPath)
f.Close()
}
}()
}
// #endregion
}
// #region agent log
if strings.Contains(apiPath, "batch") && isPartialRun && visited[apiPath] {
func() {
if f, err := os.OpenFile("debug-e1b6ef.log", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644); err == nil {
fmt.Fprintf(f, `{"sessionId":"e1b6ef","hypothesisId":"D","message":"regenerated","data":{"path":"%s","numRecs":%d}}`+"\n", apiPath, len(recs))
f.Close()
}
}()
}
// #endregion
httpMethod := "POST"
if len(recs) > 0 && recs[0].Method != "" {