Skip to content

test: raise coverage on teslasync CLI, backup, schema, chaos-runner - #122

Closed
atulmgupta wants to merge 1 commit into
mainfrom
add-tests
Closed

atulmgupta wants to merge 1 commit into
mainfrom
add-tests

Conversation

@atulmgupta

Copy link
Copy Markdown
Contributor

What

Adds high-value unit tests for previously thin Go packages and a chaos-runner recovery-probe fix.

Coverage deltas (package-level, local)

  • cmd/teslasync: 0% → 50% (drain, healthcheck, logger, subcommands)
  • internal/backup: 1.3% → 39.5% (local storage round-trip, restore/gzip, provider init)
  • internal/schemacheck: 1.5% → 100% (Compute fingerprint + exclude + error paths)
  • internal/backupverify: 20.9% → 100% (VerifyLatest success and invariant failures)
  • internal/audit: extra redactor/category/nil-receiver coverage
  • cmd/chaos-runner: recovery probe keeps last concrete failure (e.g. HTTP 503) instead of overwriting with deadline; fleet/battery recovery tests

Not yet 90% repo-wide

CI backend total was ~56.5% with 331 packages below 90%. This PR is the first slice of that work, not the finish line. Remaining gaps are mostly DB-backed handlers/repos and main() wiring.

How to test

  • go test ./cmd/teslasync ./internal/backup ./internal/schemacheck ./internal/backupverify ./internal/audit ./cmd/chaos-runner -count=1
  • Local docker compose build succeeded.

Notes

Local Docker used WEB_PORT=3119.

Add high-value unit tests for previously thin packages: teslasync drain/healthcheck, local backup storage + restore, schema fingerprint Compute, backupverify VerifyLatest, audit recorder helpers, and chaos-runner recovery probes. Preserve the last concrete recovery failure instead of overwriting it with a later deadline.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 5b104204-65b7-4d04-90a4-e2d5897b8e2e
Copilot AI lite review requested due to automatic review settings September 18, 2026 20:02

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Several new tests depend on fixed host ports or call t.Fatalf from HTTP handler goroutines, and schema iterator-error paths remain untested.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Adds targeted Go test coverage across CLI, backup, schema, audit, and chaos-runner packages, plus improves recovery-probe error reporting.

Changes:

  • Adds storage, restore, verification, schema, audit, and CLI tests.
  • Preserves concrete recovery failures when retry deadlines are reached.
  • Adds fleet-state and battery recovery-probe tests.

Verification was not run in this review environment.

File summaries
File Description
internal/schemacheck/compute_test.go Fingerprint, exclusion, scan, and query-error tests
internal/backupverify/verify_latest_test.go Backup verification success and failure cases
internal/backup/storage_test.go Provider, storage, checksum, gzip, and allowlist tests
internal/audit/recorder_more_test.go Additional recorder and redaction coverage
cmd/teslasync/main_test.go Logger, healthcheck, drain, and subcommand tests
cmd/chaos-runner/main.go Retains concrete recovery failures
cmd/chaos-runner/main_test.go Recovery and fleet/battery probe tests
Review details

Suppressed comments (1)

cmd/chaos-runner/main_test.go:433

  • This path assertion is also executed in the httptest server goroutine, so t.Fatalf can stop only that goroutine instead of the test. Report the mismatch without FailNow, or move the assertion after the request returns.
			t.Fatalf("path=%s", r.URL.Path)
  • Files reviewed: 7/7 changed files
  • Comments generated: 4
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

t.Parallel()
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/api/v1/vehicles/states" {
t.Fatalf("path=%s", r.URL.Path)
t.Setenv("TESLASYNC_PORT", "")
// Exercise the empty-env branch. A local docker stack may already
// be serving :8080, so either 0 or 1 is acceptable.
_ = healthcheck()

func TestDrain_DefaultPortWhenUnset(t *testing.T) {
t.Setenv("TESLASYNC_DRAIN_PORT", "")
if code := drain(); code != 1 {
Comment on lines +156 to +176
func TestCompute_ScanAndIterErrors(t *testing.T) {
t.Parallel()
if _, err := Compute(context.Background(), &scriptedQuerier{
tables: &fakeRows{data: [][]any{{"vehicles"}}, scanErr: errors.New("scan tables")},
}, nil); err == nil {
t.Fatal("want table scan error")
}
if _, err := Compute(context.Background(), &scriptedQuerier{
tables: &fakeRows{data: [][]any{{"vehicles"}}},
columns: &fakeRows{data: [][]any{{"vehicles", "id", "bigint", "NO"}}, scanErr: errors.New("scan cols")},
}, nil); err == nil {
t.Fatal("want column scan error")
}
if _, err := Compute(context.Background(), &scriptedQuerier{
tables: &fakeRows{data: [][]any{{"vehicles"}}},
columns: &fakeRows{data: [][]any{{"vehicles", "id", "bigint", "NO"}}},
indexes: &fakeRows{data: [][]any{{"vehicles", "idx", "CREATE INDEX"}}, scanErr: errors.New("scan idx")},
}, nil); err == nil {
t.Fatal("want index scan error")
}
}

Copilot AI commented Sep 18, 2026

Copy link
Copy Markdown

One or more custom setup steps configured for this repository failed during this Copilot code review run:

Verify TypeScript build

Setup steps run before each review. If the review above is missing context, or no review was posted at all, the failing step above may be the cause. See the workflow run for failure details, fix your setup steps configuration, and re-request a review.

Note

You can configure setup steps for Copilot code review separately from Copilot cloud agent with a copilot-code-review.yml file. Read the docs for details.

@atulmgupta

Copy link
Copy Markdown
Contributor Author

Superseded by #130, which consolidated this PR and has now been merged.

@atulmgupta atulmgupta closed this Sep 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants