mirror of
https://github.com/PerpetualSoftware/pad.git
synced 2026-11-27 10:22:07 +00:00
fix(mcp): remote needs not-mine and restore take an array ref (BUG-4891)
stdio expands an array ref into several positionals, since the CLI declares `not-mine <ref>...` and `restore <ref>...`. The remote dispatcher read ref as a string only, so an array came back as validation_failed "ref is required". The remote dispatcher now takes a string or an array of strings and processes each ref in order, stopping at the first error. On a call with several refs the error names the failing ref and the ones already done, as the CLI does; a single-ref call is unchanged. A to_role or to_user target is resolved once, and each item still gets its own seq-guarded PATCH before its PUT. Claude-Session: https://claude.ai/code/session_0191CBGZZkkPkm53xfTcPysi
This commit is contained in:
+2
-2
@@ -1085,9 +1085,9 @@ still rolls back atomically.
|
||||
`pad_needs` is the caller's own needs-you inbox (`GET /api/v1/me/needs`, see docs/api.md) and its "not mine" triage (TASK-4643). It is per person: nobody else's view changes. It is excluded from the ChatGPT surface (per-person inbox triage belongs to the web app). Both transports run the same steps: stdio through `pad needs ...`, remote through the dispatcher's special routes, every hop through the same authenticated request path, so scope checks apply to each.
|
||||
|
||||
- `list`: the rows `GET /me/needs` returns (oldest-waiting first), with `view` `active` (default) or `hidden`; pass a page's `next_cursor` back as `cursor` for the next page (`limit`: default 50, max 200). Only an EXPLICIT `workspace` narrows it: the session default (`pad_set_workspace`, `.pad.toml`) is not applied, because the inbox spans every workspace. The handler filters a token's workspace allow-list itself. Read-only.
|
||||
- `not-mine` (`ref`, one item): hides the item until it comes back to you: an open @mention of you, a status transition into a waiting status, a move into a waiting collection, an assignment to you, or a reminder due to you (the full rule is under `PUT .../needs/not-mine` in docs/api.md). The PUT body is `{}`: no marker, so the server records the item as it is now, and no `source`, which the server takes from how the request authenticated (`cli` for a token). Replaces any snooze of yours on the item.
|
||||
- `not-mine` (`ref`): hides the item until it comes back to you: an open @mention of you, a status transition into a waiting status, a move into a waiting collection, an assignment to you, or a reminder due to you (the full rule is under `PUT .../needs/not-mine` in docs/api.md). The PUT body is `{}`: no marker, so the server records the item as it is now, and no `source`, which the server takes from how the request authenticated (`cli` for a token). Replaces any snooze of yours on the item.
|
||||
- `to_role` (a role slug) or `to_user` (a member's name or email), never both, first gives the item away: `to_role` sets the role and clears the person, `to_user` sets the person. The dispatcher reads the item's `seq` and sends the existing item PATCH with that `expected_seq`; a stale seq is `update_conflict`, and an unknown role or member, or any refused PATCH, returns before the PUT, so nothing is written. If only the PUT fails, the reassignment stands and the error message says so ("the item was already given to ..."); retrying the same call is safe.
|
||||
- The result is `{results: [{ref, not_mine, given_to?}]}`, with `given_to: {kind: role|user, id, label}` when the item was reassigned.
|
||||
- `restore` (`ref`): removes your not-mine mark, then your dismissal or deferral. Both are idempotent. The result is `{results: [{ref, not_mine: null, snooze: null}]}`.
|
||||
|
||||
The CLI (`pad needs list|not-mine|restore`) takes several refs on `not-mine` and `restore`, processed in order, stopping at the first error and naming the refs already done.
|
||||
The CLI (`pad needs list|not-mine|restore`) takes several refs on `not-mine` and `restore`, processed in order, stopping at the first error and naming the refs already done. Both transports also take `ref` as an array of refs on these two actions with the same rule: one `results` entry per ref, in order; on an error, a call with several refs prefixes the message with the failing ref and appends `(already done: ...)`, and later refs are untouched. The schema keeps `ref` a string.
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
"github.com/PerpetualSoftware/pad/internal/models"
|
||||
"github.com/mark3labs/mcp-go/mcp"
|
||||
@@ -20,26 +21,32 @@ func needsItemURL(ws, ref string) string {
|
||||
return "/api/v1/workspaces/" + url.PathEscape(ws) + "/items/" + url.PathEscape(ref)
|
||||
}
|
||||
|
||||
// needsTarget reads ref and the workspace, which every needs write needs.
|
||||
func needsTarget(ctx context.Context, d *HTTPHandlerDispatcher, key string, input map[string]any) (ws, ref string, fail *CallToolResult) {
|
||||
// needsTargets reads the workspace and the refs, which every needs write
|
||||
// needs. ref is a string or, as stdio accepts (cmdhelp marks it repeatable),
|
||||
// an array of strings.
|
||||
func needsTargets(ctx context.Context, d *HTTPHandlerDispatcher, key string, input map[string]any) (ws string, refs []string, fail *CallToolResult) {
|
||||
ws, _ = input["workspace"].(string)
|
||||
if ws == "" {
|
||||
return "", "", noWorkspaceResult(ctx, d.Lister)
|
||||
return "", nil, noWorkspaceResult(ctx, d.Lister)
|
||||
}
|
||||
ref, _ = input["ref"].(string)
|
||||
if ref == "" {
|
||||
return "", "", validationFailedResult(key, "ref is required", "Pass the item ref, e.g. ref=TASK-5.")
|
||||
refs, err := bulkUpdateRefs(input["ref"])
|
||||
if err != nil {
|
||||
return "", nil, validationFailedResult(key, err.Error(), "Pass the item ref, e.g. ref=TASK-5, or an array of refs.")
|
||||
}
|
||||
return ws, ref, nil
|
||||
if len(refs) == 0 {
|
||||
return "", nil, validationFailedResult(key, "ref is required", "Pass the item ref, e.g. ref=TASK-5.")
|
||||
}
|
||||
return ws, refs, nil
|
||||
}
|
||||
|
||||
// dispatchNeedsNotMine is `needs not-mine`: with to_role or to_user it first
|
||||
// reassigns the item through the existing item PATCH, guarded by the seq it
|
||||
// reassigns each item through the existing item PATCH, guarded by the seq it
|
||||
// has just read, and only then marks it not mine with an empty body. A refused
|
||||
// lookup or PATCH returns before the PUT, so nothing is written.
|
||||
// lookup or PATCH returns before the PUT, so nothing is written for that ref.
|
||||
// Refs are processed in order and processing stops at the first error.
|
||||
func (d *HTTPHandlerDispatcher) dispatchNeedsNotMine(ctx context.Context, input map[string]any, user *models.User) (*CallToolResult, error) {
|
||||
const key = "needs not-mine"
|
||||
ws, ref, fail := needsTarget(ctx, d, key, input)
|
||||
ws, refs, fail := needsTargets(ctx, d, key, input)
|
||||
if fail != nil {
|
||||
return fail, nil
|
||||
}
|
||||
@@ -48,9 +55,10 @@ func (d *HTTPHandlerDispatcher) dispatchNeedsNotMine(ctx context.Context, input
|
||||
if toRole != "" && toUser != "" {
|
||||
return validationFailedResult(key, "to_role and to_user are mutually exclusive", "Pass one of them, or neither."), nil
|
||||
}
|
||||
var give map[string]any
|
||||
var givenTo map[string]any
|
||||
if toRole != "" || toUser != "" {
|
||||
patch := map[string]any{}
|
||||
give = map[string]any{}
|
||||
if toRole != "" {
|
||||
id, err := d.lookupRoleID(ctx, user, ws, toRole)
|
||||
if err != nil {
|
||||
@@ -59,7 +67,7 @@ func (d *HTTPHandlerDispatcher) dispatchNeedsNotMine(ctx context.Context, input
|
||||
}
|
||||
return validationFailedResult(key, "resolve to_role: "+err.Error(), "Pass an existing agent role slug."), nil
|
||||
}
|
||||
patch["agent_role_id"], patch["clear_assigned_user"] = id, true
|
||||
give["agent_role_id"], give["clear_assigned_user"] = id, true
|
||||
givenTo = map[string]any{"kind": "role", "id": id, "label": toRole}
|
||||
} else {
|
||||
id, err := d.lookupAssigneeID(ctx, user, ws, toUser)
|
||||
@@ -69,52 +77,83 @@ func (d *HTTPHandlerDispatcher) dispatchNeedsNotMine(ctx context.Context, input
|
||||
}
|
||||
return validationFailedResult(key, "resolve to_user: "+err.Error(), "Pass a workspace member's name or email."), nil
|
||||
}
|
||||
patch["assigned_user_id"] = id
|
||||
give["assigned_user_id"] = id
|
||||
givenTo = map[string]any{"kind": "user", "id": id, "label": toUser}
|
||||
}
|
||||
}
|
||||
entries := make([]any, 0, len(refs))
|
||||
for i, ref := range refs {
|
||||
entry, res, err := d.needsNotMineOne(ctx, key, user, ws, ref, give, givenTo)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
if res != nil {
|
||||
noteNeedsRefFailure(res, refs, i)
|
||||
return res, nil
|
||||
}
|
||||
entries = append(entries, entry)
|
||||
}
|
||||
return needsResults(key, entries), nil
|
||||
}
|
||||
|
||||
// needsNotMineOne gives one item away when give is set, then marks it not
|
||||
// mine. It returns the result entry, or the error result to stop on.
|
||||
func (d *HTTPHandlerDispatcher) needsNotMineOne(ctx context.Context, key string, user *models.User, ws, ref string, give, givenTo map[string]any) (any, *CallToolResult, error) {
|
||||
if give != nil {
|
||||
req, err := d.buildAuthedRequest(ctx, http.MethodGet, needsItemURL(ws, ref), nil, user)
|
||||
if err != nil {
|
||||
return buildRequestErrorResult(key, err), nil
|
||||
return nil, buildRequestErrorResult(key, err), nil
|
||||
}
|
||||
resp, exceeded := d.serveCapped(req)
|
||||
if exceeded {
|
||||
return responseTooLargeResult(key, d.responseMaxBytes()), nil
|
||||
return nil, responseTooLargeResult(key, d.responseMaxBytes()), nil
|
||||
}
|
||||
if resp.StatusCode >= 400 {
|
||||
return packageHTTPResponse(req.Context(), key, resp, d.Lister)
|
||||
res, err := packageHTTPResponse(req.Context(), key, resp, d.Lister)
|
||||
return nil, res, err
|
||||
}
|
||||
bodyBytes, err := io.ReadAll(resp.Body)
|
||||
_ = resp.Body.Close()
|
||||
if err != nil {
|
||||
return dispatcherErrorResult(key, "read item", err), nil
|
||||
return nil, dispatcherErrorResult(key, "read item", err), nil
|
||||
}
|
||||
var item struct {
|
||||
Seq int64 `json:"seq"`
|
||||
}
|
||||
if err := json.Unmarshal(bodyBytes, &item); err != nil {
|
||||
return dispatcherErrorResult(key, "decode item", err), nil
|
||||
return nil, dispatcherErrorResult(key, "decode item", err), nil
|
||||
}
|
||||
patch := make(map[string]any, len(give)+1)
|
||||
for k, v := range give {
|
||||
patch[k] = v
|
||||
}
|
||||
patch["expected_seq"] = item.Seq
|
||||
raw, err := json.Marshal(patch)
|
||||
if err != nil {
|
||||
return dispatcherErrorResult(key, "encode request", err), nil
|
||||
return nil, dispatcherErrorResult(key, "encode request", err), nil
|
||||
}
|
||||
res, err := d.executeRequest(ctx, key, user, http.MethodPatch, needsItemURL(ws, ref), raw)
|
||||
if err != nil || res.IsError {
|
||||
return res, err
|
||||
return nil, res, err
|
||||
}
|
||||
}
|
||||
res, err := d.executeRequest(ctx, key, user, http.MethodPut, needsItemURL(ws, ref)+"/needs/not-mine", []byte(`{}`))
|
||||
if err != nil {
|
||||
return res, err
|
||||
return nil, res, err
|
||||
}
|
||||
if res.IsError {
|
||||
if givenTo != nil {
|
||||
notePartialGive(res, givenTo["label"].(string))
|
||||
}
|
||||
return res, nil
|
||||
return nil, res, nil
|
||||
}
|
||||
return needsResults(res, givenTo), nil
|
||||
// The write has landed, so an unexpected body shape is passed through
|
||||
// rather than reported as a failure.
|
||||
entry := res.StructuredContent
|
||||
if m, ok := entry.(map[string]any); ok && m != nil && givenTo != nil {
|
||||
m["given_to"] = givenTo
|
||||
}
|
||||
return entry, nil, nil
|
||||
}
|
||||
|
||||
// notePartialGive prefixes the error message of a failed not-mine PUT that
|
||||
@@ -122,6 +161,27 @@ func (d *HTTPHandlerDispatcher) dispatchNeedsNotMine(ctx context.Context, input
|
||||
// already changed hands (the CLI says the same). Retrying the call is safe.
|
||||
func notePartialGive(res *CallToolResult, label string) {
|
||||
prefix := "the item was already given to " + label + ", but marking it not mine failed: "
|
||||
rewriteErrorMessage(res, func(msg string) string { return prefix + msg })
|
||||
}
|
||||
|
||||
// noteNeedsRefFailure names, on a call with several refs, the ref that failed
|
||||
// and the ones already done, as the CLI does. A single-ref error is unchanged.
|
||||
func noteNeedsRefFailure(res *CallToolResult, refs []string, failed int) {
|
||||
if len(refs) < 2 {
|
||||
return
|
||||
}
|
||||
rewriteErrorMessage(res, func(msg string) string {
|
||||
msg = refs[failed] + ": " + msg
|
||||
if failed > 0 {
|
||||
msg += " (already done: " + strings.Join(refs[:failed], ", ") + ")"
|
||||
}
|
||||
return msg
|
||||
})
|
||||
}
|
||||
|
||||
// rewriteErrorMessage applies edit to the message of an error result: the
|
||||
// envelope's error.message when the text is one, else the whole text.
|
||||
func rewriteErrorMessage(res *CallToolResult, edit func(string) string) {
|
||||
for i, c := range res.Content {
|
||||
tc, ok := c.(mcp.TextContent)
|
||||
if !ok {
|
||||
@@ -131,7 +191,7 @@ func notePartialGive(res *CallToolResult, label string) {
|
||||
if json.Unmarshal([]byte(tc.Text), &env) == nil {
|
||||
if e, ok := env["error"].(map[string]any); ok {
|
||||
msg, _ := e["message"].(string)
|
||||
e["message"] = prefix + msg
|
||||
e["message"] = edit(msg)
|
||||
if raw, err := json.Marshal(env); err == nil {
|
||||
tc.Text = string(raw)
|
||||
res.Content[i] = tc
|
||||
@@ -142,45 +202,45 @@ func notePartialGive(res *CallToolResult, label string) {
|
||||
}
|
||||
}
|
||||
}
|
||||
tc.Text = prefix + tc.Text
|
||||
tc.Text = edit(tc.Text)
|
||||
res.Content[i] = tc
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// dispatchNeedsRestore is `needs restore`: it removes the caller's not-mine
|
||||
// mark and then their snooze. Both DELETEs are idempotent.
|
||||
// dispatchNeedsRestore is `needs restore`: for each ref in order it removes
|
||||
// the caller's not-mine mark and then their snooze, stopping at the first
|
||||
// error. Both DELETEs are idempotent.
|
||||
func (d *HTTPHandlerDispatcher) dispatchNeedsRestore(ctx context.Context, input map[string]any, user *models.User) (*CallToolResult, error) {
|
||||
const key = "needs restore"
|
||||
ws, ref, fail := needsTarget(ctx, d, key, input)
|
||||
ws, refs, fail := needsTargets(ctx, d, key, input)
|
||||
if fail != nil {
|
||||
return fail, nil
|
||||
}
|
||||
for _, kind := range []string{"not-mine", "snooze"} {
|
||||
res, err := d.executeRequest(ctx, key, user, http.MethodDelete, needsItemURL(ws, ref)+"/needs/"+kind, nil)
|
||||
if err != nil || res.IsError {
|
||||
return res, err
|
||||
entries := make([]any, 0, len(refs))
|
||||
for i, ref := range refs {
|
||||
for _, kind := range []string{"not-mine", "snooze"} {
|
||||
res, err := d.executeRequest(ctx, key, user, http.MethodDelete, needsItemURL(ws, ref)+"/needs/"+kind, nil)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
if res.IsError {
|
||||
noteNeedsRefFailure(res, refs, i)
|
||||
return res, nil
|
||||
}
|
||||
}
|
||||
entries = append(entries, map[string]any{"ref": ref, "not_mine": nil, "snooze": nil})
|
||||
}
|
||||
payload := map[string]any{"results": []any{map[string]any{"ref": ref, "not_mine": nil, "snooze": nil}}}
|
||||
raw, _ := json.Marshal(payload)
|
||||
return structuredResult(payload, string(raw)), nil
|
||||
return needsResults(key, entries), nil
|
||||
}
|
||||
|
||||
// needsResults gives the remote result the CLI's JSON shape: {results: [...]},
|
||||
// one entry per ref, with given_to when the item was reassigned.
|
||||
func needsResults(res *CallToolResult, givenTo map[string]any) *CallToolResult {
|
||||
entry, ok := res.StructuredContent.(map[string]any)
|
||||
if !ok || entry == nil {
|
||||
return res
|
||||
}
|
||||
if givenTo != nil {
|
||||
entry["given_to"] = givenTo
|
||||
}
|
||||
payload := map[string]any{"results": []any{entry}}
|
||||
func needsResults(key string, entries []any) *CallToolResult {
|
||||
payload := map[string]any{"results": entries}
|
||||
raw, err := json.Marshal(payload)
|
||||
if err != nil {
|
||||
return dispatcherErrorResult("needs not-mine", "encode result", err)
|
||||
return dispatcherErrorResult(key, "encode result", err)
|
||||
}
|
||||
return structuredResult(payload, string(raw))
|
||||
}
|
||||
|
||||
@@ -284,3 +284,137 @@ func TestPadNeeds_RemotePutFailsAfterGiveSaysSo(t *testing.T) {
|
||||
t.Fatalf("error does not say the item was already reassigned: %s", txt)
|
||||
}
|
||||
}
|
||||
|
||||
// BUG-4891: stdio expands an array ref into several positionals (cmdhelp marks
|
||||
// ref repeatable), so the remote dispatcher takes one too: each ref in order,
|
||||
// stopping at the first error and naming the refs already done, as the CLI does.
|
||||
|
||||
// secondItem adds another item to the fixture's collection, assigned to the owner.
|
||||
func (f *clearFixture) secondItem(t *testing.T) *models.Item {
|
||||
t.Helper()
|
||||
item, err := f.store.CreateItem(f.workspace.ID, f.item.CollectionID, models.ItemCreate{
|
||||
Title: "Also assigned", AssignedUserID: &f.owner.ID, AgentRoleID: &f.role.ID,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return item
|
||||
}
|
||||
|
||||
func resultRefs(t *testing.T, res *CallToolResult) []string {
|
||||
t.Helper()
|
||||
var out struct {
|
||||
Results []struct {
|
||||
Ref string `json:"ref"`
|
||||
GivenTo json.RawMessage `json:"given_to"`
|
||||
} `json:"results"`
|
||||
}
|
||||
raw, _ := json.Marshal(res.StructuredContent)
|
||||
if err := json.Unmarshal(raw, &out); err != nil {
|
||||
t.Fatalf("result shape: %s (%v)", raw, err)
|
||||
}
|
||||
refs := make([]string, len(out.Results))
|
||||
for i, r := range out.Results {
|
||||
refs[i] = r.Ref
|
||||
}
|
||||
return refs
|
||||
}
|
||||
|
||||
func TestPadNeeds_RemoteNotMineArrayRef(t *testing.T) {
|
||||
f := newClearFixture(t)
|
||||
second := f.secondItem(t)
|
||||
other, err := f.store.CreateAgentRole(f.workspace.ID, models.AgentRoleCreate{Name: "Reviewer"})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
res := f.needsDispatch(t, nil, "not-mine", map[string]any{
|
||||
"workspace": f.workspace.Slug, "ref": []any{f.item.Slug, second.Slug}, "to_role": other.Slug,
|
||||
})
|
||||
if res.IsError {
|
||||
t.Fatalf("not-mine: %s", textOf(res))
|
||||
}
|
||||
for _, it := range []*models.Item{f.item, second} {
|
||||
got, err := f.store.GetItem(it.ID)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got.AgentRoleID == nil || *got.AgentRoleID != other.ID {
|
||||
t.Fatalf("%s role = %v, want %s", it.Slug, got.AgentRoleID, other.ID)
|
||||
}
|
||||
if nm, err := f.store.GetNeedsNotMine(f.owner.ID, it.ID); err != nil || nm == nil {
|
||||
t.Fatalf("%s not-mine row: %+v %v", it.Slug, nm, err)
|
||||
}
|
||||
}
|
||||
if got := resultRefs(t, res); len(got) != 2 {
|
||||
t.Fatalf("want one result per ref, got %v", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPadNeeds_RemoteRestoreArrayRef(t *testing.T) {
|
||||
f := newClearFixture(t)
|
||||
second := f.secondItem(t)
|
||||
for _, it := range []*models.Item{f.item, second} {
|
||||
if _, err := f.store.MarkNeedsNotMine(f.owner.ID, f.workspace.ID, it.ID, models.NeedsSourceCLI, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
res := f.needsDispatch(t, nil, "restore", map[string]any{
|
||||
"workspace": f.workspace.Slug, "ref": []string{f.item.Slug, second.Slug},
|
||||
})
|
||||
if res.IsError {
|
||||
t.Fatalf("restore: %s", textOf(res))
|
||||
}
|
||||
for _, it := range []*models.Item{f.item, second} {
|
||||
if nm, err := f.store.GetNeedsNotMine(f.owner.ID, it.ID); err != nil || nm != nil {
|
||||
t.Fatalf("%s not-mine survived restore: %+v %v", it.Slug, nm, err)
|
||||
}
|
||||
}
|
||||
if got := resultRefs(t, res); len(got) != 2 || got[0] != f.item.Slug || got[1] != second.Slug {
|
||||
t.Fatalf("results out of order: %v", got)
|
||||
}
|
||||
}
|
||||
|
||||
// A ref that fails stops the run: later refs are untouched and the error names
|
||||
// the failing ref and the ones already done.
|
||||
func TestPadNeeds_RemoteArrayRefStopsAtFirstError(t *testing.T) {
|
||||
f := newClearFixture(t)
|
||||
second := f.secondItem(t)
|
||||
for _, verb := range []string{"not-mine", "restore"} {
|
||||
if verb == "restore" {
|
||||
if _, err := f.store.MarkNeedsNotMine(f.owner.ID, f.workspace.ID, second.ID, models.NeedsSourceCLI, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
res := f.needsDispatch(t, nil, verb, map[string]any{
|
||||
"workspace": f.workspace.Slug, "ref": []any{f.item.Slug, "TASK-99999", second.Slug},
|
||||
})
|
||||
if !res.IsError {
|
||||
t.Fatalf("%s: want an error result, got %s", verb, textOf(res))
|
||||
}
|
||||
txt := textOf(res)
|
||||
if !strings.Contains(txt, "TASK-99999: ") || !strings.Contains(txt, "(already done: "+f.item.Slug+")") {
|
||||
t.Fatalf("%s: error does not name the failing ref and the done ones: %s", verb, txt)
|
||||
}
|
||||
nm, err := f.store.GetNeedsNotMine(f.owner.ID, second.ID)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if (verb == "not-mine") != (nm == nil) {
|
||||
t.Fatalf("%s: the ref after the failure was processed: %+v", verb, nm)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// A malformed array is refused before anything is written.
|
||||
func TestPadNeeds_RemoteArrayRefMalformed(t *testing.T) {
|
||||
f := newClearFixture(t)
|
||||
for _, ref := range []any{[]any{f.item.Slug, 5}, []any{f.item.Slug, ""}, []any{}} {
|
||||
res := f.needsDispatch(t, nil, "not-mine", map[string]any{"workspace": f.workspace.Slug, "ref": ref})
|
||||
if !res.IsError || !strings.Contains(textOf(res), "validation_failed") {
|
||||
t.Fatalf("ref %v: want validation_failed, got %s", ref, textOf(res))
|
||||
}
|
||||
if nm, err := f.store.GetNeedsNotMine(f.owner.ID, f.item.ID); err != nil || nm != nil {
|
||||
t.Fatalf("ref %v: wrote a not-mine row: %+v %v", ref, nm, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user