mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-06-19 06:43:54 +08:00
Mentioning an AI bot (e.g. `@Forum_Research_Assis`) in a topic the bot's
User record can't see — like a category restricted to a group the bot
isn't part of — surfaced the "this user cannot see this mention" warning
popup in the composer. The warning is misleading: AI bots reply via
`PostCreator.create!(... skip_guardian: true)` (`playground.rb`), so
they respond regardless of whether their User can `Guardian#can_see?`
the topic.
The previous case-insensitive fix (9a4cca29) exposed this latent
behavior. Pre-fix, mixed-case names hit a case-sensitive hash miss in
`ComposerController#mentions` and silently returned an empty
`user_reasons`. Post-fix, the lookup hits correctly and the reachability
check — which was always there — now fires for AI bot users that
genuinely can't see the topic.
Adds a `:composer_mention_user_reason` plugin modifier, applied after
the standard reason is computed in `user_reason`, so plugins can clear
or transform it. The AI plugin registers against the modifier and
returns `nil` for any user in
`DiscourseAi::AiBot::EntryPoint.all_bot_ids` (covering both AI agent
users and chat-bot-enabled LLM model users).
discobot and the system user are intentionally unaffected: discobot's
`PostCreator.create!` does not skip the guardian, so the reachability
warning remains accurate for it.
https://meta.discourse.org/t/401292
29 lines
842 B
Ruby
Vendored
29 lines
842 B
Ruby
Vendored
# frozen_string_literal: true
|
|
|
|
RSpec.describe ComposerController do
|
|
fab!(:admin)
|
|
fab!(:ai_agent)
|
|
fab!(:private_category) { Fabricate(:private_category, group: Group[:staff]) }
|
|
fab!(:restricted_topic) { Fabricate(:topic, category: private_category) }
|
|
|
|
before do
|
|
enable_current_plugin
|
|
sign_in(admin)
|
|
end
|
|
|
|
describe "#mentions" do
|
|
it "suppresses the reachability warning when mentioning an AI bot user" do
|
|
agent_user = ai_agent.create_user!
|
|
|
|
get "/composer/mentions.json",
|
|
params: {
|
|
names: [agent_user.username.upcase],
|
|
topic_id: restricted_topic.id,
|
|
}
|
|
|
|
expect(response.status).to eq(200)
|
|
expect(response.parsed_body["users"]).to contain_exactly(agent_user.username_lower)
|
|
expect(response.parsed_body["user_reasons"]).to eq({})
|
|
end
|
|
end
|
|
end
|