fix fresh-host acceptance and document real-host debugging learnings
This commit is contained in:
@@ -34,9 +34,13 @@ func (c *Client) BatchCreateAccounts(ctx context.Context, req BatchCreateAccount
|
||||
return models, nil
|
||||
}
|
||||
|
||||
func (c *Client) TestAccount(ctx context.Context, accountID string) (ProbeResult, error) {
|
||||
func (c *Client) TestAccount(ctx context.Context, accountID, modelID string) (ProbeResult, error) {
|
||||
path := "/api/v1/admin/accounts/" + accountID + "/test"
|
||||
statusCode, _, body, err := c.perform(ctx, http.MethodPost, path, map[string]any{})
|
||||
req := map[string]any{}
|
||||
if strings.TrimSpace(modelID) != "" {
|
||||
req["model_id"] = strings.TrimSpace(modelID)
|
||||
}
|
||||
statusCode, _, body, err := c.perform(ctx, http.MethodPost, path, req)
|
||||
if err != nil {
|
||||
return ProbeResult{}, err
|
||||
}
|
||||
@@ -158,35 +162,77 @@ func parseProbeResult(body []byte) (ProbeResult, error) {
|
||||
return ProbeResult{}, fmt.Errorf("missing data event")
|
||||
}
|
||||
|
||||
var event struct {
|
||||
type probeEvent struct {
|
||||
Type string `json:"type"`
|
||||
Status string `json:"status"`
|
||||
Message string `json:"message"`
|
||||
Error string `json:"error"`
|
||||
OK *bool `json:"ok"`
|
||||
Success *bool `json:"success"`
|
||||
}
|
||||
if err := json.Unmarshal([]byte(payloads[len(payloads)-1]), &event); err != nil {
|
||||
return ProbeResult{}, err
|
||||
}
|
||||
|
||||
ok := false
|
||||
switch {
|
||||
case event.OK != nil:
|
||||
ok = *event.OK
|
||||
case event.Success != nil:
|
||||
ok = *event.Success
|
||||
default:
|
||||
switch strings.ToLower(strings.TrimSpace(event.Status)) {
|
||||
case "ok", "pass", "passed", "success", "succeeded":
|
||||
ok = true
|
||||
var latest ProbeResult
|
||||
sawProbeState := false
|
||||
|
||||
for _, payload := range payloads {
|
||||
var event probeEvent
|
||||
if err := json.Unmarshal([]byte(payload), &event); err != nil {
|
||||
return ProbeResult{}, err
|
||||
}
|
||||
|
||||
message := strings.TrimSpace(event.Message)
|
||||
if message == "" {
|
||||
message = strings.TrimSpace(event.Error)
|
||||
}
|
||||
|
||||
eventType := strings.ToLower(strings.TrimSpace(event.Type))
|
||||
if eventType == "error" || strings.TrimSpace(event.Error) != "" {
|
||||
if message == "" {
|
||||
message = "account probe returned an error event"
|
||||
}
|
||||
return ProbeResult{
|
||||
OK: false,
|
||||
Status: "failed",
|
||||
Message: message,
|
||||
}, nil
|
||||
}
|
||||
|
||||
ok := false
|
||||
switch {
|
||||
case event.OK != nil:
|
||||
ok = *event.OK
|
||||
case event.Success != nil:
|
||||
ok = *event.Success
|
||||
default:
|
||||
switch strings.ToLower(strings.TrimSpace(event.Status)) {
|
||||
case "ok", "pass", "passed", "success", "succeeded":
|
||||
ok = true
|
||||
}
|
||||
}
|
||||
|
||||
if eventType == "test_complete" {
|
||||
return ProbeResult{
|
||||
OK: ok,
|
||||
Status: normalizeProbeStatus(event.Status, ok),
|
||||
Message: message,
|
||||
}, nil
|
||||
}
|
||||
|
||||
if event.Status != "" || event.OK != nil || event.Success != nil {
|
||||
latest = ProbeResult{
|
||||
OK: ok,
|
||||
Status: normalizeProbeStatus(event.Status, ok),
|
||||
Message: message,
|
||||
}
|
||||
sawProbeState = true
|
||||
}
|
||||
}
|
||||
|
||||
status := normalizeProbeStatus(event.Status, ok)
|
||||
return ProbeResult{
|
||||
OK: ok,
|
||||
Status: status,
|
||||
Message: strings.TrimSpace(event.Message),
|
||||
}, nil
|
||||
if sawProbeState {
|
||||
return latest, nil
|
||||
}
|
||||
|
||||
return ProbeResult{}, fmt.Errorf("missing probe status event")
|
||||
}
|
||||
|
||||
func normalizeProbeStatus(status string, ok bool) string {
|
||||
|
||||
Reference in New Issue
Block a user