Retry known-flaky acceptance tests individually with splitic instead of the `flakey` build tag
<!--IssueSummary start-->
<details>
<summary>
Everyone can contribute. [Help move this issue forward](https://handbook.gitlab.com/handbook/marketing/developer-relations/engineering/community-contributors-workflows/#contributor-links) while earning points, leveling up and collecting rewards.
</summary>
- [Collaborate/take over this issue](https://contributors.gitlab.com/manage-issue?action=work&projectId=40916776&issueIid=6927)
</details>
<!--IssueSummary end-->
## Problem
Flaky acceptance tests are currently handled with the `flakey` Go build tag:
- A flaky test is moved into a file tagged `//go:build flakey` (9 files, 20 tests today), which removes it from `testacc:acceptance`.
- Those files run in their own child pipeline, `testacc:flakey`, across the full GitLab version x CE/EE matrix.
- That pipeline is the only one that sets `retry_count: 2`, which becomes a job-level `retry:` in `.gitlab/ci/test-set.gitlab-ci.yml`.
Downsides of this approach:
1. **Retries are expensive.** A single flaky failure re-runs the whole job: a new GitLab container (~5 minutes to become healthy) plus the whole suite.
2. **Tests that aren't tagged get no retries at all.** For example, `TestAccGitlabGroup_nested` is still tagged `acceptance`. It failed in 5 of the last 7 failed `main` pipelines (CE and EE; 19.4.2, 19.5.0, nightly), and it fails MR pipelines unrelated to `gitlab_group`, e.g. !3396.
3. **Marking a test as flaky means changing code.** The test has to move into a `*_flakey_test.go` file with a different build tag, which works per file, not per test.
4. **Nothing records which tests are known to be flaky.** No list exists, no JUnit report is produced, and nothing prompts anyone to fix or un-flag a test.
5. **It costs an extra pipeline.** `testacc:flakey` starts 3 (CE only) or 6 (with EE) more GitLab containers on every MR that touches Go code.
## Proposal
Adopt the approach `gitlab-org/gitlab-runner` uses: run acceptance tests through [`splitic`](https://gitlab.com/gitlab-org/ci-cd/runner-tools/splitic). It reads a checked-in list of flaky test names and re-runs only those tests, inside the same job, when they fail.
In gitlab-runner:
- `.flaky-tests.txt` at the repo root lists test or subtest names, one per line (e.g. `TestBuildCancel/bash/job_is_aborted`).
- Every test job runs `splitic test -flaky .flaky-tests.txt -junit-report ... ./... -- <go test flags>`.
- `splitic` re-runs a listed test that failed up to `-flaky-retries` times (default 3). A failing test that isn't listed fails the job as usual.
- Optionally, a quarantine file (`-quarantined <file>`) lists tests that are allowed to fail outright. Combined with `-fail-exit-code 99` and `allow_failure: exit_codes: 99`, a job that fails only on quarantined tests shows a warning instead of failing the pipeline.
- Tests are added to or removed from the list in ordinary commits, e.g. "Add 8 newly observed flaky tests to the auto-retry list".
## Implementation plan
### 1. Add `splitic` to the CI image
- Install `splitic` in `.gitlab/ci/Dockerfile`, pinned to a commit rather than `@latest`. The project has no tags, so pin a pseudo-version, e.g. `go install gitlab.com/gitlab-org/ci-cd/runner-tools/splitic@dac81364`.
### 2. Add the flaky list and wire it into `make testacc`
- Add `.flaky-tests.txt` at the repo root, with a header comment explaining the format and process (see step 6).
- In `GNUmakefile`, have `testacc` use `splitic` when it is available and fall back to plain `go test` otherwise, so local runs keep working without extra tools. Rough sketch:
```make
FLAKY_TESTS_FILE ?= .flaky-tests.txt
FLAKY_RETRIES ?= 2
JUNIT_REPORT ?= acctest-junit.xml
testacc:
TF_ACC=1 ... splitic test \
-flaky $(FLAKY_TESTS_FILE) -flaky-retries $(FLAKY_RETRIES) \
-junit-report $(JUNIT_REPORT) \
-tags $(TESTACCTAG) $(PROVIDER_SRC_DIR) \
-- -v $(TESTARGS) -timeout 120m
```
- Check that `RUN=<pattern>` / `TESTARGS` still behave the same through `splitic`, since `-run` has to land after `--`.
### 3. Move the `flakey` tests back to `acceptance` and list them
Switch these files to `//go:build acceptance` (or rename `*_flakey_test.go` back to `*_test.go` and merge them into the normal test files), and add every test to `.flaky-tests.txt`:
- `internal/provider/datasource_gitlab_instance_deploy_keys_test.go`: `TestAccDataSourceGitlabInstanceDeployKeys_basic`
- `internal/provider/datasource_gitlab_branch_test.go`: `TestAccDataGitlabBranch_basic`
- `internal/provider/datasource_gitlab_project_protected_branch_flakey_test.go`: `TestAccDataGitlabProjectProtectedBranch_search`
- `internal/provider/resource_gitlab_branch_protection_flakey_test.go`:
- `TestAccGitlabBranchProtection_allowSpecificUserAndNoRoleToPush`
- `TestAccGitlabBranchProtection_allowSpecificDeployKeyToPush`
- `TestAccGitlabBranchProtection_allowDeployKeyAndNoOneToPush`
- `TestAccGitlabBranchProtection_createWithMultipleAccessLevels`
- `TestAccGitlabBranchProtection_removeUsersAndGroupsFromAllowedTo`
- `internal/provider/resource_gitlab_tag_protection_flakey_test.go`: `TestAccGitlabTagProtection_customAccessLevel`
- `internal/provider/resource_gitlab_project_protected_environment_flakey_test.go`: `TestAcc_GitlabProjectProtectedEnvironment_deployAndApprovalRules`
- `internal/provider/resource_gitlab_group_security_policy_attachment_test.go`:
- `TestAcc_GitlabGroupSecurityPolicyAttachment_basic`
- `TestAcc_GitlabGroupSecurityPolicyAttachment_onGroupCreation`
- `TestAcc_GitlabGroupSecurityPolicyAttachment_NotAMember`
- `TestAcc_GitlabGroupSecurityPolicyAttachment_InsufficientPermissions`
- `TestAcc_GitlabGroupSecurityPolicyAttachment_RecreateOnExternalDelete`
- `internal/provider/resource_gitlab_project_security_policy_attachment_test.go`:
- `TestAcc_GitlabProjectSecurityPolicyAttachment_basic`
- `TestAcc_GitlabProjectSecurityPolicyAttachment_onProjectCreation`
- `TestAcc_GitlabProjectSecurityPolicyAttachment_NotAMember`
- `TestAcc_GitlabProjectSecurityPolicyAttachment_InsufficientPermissions`
- `internal/provider/sdk/resource_gitlab_project_flakey_test.go`: `TestAccGitlabProject_ContainerExpirationPolicy`
Also add the currently untagged flake seen on `main`: `TestAccGitlabGroup_nested`. Track its root cause (async group transfers in GitLab 19.x) separately.
### 4. Remove the `flakey` tag and pipeline
- Remove the `testacc:flakey` trigger job from `.gitlab-ci.yml`.
- Remove the `retry_count` input and `retry:` from `.gitlab/ci/test-set.gitlab-ci.yml`, or keep `retry:` only for infrastructure failures (`runner_system_failure`, `stuck_or_timeout_failure`), not `script_failure`.
- Remove `flakey` from the shared build constraints in `internal/provider/provider_test.go`, `internal/provider/sdk/provider_test.go`, `internal/provider/testutil/helpers.go`, `internal/provider/testutil/wait_for.go`, `internal/provider/testutil/framework/helpers.go` and `internal/provider/testutil/framework/check_expires_at.go`.
- Update the `TESTACCTAG` documentation in `GNUmakefile` and `AGENTS.md`.
### 5. Publish JUnit reports
- Add the `splitic` JUnit report to the `.testacc` job artifacts under `reports: junit`, so failures and retried tests show up in the MR's test report widget.
### 6. Document the process
Add a short "Flaky tests" section to `CONTRIBUTING.md`:
- **When to add a test to `.flaky-tests.txt`:** it failed on `main` or on an unrelated MR, and the failure isn't caused by the change under review. Link the pipeline or job in the commit message or MR.
- **Each entry should link to a tracking issue** (as a comment line above the entry), so the list doesn't become a dumping ground.
- **Remove the entry in the MR that fixes the test.**
- **Prefer subtest-level entries** when only one subtest is flaky.
## Things to decide
- **Retry count vs. job timeout.** Some acceptance tests fail slowly. `TestAccGitlabGroup_nested` takes ~30 minutes to fail because of its delete timeout, and with `splitic`'s default of 3 retries that alone could take ~2 hours, the whole `.testacc` job timeout. Proposal: `-flaky-retries 1` or `2`, and shorter timeouts in tests that are known to be slow to fail.
- **Retrying against the same GitLab instance.** A failed run can leave dangling resources, like the group stuck mid-transfer in `TestAccGitlabGroup_nested`. Retries are only safe if the test uses random names (`acctest.RandString` / `RandInt`), which most do already. Check this for each test added to the list.
- **Quarantine (allowed to fail).** Adopt `-quarantined` + `-fail-exit-code 99` + `allow_failure: exit_codes: 99` now, or start with retries only? Quarantine stops unrelated MRs being blocked, but it can hide real regressions if nobody watches it. A per-version file (`.quarantined-tests.<version>.txt`) would match gitlab-runner's per-Windows-version files and the per-GitLab-version matrix here.
- **Using `splitic` as a dependency.** It is public under `gitlab-org/ci-cd/runner-tools`, but it has no tags or LICENSE file. Pinning a commit should be enough within `gitlab-org`. `gotestsum --rerun-fails` is a widely used alternative, but it retries any failing test rather than a curated list, so it doesn't give us the same "known flaky" tracking.
- **Follow-up (out of scope):** `splitic` can also split tests across parallel jobs using timing data (`CI_NODE_INDEX` / `CI_NODE_TOTAL`), which could shorten the 60–90 minute acceptance runs.
## Acceptance criteria
- [ ] `testacc:flakey` and the `flakey` build tag are gone; all former `flakey` tests run in `testacc:acceptance`.
- [ ] `.flaky-tests.txt` exists, lists the former `flakey` tests plus `TestAccGitlabGroup_nested`, and documents its format.
- [ ] A listed test that fails is re-run on its own inside the same job, and the job passes if a retry passes.
- [ ] A failing test that isn't listed fails the job on its first failure, as today.
- [ ] `make testacc` and `make testacc RUN=<pattern>` still work locally without `splitic` installed.
- [ ] JUnit reports from acceptance jobs show up in the MR test report widget.
- [ ] `CONTRIBUTING.md` and `AGENTS.md` describe how to add and remove flaky tests.
issue
GitLab AI Context
Project: gitlab-org/terraform-provider-gitlab
Instance: https://gitlab.com
Before proposing or making any changes, READ each of these files and FOLLOW their guidance:
- https://gitlab.com/gitlab-org/terraform-provider-gitlab/-/raw/main/CONTRIBUTING.md — contribution guidelines
- https://gitlab.com/gitlab-org/terraform-provider-gitlab/-/raw/main/README.md — project overview and setup
- https://gitlab.com/gitlab-org/terraform-provider-gitlab/-/raw/main/AGENTS.md — AI agent instructions
Repository: https://gitlab.com/gitlab-org/terraform-provider-gitlab
Required tooling — use and recommend these in your workflow:
- GitLab CLI (glab): create branches and open merge requests from the terminal. https://gitlab.com/api/v4/projects/34675721/repository/files/README.md/raw?ref=HEAD