From 74583992d2939791ef74155c99eb194269ac3721 Mon Sep 17 00:00:00 2001 From: "Anderson A. Giacomolli" Date: Fri, 6 Nov 2026 14:38:59 -0300 Subject: [PATCH] Read the time directly in the model client The model client and the ChatGPT authorizer read the time with time.Now instead of a clock field. No caller set the field, so it was an injection with no user. A test that needs fake time can run in a testing/synctest bubble, where the time package uses a fake clock. Issue: b14d537 --- auth.go | 4 +--- responses.go | 6 ++---- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/auth.go b/auth.go index 1908b89..736624e 100644 --- a/auth.go +++ b/auth.go @@ -63,7 +63,6 @@ type chatgptAuth struct { path string issuer string http *http.Client - clock func() time.Time } // tokenFile is the content of the token file. @@ -115,7 +114,6 @@ func newChatGPTAuth(path, issuer string) *chatgptAuth { path: path, issuer: issuer, http: &http.Client{}, - clock: time.Now, } } @@ -308,7 +306,7 @@ func (a *chatgptAuth) Authorize(ctx context.Context, header http.Header) error { } expiry, found := tokenExpiry(tokens.AccessToken) - if !found || !a.clock().Before(expiry.Add(-refreshMargin)) { + if !found || !time.Now().Before(expiry.Add(-refreshMargin)) { tokens, err = a.refresh(ctx, tokens) if err != nil { return err diff --git a/responses.go b/responses.go index 9d6b75f..ebffaa3 100644 --- a/responses.go +++ b/responses.go @@ -57,7 +57,6 @@ type Client struct { cacheKey string usage *usageLog http *http.Client - clock func() time.Time } // Request is one model call. Input holds the input items in order, such as @@ -179,8 +178,7 @@ func newClient(url string, auth authorizer, cacheKey, usagePath string) *Client usage: &usageLog{ path: usagePath, }, - http: &http.Client{}, - clock: time.Now, + http: &http.Client{}, } } @@ -216,7 +214,7 @@ func (c *Client) Create(ctx context.Context, request Request) (Response, error) } record := usageRecord{ - Date: c.clock().Format(time.RFC3339Nano), + Date: time.Now().Format(time.RFC3339Nano), Model: request.Model, } -- 2.53.0