Skip to content

Build AI methods with your coding agent, then run them anywhere: as an MCP for chatbots, as a webapp for people, or via API for your software.

Fix/ut concept library (#145)

Thomas Hebrard91095f56277b
diff --git a/pyproject.toml b/pyproject.toml
index 6fad97cb2..b00e59042 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -24,7 +24,7 @@ dependencies = [
"instructor>=1.8.3",
"jinja2>=3.1.4",
"json2html>=1.3.0",
- "kajson @ git+https://github.com/Pipelex/kajson.git@refactor/Proper-Singleton",
+ "kajson==0.3.0",
"markdown>=3.6",
"networkx>=3.4.2",
"openai>=1.60.1",
diff --git a/tests/conftest.py b/tests/conftest.py
index fb5e59fca..35d6afc56 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -9,6 +9,8 @@ import pipelex.config
import pipelex.pipelex
from pipelex import log
from pipelex.config import get_config
+from pipelex.core.concept_provider_abstract import ConceptProviderAbstract
+from pipelex.hub import get_concept_provider
from tests.cases.registry import Fruit
pytest_plugins = [
@@ -66,3 +68,9 @@ def cherry() -> Fruit:
def blueberry() -> Fruit:
"""Blueberry fruit fixture."""
return Fruit(name="blueberry", color="blue")
+
+
[email protected](scope="module")
+def concept_provider() -> ConceptProviderAbstract:
+ """Concept provider fixture for testing concept compatibility."""
+ return get_concept_provider()
diff --git a/tests/test_pipelines/concept_library/is_compatible_concept_code.py b/tests/test_pipelines/concept_library/is_compatible_concept_code.py
new file mode 100644
index 000000000..14ebdaaa9
--- /dev/null
+++ b/tests/test_pipelines/concept_library/is_compatible_concept_code.py
@@ -0,0 +1,45 @@
+from typing import Dict, List, Optional
+
+from pydantic import Field
+
+from pipelex.core.stuff_content import StructuredContent
+
+
+class FundamentalsDoc(StructuredContent):
+ project_overview: Optional[str] = Field(
+ None,
+ description="Mission, key features, architecture diagram, demo links",
+ )
+ core_concepts: Optional[Dict[str, str]] = Field(
+ None,
+ description=(
+ "Names and definitions for project-specific terms, acronyms, data model names, background knowledge, business rules, domain entities"
+ ),
+ )
+ repository_map: Optional[str] = Field(
+ None,
+ description="Directory layout explanation and purpose of each folder",
+ )
+
+
+class DocumentationConcept(StructuredContent):
+ """A specialized documentation concept that extends FundamentalsDoc."""
+
+ title: str = Field(..., description="Title of the documentation")
+ sections: List[str] = Field(default_factory=list, description="List of section names")
+ last_updated: Optional[str] = Field(None, description="Last update timestamp")
+
+
+class MultiMediaConcept(StructuredContent):
+ """A concept that combines text and images."""
+
+ text_content: str = Field(..., description="The text content")
+ image_urls: List[str] = Field(default_factory=list, description="List of image URLs")
+ caption: Optional[str] = Field(None, description="Optional caption for the content")
+
+
+class IndependentConcept(StructuredContent):
+ """An independent concept with its own structure."""
+
+ unique_field: str = Field(..., description="A unique field for this concept")
+ metadata: Dict[str, str] = Field(default_factory=dict, description="Metadata dictionary")
diff --git a/tests/test_pipelines/concept_library/is_compatible_concept_code.toml b/tests/test_pipelines/concept_library/is_compatible_concept_code.toml
new file mode 100644
index 000000000..c44da1afc
--- /dev/null
+++ b/tests/test_pipelines/concept_library/is_compatible_concept_code.toml
@@ -0,0 +1,46 @@
+domain = "concept_library_tests"
+
+[concept]
+# Simple concept with no structure - should default to Text
+SimpleTextConcept = "A simple concept that should default to Text"
+
+# Concept with explicit structure class
+FundamentalsDoc = "A comprehensive overview of the fundamental concepts and principles of software engineering."
+
+# Concept that explicitly refines Text
+[concept.ExplicitTextConcept]
+Concept = "A concept that explicitly refines Text"
+refines = ["Text"]
+
+# Concept that refines Image
+[concept.ImageBasedConcept]
+Concept = "A concept based on images"
+refines = ["Image"]
+
+# Concept that refines FundamentalsDoc
+[concept.DocumentationConcept]
+Concept = "A specialized documentation concept"
+structure = "DocumentationConcept"
+refines = ["FundamentalsDoc"]
+
+# Concept that refines both Text and Image (multiple inheritance)
+[concept.MultiMediaConcept]
+Concept = "A concept that combines text and images"
+structure = "MultiMediaConcept"
+refines = ["Text", "Image"]
+
+# Concept with custom structure that doesn't refine anything
+[concept.IndependentConcept]
+Concept = "An independent concept with custom structure"
+structure = "IndependentConcept"
+
+# Concept that refines a non-native concept
+[concept.SpecializedDoc]
+Concept = "A specialized document that builds on FundamentalsDoc"
+refines = ["FundamentalsDoc"]
+
+# Chain of inheritance: Text -> ExplicitTextConcept -> DerivedTextConcept
+[concept.DerivedTextConcept]
+Concept = "A concept derived from ExplicitTextConcept"
+refines = ["ExplicitTextConcept"]
+
diff --git a/tests/unit/pipelex/core/test_concept_library.py b/tests/unit/pipelex/core/test_concept_library.py
index 839620f40..58603661b 100644
--- a/tests/unit/pipelex/core/test_concept_library.py
+++ b/tests/unit/pipelex/core/test_concept_library.py
@@ -1,5 +1,6 @@
from pipelex.core.concept import Concept
from pipelex.core.concept_native import NativeConcept
+from pipelex.core.concept_provider_abstract import ConceptProviderAbstract
class Testget_concept_providerIsNativeConcept:
@@ -128,3 +129,103 @@ class Testget_concept_providerIsNativeConcept:
# And they should also work with the explicit "native." prefix
assert Concept.is_native_concept(f"native.{concept_name}") is True, f"'native.{concept_name}' should also be recognized as native concept"
+
+
+class TestConceptLibraryCompatibility:
+ """Test ConceptLibrary compatibility methods."""
+
+ def test_is_compatible_by_concept_code_simple_text_concept_vs_text(self, concept_provider: ConceptProviderAbstract):
+ """Test that SimpleTextConcept (no structure) is compatible with native Text."""
+ # Test: SimpleTextConcept should be compatible with native Text (defaults to Text)
+ result = concept_provider.is_compatible_by_concept_code(
+ tested_concept_code="concept_library_tests.SimpleTextConcept", wanted_concept_code="native.Text"
+ )
+ assert result is True, "SimpleTextConcept should be compatible with native Text"
+
+ def test_is_compatible_by_concept_code_fundamentals_doc_vs_text(self, concept_provider: ConceptProviderAbstract):
+ """Test that FundamentalsDoc (custom structure) is not compatible with native Text."""
+ # Test: FundamentalsDoc should NOT be compatible with native Text (has custom structure)
+ result = concept_provider.is_compatible_by_concept_code(
+ tested_concept_code="concept_library_tests.FundamentalsDoc", wanted_concept_code="native.Text"
+ )
+ assert result is False, "FundamentalsDoc should not be compatible with native Text"
+
+ def test_is_compatible_by_concept_code_explicit_text_concept_vs_text(self, concept_provider: ConceptProviderAbstract):
+ """Test that ExplicitTextConcept (explicitly refines Text) is compatible with native Text."""
+ # Test: ExplicitTextConcept should be compatible with native Text
+ result = concept_provider.is_compatible_by_concept_code(
+ tested_concept_code="concept_library_tests.ExplicitTextConcept", wanted_concept_code="native.Text"
+ )
+ assert result is True, "ExplicitTextConcept should be compatible with native Text"
+
+ def test_is_compatible_by_concept_code_image_based_concept_vs_image(self, concept_provider: ConceptProviderAbstract):
+ """Test that ImageBasedConcept is compatible with native Image."""
+ # Test: ImageBasedConcept should be compatible with native Image
+ result = concept_provider.is_compatible_by_concept_code(
+ tested_concept_code="concept_library_tests.ImageBasedConcept", wanted_concept_code="native.Image"
+ )
+ assert result is True, "ImageBasedConcept should be compatible with native Image"
+
+ def test_is_compatible_by_concept_code_image_based_concept_vs_text(self, concept_provider: ConceptProviderAbstract):
+ """Test that ImageBasedConcept is not compatible with native Text."""
+ # Test: ImageBasedConcept should NOT be compatible with native Text
+ result = concept_provider.is_compatible_by_concept_code(
+ tested_concept_code="concept_library_tests.ImageBasedConcept", wanted_concept_code="native.Text"
+ )
+ assert result is False, "ImageBasedConcept should not be compatible with native Text"
+
+ def test_is_compatible_by_concept_code_documentation_concept_vs_fundamentals_doc(self, concept_provider: ConceptProviderAbstract):
+ """Test that DocumentationConcept is compatible with FundamentalsDoc."""
+ # Test: DocumentationConcept should be compatible with FundamentalsDoc
+ result = concept_provider.is_compatible_by_concept_code(
+ tested_concept_code="concept_library_tests.DocumentationConcept", wanted_concept_code="concept_library_tests.FundamentalsDoc"
+ )
+ assert result is True, "DocumentationConcept should be compatible with FundamentalsDoc"
+
+ def test_is_compatible_by_concept_code_specialized_doc_vs_fundamentals_doc(self, concept_provider: ConceptProviderAbstract):
+ """Test that SpecializedDoc is compatible with FundamentalsDoc."""
+ # Test: SpecializedDoc should be compatible with FundamentalsDoc
+ result = concept_provider.is_compatible_by_concept_code(
+ tested_concept_code="concept_library_tests.SpecializedDoc", wanted_concept_code="concept_library_tests.FundamentalsDoc"
+ )
+ assert result is True, "SpecializedDoc should be compatible with FundamentalsDoc"
+
+ def test_is_compatible_by_concept_code_multimedia_concept_vs_text(self, concept_provider: ConceptProviderAbstract):
+ """Test that MultiMediaConcept is compatible with Text (multiple inheritance)."""
+ # Test: MultiMediaConcept should be compatible with Text
+ result = concept_provider.is_compatible_by_concept_code(
+ tested_concept_code="concept_library_tests.MultiMediaConcept", wanted_concept_code="native.Text"
+ )
+ assert result is True, "MultiMediaConcept should be compatible with Text"
+
+ def test_is_compatible_by_concept_code_multimedia_concept_vs_image(self, concept_provider: ConceptProviderAbstract):
+ """Test that MultiMediaConcept is compatible with Image (multiple inheritance)."""
+ # Test: MultiMediaConcept should be compatible with Image
+ result = concept_provider.is_compatible_by_concept_code(
+ tested_concept_code="concept_library_tests.MultiMediaConcept", wanted_concept_code="native.Image"
+ )
+ assert result is True, "MultiMediaConcept should be compatible with Image"
+
+ def test_is_compatible_by_concept_code_independent_concept_vs_text(self, concept_provider: ConceptProviderAbstract):
+ """Test that IndependentConcept is not compatible with Text."""
+ # Test: IndependentConcept should NOT be compatible with Text (no refines)
+ result = concept_provider.is_compatible_by_concept_code(
+ tested_concept_code="concept_library_tests.IndependentConcept", wanted_concept_code="native.Text"
+ )
+ assert result is False, "IndependentConcept should not be compatible with Text"
+
+ def test_is_compatible_by_concept_code_derived_text_concept_vs_text(self, concept_provider: ConceptProviderAbstract):
+ """Test that DerivedTextConcept is compatible with Text (inheritance chain)."""
+ # Test: DerivedTextConcept should be compatible with Text (through ExplicitTextConcept)
+ result = concept_provider.is_compatible_by_concept_code(
+ tested_concept_code="concept_library_tests.DerivedTextConcept", wanted_concept_code="native.Text"
+ )
+ assert result is True, "DerivedTextConcept should be compatible with Text through inheritance chain"
+
+ def test_is_compatible_by_concept_code_derived_text_concept_vs_explicit_text(self, concept_provider: ConceptProviderAbstract):
+ """Test that DerivedTextConcept is compatible with ExplicitTextConcept (direct inheritance)."""
+ # Test: DerivedTextConcept should be compatible with ExplicitTextConcept
+ result = concept_provider.is_compatible_by_concept_code(
+ tested_concept_code="concept_library_tests.DerivedTextConcept", wanted_concept_code="concept_library_tests.ExplicitTextConcept"
+ )
+ assert result is True, "DerivedTextConcept should be compatible with ExplicitTextConcept"
diff --git a/uv.lock b/uv.lock
index 194efd2d9..cdeb9cf39 100644
--- a/uv.lock
+++ b/uv.lock
@@ -890,10 +890,14 @@ wheels = [
[[package]]
name = "kajson"
version = "0.3.0"
-source = { git = "https://github.com/Pipelex/kajson.git?rev=refactor%2FProper-Singleton#de8d4a8f5a45feb3b473ab8ccba0c38ca692b391" }
+source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "pydantic" },
]
+sdist = { url = "https://files.pythonhosted.org/packages/b3/51/83d17d4fc6db6b9d497f91c6cbdf7c5677116797a44d0ad65960f1b66c90/kajson-0.3.0.tar.gz", hash = "sha256:5ea8e164cd7fc96877bf4038cf64c286ac4606814146c24dc9ecc4a2c6ac047d", size = 20271, upload-time = "2025-07-09T09:52:33.851Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/f9/d5/4a7974d072c5eb6565e5abe3d52b13f662491934dac4b9ea15836fa2da69/kajson-0.3.0-py3-none-any.whl", hash = "sha256:d8cc72875ebef6ea44c06c96fe63accf5b0721ca24ea1e593814dd45fd25bf15", size = 26711, upload-time = "2025-07-09T09:52:32.639Z" },
+]
[[package]]
name = "markdown"
@@ -1709,7 +1713,7 @@ requires-dist = [
{ name = "instructor", specifier = ">=1.8.3" },
{ name = "jinja2", specifier = ">=3.1.4" },
{ name = "json2html", specifier = ">=1.3.0" },
- { name = "kajson", git = "https://github.com/Pipelex/kajson.git?rev=refactor%2FProper-Singleton" },
+ { name = "kajson", specifier = "==0.3.0" },
{ name = "markdown", specifier = ">=3.6" },
{ name = "mistralai", marker = "extra == 'mistralai'", specifier = "==1.5.2" },
{ name = "mkdocs", marker = "extra == 'docs'", specifier = "==1.6.1" },