chore: 初始化仓库,导入项目基线代码
Academy v0.8.3 完整代码基线:Go 后端(internal/cmd/cli/mcp-server/docreader)、 Vue 前端(frontend)、数据库迁移(migrations)、部署编排(docker/helm/deploy)与文档。 今日开发的培训推送管理改动随后单独提交。
This commit is contained in:
commit
7ec21f35b0
5767 files changed
+1436788
No files matched your search
@@ -0,0 +1,52 @@
|
||||
package sourceloc
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"academy/internal/types"
|
||||
)
|
||||
|
||||
// TestAlignIndexesUniqueRowsInOnePass locks the large-table path: every row is
|
||||
// a distinct unit, and all of them must still align despite the former
|
||||
// per-key full-document scan. The linearity itself is covered by the benchmark.
|
||||
func TestAlignIndexesUniqueRowsInOnePass(t *testing.T) {
|
||||
const rows = 2000
|
||||
var md strings.Builder
|
||||
md.WriteString("| id | value |\n| --- | --- |\n")
|
||||
units := make([]Unit, 0, rows)
|
||||
for i := 0; i < rows; i++ {
|
||||
text := fmt.Sprintf("row-%04d value-%04d", i, i)
|
||||
fmt.Fprintf(&md, "| row-%04d | value-%04d |\n", i, i)
|
||||
units = append(units, Unit{Text: text, Locator: types.SourceLocator{
|
||||
Type: "sheet", Sheet: "CSV", RowStart: i + 2, RowEnd: i + 2,
|
||||
}})
|
||||
}
|
||||
blocks := Align(md.String(), units)
|
||||
if len(blocks) != len(units) {
|
||||
t.Fatalf("aligned %d of %d unique rows", len(blocks), len(units))
|
||||
}
|
||||
for i, block := range blocks {
|
||||
if block.Locator.RowStart != units[i].Locator.RowStart {
|
||||
t.Fatalf("row %d mapped to source row %d", i, block.Locator.RowStart)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Repeated keys must still be rejected unless the document and the source units
|
||||
// account for every occurrence. Prefix bucketing must not turn a TOC duplicate
|
||||
// into a false exact match.
|
||||
func TestAlignPrefixIndexKeepsDuplicateSafety(t *testing.T) {
|
||||
units := []Unit{
|
||||
{Text: "设备验收合格", Locator: types.SourceLocator{Type: "pdf", Page: 1}},
|
||||
}
|
||||
if blocks := Align("目录:设备验收合格。\n正文:设备验收合格。", units); len(blocks) != 0 {
|
||||
t.Fatalf("unaccounted duplicate aligned: %#v", blocks)
|
||||
}
|
||||
units = append(units, Unit{Text: "设备验收合格", Locator: types.SourceLocator{Type: "pdf", Page: 2}})
|
||||
blocks := Align("设备验收合格\n设备验收合格", units)
|
||||
if len(blocks) != 2 || blocks[1].Locator.Page != 2 {
|
||||
t.Fatalf("accounted duplicates = %#v", blocks)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user