Skip to content

test(k8s): Use the git fake in k8s and argo cd gate tests #2182

Closed

Description

@dan-petty

What happened

#2143 records the owner's rule of 2026-10-24: a test of src/ starts no program. The Kubernetes and Argo CD gate tests still start a real git. The test-suite audit of 2026-10-24 at df8e2ee recorded every program a test started, with a PEP 578 audit hook on subprocess.Popen. It saw 38 tests in these files start git:

File Tests that started git
tests/test_k8s.py 21
tests/test_k8s_argocd_gate.py 9
tests/test_k8s_argocd_overrides.py 5
tests/test_k8s_argocd_apps.py 2
tests/test_k8s_devops_runtime.py 1

Most of them build a repository under tmp_path with a git helper or fixture, and the code under test then starts git through the process runner. A test that starts only git has a median time of 0.194 s, against 0.026 s for a test that starts nothing (the audit's cost summary).

What should happen

These tests reach git through the git fake of #2146 and start no program. A helper that builds a repository with git goes: the test writes its files under tmp_path and states the git answers it needs. A test that needs an answer that #2146 did not record adds the transcript with the recording row of #2146.

Evidence

  • .data/agent/scratch/audit/full_list.txt of the 2026-10-24 audit, section 1.git.

At b170358:

  • tests/test_k8s.py:1757-1790: _git and _commit.
  • tests/test_k8s_argocd_gate.py:17: _git_run.
  • tests/test_k8s_argocd_overrides.py:184-193: _repo.

Acceptance criteria

  • No test in the files above starts git or another program. The hermetic floor fails any of them that starts git, as it fails a test that starts gh.
  • The tests reach git only through the fake of test(git): one git seam answers tests from recorded git transcripts, with a contract suite that replays them #2146, and patch no devops_cli name (docs/TESTING.md).
  • Each test still checks the behaviour it checked before. The pull request names each test it deletes and why.
  • The pull request gives the summed time of these files before and after (uv run pytest <files> -n 0 --durations=0).
  • uv run devops ci passes.

Order: after #2146. #2174 migrates the data directory, run store and gitignore tests in the same way. Follows ADR 0007 as #2143 amends it. Related: #1322 (k8s/), #1323 (the devops k8s commands).

Source: #2146

Alternatives check of 2026-11-02: not-applicable.
Class: test, no search.
Tool: none found.

Proposed design

Problem statement

The Kubernetes and Argo CD gate tests in five test modules start a real git. The owner's rule of 2026-10-24 says a test of src/ starts no program. The tests must reach git through the GitFake of #2146. A test writes its files under tmp_path and states the git answers it needs. A git answer with no transcript gets a new scenario and a recording.

Acceptance criteria

Requirement: No program starts in the five modules

Each of the five named test modules SHALL start no program when it runs.

Scenario: The five modules run inside the hermetic floor

  • WHEN a person runs the five modules with uv run pytest
  • THEN every test passes and no test starts a real program, because the floor and git_fake refuse it.

Requirement: Git answers come from the fake

A test in the five modules MUST reach git only through the git_fake fixture.

Scenario: A migrated test asks git for an answer

  • WHEN the test runs a git command through the code under test
  • THEN GitFake answers it from a transcript of tests/fixtures/git/, and a command with no record fails the test and names the command.

Requirement: The git helpers are gone

The five modules MUST hold no helper that starts git.

Scenario: The modules are searched for the four helpers

  • WHEN a person runs ! git grep -n -I -F '_git_run' tests/k8s/test_k8s_argocd_gate.py and the same check for _git, _commit and _repo in the modules that hold them
  • THEN git finds no match for any of the four helpers in the five modules.

Requirement: A new git answer gets a recorded scenario

A test that needs a git command with no transcript MUST add a scenario to tests/support/git_scenarios.py and record it.

Scenario: The git row records every scenario again

  • WHEN a person runs the git row of devops ci
  • THEN the row passes and it fails on a transcript that differs from a new recording.

Requirement: Each migrated test keeps its behaviour

A migrated test SHALL assert the behaviour that it asserted before the migration.

Scenario: A migrated test reads the repository of its scenario

  • WHEN the test runs over the recorded scenario, with the repository at the scenario name under tmp_path
  • THEN it makes the same assertion as before the migration, and the pull request names each deleted test and the reason.

Requirement: The run time is reported

The pull request MUST give the summed time of the five modules before and after the change.

Scenario: The five modules are timed on both revisions

  • WHEN a person runs uv run pytest -n 0 --durations=0 on the base and on the branch
  • THEN the pull request shows both summed times.

Requirement: The gate passes

The change MUST pass uv run devops ci.

Scenario: The full gate runs on the branch

  • WHEN a person runs uv run devops ci
  • THEN the command exits 0.

Existing Tool Considered

The alternatives check of 2026-11-02 returned not-applicable for an item of class test and made no search, so it named no tool. The need is covered by the project's own GitFake in tests/support/fakes/git.py behind the git_fake fixture, which #2146 delivered. The change builds no code: it adds git scenarios and their transcripts, edits the five modules, and keeps the fake that already has a contract suite. Building a second git double would add code to keep, a contract suite of its own and a recording row, and docs/TESTING.md forbids a test that builds its own double of an edge.

Key questions

  • Which git commands do the five modules need from the fake?: The helpers make a repository. _git_run runs git init, git config user.name and git config user.email. _git and _commit run git add and git commit. _repo builds a repository with git. A command with no transcript gets a new scenario in tests/support/git_scenarios.py and a recording. [sources: tests/k8s/test_k8s_argocd_gate.py:17, tests/k8s/test_k8s_argocd_gate.py:289, tests/commands/k8s/test_k8s.py:1884, tests/k8s/test_k8s_argocd_overrides.py, docs/TESTING.md]
  • Where do the five test modules sit at the refined commit?: They moved into the mirror directories. test_k8s.py sits in tests/commands/k8s/, and the Argo CD gate and overrides modules sit in tests/k8s/. The acceptance criteria name each module by file name, so they hold at either path. [sources: tests/commands/k8s/test_k8s.py, tests/k8s/test_k8s_argocd_gate.py, tests/k8s/test_k8s_argocd_overrides.py]
  • How does a test add a git transcript that test(git): one git seam answers tests from recorded git transcripts, with a contract suite that replays them #2146 did not record?: Add a scenario to tests/support/git_scenarios.py and record it with uv run python -c "import sys; from tests.support.git_recording import main; sys.exit(main([]))". The git row of devops ci records every scenario again with the real git and fails when a transcript differs. [sources: docs/TESTING.md, tests/support/git_scenarios.py, tests/support/git_recording.py, tests/support/fakes/git.py]
  • Which issue must be delivered before this one?: test(git): one git seam answers tests from recorded git transcripts, with a contract suite that replays them #2146, which delivers GitFake and the git_fake fixture. docs/TESTING.md lists both as existing at the refined commit, so the order is met and this item can start. [sources: docs/TESTING.md, tests/support/fakes/git.py]
  • Which fixture states the git answers of a migrated test?: The test asks for git_fake and names its scenarios with git_fake.replay(...). It puts each repository of a scenario at the scenario name under tmp_path. It writes the files and reads them back from tmp_path. (best practice) [sources: docs/TESTING.md, tests/support/fakes/git.py, docs/adr/0007-tests-double-only-process-edges.md]
    • Chosen: The git_fake fixture with recorded scenarios. docs/TESTING.md gives one fake for the git edge, and a test names the scenarios it needs with git_fake.replay(...).
    • Rejected: A git double built in each test module. docs/TESTING.md forbids a test that builds its own double of an edge and gives each edge one shared fake.
    • Rejected: A real git for the setup, with the fake on the code under test. The hermetic floor refuses a real git, and the owner's rule of 2026-10-24 says a test of src/ starts no program.
  • How does a test reach a program other than git?: Through the fake at the process seam. When the check reads committed files, it goes to a row of devops ci instead, and the k8s row renders the committed manifests with kubectl kustomize once each. A test keeps no real program. (best practice) [sources: docs/TESTING.md]
    • Chosen: The fake at the process seam, or a devops ci row for a check of committed files. docs/TESTING.md fakes every program, keeps a real child process only in the process runner's contract suite, and gives a check of committed files to a row of devops ci.
    • Rejected: Keep the real program in the test. The hermetic floor refuses the program, and the acceptance criteria refuse a program start.
    • Rejected: A new double for each test that starts a program. docs/TESTING.md gives each edge one shared fake and forbids a test that builds its own double.
  • Does this item stay apart from test(core): the data directory, run store and gitignore tests start no git and reach git through the git fake #2174 and the other migration items?: Yes. test(core): the data directory, run store and gitignore tests start no git and reach git through the git fake #2174 moves the data directory, run store and gitignore tests, and this item moves the five Kubernetes and Argo CD modules. An item is one issue and one pull request that delivers nothing else. (best practice) [sources: CONTEXT.md, docs/TESTING.md]

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

#2146

Activity

  1. added
    type/test
    source/agent
    on Oct 24, 2026
  2. dan-petty commented on Oct 24, 2026

    @dan-petty
    OwnerAuthor

    The owner decided on 2026-10-24 that this item is separate from #2174: each of #2174 and #2178 to #2183 moves a different group of test files to the git fake, and each gives its own pull request. Intake judged it a duplicate of #2174 (recorded as a case on #1989), so it was placed by hand with the values of #2174: Priority P2-Medium, Value Medium; Effort Medium.

  3. dan-petty commented on Oct 28, 2026

    @dan-petty
    OwnerAuthor

    Refine cannot set this item to Ready at bb46660 until a person answers the questions below. Reply in a comment or edit the body, and the next refine round looks at the item again.

  4. added
    priority/p2-medium
    status/new
    value/medium
    effort/medium
    scope/k8s
    on Oct 28, 2026
  5. devops-cli-service commented on Nov 2, 2026

    @devops-cli-service
    Contributor

    Alternatives check: not-applicable

    Class: test. The check makes no search and no model call for an item of this class.

    Tool: none found

    Checked on 2026-11-02. A person decides what this means for the item. The check changes no label and closes no issue.

  6. added
    status/ready
    and removed
    status/new
    on Nov 5, 2026
  7. devops-cli-service commented on Nov 5, 2026

    @devops-cli-service
    Contributor

    Status set to Ready at d254410 (see proposed design in issue body).

  8. changed the title [-]test(k8s): the kubernetes and argo cd gate tests start no git and reach git through the git fake[/-] [+]test(k8s): Use the git fake in k8s and argo cd gate tests[/+] on Nov 6, 2026
  9. dan-petty commented on Nov 6, 2026

    @dan-petty
    OwnerAuthor

    The job shortened the title of this item. The summary had 85 characters, and the limit is 60. The type and the scope stay.

    • Before: test(k8s): the kubernetes and argo cd gate tests start no git and reach git through the git fake
    • After: test(k8s): Use the git fake in k8s and argo cd gate tests
    • Source of the summary: the background model
  10. added
    status/in-progress
    status/in-review
    and removed
    status/ready
    status/in-progress
    on Nov 8, 2026
  11. removed
    status/in-review
    on Nov 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/mediumpriority/p2-mediumscope/k8ssource/agenttype/testvalue/medium

    Type

    No type

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions