Files
Jeremy Ruppel e049627258 test(coderd/templatebuilder): fix ETXTBSY flake in TestQuickstartCppInstallGuard (#32403)
`TestQuickstartCppInstallGuard` wrote stub executables in parallel
subtests and then executed them through the quickstart install script. A
concurrent fork could inherit a stub's write fd, so the exec failed with
`Text file busy` (golang/go#22315). The stubs are now bash functions
prepended to the script, so the test does not write or execute any
files.

This PR also adds `TestBaseBundlesReferencedFiles`. It walks each base's
rendered `main.tf` HCL and checks that every `file()`/`templatefile()`
path is bundled in `BaseExtraFiles`. It replaces the hand-written
`AWSLinuxExtraFiles` and `AzureLinuxExtraFiles` subtests.

Fixes CLIENT-1102

<details>
<summary>Plan and decision log</summary>

### Fix CLIENT-1102: flake in TestQuickstartCppInstallGuard

#### Problem

`TestQuickstartCppInstallGuard` wrote stub executables in parallel
subtests, then executed the quickstart install script. A concurrent fork
could inherit a stub's write fd, so executing a stub failed with
`ETXTBSY` (golang/go#22315).

#### Decision log

1. Hold `syscall.ForkLock` while writing stubs. Rejected: it keeps the
file setup and protects only this process.
2. Replace the stub files with bash functions, so no file is written or
executed. Implemented.
3. Delete the test and only check that the files are referenced. Tried,
then reverted after review: the test is the only regression test for the
C/C++ install guard (#30374), and running scripts from Go tests is not
against repo policy.
4. Keep the reference check as a separate test. It covers a different
contract: every file that a base's `main.tf` passes to
`file()`/`templatefile()` must be bundled.

#### Change

- `TestQuickstartCppInstallGuard`: define the stubs as bash functions
prepended to the script. `PATH` is an empty temp dir, `sudo` echoes its
arguments, and the test checks stdout for `SUDO: apt-get install`.
- Add `TestBaseBundlesReferencedFiles`: one parallel subtest per base.
Each renders `main.tf` with `testRenderContext`, walks the parsed HCL
for `file()`/`templatefile()` calls, evaluates the path with
`path.module = "."`, and checks that it is a key of `BaseExtraFiles`,
which `Compose` passes through unchanged. A path that is not a literal
fails the test, and so does a base that bundles files without
referencing any of them. Calls in comments and heredocs are ignored.
- Remove the `AWSLinuxExtraFiles` and `AzureLinuxExtraFiles` subtests,
which only listed file names by hand and are now covered by
`TestBaseBundlesReferencedFiles`.

#### Verification

- With the guard set back to gcc only, `MissingCmake` and `OnlyGcc`
fail.
- `go test ./coderd/templatebuilder -run
'^TestQuickstartCppInstallGuard$' -count=500 -cpu=8` passes, as does the
whole package with `-count=20 -cpu=8`.
- Reference check mutations: a renamed quickstart reference, a removed
aws-linux file, and a misspelled DigitalOcean reference each fail the
subtest for that base with a short message. A path that is not a literal
fails. A call in a comment is ignored.
- `golangci-lint` (0 issues), `gofmt`, `git diff --check`.

</details>

---

_Generated with Coder Agents on behalf of @jeremyruppel._
2026-11-18 14:59:15 -05:00
..