Skip to content

fix: correct packageHasInstalled false positive for uninstalled packages - #885

Open
add-uos wants to merge 2 commits into
linuxdeepin:masterfrom
add-uos:agent/pms-bug-bot/02c28abe0c96
Open

add-uos wants to merge 2 commits into
linuxdeepin:masterfrom
add-uos:agent/pms-bug-bot/02c28abe0c96

Conversation

@add-uos

@add-uos add-uos commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

fix: correct packageHasInstalled false positive for uninstalled packages

  1. Root cause: packageHasInstalled used r.contains("installed") which
    matches dpkg's not-installed output "package 'x' is not installed"
  2. Fix: change to r.contains("Status: install ok installed") for exact
    dpkg status line matching
  3. Impact: dde-printer status detection in PageMultiInfo and PageSingleInfo
    now correctly returns false when the package is not installed

Influence:

  1. Test dde-printer detection when dde-printer is installed
  2. Test dde-printer detection when dde-printer is not installed
  3. Verify no regression on device manager printer menu display

fix: 修复未安装包被误判为已安装的问题

  1. 根因:packageHasInstalled 使用 r.contains("installed") 模糊匹配,
    dpkg 未安装包输出 "package 'x' is not installed" 同样包含该子串
  2. 方案:改为 r.contains("Status: install ok installed") 精确匹配
    dpkg 标准状态行
  3. 影响:PageMultiInfo 和 PageSingleInfo 中 dde-printer 安装检测
    在未安装时正确返回 false

Influence:

  1. 测试已安装 dde-printer 时的检测结果
  2. 测试未安装 dde-printer 时的检测结果
  3. 验证设备管理器打印机菜单显示无回归

PMS: BUG-DEF-DM-PAGE-001

Summary by Sourcery

Fix package installation status detection to accurately control printer-related device manager behavior.

Bug Fixes:

  • Correct package installation detection so uninstalled packages are no longer falsely reported as installed.

Tests:

  • Add parameterized coverage for installed, uninstalled, empty, and standard dpkg status outputs.

Chores:

  • Update copyright years in the affected source and test files.

1. Root cause: packageHasInstalled used r.contains("installed") which
   matches dpkg's not-installed output "package 'x' is not installed"
2. Fix: change to r.contains("Status: install ok installed") for exact
   dpkg status line matching
3. Impact: dde-printer status detection in PageMultiInfo and PageSingleInfo
   now correctly returns false when the package is not installed

Influence:
1. Test dde-printer detection when dde-printer is installed
2. Test dde-printer detection when dde-printer is not installed
3. Verify no regression on device manager printer menu display

fix: 修复未安装包被误判为已安装的问题

1. 根因:packageHasInstalled 使用 r.contains("installed") 模糊匹配,
   dpkg 未安装包输出 "package 'x' is not installed" 同样包含该子串
2. 方案:改为 r.contains("Status: install ok installed") 精确匹配
   dpkg 标准状态行
3. 影响:PageMultiInfo 和 PageSingleInfo 中 dde-printer 安装检测
   在未安装时正确返回 false

Influence:
1. 测试已安装 dde-printer 时的检测结果
2. 测试未安装 dde-printer 时的检测结果
3. 验证设备管理器打印机菜单显示无回归

PMS: BUG-DEF-DM-PAGE-001
@sourcery-ai

sourcery-ai Bot commented Oct 23, 2026

Copy link
Copy Markdown

Sorry @add-uos, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 4 days and 18 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: add-uos

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@sourcery-ai

sourcery-ai Bot commented Oct 23, 2026

Copy link
Copy Markdown

Reviewer's Guide

Corrects false-positive package detection by matching dpkg’s exact installed status line, with stubbed parameterized tests covering installed, uninstalled, empty, and metadata-bearing outputs; this fixes dde-printer status handling used by the multi- and single-device pages.

Sequence diagram for exact package installation detection

sequenceDiagram
    participant PageInfo
    participant QProcess
    participant dpkg

    PageInfo->>QProcess: start dpkg -s packageName
    QProcess->>dpkg: query package status
    dpkg-->>QProcess: status output
    QProcess-->>PageInfo: readAll()
    PageInfo->>PageInfo: packageHasInstalled(packageName)
    alt output contains Status: install ok installed
        PageInfo-->>PageInfo: return true
    else output does not contain exact status line
        PageInfo-->>PageInfo: return false
    end
Loading

Flow diagram for dde-printer status handling

flowchart TD
    A[PageMultiInfo or PageSingleInfo checks dde-printer] --> B[PageInfo.packageHasInstalled]
    B --> C[Read dpkg status output]
    C --> D{Contains exact installed status line?}
    D -->|Yes| E[Report dde-printer installed]
    D -->|No| F[Report dde-printer not installed]
    E --> G[Show printer menu when applicable]
    F --> H[Do not treat package as installed]
Loading

File-Level Changes

Change Details Files
Make package installation detection require dpkg’s explicit installed status line instead of a broad substring match.
  • Replace the ambiguous installed search with Status: install ok installed matching.
  • Preserve the existing logging and boolean-return behavior.
deepin-devicemanager/src/Page/PageInfo.cpp
Add parameterized unit coverage for installed and uninstalled dpkg output.
  • Stub QIODevice::readAll to inject deterministic dpkg responses.
  • Verify exact status output, metadata-containing output, empty output, and the uninstalled diagnostic.
  • Exercise the shared implementation through PageMultiInfo.
deepin-devicemanager/tests/src/Page/ut_pageinfo.cpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

总体评分: 97 分 (通过阈值: 70分)

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 本次提交修复了 packageHasInstalled 函数中因匹配字符串过于宽泛(contains("installed"))导致未安装包被误判为已安装的问题,改为精确匹配 dpkg 状态字符串 "Status: install ok installed",并补充了完整的参数化单元测试。四维度均通过,代码质量维度存在测试隔离不完整的轻微问题(未 stub QProcess::start/waitForFinished,导致测试可能实际执行 dpkg 命令),建议改进测试隔离。

🔍 详细分析

1. 语法逻辑 ✅

评价: 语法正确,逻辑清晰 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: ['无需修改,语法逻辑正确。']


2. 代码质量 ✅

评价: 代码结构清晰,注释完整 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: ['建议在测试中增加对 QProcess::start 和 QProcess::waitForFinished 的 stub,使测试完全脱离系统环境依赖,参考下方修复代码示例。']


3. 代码性能 ✅

评价: 性能良好,资源使用合理 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: ['无需修改,性能合理。']


4. 代码安全 🔒

评价: 存在0个安全漏洞 ✅ 通过

🔐 发现 0 个安全漏洞

安全漏洞详情:
✅ 未发现安全漏洞

建议: ['无需修改,安全合规。']


💡 改进建议代码示例

// 改进建议:在 ut_pageinfo.cpp 中增加对 QProcess::start 和 waitForFinished 的 stub,
// 使测试完全隔离系统环境依赖

static void ut_QProcess_start(void *self, const QString &program, const QStringList &arguments)
{
    Q_UNUSED(self)
    Q_UNUSED(program)
    Q_UNUSED(arguments)
    // Stub: 不实际启动进程
}

static bool ut_QProcess_waitForFinished(void *self, int msecs)
{
    Q_UNUSED(self)
    Q_UNUSED(msecs)
    return true; // Stub: 直接返回成功
}

TEST_P(PackageHasInstalled_UT, packageHasInstalled)
{
    g_readAllData = GetParam().dpkgOutput;

    Stub stub;
    stub.set(ADDR(QIODevice, readAll), ut_QIODevice_readAll);
    stub.set(ADDR(QProcess, start), ut_QProcess_start);
    stub.set(ADDR(QProcess, waitForFinished), ut_QProcess_waitForFinished);

    PageMultiInfo *p = new PageMultiInfo;
    PageInfo *pageInfo = dynamic_cast<PageInfo *>(p);
    bool result = pageInfo->packageHasInstalled("test-package");
    EXPECT_EQ(GetParam().expected, result);
    delete p;
}

本报告由 AI 代码审查工具自动生成

@deepin-bot

deepin-bot Bot commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

TAG Bot

New tag: 6.0.75
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #956

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants