Skip to content

test(clink): cover clink_vfox.lua and fix the bugs found by the tests - #735

Merged
linghengqian merged 5 commits into
version-fox:mainfrom
linghengqian:clink-vfox-lua-tests
Oct 22, 2026
Merged

linghengqian merged 5 commits into
version-fox:mainfrom
linghengqian:clink-vfox-lua-tests

Conversation

@linghengqian

@linghengqian linghengqian commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

Closes #728.

internal/shell/clink_vfox.lua had no automated coverage, so a regression in its output parsing or its completions only showed up when someone used Clink on Windows. This PR adds tests that run in the existing go test ./... matrix (including windows-latest), without Clink and without a new CI job.

Tests of the script

The script runs in a gopher-lua VM (already a dependency):

  • internal/shell/testdata/clink/fake_clink.lua is a small fake of the Clink API the script uses (argmatcher with addarg/addflags, .. links, onadvance, setdelayinit, prompt filters and coroutines), written after the Clink manual and arguments.lua. Like Clink, it runs the delayed initialization again on every input line.
  • io and os are replaced by in-memory fakes. The real gopher-lua io.popen and os.execute would run the script's commands.
  • The commands return canned output: vfox available and vfox ls (with and without ANSI colors, with every tree glyph and both ✓/✗), vfox activate clink (rendered from the real hook template and Clink.Export), vfox env -s clink and vfox config -l.
  • The tests check the completions of every command (use, unuse, exec, info, remove, env, ... with their aliases and flags), the startup sequence, the prompt hook, and the 24 hour cache of the plugin list.

Locking the formats the script parses

cmd/commands/clink_format_test.go renders vfox available and vfox ls with the production code and compares them with the files the script's tests use (internal/shell/testdata/clink: one for vfox available, two for vfox ls, with and without the links and aliases of #736). Changing either format now fails a test that points at the script. go test ./cmd/commands -run MatchesClinkFixture -update-clink-fixtures regenerates the files.

For that, the code that prints the two outputs moved, unchanged, into printAvailable and printInstalledSdks. I built the binary before and after and compared the output of vfox available (live registry) and of vfox ls (with links made by hand and aliases made with vfox alias set): byte-for-byte identical.

Bugs the tests found

Each fix is its own commit, with a regression test that fails without it.

  • vfox add <Tab> looked for plugin names on the line as Lua patterns, so gcc-arm-none-eabi (a real plugin) was offered again after it had been entered. It searches for plain text now.
  • An empty vfox_available.txt, or one that does not start with a timestamp, for instance left behind when the shell is closed while vfox available runs, made the delayed initialization fail with an arithmetic error on nil on every input line until the file was deleted. It is now treated as an expired cache and rewritten.
  • Since feat: link existing SDKs, add vfox doctor, aliases and path.mode #736, vfox ls follows the name of a version with (linked → path) and [alias: ...], and a linked version can have any name. The script took every entry that starts with a digit for a version and used the whole entry as its name, so vfox use, exec and uninstall completed [email protected] (linked → /opt/node), versions such as system were lost, and v1.22.0 was taken for an SDK. It now tells the SDKs from their versions by their place in the tree, and takes the first word of an entry for the name of a version.
  • vfox activate records the PATH baseline in __VFOX_ORIG_PATH once per shell session, and again for a shell that inherited it, which it recognizes by __VFOX_PID. The script sets __VFOX_PID to its own shell before it runs vfox activate, so a Clink session started from a shell where vfox is active kept the baseline of that shell. The script already cleared __VFOX_CURTMPPATH for the same reason; it clears the baseline too.

How it was checked

  • go vet for linux, windows and darwin; the full test suite on an LF checkout (minus internal/shared/printer, whose interactive tests need a TTY), and the touched packages on a CRLF checkout; every commit builds and passes on its own.
  • Mutation check: I injected 57 regressions one at a time into clink_vfox.lua (a missing tree glyph, a broken ANSI pattern, the cache boundary, the pre-Fixed several issues in the clink_vfox.lua script #724 = parsing, a dropped startup variable, a lost flag, ...) and 15 into the two printers. Every one makes a test fail.
  • I ran the script against the raw output of the real binary: the plugins of the live registry, and a colored vfox ls with real links and aliases.
  • Not tried in real Clink on Windows. The VM stands in for it, so a look at the changes in the script from someone who uses Clink is welcome.

@codecov

codecov Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.66667% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 51.39%. Comparing base (feb6092) to head (6e40e85).

Files with missing lines Patch % Lines
cmd/commands/available.go 33.33% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #735      +/-   ##
==========================================
+ Coverage   51.05%   51.39%   +0.33%     
==========================================
  Files         111      111              
  Lines        8236     8240       +4     
==========================================
+ Hits         4205     4235      +30     
+ Misses       3609     3583      -26     
  Partials      422      422              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

clink_vfox.lua had no automated coverage, so a regression in its output
parsing or in its completions only showed up when someone used Clink on
Windows.

Run the script in a gopher-lua VM against a fake Clink
(testdata/clink/fake_clink.lua), with the io and os libraries replaced by
in-memory fakes so that no command is run and no file is touched. The
tests feed it the output of vfox available, vfox ls, vfox activate clink
and vfox env -s clink, with and without colors, and check the startup, the
prompt hook, the plugin cache and the completions of every command. They
run in the existing go test matrix, including Windows.

The script parses the output of vfox available and vfox ls. Move the code
that prints them into printAvailable and printInstalledSdks, unchanged,
and compare what they print with the files the script's tests use, so that
a change to either format fails a test instead of silently breaking
completion in Clink. Running
`go test ./cmd/commands -run MatchesClinkFixture -update-clink-fixtures`
regenerates the files.

Part of version-fox#728.
vfox add completes the plugins of the registry and leaves out the ones that
are already on the line. It looked for each name in the line as a Lua
pattern. In a name like gcc-arm-none-eabi the hyphens are quantifiers, so
the plugin was offered again after it had been entered, and a dot in a name
would match any character. Search for the name as plain text instead.
The script caches the output of vfox available in vfox_available.txt, with
a timestamp on the first line, and only lists the plugins again after a
day. It subtracted that timestamp without checking it, so a file that is
empty or does not start with a number, such as the one left behind when the
shell is closed while vfox available is running, raised an error in the
delayed initialization of the vfox argmatcher. The file was never replaced,
so every following input line failed in the same way until the user deleted
it.

Treat such a file as an expired cache: list the plugins again and write the
file anew.
vfox ls follows the name of a version with "(linked → path)" when it is a
link and with "[alias: ...]" when it has aliases, and a linked version can
have any name. The script took every entry that starts with a digit for a
version and used the whole entry as its name, so vfox use, exec and
uninstall completed "[email protected] (linked → /opt/node)", versions such as
system were lost, and v1.22.0 was taken for an SDK.

Tell the SDKs from their versions by where they are in the tree: the first
level is the SDKs, the second one their versions, and the name of a version
is the first word of its entry. A second golden file locks the output of vfox
ls for links and aliases.
vfox activate records the PATH it found in __VFOX_ORIG_PATH once per shell
session, and records it again for a shell that inherited the variable from
another session. It tells the two apart by __VFOX_PID, which the script sets
to the PID of its own shell before it runs vfox activate. A Clink session
started from a shell where vfox is active therefore kept the baseline of
that shell. The script already clears __VFOX_CURTMPPATH for the same
reason: clear the baseline too.
@linghengqian linghengqian changed the title test(clink): cover clink_vfox.lua and fix two bugs found by the tests test(clink): cover clink_vfox.lua and fix the bugs found by the tests Oct 22, 2026

@aooohan aooohan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. I reviewed 6e40e85, including the fake Clink API and the checks that tie its fixtures to the real command output. The printer extractions preserve the existing output, and the regressions cover the broken cache timestamp, literal plugin names, linked/version labels, and an inherited PATH baseline.

The build, go vet ./..., and CI=true go test ./... all passed with Go 1.24.0 on macOS arm64. GitHub's Windows, macOS, and Linux jobs are green too. I haven't run this in native Clink on Windows; my local check exercised the actual Lua script through the VM harness. No blocking findings from me.

@linghengqian
linghengqian merged commit 10c9f96 into version-fox:main Oct 22, 2026
6 checks passed
@linghengqian
linghengqian deleted the clink-vfox-lua-tests branch October 22, 2026 11:11
@linghengqian linghengqian added this to the 1.0.14 milestone Oct 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Add automated test coverage for clink_vfox.lua

2 participants