57 lines
1.9 KiB
Go
57 lines
1.9 KiB
Go
|
|
package bootstrap
|
||
|
|
|
||
|
|
import (
|
||
|
|
"context"
|
||
|
|
"fmt"
|
||
|
|
|
||
|
|
fwcli "forge.lclr.dev/AI/mcp-framework/cli"
|
||
|
|
"forge.lclr.dev/AI/mcp-framework/secretstore"
|
||
|
|
)
|
||
|
|
|
||
|
|
// StandardConfigTestOptions configure le handler de config test standard.
|
||
|
|
// Aucun champ n'est obligatoire — omettez ceux qui ne s'appliquent pas à l'application.
|
||
|
|
type StandardConfigTestOptions struct {
|
||
|
|
// ConfigCheck vérifie que le fichier de configuration est lisible.
|
||
|
|
// Construire avec cli.NewConfigCheck(store).
|
||
|
|
ConfigCheck fwcli.DoctorCheck
|
||
|
|
|
||
|
|
// OpenStore ouvre le secret store pour vérifier sa disponibilité.
|
||
|
|
// Si fourni, un SecretStoreAvailabilityCheck est automatiquement inclus.
|
||
|
|
OpenStore func() (secretstore.Store, error)
|
||
|
|
|
||
|
|
// ConnectivityCheck vérifie la connectivité applicative (IMAP, HTTP, etc.).
|
||
|
|
ConnectivityCheck fwcli.DoctorCheck
|
||
|
|
|
||
|
|
// ExtraChecks contient des vérifications supplémentaires spécifiques à l'application.
|
||
|
|
ExtraChecks []fwcli.DoctorCheck
|
||
|
|
}
|
||
|
|
|
||
|
|
// StandardConfigTestHandler retourne un Handler pour la commande config test.
|
||
|
|
// Il inclut : config (si fourni), secret store (si fourni), connectivité (si fournie),
|
||
|
|
// checks supplémentaires. Le ManifestCheck est intentionnellement absent : le manifest
|
||
|
|
// est un artefact de build, pas une contrainte runtime.
|
||
|
|
func StandardConfigTestHandler(opts StandardConfigTestOptions) Handler {
|
||
|
|
return func(ctx context.Context, inv Invocation) error {
|
||
|
|
doctorOpts := fwcli.DoctorOptions{
|
||
|
|
ConfigCheck: opts.ConfigCheck,
|
||
|
|
ConnectivityCheck: opts.ConnectivityCheck,
|
||
|
|
ExtraChecks: opts.ExtraChecks,
|
||
|
|
}
|
||
|
|
|
||
|
|
if opts.OpenStore != nil {
|
||
|
|
doctorOpts.SecretStoreCheck = fwcli.SecretStoreAvailabilityCheck(opts.OpenStore)
|
||
|
|
}
|
||
|
|
|
||
|
|
report := fwcli.RunDoctor(ctx, doctorOpts)
|
||
|
|
|
||
|
|
if err := fwcli.RenderDoctorReport(inv.Stdout, report); err != nil {
|
||
|
|
return err
|
||
|
|
}
|
||
|
|
|
||
|
|
if report.HasFailures() {
|
||
|
|
return fmt.Errorf("config checks failed")
|
||
|
|
}
|
||
|
|
return nil
|
||
|
|
}
|
||
|
|
}
|