Skip to content

luai: expose lines() on the Windows io.popen handle - #751

Merged
aooohan merged 1 commit into
version-fox:mainfrom
CGIFM:fix/windows-popen-lines
Nov 9, 2026
Merged

aooohan merged 1 commit into
version-fox:mainfrom
CGIFM:fix/windows-popen-lines

Conversation

@CGIFM

@CGIFM CGIFM commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

What

Add a lines() method to the Lua table returned by the Windows io.popen() override in internal/plugin/luai/exec.go.

Why

Plugins on Windows cannot iterate command output with the standard Lua idiom:

for file in listing:lines() do

The override installs its own handle table with only read, write and close, so listing:lines is nil and the call fails with attempt to call a non-function object. Every plugin that shells out and parses output line by line is affected. The concrete breakage reported in #749 is vfox-python's PostInstall, which dies while enumerating its downloaded MSI packages, so vfox install python@<version> cannot complete on Windows.

gopher-lua's own file and process handles (iolib.go fileMethods) expose lines, and so did native io.popen before the Windows override was introduced in #712. This restores that contract.

Reproduction

With the Python plugin installed, on Windows:

vfox install python@3.14.10
plugin [PostInstall] method error: ...\lib\util.lua:171: Failed to list installer packages: ...: attempt to call a non-function object

A minimal version of the same failure, run against the base commit:

go test ./internal/plugin/luai -run TestPopenHandleLines -count=1 -v

=== RUN   TestPopenHandleLinesIteratesLines
    exec_popen_lines_test.go:50: Lua execution failed: <string>:4: attempt to call a non-function object
--- FAIL: TestPopenHandleLinesIteratesLines

The same handle's read("*a") works at the base commit (returns "hello\r\n"), so the child process and pipe are fine — the method is simply missing.

Root cause

internal/plugin/luai/exec.go:132 (base 3682fe8) builds the handle table:

f := ls.NewTable()
f.RawSetString("read", ...)
f.RawSetString("write", ...)
f.RawSetString("close", ...)

lines was never registered. The file was created in #712 (git show 5a54885 --stat shows internal/plugin/luai/exec.go | 265 +++++), replacing the native gopher-lua handle, so this is an API gap introduced by that override rather than a plugin misuse.

Verification

  • New regression test TestPopenHandleLinesIteratesLines: fails on the base commit with attempt to call a non-function object, passes with the change. The iterator yields alpha, beta, gamma from a real cmd.exe run, which also proves CRLF is stripped.
  • TestPopenHandleLinesRejectsWriteMode: lines() on a write-mode handle raises cannot read from a write-only popen handle, matching the existing read method.
  • Full suite (go test ./... -count=1, twice): all packages pass, 31s and 27s. internal/shared/printer's interactive TestSelect_Show is skipped because it blocks on keyboard input in this environment; it fails the same way on the unmodified base commit.
  • gofmt -l and go vet ./internal/plugin/luai/ are clean.
  • Edge cases exercised: empty output, final line without newline, CRLF output, blank lines, two handles iterated interleaved, two iterators on one handle, 5000-line output, a 200000-byte single line, and iteration after close() (raises instead of silently ending).

Risk

The change is additive and only affects the Windows override; macOS and Linux keep gopher-lua's native io.popen. Format arguments are not interpreted, matching gopher-lua's file:lines(). The global io.lines(filename) function is untouched.

The Windows io.popen override added in version-fox#712 returns a table with read,
write and close only. gopher-lua's file and process handles also expose
lines(), so plugin code that iterates command output with
`for line in handle:lines()` fails with "attempt to call a non-function
object" before reading anything. vfox-python's PostInstall hits this while
enumerating its installer packages, which breaks `vfox install python` on
Windows.

Add a lines() method that returns an iterator backed by the same buffered
reader as read("*l"): one line without its trailing CR/LF per call, nil at
EOF, and an error on the write-only mode. This restores the contract the
override was meant to preserve.

Fixes version-fox#749
@codecov

codecov Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 56.21%. Comparing base (3682fe8) to head (d864d00).

Files with missing lines Patch % Lines
internal/plugin/luai/exec.go 0.00% 12 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #751      +/-   ##
==========================================
- Coverage   56.29%   56.21%   -0.08%     
==========================================
  Files         115      115              
  Lines        8564     8576      +12     
==========================================
  Hits         4821     4821              
- Misses       3279     3291      +12     
  Partials      464      464              

☔ 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.

@aooohan
aooohan merged commit 4754dfd into version-fox:main Nov 9, 2026
6 checks passed
@aooohan

aooohan commented Nov 9, 2026

Copy link
Copy Markdown
Member

Thanks for the first contribution ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants