feat: sync deployed v1.0.0-rc.38-custom.42

Sync production source including routing, billing, Astra detection and public uptime. Update custom build instructions and license packaging.
This commit is contained in:
cneicy committed 2026-09-26 04:49:11 +08:00
1 parent aa6c3f50f4
commit ceddfd3d6b
828 files changed
+122253 -13702

No files matched your search

+20 -22
View File
@@ -211,12 +211,9 @@ func TestStreamScannerHandler_DataWithExtraSpaces(t *testing.T) {
assert.Equal(t, "{\"trimmed\":true}", got)
}
// TestStreamScannerHandler_ClientCancelAbortsUpstreamAndReturns pins the
// disconnect contract: when the client goes away, the handler must return
// promptly (all goroutines joined, so the gin.Context can never leak into a
// pooled reuse), the upstream body must be closed to stop token generation,
// and no data received after the disconnect may be processed or written.
func TestStreamScannerHandler_ClientCancelAbortsUpstreamAndReturns(t *testing.T) {
// TestStreamScannerHandler_ClientCancelDrainsUpstreamUsage verifies that a client
// disconnect stops writes but leaves the upstream readable through its terminal event.
func TestStreamScannerHandler_ClientCancelDrainsUpstreamUsage(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
@@ -252,7 +249,6 @@ func TestStreamScannerHandler_ClientCancelAbortsUpstreamAndReturns(t *testing.T)
_, err := fmt.Fprint(pw, "data: first\n")
require.NoError(t, err)
select {
case <-firstHandled:
case <-time.After(2 * time.Second):
@@ -260,31 +256,21 @@ func TestStreamScannerHandler_ClientCancelAbortsUpstreamAndReturns(t *testing.T)
}
cancel()
_, err = fmt.Fprint(pw, "data: usage\ndata: [DONE]\n")
require.NoError(t, err, "client disconnect must not close the upstream body")
require.NoError(t, pw.Close())
// The handler must return without any further upstream input: cleanup
// closes resp.Body, which unblocks the scanner goroutine.
select {
case <-done:
case <-time.After(2 * time.Second):
t.Fatal("handler did not return after client disconnect")
t.Fatal("handler did not finish draining the upstream stream")
}
// Upstream read side must be closed so the provider stops generating
// (and billing) for a request nobody is listening to.
_, err = fmt.Fprint(pw, "data: second\n")
require.ErrorIs(t, err, io.ErrClosedPipe, "upstream body should be closed after client disconnect")
assert.Equal(t, int64(1), count.Load(), "no chunk after disconnect should be processed")
assert.Equal(t, int64(2), count.Load(), "terminal upstream data should be processed after client disconnect")
require.NotNil(t, info.StreamStatus)
assert.Equal(t, relaycommon.StreamEndReasonClientGone, info.StreamStatus.EndReason)
body := recorder.Body.String()
assert.Contains(t, body, "first")
assert.NotContains(t, body, "second")
}
// ---------- Ping tests ----------
func TestStreamScannerHandler_PingSentDuringSlowUpstream(t *testing.T) {
setting := operation_setting.GetGeneralSetting()
oldEnabled := setting.PingIntervalEnabled
@@ -571,3 +557,15 @@ func TestStreamScannerHandler_StreamStatus_ReplacesPreInitialized(t *testing.T)
assert.Equal(t, relaycommon.StreamEndReasonDone, info.StreamStatus.EndReason)
assert.Equal(t, 0, info.StreamStatus.TotalErrorCount())
}
func TestNewStreamScannerCallerLimit(t *testing.T) {
// The smaller buffer must actually constrain a line; a preallocated 64 KiB
// buffer would otherwise bypass this caller's 1 KiB limit in bufio.Scanner.
scanner := NewStreamScanner(strings.NewReader(strings.Repeat("x", 2048)+"\n"), 1024)
assert.False(t, scanner.Scan())
require.Error(t, scanner.Err())
scanner = NewStreamScanner(strings.NewReader("data: ok\n"), 1024)
require.True(t, scanner.Scan())
assert.Equal(t, "data: ok", scanner.Text())
require.NoError(t, scanner.Err())
}