Skip to content

fix: channel-lark feature compilation errors#3032

Closed
gqf2008 wants to merge 1 commit intozeroclaw-labs:masterfrom
gqf2008:fix/channel-lark-compilation
Closed

fix: channel-lark feature compilation errors#3032
gqf2008 wants to merge 1 commit intozeroclaw-labs:masterfrom
gqf2008:fix/channel-lark-compilation

Conversation

@gqf2008
Copy link
Copy Markdown

@gqf2008 gqf2008 commented Mar 8, 2026

Fix compilation errors when enabling the channel-lark feature:

  • Add platform field to LarkChannel struct (replaces use_feishu bool)
  • Add mention_only parameter to new_with_platform function
  • Implement from_lark_config and from_feishu_config methods
  • Fix test fixture with mention_only field

Also fix import ordering in src/peripherals/serial.rs (cargo fmt).

Validation

  • cargo check --features channel-lark ✓
  • cargo test --features channel-lark -- lark (48/48 passing) ✓
  • cargo fmt --check ✓

Summary by CodeRabbit

  • Refactor
    • Improved internal platform selection logic for Lark/Feishu integration, replacing a boolean flag with a typed platform representation for more robust configuration handling.
    • Reorganized internal import statements for better code maintainability.

Fix compilation errors when enabling the channel-lark feature:

- Add platform field to LarkChannel struct (replaces use_feishu bool)
- Add mention_only parameter to new_with_platform function
- Implement from_lark_config and from_feishu_config methods
- Fix test fixture with mention_only field

Also fix import ordering in src/peripherals/serial.rs (cargo fmt).

Validation:
- cargo check --features channel-lark ✓
- cargo test --features channel-lark -- lark (48/48 passing) ✓
- cargo fmt --check ✓
Copilot AI review requested due to automatic review settings March 8, 2026 15:58
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 8, 2026

Note

.coderabbit.yaml has unrecognized properties

CodeRabbit is using all valid settings from your configuration. Unrecognized properties (listed below) have been ignored and may indicate typos or deprecated fields that can be removed.

⚠️ Parsing warnings (1)
Validation error: Unrecognized key(s) in object: 'tools', 'path_filters', 'review_instructions'
⚙️ Configuration instructions
  • Please see the configuration documentation for more information.
  • You can also validate your configuration using the online YAML validator.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json
📝 Walkthrough

Walkthrough

This PR replaces the boolean use_feishu flag in LarkChannel with a typed LarkPlatform enum, introduces platform-specific constructors (from_lark_config, from_feishu_config), updates the from_config method to derive platform from legacy configuration, and reorders an import in the serial module.

Changes

Cohort / File(s) Summary
Platform Enum Refactoring
src/channels/lark.rs
Replaced use_feishu: bool field with platform: LarkPlatform enum. Added from_lark_config() and from_feishu_config() constructors for explicit platform selection. Updated from_config() to derive platform from legacy use_feishu flag. Modified new_with_platform() signature to include platform parameter. Tests updated to use new constructor methods.
Import Reordering
src/peripherals/serial.rs
Relocated import statement; no functional changes.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

Suggested labels

size: S, risk: medium, channel, channel: lark, tests

Suggested reviewers

  • JordanTheJet
  • theonlyhennygod
🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is mostly complete with a clear problem statement and validation evidence, but it is missing several required sections from the template (Labels, Change Metadata, Linked Issues, etc.). Add required sections: Label Snapshot, Change Metadata, Linked Issue, Security Impact, Privacy and Data Hygiene, Compatibility, Human Verification, Side Effects, and Rollback Plan.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change—fixing compilation errors for the channel-lark feature by refactoring the platform representation.
Docstring Coverage ✅ Passed Docstring coverage is 83.33% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes channel-lark feature build issues by refactoring Lark/Feishu endpoint selection into an explicit LarkPlatform on LarkChannel, updating constructors/config adapters accordingly, and aligning a test fixture with the new config shape.

Changes:

  • Replace use_feishu: bool on LarkChannel with platform: LarkPlatform and route base URLs / proxy keys via that enum.
  • Extend new_with_platform to accept mention_only, and add explicit from_lark_config / from_feishu_config constructors (keeping from_config as the legacy compatibility path).
  • Apply cargo fmt import ordering adjustment in src/peripherals/serial.rs.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/peripherals/serial.rs Import ordering change from rustfmt (no behavior change).
src/channels/lark.rs Platform refactor + constructor/config wiring updates; test fixture updated for mention_only.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/channels/lark.rs
Comment on lines +390 to +398
pub fn from_feishu_config(config: &crate::config::schema::FeishuConfig) -> Self {
let mut ch = Self::new_with_platform(
config.app_id.clone(),
config.app_secret.clone(),
config.verification_token.clone().unwrap_or_default(),
config.port,
config.allowed_users.clone(),
false, // mention_only not part of FeishuConfig
LarkPlatform::Feishu,
Copy link

Copilot AI Mar 8, 2026

Choose a reason for hiding this comment

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

from_feishu_config hard-codes mention_only to false because FeishuConfig lacks this field. That creates a surprising feature-parity gap vs LarkConfig (and vs the legacy LarkConfig { use_feishu: true } path, which can enable mention_only). Consider adding mention_only to FeishuConfig as well, or otherwise documenting/centralizing this behavior so users can’t accidentally lose mention-only filtering when switching to [channels_config.feishu].

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/channels/lark.rs`:
- Around line 390-398: The Feishu conversion currently hard-codes mention_only:
false in from_feishu_config, which silently broadens group-response permissions;
update the config and constructor flow by adding a mention_only: Option<bool>
(or bool with default) to the FeishuConfig struct and propagate it into
LarkChannel creation inside from_feishu_config (i.e., replace the hard-coded
false with config.mention_only.unwrap_or(false) or config.mention_only); ensure
the FeishuConfig definition (schema::FeishuConfig) and any
deserialization/defaults are updated so callers can opt into mention-gating
rather than defaulting to permissive behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: d28c1daa-796b-453d-b96a-aad9bedee3d1

📥 Commits

Reviewing files that changed from the base of the PR and between f7fefd4 and df5d309.

📒 Files selected for processing (2)
  • src/channels/lark.rs
  • src/peripherals/serial.rs

Comment thread src/channels/lark.rs
Comment on lines +390 to +398
pub fn from_feishu_config(config: &crate::config::schema::FeishuConfig) -> Self {
let mut ch = Self::new_with_platform(
config.app_id.clone(),
config.app_secret.clone(),
config.verification_token.clone().unwrap_or_default(),
config.port,
config.allowed_users.clone(),
false, // mention_only not part of FeishuConfig
LarkPlatform::Feishu,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf 'FeishuConfig definition and related fields:\n'
rg -n -C4 --type rust '\bstruct\s+FeishuConfig\b|\bmention_only\b' src

printf '\nLark/Feishu constructor call sites:\n'
rg -n -C3 --type rust '\bfrom_feishu_config\s*\(|\bfrom_lark_config\s*\(|\bfrom_config\s*\(' src

Repository: zeroclaw-labs/zeroclaw

Length of output: 50378


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '=== FeishuConfig struct definition ===\n'
sed -n '3207,3230p' src/config/schema.rs

printf '\n=== from_feishu_config wiring/calls ===\n'
rg -n 'from_feishu_config|LarkChannel::from_feishu_config' --type rust

printf '\n=== LarkConfig struct mention_only field ===\n'
sed -n '3175,3190p' src/config/schema.rs

Repository: zeroclaw-labs/zeroclaw

Length of output: 2273


Feishu configuration lacks mention-gating support; don't silently default to permissive behavior.

FeishuConfig struct (lines 3207–3230 in src/config/schema.rs) does not have a mention_only field, whereas LarkConfig does. Line 397 of src/channels/lark.rs hard-codes mention_only: false when constructing a LarkChannel from Feishu config. This means every Feishu-configured bot will respond to all allowed group messages without requiring an explicit @-mention, inconsistent with Lark bots and contrary to the intent expressed in should_respond_in_group().

Per coding guidelines, "never silently broaden permissions/capabilities; document fallback behavior when fallback is intentional and safe." Either:

  1. Add mention_only field to FeishuConfig so users can opt into group-mention gating, or
  2. Explicitly error if mention-gating is unsupported, rather than silently defaulting to the more permissive behavior.

If accepting the permissive default is intentional (e.g., Feishu API does not support group-mention filtering), document that trade-off explicitly in the code.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/channels/lark.rs` around lines 390 - 398, The Feishu conversion currently
hard-codes mention_only: false in from_feishu_config, which silently broadens
group-response permissions; update the config and constructor flow by adding a
mention_only: Option<bool> (or bool with default) to the FeishuConfig struct and
propagate it into LarkChannel creation inside from_feishu_config (i.e., replace
the hard-coded false with config.mention_only.unwrap_or(false) or
config.mention_only); ensure the FeishuConfig definition (schema::FeishuConfig)
and any deserialization/defaults are updated so callers can opt into
mention-gating rather than defaulting to permissive behavior.

@rikitrader
Copy link
Copy Markdown

Thanks for the fix! This PR introduces LarkPlatform::Lark and LarkPlatform::Feishu usage but the enum type definition doesn't appear in the diff — the code won't compile without it. Also, the test fixture at line ~2114 still references use_feishu: true instead of platform: LarkPlatform::....

Could you:

  1. Add the LarkPlatform enum definition (with appropriate derives)
  2. Update the test fixture to use the new platform field

Happy to re-review once those are in.

@rareba
Copy link
Copy Markdown
Contributor

rareba commented Mar 9, 2026

Fixed the issues raised by @rikitrader:

  1. Added LarkPlatform enum to config::schema with #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema, Default)] and #[serde(rename_all = "lowercase")] so it can be used as a first-class config type. Defaults to Lark.

  2. Replaced use_feishu: bool with platform: LarkPlatform in LarkConfig. The serde default is LarkPlatform::Lark, preserving backward compatibility for configs that omit the field.

  3. Removed the local LarkPlatform enum from lark.rs and replaced it with use crate::config::schema::LarkPlatform. The impl LarkPlatform block with helper methods (api_base, ws_base, etc.) remains in lark.rs.

  4. Updated from_config to read config.platform directly instead of converting from config.use_feishu.

  5. Fixed all test fixtures in both schema.rs and lark.rs to use platform: LarkPlatform::Lark / LarkPlatform::Feishu instead of use_feishu: true/false.

  6. Updated channel wiring (channels/mod.rs) and wizard (onboard/wizard.rs) to use the typed enum comparison.

Verified: cargo check passes cleanly.

@makoMakoGo
Copy link
Copy Markdown

makoMakoGo commented Mar 9, 2026

Thanks — I only noticed this PR after opening #3081, so I closed mine as a duplicate.

Small correction to my follow-up note: the mention_only point is not part of the original compile-break from #2230. It is a follow-up behavior-consistency issue introduced by the explicit from_feishu_config() path in this patch.

Concretely: from_feishu_config() currently hard-codes mention_only = false, so Feishu group-message handling becomes broader than the Lark path even though both now share the same channel implementation. The build fix in this PR still stands on its own; I just wanted to flag this as a separate follow-up worth addressing either here or in a later small PR.

I verified that behavior locally on macOS while testing a Feishu-enabled build.

@theonlyhennygod
Copy link
Copy Markdown
Collaborator

Closing as stale — this PR has had no activity for over 2 weeks and is significantly behind master. If you'd like to continue this work, feel free to reopen with a fresh rebase against current master. Thanks for the contribution!

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.

6 participants