Repository navigation
fix: Telegram /cancel command + forum topic sync for new projects - #69
Merged
Merged
Conversation
/cancel was advertised in the native Telegram command menu (_setCommands) but had no case in the private-chat command switch, so it fell through to "unknown command". Added _cmdCancel: clears pending attachments and lands on the dialog overview (if a session is active) or the main menu. Forum-mode project topics only synced on the initial /connect sweep, or reactively when session activity happened to reference a workdir. A project added afterward with no chat yet never got a topic. Added ensureProjectTopic() (check-then-create, idempotent) to TelegramBotForum, refactored _syncProjectTopics to use it, and wired TelegramBot#notifyProjectAdded to fan out to every connected forum right after POST /api/projects registers a project.
Adds coverage for both fixes in fc4fd21: - /cancel clears pending attachments and lands on a sane screen instead of falling through to the "unknown command" reply. - notifyProjectAdded creates exactly one topic per connected forum, is idempotent on repeat calls, and no-ops on an empty workdir. Also fixes a pre-existing test-harness leak: the media-attachment block (forum attachments land in the forum-scoped store) overwrote bot._callApi with a mock that had no createForumTopic branch and never restored the original afterward, so every test running after it silently got {} back from createForumTopic instead of a message_thread_id -- surfaced as a "cannot bind SQLite parameter 1" error swallowed by notifyProjectAdded's own catch/warn. The new tests are what exposed it; unrelated to fc4fd21's application code.
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.
Fixes
/canceldid nothing._setCommands()advertised it in Telegram's native slash menu, but_handleCommand's switch had no matchingcase, so it fell through to "Unknown command". Added the handler: clears pending attachments and returns the user to their active session dialog, or the main menu if none.Forum topics didn't appear for projects added after
/connect. Topics were only created reactively (on first chat activity) or once during the initial/connectsweep. A project added later via the Studio UI never got a topic until (if ever) some activity happened to trigger the fallback path. AddedTelegramBot#notifyProjectAdded(), called fromserver.jsright afterPOST /api/projectspersists a new project (both the local and remote-SSH branches), and a publicTelegramBotForum#ensureProjectTopic()(check-then-create, idempotent) that it delegates to.Review
Went through 3 independent parallel checks before this PR: a correctness pass, a regression/convention pass (flagged missing test coverage, since closed — see below), and an independent second opinion via Consilium (codex/gpt-5.6-terra), which flagged a theoretical TOCTOU race in
ensureProjectTopicunder concurrent calls for the same workdir. Accepted as a non-issue for now: it needs two simultaneousPOST /api/projectscalls for the same workdir from a single-user UI, andINSERT OR REPLACEonthread_idmeans the worst case is a harmless duplicate row, not corruption.Tests
Added 8 new assertions to
test/telegram-behaviour.test.js(3 for/cancel, 5 fornotifyProjectAdded: creation, idempotency, empty-workdir no-op). Also fixed a pre-existing test-harness leak found while writing these: a mock override in an earlier block never restoredbot._callApi, silently breakingcreateForumTopicfor every test after it.telegram-behaviour.test.js: 63/63 passingtelegram-format.test.js: 38/38 passing