Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
__pycache__/
*.pyc
.pytest_cache/
18 changes: 16 additions & 2 deletions task.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,24 @@
from commands.done import mark_done


DEFAULT_CONFIG = """# Task CLI configuration
storage:
format: json
max_tasks: 1000

display:
color: true
unicode: true
"""


def load_config():
"""Load configuration from file."""
"""Load configuration from file, falling back to defaults if missing."""
config_path = Path.home() / ".config" / "task-cli" / "config.yaml"
# NOTE: This will crash if config doesn't exist - known bug for bounty testing
if not config_path.exists():
config_path.parent.mkdir(parents=True, exist_ok=True)
config_path.write_text(DEFAULT_CONFIG)
return DEFAULT_CONFIG
with open(config_path) as f:
return f.read()

Expand Down
27 changes: 27 additions & 0 deletions test_task.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
"""Basic tests for task CLI."""

import json
import os
import shutil
import pytest
from pathlib import Path
from commands.add import add_task, validate_description
from commands.done import validate_task_id
from task import load_config


def test_validate_description():
Expand All @@ -28,3 +31,27 @@ def test_validate_task_id():

with pytest.raises(ValueError):
validate_task_id(tasks, 99)


def test_load_config_missing_file(tmp_path, monkeypatch):
"""Test that load_config handles missing config file gracefully."""
# Redirect HOME to a temp directory
monkeypatch.setattr(Path, "home", lambda: tmp_path)

# Ensure config doesn't exist
config_dir = tmp_path / ".config" / "task-cli"
if config_dir.exists():
shutil.rmtree(config_dir)

# Should not crash, should create default config
config_content = load_config()
assert "storage:" in config_content
assert "display:" in config_content

# Config file should now exist
config_path = config_dir / "config.yaml"
assert config_path.exists()

# Loading again should return the same content
config_content2 = load_config()
assert config_content2 == config_content