feat(dingtalk): per-frame wide-table grouping (stream keeps tables flowing while streaming)
This commit is contained in:
@@ -81,19 +81,45 @@ func TestNormalizeKeepsWideTableWhenGroupingDisabled(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestRewriteOutboundContentWideTableGroupingToggle proves the handler wires
|
||||
// the switch through to the final frame, which is what the client sees.
|
||||
func TestRewriteOutboundContentWideTableGroupingToggle(t *testing.T) {
|
||||
func TestTableGroupingForMode(t *testing.T) {
|
||||
cases := []struct {
|
||||
mode string
|
||||
wantPartial bool
|
||||
wantFinal bool
|
||||
}{
|
||||
{mode: "", wantPartial: true, wantFinal: true},
|
||||
{mode: "on", wantPartial: true, wantFinal: true},
|
||||
{mode: "weird", wantPartial: true, wantFinal: true},
|
||||
{mode: "off", wantPartial: false, wantFinal: false},
|
||||
{mode: "NO", wantPartial: false, wantFinal: false},
|
||||
{mode: "stream", wantPartial: true, wantFinal: false},
|
||||
{mode: " Stream ", wantPartial: true, wantFinal: false},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
partial, final := tableGroupingForMode(tc.mode)
|
||||
if partial != tc.wantPartial || final != tc.wantFinal {
|
||||
t.Fatalf("tableGroupingForMode(%q) = (%v,%v), want (%v,%v)", tc.mode, partial, final, tc.wantPartial, tc.wantFinal)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestWideTableGroupingPerFrame proves the switch reaches both frames the card
|
||||
// renders: the streaming frames and the final one. The streaming path drops
|
||||
// unstable table blocks, so with grouping off a partial frame simply carries no
|
||||
// table at all.
|
||||
func TestWideTableGroupingPerFrame(t *testing.T) {
|
||||
wide := "| 对比项 | CR 系列 | CRA 系列 |\n| :--- | :--- | :--- |\n| **关节最大速度** | " +
|
||||
strings.Repeat("J1: 180°/s (CR3A/5A/7A) ", 6) + " | CC262 |"
|
||||
const tableMarker, groupMarker = "| 对比项 |", "- CR 系列:"
|
||||
cases := []struct {
|
||||
name string
|
||||
disabled bool
|
||||
wantTable bool
|
||||
wantDetail string
|
||||
name string
|
||||
mode string
|
||||
partialWant [2]bool // [grouped, table]
|
||||
finalWant [2]bool // [grouped, table]
|
||||
}{
|
||||
{name: "grouping enabled rewrites wide table", disabled: false, wantTable: false, wantDetail: "**关节最大速度**"},
|
||||
{name: "grouping disabled keeps wide table", disabled: true, wantTable: true, wantDetail: "| 对比项 |"},
|
||||
{name: "default groups every frame", mode: "", partialWant: [2]bool{true, false}, finalWant: [2]bool{true, false}},
|
||||
{name: "off keeps the table on the final frame", mode: "off", partialWant: [2]bool{false, false}, finalWant: [2]bool{false, true}},
|
||||
{name: "stream groups partial and keeps the final table", mode: "stream", partialWant: [2]bool{true, false}, finalWant: [2]bool{false, true}},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
@@ -101,17 +127,25 @@ func TestRewriteOutboundContentWideTableGroupingToggle(t *testing.T) {
|
||||
TenantConfig{TenantKey: "tenant-a", Channel: "dingtalk"},
|
||||
&fakeQA{},
|
||||
&fakeReply{},
|
||||
HandlerOptions{WideTableGroupingDisabled: tc.disabled},
|
||||
HandlerOptions{WideTableGrouping: tc.mode},
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("NewHandlerWithOptions: %v", err)
|
||||
}
|
||||
got := h.rewriteOutboundContent(context.Background(), wide)
|
||||
if strings.Contains(got, "| 对比项 |") != tc.wantTable {
|
||||
t.Fatalf("table present = %v, want %v, got %q", strings.Contains(got, "| 对比项 |"), tc.wantTable, got)
|
||||
frames := map[string]struct {
|
||||
got string
|
||||
want [2]bool
|
||||
}{
|
||||
"partial": {got: h.sanitizeOutboundPartial(context.Background(), wide), want: tc.partialWant},
|
||||
"final": {got: h.rewriteOutboundContent(context.Background(), wide), want: tc.finalWant},
|
||||
}
|
||||
if !strings.Contains(got, tc.wantDetail) {
|
||||
t.Fatalf("missing %q in %q", tc.wantDetail, got)
|
||||
for name, frame := range frames {
|
||||
grouped := strings.Contains(frame.got, groupMarker)
|
||||
table := strings.Contains(frame.got, tableMarker)
|
||||
if grouped != frame.want[0] || table != frame.want[1] {
|
||||
t.Fatalf("%s frame: grouped=%v table=%v, want grouped=%v table=%v, got %q",
|
||||
name, grouped, table, frame.want[0], frame.want[1], frame.got)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user