From a3d35c7f12a1e1be61a4c0b022a277b273f460e0 Mon Sep 17 00:00:00 2001 From: nvaldez Date: Thu, 19 Nov 2026 11:53:41 +0100 Subject: [PATCH] Implement SPEC 7.1.1.4: wiki init duplicate error handling wiki init now catches FileExistsError, prints one stderr line with the update suggestion, and exits 1. SPEC.md status for wiki init bumped to Implemented (v1.22.2). Adds test for message format, exit code, and single-line stderr output. Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe --- SPEC.md | 12 ++++++------ src/fiona/__main__.py | 12 ++++++++++-- tests/test_fiona_main.py | 41 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 8 deletions(-) diff --git a/SPEC.md b/SPEC.md index 1e33a7c..e661f32 100644 --- a/SPEC.md +++ b/SPEC.md @@ -1,9 +1,9 @@ --- name: Fiona-Assistant Specification -version: 1.22.1 +version: 1.22.2 title: Project Spec Sheet created: 2026-09-23 -updated: 2026-10-24 +updated: 2026-11-04 type: summary --- @@ -1812,9 +1812,9 @@ Requirements for the `wiki` subcommands. #### 7.1.1. wiki init -> Status: Partially Implemented +> Status: Implemented -Implements sections 3 and 4.7.1. +Implements sections 3, 4.7.1, and 7.1.1. - *7.1.1.1.* Copy is 1:1 aside from `DATE_PLACEHOLDER`, `ignore_files`, and paths matched by the repository `.gitignore`. @@ -1832,8 +1832,8 @@ Implements sections 3 and 4.7.1. - *acceptance*: After init, `.gitignore` contains `__pycache__/` and `personal/`. A line `keep-me` written before init is still in the file. -- *7.1.1.4.* `NOT_IMPLEMENTED` The CLI turns the refusal of *3.2.2.* - into one stderr line and exit 1 (*1.2.7.*): +- *7.1.1.4.* The CLI turns the refusal of *3.2.2.* into one stderr + line and exit 1 (*1.2.7.*): `Error: Directory '' already contains llm-wiki files: . Run fiona-assistant wiki update to refresh the template.` The line is one line, even though it is wrapped here. `` is diff --git a/src/fiona/__main__.py b/src/fiona/__main__.py index ab165f5..d4be833 100644 --- a/src/fiona/__main__.py +++ b/src/fiona/__main__.py @@ -440,8 +440,16 @@ def main(): sys.exit(1) elif args.command == "wiki": if args.wiki_subcommand == "init": - result = wiki_init(args.directory) - print(result) + try: + result = wiki_init(args.directory) + print(result) + except FileExistsError as e: + # SPEC 7.1.1.4: format the error message and exit 1 + # The FileExistsError message is: "Directory '' already contains llm-wiki files: " + # We want: "Error: Directory '' already contains llm-wiki files: . Run fiona-assistant wiki update to refresh the template." + formatted_error = f"Error: {e}. Run fiona-assistant wiki update to refresh the template." + print(formatted_error, file=sys.stderr) + sys.exit(1) elif args.wiki_subcommand == "check-update": sys.exit(check_update_main( directory=args.directory, diff --git a/tests/test_fiona_main.py b/tests/test_fiona_main.py index 1ffb827..c195e7a 100644 --- a/tests/test_fiona_main.py +++ b/tests/test_fiona_main.py @@ -194,6 +194,47 @@ class TestFionaMain: captured = capsys.readouterr() assert "Successfully initialized llm-wiki directory" in captured.out + def test_main_wiki_init_duplicate_error(self, capsys, tmp_path): + """Test main() wiki init on duplicate prints error on stderr and exits 1. + + Implements SPEC 7.1.1.4: The CLI turns the refusal of 3.2.2 into + one stderr line and exit 1: Error: Directory '' already contains + llm-wiki files: . Run fiona-assistant wiki update to refresh + the template. + """ + from fiona.wiki.wiki import wiki_init + # Initialize the wiki first + wiki_init(str(tmp_path)) + + # Try to initialize again - should fail + with patch('sys.argv', ['fiona-assistant', 'wiki', 'init', str(tmp_path)]), \ + pytest.raises(SystemExit) as exc_info: + main() + + # Should exit with code 1 + assert exc_info.value.code == 1 + + captured = capsys.readouterr() + # Should print error message to stderr + assert captured.err.startswith("Error: Directory '") + assert str(tmp_path) in captured.err + assert "already contains llm-wiki files:" in captured.err + # Should list the indicators + assert "AGENTS.md" in captured.err + assert "fiona-settings.json" in captured.err + assert "wiki/" in captured.err + assert "ingest/" in captured.err + assert "README.md" in captured.err + # Should include the suggestion + assert "Run fiona-assistant wiki update to refresh the template." in captured.err + # Should be exactly one line (may have trailing newline) + stripped_lines = [line for line in captured.err.split('\n') if line] + assert len(stripped_lines) == 1 + # Should not print to stdout + assert captured.out == "" + # Should not print traceback + assert "Traceback" not in captured.err + def test_main_wiki_sanity(self, capsys, minimal_wiki): """Test main() dispatches wiki sanity and exits 0 on clean wiki.""" with patch('sys.argv', ['fiona-assistant', 'wiki', 'sanity', str(minimal_wiki)]), \