|
12 | 12 | setup_pipeline, |
13 | 13 | setup_test_case, |
14 | 14 | ) |
| 15 | +from deepset_mcp.benchmark.runner.teardown_actions import ( |
| 16 | + teardown_all, |
| 17 | + teardown_index, |
| 18 | + teardown_pipeline, |
| 19 | + teardown_test_case, |
| 20 | +) |
15 | 21 |
|
16 | 22 | app = typer.Typer(help="Short commands for listing/creating test cases, pipelines, and indexes.") |
17 | 23 |
|
@@ -199,6 +205,154 @@ def create_index( |
199 | 205 | raise typer.Exit(code=1) |
200 | 206 |
|
201 | 207 |
|
| 208 | +@app.command("delete-case") |
| 209 | +def delete_case( |
| 210 | + test_name: str = typer.Argument(..., help="Test-case name (without .yml)."), |
| 211 | + workspace_name: str = typer.Option( |
| 212 | + "default", "--workspace", "-w", help="Workspace from which to delete pipelines and indexes." |
| 213 | + ), |
| 214 | + api_key: str | None = typer.Option( |
| 215 | + None, |
| 216 | + "--api-key", |
| 217 | + "-k", |
| 218 | + help="Explicit DP_API_KEY to use (overrides environment).", |
| 219 | + ), |
| 220 | + task_dir: str | None = typer.Option( |
| 221 | + None, |
| 222 | + help="Directory where test-case YAMLs are stored.", |
| 223 | + ), |
| 224 | +) -> None: |
| 225 | + """Load a single test-case by name and delete its pipeline + index (if any) from `workspace_name`.""" |
| 226 | + try: |
| 227 | + test_cfg = load_test_case_by_name(name=test_name, task_dir=task_dir) |
| 228 | + except FileNotFoundError: |
| 229 | + typer.secho(f"Test-case '{test_name}' not found under {task_dir}.", fg=typer.colors.RED) |
| 230 | + raise typer.Exit(code=1) |
| 231 | + except Exception as e: |
| 232 | + typer.secho(f"Failed to load test-case '{test_name}': {e}", fg=typer.colors.RED) |
| 233 | + raise typer.Exit(code=1) |
| 234 | + |
| 235 | + typer.secho(f"→ Deleting resources for '{test_name}' from '{workspace_name}'…", fg=typer.colors.GREEN) |
| 236 | + try: |
| 237 | + teardown_test_case(test_cfg=test_cfg, workspace_name=workspace_name, api_key=api_key) |
| 238 | + except Exception as e: |
| 239 | + typer.secho(f"✘ Failed to teardown '{test_name}': {e}", fg=typer.colors.RED) |
| 240 | + raise typer.Exit(code=1) |
| 241 | + |
| 242 | + typer.secho(f"✔ '{test_name}' resources deleted.", fg=typer.colors.GREEN) |
| 243 | + |
| 244 | + |
| 245 | +@app.command("delete-all") |
| 246 | +def delete_all( |
| 247 | + workspace_name: str = typer.Option( |
| 248 | + "default", "--workspace", "-w", help="Workspace from which to delete pipelines and indexes." |
| 249 | + ), |
| 250 | + api_key: str | None = typer.Option( |
| 251 | + None, |
| 252 | + "--api-key", |
| 253 | + "-k", |
| 254 | + help="Explicit DP_API_KEY to use (overrides environment).", |
| 255 | + ), |
| 256 | + concurrency: int = typer.Option( |
| 257 | + 5, |
| 258 | + "--concurrency", |
| 259 | + "-c", |
| 260 | + help="Maximum number of test-cases to teardown in parallel.", |
| 261 | + ), |
| 262 | + task_dir: str | None = typer.Option( |
| 263 | + None, |
| 264 | + help="Directory where test-case YAMLs are stored.", |
| 265 | + ), |
| 266 | +) -> None: |
| 267 | + """Load every test-case under `task_dir` and delete pipelines + indexes from `workspace_name` in parallel.""" |
| 268 | + paths = find_all_test_case_paths(task_dir) |
| 269 | + if not paths: |
| 270 | + typer.secho(f"No test-case files found in {task_dir}", fg=typer.colors.RED) |
| 271 | + raise typer.Exit(code=1) |
| 272 | + |
| 273 | + # 1) Load all configs |
| 274 | + test_cfgs: list[TestCaseConfig] = [] |
| 275 | + for p in paths: |
| 276 | + try: |
| 277 | + cfg = load_test_case_from_path(path=p) |
| 278 | + test_cfgs.append(cfg) |
| 279 | + except Exception as e: |
| 280 | + typer.secho(f"Skipping '{p.stem}' (load error: {e})", fg=typer.colors.YELLOW) |
| 281 | + |
| 282 | + if not test_cfgs: |
| 283 | + typer.secho("No valid test-case configs to delete.", fg=typer.colors.RED) |
| 284 | + raise typer.Exit(code=1) |
| 285 | + |
| 286 | + typer.secho( |
| 287 | + f"→ Deleting {len(test_cfgs)} test-cases from '{workspace_name}' (concurrency={concurrency})…", |
| 288 | + fg=typer.colors.GREEN, |
| 289 | + ) |
| 290 | + try: |
| 291 | + teardown_all( |
| 292 | + test_cfgs=test_cfgs, |
| 293 | + workspace_name=workspace_name, |
| 294 | + api_key=api_key, |
| 295 | + concurrency=concurrency, |
| 296 | + ) |
| 297 | + except Exception as e: |
| 298 | + typer.secho(f"✘ Some test-cases failed during deletion: {e}", fg=typer.colors.RED) |
| 299 | + raise typer.Exit(code=1) |
| 300 | + |
| 301 | + typer.secho("✔ All test-cases teardown attempted.", fg=typer.colors.GREEN) |
| 302 | + |
| 303 | + |
| 304 | +@app.command("delete-pipe") |
| 305 | +def delete_pipe( |
| 306 | + pipeline_name: str = typer.Option(..., "--name", "-n", help="Name of the pipeline to delete."), |
| 307 | + workspace_name: str = typer.Option( |
| 308 | + "default", "--workspace", "-w", help="Workspace from which to delete the pipeline." |
| 309 | + ), |
| 310 | + api_key: str | None = typer.Option( |
| 311 | + None, |
| 312 | + "--api-key", |
| 313 | + "-k", |
| 314 | + help="Explicit DP_API_KEY to use (overrides environment).", |
| 315 | + ), |
| 316 | +) -> None: |
| 317 | + """Delete a single pipeline from `workspace_name`.""" |
| 318 | + try: |
| 319 | + teardown_pipeline( |
| 320 | + pipeline_name=pipeline_name, |
| 321 | + workspace_name=workspace_name, |
| 322 | + api_key=api_key, |
| 323 | + ) |
| 324 | + typer.secho(f"✔ Pipeline '{pipeline_name}' deleted from '{workspace_name}'.", fg=typer.colors.GREEN) |
| 325 | + except Exception as e: |
| 326 | + typer.secho(f"✘ Failed to delete pipeline '{pipeline_name}': {e}", fg=typer.colors.RED) |
| 327 | + raise typer.Exit(code=1) |
| 328 | + |
| 329 | + |
| 330 | +@app.command("delete-index") |
| 331 | +def delete_index( |
| 332 | + index_name: str = typer.Option(..., "--name", "-n", help="Name of the index to delete."), |
| 333 | + workspace_name: str = typer.Option( |
| 334 | + "default", "--workspace", "-w", help="Workspace from which to delete the index." |
| 335 | + ), |
| 336 | + api_key: str | None = typer.Option( |
| 337 | + None, |
| 338 | + "--api-key", |
| 339 | + "-k", |
| 340 | + help="Explicit DP_API_KEY to use (overrides environment).", |
| 341 | + ), |
| 342 | +) -> None: |
| 343 | + """Delete a single index from `workspace_name`.""" |
| 344 | + try: |
| 345 | + teardown_index( |
| 346 | + index_name=index_name, |
| 347 | + workspace_name=workspace_name, |
| 348 | + api_key=api_key, |
| 349 | + ) |
| 350 | + typer.secho(f"✔ Index '{index_name}' deleted from '{workspace_name}'.", fg=typer.colors.GREEN) |
| 351 | + except Exception as e: |
| 352 | + typer.secho(f"✘ Failed to delete index '{index_name}': {e}", fg=typer.colors.RED) |
| 353 | + raise typer.Exit(code=1) |
| 354 | + |
| 355 | + |
202 | 356 | def cli() -> None: |
203 | 357 | """Entrypoint for the benchmark CLI.""" |
204 | 358 | app() |
|
0 commit comments