test(portal): prune weak contract tests

cognitive committed Apr 30, 2026 at 00:08 UTC 0bcf905105d49eb6e7cc11de7006c31380076fd4
3 files changed +37 -53
portal/acme/cloudflare/provider_test.go
+6 -3
@@ -9,8 +9,11 @@ func TestChallengeProviderRequiresToken(t *testing.T) {
9 t.Parallel()
10
11 provider := New("")
12 - _, err := provider.ChallengeProvider(context.Background())
13 - if err == nil {
14 - t.Fatal("ChallengeProvider() error = nil, want error")
12 + challengeProvider, err := provider.ChallengeProvider(context.Background())
13 + if challengeProvider != nil {
14 + t.Fatalf("ChallengeProvider() provider = %T, want nil", challengeProvider)
15 + }
16 + if err == nil || err.Error() != "cloudflare token is required" {
17 + t.Fatalf("ChallengeProvider() error = %v, want local token error", err)
18 }
19 }
portal/discovery/mols_test.go
+15 -47
@@ -328,8 +328,8 @@ func TestMOLSSelectPriorityCongestionSwitchChangesOrder(t *testing.T) {
328 }
329
330 // TestMOLSSelectPriorityVariantGridActivatesOnHighCV confirms that a high
331 -// coefficient of variation triggers the variant multipliers (7, 11) rather than
332 -// the base (3, 5), producing a different relay ordering from the base grid.
331 +// coefficient of variation triggers the variant multipliers (7, 11) while the
332 +// mean RTT stays below the congestion threshold.
333 func TestMOLSSelectPriorityVariantGridActivatesOnHighCV(t *testing.T) {
334 policy := MOLSRelayPolicy{}
335
@@ -341,19 +341,23 @@ func TestMOLSSelectPriorityVariantGridActivatesOnHighCV(t *testing.T) {
341 LocalAddress: "ingress-cv",
342 })
343
344 - // High-CV mode: very different RTTs that push CV well above 0.5.
344 + // High-CV mode: very different RTTs push CV above 0.5 while the mean stays
345 + // below the congestion threshold, isolating the variant-grid branch.
346 r1v := r1
346 - r1v.DiscoveryRTT = 10 * time.Millisecond
347 + r1v.DiscoveryRTT = 100 * time.Millisecond
348 r1v.DiscoveryRTTAt = time.Now()
349 r2v := r2
349 - r2v.DiscoveryRTT = 5000 * time.Millisecond
350 + r2v.DiscoveryRTT = 400 * time.Millisecond
351 r2v.DiscoveryRTTAt = time.Now()
352
353 // Verify high-CV state is actually detected.
353 - _, cv := molsRTTStats([]RelayState{r1v, r2v})
354 + avgRTT, cv := molsRTTStats([]RelayState{r1v, r2v})
355 if cv <= molsCVThreshold {
356 t.Fatalf("test precondition: cv = %v, want > %v", cv, molsCVThreshold)
357 }
358 + if avgRTT > molsCongestionRTTThreshold {
359 + t.Fatalf("test precondition: avgRTT = %v, want <= %v", avgRTT, molsCongestionRTTThreshold)
360 + }
361
362 variantOrder := policy.SelectPriority([]RelayState{r1v, r2v}, ClientState{
363 LocalAddress: "ingress-cv",
@@ -363,27 +367,12 @@ func TestMOLSSelectPriorityVariantGridActivatesOnHighCV(t *testing.T) {
367 t.Fatalf("expected 2 relays in both modes: normal=%d variant=%d", len(normalOrder), len(variantOrder))
368 }
369
366 - // Check internally that the variant grid would produce different scores.
367 - ingressIdx := hashToGF64("ingress-cv")
368 - j1 := hashToGF64("https://relay-one.example")
369 - j2 := hashToGF64("https://relay-two.example")
370 - base1 := molsScore(ingressIdx, j1, molsBaseM1, molsBaseM2)
371 - base2 := molsScore(ingressIdx, j2, molsBaseM1, molsBaseM2)
372 - var1 := molsScore(ingressIdx, j1, molsVariantM1, molsVariantM2)
373 - var2 := molsScore(ingressIdx, j2, molsVariantM1, molsVariantM2)
374 -
375 - // Verify that the base and variant grids actually produce different relative
376 - // orderings for at least this pair of relays. If the orderings happen to be
377 - // identical the two multiplier sets produce the same ranking for these inputs,
378 - // which is not a bug (it depends on the hash collision distribution).
379 - baseFirst := base1 > base2
380 - varFirst := var1 > var2
381 - if baseFirst != varFirst {
382 - // Orderings differ: variant grid has the expected effect.
383 - return
370 + if normalOrder[0] != "https://relay-one.example" {
371 + t.Fatalf("normal order first relay = %q, want relay-one", normalOrder[0])
372 + }
373 + if variantOrder[0] != "https://relay-two.example" {
374 + t.Fatalf("variant order first relay = %q, want relay-two", variantOrder[0])
375 }
385 - // Orderings are the same: acceptable but worth noting.
386 - t.Logf("base and variant grids produce same ranking for this relay pair (ingress %d, j1=%d, j2=%d)", ingressIdx, j1, j2)
376 }
377
378 // TestMOLSSelectPriorityDifferentIngressDifferentOrder verifies that two
@@ -561,27 +550,6 @@ func TestMOLSMagicColumnSum(t *testing.T) {
550 }
551 }
552
564 -// TestMOLSMagicMainDiagonalSum verifies that the main diagonal sums to the
565 -// magic constant (magic square property).
566 -func TestMOLSMagicMainDiagonalSum(t *testing.T) {
567 - const magicSum = molsOrder * (molsOrder*molsOrder + 1) / 2
568 -
569 - var diagSum int
570 - for k := range uint8(64) {
571 - diagSum += molsScore(k, k, molsBaseM1, molsBaseM2)
572 - }
573 - // Allow ±1 rounding for floating-point-free integer arithmetic.
574 - diff := diagSum - magicSum
575 - if diff < 0 {
576 - diff = -diff
577 - }
578 - if diff > 1 {
579 - t.Logf("main diagonal sum = %d, magic constant = %d (diff %d)", diagSum, magicSum, diff)
580 - // The diagonal magic property requires the specific construction used.
581 - // Log rather than fail so the test documents the observed behaviour.
582 - }
583 -}
584 -
553 // TestMOLSGridUniqueness checks that all n² cells of the base grid have
554 // distinct values (Latin-square MOLS composite uniqueness).
555 func TestMOLSGridUniqueness(t *testing.T) {
portal/server_test.go
+16 -3
@@ -13,6 +13,7 @@ import (
13 "io"
14 "math/big"
15 "net/http"
16 + "net/http/httptest"
17 "os"
18 "path/filepath"
19 "strings"
@@ -88,7 +89,7 @@ func writeManualRelayCertificate(t *testing.T, keyDir, baseDomain string) {
89 }
90 }
91
91 -func TestNewServerInitializesRelaySetWhenDiscoveryEnabled(t *testing.T) {
92 +func TestRelayDiscoveryEnabledServesDiscoveryEnvelope(t *testing.T) {
93 t.Parallel()
94
95 server, err := NewServer(ServerConfig{
@@ -99,8 +100,20 @@ func TestNewServerInitializesRelaySetWhenDiscoveryEnabled(t *testing.T) {
100 if err != nil {
101 t.Fatalf("NewServer() error = %v", err)
102 }
102 - if server.relaySet == nil {
103 - t.Fatal("relaySet = nil, want discovery relay set")
103 +
104 + req := httptest.NewRequest(http.MethodGet, types.PathDiscovery, nil)
105 + rec := httptest.NewRecorder()
106 + server.handleRelayDiscovery(rec, req)
107 +
108 + if rec.Code != http.StatusOK {
109 + t.Fatalf("GET relay discovery status = %d, want %d", rec.Code, http.StatusOK)
110 + }
111 + var envelope types.APIEnvelope[types.DiscoveryResponse]
112 + if err := json.NewDecoder(rec.Body).Decode(&envelope); err != nil {
113 + t.Fatalf("json.Decode() error = %v", err)
114 + }
115 + if !envelope.OK || envelope.Data.ProtocolVersion != types.DiscoveryVersion {
116 + t.Fatalf("discovery envelope = %+v, want ok discovery response", envelope)
117 }
118 }
119