fix(dingtalk): keep streaming frames growing while a table forms

A table that starts forming made stableMarkdownPrefix truncate every
streaming frame at the table start, so the card froze and the whole table
plus tail arrived in the single finalize frame (live: 5.2 KB dump after the
answer had already finished upstream).

Add the DINGTALK_CARD_WIDE_TABLE_GROUP=smooth mode: over-wide tables are
grouped on every frame (as "on") and, while streaming, every table is
grouped so no table block survives into a partial frame. The final frame
keeps the real table whenever it lays out safely.
This commit is contained in:
hermes
2026-09-20 10:07:55 +08:00
parent 1bbaf2f07a
commit 30a95ef08a
6 changed files with 109 additions and 18 deletions
+3 -1
View File
@@ -12,13 +12,15 @@ import (
// unset / on → grouped list on every frame (historical behaviour)
// off → real tables on every frame
// stream → grouped list while streaming, real table on the final frame
// smooth → like "on", and every table is grouped while streaming so a
// table forming mid-answer no longer freezes the card
//
// The default stays "on" so an environment without the variable renders exactly
// as before; DINGTALK_CARD_WIDE_TABLE_GROUP selects the other modes.
func cardWideTableGroupingMode() string {
mode := strings.ToLower(strings.TrimSpace(os.Getenv("DINGTALK_CARD_WIDE_TABLE_GROUP")))
switch mode {
case "off", "0", "false", "no", "stream", "streaming", "partial":
case "off", "0", "false", "no", "stream", "streaming", "partial", "smooth":
log.Printf("DingTalk wide-table grouping mode=%s", mode)
return mode
default:
+4
View File
@@ -232,6 +232,10 @@ func TestCardWideTableGroupingMode(t *testing.T) {
if got := cardWideTableGroupingMode(); got != "" {
t.Fatalf("on is the default and must not be forwarded as a mode, got %q", got)
}
t.Setenv("DINGTALK_CARD_WIDE_TABLE_GROUP", "SMOOTH")
if got := cardWideTableGroupingMode(); got != "smooth" {
t.Fatalf("smooth must be normalised, got %q", got)
}
}
func TestMainDoesNotExposeWebAdministrationOrSetupOnlyMode(t *testing.T) {