(new): expand runtime APIs
Golang lint / lint (push) Successful in 58s
Golang lint / lint (pull_request) Successful in 13m10s

(fix): harden concurrent lifecycle
(tests): add regression coverage
(doc): update v1.2 guidance
This commit is contained in:
2026-08-20 11:08:45 +03:00
parent 29b208eeec
commit 24040fe164
37 changed files with 1129 additions and 157 deletions
+37
View File
@@ -157,6 +157,43 @@ func TestRequireChatAdminUsesNormalizedIDs(t *testing.T) {
}
}
func TestRequireChatAdminUsesMessageContextCancellation(t *testing.T) {
api := tgapi.NewAPI(
tgapi.NewAPIOpts("token").
SetAPIURL("https://example.test").
SetHTTPClient(&http.Client{Transport: roundTripFunc(func(req *http.Request) (*http.Response, error) {
if err := req.Context().Err(); err != nil {
return nil, err
}
return &http.Response{
StatusCode: http.StatusOK,
Header: http.Header{"Content-Type": []string{"application/json"}},
Body: io.NopCloser(strings.NewReader(`{"ok":true,"result":{"status":"administrator","user":{"id":55,"is_bot":false,"first_name":"tester"}}}`)),
}, nil
})}),
)
t.Cleanup(func() {
if err := api.Close(); err != nil {
t.Fatalf("Close returned error: %v", err)
}
})
requestCtx, cancel := context.WithCancel(context.Background())
cancel()
ctx := &MessageContext{
API: api,
ChatID: -2001,
FromID: 55,
Logger: sneklog.NewLogger(),
ctx: requestCtx,
}
err := RequireChatAdmin[NoData]()(ctx, NoData{})
if !errors.Is(err, context.Canceled) || !IsInternalError(err) {
t.Fatalf("RequireChatAdmin error = %v, want internal context.Canceled", err)
}
}
func TestAllPoliciesReturnsFirstError(t *testing.T) {
want := AsUserError(errors.New("blocked"))
policy := AllPolicies(