From 0441bcd91146fea0ad0d602f58fcf653ce5a0709 Mon Sep 17 00:00:00 2001 From: Matteo Rosati Date: Wed, 22 Apr 2026 22:21:14 +0200 Subject: [PATCH] remove command aliases --- README.md | 14 ++--- chromy/cli.py | 10 --- tests/test_cli.py | 157 +++++++++++++++++++++++----------------------- 3 files changed, 84 insertions(+), 97 deletions(-) diff --git a/README.md b/README.md index 6f3e1ce..fdd0374 100644 --- a/README.md +++ b/README.md @@ -116,13 +116,13 @@ uv run mypy . ## Commands ```text -list-collections | lc -create-collection | cc -delete-collection | dc -count | co -add-data | ad -query | q -delete | del --where = +list-collections +create-collection +delete-collection +count +add-data +query +delete --where = ``` ### Examples diff --git a/chromy/cli.py b/chromy/cli.py index 80c3be9..666ec92 100644 --- a/chromy/cli.py +++ b/chromy/cli.py @@ -31,7 +31,6 @@ def _fail(message: str) -> None: raise typer.Exit(1) -@app.command("lc", help="List all collections stored in the local Chroma database.") @app.command( "list-collections", help="List all collections stored in the local Chroma database.", @@ -40,7 +39,6 @@ def list_collections() -> None: _run(handle_list_collections) -@app.command("cc", help="Create a collection in the local Chroma database.") @app.command( "create-collection", help="Create a collection in the local Chroma database.", @@ -57,7 +55,6 @@ def create_collection( _fail(f"Collection '{collection}' already exists.") -@app.command("dc", help="Delete a collection from the local Chroma database.") @app.command( "delete-collection", help="Delete a collection from the local Chroma database.", @@ -74,7 +71,6 @@ def delete_collection( _fail(f"Collection '{collection}' does not exist.") -@app.command("co", help="Count records in a collection from the local Chroma database.") @app.command( "count", help="Count records in a collection from the local Chroma database.", @@ -91,10 +87,6 @@ def count( _fail(f"Collection '{collection}' does not exist.") -@app.command( - "ad", - help="Chunk, embed, and add a file to a collection in the local Chroma database.", -) @app.command( "add-data", help="Chunk, embed, and add a file to a collection in the local Chroma database.", @@ -117,7 +109,6 @@ def add_data( _fail(f"The file {file} was not found.") -@app.command("q", help="Query a collection with the provided text.") @app.command("query", help="Query a collection with the provided text.") def query( collection: Annotated[ @@ -135,7 +126,6 @@ def query( _fail(f"Collection '{collection}' does not exist.") -@app.command("del", help="Delete records from a collection using a metadata filter.") @app.command("delete", help="Delete records from a collection using a metadata filter.") def delete_records( collection: Annotated[ diff --git a/tests/test_cli.py b/tests/test_cli.py index 2bbb703..910c560 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -11,102 +11,99 @@ from chromy.cli import app class CliTests(unittest.TestCase): - def test_list_collections_and_alias(self) -> None: - for command in ("list-collections", "lc"): - with patch( - "chromy.handlers.list_collections.list_collections", - return_value=[], - ): - result = _invoke([command]) + def test_list_collections(self) -> None: + with patch( + "chromy.handlers.list_collections.list_collections", + return_value=[], + ): + result = _invoke(["list-collections"]) - self.assertEqual(result.exit_code, 0) - self.assertEqual(result.stdout, "No collections found.\n") + self.assertEqual(result.exit_code, 0) + self.assertEqual(result.stdout, "No collections found.\n") - def test_create_collection_and_alias(self) -> None: - for command in ("create-collection", "cc"): - with patch( - "chromy.handlers.create_collection.create_collection", - return_value="notes", - ) as create_collection: - result = _invoke([command, "notes"]) + def test_create_collection(self) -> None: + with patch( + "chromy.handlers.create_collection.create_collection", + return_value="notes", + ) as create_collection: + result = _invoke(["create-collection", "notes"]) - create_collection.assert_called_once_with("notes") - self.assertEqual(result.exit_code, 0) - self.assertEqual(result.stdout, "Created collection 'notes'.\n") + create_collection.assert_called_once_with("notes") + self.assertEqual(result.exit_code, 0) + self.assertEqual(result.stdout, "Created collection 'notes'.\n") - def test_delete_collection_and_alias(self) -> None: - for command in ("delete-collection", "dc"): - with patch( - "chromy.handlers.delete_collection.delete_collection", - ) as delete_collection: - result = _invoke([command, "notes"]) + def test_delete_collection(self) -> None: + with patch( + "chromy.handlers.delete_collection.delete_collection", + ) as delete_collection: + result = _invoke(["delete-collection", "notes"]) - delete_collection.assert_called_once_with("notes") - self.assertEqual(result.exit_code, 0) - self.assertEqual(result.stdout, "Deleted collection 'notes'.\n") + delete_collection.assert_called_once_with("notes") + self.assertEqual(result.exit_code, 0) + self.assertEqual(result.stdout, "Deleted collection 'notes'.\n") - def test_count_and_alias(self) -> None: - for command in ("count", "co"): - with patch( - "chromy.handlers.count_collection.count_collection", - return_value=7, - ) as count_collection: - result = _invoke([command, "notes"]) + def test_count(self) -> None: + with patch( + "chromy.handlers.count_collection.count_collection", + return_value=7, + ) as count_collection: + result = _invoke(["count", "notes"]) - count_collection.assert_called_once_with("notes") - self.assertEqual(result.exit_code, 0) - self.assertEqual(result.stdout, "7\n") + count_collection.assert_called_once_with("notes") + self.assertEqual(result.exit_code, 0) + self.assertEqual(result.stdout, "7\n") - def test_add_data_and_alias(self) -> None: - for command in ("add-data", "ad"): - with patch( - "chromy.handlers.add_data.ingest_file", - return_value=3, - ) as ingest_file: - result = _invoke([command, "notes", "romeo_and_juliet.txt"]) + def test_add_data(self) -> None: + with patch( + "chromy.handlers.add_data.ingest_file", + return_value=3, + ) as ingest_file: + result = _invoke(["add-data", "notes", "romeo_and_juliet.txt"]) - ingest_file.assert_called_once_with("notes", "romeo_and_juliet.txt") - self.assertEqual(result.exit_code, 0) - self.assertEqual(result.stdout, "Added 3 records to collection 'notes'.\n") + ingest_file.assert_called_once_with("notes", "romeo_and_juliet.txt") + self.assertEqual(result.exit_code, 0) + self.assertEqual(result.stdout, "Added 3 records to collection 'notes'.\n") - def test_query_and_alias(self) -> None: + def test_query(self) -> None: query_result = {"ids": [["1"]], "documents": [["hello"]]} - for command in ("query", "q"): - with ( - patch( - "chromy.handlers.query.run_query", return_value=query_result - ) as run, - patch( - "chromy.handlers.query.format_query_result", - return_value=["Query results:", "1"], - ) as format_result, - ): - result = _invoke([command, "notes", "Where is Romeo?"]) + with ( + patch("chromy.handlers.query.run_query", return_value=query_result) as run, + patch( + "chromy.handlers.query.format_query_result", + return_value=["Query results:", "1"], + ) as format_result, + ): + result = _invoke(["query", "notes", "Where is Romeo?"]) - run.assert_called_once_with("notes", "Where is Romeo?") - format_result.assert_called_once_with(query_result) - self.assertEqual(result.exit_code, 0) - self.assertEqual(result.stdout, "Query results:\n1\n") + run.assert_called_once_with("notes", "Where is Romeo?") + format_result.assert_called_once_with(query_result) + self.assertEqual(result.exit_code, 0) + self.assertEqual(result.stdout, "Query results:\n1\n") - def test_delete_records_and_alias(self) -> None: - for command in ("delete", "del"): - with patch( - "chromy.handlers.delete_collection.delete_data", - return_value=2, - ) as delete_data: - result = _invoke( - [command, "notes", "--where", " file_name = play.txt "], - ) - - delete_data.assert_called_once_with("notes", {"file_name": "play.txt"}) - self.assertEqual(result.exit_code, 0) - self.assertEqual( - result.stdout, - "Deleted 2 record(s) from collection 'notes' " - "where file_name=play.txt.\n", + def test_delete_records(self) -> None: + with patch( + "chromy.handlers.delete_collection.delete_data", + return_value=2, + ) as delete_data: + result = _invoke( + ["delete", "notes", "--where", " file_name = play.txt "], ) + delete_data.assert_called_once_with("notes", {"file_name": "play.txt"}) + self.assertEqual(result.exit_code, 0) + self.assertEqual( + result.stdout, + "Deleted 2 record(s) from collection 'notes' " + "where file_name=play.txt.\n", + ) + + def test_removed_alias_is_rejected(self) -> None: + result = _invoke(["lc"]) + + self.assertNotEqual(result.exit_code, 0) + self.assertIn("No such command", result.output) + def test_invalid_delete_filter_keeps_user_facing_error(self) -> None: result = _invoke(["delete", "notes", "--where", "file_name"])