from typing import Dict
from typing import Any
import uuid


def make_test_experiment_config(config: Dict[str, Any]) -> Dict[str, Any]:
    """
    Create a short experiment that based on a modified version of the
    experiment config of the request and monitors its progress for success.
    The short experiment is created as archived to be not user-visible by
    default.

    The experiment configuration is modified such that:
    1. The training step takes a minimum amount of time.
    2. All checkpoints are GC'd after experiment finishes.
    3. The experiment does not attempt restarts on failure.
    """
    config_test = config.copy()
    config_test.update(
        {
            "description": "[test-mode] {}".format(
                config_test.get("description", str(uuid.uuid4()))
            ),
            "batches_per_step": 1,
            "min_validation_period": 1,
            "checkpoint_storage": {
                **config_test.get("checkpoint_storage", {}),
                "save_experiment_best": 0,
                "save_trial_best": 0,
                "save_trial_latest": 0,
            },
            "searcher": {
                "name": "single",
                "metric": config_test["searcher"]["metric"],
                "max_steps": 1,
            },
            "resources": {**config_test.get("resources", {"slots_per_trial": 1})},
            "max_restarts": 0,
        }
    )
    config.setdefault(
        "data_layer", {"type": "shared_fs", "container_storage_path": "/tmp/determined"}
    )
    return config_test