Skip to content

Commit 61c5b8a

Browse files
refactor(backend): drop Env config field — not needed yet (#10)
Per review on #14: AO_ENV / Config.Env / IsProduction() weren't load-bearing for Phase 1a — they only switched the slog handler. Removing them now keeps the surface minimal; the env knob can come back later when a real consumer needs it. - config: remove Env field, AO_ENV parsing, and IsProduction helper. - main: collapse newLogger to a single text-handler path. - httpd: drop the env field from the listening log line. - tests: drop the env assertions and AO_ENV fixture. Co-Authored-By: Claude Opus 4.7 <[email protected]>
1 parent a86ae08 commit 61c5b8a

5 files changed

Lines changed: 7 additions & 29 deletions

File tree

‎backend/internal/config/config.go‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@ type Config struct {
3434
Host string
3535
// Port is the TCP port to bind. The daemon fails fast if it is taken.
3636
Port int
37-
// Env is the deployment environment label ("development" | "production").
38-
// It only affects log verbosity / formatting, never bind behaviour.
39-
Env string
4037
// RequestTimeout bounds REST request handling.
4138
RequestTimeout time.Duration
4239
// ShutdownTimeout is the hard graceful-shutdown deadline.
@@ -51,9 +48,6 @@ func (c Config) Addr() string {
5148
return fmt.Sprintf("%s:%d", c.Host, c.Port)
5249
}
5350

54-
// IsProduction reports whether the daemon is running in production mode.
55-
func (c Config) IsProduction() bool { return c.Env == "production" }
56-
5751
// Load resolves configuration from the environment, applying defaults. It
5852
// returns an error only for values that are present but malformed (e.g. a
5953
// non-numeric AO_PORT); missing values fall back to defaults.
@@ -62,15 +56,13 @@ func (c Config) IsProduction() bool { return c.Env == "production" }
6256
//
6357
// AO_HOST bind host (default 127.0.0.1)
6458
// AO_PORT bind port (default 3001)
65-
// AO_ENV environment label (default development)
6659
// AO_REQUEST_TIMEOUT per-request timeout (Go duration, default 60s)
6760
// AO_SHUTDOWN_TIMEOUT shutdown deadline (Go duration, default 10s)
6861
// AO_RUN_FILE running.json path (default <state-dir>/running.json)
6962
func Load() (Config, error) {
7063
cfg := Config{
7164
Host: getEnv("AO_HOST", DefaultHost),
7265
Port: DefaultPort,
73-
Env: getEnv("AO_ENV", "development"),
7466
RequestTimeout: DefaultRequestTimeout,
7567
ShutdownTimeout: DefaultShutdownTimeout,
7668
}

‎backend/internal/config/config_test.go‎

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
func TestLoadDefaults(t *testing.T) {
99
// Clear every recognised var so we observe pure defaults regardless of the
1010
// surrounding environment.
11-
for _, k := range []string{"AO_HOST", "AO_PORT", "AO_ENV", "AO_REQUEST_TIMEOUT", "AO_SHUTDOWN_TIMEOUT", "AO_RUN_FILE"} {
11+
for _, k := range []string{"AO_HOST", "AO_PORT", "AO_REQUEST_TIMEOUT", "AO_SHUTDOWN_TIMEOUT", "AO_RUN_FILE"} {
1212
t.Setenv(k, "")
1313
}
1414

@@ -22,9 +22,6 @@ func TestLoadDefaults(t *testing.T) {
2222
if cfg.Port != DefaultPort {
2323
t.Errorf("Port = %d, want %d", cfg.Port, DefaultPort)
2424
}
25-
if cfg.Env != "development" {
26-
t.Errorf("Env = %q, want development", cfg.Env)
27-
}
2825
if cfg.RequestTimeout != DefaultRequestTimeout {
2926
t.Errorf("RequestTimeout = %s, want %s", cfg.RequestTimeout, DefaultRequestTimeout)
3027
}
@@ -34,15 +31,11 @@ func TestLoadDefaults(t *testing.T) {
3431
if cfg.RunFilePath == "" {
3532
t.Error("RunFilePath is empty, want a resolved default path")
3633
}
37-
if cfg.IsProduction() {
38-
t.Error("IsProduction() = true for development env")
39-
}
4034
}
4135

4236
func TestLoadOverrides(t *testing.T) {
4337
t.Setenv("AO_HOST", "127.0.0.2")
4438
t.Setenv("AO_PORT", "4002")
45-
t.Setenv("AO_ENV", "production")
4639
t.Setenv("AO_REQUEST_TIMEOUT", "5s")
4740
t.Setenv("AO_SHUTDOWN_TIMEOUT", "3s")
4841
t.Setenv("AO_RUN_FILE", "/tmp/ao-test-running.json")
@@ -54,9 +47,6 @@ func TestLoadOverrides(t *testing.T) {
5447
if cfg.Addr() != "127.0.0.2:4002" {
5548
t.Errorf("Addr() = %q, want 127.0.0.2:4002", cfg.Addr())
5649
}
57-
if !cfg.IsProduction() {
58-
t.Error("IsProduction() = false, want true")
59-
}
6050
if cfg.RequestTimeout != 5*time.Second {
6151
t.Errorf("RequestTimeout = %s, want 5s", cfg.RequestTimeout)
6252
}

‎backend/internal/httpd/server.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func (s *Server) Run(ctx context.Context) error {
7373

7474
serveErr := make(chan error, 1)
7575
go func() {
76-
s.log.Info("daemon listening", "addr", s.Addr().String(), "pid", info.PID, "env", s.cfg.Env)
76+
s.log.Info("daemon listening", "addr", s.Addr().String(), "pid", info.PID)
7777
// Serve returns ErrServerClosed on a clean Shutdown; that is success.
7878
if err := s.http.Serve(s.listen); err != nil && !errors.Is(err, http.ErrServerClosed) {
7979
serveErr <- err

‎backend/internal/httpd/server_test.go‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ func TestServerLifecycle(t *testing.T) {
4646
cfg := config.Config{
4747
Host: "127.0.0.1",
4848
Port: 0, // let the OS pick a free port — no conflict with a real daemon
49-
Env: "development",
5049
ShutdownTimeout: 5 * time.Second,
5150
RunFilePath: runPath,
5251
}

‎backend/main.go‎

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func run() error {
3030
return err
3131
}
3232

33-
log := newLogger(cfg)
33+
log := newLogger()
3434

3535
// Fail fast if a live daemon already owns the handshake file. A run-file
3636
// left by a crashed predecessor (dead PID) is treated as stale and
@@ -54,12 +54,9 @@ func run() error {
5454
return srv.Run(ctx)
5555
}
5656

57-
// newLogger returns a text logger in development and JSON in production. The
58-
// daemon logs to stderr so the Electron supervisor can capture it separately
59-
// from any structured stdout protocol added later.
60-
func newLogger(cfg config.Config) *slog.Logger {
61-
if cfg.IsProduction() {
62-
return slog.New(slog.NewJSONHandler(os.Stderr, nil))
63-
}
57+
// newLogger returns the daemon's slog logger. It writes to stderr so the
58+
// Electron supervisor can capture it separately from any structured stdout
59+
// protocol added later.
60+
func newLogger() *slog.Logger {
6461
return slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: slog.LevelDebug}))
6562
}

0 commit comments

Comments
 (0)