or run

npx @tessl/cli init
Log in

Version

Files

tile.json

task.mdevals/scenario-4/

Configuration Export System

Build a system that exports application configuration objects to JSON format with metadata tracking for version control and audit purposes.

Requirements

The system should:

  1. Export configuration objects to JSON format with type information preserved
  2. Include a timestamp indicating when the configuration was exported
  3. Allow reconstruction of configuration objects from exported JSON without explicit type specification
  4. Handle nested configuration objects with different types

Configuration Classes

Your solution should work with the following configuration structures:

class DatabaseConfig:
    def __init__(self, host: str, port: int, max_connections: int):
        self.host = host
        self.port = port
        self.max_connections = max_connections

class CacheConfig:
    def __init__(self, ttl_seconds: int, max_size: int):
        self.ttl_seconds = ttl_seconds
        self.max_size = max_size

class AppConfig:
    def __init__(self, app_name: str, database: DatabaseConfig, cache: CacheConfig):
        self.app_name = app_name
        self.database = database
        self.cache = cache

Test Cases

Export with metadata { .test }

  • Given an AppConfig with database config (host="localhost", port=5432, max_connections=10) and cache config (ttl_seconds=300, max_size=1000), when exported with metadata, the output should include a -meta section with class information and dump timestamp. @test

Reconstruct without type specification { .test }

  • Given a JSON export that includes metadata, when loading the configuration without specifying the target class type, the system should reconstruct the correct AppConfig, DatabaseConfig, and CacheConfig objects. @test

Metadata includes type paths { .test }

  • Given an AppConfig with nested objects, when exported with metadata, the -meta section should map JSON paths to fully-qualified class names for the root object and all nested objects. @test

Export without metadata { .test }

  • Given an AppConfig, when exported without metadata mode enabled, the output should be a plain JSON dictionary with no -meta section. @test

Implementation

@generates

API

def export_config(config: AppConfig, include_metadata: bool = True) -> dict:
    """
    Export configuration to a JSON-compatible dictionary.

    Args:
        config: The application configuration to export
        include_metadata: If True, include type and timestamp metadata

    Returns:
        A dictionary containing the configuration data and optionally metadata
    """
    pass

def load_config(data: dict) -> AppConfig:
    """
    Load configuration from a JSON-compatible dictionary.

    If the data contains metadata, uses it to reconstruct the correct types.
    Otherwise, requires explicit type information.

    Args:
        data: The dictionary containing configuration data

    Returns:
        The reconstructed AppConfig object
    """
    pass

Dependencies { .dependencies }

jsons { .dependency }

Provides serialization and deserialization support with metadata capabilities.

@satisfied-by