Add per-vault periodic notes config, fix version/print-default bugs, stop tracking build artifacts

- onyx periodic --view/--edit: configure folder/format/template per note type,
  independent of Obsidian's Daily Notes / Periodic Notes plugin state
- fix: weekly/monthly/quarterly/yearly notes no longer silently inherit the
  daily note's folder/template when no plugin config exists
- fix: quarterly notes now resolve the real quarter number instead of a
  literal 'Q'
- fix: onyx --version now works at the root command group; remove the
  redundant no-op 'version' subcommand
- fix: print-default no longer dumps the raw vault config dict for
  long-form vault entries
- expand --help text across periodic/create/set-default commands
- add .gitignore; stop tracking build/, dist/, __pycache__/, .idea/, .vscode/
This commit is contained in:
olivier committed 2026-09-24 17:11:43 -04:00
1 parent d13e377aba
commit 0dddb57d76
30 files changed
+457 -21318

No files matched your search

Binary file not shown.
+132 -13
View File
@@ -3,9 +3,10 @@ import unittest
import yaml
import shutil
from pathlib import Path
from src.onyx import OnyxCLI
from src.onyx import OnyxCLI, cli
from unittest.mock import patch, MagicMock
import click
from click.testing import CliRunner
from datetime import datetime
class TestOnyxCLI(unittest.TestCase):
@@ -140,8 +141,8 @@ Test content"""
# Test that frontmatter operations work correctly
# Test frontmatter --edit
self.cli.frontmatter_edit(test_note, 'tags', 'test,new')
self.cli.frontmatter_edit(test_note, 'status', 'published')
self.cli.frontmatter_edit(test_note, ('tags',), ('test,new',))
self.cli.frontmatter_edit(test_note, ('status',), ('published',))
content = (self.test_dir / test_note).read_text(encoding='utf-8-sig')
frontmatter = yaml.safe_load(content.split('---')[1])
@@ -150,38 +151,38 @@ Test content"""
# Test frontmatter --view
with patch('click.echo') as mock_echo:
self.cli.frontmatter_view(test_note, 'tags')
mock_echo.assert_called_with(yaml.dump({'tags': ['test', 'new']}, default_flow_style=False).strip())
self.cli.frontmatter_view(test_note, ('tags',))
mock_echo.assert_called_with("['test', 'new']")
# Test frontmatter --view with value check
with patch('click.echo') as mock_echo:
self.cli.frontmatter_view(test_note, 'tags', 'test')
mock_echo.assert_called_with('true')
self.cli.frontmatter_view(test_note, ('tags',), 'test')
mock_echo.assert_called_with('tags: true')
self.cli.frontmatter_view(test_note, 'tags', 'nonexistent')
mock_echo.assert_called_with('false')
self.cli.frontmatter_view(test_note, ('tags',), 'nonexistent')
mock_echo.assert_called_with('tags: false')
# Test frontmatter --clear
self.cli.frontmatter_clear(test_note, 'tags')
self.cli.frontmatter_clear(test_note, ('tags',))
content = (self.test_dir / test_note).read_text(encoding='utf-8-sig')
frontmatter = yaml.safe_load(content.split('---')[1])
self.assertEqual(frontmatter['tags'], [])
# Test frontmatter --clear with multiple keys
self.cli.frontmatter_clear(test_note, 'status,title')
self.cli.frontmatter_clear(test_note, ('status,title',))
content = (self.test_dir / test_note).read_text(encoding='utf-8-sig')
frontmatter = yaml.safe_load(content.split('---')[1])
self.assertEqual(frontmatter['status'], '')
self.assertEqual(frontmatter['title'], '')
# Test frontmatter --delete
self.cli.frontmatter_delete(test_note, 'tags')
self.cli.frontmatter_delete(test_note, ('tags',))
content = (self.test_dir / test_note).read_text(encoding='utf-8-sig')
frontmatter = yaml.safe_load(content.split('---')[1])
self.assertNotIn('tags', frontmatter)
# Test frontmatter --delete with multiple keys
self.cli.frontmatter_delete(test_note, 'status,title')
self.cli.frontmatter_delete(test_note, ('status,title',))
content = (self.test_dir / test_note).read_text(encoding='utf-8-sig')
# After deleting all keys, there should be no frontmatter section
self.assertNotIn('---', content)
@@ -217,6 +218,59 @@ Test content"""
# Daily note should be empty since no template is configured
self.assertEqual(daily_note.read_text(encoding='utf-8-sig'), '')
def test_weekly_note_does_not_inherit_daily_folder(self):
"""Regression: weekly notes must not silently reuse the daily note's folder/template."""
obsidian_dir = self.test_dir / '.obsidian'
obsidian_dir.mkdir(parents=True, exist_ok=True)
(obsidian_dir / 'daily-notes.json').write_text(
'{"format": "YYYY-MM-DD", "folder": "periodic/daily", "template": "templates/daily.md"}',
encoding='utf-8-sig'
)
self.cli.weekly_note(date="2025-11-27")
weekly_note = self.test_dir / '2025-W48.md'
self.assertTrue(weekly_note.exists())
self.assertFalse((self.test_dir / 'periodic' / 'daily' / '2025-W48.md').exists())
def test_periodic_config_edit_and_resolution(self):
"""onyx's own periodic config wins over plugin/defaults and is used by weekly_note()."""
template_path = self.test_dir / 'templates' / 'weekly.md'
template_path.parent.mkdir(parents=True, exist_ok=True)
template_path.write_text('# Weekly template', encoding='utf-8-sig')
self.cli.set_periodic_config(
'weekly', folder='periodic/weekly', format='YYYY-[W]WW', template='templates/weekly.md'
)
self.cli.weekly_note(date="2025-11-27")
weekly_note = self.test_dir / 'periodic' / 'weekly' / '2025-W48.md'
self.assertTrue(weekly_note.exists())
self.assertEqual(weekly_note.read_text(encoding='utf-8-sig'), '# Weekly template')
config = yaml.safe_load(self.cli.config_file.read_text(encoding='utf-8-sig'))
saved = config['vaults']['test_vault']['periodic_notes']['weekly']
self.assertEqual(saved['folder'], 'periodic/weekly')
self.assertEqual(saved['format'], 'YYYY-[W]WW')
self.assertEqual(saved['template'], 'templates/weekly.md')
def test_periodic_config_view(self):
"""print_periodic_config reports the resolved settings, not raw config fragments."""
self.cli.set_periodic_config('monthly', folder='periodic/monthly')
with patch('click.echo') as mock_echo:
self.cli.print_periodic_config('monthly')
printed = '\n'.join(call.args[0] for call in mock_echo.call_args_list)
self.assertIn('periodic/monthly', printed)
self.assertIn('YYYY-MM', printed)
def test_quarterly_note_filename(self):
"""Quarterly notes must resolve the actual quarter number, not a literal 'Q'."""
self.cli.quarterly_note(date="2025-11-27")
self.assertTrue((self.test_dir / '2025-Q4.md').exists())
@patch('subprocess.run')
@patch('os.startfile')
def test_open_note(self, mock_startfile, mock_run):
@@ -251,5 +305,70 @@ Test content"""
with self.assertRaises(click.UsageError):
self.cli.delete_note('nonexistent.md')
def test_frontmatter_path_resolution(self):
"""Test frontmatter path resolution with --output-path"""
# Create a test note with a relative path
note_content = """---
path: Projects/my-project
---
Test content"""
test_note = 'path_test.md'
self.cli.create_note(test_note, note_content)
# Setup vault with path prefix
prefix = str(self.test_dir / 'prefix_root')
self.cli.set_default_vault('test_vault', str(self.test_dir), path_prefix=prefix)
# Test 1: No --output-path (should return raw value)
with patch('click.echo') as mock_echo:
self.cli.frontmatter_view(test_note, ('path',), output_path=None)
mock_echo.assert_called_with('Projects/my-project')
# Test 2: --output-path flag (should use config prefix)
expected_path = str(Path(prefix).resolve() / 'Projects/my-project')
with patch('click.echo') as mock_echo:
self.cli.frontmatter_view(test_note, ('path',), output_path=True)
mock_echo.assert_called_with(expected_path)
# Test 3: --output-path with custom value
custom_prefix = str(self.test_dir / 'custom')
expected_custom_path = str(Path(custom_prefix) / 'Projects/my-project')
with patch('click.echo') as mock_echo:
self.cli.frontmatter_view(test_note, ('path',), output_path=custom_prefix)
mock_echo.assert_called_with(expected_custom_path)
def test_set_default_vault(self):
"""Test setting default vault"""
self.cli.set_default_vault('new_vault', str(self.test_dir))
self.assertEqual(self.cli.default_vault, 'new_vault')
config = yaml.safe_load(self.cli.config_file.read_text(encoding='utf-8-sig'))
self.assertEqual(config['default_vault'], 'new_vault')
# Check new dict structure
self.assertEqual(config['vaults']['new_vault']['path'], str(self.test_dir.resolve()))
# Test updating with path_prefix
prefix = "C:\\Users\\test"
self.cli.set_default_vault('new_vault', str(self.test_dir), path_prefix=prefix)
config = yaml.safe_load(self.cli.config_file.read_text(encoding='utf-8-sig'))
self.assertEqual(config['vaults']['new_vault']['path_prefix'], str(Path(prefix).resolve()))
def test_cli_version_flag(self):
"""onyx --version must work at the root command group (no separate 'version' subcommand)."""
result = CliRunner().invoke(cli, ['--version'])
self.assertEqual(result.exit_code, 0)
self.assertIn('onyx, version', result.output)
self.assertNotIn('version', [c for c in cli.commands])
def test_print_default_shows_path_not_raw_dict(self):
"""Regression: print_default must print the path string, not the dict, for long-form vault configs."""
self.cli.set_default_vault('test_vault', str(self.test_dir.resolve()), path_prefix=str(self.test_dir))
with patch('click.echo') as mock_echo:
self.cli.print_default()
printed = '\n'.join(call.args[0] for call in mock_echo.call_args_list)
self.assertIn(str(self.test_dir.resolve()), printed)
self.assertNotIn('path_prefix', printed)
if __name__ == '__main__':
unittest.main()