CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-crosshair-tool

Analyze Python code for correctness using symbolic execution and SMT solving to automatically find counterexamples for functions with type annotations and contracts.

86

1.24x
Overview
Eval results
Files

task.mdevals/scenario-8/

Configuration Validator

Build a system that uses symbolic execution to find valid configuration parameters that satisfy system constraints.

Problem Description

You need to implement configuration validation functions for a server deployment system. The system must find valid configuration values that satisfy multiple interdependent constraints.

Requirements

Implement a function validate_server_config that verifies a server configuration is valid. The configuration has the following parameters:

  • worker_threads: Number of worker threads (must be positive integer)
  • connection_pool_size: Size of connection pool (must be positive integer)
  • max_memory_mb: Maximum memory in MB (must be positive integer)
  • timeout_seconds: Request timeout in seconds (must be positive integer)

The configuration must satisfy these constraints:

  1. worker_threads must be between 1 and 32
  2. connection_pool_size must be at least worker_threads * 2
  3. max_memory_mb must be at least connection_pool_size * 10
  4. timeout_seconds must be between 1 and 300
  5. The total score (worker_threads * 100 + connection_pool_size * 10) must not exceed 5000

The function should raise a ValueError with a descriptive message if any constraint is violated.

Implement a second function find_optimal_config that uses symbolic execution to find a configuration that maximizes worker_threads while satisfying all constraints, given a fixed max_memory_mb budget.

Test Cases

  • Configuration with worker_threads=4, connection_pool_size=8, max_memory_mb=80, timeout_seconds=30 is valid @test
  • Configuration with worker_threads=4, connection_pool_size=6, max_memory_mb=80, timeout_seconds=30 raises ValueError because pool size is too small @test
  • Finding optimal config with max_memory_mb=500 returns a valid configuration that maximizes worker threads @test

Implementation

@generates

API

from typing import NamedTuple

class ServerConfig(NamedTuple):
    """Server configuration parameters."""
    worker_threads: int
    connection_pool_size: int
    max_memory_mb: int
    timeout_seconds: int

def validate_server_config(config: ServerConfig) -> None:
    """
    Validate a server configuration against system constraints.

    Raises:
        ValueError: If any constraint is violated, with a message describing the issue.
    """
    pass

def find_optimal_config(max_memory_mb: int) -> ServerConfig:
    """
    Find a valid configuration that maximizes worker_threads given a memory budget.

    Uses symbolic execution to search the constraint space.

    Args:
        max_memory_mb: The memory budget constraint

    Returns:
        An optimal ServerConfig that maximizes worker_threads

    Raises:
        ValueError: If no valid configuration exists for the given budget
    """
    pass

Dependencies { .dependencies }

crosshair-tool { .dependency }

Provides symbolic execution and constraint solving capabilities for searching valid parameter combinations.

@satisfied-by

Install with Tessl CLI

npx tessl i tessl/pypi-crosshair-tool

tile.json