|
| 1 | +# (C) Datadog, Inc. 2026-present |
| 2 | +# All rights reserved |
| 3 | +# Licensed under a 3-clause BSD style license (see LICENSE) |
| 4 | +from typing import Annotated, Literal |
| 5 | + |
| 6 | +from pydantic import Field |
| 7 | + |
| 8 | +from ddev.ai.tools.core.base import BaseToolInput |
| 9 | +from ddev.ai.tools.shell.base import CmdTool |
| 10 | + |
| 11 | +ValidateSubcommand = Literal["config", "models", "metadata", "all"] |
| 12 | + |
| 13 | + |
| 14 | +class DdevValidateInput(BaseToolInput): |
| 15 | + subcommand: Annotated[ |
| 16 | + ValidateSubcommand, |
| 17 | + Field( |
| 18 | + description=( |
| 19 | + "Which validator to run. Options:" |
| 20 | + "- 'config': validates assets/configuration/spec.yaml against data/conf.yaml.example. " |
| 21 | + "- 'models': validates spec.yaml against datadog_checks/<integration>/config_models/. " |
| 22 | + "- 'metadata': validates metadata.csv. " |
| 23 | + "- 'all': runs all ~20 validators in parallel. Some of these always scan the entire " |
| 24 | + "repository, so the output may include failures for files outside of <integration>. " |
| 25 | + "IGNORE those unrelated failures — only act on failures that reference files inside " |
| 26 | + "your integration's directory. It might take a long time to run. Use 'all' only as " |
| 27 | + "a final sweep to catch issues the targeted validators do not cover." |
| 28 | + ) |
| 29 | + ), |
| 30 | + ] |
| 31 | + integration: Annotated[str, Field(description="Integration name to validate")] |
| 32 | + sync: Annotated[ |
| 33 | + bool, |
| 34 | + Field( |
| 35 | + description=( |
| 36 | + "Regenerate / auto-fix derived files instead of only checking. " |
| 37 | + "For 'config', regenerates conf.yaml.example. " |
| 38 | + "For 'models', regenerates config_models/. " |
| 39 | + "For 'metadata', rewrites metadata.csv into canonical form. " |
| 40 | + "For 'all', auto-fixes every validator that supports it." |
| 41 | + ) |
| 42 | + ), |
| 43 | + ] = False |
| 44 | + |
| 45 | + |
| 46 | +class DdevValidateTool(CmdTool[DdevValidateInput]): |
| 47 | + """Validates an integration's spec, config example, config models, or metadata.csv. |
| 48 | + Set `sync=true` to regenerate the derived files from spec.yaml.""" |
| 49 | + |
| 50 | + timeout = 660 |
| 51 | + |
| 52 | + @property |
| 53 | + def name(self) -> str: |
| 54 | + return "ddev_validate" |
| 55 | + |
| 56 | + def cmd(self, tool_input: DdevValidateInput) -> list[str]: |
| 57 | + cmd = ["ddev", "--no-interactive", "validate", tool_input.subcommand] |
| 58 | + if tool_input.sync: |
| 59 | + cmd.append("--fix" if tool_input.subcommand == "all" else "--sync") |
| 60 | + cmd.append(tool_input.integration) |
| 61 | + return cmd |
0 commit comments