Files
ragflow/internal/ingestion/pipeline/pipeline_knowledge_compiler_test.go
Jack 5ba8c4febb chore(go): classify tests into unit/integration/e2e/manual tiers via build tags (#17586)
## Summary
Classify the Go test suite by dependency level using build tags so the
default
`go test ./...` run stays self-contained, and add local convenience
commands
plus a documented convention.

- Add build tags to 5 real-service tests that were previously un-tagged
and only
soft-isolated via `t.Skip`: `kg_test.go` (integration), `minio_test.go`
  (integration), `template_integration_test.go` (integration),
`stagehand_runtime_integration_test.go` (integration),
`pipeline_e2e_test.go` (e2e).
  The default unit run no longer compiles/attempts these.
- Reclassify the full-pipeline `real_consumer` tests from `integration`
to `e2e`.
- Add `build.sh` shortcuts: `--test-integration`, `--test-e2e`,
`--test-manual`,
`--test-all` (integration + e2e; `manual` is excluded and is local
opt-in only,
  never run in CI).
- Document the tier scheme (unit / integration / e2e / manual +
orthogonal cgo) in
  `AGENTS.md`.

## Tier definitions
| Tier | Build tag | Runs by default? |
|---|---|---|
| Unit | (none) | Yes — in-memory SQLite / miniredis / httptest stubs |
| Integration | `integration` | No (`-tags integration`) — single real
service |
| E2E | `e2e` | No (`-tags e2e`) — full ingest→index→retrieve pipeline |
| Manual | `manual` | No (`-tags manual`) — very slow; never in CI |

## Verification
- `gofmt -l` clean on all changed files; `bash -n build.sh` OK.
- `go list` confirms the default set excludes the tagged files, and
  `-tags integration` / `-tags e2e` include them.
- Full regression: unit / integration / e2e each **97 ok, 0 FAIL**.
- Fixed a regression where `pipeline_knowledge_compiler_test.go` relied
on a
transitive import side-effect from `template_integration_test.go` to
register
the `File`/`Parser`/`TokenChunker` components; it now blank-imports the
  component packages directly.

## Test plan
- [ ] `./build.sh --test` (unit) passes
- [ ] `./build.sh --test-integration` passes (needs real services; skips
otherwise)
- [ ] `./build.sh --test-e2e` passes (needs real services; skips
otherwise)

---------

Co-authored-by: CodeBuddy <noreply@cnb.cool>
2026-07-31 11:52:48 +08:00

75 lines
2.9 KiB
Go

//
// Copyright 2026 The InfiniFlow Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package pipeline
import (
"os"
"path/filepath"
"testing"
// Blank-import the KnowledgeCompiler component so its runtime.MustRegister
// init hook fires and the component name referenced by the template is
// resolvable in the default runtime factory.
"ragflow/internal/agent/runtime"
// Blank-import the parent component package so its init registers the
// File/Parser/TokenChunker components this test's template references.
_ "ragflow/internal/ingestion/component"
_ "ragflow/internal/ingestion/component/chunker"
_ "ragflow/internal/ingestion/component/knowledge_compiler"
)
// TestKnowledgeCompilerTemplate_RegisteredAndDecodable verifies the
// knowledge_compiler ingestion template is loaded by the built-in registry,
// carries the expected title, references runtime-registered components, and
// decodes into a pipeline via NewPipelineFromDSL. A full Run is intentionally
// not exercised here: it needs real LLM/embedder/ES wiring (covered by the
// knowledge_compiler component E2E tests) and is skipped in the headless
// chunks-smoke test.
func TestKnowledgeCompilerTemplate_RegisteredAndDecodable(t *testing.T) {
r, err := DefaultRegistry()
if err != nil {
t.Fatalf("DefaultRegistry: %v", err)
}
tpl, ok := r.Get("knowledge_compiler")
if !ok {
t.Fatal("knowledge_compiler template not registered in built-in registry")
}
if tpl.Title != "Knowledge Compiler" {
t.Fatalf("title = %q, want 'Knowledge Compiler'", tpl.Title)
}
// Ensure the default runtime factory is installed, then confirm every
// component_name the template references is actually registered.
runtime.InstallDefaultRegistryFactory()
if runtime.DefaultFactory() == nil {
t.Fatal("default runtime factory not installed")
}
for _, name := range []string{"File", "Parser", "TokenChunker", "KnowledgeCompiler"} {
if _, _, _, ok := runtime.DefaultRegistry.Lookup(name); !ok {
t.Errorf("component %q referenced by template is not registered in the runtime factory", name)
}
}
path := filepath.Join(repoRootFromPipelineTest(t), "internal", "ingestion", "pipeline", "template", "ingestion_pipeline_knowledge_compiler.json")
raw, err := os.ReadFile(path)
if err != nil {
t.Fatalf("read template: %v", err)
}
if _, err := NewPipelineFromDSL(raw, "kc-validation"); err != nil {
t.Fatalf("NewPipelineFromDSL: %v", err)
}
}