"""Tests for CLI enrich command.""" import json from click.testing import CliRunner from vlm.cli import main def test_enrich_in_place_updates_identities(tmp_path): """`vlm enrich` should update identities file in place by default.""" library_root = tmp_path / "library" library_root.mkdir(parents=True) config_file = tmp_path / "config.yaml" config_file.write_text( f""" library_root: {library_root} categories: movie: [movie, movies] series: [series, tv, shows] anime: [anime] enrichment: cache_db: {tmp_path / 'cache.db'} """.strip() ) identities_file = tmp_path / "identities.json" identities_file.write_text(json.dumps({ "metadata": {}, "movies": [ { "path": "/library/movie/Test.2024.mkv", "filename": "Test.2024.mkv", "category": "movie", "title": "Test", "year": 2024, "confidence": 0.9, "needs_review": False, } ], "series": [], "anime": [], "other": [], }, ensure_ascii=False)) runner = CliRunner() result = runner.invoke(main, ["--config", str(config_file), "enrich", "--input", str(identities_file)]) assert result.exit_code == 0 assert "Enrichment complete!" in result.output updated = json.loads(identities_file.read_text(encoding="utf-8")) assert updated["metadata"]["enriched"] is True def test_enrich_refresh_all_option_runs_successfully(tmp_path): """`vlm enrich --refresh-all` should execute successfully.""" library_root = tmp_path / "library" library_root.mkdir(parents=True) config_file = tmp_path / "config.yaml" config_file.write_text( f""" library_root: {library_root} categories: movie: [movie, movies] series: [series, tv, shows] anime: [anime] enrichment: cache_db: {tmp_path / 'cache.db'} """.strip() ) identities_file = tmp_path / "identities.json" identities_file.write_text(json.dumps({ "metadata": {}, "movies": [], "series": [], "anime": [], "other": [], })) runner = CliRunner() result = runner.invoke( main, ["--config", str(config_file), "enrich", "--input", str(identities_file), "--refresh-all"], ) assert result.exit_code == 0 assert "Enrichment complete!" in result.output def test_enrich_rejects_conflicting_refresh_flags(tmp_path): """Conflicting refresh flags should fail with a clear error.""" library_root = tmp_path / "library" library_root.mkdir(parents=True) config_file = tmp_path / "config.yaml" config_file.write_text( f""" library_root: {library_root} categories: movie: [movie, movies] series: [series, tv, shows] anime: [anime] enrichment: cache_db: {tmp_path / 'cache.db'} """.strip() ) identities_file = tmp_path / "identities.json" identities_file.write_text(json.dumps({ "metadata": {}, "movies": [], "series": [], "anime": [], "other": [], })) runner = CliRunner() result = runner.invoke( main, [ "--config", str(config_file), "enrich", "--input", str(identities_file), "--refresh-all", "--refresh-changed-only", ], ) assert result.exit_code == 1 assert "mutually exclusive" in result.output