diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml deleted file mode 100644 index ccc8a9b8..00000000 --- a/.github/workflows/test.yml +++ /dev/null @@ -1,52 +0,0 @@ -name: test -on: - push: - branches: - - 'main' - pull_request: - branches: - - 'main' - workflow_dispatch: - schedule: - # daily 9AM EST - - cron: "0 14 * * *" - -jobs: - plenary: - runs-on: ubuntu-22.04 - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - - name: Setup Neovim nightly - uses: rhysd/action-setup-vim@v1 - with: - neovim: true - version: nightly - - - name: Setup Kitty - run: | - curl -L https://sw.kovidgoyal.net/kitty/installer.sh | sh /dev/stdin launch=n - - - name: Install dependencies - run: | - sudo apt update - sudo apt install -y xfce4 libxcb-xkb1 - # homebrew is not used but is required to reproduce an issue for a test case - /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" - - - name: Start Xvfb - run: | - Xvfb :1 -screen 0 1024x768x16 & - - - name: Test kitty-scrollback.nvim - run: | - # TODO: improve the env var exports, github actions are making it hard so I gave up for now - export PATH=$HOME/.local/kitty.app/bin:/home/linuxbrew/.linuxbrew/bin:$PATH - export DISPLAY=:1 - export PS1="\[\e[34m\]$ \[\e[m\]" - echo 'export PATH=$HOME/.local/kitty.app/bin:/home/linuxbrew/.linuxbrew/bin:$PATH' >> "$HOME/.bashrc" - echo 'export DISPLAY=:1' >> "$HOME/.bashrc" - echo 'export PS1="\[\e[34m\]$ \[\e[m\]"' >> "$HOME/.bashrc" - make test - diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 00000000..144c2aad --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,100 @@ +name: tests +on: + push: + branches: + - 'main' + pull_request: + branches: + - 'main' + workflow_dispatch: + inputs: + enable_debug_vnc: + required: false + type: boolean + default: false + enable_debug_tmate: + required: false + type: boolean + default: false + schedule: + # daily 9AM EST + - cron: "0 14 * * *" + +jobs: + plenary: + runs-on: ubuntu-22.04 + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Setup Neovim nightly + uses: rhysd/action-setup-vim@v1 + with: + neovim: true + version: nightly + + - name: Setup Kitty + run: | + curl -L https://sw.kovidgoyal.net/kitty/installer.sh | sh /dev/stdin launch=n + + - name: Install dependencies + run: | + sudo apt update + sudo apt install -y xfce4 libxcb-xkb1 + # homebrew is not used but is required to reproduce an issue for a test case + /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" + + - name: Start Xvfb + if: ${{ ! inputs.enable_debug_vnc }} + run: | + Xvfb :1 -screen 0 1024x768x16 & + + - name: (debug) Start TurboVNC + if: ${{ inputs.enable_debug_vnc }} + run: | + mkdir -p "$GITHUB_WORKSPACE/tmp" + curl -s -L https://github.com/TurboVNC/turbovnc/releases/download/3.1/turbovnc_3.1_amd64.deb -o "$GITHUB_WORKSPACE/tmp/turbovnc.deb" + cd "$GITHUB_WORKSPACE/tmp" || exit 1 + sudo dpkg -i turbovnc.deb + sudo apt update + sudo apt install -f + cd "$GITHUB_WORKSPACE" || exit 1 + export PATH="/opt/TurboVNC/bin:$PATH" + vncserver -SecurityTypes None + + - name: (debug) Setup ngrok session + if: ${{ inputs.enable_debug_vnc }} + env: + NGROK_AUTH_TOKEN: ${{ secrets.NGROK_AUTH_TOKEN }} + run: | + mkdir -p "$GITHUB_WORKSPACE/tmp/bin" + curl -s -L https://bin.equinox.io/c/bNyj1mQVY4c/ngrok-v3-stable-linux-amd64.tgz -o "$GITHUB_WORKSPACE/tmp/ngrok.tgz" + cd "$GITHUB_WORKSPACE/tmp" || exit 1 + tar -xvf ngrok.tgz -C "$GITHUB_WORKSPACE/tmp/bin" + cd "$GITHUB_WORKSPACE" || exit 1 + export PATH="$GITHUB_WORKSPACE/tmp/bin:$PATH" + ngrok config add-authtoken "$NGROK_AUTH_TOKEN" + ngrok tcp 22 --log=stdout > "$GITHUB_WORKSPACE/tmp/ngrok.log" & + sleep 1 # wait for ngrok to start + NGROK_TLS_URL="$(curl --silent http://127.0.0.1:4040/api/tunnels | jq -r '.tunnels[0].public_url')" + host="$(echo $NGROK_TLS_URL | awk -F:// '{print $2}' | awk -F: ' {print $1}')" + port="$(echo $NGROK_TLS_URL | awk -F:// '{print $2}' | awk -F: ' {print $2}')" + printf '\n\nngrok agent running avaible at %s\n\nRun the following command on your machine:\n\n ssh -L 59000:localhost:5901 -C -N -p %s -l runner %s\n\nConnect on your machine at: localhost:59000\n\n' $NGROK_TLS_URL $port $host + + - name: (debug) Setup tmate session + if: ${{ inputs.enable_debug_tmate || inputs.enable_debug_vnc }} + uses: mxschmitt/action-tmate@v3 + + - name: Test kitty-scrollback.nvim + run: | + # TODO: improve the env var exports, github actions are making it hard so I gave up for now + export KITTY_CONFIG_DIRECTORY="$GITHUB_WORKSPACE/tests" + export PATH=$HOME/.local/kitty.app/bin:/home/linuxbrew/.linuxbrew/bin:$PATH + export DISPLAY=:1 + export PS1="\[\e[34m\]$ \[\e[m\]" + echo 'export KITTY_CONFIG_DIRECTORY="$GITHUB_WORKSPACE/tests"' >> "$HOME/.bashrc" + echo 'export PATH=$HOME/.local/kitty.app/bin:/home/linuxbrew/.linuxbrew/bin:$PATH' >> "$HOME/.bashrc" + echo 'export DISPLAY=:1' >> "$HOME/.bashrc" + echo 'export PS1="\[\e[34m\]$ \[\e[m\]"' >> "$HOME/.bashrc" + make test + diff --git a/CHANGELOG.md b/CHANGELOG.md index cd53c1e4..a393e016 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## [2.4.3](https://github.com/mikesmithgh/kitty-scrollback.nvim/compare/v2.4.2...v2.4.3) (2023-12-11) + + +### Bug Fixes + +* add kitty fallback for checkhealth ([#98](https://github.com/mikesmithgh/kitty-scrollback.nvim/issues/98)) ([6c93db4](https://github.com/mikesmithgh/kitty-scrollback.nvim/commit/6c93db4f4a82001cd1c6f3ff014481426dfa8648)) + ## [2.4.2](https://github.com/mikesmithgh/kitty-scrollback.nvim/compare/v2.4.1...v2.4.2) (2023-12-07) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 0f922bcf..4048a35d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -15,10 +15,17 @@ ## Troubleshooting ### Github Actions -- Interactive debug the action by temporarily adding the build step -```yml -- name: Setup tmate session - uses: mxschmitt/action-tmate@v3 -``` + +#### Interactive debugging + +- Run the worklow [tests](https://github.com/mikesmithgh/kitty-scrollback.nvim/actions/workflows/tests.yml) + - Check `enable_debug_vnc` to enable TurboVNC, ngrok, and tmate debugging + - This allows you to connect to the Github runner via vnc (for GUI) and ssh + - Check `enable_debug_tmate` to enable tmate debugging + - This allows you to connect to the Github runner via ssh + +#### Verbose logging + - Enable verbose logging by running the action with [debug logging](https://docs.github.com/en/actions/monitoring-and-troubleshooting-workflows/enabling-debug-logging) enabled. + - This can also be achieved by setting `RUNNER_DEBUG` to `1`, `RUNNER_DEBUG=1 make test` diff --git a/lua/kitty-scrollback/api.lua b/lua/kitty-scrollback/api.lua index 9a189dbb..d5aa00eb 100644 --- a/lua/kitty-scrollback/api.lua +++ b/lua/kitty-scrollback/api.lua @@ -80,10 +80,14 @@ M.generate_kittens = function(all, generate_modes) target_gen_modes[gen_mode] = true end - local kitty_scrollback_kitten = - vim.api.nvim_get_runtime_file('python/kitty_scrollback_nvim.py', false)[1] - local example_path = - vim.api.nvim_get_runtime_file('lua/kitty-scrollback/configs/example.lua', false)[1] + local kitty_scrollback_kitten = vim.fn.fnamemodify( + vim.api.nvim_get_runtime_file('python/kitty_scrollback_nvim.py', false)[1], + ':p' + ) + local example_path = vim.fn.fnamemodify( + vim.api.nvim_get_runtime_file('lua/kitty-scrollback/configs/example.lua', false)[1], + ':p' + ) local action_alias = 'kitty_scrollback_nvim' local alias_config = { @@ -181,8 +185,10 @@ M.generate_kittens = function(all, generate_modes) end M.checkhealth = function() - local kitty_scrollback_kitten = - vim.api.nvim_get_runtime_file('python/kitty_scrollback_nvim.py', false)[1] + local kitty_scrollback_kitten = vim.fn.fnamemodify( + vim.api.nvim_get_runtime_file('python/kitty_scrollback_nvim.py', false)[1], + ':p' + ) -- NOTE(#58): nvim v0.9 support -- setup backports for v0.9 because checkhealth can be called outside of standard setup flow if vim.fn.has('nvim-0.10') <= 0 then @@ -191,7 +197,8 @@ M.checkhealth = function() if vim.fn.has('nvim-0.9') > 0 then vim .system({ - p.kitty_data.kitty_path, + -- fallback to 'kitty' because checkhealth can be called outside of standard setup flow + (p and p.kitty_data and p.kitty_data.kitty_path) and p.kitty_data.kitty_path or 'kitty', '@', 'kitten', kitty_scrollback_kitten, diff --git a/tests/helpers.lua b/tests/helpers.lua index 962a10b1..884f1746 100644 --- a/tests/helpers.lua +++ b/tests/helpers.lua @@ -314,4 +314,47 @@ M.assert_screen_equals = function(actual, expected, ...) assert(actual_rstrip == expected_rstrip, ...) end +M.assert_screen_starts_with = function(actual, expected, ...) + local expected_rstrip = expected:gsub('%s*\n', '\n'):gsub('\n$', '') + local actual_rstrip = actual:gsub('%s*\n', '\n'):sub(1, #expected_rstrip) + M.debug({ + actual = actual, + actual_rstrip = actual_rstrip, + actual_length = #actual, + actual_rstrip_length = #actual_rstrip, + expected = expected, + expected_rstrip = expected_rstrip, + expected_length = #expected, + expected_rstrip_length = #expected_rstrip, + }) + if actual_rstrip ~= expected_rstrip then + print_differences(actual_rstrip, expected_rstrip) + end + assert(actual_rstrip == expected_rstrip, ...) +end + +M.assert_screen_match = function(actual, pattern, ...) + local actual_rstrip = actual:gsub('%s*\n', '\n') + M.debug({ + actual = actual, + actual_rstrip = actual_rstrip, + actual_length = #actual, + actual_rstrip_length = #actual_rstrip, + match = pattern, + }) + assert(actual_rstrip:match(pattern), ...) +end + +M.assert_screen_not_match = function(actual, pattern, ...) + local actual_rstrip = actual:gsub('%s*\n', '\n') + M.debug({ + actual = actual, + actual_rstrip = actual_rstrip, + actual_length = #actual, + actual_rstrip_length = #actual_rstrip, + match = pattern, + }) + assert(not actual_rstrip:match(pattern), ...) +end + return M diff --git a/tests/kitty-scrollback/kitty_scrollback_spec.lua b/tests/kitty-scrollback/kitty_scrollback_spec.lua index 3a386039..7f2e424d 100644 --- a/tests/kitty-scrollback/kitty_scrollback_spec.lua +++ b/tests/kitty-scrollback/kitty_scrollback_spec.lua @@ -12,7 +12,7 @@ local ksb_dir = vim.fn.fnamemodify( ) h.debug({ ksb_dir = ksb_dir, - minimal_kitty_conf = ksb_dir .. 'tests/minimal_kitty.conf', + kitty_conf = ksb_dir .. 'tests/kitty.conf', }) local tmpsock = h.tempsocket(ksb_dir .. 'tmp/') @@ -25,7 +25,7 @@ local kitty_cmd = h.debug({ 'kitty', '--listen-on=unix:' .. tmpsock, '--config', - ksb_dir .. 'tests/minimal_kitty.conf', + ksb_dir .. 'tests/kitty.conf', '--override', 'shell=' .. shell, '--session', @@ -34,6 +34,7 @@ local kitty_cmd = h.debug({ describe('kitty-scrollback.nvim', function() before_each(function() + vim.fn.mkdir(ksb_dir .. 'tests/workdir', 'p') kitty_instance = vim.system(kitty_cmd, { stdin = 'cd ' .. ksb_dir .. 'tests/workdir', }) @@ -85,4 +86,27 @@ $ brew search a 󰄛 'kitty-scrollback.nvim content did not match the terminal screen' ) end) + + it('should successfully open checkhealth', function() + local stdtout = h.feed_kitty({ + [[nvim +'lua vim.opt.rtp:append("../..") vim.opt.rtp:append("../../kitty-scrollback.nvim") require("kitty-scrollback").setup() vim.cmd("KittyScrollbackCheckHealth")']], + [[\n]], -- enter + }) + h.assert_screen_not_match( + stdtout, + 'ERROR', + 'kitty-scrollback.nvim checkhealth had an unexpected health check ERROR' + ) + h.assert_screen_starts_with( + stdtout, + [[ + +────────────────────────────────────────────────────────────────────────────── +kitty-scrollback: require("kitty-scrollback.health").check() + +kitty-scrollback: Neovim version +]], + 'kitty-scrollback.nvim checkhealth content did not start with expected content' + ) + end) end) diff --git a/tests/minimal_kitty.conf b/tests/kitty.conf similarity index 100% rename from tests/minimal_kitty.conf rename to tests/kitty.conf