mirror of
https://github.com/hanzoai/iam.git
synced 2026-11-19 18:37:16 +00:00
internal/notify decided "can a code reach a person" by stat-ing notify.sock, and that answer was wrong in both directions. NOT SUFFICIENT. A socket file outlives the process that bound it wherever the run directory is a volume, and cloud's is (/var/lib/cloud/run, on a PVC). The live identity pod has sockets from pod generations that died a week earlier, so a stat reports a peer that nobody is listening for: delivery looks configured and every send fails with a person waiting. cloud already learned this and wrote it down — plane.Listening CONNECTS for exactly this reason, after a commerce socket left by a previous pod read as "up" for three days and took every prepaid-balance read with it. This is that defect, a second time, in a module that cannot see the lesson. NOT NECESSARY. notify is started ON DEMAND by the router that owns the app list. Its socket is bound after IAM mounts, so at the moment this decided, a notify that one call would have woken is indistinguishable from one that is not deployed at all — and hiding the method is self-fulfilling: nothing calls notify, so nothing ever starts it. Neither fact is knowable here. Both are known to the router, and this module links no router. So the transport moves to the composition root that has one: cloud binds it with server.BindSender and reaches notify through plane.Ask, which wakes a cold peer and separates "not deployed here" from "here and failing". IAM keeps the seam and nothing else — internal/notify is deleted rather than reduced, because a second plane client in a module that cannot import the first was the root of it. The seam now carries a Message instead of a code, because the WORDS are OTP policy and belong to the OTP: the expiry sentence renders from verificationCodeTTL, the same constant that expires the record. A transport composing its own sentence would restate a policy it cannot read, and the two would part company the first time the TTL moved. iam's own binary binds nothing and says so on stderr. It cannot start notify and must not guess; password and social sign-in are complete without it.
90 lines
3.4 KiB
Go
90 lines
3.4 KiB
Go
// Copyright 2026 Hanzo AI, Inc.
|
|
// SPDX-License-Identifier: MIT OR Apache-2.0
|
|
|
|
package server
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
)
|
|
|
|
type hostSender struct{ sent []Message }
|
|
|
|
func (h *hostSender) Send(_ context.Context, m Message) error {
|
|
h.sent = append(h.sent, m)
|
|
return nil
|
|
}
|
|
|
|
// A HOST outside this module must be able to supply the transport. The seam
|
|
// lives in an internal package, so without this re-export a grafted IAM could
|
|
// never deliver a code and every code-shaped method would stay dark in the one
|
|
// deployment that has a delivery service to reach.
|
|
func TestAHostCanBindDelivery(t *testing.T) {
|
|
var s Sender = &hostSender{}
|
|
BindSender(s)
|
|
t.Cleanup(func() { BindSender(nil) })
|
|
|
|
if !DeliveryConfigured() {
|
|
t.Fatal("binding a sender did not switch delivery on")
|
|
}
|
|
BindSender(nil)
|
|
if DeliveryConfigured() {
|
|
t.Fatal("unbinding did not switch delivery off — the predicate must follow the sender")
|
|
}
|
|
}
|
|
|
|
// A host must receive a message it can carry WITHOUT knowing any OTP policy: the
|
|
// words are already written and the expiry is already stated.
|
|
//
|
|
// This is the property that lets the transport live in the host. It used to live
|
|
// here, because the wording lived here too — and a transport that composed its own
|
|
// sentence would have had to restate verificationCodeTTL, a constant it cannot
|
|
// read. Now the host receives bytes and an address and needs to know nothing else.
|
|
func TestAHostReceivesAMessageItCanCarryWithoutKnowingThePolicy(t *testing.T) {
|
|
h := &hostSender{}
|
|
BindSender(h)
|
|
t.Cleanup(func() { BindSender(nil) })
|
|
|
|
m := Message{Org: "hanzo", Channel: "phone", To: "+15550100", Body: "your code is 123456"}
|
|
if err := h.Send(context.Background(), m); err != nil {
|
|
t.Fatalf("send: %v", err)
|
|
}
|
|
got := h.sent[0]
|
|
if got.Org == "" {
|
|
t.Error("no tenant reached the transport — a carrier resolves the sending account by org")
|
|
}
|
|
if got.Body == "" {
|
|
t.Error("no body reached the transport — the words are IAM's to write, not the carrier's")
|
|
}
|
|
}
|
|
|
|
// THERE IS NO PlaneSender ANY MORE, and this records why rather than leaving the
|
|
// absence to be rediscovered.
|
|
//
|
|
// It returned the plane transport when notify's socket FILE existed and nil when it
|
|
// did not, and nil was the delivery switch. Both halves were wrong. A socket file
|
|
// outlives the process that bound it wherever the run directory is a volume, so a
|
|
// file a dead pod left behind reported delivery that could not happen — the fleet
|
|
// has already paid three days of a fail-closed payment rail for exactly that shape.
|
|
// And notify is started ON DEMAND, so a service that one call would have woken
|
|
// reported no delivery at all: the predicate hid the method, nothing ever called
|
|
// notify, and nothing ever would.
|
|
//
|
|
// Neither fact is knowable here. Whether a delivery service is part of a deployment
|
|
// — and whether a cold one can be started — is known to the router that owns the app
|
|
// list, and this module links no router. So the transport moved to the composition
|
|
// root that has one, and this package keeps only the seam.
|
|
func TestDeliveryIsTheHostsAssertionNotASocketFile(t *testing.T) {
|
|
t.Setenv("ZIP_RUNTIME_DIR", t.TempDir()) // whatever is or is not here changes nothing
|
|
|
|
BindSender(nil)
|
|
if DeliveryConfigured() {
|
|
t.Fatal("delivery reported configured with no sender bound")
|
|
}
|
|
BindSender(&hostSender{})
|
|
t.Cleanup(func() { BindSender(nil) })
|
|
if !DeliveryConfigured() {
|
|
t.Fatal("a host that bound a transport must be believed — the predicate is its assertion")
|
|
}
|
|
}
|