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 <vibe@mistral.ai>
This commit is contained in:
nvaldez
2026-11-19 11:53:41 +01:00
parent def3d2cd6d
commit a3d35c7f12
3 changed files with 57 additions and 8 deletions
+6 -6
View File
@@ -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 '<path>' already contains llm-wiki files:
<names>. Run fiona-assistant wiki update to refresh the template.`
The line is one line, even though it is wrapped here. `<names>` is
+8
View File
@@ -440,8 +440,16 @@ def main():
sys.exit(1)
elif args.command == "wiki":
if args.wiki_subcommand == "init":
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 '<path>' already contains llm-wiki files: <names>"
# We want: "Error: Directory '<path>' already contains llm-wiki files: <names>. 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,
+41
View File
@@ -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 '<path>' already contains
llm-wiki files: <names>. 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)]), \