Skip to content

Make chat connections editable, testable, and explicitly selectable - #94

Open
mdiniz97 wants to merge 6 commits into
jhd3197:mainfrom
mdiniz97:fix/chat-connection-contract
Open

Make chat connections editable, testable, and explicitly selectable#94
mdiniz97 wants to merge 6 commits into
jhd3197:mainfrom
mdiniz97:fix/chat-connection-contract

Conversation

@mdiniz97

Copy link
Copy Markdown
Contributor

Chat connections already had a delivery path, but not a complete management contract: administrators could create and delete them, but could not safely update credentials, test a disabled destination, or explicitly choose the default connection. That gap would force every new provider (including future additions) to invent its own lifecycle rules. This PR completes the shared contract first, while leaving provider-specific formatting and rich payloads for follow-up changes.

Highlights

  • Update connection metadata and encrypted credentials without allowing the provider kind to change.
  • Test active or inactive connections through the real formatter and transport path.
  • Record the latest test timestamp and outcome without exposing webhook URLs or bot tokens in API errors.
  • Select and reactivate a default connection, scoped by provider kind.
  • Reject malformed update payloads, including arrays, booleans, and explicit JSON null.
Technical changes
  • Adds the update, test, and default-selection service operations and admin API routes.
  • Validates updates before mutating the database and preserves omitted credentials.
  • Keeps the documented global Telegram bot-token fallback unchanged.
  • Uses a transient notification for tests and persists only the connection test result.
  • Returns a stable public error when formatter or transport failures occur.
  • Adds focused coverage for credential rotation, clearing, inactive tests, default scoping, secret-safe errors, and invalid JSON bodies.

Verification

  • Chat connection suite: 37 passed
  • Backend suite: 3098 passed, 98 skipped
  • Two incremental-backup tests were deselected because they require GNU tar and fail on the unchanged macOS bsdtar baseline

jhd3197 added a commit that referenced this pull request Aug 13, 2026
…ields

Follow-up to PR #94. ChatWebhookService.update() decrypted every stored
credential and re-encrypted the lot on any credential-bearing request.
decrypt_secret_safe() returns its input unchanged when a value will not
decrypt, so a wrong-key or not-yet-migrated row got wrapped a second time
and became unrecoverable -- and it happened to fields the request never
named. It now patches the ciphertext dict directly and encrypts only what
it assigns, so untouched credentials survive byte-identical.

Also tolerate an unchanged is_default in a round-tripped body (to_dict()
always emits it, so GET -> edit -> PUT rejected an untouched field), and
record the delivery failure reason in the server log. The reason stays out
of the HTTP response: transport errors embed the full webhook URL and any
Telegram bot token.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.

1 participant