fix front end issues

This commit is contained in:
Rongsong Shen 2026-05-01 21:22:45 +08:00
parent 177cf45af5
commit d7afd72e5b
18 changed files with 345 additions and 61 deletions

View file

@ -18,9 +18,6 @@ var HOSTSTAT = map[string]int{
}
func HostStateStr(state int) string {
if state == 0 {
return "UNKNOWN"
}
if (state & HOSTSTAT["UNAVAIL"]) != 0 {
return "UNAVAIL"
} else if (state & HOSTSTAT["CLOSED"]) != 0 {

View file

@ -9,9 +9,9 @@ func TestHostStateStr(t *testing.T) {
want string
}{
{
name: "zero value returns UNKNOWN when no worker has reported",
name: "zero value (no bad flags set) returns OK — C status=0 means healthy",
state: 0,
want: "UNKNOWN",
want: "OK",
},
{
name: "UNAVAIL flag",

View file

@ -70,8 +70,9 @@ var JOBSTAT = map[string]int{
"SSUSP": 0x40,
"PDONE": 0x80,
"PERR": 0x100,
"WAIT": 0x200,
"RUNKWN": 0x8000,
"UNKNOWN": 0x1000,
"UNKNOWN": 0x10000, // C JOB_STAT_UNKWN: worker lost contact with controller
}
var LAUNCHTYPE = map[string]int{
@ -90,12 +91,16 @@ func JobStateStr(state int) string {
return "USUSP"
} else if (state & JOBSTAT["SSUSP"]) != 0 {
return "SSUSP"
} else if (state & JOBSTAT["RUNKWN"]) != 0 {
return "RUNKWN"
}
return "RUN"
} else if (state & JOBSTAT["EXIT"]) != 0 {
return "EXIT"
} else if (state & JOBSTAT["DONE"]) != 0 {
return "DONE"
} else if (state & JOBSTAT["UNKNOWN"]) != 0 {
return "UNKWN"
}
return "ERR"
}
@ -245,6 +250,16 @@ func (jsb *Jsonb) IsZero() bool {
return jsb.String == ""
}
func (jsb Jsonb) MarshalJSON() ([]byte, error) {
if jsb.String == "" {
return []byte(`null`), nil
}
if json.Valid([]byte(jsb.String)) {
return []byte(jsb.String), nil
}
return json.Marshal(jsb.String)
}
func (tm *CustomTime) Tm() time.Time {
return tm.Time
}

View file

@ -0,0 +1,99 @@
package models
import "testing"
func TestJobStateStr(t *testing.T) {
tests := []struct {
name string
state int
want string
}{
{
name: "PEND",
state: JOBSTAT["PEND"],
want: "PEND",
},
{
name: "PSUSP (PEND+PSUSP)",
state: JOBSTAT["PEND"] | JOBSTAT["PSUSP"],
want: "PSUSP",
},
{
name: "RUN",
state: JOBSTAT["RUN"],
want: "RUN",
},
{
name: "USUSP (RUN+USUSP)",
state: JOBSTAT["RUN"] | JOBSTAT["USUSP"],
want: "USUSP",
},
{
name: "SSUSP (RUN+SSUSP)",
state: JOBSTAT["RUN"] | JOBSTAT["SSUSP"],
want: "SSUSP",
},
{
name: "RUNKWN (RUN+RUNKWN — lost contact with remote cluster)",
state: JOBSTAT["RUN"] | JOBSTAT["RUNKWN"],
want: "RUNKWN",
},
{
name: "EXIT",
state: JOBSTAT["EXIT"],
want: "EXIT",
},
{
name: "DONE",
state: JOBSTAT["DONE"],
want: "DONE",
},
{
name: "UNKNOWN (0x10000 — worker lost contact with controller)",
state: JOBSTAT["UNKNOWN"],
want: "UNKWN",
},
{
name: "zero state returns ERR",
state: 0,
want: "ERR",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := JobStateStr(tt.state)
if got != tt.want {
t.Errorf("JobStateStr(0x%X) = %q, want %q", tt.state, got, tt.want)
}
})
}
}
func TestJobStatMapValues(t *testing.T) {
// Verify bitmask values match C JOB_STAT_* defines in src/include/xce/types.h.
expected := map[string]int{
"PEND": 0x01,
"RUN": 0x02,
"EXIT": 0x04,
"DONE": 0x08,
"PSUSP": 0x10,
"USUSP": 0x20,
"SSUSP": 0x40,
"PDONE": 0x80,
"PERR": 0x100,
"WAIT": 0x200,
"RUNKWN": 0x8000,
"UNKNOWN": 0x10000,
}
for key, want := range expected {
got, ok := JOBSTAT[key]
if !ok {
t.Errorf("JOBSTAT[%q] missing", key)
continue
}
if got != want {
t.Errorf("JOBSTAT[%q] = 0x%X, want 0x%X", key, got, want)
}
}
}