test(knowledge): unbreak service test package after tag-loading change
Fixing the knowledge_create_test compile error in this branch let the internal/application/service test package run for the first time, which exposed two latent failures introduced when GetKnowledgeByID started eagerly loading tags: - GetOwningKBCreatorID went through the service-level GetKnowledgeByID (which now calls repo.GetKnowledgeTags); ownership resolution only needs the knowledge -> kb_id link, so resolve via repo.GetKnowledgeByID directly (tenant-scoped) and drop the extra tag query. - createKnowledgeFileRepoStub lacked GetKnowledgeTags, which the create path always invokes via setAndAttachKnowledgeTags; add the stub method.
This commit is contained in:
@@ -489,7 +489,15 @@ func (s *knowledgeService) GetKnowledgeByIDOnly(ctx context.Context, id string)
|
||||
// KB row itself is not returned so callers can't accidentally widen
|
||||
// their scope past "needed the creator id".
|
||||
func (s *knowledgeService) GetOwningKBCreatorID(ctx context.Context, knowledgeID string) (string, error) {
|
||||
knowledge, err := s.GetKnowledgeByID(ctx, knowledgeID)
|
||||
// Resolve via the repository directly: ownership only needs the
|
||||
// knowledge -> kb_id link, so we deliberately skip the service-level
|
||||
// GetKnowledgeByID (which also eagerly loads tags) to keep this lookup
|
||||
// minimal and tenant-scoped.
|
||||
tenantID, ok := ctx.Value(types.TenantIDContextKey).(uint64)
|
||||
if !ok {
|
||||
return "", werrors.NewUnauthorizedError("Tenant ID not found in context")
|
||||
}
|
||||
knowledge, err := s.repo.GetKnowledgeByID(ctx, tenantID, knowledgeID)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
@@ -39,6 +39,15 @@ func (r *createKnowledgeFileRepoStub) CreateKnowledge(ctx context.Context, knowl
|
||||
return r.createErr
|
||||
}
|
||||
|
||||
// GetKnowledgeTags is invoked by setAndAttachKnowledgeTags after create even
|
||||
// when no tags were supplied; a fresh knowledge has none, so return empty.
|
||||
func (r *createKnowledgeFileRepoStub) GetKnowledgeTags(
|
||||
ctx context.Context,
|
||||
knowledgeIDs []string,
|
||||
) (map[string][]*types.KnowledgeTag, error) {
|
||||
return map[string][]*types.KnowledgeTag{}, nil
|
||||
}
|
||||
|
||||
type createKnowledgeFileKBServiceStub struct {
|
||||
interfaces.KnowledgeBaseService
|
||||
|
||||
|
||||
Reference in New Issue
Block a user