Files
Agent-System-Backend/pkg/extension/surface_test.go
T
weichen 727f3702d0
ci / vet-and-test (pull_request) Successful in 46s
Expose builtin document parsing through the host handle
Why: downstream parsers are unreachable via extension.Host and the base lacked xlsx/pptx parsers; MS1 needs Excel and PPT ingest (EXT-5 request, documents proposal 2026-10-06-ext-5-host-parse-document).

Evidence: local GOWORK=off go test ./... all 29 packages pass incl. new ooxml_test (hand-built parts), ooxml_python_test (openpyxl/python-pptx round-trip), inproc owner-scope and limit tests, xlsx upload e2e; go vet clean; recorded as SELF on the Dev task card, PR CI to confirm.

Impact: Host gains ParseDocument (pure compute; errors only on ctx cancel or >100MiB input); builtin:xlsx (sheet order via workbook.xml rels, rich-text shared strings, formula cache, 1900/1904 dates, sparse cells) and builtin:pptx (sldIdLst order, titles, group shapes, AlternateContent Choice, tables, notes) added with 200k-cell/64MiB-part caps; legacy doc/xls/ppt get an actionable hint; ParsersDescription gains xlsx/pptx and the missing text ext; surface snapshot now records exported interface methods; docx part reads share the 64MiB cap.

Refs: documents 2026-10-06-ext-5-host-parse-document.md; EXT-1 host.go precedent.
2026-10-06 14:59:38 +00:00

81 lines
1.9 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package extension
import (
"go/ast"
"go/parser"
"go/token"
"os"
"path/filepath"
"sort"
"strings"
"testing"
)
func TestSurfaceSnapshot(t *testing.T) {
fset := token.NewFileSet()
pkgs, err := parser.ParseDir(fset, ".", func(info os.FileInfo) bool {
return !strings.HasSuffix(info.Name(), "_test.go")
}, 0)
if err != nil {
t.Fatal(err)
}
pkg := pkgs["extension"]
if pkg == nil {
t.Fatal("package extension not parsed")
}
var names []string
for _, f := range pkg.Files {
for _, d := range f.Decls {
switch n := d.(type) {
case *ast.FuncDecl:
if n.Recv == nil && n.Name.IsExported() {
names = append(names, n.Name.Name)
}
case *ast.GenDecl:
for _, spec := range n.Specs {
switch s := spec.(type) {
case *ast.TypeSpec:
if s.Name.IsExported() {
names = append(names, s.Name.Name)
// 导出接口同时记录其方法:只加方法、不改顶层名的
// 变更同样必须更新 surface.txt(EXT-5 起执行)。
if it, ok := s.Type.(*ast.InterfaceType); ok {
for _, m := range it.Methods.List {
for _, id := range m.Names {
if id.IsExported() {
names = append(names, s.Name.Name+"."+id.Name)
}
}
}
}
}
case *ast.ValueSpec:
for _, name := range s.Names {
if name.IsExported() {
names = append(names, name.Name)
}
}
}
}
}
}
}
sort.Strings(names)
got := strings.Join(names, "\n") + "\n"
path := filepath.Join("surface.txt")
want, err := os.ReadFile(path)
if err != nil {
t.Fatal(err)
}
if got != string(want) {
t.Fatalf("public surface drifted; update surface.txt if the change is intentional\n got:\n%s\nwant:\n%s", got, want)
}
}
func TestMainWithoutLink(t *testing.T) {
SetRunner(nil)
if err := Main(Options{}); err != ErrNotLinked {
t.Fatalf("got %v", err)
}
}