fix(taskmanager): flush flow runs on Infrahub 1.13, which takes no number of days
Summary
- Problem: Infrahub 1.13 removes
--days-to-keepand--batch-sizefrominfrahub tasks flush flow-runs(opsmill/infrahub#11289): the task manager deletes up to its own task history retention, and--rewritereturns the disk space.infrahub-taskmanager flush flow-runspasses both options. An unknown option is not the "no such command" error that starts the tool's script fallback, so on 1.13 the tool fails. - Change: the tool reads
infrahub tasks flush flow-runs --helpin the task worker and strips ANSI color formatting before checking the options. Forced-color help therefore uses the same detection as plain help.- When the help offers
--rewriteand no--days-to-keep(1.13 and later), the tool runsinfrahub tasks flush flow-runs, with--rewritewhen the new--rewriteflag is given. It warns whendays_to_keeporbatch_sizewere given, because those releases ignore them, and names the setting to use instead:INFRAHUB_TASK_MANAGER_RETENTION_TASK_HISTORY. - Otherwise the tool behaves as before, including the script fallback for releases without the command.
--rewriteis then ignored, with a warning. flush stale-runsis unchanged: its options stay in 1.13.
- When the help offers
- Release order: this can ship before Infrahub 1.13, because earlier releases keep the previous behaviour.
Validation of colored-help detection
The new colored-help cases fail against the previous implementation and pass with ANSI normalization, alongside the existing detection, command and warning cases. These tests ran in an isolated Go package containing the affected production declarations and the repository's test file; gofmt passed. The full package suite could not run locally because dependency downloads were denied and the embedded watchdog binaries were absent.
Original branch validation
- Unit tests for the detection, the command and the warning. The detection fixtures are the real help texts, printed with
COLUMNS=100by the Infrahub 1.11.4 image and by a build of opsmill/infrahub#10869. go vet,gofmtand golangci-lint v2.5.0 (0 issues), in containers.- End to end, with a macOS build of this branch, against a Docker Compose dev stack built from the opsmill/infrahub stack that ships 1.13:
flush flow-runs 7 --rewritewarned that the 7 days are ignored, then deleted 20,000 runs that ended 35 days ago and printed the per-table rewrite summary (21.4 MB before, 3.7 MB after);flush flow-runs --rewritewith no days gave no warning and deleted 5,000 runs;flush stale-runscompleted.
- Not run: a Kubernetes deployment, and an end-to-end run against a release before 1.13. On Kubernetes the run goes through
ExecStream, which builds itskubectl execarguments, environment included, with the same function asExec, and returns an error when the command fails; the tool's script fallback already uses it. go test ./...also fails insrc/internal/updater(install_test.go:22: direct: got "container") when run inside a container, onmainas well; it is unrelated to this change.
š¤ Generated with Claude Code
Summary by cubic
Fixes infrahub-taskmanager flush flow-runs on Infrahub 1.13, which removed --days-to-keep and --batch-size from infrahub tasks flush flow-runs. The tool passes both options, and since an unknown option isn't the "no such command" error that triggers its script fallback, the command failed on 1.13.
The tool now reads the command's help in the task worker to detect the Infrahub version. When 1.13 or later is detected, it runs the command without the removed flags, passes the new --rewrite flag when requested, and warns when days_to_keep or batch_size were given that they are ignored, pointing to INFRAHUB_TASK_MANAGER_RETENTION_TASK_HISTORY instead. Earlier releases keep the previous behavior, with --rewrite ignored and a warning.
Migration
- On Infrahub 1.13+,
days_to_keepandbatch_sizeare meaningless; setINFRAHUB_TASK_MANAGER_RETENTION_TASK_HISTORYinstead.