refactor: simplify the operations/command layer (#49, #43)#53
Open
kfastov wants to merge 1 commit into
Open
Conversation
Internal cleanup of the op/command layer the warm-backend work produced; no change to user-visible output, errors, or exit codes. - runOperation invokes the op directly and only starts a server (then retries once) when the call fails because the server is unreachable. invoke now raises ServerUnavailableError for a missing control.json or a refused loopback connection, distinct from an op that ran and failed (a 4xx/5xx/send error) or a request timeout, neither of which spawns a server. The warm path drops from two loopback round-trips to one. - Extract one source-resolution helper for the single-result message ops (messagesGet/messagesContext): live / both / archive-then-live-fallback, whole result from a single source. Extract one result-selection helper for the list/search ops. Behavior identical. - Forward the ~16 one-line passthrough ops through a small declaration table; only composite ops (message ops, sends, anything reshaping a result or calling more than one method) stay hand-written. - Build the send args shared by send text/photo/file once instead of repeating the per-handler flag map, keeping the same validation order. - Tests: invoke-first then start-on-connection-failure (and that an op error does not spawn a server); the shared source resolution across all four source modes (no source mixing); a generic passthrough forwarding.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Cleanup of the operations/command layer the warm-backend work produced — no user-visible behavior change (same output incl
--json, same errors/exit codes). Addresses #49 and #43.Changes
runOperationnow callsinvokedirectly (one loopback round-trip on the warm path instead of ping+invoke). Only aServerUnavailableError(nocontrol.json/ refused loopback connection — detected viaisFetchConnectionFailure) triggersensureServer+ a single retry. A 4xx/5xx op error, a relayedsendError, and a request timeout/abort are NOT connection failures and never spawn a server (preserves the send-timeout contract).resolveFromSource({ source, fetchLive, fetchArchive })andselectMessageResults(...)collapse the duplicated live/both/archive/live-fallback logic acrossmessagesGet/messagesContext/messagesList/messagesSearch. Identical behavior.PASSTHROUGHStable generates 16 one-line ops viabuildPassthroughOps; only composite ops stay hand-written. All 44 ops and their result shapes are preserved (the MCP tools and/control/invokedepend on them). The threesend*handlers sharebuildCommonSendArgsinstead of each rebuilding the flag map (same validation order → same first-error).bothmerges viamergeMessageSetspreserving each row'ssource;archive→livefallback surfacesusedLiveFallback. No mixing found. TG calls: one follow-up reported (not changed, since it affects which labels appear) —resolveLiveMetadataissues an extragetPeerMetadatawhenusernameisn't cached even though the fetch already returnspeerTitle; candidate to cache/skip later.Tests
npm test→ 349 passing (336 + 13 new: invoke-first vs spawn-on-connection-failure incl. op-error-does-not-spawn, the source-resolution helper across all source modes, the generic passthrough forwarding, handlers passing args through). Nonode_modulescommitted; comments behavioral.Note
#49's "minimize TG API calls" is covered except the one reported
resolveLiveMetadataround-trip (a safe-to-defer follow-up). #43 (thin handlers) is addressed via the passthrough + shared send args.