Skip to content

fix: inconsistent format issue when checking if the plugin is installed#7493

Open
Waterwzy wants to merge 3 commits intoAstrBotDevs:masterfrom
Waterwzy:fix/7491
Open

fix: inconsistent format issue when checking if the plugin is installed#7493
Waterwzy wants to merge 3 commits intoAstrBotDevs:masterfrom
Waterwzy:fix/7491

Conversation

@Waterwzy
Copy link
Copy Markdown
Contributor

@Waterwzy Waterwzy commented Apr 12, 2026

Fix #7491

Modifications / 改动点

dashboard/src/views/extension/useExtensionPage.js

  • 增加了两处replace,保证-_的一致性
  • 保留了repo检测作为兜底措施
  • This is NOT a breaking change. / 这不是一个破坏性变更。

Screenshots or Test Results / 运行截图或测试结果

当本地repo与插件市场repo不一致时:

9a7844c82a875acd92df2d4f1a3c1348 15a2b393d5ff54b9944d3d75deee9568

说明astrbot正确识别匹配了插件名称


Checklist / 检查清单

  • 😊 If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
    / 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。

  • 👀 My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
    / 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”

  • 🤓 I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in requirements.txt and pyproject.toml.
    / 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到 requirements.txtpyproject.toml 文件相应位置。

  • 😮 My changes do not introduce malicious code.
    / 我的更改没有引入恶意代码。

Summary by Sourcery

Bug Fixes:

  • Ensure plugin installation detection treats dashes and underscores consistently in extension names to prevent false negatives.

@auto-assign auto-assign bot requested review from LIghtJUNction and anka-afk April 12, 2026 15:03
@dosubot dosubot bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Apr 12, 2026
Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 2 issues, and left some high level feedback:

  • The normalization for plugin names only replaces _ with -; if you want true consistency, consider a shared helper (e.g., normalizeName(name)) that also handles casing and both _/- directions so the logic is not duplicated inline and is easier to maintain.
  • The inline comments on the replace calls explain the intent but are embedded at the end of long lines; consider extracting the logic into a clearly named function or adding a brief comment above the block to keep line length shorter and semantics clearer.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The normalization for plugin names only replaces `_` with `-`; if you want true consistency, consider a shared helper (e.g., `normalizeName(name)`) that also handles casing and both `_`/`-` directions so the logic is not duplicated inline and is easier to maintain.
- The inline comments on the `replace` calls explain the intent but are embedded at the end of long lines; consider extracting the logic into a clearly named function or adding a brief comment above the block to keep line length shorter and semantics clearer.

## Individual Comments

### Comment 1
<location path="dashboard/src/views/extension/useExtensionPage.js" line_range="1291" />
<code_context>
     const data = Array.isArray(extension_data?.data) ? extension_data.data : [];
     const installedRepos = new Set(data.map((ext) => ext.repo?.toLowerCase()));
-    const installedNames = new Set(data.map((ext) => ext.name));
+    const installedNames = new Set(data.map((ext) => ext.name.replace(/_/g, '-')));//统一格式,以防下面的匹配不生效
     const installedByRepo = new Map(
       data
</code_context>
<issue_to_address>
**issue (bug_risk):** Defensive check for `ext.name` before calling `replace` to avoid runtime errors.

If any `data` entry has a missing or non-string `name`, `ext.name.replace` will throw. Consider a small helper, e.g. `const normalizeName = (name) => String(name || '').replace(/_/g, '-');` and use `normalizeName(ext.name)` here.
</issue_to_address>

### Comment 2
<location path="dashboard/src/views/extension/useExtensionPage.js" line_range="1321" />
<code_context>
       plugin.installed =
         installedRepos.has(plugin.repo?.toLowerCase()) ||
-        installedNames.has(plugin.name);
+        installedNames.has(plugin.name.replace(/_/g, '-'));//统一格式,防止匹配失败
     }

</code_context>
<issue_to_address>
**issue (bug_risk):** Also guard `plugin.name` when calling `replace` to prevent potential crashes.

If `plugin.name` is ever null/undefined or not a string, calling `.replace` will throw. Consider guarding it or using a small helper like `normalizeName(plugin.name)` to safely normalize and reuse the logic.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@dosubot dosubot bot added area:webui The bug / feature is about webui(dashboard) of astrbot. feature:plugin The bug / feature is about AstrBot plugin system. labels Apr 12, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the extension installation check to normalize plugin names by replacing underscores with hyphens. The review feedback suggests further improving the robustness of this matching by incorporating case-insensitivity and string normalization via the normalizeStr utility, while also ensuring consistency across other name-based lookups in the file.

Waterwzy and others added 2 commits April 12, 2026 23:12
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Apr 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:webui The bug / feature is about webui(dashboard) of astrbot. feature:plugin The bug / feature is about AstrBot plugin system. lgtm This PR has been approved by a maintainer size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]检查是否安装插件时的匹配问题

2 participants