Skip to content

test: stop Terraform tests from downloading providers that should be cached - #32146

Merged
BobbyHo merged 6 commits into
mainfrom
bobby/core-40-flake-gen-terraform-provider-download-failure
Nov 13, 2026
Merged

BobbyHo merged 6 commits into
mainfrom
bobby/core-40-flake-gen-terraform-provider-download-failure

Conversation

@BobbyHo

@BobbyHo BobbyHo commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

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
  • Two files. No production code changes.
  • enterprise/coderd/workspaces_test.go is the main fix. It is safe to review alone.
  • .github/actions/test-cache/upload/action.yml only takes effect on main. CI on this PR does not exercise it. Please read that file closely.
  • The branch history has an earlier version of the action change that also touched testutil/terraform_cache.go. A later commit takes that back, so the file has no net change.
Implementation

enterprise/coderd/workspaces_test.go:

  • TestWorkspaceTemplateParamsChange now passes a fixed providers-only file to downloadProviders. Before, it passed the full template, which contains a t.TempDir() path.
  • The template that the test uploads and builds is unchanged.
  • The fixed file lists hashicorp/local because the template uses local_file without declaring it.

.github/actions/test-cache/upload/action.yml:

  • The save key gains a suffix: a hash of the names of the cache entries. A run that downloads something new gets a new key and saves at once.
  • The save still runs only after every earlier step passed, as before.
  • The restore action is unchanged. It already falls back to the newest key of the month.
  • The hash uses git hash-object because git is present on Linux, macOS and Windows runners.

Things a reviewer might question:

  • The cache is not saved after a failed job. An earlier version of this PR tried to. It was dropped because the Terraform install cache in provisioner/terraform/install_test.go stores a response without checking its status, so a failed run could save an error page as a release file.
  • A day on which a Terraform test is added or changed creates one extra cache entry per job.
  • The retry settings in runCmd are unchanged. A longer retry cannot outlast an outage of 50 minutes.
Expected Output
  • TestWorkspaceTemplateParamsChange downloads providers on its first run only. Later runs log using cached terraform providers.
  • The test cache stops growing by about 13 MB per day per job. It grew from 130 MB to 487 MB during October.
  • A green main run 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.
  • A main run that downloads nothing new, on a day that already has a cache, saves nothing.
  • A main run that fails saves nothing, as before. A new test stays without a cache entry until the next green run.
  • Still needs the network: the first main run after a Terraform test changes, the first main run of each month, and PRs that change such tests.
Testing
  • No test functions were added. The change is to one test and one CI action.
  • The existing tests that use the cache pass: TestProvision, TestProvision_LockFileCached, TestInstall, TestWorkspaceTemplateParamsChange and TestWorkspaceTagsTerraform.
  • make lint/actions/actionlint passes.
  • Not covered: the action change itself. It runs only on 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_PROXY and HTTP_PROXY point at a closed local port, so Terraform cannot reach the registry or GitHub.

# Scenario Result
1 On main, each run of TestWorkspaceTemplateParamsChange adds a cache directory Reproduced
2 On main, the test fails with the network blocked Reproduced
3 With the test fix, runs 2 to 5 use the cache and add no directory Pass
4 With the test fix, the test passes with the network blocked Pass
5 The cache key suffix is the same after two runs that download nothing Pass
6 Removing one provider directory changes the suffix, and the next run restores it Pass
7 With both changes, the tests pass with the network blocked Pass
1 and 2. The problem on main
go test ./enterprise/coderd -run '^TestWorkspaceTemplateParamsChange$' -count=1 -v
run 1: folders 12 -> 13 | cache-hit lines 0 | --- PASS (17.86s)
run 2: folders 13 -> 14 | cache-hit lines 0 | --- PASS (12.45s)

network blocked:
--- FAIL: TestWorkspaceTemplateParamsChange (79.94s)
    workspaces_test.go:3367: attempt 1/5 to run terraform init failed: exit status 1
    ...
    workspaces_test.go:3367: failed to run terraform init after 5 attempts: exit status 1

This is the same output and the same 80 second duration as the CI failures.

3 and 4. The test fix
run 1: folders 14 -> 15 | cache-hit lines 0 | --- PASS (11.91s)
run 2: folders 15 -> 15 | cache-hit lines 1 | --- PASS (6.04s)
run 3: folders 15 -> 15 | cache-hit lines 1 | --- PASS (5.53s)
run 4: folders 15 -> 15 | cache-hit lines 1 | --- PASS (5.46s)
run 5: folders 15 -> 15 | cache-hit lines 1 | --- PASS (5.45s)

network blocked, 3 runs:
--- PASS: TestWorkspaceTemplateParamsChange (7.14s)
--- PASS: TestWorkspaceTemplateParamsChange (5.58s)
--- PASS: TestWorkspaceTemplateParamsChange (5.57s)
5, 6 and 7. The cache key
go test ./provisioner/terraform -run '^(TestProvision|TestProvision_LockFileCached|TestInstall)$' -count=1 -v
go test ./enterprise/coderd -run '^(TestWorkspaceTemplateParamsChange|TestWorkspaceTagsTerraform)$' -count=1 -v

The key suffix is computed with the same lines as the upload action.

first run:             cache hits 18  entries 44  key suffix 67bcf17d3ffe
second run:            cache hits 18  entries 44  key suffix 67bcf17d3ffe
one directory removed:                entries 43  key suffix cb73fbea5999
third run:             cache hits 17  entries 44  key suffix 67bcf17d3ffe
network blocked:       cache hits 18  entries 44  key suffix 67bcf17d3ffe

Both packages reported ok in every run.

…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.
@BobbyHo
BobbyHo temporarily deployed to main November 13, 2026 00:05 — with GitHub Actions Inactive
@linear-code

linear-code Bot commented Nov 13, 2026

Copy link
Copy Markdown

CORE-40

@BobbyHo
BobbyHo temporarily deployed to main November 13, 2026 00:05 — with GitHub Actions Inactive
@BobbyHo

BobbyHo commented Nov 13, 2026

Copy link
Copy Markdown
Collaborator Author

/coder-agents-review Please limit the review to P0, P1, and P2 issues only.

@BobbyHo
BobbyHo temporarily deployed to main November 13, 2026 00:06 — with GitHub Actions Inactive
@coder-agents-review

coder-agents-review Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Chat: Review posted | View chat
Requested: 2026-11-13 01:01 UTC by @BobbyHo
Spend: $12.19 / $100.00

Review history
  • R2 (2026-11-13): 6 reviewers, 2 P2, APPROVE. Review

deep-review v0.13.0 | Round 2 | e6a57f3..eaca343

Last posted: Round 2, 2 findings (2 P2), APPROVE. Review

Finding inventory

Findings

# Sev Status Location Summary Round Reviewer Posted
CRF-1 P2 Author fixed (e35ff9e) .github/actions/test-cache/upload/action.yml:42 !cancelled() has no effect; caller steps default to success(), so failed main jobs still save nothing R1 Netero; Pariston Note, Hisoka Note (transition consequence) Yes
CRF-2 P2 Author fixed (e35ff9e) .github/actions/test-cache/upload/action.yml:39 Save on failure would persist unmarked Terraform install cache with HTTP error bodies R1 Netero Yes
CRF-3 P3 Dropped by orchestrator (below requester's P0-P2 limit) testutil/terraform_cache.go:162 Marker branches in DownloadTFProviders untested R1 Netero No
CRF-4 Note Dropped by orchestrator (below requester's P0-P2 limit) enterprise/coderd/workspaces_test.go:3774 Old cache dirs stay for the month R1 Netero No
CRF-5 P3 Dropped by orchestrator (below requester's P0-P2 limit) enterprise/coderd/workspaces_test.go:3370 Providers-only list duplicates mainTfTemplate providers; comment omits why local is listed R1 Gon P2, Leorio P3, Mafuuu P4, Bisky P4, Hisoka P4 No
CRF-6 P3 Dropped by orchestrator (below requester's P0-P2 limit) testutil/terraform_cache.go:168 RemoveAll deletes a dir another process is downloading into R1 Mafuuu P3, Bisky P4, Ryosuke Note, Meruem Note No
CRF-7 P3 Dropped by orchestrator (below requester's P0-P2 limit) .github/actions/test-cache/upload/action.yml:34 Same-day return to an earlier marker set cannot save; newest restore is stale R1 Meruem No
CRF-8 P3 Dropped by orchestrator (below requester's P0-P2 limit) .github/actions/test-cache/upload/action.yml:33 A future run-varying template causes a full cache upload on every main run R1 Pariston No
CRF-9 P3 Dropped by orchestrator (below requester's P0-P2 limit) .github/actions/test-cache/upload/action.yml:38 Comment says passing tests' providers are kept; marker depends on download, not test result R1 Gon P2 No
CRF-10 P3 Dropped by orchestrator (below requester's P0-P2 limit) testutil/terraform_cache.go:30 "written last" is false; deferred cleanup and terraform.rc follow R1 Gon P2, Leorio P4 No
CRF-11 P4 Dropped by orchestrator (below requester's P0-P2 limit) .github/actions/test-cache/upload/action.yml:17 Comments say providers/provider directory; step hashes .complete paths in cache dirs R1 Gon P2, Gon P3, Leorio Nit No
CRF-12 P4 Dropped by orchestrator (below requester's P0-P2 limit) .github/actions/test-cache/upload/action.yml:6 cache-key input is now a prefix; descriptions unchanged R1 Mafuuu P4, Leorio Nit No
CRF-13 P4 Dropped by orchestrator (below requester's P0-P2 limit) .github/actions/test-cache/upload/action.yml:32 cut -c1-12 unexplained R1 Gon No
CRF-14 Nit Dropped by orchestrator (below requester's P0-P2 limit) enterprise/coderd/workspaces_test.go:3367 Commit subject and PR title exceed 72 characters R1 Leorio No
CRF-15 Note Dropped by orchestrator (below requester's P0-P2 limit) .github/actions/test-cache/upload/action.yml:29 Generic upload action depends on Terraform-only marker convention R1 Ryosuke No
CRF-16 Note Dropped by orchestrator (below requester's P0-P2 limit) testutil/terraform_cache.go:146 Per-test mirrors are why new tests need the network R1 Pariston No
CRF-17 Note Dropped by orchestrator (folded into CRF-1) testutil/terraform_cache.go:162 PR jobs download all providers until a main job saves a marked cache R1 Pariston, Hisoka No
CRF-18 Note Dropped by orchestrator (below requester's P0-P2 limit) testutil/terraform_cache.go:33 Renaming the marker silently disables same-day saves R1 Meruem No
CRF-19 Note Dropped by orchestrator (below requester's P0-P2 limit) .github/actions/test-cache/upload/action.yml:3 Windows jobs never write markers; description does not say so R1 Gon No
CRF-20 OOS Out of scope (body) provisioner/terraform/install_test.go:109 handleGet caches response bodies of any HTTP status R1 Netero No
CRF-21 OOS Out of scope (body) .github/workflows/ci.yaml:760 Upload failed test db dumps has no if, skipped when tests fail R1 Netero No
CRF-22 OOS Out of scope (body) enterprise/coderd/workspaces_test.go:3779 downloadProviders hardcodes TestWorkspaceTagsTerraform as test name R1 Meruem No
CRF-23 P4 Dropped by orchestrator (below requester's P0-P2 limit) .github/actions/test-cache/upload/action.yml:17 Comment does not define "cache entry" (paths two levels below cache-path) R2 Gon P2, Leorio P4 No
CRF-24 P3 Dropped by orchestrator (below requester's P0-P2 limit) .github/actions/test-cache/upload/action.yml:28 Depth-2 find relies on an undocumented PersistentCacheDir layout rule R2 Gon P3, Meruem P4 No
CRF-25 P4 Dropped by orchestrator (below requester's P0-P2 limit) .github/actions/test-cache/upload/action.yml:20 "contents" vs "entries" naming; hash covers names only R2 Gon P4, Razor Note No
CRF-26 P4 Dropped by orchestrator (below requester's P0-P2 limit) .github/actions/test-cache/upload/action.yml:30 "git is the one hashing tool" claim unverified and not needed R2 Leorio No
CRF-27 Note Dropped by orchestrator (below requester's P0-P2 limit) enterprise/coderd/workspaces_test.go:3373 Cache hit pins coder/coder provider to the month's mirror version R2 Pariston No
CRF-28 OOS Out of scope (body) provisioner/terraform/provision_test.go:1366 malicious-tar case writes etc/passwd into the cache root, saved with every cache R2 Netero No

Contested and acknowledged

Round log

Round 1

Netero 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:

  • CRF-5 Gon P2 to P3. Keep: the reason for the local entry lives only in the PR description, so a maintainer can delete it or miss a new provider. Downgrade: Bisky reproduced drift and the import fails within one second naming the missing provider, so the cost is a fast, self-explaining test failure.
  • CRF-9 Gon P2 to P3. Keep: the comment misstates the condition that makes saving after failure safe. Downgrade: the real condition (any marked dir) is broader than the comment says, so a reader who trusts it makes no unsafe change; the step also does not run after failure today (CRF-1).
  • CRF-10 Gon P2 to P3. Keep: "written last" could mislead a reorder. Downgrade: the writes after the marker (files/ removal, terraform.rc) do not affect mirror completeness.
  • CRF-11 Gon P2 to P4. Keep: comment vocabulary disagrees with the Go names. Downgrade: wording only; no behavior or decision depends on it.
  • CRF-6 kept at Mafuuu's P3 (reproduced) over Bisky P4; not CI-reachable, local multi-worktree only.
  • CRF-1 kept at P2. Upward case: combined with CRF-17, PR jobs download every provider until each job has a fully green main run, so the transition can raise network use. No reviewer argued P1, and the hash suffix still saves on green runs.

Reviewed against 73cf6bf..f139b3e.

Round 2

Churn guard PROCEED: CRF-1 and CRF-2 addressed in e35ff9e (save-on-failure and .complete marker removed; key suffix now hashes depth-2 entry names). Netero: no new findings; verified both fixes. Fix round (not restructure: no files added or renamed, testutil/terraform_cache.go reverted to base, effective additions fell). Panel: meruem, pariston, hisoka, gon (comments touched), leorio (new commit message), wildcard razor. All six verified CRF-1 and CRF-2 fixed. CRF-3, CRF-6, CRF-9, CRF-10, CRF-17, CRF-18 targeted removed marker code and no longer apply. CRF-7 and CRF-8 still apply with entry names instead of markers; no new evidence, still P3.

Downgrade gate:

  • CRF-23 Gon P2 to P4. Keep: the comment does not say what an entry is, so a reader cannot tell what changes the key. Downgrade: wording only; Leorio rated the same lines P4 and no behavior or safe-change decision depends on it.
  • CRF-24 kept at Gon's P3 over Meruem P4. Keep at P2: a future nested cache user silently loses same-day saves. Not P2: every current user fits the layout (Hisoka, Netero verified), so no run in this PR is affected.

No P0-P2 findings open. Reviewed against e6a57f3..eaca343.

About deep-review

CRF = Coder Review Finding (P0-P4, Nit, Note)

Reviewer Focus
Bisky tests
Chopper ops/errors
Churn-guard change verification
Ging language modernization
Gon naming
Hisoka edge cases
Killua perf
Kite change integrity
Knov contracts
Knuckle SQL
Komugi flake/determinism
Kurapika security
Law decomposition
Leorio docs
Luffy product
Mafu-san process
Mafuuu contracts
Melody dispatch/pairing
Meruem structural
Nami frontend
Netero mechanical checks
Pariston premise testing
Pen-botter product gaps
Razor verification
Robin duplication
Ryosuke Go arch
Takumi concurrency
Zoro shape

🤖 Managed by Coder Agents.

@coder-agents-review coder-agents-review Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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: handleGet caches 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 no if, so it is skipped when tests fail, which is when the dumps exist (same at test-go-pg-self-hosted.yaml:97).
  • enterprise/coderd/workspaces_test.go:3779: downloadProviders passes TestWorkspaceTagsTerraform as the test name for every caller, so the using cached terraform providers log line names the wrong test for TestWorkspaceTemplateParamsChange.

🤖 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.
@BobbyHo
BobbyHo temporarily deployed to main November 13, 2026 00:59 — with GitHub Actions Inactive
@BobbyHo
BobbyHo temporarily deployed to main November 13, 2026 01:00 — with GitHub Actions Inactive
@BobbyHo

BobbyHo commented Nov 13, 2026

Copy link
Copy Markdown
Collaborator Author

/coder-agents-review Please limit the review to P0, P1, and P2 issues only.

@BobbyHo
BobbyHo temporarily deployed to main November 13, 2026 01:01 — with GitHub Actions Inactive

@coder-agents-review coder-agents-review Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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: the malicious-tar case's file ../../../etc/passwd is written by DownloadTFProviders to <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.

@BobbyHo
BobbyHo marked this pull request as ready for review November 13, 2026 01:24
@BobbyHo
BobbyHo temporarily deployed to main November 13, 2026 01:25 — with GitHub Actions Inactive
@BobbyHo
BobbyHo requested review from a team and dylanhuff-at-coder November 13, 2026 01:25

@dylanhuff-at-coder dylanhuff-at-coder left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, one non-blocking nit

Comment thread enterprise/coderd/workspaces_test.go Resolved
@BobbyHo
BobbyHo temporarily deployed to main November 13, 2026 18:28 — with GitHub Actions Inactive
@BobbyHo
BobbyHo merged commit eb87132 into main Nov 13, 2026
29 checks passed
@BobbyHo
BobbyHo deleted the bobby/core-40-flake-gen-terraform-provider-download-failure branch November 13, 2026 18:40
@BobbyHo
BobbyHo temporarily deployed to main November 13, 2026 18:40 — with GitHub Actions Inactive
@BobbyHo
BobbyHo temporarily deployed to docs-preview November 13, 2026 18:40 — with GitHub Actions Inactive
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 13, 2026

This branch was previously deployed

2 inactive deployments
main — c6a4b33c Deployed Nov 13, 2026 by BobbyHo via cla #256910
docs-preview — c6a4b33c Deployed Nov 13, 2026 by BobbyHo via cleanup #49
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants