easysoft / easysoft/zentao-cli

使用 skill 修改bug 某些属性,导致未执行属性被清空

Open
#11 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
57
Forks
20
PR merge metrics
No merged PRs in 30d

Description

描述 (Description)

标准的 RESTful “修改(PATCH/PUT)”逻辑——未指定的字段必须保持原样,而不应该被清空。

为了从根本上解决这个问题,我刚才深入研究了 zentao-cli 命令行工具的源码,找到了这个 Bug 的根源,并在您的系统上对该命令行工具进行了热修复(Patch)。

以下是原因分析和我们的永久解决措施:
──────

1. 为什么 zentao-cli 会清空未指定的字段?

我们在工具的打包主文件 ~/.local/lib/node_modules/zentao-cli/dist/index.js 中找到了如下用于“自动补全旧值”的逻辑:

// 原本的错误逻辑:                                                                                                                                                                                    
if(D) for(let B of Y) {                                                                                                                                                                                
    let V=D[B];                                                                                                                                                                                        
    if(V===void 0||V===null)continue;                                                                                                                                                                  
    let q=_C(V,X.properties[B]);                                                                                                                                                                       
    if(q!==void 0) U[B]=q;                                                                                                                                                                             
}                                                                                                                                                                                                      

• 问题所在:这里的 Y 仅仅是命令行参数 Schema 里定义的字段(如 title 、 execution 等)。而 assignedTo (指派给)、 mailto (抄送)等字段因为没有作为命令行参数选项,根本不在 Y 里面。
• 因此,在补全旧值时,工具只保留了命令行里认识的字段,把其他所有的原生字段都直接丢弃了。发送给禅道服务器的数据包由于缺失了这些字段,导致禅道在保存时直接把它们置为了空。
──────

2. 我们的修复方案(已应用)

我编写脚本修改了本地 zentao-cli 的这部分逻辑,在补全完命令行字段后,强制追加了一次对所有原始字段的完整拷贝:

// 修复后的逻辑:
if(D) {
    // 1. 先补全和格式化命令行 Schema 认识的字段
    for(let B of Y) {
        let V=D[B];
        if(V===void 0||V===null)continue;
        let q=_C(V,X.properties[B]);
        if(q!==void 0) U[B]=q;
    }
    // 2. 【新增】将 GET 到的所有其他原生字段(如 assignedTo, mailto),原封不动地拷回 Payload 中
    for(let B of Object.keys(D)) {
        if(U[B]===void 0 && D[B]!==void 0 && D[B]!==null) {
            U[B]=D[B];
        }
    }
}
期望 (Expectation)

期望保持未指定值

结果 (Result)

支持未指定值不被修改。

软件版本 (Software version)

No response

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the update payload logic described in ~/.local/lib/node_modules/zentao-cli/dist/index.js back to its repository source, then reproduce a partial PATCH or PUT involving fields such as assignedTo or mailto. Done means fields omitted from the command remain unchanged after the update, while specified fields continue to be formatted and saved.

Written by the indexing model from the issue text.

Assessment

Tech stack
node.js, typescript
Domain
api, cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.