项目文件夹

文件
wehub-resource-sync a06f331eb8
CI / benchmark (push) Has been skipped
install-script / posix-syntax (push) Successful in 6m1s
CI / build-onnx (push) Failing after 6m43s
init-smoke / dry-run (push) Failing after 15m57s
security / govulncheck (push) Has been cancelled
security / trivy-fs (push) Has been cancelled
CI / test (1.26, ubuntu-latest) (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
CI / test (1.26, macos-latest) (push) Has been cancelled
CI / build-windows (push) Has been cancelled
CI / lint (push) Has been cancelled
install-script / powershell-syntax (push) Has been cancelled
install-script / install (macos-14) (push) Has been cancelled
install-script / install (ubuntu-latest) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:33:42 +08:00

101 行
3.0 KiB
Go

package indexer
import (
"path/filepath"
"testing"
"github.com/stretchr/testify/require"
"go.uber.org/zap"
"github.com/zzet/gortex/internal/config"
"github.com/zzet/gortex/internal/graph"
"github.com/zzet/gortex/internal/parser"
"github.com/zzet/gortex/internal/parser/languages"
)
// TestStripConfigArtifacts_PreservesDocFrontmatter verifies the strip pass
// (run when the `configs` coverage domain is gated off, the default) drops
// code-origin config keys but keeps document-frontmatter keys — so a
// Quarto .qmd's declared metadata stays searchable.
func TestStripConfigArtifacts_PreservesDocFrontmatter(t *testing.T) {
result := &parser.ExtractionResult{
Nodes: []*graph.Node{
{ID: "cfg::env::AWS_SECRET", Kind: graph.KindConfigKey, Name: "AWS_SECRET", Meta: map[string]any{"source": "env"}},
{ID: "report.qmd::cfg:title", Kind: graph.KindConfigKey, Name: "title", Meta: map[string]any{"source": "quarto_frontmatter"}},
{ID: "k8s::cfg::REPLICAS", Kind: graph.KindConfigKey, Name: "REPLICAS", Meta: map[string]any{"origin": "k8s"}},
{ID: "report.qmd", Kind: graph.KindFile, Name: "report.qmd"},
},
Edges: []*graph.Edge{
{From: "report.qmd", To: "report.qmd::cfg:title", Kind: graph.EdgeDefines},
{From: "svc.go::Load", To: "cfg::env::AWS_SECRET", Kind: graph.EdgeReadsConfig},
},
}
stripConfigArtifacts(result)
has := func(id string) bool {
for _, n := range result.Nodes {
if n.ID == id {
return true
}
}
return false
}
if has("cfg::env::AWS_SECRET") {
t.Error("code-origin config key should be stripped when the configs domain is off")
}
if !has("report.qmd::cfg:title") {
t.Error("quarto frontmatter config key must survive the configs-domain strip")
}
if !has("k8s::cfg::REPLICAS") {
t.Error("infra-origin config key must survive the strip")
}
defines, reads := 0, 0
for _, e := range result.Edges {
switch e.Kind {
case graph.EdgeDefines:
defines++
case graph.EdgeReadsConfig:
reads++
}
}
if defines != 1 {
t.Errorf("EdgeDefines to surviving frontmatter key = %d, want 1", defines)
}
if reads != 0 {
t.Errorf("reads_config edges = %d, want 0 (dropped with the domain)", reads)
}
}
// TestIndex_QuartoFrontmatterSurvivesDefaultConfig is the end-to-end guard:
// indexing a .qmd with the default config (configs domain off) still yields
// the frontmatter keys as graph nodes.
func TestIndex_QuartoFrontmatterSurvivesDefaultConfig(t *testing.T) {
dir := t.TempDir()
writeFile(t, filepath.Join(dir, "report.qmd"), `---
title: My Report
format: html
---
# Introduction
Some prose.
`)
reg := parser.NewRegistry()
reg.Register(languages.NewQuartoExtractor())
cfg := config.Default().Index
cfg.Workers = 2
g := graph.New()
idx := New(g, reg, cfg, zap.NewNop())
_, err := idx.Index(dir)
require.NoError(t, err)
if len(g.FindNodesByName("title")) == 0 {
t.Error("quarto frontmatter key 'title' missing from default-config index")
}
if len(g.FindNodesByName("format")) == 0 {
t.Error("quarto frontmatter key 'format' missing from default-config index")
}
}