From 87ba4c17644d95ed4745495c7f1a95f02a0c2b40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Fr=C3=B3es=20Franco?= Date: Sun, 31 May 2026 21:45:50 -0300 Subject: [PATCH] test(calendar): add Vim + Neovim integration harnesses Add headless harnesses covering the calendar-vim integration, wired into CI alongside the existing keymap/config suites: - test-calendar-vim.sh/.vim (+ -optout.vim): pure-VimL diary hooks (calendar_sign markers, calendar_action path resolution from wiki root, calendar window close), plugin/nuwiki.vim hook auto-wiring that overrides calendar-vim's defaults, and opt-out via g:nuwiki_use_calendar and g:nuwiki_no_calendar. Uses a stub calendar-vim on the runtimepath. - test-calendar.sh/.lua: Neovim setup() wiring + window-close under the real window API, and opt-out via use_calendar = false. Fixes surfaced by the suite: - diary.vim: new diary entries set filetype 'vimwiki' (was the raw extension, e.g. 'wiki'); the stray FileType autocmd also blocked the calendar window from closing. - init.lua: drop the redundant Neovim FileType autocmd (plugin/nuwiki.vim already wires both editors) and translate use_calendar=false into g:nuwiki_no_calendar so the opt-out actually disables wiring. --- .gitea/workflows/ci.yaml | 4 + autoload/nuwiki/diary.vim | 10 +- development/ONBOARDING.md | 7 +- .../tests/test-calendar-vim-optout.vim | 40 ++++++ development/tests/test-calendar-vim.sh | 121 ++++++++++++++++++ development/tests/test-calendar-vim.vim | 97 ++++++++++++++ development/tests/test-calendar.lua | 92 +++++++++++++ development/tests/test-calendar.sh | 106 +++++++++++++++ lua/nuwiki/init.lua | 25 +--- 9 files changed, 475 insertions(+), 27 deletions(-) create mode 100644 development/tests/test-calendar-vim-optout.vim create mode 100755 development/tests/test-calendar-vim.sh create mode 100644 development/tests/test-calendar-vim.vim create mode 100644 development/tests/test-calendar.lua create mode 100755 development/tests/test-calendar.sh diff --git a/.gitea/workflows/ci.yaml b/.gitea/workflows/ci.yaml index 2eed90b..2ce8798 100644 --- a/.gitea/workflows/ci.yaml +++ b/.gitea/workflows/ci.yaml @@ -100,3 +100,7 @@ jobs: run: ./development/tests/test-config.sh - name: run Vim config parity harness run: ./development/tests/test-config-vim.sh + - name: run Neovim calendar integration harness + run: ./development/tests/test-calendar.sh + - name: run Vim calendar integration harness + run: ./development/tests/test-calendar-vim.sh diff --git a/autoload/nuwiki/diary.vim b/autoload/nuwiki/diary.vim index 40bbfa3..a6c28b2 100644 --- a/autoload/nuwiki/diary.vim +++ b/autoload/nuwiki/diary.vim @@ -34,12 +34,10 @@ function! nuwiki#diary#calendar_action(day, month, year, week, dir) abort endif execute 'edit ' . fnameescape(l:file_path) - if !filereadable(l:file_path) - if l:c.ext[0] ==# '.' - execute 'setfiletype ' . l:c.ext[1:] - else - execute 'setfiletype ' . l:c.ext - endif + " A brand-new entry has no file on disk yet, so ftdetect may not have run; + " ensure the vimwiki filetype so syntax/maps are active immediately. + if &filetype !=# 'vimwiki' + setfiletype vimwiki endif " Close the calendar window now that the diary is open (keep at least one). diff --git a/development/ONBOARDING.md b/development/ONBOARDING.md index c9370cb..1909afd 100644 --- a/development/ONBOARDING.md +++ b/development/ONBOARDING.md @@ -79,7 +79,12 @@ nuwiki/ │ ├── test-keymaps.sh # Neovim keymap harness │ ├── test-keymaps.lua │ ├── test-keymaps-vim.sh # Vim keymap harness -│ └── test-keymaps-vim.vim +│ ├── test-keymaps-vim.vim +│ ├── test-calendar.sh # Neovim calendar-vim integration harness +│ ├── test-calendar.lua +│ ├── test-calendar-vim.sh # Vim calendar-vim integration harness +│ ├── test-calendar-vim.vim +│ └── test-calendar-vim-optout.vim │ └── .gitea/ └── workflows/ diff --git a/development/tests/test-calendar-vim-optout.vim b/development/tests/test-calendar-vim-optout.vim new file mode 100644 index 0000000..07340d1 --- /dev/null +++ b/development/tests/test-calendar-vim-optout.vim @@ -0,0 +1,40 @@ +" development/tests/test-calendar-vim-optout.vim — driven by test-calendar-vim.sh. +" +" Asserts that the calendar-vim integration stays OFF when the user opts out +" (g:nuwiki_use_calendar = 0 or g:nuwiki_no_calendar = 1). In that case the +" FileType autocmd must leave calendar-vim's own defaults untouched, so the +" hooks still point at 'calendar#diary' / 'calendar#sign' (set by the stub). + +let s:results = [] +let s:pass = 0 +let s:fail = 0 +let s:out = $NUWIKI_CALENDAR_RESULTS + +function! s:record(ok, name, detail) abort + let l:line = (a:ok ? 'PASS' : 'FAIL') . ' ' . a:name + if a:detail !=# '' + let l:line .= ' — ' . a:detail + endif + call add(s:results, l:line) + if a:ok + let s:pass += 1 + else + let s:fail += 1 + endif +endfunction + +" The buffer is already a loaded vimwiki file (FileType has fired). nuwiki must +" NOT have rewired the hooks — they should still be calendar-vim's defaults. +call s:record(&filetype ==# 'vimwiki', 'ftplugin.attached', + \ &filetype ==# 'vimwiki' ? '' : 'filetype=' . &filetype) +call s:record(get(g:, 'calendar_action', '') !=# 'vimwiki#diary#calendar_action', + \ 'optout.action_not_wired', + \ 'g:calendar_action=' . get(g:, 'calendar_action', '')) +call s:record(get(g:, 'calendar_sign', '') !=# 'vimwiki#diary#calendar_sign', + \ 'optout.sign_not_wired', + \ 'g:calendar_sign=' . get(g:, 'calendar_sign', '')) + +call add(s:results, '') +call add(s:results, printf('SUMMARY: %d passed, %d failed', s:pass, s:fail)) +call writefile(s:results, s:out) +execute (s:fail == 0 ? 'qall!' : 'cquit!') diff --git a/development/tests/test-calendar-vim.sh b/development/tests/test-calendar-vim.sh new file mode 100755 index 0000000..455f479 --- /dev/null +++ b/development/tests/test-calendar-vim.sh @@ -0,0 +1,121 @@ +#!/usr/bin/env bash +# +# development/tests/test-calendar-vim.sh — calendar-vim integration harness (Vim). +# +# Exercises the pure-VimL diary hooks (nuwiki#diary#calendar_action / +# nuwiki#diary#calendar_sign) plus plugin/nuwiki.vim's auto-wiring of +# g:calendar_action / g:calendar_sign. A stub calendar-vim is placed on the +# runtimepath so :Calendar exists and the hooks start at calendar-vim's own +# defaults — the exact state nuwiki must detect and override. +# +# Two runs: +# 1. default → integration ON, hooks rewired, diary paths from wiki root +# 2. opt-out → g:nuwiki_use_calendar=0 / g:nuwiki_no_calendar=1 leave +# calendar-vim's defaults untouched +# +# No LSP binary is needed — the diary hooks are entirely client-side VimL. +# Exit code: 0 when all assertions pass, 1 otherwise. Skips (0) without vim. + +set -euo pipefail + +REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)" +TMP="$(mktemp -d -t nuwiki-calendar-vim-test-XXXXXX)" +trap 'rm -rf "$TMP"' EXIT + +log() { printf '\033[1;34m[calendar-vim]\033[0m %s\n' "$*"; } + +if ! command -v vim >/dev/null 2>&1; then + log 'vim not installed — skipping' + exit 0 +fi + +# --- Scratch wiki with one seeded diary entry (2026-05-30) ---------------- +WIKI="$TMP/wiki" +mkdir -p "$WIKI/diary" +echo "= index =" > "$WIKI/index.wiki" +echo "= 2026-05-30 =" > "$WIKI/diary/2026-05-30.wiki" + +# --- Stub calendar-vim ---------------------------------------------------- +# Mimics the real plugin closely enough for detection + the override path: +# defines :Calendar and seeds calendar-vim's default hook names. +CAL="$TMP/calendar-vim" +mkdir -p "$CAL/plugin" "$CAL/autoload" +cat > "$CAL/plugin/calendar.vim" <<'EOF' +if exists('g:loaded_calendar_stub') | finish | endif +let g:loaded_calendar_stub = 1 +let g:calendar_action = get(g:, 'calendar_action', 'calendar#diary') +let g:calendar_sign = get(g:, 'calendar_sign', 'calendar#sign') +command! -nargs=* Calendar echo 'stub calendar' +EOF +cat > "$CAL/autoload/calendar.vim" <<'EOF' +function! calendar#open(...) abort +endfunction +function! calendar#diary(...) abort +endfunction +function! calendar#sign(...) abort + return 0 +endfunction +EOF + +run_harness() { + local label="$1" vimrc="$2" harness="$3" + local results="$TMP/results-$label.txt" + log "running $label harness…" + NUWIKI_CALENDAR_RESULTS="$results" \ + NUWIKI_CALENDAR_WIKI="$WIKI" \ + timeout 30 vim -e -s -u "$vimrc" -c "edit $WIKI/index.wiki" \ + -c "source $harness" "$TMP/$label.log" 2>&1 || true + if [[ ! -f "$results" ]]; then + echo "calendar $label harness produced no output" >&2 + echo "--- vim log ---" >&2 + cat "$TMP/$label.log" >&2 || true + return 1 + fi + cat "$results" + grep -qE '^SUMMARY: [0-9]+ passed, 0 failed' "$results" +} + +# --- Run 1: default (integration ON) -------------------------------------- +VIMRC="$TMP/vimrc" +cat > "$VIMRC" <