Files
adamfandClaude Opus 5.5 67cb8137f9
Test and publish / test (push) Successful in 6m39s
Test and publish / publish (push) Failing after 0s
Split the job tracker out of web_server into its own app
The applications tracker, leads inbox, email pipeline and capture userscript
move here from web_server's backend, Python service and Vue app, as one Go
binary that serves its own Vue SPA under /jobs/.

- The Go services, resolvers and tests move over almost unchanged.
- The three Claude calls are ported from Python to Go (internal/claude),
  with the same prompts, per-model request shaping and error messages.
- There is no login: internal/auth asks the site backend's
  /auth/validate-admin with the visitor's cookies, and relays refreshed
  cookies back.
- A Settings page replaces the admin-panel capture token card and adds the
  Microsoft sign-in link and a manual email sync.
- The userscript is 2.0.0, at /jobs/, and migrates a saved API base.
- Dockerfile, a standalone compose with Postgres, Makefile, and a Gitea CI
  workflow that tests and publishes the image.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-14 16:24:16 +01:00

62 lines
2.3 KiB
Go

package handlers
import (
"net/http"
"net/http/httptest"
"os"
"path/filepath"
"testing"
"github.com/gin-gonic/gin"
)
func TestSPA(t *testing.T) {
gin.SetMode(gin.TestMode)
dir := t.TempDir()
os.MkdirAll(filepath.Join(dir, "assets"), 0o755)
os.WriteFile(filepath.Join(dir, "index.html"), []byte("index"), 0o644)
os.WriteFile(filepath.Join(dir, "assets", "app-1a2b.js"), []byte("js"), 0o644)
os.WriteFile(filepath.Join(dir, "job-capture.user.js"), []byte("userscript"), 0o644)
// Outside dir: must never be reachable.
os.WriteFile(filepath.Join(filepath.Dir(dir), "secret"), []byte("secret"), 0o644)
r := gin.New()
r.GET("/jobs/api/health", func(c *gin.Context) { c.String(http.StatusOK, "ok") })
r.NoRoute(SPA(dir, "/jobs"))
cases := []struct {
method, path string
code int
body string
cache string
}{
{"GET", "/jobs/", 200, "index", "no-cache"},
{"GET", "/jobs/leads", 200, "index", "no-cache"},
{"GET", "/jobs/settings/anything", 200, "index", "no-cache"},
{"GET", "/jobs/assets/app-1a2b.js", 200, "js", "public, max-age=31536000, immutable"},
{"GET", "/jobs/job-capture.user.js", 200, "userscript", "no-cache"},
{"GET", "/jobs/api/health", 200, "ok", ""},
{"GET", "/jobs/api/nope", 404, `{"error":"not found"}`, ""},
{"GET", "/jobs/assets/gone.js", 404, "404 page not found", ""},
// net/http refuses a path that climbs, before anything is read.
{"GET", "/jobs/../secret", 400, "invalid URL path\n", ""},
{"GET", "/jobs/%2e%2e/secret", 400, "invalid URL path\n", ""},
{"POST", "/jobs/leads", 404, `{"error":"not found"}`, ""},
{"GET", "/elsewhere", 404, `{"error":"not found"}`, ""},
}
for _, c := range cases {
rec := httptest.NewRecorder()
r.ServeHTTP(rec, httptest.NewRequest(c.method, c.path, nil))
if rec.Code != c.code || rec.Body.String() != c.body || rec.Header().Get("Cache-Control") != c.cache {
t.Errorf("%s %s = %d %q (cache %q), want %d %q (cache %q)",
c.method, c.path, rec.Code, rec.Body, rec.Header().Get("Cache-Control"), c.code, c.body, c.cache)
}
}
rec := httptest.NewRecorder()
r.ServeHTTP(rec, httptest.NewRequest("GET", "/jobs", nil))
if rec.Code != http.StatusMovedPermanently || rec.Header().Get("Location") != "/jobs/" {
t.Errorf("GET /jobs = %d to %q, want a redirect to /jobs/", rec.Code, rec.Header().Get("Location"))
}
}