Files
compute/service/reachable_test.go
zeekay 770d447c42 there is one way visor reaches a cloud
The direct token is gone: no digitalOceanToken(), no DIGITALOCEAN_ACCESS_TOKEN,
no digitalOceanToken conf key, no fallback that holds a key in this process. A
provider credential is spent through hanzoai/egress or it is not spent, and
without a carrier the platform account refuses with a sentence that says so.

Deleting the fallback fixes a reporting bug rather than only tidying. Presence
was two questions — a token OR a carrier — and the token half was the misleading
one: a revoked key is still a non-empty string, so ComputeConfigured answered
"configured" straight through a revocation, every caller took the configured
branch and failed inside it, and the hourly sweep reported zeros that read as
real data instead of "not connected". One question cannot disagree with itself.

The tests follow the same rule. What used to be asserted by setting an env var
is asserted by registering a carrier; four t.Setenv calls that cleared a variable
nothing reads any more are gone; and the live catalog test now skips on the
carrier rather than on a token, because a skip message that names the wrong
prerequisite sends the next reader to set something that does nothing.
2026-08-22 11:46:31 -07:00

87 lines
3.7 KiB
Go

// Copyright 2025 Hanzo Industries Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// reachable_test.go pins the difference between "a credential is SET" and "a
// credential WORKS" — the distinction the whole estate was missing when a revoked
// DigitalOcean token kept every presence check returning true.
package service
import (
"context"
"net/http"
"testing"
)
// reachableBy makes the platform account reachable for one test, or not. Reaching
// a cloud is the carrier's job and only the carrier's, so this is the whole of
// what "configured" means now.
func reachableBy(t *testing.T, carried bool) {
t.Helper()
t.Cleanup(func() { RegisterCarrier(nil) })
if !carried {
RegisterCarrier(nil)
return
}
RegisterCarrier(func(Credential) (*http.Client, error) { return &http.Client{}, nil })
}
// TestPresenceCannotSeeARevocation is the mechanism finding, as a test.
//
// Every "is DO configured?" check in the estate is a PRESENCE check, and presence
// cannot see a revocation: a carrier is registered whether or not egress is up and
// whether or not the credential it holds still works — so ComputeConfigured stays
// true through a revocation, the code takes the configured branch, and fails
// inside it. That is why so much of this reported zeros that read as real data
// rather than "not connected". ComputeReachable is the question that actually
// distinguishes them.
//
// The context is cancelled before the call, so this is hermetic: no network, no
// DigitalOcean, no token minted. Cancellation can only produce an error if a call
// was actually ATTEMPTED, which is exactly the property under test — a presence
// check would sail through it, which is the point.
func TestPresenceCannotSeeARevocation(t *testing.T) {
reachableBy(t, true)
if !ComputeConfigured() {
t.Fatal("a registered carrier must read as configured — that is the premise: presence cannot see a revocation")
}
ctx, cancel := context.WithCancel(context.Background())
cancel()
if err := ComputeReachable(ctx); err == nil {
t.Fatal("ComputeReachable answered without reaching the provider — it is a presence check wearing a reachability name, " +
"and the hourly sweep would claim (and destroy) an hour it cannot bill")
}
}
// TestNothingToAskIsNotAFailure keeps the two negative cases apart. An UNCONFIGURED
// configured cloud account is not an unreachable one: it means there are no platform resources at
// all, so an empty answer is the TRUE answer and the hour must still be claimed —
// otherwise a deployment with no carrier stops billing its tenants' own
// resources forever, which trades one revenue outage for another.
func TestNothingToAskIsNotAFailure(t *testing.T) {
reachableBy(t, false)
if ComputeConfigured() {
t.Fatal("no carrier must read as unconfigured — there is no other way to reach a cloud")
}
ctx, cancel := context.WithCancel(context.Background())
cancel() // even cancelled: with nothing to ask, nothing is asked.
if err := ComputeReachable(ctx); err != nil {
t.Fatalf("an unconfigured configured cloud account reported unreachable (%v) — "+
"'there is nothing to ask' and 'the answer did not come back' are different facts", err)
}
}