Abstract

This folder contains unit tests for the Kubernetes Operator Agent.

Python Unit Tests API#

Documentation to be provided.

Tests API Documentation#

Test Configuration#

Pytest configuration module.

This module sets up configurations and fixtures for Pytest, allowing the test environment to include custom configurations for the application.

tests.conftest.MODULE_DIR = '/home/runner/work/k8s-operator-agent/k8s-operator-agent'#

Add the parent directory of the current file to the system path

tests.conftest.config()#

Provide a Hypercorn Config object for testing.

This fixture returns a pre-configured Hypercorn hypercorn.config.Config object used for testing purposes. It binds the server to 0.0.0.0:8080, enables the reloader, and sets the access log to stdout.

Variables:

ret_value (hypercorn.config.Config) – The HyperCorn Config object.

Return ret_value:

The configured Hypercorn Config object.

Test Init#

Kubernetes Operator Agent init test module.

tests.test_init.test_get_version_fallback()#

Test get_version fallback to default version on error.

This test simulates a failure in retrieving the version from the Git repository by raising a ValueError. It mocks the Version.from_str method and its devel_increment behavior to verify that the default version (“0.0.1”) is used when the Git query fails.

Variables:
  • mock_version (MagicMock) – A MagicMock of the version_query.Version object.

  • version (str) – A string representation of the test version.

tests.test_init.test_get_version_success()#

Test get_version when git version query is successful.

This test mocks the return value of query_git_repo to simulate successful version retrieval. It checks whether the version is returned correctly and verifies that the to_str method is called once.

Variables:
  • mock_version (MagicMock) – A MagicMock of the version_query module.

  • version (str) – A string representation of the test version.

tests.test_init.test_version_init()#

Test if __version__ is initialized correctly.

This test verifies whether __version__ is correctly initialized as a string and checks if its value matches the result of Version.from_str(“0.0.1”).to_str().

Variables:

__version__ (str) – The module’s version value.

Test Prompts#

Kubernetes Operator Agent unit tests module.

tests.test_prompts.test_prompt_avoidance_section()#

Test that SYSTEM_PROMPT contains avoidance instructions.

Ensures that SYSTEM_PROMPT includes instructions to avoid prompting users for input, explaining how to do things, or asking users to take actions.

Variables:

SYSTEM_PROMPT (str) – The prompt provided to the LLM system.

tests.test_prompts.test_prompt_contains_helm()#

Test that SYSTEM_PROMPT contains helm-related instructions.

Verifies the presence of key helm-related operations such as ‘helm list’, the use of helm for installations, updates, and deletions of applications.

Variables:

SYSTEM_PROMPT (str) – The prompt provided to the LLM system.

tests.test_prompts.test_prompt_contains_kubectl()#

Test that SYSTEM_PROMPT contains kubectl-related instructions.

Ensures that the SYSTEM_PROMPT includes kubectl commands for querying and managing Kubernetes resources, including CRDs and other resource types.

Variables:

SYSTEM_PROMPT (str) – The prompt provided to the LLM system.

tests.test_prompts.test_prompt_exists()#

Test that SYSTEM_PROMPT is defined and contains non-empty content.

Ensures that the SYSTEM_PROMPT constant exists, is a string, and is not empty after stripping any surrounding whitespace.

Variables:

SYSTEM_PROMPT (str) – The prompt provided to the LLM system.

tests.test_prompts.test_prompt_instructions()#

Test that SYSTEM_PROMPT contains key instruction sections.

Verifies the presence of specific instructional guidance, including usage of the terminal function, explanations of commands, and decision-making based on the current cluster state.

Variables:

SYSTEM_PROMPT (str) – The prompt provided to the LLM system.

tests.test_prompts.test_prompt_keywords(keyword)#

Parameterized test for ensuring key terms in SYSTEM_PROMPT.

This test checks if essential concepts and keywords like ‘CurrentClusterState’ and ‘bash pipes’ are present in the SYSTEM_PROMPT content.

Parameters:

keyword (str) – The parametrized keyword string.

Variables:

SYSTEM_PROMPT (str) – The prompt provided to the LLM system.

Test Settings#

Kubernetes Operator Agent settings unit tests module.

tests.test_settings.test_debug_setting()#

Test that DEBUG is set to True by default and is of type bool.

Variables:

DEBUG (bool) – Enable or disable debug output.

tests.test_settings.test_defaults(env_var, default_value, var_type)#

Parameterized test to check various environment variable default values.

Parameters:
  • env_var (str) – The environment variable under test.

  • default_value (str) – The expected default value.

  • var_type (str) – The type of the expected value.

tests.test_settings.test_langchain_endpoint()#

Test that LANGCHAIN_ENDPOINT is set to the correct default value.

tests.test_settings.test_langchain_project()#

Test that LANGCHAIN_PROJECT is set to the correct default value.

tests.test_settings.test_log_level_debug()#

Test that LOG_LEVEL is set to DEBUG when DEBUG is True.

Variables:

LOG_LEVEL (str) – Setting to determine the verbosity of log output.

tests.test_settings.test_ollama_base_url()#

Test that OLLAMA_BASE_URL is set to the default value.

Variables:

OLLAMA_BASE_URL (str) – URL for an Open LLAMA server to use.

tests.test_settings.test_ollama_model()#

Test that OLLAMA_MODEL is set to the default value.

Variables:

OLLAMA_MODEL (str) – The OLLAMA model to be used.

tests.test_settings.test_openai_model()#

Test that OPENAI_MODEL is set to the default value.

Variables:

OPENAI_MODEL (str) – Name of the OpenAI model to use.

tests.test_settings.test_openai_model_temp()#

Test that OPENAI_MODEL_TEMP is set to the correct default value.

Variables:

OPENAI_MODEL_TEMP (str) – Value of OpenAI Model temp setting.

tests.test_settings.test_port()#

Test that PORT is set to the correct default value of 8000.

Variables:

PORT (str) – The port that the agent will listen on.

tests.test_settings.test_redis_url()#

Test that REDIS_URL is set to the default Redis server URL.

Variables:

REDIS_URL (str) – URL for a working Redis server.

Test Webapp#