92d78dea72
text/ gh-style display-width string helpers (Truncate / FuzzyAgo / Pluralize)
compat/ server-CLI version skew probe (kubectl) + 24h TTL cache (gh internal/update)
acceptance/contract/ helpers_test.go for in-process cobra exec + golden assert
(uses iostreams.SetForTest singleton replacement; no t.Parallel)
cmdutil/errors.go: AllCodes() + ClassifyHTTPErrorOutputs() bridge for the
contract test suite (no behavior change in error handling)
go-runewidth promoted from indirect to direct (used by text.Truncate for
display-width-aware CJK truncation).
acceptance/contract/helpers_test.go forward-references cmd.NewRootCmd which
is exported in PR-7 — that file does not compile until then by design.
41 lines
1.2 KiB
Go
41 lines
1.2 KiB
Go
// Package compat probes server `/system/info` and decides client-server
|
|
// version skew level. Used by `weknora doctor` 的 server_version 检查项。
|
|
//
|
|
// Mirrors gh internal/update/update.go cache pattern (24h TTL state file)
|
|
// and kubectl pkg/version/skew_warning.go three-tier compat semantics
|
|
// (major-mismatch=hard / minor-mismatch=soft / equal=ok).
|
|
package compat
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"time"
|
|
|
|
sdk "github.com/Tencent/WeKnora/client"
|
|
)
|
|
|
|
// Info is the cached server version snapshot.
|
|
type Info struct {
|
|
ServerVersion string `yaml:"server_version"`
|
|
EngineInfo map[string]string `yaml:"engine_info,omitempty"`
|
|
ProbedAt time.Time `yaml:"probed_at"`
|
|
}
|
|
|
|
// ProbeService is the narrow SDK surface compat depends on (testability via
|
|
// fake; mirrors v0.0 service interface pattern).
|
|
type ProbeService interface {
|
|
GetSystemInfo(ctx context.Context) (*sdk.SystemInfo, error)
|
|
}
|
|
|
|
// Probe calls server /system/info and returns a fresh Info snapshot.
|
|
func Probe(ctx context.Context, c ProbeService) (*Info, error) {
|
|
resp, err := c.GetSystemInfo(ctx)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("probe server: %w", err)
|
|
}
|
|
return &Info{
|
|
ServerVersion: resp.Version,
|
|
ProbedAt: time.Now(),
|
|
}, nil
|
|
}
|