Track fixed and ignored review findings
This commit is contained in:
@@ -10,7 +10,7 @@ import (
|
||||
"g.fc.run/misc/byre/internal/api"
|
||||
)
|
||||
|
||||
const reviewColumns = `id, task_id, snapshot_n, coalesce(agent_session_id, ''), vendor, model, state, result, error, created_at, finished_at`
|
||||
const reviewColumns = `id, task_id, snapshot_n, coalesce(agent_session_id, ''), vendor, model, state, result, error, created_at, finished_at, finding_states`
|
||||
|
||||
func (s *Store) CreateReview(ctx context.Context, r api.Review) error {
|
||||
finishedAt := ""
|
||||
@@ -26,9 +26,9 @@ func (s *Store) CreateReview(ctx context.Context, r api.Review) error {
|
||||
return err
|
||||
}
|
||||
if r.State == api.ReviewStateRunning {
|
||||
return emitReview(ctx, tx, emit, "review.started", r.Id)
|
||||
return emitReview(ctx, tx, emit, "review.started", r.Id, "byre")
|
||||
}
|
||||
return emitReview(ctx, tx, emit, "review.finished", r.Id)
|
||||
return emitReview(ctx, tx, emit, "review.finished", r.Id, "byre")
|
||||
})
|
||||
}
|
||||
|
||||
@@ -86,7 +86,27 @@ func (s *Store) FinishReview(ctx context.Context, id string, state api.ReviewSta
|
||||
if n == 0 {
|
||||
return ErrNotFound
|
||||
}
|
||||
return emitReview(ctx, tx, emit, "review.finished", id)
|
||||
return emitReview(ctx, tx, emit, "review.finished", id, "byre")
|
||||
})
|
||||
}
|
||||
|
||||
func (s *Store) SetFindingState(ctx context.Context, id string, index int, state api.FindingState, actor string) error {
|
||||
return s.write(ctx, func(tx *sql.Tx, emit emitFunc) error {
|
||||
res, err := tx.ExecContext(ctx, `
|
||||
UPDATE reviews SET finding_states = json_set(finding_states, '$."' || ? || '"', ?)
|
||||
WHERE id = ? AND state = ? AND ? < json_array_length(nullif(result, ''), '$.findings')
|
||||
`, index, string(state), id, string(api.ReviewStateDone), index)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
n, err := res.RowsAffected()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if n == 0 {
|
||||
return ErrNotFound
|
||||
}
|
||||
return emitReview(ctx, tx, emit, "review.finding", id, actor)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -123,7 +143,7 @@ func (s *Store) FirstTaskMessage(ctx context.Context, taskID string) (string, er
|
||||
return text, err
|
||||
}
|
||||
|
||||
func emitReview(ctx context.Context, tx *sql.Tx, emit emitFunc, kind, id string) error {
|
||||
func emitReview(ctx context.Context, tx *sql.Tx, emit emitFunc, kind, id, actor string) error {
|
||||
r, err := scanReview(tx.QueryRowContext(ctx, `SELECT `+reviewColumns+` FROM reviews WHERE id = ?`, id))
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -133,7 +153,7 @@ func emitReview(ctx context.Context, tx *sql.Tx, emit emitFunc, kind, id string)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return emit(api.Event{Kind: kind, ProjectId: &projectID, TaskId: &r.TaskId, Actor: "byre", Payload: ToPayload(r)})
|
||||
return emit(api.Event{Kind: kind, ProjectId: &projectID, TaskId: &r.TaskId, Actor: actor, Payload: ToPayload(r)})
|
||||
}
|
||||
|
||||
func questionReviews(ctx context.Context, q querier, item api.InboxItem) ([]api.Review, error) {
|
||||
@@ -171,11 +191,17 @@ func scanReview(row scanner) (api.Review, error) {
|
||||
result := ""
|
||||
createdAt := ""
|
||||
finishedAt := ""
|
||||
err := row.Scan(&r.Id, &r.TaskId, &r.SnapshotN, &r.AgentSessionId, &r.Vendor, &r.Model, &state, &result, &r.Error, &createdAt, &finishedAt)
|
||||
findingStates := ""
|
||||
err := row.Scan(&r.Id, &r.TaskId, &r.SnapshotN, &r.AgentSessionId, &r.Vendor, &r.Model, &state, &result, &r.Error, &createdAt, &finishedAt, &findingStates)
|
||||
if err != nil {
|
||||
return r, err
|
||||
}
|
||||
r.State = api.ReviewState(state)
|
||||
r.FindingStates = map[string]api.FindingState{}
|
||||
err = json.Unmarshal([]byte(findingStates), &r.FindingStates)
|
||||
if err != nil {
|
||||
return r, err
|
||||
}
|
||||
if result != "" {
|
||||
res := map[string]any{}
|
||||
err = json.Unmarshal([]byte(result), &res)
|
||||
|
||||
Reference in New Issue
Block a user