Skip to content

feat(coverage): static test-coverage estimate for last9-otel-setup.sh#24

Open
prathamesh-sonpatki wants to merge 4 commits into
mainfrom
prathamesh/fde-209-kcov-integration-coverage
Open

feat(coverage): static test-coverage estimate for last9-otel-setup.sh#24
prathamesh-sonpatki wants to merge 4 commits into
mainfrom
prathamesh/fde-209-kcov-integration-coverage

Conversation

@prathamesh-sonpatki

Copy link
Copy Markdown
Member

What

Adds a real, repeatable test-coverage estimate for last9-otel-setup.sh (the 2945-line, 50-function central script), surfaced locally and in CI.

Closes FDE-209.

Why not kcov

The original plan was kcov runtime line coverage. Proven unworkable during implementation:

  • kcov bash coverage = 0% on macOS (Linux-only ptrace feature)
  • kcov was dropped from ubuntu-24.04 repos (= GitHub ubuntu-latest)
  • even on ubuntu-22.04 under ptrace, kcov reports 0 lines — its bash instrumentation does not follow the grandchild bash "$SCRIPT" the test suites spawn

What shipped instead — static call-graph coverage

  • tests/coverage-report.py — builds the function call graph (command-position matching; strings/comments stripped so names inside echo/log text aren't counted as calls), seeds from what the tests actually drive (always-run prelude + install/monitoring/events handlers exercised by the layer-2 e2e modes + every function named in the test files), takes the transitive closure. main is counted as executed but not traversed, so its untested uninstall and help/examples branches aren't wrongly credited.
  • tests/test_coverage_report.py — 10 guard tests for the model.
  • run.sh coverage — local entrypoint (--min N for an optional gate).
  • integration.yml — report-only coverage job writing the % + untested list to the job summary.

Result

84% of functions / 78% of lines (42/50). Untested: the four uninstall paths (303 lines), tolerations-on-monitoring, operator detection, deployment-mode switch, and the no-arg examples screen.

Verification

analyzer self-tests 10/10 · bats 38/38 · python adopt tests pass · no regressions.

🤖 Generated with Claude Code

prathamesh-sonpatki and others added 4 commits June 1, 2026 13:47
…p.sh

Runtime line coverage (kcov) is unusable here: kcov's bash instrumentation is
Linux-only and does not propagate to the grandchild `bash "$SCRIPT"` processes
the test suites spawn (confirmed 0 lines even on ubuntu under ptrace; kcov was
also dropped from ubuntu-24.04 repos). Instead, estimate coverage statically.

tests/coverage-report.py builds the script's function call graph (command-
position matching, with strings and comments stripped so names inside echo/log
text are not counted as calls), seeds it with the functions the test suites
actually drive — the always-run prelude, the install/monitoring/events handlers
exercised by the layer-2 e2e modes, and every function named in the test files —
takes the transitive closure, and reports function-level and line-weighted
coverage plus the untested list. main() is counted as executed but not traversed,
so its untested uninstall and help/examples branches are not wrongly credited.

Current estimate: 84% of functions, 78% of lines. Untested: the four uninstall
paths, tolerations-on-monitoring, operator detection, deployment-mode switch,
and the no-arg examples screen.

- run.sh gains a `coverage` entrypoint (`--min N` available for an optional gate)
- integration.yml gains a report-only `coverage` job that writes the % and the
  untested list to the GitHub job summary
- tests/test_coverage_report.py guards the call-graph model

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…ines

Adds characterization tests for every function the coverage analyzer flagged
untested, raising last9-otel-setup.sh coverage from 84%/78% to 100%/100%.

- tests/integration/uninstall.bats: drives all four uninstall paths
  (uninstall_opentelemetry/_all/_last9_monitoring/_events_agent) through the
  entry point with stubbed helm/kubectl/sleep; `yes | tr -d '\n'` answers the
  interactive y/N prompts. Covers the real uninstall branch, the cancel branch,
  and the not-installed branch.
- tests/unit.bats: update_deployment_mode (daemonset→deployment, logsCollection
  off, filelog commented + missing-file error), apply_tolerations_to_monitoring_values
  (awk/sed fallback so no yq needed in CI, incl. default node-exporter tolerations),
  detect_existing_prometheus_operator (found/not-found/own-namespace), show_examples.
- helm stub: SIMULATE_INSTALLED makes `helm list` report releases so uninstall
  takes the real path; new no-op sleep stub keeps uninstall tests fast.
- coverage-report.py: count uninstall.bats; fix the call-graph matcher to treat
  `if/elif/while/until <fn>` as a call (it missed `if detect_existing_prometheus_operator`).

Analyzer now surfaces two genuinely dead functions (defined, no caller anywhere
in the script): apply_tolerations_to_monitoring_values and detect_host_platform.
The CI summary now lists both untested and dead-code functions.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Main added tests/test_install_operator.py and new script functions; include the
new test file so its coverage is credited. last9-otel-setup.sh stays at
100% function / 100% line coverage (now 2772 lines, 22 directly-tested);
apply_tolerations_to_monitoring_values and detect_host_platform remain dead.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant