myxce/src/frontend/xcecli/cmd/jobs/restart_test.go
Rongsong Shen c15580a7f3
fix(frontend): peek and restart take <array-id>[k] and written job IDs
- apiserver peek (parseJobIDParam): <array-id>[k] now resolves to the
  element; it used to drop [k] and look up the array identity itself
  (and panicked in parseArrayName on some inputs). A job number still
  names that job exactly (an element by its own XCE_JOBID); ranges and
  invalid selections are rejected.
- apiserver restart: the decimal-only pre-check (isValidJobId, now
  unused and removed) rejected the written form c-a-ts-seq[k];
  ParseIdentitySelection, already used for the lookup, validates it.
- xcecli jobs restart converts its argument with ToAPIJobID like the
  control commands, so written IDs work and invalid ones fail locally.
- docs: the peek/restart caveat in the Job arrays section.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-02 09:42:27 +00:00

42 lines
1.1 KiB
Go

package jobs
import (
"strconv"
"strings"
"testing"
"xcecli/common/format"
)
// restart sends the API server the decimal job key (or <key>[k]); a job ID
// in its written form c-a-ts-seq used to be sent unconverted and rejected.
func TestRestartParseCmdArgsConvertsJobID(t *testing.T) {
written := format.FormatJobID(int64(testArrayKey))
key := strconv.FormatUint(testArrayKey, 10)
cases := []struct{ in, want string }{
{key, key},
{written, key},
{written + "[2]", key + "[2]"},
{key + "[2]", key + "[2]"},
}
for _, c := range cases {
r := NewJobRestart(nil)
if err := r.ParseCmdArgs(nil, []string{c.in}); err != nil {
t.Errorf("%q: unexpected error %v", c.in, err)
continue
}
if r.jobID != c.want {
t.Errorf("%q: sends %q, want %q", c.in, r.jobID, c.want)
}
}
for _, in := range []string{written + "[1-3]", "garbage"} {
r := NewJobRestart(nil)
err := r.ParseCmdArgs(nil, []string{in})
if err == nil {
t.Errorf("%q: want an error", in)
} else if !strings.Contains(err.Error(), in) {
t.Errorf("%q: error %q does not name the selection", in, err)
}
}
}