refactor: modularize audit and harden build validation

This commit is contained in:
Mikhail Chusavitin
2026-08-31 21:22:16 +03:00
parent bb22ccfafe
commit ac4bc0b2b7
78 changed files with 13598 additions and 13130 deletions
+28 -11
View File
@@ -16,6 +16,19 @@ import (
"bee/audit/internal/platform"
)
type flushNotifyRecorder struct {
*httptest.ResponseRecorder
flushed chan struct{}
}
func (r *flushNotifyRecorder) Flush() {
r.ResponseRecorder.Flush()
select {
case r.flushed <- struct{}{}:
default:
}
}
func TestTaskQueuePersistsAndRecoversPendingTasks(t *testing.T) {
dir := t.TempDir()
q := &taskQueue{
@@ -275,7 +288,10 @@ func TestHandleAPITasksStreamPendingTaskStartsSSEImmediately(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
req := httptest.NewRequest(http.MethodGet, "/api/tasks/pending-1/stream", nil).WithContext(ctx)
req.SetPathValue("id", "pending-1")
rec := httptest.NewRecorder()
rec := &flushNotifyRecorder{
ResponseRecorder: httptest.NewRecorder(),
flushed: make(chan struct{}, 1),
}
done := make(chan struct{})
go func() {
@@ -284,17 +300,18 @@ func TestHandleAPITasksStreamPendingTaskStartsSSEImmediately(t *testing.T) {
close(done)
}()
deadline := time.Now().Add(2 * time.Second)
for time.Now().Before(deadline) {
if strings.Contains(rec.Body.String(), "Task is queued. Waiting for worker...") {
cancel()
<-done
if rec.Code != http.StatusOK {
t.Fatalf("status=%d body=%s", rec.Code, rec.Body.String())
}
return
select {
case <-rec.flushed:
cancel()
<-done
if rec.Code != http.StatusOK {
t.Fatalf("status=%d body=%s", rec.Code, rec.Body.String())
}
time.Sleep(20 * time.Millisecond)
if !strings.Contains(rec.Body.String(), "Task is queued. Waiting for worker...") {
t.Fatalf("missing queued status, body=%q", rec.Body.String())
}
return
case <-time.After(2 * time.Second):
}
cancel()
<-done