diff --git a/internal/channels/telegram/media_test.go b/internal/channels/telegram/media_test.go index b3c6b9bde..8edd297d2 100644 --- a/internal/channels/telegram/media_test.go +++ b/internal/channels/telegram/media_test.go @@ -16,6 +16,7 @@ import ( "github.com/go-telegram/bot" "github.com/samcharles93/archie-core/internal/gateway" + "github.com/samcharles93/archie-core/internal/tools/sendfile" ) // mediaAPI stands in for the Bot API, recording which sendX method was @@ -450,6 +451,22 @@ func TestSendMedia_LocalPathFailures(t *testing.T) { } } +// TestMediaUploadCeilingsAgreeWithSendFile pins the contract documented in +// sendfile/tool.go: the send_file early check and this sender's Bot API +// ceilings must be the same number, or an oversized file is reported "sent" +// by the tool and then silently rejected here -- the exact silent +// non-delivery send_file exists to end. +func TestMediaUploadCeilingsAgreeWithSendFile(t *testing.T) { + if sendfile.MaxImageUploadBytes != maxPhotoUploadBytes { + t.Errorf("send_file image ceiling = %d bytes, telegram photo ceiling = %d bytes; they must agree", + sendfile.MaxImageUploadBytes, maxPhotoUploadBytes) + } + if sendfile.MaxUploadBytes != maxFileUploadBytes { + t.Errorf("send_file upload ceiling = %d bytes, telegram file ceiling = %d bytes; they must agree", + sendfile.MaxUploadBytes, maxFileUploadBytes) + } +} + // A photo just under the photo ceiling must still be accepted -- the // per-type limits must not collapse into one conservative number. func TestSendMedia_PhotoUnderLimitIsSent(t *testing.T) { diff --git a/internal/infrastructure/servicediscovery/nats/registry.go b/internal/infrastructure/servicediscovery/nats/registry.go index 99582d7a6..7a7d39b4e 100644 --- a/internal/infrastructure/servicediscovery/nats/registry.go +++ b/internal/infrastructure/servicediscovery/nats/registry.go @@ -45,10 +45,10 @@ type Client struct { // On any failure the partially-built connection is closed before returning, so // a failed Connect leaks nothing. func Connect(ctx context.Context, cfg Config, log *slog.Logger) (*Client, error) { + cfg = cfg.withDefaults() if err := cfg.Validate(); err != nil { return nil, err } - cfg = cfg.withDefaults() if log == nil { log = slog.New(slog.DiscardHandler) } diff --git a/internal/infrastructure/servicediscovery/nats/registry_test.go b/internal/infrastructure/servicediscovery/nats/registry_test.go index 1b7f56b1a..c369a1e14 100644 --- a/internal/infrastructure/servicediscovery/nats/registry_test.go +++ b/internal/infrastructure/servicediscovery/nats/registry_test.go @@ -23,6 +23,17 @@ func testConfig() Config { return Config{TTL: time.Second, Heartbeat: 200 * time.Millisecond} } +// TestConnectRejectsTTLBelowDefaultHeartbeat pins the Connect ordering: a +// caller that sets TTL below DefaultHeartbeat and leaves Heartbeat unset must +// be refused as ErrInvalidConfig, not silently given a registry whose live +// entries expire between refreshes (DefaultHeartbeat >= TTL). +func TestConnectRejectsTTLBelowDefaultHeartbeat(t *testing.T) { + _, err := Connect(context.Background(), Config{URL: "nats://127.0.0.1:1", TTL: 2 * time.Second}, discardLogger()) + if !errors.Is(err, ErrInvalidConfig) { + t.Fatalf("Connect() = %v, want ErrInvalidConfig", err) + } +} + // newServer starts a real in-process NATS server with JetStream enabled. This // is the established test technique for the NATS infrastructure (see the // sibling eventbus/nats retention test): a real server, not a mocked client. diff --git a/internal/releaseupdate/service.go b/internal/releaseupdate/service.go index c48effffd..48b2b453d 100644 --- a/internal/releaseupdate/service.go +++ b/internal/releaseupdate/service.go @@ -147,7 +147,7 @@ func (s *Service) Check(ctx context.Context, recipient int64) (Snapshot, error) deferred := state[strconv.FormatInt(recipient, 10)] for index := range snapshot.Components { component := &snapshot.Components[index] - if deferred[component.ID] == component.Available { + if component.Available != "" && deferred[component.ID] == component.Available { component.Available = "" snapshot.Deferred = true } diff --git a/internal/releaseupdate/service_test.go b/internal/releaseupdate/service_test.go index c56332b4e..28604291a 100644 --- a/internal/releaseupdate/service_test.go +++ b/internal/releaseupdate/service_test.go @@ -50,6 +50,30 @@ func TestServiceDefersOnlyTheVersionsShownToThatRecipient(t *testing.T) { } } +// TestServiceCheckNeverDeferredEmptyAvailable pins the empty-Available +// combination: for a recipient who has never deferred a component (or a +// component absent from the deferral map), deferred[component.ID] is the +// empty string, and a component with no available update also has an empty +// Available. "" == "" must not read as a deferral -- that tells an +// up-to-date recipient their update is "deferred". +func TestServiceCheckNeverDeferredEmptyAvailable(t *testing.T) { + catalog := &catalogStub{snapshot: Snapshot{Components: []Component{ + {ID: ComponentDaemon, Label: "Gateway", Installed: "1.0.0", Available: ""}, + }}} + service := Service{Catalog: catalog, StatePath: filepath.Join(t.TempDir(), "deferrals.json")} + + snapshot, err := service.Check(context.Background(), 42) + if err != nil { + t.Fatal(err) + } + if snapshot.Deferred { + t.Error("Deferred = true for a never-deferred recipient with no available update") + } + if got := snapshot.Components[0].Available; got != "" { + t.Errorf("Available = %q, want empty", got) + } +} + // TestServiceCheckEnrichesInstallTypeAndReference is the regression proof // for archie-core-1786751948782-3-837a8fd0 point 4: the external check // command reports what version exists, not how this instance was actually