Review recorded explanations of a solution on the site
Test and publish the site / test (push) Successful in 2m4s
Test and publish the site / publish (push) Successful in 1m44s

The admin can upload a recording of themselves explaining a problem's
solution out loud (mp3, m4a, wav, webm, ogg or flac, up to 25 MB) and
get interview-style feedback, committed as reviews/<id>.md so every
attempt is kept.

Claude can't take audio, so the recording is transcribed first by an
OpenAI-compatible endpoint (whisper-1 by default; TRANSCRIBE_API_KEY,
with TRANSCRIBE_URL for a self-hosted server). Pace, pauses, filler
words and when complexity first comes up are measured from the word
timestamps and given to Claude with the timestamped transcript, the
statement and optionally the code. The reply covers the verdict, scores
in five areas, the approach and its complexity, missed edge cases,
delivery and what to work on.

Recordings are kept for playback in an S3 bucket (Garage) when the
S3_* settings are given, and are thrown away otherwise. Reviews are
admin-only. The job runs in the background like Explain, and the
statement fetch and save-error handling are now shared between the two.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-10-20 01:56:55 +01:00
co-authored by Claude Opus 5.5
parent 33027429c5
commit 63608f130c
25 changed files with 2381 additions and 54 deletions
+149
View File
@@ -0,0 +1,149 @@
package transcribe
import (
"context"
"encoding/json"
"errors"
"io"
"net/http"
"net/http/httptest"
"strings"
"testing"
)
const fixture = `{
"task": "transcribe", "language": "english", "duration": 30.0,
"text": "Um, so I'd sort it. The complexity is O(n log n).",
"segments": [
{"id": 0, "start": 0.0, "end": 2.0, "text": " Um, so I'd sort it."},
{"id": 1, "start": 5.0, "end": 8.0, "text": " The complexity is O(n log n)."}
],
"words": [
{"word": "Um", "start": 0.0, "end": 0.3},
{"word": "so", "start": 0.4, "end": 0.6},
{"word": "I'd", "start": 0.7, "end": 0.9},
{"word": "sort", "start": 1.0, "end": 1.4},
{"word": "it", "start": 1.5, "end": 2.0},
{"word": "The", "start": 5.0, "end": 5.2},
{"word": "complexity", "start": 5.3, "end": 6.0},
{"word": "is", "start": 6.1, "end": 6.3},
{"word": "O(n", "start": 6.4, "end": 7.0},
{"word": "log", "start": 7.1, "end": 7.5},
{"word": "n)", "start": 7.6, "end": 8.0}
]
}`
func TestTranscribeSendsVerboseJSONRequest(t *testing.T) {
var got struct {
auth, model, format, file, filename string
grains []string
}
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/v1/audio/transcriptions" {
http.NotFound(w, r)
return
}
got.auth = r.Header.Get("Authorization")
if err := r.ParseMultipartForm(1 << 20); err != nil {
t.Error(err)
}
got.model = r.FormValue("model")
got.format = r.FormValue("response_format")
got.grains = r.MultipartForm.Value["timestamp_granularities[]"]
f, h, err := r.FormFile("file")
if err == nil {
b, _ := io.ReadAll(f)
got.file, got.filename = string(b), h.Filename
}
io.WriteString(w, fixture)
}))
defer srv.Close()
c, err := New(srv.URL+"/", "k3y", "")
if err != nil {
t.Fatal(err)
}
tr, err := c.Transcribe(context.Background(), "take1.mp3", []byte("ID3fake"))
if err != nil {
t.Fatal(err)
}
if got.auth != "Bearer k3y" || got.model != DefaultModel || got.format != "verbose_json" ||
strings.Join(got.grains, ",") != "word,segment" || got.file != "ID3fake" || got.filename != "take1.mp3" {
t.Errorf("request = %+v", got)
}
if tr.Duration != 30 || len(tr.Words) != 11 || len(tr.Segments) != 2 {
t.Errorf("transcript = %+v", tr)
}
}
func TestTranscribeFailures(t *testing.T) {
if _, err := New("", "", ""); !errors.Is(err, ErrNotConfigured) {
t.Fatalf("blank key: %v", err)
}
for status, want := range map[int]string{401: "key was refused", 429: "rate limited", 400: "rejected the recording", 503: "unavailable"} {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(status)
io.WriteString(w, `{"error":{"message":"nope"}}`)
}))
c, _ := New(srv.URL, "k", "")
_, err := c.Transcribe(context.Background(), "a.mp3", []byte("x"))
var f *Failure
if !errors.As(err, &f) || !strings.Contains(f.Msg, want) || !strings.Contains(f.Err.Error(), "nope") {
t.Errorf("HTTP %d: %v, want %q", status, err, want)
}
srv.Close()
}
}
func TestMetrics(t *testing.T) {
var tr Transcript
if err := json.Unmarshal([]byte(fixture), &tr); err != nil {
t.Fatal(err)
}
m := tr.Metrics()
if m.Words != 11 || m.WPM != 22 {
t.Errorf("words = %d, wpm = %v", m.Words, m.WPM)
}
if len(m.Pauses) != 1 || m.Pauses[0] != (Pause{2, 3}) || m.Longest() != (Pause{2, 3}) {
t.Errorf("pauses = %+v", m.Pauses)
}
if m.FillerCount != 1 || m.Fillers[0] != (Filler{"um", 1}) {
t.Errorf("fillers = %+v", m.Fillers)
}
if m.ComplexityAt != 5.3 {
t.Errorf("complexity at %v, want 5.3", m.ComplexityAt)
}
}
func TestMetricsWithoutWordTimings(t *testing.T) {
tr := Transcript{
Duration: 60,
Segments: []Segment{
{0, 10, "Ummm, you know, it's like a heap, kind of."},
{10.5, 20, "Uhh, big O of n."},
{25, 30, "Basically done."},
},
}
m := tr.Metrics()
if m.Words != 16 || m.WPM != 16 {
t.Errorf("words = %d, wpm = %v", m.Words, m.WPM)
}
if len(m.Pauses) != 1 || m.Pauses[0] != (Pause{20, 5}) {
t.Errorf("pauses = %+v", m.Pauses)
}
want := map[string]int{"um": 1, "you know": 1, "like": 1, "kind of": 1, "uh": 1, "basically": 1}
if m.FillerCount != 6 || len(m.Fillers) != len(want) {
t.Errorf("fillers = %+v", m.Fillers)
}
for _, f := range m.Fillers {
if want[f.Word] != f.Count {
t.Errorf("filler %q = %d", f.Word, f.Count)
}
}
if m.ComplexityAt != 10.5 {
t.Errorf("complexity at %v, want 10.5", m.ComplexityAt)
}
if quiet := (&Transcript{Text: "hi"}); quiet.Metrics().ComplexityAt != -1 {
t.Error("no mention should be -1")
}
}