Enhance knowledge base configuration by normalizing and validating custom instruction fields. Implemented length checks for prompt instructions and added tests for validation logic. Updated GraphSettings to retain custom instructions when extraction is disabled.

This commit is contained in:
wizardchen
2026-07-13 12:14:36 +08:00
committed by lyingbug
parent c1cddb4d4d
commit 5eefa70e6f
9 changed files with 158 additions and 35 deletions
@@ -2,6 +2,7 @@ package service
import (
"context"
"strings"
"testing"
werrors "github.com/Tencent/WeKnora/internal/errors"
@@ -227,6 +228,21 @@ func TestResolveProcessConfig_PreservesKnowledgeBasePromptInstructions(t *testin
require.Equal(t, "contract entities", eff.ExtractConfig.CustomInstructions)
}
func TestValidateProcessOverrides_RejectsOversizedInstructions(t *testing.T) {
t.Parallel()
kb := &types.KnowledgeBase{}
overrides := &types.KnowledgeProcessOverrides{
VLMConfig: &types.VLMConfig{
CustomInstructions: strings.Repeat("x", types.MaxCustomPromptInstructionsLength+1),
},
}
err := ValidateProcessOverrides(context.Background(), kb, overrides, []string{"txt"})
require.Error(t, err)
var badReq *werrors.AppError
require.ErrorAs(t, err, &badReq)
}
func TestValidateProcessOverrides_NilOverrides(t *testing.T) {
t.Parallel()