Repository navigation
Description
Problem
Counts come from one AST pass over tests/test_*.py at 5c45b1e, the head of release/v0.2.28, and [code: …] lines are at the same commit. A file belongs to the package it references most, as in the census. A patch site is a patch, patch.object, patch.dict, mocker.patch or monkeypatch.setattr/setitem/delattr call aimed at devops_cli. A private import is a _-prefixed name imported from devops_cli.
- Files. 18 test files have
k8s/as their primary package: 6,752 lines and 352 tests [measured: AST pass at 5c45b1e].- They are
test_http_connection_pool,test_k8s_argocd_overrides,test_k8s_chaos_runner,test_k8s_configmap,test_k8s_context_resolution,test_k8s_credentials,test_k8s_doctor,test_k8s_gpu_matrix,test_k8s_logql,test_k8s_logs_diff_chaos,test_k8s_models,test_k8s_policy,test_k8s_port_forward_daemon,test_k8s_push_secrets,test_k8s_security_stream,test_k8s_service,test_k8s_service_proxyandtest_k8s_template. test_k8s_argocd_overridescame with fix(k8s): argo cd takes homelab values from deploy-time overrides, and the repository holds no private or placeholder config #1290, which deletedtest_k8s_argocd_sourceandk8s/argocd_source.pyand addedk8s/argocd_overrides.py.test_k8s_argocd_apps.pychecks committed manifests, so test(cli): every test file sits in the directory mirroring the package it tests or in tests/invariants/, and the root conftest holds only the hermetic floor #1313 places it intests/invariants/instead.
- They are
- Coupling. The 18 files hold 134 internal patch sites and 24 private imports, in 10 files [measured].
- The most-patched internals:
service_proxy._kube_configuration11,credentials._keyring_set7,commands.devcontainer.run_subprocess6,context.configured_context6, andload_settings9. - 76 more sites patch libraries directly, among them 21
httpx2, 18kubernetes.*and 13sys.modulesswaps that inject a fakekubernetes, because everykubernetesimport is function-local. - 9 of the files build a module-level
runner = CliRunner().
- The most-patched internals:
- Kubernetes API.
KubernetesServiceis a process singleton [code: k8s/service.py:55,get_instance:76].- Two modules load their own client instead [code: k8s/service_proxy.py:178-181; k8s/doctor.py:634].
- Two read its private
_core_v1[code: k8s/informer.py:100; k8s/service_proxy.py:328]. FakeCoreV1(tests/k8s_fakes.py) is installed by patching the privateui.data_providers._get_k8s_client[code: tests/test_k8s_models.py:383].
- Other edges outside a seam.
- HTTP:
- httpx2 clients are built inline [code: k8s/credentials.py:222, :315, :403, :434], and
logql.pycallshttpx2.get[code: k8s/logql.py:365].
- httpx2 clients are built inline [code: k8s/credentials.py:222, :315, :403, :434], and
- Processes:
- kubectl runs through two module-local helpers,
kubectl[code: k8s/node_port.py:39] and_kubectl[code: k8s/secret_push.py:262]; - gh is called without
run_gh[code: k8s/secret_push.py:323]; shutil.whichis called directly [code: k8s/logs.py:50];- the port-forward daemon has its own process-group kill [code: k8s/port_forward_daemon.py:79-102], one of the four copies refactor(cli): one process runner owns execution, process groups and dry-run #775 consolidates;
argocd_overrides.pytakes its runner as an untypedruncallable [code: k8s/argocd_overrides.py:29, :80], and its tests run realkubectl kustomize[code: tests/test_k8s_argocd_overrides.py:224].
- kubectl runs through two module-local helpers,
- Keyring:
credentials.pyimports the privateconfig.settings._keyring_set[code: k8s/credentials.py:17].
- Clock:
- the client cache expires on
time.time()[code: k8s/service.py:346], and the chaos run waits withtime.sleepfor up to 10 s [code: k8s/chaos.py:104]; tests/test_k8s_service.py:460-466sets the private_cache_ttland sleeps for real to expire an entry.
- the client cache expires on
- HTTP:
- Logic living in commands/.
_apply_configured_k8s_contextdecides which context kubectl follows [code: commands/devcontainer.py:595].test_k8s_context_resolution.pyimports it privately 6 times.- Two files import the
devops k8s podsrenderercommands.k8s.diagnostics._build_pods_tablethree times [code: tests/test_k8s_logs_diff_chaos.py:98, :125; tests/test_k8s_models.py:20].
- Files and names.
test_k8s_push_secrets.py(1,203 lines, 55 tests) mixes four things: invariants over committed files (every secret underk8s/has a table row; the README lists the table), the push, the plan and dry run, and the GitHub machine account.test_k8s_argocd_overrides.pyalso checks the committed Argo CD Applications: it renders each one withkubectl kustomize[code: tests/test_k8s_argocd_overrides.py:250].test_k8s_credentials.pynames its tests..._success/..._failure(:28-:155). There are 18 such names across these files.
Acceptance criteria
- No internal patches or private imports. The test files under
tests/k8s/have zero patch sites aimed at devops_cli internals and zero private imports. If test(cli): ratchets hold internal patches, private imports and test accommodations in src at today's counts and name each site that would raise one #1309 has landed, its two ceilings drop by the counts these files carry when the item starts (134 and 24 at 5c45b1e). - Kubernetes API through refactor(k8s): KubernetesService is the Kubernetes API seam, with a shared fake cluster and its contract suite #1315.
- No module in
k8s/loads a Kubernetes client of its own:service_proxy.pyanddoctor.pytake theirs from refactor(k8s): KubernetesService is the Kubernetes API seam, with a shared fake cluster and its contract suite #1315's seam, unless refactor(k8s): KubernetesService is the Kubernetes API seam, with a shared fake cluster and its contract suite #1315 has already routed them. informer.pyandservice_proxy.pystop reading_core_v1.- Tests use the promoted
FakeCoreV1. - No test patches
sys.modules,kubernetes.*,_kube_configurationor_get_k8s_client.
- No module in
- HTTP through refactor(cli): Unify HTTP and DNS seams with shared fakes #1314.
credentials.pyandlogql.pybuild no httpx2 client of their own, and their tests use the HTTP fake. - Processes through refactor(cli): one process runner owns execution, process groups and dry-run #775.
- kubectl, gh and stern run through the process runner.
argocd_overrides.py'srunparameter is typed by the runner's Protocol, and its tests pass the process fake. git stays real (Q23), and thekubectl kustomizerender is declared as a real local tool, as test(cli): the hermetic floor fails a test that reaches an edge without a fake and resets all process-wide state after every test #1310 requires.- This item confirms the daemon's own process-group kill is gone (refactor(cli): one process runner owns execution, process groups and dry-run #775 consolidates the four copies):
rg -n "os\.killpg" src/devops_cli/k8sprints nothing. - Tests script these tools by argv on the process fake, which also answers
shutil.which. - In
test_k8s_push_secrets.py,FakeClustergives way to the process fake,FakeKeyringto refactor(security): one keyring seam owns the keyring and the Secret Service lock check, with a shared keyring fake and its contract suite #1318's keyring fake, andforbid_requeststo test(cli): the hermetic floor fails a test that reaches an edge without a fake and resets all process-wide state after every test #1310's default deny. - Whichever of this item and test(k8s): devops k8s commands are thin adapters tested over edge fakes, and the _K8sModule patch forwarding is gone #1323 lands second deletes
tests/cluster_secret_fakes.py. By then test(cli): the hermetic floor fails a test that reaches an edge without a fake and resets all process-wide state after every test #1310 has deletedforbid_requests, refactor(security): one keyring seam owns the keyring and the Secret Service lock check, with a shared keyring fake and its contract suite #1318 has movedFakeKeyringtotests/support/fakes/keyring.py, and no test imports from the module.
- Keyring through refactor(security): one keyring seam owns the keyring and the Secret Service lock check, with a shared keyring fake and its contract suite #1318.
credentials.pyno longer imports_keyring_set, and its tests read and write the keyring fake. - Clock through refactor(cli): tests control time: time-machine fakes wall-clock reads, and retry and rate-limit waits return at once and are recorded #1320. Cache expiry and the chaos wait are tested on refactor(cli): tests control time: time-machine fakes wall-clock reads, and retry and rate-limit waits return at once and are recorded #1320's clock; no test sleeps for real or sets
_cache_ttl. - No interim markers. If test(cli): the hermetic floor fails a test that reaches an edge without a fake and resets all process-wide state after every test #1310 added its interim
unreachable(...)marker, none remains in this item's test files: each gives way to the fake of the edge it names, in the fake's refusing state where the test relies on the refusal. - Logic out of commands/ (Q19).
_apply_configured_k8s_contextbecomes a public function ink8s/context.py, tested intests/k8s/.commands/devcontainer.pycalls it.
- The three
_build_pods_tabletests become CLI tests ofdevops k8s podsundertests/commands/k8s/, run against the Kubernetes API fake, so no file of this item imports the renderer. - Behaviour files (Q10).
test_k8s_push_secrets.pyis split by behaviour, for exampletest_cluster_secret_push.pyandtest_cluster_secret_plan.py.- Its tests over committed files, and the overrides test over the committed Applications, are added to the Q13 subject file
tests/invariants/test_k8s_manifests.py, which this item creates if no earlier item has. No second manifest file is added beside it; test(cli): Convert ratchets to bans and merge invariant tests #1336 merges the manifest files test(cli): every test file sits in the directory mirroring the package it tests or in tests/invariants/, and the root conftest holds only the hermetic floor #1313 moved into the same subject file. - No test name ends in
_success,_failure,_basicor_command(Q8).
- Snapshots and assertions.
- Rendered manifests from
k8s/template.pyand the Kustomize patches fromk8s/argocd_overrides.pyare compared as syrupy snapshots (Q18; test(cli): tests find the repository root and fixtures from any depth, import no other test module and build test data with shared builders, and devops test maps a change to its mirror directory #1312 adds syrupy). - Other assertions compare whole values (Q7).
- Rendered manifests from
- The 9 module-level
runner = CliRunner()give way to test(cli): the hermetic floor fails a test that reaches an edge without a fake and resets all process-wide state after every test #1310'sclifixture (Q14). - Every line of
k8s/that no public behaviour reaches is deleted (Q22), and the 90% coverage gate passes. -
uv run devops cipasses.
Key questions
- Which files belong to this item? Decided 2026-10-07: under Q17, each file goes to the package that owns most of what it tests, and test(cli): every test file sits in the directory mirroring the package it tests or in tests/invariants/, and the root conftest holds only the hermetic floor #1313 places it in that package's mirror directory. This item owns exactly the files named above; a file in a shared directory belongs to the one E item that names it.
- Does
test_http_connection_pool.pybelong here? (proposed) Yes: it referencesk8s/more thanhttp/(15 to 8), so test(cli): every test file sits in the directory mirroring the package it tests or in tests/invariants/, and the root conftest holds only the hermetic floor #1313 places it intests/k8s/. Its service-proxy and context-cache tests stay here; its tests ofhttp/pool.pyalone move totests/http/, migrated. - Is this one pull request? Decided 2026-10-07: under Q33, it is filed now as one item, and refinement applies
needs-splitif it proves too big.
Strategic alignment
- Depends on: test(cli): every test file sits in the directory mirroring the package it tests or in tests/invariants/, and the root conftest holds only the hermetic floor #1313, refactor(cli): one process runner owns execution, process groups and dry-run #775, refactor(cli): Unify HTTP and DNS seams with shared fakes #1314, refactor(k8s): KubernetesService is the Kubernetes API seam, with a shared fake cluster and its contract suite #1315, refactor(security): one keyring seam owns the keyring and the Secret Service lock check, with a shared keyring fake and its contract suite #1318, refactor(cli): tests control time: time-machine fakes wall-clock reads, and retry and rate-limit waits return at once and are recorded #1320. Blocks: test(cli): Convert ratchets to bans and merge invariant tests #1336. Related: test(cli): ratchets hold internal patches, private imports and test accommodations in src at today's counts and name each site that would raise one #1309 (the ratchets this item lowers), fix(ai): the durable-run store resolves under the data directory, so tests never write .data/durable_runs.db into the checkout #1036 (the port-forward daemon's cwd-relative state file [code: k8s/port_forward_daemon.py:21]), fix(k8s): argo cd takes homelab values from deploy-time overrides, and the repository holds no private or placeholder config #1290 (added
k8s/argocd_overrides.pyand its tests), test(k8s): devops k8s commands are thin adapters tested over edge fakes, and the _K8sModule patch forwarding is gone #1323 (receives thedevops k8s podsCLI tests), test(ci): devops ci, test, devcontainer, workspace, install-tools, uv, branches and pipeline are tested over edge fakes, with no lazy patch targets or PYTEST_CURRENT_TEST checks #1325 (ownscommands/devcontainer.py), test(telemetry): telemetry, server, ui, output and docs tests run on edge fakes, and the dashboard suite splits by behaviour #1334 (owns theui/data_providers.pyloaders), test(cli): Use edge fakes and real git; drop test rebind hooks #1333 (ownshttp/, whose pool tests leavetest_http_connection_pool.py). - Parent: test(cli): tests double only process edges and mirror the source tree #1307 (phase E).
Proposed design
Problem statement
The 18 test files for the k8s/ package test through internal implementation details. They hold 134 internal patch sites and 24 private imports across 10 files. They must test through the public interface using the shared fakes for Kubernetes API, HTTP, process, keyring and clock.
Acceptance criteria
- Criterion 1: The test files under tests/k8s/ have zero patch sites aimed at devops_cli internals and zero private imports.
Verification: Run an AST pass over tests/k8s/test_*.py and confirm zero patch sites targeting devops_cli and zero _-prefixed imports from devops_cli. - Criterion 2: No module in k8s/ loads a Kubernetes client of its own; service_proxy.py and doctor.py take theirs from refactor(k8s): KubernetesService is the Kubernetes API seam, with a shared fake cluster and its contract suite #1315's seam.
Verification: Run rg -n 'CoreV1Api|load_kube_config|load_incluster' src/devops_cli/k8s/service_proxy.py src/devops_cli/k8s/doctor.py and confirm no direct client construction. - Criterion 3: informer.py and service_proxy.py stop reading the private _core_v1 attribute.
Verification: Run rg -n '_core_v1' src/devops_cli/k8s/ and confirm no match. - Criterion 4: Tests use the promoted FakeCoreV1 and no test patches sys.modules, kubernetes.*, _kube_configuration or _get_k8s_client.
Verification: Run rg -n 'sys.modules|kubernetes.*|_kube_configuration|_get_k8s_client' tests/k8s/ and confirm no match. - Criterion 5: credentials.py and logql.py build no httpx2 client of their own and their tests use the HTTP fake from refactor(cli): Unify HTTP and DNS seams with shared fakes #1314.
Verification: Run rg -n 'httpx2.(get|Client|AsyncClient)' src/devops_cli/k8s/credentials.py src/devops_cli/k8s/logql.py and confirm no inline client construction. - Criterion 6: kubectl, gh and stern run through the process runner from refactor(cli): one process runner owns execution, process groups and dry-run #775; argocd_overrides.py's run parameter is typed by the runner's Protocol.
Verification: Run rg -n 'subprocess.run|run_subprocess|shutil.which' src/devops_cli/k8s/ and confirm all calls go through the process runner. - Criterion 7: The port-forward daemon's own process-group kill is gone.
Verification: Run rg -n 'os.killpg' src/devops_cli/k8s and confirm no output. - Criterion 8: credentials.py no longer imports the private _keyring_set and its tests read and write the keyring fake from refactor(security): one keyring seam owns the keyring and the Secret Service lock check, with a shared keyring fake and its contract suite #1318.
Verification: Run rg -n '_keyring_set' src/devops_cli/k8s/credentials.py and confirm no match. - Criterion 9: Cache expiry and the chaos wait are tested on refactor(cli): tests control time: time-machine fakes wall-clock reads, and retry and rate-limit waits return at once and are recorded #1320's clock; no test sleeps for real or sets _cache_ttl.
Verification: Run rg -n 'time.sleep|_cache_ttl' tests/k8s/ and confirm no match. - Criterion 10: _apply_configured_k8s_context is a public function in k8s/context.py and commands/devcontainer.py calls it.
Verification: Run rg -n 'apply_configured_k8s_context' src/devops_cli/k8s/context.py src/devops_cli/commands/devcontainer.py and confirm both references. - Criterion 11: The three _build_pods_table tests become CLI tests of devops k8s pods under tests/commands/k8s/.
Verification: Run rg -n '_build_pods_table' tests/k8s/ and confirm no match; confirm the tests exist under tests/commands/k8s/. - Criterion 12: test_k8s_push_secrets.py is split by behaviour and its manifest invariants move to tests/invariants/test_k8s_manifests.py.
Verification: Confirm test_k8s_push_secrets.py no longer exists; confirm the new behaviour files and the invariants file exist. - Criterion 13: No test name ends in _success, _failure, basic or command.
Verification: Run rg -n 'def test.*(success|failure|basic|command)\b' tests/k8s/ and confirm no match. - Criterion 14: Rendered manifests and Kustomize patches are compared as syrupy snapshots.
Verification: Confirm snapshot files exist under tests/snapshots/ for the template and argocd_overrides tests. - Criterion 15: The 9 module-level runner = CliRunner() instances give way to test(cli): the hermetic floor fails a test that reaches an edge without a fake and resets all process-wide state after every test #1310's cli fixture.
Verification: Run rg -n 'runner = CliRunner()' tests/k8s/ and confirm no match. - Criterion 16: Every line of k8s/ that no public behaviour reaches is deleted and the 90% coverage gate passes.
Verification: Run uv run devops ci and confirm the coverage gate passes at 90%.
Key questions
- Which files belong to this item?: The 18 files named in the body, placed under tests/k8s/ by test(cli): every test file sits in the directory mirroring the package it tests or in tests/invariants/, and the root conftest holds only the hermetic floor #1313. (proposed)
- Does test_http_connection_pool.py belong here?: Yes. It references k8s/ more than http/ (15 to 8), so test(cli): every test file sits in the directory mirroring the package it tests or in tests/invariants/, and the root conftest holds only the hermetic floor #1313 places it in tests/k8s/. (proposed)
- Is this one pull request?: No. The change touches 18 test files across 6 integration seams and includes file splits and code moves. It splits into multiple items. (proposed)
Fit
Needs splitting into 8 items:
- Kubernetes API: route service_proxy.py and doctor.py through refactor(k8s): KubernetesService is the Kubernetes API seam, with a shared fake cluster and its contract suite #1315's seam, stop reading _core_v1, use promoted FakeCoreV1, remove sys.modules and kubernetes.* patches
- HTTP: route credentials.py and logql.py through refactor(cli): Unify HTTP and DNS seams with shared fakes #1314's seam, use the HTTP fake in their tests
- Processes: route kubectl, gh and stern through refactor(cli): one process runner owns execution, process groups and dry-run #775's process runner, type argocd_overrides.py's run parameter, confirm the daemon's process-group kill is gone
- Keyring: remove the _keyring_set import from credentials.py, use refactor(security): one keyring seam owns the keyring and the Secret Service lock check, with a shared keyring fake and its contract suite #1318's keyring fake in tests
- Clock: test cache expiry and the chaos wait on refactor(cli): tests control time: time-machine fakes wall-clock reads, and retry and rate-limit waits return at once and are recorded #1320's clock, remove real sleeps and _cache_ttl patches
- Logic move: make _apply_configured_k8s_context public in k8s/context.py, move _build_pods_table tests to CLI tests under tests/commands/k8s/
- Behaviour splits: split test_k8s_push_secrets.py by behaviour, move manifest invariants to tests/invariants/test_k8s_manifests.py, rename _success/_failure tests
- Cleanup: add syrupy snapshots, compare whole values, replace CliRunner with the cli fixture, delete dead code, pass the 90% coverage gate
Suspected block
None.
Dependencies
Alternatives check of 2026-10-29: not-applicable.
Tool: none found.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsNew
- StatusShow more project fieldsNew
Activity
dan-petty-bot commentedon Oct 8, 2026
Intake placed this item to the backlog: at intake only a critical fix goes into a release; a release start pulls Ready items in, P0 features first.
It improves long-term test maintainability and reduces brittleness but does not fix a user-facing defect.Removing 134 internal patch sites and 24 private imports makes the k8s/ suite far easier to maintain and less fragile to refactors.18 test files, 6 752 lines, 352 tests, 134 patch sites and 24 private imports must be reworked across HTTP, process, keyring and clock seams.3 remaining items
refactor(k8s): KubernetesService is the Kubernetes API seam, with a s…
devops-cli-service commentedon Oct 30, 2026
Alternatives check: not-applicable
Tool: none found
Checked on 2026-10-29. A person decides what this means for the item. The check changes no label and closes no issue.
test(k8s): test k8s/ through public interface over edge fakes (#1322)
test(k8s): test k8s/ through public interface over edge fakes (#1322)
test(k8s): test k8s/ through public interface over edge fakes (#1322)
test(k8s): test k8s/ through public interface over edge fakes (#1322)