Repository navigation
test(clink): cover clink_vfox.lua and fix the bugs found by the tests - #735
Conversation
Codecov Report❌ Patch coverage is
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. 🚀 New features to boost your workflow:
|
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.
66f36d3 to
6e40e85
Compare
aooohan
left a comment
There was a problem hiding this comment.
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.
Closes #728.
internal/shell/clink_vfox.luahad 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 existinggo test ./...matrix (includingwindows-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.luais a small fake of the Clink API the script uses (argmatcherwithaddarg/addflags,..links,onadvance,setdelayinit, prompt filters and coroutines), written after the Clink manual andarguments.lua. Like Clink, it runs the delayed initialization again on every input line.ioandosare replaced by in-memory fakes. The real gopher-luaio.popenandos.executewould run the script's commands.vfox availableandvfox ls(with and without ANSI colors, with every tree glyph and both ✓/✗),vfox activate clink(rendered from the real hook template andClink.Export),vfox env -s clinkandvfox config -l.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.gorendersvfox availableandvfox lswith the production code and compares them with the files the script's tests use (internal/shell/testdata/clink: one forvfox available, two forvfox 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-fixturesregenerates the files.For that, the code that prints the two outputs moved, unchanged, into
printAvailableandprintInstalledSdks. I built the binary before and after and compared the output ofvfox available(live registry) and ofvfox ls(with links made by hand and aliases made withvfox 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, sogcc-arm-none-eabi(a real plugin) was offered again after it had been entered. It searches for plain text now.vfox_available.txt, or one that does not start with a timestamp, for instance left behind when the shell is closed whilevfox availableruns, 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.vfox lsfollows 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, sovfox use,execanduninstallcompleted[email protected] (linked → /opt/node), versions such assystemwere lost, andv1.22.0was 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 activaterecords the PATH baseline in__VFOX_ORIG_PATHonce per shell session, and again for a shell that inherited it, which it recognizes by__VFOX_PID. The script sets__VFOX_PIDto its own shell before it runsvfox activate, so a Clink session started from a shell where vfox is active kept the baseline of that shell. The script already cleared__VFOX_CURTMPPATHfor the same reason; it clears the baseline too.How it was checked
go vetfor linux, windows and darwin; the full test suite on an LF checkout (minusinternal/shared/printer, whose interactive tests need a TTY), and the touched packages on a CRLF checkout; every commit builds and passes on its own.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.vfox lswith real links and aliases.