feat(task): auto-inject scheduling params into script template via scheduling_map

Add scheduling_map field to ParameterSchema so Application creators can
declare that a parameter (e.g. NP) maps to a scheduling field (e.g. cpus).
The backend auto-injects the scheduling value into script template variables
before rendering, eliminating duplicate user input. The frontend hides
mapped parameters from the form and injects their values on submit.
This commit is contained in:
dailz
2026-04-22 10:26:52 +08:00
parent 435ab285c1
commit 5591b67f75
9 changed files with 206 additions and 2 deletions

View File

@@ -1266,3 +1266,49 @@ func TestProcessTask_PartialSchedulingParams(t *testing.T) {
t.Errorf("KillOnNodeFail = %v, want nil", j.KillOnNodeFail)
}
}
func TestTaskService_ProcessTask_SchedulingMapInjection(t *testing.T) {
jobID := int32(42)
var capturedReq slurm.JobSubmitReq
env := newTaskTestEnv(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if err := json.NewDecoder(r.Body).Decode(&capturedReq); err != nil {
t.Fatalf("decode request body: %v", err)
}
json.NewEncoder(w).Encode(slurm.OpenapiJobSubmitResponse{
Result: &slurm.JobSubmitResponseMsg{JobID: &jobID},
})
}))
defer env.close()
params := json.RawMessage(`[
{"name": "NP", "type": "integer", "scheduling_map": "cpus", "required": true}
]`)
appID := env.createApp(t, "sched-map-app", "#!/bin/bash\nmpirun -np $NP my_app", params)
cpus := int32(8)
task, err := env.svc.CreateTask(context.Background(), &model.CreateTaskRequest{
AppID: appID,
TaskName: "sched-map-test",
Cpus: &cpus,
})
if err != nil {
t.Fatalf("CreateTask: %v", err)
}
if err := env.svc.ProcessTask(context.Background(), task.ID); err != nil {
t.Fatalf("ProcessTask: %v", err)
}
if capturedReq.Script == nil {
t.Fatal("submitted script is nil")
}
if !strings.Contains(*capturedReq.Script, "'8'") {
t.Errorf("rendered script does not contain shell-escaped scheduling value:\n%s", *capturedReq.Script)
}
if !strings.Contains(*capturedReq.Script, "mpirun -np '8'") {
t.Errorf("rendered script does not contain expected mpirun command:\n%s", *capturedReq.Script)
}
}