Drop link self-healing paths, fix linter findings

- Remove link resync on module reconnect, link resave on no-op config
  update, and link backfill on variable create/upsert: links are
  formed only on config save
- Disable exhaustruct_v5 and goconst linters
- Fix golangci-lint findings: noinlineerr, slices.Backward,
  wrapcheck for ConfigValidationError (errors.As in controller keeps
  working via %w), funlen nolint on acceptance test
This commit is contained in:
Hermes Agent committed 2026-10-28 11:22:59 +03:00
1 parent 7f4e3ef028
commit c464393e93
9 files changed
+9 -114

No files matched your search

+2 -7
View File
@@ -152,11 +152,6 @@ func (c Config) CreateUpdateConfig(
return nil, errors.WithMessage(err, "compare data configs")
}
if isMatch {
// Links may be missing after a partially failed update; re-save them even when data is unchanged.
err = c.variableService.SaveVariableLinks(ctx, req.Id, variableExtractionResult.VariableLinks)
if err != nil {
return nil, errors.WithMessage(err, "save variable links")
}
c.logger.Info(ctx, "no changes in config; skip update")
return &domain.CreateUpdateConfigResponse{Config: configToDto(*oldConfig, nil), IsChanged: false}, nil
}
@@ -328,7 +323,7 @@ func (c Config) extractAndCheckVariables(ctx context.Context, configId string, i
for _, variable := range variableExtractionResult.AbsentVariables {
details[variable] = "variable is not defined"
}
return nil, domain.NewConfigValidationError(details)
return nil, errors.WithMessage(domain.NewConfigValidationError(details), "config validation")
}
return variableExtractionResult, nil
}
@@ -350,7 +345,7 @@ func (c Config) validateConfigUpdate(ctx context.Context, moduleId string, confi
return nil
}
return domain.NewConfigValidationError(details)
return errors.WithMessage(domain.NewConfigValidationError(details), "config validation")
}
func (c Config) emitChangeActiveConfigEvent(ctx context.Context, moduleId string) error {
-10
View File
@@ -240,16 +240,6 @@ func (s Service) OnModuleConfigSchema(
}
config = &initialConfig
} else {
// Re-sync links on every connect: they are derived data and may be missing after a partially failed update.
result, err := s.variableService.ExtractVariables(ctx, config.Id, config.Data)
if err != nil {
return errors.WithMessage(err, "extract variables from active config")
}
err = s.variableService.SaveVariableLinks(ctx, config.Id, result.VariableLinks)
if err != nil {
return errors.WithMessage(err, "resync variable links in store")
}
}
configData, err := s.variableService.RenderConfig(ctx, config.Data)
+2 -1
View File
@@ -150,7 +150,8 @@ func (d Adapter) exec(ctx context.Context, inTx bool, requests [][]any) ([]sql.R
for _, result := range resp.Results {
// rqlite reports per-statement failures in individual results with HTTP 200,
// and aborts the whole transaction on the first failed statement.
if err := catchError(nil, result); err != nil {
err := catchError(nil, result)
if err != nil {
return nil, errors.WithMessagef(err, "exec transaction on statement: %v", requests[min(len(results), len(requests)-1)])
}
results = append(results, result)
-39
View File
@@ -20,12 +20,10 @@ type Repo interface {
Upsert(ctx context.Context, variables []entity.Variable) error
Delete(ctx context.Context, name string) (bool, error)
UpsertLinks(ctx context.Context, configId string, links []entity.ConfigHasVariable) error
InsertLinks(ctx context.Context, links []entity.ConfigHasVariable) error
}
type ConfigRepo interface {
GetMetaByVariables(ctx context.Context, variables []string) (map[string][]entity.ConfigMetaWithVariable, error)
FindIdsByVariableReference(ctx context.Context, variableName string) ([]string, error)
}
type EventRepo interface {
@@ -108,16 +106,6 @@ func (s Service) Create(ctx context.Context, req domain.CreateVariableRequest) e
if err != nil {
return errors.WithMessage(err, "insert variable")
}
err = s.syncVariableLinks(ctx, []string{variable.Name})
if err != nil {
return errors.WithMessage(err, "sync variable links")
}
err = s.syncConfigsByVariables(ctx, []string{variable.Name})
if err != nil {
return errors.WithMessage(err, "sync configs by variables")
}
return nil
}
@@ -163,11 +151,6 @@ func (s Service) Upsert(ctx context.Context, req []domain.UpsertVariableRequest)
return errors.WithMessage(err, "upsert variables")
}
err = s.syncVariableLinks(ctx, variableNames)
if err != nil {
return errors.WithMessage(err, "sync variable links")
}
err = s.syncConfigsByVariables(ctx, variableNames)
if err != nil {
return errors.WithMessage(err, "sync configs by variables")
@@ -310,28 +293,6 @@ func (s Service) toDto(variable entity.Variable, metaByVariables map[string][]en
}
}
func (s Service) syncVariableLinks(ctx context.Context, variableNames []string) error {
for _, name := range variableNames {
configIds, err := s.configRepo.FindIdsByVariableReference(ctx, name)
if err != nil {
return errors.WithMessagef(err, "find configs referencing variable: %s", name)
}
links := make([]entity.ConfigHasVariable, 0, len(configIds))
for _, configId := range configIds {
links = append(links, entity.ConfigHasVariable{
ConfigId: configId,
VariableName: name,
})
}
err = s.repo.InsertLinks(ctx, links)
if err != nil {
return errors.WithMessagef(err, "insert links for variable: %s", name)
}
}
return nil
}
func (s Service) syncConfigsByVariables(ctx context.Context, variables []string) error {
metaByVariables, err := s.configRepo.GetMetaByVariables(ctx, variables)
if err != nil {