fix: complete target diagnostics and reset inspection

This commit is contained in:
proxyctl coordinator
2026-07-17 10:29:41 +08:00
parent f6c6ead325
commit 0fbaa71e37
14 changed files with 366 additions and 10 deletions
+28
View File
@@ -82,6 +82,8 @@ type Adapter struct {
runner Runner
}
var _ target.Diagnosable = (*Adapter)(nil)
func New(configuration Configuration, files FileSystem, runner Runner) *Adapter {
defaults := DefaultConfiguration()
if configuration.DebianVersionFile == "" {
@@ -116,6 +118,32 @@ func (a *Adapter) Description() target.Description {
func (a *Adapter) Confirmation(bool) string { return "" }
// DiagnosticChecks observes the APT command, configuration schema, and current
// filesystem authority without changing the overlay or effective settings.
func (a *Adapter) DiagnosticChecks(ctx context.Context, _ *profile.Profile) []target.Check {
commandCheck := target.Check{Name: "required command", OK: true, Evidence: "apt-config is available"}
command, err := a.runner.LookPath("apt-config")
if err != nil {
commandCheck.OK = false
commandCheck.Evidence = "apt-config is unavailable: " + profile.RedactText(err.Error())
} else if _, err := a.runner.Output(ctx, command, "dump"); err != nil {
commandCheck.OK = false
commandCheck.Evidence = "apt-config dump failed: " + profile.RedactText(err.Error())
}
marker, markerErr := os.Stat(a.configuration.DebianVersionFile)
directory, directoryErr := os.Stat(a.configuration.ConfigDirectory)
schemaOK := markerErr == nil && marker.Mode().IsRegular() && directoryErr == nil && directory.IsDir()
schemaEvidence := "Debian marker and apt.conf.d configuration directory are present"
if !schemaOK {
schemaEvidence = profile.RedactText(fmt.Sprintf("Debian marker or apt.conf.d configuration directory is unusable: marker=%v directory=%v", markerErr, directoryErr))
}
return []target.Check{
commandCheck,
{Name: "configuration schema", OK: schemaOK, Evidence: schemaEvidence},
target.ReadOnlyWriteAuthority(a.configuration.OverlayFile),
}
}
func (a *Adapter) Availability(ctx context.Context) target.Availability {
marker, err := os.Stat(a.configuration.DebianVersionFile)
if err != nil || !marker.Mode().IsRegular() {