feat: v0.4.0 — section, resolve, list, tasks

- section: append to / replace one section, list-aware spacing, fences ignored
- resolve: filename or alias, case/accent-insensitive, --link wikilinks
- list: frontmatter filters (key=value, key!=value, key, !key), --json
- tasks: checkbox tasks by folder, date range, status, --ignore-from template, --json
- libyaml loader for whole-vault scans
This commit is contained in:
olivier committed 2026-10-19 11:59:16 -04:00
1 parent 3d3873b699
commit d063551a1e
3 files changed
+500 -1

No files matched your search

+124
View File
@@ -1,3 +1,4 @@
import json
import os
import unittest
import yaml
@@ -252,6 +253,129 @@ Test content"""
self.cli.frontmatter_list_items('bad', 'related', ('[[Plane]]',))
self.assertEqual(note.read_text(encoding='utf-8'), content)
DAILY = (
'---\n'
'type: daily-note\n'
'# Journal: not a heading inside frontmatter\n'
'---\n'
'\n'
'# 2026-10-29\n'
'\n'
'## To do\n'
'### Matin\n'
'- [ ] Regarder ma Weekly note\n'
'\n'
'### Après-midi\n'
'\n'
'### Soir\n'
'- [ ] Prendre calcium\n'
'\n'
'```markdown\n'
'## Journal\n'
'```\n'
'\n'
'## Journal\n'
'Aujourd’hui, Mark présente Align.')
def _daily(self):
note = self.test_dir / 'd.md'
note.write_text(self.DAILY, encoding='utf-8')
return note
def test_section_append(self):
"""Blank line before new blocks, none between list items or after an empty heading;
headings in frontmatter or code fences are ignored; nothing else moves"""
note = self._daily()
self.cli.write_section('d', '## Journal', '### 10:00 - Ménage\n- fait')
self.cli.write_section('d', 'matin', '- [ ] Appeler Haro')
self.cli.write_section('d', '### Après-midi', '- [ ] Courses\n')
self.cli.write_section('d', '## Journal', '### 11:00')
self.assertEqual(note.read_text(encoding='utf-8'), self.DAILY
.replace('- [ ] Regarder ma Weekly note\n', '- [ ] Regarder ma Weekly note\n- [ ] Appeler Haro\n')
.replace('### Après-midi\n', '### Après-midi\n- [ ] Courses\n')
.replace('Align.', 'Align.\n\n### 10:00 - Ménage\n- fait\n\n### 11:00\n'))
def test_section_replace_keeps_neighbours(self):
"""Replacing '## To do' drops its subsections and the code block inside it, but stops
at '## Journal' (the fake one in the fence doesn't end the section)"""
note = self._daily()
self.cli.write_section('d', '## To do', '- [ ] Une seule tâche', replace=True)
self.cli.write_section('d', '## Journal', '', replace=True)
self.assertEqual(note.read_text(encoding='utf-8'),
'---\ntype: daily-note\n# Journal: not a heading inside frontmatter\n---\n\n# 2026-10-29\n\n'
'## To do\n- [ ] Une seule tâche\n\n## Journal\n')
def test_section_missing_heading(self):
note = self._daily()
with self.assertRaises(click.UsageError):
self.cli.write_section('d', '## Review', 'x')
self.assertEqual(note.read_text(encoding='utf-8'), self.DAILY)
self.cli.write_section('d', 'Review', 'Bilan', create=True)
self.assertEqual(note.read_text(encoding='utf-8'), self.DAILY + '\n\n## Review\nBilan\n')
def _write_notes(self, notes: dict):
for rel, text in notes.items():
path = self.test_dir / rel
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text(text, encoding='utf-8')
def _echoed(self, call, *args, **kwargs):
with patch('click.echo') as echo:
result = call(*args, **kwargs)
return [c.args[0] for c in echo.call_args_list], result
def test_resolve_by_name_or_alias(self):
"""Case/accent-insensitive exact match; alias gives [[Note|Alias]]; shared filename
gives a path link; no fuzzy match"""
self._write_notes({
'entities/people/Stéphane Charbonneau.md': '---\naliases:\n - Stéphane\n---\n',
'entities/people/Stéphane Bigham.md': '---\naliases: [stephane]\n---\n',
'entities/businesses/Securitech.md': '---\naliases:\n - Sécuritech\n---\n',
'entities/businesses/Haro.md': '',
'archives/Haro.md': '',
'.trash/Securitech.md': '',
})
self.assertEqual(self._echoed(self.cli.resolve_note, 'STEPHANE', link=True),
(['[[Stéphane Bigham|stephane]]', '[[Stéphane Charbonneau|Stéphane]]'], 2))
self.assertEqual(self._echoed(self.cli.resolve_note, 'sécuritech'),
(['entities/businesses/Securitech'], 1))
self.assertEqual(self._echoed(self.cli.resolve_note, 'haro', folder='entities', link=True),
(['[[entities/businesses/Haro]]'], 1))
self.assertEqual(self._echoed(self.cli.resolve_note, 'Charbonneau'), ([], 0))
def test_list_where(self):
self._write_notes({
'projects/A.md': '---\ntype: project\nstatus: active\nclient: "[[Symbolitech]]"\n---\n',
'projects/B.md': '---\ntype: project\nstatus: done\nclient: "[[Diakonos]]"\n---\n',
'projects/C.md': '---\ntype: project\ntags:\n - Écriture\n---\n',
'notes/D.md': '---\ntype: project\nstatus: active\n---\n',
})
list_notes = self.cli.list_notes
self.assertEqual(self._echoed(list_notes, 'projects', ('status=ACTIVE', 'client=symbolitech'))[0],
['projects/A'])
self.assertEqual(self._echoed(list_notes, 'projects', ('status!=done', 'type'))[0],
['projects/A', 'projects/C'])
self.assertEqual(self._echoed(list_notes, None, ('!status',))[0], ['projects/C'])
self.assertEqual(self._echoed(list_notes, 'projects', ('tags=ecriture',))[0], ['projects/C'])
def test_tasks_dates_statuses_and_template(self):
self._write_notes({
'template.md': '- [ ] Prendre calcium\n',
'daily/2026-10-12.md': '## To do\n### Matin\n- [ ] Appeler Haro\n- [x] Fait\n- [/] En cours\n'
'```\n- [ ] dans du code\n```\n## Soir\n - [ ] prendre CALCIUM\n- [-] Annulé\n',
'daily/2026-10-20.md': '- [ ] Trop tard\n',
'daily/Sans date.md': '---\ndate: 2026-10-13\n---\n- [ ] Daté par la propriété\n',
})
lines, _ = self._echoed(self.cli.list_tasks, 'daily', '2026-10-12', '2026-10-18',
{'open', 'doing'}, 'template')
self.assertEqual(lines, ['daily/2026-10-12.md:3: - [ ] Appeler Haro',
'daily/2026-10-12.md:5: - [/] En cours',
'daily/Sans date.md:4: - [ ] Daté par la propriété'])
output, _ = self._echoed(self.cli.list_tasks, 'daily', statuses={'cancelled'}, as_json=True)
self.assertEqual(json.loads(output[0]), [{'path': 'daily/2026-10-12.md', 'line': 11, 'date': '2026-10-12',
'status': 'cancelled', 'heading': 'Soir', 'text': 'Annulé'}])
def test_move_rewrites_every_link_form(self):
"""Aliases, headings, embeds, path links, frontmatter links, regex characters"""
(self.test_dir / 'films').mkdir()