Skip to content

Offline tests missing for some send, read, daemon and storage paths #229

Open

Description

@neoromantic

tg runs the paths below, but no offline test (bun run test or bun run test:e2e) covers them. A few are covered only by the opt-in live suite, src/test/telegram.integration.test.ts. I checked each one on main at 649eef9 by grepping the tests for it.

Send (src/commands/send.ts, src/commands/send/)

  • The USER_IS_BOT and CHAT_WRITE_FORBIDDEN messages of tg send. send.test.ts covers a local recipient error and the RICH_MESSAGE_ hints, but not these two.
  • The output of a successful tg send --file (file: { name, mimeType, size, sentAs } and attachment), and how the command wires in sendFile. Only the live suite covers them. send-file.e2e.test.ts covers argument errors, and send-file.test.ts covers sendFile and sentAttachment on their own.
  • extractMessageInfo for an updateShortSentMessage result and for updateMessageID. The results in send.test.ts all carry updateNewMessage. send-cache.test.ts covers both shapes, but for a different function: the cache write.

Read commands (src/commands/user/, src/commands/chats/, src/commands/contacts.ts)

  • tg user @username and tg user +phone through Telegram, in user/lookup.ts and user/helpers.ts: the identifier kinds, phone normalisation, contacts.resolveUsername and contacts.resolvePhone, and the USERNAME_NOT_OCCUPIED and PHONE_NOT_OCCUPIED messages. user.test.ts covers only a user ID with --fresh.
  • tg me from the API (user/me.ts), with --fresh or on a first run: getMe, the cache write, and storing the account's user_id. Also the background refresh of a stale cached me, and AUTH_REQUIRED when getMe fails. Tests read me only from the cache (multi-account.e2e.test.ts).
  • tg chats list --fresh on a cache that already holds chats, and the --type / --unread filters on the API path (filterChatsByType), in chats/list.ts. chats.test.ts covers only fetchChatsFromApi.
  • tg chats get --fresh @username (fetchChatFromApi in chats/get.ts). commands.e2e.test.ts covers only the refusal of --fresh with an ID.
  • The API paths of tg contacts search and tg contacts get. contacts.test.ts covers only contacts list --fresh.

SQL and status (src/commands/sql/query.ts, src/commands/status.ts)

  • tg sql --limit N, and the default of 1000, run through the command. applyQueryLimit and the refusal of an invalid limit are tested; nothing checks that the command applies the limit.
  • tg status lists at most 5 pending jobs (getPendingJobs().slice(0, 5)). status.e2e.test.ts tests that cap only for failed jobs.

Daemon (src/daemon/)

  • The shutdown timeout in cleanupWithTimeout (daemon.ts): warn, release the PID file, exit 1. The test context sets shutdownTimeoutMs to 1,000,000.
  • What onEditMessage in setupEventHandlers (daemon-accounts.ts) passes to handleEditMessage: the text, falling back to rich text, and the edit date. daemon-accounts.connect.test.ts only counts the handlers, and update-handlers.test.ts tests handleEditMessage on its own.
  • SIGINT. daemon-accounts.test.ts tests only the SIGTERM handler.

Storage (src/db/index.ts)

  • data.db's own upgrades in initSchema. These are the ALTER TABLE accounts ADD COLUMN steps for user_id, username and label, and migrateAndResolveDuplicates. That function gives a user:<id> phone its user_id, or deletes the row when another account already has that user_id. Every test creates data.db with the current schema.

Search and account selection

  • --phrase together with --snippet in tg messages search: the command passes phrase to snippetTerms (src/commands/messages/search.ts), but no e2e test runs both flags. snippetTerms itself is unit-tested.
  • An empty --account "", which fails with INVALID_ARGS ("Account selector cannot be empty"), and an --account @username that matches no account, which fails with ACCOUNT_NOT_FOUND. Both are in resolveAccountSelector (src/utils/account-selector.ts). The tests cover a missing ID and a missing label. Both cases behave correctly on main; there's just no test for either.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions