refactor(brokeripc): move test-only SocketDir out of production
- commit
- 2d72cbf9c4a1bcc133f2d44fe4364051b4484568
- author
- brice · · 2026-09-23 12:11 UTC
- parent
- f2870bb
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
3 files · +13 -10
M internal/adapters/brokeripc/export_test.go +11 -0
| @@ -1,5 +1,9 @@ | |||
| 1 | 1 | package brokeripc | |
| 2 | 2 | ||
| 3 | + | import ( | |
| 4 | + | "github.com/bnema/vev/internal/adapters/ipc" | |
| 5 | + | ) | |
| 6 | + | ||
| 3 | 7 | // Test-only accessors (export_test.go pattern): these observe listener | |
| 4 | 8 | // internals that only this package's own tests need. They are kept out of | |
| 5 | 9 | // the production build so a live server's diagnostics or capacity never | |
| @@ -32,3 +36,10 @@ func (l *listener) liveSessions() int { | |||
| 32 | 36 | // convenience default runtime directory, for tests that need it without | |
| 33 | 37 | // composing SocketPath(SocketDir()) themselves. | |
| 34 | 38 | func DefaultSocketPath() string { return SocketPath(SocketDir()) } | |
| 39 | + | ||
| 40 | + | // SocketDir returns the per-user directory the broker endpoint belongs in: | |
| 41 | + | // $XDG_RUNTIME_DIR/vev when set, else /run/user/<uid>/vev when that directory | |
| 42 | + | // exists, else /tmp/vev-<uid>. It is the daemon's per-user runtime directory as | |
| 43 | + | // well, so both endpoints share one owner-only directory while keeping | |
| 44 | + | // distinct socket names. | |
| 45 | + | func SocketDir() string { return ipc.SocketDir() } | |
| @@ -1,5 +1,9 @@ | |||||
| 1 | package brokeripc | 1 | package brokeripc | ||
| 2 | 2 | ||||
| 3 | + | import ( | |||
| 4 | + | "github.com/bnema/vev/internal/adapters/ipc" | |||
| 5 | + | ) | |||
| 6 | + | ||||
| 3 | // Test-only accessors (export_test.go pattern): these observe listener | 7 | // Test-only accessors (export_test.go pattern): these observe listener | ||
| 4 | // internals that only this package's own tests need. They are kept out of | 8 | // internals that only this package's own tests need. They are kept out of | ||
| 5 | // the production build so a live server's diagnostics or capacity never | 9 | // the production build so a live server's diagnostics or capacity never | ||
| @@ -32,3 +36,10 @@ func (l *listener) liveSessions() int { | |||||
| 32 | // convenience default runtime directory, for tests that need it without | 36 | // convenience default runtime directory, for tests that need it without | ||
| 33 | // composing SocketPath(SocketDir()) themselves. | 37 | // composing SocketPath(SocketDir()) themselves. | ||
| 34 | func DefaultSocketPath() string { return SocketPath(SocketDir()) } | 38 | func DefaultSocketPath() string { return SocketPath(SocketDir()) } | ||
| 39 | + | ||||
| 40 | + | // SocketDir returns the per-user directory the broker endpoint belongs in: | |||
| 41 | + | // $XDG_RUNTIME_DIR/vev when set, else /run/user/<uid>/vev when that directory | |||
| 42 | + | // exists, else /tmp/vev-<uid>. It is the daemon's per-user runtime directory as | |||
| 43 | + | // well, so both endpoints share one owner-only directory while keeping | |||
| 44 | + | // distinct socket names. | |||
| 45 | + | func SocketDir() string { return ipc.SocketDir() } | |||
M internal/adapters/brokeripc/socket.go +0 -9
| @@ -2,8 +2,6 @@ package brokeripc | |||
| 2 | 2 | ||
| 3 | 3 | import ( | |
| 4 | 4 | "path/filepath" | |
| 5 | - | ||
| 6 | - | "github.com/bnema/vev/internal/adapters/ipc" | |
| 7 | 5 | ) | |
| 8 | 6 | ||
| 9 | 7 | // SocketFileName is the fixed name of the per-user broker IPC socket inside its | |
| @@ -16,10 +14,3 @@ const SocketFileName = "broker.sock" | |||
| 16 | 14 | func SocketPath(runtimeDir string) string { | |
| 17 | 15 | return filepath.Join(runtimeDir, SocketFileName) | |
| 18 | 16 | } | |
| 19 | - | ||
| 20 | - | // SocketDir returns the per-user directory the broker endpoint belongs in: | |
| 21 | - | // $XDG_RUNTIME_DIR/vev when set, else /run/user/<uid>/vev when that directory | |
| 22 | - | // exists, else /tmp/vev-<uid>. It is the daemon's per-user runtime directory as | |
| 23 | - | // well, so both endpoints share one owner-only directory while keeping | |
| 24 | - | // distinct socket names. | |
| 25 | - | func SocketDir() string { return ipc.SocketDir() } | |
| @@ -2,8 +2,6 @@ package brokeripc | |||||
| 2 | 2 | ||||
| 3 | import ( | 3 | import ( | ||
| 4 | "path/filepath" | 4 | "path/filepath" | ||
| 5 | - | ||||
| 6 | - | "github.com/bnema/vev/internal/adapters/ipc" | |||
| 7 | ) | 5 | ) | ||
| 8 | 6 | ||||
| 9 | // SocketFileName is the fixed name of the per-user broker IPC socket inside its | 7 | // SocketFileName is the fixed name of the per-user broker IPC socket inside its | ||
| @@ -16,10 +14,3 @@ const SocketFileName = "broker.sock" | |||||
| 16 | func SocketPath(runtimeDir string) string { | 14 | func SocketPath(runtimeDir string) string { | ||
| 17 | return filepath.Join(runtimeDir, SocketFileName) | 15 | return filepath.Join(runtimeDir, SocketFileName) | ||
| 18 | } | 16 | } | ||
| 19 | - | ||||
| 20 | - | // SocketDir returns the per-user directory the broker endpoint belongs in: | |||
| 21 | - | // $XDG_RUNTIME_DIR/vev when set, else /run/user/<uid>/vev when that directory | |||
| 22 | - | // exists, else /tmp/vev-<uid>. It is the daemon's per-user runtime directory as | |||
| 23 | - | // well, so both endpoints share one owner-only directory while keeping | |||
| 24 | - | // distinct socket names. | |||
| 25 | - | func SocketDir() string { return ipc.SocketDir() } | |||
M internal/app/broker_offline_status_test.go +2 -1
| @@ -17,6 +17,7 @@ import ( | |||
| 17 | 17 | ||
| 18 | 18 | "github.com/bnema/vev/internal/adapters/brokerconfig" | |
| 19 | 19 | "github.com/bnema/vev/internal/adapters/brokeripc" | |
| 20 | + | "github.com/bnema/vev/internal/adapters/ipc" | |
| 20 | 21 | "github.com/bnema/vev/internal/adapters/lifecycle" | |
| 21 | 22 | ) | |
| 22 | 23 | ||
| @@ -444,7 +445,7 @@ func TestBrokerStatusEnsureRejectsUnsafeRoot(t *testing.T) { | |||
| 444 | 445 | root string | |
| 445 | 446 | }{ | |
| 446 | 447 | {name: "relative root", root: "relative"}, | |
| 447 | - | {name: "production overlap", root: brokeripc.SocketDir()}, | |
| 448 | + | {name: "production overlap", root: ipc.SocketDir()}, | |
| 448 | 449 | } | |
| 449 | 450 | for _, tt := range tests { | |
| 450 | 451 | t.Run(tt.name, func(t *testing.T) { | |
| @@ -17,6 +17,7 @@ import ( | |||||
| 17 | 17 | ||||
| 18 | "github.com/bnema/vev/internal/adapters/brokerconfig" | 18 | "github.com/bnema/vev/internal/adapters/brokerconfig" | ||
| 19 | "github.com/bnema/vev/internal/adapters/brokeripc" | 19 | "github.com/bnema/vev/internal/adapters/brokeripc" | ||
| 20 | + | "github.com/bnema/vev/internal/adapters/ipc" | |||
| 20 | "github.com/bnema/vev/internal/adapters/lifecycle" | 21 | "github.com/bnema/vev/internal/adapters/lifecycle" | ||
| 21 | ) | 22 | ) | ||
| 22 | 23 | ||||
| @@ -444,7 +445,7 @@ func TestBrokerStatusEnsureRejectsUnsafeRoot(t *testing.T) { | |||||
| 444 | root string | 445 | root string | ||
| 445 | }{ | 446 | }{ | ||
| 446 | {name: "relative root", root: "relative"}, | 447 | {name: "relative root", root: "relative"}, | ||
| 447 | - | {name: "production overlap", root: brokeripc.SocketDir()}, | 448 | + | {name: "production overlap", root: ipc.SocketDir()}, |
| 448 | } | 449 | } | ||
| 449 | for _, tt := range tests { | 450 | for _, tt := range tests { | ||
| 450 | t.Run(tt.name, func(t *testing.T) { | 451 | t.Run(tt.name, func(t *testing.T) { | ||