Skip to content

refactor(code-quality): typed errors, test module gating, deferred TODO markers#3401

Merged
bug-ops merged 4 commits intomainfrom
code-quality-improvements
Apr 25, 2026
Merged

refactor(code-quality): typed errors, test module gating, deferred TODO markers#3401
bug-ops merged 4 commits intomainfrom
code-quality-improvements

Conversation

@bug-ops
Copy link
Copy Markdown
Owner

@bug-ops bug-ops commented Apr 25, 2026

Summary

Code quality improvements pass — scoped to changes that do not introduce new abstractions or architectural rewrites (per CLAUDE.md v1.0 directive and critic review).

E1/E2 — Typed error variants

Replace Other(String) catch-all with specific typed variants across LlmError, AgentError, ChannelError, MemoryError:

  • ApiError { provider, status } — HTTP errors from LLM providers (no raw body exposure)
  • ContextLengthExceeded, RateLimited, Unavailable — provider state variants
  • InvalidInput { provider, message } — structured 400 responses
  • NoActiveSession — channel state (replaces stringly-typed Other("no active chat"))
  • StructuredParse — structured output parse failures

is_context_length_error() now matches on typed variant instead of substring-matching English text. body_is_context_length_error() is pub(crate) transport-layer helper.

C1 — Gate test scaffolding behind cfg

pub mod testing / pub mod mock in production builds: zeph-core, zeph-llm, zeph-memory, zeph-mcp all gated behind #[cfg(any(test, feature = "testing"))]. Verified testing feature is absent from all default and full feature sets.

F1 — Naming cleanup

SkillRegistry::get_skillskill, get_bodybody (drops redundant get_ prefix).

Deferred TODO markers

Architectural items that exceed the scope of this PR are documented at their deferral points:

  • A1Agent<C> god object decomposition (zeph-core/src/agent/mod.rs)
  • A2 — Typestate builder (zeph-core/src/agent/builder.rs)
  • A3Channel trait split into sub-traits (zeph-core/src/channel.rs)
  • D1AnyProviderArc<dyn LlmProvider> (zeph-llm/src/any.rs)
  • D2/G3ToolExecutor consolidation + middleware stack (zeph-tools/src/executor.rs)
  • D4 — Typed config presets (zeph-config/src/lib.rs)
  • B2/B3 — Unjustified allow(clippy::too_many_lines/arguments) (7 sites)

Validation

  • cargo +nightly fmt --check: pass
  • cargo clippy --workspace --lib --bins -- -D warnings: 0 warnings
  • cargo nextest run --workspace --lib --bins: 8500 passed / 0 failed
  • cargo check --workspace: pass
  • Security audit: clean (no new vulnerabilities, no unsafe, test modules correctly gated)

bug-ops added 3 commits April 25, 2026 19:21
…ariants

Add ApiError { provider, status } to LlmError to replace the common pattern
of wrapping non-success HTTP responses in Other(String). Add NoActiveSession
to ChannelError to replace Other("no active chat"/"no active channel") across
telegram, discord, and slack adapters.

Move context-length detection from is_context_length_error() into a
pub(crate) body_is_context_length_error() helper used at the transport layer
in each provider (claude, openai, gemini). is_context_length_error() now only
matches ContextLengthExceeded, removing the string-heuristic fallback.

Update all affected tests to assert on the new typed error format.
… markers

- Gate pub mod testing/mock behind #[cfg(any(test, feature = "testing"))]
  in zeph-core, zeph-llm, zeph-memory, zeph-mcp (C1)
- Add TODO comments at deferral points for A1 (Agent god object), A2 (typestate
  builder), A3 (Channel trait split), D1 (AnyProvider object safety), D2/G3
  (ToolExecutor consolidation + middleware), D4 (config presets)
- Rename SkillRegistry::get_skill/get_body to skill/body (F1 naming cleanup)
…essions

Add TODO(B2)/TODO(B3) comments to allow(clippy::too_many_lines) and
allow(clippy::too_many_arguments) attributes that had no justification comment,
making it clear these are deferred refactors rather than accepted exceptions.
@github-actions github-actions Bot added llm zeph-llm crate (Ollama, Claude) skills zeph-skills crate memory zeph-memory crate (SQLite) channels zeph-channels crate (Telegram) rust Rust code changes core zeph-core crate dependencies Dependency updates refactor Code refactoring without functional changes size/XL Extra large PR (500+ lines) labels Apr 25, 2026
@bug-ops bug-ops enabled auto-merge (squash) April 25, 2026 17:42
@bug-ops bug-ops merged commit f13086d into main Apr 25, 2026
32 checks passed
@bug-ops bug-ops deleted the code-quality-improvements branch April 25, 2026 17:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channels zeph-channels crate (Telegram) core zeph-core crate dependencies Dependency updates llm zeph-llm crate (Ollama, Claude) memory zeph-memory crate (SQLite) refactor Code refactoring without functional changes rust Rust code changes size/XL Extra large PR (500+ lines) skills zeph-skills crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant