Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ require (
golang.org/x/text v0.34.0 // indirect
)

replace github.com/adcondev/poster => ../poster
replace github.com/adcondev/poster => ./mock_poster

Copilot AI Feb 19, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change from ../poster to ./mock_poster appears unintentional and problematic. The original ../poster replace directive suggests a local development setup with the poster repository located alongside this one. Changing it to ./mock_poster would expect a mock_poster directory in the current repository root, which doesn't appear to exist based on the directory listing.

This change will break builds unless:

  1. A mock_poster directory exists in the repository (not shown in the PR)
  2. This is meant to be temporary for testing purposes only

If this change was intentional for testing, it should not be committed to the main branch. If it was accidental (perhaps made to enable local testing), it should be reverted to ../poster.

Suggested change
replace github.com/adcondev/poster => ./mock_poster
replace github.com/adcondev/poster => ../poster

Copilot uses AI. Check for mistakes.
39 changes: 21 additions & 18 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ type Environment struct {
Verbose bool

// Impresora
DefaultPrinter string
DefaultPrinter string
PrinterCacheTTL time.Duration

Copilot AI Feb 19, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new field PrinterCacheTTL lacks documentation. Following Go conventions and consistency with other fields in this struct, consider adding a comment explaining its purpose. For example:

// Impresora
DefaultPrinter  string        // Default printer name for print jobs
PrinterCacheTTL time.Duration // Duration to cache printer discovery results

This improves code maintainability and helps other developers understand the configuration options.

Suggested change
PrinterCacheTTL time.Duration
PrinterCacheTTL time.Duration // Duration to cache printer discovery results

Copilot uses AI. Check for mistakes.
}

// LogPath returns the full log file path for this environment.
Expand All @@ -55,26 +56,28 @@ func (e Environment) LogPath(programData string) string {
// environments defines available deployment configurations
var environments = map[string]Environment{
"remote": {
Name: "REMOTO",
ServiceName: ServiceName,
ListenAddr: "0.0.0.0:" + ServerPort,
ReadTimeout: 15 * time.Second,
WriteTimeout: 15 * time.Second,
IdleTimeout: 60 * time.Second,
QueueCapacity: 50,
Verbose: false,
DefaultPrinter: "",
Name: "REMOTO",
ServiceName: ServiceName,
ListenAddr: "0.0.0.0:" + ServerPort,
ReadTimeout: 15 * time.Second,
WriteTimeout: 15 * time.Second,
IdleTimeout: 60 * time.Second,
QueueCapacity: 50,
Verbose: false,
DefaultPrinter: "",
PrinterCacheTTL: 30 * time.Second,
},
"local": {
Name: "LOCAL",
ServiceName: ServiceName,
ListenAddr: "localhost:" + ServerPort,
ReadTimeout: 30 * time.Second,
WriteTimeout: 30 * time.Second,
Name: "LOCAL",
ServiceName: ServiceName,
ListenAddr: "localhost:" + ServerPort,
ReadTimeout: 30 * time.Second,
WriteTimeout: 30 * time.Second,
IdleTimeout: 120 * time.Second,
QueueCapacity: 50,
Verbose: true,
DefaultPrinter: "58mm PT-210",
QueueCapacity: 50,
Verbose: true,
DefaultPrinter: "58mm PT-210",
PrinterCacheTTL: 30 * time.Second,
},
}

Expand Down
2 changes: 1 addition & 1 deletion internal/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (p *Program) Start() error {
// Initialize auth manager (bound to service context for clean shutdown)
p.authMgr = auth.NewManager(p.ctx)

p.printerDiscovery = NewPrinterDiscovery()
p.printerDiscovery = NewPrinterDiscovery(cfg.PrinterCacheTTL)
p.printerDiscovery.LogStartupDiagnostics()

// Initialize WebSocket server
Expand Down
4 changes: 2 additions & 2 deletions internal/daemon/printer_discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ type PrinterDiscovery struct {
}

// NewPrinterDiscovery creates a new discovery service
func NewPrinterDiscovery() *PrinterDiscovery {
func NewPrinterDiscovery(cacheTTL time.Duration) *PrinterDiscovery {
return &PrinterDiscovery{
cacheTTL: 30 * time.Second,
cacheTTL: cacheTTL,
}
}

Expand Down
14 changes: 14 additions & 0 deletions internal/daemon/printer_discovery_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package daemon

import (
"testing"
"time"
)

func TestNewPrinterDiscovery(t *testing.T) {
ttl := 10 * time.Second
pd := NewPrinterDiscovery(ttl)
if pd.cacheTTL != ttl {
t.Errorf("expected cacheTTL %v, got %v", ttl, pd.cacheTTL)
Comment on lines +11 to +12

Copilot AI Feb 19, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test is accessing the unexported field cacheTTL directly. In Go, tests in the same package can access unexported fields, but this creates tight coupling between the test and implementation details. Consider either:

  1. Making cacheTTL an exported field (CacheTTL) if it's intended to be observable
  2. Adding a getter method like GetCacheTTL() time.Duration to PrinterDiscovery
  3. Testing the behavior indirectly through the public API (though this may be harder for a simple TTL value)

Since this is a simple configuration value and the test verifies correct initialization, making it exported or adding a getter would be appropriate.

Suggested change
if pd.cacheTTL != ttl {
t.Errorf("expected cacheTTL %v, got %v", ttl, pd.cacheTTL)
if pd == nil {
t.Errorf("expected non-nil PrinterDiscovery from NewPrinterDiscovery")

Copilot uses AI. Check for mistakes.
}
}
Loading