feat(image): define provider-neutral image capability contract and config
Adds internal/domain/image (Provider/Registry per the plugin engine family shape, but no Lifecycle -- a provider is call-scoped, not long-running) and config.ImageConfig with the same explicit enabled=true cost gate MinimaxConfig already uses, since a hosted provider spends real API credits and a local one can saturate the host GPU. Design doc at docs/prds/image-capability-contract.md per CLAUDE.md's rule for undesigned capabilities. No provider implementation lands here -- that's the epic's next child bead. Also re-links all 7 epic children that were unlinked from archie-core-1786748942120-1-6636e629 (same orphaning pattern found in the curator/memory epics earlier this session).
This commit is contained in:
1 parent
622961a875
commit
75158b7fc7
10 files changed
+915
-38
No files matched your search
@@ -87,9 +87,49 @@ func validate(cfg *config.Config) error {
|
||||
if err := validateMemory(cfg); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := validateImage(cfg); err != nil {
|
||||
return err
|
||||
}
|
||||
return validateCapture(cfg)
|
||||
}
|
||||
|
||||
// validateImage rejects an enabled hosted provider with no class or no
|
||||
// resolvable credential, and a Default naming a provider that is not both
|
||||
// present and enabled -- either would let /image silently fall back to
|
||||
// "always ask" (harmless) or fail at call time with a confusing error
|
||||
// (not harmless). An absent [image] section is valid and registers no
|
||||
// provider, matching the epic's non-goal that a paid provider must never
|
||||
// activate by omission.
|
||||
func validateImage(cfg *config.Config) error {
|
||||
for name, p := range cfg.Image.Hosted {
|
||||
if !p.Enabled {
|
||||
continue
|
||||
}
|
||||
if p.Class == "" {
|
||||
return fmt.Errorf("%w: image.hosted.%s.class is required when enabled", ErrInvalidInput, name)
|
||||
}
|
||||
if p.APIKeyEnv == "" && p.APIKey == (secret.SecretRef{}) {
|
||||
return fmt.Errorf("%w: image.hosted.%s requires api_key_env or api_key when enabled", ErrInvalidInput, name)
|
||||
}
|
||||
}
|
||||
for name, p := range cfg.Image.Local {
|
||||
if p.Enabled && p.Backend == "" {
|
||||
return fmt.Errorf("%w: image.local.%s.backend is required when enabled", ErrInvalidInput, name)
|
||||
}
|
||||
}
|
||||
if cfg.Image.Default != "" {
|
||||
hosted, hostedOK := cfg.Image.Hosted[cfg.Image.Default]
|
||||
local, localOK := cfg.Image.Local[cfg.Image.Default]
|
||||
switch {
|
||||
case hostedOK && hosted.Enabled, localOK && local.Enabled:
|
||||
// found and enabled
|
||||
default:
|
||||
return fmt.Errorf("%w: image.default %q must name an enabled provider under image.hosted or image.local", ErrInvalidInput, cfg.Image.Default)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// validateMemory rejects an engine name outside memoryEngines. Empty is
|
||||
// valid input to Validate (applyDefaults resolves it to memoryEngineBuiltin
|
||||
// before this runs on the real load path); it is not "unknown" so it does
|
||||
|
||||
@@ -380,3 +380,104 @@ func TestValidateMemoryRejectsProviderSetToAnything(t *testing.T) {
|
||||
t.Errorf("error text = %q, want it to name the field and the value", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateImageAcceptsAbsentSection(t *testing.T) {
|
||||
cfg := minimalValidConfig()
|
||||
if err := validateImage(&cfg); err != nil {
|
||||
t.Fatalf("validateImage(absent) = %v, want nil", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateImageRejectsEnabledHostedWithoutClass(t *testing.T) {
|
||||
cfg := minimalValidConfig()
|
||||
cfg.Image.Hosted = map[string]config.ImageHostedProvider{
|
||||
"openai": {Enabled: true, APIKeyEnv: "OPENAI_API_KEY"},
|
||||
}
|
||||
err := validateImage(&cfg)
|
||||
if !errors.Is(err, ErrInvalidInput) {
|
||||
t.Fatalf("validateImage(no class) = %v, want wrapping ErrInvalidInput", err)
|
||||
}
|
||||
if !strings.Contains(err.Error(), "image.hosted.openai.class") {
|
||||
t.Errorf("error text = %q, want it to name the field", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateImageRejectsEnabledHostedWithoutCredential(t *testing.T) {
|
||||
cfg := minimalValidConfig()
|
||||
cfg.Image.Hosted = map[string]config.ImageHostedProvider{
|
||||
"openai": {Enabled: true, Class: "openai"},
|
||||
}
|
||||
err := validateImage(&cfg)
|
||||
if !errors.Is(err, ErrInvalidInput) {
|
||||
t.Fatalf("validateImage(no credential) = %v, want wrapping ErrInvalidInput", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateImageAcceptsDisabledHostedWithoutCredential(t *testing.T) {
|
||||
cfg := minimalValidConfig()
|
||||
cfg.Image.Hosted = map[string]config.ImageHostedProvider{
|
||||
"openai": {Enabled: false},
|
||||
}
|
||||
if err := validateImage(&cfg); err != nil {
|
||||
t.Fatalf("validateImage(disabled) = %v, want nil", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateImageAcceptsEnabledHostedWithCredential(t *testing.T) {
|
||||
cfg := minimalValidConfig()
|
||||
cfg.Image.Hosted = map[string]config.ImageHostedProvider{
|
||||
"openai": {Enabled: true, Class: "openai", APIKeyEnv: "OPENAI_API_KEY"},
|
||||
}
|
||||
if err := validateImage(&cfg); err != nil {
|
||||
t.Fatalf("validateImage(valid hosted) = %v, want nil", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateImageRejectsEnabledLocalWithoutBackend(t *testing.T) {
|
||||
cfg := minimalValidConfig()
|
||||
cfg.Image.Local = map[string]config.ImageLocalProvider{
|
||||
"sdxl": {Enabled: true},
|
||||
}
|
||||
err := validateImage(&cfg)
|
||||
if !errors.Is(err, ErrInvalidInput) {
|
||||
t.Fatalf("validateImage(no backend) = %v, want wrapping ErrInvalidInput", err)
|
||||
}
|
||||
if !strings.Contains(err.Error(), "image.local.sdxl.backend") {
|
||||
t.Errorf("error text = %q, want it to name the field", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateImageRejectsDefaultNamingDisabledProvider(t *testing.T) {
|
||||
cfg := minimalValidConfig()
|
||||
cfg.Image.Default = "openai"
|
||||
cfg.Image.Hosted = map[string]config.ImageHostedProvider{
|
||||
"openai": {Enabled: false},
|
||||
}
|
||||
err := validateImage(&cfg)
|
||||
if !errors.Is(err, ErrInvalidInput) {
|
||||
t.Fatalf("validateImage(default names disabled) = %v, want wrapping ErrInvalidInput", err)
|
||||
}
|
||||
if !strings.Contains(err.Error(), `image.default "openai"`) {
|
||||
t.Errorf("error text = %q, want it to name the field and value", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateImageRejectsDefaultNamingUnregisteredProvider(t *testing.T) {
|
||||
cfg := minimalValidConfig()
|
||||
cfg.Image.Default = "missing"
|
||||
err := validateImage(&cfg)
|
||||
if !errors.Is(err, ErrInvalidInput) {
|
||||
t.Fatalf("validateImage(default names unregistered) = %v, want wrapping ErrInvalidInput", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateImageAcceptsDefaultNamingEnabledLocalProvider(t *testing.T) {
|
||||
cfg := minimalValidConfig()
|
||||
cfg.Image.Default = "sdxl"
|
||||
cfg.Image.Local = map[string]config.ImageLocalProvider{
|
||||
"sdxl": {Enabled: true, Backend: "sdxl-turbo"},
|
||||
}
|
||||
if err := validateImage(&cfg); err != nil {
|
||||
t.Fatalf("validateImage(default names enabled local) = %v, want nil", err)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user