fix: 按评审补齐 mock 校验、Worker 上限保护与测试(Codex gpt-6-sol)

This commit is contained in:
RuoJi6 committed 2026-10-24 22:08:35 +08:00
1 parent a1dc362bae
commit 2e6ceddf95
8 files changed
+125 -21

No files matched your search

+5
View File
@@ -778,6 +778,11 @@ func (e *Engine) Run(ctx context.Context, t *Task) {
func workerCountForTask(t *Task, global int) int {
if t != nil && t.WorkerCount > 0 {
// Direct database edits can bypass validation; cap those values so the
// engine never starts more than the supported per-task worker count.
if t.WorkerCount > db.MaxTaskWorkerCount {
return db.MaxTaskWorkerCount
}
return t.WorkerCount
}
return global
+8 -1
View File
@@ -1,6 +1,10 @@
package server
import "testing"
import (
"testing"
"github.com/Autumn-27/artex/db"
)
func TestWorkerCountForTaskUsesOverrideOrGlobalDefault(t *testing.T) {
if got := workerCountForTask(&Task{WorkerCount: 5}, 3); got != 5 {
@@ -12,4 +16,7 @@ func TestWorkerCountForTaskUsesOverrideOrGlobalDefault(t *testing.T) {
if got := workerCountForTask(&Task{WorkerCount: -1}, 3); got != 3 {
t.Fatalf("negative override = %d, want global 3", got)
}
if got := workerCountForTask(&Task{WorkerCount: db.MaxTaskWorkerCount + 1}, 3); got != db.MaxTaskWorkerCount {
t.Fatalf("oversized override = %d, want capped %d", got, db.MaxTaskWorkerCount)
}
}