Compare commits
1 commit
main
...
fix/bd-5ys
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f2722beec1 |
4 changed files with 82 additions and 18 deletions
|
|
@ -1469,8 +1469,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
close runs, while the proxied route refuses that argument and closes the
|
||||
rest.) In `--json` mode the summary is instead a compact JSON line on stderr
|
||||
naming the failed ids, matching `bd update`'s partial-failure report, while
|
||||
stdout keeps the usual closed-issues array. Each `failed[]` entry carries the
|
||||
refusal as the engine worded it, identically on both routes; the `--force`
|
||||
stdout keeps the usual closed-issues array. A single refused id gets that
|
||||
JSON report too, as it does from `bd update`; only the text summary is left
|
||||
off for it, since its refusal already names it. Each `failed[]` entry carries
|
||||
the refusal as the engine worded it, identically on both routes; the `--force`
|
||||
hint and the route's own framing stay on the human-readable stderr line, which
|
||||
is unchanged. `--claim-next` still claims when
|
||||
part of the batch closed — the claim commits inside the batch's own
|
||||
|
|
|
|||
|
|
@ -468,25 +468,28 @@ func closeClaimedID(claimed *types.Issue) string {
|
|||
// denominator, because only it knows what it attempted — the direct route
|
||||
// counts resolved ids, the proxied one counts arguments.
|
||||
//
|
||||
// The summary is suppressed for a single-id batch deliberately: one inline
|
||||
// refusal is already unambiguous about which id failed, and suppressing it
|
||||
// keeps single-id stderr byte-identical to what it was before close learned to
|
||||
// fail a partial batch.
|
||||
// The text summary is suppressed for a single-id batch deliberately: one
|
||||
// inline refusal is already unambiguous about which id failed, and suppressing
|
||||
// it keeps single-id stderr byte-identical to what it was before close learned
|
||||
// to fail a partial batch.
|
||||
//
|
||||
// In --json mode the summary is one compact JSON line on stderr — the shape
|
||||
// reportUpdateFailures established — so a consumer that sees exit 1 can read
|
||||
// WHICH ids failed instead of scraping English prose, while stdout keeps the
|
||||
// plain closed-issues array a successful close emits. claimedNextID names the
|
||||
// issue --claim-next claimed on this run, if any: that claim is committed
|
||||
// inside the batch's own transaction and a sibling's refusal does not roll it
|
||||
// back, so the report names it rather than pretending it did not happen.
|
||||
// plain closed-issues array a successful close emits. It is emitted for a
|
||||
// single id too, as reportUpdateFailures' is: a consumer closing one id at a
|
||||
// time needs a parseable reason as much as one closing a batch. claimedNextID
|
||||
// names the issue --claim-next claimed on this run, if any: that claim is
|
||||
// committed inside the batch's own transaction and a sibling's refusal does
|
||||
// not roll it back, so the report names it rather than pretending it did not
|
||||
// happen.
|
||||
func reportCloseFailures(failures []closeIDFailure, total int, claimedNextID string, jsonOut bool) error {
|
||||
if total <= 1 {
|
||||
return SilentExit()
|
||||
}
|
||||
msg := fmt.Sprintf("%d of %d issues failed to close", len(failures), total)
|
||||
|
||||
if !jsonOut {
|
||||
if total <= 1 {
|
||||
return SilentExit()
|
||||
}
|
||||
fmt.Fprintf(os.Stderr, "Error: %s\n", msg)
|
||||
if claimedNextID != "" {
|
||||
fmt.Fprintf(os.Stderr, "Note: --claim-next already claimed %s; it stays assigned to you.\n", claimedNextID)
|
||||
|
|
|
|||
|
|
@ -523,8 +523,8 @@ func TestProxiedServerServeClose(t *testing.T) {
|
|||
// bdProxiedCloseFailedError runs an unforced `bd close --json` of id that must
|
||||
// be refused and returns the failed[].error it reports for id — the
|
||||
// route-independent spelling of the refusal (see assertCloseFailedErrorIsTyped).
|
||||
// A closable companion rides along because the failure report is the
|
||||
// partial-batch shape: a lone refused id prints no failed[] array.
|
||||
// A closable companion rides along, so the report read here is the
|
||||
// partial-batch shape, whose failed[] must name id alone.
|
||||
func bdProxiedCloseFailedError(t *testing.T, bd, dir, id string) string {
|
||||
t.Helper()
|
||||
companion := bdProxiedCreate(t, bd, dir, "closable companion", "-p", "2")
|
||||
|
|
|
|||
|
|
@ -1658,9 +1658,10 @@ func TestParityCloseNothingSettledExits1(t *testing.T) {
|
|||
if res.stdout != "" {
|
||||
t.Errorf("stdout = %q, want empty (SilentExit prints nothing itself)", res.stdout)
|
||||
}
|
||||
// The batch summary is multi-id ONLY. A single refused id already names
|
||||
// itself on stderr, so adding `N of M issues failed to close` to it would
|
||||
// be noise — and this is the sole assertion pinning that suppression.
|
||||
// The text batch summary is multi-id ONLY. A single refused id already
|
||||
// names itself on stderr, so adding `N of M issues failed to close` to it
|
||||
// would be noise — and this is the sole assertion pinning that
|
||||
// suppression. --json is different: TestParityCloseJSONFailureReport.
|
||||
if strings.Contains(res.stderr, "issues failed to close") {
|
||||
t.Errorf("stderr = %q, want no batch summary for a single id", res.stderr)
|
||||
}
|
||||
|
|
@ -1669,6 +1670,64 @@ func TestParityCloseNothingSettledExits1(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
// TestParityCloseJSONFailureReport pins the --json failure report for a
|
||||
// single refused id, the close twin of TestParityUpdateJSONFailureReport: a
|
||||
// consumer closing one id at a time must get a parseable reason, as it does
|
||||
// from `bd update --json`. stdout stays empty because nothing closed, the
|
||||
// inline refusal is unchanged, and the LAST stderr line is the compact JSON
|
||||
// report — with no text summary beside it. Source: cmd/bd/close.go
|
||||
// reportCloseFailures.
|
||||
func TestParityCloseJSONFailureReport(t *testing.T) {
|
||||
env := newParityEnv(t)
|
||||
env.seed("test-clsjf", "Owned by another actor", func(i *types.Issue) {
|
||||
i.Assignee = "someone-else"
|
||||
})
|
||||
|
||||
jsonOutput = true
|
||||
env.setFlags(closeCmd, nil)
|
||||
res := env.run(closeCmd, "test-clsjf")
|
||||
|
||||
if res.exitCode != 1 {
|
||||
t.Fatalf("exit = %d, want 1\nstderr:\n%s", res.exitCode, res.stderr)
|
||||
}
|
||||
if res.stdout != "" {
|
||||
t.Errorf("stdout = %q, want empty (no issue was closed)", res.stdout)
|
||||
}
|
||||
if env.get("test-clsjf").Status == types.StatusClosed {
|
||||
t.Error("the refused ID must not have been closed")
|
||||
}
|
||||
|
||||
refusal := fmt.Sprintf("cannot close %s: assignee is %q, actor is %q; reclaim or use --force to override",
|
||||
"test-clsjf", "someone-else", actor)
|
||||
lines := strings.Split(strings.TrimRight(res.stderr, "\n"), "\n")
|
||||
if len(lines) != 2 || lines[0] != refusal {
|
||||
t.Fatalf("stderr = %q, want the inline refusal %q and then one JSON report line", res.stderr, refusal)
|
||||
}
|
||||
var payload struct {
|
||||
Error string `json:"error"`
|
||||
SchemaVersion int `json:"schema_version"`
|
||||
Failed []struct {
|
||||
ID string `json:"id"`
|
||||
Error string `json:"error"`
|
||||
} `json:"failed"`
|
||||
}
|
||||
if err := json.Unmarshal([]byte(lines[1]), &payload); err != nil {
|
||||
t.Fatalf("last stderr line is not the JSON failure report: %v\nline: %s", err, lines[1])
|
||||
}
|
||||
if payload.Error != "1 of 1 issues failed to close" {
|
||||
t.Errorf("error = %q, want %q", payload.Error, "1 of 1 issues failed to close")
|
||||
}
|
||||
if payload.SchemaVersion != JSONSchemaVersion {
|
||||
t.Errorf("schema_version = %d, want %d", payload.SchemaVersion, JSONSchemaVersion)
|
||||
}
|
||||
if len(payload.Failed) != 1 {
|
||||
t.Fatalf("failed entries = %d, want 1", len(payload.Failed))
|
||||
}
|
||||
if payload.Failed[0].ID != "test-clsjf" || payload.Failed[0].Error != refusal {
|
||||
t.Errorf("failed[0] = %+v, want {ID:%s Error:%s}", payload.Failed[0], "test-clsjf", refusal)
|
||||
}
|
||||
}
|
||||
|
||||
// TestParityCloseAlreadyClosedIsIdempotentSuccess pins the re-close no-op:
|
||||
// exit 0, the issue still reported on stdout, last-touched still recorded, and
|
||||
// NO second close event. Source: cmd/bd/close.go:167-195.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue