Repository navigation
test: stop Terraform tests from downloading providers that should be cached - #32146
Conversation
…aceTemplateParamsChange The provider cache is keyed on the template contents. The template holds a t.TempDir() path, so the key was new on every run and the test downloaded the providers every time. It failed whenever GitHub returned a 5xx for a provider file, and it left one unused cache directory behind per run. Pass a fixed providers-only file to the cache helper. The template the test builds is unchanged.
The test cache was saved once per day, by the first job on main that finished green. A Terraform test added later that day had no cache entry until a later day's first green run, and downloaded its providers on every run until then. Add a hash of the cached provider directories to the cache key, so a run that downloads new providers saves them at once. Save after failed jobs too. Mark each provider directory with a .complete file once it is fully downloaded, and download again when the file is missing, so a directory left part way through is never reused.
|
/coder-agents-review Please limit the review to P0, P1, and P2 issues only. |
|
Chat: Review posted | View chat Review history
deep-review v0.13.0 | Round 2 | Last posted: Round 2, 2 findings (2 P2), APPROVE. Review Finding inventoryFindings
Contested and acknowledgedRound logRound 1Netero first pass: 2 P2, 1 P3, 1 Note; no P0, so panel ran. Law skipped (54 effective additions). Full panel (round 1): ging-go, ryosuke, pariston, mafuuu, bisky, gon, leorio, hisoka, wildcard meruem. Requester (@BobbyHo PR comment) asked for P0-P2 only, so P3 and below are recorded and not posted. Downgrade gate:
Reviewed against 73cf6bf..f139b3e. Round 2Churn guard PROCEED: CRF-1 and CRF-2 addressed in e35ff9e (save-on-failure and Downgrade gate:
About deep-reviewCRF = Coder Review Finding (P0-P4, Nit, Note)
|
There was a problem hiding this comment.
This PR fixes the provider cache key for TestWorkspaceTemplateParamsChange, adds a .complete marker to DownloadTFProviders, and makes the CI test-cache upload save under a key that changes with the marker set. 2 P2 findings, both on the save-after-failure change. Commit 1 works as described: two consecutive runs of TestWorkspaceTemplateParamsChange hit the cache and added no directory. As requested, this review posts only P0 to P2.
Out of scope (needs a ticket or explicit acceptance by a human):
provisioner/terraform/install_test.go:109:handleGetcaches the response body for any HTTP status, so a 5xx from releases.hashicorp.com is stored as the release file and served on every later run that reads the same cache..github/workflows/ci.yaml:760: "Upload failed test db dumps" has noif, so it is skipped when tests fail, which is when the dumps exist (same attest-go-pg-self-hosted.yaml:97).enterprise/coderd/workspaces_test.go:3779:downloadProviderspassesTestWorkspaceTagsTerraformas the test name for every caller, so theusing cached terraform providerslog line names the wrong test forTestWorkspaceTemplateParamsChange.
🤖 This review was automatically generated with Coder Agents.
The previous commit tried to save the cache after failed jobs. That had no effect, because the workflow steps that call this action are skipped when an earlier step fails. Making it work would also save the Terraform install cache after a failed run, and that cache can hold an HTTP error body. Keep saving only after success. Build the key suffix from the names of all cache entries, and remove the .complete marker, which is no longer needed.
|
/coder-agents-review Please limit the review to P0, P1, and P2 issues only. |
There was a problem hiding this comment.
Commit e35ff9e removes the save-after-failure condition and the .complete marker, and the upload key suffix now hashes the names of the entries two levels under ~/.cache/coderv2-test. No new P0 to P2 findings. Both round 1 findings are fixed: the save runs only after every earlier step passes, so neither a partial provider directory nor a cached HTTP error body from a failed run is saved. TestWorkspaceTemplateParamsChange still hits the cache and adds no directory on repeated runs. As requested, this review posts only P0 to P2.
Out of scope (needs a ticket or explicit acceptance by a human):
provisioner/terraform/provision_test.go:1366: themalicious-tarcase's file../../../etc/passwdis written byDownloadTFProvidersto<cache root>/etc/passwd, outside its cache directory, so cleanup never removes it and every saved test cache carries it.
🤖 This review was automatically generated with Coder Agents.
dylanhuff-at-coder
left a comment
There was a problem hiding this comment.
lgtm, one non-blocking nit
TL;DR
Some Go tests run real Terraform and fail whenever GitHub returns a 500 or 504 for a provider download. These tests are meant to read providers from a cache that CI restores, so they should not need the network at all. Two gaps made them need it. One test built its cache key from a path that is new on every run, so it downloaded the providers every time. And CI saved the cache only once per day, so a newly added test could go more than a day without a cache entry. This PR closes both gaps.
Refs https://linear.app/codercom/issue/CORE-40/flake-gen-terraform-provider-download-failure-context-deadline
How to navigate this PR
enterprise/coderd/workspaces_test.gois the main fix. It is safe to review alone..github/actions/test-cache/upload/action.ymlonly takes effect onmain. CI on this PR does not exercise it. Please read that file closely.testutil/terraform_cache.go. A later commit takes that back, so the file has no net change.Implementation
enterprise/coderd/workspaces_test.go:TestWorkspaceTemplateParamsChangenow passes a fixed providers-only file todownloadProviders. Before, it passed the full template, which contains at.TempDir()path.hashicorp/localbecause the template useslocal_filewithout declaring it..github/actions/test-cache/upload/action.yml:git hash-objectbecause git is present on Linux, macOS and Windows runners.Things a reviewer might question:
provisioner/terraform/install_test.gostores a response without checking its status, so a failed run could save an error page as a release file.runCmdare unchanged. A longer retry cannot outlast an outage of 50 minutes.Expected Output
TestWorkspaceTemplateParamsChangedownloads providers on its first run only. Later runs logusing cached terraform providers.mainrun that adds a Terraform test saves a cache that contains its providers at once. Before, that waited for the first green run of a later day.mainrun that downloads nothing new, on a day that already has a cache, saves nothing.mainrun that fails saves nothing, as before. A new test stays without a cache entry until the next green run.mainrun after a Terraform test changes, the firstmainrun of each month, and PRs that change such tests.Testing
TestProvision,TestProvision_LockFileCached,TestInstall,TestWorkspaceTemplateParamsChangeandTestWorkspaceTagsTerraform.make lint/actions/actionlintpasses.main. After merge, check that the upload step logs a key with a hash suffix.Manual Test
Run on macOS with Terraform 1.15.7. "Network blocked" means
HTTPS_PROXYandHTTP_PROXYpoint at a closed local port, so Terraform cannot reach the registry or GitHub.main, each run ofTestWorkspaceTemplateParamsChangeadds a cache directorymain, the test fails with the network blocked1 and 2. The problem on main
This is the same output and the same 80 second duration as the CI failures.
3 and 4. The test fix
5, 6 and 7. The cache key
The key suffix is computed with the same lines as the upload action.
Both packages reported
okin every run.