mirror of
https://github.com/alibaba/open-code-review.git
synced 2026-08-19 21:54:20 +00:00
* test: raise statement coverage to 90% and enforce it in CI Add unit tests across the cmd and internal packages to bring total statement coverage above 90%, and gate future regressions. - Cover CLI helpers, provider TUI handlers, resume/manifest paths, and error branches in config, llm, llmloop, scan, session, agent, viewer, mcp, pathutil, and telemetry. - Raise the coverage threshold from 80% to 90% in the Makefile (COVERAGE_THRESHOLD) and in the CI "Check coverage threshold" step. - Ignore generated coverage.out and coverage.html artifacts. Total statement coverage is now 90.5%, measured consistently by both `make coverage` and the CI `go test ./...` scope. * test: widen statement coverage margin with environment-independent unit tests Add table-driven unit tests for pure, environment-independent functions to raise the statement-coverage safety margin above the 90% threshold: - session.ResumeState.ValidateScanOptions (70% -> 100%) - rules.SystemRule.UnmarshalJSON error branches (71% -> 82%) - llmloop.stripMarkdownFences no-newline branch (82% -> 100%) - diff.firstLine empty/blank-input branch - diff.extractCodeBlock missing-newline and no-closing-fence branches - main.truncate n<=1 and normalization branches - agent.Agent nil-receiver accessor guards
43 lines
1.2 KiB
Go
43 lines
1.2 KiB
Go
// SPDX-License-Identifier: Apache-2.0
|
|
// Copyright 2026 alibaba/open-code-review Contributors
|
|
|
|
package main
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
// TestCompleteSessionIDs_WithSession drives the success loop of the shell
|
|
// completion helper against a real fixture session, covering the prefix-match
|
|
// and no-match branches that the fresh-repo test cannot reach.
|
|
func TestCompleteSessionIDs_WithSession(t *testing.T) {
|
|
newCmd := func(repo string) *cobra.Command {
|
|
c := &cobra.Command{}
|
|
c.Flags().String("repo", repo, "")
|
|
return c
|
|
}
|
|
|
|
t.Run("lists matching session IDs", func(t *testing.T) {
|
|
t.Setenv("HOME", t.TempDir())
|
|
repoDir := t.TempDir()
|
|
id := writeRangeResumeSession(t, repoDir, "a.go")
|
|
|
|
got, _ := completeSessionIDs(newCmd(repoDir), nil, id[:4])
|
|
if len(got) == 0 {
|
|
t.Fatalf("expected a completion for session %s, got none", id)
|
|
}
|
|
})
|
|
|
|
t.Run("prefix that matches nothing yields empty list", func(t *testing.T) {
|
|
t.Setenv("HOME", t.TempDir())
|
|
repoDir := t.TempDir()
|
|
writeRangeResumeSession(t, repoDir, "a.go")
|
|
|
|
got, _ := completeSessionIDs(newCmd(repoDir), nil, "zzzz-no-match")
|
|
if len(got) != 0 {
|
|
t.Errorf("got %v, want empty", got)
|
|
}
|
|
})
|
|
}
|