Skip to content

notify: make the summary and asset limits configurable - #172

Merged
BaaRai merged 1 commit into
mainfrom
feat/notify-configurable-limits
Nov 10, 2026
Merged

BaaRai merged 1 commit into
mainfrom
feat/notify-configurable-limits

Conversation

@BaaRai

@BaaRai BaaRai commented Nov 10, 2026

Copy link
Copy Markdown
Owner

What

The summary length and the number of assets listed in IM notifications are now two global settings instead of the fixed constants maxSummaryRunes = 120 and maxAssetsShown = 3. This is the second change for #168; the "and N more" count was fixed in #170.

Key (settings table, GET/PUT /api/settings) Default when unset Bounds 0
notify_summary_max_runes 120 0–4000 no truncation
notify_assets_max_shown 3 0–50 no truncation
  • notify/: Message carries an optional Limits; nil renders with the old 120 / 3. The DingTalk/WeCom markdown, Feishu card, Telegram and email renderers read it instead of the constants, which stay as DefaultMaxSummaryRunes / DefaultMaxAssetsShown. The package still does not touch the database.
  • server/: the two keys sit next to the other notify_* settings and use the same GetSetting / SetSetting store. The delivery engine reads them when it renders (realtime and digest), and so does the channel test message. PUT /api/settings answers 400 for a value outside the bounds; a stored value that is unparseable or out of bounds reads as the default.
  • Feishu guard: with 0, nothing bounded a single item in a card, and Feishu rejects an oversized request as a whole. feishuCard now truncates an item's text as the final backstop, the role TruncateBytes plays in markdownBody for DingTalk (20000 bytes) and WeCom (4096 bytes).

Why

Reported in #168: on a host with no link-back URL the IM message is the only place a reviewer sees the finding, and 120 characters / 3 assets could not be changed.

Decisions to review

  • feishuMaxCardBytes goes from 24000 to 16000. The Feishu custom bot guide caps the request body at 20 KB ("发送消息时,请求体的数据大小不能超过 20 KB"), so a guard at 24000 would not have kept a message inside the limit. This also makes Feishu digests split a little earlier than before. The new test measures the request body sent on the wire: 16157 bytes for a single push and 16370 for a digest with an oversized first item; with the constant back at 24000 it fails at 24157 and 24370.
  • The guard counts the item text in raw bytes, like the DingTalk guard and the existing digest packing. JSON escaping, the card title in the header and the per-item wrapper of a digest are covered only by the 4000-byte margin, not counted. A Feishu digest of several hundred short items can therefore still exceed 20 KB; that was already the case before this change and is not addressed here.
  • The digest one-liners keep their own fixed 60-character summary (markdown and email). Only the asset limit applies to digest lines.
  • The channel test message uses the stored limits too, so it previews what real messages look like.

Not included

Verification

Run in WSL (Go 1.26.10, linux/amd64) on the committed tree, against a throwaway postgres:16-alpine container that was removed afterwards.

  • gofmt: clean on the changed files. server/server.go has one unformatted struct that is already unformatted on main; this change does not touch it.
  • go build ./...: pass. go vet ./...: pass.
  • ARTEX_PG_DSN=... go test -p 1 ./... -count=1 on a fresh database (the CI command): pass, all 14 packages with tests ok, 0 failures.
  • go test -race ./notify -count=1: pass.
  • New tests, all run and passing:
    • notify, no database: TestMessageLimitsApplyToSinglePush (unset / 0 / custom values across the markdown, Feishu, Telegram and email renderers), TestMessageLimitsApplyToDigestAssets, TestFeishuUntruncatedItemStaysWithinBodyLimit.
    • server, no database: TestNotifyLimitValue.
    • server, Postgres: TestNotifyLimitSettingsRoundTrip (unset reads 120 / 3; 500/10, 0/0 and 4000/50 round-trip through PUT /api/settings, the settings rows and the delivery engine's reader; -1, 4001 and 51 answer 400 and leave the stored value alone), TestNotifySummaryLimitReachesDelivery (a 300-character summary is cut at 120 with the key unset and sent whole to a fake DingTalk receiver once the key is 0).
  • The Feishu guard test was checked against two mutations: it fails with the constant back at 24000, and with the truncation disabled (68418-byte body).
  • go test ./... -count=1 without ARTEX_PG_DSN: every package passes except server, where 44 tests fail with "no database config found". 42 of them are existing tests; the 2 new Postgres tests use the same fixture and fail the same way instead of skipping.

Not verified:

  • No message was sent to a real Feishu, DingTalk, WeCom or Telegram endpoint. The 20 KB figure comes from Feishu's documentation, not from a rejected request.
  • Asset-limit behaviour end to end through Postgres (only the summary limit has an end-to-end test; the asset limit is covered by the renderer tests and the settings round-trip).
  • The web UI was not built or run; this change has no frontend part.
  • A second full run on the same database fails 4 db tests on duplicate rows left by the first run. CI already notes that the db tests are not idempotent across runs; this change does not touch db/.

Do not merge before go, shell and web are green on the exact head SHA.

The IM renderers cut the summary of a single push at 120 characters and
listed at most 3 assets, as fixed constants. Both are now global settings
in the settings table, read by the delivery engine when it renders:

  notify_summary_max_runes   0-4000, default 120
  notify_assets_max_shown    0-50,   default 3

0 means no truncation and an unset key keeps 120 / 3. PUT /api/settings
answers 400 for a value outside the bounds. The limits travel on
notify.Message, so the notify package still does not touch the database.

With no truncation, nothing bounded a single item in a Feishu card, and
Feishu rejects an oversized request as a whole. feishuCard now truncates
an item's text as the final backstop, the role TruncateBytes plays in
markdownBody for DingTalk and WeCom. feishuMaxCardBytes goes from 24000
to 16000: Feishu custom bots cap the request body at 20 KB, which the old
value exceeded.

Refs #168.
@BaaRai
BaaRai merged commit 3b6eb2f into main Nov 10, 2026
4 checks passed
tuhoangwkm pushed a commit to tuhoangwkm/ARTEX that referenced this pull request Nov 11, 2026
PR BaaRai#172 made the summary length and the number of assets listed in an IM
message configurable, but only through the API. The Notifications page now
shows both next to the other global settings:

  Summary length (characters)   notify_summary_max_runes   0-4000
  Assets listed per finding     notify_assets_max_shown    0-50

The values are read from GET /api/settings (they are not part of
/notify/meta) and saved with the existing "Save global settings" PUT.
Each field carries a help text stating that 0 means no truncation.

A value that is not a whole number within the bounds marks the input
invalid and blocks the save with a toast. The check runs before the
request because the backend applies the fields of one PUT in order, so a
400 on a limit would leave the URL and digest interval already saved. An
empty field is not submitted and keeps the stored value.
@BaaRai BaaRai mentioned this pull request Nov 11, 2026
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