Skip to content

refactor(ingestion): cleanup — stdlib reuse and shared component names - #21149

Merged
yuzhichang merged 1 commit into
infiniflow:mainfrom
xugangqiang:refactor/ingestion-p0-cleanup
Oct 19, 2026
Merged

yuzhichang merged 1 commit into
infiniflow:mainfrom
xugangqiang:refactor/ingestion-p0-cleanup

Conversation

@xugangqiang

Copy link
Copy Markdown
Contributor

What

Second batch of zero-risk cleanups from the ingestion pipeline review (the P0 items; the deep-copy consolidation was deferred as P1):

  • component: drop the contains wrapper around slices.Contains; the three tokenizer call sites call the stdlib directly.
  • knowledge_compiler: mapKeys is now slices.Sorted(maps.Keys(m)) instead of a hand-written loop + sort.Strings.
  • component: extract newExtractorChatConfig from resolveExtractorChatConfig / resolveExtractorChatDefaultConfig, whose apiKey/baseURL extraction and config construction were byte-identical. Both functions were previously untested; the new tests cover the composite and tenant-default paths, mixed-case driver names, nil api configs, resolver errors, and the no-tenant/no-state early returns.
  • pipeline + schema: canonical component names (Parser / Extractor / Compiler) now live in internal/ingestion/component/schema — the one package both the component and pipeline layers already import (they deliberately do not import each other). The component-side constants alias them; the pipeline's failure-message switch and param predicates reference them instead of inline literals. cpnID namespace prefixes (extractor: etc.) stay as literals with their existing comments.

Why

AGENTS.md: prefer existing utilities over hand-rolled code, reduce public surface, collapse duplicate paths. Each item was re-verified against current upstream/main before implementation (several sibling findings from the same review had already been resolved upstream by #21073).

How it was tested

TDD in an isolated worktree (refactor/ingestion-p0-cleanup, single commit):

  • Real RED→GREEN: an AST-based guard test (TestPipelineHasNoBareComponentNameLiterals) failed on the four bare component-name literals in the pipeline package before the constant consolidation, and passes after — it now fails the build if a literal reappears.
  • Characterization guards: TestFormatComponentFailure (10 subtests: nil error, per-component timeout guidance, wrapped/mixed-case timeout detection, prefix stripping, empty names — the function had no direct test before), TestMapKeysReturnsSortedKeys (unordered/empty/nil/single/unicode/100-key inputs), and the new extractor chat-config tests.
  • Corner cases: nil vs empty maps, unicode key ordering, mixed-case driver names, nil apiConfig and nil credential fields, resolver errors, missing canvas state/tenant.
  • Regression: bash build.sh --test ./internal/ingestion/... fully green; bash build.sh --test-integration on the affected packages produces a failure set identical to a clean base checkout (6 pre-existing failures around TestPipelineRun_Template* / TestTokenizerComponent_Embedding_*, unrelated to this diff).

Risk / notes

  • All four items are behavior-preserving refactors; the only semantic nuance is mapKeys now returning nil (instead of an empty non-nil slice) for an empty map — the single caller logs it via zap.Strings, where both render as [].
  • Local lefthook reports the known 706 pre-existing ruff errors repo-wide (local ruff is stricter than the repo baseline; CI does not run ruff). All Go-relevant checks (gofmt, file hygiene) pass; no Python files are touched.

…omponent names

Four zero-risk reuse/simplification items from the pipeline review:

- component: drop the contains wrapper around slices.Contains and call the
  stdlib directly at the three tokenizer call sites.
- knowledge_compiler: mapKeys is now slices.Sorted(maps.Keys(m)); the sorted
  output contract (deterministic diagnostics) is pinned by a new guard test.
- component: extract newExtractorChatConfig from the two
  resolveExtractorChat*Config functions, whose apiKey/baseURL extraction and
  config construction were byte-identical. Both functions were previously
  untested; the new tests cover the composite and tenant-default paths,
  mixed-case driver names, nil api configs, resolver errors, and the
  no-tenant/no-state early returns.
- pipeline + schema: canonical component names (Parser/Extractor/Compiler)
  now live in the schema package — the one package both the component and
  pipeline layers already import. The component-side constants alias them,
  and the pipeline's failure-message switch and param predicates reference
  them instead of inline literals. An AST-based guard test fails the build
  if a bare component-name literal reappears in the pipeline package.
@xugangqiang xugangqiang added the ci Continue Integration label Oct 19, 2026
@coderabbitai

coderabbitai Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d494f4ca-a640-48e7-bf58-c98e0fb69880
📥 Commits

Reviewing files that changed from the base of the PR and between 6488930 and d2edddf.

📒 Files selected for processing: 10
  • internal/ingestion/component/extractor.go
  • internal/ingestion/component/extractor_chat_config_test.go
  • internal/ingestion/component/knowledge_compiler/component.go
  • internal/ingestion/component/knowledge_compiler/mapkeys_test.go
  • internal/ingestion/component/parser.go
  • internal/ingestion/component/schema/component_names.go
  • internal/ingestion/component/tokenizer.go
  • internal/ingestion/pipeline/pipeline.go
  • internal/ingestion/pipeline/pipeline_failure_message_test.go
  • internal/ingestion/pipeline/pipeline_params.go

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.

📝 Walkthrough

The ingestion code now uses shared component-name constants. Extractor chat configuration construction is shared by explicit and tenant-default model resolution. Compiler map-key ordering and tokenizer membership checks use standard-library functions.

Changes: Ingestion component consistency

Layer / File(s) Summary
Canonical component names and pipeline matching
internal/ingestion/component/schema/component_names.go, internal/ingestion/component/extractor.go, internal/ingestion/component/parser.go, internal/ingestion/component/knowledge_compiler/component.go, internal/ingestion/pipeline/pipeline.go, internal/ingestion/pipeline/pipeline_params.go, internal/ingestion/pipeline/pipeline_failure_message_test.go
Shared constants define the Parser, Extractor, and Compiler names. Component declarations and pipeline matching use those constants. Tests cover failure-message formatting and scan pipeline source for bare component-name literals.
Extractor chat configuration
internal/ingestion/component/extractor.go, internal/ingestion/component/extractor_chat_config_test.go
Explicit and tenant-default model resolution use a shared config builder. Tests cover resolver inputs, driver-name casing, credentials, and empty or error results.
Compiler map-key ordering
internal/ingestion/component/knowledge_compiler/component.go, internal/ingestion/component/knowledge_compiler/mapkeys_test.go
mapKeys uses maps.Keys and slices.Sorted. Tests cover sorted output, nil and empty maps, Unicode keys, and a 100-key map.
Tokenizer slice checks
internal/ingestion/component/tokenizer.go
Full-text and embedding checks use slices.Contains directly. The local wrapper is removed.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~15 minutes

Change: Refactor

Suggested reviewers: jay77721

Merge Risk: ⚪ Minimal · up to d2edd

The ingestion cleanup has no identified merge-blocking issue and is ready to merge after normal checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 54.55% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 22 functions across 10 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description check Passed The description is detailed and relevant. It explains the changes, motivation, testing, known failures, and risks. It does not use the template's exact "### Summary" heading, but it provides the requi…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Title check Passed The title clearly summarizes the main changes: ingestion cleanup, standard-library reuse, and shared component names.
Full details: Description check

Explanation

The description is detailed and relevant. It explains the changes, motivation, testing, known failures, and risks. It does not use the template's exact "### Summary" heading, but it provides the required summary information through the "## What" and "## Why" sections.

  • Fix all pre-merge checks with AI
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

A rabbit checks the names in place
Then sorts the keys at steady pace
The chat configs find their way
Slice checks greet the light of day
Hop, hop—tests keep things in line

Comment @coderabbitai help to get the list of available commands.

@xugangqiang xugangqiang changed the title refactor(ingestion): second cleanup batch — stdlib reuse and shared component names refactor(ingestion): cleanup — stdlib reuse and shared component names Oct 19, 2026

@yuzhichang yuzhichang left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. The shared component-name constants, slices/maps replacements, and chat-config extraction are behavior-preserving; the added tests cover the moved helpers. No blocking findings.

@yuzhichang
yuzhichang merged commit 1e0224d into infiniflow:main Oct 19, 2026
6 checks passed
@xugangqiang
xugangqiang deleted the refactor/ingestion-p0-cleanup branch November 26, 2026 09:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants