[restore-vowifi-25.09] fix MT RP report correlation

This commit is contained in:
yibaiba committed 2026-08-10 19:46:25 +08:00
1 parent fb2ed79045
commit f64388a0bd
10 files changed
+168 -161

No files matched your search

@@ -351,10 +351,6 @@ func normalizeFragmentIdentity(value string) string {
return strings.TrimSpace(value)
}
func formatIncompleteFragmentContent(content string, received, total int, missing string) string {
return fmt.Sprintf("[incomplete %d/%d missing=%s] %s", received, total, missing, content)
}
func assembleFragmentText(fragments []*smsFragment) string {
ordered := append([]*smsFragment(nil), fragments...)
sort.SliceStable(ordered, func(left, right int) bool {
@@ -3,24 +3,20 @@ package imscore
import (
"errors"
"fmt"
"strings"
"time"
"github.com/iniwex5/vowifi-go/internal/vowifi/logging"
)
type degradedFragmentMessage struct {
message inboundSMS
key string
sessionID string
received int
total int
missing string
seqList string
callIDs string
ackedSeq string
first time.Time
latest time.Time
key string
received int
total int
missing string
seqList string
ackedSeq string
first time.Time
latest time.Time
}
func (s *Service) startFragmentCleanup() {
@@ -197,16 +193,9 @@ func buildDegradedFragmentMessage(key string, fragments []*smsFragment) *degrade
total := fragmentTotal(fragments)
missing := missingSMSSeqs(fragments, total)
return &degradedFragmentMessage{
message: inboundSMS{
sender: senderFromFragmentKey(key), targetURI: first.ToURI,
content: formatIncompleteFragmentContent(
assembleFragmentText(fragments), len(fragments), total, missing,
),
timestamp: latest,
},
key: key, sessionID: buildFragmentSessionInstanceID(key, fragments),
key: key,
received: len(fragments), total: total, missing: missing,
seqList: fragmentSeqList(fragments), callIDs: fragmentCallIDList(fragments),
seqList: fragmentSeqList(fragments),
ackedSeq: ackedFragmentSeqs(fragments), first: firstSeen, latest: latest,
}
}
@@ -220,23 +209,10 @@ func (s *Service) publishFragmentCleanupResults(
}
for _, item := range degraded {
logging.WarnRate("sms-fragment-timeout:"+item.key, time.Duration(0),
"IMS 长短信分片超时(审计模式,不发送 480)",
"IMS 长短信分片超时(保留等待晚到分片,不发布残缺短信)",
"device", s.cfg.DeviceID, "key", item.key, "fragments", item.received,
"expected_total", item.total, "received_seq", item.seqList,
"missing_seq", item.missing, "first_seen", item.first, "last_seen", item.latest,
"age_ms", time.Since(item.latest).Milliseconds(), "acked_seq", item.ackedSeq)
if strings.TrimSpace(item.message.content) == "" {
continue
}
logging.WarnRate("sms-fragment-degraded:"+item.key, time.Duration(0),
"IMS 长短信超时降级拼接并入库",
"device", s.cfg.DeviceID, "sender", item.message.sender, "key", item.key,
"received", item.received, "total", item.total, "missing_seq", item.missing,
"seq_list", item.seqList, "call_ids", item.callIDs, "acked_seq", item.ackedSeq)
s.publishLogNotification(formatVoWiFiIncompleteSMSMessage(
s.cfg.DeviceID, item.message.sender, item.message.content,
item.message.timestamp, item.received, item.total, item.missing,
))
s.publishInboundSMSWithFragment(item.message, item.sessionID, true)
}
}
@@ -179,7 +179,6 @@ func TestInboundFragmentPersistenceRetainsDegradedSessionForLateCompletion(t *te
); err != nil {
t.Fatal(err)
}
key := inboundSMSFragmentKey(message)
time.Sleep(5 * time.Millisecond)
if err := service.cleanupExpiredFragments(time.Millisecond); err != nil {
t.Fatal(err)
@@ -188,13 +187,7 @@ func TestInboundFragmentPersistenceRetainsDegradedSessionForLateCompletion(t *te
if err != nil || len(stored) != 1 || stored[0].Fragment.DegradedAt.IsZero() {
t.Fatalf("stored degraded fragments=%#v err=%v", stored, err)
}
assertIMSEventTypes(t, subscriber, "LogNotify")
degradedSessionID := assertFragmentSMS(t, subscriber, expectedFragmentSMS{
Content: "[incomplete 1/2 missing=2] stale", Incomplete: true,
})
if degradedSessionID == key {
t.Fatal("fragment event exposed the reusable raw fragment key")
}
assertNoIMSEvent(t, subscriber, "incomplete fragment timeout")
if _, err := service.finalizeInboundSMSData(
fragmentTestRequest("mt-stale-duplicate"), message, "SIP/2.0 200 OK\r\n\r\n",
); err != nil {
@@ -218,7 +211,7 @@ func TestInboundFragmentPersistenceRetainsDegradedSessionForLateCompletion(t *te
t.Fatal(err)
}
assertFragmentSMS(t, restoredSubscriber, expectedFragmentSMS{
Content: "stale complete", SessionKey: degradedSessionID,
Content: "stale complete",
})
stored, err = store.LoadInboundFragments(restored.inboundFragmentOwner())
if err != nil || len(stored) != 0 {
@@ -289,7 +282,7 @@ func TestInboundFragmentPersistenceDeletesAtLateWindowExpiry(t *testing.T) {
if err := service.cleanupExpiredFragments(time.Millisecond); err != nil {
t.Fatal(err)
}
assertIMSEventTypes(t, subscriber, "LogNotify", "SMSReceived")
assertNoIMSEvent(t, subscriber, "incomplete fragment timeout")
expiredAt := time.Now().Add(-inboundSMSLateReassemblyTTL - time.Second)
if err := store.MarkInboundFragmentsDegraded(service.inboundFragmentScope(key), expiredAt); err != nil {
t.Fatal(err)
@@ -319,7 +312,7 @@ func TestInboundFragmentPersistenceRejectsArrivalAfterLateWindow(t *testing.T) {
if err := service.cleanupExpiredFragments(time.Millisecond); err != nil {
t.Fatal(err)
}
assertIMSEventTypes(t, subscriber, "LogNotify", "SMSReceived")
assertNoIMSEvent(t, subscriber, "incomplete fragment timeout")
expiredAt := time.Now().Add(-inboundSMSLateReassemblyTTL - time.Second)
if err := store.MarkInboundFragmentsDegraded(service.inboundFragmentScope(key), expiredAt); err != nil {
t.Fatal(err)
@@ -38,16 +38,6 @@ func formatVoWiFiSMSSentMessage(device, number, content string, at time.Time, pa
device, number, at.Format(smsNotificationTimeLayout), content, parts)
}
func formatVoWiFiIncompleteSMSMessage(
device, number, content string,
at time.Time,
received, total int,
missing string,
) string {
return fmt.Sprintf("收到新短信 / VoWiFi\n设备 %s\n号码 %s\n时间 %s\n内容 %s\n状态 分片不完整 %d/%d,已降级拼接\n缺失 %s",
device, number, at.Format(smsNotificationTimeLayout), content, received, total, missing)
}
func (s *Service) getRuntimeEventBus() *EventBus {
if s == nil {
return nil
+32 -54
View File
@@ -12,11 +12,12 @@ import (
"github.com/iniwex5/vowifi-go/internal/vowifi/logging"
)
const (
rpAckInitialDelay = 100 * time.Millisecond
rpAckRetryDelay = time.Second
rpAckMaxAttempts = 4
)
type rpReportRequest struct {
Inbound string
Body []byte
RPMR byte
Fingerprint string
}
type mtAckAudit struct {
traceID, target, destination, transport, callID, fingerprint string
@@ -44,49 +45,8 @@ func (s *Service) recordMTAckAudit(audit mtAckAudit, err error) {
s.lastMTAckMu.Unlock()
}
func (s *Service) sendRpAckWithRetry(inbound string, body []byte, rpMR byte, fingerprint string) {
s.sendRpAckWithRetryPolicy(inbound, body, rpMR, fingerprint, rpAckInitialDelay, rpAckRetryDelay)
}
func (s *Service) sendRpAckWithRetryPolicy(
inbound string,
body []byte,
rpMR byte,
fingerprint string,
initialDelay, retryDelay time.Duration,
) {
if !s.waitSMSRetryDelay(initialDelay) {
return
}
delay := retryDelay
var lastErr error
for attempt := 0; attempt < rpAckMaxAttempts; attempt++ {
if attempt > 0 && !s.waitSMSRetryDelay(delay) {
return
}
lastErr = s.sendRpAck(inbound, body, rpMR, fingerprint)
if lastErr == nil {
return
}
delay *= 2
}
logging.WarnRate("smsip_rp_ack_retry_exhausted", "IMS RP-ACK retries exhausted",
"attempts", rpAckMaxAttempts, "err", lastErr)
}
func (s *Service) waitSMSRetryDelay(delay time.Duration) bool {
timer := time.NewTimer(delay)
defer timer.Stop()
select {
case <-timer.C:
return true
case <-s.stop:
return false
}
}
func (s *Service) sendRpAck(inbound string, body []byte, rpMR byte, fingerprint string) error {
request, err := s.buildRPAckMESSAGE(inbound, body)
func (s *Service) sendRPReport(report rpReportRequest) error {
request, err := s.buildRPAckMESSAGE(report.Inbound, report.Body)
if err != nil {
s.mtAckSendErr.Add(1)
return err
@@ -99,15 +59,23 @@ func (s *Service) sendRpAck(inbound string, body []byte, rpMR byte, fingerprint
traceID := common.NewTraceID()
audit := mtAckAudit{
traceID: traceID, target: request.Recipient.String(), destination: destinationFromContext(modeCtx),
transport: modeCtx.Transport, callID: request.CallID().Value(), rpMR: int(rpMR),
fingerprint: fingerprint, at: time.Now(),
transport: modeCtx.Transport, callID: request.CallID().Value(), rpMR: int(report.RPMR),
fingerprint: report.Fingerprint, at: time.Now(),
}
logging.RunDebug("IMS RP ACK send",
logging.RunDebug("IMS RP report send",
"trace_id", traceID, "target", audit.target, "destination", audit.destination,
"transport", audit.transport, "call_id", audit.callID, "rp_mr", audit.rpMR)
ctx, cancel := context.WithTimeout(common.WithTraceID(context.Background(), traceID), inboundSMSAckTimeout)
defer cancel()
err = s.sendOutOfDialogRequest(ctx, modeCtx, request)
response, err := s.sendByMode(outboundSendOperation{
Context: ctx,
Mode: modeCtx,
Request: request,
Timeout: inboundSMSAckTimeout,
})
if err == nil {
err = validateRPReportResponse(response)
}
if err != nil {
s.mtAckSendErr.Add(1)
s.recordMTAckAudit(audit, err)
@@ -118,8 +86,18 @@ func (s *Service) sendRpAck(inbound string, body []byte, rpMR byte, fingerprint
return nil
}
func resolveRpAckTarget(contact, from string) (string, error) {
if target := firstSIPHeaderURI(contact); target != "" {
func validateRPReportResponse(response *sipResponse) error {
if response == nil {
return errors.New("IMS RP report returned no SIP response")
}
if response.StatusCode < 200 || response.StatusCode >= 300 {
return fmt.Errorf("IMS RP report rejected: SIP %d %s", response.StatusCode, strings.TrimSpace(response.Reason))
}
return nil
}
func resolveRpAckTarget(assertedIdentity, from string) (string, error) {
if target := firstSIPHeaderURI(assertedIdentity); target != "" {
return target, nil
}
if target := firstSIPHeaderURI(from); target != "" {
@@ -55,7 +55,14 @@ func (s *Service) handleInboundTPStatusReport(raw string, rpMR byte, payload []b
return inboundSIPResult{
response: response,
afterReply: func() {
s.sendRpAckWithRetry(raw, smscodec.BuildRPAck(rpMR), rpMR, "")
err := s.sendRPReport(rpReportRequest{
Inbound: raw, Body: smscodec.BuildRPAck(rpMR), RPMR: rpMR,
})
if err != nil {
logging.WarnRate("ims-status-report-rp-ack:"+s.cfg.DeviceID, time.Minute,
"IMS status report RP-ACK delivery failed",
"device", s.cfg.DeviceID, "rp_mr", int(rpMR), "error", err)
}
},
}, recordErr
}
@@ -180,10 +180,13 @@ func (s *Service) finalizeInboundSMSData(
return inboundSIPResult{
response: response,
afterReply: func() {
if fragmentKey != "" {
ackErr := s.sendRPReport(rpReportRequest{
Inbound: raw, Body: smscodec.BuildRPAck(message.rpMR),
RPMR: message.rpMR, Fingerprint: fingerprint,
})
if ackErr == nil && fragmentKey != "" {
s.markFragmentAcked(fragmentKey, message.partNo)
}
s.sendRpAckWithRetry(raw, smscodec.BuildRPAck(message.rpMR), message.rpMR, fingerprint)
},
}, nil
}
@@ -282,7 +285,13 @@ func (s *Service) inboundSMSProtocolError(raw string, status int, rpMR byte, sen
result := inboundSIPResult{response: response}
if sendRPError {
result.afterReply = func() {
s.sendRpAckWithRetry(raw, smscodec.BuildRPError(rpMR, rpCauseTemporaryFailure), rpMR, "")
err := s.sendRPReport(rpReportRequest{
Inbound: raw, Body: smscodec.BuildRPError(rpMR, rpCauseTemporaryFailure), RPMR: rpMR,
})
if err != nil {
logging.WarnRate("ims-inbound-rp-error:"+s.cfg.DeviceID, time.Minute,
"IMS RP-ERROR delivery failed", "device", s.cfg.DeviceID, "rp_mr", int(rpMR), "error", err)
}
}
}
return result, protocolErr
@@ -307,18 +316,22 @@ func (s *Service) publishInboundSMSWithFragment(
})
}
func (s *Service) sendInboundSMSControl(inbound string, body []byte) {
s.sendRpAckWithRetry(inbound, body, 0, "")
}
func (s *Service) buildInboundSMSControlRequest(inbound string, body []byte) (string, error) {
remoteURI, err := resolveRpAckTarget(
rawSIPHeaderValue(inbound, "Contact"), rawSIPHeaderValue(inbound, "From"),
rawSIPHeaderValue(inbound, "P-Asserted-Identity"), rawSIPHeaderValue(inbound, "From"),
)
if err != nil {
return "", err
}
return s.buildSMSMESSAGE(remoteURI, body)
callID := strings.TrimSpace(rawSIPHeaderValue(inbound, "Call-ID"))
if callID == "" || strings.ContainsAny(callID, "\r\n") {
return "", errors.New("IMS RP-ACK In-Reply-To is unavailable")
}
return s.buildSMSMESSAGEWithOptions(smsMESSAGEOptions{
RemoteURI: remoteURI,
Body: body,
InReplyTo: callID,
})
}
func normalizedContentType(value string) string {
@@ -53,6 +53,30 @@ func TestInboundSMSDeliversEventAndSendsRPAck(t *testing.T) {
if string(body) != string(smscodec.BuildRPAck(rpMR)) {
t.Fatalf("RP-ACK body = %x", body)
}
if !strings.HasPrefix(request, "MESSAGE sip:+447802002606@ims.example SIP/2.0") {
t.Fatalf("RP-ACK request target = %q", strings.SplitN(request, "\r\n", 2)[0])
}
if got := rawSIPHeaderValue(request, "In-Reply-To"); got != "inbound-sms" {
t.Fatalf("RP-ACK In-Reply-To = %q", got)
}
}
func TestInboundRPAckTargetsAssertedIPSMGW(t *testing.T) {
service, _, outbound := newInboundSMSTestService(t)
raw := inboundSMSRequest(t, imsSMSContentType, inboundRPData(t, 0x35, "+447700900123", "hello"))
raw = strings.Replace(raw, "From: <sip:+447802002606@ims.example>;tag=remote\r\n",
"P-Asserted-Identity: <sip:ipsmgw@ims.example>\r\n"+
"From: <sip:+447802002606@ims.example>;tag=remote\r\n", 1)
if err := service.dispatchInboundSIP(raw, func(string) error { return nil }); err != nil {
t.Fatal(err)
}
request := waitForOutboundSMSControl(t, outbound)
if !strings.HasPrefix(request, "MESSAGE sip:ipsmgw@ims.example SIP/2.0") {
t.Fatalf("RP-ACK request target = %q", strings.SplitN(request, "\r\n", 2)[0])
}
if got := rawSIPHeaderValue(request, "To"); got != "<sip:ipsmgw@ims.example>" {
t.Fatalf("RP-ACK To = %q", got)
}
}
func TestInboundMalformedSMSReturnsProtocolErrorWithoutEvent(t *testing.T) {
@@ -12,13 +12,30 @@ import (
const smsSupportedHeader = "path, 100rel, replaces, gruu"
func (s *Service) buildSMSMESSAGE(remoteURI string, body []byte) (string, error) {
return s.buildSMSMESSAGEWithOptions(smsMESSAGEOptions{
RemoteURI: remoteURI,
Body: body,
})
}
type smsMESSAGEOptions struct {
RemoteURI string
Body []byte
InReplyTo string
}
func (s *Service) buildSMSMESSAGEWithOptions(options smsMESSAGEOptions) (string, error) {
if s == nil || s.cfg == nil {
return "", errors.New("imscore: SMS service is not configured")
}
remoteURI = strings.TrimSpace(remoteURI)
remoteURI := strings.TrimSpace(options.RemoteURI)
if remoteURI == "" || strings.ContainsAny(remoteURI, "\r\n") {
return "", errors.New("imscore: invalid SMS remote URI")
}
inReplyTo := strings.TrimSpace(options.InReplyTo)
if strings.ContainsAny(inReplyTo, "\r\n") {
return "", errors.New("imscore: invalid SMS In-Reply-To")
}
profile, err := s.reserveRegisteredSIPProfile()
if err != nil {
return "", fmt.Errorf("imscore: SMS registered profile: %w", err)
@@ -33,7 +50,11 @@ func (s *Service) buildSMSMESSAGE(remoteURI string, body []byte) (string, error)
}
fmt.Fprintf(&request, "From: <%s>;tag=%s\r\n", profile.LocalURI, newTag())
fmt.Fprintf(&request, "To: <%s>\r\n", remoteURI)
fmt.Fprintf(&request, "Call-ID: %s\r\nCSeq: %d MESSAGE\r\n", callID, profile.InitialCSeq)
fmt.Fprintf(&request, "Call-ID: %s\r\n", callID)
if inReplyTo != "" {
request.WriteString("In-Reply-To: " + inReplyTo + "\r\n")
}
fmt.Fprintf(&request, "CSeq: %d MESSAGE\r\n", profile.InitialCSeq)
request.WriteString("Contact: " + profile.ContactHeader + "\r\n")
request.WriteString("Max-Forwards: 70\r\n")
request.WriteString("P-Preferred-Identity: <" + profile.LocalURI + ">\r\n")
@@ -54,8 +75,8 @@ func (s *Service) buildSMSMESSAGE(remoteURI string, body []byte) (string, error)
}
request.WriteString("Content-Type: " + imsSMSContentType + "\r\n")
request.WriteString("Content-Transfer-Encoding: binary\r\n")
fmt.Fprintf(&request, "Content-Length: %d\r\n\r\n", len(body))
request.Write(body)
fmt.Fprintf(&request, "Content-Length: %d\r\n\r\n", len(options.Body))
request.Write(options.Body)
return request.String(), nil
}
@@ -170,27 +170,23 @@ func TestFragmentStateCompletesOutOfOrderAndAuditsCollision(t *testing.T) {
}
}
func TestRPAckRetriesAndRecordsSuccess(t *testing.T) {
func TestRPReportDoesNotRetryAfterTransportFailure(t *testing.T) {
service, _, _ := newInboundSMSTestService(t)
attempts := 0
outbound := make(chan string, 1)
service.transport.SetSendFn(func(raw string) error {
service.transport.SetSendFn(func(string) error {
attempts++
if attempts < 3 {
return syscall.EAGAIN
}
outbound <- raw
service.transport.DeliverResponse(registerResponseForRequest(raw, 200, nil))
return nil
return syscall.EAGAIN
})
raw := inboundSMSRequest(t, imsSMSContentType, inboundRPData(t, 0x31, "+447700900123", "ack"))
service.sendRpAckWithRetryPolicy(raw, smscodec.BuildRPAck(0x31), 0x31, "fingerprint", time.Millisecond, time.Millisecond)
if attempts != 3 || service.mtAckSendOK.Load() != 1 || service.mtAckSendErr.Load() != 2 {
err := service.sendRPReport(rpReportRequest{
Inbound: raw, Body: smscodec.BuildRPAck(0x31), RPMR: 0x31, Fingerprint: "fingerprint",
})
if err == nil || attempts != 1 || service.mtAckSendOK.Load() != 0 || service.mtAckSendErr.Load() != 1 {
t.Fatalf("attempts=%d ok=%d err=%d", attempts, service.mtAckSendOK.Load(), service.mtAckSendErr.Load())
}
}
func TestRPAckUsesRecoveredStatelessOutOfDialogWrite(t *testing.T) {
func TestRPReportWaitsForSIPAcceptance(t *testing.T) {
service, _, _ := newInboundSMSTestService(t)
outbound := make(chan string, 1)
service.transport.SetSendFn(func(raw string) error {
@@ -200,26 +196,49 @@ func TestRPAckUsesRecoveredStatelessOutOfDialogWrite(t *testing.T) {
raw := inboundSMSRequest(t, imsSMSContentType, inboundRPData(t, 0x32, "+447700900123", "ack"))
done := make(chan error, 1)
go func() {
done <- service.sendRpAck(raw, smscodec.BuildRPAck(0x32), 0x32, "fingerprint")
done <- service.sendRPReport(rpReportRequest{
Inbound: raw, Body: smscodec.BuildRPAck(0x32), RPMR: 0x32, Fingerprint: "fingerprint",
})
}()
request := waitForOutboundSMSControl(t, outbound)
select {
case err := <-done:
if err != nil {
t.Fatal(err)
}
case <-time.After(250 * time.Millisecond):
t.Fatal("RP-ACK waited for a SIP final response")
t.Fatalf("RP report completed before SIP response: %v", err)
case <-time.After(20 * time.Millisecond):
}
service.transport.DeliverResponse(registerResponseForRequest(request, 202, nil))
if err := <-done; err != nil {
t.Fatal(err)
}
request := waitForOutboundSMSControl(t, outbound)
if body, err := rawSIPBody(request); err != nil || string(body) != string(smscodec.BuildRPAck(0x32)) {
t.Fatalf("RP-ACK body = %x, err = %v", body, err)
}
if got := rawSIPHeaderValue(request, "In-Reply-To"); got != "inbound-sms" {
t.Fatalf("In-Reply-To = %q", got)
}
if service.mtAckSendOK.Load() != 1 || service.mtAckSendErr.Load() != 0 {
t.Fatalf("ok=%d err=%d", service.mtAckSendOK.Load(), service.mtAckSendErr.Load())
}
}
func TestRPReportRejectsNon2xxResponse(t *testing.T) {
service, _, _ := newInboundSMSTestService(t)
service.transport.SetSendFn(func(raw string) error {
service.transport.DeliverResponse(registerResponseForRequest(raw, 403, nil))
return nil
})
raw := inboundSMSRequest(t, imsSMSContentType, inboundRPData(t, 0x33, "+447700900123", "ack"))
err := service.sendRPReport(rpReportRequest{
Inbound: raw, Body: smscodec.BuildRPAck(0x33), RPMR: 0x33,
})
if err == nil || !strings.Contains(err.Error(), "SIP 403") {
t.Fatalf("RP report error = %v", err)
}
if service.mtAckSendOK.Load() != 0 || service.mtAckSendErr.Load() != 1 {
t.Fatalf("ok=%d err=%d", service.mtAckSendOK.Load(), service.mtAckSendErr.Load())
}
}
func TestOutboundSMSUsesProductionUDPSocket(t *testing.T) {
registrar, client, service := newRealUDPSMSService(t)
serverErr := make(chan error, 1)
@@ -264,23 +283,16 @@ func TestSMSReadyCallbackFiresOnce(t *testing.T) {
}
}
func TestRecoveredSMSNotificationFormats(t *testing.T) {
func TestRecoveredSMSSentNotificationFormat(t *testing.T) {
at := time.Date(2026, time.August, 9, 12, 34, 56, 0, time.UTC)
sent := formatVoWiFiSMSSentMessage("wwan0", "+447700900123", "hello", at, 2)
wantSent := "发送短信 / 完成\n设备 wwan0\n号码 +447700900123\n通道 VoWiFi\n时间 2026-08-09 12:34:56\n内容 hello\n分片 2"
if sent != wantSent {
t.Fatalf("sent notification = %q", sent)
}
incomplete := formatVoWiFiIncompleteSMSMessage(
"wwan0", "+447700900123", "part", at, 1, 3, "2,3",
)
wantIncomplete := "收到新短信 / VoWiFi\n设备 wwan0\n号码 +447700900123\n时间 2026-08-09 12:34:56\n内容 part\n状态 分片不完整 1/3,已降级拼接\n缺失 2,3"
if incomplete != wantIncomplete {
t.Fatalf("incomplete notification = %q", incomplete)
}
}
func TestFragmentTimeoutDegradesAndAudits(t *testing.T) {
func TestFragmentTimeoutAuditsWithoutPublishingIncompleteSMS(t *testing.T) {
service, subscriber, _, _ := newDeliveryReportTestService(t)
fragment := &smsFragment{
Ref: 7, Total: 2, Seq: 1, Content: "first", RpMr: 4,
@@ -294,7 +306,7 @@ func TestFragmentTimeoutDegradesAndAudits(t *testing.T) {
fragment.Time = time.Now().Add(-time.Second)
service.fragmentMu.Unlock()
service.cleanupExpiredFragments(time.Millisecond)
assertIMSEventTypes(t, subscriber, "LogNotify", "SMSReceived")
assertNoIMSEvent(t, subscriber, "incomplete fragment")
snapshot := service.fragmentAuditSnapshot()
failures, ok := snapshot["audit_failures"].([]fragmentAuditFailure)
recent, recentOK := snapshot["recent_failures"].([]fragmentAuditFailure)
@@ -304,9 +316,6 @@ func TestFragmentTimeoutDegradesAndAudits(t *testing.T) {
failures[0].MissingSeq != "2" {
t.Fatalf("fragment audit = %#v", snapshot)
}
if got := formatIncompleteFragmentContent("first", 1, 2, "2"); got != "[incomplete 1/2 missing=2] first" {
t.Fatalf("incomplete content=%q", got)
}
}
func TestInboundFragmentTTLUsesLocalArrivalTime(t *testing.T) {