Skip to content

Modern Docker Management, Designed for Everyone

chore: cleanup redundant logic

Kyle Mendelle1ae197274a6
diff --git a/AGENTS.md b/AGENTS.md
index 1bf4bb214..aaf16b54f 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -1,18 +1,22 @@
-# Arcane Agent Guide
+# Arcane agent guide
-All AI-assisted work must follow [AI_POLICY.md](./AI_POLICY.md). Keep changes focused,
-verify them locally, and disclose AI assistance when contributing.
+Follow [AI_POLICY.md](./AI_POLICY.md), including its maintainer exemption. Outside
+contributors must disclose AI assistance and meet its human verification requirements.
Arcane is a Docker management platform with a Go backend, SvelteKit frontend,
headless agent modes, and a Cobra CLI.
## Non-negotiable rules
-- Update existing code in place. Search before adding functions, services, wrappers,
- API clients, components, or utilities.
-- Never add stubs, shims, pass-through helpers, or duplicate implementations.
-- Call existing `pkg/` helpers directly instead of wrapping them.
-- Add new code only for genuinely new behavior and integrate it with the owning domain.
+- Search the owning domain and existing helpers before adding functions, services,
+ API clients, components, or utilities. Update existing logic and its callers directly.
+- Never add stubs, compatibility shims, pass-through wrappers, or duplicate
+ implementations. Call existing helpers directly.
+- Integrate new functionality with the owning domain. Keep each file focused on one
+ coherent responsibility. Do not create god files in services, components, or CLI commands.
+- Updating in place allows moving related logic into focused sibling files within the
+ same domain. Split by responsibility, not a fixed line count. Avoid trivial file
+ splits, unnecessary abstractions, and unrelated restructuring.
- Keep comments short. If code needs a paragraph to explain its structure, simplify it.
- Never run state-changing Git commands. Do not stage, commit, push, tag, stash,
create branches, or create worktrees.
@@ -20,7 +24,11 @@ headless agent modes, and a Cobra CLI.
- Name every unexported Go function with an `Internal` suffix.
- Put public/shared Go types in the top-level `types/` module.
- Put reusable helper utilities under `backend/pkg/utils/` in the appropriate package.
-- Do not add tests for handlers. Test business logic at the service layer instead.
+- Add tests only for new functionality. For bug fixes and refactors, update existing
+ tests when necessary and run relevant existing coverage; do not add regression tests.
+- Never add handler tests. Test new business behavior at the service layer or in its
+ owning logic package. Preserve existing handler tests; this rule does not authorize
+ deleting them.
- After any change, run `just format all`, then `just lint all`, and fix every issue.
Never revert formatter output.
@@ -45,29 +53,33 @@ backend/
├── cmd/ process entrypoint
├── api/ API assembly and exceptional HTTP/stream/WebSocket routes
├── internal/
-│ ├── <domain>/ domain module, handler, service, and related files
+│ ├── <domain>/ module, routes, business logic, and persistence models
│ ├── bootstrap/ application lifecycle, router, jobs, and startup wiring
│ ├── di/ Fx dependency graph and providers
│ ├── config/ environment configuration
-│ ├── database/ database setup and migrations
-│ ├── middleware/ authentication, authorization, and environment proxying
-│ └── models/ private GORM persistence models
-├── pkg/ reusable infrastructure and domain-independent libraries
+│ ├── database/ database setup and shared persistence primitives
+│ └── middleware/ authentication, authorization, and environment proxying
+├── pkg/ reusable engines, infrastructure, and helpers
├── resources/ migrations, email templates, and runtime assets
└── frontend/ embedded frontend build
```
-Most domains under `backend/internal/<domain>/` follow this shape:
+Domains under `backend/internal/<domain>/` own their behavior and routes:
-- `module.go` constructs the domain and exposes `Service()` or `Handler()` only when
- another domain needs them.
-- `handler.go` owns Huma input/output types, route registration, and thin handlers.
-- `service.go` and focused sibling files own business logic.
-- Tests stay beside the code they cover.
+- `module.go` wires the domain and registers its routes. Expose services or handlers
+ only when collaborators need them, following the existing module's pattern.
+- `handler.go` and focused route files translate typed HTTP input and call services.
+- Business logic lives in service or domain-named files and focused siblings, such as
+ the project domain's Compose cache, lifecycle, sync, and workspace files. There is
+ no requirement to collect everything in `service.go`.
+- Domain persistence models live beside their owning logic, commonly in `model.go`.
+ Tests belong beside the logic they cover, subject to the test rules above.
-Wire dependencies in `internal/di`; keep startup order and lifecycle hooks in
-`internal/bootstrap`. Do not turn `api/` back into a global handlers directory or
-recreate a global `internal/services` layer.
+Wire dependencies in `internal/di`; keep startup order, lifecycle hooks, database
+migration wiring, and router assembly in `internal/bootstrap`. The remaining `api/`
+code handles API assembly, diagnostics, streams, WebSockets, and webhook dispatch.
+Keep ordinary REST endpoints in their domains. Do not expand `api/handlers` into a
+central handler layer or recreate a global `internal/services` or models package.
Use Echo v5 as the router and Huma v2 for typed REST/OpenAPI operations. Register
permissioned endpoints with `middleware.RegisterWithPermission`. Direct Echo routes
@@ -87,9 +99,30 @@ Before adding backend logic, search the owning domain plus:
- `backend/pkg/libarcane` for reusable Arcane engines and transport behavior.
- `backend/pkg/utils` for shared infrastructure utilities.
-Persistence models embed `models.BaseModel`. Use existing GORM model helpers and
-`Preload` relationships where appropriate; do not expose persistence models as API
-contracts.
+Persistence models use `database.BaseModel` and existing database helpers where
+appropriate. Reuse GORM relationships and `Preload`; keep persistence models separate
+from public API contracts in `types/`.
+
+### CLI and shared types
+
+```text
+cli/
+├── main.go CLI entrypoint
+├── pkg/ Cobra root and domain command packages
+└── internal/
+ ├── client/ shared API client
+ ├── config/ CLI configuration
+ ├── cmdutil/ command support
+ ├── output/ output rendering
+ └── ... prompts, runtime state, and other internal support
+
+types/ shared domain and API contracts, grouped by domain
+```
+
+Update existing commands and reuse the CLI client, configuration, and output code.
+Keep commands focused on input, API calls, and output; backend business behavior
+belongs in its owning backend domain. Keep shared contracts in `types/` independent
+of backend persistence and application wiring.
### Frontend
@@ -102,6 +135,10 @@ frontend/src/
└── lib/
├── components/ shared UI components
├── config/ navigation and access-surface configuration
+ ├── hooks/ reusable reactive behavior
+ ├── layouts/ shared layout components
+ ├── query/ shared query keys
+ ├── paraglide/ generated message code
├── services/ API clients extending BaseAPIService
├── stores/ rune-based application state
├── types/ frontend-only TypeScript types
@@ -116,6 +153,7 @@ frontend/src/
- Put every rendered string behind Paraglide messages.
- Reuse a matching key from `frontend/messages/en.json` before adding one.
- Add new keys only to `en.json`; Crowdin manages every other locale.
+- Generate Paraglide output through the existing tooling; do not edit it by hand.
### Multi-environment and authorization
@@ -139,13 +177,31 @@ frontend/src/
## Validation
-Use the narrowest relevant test first, then the repository gates:
+Adding tests and running tests are separate decisions. The new-functionality-only
+rule does not waive verification. Run the narrowest relevant existing coverage for
+changed behavior, then select the appropriate repository test target. Examples:
+
+```bash
+just test backend
+just test cli
+just test types
+```
+
+Use `just test e2e` for browser coverage when the required environment is available.
+`just test all` includes E2E tests and requires their prerequisites. Do not start a
+development stack implicitly to satisfy a test target.
+
+After every change, including documentation changes, run these gates in order:
```bash
just format all
just lint all
-just test backend|cli|types|e2e|all
```
-For AI-assisted code contributions, also run the development environment and manually
-exercise the changed frontend and backend behavior as required by `AI_POLICY.md`.
+Fix reported issues and retain formatter output. Report what ran, what passed,
+and any blockers. Documentation-only changes do not require adding tests.
+
+For maintainer work, do not start, restart, or rebuild the development stack unless
+the user explicitly asks. Outside contributions must satisfy the development and
+human testing requirements in `AI_POLICY.md` before submission. Do not claim manual
+verification that has not happened.
diff --git a/backend/internal/imageupdate/handler.go b/backend/internal/imageupdate/handler.go
index 786e58a27..d07cac9fe 100644
--- a/backend/internal/imageupdate/handler.go
+++ b/backend/internal/imageupdate/handler.go
@@ -202,7 +202,7 @@ func (h *ImageUpdateHandler) CheckAllImages(ctx context.Context, input *CheckAll
}
func (h *ImageUpdateHandler) GetUpdateInfoByRefs(ctx context.Context, input *GetUpdateInfoByRefsInput) (*handlerutil.Out[map[string]*imagetypes.UpdateInfo], error) {
- imageRefs := parseImageRefsQueryInternal(input.ImageRefs)
+ imageRefs := utils.UniqueNonEmptyStrings(strings.Split(input.ImageRefs, ","))
if len(imageRefs) == 0 {
return &handlerutil.Out[map[string]*imagetypes.UpdateInfo]{
Body: base.ApiResponse[map[string]*imagetypes.UpdateInfo]{
@@ -238,26 +238,3 @@ func (h *ImageUpdateHandler) GetUpdateSummary(ctx context.Context, input *GetUpd
},
}, nil
}
-
-func parseImageRefsQueryInternal(raw string) []string {
- if strings.TrimSpace(raw) == "" {
- return nil
- }
-
- parts := strings.Split(raw, ",")
- result := make([]string, 0, len(parts))
- seen := make(map[string]struct{}, len(parts))
- for _, part := range parts {
- ref := strings.TrimSpace(part)
- if ref == "" {
- continue
- }
- if _, exists := seen[ref]; exists {
- continue
- }
- seen[ref] = struct{}{}
- result = append(result, ref)
- }
-
- return result
-}
diff --git a/backend/internal/imageupdate/image_update.go b/backend/internal/imageupdate/image_update.go
index afe6c1b87..b58850f41 100644
--- a/backend/internal/imageupdate/image_update.go
+++ b/backend/internal/imageupdate/image_update.go
@@ -722,7 +722,7 @@ func (s *ImageUpdateService) getAllImageRefsInternal(ctx context.Context, limit
excludedContainers := make(map[string]bool)
if s.settingsService != nil {
- for _, name := range settings.ParseExcludedContainerNames(s.settingsService.GetStringSetting(ctx, "autoUpdateExcludedContainers", "")) {
+ for _, name := range utils.UniqueNonEmptyStrings(strings.Split(s.settingsService.GetStringSetting(ctx, "autoUpdateExcludedContainers", ""), ",")) {
excludedContainers[name] = true
}
}
diff --git a/backend/internal/project/project.go b/backend/internal/project/project.go
index 2b0b3ca11..cd0a2efa8 100644
--- a/backend/internal/project/project.go
+++ b/backend/internal/project/project.go
@@ -123,16 +123,7 @@ func (s *ProjectService) ValidateComposeDirectory(ctx context.Context, projectNa
if err != nil {
return 0, err
}
- var dockerClient *client.Client
- if s.dockerService != nil {
- dockerClient, _ = s.dockerService.GetClient(ctx)
- }
- pathMapper := projects.NewPathMapperForConfiguredDirectory(
- ctx,
- s.settingsService.GetStringSetting(ctx, "projectsDirectory", "/app/data/projects"),
- "/app/data/projects",
- dockerClient,
- )
+ pathMapper := s.projectPathMapperInternal(ctx)
composeProject, err := projects.LoadComposeProject(
ctx,
filepath.Join(projectPath, composeFileName),
@@ -415,3 +406,16 @@ func (s *ProjectService) EnsureProjectPathUnderRoot(ctx context.Context, proj *P
}
return nil
}
+
+func (s *ProjectService) projectPathMapperInternal(ctx context.Context) *projects.PathMapper {
+ var dockerClient *client.Client
+ if s.dockerService != nil {
+ dockerClient, _ = s.dockerService.GetClient(ctx)
+ }
+ return projects.NewPathMapperForConfiguredDirectory(
+ ctx,
+ s.settingsService.GetStringSetting(ctx, "projectsDirectory", "/app/data/projects"),
+ "/app/data/projects",
+ dockerClient,
+ )
+}
diff --git a/backend/internal/project/project_compose_cache.go b/backend/internal/project/project_compose_cache.go
index 4d9d799fa..f8cdd73d8 100644
--- a/backend/internal/project/project_compose_cache.go
+++ b/backend/internal/project/project_compose_cache.go
@@ -17,7 +17,6 @@ import (
"github.com/getarcaneapp/arcane/backend/v2/internal/common"
"github.com/getarcaneapp/arcane/backend/v2/pkg/projects"
"github.com/getarcaneapp/arcane/backend/v2/pkg/utils"
- "github.com/moby/moby/client"
"github.com/samber/hot"
"github.com/samber/mo"
"gorm.io/gorm"
@@ -238,16 +237,7 @@ func (s *ProjectService) loadComposeProjectForProjectInternal(ctx context.Contex
}
projectsDirectory := getProjectsDirectoryOrDefaultInternal(ctx, cfg)
- var dockerClient *client.Client
- if s.dockerService != nil {
- dockerClient, _ = s.dockerService.GetClient(ctx)
- }
- pathMapper := projects.NewPathMapperForConfiguredDirectory(
- ctx,
- s.settingsService.GetStringSetting(ctx, "projectsDirectory", "/app/data/projects"),
- "/app/data/projects",
- dockerClient,
- )
+ pathMapper := s.projectPathMapperInternal(ctx)
composeProject, loadErr := projects.LoadComposeProject(ctx, composeFileFullPath, projects.NormalizeProjectName(proj.Name), projectsDirectory, utils.BoolOrDefault(cfg.AutoInjectEnv.Value, false), pathMapper, nil, nil, false)
if loadErr != nil {
diff --git a/backend/internal/project/project_lifecycle.go b/backend/internal/project/project_lifecycle.go
index badb5b20a..b221f8359 100644
--- a/backend/internal/project/project_lifecycle.go
+++ b/backend/internal/project/project_lifecycle.go
@@ -27,7 +27,6 @@ import (
"github.com/getarcaneapp/arcane/types/v2"
"github.com/getarcaneapp/arcane/types/v2/containerregistry"
"github.com/getarcaneapp/arcane/types/v2/project"
- "github.com/moby/moby/client"
"go.getarcane.app/acfs"
buildtypes "go.getarcane.app/builds/types"
"go.getarcane.app/sys/cgroup"
@@ -1042,16 +1041,7 @@ func (s *ProjectService) RestartProject(ctx context.Context, projectID string, s
cfg := s.settingsService.GetSettingsOrDefaults(ctx)
projectsDirectory := getProjectsDirectoryOrDefaultInternal(ctx, cfg)
- var dockerClient *client.Client
- if s.dockerService != nil {
- dockerClient, _ = s.dockerService.GetClient(ctx)
- }
- pathMapper := projects.NewPathMapperForConfiguredDirectory(
- ctx,
- s.settingsService.GetStringSetting(ctx, "projectsDirectory", "/app/data/projects"),
- "/app/data/projects",
- dockerClient,
- )
+ pathMapper := s.projectPathMapperInternal(ctx)
compProj, _, lerr := projects.LoadComposeProjectFromDir(ctx, proj.Path, projects.NormalizeProjectName(proj.Name), projectsDirectory, utils.BoolOrDefault(cfg.AutoInjectEnv.Value, false), pathMapper)
if lerr != nil {
diff --git a/backend/internal/project/project_sync.go b/backend/internal/project/project_sync.go
index ba5e5a261..9da1cd386 100644
--- a/backend/internal/project/project_sync.go
+++ b/backend/internal/project/project_sync.go
@@ -13,7 +13,6 @@ import (
"github.com/getarcaneapp/arcane/backend/v2/internal/common"
"github.com/getarcaneapp/arcane/backend/v2/pkg/projects"
"github.com/getarcaneapp/arcane/backend/v2/pkg/utils"
- "github.com/moby/moby/client"
"github.com/samber/mo"
"gorm.io/gorm"
)
@@ -472,16 +471,7 @@ func (s *ProjectService) loadComposeMetadataForSyncInternal(ctx context.Context,
return meta, pErr
}
- var dockerClient *client.Client
- if s.dockerService != nil {
- dockerClient, _ = s.dockerService.GetClient(ctx)
- }
- pathMapper := projects.NewPathMapperForConfiguredDirectory(
- ctx,
- s.settingsService.GetStringSetting(ctx, "projectsDirectory", "/app/data/projects"),
- "/app/data/projects",
- dockerClient,
- )
+ pathMapper := s.projectPathMapperInternal(ctx)
autoInjectEnv := utils.BoolOrDefault(cfg.AutoInjectEnv.Value, false)
diff --git a/backend/internal/project/service_test.go b/backend/internal/project/service_test.go
index 3b43ee6c0..3c57f0a3a 100644
--- a/backend/internal/project/service_test.go
+++ b/backend/internal/project/service_test.go
@@ -7366,3 +7366,19 @@ func TestProjectService_MapProjectToDto_SeedsHasBuildDirectiveFromPersistedRefs(
})
}
}
+
+func TestProjectPathMapperUsesCurrentSettingsInternal(t *testing.T) {
+ db := setupProjectTestDB(t)
+ settingsService, err := newSettingsServiceForTestInternal(t, t.Context(), db)
+ require.NoError(t, err)
+ service := &ProjectService{settingsService: settingsService}
+ containerDir := t.TempDir()
+ for _, hostDir := range []string{t.TempDir(), t.TempDir()} {
+ require.NoError(t, settingsService.SetStringSetting(t.Context(), "projectsDirectory", containerDir+":"+hostDir))
+ mapper := service.projectPathMapperInternal(t.Context())
+ require.NotNil(t, mapper)
+ mapped, err := mapper.ContainerToHost(filepath.Join(containerDir, "data"))
+ require.NoError(t, err)
+ require.Equal(t, filepath.Join(hostDir, "data"), mapped)
+ }
+}
diff --git a/backend/internal/s3/service.go b/backend/internal/s3/service.go
index 6cbf7ae11..67a6f9749 100644
--- a/backend/internal/s3/service.go
+++ b/backend/internal/s3/service.go
@@ -80,6 +80,19 @@ func (s *S3DestinationService) ListAllS3Destinations(ctx context.Context) ([]bac
return s3DestinationsToDTOsInternal(destinations), nil
}
+// ListS3DestinationsByID indexes destination DTOs for backup metadata lookups.
+func (s *S3DestinationService) ListS3DestinationsByID(ctx context.Context) (map[string]backuptypes.S3Destination, error) {
+ destinations, err := s.ListAllS3Destinations(ctx)
+ if err != nil {
+ return nil, err
+ }
+ indexed := make(map[string]backuptypes.S3Destination, len(destinations))
+ for _, destination := range destinations {
+ indexed[destination.ID] = destination
+ }
+ return indexed, nil
+}
+
func (s *S3DestinationService) getS3DestinationModelInternal(ctx context.Context, id string) (*S3Destination, error) {
var destination S3Destination
if err := s.db.WithContext(ctx).Where("id = ?", strings.TrimSpace(id)).First(&destination).Error; err != nil {
diff --git a/backend/internal/s3/service_test.go b/backend/internal/s3/service_test.go
index 727940f75..d544e18ea 100644
--- a/backend/internal/s3/service_test.go
+++ b/backend/internal/s3/service_test.go
@@ -272,3 +272,23 @@ func TestS3DestinationService_TestS3DestinationRoundTrip(t *testing.T) {
require.Equal(t, "production", persisted.Prefix)
require.Empty(t, persisted.Region)
}
+
+func TestListS3DestinationsByIDInternal(t *testing.T) {
+ service, db := setupS3DestinationServiceTestInternal(t)
+ indexed, err := service.ListS3DestinationsByID(t.Context())
+ require.NoError(t, err)
+ require.Empty(t, indexed)
+ destination := S3Destination{Name: "Offsite", Bucket: "backups", SecretAccessKey: "encrypted"}
+ require.NoError(t, db.Create(&destination).Error)
+ indexed, err = service.ListS3DestinationsByID(t.Context())
+ require.NoError(t, err)
+ require.Len(t, indexed, 1)
+ require.Equal(t, "Offsite", indexed[destination.ID].Name)
+ require.Equal(t, "backups", indexed[destination.ID].Bucket)
+ require.True(t, indexed[destination.ID].SecretConfigured)
+ require.Empty(t, indexed["missing"].Name)
+ require.NoError(t, db.Migrator().DropTable(&S3Destination{}))
+ indexed, err = service.ListS3DestinationsByID(t.Context())
+ require.ErrorContains(t, err, "failed to list S3 destinations")
+ require.Nil(t, indexed)
+}
diff --git a/backend/internal/settings/service.go b/backend/internal/settings/service.go
index 0bb2c3808..0be7720df 100644
--- a/backend/internal/settings/service.go
+++ b/backend/internal/settings/service.go
@@ -937,29 +937,12 @@ func (s *SettingsService) SetStringSetting(ctx context.Context, key, value strin
return s.UpdateSetting(ctx, key, value)
}
-// ParseExcludedContainerNames returns the trimmed, deduplicated names from a comma-separated exclusion list.
-func ParseExcludedContainerNames(raw string) []string {
- seen := make(map[string]struct{})
- var ordered []string
- for part := range strings.SplitSeq(raw, ",") {
- name := strings.TrimSpace(part)
- if name == "" {
- continue
- }
- if _, ok := seen[name]; !ok {
- seen[name] = struct{}{}
- ordered = append(ordered, name)
- }
- }
- return ordered
-}
-
// SetContainerAutoUpdateExclusionInternal adds or removes a container name from
// the autoUpdateExcludedContainers setting. When excluded is true the container
// is added to the list; when false it is removed.
func (s *SettingsService) SetContainerAutoUpdateExclusionInternal(ctx context.Context, containerName string, excluded bool) error {
_, err := s.writes.Execute(ctx, "update container auto-update exclusion", func(writeCtx context.Context) (actors.NoPayload, error) {
- ordered := ParseExcludedContainerNames(s.GetStringSetting(writeCtx, "autoUpdateExcludedContainers", ""))
+ ordered := utils.UniqueNonEmptyStrings(strings.Split(s.GetStringSetting(writeCtx, "autoUpdateExcludedContainers", ""), ","))
if excluded {
if !slices.Contains(ordered, containerName) {
diff --git a/backend/internal/systembackup/service.go b/backend/internal/systembackup/service.go
index 0ca654cd1..b3339a673 100644
--- a/backend/internal/systembackup/service.go
+++ b/backend/internal/systembackup/service.go
@@ -491,17 +491,15 @@ func (s *SystemBackupService) ListBackups(ctx context.Context, params pagination
if err != nil {
return nil, pagination.Response{}, fmt.Errorf("failed to list system backups: %w", err)
}
- names := make(map[string]string)
+ names := make(map[string]backuptypes.S3Destination)
if s.s3Destinations != nil {
- if destinations, listErr := s.s3Destinations.ListAllS3Destinations(ctx); listErr == nil {
- for _, destination := range destinations {
- names[destination.ID] = destination.Name
- }
+ if available, listErr := s.s3Destinations.ListS3DestinationsByID(ctx); listErr == nil {
+ names = available
}
}
result := make([]backuptypes.SystemBackupRun, len(runs))
for i := range runs {
- runs[i].S3DestinationName = names[runs[i].S3DestinationID]
+ runs[i].S3DestinationName = names[runs[i].S3DestinationID].Name
result[i] = runs[i].ToDTO()
}
return result, response, nil
@@ -1472,25 +1470,23 @@ func (s *SystemBackupService) GetPolicies(ctx context.Context) (*backuptypes.Sys
result := &backuptypes.SystemBackupPolicyCollection{
Policies: make([]backuptypes.SystemBackupPolicy, 0, len(policies)), RecoveryKeyStored: configured,
}
- destinations := make(map[string]string)
+ destinations := make(map[string]backuptypes.S3Destination)
if s.s3Destinations != nil {
- if available, listErr := s.s3Destinations.ListAllS3Destinations(ctx); listErr == nil {
- for _, destination := range available {
- destinations[destination.ID] = destination.Name
- }
+ if available, listErr := s.s3Destinations.ListS3DestinationsByID(ctx); listErr == nil {
+ destinations = available
}
}
for i := range policies {
var lastRun *SystemBackupRun
var run SystemBackupRun
if runErr := s.db.WithContext(ctx).Where("policy_id = ?", policies[i].ID).Order("created_at DESC").First(&run).Error; runErr == nil {
- run.S3DestinationName = destinations[run.S3DestinationID]
+ run.S3DestinationName = destinations[run.S3DestinationID].Name
lastRun = &run
} else if !errors.Is(runErr, gorm.ErrRecordNotFound) {
return nil, fmt.Errorf("failed to load latest system backup: %w", runErr)
}
dto := policies[i].ToDTO(lastRun)
- dto.S3DestinationName = destinations[policies[i].S3DestinationID]
+ dto.S3DestinationName = destinations[policies[i].S3DestinationID].Name
result.Policies = append(result.Policies, dto)
}
return result, nil
diff --git a/backend/internal/systembackup/system_volume.go b/backend/internal/systembackup/system_volume.go
index 445ae94fb..67b0f6a26 100644
--- a/backend/internal/systembackup/system_volume.go
+++ b/backend/internal/systembackup/system_volume.go
@@ -66,17 +66,15 @@ func (s *SystemBackupService) GetSystemVolumeBackupConfig(ctx context.Context) (
if err != nil {
return nil, err
}
- destinations := make(map[string]string)
+ destinations := make(map[string]backuptypes.S3Destination)
if s.s3Destinations != nil {
- if available, listErr := s.s3Destinations.ListAllS3Destinations(ctx); listErr == nil {
- for _, destination := range available {
- destinations[destination.ID] = destination.Name
- }
+ if available, listErr := s.s3Destinations.ListS3DestinationsByID(ctx); listErr == nil {
+ destinations = available
}
}
for i := range collection.Policies {
policy := &collection.Policies[i]
- policy.S3DestinationName = destinations[policy.S3DestinationID]
+ policy.S3DestinationName = destinations[policy.S3DestinationID].Name
if s.db == nil {
continue
}
@@ -89,7 +87,7 @@ func (s *SystemBackupService) GetSystemVolumeBackupConfig(ctx context.Context) (
ID: lastRun.ID, Size: lastRun.Size, CreatedAt: lastRun.CreatedAt, Status: string(lastRun.Status),
Trigger: string(lastRun.Trigger), Destination: backuptypes.SystemBackupDestination(lastRun.Destination),
LocalSnapshotID: lastRun.LocalSnapshotID, RemoteSnapshotID: lastRun.RemoteSnapshotID,
- S3DestinationID: lastRun.S3DestinationID, S3DestinationName: destinations[lastRun.S3DestinationID],
+ S3DestinationID: lastRun.S3DestinationID, S3DestinationName: destinations[lastRun.S3DestinationID].Name,
PolicyID: lastRun.PolicyID, Error: lastRun.Error,
}
} else if !errors.Is(runErr, gorm.ErrRecordNotFound) {
@@ -399,15 +397,11 @@ func decorateHistoryDestinationsInternal(ctx context.Context, service *s3domain.
if service == nil {
return
}
- destinations, err := service.ListAllS3Destinations(ctx)
+ destinations, err := service.ListS3DestinationsByID(ctx)
if err != nil {
return
}
- names := make(map[string]string, len(destinations))
- for _, destination := range destinations {
- names[destination.ID] = destination.Name
- }
for i := range history {
- history[i].S3DestinationName = names[history[i].S3DestinationID]
+ history[i].S3DestinationName = destinations[history[i].S3DestinationID].Name
}
}
diff --git a/backend/internal/systembackup/system_volume_test.go b/backend/internal/systembackup/system_volume_test.go
index 508940027..b21702e5e 100644
--- a/backend/internal/systembackup/system_volume_test.go
+++ b/backend/internal/systembackup/system_volume_test.go
@@ -6,6 +6,7 @@ import (
"time"
"github.com/getarcaneapp/arcane/backend/v2/internal/database"
+ s3domain "github.com/getarcaneapp/arcane/backend/v2/internal/s3"
"github.com/getarcaneapp/arcane/backend/v2/internal/volume"
"github.com/getarcaneapp/arcane/backend/v2/pkg/pagination"
backuptypes "github.com/getarcaneapp/arcane/types/v2/backup"
@@ -97,3 +98,21 @@ func TestListBackupHistoryClassifiesAndFiltersOrigins(t *testing.T) {
require.Equal(t, backuptypes.ManagementTypeVolume, volumeRows[0].Type)
require.Equal(t, "cache", volumeRows[0].ResourceName)
}
+
+func TestHistoryDestinationDecorationInternal(t *testing.T) {
+ db, err := gorm.Open(sqlite.Open(":memory:"), &gorm.Config{})
+ require.NoError(t, err)
+ require.NoError(t, db.AutoMigrate(&s3domain.S3Destination{}))
+ destination := s3domain.S3Destination{Name: "Offsite", Bucket: "backups"}
+ require.NoError(t, db.Create(&destination).Error)
+ service := s3domain.NewS3DestinationService(&database.DB{DB: db})
+ history := []backuptypes.HistoryEntry{{S3DestinationID: destination.ID}, {S3DestinationID: "missing"}}
+ decorateHistoryDestinationsInternal(t.Context(), service, history)
+ require.Equal(t, "Offsite", history[0].S3DestinationName)
+ require.Empty(t, history[1].S3DestinationName)
+ require.NoError(t, db.Migrator().DropTable(&s3domain.S3Destination{}))
+ decorateHistoryDestinationsInternal(t.Context(), service, history)
+ require.Equal(t, "Offsite", history[0].S3DestinationName)
+ decorateHistoryDestinationsInternal(t.Context(), nil, history)
+ require.Equal(t, "Offsite", history[0].S3DestinationName)
+}
diff --git a/backend/internal/updater/service.go b/backend/internal/updater/service.go
index 38961849f..c6c0a46ed 100644
--- a/backend/internal/updater/service.go
+++ b/backend/internal/updater/service.go
@@ -658,7 +658,7 @@ func (s *UpdaterService) ExcludedContainers(ctx context.Context) ([]string, erro
if s.deps.Settings == nil {
return nil, nil
}
- return settings.ParseExcludedContainerNames(s.deps.Settings.GetStringSetting(ctx, "autoUpdateExcludedContainers", "")), nil
+ return utils.UniqueNonEmptyStrings(strings.Split(s.deps.Settings.GetStringSetting(ctx, "autoUpdateExcludedContainers", ""), ",")), nil
}
// ProjectByComposeName resolves an Arcane project from a Docker Compose project name.
@@ -1265,7 +1265,7 @@ func (s *UpdaterService) buildExcludedContainerSetInternal(ctx context.Context)
if s.deps.Settings == nil {
return nil
}
- names := settings.ParseExcludedContainerNames(s.deps.Settings.GetStringSetting(ctx, "autoUpdateExcludedContainers", ""))
+ names := utils.UniqueNonEmptyStrings(strings.Split(s.deps.Settings.GetStringSetting(ctx, "autoUpdateExcludedContainers", ""), ","))
if len(names) == 0 {
return nil
}
diff --git a/backend/internal/version/service.go b/backend/internal/version/service.go
index 6007d8b42..f101a1750 100644
--- a/backend/internal/version/service.go
+++ b/backend/internal/version/service.go
@@ -25,6 +25,7 @@ import (
"github.com/getarcaneapp/arcane/backend/v2/internal/registry"
"github.com/getarcaneapp/arcane/backend/v2/internal/settings"
"github.com/getarcaneapp/arcane/backend/v2/pkg/libarcane"
+ "github.com/getarcaneapp/arcane/backend/v2/pkg/utils"
"github.com/getarcaneapp/arcane/types/v2/version"
"github.com/samber/hot"
"go.getarcane.app/sys/cgroup"
@@ -331,7 +332,7 @@ func (s *VersionService) GetAppVersionInfo(ctx context.Context) *version.Info {
GoVersion: config.GoVersion(),
NodeVersion: config.NodeVersion,
SvelteKitVersion: config.SvelteKitVersion,
- EnabledFeatures: append(parseEnabledFeatures(), apns.FeatureName),
+ EnabledFeatures: append(utils.UniqueNonEmptyStrings(strings.Split(strings.ToLower(buildables.EnabledFeatures), ",")), apns.FeatureName),
BuildTime: config.BuildTime,
IsSemverVersion: isSemver,
UpdateAvailable: false,
@@ -399,28 +400,6 @@ func (s *VersionService) storedOrDigestBasedUpdateInternal(ctx context.Context,
return false, ""
}
-func parseEnabledFeatures() []string {
- raw := strings.TrimSpace(buildables.EnabledFeatures)
- if raw == "" {
- return nil
- }
- parts := strings.Split(raw, ",")
- features := make([]string, 0, len(parts))
- seen := make(map[string]struct{}, len(parts))
- for _, part := range parts {
- feature := strings.ToLower(strings.TrimSpace(part))
- if feature == "" {
- continue
- }
- if _, exists := seen[feature]; exists {
- continue
- }
- seen[feature] = struct{}{}
- features = append(features, feature)
- }
- return features
-}
-
// detectCurrentImageInfo attempts to detect the current container's image tag and digest
func (s *VersionService) detectCurrentImageInfo(ctx context.Context) (tag string, digest string, imageRef string, imageID string) {
if s.dockerService == nil {
diff --git a/backend/internal/volume/backup.go b/backend/internal/volume/backup.go
index 5ca86b0c6..41ce07218 100644
--- a/backend/internal/volume/backup.go
+++ b/backend/internal/volume/backup.go
@@ -22,7 +22,6 @@ import (
"github.com/getarcaneapp/arcane/backend/v2/internal/common"
"github.com/getarcaneapp/arcane/backend/v2/internal/database"
"github.com/getarcaneapp/arcane/backend/v2/internal/event"
- s3domain "github.com/getarcaneapp/arcane/backend/v2/internal/s3"
docker "github.com/getarcaneapp/arcane/backend/v2/pkg/dockerutil"
"github.com/getarcaneapp/arcane/backend/v2/pkg/libarcane"
activitylib "github.com/getarcaneapp/arcane/backend/v2/pkg/libarcane/activity"
@@ -383,16 +382,12 @@ func (s *VolumeService) ListBackupsPaginated(ctx context.Context, volumeName str
}
if s.s3Destinations != nil && hasS3Destination {
// Destination names are decoration; never fail the listing over them.
- destinations, destinationErr := s.s3Destinations.ListAllS3Destinations(ctx)
+ destinations, destinationErr := s.s3Destinations.ListS3DestinationsByID(ctx)
if destinationErr != nil {
slog.WarnContext(ctx, "could not resolve volume backup S3 destination names", "volume", volumeName, "error", destinationErr)
} else {
- destinationNames := make(map[string]string, len(destinations))
- for _, destination := range destinations {
- destinationNames[destination.ID] = destination.Name
- }
for i := range backups {
- backups[i].S3DestinationName = destinationNames[backups[i].S3DestinationID]
+ backups[i].S3DestinationName = destinations[backups[i].S3DestinationID].Name
}
}
}
@@ -1693,14 +1688,12 @@ func (s *VolumeService) GetBackupPolicies(ctx context.Context, volumeName string
return nil, err
}
result := &volumetypes.BackupPolicyCollection{Policies: make([]volumetypes.BackupPolicy, 0, len(policies))}
- destinations := make(map[string]s3domain.S3Destination)
+ destinations := make(map[string]backuptypes.S3Destination)
if s.s3Destinations != nil {
- available, listErr := s.s3Destinations.ListAllS3Destinations(ctx)
+ available, listErr := s.s3Destinations.ListS3DestinationsByID(ctx)
if listErr == nil {
result.S3Available = len(available) > 0
- for _, destination := range available {
- destinations[destination.ID] = s3domain.S3Destination{ID: destination.ID, Name: destination.Name, Bucket: destination.Bucket}
- }
+ destinations = available
}
}
for i := range policies {
diff --git a/backend/internal/volume/service_test.go b/backend/internal/volume/service_test.go
index d129086b7..32a8cc717 100644
--- a/backend/internal/volume/service_test.go
+++ b/backend/internal/volume/service_test.go
@@ -1022,3 +1022,23 @@ func TestVolumeBackupContainerLifecycleWaitsForRunningComposeReplacement(t *test
require.Empty(t, remaining)
require.Equal(t, []string{"stop:old-id"}, operations)
}
+
+func TestBackupPolicyDestinationLookupFailureInternal(t *testing.T) {
+ db, err := gorm.Open(sqlite.Open(":memory:"), &gorm.Config{})
+ require.NoError(t, err)
+ require.NoError(t, db.AutoMigrate(&VolumeBackupPolicy{}, &VolumeBackup{}, &s3domain.S3Destination{}))
+ policy := &VolumeBackupPolicy{VolumeName: "app-data", Schedule: "0 0 2 * * *", S3DestinationID: "missing"}
+ require.NoError(t, db.Create(policy).Error)
+ service := &VolumeService{db: &database.DB{DB: db}, s3Destinations: s3domain.NewS3DestinationService(&database.DB{DB: db})}
+ for _, drop := range []bool{false, true} {
+ if drop {
+ require.NoError(t, db.Migrator().DropTable(&s3domain.S3Destination{}))
+ }
+ collection, err := service.GetBackupPolicies(t.Context(), "app-data")
+ require.NoError(t, err)
+ require.Len(t, collection.Policies, 1)
+ require.False(t, collection.S3Available)
+ require.Empty(t, collection.Policies[0].S3DestinationName)
+ require.Empty(t, collection.Policies[0].S3Bucket)
+ }
+}
diff --git a/backend/pkg/projects/path_mapper_test.go b/backend/pkg/projects/path_mapper_test.go
index 753d04dca..565aa7879 100644
--- a/backend/pkg/projects/path_mapper_test.go
+++ b/backend/pkg/projects/path_mapper_test.go
@@ -13,6 +13,12 @@ import (
func TestNewPathMapperForConfiguredDirectory(t *testing.T) {
ctx := context.Background()
+ t.Run("empty configuration uses default without Docker", func(t *testing.T) {
+ defaultDir := filepath.Join(t.TempDir(), "projects")
+ require.Nil(t, NewPathMapperForConfiguredDirectory(ctx, "", defaultDir, nil))
+ require.DirExists(t, defaultDir)
+ })
+
t.Run("matching paths do not need a mapper", func(t *testing.T) {
containerDir := t.TempDir()
pathMapper := NewPathMapperForConfiguredDirectory(ctx, containerDir, containerDir, nil)
diff --git a/backend/pkg/utils/notifications/discord_sender.go b/backend/pkg/utils/notifications/discord_sender.go
index c4820a0e7..3bc4ec161 100644
--- a/backend/pkg/utils/notifications/discord_sender.go
+++ b/backend/pkg/utils/notifications/discord_sender.go
@@ -5,9 +5,7 @@ import (
"emperror.dev/errors"
- "github.com/nicholas-fedor/shoutrrr"
"github.com/nicholas-fedor/shoutrrr/pkg/services/chat/discord"
- shoutrrrTypes "github.com/nicholas-fedor/shoutrrr/pkg/types"
)
// BuildDiscordURL converts DiscordConfig to Shoutrrr URL format using shoutrrr's Config
@@ -37,16 +35,5 @@ func SendDiscord(ctx context.Context, config DiscordConfig, message string) erro
return errors.WrapIf(err, "failed to build shoutrrr Discord URL")
}
- sender, err := shoutrrr.CreateSenderWithOptions(shoutrrrTypes.SenderOptions{}, shoutrrrURL)
- if err != nil {
- return errors.WrapIf(err, "failed to create shoutrrr Discord sender")
- }
-
- errs := sender.Send(message, nil)
- for _, err := range errs {
- if err != nil {
- return errors.WrapIf(err, "failed to send Discord message via shoutrrr")
- }
- }
- return nil
+ return sendShoutrrrInternal("Discord", shoutrrrURL, message, nil)
}
diff --git a/backend/pkg/utils/notifications/googlechat_sender.go b/backend/pkg/utils/notifications/googlechat_sender.go
index 253b0b3d7..b38f9c022 100644
--- a/backend/pkg/utils/notifications/googlechat_sender.go
+++ b/backend/pkg/utils/notifications/googlechat_sender.go
@@ -7,7 +7,6 @@ import (
"emperror.dev/errors"
- "github.com/nicholas-fedor/shoutrrr"
shoutrrrTypes "github.com/nicholas-fedor/shoutrrr/pkg/types"
)
@@ -63,16 +62,5 @@ func SendGoogleChat(ctx context.Context, config GoogleChatConfig, message string
return errors.WrapIf(err, "failed to build shoutrrr Google Chat URL")
}
- sender, err := shoutrrr.CreateSenderWithOptions(shoutrrrTypes.SenderOptions{}, shoutrrrURL)
- if err != nil {
- return errors.WrapIf(err, "failed to create shoutrrr Google Chat sender")
- }
-
- errs := sender.Send(message, &shoutrrrTypes.Params{})
- for _, err := range errs {
- if err != nil {
- return errors.WrapIf(err, "failed to send Google Chat message via shoutrrr")
- }
- }
- return nil
+ return sendShoutrrrInternal("Google Chat", shoutrrrURL, message, &shoutrrrTypes.Params{})
}
diff --git a/backend/pkg/utils/notifications/gotify_sender.go b/backend/pkg/utils/notifications/gotify_sender.go
index 2c2ed646e..1414cf9d5 100644
--- a/backend/pkg/utils/notifications/gotify_sender.go
+++ b/backend/pkg/utils/notifications/gotify_sender.go
@@ -9,7 +9,6 @@ import (
"emperror.dev/errors"
- "github.com/nicholas-fedor/shoutrrr"
shoutrrrTypes "github.com/nicholas-fedor/shoutrrr/pkg/types"
)
@@ -70,18 +69,5 @@ func SendGotify(ctx context.Context, config GotifyConfig, message string) error
return errors.WrapIf(err, "failed to build shoutrrr Gotify URL")
}
- sender, err := shoutrrr.CreateSenderWithOptions(shoutrrrTypes.SenderOptions{}, shoutrrrURL)
- if err != nil {
- return errors.WrapIf(err, "failed to create shoutrrr Gotify sender")
- }
-
- params := &shoutrrrTypes.Params{}
-
- errs := sender.Send(message, params)
- for _, err := range errs {
- if err != nil {
- return errors.WrapIf(err, "failed to send Gotify message via shoutrrr")
- }
- }
- return nil
+ return sendShoutrrrInternal("Gotify", shoutrrrURL, message, &shoutrrrTypes.Params{})
}
diff --git a/backend/pkg/utils/notifications/matrix_sender.go b/backend/pkg/utils/notifications/matrix_sender.go
index 6d5a24a01..fe0717eb0 100644
--- a/backend/pkg/utils/notifications/matrix_sender.go
+++ b/backend/pkg/utils/notifications/matrix_sender.go
@@ -8,7 +8,6 @@ import (
"emperror.dev/errors"
- "github.com/nicholas-fedor/shoutrrr"
shoutrrrTypes "github.com/nicholas-fedor/shoutrrr/pkg/types"
)
@@ -63,18 +62,5 @@ func SendMatrix(ctx context.Context, config MatrixConfig, message string) error
return errors.WrapIf(err, "failed to build shoutrrr Matrix URL")
}
- sender, err := shoutrrr.CreateSenderWithOptions(shoutrrrTypes.SenderOptions{}, shoutrrrURL)
- if err != nil {
- return errors.WrapIf(err, "failed to create shoutrrr Matrix sender")
- }
-
- params := &shoutrrrTypes.Params{}
-
- errs := sender.Send(message, params)
- for _, err := range errs {
- if err != nil {
- return errors.WrapIf(err, "failed to send Matrix message via shoutrrr")
- }
- }
- return nil
+ return sendShoutrrrInternal("Matrix", shoutrrrURL, message, &shoutrrrTypes.Params{})
}
diff --git a/backend/pkg/utils/notifications/ntfy_sender.go b/backend/pkg/utils/notifications/ntfy_sender.go
index 60d5e9cd0..d8d3187dd 100644
--- a/backend/pkg/utils/notifications/ntfy_sender.go
+++ b/backend/pkg/utils/notifications/ntfy_sender.go
@@ -8,7 +8,6 @@ import (
"emperror.dev/errors"
- "github.com/nicholas-fedor/shoutrrr"
shoutrrrTypes "github.com/nicholas-fedor/shoutrrr/pkg/types"
)
@@ -100,18 +99,5 @@ func SendNtfy(ctx context.Context, config NtfyConfig, message string) error {
return errors.WrapIf(err, "failed to build shoutrrr Ntfy URL")
}
- sender, err := shoutrrr.CreateSenderWithOptions(shoutrrrTypes.SenderOptions{}, shoutrrrURL)
- if err != nil {
- return errors.WrapIf(err, "failed to create shoutrrr Ntfy sender")
- }
-
- params := &shoutrrrTypes.Params{}
-
- errs := sender.Send(message, params)
- for _, err := range errs {
- if err != nil {
- return errors.WrapIf(err, "failed to send Ntfy message via shoutrrr")
- }
- }
- return nil
+ return sendShoutrrrInternal("Ntfy", shoutrrrURL, message, &shoutrrrTypes.Params{})
}
diff --git a/backend/pkg/utils/notifications/pushover_sender.go b/backend/pkg/utils/notifications/pushover_sender.go
index 22b432f27..47ab6645e 100644
--- a/backend/pkg/utils/notifications/pushover_sender.go
+++ b/backend/pkg/utils/notifications/pushover_sender.go
@@ -7,9 +7,6 @@ import (
"strings"
"emperror.dev/errors"
-
- "github.com/nicholas-fedor/shoutrrr"
- shoutrrrTypes "github.com/nicholas-fedor/shoutrrr/pkg/types"
)
// BuildPushoverURL converts PushoverConfig to Shoutrrr URL format.
@@ -73,16 +70,5 @@ func SendPushover(ctx context.Context, config PushoverConfig, message string) er
return errors.WrapIf(err, "failed to build shoutrrr Pushover URL")
}
- sender, err := shoutrrr.CreateSenderWithOptions(shoutrrrTypes.SenderOptions{}, shoutrrrURL)
- if err != nil {
- return errors.WrapIf(err, "failed to create shoutrrr Pushover sender")
- }
-
- errs := sender.Send(message, nil)
- for _, err := range errs {
- if err != nil {
- return errors.WrapIf(err, "failed to send Pushover message via shoutrrr")
- }
- }
- return nil
+ return sendShoutrrrInternal("Pushover", shoutrrrURL, message, nil)
}
diff --git a/backend/pkg/utils/notifications/shoutrrr_test.go b/backend/pkg/utils/notifications/shoutrrr_test.go
new file mode 100644
index 000000000..d93437f67
--- /dev/null
+++ b/backend/pkg/utils/notifications/shoutrrr_test.go
@@ -0,0 +1,46 @@
+package notifications
+
+import (
+ "io"
+ "net/http"
+ "net/http/httptest"
+ "net/url"
+ "testing"
+
+ "github.com/stretchr/testify/require"
+)
+
+func TestSendGotifyDeliveryInternal(t *testing.T) {
+ for _, status := range []int{http.StatusOK, http.StatusInternalServerError} {
+ t.Run(http.StatusText(status), func(t *testing.T) {
+ requests := make(chan string, 1)
+ server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ body, _ := io.ReadAll(r.Body)
+ requests <- string(body)
+ w.Header().Set("Content-Type", "application/json")
+ w.WriteHeader(status)
+ _, _ = w.Write([]byte(`{"id":1,"error":"delivery failed"}`))
+ }))
+ defer server.Close()
+ endpoint, err := url.Parse(server.URL)
+ require.NoError(t, err)
+ err = SendGotify(t.Context(), GotifyConfig{Host: endpoint.Host, Token: "A12345678901234", DisableTLS: true}, "consolidated delivery")
+ if status == http.StatusOK {
+ require.NoError(t, err)
+ } else {
+ require.ErrorContains(t, err, "failed to send Gotify message via shoutrrr")
+ }
+ select {
+ case body := <-requests:
+ require.Contains(t, body, "consolidated delivery")
+ default:
+ t.Fatal("notification was not delivered to the HTTP server")
+ }
+ })
+ }
+}
+
+func TestSendShoutrrrConstructionErrorInternal(t *testing.T) {
+ err := sendShoutrrrInternal("Slack", "unsupported-provider://localhost", "message", nil)
+ require.ErrorContains(t, err, "failed to create shoutrrr Slack sender")
+}
diff --git a/backend/pkg/utils/notifications/signal_sender.go b/backend/pkg/utils/notifications/signal_sender.go
index 61e69c751..031843d9d 100644
--- a/backend/pkg/utils/notifications/signal_sender.go
+++ b/backend/pkg/utils/notifications/signal_sender.go
@@ -5,9 +5,7 @@ import (
"emperror.dev/errors"
- "github.com/nicholas-fedor/shoutrrr"
"github.com/nicholas-fedor/shoutrrr/pkg/services/chat/signal"
- shoutrrrTypes "github.com/nicholas-fedor/shoutrrr/pkg/types"
)
// BuildSignalURL converts SignalConfig to Shoutrrr URL format using shoutrrr's Config
@@ -57,16 +55,5 @@ func SendSignal(ctx context.Context, config SignalConfig, message string) error
return errors.WrapIf(err, "failed to build shoutrrr Signal URL")
}
- sender, err := shoutrrr.CreateSenderWithOptions(shoutrrrTypes.SenderOptions{}, shoutrrrURL)
- if err != nil {
- return errors.WrapIf(err, "failed to create shoutrrr Signal sender")
- }
-
- errs := sender.Send(message, nil)
- for _, err := range errs {
- if err != nil {
- return errors.WrapIf(err, "failed to send Signal message via shoutrrr")
- }
- }
- return nil
+ return sendShoutrrrInternal("Signal", shoutrrrURL, message, nil)
}
diff --git a/backend/pkg/utils/notifications/slack_sender.go b/backend/pkg/utils/notifications/slack_sender.go
index f54512bd6..a0b2b2f48 100644
--- a/backend/pkg/utils/notifications/slack_sender.go
+++ b/backend/pkg/utils/notifications/slack_sender.go
@@ -5,9 +5,7 @@ import (
"emperror.dev/errors"
- "github.com/nicholas-fedor/shoutrrr"
"github.com/nicholas-fedor/shoutrrr/pkg/services/chat/slack"
- shoutrrrTypes "github.com/nicholas-fedor/shoutrrr/pkg/types"
)
// BuildSlackURL converts SlackConfig to Shoutrrr URL format using shoutrrr's Config
@@ -47,16 +45,5 @@ func SendSlack(ctx context.Context, config SlackConfig, message string) error {
return errors.WrapIf(err, "failed to build shoutrrr Slack URL")
}
- sender, err := shoutrrr.CreateSenderWithOptions(shoutrrrTypes.SenderOptions{}, shoutrrrURL)
- if err != nil {
- return errors.WrapIf(err, "failed to create shoutrrr Slack sender")
- }
-
- errs := sender.Send(message, nil)
- for _, err := range errs {
- if err != nil {
- return errors.WrapIf(err, "failed to send Slack message via shoutrrr")
- }
- }
- return nil
+ return sendShoutrrrInternal("Slack", shoutrrrURL, message, nil)
}
diff --git a/backend/pkg/utils/notifications/telegram_sender.go b/backend/pkg/utils/notifications/telegram_sender.go
index 1ee21d8ec..bbd7addba 100644
--- a/backend/pkg/utils/notifications/telegram_sender.go
+++ b/backend/pkg/utils/notifications/telegram_sender.go
@@ -5,9 +5,7 @@ import (
"emperror.dev/errors"
- "github.com/nicholas-fedor/shoutrrr"
"github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram"
- shoutrrrTypes "github.com/nicholas-fedor/shoutrrr/pkg/types"
)
// BuildTelegramURL converts TelegramConfig to Shoutrrr URL format using shoutrrr's Config
@@ -52,16 +50,5 @@ func SendTelegram(ctx context.Context, config TelegramConfig, message string) er
return errors.WrapIf(err, "failed to build shoutrrr Telegram URL")
}
- sender, err := shoutrrr.CreateSenderWithOptions(shoutrrrTypes.SenderOptions{}, shoutrrrURL)
- if err != nil {
- return errors.WrapIf(err, "failed to create shoutrrr Telegram sender")
- }
-
- errs := sender.Send(message, nil)
- for _, err := range errs {
- if err != nil {
- return errors.WrapIf(err, "failed to send Telegram message via shoutrrr")
- }
- }
- return nil
+ return sendShoutrrrInternal("Telegram", shoutrrrURL, message, nil)
}
diff --git a/backend/pkg/utils/notifications/utils.go b/backend/pkg/utils/notifications/utils.go
index faf9ea3c9..f27b3f3c0 100644
--- a/backend/pkg/utils/notifications/utils.go
+++ b/backend/pkg/utils/notifications/utils.go
@@ -1,6 +1,12 @@
package notifications
-import "strings"
+import (
+ "strings"
+
+ "emperror.dev/errors"
+ "github.com/nicholas-fedor/shoutrrr"
+ shoutrrrTypes "github.com/nicholas-fedor/shoutrrr/pkg/types"
+)
// SanitizeForEmail sanitizes text for safe use in email subjects
func SanitizeForEmail(text string) string {
@@ -12,3 +18,16 @@ func SanitizeForEmail(text string) string {
// Trim whitespace
return strings.TrimSpace(text)
}
+
+func sendShoutrrrInternal(provider, destinationURL, message string, params *shoutrrrTypes.Params) error {
+ sender, err := shoutrrr.CreateSenderWithOptions(shoutrrrTypes.SenderOptions{}, destinationURL)
+ if err != nil {
+ return errors.WrapIff(err, "failed to create shoutrrr %s sender", provider)
+ }
+ for _, err := range sender.Send(message, params) {
+ if err != nil {
+ return errors.WrapIff(err, "failed to send %s message via shoutrrr", provider)
+ }
+ }
+ return nil
+}
diff --git a/backend/pkg/utils/strings_test.go b/backend/pkg/utils/strings_test.go
index 6ce7f0b18..730fdaf76 100644
--- a/backend/pkg/utils/strings_test.go
+++ b/backend/pkg/utils/strings_test.go
@@ -84,3 +84,17 @@ func TestTrimQuotes(t *testing.T) {
})
}
}
+
+func TestUniqueNonEmptyStrings(t *testing.T) {
+ for _, tt := range []struct {
+ name string
+ input, want []string
+ }{
+ {name: "nil"},
+ {name: "empty tokens", input: []string{"", " \t "}},
+ {name: "stable order and case", input: []string{" beta ", "alpha", "beta", "Alpha", ""}, want: []string{"beta", "alpha", "Alpha"}},
+ {name: "does not split values", input: []string{"a,b", "a b"}, want: []string{"a,b", "a b"}},
+ } {
+ t.Run(tt.name, func(t *testing.T) { assert.Equal(t, tt.want, UniqueNonEmptyStrings(tt.input)) })
+ }
+}