From 8b24e68a0eece052e04fc6bb32d837d862e9d1d1 Mon Sep 17 00:00:00 2001 From: Isaac Fletcher Date: Tue, 2 Jun 2026 12:35:03 -0700 Subject: [PATCH] Fix Windows cross-compilation error in expect step (#621) Summary: The goreleaser build for `windows_amd64` was failing because `pty.Winsize.Cols` is `uint16` on Unix but `uint` on Windows. The explicit `uint16(termWidth)` cast in `expectstep.go` caused a type mismatch when cross-compiling. Fix uses platform-specific `newWinsize` helpers with build tags, matching the existing pattern from D85156306 (`requirements_unix.go` / `requirements_windows.go`). Also adds a cross-compilation step to the GitHub Actions test workflow so that builds for all release targets (linux, darwin, windows) are verified on every PR before merge. This would have caught this issue before it landed. Reviewed By: d0n601 Differential Revision: D106692973 --- .github/workflows/tests.yaml | 8 ++++++++ pkg/blocks/expectstep.go | 3 ++- pkg/blocks/winsize_unix.go | 28 ++++++++++++++++++++++++++++ pkg/blocks/winsize_windows.go | 28 ++++++++++++++++++++++++++++ 4 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 pkg/blocks/winsize_unix.go create mode 100644 pkg/blocks/winsize_windows.go diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 843b2cac..fb5fad23 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -27,6 +27,14 @@ jobs: with: path-to-profile: coverage-all.out + - name: Cross-compile for all release targets + run: | + GOOS=linux GOARCH=amd64 go build ./... + GOOS=darwin GOARCH=amd64 go build ./... + GOOS=darwin GOARCH=arm64 go build ./... + GOOS=windows GOARCH=amd64 go build ./... + GOOS=windows GOARCH=arm64 go build ./... + - name: Build the TTPForge Binary run: | go build -o ttpforge diff --git a/pkg/blocks/expectstep.go b/pkg/blocks/expectstep.go index a66bf55f..0e943535 100644 --- a/pkg/blocks/expectstep.go +++ b/pkg/blocks/expectstep.go @@ -214,7 +214,8 @@ func (s *ExpectStep) Execute(execCtx TTPExecutionContext) (*ActResult, error) { if s.TerminalWidth > 0 { termWidth = s.TerminalWidth } - if err := pty.Setsize(console.Tty(), &pty.Winsize{Rows: 24, Cols: uint16(termWidth)}); err != nil { + ws := newWinsize(24, termWidth) + if err := pty.Setsize(console.Tty(), &ws); err != nil { logging.L().Warnf("failed to set terminal width: %v", err) } diff --git a/pkg/blocks/winsize_unix.go b/pkg/blocks/winsize_unix.go new file mode 100644 index 00000000..29845862 --- /dev/null +++ b/pkg/blocks/winsize_unix.go @@ -0,0 +1,28 @@ +//go:build unix + +/* +Copyright © 2024-present, Meta Platforms, Inc. and affiliates +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +package blocks + +import "github.com/creack/pty" + +func newWinsize(rows, cols int) pty.Winsize { + return pty.Winsize{Rows: uint16(rows), Cols: uint16(cols)} +} diff --git a/pkg/blocks/winsize_windows.go b/pkg/blocks/winsize_windows.go new file mode 100644 index 00000000..cdafc05b --- /dev/null +++ b/pkg/blocks/winsize_windows.go @@ -0,0 +1,28 @@ +//go:build windows + +/* +Copyright © 2024-present, Meta Platforms, Inc. and affiliates +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +package blocks + +import "github.com/creack/pty" + +func newWinsize(rows, cols int) pty.Winsize { + return pty.Winsize{Rows: uint(rows), Cols: uint(cols)} +}