Declare GraphQL auth in the schema and drop the Go Claude client

Authorisation: @admin and @signedIn schema directives replace the 25
hand-copied resolver checks. A test fails if a mutation has neither and
is not on the public allow-list, so a new mutation cannot ship unguarded.

IDs: uint model IDs bind through graphql.UintID, removing the ten
int(obj.ID) resolvers.

Job status is a GraphQL enum, tied to services.statusOrder by a test.
Input is strict, so the mutations no longer coerce an unknown status to
"applied"; output is lenient so one legacy row cannot fail the list.

deleteJobApplication and deleteJobAppReference now error on a missing id
like the other deletes.

The rowing reader, the job extractor and now the email classifier reach
the Python service through one services.CallPython helper. The email
pipeline's prompt and fence stripping moved to Python, and
anthropic-sdk-go is gone from go.mod.

Fix the auth test fixture, whose 11-byte secret had been panicking the
services test package since InitAuth began requiring 32 bytes. Add a
test that keeps the python service's compose environment list in step
with the env registry.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-10-12 14:39:19 +01:00
co-authored by Claude Opus 5.5
parent 307268fbea
commit 71344a1f8d
55 changed files with 2271 additions and 1099 deletions
+7 -54
View File
@@ -1,12 +1,8 @@
package handlers
import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"io"
"log"
"net/http"
"net/url"
@@ -20,7 +16,7 @@ import (
"gorm.io/gorm"
)
// Job capture: the three endpoints behind userscripts/job-capture.user.js,
// Job capture: the three endpoints behind vue/public/job-capture.user.js,
// which adds the posting open in the browser to the job tracker.
//
// These are REST, and token-authenticated, because the caller is a userscript
@@ -51,10 +47,6 @@ const (
maxPageRunes = 40_000
)
// jobExtractClient bounds the wait on the Python service; see
// rowingReadClient for why two minutes.
var jobExtractClient = &http.Client{Timeout: 2 * time.Minute}
// CaptureTokenMiddleware guards the capture routes with the token generated
// in the admin panel (services.CaptureToken), presented as
// "Authorization: Bearer <token>".
@@ -250,55 +242,16 @@ type ExtractedJobPosting struct {
Notes *string `json:"notes"`
}
// postingReadError is a failure the Python service reported in words that are
// safe to show in the capture popup (its 502 detail); the job-capture
// counterpart of displayReadError.
type postingReadError struct{ detail string }
func (e *postingReadError) Error() string { return e.detail }
// extractJobPosting sends a page's text to the Python service and returns the
// fields Claude picked out. It mirrors readRowingDisplay, including which
// replies are relayed and which are only logged.
// fields Claude picked out. Like readRowingDisplay it is a thin wrapper over
// services.CallPython, which decides which replies are relayed (a
// *services.PythonError) and which are only logged.
func (store *Store) extractJobPosting(ctx context.Context, pageURL, title, text string) (ExtractedJobPosting, error) {
var posting ExtractedJobPosting
body, err := json.Marshal(struct {
return services.CallPython[ExtractedJobPosting](ctx, store.PythonURL, jobExtractPath, struct {
URL string `json:"url"`
Title string `json:"title"`
Text string `json:"text"`
}{pageURL, title, text})
if err != nil {
return posting, err
}
req, err := http.NewRequestWithContext(ctx, http.MethodPost, store.PythonURL+jobExtractPath, bytes.NewReader(body))
if err != nil {
return posting, err
}
req.Header.Set("Content-Type", "application/json")
resp, err := jobExtractClient.Do(req)
if err != nil {
return posting, err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
var failure struct {
Detail string `json:"detail"`
}
raw, _ := io.ReadAll(io.LimitReader(resp.Body, 4<<10))
if resp.StatusCode == http.StatusBadGateway && json.Unmarshal(raw, &failure) == nil && failure.Detail != "" {
return posting, &postingReadError{detail: failure.Detail}
}
return posting, fmt.Errorf("job extractor returned %d: %s", resp.StatusCode, raw)
}
if err := json.NewDecoder(resp.Body).Decode(&posting); err != nil {
return posting, fmt.Errorf("decoding job extractor response: %w", err)
}
return posting, nil
}
// truncateRunes cuts s to at most max runes, on a rune boundary so the result
@@ -344,9 +297,9 @@ func (store *Store) JobCaptureExtract(ctx *gin.Context) {
truncateRunes(input.URL, 2000), truncateRunes(input.Title, 500), truncateRunes(text, maxPageRunes))
if err != nil {
log.Println("Job extract failed:", err)
var readErr *postingReadError
var readErr *services.PythonError
if errors.As(err, &readErr) {
ctx.JSON(http.StatusBadGateway, gin.H{"error": readErr.detail})
ctx.JSON(http.StatusBadGateway, gin.H{"error": readErr.Detail})
return
}
ctx.JSON(http.StatusBadGateway, gin.H{"error": "failed to read the page"})