Anydoc / anydoc parser engine (push) Canceled after 0s
App / Format, vet, test, and build (push) Canceled after 0s
CLI / test (macos-latest / go 1.26) (push) Canceled after 0s
CLI / test (ubuntu-latest / go 1.26) (push) Canceled after 0s
CLI / test (windows-latest / go 1.26) (push) Canceled after 0s
Build and Push Docker Image / build-ui (push) Canceled after 0s
Build and Push Docker Image / build-docreader (push) Canceled after 0s
Build and Push Docker Image / build-sandbox (push) Canceled after 0s
Build and Push Docker Image / build-app (amd64, linux/amd64, ubuntu-latest) (push) Canceled after 0s
Build and Push Docker Image / build-app (arm64, linux/arm64, ubuntu-24.04-arm) (push) Canceled after 0s
DocReader / Python tests and Go client tests (push) Canceled after 0s
Build & Publish (dsh-weknora) / Typecheck, test, pack (push) Canceled after 0s
Build & Publish (dsh-weknora) / End-to-end inside dsh (pinned) (push) Canceled after 0s
Build & Publish (dsh-weknora) / End-to-end inside dsh (latest, advisory) (push) Canceled after 0s
Frontend / Test, type-check, and build (push) Canceled after 0s
Go Lint Cache / warm lint cache (.) (push) Canceled after 0s
Go Lint Cache / warm lint cache (cli) (push) Canceled after 0s
Go Lint Cache / warm lint cache (client) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.10) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.11) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.12) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.13) (push) Canceled after 0s
Build and Push Docker Image / merge (push) Canceled after 0s
Build & Publish (dsh-weknora) / Publish to npm (push) Canceled after 0s
Build & Publish (mcp-server) / Build sdist + wheel (push) Canceled after 0s
Build & Publish (mcp-server) / Publish to PyPI (push) Canceled after 0s
64 lines
2.5 KiB
Go
64 lines
2.5 KiB
Go
package service
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/Tencent/WeKnora/internal/types"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
type digitalHumanTestReader struct {
|
|
request *types.ReadRequest
|
|
result *types.ReadResult
|
|
err error
|
|
}
|
|
|
|
func (r *digitalHumanTestReader) Read(_ context.Context, request *types.ReadRequest) (*types.ReadResult, error) {
|
|
r.request = request
|
|
return r.result, r.err
|
|
}
|
|
|
|
func TestDigitalHumanUploadPreservesSubtitleEvidence(t *testing.T) {
|
|
service := &DigitalHumanService{}
|
|
for _, ext := range []string{"TXT", "md", "markdown", "srt", "vtt"} {
|
|
source, err := service.readDigitalHumanUpload(context.Background(), DigitalHumanUpload{Name: "source." + ext, Data: []byte("\ufeff1\n00:00:01,000 --> 00:00:02,000\nOriginal words\n")})
|
|
require.NoError(t, err)
|
|
require.Equal(t, "1\n00:00:01,000 --> 00:00:02,000\nOriginal words", source.Text)
|
|
}
|
|
}
|
|
|
|
func TestDigitalHumanUploadRejectsInvalidOrTruncatedMaterials(t *testing.T) {
|
|
service := &DigitalHumanService{}
|
|
for _, file := range []DigitalHumanUpload{
|
|
{Name: "source.exe", Data: []byte("text")},
|
|
{Name: "empty.pdf"},
|
|
{Name: "empty.txt", Data: []byte(" \n")},
|
|
{Name: "invalid.txt", Data: []byte{0xff}},
|
|
{Name: "large.pdf", Data: make([]byte, DigitalHumanFileLimit+1)},
|
|
{Name: "too-many-words.txt", Data: []byte(strings.Repeat("x", digitalHumanSourceLimit+1))},
|
|
} {
|
|
_, err := service.readDigitalHumanUpload(context.Background(), file)
|
|
require.Error(t, err, file.Name)
|
|
}
|
|
}
|
|
|
|
func TestDigitalHumanUploadDispatchesDocumentsToReader(t *testing.T) {
|
|
if types.DefaultParserEngine("pdf") == "anydoc" {
|
|
t.Skip("linked builds exercise the local parser instead of the remote transport")
|
|
}
|
|
reader := &digitalHumanTestReader{result: &types.ReadResult{MarkdownContent: "# Source\nAll source evidence"}}
|
|
service := &DigitalHumanService{reader: reader}
|
|
for _, ext := range []string{"doc", "docx", "pdf", "ppt", "pptx", "rtf", "odt"} {
|
|
source, err := service.readDigitalHumanUpload(context.Background(), DigitalHumanUpload{Name: "source." + ext, Data: []byte("document bytes")})
|
|
require.NoError(t, err, ext)
|
|
require.Equal(t, "# Source\nAll source evidence", source.Text)
|
|
require.Equal(t, ext, reader.request.FileType)
|
|
require.Equal(t, "false", reader.request.ParserEngineOverrides["anydoc_extract_images"])
|
|
}
|
|
reader.result = &types.ReadResult{}
|
|
_, err := service.readDigitalHumanUpload(context.Background(), DigitalHumanUpload{Name: "scan.pdf", Data: []byte("scan")})
|
|
require.Error(t, err)
|
|
}
|