Skip to content

Self-hosted workflows for coding-agent delivery. Orchestrate CodeBuddy, Codex and Claude Code with scripts and human approval gates. Includes Local workflows for coding assistants.

refactor(auth): flatten NormalizePhotoSpec into a single-level switch (#517) (#518)

fx-kurumibb835c205936
diff --git a/internal/auth/photo.go b/internal/auth/photo.go
index 582e9e18..0416f2b5 100644
--- a/internal/auth/photo.go
+++ b/internal/auth/photo.go
@@ -30,22 +30,13 @@ func NormalizePhotoSpec(spec int) int {
switch {
case spec <= 0:
return 100
- case spec <= 48:
+ case spec <= 74:
return 48
- case spec <= 100:
- if spec <= 74 {
- return 48
- }
+ case spec <= 125:
return 100
- case spec <= 150:
- if spec <= 125 {
- return 100
- }
+ case spec <= 300:
return 150
default:
- if spec <= 300 {
- return 150
- }
return 500
}
}
diff --git a/internal/auth/photo_spec_boundaries_test.go b/internal/auth/photo_spec_boundaries_test.go
new file mode 100644
index 00000000..5dfa17ee
--- /dev/null
+++ b/internal/auth/photo_spec_boundaries_test.go
@@ -0,0 +1,50 @@
+package auth
+
+import "testing"
+
+// legacyNormalizePhotoSpec is the pre-refactor nested implementation, kept
+// here only to prove the flattened switch returns identical values.
+func legacyNormalizePhotoSpec(spec int) int {
+ switch {
+ case spec <= 0:
+ return 100
+ case spec <= 48:
+ return 48
+ case spec <= 100:
+ if spec <= 74 {
+ return 48
+ }
+ return 100
+ case spec <= 150:
+ if spec <= 125 {
+ return 100
+ }
+ return 150
+ default:
+ if spec <= 300 {
+ return 150
+ }
+ return 500
+ }
+}
+
+func TestNormalizePhotoSpecBoundaries(t *testing.T) {
+ tests := []struct{ input, want int }{
+ {-1, 100}, {0, 100}, {1, 48}, {48, 48}, {74, 48}, {75, 100},
+ {100, 100}, {125, 100}, {126, 150}, {150, 150}, {300, 150},
+ {301, 500}, {500, 500}, {10000, 500},
+ }
+ for _, tt := range tests {
+ if got := NormalizePhotoSpec(tt.input); got != tt.want {
+ t.Errorf("NormalizePhotoSpec(%d) = %d, want %d", tt.input, got, tt.want)
+ }
+ }
+}
+
+func TestNormalizePhotoSpecMatchesLegacy(t *testing.T) {
+ for spec := -1000; spec <= 1000; spec++ {
+ if got, want := NormalizePhotoSpec(spec), legacyNormalizePhotoSpec(spec); got != want {
+ t.Fatalf("NormalizePhotoSpec(%d) = %d, legacy = %d", spec, got, want)
+ }
+ }
+}