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
path string
issuer string
http *http.Client
- clock func() time.Time
}
// tokenFile is the content of the token file.
path: path,
issuer: issuer,
http: &http.Client{},
- clock: time.Now,
}
}
}
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
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
usage: &usageLog{
path: usagePath,
},
- http: &http.Client{},
- clock: time.Now,
+ http: &http.Client{},
}
}
}
record := usageRecord{
- Date: c.clock().Format(time.RFC3339Nano),
+ Date: time.Now().Format(time.RFC3339Nano),
Model: request.Model,
}