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.

Tests for ConceptSpec genration

Louis Choquel931a6fc695ca
diff --git a/pipelex/cli/commands/build_cmd.py b/pipelex/cli/commands/build_cmd.py
index 1abc50fab..ba13a3cce 100644
--- a/pipelex/cli/commands/build_cmd.py
+++ b/pipelex/cli/commands/build_cmd.py
@@ -8,6 +8,7 @@ from pipelex import pretty_print
from pipelex.hub import get_report_delegate
from pipelex.language.plx_factory import PlxFactory
from pipelex.libraries.pipelines.builder.builder import PipelexBundleSpec
+from pipelex.libraries.pipelines.builder.builder_loop import BuilderLoop
from pipelex.pipelex import Pipelex
from pipelex.pipeline.execute import execute_pipeline
from pipelex.tools.misc.file_utils import ensure_directory_for_file_path, save_text_to_path
@@ -24,8 +25,8 @@ pipelex build pipe "Given an RDFP PDF, build a compliance matrix"
"""
-@build_app.command("pipe")
-def build_pipe_cmd(
+@build_app.command("one-shot")
+def build_one_shot_cmd(
brief: Annotated[
str,
typer.Argument(help="Brief description of what the pipeline should do"),
@@ -75,3 +76,51 @@ def build_pipe_cmd(
typer.echo(typer.style(f"\n✅ Pipeline built in {end_time - start_time:.2f} seconds", fg=typer.colors.GREEN))
get_report_delegate().generate_report()
+
+
+@build_app.command("pipe")
+def build_pipe_cmd(
+ brief: Annotated[
+ str,
+ typer.Argument(help="Brief description of what the pipeline should do"),
+ ],
+ output_path: Annotated[
+ str,
+ typer.Option("--output", "-o", help="Path to save the generated PLX file"),
+ ] = "./results/generated_pipeline.plx",
+ no_output: Annotated[
+ bool,
+ typer.Option("--no-output", help="Skip saving the pipeline to file"),
+ ] = False,
+) -> None:
+ Pipelex.make(relative_config_folder_path="../../../pipelex/libraries", from_file=True)
+ typer.echo("=" * 70)
+ typer.echo(typer.style("🔥 Starting pipe builder... 🚀", fg=typer.colors.GREEN))
+ typer.echo("")
+
+ async def run_pipeline():
+ if no_output:
+ typer.echo(typer.style("\n⚠️ Pipeline will not be saved to file (--no-output specified)", fg=typer.colors.YELLOW))
+ elif not output_path:
+ typer.echo(typer.style("\n🛑 Cannot save a pipeline to an empty file name", fg=typer.colors.RED))
+ raise typer.Exit(1)
+ else:
+ ensure_directory_for_file_path(file_path=output_path)
+
+ builder_loop = BuilderLoop()
+ # Save to file unless explicitly disabled with --no-output
+ if no_output:
+ typer.echo(typer.style("\n⚠️ Pipeline not saved to file (--no-output specified)", fg=typer.colors.YELLOW))
+ return
+
+ pipelex_bundle_spec = await builder_loop.build_and_fix(pipe_code="pipe_builder", input_memory={"brief": brief})
+ plx_content = PlxFactory.make_plx_content(blueprint=pipelex_bundle_spec.to_blueprint())
+ save_text_to_path(text=plx_content, path=output_path)
+ typer.echo(typer.style(f"\n✅ Pipeline saved to: {output_path}", fg=typer.colors.GREEN))
+
+ start_time = time.time()
+ asyncio.run(run_pipeline())
+ end_time = time.time()
+ typer.echo(typer.style(f"\n✅ Pipeline built in {end_time - start_time:.2f} seconds", fg=typer.colors.GREEN))
+
+ get_report_delegate().generate_report()
diff --git a/pipelex/core/concepts/concept_blueprint.py b/pipelex/core/concepts/concept_blueprint.py
index 2582da942..92bf5be31 100644
--- a/pipelex/core/concepts/concept_blueprint.py
+++ b/pipelex/core/concepts/concept_blueprint.py
@@ -129,7 +129,7 @@ class ConceptBlueprint(BaseModel):
@classmethod
def validate_concept_code(cls, concept_code: str) -> None:
if not is_pascal_case(concept_code):
- msg = f"Concept code '{concept_code}' must be PascalCase (letters and numbers only, starting with uppercase, without `.`)"
+ msg = f"ConceptBlueprint validate_concept_code: Concept code '{concept_code}' must be PascalCase (letters and numbers only, starting with uppercase, without `.`)"
raise ConceptCodeError(msg)
@classmethod
@@ -165,7 +165,7 @@ class ConceptBlueprint(BaseModel):
# Validate concept code
if not is_pascal_case(concept_code):
- msg = f"Concept code '{concept_code}' must be PascalCase (letters and numbers only, starting with uppercase, without `.`)"
+ msg = f"ConceptBlueprint validate_concept_string: Concept code '{concept_code}' must be PascalCase (letters and numbers only, starting with uppercase, without `.`)"
raise ConceptCodeError(msg)
# Validate that if the concept code is among the native concepts, the domain MUST be native.
diff --git a/pipelex/libraries/pipelines/builder/builder_loop.py b/pipelex/libraries/pipelines/builder/builder_loop.py
new file mode 100644
index 000000000..83fd0cce2
--- /dev/null
+++ b/pipelex/libraries/pipelines/builder/builder_loop.py
@@ -0,0 +1,56 @@
+import asyncio
+import time
+from typing import Annotated, Any, cast
+
+import typer
+from pydantic import ConfigDict, Field, ValidationError, field_validator
+
+from pipelex import log, pretty_print
+from pipelex.client.protocol import ImplicitMemory
+from pipelex.core.bundles.pipelex_bundle_blueprint import PipeBlueprintUnion, PipelexBundleBlueprint
+from pipelex.core.concepts.concept_blueprint import ConceptBlueprint
+from pipelex.core.domains.domain_blueprint import DomainBlueprint
+from pipelex.core.memory.working_memory import WorkingMemory
+from pipelex.core.stuffs.stuff_content import ListContent, StructuredContent
+from pipelex.exceptions import (
+ ConceptDefinitionError,
+ ConceptLoadingError,
+ DomainLoadingError,
+ PipeDefinitionError,
+ PipelexError,
+ PipeLoadingError,
+ StaticValidationError,
+)
+from pipelex.hub import get_class_registry, get_library_manager, get_report_delegate
+from pipelex.language.plx_factory import PlxFactory
+from pipelex.libraries.pipelines.builder.builder import PipelexBundleSpec
+from pipelex.libraries.pipelines.builder.concept.concept_spec import ConceptSpec
+from pipelex.libraries.pipelines.builder.pipe.pipe_batch_spec import PipeBatchSpec
+from pipelex.libraries.pipelines.builder.pipe.pipe_compose_spec import PipeComposeSpec
+from pipelex.libraries.pipelines.builder.pipe.pipe_condition_spec import PipeConditionSpec
+from pipelex.libraries.pipelines.builder.pipe.pipe_func_spec import PipeFuncSpec
+from pipelex.libraries.pipelines.builder.pipe.pipe_img_spec import PipeImgGenSpec
+from pipelex.libraries.pipelines.builder.pipe.pipe_llm_spec import PipeLLMSpec
+from pipelex.libraries.pipelines.builder.pipe.pipe_ocr_spec import PipeOcrSpec
+from pipelex.libraries.pipelines.builder.pipe.pipe_parallel_spec import PipeParallelSpec
+from pipelex.libraries.pipelines.builder.pipe.pipe_sequence_spec import PipeSequenceSpec
+from pipelex.libraries.pipelines.builder.pipe.pipe_signature import PipeSignature
+from pipelex.pipe_works.pipe_dry import dry_run_pipes
+from pipelex.pipelex import Pipelex
+from pipelex.pipeline.execute import execute_pipeline
+from pipelex.tools.misc.file_utils import ensure_directory_for_file_path, save_text_to_path
+from pipelex.tools.typing.pydantic_utils import format_pydantic_validation_error
+
+
+class BuilderLoop:
+ async def build_and_fix(self, pipe_code: str, input_memory: ImplicitMemory | None = None) -> PipelexBundleSpec:
+ pretty_print(f"Building and fixing with {pipe_code}")
+ pipe_output = await execute_pipeline(
+ pipe_code=pipe_code,
+ input_memory=input_memory,
+ )
+ pretty_print(pipe_output, title="Pipe Output")
+
+ pipelex_bundle_spec = pipe_output.working_memory.get_stuff_as(name="pipelex_bundle_spec", content_type=PipelexBundleSpec)
+ pretty_print(pipelex_bundle_spec, title="Pipelex Bundle Spec")
+ return pipelex_bundle_spec
diff --git a/pipelex/libraries/pipelines/builder/concept/concept_spec.py b/pipelex/libraries/pipelines/builder/concept/concept_spec.py
index e826b4277..0ccdf63a1 100644
--- a/pipelex/libraries/pipelines/builder/concept/concept_spec.py
+++ b/pipelex/libraries/pipelines/builder/concept/concept_spec.py
@@ -160,45 +160,22 @@ class ConceptSpec(StructuredContent):
),
)
- @classmethod
- def _post_validate_concept_code(cls, concept_code: str) -> None:
- if not is_pascal_case(concept_code):
- msg = f"Concept code '{concept_code}' must be PascalCase (letters and numbers only, starting with uppercase, without `.`)"
- raise ConceptCodeError(msg)
-
- @classmethod
- def validate_concept_string_or_code(cls, concept_string_or_code: str) -> None:
- if concept_string_or_code.count(".") > 1:
- msg = (
- f"concept_string_or_code '{concept_string_or_code}' is invalid. "
- "It should either contain a domain in snake_case and a concept code in PascalCase separated by one dot, "
- "or be a concept code in PascalCase."
- )
- raise ConceptStringOrConceptCodeError(msg)
-
- if concept_string_or_code.count(".") == 1:
- domain, concept_code = concept_string_or_code.split(".")
- DomainBlueprint.validate_domain_code(code=domain)
- cls._post_validate_concept_code(concept_code=concept_code)
- else:
- cls._post_validate_concept_code(concept_code=concept_string_or_code)
-
@field_validator("the_concept_code", mode="before")
@classmethod
- def validate_concept_code(cls, concept_code: str) -> str:
- if "." in concept_code:
- domain, concept_code = concept_code.split(".")
+ def validate_concept_code(cls, value: str) -> str:
+ if "." in value:
+ domain, concept_code = value.split(".")
if not is_pascal_case(concept_code):
- log.warning(f"Concept code '{concept_code}' is not PascalCase, converting to PascalCase")
- pascal_cased = snake_to_pascal_case(concept_code)
- return f"{domain}.{pascal_cased}"
+ log.warning(f"Concept code '{value}' is not PascalCase, converting to PascalCase")
+ pascal_cased_value = snake_to_pascal_case(concept_code)
+ return f"{domain}.{pascal_cased_value}"
else:
- return concept_code
- elif not is_pascal_case(concept_code):
- log.warning(f"Concept code '{concept_code}' is not PascalCase, converting to PascalCase")
- return snake_to_pascal_case(concept_code)
+ return value
+ elif not is_pascal_case(value):
+ log.warning(f"Concept code '{value}' is not PascalCase, converting to PascalCase")
+ return snake_to_pascal_case(value)
else:
- return concept_code
+ return value
@field_validator("refines", mode="before")
@classmethod
@@ -221,6 +198,29 @@ class ConceptSpec(StructuredContent):
raise ConceptSpecError(msg)
return values
+ @classmethod
+ def _post_validate_concept_code(cls, concept_code: str) -> None:
+ if not is_pascal_case(concept_code):
+ msg = f"ConceptSpec _post_validate_concept_code: Concept code '{concept_code}' must be PascalCase (letters and numbers only, starting with uppercase, without `.`)"
+ raise ConceptCodeError(msg)
+
+ @classmethod
+ def validate_concept_string_or_code(cls, concept_string_or_code: str) -> None:
+ if concept_string_or_code.count(".") > 1:
+ msg = (
+ f"concept_string_or_code '{concept_string_or_code}' is invalid. "
+ "It should either contain a domain in snake_case and a concept code in PascalCase separated by one dot, "
+ "or be a concept code in PascalCase."
+ )
+ raise ConceptStringOrConceptCodeError(msg)
+
+ if concept_string_or_code.count(".") == 1:
+ domain, concept_code = concept_string_or_code.split(".")
+ DomainBlueprint.validate_domain_code(code=domain)
+ cls._post_validate_concept_code(concept_code=concept_code)
+ else:
+ cls._post_validate_concept_code(concept_code=concept_string_or_code)
+
def to_blueprint(self) -> ConceptBlueprint:
"""Convert this ConceptBlueprint to the original core ConceptBlueprint."""
# TODO: Clarify concept structure blueprint
diff --git a/tests/integration/pipelex/conftest.py b/tests/integration/pipelex/conftest.py
index 898cb0107..7ad270cd7 100644
--- a/tests/integration/pipelex/conftest.py
+++ b/tests/integration/pipelex/conftest.py
@@ -51,7 +51,7 @@ def llm_preset_id(request: pytest.FixtureRequest) -> str:
# "gpt-4o-mini",
# "gpt-5-mini",
# "gpt-5-chat",
- # "claude-4-sonnet",
+ "claude-4-sonnet",
# "claude-4.1-opus",
# "claude-3.5-sonnet",
# "claude-3.5-sonnet-v2"
@@ -59,7 +59,7 @@ def llm_preset_id(request: pytest.FixtureRequest) -> str:
# "grok-3",
# "grok-3-mini",
# "base-claude",
- "gemini-2.5-flash-lite",
+ # "gemini-2.5-flash-lite",
# "gemini-2.5-flash",
# "gemini-2.5-pro",
],
diff --git a/tests/integration/pipelex/libraries/pipelines/builder/__init__.py b/tests/integration/pipelex/libraries/pipelines/builder/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/tests/integration/pipelex/libraries/pipelines/builder/concept/__init__.py b/tests/integration/pipelex/libraries/pipelines/builder/concept/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/tests/integration/pipelex/libraries/pipelines/builder/concept/integration_test_data.py b/tests/integration/pipelex/libraries/pipelines/builder/concept/integration_test_data.py
new file mode 100644
index 000000000..84df0b09d
--- /dev/null
+++ b/tests/integration/pipelex/libraries/pipelines/builder/concept/integration_test_data.py
@@ -0,0 +1,123 @@
+from typing import ClassVar
+
+
+class ConceptSpecGenerationTestCases:
+ """Test cases for LLM-based ConceptSpec generation."""
+
+ # Test case: Simple concept without structure or refines
+ SIMPLE_CONCEPT_PROMPT = """
+Generate a concept specification for a "BlogPost" concept.
+
+Requirements:
+- the_concept_code: BlogPost
+- definition: A blog post with title, content, and publication date
+- structure: None (leave empty)
+- refines: None (leave empty)
+"""
+
+ # Test case: Concept that refines a native concept
+ REFINES_TEXT_PROMPT = """
+Generate a concept specification for a "ProductDescription" concept.
+
+Requirements:
+- the_concept_code: ProductDescription
+- definition: A detailed description of a product for e-commerce
+- refines: Text (this concept refines the native Text concept)
+- structure: None (leave empty because we're using refines)
+"""
+
+ # Test case: Concept with simple structure
+ SIMPLE_STRUCTURE_PROMPT = """
+Generate a concept specification for a "Person" concept with a simple structure.
+
+Requirements:
+- the_concept_code: Person
+- definition: A person with basic information
+- structure: A dictionary with these fields:
+ - name: (type: text, definition: "The person's full name", required: true)
+ - age: (type: integer, definition: "The person's age", required: true)
+- refines: None (leave empty)
+"""
+
+ # Test case: Concept with complex structure
+ COMPLEX_STRUCTURE_PROMPT = """
+Generate a concept specification for a "Product" concept with a detailed structure.
+
+Requirements:
+- the_concept_code: Product
+- definition: A product in an e-commerce system
+- structure: A dictionary with these fields:
+ - name: (type: text, definition: "Product name", required: true)
+ - description: (type: text, definition: "Product description", required: true)
+ - price: (type: number, definition: "Product price in dollars", required: true)
+ - stock_quantity: (type: integer, definition: "Number of items in stock", required: false, default_value: 0)
+ - is_available: (type: boolean, definition: "Whether the product is currently available", required: false, default_value: true)
+- refines: None (leave empty)
+"""
+
+ # Test case: Concept with optional fields and defaults
+ OPTIONAL_FIELDS_PROMPT = """
+Generate a concept specification for a "UserProfile" concept.
+
+Requirements:
+- the_concept_code: UserProfile
+- definition: A user profile with optional settings
+- structure: A dictionary with these fields:
+ - username: (type: text, definition: "User's username", required: true)
+ - email: (type: text, definition: "User's email address", required: true)
+ - bio: (type: text, definition: "User biography", required: false, default_value: "")
+ - notification_enabled: (type: boolean, definition: "Whether notifications are enabled", required: false, default_value: true)
+ - login_count: (type: integer, definition: "Number of times user has logged in", required: false, default_value: 0)
+- refines: None (leave empty)
+"""
+
+ # Test case: Concept with snake_case code (tests conversion)
+ SNAKE_CASE_CONCEPT_PROMPT = """
+Generate a concept specification for a "customer_order" concept.
+
+Requirements:
+- the_concept_code: customer_order
+- definition: An order placed by a customer
+- structure: A dictionary with these fields:
+ - order_number: (type: text, definition: "Unique order identifier", required: true)
+ - total_amount: (type: number, definition: "Total order amount", required: true)
+ - is_paid: (type: boolean, definition: "Payment status", required: false, default_value: false)
+- refines: None (leave empty)
+"""
+
+ # Test case: Concept refining Image
+ REFINES_IMAGE_PROMPT = """
+Generate a concept specification for a "ProductPhoto" concept.
+
+Requirements:
+- the_concept_code: ProductPhoto
+- definition: A photograph of a product for display in catalog
+- refines: Image (this concept refines the native Image concept)
+- structure: None (leave empty because we're using refines)
+"""
+
+ # Test case: Concept with date field
+ DATE_FIELD_PROMPT = """
+Generate a concept specification for an "Event" concept with a date field.
+
+Requirements:
+- the_concept_code: Event
+- definition: An event with scheduling information
+- structure: A dictionary with these fields:
+ - title: (type: text, definition: "Event title", required: true)
+ - description: (type: text, definition: "Event description", required: true)
+ - start_date: (type: date, definition: "Event start date and time", required: true)
+ - is_public: (type: boolean, definition: "Whether the event is public", required: false, default_value: true)
+- refines: None (leave empty)
+"""
+
+ TEST_CASES: ClassVar[list[tuple[str, str]]] = [
+ # ("simple_concept", SIMPLE_CONCEPT_PROMPT),
+ # ("refines_text", REFINES_TEXT_PROMPT),
+ # ("simple_structure", SIMPLE_STRUCTURE_PROMPT),
+ # ("complex_structure", COMPLEX_STRUCTURE_PROMPT),
+ # ("optional_fields", OPTIONAL_FIELDS_PROMPT),
+ ("snake_case_concept", SNAKE_CASE_CONCEPT_PROMPT),
+ # ("refines_image", REFINES_IMAGE_PROMPT),
+ # ("date_field", DATE_FIELD_PROMPT),
+ ]
diff --git a/tests/integration/pipelex/libraries/pipelines/builder/concept/test_concept_spec_generation.py b/tests/integration/pipelex/libraries/pipelines/builder/concept/test_concept_spec_generation.py
new file mode 100644
index 000000000..6c8b7f262
--- /dev/null
+++ b/tests/integration/pipelex/libraries/pipelines/builder/concept/test_concept_spec_generation.py
@@ -0,0 +1,69 @@
+import pytest
+
+from pipelex import log, pretty_print
+from pipelex.cogt.llm.llm_job_components import LLMJobParams
+from pipelex.cogt.llm.llm_job_factory import LLMJobFactory
+from pipelex.hub import get_llm_worker
+from pipelex.libraries.pipelines.builder.concept.concept_spec import ConceptSpec
+
+from tests.integration.pipelex.libraries.pipelines.builder.concept.integration_test_data import ConceptSpecGenerationTestCases
+
+
[email protected](loop_scope="class")
+class TestConceptSpecGeneration:
+ """Integration tests for generating ConceptSpec objects using LLM.
+
+ These tests verify that LLMs can generate valid ConceptSpec objects
+ from natural language prompts describing various concept shapes.
+ """
+
+ @pytest.mark.parametrize("topic,user_prompt", ConceptSpecGenerationTestCases.TEST_CASES)
+ async def test_generate_concept_spec(
+ self,
+ llm_job_params: LLMJobParams,
+ llm_handle: str,
+ topic: str,
+ user_prompt: str,
+ ):
+ """Test generating a ConceptSpec using LLM from a natural language prompt.
+
+ Args:
+ llm_job_params: LLM job parameters from fixture
+ llm_handle: LLM handle from fixture
+ topic: Test case topic/name
+ user_prompt: Natural language prompt describing the concept
+ """
+ log.info(f"Testing {topic} with llm_handle '{llm_handle}'")
+
+ # Get the LLM worker
+ llm_worker = get_llm_worker(llm_handle=llm_handle)
+
+ # Skip if object generation is not supported
+ if not llm_worker.is_gen_object_supported:
+ pytest.skip(f"LLM worker '{llm_worker.desc}' does not support object generation")
+
+ log.info(f"Using llm_worker: {llm_worker.desc}")
+
+ # Create the LLM job with the prompt
+ llm_job = LLMJobFactory.make_llm_job_from_prompt_contents(
+ system_text="You are an expert at generating concept specifications for a data modeling system.",
+ user_text=user_prompt,
+ llm_job_params=llm_job_params,
+ )
+
+ # Generate the ConceptSpec object
+ generated_concept_spec = await llm_worker.gen_object(llm_job=llm_job, schema=ConceptSpec)
+
+ # Display the result
+ pretty_print(generated_concept_spec, title=f"Generated ConceptSpec for '{topic}' using {llm_handle}")
+
+ # Basic validation: if we got here without exceptions, the ConceptSpec was created successfully
+ # The Pydantic validation and field validators have already run
+ assert generated_concept_spec is not None
+ assert isinstance(generated_concept_spec, ConceptSpec)
+ assert generated_concept_spec.the_concept_code
+ assert generated_concept_spec.definition
+
+ log.info(f"✓ Successfully generated ConceptSpec for '{topic}': {generated_concept_spec.the_concept_code}")
diff --git a/tests/unit/pipelex/libraries/pipelines/builder/concept/test_concept_blueprint.py b/tests/unit/pipelex/libraries/pipelines/builder/concept/test_concept_blueprint.py
index b6c5a1bae..9e765c6a5 100644
--- a/tests/unit/pipelex/libraries/pipelines/builder/concept/test_concept_blueprint.py
+++ b/tests/unit/pipelex/libraries/pipelines/builder/concept/test_concept_blueprint.py
@@ -1,16 +1,43 @@
import pytest
+from pipelex import log
from pipelex.core.concepts.concept_blueprint import ConceptBlueprint
from pipelex.libraries.pipelines.builder.concept.concept_spec import ConceptSpec
-from .test_data import ConceptBlueprintTestCases
+from tests.unit.pipelex.libraries.pipelines.builder.concept.test_data import ConceptBlueprintTestCases, ConceptCodeValidationTestCases
class TestConceptBlueprintConversion:
@pytest.mark.parametrize(
- "test_name,concept_spec,expected_core",
+ "topic,concept_spec,expected_core",
ConceptBlueprintTestCases.TEST_CASES,
)
- def test_concept_to_core_blueprint(self, test_name: str, concept_spec: ConceptSpec, expected_core: ConceptBlueprint):
+ def test_concept_to_core_blueprint(self, topic: str, concept_spec: ConceptSpec, expected_core: ConceptBlueprint):
+ log.verbose(f"Testing {topic}")
result = concept_spec.to_blueprint()
assert result == expected_core
+
+
+class TestConceptCodeValidation:
+ """Tests for concept code validation and snake_case to PascalCase conversion."""
+
+ @pytest.mark.parametrize(
+ "topic,input_code,expected_code",
+ ConceptCodeValidationTestCases.TEST_CASES,
+ )
+ def test_concept_code_conversion(self, topic: str, input_code: str, expected_code: str):
+ """Test that concept codes are properly converted from snake_case to PascalCase."""
+ log.verbose(f"Testing {topic}: '{input_code}' -> '{expected_code}'")
+
+ # Create a ConceptSpec with the input code
+ concept_spec = ConceptSpec(
+ the_concept_code=input_code,
+ definition="Test concept for code validation",
+ refines=None,
+ structure=None,
+ )
+
+ # Verify the concept code was converted correctly
+ assert concept_spec.the_concept_code == expected_code, (
+ f"Expected concept code to be '{expected_code}', but got '{concept_spec.the_concept_code}'"
+ )
diff --git a/tests/unit/pipelex/libraries/pipelines/builder/concept/test_data.py b/tests/unit/pipelex/libraries/pipelines/builder/concept/test_data.py
index 27152474f..923dfb74c 100644
--- a/tests/unit/pipelex/libraries/pipelines/builder/concept/test_data.py
+++ b/tests/unit/pipelex/libraries/pipelines/builder/concept/test_data.py
@@ -153,3 +153,82 @@ class ConceptBlueprintTestCases:
CONCEPT_WITH_INTEGER_FIELD,
CONCEPT_WITH_MULTIPLE_FIELDS,
]
+
+
+class ConceptCodeValidationTestCases:
+ """Test cases for concept code validation and snake_case to PascalCase conversion."""
+
+ # Test case: snake_case without domain -> PascalCase
+ SNAKE_CASE_NO_DOMAIN = (
+ "snake_case_no_domain",
+ "concept_name",
+ "ConceptName",
+ )
+
+ # Test case: PascalCase without domain -> unchanged
+ PASCAL_CASE_NO_DOMAIN = (
+ "pascal_case_no_domain",
+ "ConceptName",
+ "ConceptName",
+ )
+
+ # Test case: snake_case with domain -> domain.PascalCase
+ SNAKE_CASE_WITH_DOMAIN = (
+ "snake_case_with_domain",
+ "my_domain.concept_name",
+ "my_domain.ConceptName",
+ )
+
+ # Test case: PascalCase with domain -> unchanged
+ PASCAL_CASE_WITH_DOMAIN = (
+ "pascal_case_with_domain",
+ "my_domain.ConceptName",
+ "my_domain.ConceptName",
+ )
+
+ # Test case: mixed case with domain -> domain.PascalCase
+ MIXED_CASE_WITH_DOMAIN = (
+ "mixed_case_with_domain",
+ "my_domain.some_complex_concept_name",
+ "my_domain.SomeComplexConceptName",
+ )
+
+ # Test case: single word snake_case -> PascalCase
+ SINGLE_WORD_SNAKE = (
+ "single_word_snake",
+ "concept",
+ "Concept",
+ )
+
+ # Test case: multiple underscores -> PascalCase
+ MULTIPLE_UNDERSCORES = (
+ "multiple_underscores",
+ "my_super_long_concept_name",
+ "MySuperLongConceptName",
+ )
+
+ # Test case: with numbers in snake_case
+ WITH_NUMBERS_SNAKE = (
+ "with_numbers_snake",
+ "concept_v2_name",
+ "ConceptV2Name",
+ )
+
+ # Test case: with numbers in domain.snake_case
+ WITH_NUMBERS_DOMAIN_SNAKE = (
+ "with_numbers_domain_snake",
+ "domain_v1.concept_name_v2",
+ "domain_v1.ConceptNameV2",
+ )
+
+ TEST_CASES: ClassVar[list[tuple[str, str, str]]] = [
+ SNAKE_CASE_NO_DOMAIN,
+ PASCAL_CASE_NO_DOMAIN,
+ SNAKE_CASE_WITH_DOMAIN,
+ PASCAL_CASE_WITH_DOMAIN,
+ MIXED_CASE_WITH_DOMAIN,
+ SINGLE_WORD_SNAKE,
+ MULTIPLE_UNDERSCORES,
+ WITH_NUMBERS_SNAKE,
+ WITH_NUMBERS_DOMAIN_SNAKE,
+ ]