- 重新实现Markdown追加分片,确保每个分片为完整独立的顶级区块序列,满足update_document追加模式要求 - 修复分片过程中丢失换行符导致标题等Markdown元素识别错误的问题 - 解决超大表格和代码块被截断在单元格或代码围栏中间的问题 - 修正读取回写验证,避免与服务器未接收的内容比较导致验证失败 - 统一多条Markdown写入路径,统一分片逻辑与分片大小限制(30000字符) - doc update --index参数在内容需分片时改为失败,避免不可预期的插入位置 - 添加分片写入过程中的降级变更通知字段,明确分片对文档结构的影响 - 优化写入流水线,增强超长内容自动分片支持和错误处理逻辑 - 补充分片相关的单元测试,保障内容完整性及边界拆分行为
39 lines
1.6 KiB
Go
39 lines
1.6 KiB
Go
// Copyright 2026 Alibaba Group
|
|
// Licensed under the Apache License, Version 2.0
|
|
|
|
package smart
|
|
|
|
import (
|
|
"errors"
|
|
"strings"
|
|
"testing"
|
|
|
|
apperrors "github.com/DingTalk-Real-AI/dingtalk-workspace-cli/internal/errors"
|
|
"github.com/DingTalk-Real-AI/dingtalk-workspace-cli/internal/helpers"
|
|
)
|
|
|
|
func TestCrossPlatformCoverageDocAppendRejectsOversizedText(t *testing.T) {
|
|
// +doc-append takes --text from argv only (no @file, no stdin) and writes via
|
|
// CallMCP, which returns just an error and so cannot report partial progress
|
|
// across chunks. Rather than grow a second chunk loop here, oversized input
|
|
// is pointed at the command that already chunks, repeats table headers and
|
|
// verifies.
|
|
fake := &stubMailboxCaller{}
|
|
long := strings.Repeat("字", helpers.DefaultMarkdownChunkRunes+1)
|
|
err := runShortcutErr(t, fake, "doc", "+doc-append", "--doc", "node-1", "--text", long, "--yes")
|
|
var typed *apperrors.Error
|
|
if err == nil || !errors.As(err, &typed) || typed.Reason != "doc_append_content_too_long" {
|
|
t.Fatalf("expected a fail-closed validation error, got %#v", err)
|
|
}
|
|
if !strings.Contains(strings.Join(typed.Actions, " "), "+update") {
|
|
t.Errorf("error must point at the chunking command: %#v", typed.Actions)
|
|
}
|
|
|
|
// Exactly at the limit is still allowed, so the guard is a ceiling rather
|
|
// than an off-by-one refusal.
|
|
atLimit := strings.Repeat("字", helpers.DefaultMarkdownChunkRunes)
|
|
if err := runShortcutErr(t, fake, "doc", "+doc-append", "--doc", "node-1", "--text", atLimit, "--yes"); err != nil {
|
|
t.Fatalf("content at the limit must be accepted: %v", err)
|
|
}
|
|
}
|