From 2b4ef97b39a3b8c59e1d7821ee13bac2db20395d Mon Sep 17 00:00:00 2001 From: Sutu Sebastian Date: Tue, 17 Nov 2026 13:46:45 +0200 Subject: [PATCH 01/14] feat(drain): add reply seam, marker, and locked ledger --- internal/core/drain/ledger.go | 52 +++++++++++++++ internal/core/drain/ledger_test.go | 47 ++++++++++++++ internal/core/hostcaps.go | 23 ++++++- internal/core/hostcaps_test.go | 27 +++++++- internal/core/post/host.go | 48 ++++++++++++++ internal/core/post/host_reply.go | 68 ++++++++++++++++++++ internal/core/post/host_reply_test.go | 73 ++++++++++++++++++++++ internal/core/threads/reply_marker_test.go | 34 ++++++++++ internal/core/threads/threads.go | 28 ++++++++- 9 files changed, 393 insertions(+), 7 deletions(-) create mode 100644 internal/core/drain/ledger.go create mode 100644 internal/core/drain/ledger_test.go create mode 100644 internal/core/post/host_reply.go create mode 100644 internal/core/post/host_reply_test.go create mode 100644 internal/core/threads/reply_marker_test.go diff --git a/internal/core/drain/ledger.go b/internal/core/drain/ledger.go new file mode 100644 index 000000000..3a7ca57b0 --- /dev/null +++ b/internal/core/drain/ledger.go @@ -0,0 +1,52 @@ +package drain + +import ( + "encoding/json" + "errors" + "io/fs" + + "github.com/stainless-code/verdict/internal/atomic" + "github.com/stainless-code/verdict/internal/jq" + "github.com/stainless-code/verdict/internal/storelock" +) + +// AppendLedger records one successful reply under the store lock. A crash +// after a host write but before this call is the only unrecorded window; once +// the entry lands, the next drain reads it and makes no second host write. +func AppendLedger(path string, entry LedgerEntry) error { + unlock, err := storelock.Acquire(path, storelock.DefaultWait) + if err != nil { + return jq.NewErrf("could not lock %s: %v", path, err) + } + defer unlock() + entries, err := readLedger(path) + if err != nil { + return err + } + entries = append(entries, entry) + raw, err := json.MarshalIndent(entries, "", " ") + if err != nil { + return jq.NewErrf("could not encode %s: %v", path, err) + } + if err := atomic.WriteFile(path, append(raw, '\n')); err != nil { + return jq.NewErrf("could not write %s: %v", path, err) + } + return nil +} + +// readLedger reads the shared address-reviews ledger. An absent file is an +// empty one; a corrupt file refuses instead of being read as nobody replied. +func readLedger(path string) ([]LedgerEntry, error) { + raw, err := jq.CappedFile(path, jq.MaxPRBytes) + if err != nil { + if errors.Is(err, fs.ErrNotExist) { + return []LedgerEntry{}, nil + } + return nil, jq.NewErrf("unreadable %s: %v", path, err) + } + var entries []LedgerEntry + if err := json.Unmarshal(raw, &entries); err != nil { + return nil, jq.NewErrf("unreadable %s: %v", path, err) + } + return entries, nil +} diff --git a/internal/core/drain/ledger_test.go b/internal/core/drain/ledger_test.go new file mode 100644 index 000000000..989e6e937 --- /dev/null +++ b/internal/core/drain/ledger_test.go @@ -0,0 +1,47 @@ +package drain + +import ( + "encoding/json" + "os" + "path/filepath" + "testing" +) + +// TestAppendLedgerKeepsLegacyEntries pins the shared format: one drain entry +// appended under the lock without rewriting the address-reviews entries. +func TestAppendLedgerKeepsLegacyEntries(t *testing.T) { + path := filepath.Join(t.TempDir(), KeyLedgerJSON) + legacy := `[{"thread":"PRRT_old","reply_id":"900","at":"2026-11-04T00:00:00Z"}]` + "\n" + if err := os.WriteFile(path, []byte(legacy), 0o600); err != nil { + t.Fatal(err) + } + entries := []LedgerEntry{ + {Thread: "PRRT_1", ReplyID: "77", At: "2026-11-05T00:00:00Z", InReplyTo: "102", By: ReplyBy}, + {Thread: "PRRT_2", ReplyID: "88", At: "2026-11-05T00:01:00Z", InReplyTo: "202", By: ReplyBy}, + } + for _, entry := range entries { + if err := AppendLedger(path, entry); err != nil { + t.Fatalf("AppendLedger: %v", err) + } + } + got, err := readLedgerForTest(path) + if err != nil { + t.Fatal(err) + } + if len(got) != 3 || got[0].Thread != "PRRT_old" || got[0].InReplyTo != "" || + got[1] != entries[0] || got[2] != entries[1] { + t.Fatalf("ledger = %+v", got) + } +} + +func readLedgerForTest(path string) ([]LedgerEntry, error) { + raw, err := os.ReadFile(path) + if err != nil { + return nil, err + } + var entries []LedgerEntry + if err := json.Unmarshal(raw, &entries); err != nil { + return nil, err + } + return entries, nil +} diff --git a/internal/core/hostcaps.go b/internal/core/hostcaps.go index e75f8f39d..890199ff3 100644 --- a/internal/core/hostcaps.go +++ b/internal/core/hostcaps.go @@ -20,6 +20,9 @@ type HostCapabilities struct { Approve bool RequestChanges bool ThreadResolution bool + // ThreadReply is drain's host reply call. It is internal to post mode in + // v1, so it is not published in data.capabilities and adds no fetch golden. + ThreadReply bool // ReviewVerdicts is the compatibility sum of Approve and RequestChanges. // CapabilitiesFor derives it, so no table row can claim a verdict pair it // does not carry; new readers branch on the two split flags instead. @@ -38,6 +41,8 @@ const ( CapabilityApprove = "approve" CapabilityRequestChanges = "request_changes" CapabilityThreadResolution = "thread_resolution" + // CapabilityThreadReply names the internal capability drain's reply gate. + CapabilityThreadReply = "thread_reply" ) // capabilityTotal is how many capability names the table publishes. Unsupported @@ -66,6 +71,8 @@ const ( // it has no documented resolve endpoint, so resolution stays a manual // host/CLI step there. reasonNoResolveMutation = "no-resolve-mutation" + // reasonNoThreadReply names a posting host with no reply endpoint. + reasonNoThreadReply = "no-thread-reply" ) // CapabilityGap is one absent capability and the code that says why. @@ -91,11 +98,11 @@ var hostCapabilities = map[string]HostCapabilities{ providerGitHub: { Provider: providerGitHub, Fetch: true, Post: true, InlineAnchors: true, Approve: true, RequestChanges: true, - ThreadResolution: true, + ThreadResolution: true, ThreadReply: true, }, providerGitLab: { Provider: providerGitLab, Fetch: true, Post: true, InlineAnchors: true, - Approve: true, ThreadResolution: true, + Approve: true, ThreadResolution: true, ThreadReply: true, }, providerGitCafe: {Provider: providerGitCafe, Fetch: true}, providerForgejo: { @@ -167,6 +174,18 @@ func (c HostCapabilities) ReasonFor(capability string) string { return "" } +// ThreadReplyReason returns the published cause for a host with no reply +// call: a host with no submit path says so, and a posting host names the gap. +func (c HostCapabilities) ThreadReplyReason() string { + if c.ThreadReply { + return "" + } + if !c.Post { + return c.submitReason(reasonNoThreadReply) + } + return reasonNoThreadReply +} + // submitReason names why one submit-side capability is absent: the host has no // submit path at all, or it posts without that one write. func (c HostCapabilities) submitReason(without string) string { diff --git a/internal/core/hostcaps_test.go b/internal/core/hostcaps_test.go index ca8b3cbf8..3bb1c28ce 100644 --- a/internal/core/hostcaps_test.go +++ b/internal/core/hostcaps_test.go @@ -14,11 +14,11 @@ func TestCapabilityTable(t *testing.T) { "github": { Provider: "github", Fetch: true, Post: true, InlineAnchors: true, Approve: true, RequestChanges: true, ReviewVerdicts: true, - ThreadResolution: true, + ThreadResolution: true, ThreadReply: true, }, "gitlab": { Provider: "gitlab", Fetch: true, Post: true, InlineAnchors: true, - Approve: true, ThreadResolution: true, + Approve: true, ThreadResolution: true, ThreadReply: true, }, "gitcafe": {Provider: "gitcafe", Fetch: true}, "forgejo": { @@ -48,6 +48,29 @@ func TestCapabilityTable(t *testing.T) { } } +// TestThreadReplyCapability pins the two hosts that carry drain's reply call. +// A third host advertising it would let post mode aim a write at a host with +// no endpoint for it. +func TestThreadReplyCapability(t *testing.T) { + t.Parallel() + for _, tc := range []struct { + provider string + want bool + }{ + {provider: "github", want: true}, + {provider: "gitlab", want: true}, + {provider: "forgejo", want: false}, + {provider: "gitcafe", want: false}, + {provider: "bitbucket", want: false}, + {provider: "azure", want: false}, + {provider: "codeberg", want: false}, + } { + if got := CapabilitiesFor(tc.provider).ThreadReply; got != tc.want { + t.Errorf("%s: ThreadReply = %v, want %v", tc.provider, got, tc.want) + } + } +} + // TestReviewVerdictsIsTheAND proves the compatibility sum cannot be declared: // it is approve && request_changes on every host, including the unknown one. func TestReviewVerdictsIsTheAND(t *testing.T) { diff --git a/internal/core/post/host.go b/internal/core/post/host.go index a841ff7b6..673c2d059 100644 --- a/internal/core/post/host.go +++ b/internal/core/post/host.go @@ -39,6 +39,13 @@ type hostResolver interface { repo, pr, threadID string) error } +// hostReplier is the reply half: the one call that answers a waiting comment +// in a thread verdict authored. Only hosts with a reply endpoint get one. +type hostReplier interface { + replyThread(ctx context.Context, cmdr Commander, env map[string]string, + repo, pr, rootID, threadID, body string) (string, error) +} + // hostFor is the post path's only provider switch: every host behavior a verb // reaches goes through the triple it returns. A provider outside the switch // gets GitHub's writer and reader, because checkBundle refuses a host it @@ -57,6 +64,47 @@ func hostFor(provider string) (hostWriter, hostReader, hostResolver) { } } +// replierFor is post mode's only reply-provider switch. A host with no reply +// endpoint gets nil, and the capability gate refuses before a call is built. +func replierFor(provider string) hostReplier { + switch provider { + case providerGitHub: + return githubHost{} + case providerGitLab: + return gitlabHost{} + default: + return nil + } +} + +// ReplyThread answers one waiting comment through the host seam and returns +// the host's id for the new reply. A host without the capability refuses typed +// before any call; a failed call keeps the host's own reason where it has one. +func ReplyThread( + ctx context.Context, cmdr Commander, provider string, env map[string]string, + repo, pr, rootID, threadID, body string, +) (string, *core.RefusalError) { + caps := core.CapabilitiesFor(provider) + replier := replierFor(provider) + if !caps.ThreadReply || replier == nil { + return "", &core.RefusalError{Code: codeProviderUnimplemented, Message: fmt.Sprintf( + "thread replies on %s are not implemented (%s)", + provider, caps.ThreadReplyReason())} + } + if cmdr == nil { + return "", &core.RefusalError{Code: codeThreadsFailed, Message: "threads failed: no commander in runtime"} + } + id, err := replier.replyThread(ctx, cmdr, env, repo, pr, rootID, threadID, body) + if err != nil { + if ref, ok := errors.AsType[*core.RefusalError](err); ok { + return "", ref + } + return "", &core.RefusalError{Code: codeThreadsFailed, Message: fmt.Sprintf( + "could not reply to thread %s: %v", threadID, err)} + } + return id, nil +} + // SelfLogin reads the authenticated login the resolve identity gate compares // the thread root author against. func SelfLogin( diff --git a/internal/core/post/host_reply.go b/internal/core/post/host_reply.go new file mode 100644 index 000000000..40a3d0629 --- /dev/null +++ b/internal/core/post/host_reply.go @@ -0,0 +1,68 @@ +package postcore + +import ( + "context" + "fmt" + "net/url" + + "github.com/stainless-code/verdict/internal/core" + "github.com/stainless-code/verdict/internal/jq" +) + +// replyThread posts one drain reply on GitHub as a direct reply to the root +// comment. The body is one -f field, never part of a shell command. +func (githubHost) replyThread(ctx context.Context, cmdr Commander, _ map[string]string, + repo, pr, rootID, _, body string, +) (string, error) { + argv := []string{ + toolGH, cmdAPI, flagMethod, methodPost, + ghReposPrefix + repo + "/pulls/" + pr + "/comments/" + rootID + "/replies", + flagRawField, "body=" + body, + } + res, err := cmdr.Run(ctx, &core.Command{Argv: argv}) + if err != nil { + return "", jq.NewErrf("github reply thread: %v", err) + } + if res.ExitCode != 0 { + return "", &core.RefusalError{Code: codeThreadsFailed, Message: fmt.Sprintf( + "github did not reply to comment %s: %s", rootID, firstReason(res.Stderr))} + } + return replyID(res.Stdout) +} + +// replyThread posts one drain reply as a GitLab discussion note. Like the +// other GitLab writes, the JSON body arrives on stdin with the content type +// pinned on argv. +func (gitlabHost) replyThread(ctx context.Context, cmdr Commander, _ map[string]string, + repo, pr, _, threadID, body string, +) (string, error) { + endpoint := gitlabEndpoint(repo, pr, + gitlabDiscussionsPath+"/"+url.PathEscape(threadID)+gitlabNotesPath) + argv := []string{ + toolGlab, cmdAPI, endpoint, flagMethod, methodPost, + flagHeader, gitlabContentType, flagInput, "-", + } + res, err := gitlabCall(ctx, cmdr, argv, jq.NewObj("body", body).MarshalPretty()) + if err != nil { + return "", err + } + if res.ExitCode != 0 { + return "", &core.RefusalError{Code: codeThreadsFailed, Message: fmt.Sprintf( + "gitlab did not reply to discussion %s: %s", threadID, firstReason(res.Stderr))} + } + return replyID(res.Stdout) +} + +// replyID reads the new note id from a host reply. Both hosts accept a number +// or a string; a reply the host did not identify cannot enter the ledger. +func replyID(stdout string) (string, error) { + doc, err := jq.Decode([]byte(stdout)) + if err != nil { + return "", jq.NewErrf("reply response unreadable: %v", err) + } + id, ok := navField(doc, "id") + if !ok || jq.Falsey(id) { + return "", jq.NewErr("reply response carried no id") + } + return jq.Str(id), nil +} diff --git a/internal/core/post/host_reply_test.go b/internal/core/post/host_reply_test.go new file mode 100644 index 000000000..f5f0f877e --- /dev/null +++ b/internal/core/post/host_reply_test.go @@ -0,0 +1,73 @@ +package postcore + +import ( + "context" + "strings" + "testing" + + "github.com/stainless-code/verdict/internal/core" + "github.com/stainless-code/verdict/internal/jq" +) + +// TestReplyThreadArgv pins the exact host calls drain makes and the body each +// one carries. The body is one argv field on GitHub and one stdin document on +// GitLab; no shell or interpolation sits between the draft and the host. +func TestReplyThreadArgv(t *testing.T) { + const body = "answer with @alice and `quotes`\n" + cases := []struct { + name, provider, call, stdin, id string + }{ + { + name: "github", provider: "github", id: "77", + call: "gh\x00api\x00--method\x00POST\x00repos/acme/app/pulls/7/comments/101/replies\x00-f\x00body=" + body, + }, + { + name: "gitlab", provider: "gitlab", id: "88", + call: "glab\x00api\x00projects/acme%2Fapp/merge_requests/7/discussions/PRRT_1/notes\x00--method\x00POST\x00--header\x00Content-Type: application/json\x00--input\x00-", + stdin: "{\"body\":\"answer with @alice and `quotes`\\n\"}", + }, + } + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + cmdr := &scriptCommander{t: t, out: map[string]scriptResult{ + tc.call: {stdout: `{"id":` + tc.id + `}`}, + }} + got, ref := ReplyThread(context.Background(), cmdr, tc.provider, nil, + "acme/app", "7", "101", "PRRT_1", body) + if ref != nil { + t.Fatalf("ReplyThread refused: %+v", ref) + } + if got != tc.id { + t.Errorf("reply id = %q, want %q", got, tc.id) + } + if len(cmdr.calls) != 1 || strings.Join(cmdr.calls[0], "\x00") != tc.call { + t.Fatalf("calls = %q, want %q", cmdr.calls, tc.call) + } + if tc.stdin != "" { + doc, err := jq.Decode([]byte(cmdr.stdin[0])) + obj, ok := jq.AsMap(doc) + if err != nil || !ok || jq.R(jq.Alt(obj["body"], "")) != body { + t.Errorf("stdin body = %q (err %v), want %q", cmdr.stdin[0], err, body) + } + } + }) + } +} + +// TestReplyThreadRefusesUnsupportedHost pins the capability gate: Forgejo gets +// a typed refusal and the host is never called. +func TestReplyThreadRefusesUnsupportedHost(t *testing.T) { + cmdr := &scriptCommander{t: t, out: map[string]scriptResult{}} + _, ref := ReplyThread(context.Background(), cmdr, "forgejo", nil, + "acme/app", "7", "101", "PRRT_1", "answer") + if ref == nil || ref.Code != "provider-unimplemented" { + t.Fatalf("refusal = %+v, want provider-unimplemented", ref) + } + if !strings.Contains(ref.Message, core.CapabilitiesFor("forgejo").ThreadReplyReason()) { + t.Errorf("message %q did not name the reason %q", ref.Message, + core.CapabilitiesFor("forgejo").ThreadReplyReason()) + } + if len(cmdr.calls) != 0 { + t.Errorf("unsupported host made %d call(s)", len(cmdr.calls)) + } +} diff --git a/internal/core/threads/reply_marker_test.go b/internal/core/threads/reply_marker_test.go new file mode 100644 index 000000000..09c495c2c --- /dev/null +++ b/internal/core/threads/reply_marker_test.go @@ -0,0 +1,34 @@ +package threadscore + +import "testing" + +// TestReplyMarkerRoundTrip pins the hidden marker drain appends and the author +// label a fresh threads refresh gives the reply. A quoted marker is not the +// final line and must not make a human comment verdict-authored. +func TestReplyMarkerRoundTrip(t *testing.T) { + thread, waiting := "PRRT_1", "456" + marker := ReplyMarker(thread, waiting) + if want := ""; marker != want { + t.Fatalf("ReplyMarker = %q, want %q", marker, want) + } + body := "Here is the answer.\n\n" + marker + if !IsVerdictBody(body) { + t.Error("a posted reply body did not read as verdict-marked") + } + if got := AuthorKind("alice", false, body); got != AuthorVerdict { + t.Errorf("AuthorKind = %q, want %q", got, AuthorVerdict) + } + quoted := "you wrote " + marker + "\nstill a human reply" + if IsVerdictBody(quoted) { + t.Error("a quoted marker read as the final line") + } + if got := AuthorKind("alice", false, quoted); got != AuthorHuman { + t.Errorf("quoted AuthorKind = %q, want %q", got, AuthorHuman) + } + if id, to, ok := ReplyTarget(body); !ok || id != thread || to != waiting { + t.Errorf("ReplyTarget = %q, %q, %v; want %q, %q, true", id, to, ok, thread, waiting) + } + if _, _, ok := ReplyTarget(quoted); ok { + t.Error("ReplyTarget read a quoted marker") + } +} diff --git a/internal/core/threads/threads.go b/internal/core/threads/threads.go index c31b0e556..f4ed16c2a 100644 --- a/internal/core/threads/threads.go +++ b/internal/core/threads/threads.go @@ -311,6 +311,13 @@ const summaryMarkerFormat = "" // distinct from both finding and review markers. var summaryMarkerRe = regexp.MustCompile(`^$`) +// replyMarkerFormat is the hidden final line drain appends to a posted reply. +// It binds the reply to the thread and the waiting comment it answers. +const replyMarkerFormat = "" + +// replyMarkerRe reads only a body's final line, and only ids without whitespace. +var replyMarkerRe = regexp.MustCompile(`^$`) + // SummaryMarker renders the hidden final line of a PR-level summary comment. func SummaryMarker(head string) string { return fmt.Sprintf(summaryMarkerFormat, head) @@ -321,6 +328,20 @@ func HasSummaryMarker(body string) bool { return summaryMarkerRe.MatchString(finalLine(body)) } +// ReplyMarker renders the hidden final line of one drain reply. +func ReplyMarker(threadID, waitingID string) string { + return fmt.Sprintf(replyMarkerFormat, threadID, waitingID) +} + +// ReplyTarget reads the thread and waiting comment one drain reply answered. +func ReplyTarget(body string) (threadID, waitingID string, ok bool) { + m := replyMarkerRe.FindStringSubmatch(finalLine(body)) + if m == nil { + return "", "", false + } + return m[1], m[2], true +} + // FindingMarker renders the hidden final line carrying a finding sig. func FindingMarker(sig string) string { return fmt.Sprintf(findingMarkerFormat, sig) @@ -336,11 +357,12 @@ func FindingSig(body string) (string, bool) { } // IsVerdictBody reports whether a body carries a verdict marker as its final -// line: a finding marker on an inline comment, the review marker, or the -// summary comment marker. Used only for the advisory author_kind label. +// line: a finding, review, summary, or drain reply marker. Used only for the +// advisory author_kind label. func IsVerdictBody(body string) bool { last := finalLine(body) - return findingMarkerRe.MatchString(last) || reviewMarkerRe.MatchString(last) || summaryMarkerRe.MatchString(last) + return findingMarkerRe.MatchString(last) || reviewMarkerRe.MatchString(last) || + summaryMarkerRe.MatchString(last) || replyMarkerRe.MatchString(last) } // AuthorKind classifies one comment author: verdict when its own marker is the From 2715ca123a063efa9f868a816fea9983f39937a5 Mon Sep 17 00:00:00 2001 From: Sutu Sebastian Date: Tue, 17 Nov 2026 13:51:18 +0200 Subject: [PATCH 02/14] feat(drain): post marked replies under the live refresh gates --- internal/core/drain/plan.go | 21 ++- internal/core/drain/post.go | 154 ++++++++++++++++++++ internal/core/drain/post_test.go | 224 +++++++++++++++++++++++++++++ internal/core/post/secretvalues.go | 9 ++ internal/drain/post.go | 107 ++++++++++++++ internal/drain/verb.go | 15 +- internal/drain/verb_test.go | 11 ++ 7 files changed, 536 insertions(+), 5 deletions(-) create mode 100644 internal/core/drain/post.go create mode 100644 internal/core/drain/post_test.go create mode 100644 internal/drain/post.go diff --git a/internal/core/drain/plan.go b/internal/core/drain/plan.go index 67be9eb2c..2b7847065 100644 --- a/internal/core/drain/plan.go +++ b/internal/core/drain/plan.go @@ -3,6 +3,7 @@ package drain import ( "crypto/sha256" "encoding/hex" + "encoding/json" "fmt" "strings" @@ -26,7 +27,9 @@ const ( CodeDraftsInvalid = "drafts-invalid" // CodeDraftsStale refuses a draft written against another plan. CodeDraftsStale = "drafts-stale" - keyThreadID = "thread_id" + // CodeDrainIncomplete refuses a post run after some writes failed. + CodeDrainIncomplete = "drain-incomplete" + keyThreadID = "thread_id" ) // Dispositions counts the draft verdicts the agent chose. @@ -173,3 +176,19 @@ func WritePlan(path string, f *File) error { } return atomic.WriteFile(path, []byte(jq.PrettyOrdered(f.Wire()))) } + +// ReadPlan reads the plan a draft was written against. +func ReadPlan(path string) (*File, error) { + raw, err := jq.CappedFile(path, jq.MaxPRBytes) + if err != nil { + return nil, jq.NewErrf("read plan: %v", err) + } + var f File + if err := json.Unmarshal(raw, &f); err != nil { + return nil, jq.NewErrf("decode plan: %v", err) + } + if f.SchemaVersion != SchemaVersion { + return nil, jq.NewErrf("plan schema_version %q, want %q", f.SchemaVersion, SchemaVersion) + } + return &f, nil +} diff --git a/internal/core/drain/post.go b/internal/core/drain/post.go new file mode 100644 index 000000000..fdb533b08 --- /dev/null +++ b/internal/core/drain/post.go @@ -0,0 +1,154 @@ +package drain + +import ( + "bytes" + "encoding/json" + "fmt" + "strings" + + "github.com/stainless-code/verdict/internal/core" + postcore "github.com/stainless-code/verdict/internal/core/post" + recordcore "github.com/stainless-code/verdict/internal/core/record" + threadscore "github.com/stainless-code/verdict/internal/core/threads" +) + +// ReasonStaleThread names a draft whose waiting comment changed after the +// plan was made: the agent answered a question that is no longer the last one. +const ReasonStaleThread = "stale-thread" + +// PostRequest carries one post run. The write callbacks are injected so the +// ordering and the idempotency rules can be tested without a host. +type PostRequest struct { + Plan *File + DraftsRaw []byte + Feed *threadscore.File + Ledger []LedgerEntry + Provider string + Repo string + PR string + At string + Reply func(rootID, threadID, body string) (string, error) + Resolve func(threadID string) error + Append func(LedgerEntry) error + SaveFeed func(*threadscore.File) error +} + +// PostResult is what the final receipt records. +type PostResult struct { + Posted []Posted + Failed []Failed + Incomplete bool +} + +// Post runs §6's gates in order, then posts each draft and records one ledger +// entry per successful write. A host failure is recorded and the remaining +// drafts are still attempted; the caller turns Incomplete into a refusal. +func Post(req *PostRequest) (*PostResult, *core.RefusalError) { + if req.Plan == nil || req.Feed == nil { + return nil, &core.RefusalError{Code: CodeDrainFailed, Message: "drain-failed: no plan or thread feed to post against"} + } + if len(bytes.TrimSpace(req.DraftsRaw)) == 0 { + return nil, invalid("root", "no drafts; run drain --agent first") + } + summary, noDraftsSkips, ref := CheckDrafts(req.DraftsRaw, req.Plan) + if ref != nil { + return nil, ref + } + req.Plan.Drafts = summary + req.Plan.Skipped = append(req.Plan.Skipped, noDraftsSkips...) + caps := core.CapabilitiesFor(req.Provider) + if !caps.ThreadReply { + return nil, &core.RefusalError{Code: "provider-unimplemented", Message: fmt.Sprintf( + "thread replies on %s are not implemented (%s)", req.Provider, caps.ThreadReplyReason())} + } + var doc RepliesFile + if err := json.Unmarshal(req.DraftsRaw, &doc); err != nil { + return nil, invalid("root", err.Error()) + } + if ref := secretGate(doc.Replies); ref != nil { + return nil, ref + } + byID := make(map[string]*threadscore.Thread, len(req.Feed.Threads)) + for i := range req.Feed.Threads { + byID[req.Feed.Threads[i].ID] = &req.Feed.Threads[i] + } + res := &PostResult{Posted: []Posted{}, Failed: []Failed{}} + for _, reply := range doc.Replies { + postOne(req, byID, reply, res) + } + req.Plan.Posted = res.Posted + req.Plan.Failed = res.Failed + at := req.At + req.Plan.PostedAt = &at + if req.SaveFeed != nil { + if err := req.SaveFeed(req.Feed); err != nil { + res.Failed = append(res.Failed, Failed{ThreadID: "", Reason: "could not update threads.json: " + err.Error()}) + req.Plan.Failed = res.Failed + } + } + res.Incomplete = len(res.Failed) > 0 + return res, nil +} + +func postOne(req *PostRequest, byID map[string]*threadscore.Thread, reply Reply, res *PostResult) { + thread, ok := byID[reply.ThreadID] + if !ok || len(thread.Comments) == 0 { + res.Failed = append(res.Failed, Failed{ThreadID: reply.ThreadID, Reason: "thread missing from refreshed feed"}) + return + } + last := thread.Comments[len(thread.Comments)-1] + switch { + case thread.Resolved: + req.Plan.Skipped = append(req.Plan.Skipped, Skip{ThreadID: reply.ThreadID, Reason: ReasonResolved}) + return + case last.ID != reply.WaitingCommentID: + req.Plan.Skipped = append(req.Plan.Skipped, Skip{ThreadID: reply.ThreadID, Reason: ReasonStaleThread}) + return + case answered(req.Ledger, reply.ThreadID, &last): + req.Plan.Skipped = append(req.Plan.Skipped, Skip{ThreadID: reply.ThreadID, Reason: ReasonAlreadyReplied}) + return + case reply.Disposition == DispositionDefer: + req.Plan.Skipped = append(req.Plan.Skipped, Skip{ThreadID: reply.ThreadID, Reason: "defer"}) + return + } + body := recordcore.NeutralizeMentions(reply.Body) + "\n\n" + + threadscore.ReplyMarker(reply.ThreadID, reply.WaitingCommentID) + id, err := req.Reply(thread.Comments[0].ID, reply.ThreadID, body) + if err != nil { + res.Failed = append(res.Failed, Failed{ThreadID: reply.ThreadID, Reason: err.Error()}) + return + } + entry := LedgerEntry{Thread: reply.ThreadID, ReplyID: id, At: req.At, + InReplyTo: reply.WaitingCommentID, By: ReplyBy} + if err := req.Append(entry); err != nil { + res.Failed = append(res.Failed, Failed{ThreadID: reply.ThreadID, Reason: "could not record reply: " + err.Error()}) + return + } + req.Ledger = append(req.Ledger, entry) + posted := Posted{ThreadID: reply.ThreadID, ReplyID: id, Disposition: string(reply.Disposition)} + if reply.Disposition == DispositionWithdraw { + if err := req.Resolve(reply.ThreadID); err != nil { + res.Failed = append(res.Failed, Failed{ThreadID: reply.ThreadID, Reason: "could not resolve thread: " + err.Error()}) + } else { + thread.Resolved = true + posted.Resolved = true + } + } + res.Posted = append(res.Posted, posted) +} + +// secretGate scans every outbound body before the first write and names the +// draft site. There is no override on drain: a posted reply cannot be unsent. +func secretGate(replies []Reply) *core.RefusalError { + for i, reply := range replies { + if reply.Disposition == DispositionDefer { + continue + } + if shapes := postcore.BodySecretShapes(reply.Body); len(shapes) > 0 { + return &core.RefusalError{Code: postcore.CodeSecretShaped, Message: fmt.Sprintf( + "%s: replies[%d].body carries a secret-shaped value (%s); remove it before posting", + postcore.CodeSecretShaped, i, strings.Join(shapes, ", "))} + } + } + return nil +} diff --git a/internal/core/drain/post_test.go b/internal/core/drain/post_test.go new file mode 100644 index 000000000..a41a66073 --- /dev/null +++ b/internal/core/drain/post_test.go @@ -0,0 +1,224 @@ +package drain + +import ( + "encoding/json" + "errors" + "strings" + "testing" + + threadscore "github.com/stainless-code/verdict/internal/core/threads" +) + +type postCall struct { + root, thread, body string +} + +func postFixture(t *testing.T, bodies map[string]string) (*PostRequest, *[]postCall, *[]LedgerEntry) { + t.Helper() + ids := []string{"PRRT_1", "PRRT_2", "PRRT_3"} + waiting := map[string]string{"PRRT_1": "101", "PRRT_2": "201", "PRRT_3": "301"} + var pending []Pending + var replies []Reply + var threads []threadscore.Thread + for _, id := range ids { + pending = append(pending, Pending{ + ThreadID: id, RootCommentID: "root-" + id, WaitingCommentID: waiting[id], + WaitingAuthor: "alice", WaitingAt: "2026-11-02T00:00:00Z", Path: "a.go", + }) + disposition := DispositionAnswer + if id == "PRRT_2" { + disposition = DispositionWithdraw + } + body := "A considered answer." + if custom, ok := bodies[id]; ok { + body = custom + } + replies = append(replies, Reply{ThreadID: id, WaitingCommentID: waiting[id], + Disposition: disposition, Body: body}) + rootBody := "finding\n\n" + threadscore.ReplyMarker("root", "0") + threads = append(threads, threadscore.Thread{ + ID: id, Kind: threadscore.KindReview, Author: "verdict-bot", + AuthorKind: threadscore.AuthorVerdict, + Comments: []threadscore.Comment{ + {ID: "root-" + id, Author: "verdict-bot", AuthorKind: threadscore.AuthorVerdict, Body: rootBody}, + {ID: waiting[id], Author: "alice", AuthorKind: threadscore.AuthorHuman, Body: "a question"}, + }, + }) + } + plan := &File{Provider: "github", PR: 7, Pending: pending, PlanDigest: Digest(pending)} + raw, err := json.Marshal(RepliesFile{SchemaVersion: SchemaVersion, PlanDigest: plan.PlanDigest, Replies: replies}) + if err != nil { + t.Fatal(err) + } + feed := &threadscore.File{Provider: "github", PR: 7, Threads: threads} + var calls []postCall + var ledger []LedgerEntry + req := &PostRequest{ + Plan: plan, DraftsRaw: raw, Feed: feed, Provider: "github", Repo: "acme/app", PR: "7", + At: "2026-11-05T00:00:00Z", + Reply: func(root, thread, body string) (string, error) { + calls = append(calls, postCall{root, thread, body}) + return "reply-" + thread, nil + }, + Resolve: func(string) error { return nil }, + Append: func(entry LedgerEntry) error { ledger = append(ledger, entry); return nil }, + SaveFeed: func(*threadscore.File) error { return nil }, + } + return req, &calls, &ledger +} + +// TestPostMarksBodiesAndLedger pins the reply bytes and the order: each write +// gets a locked ledger entry, and withdraw resolves only after the reply lands. +func TestPostMarksBodiesAndLedger(t *testing.T) { + req, calls, ledger := postFixture(t, map[string]string{ + "PRRT_1": "Ping @alice, see the note.", + }) + var resolved []string + req.Resolve = func(id string) error { resolved = append(resolved, id); return nil } + res, ref := Post(req) + if ref != nil { + t.Fatalf("Post refused: %+v", ref) + } + if len(*calls) != 3 || len(*ledger) != 3 { + t.Fatalf("calls = %d, ledger = %d, want 3 each", len(*calls), len(*ledger)) + } + first := (*calls)[0] + if want := threadscore.ReplyMarker("PRRT_1", "101"); !strings.HasSuffix(first.body, want) { + t.Errorf("body %q did not end with %q", first.body, want) + } + if !strings.Contains(first.body, "@\u200balice") || strings.Contains(first.body, "@alice") { + t.Errorf("mention was not neutralized: %q", first.body) + } + if len(resolved) != 1 || resolved[0] != "PRRT_2" { + t.Errorf("resolved = %v, want PRRT_2", resolved) + } + if (*ledger)[1].InReplyTo != "201" || (*ledger)[1].By != ReplyBy || (*ledger)[1].ReplyID != "reply-PRRT_2" { + t.Errorf("withdraw ledger entry = %+v", (*ledger)[1]) + } + if len(res.Posted) != 3 || !res.Posted[1].Resolved || res.Incomplete { + t.Errorf("result = %+v", res) + } + if req.Feed.Threads[1].Resolved != true || req.Feed.Threads[0].Resolved { + t.Error("withdraw was not the only thread marked resolved in the feed") + } +} + +// TestPostPartialFailureRerunIsIdempotent fails write 2, then reruns with the +// recorded ledger. The thread whose reply landed is never written twice. +func TestPostPartialFailureRerunIsIdempotent(t *testing.T) { + req, calls, ledger := postFixture(t, nil) + failSecond := true + req.Reply = func(root, thread, body string) (string, error) { + if thread == "PRRT_2" && failSecond { + return "", errors.New("host rejected the reply") + } + *calls = append(*calls, postCall{root, thread, body}) + return "reply-" + thread, nil + } + first, ref := Post(req) + if ref != nil || !first.Incomplete || len(first.Failed) != 1 || first.Failed[0].ThreadID != "PRRT_2" { + t.Fatalf("first result = %+v, refusal = %+v", first, ref) + } + if len(*ledger) != 2 { + t.Fatalf("ledger after failure = %+v", *ledger) + } + req.Ledger = append([]LedgerEntry{}, (*ledger)...) + // The live refresh reads the posted marker back as verdict-authored. + for i := range req.Feed.Threads { + if req.Feed.Threads[i].ID == "PRRT_1" { + last := &req.Feed.Threads[i].Comments[1] + last.Body += "\n\n" + threadscore.ReplyMarker("PRRT_1", last.ID) + last.AuthorKind = threadscore.AuthorVerdict + } + } + *calls = nil + failSecond = false + second, ref := Post(req) + if ref != nil || second.Incomplete || len(second.Posted) != 1 { + t.Fatalf("second result = %+v, refusal = %+v", second, ref) + } + for _, call := range *calls { + if call.thread == "PRRT_1" { + t.Errorf("rerun double-posted %q", call.thread) + } + } + if !hasSkip(req.Plan.Skipped, "PRRT_1", ReasonAlreadyReplied) || + !hasSkip(req.Plan.Skipped, "PRRT_3", ReasonAlreadyReplied) { + t.Errorf("rerun skips = %+v", req.Plan.Skipped) + } +} + +func hasSkip(skips []Skip, thread, reason string) bool { + for _, skip := range skips { + if skip.ThreadID == thread && skip.Reason == reason { + return true + } + } + return false +} + +// TestPostStaleAndSecretRefusals pins the live checks before the first write: +// a new comment makes a draft stale, and a credential body refuses the whole +// run with no host call at all. +func TestPostStaleAndSecretRefusals(t *testing.T) { + req, calls, ledger := postFixture(t, nil) + req.Feed.Threads[0].Comments[1].ID = "999" + res, ref := Post(req) + if ref != nil || len(res.Posted) != 2 { + t.Fatalf("stale result = %+v, refusal = %+v", res, ref) + } + if len(res.Failed) != 0 { + t.Errorf("stale failures = %+v", res.Failed) + } + if !hasSkip(req.Plan.Skipped, "PRRT_1", ReasonStaleThread) { + t.Errorf("stale skip missing from %+v", req.Plan.Skipped) + } + for _, call := range *calls { + if call.thread == "PRRT_1" { + t.Error("stale thread was posted") + } + } + if len(*ledger) != 2 { + t.Errorf("stale run wrote %d ledger entries, want 2", len(*ledger)) + } + + secretReq, secretCalls, secretLedger := postFixture(t, map[string]string{ + "PRRT_1": "key AKIAIOSFODNN7EXAMPLE here", + }) + _, ref = Post(secretReq) + if ref == nil || ref.Code != "post-secret-shaped" { + t.Fatalf("secret refusal = %+v, want post-secret-shaped", ref) + } + if len(*secretCalls) != 0 || len(*secretLedger) != 0 { + t.Errorf("secret draft made %d call(s) and %d ledger entry/entries", len(*secretCalls), len(*secretLedger)) + } +} + +// TestPostNoDraftsRefuses pins the advice a post run gives when --agent has +// not written the artifact yet. +func TestPostNoDraftsRefuses(t *testing.T) { + req, calls, ledger := postFixture(t, nil) + req.DraftsRaw = nil + _, ref := Post(req) + if ref == nil || ref.Code != CodeDraftsInvalid || + !strings.Contains(ref.Message, "no drafts; run drain --agent first") { + t.Fatalf("refusal = %+v", ref) + } + if len(*calls) != 0 || len(*ledger) != 0 { + t.Error("no-drafts refusal made a write") + } +} + +// TestPostRefusesUnsupportedHost pins the order: the capability gate fires +// before the drafts are posted, and the reason names the missing capability. +func TestPostRefusesUnsupportedHost(t *testing.T) { + req, calls, ledger := postFixture(t, nil) + req.Provider = "forgejo" + _, ref := Post(req) + if ref == nil || ref.Code != "provider-unimplemented" { + t.Fatalf("refusal = %+v, want provider-unimplemented", ref) + } + if len(*calls) != 0 || len(*ledger) != 0 { + t.Error("unsupported host made a write") + } +} diff --git a/internal/core/post/secretvalues.go b/internal/core/post/secretvalues.go index 33a6793a5..22446e0c7 100644 --- a/internal/core/post/secretvalues.go +++ b/internal/core/post/secretvalues.go @@ -15,6 +15,15 @@ import ( // instead of offering a repair. const codeSecretShaped = "post-secret-shaped" +// CodeSecretShaped is the code drain reports for a reply body carrying a +// credential. Both verbs read the same scan and the same refusal code. +const CodeSecretShaped = codeSecretShaped + +// BodySecretShapes runs the post secret scan over one outbound reply body. +func BodySecretShapes(body string) []string { + return envsecret.SecretValueShapes(body) +} + // AllowSecretValuesFlag is the override the refusal, the dry-run warning, the // re-entry line, and the usage text name. It lives here because the refusal // spells it, and a second spelling in the adapter would let the two drift. diff --git a/internal/drain/post.go b/internal/drain/post.go new file mode 100644 index 000000000..7a9e92889 --- /dev/null +++ b/internal/drain/post.go @@ -0,0 +1,107 @@ +package drain + +import ( + "context" + "errors" + "fmt" + "io/fs" + + "github.com/stainless-code/verdict/internal/cli" + "github.com/stainless-code/verdict/internal/core" + draincore "github.com/stainless-code/verdict/internal/core/drain" + coreexec "github.com/stainless-code/verdict/internal/core/exec" + fetchcore "github.com/stainless-code/verdict/internal/core/fetch" + postcore "github.com/stainless-code/verdict/internal/core/post" + threadscore "github.com/stainless-code/verdict/internal/core/threads" + "github.com/stainless-code/verdict/internal/jq" + "github.com/stainless-code/verdict/internal/readcommon" +) + +// postMode runs §6's gates before a single host write: validate the drafts, +// check the capability, refresh the feed, then hand the write order to the +// pure post service. The plan and the feed it writes are the run's receipt. +func postMode(ctx context.Context, r *cli.Runner, req Request, fl *flags) int { + dir, ref := readcommon.ResolveBundleDir(req.RepoRootPath(), req.Pr) + if ref != nil { + return r.Refuse(drainFailed(ref.Message)) + } + plan, err := draincore.ReadPlan(dir + pathSep + draincore.KeyPlanJSON) + if err != nil { + return r.Refuse(drainFailed(err.Error())) + } + provider := plan.Provider + if fl.provider != "" && fl.provider != provider { + return r.Refuse(drainFailed(fmt.Sprintf("--provider %s disagrees with the plan's %s", fl.provider, provider))) + } + caps := core.CapabilitiesFor(provider) + if !caps.ThreadReply { + return r.Refuse(&core.RefusalError{Code: "provider-unimplemented", Message: fmt.Sprintf( + "thread replies on %s are not implemented (%s)", provider, caps.ThreadReplyReason())}) + } + var drafts []byte + drafts, err = jq.CappedFile(dir+pathSep+draincore.KeyDraftsJSON, jq.MaxPRBytes) + if err != nil && !errors.Is(err, fs.ErrNotExist) { + return r.Refuse(drainFailed(fmt.Sprintf("unreadable %s/%s: %v", dir, draincore.KeyDraftsJSON, err))) + } + resp, ref := fetchcore.RunThreads(ctx, refreshRequest(r, req, fl)) + if ref != nil { + return r.Refuse(drainFailed(ref.Message)) + } + in, code, done := readInputs(ctx, r, req, fl, resp) + if done { + return code + } + cmdr := commander(req) + at := req.TimeUTC() + draftsReq := &draincore.PostRequest{ + Plan: plan, DraftsRaw: drafts, Feed: in.feed, Ledger: in.ledger, + Provider: provider, Repo: req.Repo, PR: req.Pr, At: at, + Reply: func(rootID, threadID, body string) (string, error) { + id, rerr := postcore.ReplyThread(ctx, cmdr, provider, req.Env, req.Repo, req.Pr, rootID, threadID, body) + if rerr != nil { + return "", rerr + } + return id, nil + }, + Resolve: func(threadID string) error { + return postcore.ResolveThread(ctx, cmdr, provider, req.Env, req.Repo, req.Pr, threadID) + }, + Append: func(entry draincore.LedgerEntry) error { + return draincore.AppendLedger(dir+pathSep+draincore.KeyLedgerJSON, entry) + }, + SaveFeed: func(feed *threadscore.File) error { + return threadscore.WriteFile(dir+pathSep+threadscore.KeyThreadsJSON, feed) + }, + } + result, ref := draincore.Post(draftsReq) + if ref != nil { + return r.Refuse(ref) + } + if err := draincore.WritePlan(dir+pathSep+draincore.KeyPlanJSON, plan); err != nil { + return r.Refuse(drainFailed(err.Error())) + } + r.Warnings = append(r.Warnings, resp.Warnings...) + nextText := "refresh threads with verdict threads " + req.Repo + " " + req.Pr + if result.Incomplete { + nextText = "re-run verdict drain " + req.Repo + " " + req.Pr + " --post" + } + fmt.Fprintf(r.Human, "» %d posted, %d failed -> %s/%s\n", + len(result.Posted), len(result.Failed), dir, draincore.KeyPlanJSON) + if r.JSONMode { + env := core.RenderEnvelope(verbDrain, req.Repo, req.Pr, core.NowUTC(r.Now()), nextText, + r.Warnings, plan.Wire(), nil) + fmt.Fprint(r.Out, jq.PrettyOrdered(env)) + } + if result.Incomplete { + return r.Refuse(&core.RefusalError{Code: draincore.CodeDrainIncomplete, Message: fmt.Sprintf( + "%d thread(s) could not be posted; the ledger makes a re-run idempotent", len(result.Failed))}) + } + return cli.ExitOK +} + +func commander(req Request) core.Commander { + if req.Commander != nil { + return req.Commander + } + return coreexec.Runner{OutputCap: coreexec.FetchOutputCap, MissingTool: true} +} diff --git a/internal/drain/verb.go b/internal/drain/verb.go index e9a5e8e26..4dd5ef389 100644 --- a/internal/drain/verb.go +++ b/internal/drain/verb.go @@ -28,7 +28,7 @@ import ( const ( verbDrain = "drain" - wantFlags = "--provider , --max-threads <1-100>, --agent , --timeout , -- , --json" + wantFlags = "--provider , --max-threads <1-100>, --agent , --timeout , --post, -- , --json" defaultMax = "20" pathSep = "/" ) @@ -42,12 +42,13 @@ type flags struct { agent string timeout string pass []string + post bool } // Run executes `drain [--provider

] [--max-threads ] -// [--agent [--timeout ] [-- ]] [--json]`. It refreshes -// threads through the same service the threads verb uses, then writes one -// plan; there is no host write and no --post in this build. +// [--agent [--timeout ] [-- ]] [--post] [--json]`. Plan +// and draft modes never write to the host; --post validates the drafts first +// and then follows the ordered write path. func Run(ctx context.Context, r *cli.Runner, args []string, req Request) int { r.Repo, r.Pr = req.Repo, req.Pr fl, code, done := parseFlags(r, args) @@ -61,6 +62,9 @@ func Run(ctx context.Context, r *cli.Runner, args []string, req Request) int { if ref := preflight(req); ref != nil { return r.Refuse(ref) } + if fl.post { + return postMode(ctx, r, req, fl) + } resp, ref := fetchcore.RunThreads(ctx, refreshRequest(r, req, fl)) if ref != nil { return r.Refuse(drainFailed(ref.Message)) @@ -208,6 +212,9 @@ func parseFlags(r *cli.Runner, args []string) (*flags, int, bool) { func consumeFlag(r *cli.Runner, fl *flags, args []string, i int) (int, int, bool) { a := args[i] switch { + case a == "--post": + fl.post = true + return i, 0, false case a == "--provider" || a == "--max-threads" || a == "--agent" || a == "--timeout": v, nextIndex, u := cli.FlagValue(args, i, a, "") if u != nil { diff --git a/internal/drain/verb_test.go b/internal/drain/verb_test.go index d1eb58094..3aea400f2 100644 --- a/internal/drain/verb_test.go +++ b/internal/drain/verb_test.go @@ -25,6 +25,17 @@ func TestNextAfterAgentDoesNotRecommendPost(t *testing.T) { } } +func TestParseFlagsAcceptsPost(t *testing.T) { + t.Parallel() + fl, code, done := parseFlags(&cli.Runner{}, []string{"--agent", "claude", "--post"}) + if done || code != 0 || !fl.post || fl.agent != "claude" { + t.Fatalf("parse = %+v, %d, %v", fl, code, done) + } + if !strings.Contains(wantFlags, "--post") { + t.Errorf("usage %q does not offer --post", wantFlags) + } +} + func TestRefreshRequestKeepsInjectedCommander(t *testing.T) { t.Parallel() cmdr := &stubCommander{} From 6923d0e8602acf9f0842cd59dd1ef30e48becf31 Mon Sep 17 00:00:00 2001 From: Sutu Sebastian Date: Tue, 17 Nov 2026 14:21:41 +0200 Subject: [PATCH 03/14] docs(drain): document reply posting and its refusal legs --- .changeset/drain-post.md | 5 + apps/docs/content/04-roadmap/index.mdx | 2 +- clients/ts/src/refusal-codes.gen.ts | 1 + cmd/verdict/usage.go | 11 +- docs/manual.md | 34 +++-- docs/troubleshooting.md | 6 + evals/README.md | 4 +- evals/cases/drain-post.sh | 156 +++++++++++++++++++ evals/cases/drain-refusals.sh | 26 +++- evals/cases/drain-stale.sh | 118 +++++++++++++++ internal/core/drain/ledger.go | 4 +- internal/core/drain/ledger_test.go | 4 +- internal/core/drain/post.go | 131 ++++++++++------ internal/core/drain/post_test.go | 167 +++++++++++++-------- internal/core/hint.go | 1 + internal/core/hint_test.go | 7 + internal/core/post/host_reply_test.go | 93 +++++++----- internal/core/refusalcodes.go | 1 + internal/core/testdata/hints.golden | 1 + internal/core/threads/reply_marker_test.go | 28 ++-- internal/core/threads/threads.go | 2 +- internal/drain/post.go | 139 ++++++++++++----- scripts/verdict-complete.sh | 2 +- skills/verdict/prompts/address-reviews.md | 4 +- skills/verdict/references/commands.md | 14 ++ 25 files changed, 736 insertions(+), 225 deletions(-) create mode 100644 .changeset/drain-post.md create mode 100644 evals/cases/drain-post.sh create mode 100644 evals/cases/drain-stale.sh diff --git a/.changeset/drain-post.md b/.changeset/drain-post.md new file mode 100644 index 000000000..4f570af62 --- /dev/null +++ b/.changeset/drain-post.md @@ -0,0 +1,5 @@ +--- +"@stainless-code/verdict": minor +--- + +`drain --post` answers the waiting review threads from a validated `drain.replies.json`. GitHub and GitLab post one marked reply per draft and append `replies.json` under a lock after each write; `withdraw` also resolves its thread. Secret-shaped bodies refuse before any write, stale threads are skipped, and a failed write records `failed[]` and refuses `drain-incomplete` so the same command can finish the remaining replies. diff --git a/apps/docs/content/04-roadmap/index.mdx b/apps/docs/content/04-roadmap/index.mdx index 23e4eb628..da2f3b4e6 100644 --- a/apps/docs/content/04-roadmap/index.mdx +++ b/apps/docs/content/04-roadmap/index.mdx @@ -22,7 +22,7 @@ Planned means it is not built yet, and says so on its own line. | ------------- | ------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | Bundle | `fetch`, `fetch-local`, `index` | One diff per review target, from a host PR or your working tree, into `.verdict/state/`, plus the local code index (`index build`) the impact answers read. Chunking and a budget gate are opt-in. | | Review | `run`, `record`, `panel`, `ingest`, `adopt`, `fix`, `handoff` | Launch your own agent on the bundle (`run`), validate its review and merge it into findings, plan independent disprove attempts (`panel`), ingest SARIF lint findings, carry local findings onto a PR, loop on one finding without escaping scope, and hand the fix brief to someone else. | -| Decide | `report`, `triage`, `threads`, `drain`, `risk`, `next`, `show`, `trend`, `gate` | Render the bundle, gate on severity (`--check`), compose the gate dimensions (`gate`), list review threads waiting on verdict and draft replies with your agent (`drain`, plan and draft only — posting lands later), queue the portfolio risk score (`risk`), and read trend across runs. | +| Decide | `report`, `triage`, `threads`, `drain`, `risk`, `next`, `show`, `trend`, `gate` | Render the bundle, gate on severity (`--check`), compose the gate dimensions (`gate`), list review threads waiting on verdict, draft replies with your agent, and post them with `drain --post` (`drain`), queue the portfolio risk score (`risk`), and read trend across runs. | | Post | `post`, `pr-wait` | Exactly one review, with anchor validation, stale-SHA and duplicate guards, `--dry-run`, and `--bind` for an approval; `pr-wait` waits on a PR's checks, review, or merge state without writing anything. | | Trust | `verify`, `check-tree`, `doctor`, `calibrate`, `backtest`, `ready` | Check the bundle, the tree, the host login, past calibration, and readiness in one place, and mine, replay, and score bug-introducing candidates from your own history (`backtest`). | | Agent surface | `skill`, `mcp` | The embedded skill (`skill`, `skill files`, `skill install`) and the review verbs as MCP tools over stdio. | diff --git a/clients/ts/src/refusal-codes.gen.ts b/clients/ts/src/refusal-codes.gen.ts index b76217602..e195cdbec 100644 --- a/clients/ts/src/refusal-codes.gen.ts +++ b/clients/ts/src/refusal-codes.gen.ts @@ -100,6 +100,7 @@ export type RefusalCode = | "drafts-invalid" | "drafts-stale" | "drain-failed" + | "drain-incomplete" | "duplicate-payload" | "fetch-failed" | "filtered-out" diff --git a/cmd/verdict/usage.go b/cmd/verdict/usage.go index 1cc52c4bd..17dc4bcbe 100644 --- a/cmd/verdict/usage.go +++ b/cmd/verdict/usage.go @@ -277,14 +277,17 @@ func usageText() string { " makes one host write per thread and writes threads-resolve.json. GitHub and\n" + " GitLab carry it; Forgejo refuses typed (no documented resolve endpoint).\n" + " drain [--provider

] [--max-threads <1-100>] [--json]\n" + - " [--agent [--timeout ] [-- ...]]\n" + + " [--agent [--timeout ] [-- ...]] [--post]\n" + " answer every review thread waiting on verdict: refresh threads, then write\n" + " .verdict/state//drain.json with the pending list, typed skips, and a plan digest.\n" + " Zero pending is success and launches no agent. --max-threads defaults to 20;\n" + " older questions are taken first and the rest are deferred. --agent drafts one\n" + - " drain.replies.json through the run launcher; no host write happens in this\n" + - " build (there is no --post yet). A truncated feed or unreadable login refuses\n" + - " drain-failed before the plan is written.\n" + + " drain.replies.json through the run launcher. --post validates those drafts,\n" + + " re-reads threads, posts one marked reply per draft, and appends replies.json\n" + + " after each write; withdraw also resolves its thread. GitHub and GitLab carry\n" + + " replies; other hosts refuse provider-unimplemented. A failed write records\n" + + " failed[] and refuses drain-incomplete so a re-run finishes the rest. A\n" + + " truncated feed or unreadable login refuses drain-failed before any write.\n" + " trend [--rules] [--overlap] [--incidents] [--resolution] [--json]\n" + " portfolio rollup over existing bundle stores (no network, writes nothing):\n" + " findings opened/addressed/closed over time, broken down by severity tier\n" + diff --git a/docs/manual.md b/docs/manual.md index 32a9c95f8..197151a57 100644 --- a/docs/manual.md +++ b/docs/manual.md @@ -316,16 +316,30 @@ write per thread, marks them resolved in `threads.json`, and writes refuses typed because its API has no documented resolve endpoint. `verdict drain owner/repo N [--provider p] [--max-threads 1-100] [--agent name] -[--timeout s] [-- args...] [--json]` plans one pass over the threads waiting on -verdict. It refreshes the feed, reads the login once, joins findings, and writes -`drain.json`: `pending[]`, typed `skipped[]` reasons, `other_threads`, and a -`plan_digest` over the pending list. A thread is pending when it is a review -comment verdict authored, unresolved, and its last comment is a human question -with no ledger entry answering it; the oldest questions come first and the rest -are `deferred`. `--max-threads` defaults to 20. Zero pending is success and -launches no agent. `--agent` drafts one `drain.replies.json` through the `run` -launcher; `drafts-invalid` and `drafts-stale` name a bad site or a moved plan. -This build makes no host writes and has no `--post`. +[--timeout s] [-- args...] [--post] [--json]` plans one pass over the threads +waiting on verdict. It refreshes the feed, reads the login once, joins findings, +and writes `drain.json`: `pending[]`, typed `skipped[]` reasons, `other_threads`, +and a `plan_digest` over the pending list. A thread is pending when it is a +review comment verdict authored, unresolved, and its last comment is a human +question with no ledger entry answering it; the oldest questions come first and +the rest are `deferred`. `--max-threads` defaults to 20. Zero pending is success +and launches no agent. `--agent` drafts one `drain.replies.json` through the +`run` launcher; `drafts-invalid` and `drafts-stale` name a bad site or a moved +plan. + +`--post` validates the drafts first, checks the `thread_reply` capability, then +refreshes threads and the login. A thread now resolved, answered in the +`replies.json` ledger, or whose waiting comment changed is skipped; a +secret-shaped body refuses `post-secret-shaped` before any write. Each posted +reply carries a hidden `` marker, so the next +threads refresh reads it as verdict-authored. Bodies have mentions neutralized. +GitHub replies to the root comment and GitLab adds a discussion note; `withdraw` +also resolves through the host's existing resolve call. One ledger entry is +appended under `storelock` after each successful write, so a re-run skips replies +already posted. A failed write is recorded in `failed[]`, the remaining drafts +are attempted, and the run refuses `drain-incomplete`. Forgejo and fetch-only +hosts refuse `provider-unimplemented` before any read. There is no `--dry-run` +for post and no `--allow-secret-values` override. `post.json` and `record.json` carry `schema_version: "1"`. diff --git a/docs/troubleshooting.md b/docs/troubleshooting.md index 3901a28cd..22b6c13ea 100644 --- a/docs/troubleshooting.md +++ b/docs/troubleshooting.md @@ -603,6 +603,12 @@ Cause: the bundle, `threads.json`, the login, or the reply ledger could not be r Fix: refresh threads and confirm host auth, then re-run `drain`. +## `drain-incomplete` + +Cause: at least one `drain --post` host write failed; `drain.json` names the threads in `failed[]`. Replies that landed are already in `replies.json`. + +Fix: re-run the same `drain --post` command. The ledger skips replies already posted and only the failed threads are retried; check the host's own error in `failed[]` first. + ## `duplicate-payload` Cause: every rendered summary part and comment is present in the live remote lists for this reviewed head. diff --git a/evals/README.md b/evals/README.md index fc450d08f..f2d36a5a1 100644 --- a/evals/README.md +++ b/evals/README.md @@ -103,8 +103,10 @@ the build. | `coverage` | Diff-coverage attestation reads and the opt-in gate | `next --coverage` reads the seeded snapshot (0% over both sides, the full `src/db.ts` gap) with no `findings.json`; `10-15,40-45` reads 54% with gaps `16-20,46-50` and the generated `dist/` file exempt; `post --dry-run --require-coverage` refuses `coverage-incomplete` write-free and `--force` never bypasses it (local `record` alike); `"all"` passes at 100% with no body line and a stored receipt; partial without the flag posts one `> ⚠️ coverage:` line and stores `coverage`; a chunked bundle warns and proceeds while `next` names the chunks; the stub `gh` alone on `PATH` | | `report-html` | Static dashboard file set, envelope key, refresh, and root discovery. | | `doc-coverage` | This table documents every case, and only real cases | Each `evals/cases/*.sh` has exactly one row here, every row names an existing case, and no case is documented twice — so the table cannot drift again | -| `drain-refusals` | PR A refusal legs for `drain` | Bad draft key names its site as `drafts-invalid`; a stale plan digest refuses `drafts-stale`; a truncated feed refuses `drain-failed`; `--post` stays an unknown flag with no host call; missing and stale artifacts refuse with the named codes | +| `drain-post` | Post mode over stub `gh`: replies, resolve, idempotent rerun | Two drafts post one marked reply each and one `withdraw` resolve; `replies.json` holds two `drain` entries with waiting comment ids; the marker reads back as `author_kind: verdict` on the next threads refresh; a second `--post` makes zero host writes and adds no ledger entry; every stub call is registered | +| `drain-refusals` | Refusal legs for `drain` | Bad draft key names its site as `drafts-invalid`; a stale plan digest refuses `drafts-stale`; a truncated feed refuses `drain-failed`; a secret-shaped reply refuses `post-secret-shaped` with zero writes; Forgejo `--post` refuses `provider-unimplemented` before any read; missing and stale artifacts refuse with the named codes | | `drain-plan` | Plan mode over a stub `gh` feed | One human reply and one self-login question pending; bot, resolved, verdict-answered, legacy-ledger answered, and other-author threads skipped with typed reasons; digest and schema pinned; zero host writes; stub-agent draft validation and zero-pending no-launch legs | +| `drain-stale` | A new comment between draft and post | Two drafts are validated; a human comment lands on one thread before `--post`; that thread is skipped with `stale-thread` while the other posts once, writes one ledger entry, and no unregistered host call appears across all runs | | `doctor-scope-audit` | Token-scope excess audit in `doctor` | Header-driven gh stub: an excess grant warns `token-scopes-excess` naming the scopes with a `try:` hint and rides the `--json` checks; minimal grants add no row; a header-less stub keeps the fine-grained advisory; a non-baseline grant adds the row while warn-only never fails the run; text mode opens with the `doctor @ ` stamp, closes with a summary that agrees with the exit code, is healthy on a gh/git/ps-only PATH, and writes nothing | | `doctor-provider` | `doctor --provider` checks one host's CLI | Bare `doctor` keeps today's seven GitHub rows byte for byte and shells no `glab`; `--provider gitlab` on a PATH carrying the `glab` stub and no `gh` exits 0 with the `glab-cli`/`glab-auth`/`api-reachable` rows and no `gh` row, its call log equal to the fixture argv sequence; `--provider gitea` refuses typed `bad-provider` naming the enum; the same gitlab leg without `glab` fails the `glab-cli` row and exits 1 | | `envelope-shape` | `--json` envelope (`schema_version`, `verb`, `repo`, `pr`, `at`, `next`, `warnings`, `data`, `error`) | `report` and `post --dry-run` success envelopes carry exactly the documented keys with `schema_version "1"` and null error; a refusal keeps the shape with null data and a string `error.code` | diff --git a/evals/cases/drain-post.sh b/evals/cases/drain-post.sh new file mode 100644 index 000000000..a4e782cd9 --- /dev/null +++ b/evals/cases/drain-post.sh @@ -0,0 +1,156 @@ +#!/usr/bin/env bash +# drain --post answers two threads, resolves a withdraw, and is idempotent. +set -euo pipefail +HERE="$(cd "$(dirname "$0")" && pwd)" +# shellcheck source=../lib/common.sh +. "$HERE/../lib/common.sh" + +SIG="6c3ee749e3d1f97870c9e8b5c1171fae2cb9ff4e" +HEAD="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +DRAIN_QUERY="$(awk '/QueryThreadsFull = `/{flag=1; sub(/^[^`]*`/, ""); print; next} flag && /`/{sub(/`.*/, ""); print; exit} flag{print}' "$EVAL_ROOT/internal/readcommon/gh.go")" +DIR="$EVAL_SANDBOX/.verdict/state/7" +mkdir -p "$DIR" +jq -n --arg head "$HEAD" '{state:"OPEN",headRefOid:$head,baseRefOid:"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",author:{login:"teammate"}}' >"$DIR/PR.json" +printf 'diff sentinel\n' >"$DIR/full.diff" +RB="finding"$'\n\n'"" +node() { + jq -n --arg id "$1" --arg path "$2" --argjson comments "$3" \ + '{id:$id,isResolved:false,isOutdated:false,path:$path,line:10,startLine:null,diffSide:"RIGHT",comments:{totalCount:($comments|length),nodes:$comments}}' +} +comment() { + jq -n --arg id "$1" --arg who "$2" --arg kind "$3" --arg at "$4" --arg body "$5" \ + '{id:$id,databaseId:($id|tonumber),author:{__typename:$kind,login:$who},body:$body,createdAt:$at,url:"https://example.invalid/c"}' +} +ROOT1="$(comment 101 verdict-bot Bot 2026-11-01T00:00:00Z "$RB")" +ROOT2="$(comment 201 verdict-bot Bot 2026-11-01T00:00:00Z "$RB")" +HUMAN1="$(comment 102 alice User 2026-11-02T00:00:00Z 'why?')" +HUMAN2="$(comment 202 bob User 2026-11-02T00:00:00Z 'is this wrong?')" +jq -n --argjson a "$(node PRRT_1 a.go "[$ROOT1,$HUMAN1]")" \ + --argjson b "$(node PRRT_2 b.go "[$ROOT2,$HUMAN2]")" \ + '{data:{repository:{pullRequest:{reviewThreads:{pageInfo:{hasNextPage:false,endCursor:null},nodes:[$a,$b]}}}}}' >"$EVAL_SANDBOX/page.json" + +MARK1="" +MARK2="" +TWO_NL=$'\n\n' +export DRAIN_PAGE="$EVAL_SANDBOX/page.json" DRAIN_QUERY MARK1 MARK2 TWO_NL +: >"$EVAL_STUBLOG" + +cat >"$EVAL_STUBBIN/gh" <<'GH' +#!/usr/bin/env bash +set -uo pipefail +echo "stub-gh $*" >>"$EVAL_STUBLOG" +unhandled() { + echo "unhandled gh call ($*)" >>"$EVAL_STUBLOG" + echo "unregistered gh call: $*" >&2 + exit 1 +} +if [ "$#" -eq 4 ] && [ "$1" = api ] && [ "$2" = user ] && [ "$3" = --jq ] && [ "$4" = .login ]; then + printf 'verdict-bot\n' + exit 0 +fi +expected=(api graphql -F owner=acme -F name=app -F pr=7 -f "query=$DRAIN_QUERY") +if [ "$1" = api ] && [ "$2" = graphql ] && [ "$#" -eq "${#expected[@]}" ]; then + match=1 + for i in "${!expected[@]}"; do + idx=$((i + 1)) + if [ "${!idx}" != "${expected[i]}" ]; then match=0; break; fi + done + if [ "$match" -eq 1 ]; then cat "$DRAIN_PAGE"; exit 0; fi +fi +if [ "$1" = api ] && [ "$2" = graphql ] && [[ " $* " == *" threadId=PRRT_2"* ]]; then + printf '{"data":{"resolveReviewThread":{"thread":{"id":"PRRT_2","isResolved":true}}}}\n' + exit 0 +fi +reply() { + local endpoint="$1" marker="$2" id="$3" body="$4" + shift 4 + expected=(api --method POST "repos/acme/app/pulls/7/comments/$endpoint/replies" -f "body=$body") + [ "$#" -eq "${#expected[@]}" ] || return 1 + for i in "${!expected[@]}"; do + idx=$((i + 1)) + [ "${!idx}" = "${expected[i]}" ] || return 1 + done + jq --arg marker "$marker" \ + --arg prefix "$endpoint" \ + '.data.repository.pullRequest.reviewThreads.nodes |= map(if (.comments.nodes | any(.id | startswith($prefix))) then .comments.nodes[-1].body += "\n\n" + $marker else . end)' \ + "$DRAIN_PAGE" >"$DRAIN_PAGE.next" + mv "$DRAIN_PAGE.next" "$DRAIN_PAGE" + printf '{"id":%s}\n' "$id" + exit 0 +} +if [ "$1" = api ] && [ "$2" = --method ] && [ "$3" = POST ]; then + reply 101 "$MARK1" 501 "Answer one.${TWO_NL}${MARK1}" "$@" && exit 0 + reply 201 "$MARK2" 502 "Answer two.${TWO_NL}${MARK2}" "$@" && exit 0 +fi +unhandled "$@" +GH +chmod +x "$EVAL_STUBBIN/gh" + +cat >"$EVAL_STUBBIN/claude" <<'AGENT' +#!/usr/bin/env bash +echo "stub-agent $*" >>"$EVAL_STUBLOG" +digest="$(jq -r .plan_digest .verdict/state/7/drain.json)" +jq -n --arg digest "$digest" '{schema_version:"1",plan_digest:$digest,replies:[ + {thread_id:"PRRT_1",waiting_comment_id:"102",disposition:"answer",body:"Answer one."}, + {thread_id:"PRRT_2",waiting_comment_id:"202",disposition:"withdraw",body:"Answer two."}]}' \ + >.verdict/state/7/drain.replies.json +AGENT +chmod +x "$EVAL_STUBBIN/claude" + +run_review drain acme/app 7 --agent claude --json +if [ "$EVAL_STATUS" -ne 0 ] || ! jq -e '.data.drafts.count == 2' <"$EVAL_OUT" >/dev/null; then + bad "draft: exit $EVAL_STATUS $(head -c 400 "$EVAL_ERR") $(head -c 400 "$EVAL_OUT")" + eval_end +fi +good "two drafts were validated before the post run" + +run_review drain acme/app 7 --post --json +if [ "$EVAL_STATUS" -eq 0 ] && jq -e '(.data.posted | length == 2) + and (.data.failed | length == 0) and (.next | contains("threads"))' <"$EVAL_OUT" >/dev/null; then + good "P1 post writes both marked replies" +else + bad "P1 post: exit $EVAL_STATUS $(head -c 500 "$EVAL_OUT") $(head -c 300 "$EVAL_ERR")" +fi +if jq -e 'length == 2 and (map(.by) | all(. == "drain")) + and (map(.in_reply_to) | sort) == ["102","202"] + and (map(.reply_id) | sort) == ["501","502"]' "$DIR/replies.json" >/dev/null; then + good "P2 two drain ledger entries carry the waiting comment ids" +else + bad "P2 ledger: $(jq -c . "$DIR/replies.json" 2>/dev/null)" +fi +if jq -e '(.posted | length == 2) and ((.posted | map(select(.disposition == "withdraw" and .resolved)) | length) == 1) + and .failed == [] and .posted_at != null' "$DIR/drain.json" >/dev/null; then + good "P3 the final receipt records two posts and one resolve" +else + bad "P3 receipt: $(jq -c '{posted,failed,posted_at}' "$DIR/drain.json")" +fi +run_review threads acme/app 7 --json +if jq -e --arg marker "$MARK1" '.threads[] | select(.id == "PRRT_1") | (.comments[-1].author_kind == "verdict" + and (.comments[-1].body | contains($marker)))' "$DIR/threads.json" >/dev/null; then + good "P4 the posted marker round-trips as author_kind verdict" +else + bad "P4 marker round-trip: $(jq -c '.threads[] | select(.id == "PRRT_1") | .comments[-1]' "$DIR/threads.json")" +fi +if [ "$(grep -c 'body=Answer' "$EVAL_STUBLOG")" = "2" ] && \ + [ "$(grep -c 'threadId=PRRT_2' "$EVAL_STUBLOG")" = "1" ]; then + good "P5 two replies and exactly one resolve reached the host" +else + bad "P5 writes: $(grep -E 'body=|threadId=' "$EVAL_STUBLOG")" +fi + +WRITES_BEFORE="$(grep -Ec 'POST|threadId=' "$EVAL_STUBLOG" || true)" +LEDGER_BEFORE="$(wc -c <"$DIR/replies.json")" +run_review drain acme/app 7 --post --json +if [ "$EVAL_STATUS" -eq 0 ] && [ "$(grep -Ec 'POST|threadId=' "$EVAL_STUBLOG" || true)" = "$WRITES_BEFORE" ] \ + && [ "$(wc -c <"$DIR/replies.json")" = "$LEDGER_BEFORE" ] \ + && jq -e '.data | (.posted | length == 0)' <"$EVAL_OUT" >/dev/null; then + good "P6 a rerun makes zero writes and adds no ledger entry" +else + bad "P6 rerun: exit $EVAL_STATUS $(head -c 400 "$EVAL_OUT")" +fi +if matches 'unhandled gh call' "$EVAL_STUBLOG"; then + bad "a later run made an unregistered gh call: $(cat "$EVAL_STUBLOG")" +else + good "every gh call was registered" +fi +eval_end diff --git a/evals/cases/drain-refusals.sh b/evals/cases/drain-refusals.sh index f4bff378b..dc904efb6 100755 --- a/evals/cases/drain-refusals.sh +++ b/evals/cases/drain-refusals.sh @@ -66,6 +66,9 @@ case "${DRAIN_AGENT_MODE:-}" in bad-key) digest="$(jq -r .plan_digest "$DIR/drain.json")"; jq -n --arg digest "$digest" '{schema_version:"1",plan_digest:$digest,replies:[{thread_id:"PRRT_1",waiting_comment_id:"102",disposition:"answer",body:"answer",extra:true}]}' >"$DIR/drain.replies.json";; stale) jq -n '{schema_version:"1",plan_digest:"old",replies:[]}' >"$DIR/drain.replies.json";; + secret) digest="$(jq -r .plan_digest "$DIR/drain.json")"; + jq -n --arg digest "$digest" '{schema_version:"1",plan_digest:$digest,replies:[ + {thread_id:"PRRT_1",waiting_comment_id:"102",disposition:"answer",body:"key AKIAIOSFODNN7EXAMPLE"}]}' >"$DIR/drain.replies.json";; esac exit 0 AGENT @@ -106,13 +109,28 @@ else bad "R3 truncated feed rewrote drain.json" fi -STUBLOG_BEFORE="$(wc -c <"$EVAL_STUBLOG")" +export DRAIN_PAGE="$EVAL_SANDBOX/page.json" DRAIN_CURSOR= +rm -f "$DIR/drain.replies.json" +DRAIN_AGENT_MODE=secret run_review drain acme/app 7 --agent claude --json +WRITES_BEFORE="$(grep -Ec 'POST|mutation' "$EVAL_STUBLOG" || true)" run_review drain acme/app 7 --post --json -if [ "$EVAL_STATUS" -eq 2 ] && grep -q "unknown flag '--post'" "$EVAL_ERR" \ +WRITES_AFTER="$(grep -Ec 'POST|mutation' "$EVAL_STUBLOG" || true)" +if [ "$EVAL_STATUS" -eq 1 ] && jq -e '.error.code == "post-secret-shaped"' <"$EVAL_OUT" >/dev/null \ + && [ "$WRITES_BEFORE" = "$WRITES_AFTER" ]; then + good "R4 a secret-shaped reply refuses post-secret-shaped with zero writes" +else + bad "R4 secret body: exit $EVAL_STATUS $(head -c 400 "$EVAL_OUT") log: $(cat "$EVAL_STUBLOG")" +fi + +jq '.provider = "forgejo"' "$DIR/drain.json" >"$EVAL_SANDBOX/forgejo-plan.json" +cp "$EVAL_SANDBOX/forgejo-plan.json" "$DIR/drain.json" +STUBLOG_BEFORE="$(wc -c <"$EVAL_STUBLOG")" +run_review drain acme/app 7 --provider forgejo --post --json +if [ "$EVAL_STATUS" -eq 1 ] && jq -e '.error.code == "provider-unimplemented"' <"$EVAL_OUT" >/dev/null \ && [ "$(wc -c <"$EVAL_STUBLOG")" = "$STUBLOG_BEFORE" ]; then - good "R4 --post is an unknown flag and touches no host before refusal" + good "R5 Forgejo --post refuses provider-unimplemented before any read" else - bad "R4 --post: exit $EVAL_STATUS $(head -c 300 "$EVAL_ERR") log: $(cat "$EVAL_STUBLOG")" + bad "R5 Forgejo post: exit $EVAL_STATUS $(head -c 400 "$EVAL_OUT") log: $(cat "$EVAL_STUBLOG")" fi awk '/^stub-gh /' "$EVAL_STUBLOG" >"$EVAL_SANDBOX/gh-log" if matches 'unhandled gh call' "$EVAL_STUBLOG" || matches -Eqi 'mutation|POST|PATCH|DELETE' "$EVAL_SANDBOX/gh-log"; then diff --git a/evals/cases/drain-stale.sh b/evals/cases/drain-stale.sh new file mode 100644 index 000000000..ac4fac0ad --- /dev/null +++ b/evals/cases/drain-stale.sh @@ -0,0 +1,118 @@ +#!/usr/bin/env bash +# A comment landing between draft and post skips only that thread. +set -euo pipefail +HERE="$(cd "$(dirname "$0")" && pwd)" +# shellcheck source=../lib/common.sh +. "$HERE/../lib/common.sh" + +SIG="6c3ee749e3d1f97870c9e8b5c1171fae2cb9ff4e" +HEAD="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +DRAIN_QUERY="$(awk '/QueryThreadsFull = `/{flag=1; sub(/^[^`]*`/, ""); print; next} flag && /`/{sub(/`.*/, ""); print; exit} flag{print}' "$EVAL_ROOT/internal/readcommon/gh.go")" +DIR="$EVAL_SANDBOX/.verdict/state/7" +mkdir -p "$DIR" +jq -n --arg head "$HEAD" '{state:"OPEN",headRefOid:$head,baseRefOid:"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",author:{login:"teammate"}}' >"$DIR/PR.json" +printf 'diff sentinel\n' >"$DIR/full.diff" +RB="finding"$'\n\n'"" +node() { + jq -n --arg id "$1" --arg path "$2" --argjson comments "$3" \ + '{id:$id,isResolved:false,isOutdated:false,path:$path,line:10,startLine:null,diffSide:"RIGHT",comments:{totalCount:($comments|length),nodes:$comments}}' +} +comment() { + jq -n --arg id "$1" --arg who "$2" --arg kind "$3" --arg at "$4" --arg body "$5" \ + '{id:$id,databaseId:($id|tonumber),author:{__typename:$kind,login:$who},body:$body,createdAt:$at,url:"https://example.invalid/c"}' +} +ROOT1="$(comment 101 verdict-bot Bot 2026-11-01T00:00:00Z "$RB")" +ROOT2="$(comment 201 verdict-bot Bot 2026-11-01T00:00:00Z "$RB")" +HUMAN1="$(comment 102 alice User 2026-11-02T00:00:00Z 'why?')" +HUMAN2="$(comment 202 bob User 2026-11-02T00:00:00Z 'also?')" +NEW="$(comment 999 alice User 2026-11-06T00:00:00Z 'a new question')" +jq -n --argjson a "$(node PRRT_1 a.go "[$ROOT1,$HUMAN1]")" \ + --argjson b "$(node PRRT_2 b.go "[$ROOT2,$HUMAN2]")" \ + '{data:{repository:{pullRequest:{reviewThreads:{pageInfo:{hasNextPage:false,endCursor:null},nodes:[$a,$b]}}}}}' >"$EVAL_SANDBOX/page.json" +jq --argjson new "$NEW" '.data.repository.pullRequest.reviewThreads.nodes |= map(if .id == "PRRT_1" then .comments.nodes += [$new] else . end)' \ + "$EVAL_SANDBOX/page.json" >"$EVAL_SANDBOX/stale.json" + +MARK2="" +TWO_NL=$'\n\n' +export DRAIN_PAGE="$EVAL_SANDBOX/page.json" DRAIN_QUERY MARK2 TWO_NL +: >"$EVAL_STUBLOG" + +cat >"$EVAL_STUBBIN/gh" <<'GH' +#!/usr/bin/env bash +set -uo pipefail +echo "stub-gh $*" >>"$EVAL_STUBLOG" +unhandled() { + echo "unhandled gh call ($*)" >>"$EVAL_STUBLOG" + echo "unregistered gh call: $*" >&2 + exit 1 +} +if [ "$#" -eq 4 ] && [ "$1" = api ] && [ "$2" = user ] && [ "$3" = --jq ] && [ "$4" = .login ]; then + printf 'verdict-bot\n' + exit 0 +fi +expected=(api graphql -F owner=acme -F name=app -F pr=7 -f "query=$DRAIN_QUERY") +if [ "$1" = api ] && [ "$2" = graphql ] && [ "$#" -eq "${#expected[@]}" ]; then + match=1 + for i in "${!expected[@]}"; do + idx=$((i + 1)) + if [ "${!idx}" != "${expected[i]}" ]; then match=0; break; fi + done + if [ "$match" -eq 1 ]; then cat "$DRAIN_PAGE"; exit 0; fi +fi +if [ "$1" = api ] && [ "$2" = --method ] && [ "$3" = POST ]; then + expected=(api --method POST repos/acme/app/pulls/7/comments/201/replies -f "body=Answer two.${TWO_NL}${MARK2}") + if [ "$#" -eq "${#expected[@]}" ]; then + match=1 + for i in "${!expected[@]}"; do + idx=$((i + 1)) + if [ "${!idx}" != "${expected[i]}" ]; then match=0; break; fi + done + if [ "$match" -eq 1 ]; then printf '{"id":502}\n'; exit 0; fi + fi +fi +unhandled "$@" +GH +chmod +x "$EVAL_STUBBIN/gh" + +cat >"$EVAL_STUBBIN/claude" <<'AGENT' +#!/usr/bin/env bash +echo "stub-agent $*" >>"$EVAL_STUBLOG" +digest="$(jq -r .plan_digest .verdict/state/7/drain.json)" +jq -n --arg digest "$digest" '{schema_version:"1",plan_digest:$digest,replies:[ + {thread_id:"PRRT_1",waiting_comment_id:"102",disposition:"answer",body:"Answer one."}, + {thread_id:"PRRT_2",waiting_comment_id:"202",disposition:"answer",body:"Answer two."}]}' \ + >.verdict/state/7/drain.replies.json +AGENT +chmod +x "$EVAL_STUBBIN/claude" + +run_review drain acme/app 7 --agent claude --json +if [ "$EVAL_STATUS" -ne 0 ]; then + bad "draft: exit $EVAL_STATUS $(head -c 400 "$EVAL_ERR")" + eval_end +fi +export DRAIN_PAGE="$EVAL_SANDBOX/stale.json" +run_review drain acme/app 7 --post --json +if [ "$EVAL_STATUS" -eq 0 ] && jq -e '(.data.posted | length == 1) + and (.data.skipped | map(select(.reason == "stale-thread")) | map(.thread_id) == ["PRRT_1"])' \ + <"$EVAL_OUT" >/dev/null; then + good "S1 the stale thread is skipped and the fresh thread posts" +else + bad "S1 post: exit $EVAL_STATUS $(head -c 500 "$EVAL_OUT") $(head -c 300 "$EVAL_ERR")" +fi +if [ "$(grep -c 'body=Answer one' "$EVAL_STUBLOG")" = "0" ] && \ + [ "$(grep -c 'body=Answer two' "$EVAL_STUBLOG")" = "1" ]; then + good "S2 only the fresh thread reached the host" +else + bad "S2 writes: $(grep 'body=Answer' "$EVAL_STUBLOG" || true)" +fi +if jq -e 'length == 1 and .[0].reply_id == "502"' "$DIR/replies.json" >/dev/null; then + good "S3 only one ledger entry was appended" +else + bad "S3 ledger: $(jq -c . "$DIR/replies.json" 2>/dev/null)" +fi +if matches 'unhandled gh call' "$EVAL_STUBLOG"; then + bad "a later run made an unregistered or mutating gh call: $(cat "$EVAL_STUBLOG")" +else + good "every gh call was registered and only the fresh reply was a write" +fi +eval_end diff --git a/internal/core/drain/ledger.go b/internal/core/drain/ledger.go index 3a7ca57b0..3ab9cde9e 100644 --- a/internal/core/drain/ledger.go +++ b/internal/core/drain/ledger.go @@ -13,7 +13,7 @@ import ( // AppendLedger records one successful reply under the store lock. A crash // after a host write but before this call is the only unrecorded window; once // the entry lands, the next drain reads it and makes no second host write. -func AppendLedger(path string, entry LedgerEntry) error { +func AppendLedger(path string, entry *LedgerEntry) error { unlock, err := storelock.Acquire(path, storelock.DefaultWait) if err != nil { return jq.NewErrf("could not lock %s: %v", path, err) @@ -23,7 +23,7 @@ func AppendLedger(path string, entry LedgerEntry) error { if err != nil { return err } - entries = append(entries, entry) + entries = append(entries, *entry) raw, err := json.MarshalIndent(entries, "", " ") if err != nil { return jq.NewErrf("could not encode %s: %v", path, err) diff --git a/internal/core/drain/ledger_test.go b/internal/core/drain/ledger_test.go index 989e6e937..8778e00f3 100644 --- a/internal/core/drain/ledger_test.go +++ b/internal/core/drain/ledger_test.go @@ -19,8 +19,8 @@ func TestAppendLedgerKeepsLegacyEntries(t *testing.T) { {Thread: "PRRT_1", ReplyID: "77", At: "2026-11-05T00:00:00Z", InReplyTo: "102", By: ReplyBy}, {Thread: "PRRT_2", ReplyID: "88", At: "2026-11-05T00:01:00Z", InReplyTo: "202", By: ReplyBy}, } - for _, entry := range entries { - if err := AppendLedger(path, entry); err != nil { + for i := range entries { + if err := AppendLedger(path, &entries[i]); err != nil { t.Fatalf("AppendLedger: %v", err) } } diff --git a/internal/core/drain/post.go b/internal/core/drain/post.go index fdb533b08..daf502049 100644 --- a/internal/core/drain/post.go +++ b/internal/core/drain/post.go @@ -20,17 +20,17 @@ const ReasonStaleThread = "stale-thread" // ordering and the idempotency rules can be tested without a host. type PostRequest struct { Plan *File - DraftsRaw []byte Feed *threadscore.File - Ledger []LedgerEntry + Reply func(rootID, threadID, body string) (string, error) + Resolve func(threadID string) error + Append func(*LedgerEntry) error + SaveFeed func(*threadscore.File) error Provider string Repo string PR string At string - Reply func(rootID, threadID, body string) (string, error) - Resolve func(threadID string) error - Append func(LedgerEntry) error - SaveFeed func(*threadscore.File) error + DraftsRaw []byte + Ledger []LedgerEntry } // PostResult is what the final receipt records. @@ -44,6 +44,26 @@ type PostResult struct { // entry per successful write. A host failure is recorded and the remaining // drafts are still attempted; the caller turns Incomplete into a refusal. func Post(req *PostRequest) (*PostResult, *core.RefusalError) { + doc, ref := postDrafts(req) + if ref != nil { + return nil, ref + } + byID := postThreads(req.Feed) + res := &PostResult{Posted: []Posted{}, Failed: []Failed{}} + for _, reply := range doc.Replies { + postOne(req, byID, reply, res) + } + req.Plan.Posted = res.Posted + req.Plan.Failed = res.Failed + at := req.At + req.Plan.PostedAt = &at + saveFeed(req, res) + res.Incomplete = len(res.Failed) > 0 + return res, nil +} + +// postDrafts runs §6's first gates: drafts, capability, then secret scan. +func postDrafts(req *PostRequest) (*RepliesFile, *core.RefusalError) { if req.Plan == nil || req.Feed == nil { return nil, &core.RefusalError{Code: CodeDrainFailed, Message: "drain-failed: no plan or thread feed to post against"} } @@ -68,26 +88,25 @@ func Post(req *PostRequest) (*PostResult, *core.RefusalError) { if ref := secretGate(doc.Replies); ref != nil { return nil, ref } - byID := make(map[string]*threadscore.Thread, len(req.Feed.Threads)) - for i := range req.Feed.Threads { - byID[req.Feed.Threads[i].ID] = &req.Feed.Threads[i] + return &doc, nil +} + +func postThreads(feed *threadscore.File) map[string]*threadscore.Thread { + byID := make(map[string]*threadscore.Thread, len(feed.Threads)) + for i := range feed.Threads { + byID[feed.Threads[i].ID] = &feed.Threads[i] } - res := &PostResult{Posted: []Posted{}, Failed: []Failed{}} - for _, reply := range doc.Replies { - postOne(req, byID, reply, res) + return byID +} + +func saveFeed(req *PostRequest, res *PostResult) { + if req.SaveFeed == nil { + return } - req.Plan.Posted = res.Posted - req.Plan.Failed = res.Failed - at := req.At - req.Plan.PostedAt = &at - if req.SaveFeed != nil { - if err := req.SaveFeed(req.Feed); err != nil { - res.Failed = append(res.Failed, Failed{ThreadID: "", Reason: "could not update threads.json: " + err.Error()}) - req.Plan.Failed = res.Failed - } + if err := req.SaveFeed(req.Feed); err != nil { + res.Failed = append(res.Failed, Failed{Reason: "could not update threads.json: " + err.Error()}) + req.Plan.Failed = res.Failed } - res.Incomplete = len(res.Failed) > 0 - return res, nil } func postOne(req *PostRequest, byID map[string]*threadscore.Thread, reply Reply, res *PostResult) { @@ -96,19 +115,9 @@ func postOne(req *PostRequest, byID map[string]*threadscore.Thread, reply Reply, res.Failed = append(res.Failed, Failed{ThreadID: reply.ThreadID, Reason: "thread missing from refreshed feed"}) return } - last := thread.Comments[len(thread.Comments)-1] - switch { - case thread.Resolved: - req.Plan.Skipped = append(req.Plan.Skipped, Skip{ThreadID: reply.ThreadID, Reason: ReasonResolved}) - return - case last.ID != reply.WaitingCommentID: - req.Plan.Skipped = append(req.Plan.Skipped, Skip{ThreadID: reply.ThreadID, Reason: ReasonStaleThread}) - return - case answered(req.Ledger, reply.ThreadID, &last): - req.Plan.Skipped = append(req.Plan.Skipped, Skip{ThreadID: reply.ThreadID, Reason: ReasonAlreadyReplied}) - return - case reply.Disposition == DispositionDefer: - req.Plan.Skipped = append(req.Plan.Skipped, Skip{ThreadID: reply.ThreadID, Reason: "defer"}) + last := &thread.Comments[len(thread.Comments)-1] + if reason := postSkipReason(req, reply, thread, last); reason != "" { + req.Plan.Skipped = append(req.Plan.Skipped, Skip{ThreadID: reply.ThreadID, Reason: reason}) return } body := recordcore.NeutralizeMentions(reply.Body) + "\n\n" + @@ -118,23 +127,49 @@ func postOne(req *PostRequest, byID map[string]*threadscore.Thread, reply Reply, res.Failed = append(res.Failed, Failed{ThreadID: reply.ThreadID, Reason: err.Error()}) return } - entry := LedgerEntry{Thread: reply.ThreadID, ReplyID: id, At: req.At, - InReplyTo: reply.WaitingCommentID, By: ReplyBy} - if err := req.Append(entry); err != nil { + res.Posted = append(res.Posted, recordPost(req, thread, reply, id, res)) +} + +// recordPost appends the ledger entry immediately after one successful write, +// then resolves a withdraw and marks the feed. A failure is recorded but never +// rolls back the reply already on the host. +func recordPost(req *PostRequest, thread *threadscore.Thread, reply Reply, id string, res *PostResult) Posted { + entry := LedgerEntry{ + Thread: reply.ThreadID, ReplyID: id, At: req.At, + InReplyTo: reply.WaitingCommentID, By: ReplyBy, + } + if err := req.Append(&entry); err != nil { res.Failed = append(res.Failed, Failed{ThreadID: reply.ThreadID, Reason: "could not record reply: " + err.Error()}) - return + return Posted{} } req.Ledger = append(req.Ledger, entry) posted := Posted{ThreadID: reply.ThreadID, ReplyID: id, Disposition: string(reply.Disposition)} - if reply.Disposition == DispositionWithdraw { - if err := req.Resolve(reply.ThreadID); err != nil { - res.Failed = append(res.Failed, Failed{ThreadID: reply.ThreadID, Reason: "could not resolve thread: " + err.Error()}) - } else { - thread.Resolved = true - posted.Resolved = true - } + if reply.Disposition != DispositionWithdraw { + return posted + } + if err := req.Resolve(reply.ThreadID); err != nil { + res.Failed = append(res.Failed, Failed{ThreadID: reply.ThreadID, Reason: "could not resolve thread: " + err.Error()}) + return posted + } + thread.Resolved = true + posted.Resolved = true + return posted +} + +// postSkipReason returns the typed reason a refreshed thread must not post. +func postSkipReason(req *PostRequest, reply Reply, thread *threadscore.Thread, last *threadscore.Comment) string { + switch { + case thread.Resolved: + return ReasonResolved + case last.ID != reply.WaitingCommentID: + return ReasonStaleThread + case answered(req.Ledger, reply.ThreadID, last): + return ReasonAlreadyReplied + case reply.Disposition == DispositionDefer: + return "defer" + default: + return "" } - res.Posted = append(res.Posted, posted) } // secretGate scans every outbound body before the first write and names the diff --git a/internal/core/drain/post_test.go b/internal/core/drain/post_test.go index a41a66073..bc5bbc384 100644 --- a/internal/core/drain/post_test.go +++ b/internal/core/drain/post_test.go @@ -33,8 +33,10 @@ func postFixture(t *testing.T, bodies map[string]string) (*PostRequest, *[]postC if custom, ok := bodies[id]; ok { body = custom } - replies = append(replies, Reply{ThreadID: id, WaitingCommentID: waiting[id], - Disposition: disposition, Body: body}) + replies = append(replies, Reply{ + ThreadID: id, WaitingCommentID: waiting[id], + Disposition: disposition, Body: body, + }) rootBody := "finding\n\n" + threadscore.ReplyMarker("root", "0") threads = append(threads, threadscore.Thread{ ID: id, Kind: threadscore.KindReview, Author: "verdict-bot", @@ -61,14 +63,12 @@ func postFixture(t *testing.T, bodies map[string]string) (*PostRequest, *[]postC return "reply-" + thread, nil }, Resolve: func(string) error { return nil }, - Append: func(entry LedgerEntry) error { ledger = append(ledger, entry); return nil }, + Append: func(entry *LedgerEntry) error { ledger = append(ledger, *entry); return nil }, SaveFeed: func(*threadscore.File) error { return nil }, } return req, &calls, &ledger } -// TestPostMarksBodiesAndLedger pins the reply bytes and the order: each write -// gets a locked ledger entry, and withdraw resolves only after the reply lands. func TestPostMarksBodiesAndLedger(t *testing.T) { req, calls, ledger := postFixture(t, map[string]string{ "PRRT_1": "Ping @alice, see the note.", @@ -79,26 +79,50 @@ func TestPostMarksBodiesAndLedger(t *testing.T) { if ref != nil { t.Fatalf("Post refused: %+v", ref) } - if len(*calls) != 3 || len(*ledger) != 3 { - t.Fatalf("calls = %d, ledger = %d, want 3 each", len(*calls), len(*ledger)) + assertPostedCalls(t, *calls, *ledger, resolved, res) + assertWithdrawFeed(t, req.Feed) +} + +func assertPostedCalls(t *testing.T, calls []postCall, ledger []LedgerEntry, resolved []string, res *PostResult) { + t.Helper() + if len(calls) != 3 || len(ledger) != 3 { + t.Fatalf("calls = %d, ledger = %d, want 3 each", len(calls), len(ledger)) } - first := (*calls)[0] - if want := threadscore.ReplyMarker("PRRT_1", "101"); !strings.HasSuffix(first.body, want) { - t.Errorf("body %q did not end with %q", first.body, want) + assertReplyBody(t, calls[0].body) + assertWithdrawLedger(t, &ledger[1]) + assertWithdrawResult(t, resolved, res) +} + +func assertReplyBody(t *testing.T, body string) { + t.Helper() + if want := threadscore.ReplyMarker("PRRT_1", "101"); !strings.HasSuffix(body, want) { + t.Errorf("body %q did not end with %q", body, want) } - if !strings.Contains(first.body, "@\u200balice") || strings.Contains(first.body, "@alice") { - t.Errorf("mention was not neutralized: %q", first.body) + if !strings.Contains(body, "@\u200balice") || strings.Contains(body, "@alice") { + t.Errorf("mention was not neutralized: %q", body) } +} + +func assertWithdrawLedger(t *testing.T, entry *LedgerEntry) { + t.Helper() + if entry.InReplyTo != "201" || entry.By != ReplyBy || entry.ReplyID != "reply-PRRT_2" { + t.Errorf("withdraw ledger entry = %+v", entry) + } +} + +func assertWithdrawResult(t *testing.T, resolved []string, res *PostResult) { + t.Helper() if len(resolved) != 1 || resolved[0] != "PRRT_2" { t.Errorf("resolved = %v, want PRRT_2", resolved) } - if (*ledger)[1].InReplyTo != "201" || (*ledger)[1].By != ReplyBy || (*ledger)[1].ReplyID != "reply-PRRT_2" { - t.Errorf("withdraw ledger entry = %+v", (*ledger)[1]) - } if len(res.Posted) != 3 || !res.Posted[1].Resolved || res.Incomplete { t.Errorf("result = %+v", res) } - if req.Feed.Threads[1].Resolved != true || req.Feed.Threads[0].Resolved { +} + +func assertWithdrawFeed(t *testing.T, feed *threadscore.File) { + t.Helper() + if len(feed.Threads) < 2 || !feed.Threads[1].Resolved || feed.Threads[0].Resolved { t.Error("withdraw was not the only thread marked resolved in the feed") } } @@ -106,45 +130,70 @@ func TestPostMarksBodiesAndLedger(t *testing.T) { // TestPostPartialFailureRerunIsIdempotent fails write 2, then reruns with the // recorded ledger. The thread whose reply landed is never written twice. func TestPostPartialFailureRerunIsIdempotent(t *testing.T) { - req, calls, ledger := postFixture(t, nil) - failSecond := true - req.Reply = func(root, thread, body string) (string, error) { - if thread == "PRRT_2" && failSecond { - return "", errors.New("host rejected the reply") - } - *calls = append(*calls, postCall{root, thread, body}) - return "reply-" + thread, nil - } + f := failingPostFixture(t) + req := f.PostRequest first, ref := Post(req) if ref != nil || !first.Incomplete || len(first.Failed) != 1 || first.Failed[0].ThreadID != "PRRT_2" { t.Fatalf("first result = %+v, refusal = %+v", first, ref) } - if len(*ledger) != 2 { - t.Fatalf("ledger after failure = %+v", *ledger) - } - req.Ledger = append([]LedgerEntry{}, (*ledger)...) - // The live refresh reads the posted marker back as verdict-authored. - for i := range req.Feed.Threads { - if req.Feed.Threads[i].ID == "PRRT_1" { - last := &req.Feed.Threads[i].Comments[1] - last.Body += "\n\n" + threadscore.ReplyMarker("PRRT_1", last.ID) - last.AuthorKind = threadscore.AuthorVerdict - } + if len(*f.ledger) != 2 { + t.Fatalf("ledger after failure = %+v", *f.ledger) } - *calls = nil - failSecond = false + f.failSecond = false + markMarkedReplyVerdict(req) + *f.calls = nil second, ref := Post(req) if ref != nil || second.Incomplete || len(second.Posted) != 1 { t.Fatalf("second result = %+v, refusal = %+v", second, ref) } - for _, call := range *calls { + assertRerunCalls(t, *f.calls, req.Plan.Skipped) +} + +type rerunFixture struct { + *PostRequest + calls *[]postCall + ledger *[]LedgerEntry + failSecond bool +} + +func failingPostFixture(t *testing.T) *rerunFixture { + t.Helper() + req, calls, ledger := postFixture(t, nil) + f := &rerunFixture{PostRequest: req, calls: calls, ledger: ledger, failSecond: true} + req.Reply = func(root, thread, body string) (string, error) { + if thread == "PRRT_2" && f.failSecond { + return "", errors.New("host rejected the reply") + } + *calls = append(*calls, postCall{root, thread, body}) + return "reply-" + thread, nil + } + return f +} + +func assertRerunCalls(t *testing.T, calls []postCall, skips []Skip) { + t.Helper() + for _, call := range calls { if call.thread == "PRRT_1" { t.Errorf("rerun double-posted %q", call.thread) } } - if !hasSkip(req.Plan.Skipped, "PRRT_1", ReasonAlreadyReplied) || - !hasSkip(req.Plan.Skipped, "PRRT_3", ReasonAlreadyReplied) { - t.Errorf("rerun skips = %+v", req.Plan.Skipped) + if !hasSkip(skips, "PRRT_1", ReasonAlreadyReplied) || + !hasSkip(skips, "PRRT_3", ReasonAlreadyReplied) { + t.Errorf("rerun skips = %+v", skips) + } +} + +// markMarkedReplyVerdict is what a fresh threads refresh does with a posted +// marker: the answer reads back as verdict-authored, not as a human question. +func markMarkedReplyVerdict(req *PostRequest) { + req.Ledger = append([]LedgerEntry{}, req.Ledger...) + for i := range req.Feed.Threads { + if req.Feed.Threads[i].ID != "PRRT_1" { + continue + } + last := &req.Feed.Threads[i].Comments[1] + last.Body += "\n\n" + threadscore.ReplyMarker("PRRT_1", last.ID) + last.AuthorKind = threadscore.AuthorVerdict } } @@ -157,19 +206,28 @@ func hasSkip(skips []Skip, thread, reason string) bool { return false } -// TestPostStaleAndSecretRefusals pins the live checks before the first write: -// a new comment makes a draft stale, and a credential body refuses the whole -// run with no host call at all. func TestPostStaleAndSecretRefusals(t *testing.T) { req, calls, ledger := postFixture(t, nil) + assertStaleSkip(t, req, calls, ledger) + secretReq, secretCalls, secretLedger := postFixture(t, map[string]string{ + "PRRT_1": "key AKIAIOSFODNN7EXAMPLE here", + }) + _, ref := Post(secretReq) + if ref == nil || ref.Code != "post-secret-shaped" { + t.Fatalf("secret refusal = %+v, want post-secret-shaped", ref) + } + if len(*secretCalls) != 0 || len(*secretLedger) != 0 { + t.Errorf("secret draft made %d call(s) and %d ledger entry/entries", len(*secretCalls), len(*secretLedger)) + } +} + +func assertStaleSkip(t *testing.T, req *PostRequest, calls *[]postCall, ledger *[]LedgerEntry) { + t.Helper() req.Feed.Threads[0].Comments[1].ID = "999" res, ref := Post(req) - if ref != nil || len(res.Posted) != 2 { + if ref != nil || len(res.Posted) != 2 || len(res.Failed) != 0 { t.Fatalf("stale result = %+v, refusal = %+v", res, ref) } - if len(res.Failed) != 0 { - t.Errorf("stale failures = %+v", res.Failed) - } if !hasSkip(req.Plan.Skipped, "PRRT_1", ReasonStaleThread) { t.Errorf("stale skip missing from %+v", req.Plan.Skipped) } @@ -181,17 +239,6 @@ func TestPostStaleAndSecretRefusals(t *testing.T) { if len(*ledger) != 2 { t.Errorf("stale run wrote %d ledger entries, want 2", len(*ledger)) } - - secretReq, secretCalls, secretLedger := postFixture(t, map[string]string{ - "PRRT_1": "key AKIAIOSFODNN7EXAMPLE here", - }) - _, ref = Post(secretReq) - if ref == nil || ref.Code != "post-secret-shaped" { - t.Fatalf("secret refusal = %+v, want post-secret-shaped", ref) - } - if len(*secretCalls) != 0 || len(*secretLedger) != 0 { - t.Errorf("secret draft made %d call(s) and %d ledger entry/entries", len(*secretCalls), len(*secretLedger)) - } } // TestPostNoDraftsRefuses pins the advice a post run gives when --agent has diff --git a/internal/core/hint.go b/internal/core/hint.go index 03e230d18..e3678b095 100644 --- a/internal/core/hint.go +++ b/internal/core/hint.go @@ -45,6 +45,7 @@ var hintRules = []HintRule{ {codes: []string{"drafts-invalid"}, hint: "try: fix the named site in drain.replies.json, then re-run drain --agent"}, {codes: []string{"drafts-stale"}, hint: "try: re-run drain for a fresh plan, then draft against its new plan_digest"}, {codes: []string{"drain-failed"}, hint: "try: refresh threads, confirm host auth, then re-run drain"}, + {codes: []string{"drain-incomplete"}, hint: "try: re-run the same drain --post command; the ledger skips replies already posted"}, {codes: []string{"prompt-dump-failed"}, hint: "try: run from a checkout carrying SKILL.md/prompts, then re-run"}, {codes: []string{"post-failed"}, hint: "try: narrow anchor drift or body size (see above), then re-run"}, {codes: []string{"post-secret-shaped"}, hint: "try: remove the value from review.json and re-run, " + diff --git a/internal/core/hint_test.go b/internal/core/hint_test.go index f81749fdc..ae2795a74 100644 --- a/internal/core/hint_test.go +++ b/internal/core/hint_test.go @@ -55,6 +55,13 @@ func TestHintForPackSources(t *testing.T) { // TestHintForPostSecretShaped proves the refusal's hint offers both ways out — // strip the value, or publish it on purpose — and prints nothing that could be // the value itself. +// TestHintForDrainIncomplete names the command that retries only the replies +// that did not land: the ledger makes the already posted ones no-ops. +func TestHintForDrainIncomplete(t *testing.T) { + assertHintFragments(t, HintFor("drain-incomplete"), "drain-incomplete", + []string{"drain --post", "ledger skips replies already posted"}, nil) +} + func TestHintForPostSecretShaped(t *testing.T) { assertHintFragments(t, HintFor("post-secret-shaped"), "post-secret-shaped", []string{"remove the value", "--allow-secret-values"}, diff --git a/internal/core/post/host_reply_test.go b/internal/core/post/host_reply_test.go index f5f0f877e..e3b6d97c3 100644 --- a/internal/core/post/host_reply_test.go +++ b/internal/core/post/host_reply_test.go @@ -9,48 +9,61 @@ import ( "github.com/stainless-code/verdict/internal/jq" ) +type replyRoute struct { + name, provider, call, stdin, id string +} + +var replyRoutes = []replyRoute{ + { + name: "github", provider: "github", id: "77", + call: "gh\x00api\x00--method\x00POST\x00repos/acme/app/pulls/7/comments/101/replies\x00-f\x00body=" + replyTestBody, + }, + { + name: "gitlab", provider: "gitlab", id: "88", + call: "glab\x00api\x00projects/acme%2Fapp/merge_requests/7/discussions/PRRT_1/notes\x00--method\x00POST\x00--header\x00Content-Type: application/json\x00--input\x00-", + stdin: "{\"body\":\"answer with @alice and `quotes`\\n\"}", + }, +} + +const replyTestBody = "answer with @alice and `quotes`\n" + // TestReplyThreadArgv pins the exact host calls drain makes and the body each // one carries. The body is one argv field on GitHub and one stdin document on // GitLab; no shell or interpolation sits between the draft and the host. func TestReplyThreadArgv(t *testing.T) { - const body = "answer with @alice and `quotes`\n" - cases := []struct { - name, provider, call, stdin, id string - }{ - { - name: "github", provider: "github", id: "77", - call: "gh\x00api\x00--method\x00POST\x00repos/acme/app/pulls/7/comments/101/replies\x00-f\x00body=" + body, - }, - { - name: "gitlab", provider: "gitlab", id: "88", - call: "glab\x00api\x00projects/acme%2Fapp/merge_requests/7/discussions/PRRT_1/notes\x00--method\x00POST\x00--header\x00Content-Type: application/json\x00--input\x00-", - stdin: "{\"body\":\"answer with @alice and `quotes`\\n\"}", - }, + for i := range replyRoutes { + tc := &replyRoutes[i] + t.Run(tc.name, func(t *testing.T) { assertReplyRoute(t, tc) }) } - for _, tc := range cases { - t.Run(tc.name, func(t *testing.T) { - cmdr := &scriptCommander{t: t, out: map[string]scriptResult{ - tc.call: {stdout: `{"id":` + tc.id + `}`}, - }} - got, ref := ReplyThread(context.Background(), cmdr, tc.provider, nil, - "acme/app", "7", "101", "PRRT_1", body) - if ref != nil { - t.Fatalf("ReplyThread refused: %+v", ref) - } - if got != tc.id { - t.Errorf("reply id = %q, want %q", got, tc.id) - } - if len(cmdr.calls) != 1 || strings.Join(cmdr.calls[0], "\x00") != tc.call { - t.Fatalf("calls = %q, want %q", cmdr.calls, tc.call) - } - if tc.stdin != "" { - doc, err := jq.Decode([]byte(cmdr.stdin[0])) - obj, ok := jq.AsMap(doc) - if err != nil || !ok || jq.R(jq.Alt(obj["body"], "")) != body { - t.Errorf("stdin body = %q (err %v), want %q", cmdr.stdin[0], err, body) - } - } - }) +} + +func assertReplyRoute(t *testing.T, tc *replyRoute) { + t.Helper() + cmdr := &scriptCommander{t: t, out: map[string]scriptResult{ + tc.call: {stdout: `{"id":` + tc.id + `}`}, + }} + got, ref := ReplyThread(context.Background(), cmdr, tc.provider, nil, + "acme/app", "7", "101", "PRRT_1", replyTestBody) + if ref != nil { + t.Fatalf("ReplyThread refused: %+v", ref) + } + if got != tc.id { + t.Errorf("reply id = %q, want %q", got, tc.id) + } + if len(cmdr.calls) != 1 || strings.Join(cmdr.calls[0], "\x00") != tc.call { + t.Fatalf("calls = %q, want %q", cmdr.calls, tc.call) + } + if tc.stdin != "" { + assertReplyStdin(t, cmdr.stdin[0]) + } +} + +func assertReplyStdin(t *testing.T, stdin string) { + t.Helper() + doc, err := jq.Decode([]byte(stdin)) + obj, ok := jq.AsMap(doc) + if err != nil || !ok || jq.R(jq.Alt(obj["body"], "")) != replyTestBody { + t.Errorf("stdin body = %q (err %v), want %q", stdin, err, replyTestBody) } } @@ -63,9 +76,9 @@ func TestReplyThreadRefusesUnsupportedHost(t *testing.T) { if ref == nil || ref.Code != "provider-unimplemented" { t.Fatalf("refusal = %+v, want provider-unimplemented", ref) } - if !strings.Contains(ref.Message, core.CapabilitiesFor("forgejo").ThreadReplyReason()) { - t.Errorf("message %q did not name the reason %q", ref.Message, - core.CapabilitiesFor("forgejo").ThreadReplyReason()) + reason := core.CapabilitiesFor("forgejo").ThreadReplyReason() + if !strings.Contains(ref.Message, reason) { + t.Errorf("message %q did not name the reason %q", ref.Message, reason) } if len(cmdr.calls) != 0 { t.Errorf("unsupported host made %d call(s)", len(cmdr.calls)) diff --git a/internal/core/refusalcodes.go b/internal/core/refusalcodes.go index 5f6e130ba..d783a038d 100644 --- a/internal/core/refusalcodes.go +++ b/internal/core/refusalcodes.go @@ -123,6 +123,7 @@ var refusalCodes = []string{ "drafts-invalid", "drafts-stale", "drain-failed", + "drain-incomplete", "duplicate-payload", "fetch-failed", "filtered-out", diff --git a/internal/core/testdata/hints.golden b/internal/core/testdata/hints.golden index ccde5e3b7..b8d48b060 100644 --- a/internal/core/testdata/hints.golden +++ b/internal/core/testdata/hints.golden @@ -96,6 +96,7 @@ download-failed try: address the cause above, then re-run the same command drafts-invalid try: fix the named site in drain.replies.json, then re-run drain --agent drafts-stale try: re-run drain for a fresh plan, then draft against its new plan_digest drain-failed try: refresh threads, confirm host auth, then re-run drain +drain-incomplete try: re-run the same drain --post command; the ledger skips replies already posted duplicate-payload try: re-run with --force to repost the identical payload — re-fetch if the earlier review was deleted fetch-failed try: run 'gh auth status', confirm the repo/PR spelling, then re-run filtered-out try: remove --filter to review every PR, or change the trigger at the PR base and re-fetch diff --git a/internal/core/threads/reply_marker_test.go b/internal/core/threads/reply_marker_test.go index 09c495c2c..8ed3e6634 100644 --- a/internal/core/threads/reply_marker_test.go +++ b/internal/core/threads/reply_marker_test.go @@ -2,9 +2,8 @@ package threadscore import "testing" -// TestReplyMarkerRoundTrip pins the hidden marker drain appends and the author -// label a fresh threads refresh gives the reply. A quoted marker is not the -// final line and must not make a human comment verdict-authored. +// TestReplyMarkerRoundTrip pins the hidden marker drain appends and the ids it +// carries back to the next refresh. func TestReplyMarkerRoundTrip(t *testing.T) { thread, waiting := "PRRT_1", "456" marker := ReplyMarker(thread, waiting) @@ -12,10 +11,23 @@ func TestReplyMarkerRoundTrip(t *testing.T) { t.Fatalf("ReplyMarker = %q, want %q", marker, want) } body := "Here is the answer.\n\n" + marker - if !IsVerdictBody(body) { + id, to, ok := ReplyTarget(body) + if !ok || id != thread || to != waiting { + t.Errorf("ReplyTarget = %q, %q, %v; want %q, %q, true", id, to, ok, thread, waiting) + } + if _, _, ok := ReplyTarget("you wrote " + marker + "\nstill human"); ok { + t.Error("ReplyTarget read a quoted marker") + } +} + +// TestReplyMarkerSetsAuthorKind proves a posted reply reads as verdict while a +// marker quoted mid-body leaves the human author label alone. +func TestReplyMarkerSetsAuthorKind(t *testing.T) { + marker := ReplyMarker("PRRT_1", "456") + if !IsVerdictBody("answer\n\n" + marker) { t.Error("a posted reply body did not read as verdict-marked") } - if got := AuthorKind("alice", false, body); got != AuthorVerdict { + if got := AuthorKind("alice", false, "answer\n\n"+marker); got != AuthorVerdict { t.Errorf("AuthorKind = %q, want %q", got, AuthorVerdict) } quoted := "you wrote " + marker + "\nstill a human reply" @@ -25,10 +37,4 @@ func TestReplyMarkerRoundTrip(t *testing.T) { if got := AuthorKind("alice", false, quoted); got != AuthorHuman { t.Errorf("quoted AuthorKind = %q, want %q", got, AuthorHuman) } - if id, to, ok := ReplyTarget(body); !ok || id != thread || to != waiting { - t.Errorf("ReplyTarget = %q, %q, %v; want %q, %q, true", id, to, ok, thread, waiting) - } - if _, _, ok := ReplyTarget(quoted); ok { - t.Error("ReplyTarget read a quoted marker") - } } diff --git a/internal/core/threads/threads.go b/internal/core/threads/threads.go index f4ed16c2a..2c19d0ac8 100644 --- a/internal/core/threads/threads.go +++ b/internal/core/threads/threads.go @@ -315,7 +315,7 @@ var summaryMarkerRe = regexp.MustCompile(`^" -// replyMarkerRe reads only a body's final line, and only ids without whitespace. +// replyMarkerRe reads only a final line whose ids carry no whitespace. var replyMarkerRe = regexp.MustCompile(`^$`) // SummaryMarker renders the hidden final line of a PR-level summary comment. diff --git a/internal/drain/post.go b/internal/drain/post.go index 7a9e92889..994aafb9f 100644 --- a/internal/drain/post.go +++ b/internal/drain/post.go @@ -21,65 +21,126 @@ import ( // check the capability, refresh the feed, then hand the write order to the // pure post service. The plan and the feed it writes are the run's receipt. func postMode(ctx context.Context, r *cli.Runner, req Request, fl *flags) int { - dir, ref := readcommon.ResolveBundleDir(req.RepoRootPath(), req.Pr) + dir, plan, ref := postPlan(req, fl) + if ref != nil { + return r.Refuse(ref) + } + drafts, ref := postDraftsFile(dir) + if ref != nil { + return r.Refuse(ref) + } + resp, ref := fetchcore.RunThreads(ctx, refreshRequest(r, req, fl)) if ref != nil { return r.Refuse(drainFailed(ref.Message)) } + in, code, done := readInputs(ctx, r, req, fl, resp) + if done { + return code + } + result, ref := postWrites(ctx, req, dir, plan, drafts, in) + if ref != nil { + return r.Refuse(ref) + } + return postFinish(r, req, dir, plan, resp, result) +} + +// postPlan reads the plan and checks the capability before any host read. +func postPlan(req Request, fl *flags) (string, *draincore.File, *core.RefusalError) { + dir, ref := readcommon.ResolveBundleDir(req.RepoRootPath(), req.Pr) + if ref != nil { + return "", nil, drainFailed(ref.Message) + } plan, err := draincore.ReadPlan(dir + pathSep + draincore.KeyPlanJSON) if err != nil { - return r.Refuse(drainFailed(err.Error())) + return "", nil, drainFailed(err.Error()) } - provider := plan.Provider - if fl.provider != "" && fl.provider != provider { - return r.Refuse(drainFailed(fmt.Sprintf("--provider %s disagrees with the plan's %s", fl.provider, provider))) + if ref := planProvider(plan.Provider, fl.provider); ref != nil { + return "", nil, ref } - caps := core.CapabilitiesFor(provider) + caps := core.CapabilitiesFor(plan.Provider) if !caps.ThreadReply { - return r.Refuse(&core.RefusalError{Code: "provider-unimplemented", Message: fmt.Sprintf( - "thread replies on %s are not implemented (%s)", provider, caps.ThreadReplyReason())}) + return "", nil, &core.RefusalError{Code: "provider-unimplemented", Message: fmt.Sprintf( + "thread replies on %s are not implemented (%s)", plan.Provider, caps.ThreadReplyReason())} } - var drafts []byte - drafts, err = jq.CappedFile(dir+pathSep+draincore.KeyDraftsJSON, jq.MaxPRBytes) - if err != nil && !errors.Is(err, fs.ErrNotExist) { - return r.Refuse(drainFailed(fmt.Sprintf("unreadable %s/%s: %v", dir, draincore.KeyDraftsJSON, err))) + return dir, plan, nil +} + +func planProvider(planned, requested string) *core.RefusalError { + if requested != "" && requested != planned { + return drainFailed(fmt.Sprintf("--provider %s disagrees with the plan's %s", requested, planned)) } - resp, ref := fetchcore.RunThreads(ctx, refreshRequest(r, req, fl)) - if ref != nil { - return r.Refuse(drainFailed(ref.Message)) + return nil +} + +func postDraftsFile(dir string) ([]byte, *core.RefusalError) { + raw, err := jq.CappedFile(dir+pathSep+draincore.KeyDraftsJSON, jq.MaxPRBytes) + if err == nil { + return raw, nil } - in, code, done := readInputs(ctx, r, req, fl, resp) - if done { - return code + if errors.Is(err, fs.ErrNotExist) { + return nil, nil } + return nil, drainFailed(fmt.Sprintf("unreadable %s/%s: %v", dir, draincore.KeyDraftsJSON, err)) +} + +func postWrites(ctx context.Context, req Request, dir string, plan *draincore.File, + drafts []byte, in *planInputs, +) (*draincore.PostResult, *core.RefusalError) { + provider := plan.Provider cmdr := commander(req) - at := req.TimeUTC() draftsReq := &draincore.PostRequest{ Plan: plan, DraftsRaw: drafts, Feed: in.feed, Ledger: in.ledger, - Provider: provider, Repo: req.Repo, PR: req.Pr, At: at, - Reply: func(rootID, threadID, body string) (string, error) { - id, rerr := postcore.ReplyThread(ctx, cmdr, provider, req.Env, req.Repo, req.Pr, rootID, threadID, body) - if rerr != nil { - return "", rerr - } - return id, nil - }, - Resolve: func(threadID string) error { - return postcore.ResolveThread(ctx, cmdr, provider, req.Env, req.Repo, req.Pr, threadID) - }, - Append: func(entry draincore.LedgerEntry) error { - return draincore.AppendLedger(dir+pathSep+draincore.KeyLedgerJSON, entry) - }, - SaveFeed: func(feed *threadscore.File) error { - return threadscore.WriteFile(dir+pathSep+threadscore.KeyThreadsJSON, feed) - }, + Provider: provider, Repo: req.Repo, PR: req.Pr, At: req.TimeUTC(), + Reply: replyWriter(ctx, cmdr, req, provider), + Resolve: resolveWriter(ctx, cmdr, req, provider), + Append: appendLedgerWriter(dir), + SaveFeed: saveFeedWriter(dir), } result, ref := draincore.Post(draftsReq) if ref != nil { - return r.Refuse(ref) + return nil, ref } if err := draincore.WritePlan(dir+pathSep+draincore.KeyPlanJSON, plan); err != nil { - return r.Refuse(drainFailed(err.Error())) + return nil, drainFailed(err.Error()) + } + return result, nil +} + +func replyWriter(ctx context.Context, cmdr core.Commander, req Request, provider string, +) func(string, string, string) (string, error) { + return func(rootID, threadID, body string) (string, error) { + id, ref := postcore.ReplyThread(ctx, cmdr, provider, req.Env, req.Repo, req.Pr, rootID, threadID, body) + if ref != nil { + return "", jq.NewErrf("reply to %s: %v", threadID, ref) + } + return id, nil + } +} + +func resolveWriter(ctx context.Context, cmdr core.Commander, req Request, provider string) func(string) error { + return func(threadID string) error { + if ref := postcore.ResolveThread(ctx, cmdr, provider, req.Env, req.Repo, req.Pr, threadID); ref != nil { + return jq.NewErrf("resolve %s: %v", threadID, ref) + } + return nil + } +} + +func appendLedgerWriter(dir string) func(*draincore.LedgerEntry) error { + return func(entry *draincore.LedgerEntry) error { + return draincore.AppendLedger(dir+pathSep+draincore.KeyLedgerJSON, entry) + } +} + +func saveFeedWriter(dir string) func(*threadscore.File) error { + return func(feed *threadscore.File) error { + return threadscore.WriteFile(dir+pathSep+threadscore.KeyThreadsJSON, feed) } +} + +func postFinish(r *cli.Runner, req Request, dir string, plan *draincore.File, + resp *fetchcore.ThreadsResponse, result *draincore.PostResult, +) int { r.Warnings = append(r.Warnings, resp.Warnings...) nextText := "refresh threads with verdict threads " + req.Repo + " " + req.Pr if result.Incomplete { @@ -93,7 +154,7 @@ func postMode(ctx context.Context, r *cli.Runner, req Request, fl *flags) int { fmt.Fprint(r.Out, jq.PrettyOrdered(env)) } if result.Incomplete { - return r.Refuse(&core.RefusalError{Code: draincore.CodeDrainIncomplete, Message: fmt.Sprintf( + return r.Refuse(&core.RefusalError{Code: "drain-incomplete", Message: fmt.Sprintf( "%d thread(s) could not be posted; the ledger makes a re-run idempotent", len(result.Failed))}) } return cli.ExitOK diff --git a/scripts/verdict-complete.sh b/scripts/verdict-complete.sh index 1cc8eda8d..6523fdb37 100755 --- a/scripts/verdict-complete.sh +++ b/scripts/verdict-complete.sh @@ -27,7 +27,7 @@ _verdict_flags() { # $1 = verb index) printf '%s\n' build status prune callers tests-for co-changed owners blast-radius --from --at --depth --limit --commits --since --min-count --symbol --pr --paths --json;; backtest) printf '%s\n' mine replay score --since --until --run --agent --max-reviews --budget-usd --timeout --rounds --json;; threads) printf '%s\n' --provider --thread --dry-run --json;; - drain) printf '%s\n' --provider --max-threads --agent --timeout --json --;; + drain) printf '%s\n' --provider --max-threads --agent --timeout --post --json --;; fetch-local) printf '%s\n' --staged --range --base --stash --worktree --context --ignore --no-default-excludes --index --consent-over-budget --show-prompts --chunk --json;; run) printf '%s\n' --agent --recipe --stage --timeout --rounds --print --json --;; learn) printf '%s\n' --propose --from-bundle --accept --reject --dry-run --pack --incident --sha --path --note --url --at --rule --scope --id --provenance --rigor --status --retire --restore --reason --json;; diff --git a/skills/verdict/prompts/address-reviews.md b/skills/verdict/prompts/address-reviews.md index a9c0fe89f..35073077b 100644 --- a/skills/verdict/prompts/address-reviews.md +++ b/skills/verdict/prompts/address-reviews.md @@ -50,7 +50,9 @@ not the numeric comment id), which closes only verdict-authored threads and writes `threads-resolve.json`. Log every posted reply `{thread, reply_id, at}` into `.verdict/state/N/replies.json` (creating it) and skip threads already logged — a crashed-and-rerun - pass must never double-reply. Reading works on all six hosts; on GitCafe, Bitbucket, and + pass must never double-reply. `verdict drain ... --post` writes the same file with two extra + fields (`in_reply_to`, `by: "drain"`) and skips entries it already recorded; a legacy entry + without `in_reply_to` answers comments at or before its `at`. Reading works on all six hosts; on GitCafe, Bitbucket, and Azure record the disposition in `replies.json` and the summary. Resolve only after the revalidator confirms fixed, user asked, or you withdraw your own bot finding. Leave discussion/partial/disagreement open. diff --git a/skills/verdict/references/commands.md b/skills/verdict/references/commands.md index a75115e8d..a7868564d 100644 --- a/skills/verdict/references/commands.md +++ b/skills/verdict/references/commands.md @@ -45,6 +45,20 @@ review history refuses `pr-read-failed`. A head that changes during a read is retried on the next interval inside a bounded wait, and one still changing when the timeout arrives refuses `pr-read-failed`. +## `drain` — unattended thread replies + +`verdict drain owner/repo N [--provider p] [--max-threads 1-100] [--agent name] +[--timeout s] [-- args...] [--post] [--json]` writes `drain.json` with the +threads waiting on verdict, a `plan_digest`, and typed skips. `--agent` drafts +`drain.replies.json` through the `run` launcher. `--post` validates those +drafts, re-reads threads and the login, skips threads that resolved or changed, +scans for secret-shaped bodies, neutralizes mentions, and appends a hidden +`verdict-reply` marker so the next refresh labels the answer `verdict`. Each +successful write appends `replies.json` under a lock; `withdraw` also resolves. +GitHub and GitLab only; a write failure records `failed[]` and refuses +`drain-incomplete`, after which the same `--post` command retries only the +threads without a ledger entry. + ## Suppression receipts Read `excluded.json` and the TOC exclusion section before judging review coverage. From c47b41c63cadf5d1e3e5e820af575a9ec70f5e8b Mon Sep 17 00:00:00 2001 From: Sutu Sebastian Date: Tue, 17 Nov 2026 14:23:20 +0200 Subject: [PATCH 04/14] chore(size): raise the byte ratchet for drain post Measured with make size before the bump: darwin/amd64 17529360 (budget 17500000) darwin/arm64 15932226 (budget 15900000) linux/amd64 17223840 (budget 17190000) linux/arm64 15597728 (budget 15600000) windows/amd64 17619968 (budget 17590000) windows/arm64 15711744 (budget 15680000) deps 0 (budget 0) --- scripts/size-baseline.txt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/size-baseline.txt b/scripts/size-baseline.txt index 3f51706f7..69a57663e 100644 --- a/scripts/size-baseline.txt +++ b/scripts/size-baseline.txt @@ -1,7 +1,7 @@ deps 0 -darwin/amd64 17500000 -darwin/arm64 15900000 -linux/amd64 17190000 +darwin/amd64 17530000 +darwin/arm64 15940000 +linux/amd64 17230000 linux/arm64 15600000 -windows/amd64 17590000 -windows/arm64 15680000 +windows/amd64 17620000 +windows/arm64 15720000 From 75d59a908f7746962fb09bf5a7b629de38a716db Mon Sep 17 00:00:00 2001 From: Sutu Sebastian Date: Tue, 17 Nov 2026 14:35:25 +0200 Subject: [PATCH 05/14] fix(hint): name the draft, not one verb's file --- docs/troubleshooting.md | 4 ++-- internal/core/hint.go | 4 ++-- internal/core/hint_test.go | 8 ++++---- internal/core/testdata/hints.golden | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/docs/troubleshooting.md b/docs/troubleshooting.md index 22b6c13ea..23f56b01e 100644 --- a/docs/troubleshooting.md +++ b/docs/troubleshooting.md @@ -1053,9 +1053,9 @@ Fix: narrow anchor drift or body size (see above), then re-run. ## `post-secret-shaped` -Cause: `review.json` carries a secret-shaped value. +Cause: a review draft carries a secret-shaped value — `review.json` for `post`, `drain.replies.json` for `drain --post`. -Fix: remove the value from `review.json` and re-run, or pass `--allow-secret-values` to publish it anyway. +Fix: remove the value from the draft and re-run. `post` can pass `--allow-secret-values` to publish it anyway; `drain --post` has no override. ## `pr-not-open` diff --git a/internal/core/hint.go b/internal/core/hint.go index e3678b095..ea91163c1 100644 --- a/internal/core/hint.go +++ b/internal/core/hint.go @@ -48,8 +48,8 @@ var hintRules = []HintRule{ {codes: []string{"drain-incomplete"}, hint: "try: re-run the same drain --post command; the ledger skips replies already posted"}, {codes: []string{"prompt-dump-failed"}, hint: "try: run from a checkout carrying SKILL.md/prompts, then re-run"}, {codes: []string{"post-failed"}, hint: "try: narrow anchor drift or body size (see above), then re-run"}, - {codes: []string{"post-secret-shaped"}, hint: "try: remove the value from review.json and re-run, " + - "or pass --allow-secret-values to publish it anyway"}, + {codes: []string{"post-secret-shaped"}, hint: "try: remove the value from the draft and re-run; " + + "post can pass --allow-secret-values to publish it anyway"}, {codes: []string{"fix-patch-secret"}, hint: "try: remove the value from the worktree (rotate it " + "if it was real), then re-run fix"}, {codes: []string{"filtered-out"}, hint: "try: remove --filter to review every PR, or change the trigger at the PR base and re-fetch"}, diff --git a/internal/core/hint_test.go b/internal/core/hint_test.go index ae2795a74..a7583da2a 100644 --- a/internal/core/hint_test.go +++ b/internal/core/hint_test.go @@ -52,9 +52,6 @@ func TestHintForPackSources(t *testing.T) { []string{"pack.json"}) } -// TestHintForPostSecretShaped proves the refusal's hint offers both ways out — -// strip the value, or publish it on purpose — and prints nothing that could be -// the value itself. // TestHintForDrainIncomplete names the command that retries only the replies // that did not land: the ledger makes the already posted ones no-ops. func TestHintForDrainIncomplete(t *testing.T) { @@ -62,9 +59,12 @@ func TestHintForDrainIncomplete(t *testing.T) { []string{"drain --post", "ledger skips replies already posted"}, nil) } +// TestHintForPostSecretShaped proves the refusal's hint offers both ways out — +// strip the value from either draft, or publish it on purpose — without naming +// a file that only one verb writes, or anything that could be the value itself. func TestHintForPostSecretShaped(t *testing.T) { assertHintFragments(t, HintFor("post-secret-shaped"), "post-secret-shaped", - []string{"remove the value", "--allow-secret-values"}, + []string{"remove the value from the draft", "--allow-secret-values"}, []string{"AKIA", "ghp_", "sk-ant"}) } diff --git a/internal/core/testdata/hints.golden b/internal/core/testdata/hints.golden index b8d48b060..691931a8b 100644 --- a/internal/core/testdata/hints.golden +++ b/internal/core/testdata/hints.golden @@ -166,7 +166,7 @@ panel-stale try: re-run verification/dispatch.md against the current bundle head panel-too-large try: narrow the review or roster (100 findings, 4 verifiers maximum), then re-run panel partial-clone try: re-clone without --filter=blob:none, then re-run post-failed try: narrow anchor drift or body size (see above), then re-run -post-secret-shaped try: remove the value from review.json and re-run, or pass --allow-secret-values to publish it anyway +post-secret-shaped try: remove the value from the draft and re-run; post can pass --allow-secret-values to publish it anyway pr-not-open try: re-fetch the PR (bundle may be stale) pr-read-failed try: run 'gh auth status', confirm the repo/PR spelling, then re-run privacy-unavailable try: address the cause above, then re-run the same command From 6997477946ed32aa5a4bf9a16241442c23e73554 Mon Sep 17 00:00:00 2001 From: Sutu Sebastian Date: Tue, 17 Nov 2026 14:49:19 +0200 Subject: [PATCH 06/14] docs(skill): list drain in the skill --- bench/runner/testdata/tool-free-prompt.golden | 32 ++++++++++--------- .../fetch/testdata/author-advisory.golden | 8 ++--- internal/fetch/testdata/azure-happy.golden | 8 ++--- internal/fetch/testdata/base-sha-json.golden | 8 ++--- internal/fetch/testdata/base-sha-note.golden | 8 ++--- .../fetch/testdata/bitbucket-happy.golden | 8 ++--- .../fetch/testdata/bitbucket-paging.golden | 8 ++--- .../testdata/budget-over-consented.golden | 8 ++--- internal/fetch/testdata/budget-unknown.golden | 8 ++--- .../fetch/testdata/budget-unreadable.golden | 8 ++--- internal/fetch/testdata/budget-unset.golden | 8 ++--- internal/fetch/testdata/budget-within.golden | 8 ++--- .../testdata/cap-override-beats-chunk.golden | 8 ++--- internal/fetch/testdata/cap-override.golden | 8 ++--- .../testdata/controls-base-absent.golden | 8 ++--- internal/fetch/testdata/dump-json.golden | 8 ++--- internal/fetch/testdata/dump-text.golden | 8 ++--- internal/fetch/testdata/empty-diff.golden | 8 ++--- internal/fetch/testdata/file-paging.golden | 8 ++--- internal/fetch/testdata/forgejo-happy.golden | 8 ++--- .../fetch/testdata/gitcafe-base-note.golden | 8 ++--- internal/fetch/testdata/gitcafe-happy.golden | 8 ++--- .../fetch/testdata/gitlab-base-note.golden | 8 ++--- internal/fetch/testdata/gitlab-base.golden | 8 ++--- internal/fetch/testdata/gitlab-happy.golden | 8 ++--- internal/fetch/testdata/gitlab-text.golden | 8 ++--- internal/fetch/testdata/happy-json.golden | 8 ++--- internal/fetch/testdata/happy-text.golden | 8 ++--- internal/fetch/testdata/local-branch.golden | 8 ++--- .../fetch/testdata/local-dump-chunk.golden | 8 ++--- .../fetch/testdata/local-dump-text.golden | 8 ++--- internal/fetch/testdata/local-paths.golden | 8 ++--- internal/fetch/testdata/local-range.golden | 8 ++--- internal/fetch/testdata/local-range3.golden | 8 ++--- internal/fetch/testdata/local-staged.golden | 8 ++--- internal/fetch/testdata/local-stash.golden | 8 ++--- .../fetch/testdata/local-untracked.golden | 8 ++--- .../fetch/testdata/local-worktree-text.golden | 8 ++--- internal/fetch/testdata/local-worktree.golden | 8 ++--- .../fetch/testdata/over-cap-chunk-text.golden | 8 ++--- internal/fetch/testdata/over-cap-chunk.golden | 8 ++--- internal/fetch/testdata/over-cap-knob.golden | 8 ++--- .../fetch/testdata/ratelimit-retry.golden | 8 ++--- .../fetch/testdata/sensitive-kb-head.golden | 8 ++--- internal/fetch/testdata/sensitive-kb.golden | 8 ++--- internal/fetch/testdata/since-alias.golden | 8 ++--- .../fetch/testdata/threads-degraded.golden | 8 ++--- internal/provenance/prompts_test.go | 2 +- .../testdata/body/mermaid-stripped.golden | 2 +- .../record/testdata/body/non-ascii.golden | 2 +- .../testdata/body/receipt-collision.golden | 2 +- internal/record/testdata/chunk/drift.golden | 2 +- .../record/testdata/chunk/unattested.golden | 2 +- .../testdata/chunk/unknown-chunk-claim.golden | 2 +- internal/record/testdata/chunk/valid.golden | 2 +- .../verify-triage-resolved/rereview.golden | 2 +- .../testdata/degenerate/basis-bad.golden | 2 +- .../testdata/degenerate/basis-ok.golden | 2 +- .../degenerate/blob-link-local.golden | 2 +- .../testdata/degenerate/brief-valid.golden | 2 +- .../testdata/degenerate/carried-footer.golden | 2 +- .../degenerate/confidence-valid.golden | 2 +- .../degenerate/fenced-body-section.golden | 2 +- .../degenerate/missing-marker-ok.golden | 2 +- .../degenerate/normalized-fenced.golden | 2 +- .../degenerate/normalized-prose.golden | 2 +- .../degenerate/normalized-weak-shapes.golden | 2 +- .../incremental/non-touching/rereview.golden | 2 +- .../incremental/reopen/rereview.golden | 2 +- internal/record/testdata/kb/absent.golden | 2 +- .../record/testdata/kb/bad-id-shape.golden | 2 +- .../record/testdata/kb/bad-policy-env.golden | 2 +- internal/record/testdata/kb/bad-shape.golden | 2 +- .../record/testdata/kb/broken-store.golden | 2 +- .../testdata/kb/counter-adds/rereview.golden | 2 +- internal/record/testdata/kb/duplicate.golden | 2 +- internal/record/testdata/kb/empty.golden | 2 +- .../kb/false-positive/rereview.golden | 2 +- .../kb/joins-idempotent/rereview.golden | 2 +- internal/record/testdata/kb/no-store.golden | 2 +- internal/record/testdata/kb/null.golden | 2 +- internal/record/testdata/kb/retired.golden | 2 +- .../kb/string-counters/rereview.golden | 2 +- internal/record/testdata/kb/truncated.golden | 2 +- internal/record/testdata/kb/unknown.golden | 2 +- internal/record/testdata/kb/valid.golden | 2 +- .../record/testdata/matrix/n10/first.golden | 2 +- .../testdata/matrix/n10/rereview.golden | 2 +- .../record/testdata/matrix/n200/first.golden | 2 +- .../testdata/matrix/n200/rereview.golden | 2 +- .../record/testdata/matrix/n50/first.golden | 2 +- .../testdata/matrix/n50/rereview.golden | 2 +- .../testdata/overrides/dir-as-fragment.golden | 2 +- .../testdata/overrides/eq-threshold.golden | 2 +- .../record/testdata/overrides/valid.golden | 2 +- .../record/testdata/provider/gitlab.golden | 2 +- .../record/testdata/refuse/empty-prior.golden | 2 +- .../record/testdata/refuse/false-prior.golden | 2 +- .../refuse/invalid-utf8-review.golden | 2 +- .../record/testdata/refuse/null-prior.golden | 2 +- .../record/testdata/source/dirty-head.golden | 2 +- .../testdata/source/dirty-string.golden | 2 +- .../uncite/null-keeps/rereview.golden | 2 +- .../verify/contradict-exit/rereview.golden | 2 +- .../verify/contradict-timeout/rereview.golden | 2 +- .../verify/on-addressed/rereview.golden | 2 +- skills/verdict/SKILL.md | 32 ++++++++++--------- 107 files changed, 277 insertions(+), 273 deletions(-) diff --git a/bench/runner/testdata/tool-free-prompt.golden b/bench/runner/testdata/tool-free-prompt.golden index 07665ef2d..d13bda79e 100644 --- a/bench/runner/testdata/tool-free-prompt.golden +++ b/bench/runner/testdata/tool-free-prompt.golden @@ -105,10 +105,11 @@ after 3 rounds, stop and report them rather than recording a partial review. PR fetch for posting. Downstream verbs address the bundle as `local-work`. Never call `triage` — propose status changes via `triage[]` in `review.json`. -The operator's own reads between runs: `triage` (status changes), `report` -(ranked read), `threads` (refresh the PR conversation feed), `calibrate` -(predictions vs ground truth), and `fix` (one bounded verify-gated pass over a -local bundle — prints the finding plus land instructions). +The operator's own verbs between runs: `triage` (status changes), `report` +(ranked read), `threads` (refresh the PR conversation feed), `drain` (plan and +post replies to waiting threads), `calibrate` (predictions vs ground truth), and +`fix` (one bounded verify-gated pass over a local bundle — prints the finding +plus land instructions). Delta re-review: `verdict fetch owner/repo 123 --base-sha `, then load `prompts/incremental-review.md` instead of `prompts/review.md`. @@ -117,17 +118,18 @@ and you fall back to the full diff. ## Mode router -| Ask | Load | Terminal write | -| ------------------------------------------ | ------------------------------------------ | -------------------------------------------------------- | -| Review a PR | `prompts/review.md` | one review | -| Review local changes (no PR) | `prompts/review.md` + `source.json` bundle | `record`, then `report` — never `post` | -| New commits landed | `prompts/incremental-review.md` | one review OR no-review note | -| Address review threads | `prompts/address-reviews.md` | commit/push + one reply per thread | -| Fix failing CI | `prompts/fix-ci.md` | commit/push + summary | -| Implement / build | `prompts/build.md` | commit/push + PR link | -| Draft a review report without posting | `prompts/ci.md` | report markdown file, no post | -| Grade closed findings (self-grading probe) | `prompts/grade.md` | grade rows + agent judgments (additive) + agreement rate | -| Anything else | `prompts/system.md` + task text | summary stdout | +| Ask | Load | Terminal write | +| ------------------------------------------ | ------------------------------------------ | --------------------------------------------------------------- | +| Review a PR | `prompts/review.md` | one review | +| Review local changes (no PR) | `prompts/review.md` + `source.json` bundle | `record`, then `report` — never `post` | +| New commits landed | `prompts/incremental-review.md` | one review OR no-review note | +| Address review threads | `prompts/address-reviews.md` | commit/push + one reply per thread; reply-only passes use drain | +| Answer pending review-thread replies | `prompts/address-reviews.md` | `verdict drain owner/repo N --agent --post` | +| Fix failing CI | `prompts/fix-ci.md` | commit/push + summary | +| Implement / build | `prompts/build.md` | commit/push + PR link | +| Draft a review report without posting | `prompts/ci.md` | report markdown file, no post | +| Grade closed findings (self-grading probe) | `prompts/grade.md` | grade rows + agent judgments (additive) + agreement rate | +| Anything else | `prompts/system.md` + task text | summary stdout | `prompts/system.md` loads on every run. `prompts/reviewer-subagent.md` is the contract for lens subagents the Review modes dispatch — the orchestrator reads it diff --git a/internal/fetch/testdata/author-advisory.golden b/internal/fetch/testdata/author-advisory.golden index 4a9fb19ff..25c16dfda 100644 --- a/internal/fetch/testdata/author-advisory.golden +++ b/internal/fetch/testdata/author-advisory.golden @@ -353,15 +353,15 @@ rather than becoming ground truth. --- file C/.verdict/state/4701/provenance.json --- { "schema_version": "1", - "run_id": "7a1a93cded7af0dc99109adce92a216add66378c13e99f5d338eac2917e9250c", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "run_id": "b92fcd70224a6d7cf8873a8048f49b2b097717289341d5a65b37fe9b7fef74ae", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "inputs": [ { "kind": "prompt", "name": "SKILL.md", "status": "included", - "sha256": "56a5922897f1def73b571fd871ce3ea65798e595f54952aec380496e785797cb", - "bytes": 13140 + "sha256": "6e55c5ebee9a13a25b8e95e9249ec909d7e92b6bfbcf6e3a2fb7a5c6236be01c", + "bytes": 13427 }, { "kind": "prompt", diff --git a/internal/fetch/testdata/azure-happy.golden b/internal/fetch/testdata/azure-happy.golden index 242e55283..cb1368501 100644 --- a/internal/fetch/testdata/azure-happy.golden +++ b/internal/fetch/testdata/azure-happy.golden @@ -342,15 +342,15 @@ rather than becoming ground truth. --- file C/.verdict/state/4716/provenance.json --- { "schema_version": "1", - "run_id": "f4c545289fd4ba70c4e7b61870b153850b8832299464d6e627cff80ecda50eb9", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "run_id": "82fbe2b2bad3956ea640a5d7cf4a5c2312146d8802137b600d0baf7dedd2b28c", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "inputs": [ { "kind": "prompt", "name": "SKILL.md", "status": "included", - "sha256": "56a5922897f1def73b571fd871ce3ea65798e595f54952aec380496e785797cb", - "bytes": 13140 + "sha256": "6e55c5ebee9a13a25b8e95e9249ec909d7e92b6bfbcf6e3a2fb7a5c6236be01c", + "bytes": 13427 }, { "kind": "prompt", diff --git a/internal/fetch/testdata/base-sha-json.golden b/internal/fetch/testdata/base-sha-json.golden index 55c91458c..4e9786581 100644 --- a/internal/fetch/testdata/base-sha-json.golden +++ b/internal/fetch/testdata/base-sha-json.golden @@ -338,15 +338,15 @@ rather than becoming ground truth. --- file C/.verdict/state/4701/provenance.json --- { "schema_version": "1", - "run_id": "7a1a93cded7af0dc99109adce92a216add66378c13e99f5d338eac2917e9250c", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "run_id": "b92fcd70224a6d7cf8873a8048f49b2b097717289341d5a65b37fe9b7fef74ae", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "inputs": [ { "kind": "prompt", "name": "SKILL.md", "status": "included", - "sha256": "56a5922897f1def73b571fd871ce3ea65798e595f54952aec380496e785797cb", - "bytes": 13140 + "sha256": "6e55c5ebee9a13a25b8e95e9249ec909d7e92b6bfbcf6e3a2fb7a5c6236be01c", + "bytes": 13427 }, { "kind": "prompt", diff --git a/internal/fetch/testdata/base-sha-note.golden b/internal/fetch/testdata/base-sha-note.golden index c054087e2..9dc25b62c 100644 --- a/internal/fetch/testdata/base-sha-note.golden +++ b/internal/fetch/testdata/base-sha-note.golden @@ -331,15 +331,15 @@ rather than becoming ground truth. --- file C/.verdict/state/4701/provenance.json --- { "schema_version": "1", - "run_id": "7a1a93cded7af0dc99109adce92a216add66378c13e99f5d338eac2917e9250c", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "run_id": "b92fcd70224a6d7cf8873a8048f49b2b097717289341d5a65b37fe9b7fef74ae", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "inputs": [ { "kind": "prompt", "name": "SKILL.md", "status": "included", - "sha256": "56a5922897f1def73b571fd871ce3ea65798e595f54952aec380496e785797cb", - "bytes": 13140 + "sha256": "6e55c5ebee9a13a25b8e95e9249ec909d7e92b6bfbcf6e3a2fb7a5c6236be01c", + "bytes": 13427 }, { "kind": "prompt", diff --git a/internal/fetch/testdata/bitbucket-happy.golden b/internal/fetch/testdata/bitbucket-happy.golden index 78e11e10f..b2acb51c8 100644 --- a/internal/fetch/testdata/bitbucket-happy.golden +++ b/internal/fetch/testdata/bitbucket-happy.golden @@ -339,15 +339,15 @@ rather than becoming ground truth. --- file C/.verdict/state/4709/provenance.json --- { "schema_version": "1", - "run_id": "b65eb341dedec4d7370ef863b1111136f0b1722496315a62cc36c7b23daeecaa", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "run_id": "b26648cf76a4851ca1281834475590591cbad411a22432f632fd910a58dde6fd", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "inputs": [ { "kind": "prompt", "name": "SKILL.md", "status": "included", - "sha256": "56a5922897f1def73b571fd871ce3ea65798e595f54952aec380496e785797cb", - "bytes": 13140 + "sha256": "6e55c5ebee9a13a25b8e95e9249ec909d7e92b6bfbcf6e3a2fb7a5c6236be01c", + "bytes": 13427 }, { "kind": "prompt", diff --git a/internal/fetch/testdata/bitbucket-paging.golden b/internal/fetch/testdata/bitbucket-paging.golden index adc6acb84..0b6779278 100644 --- a/internal/fetch/testdata/bitbucket-paging.golden +++ b/internal/fetch/testdata/bitbucket-paging.golden @@ -333,15 +333,15 @@ rather than becoming ground truth. --- file C/.verdict/state/4717/provenance.json --- { "schema_version": "1", - "run_id": "ff0a9a58a6d123373d59520b8ea6826051ceaf6d4092d32f1793c69bd32e309f", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "run_id": "2ab4bd8d49a1d7bc14d8609a030bca10edb77393fb2ab2a5cf0cc0740d9d9801", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "inputs": [ { "kind": "prompt", "name": "SKILL.md", "status": "included", - "sha256": "56a5922897f1def73b571fd871ce3ea65798e595f54952aec380496e785797cb", - "bytes": 13140 + "sha256": "6e55c5ebee9a13a25b8e95e9249ec909d7e92b6bfbcf6e3a2fb7a5c6236be01c", + "bytes": 13427 }, { "kind": "prompt", diff --git a/internal/fetch/testdata/budget-over-consented.golden b/internal/fetch/testdata/budget-over-consented.golden index 745e4fd1a..82be3374a 100644 --- a/internal/fetch/testdata/budget-over-consented.golden +++ b/internal/fetch/testdata/budget-over-consented.golden @@ -340,15 +340,15 @@ rather than becoming ground truth. --- file C/.verdict/state/4705/provenance.json --- { "schema_version": "1", - "run_id": "c6171058407add885e1491fffd27e9b5a3848198f566fa6ade3f732b76aeb9ad", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "run_id": "b52de828f9ea0c89804103e85d5d0cc541294a69467ef2774ac3a9836edb7d30", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "inputs": [ { "kind": "prompt", "name": "SKILL.md", "status": "included", - "sha256": "56a5922897f1def73b571fd871ce3ea65798e595f54952aec380496e785797cb", - "bytes": 13140 + "sha256": "6e55c5ebee9a13a25b8e95e9249ec909d7e92b6bfbcf6e3a2fb7a5c6236be01c", + "bytes": 13427 }, { "kind": "prompt", diff --git a/internal/fetch/testdata/budget-unknown.golden b/internal/fetch/testdata/budget-unknown.golden index 2c8edb523..13ec977b0 100644 --- a/internal/fetch/testdata/budget-unknown.golden +++ b/internal/fetch/testdata/budget-unknown.golden @@ -329,15 +329,15 @@ rather than becoming ground truth. --- file C/.verdict/state/4705/provenance.json --- { "schema_version": "1", - "run_id": "c6171058407add885e1491fffd27e9b5a3848198f566fa6ade3f732b76aeb9ad", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "run_id": "b52de828f9ea0c89804103e85d5d0cc541294a69467ef2774ac3a9836edb7d30", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "inputs": [ { "kind": "prompt", "name": "SKILL.md", "status": "included", - "sha256": "56a5922897f1def73b571fd871ce3ea65798e595f54952aec380496e785797cb", - "bytes": 13140 + "sha256": "6e55c5ebee9a13a25b8e95e9249ec909d7e92b6bfbcf6e3a2fb7a5c6236be01c", + "bytes": 13427 }, { "kind": "prompt", diff --git a/internal/fetch/testdata/budget-unreadable.golden b/internal/fetch/testdata/budget-unreadable.golden index 9394964d6..b28eb0dd0 100644 --- a/internal/fetch/testdata/budget-unreadable.golden +++ b/internal/fetch/testdata/budget-unreadable.golden @@ -332,15 +332,15 @@ rather than becoming ground truth. --- file C/.verdict/state/4705/provenance.json --- { "schema_version": "1", - "run_id": "c6171058407add885e1491fffd27e9b5a3848198f566fa6ade3f732b76aeb9ad", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "run_id": "b52de828f9ea0c89804103e85d5d0cc541294a69467ef2774ac3a9836edb7d30", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "inputs": [ { "kind": "prompt", "name": "SKILL.md", "status": "included", - "sha256": "56a5922897f1def73b571fd871ce3ea65798e595f54952aec380496e785797cb", - "bytes": 13140 + "sha256": "6e55c5ebee9a13a25b8e95e9249ec909d7e92b6bfbcf6e3a2fb7a5c6236be01c", + "bytes": 13427 }, { "kind": "prompt", diff --git a/internal/fetch/testdata/budget-unset.golden b/internal/fetch/testdata/budget-unset.golden index b35108d04..47a9b518e 100644 --- a/internal/fetch/testdata/budget-unset.golden +++ b/internal/fetch/testdata/budget-unset.golden @@ -324,15 +324,15 @@ rather than becoming ground truth. --- file C/.verdict/state/4705/provenance.json --- { "schema_version": "1", - "run_id": "7a1a93cded7af0dc99109adce92a216add66378c13e99f5d338eac2917e9250c", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "run_id": "b92fcd70224a6d7cf8873a8048f49b2b097717289341d5a65b37fe9b7fef74ae", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "inputs": [ { "kind": "prompt", "name": "SKILL.md", "status": "included", - "sha256": "56a5922897f1def73b571fd871ce3ea65798e595f54952aec380496e785797cb", - "bytes": 13140 + "sha256": "6e55c5ebee9a13a25b8e95e9249ec909d7e92b6bfbcf6e3a2fb7a5c6236be01c", + "bytes": 13427 }, { "kind": "prompt", diff --git a/internal/fetch/testdata/budget-within.golden b/internal/fetch/testdata/budget-within.golden index db47ce4a3..7e7e7861a 100644 --- a/internal/fetch/testdata/budget-within.golden +++ b/internal/fetch/testdata/budget-within.golden @@ -329,15 +329,15 @@ rather than becoming ground truth. --- file C/.verdict/state/4705/provenance.json --- { "schema_version": "1", - "run_id": "c6171058407add885e1491fffd27e9b5a3848198f566fa6ade3f732b76aeb9ad", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "run_id": "b52de828f9ea0c89804103e85d5d0cc541294a69467ef2774ac3a9836edb7d30", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "inputs": [ { "kind": "prompt", "name": "SKILL.md", "status": "included", - "sha256": "56a5922897f1def73b571fd871ce3ea65798e595f54952aec380496e785797cb", - "bytes": 13140 + "sha256": "6e55c5ebee9a13a25b8e95e9249ec909d7e92b6bfbcf6e3a2fb7a5c6236be01c", + "bytes": 13427 }, { "kind": "prompt", diff --git a/internal/fetch/testdata/cap-override-beats-chunk.golden b/internal/fetch/testdata/cap-override-beats-chunk.golden index 8ddb6b826..71e370755 100644 --- a/internal/fetch/testdata/cap-override-beats-chunk.golden +++ b/internal/fetch/testdata/cap-override-beats-chunk.golden @@ -351,15 +351,15 @@ rather than becoming ground truth. --- file C/.verdict/state/4703/provenance.json --- { "schema_version": "1", - "run_id": "d92f3e34fcf3e7c903a7827906103ee92f226de0618e031c3f3930220ff71044", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "run_id": "9fb68b4c21b04e347a00a6ddb1fb10abb1be781ecd3b4b18ff1a863b796120f7", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "inputs": [ { "kind": "prompt", "name": "SKILL.md", "status": "included", - "sha256": "56a5922897f1def73b571fd871ce3ea65798e595f54952aec380496e785797cb", - "bytes": 13140 + "sha256": "6e55c5ebee9a13a25b8e95e9249ec909d7e92b6bfbcf6e3a2fb7a5c6236be01c", + "bytes": 13427 }, { "kind": "prompt", diff --git a/internal/fetch/testdata/cap-override.golden b/internal/fetch/testdata/cap-override.golden index 50b4b8a11..ed6feec05 100644 --- a/internal/fetch/testdata/cap-override.golden +++ b/internal/fetch/testdata/cap-override.golden @@ -351,15 +351,15 @@ rather than becoming ground truth. --- file C/.verdict/state/4703/provenance.json --- { "schema_version": "1", - "run_id": "e14100d648b08df11d8e233141ae4b90d5958fdb5125cfccfc46924bcb8469cc", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "run_id": "0ab1af20be72625c4b192b514cf0f2d753aa1d03820c013b08ae67733fd2baec", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "inputs": [ { "kind": "prompt", "name": "SKILL.md", "status": "included", - "sha256": "56a5922897f1def73b571fd871ce3ea65798e595f54952aec380496e785797cb", - "bytes": 13140 + "sha256": "6e55c5ebee9a13a25b8e95e9249ec909d7e92b6bfbcf6e3a2fb7a5c6236be01c", + "bytes": 13427 }, { "kind": "prompt", diff --git a/internal/fetch/testdata/controls-base-absent.golden b/internal/fetch/testdata/controls-base-absent.golden index c2b3013fd..bb179dfb6 100644 --- a/internal/fetch/testdata/controls-base-absent.golden +++ b/internal/fetch/testdata/controls-base-absent.golden @@ -345,8 +345,8 @@ api-base-panel --- file C/.verdict/state/4701/provenance.json --- { "schema_version": "1", - "run_id": "6dd40b6bffd9e761cd4441d29e7f17d296927547a1b4c05c08d3127b2b74154b", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "run_id": "dfa3b141ee2ca4c6163c4b03f00cea0e03aeb0c25e960a99d1bf45ae63a6aa14", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "panel": [ "api-base-panel" ], @@ -355,8 +355,8 @@ api-base-panel "kind": "prompt", "name": "SKILL.md", "status": "included", - "sha256": "56a5922897f1def73b571fd871ce3ea65798e595f54952aec380496e785797cb", - "bytes": 13140 + "sha256": "6e55c5ebee9a13a25b8e95e9249ec909d7e92b6bfbcf6e3a2fb7a5c6236be01c", + "bytes": 13427 }, { "kind": "prompt", diff --git a/internal/fetch/testdata/dump-json.golden b/internal/fetch/testdata/dump-json.golden index b66f9c48d..77b3e2870 100644 --- a/internal/fetch/testdata/dump-json.golden +++ b/internal/fetch/testdata/dump-json.golden @@ -325,15 +325,15 @@ rather than becoming ground truth. --- file C/.verdict/state/4702/provenance.json --- { "schema_version": "1", - "run_id": "7a1a93cded7af0dc99109adce92a216add66378c13e99f5d338eac2917e9250c", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "run_id": "b92fcd70224a6d7cf8873a8048f49b2b097717289341d5a65b37fe9b7fef74ae", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "inputs": [ { "kind": "prompt", "name": "SKILL.md", "status": "included", - "sha256": "56a5922897f1def73b571fd871ce3ea65798e595f54952aec380496e785797cb", - "bytes": 13140 + "sha256": "6e55c5ebee9a13a25b8e95e9249ec909d7e92b6bfbcf6e3a2fb7a5c6236be01c", + "bytes": 13427 }, { "kind": "prompt", diff --git a/internal/fetch/testdata/dump-text.golden b/internal/fetch/testdata/dump-text.golden index af78b2649..59084d856 100644 --- a/internal/fetch/testdata/dump-text.golden +++ b/internal/fetch/testdata/dump-text.golden @@ -385,15 +385,15 @@ rather than becoming ground truth. --- file C/.verdict/state/4702/provenance.json --- { "schema_version": "1", - "run_id": "7a1a93cded7af0dc99109adce92a216add66378c13e99f5d338eac2917e9250c", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "run_id": "b92fcd70224a6d7cf8873a8048f49b2b097717289341d5a65b37fe9b7fef74ae", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "inputs": [ { "kind": "prompt", "name": "SKILL.md", "status": "included", - "sha256": "56a5922897f1def73b571fd871ce3ea65798e595f54952aec380496e785797cb", - "bytes": 13140 + "sha256": "6e55c5ebee9a13a25b8e95e9249ec909d7e92b6bfbcf6e3a2fb7a5c6236be01c", + "bytes": 13427 }, { "kind": "prompt", diff --git a/internal/fetch/testdata/empty-diff.golden b/internal/fetch/testdata/empty-diff.golden index be1e55350..73ee8857c 100644 --- a/internal/fetch/testdata/empty-diff.golden +++ b/internal/fetch/testdata/empty-diff.golden @@ -306,15 +306,15 @@ rather than becoming ground truth. --- file C/.verdict/state/4701/provenance.json --- { "schema_version": "1", - "run_id": "290f9d069a01c0cd10139dfcb90362e9ab939b0167c22670c429dffa686ffd18", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "run_id": "a86b8a3b36881bd2e5dce391d9d2ab280eabc3d2fc78c0861ccc14cf7d97489f", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "inputs": [ { "kind": "prompt", "name": "SKILL.md", "status": "included", - "sha256": "56a5922897f1def73b571fd871ce3ea65798e595f54952aec380496e785797cb", - "bytes": 13140 + "sha256": "6e55c5ebee9a13a25b8e95e9249ec909d7e92b6bfbcf6e3a2fb7a5c6236be01c", + "bytes": 13427 }, { "kind": "prompt", diff --git a/internal/fetch/testdata/file-paging.golden b/internal/fetch/testdata/file-paging.golden index 74ca467a4..8f93f7882 100644 --- a/internal/fetch/testdata/file-paging.golden +++ b/internal/fetch/testdata/file-paging.golden @@ -334,15 +334,15 @@ rather than becoming ground truth. --- file C/.verdict/state/4712/provenance.json --- { "schema_version": "1", - "run_id": "a2a94a715e35b7e0395be7c004b041f73e89ac69ece0613efbca3b871ee5d916", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "run_id": "67a25e325f88bf10adc34a50df0713066ed568fda46ae7621bc2fdd6308c5e4c", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "inputs": [ { "kind": "prompt", "name": "SKILL.md", "status": "included", - "sha256": "56a5922897f1def73b571fd871ce3ea65798e595f54952aec380496e785797cb", - "bytes": 13140 + "sha256": "6e55c5ebee9a13a25b8e95e9249ec909d7e92b6bfbcf6e3a2fb7a5c6236be01c", + "bytes": 13427 }, { "kind": "prompt", diff --git a/internal/fetch/testdata/forgejo-happy.golden b/internal/fetch/testdata/forgejo-happy.golden index 3ab7fa801..6c9722728 100644 --- a/internal/fetch/testdata/forgejo-happy.golden +++ b/internal/fetch/testdata/forgejo-happy.golden @@ -337,15 +337,15 @@ rather than becoming ground truth. --- file C/.verdict/state/4708/provenance.json --- { "schema_version": "1", - "run_id": "b65eb341dedec4d7370ef863b1111136f0b1722496315a62cc36c7b23daeecaa", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "run_id": "b26648cf76a4851ca1281834475590591cbad411a22432f632fd910a58dde6fd", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "inputs": [ { "kind": "prompt", "name": "SKILL.md", "status": "included", - "sha256": "56a5922897f1def73b571fd871ce3ea65798e595f54952aec380496e785797cb", - "bytes": 13140 + "sha256": "6e55c5ebee9a13a25b8e95e9249ec909d7e92b6bfbcf6e3a2fb7a5c6236be01c", + "bytes": 13427 }, { "kind": "prompt", diff --git a/internal/fetch/testdata/gitcafe-base-note.golden b/internal/fetch/testdata/gitcafe-base-note.golden index d96a53a20..c42f74b6a 100644 --- a/internal/fetch/testdata/gitcafe-base-note.golden +++ b/internal/fetch/testdata/gitcafe-base-note.golden @@ -322,15 +322,15 @@ rather than becoming ground truth. --- file C/.verdict/state/4707/provenance.json --- { "schema_version": "1", - "run_id": "3cdf3183329dfbded68b26d4303f20a206d8c802b7eb0d8c11f1de9a3229ff56", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "run_id": "d239480a0331f63a9f075eea0d2d6b32f6d065c53f6d5bc8e7a5979b78f39830", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "inputs": [ { "kind": "prompt", "name": "SKILL.md", "status": "included", - "sha256": "56a5922897f1def73b571fd871ce3ea65798e595f54952aec380496e785797cb", - "bytes": 13140 + "sha256": "6e55c5ebee9a13a25b8e95e9249ec909d7e92b6bfbcf6e3a2fb7a5c6236be01c", + "bytes": 13427 }, { "kind": "prompt", diff --git a/internal/fetch/testdata/gitcafe-happy.golden b/internal/fetch/testdata/gitcafe-happy.golden index 8a030b708..7185af178 100644 --- a/internal/fetch/testdata/gitcafe-happy.golden +++ b/internal/fetch/testdata/gitcafe-happy.golden @@ -319,15 +319,15 @@ rather than becoming ground truth. --- file C/.verdict/state/4707/provenance.json --- { "schema_version": "1", - "run_id": "3cdf3183329dfbded68b26d4303f20a206d8c802b7eb0d8c11f1de9a3229ff56", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "run_id": "d239480a0331f63a9f075eea0d2d6b32f6d065c53f6d5bc8e7a5979b78f39830", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "inputs": [ { "kind": "prompt", "name": "SKILL.md", "status": "included", - "sha256": "56a5922897f1def73b571fd871ce3ea65798e595f54952aec380496e785797cb", - "bytes": 13140 + "sha256": "6e55c5ebee9a13a25b8e95e9249ec909d7e92b6bfbcf6e3a2fb7a5c6236be01c", + "bytes": 13427 }, { "kind": "prompt", diff --git a/internal/fetch/testdata/gitlab-base-note.golden b/internal/fetch/testdata/gitlab-base-note.golden index 270ef6c09..c13a786f6 100644 --- a/internal/fetch/testdata/gitlab-base-note.golden +++ b/internal/fetch/testdata/gitlab-base-note.golden @@ -322,15 +322,15 @@ rather than becoming ground truth. --- file C/.verdict/state/4706/provenance.json --- { "schema_version": "1", - "run_id": "b65eb341dedec4d7370ef863b1111136f0b1722496315a62cc36c7b23daeecaa", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "run_id": "b26648cf76a4851ca1281834475590591cbad411a22432f632fd910a58dde6fd", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "inputs": [ { "kind": "prompt", "name": "SKILL.md", "status": "included", - "sha256": "56a5922897f1def73b571fd871ce3ea65798e595f54952aec380496e785797cb", - "bytes": 13140 + "sha256": "6e55c5ebee9a13a25b8e95e9249ec909d7e92b6bfbcf6e3a2fb7a5c6236be01c", + "bytes": 13427 }, { "kind": "prompt", diff --git a/internal/fetch/testdata/gitlab-base.golden b/internal/fetch/testdata/gitlab-base.golden index eb8aaaa95..6fce42aed 100644 --- a/internal/fetch/testdata/gitlab-base.golden +++ b/internal/fetch/testdata/gitlab-base.golden @@ -324,15 +324,15 @@ rather than becoming ground truth. --- file C/.verdict/state/4706/provenance.json --- { "schema_version": "1", - "run_id": "b65eb341dedec4d7370ef863b1111136f0b1722496315a62cc36c7b23daeecaa", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "run_id": "b26648cf76a4851ca1281834475590591cbad411a22432f632fd910a58dde6fd", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "inputs": [ { "kind": "prompt", "name": "SKILL.md", "status": "included", - "sha256": "56a5922897f1def73b571fd871ce3ea65798e595f54952aec380496e785797cb", - "bytes": 13140 + "sha256": "6e55c5ebee9a13a25b8e95e9249ec909d7e92b6bfbcf6e3a2fb7a5c6236be01c", + "bytes": 13427 }, { "kind": "prompt", diff --git a/internal/fetch/testdata/gitlab-happy.golden b/internal/fetch/testdata/gitlab-happy.golden index f3d2727f0..c6bb0c47b 100644 --- a/internal/fetch/testdata/gitlab-happy.golden +++ b/internal/fetch/testdata/gitlab-happy.golden @@ -315,15 +315,15 @@ rather than becoming ground truth. --- file C/.verdict/state/4706/provenance.json --- { "schema_version": "1", - "run_id": "b65eb341dedec4d7370ef863b1111136f0b1722496315a62cc36c7b23daeecaa", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "run_id": "b26648cf76a4851ca1281834475590591cbad411a22432f632fd910a58dde6fd", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "inputs": [ { "kind": "prompt", "name": "SKILL.md", "status": "included", - "sha256": "56a5922897f1def73b571fd871ce3ea65798e595f54952aec380496e785797cb", - "bytes": 13140 + "sha256": "6e55c5ebee9a13a25b8e95e9249ec909d7e92b6bfbcf6e3a2fb7a5c6236be01c", + "bytes": 13427 }, { "kind": "prompt", diff --git a/internal/fetch/testdata/gitlab-text.golden b/internal/fetch/testdata/gitlab-text.golden index a76fa233d..fac2569c3 100644 --- a/internal/fetch/testdata/gitlab-text.golden +++ b/internal/fetch/testdata/gitlab-text.golden @@ -251,15 +251,15 @@ rather than becoming ground truth. --- file C/.verdict/state/4706/provenance.json --- { "schema_version": "1", - "run_id": "b65eb341dedec4d7370ef863b1111136f0b1722496315a62cc36c7b23daeecaa", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "run_id": "b26648cf76a4851ca1281834475590591cbad411a22432f632fd910a58dde6fd", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "inputs": [ { "kind": "prompt", "name": "SKILL.md", "status": "included", - "sha256": "56a5922897f1def73b571fd871ce3ea65798e595f54952aec380496e785797cb", - "bytes": 13140 + "sha256": "6e55c5ebee9a13a25b8e95e9249ec909d7e92b6bfbcf6e3a2fb7a5c6236be01c", + "bytes": 13427 }, { "kind": "prompt", diff --git a/internal/fetch/testdata/happy-json.golden b/internal/fetch/testdata/happy-json.golden index 16d0c4183..73e7b35ce 100644 --- a/internal/fetch/testdata/happy-json.golden +++ b/internal/fetch/testdata/happy-json.golden @@ -324,15 +324,15 @@ rather than becoming ground truth. --- file C/.verdict/state/4701/provenance.json --- { "schema_version": "1", - "run_id": "7a1a93cded7af0dc99109adce92a216add66378c13e99f5d338eac2917e9250c", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "run_id": "b92fcd70224a6d7cf8873a8048f49b2b097717289341d5a65b37fe9b7fef74ae", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "inputs": [ { "kind": "prompt", "name": "SKILL.md", "status": "included", - "sha256": "56a5922897f1def73b571fd871ce3ea65798e595f54952aec380496e785797cb", - "bytes": 13140 + "sha256": "6e55c5ebee9a13a25b8e95e9249ec909d7e92b6bfbcf6e3a2fb7a5c6236be01c", + "bytes": 13427 }, { "kind": "prompt", diff --git a/internal/fetch/testdata/happy-text.golden b/internal/fetch/testdata/happy-text.golden index d1efe0b5f..0f036bbf5 100644 --- a/internal/fetch/testdata/happy-text.golden +++ b/internal/fetch/testdata/happy-text.golden @@ -262,15 +262,15 @@ rather than becoming ground truth. --- file C/.verdict/state/4701/provenance.json --- { "schema_version": "1", - "run_id": "7a1a93cded7af0dc99109adce92a216add66378c13e99f5d338eac2917e9250c", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "run_id": "b92fcd70224a6d7cf8873a8048f49b2b097717289341d5a65b37fe9b7fef74ae", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "inputs": [ { "kind": "prompt", "name": "SKILL.md", "status": "included", - "sha256": "56a5922897f1def73b571fd871ce3ea65798e595f54952aec380496e785797cb", - "bytes": 13140 + "sha256": "6e55c5ebee9a13a25b8e95e9249ec909d7e92b6bfbcf6e3a2fb7a5c6236be01c", + "bytes": 13427 }, { "kind": "prompt", diff --git a/internal/fetch/testdata/local-branch.golden b/internal/fetch/testdata/local-branch.golden index 7e5ae9c95..e8bca3f2d 100644 --- a/internal/fetch/testdata/local-branch.golden +++ b/internal/fetch/testdata/local-branch.golden @@ -258,15 +258,15 @@ rather than becoming ground truth. --- file C/.verdict/state/local-demo/provenance.json --- { "schema_version": "1", - "run_id": "1c8bc1ada0f2272fc8cd3a846678b6e26b0816aa6da67cdd7f285b46c6846642", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "run_id": "ed528457edb2575b2c63211a347f7c973b2fce99a8db6f405f2207ab38d27818", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "inputs": [ { "kind": "prompt", "name": "SKILL.md", "status": "included", - "sha256": "56a5922897f1def73b571fd871ce3ea65798e595f54952aec380496e785797cb", - "bytes": 13140 + "sha256": "6e55c5ebee9a13a25b8e95e9249ec909d7e92b6bfbcf6e3a2fb7a5c6236be01c", + "bytes": 13427 }, { "kind": "prompt", diff --git a/internal/fetch/testdata/local-dump-chunk.golden b/internal/fetch/testdata/local-dump-chunk.golden index 5c4504ecd..d6a406530 100644 --- a/internal/fetch/testdata/local-dump-chunk.golden +++ b/internal/fetch/testdata/local-dump-chunk.golden @@ -303,15 +303,15 @@ rather than becoming ground truth. --- file C/.verdict/state/local-demo/provenance.json --- { "schema_version": "1", - "run_id": "7def631b841a7c0c72fe5db0debf9111c850b75be50bae11fa833b5883461a16", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "run_id": "e63b52012a7ac25dba47c6efd0e2a83f5adaf303a8498007831a751dc3d493c8", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "inputs": [ { "kind": "prompt", "name": "SKILL.md", "status": "included", - "sha256": "56a5922897f1def73b571fd871ce3ea65798e595f54952aec380496e785797cb", - "bytes": 13140 + "sha256": "6e55c5ebee9a13a25b8e95e9249ec909d7e92b6bfbcf6e3a2fb7a5c6236be01c", + "bytes": 13427 }, { "kind": "prompt", diff --git a/internal/fetch/testdata/local-dump-text.golden b/internal/fetch/testdata/local-dump-text.golden index dc8170cf7..518cff772 100644 --- a/internal/fetch/testdata/local-dump-text.golden +++ b/internal/fetch/testdata/local-dump-text.golden @@ -338,15 +338,15 @@ rather than becoming ground truth. --- file C/.verdict/state/local-demo/provenance.json --- { "schema_version": "1", - "run_id": "75cf79061c0168cc97afce6debae845058cf16ce82dfbe7bc3d4f78ca79f39d4", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "run_id": "e86878662bcba478fd4a1177e65c540ac95d46eb560023a7482eaf2e9e53c2ad", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "inputs": [ { "kind": "prompt", "name": "SKILL.md", "status": "included", - "sha256": "56a5922897f1def73b571fd871ce3ea65798e595f54952aec380496e785797cb", - "bytes": 13140 + "sha256": "6e55c5ebee9a13a25b8e95e9249ec909d7e92b6bfbcf6e3a2fb7a5c6236be01c", + "bytes": 13427 }, { "kind": "prompt", diff --git a/internal/fetch/testdata/local-paths.golden b/internal/fetch/testdata/local-paths.golden index f16d1a9ac..82a4b46fd 100644 --- a/internal/fetch/testdata/local-paths.golden +++ b/internal/fetch/testdata/local-paths.golden @@ -258,15 +258,15 @@ rather than becoming ground truth. --- file C/.verdict/state/local-demo/provenance.json --- { "schema_version": "1", - "run_id": "30c0dff3ea189951913069ef3deda0550eda0d8b71525da659d2c801db917e0c", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "run_id": "c5b985c25d5cf23cc9920020fa8225de67116fcdad0cf782400ae5944e56d595", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "inputs": [ { "kind": "prompt", "name": "SKILL.md", "status": "included", - "sha256": "56a5922897f1def73b571fd871ce3ea65798e595f54952aec380496e785797cb", - "bytes": 13140 + "sha256": "6e55c5ebee9a13a25b8e95e9249ec909d7e92b6bfbcf6e3a2fb7a5c6236be01c", + "bytes": 13427 }, { "kind": "prompt", diff --git a/internal/fetch/testdata/local-range.golden b/internal/fetch/testdata/local-range.golden index 9e66db5eb..d23bbe5b5 100644 --- a/internal/fetch/testdata/local-range.golden +++ b/internal/fetch/testdata/local-range.golden @@ -258,15 +258,15 @@ rather than becoming ground truth. --- file C/.verdict/state/local-demo/provenance.json --- { "schema_version": "1", - "run_id": "ea7a41cb80be2eda568016ae7204fb0415e95977cbadf046cfcac7121867c862", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "run_id": "fd2322d34fb5b4266be1b08b591c0b5ce3c4bfe4456cc859aede766649d49329", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "inputs": [ { "kind": "prompt", "name": "SKILL.md", "status": "included", - "sha256": "56a5922897f1def73b571fd871ce3ea65798e595f54952aec380496e785797cb", - "bytes": 13140 + "sha256": "6e55c5ebee9a13a25b8e95e9249ec909d7e92b6bfbcf6e3a2fb7a5c6236be01c", + "bytes": 13427 }, { "kind": "prompt", diff --git a/internal/fetch/testdata/local-range3.golden b/internal/fetch/testdata/local-range3.golden index 1a7ea8f2c..8fe64f264 100644 --- a/internal/fetch/testdata/local-range3.golden +++ b/internal/fetch/testdata/local-range3.golden @@ -258,15 +258,15 @@ rather than becoming ground truth. --- file C/.verdict/state/local-demo/provenance.json --- { "schema_version": "1", - "run_id": "ea7a41cb80be2eda568016ae7204fb0415e95977cbadf046cfcac7121867c862", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "run_id": "fd2322d34fb5b4266be1b08b591c0b5ce3c4bfe4456cc859aede766649d49329", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "inputs": [ { "kind": "prompt", "name": "SKILL.md", "status": "included", - "sha256": "56a5922897f1def73b571fd871ce3ea65798e595f54952aec380496e785797cb", - "bytes": 13140 + "sha256": "6e55c5ebee9a13a25b8e95e9249ec909d7e92b6bfbcf6e3a2fb7a5c6236be01c", + "bytes": 13427 }, { "kind": "prompt", diff --git a/internal/fetch/testdata/local-staged.golden b/internal/fetch/testdata/local-staged.golden index ee293ef99..596a38de5 100644 --- a/internal/fetch/testdata/local-staged.golden +++ b/internal/fetch/testdata/local-staged.golden @@ -258,15 +258,15 @@ rather than becoming ground truth. --- file C/.verdict/state/local-demo/provenance.json --- { "schema_version": "1", - "run_id": "a2d8eb4fcaae1b2d76ba8ca181dd0ad40b0548338c0927cc5ca125fd7aebe2d7", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "run_id": "514ad9209736fa436c6cfa71d49eca36e69e524c4a210b3589aa7e77010fcfc2", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "inputs": [ { "kind": "prompt", "name": "SKILL.md", "status": "included", - "sha256": "56a5922897f1def73b571fd871ce3ea65798e595f54952aec380496e785797cb", - "bytes": 13140 + "sha256": "6e55c5ebee9a13a25b8e95e9249ec909d7e92b6bfbcf6e3a2fb7a5c6236be01c", + "bytes": 13427 }, { "kind": "prompt", diff --git a/internal/fetch/testdata/local-stash.golden b/internal/fetch/testdata/local-stash.golden index 3c0a1aa99..98fe6aaf5 100644 --- a/internal/fetch/testdata/local-stash.golden +++ b/internal/fetch/testdata/local-stash.golden @@ -258,15 +258,15 @@ rather than becoming ground truth. --- file C/.verdict/state/local-demo/provenance.json --- { "schema_version": "1", - "run_id": "b7dbe8f49aee086d2c2ab6c12ef530dd1305790c5b1eaec19c6bd785506a9f58", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "run_id": "58c426d9cf3cb53e532c2acea6f08ece93e81217c15cf5df7960af637d283459", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "inputs": [ { "kind": "prompt", "name": "SKILL.md", "status": "included", - "sha256": "56a5922897f1def73b571fd871ce3ea65798e595f54952aec380496e785797cb", - "bytes": 13140 + "sha256": "6e55c5ebee9a13a25b8e95e9249ec909d7e92b6bfbcf6e3a2fb7a5c6236be01c", + "bytes": 13427 }, { "kind": "prompt", diff --git a/internal/fetch/testdata/local-untracked.golden b/internal/fetch/testdata/local-untracked.golden index 9f7ff1504..c27f45606 100644 --- a/internal/fetch/testdata/local-untracked.golden +++ b/internal/fetch/testdata/local-untracked.golden @@ -261,15 +261,15 @@ rather than becoming ground truth. --- file C/.verdict/state/local-demo/provenance.json --- { "schema_version": "1", - "run_id": "75cf79061c0168cc97afce6debae845058cf16ce82dfbe7bc3d4f78ca79f39d4", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "run_id": "e86878662bcba478fd4a1177e65c540ac95d46eb560023a7482eaf2e9e53c2ad", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "inputs": [ { "kind": "prompt", "name": "SKILL.md", "status": "included", - "sha256": "56a5922897f1def73b571fd871ce3ea65798e595f54952aec380496e785797cb", - "bytes": 13140 + "sha256": "6e55c5ebee9a13a25b8e95e9249ec909d7e92b6bfbcf6e3a2fb7a5c6236be01c", + "bytes": 13427 }, { "kind": "prompt", diff --git a/internal/fetch/testdata/local-worktree-text.golden b/internal/fetch/testdata/local-worktree-text.golden index 35c232600..696498649 100644 --- a/internal/fetch/testdata/local-worktree-text.golden +++ b/internal/fetch/testdata/local-worktree-text.golden @@ -211,15 +211,15 @@ rather than becoming ground truth. --- file C/.verdict/state/local-demo/provenance.json --- { "schema_version": "1", - "run_id": "75cf79061c0168cc97afce6debae845058cf16ce82dfbe7bc3d4f78ca79f39d4", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "run_id": "e86878662bcba478fd4a1177e65c540ac95d46eb560023a7482eaf2e9e53c2ad", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "inputs": [ { "kind": "prompt", "name": "SKILL.md", "status": "included", - "sha256": "56a5922897f1def73b571fd871ce3ea65798e595f54952aec380496e785797cb", - "bytes": 13140 + "sha256": "6e55c5ebee9a13a25b8e95e9249ec909d7e92b6bfbcf6e3a2fb7a5c6236be01c", + "bytes": 13427 }, { "kind": "prompt", diff --git a/internal/fetch/testdata/local-worktree.golden b/internal/fetch/testdata/local-worktree.golden index f1537fa30..532b0b49d 100644 --- a/internal/fetch/testdata/local-worktree.golden +++ b/internal/fetch/testdata/local-worktree.golden @@ -258,15 +258,15 @@ rather than becoming ground truth. --- file C/.verdict/state/local-demo/provenance.json --- { "schema_version": "1", - "run_id": "75cf79061c0168cc97afce6debae845058cf16ce82dfbe7bc3d4f78ca79f39d4", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "run_id": "e86878662bcba478fd4a1177e65c540ac95d46eb560023a7482eaf2e9e53c2ad", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "inputs": [ { "kind": "prompt", "name": "SKILL.md", "status": "included", - "sha256": "56a5922897f1def73b571fd871ce3ea65798e595f54952aec380496e785797cb", - "bytes": 13140 + "sha256": "6e55c5ebee9a13a25b8e95e9249ec909d7e92b6bfbcf6e3a2fb7a5c6236be01c", + "bytes": 13427 }, { "kind": "prompt", diff --git a/internal/fetch/testdata/over-cap-chunk-text.golden b/internal/fetch/testdata/over-cap-chunk-text.golden index 8fe5c7628..955e4a91a 100644 --- a/internal/fetch/testdata/over-cap-chunk-text.golden +++ b/internal/fetch/testdata/over-cap-chunk-text.golden @@ -407,15 +407,15 @@ rather than becoming ground truth. --- file C/.verdict/state/4703/provenance.json --- { "schema_version": "1", - "run_id": "20a584cee44a28ca65ff627d95938a2f191396428fc3268ff4245dc4f29fcd07", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "run_id": "5d848d2413108117ae2b1c3d82359ee153cc2137a76283ccfa651f79fbdb7b49", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "inputs": [ { "kind": "prompt", "name": "SKILL.md", "status": "included", - "sha256": "56a5922897f1def73b571fd871ce3ea65798e595f54952aec380496e785797cb", - "bytes": 13140 + "sha256": "6e55c5ebee9a13a25b8e95e9249ec909d7e92b6bfbcf6e3a2fb7a5c6236be01c", + "bytes": 13427 }, { "kind": "prompt", diff --git a/internal/fetch/testdata/over-cap-chunk.golden b/internal/fetch/testdata/over-cap-chunk.golden index 107476b8f..9ea9dffdf 100644 --- a/internal/fetch/testdata/over-cap-chunk.golden +++ b/internal/fetch/testdata/over-cap-chunk.golden @@ -480,15 +480,15 @@ rather than becoming ground truth. --- file C/.verdict/state/4703/provenance.json --- { "schema_version": "1", - "run_id": "20a584cee44a28ca65ff627d95938a2f191396428fc3268ff4245dc4f29fcd07", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "run_id": "5d848d2413108117ae2b1c3d82359ee153cc2137a76283ccfa651f79fbdb7b49", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "inputs": [ { "kind": "prompt", "name": "SKILL.md", "status": "included", - "sha256": "56a5922897f1def73b571fd871ce3ea65798e595f54952aec380496e785797cb", - "bytes": 13140 + "sha256": "6e55c5ebee9a13a25b8e95e9249ec909d7e92b6bfbcf6e3a2fb7a5c6236be01c", + "bytes": 13427 }, { "kind": "prompt", diff --git a/internal/fetch/testdata/over-cap-knob.golden b/internal/fetch/testdata/over-cap-knob.golden index 76df14693..52469d0ea 100644 --- a/internal/fetch/testdata/over-cap-knob.golden +++ b/internal/fetch/testdata/over-cap-knob.golden @@ -482,15 +482,15 @@ rather than becoming ground truth. --- file C/.verdict/state/4703/provenance.json --- { "schema_version": "1", - "run_id": "7b39d397318aff7729503ab76d112d7392efc602f9a89650faa36edd7023eb4a", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "run_id": "ea7ee7559b310d5f69d151d96b69b9138022b760e0fea3b4164ad20b4be36ce4", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "inputs": [ { "kind": "prompt", "name": "SKILL.md", "status": "included", - "sha256": "56a5922897f1def73b571fd871ce3ea65798e595f54952aec380496e785797cb", - "bytes": 13140 + "sha256": "6e55c5ebee9a13a25b8e95e9249ec909d7e92b6bfbcf6e3a2fb7a5c6236be01c", + "bytes": 13427 }, { "kind": "prompt", diff --git a/internal/fetch/testdata/ratelimit-retry.golden b/internal/fetch/testdata/ratelimit-retry.golden index 784750928..5d5d7d079 100644 --- a/internal/fetch/testdata/ratelimit-retry.golden +++ b/internal/fetch/testdata/ratelimit-retry.golden @@ -330,15 +330,15 @@ rather than becoming ground truth. --- file C/.verdict/state/4713/provenance.json --- { "schema_version": "1", - "run_id": "7a1a93cded7af0dc99109adce92a216add66378c13e99f5d338eac2917e9250c", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "run_id": "b92fcd70224a6d7cf8873a8048f49b2b097717289341d5a65b37fe9b7fef74ae", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "inputs": [ { "kind": "prompt", "name": "SKILL.md", "status": "included", - "sha256": "56a5922897f1def73b571fd871ce3ea65798e595f54952aec380496e785797cb", - "bytes": 13140 + "sha256": "6e55c5ebee9a13a25b8e95e9249ec909d7e92b6bfbcf6e3a2fb7a5c6236be01c", + "bytes": 13427 }, { "kind": "prompt", diff --git a/internal/fetch/testdata/sensitive-kb-head.golden b/internal/fetch/testdata/sensitive-kb-head.golden index 9d8caa72c..fe0daa193 100644 --- a/internal/fetch/testdata/sensitive-kb-head.golden +++ b/internal/fetch/testdata/sensitive-kb-head.golden @@ -343,15 +343,15 @@ rather than becoming ground truth. --- file C/.verdict/state/4715/provenance.json --- { "schema_version": "1", - "run_id": "8485c85f6a7a46b515dd9f03bfc35c23e50a51a99c0ab3125143aaf809b6a3ed", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "run_id": "5b74a4c0eb0a732ff1dd69a33508fc6b37f0a9d1b3267c59007b5f6ce715cc8d", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "inputs": [ { "kind": "prompt", "name": "SKILL.md", "status": "included", - "sha256": "56a5922897f1def73b571fd871ce3ea65798e595f54952aec380496e785797cb", - "bytes": 13140 + "sha256": "6e55c5ebee9a13a25b8e95e9249ec909d7e92b6bfbcf6e3a2fb7a5c6236be01c", + "bytes": 13427 }, { "kind": "prompt", diff --git a/internal/fetch/testdata/sensitive-kb.golden b/internal/fetch/testdata/sensitive-kb.golden index 76f95562a..bded1f537 100644 --- a/internal/fetch/testdata/sensitive-kb.golden +++ b/internal/fetch/testdata/sensitive-kb.golden @@ -341,15 +341,15 @@ rather than becoming ground truth. --- file C/.verdict/state/4715/provenance.json --- { "schema_version": "1", - "run_id": "c6b2e51e70cbfe0def4c937b8b75b6b27dbdf7c645d55476fd1a58ff76087d7b", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "run_id": "5737c63bd70a174142bc16212e563bdaca8617c2fdec13f5ab7b0d441250b628", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "inputs": [ { "kind": "prompt", "name": "SKILL.md", "status": "included", - "sha256": "56a5922897f1def73b571fd871ce3ea65798e595f54952aec380496e785797cb", - "bytes": 13140 + "sha256": "6e55c5ebee9a13a25b8e95e9249ec909d7e92b6bfbcf6e3a2fb7a5c6236be01c", + "bytes": 13427 }, { "kind": "prompt", diff --git a/internal/fetch/testdata/since-alias.golden b/internal/fetch/testdata/since-alias.golden index 55c91458c..4e9786581 100644 --- a/internal/fetch/testdata/since-alias.golden +++ b/internal/fetch/testdata/since-alias.golden @@ -338,15 +338,15 @@ rather than becoming ground truth. --- file C/.verdict/state/4701/provenance.json --- { "schema_version": "1", - "run_id": "7a1a93cded7af0dc99109adce92a216add66378c13e99f5d338eac2917e9250c", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "run_id": "b92fcd70224a6d7cf8873a8048f49b2b097717289341d5a65b37fe9b7fef74ae", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "inputs": [ { "kind": "prompt", "name": "SKILL.md", "status": "included", - "sha256": "56a5922897f1def73b571fd871ce3ea65798e595f54952aec380496e785797cb", - "bytes": 13140 + "sha256": "6e55c5ebee9a13a25b8e95e9249ec909d7e92b6bfbcf6e3a2fb7a5c6236be01c", + "bytes": 13427 }, { "kind": "prompt", diff --git a/internal/fetch/testdata/threads-degraded.golden b/internal/fetch/testdata/threads-degraded.golden index 7ade35223..07253f56e 100644 --- a/internal/fetch/testdata/threads-degraded.golden +++ b/internal/fetch/testdata/threads-degraded.golden @@ -336,15 +336,15 @@ rather than becoming ground truth. --- file C/.verdict/state/4701/provenance.json --- { "schema_version": "1", - "run_id": "7a1a93cded7af0dc99109adce92a216add66378c13e99f5d338eac2917e9250c", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "run_id": "b92fcd70224a6d7cf8873a8048f49b2b097717289341d5a65b37fe9b7fef74ae", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "inputs": [ { "kind": "prompt", "name": "SKILL.md", "status": "included", - "sha256": "56a5922897f1def73b571fd871ce3ea65798e595f54952aec380496e785797cb", - "bytes": 13140 + "sha256": "6e55c5ebee9a13a25b8e95e9249ec909d7e92b6bfbcf6e3a2fb7a5c6236be01c", + "bytes": 13427 }, { "kind": "prompt", diff --git a/internal/provenance/prompts_test.go b/internal/provenance/prompts_test.go index b484e51b1..7b4d02b52 100644 --- a/internal/provenance/prompts_test.go +++ b/internal/provenance/prompts_test.go @@ -21,7 +21,7 @@ var infoWord = regexp.MustCompile(`^[A-Za-z0-9_+.-]*$`) // byte-identical; a move here is a deliberate prompt edit, never a side effect. func TestPromptsHashUnchanged(t *testing.T) { t.Parallel() - const want = "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d" + const want = "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9" if got := PromptsHash(filepath.Join("..", "..")); got != want { t.Fatalf("PromptsHash = %s, want %s", got, want) } diff --git a/internal/record/testdata/body/mermaid-stripped.golden b/internal/record/testdata/body/mermaid-stripped.golden index 701644937..3b53274ab 100644 --- a/internal/record/testdata/body/mermaid-stripped.golden +++ b/internal/record/testdata/body/mermaid-stripped.golden @@ -90,7 +90,7 @@ other.txt NEW 1 3 "confidence": null, "security_summary": null, "tool_version": "VERSION", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "model": null, "author": null, "review_models": [], diff --git a/internal/record/testdata/body/non-ascii.golden b/internal/record/testdata/body/non-ascii.golden index 3c017429d..071dbe73e 100644 --- a/internal/record/testdata/body/non-ascii.golden +++ b/internal/record/testdata/body/non-ascii.golden @@ -94,7 +94,7 @@ other.txt NEW 1 3 "confidence": null, "security_summary": null, "tool_version": "VERSION", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "model": null, "author": null, "review_models": [], diff --git a/internal/record/testdata/body/receipt-collision.golden b/internal/record/testdata/body/receipt-collision.golden index 9d46f98a0..a154ac271 100644 --- a/internal/record/testdata/body/receipt-collision.golden +++ b/internal/record/testdata/body/receipt-collision.golden @@ -59,7 +59,7 @@ other.txt NEW 1 3 "confidence": null, "security_summary": null, "tool_version": "VERSION", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "model": null, "author": null, "review_models": [], diff --git a/internal/record/testdata/chunk/drift.golden b/internal/record/testdata/chunk/drift.golden index db390ab84..3737c9ddb 100644 --- a/internal/record/testdata/chunk/drift.golden +++ b/internal/record/testdata/chunk/drift.golden @@ -27,7 +27,7 @@ c1.txt NEW 1 2 "confidence": null, "security_summary": null, "tool_version": "VERSION", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "model": null, "author": null, "review_models": [], diff --git a/internal/record/testdata/chunk/unattested.golden b/internal/record/testdata/chunk/unattested.golden index a59999415..27bc103b5 100644 --- a/internal/record/testdata/chunk/unattested.golden +++ b/internal/record/testdata/chunk/unattested.golden @@ -27,7 +27,7 @@ c1.txt NEW 1 2 "confidence": null, "security_summary": null, "tool_version": "VERSION", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "model": null, "author": null, "review_models": [], diff --git a/internal/record/testdata/chunk/unknown-chunk-claim.golden b/internal/record/testdata/chunk/unknown-chunk-claim.golden index 92a3da133..974b33c4c 100644 --- a/internal/record/testdata/chunk/unknown-chunk-claim.golden +++ b/internal/record/testdata/chunk/unknown-chunk-claim.golden @@ -27,7 +27,7 @@ c1.txt NEW 1 2 "confidence": null, "security_summary": null, "tool_version": "VERSION", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "model": null, "author": null, "review_models": [], diff --git a/internal/record/testdata/chunk/valid.golden b/internal/record/testdata/chunk/valid.golden index d98b9a390..2c5e3c51e 100644 --- a/internal/record/testdata/chunk/valid.golden +++ b/internal/record/testdata/chunk/valid.golden @@ -54,7 +54,7 @@ c1.txt NEW 1 2 "confidence": null, "security_summary": null, "tool_version": "VERSION", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "model": null, "author": null, "review_models": [], diff --git a/internal/record/testdata/claims/verify-triage-resolved/rereview.golden b/internal/record/testdata/claims/verify-triage-resolved/rereview.golden index 300d1ca56..57bd155c5 100644 --- a/internal/record/testdata/claims/verify-triage-resolved/rereview.golden +++ b/internal/record/testdata/claims/verify-triage-resolved/rereview.golden @@ -142,7 +142,7 @@ reverts.jsonl.lock "confidence": null, "security_summary": null, "tool_version": "VERSION", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "model": null, "author": null, "review_models": [], diff --git a/internal/record/testdata/degenerate/basis-bad.golden b/internal/record/testdata/degenerate/basis-bad.golden index b58b5d886..5877ff335 100644 --- a/internal/record/testdata/degenerate/basis-bad.golden +++ b/internal/record/testdata/degenerate/basis-bad.golden @@ -96,7 +96,7 @@ other.txt NEW 1 3 "confidence": null, "security_summary": null, "tool_version": "VERSION", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "model": null, "author": null, "review_models": [], diff --git a/internal/record/testdata/degenerate/basis-ok.golden b/internal/record/testdata/degenerate/basis-ok.golden index a327aaa38..81bd3acbc 100644 --- a/internal/record/testdata/degenerate/basis-ok.golden +++ b/internal/record/testdata/degenerate/basis-ok.golden @@ -94,7 +94,7 @@ other.txt NEW 1 3 "confidence": null, "security_summary": null, "tool_version": "VERSION", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "model": null, "author": null, "review_models": [], diff --git a/internal/record/testdata/degenerate/blob-link-local.golden b/internal/record/testdata/degenerate/blob-link-local.golden index 01ac02bcc..43ed10028 100644 --- a/internal/record/testdata/degenerate/blob-link-local.golden +++ b/internal/record/testdata/degenerate/blob-link-local.golden @@ -63,7 +63,7 @@ other.txt NEW 1 3 "confidence": null, "security_summary": null, "tool_version": "VERSION", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "model": null, "author": null, "review_models": [], diff --git a/internal/record/testdata/degenerate/brief-valid.golden b/internal/record/testdata/degenerate/brief-valid.golden index 340f5363a..ccadbb429 100644 --- a/internal/record/testdata/degenerate/brief-valid.golden +++ b/internal/record/testdata/degenerate/brief-valid.golden @@ -112,7 +112,7 @@ other.txt NEW 1 3 "confidence": null, "security_summary": null, "tool_version": "VERSION", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "model": null, "author": null, "review_models": [], diff --git a/internal/record/testdata/degenerate/carried-footer.golden b/internal/record/testdata/degenerate/carried-footer.golden index bc191104a..24c8d3532 100644 --- a/internal/record/testdata/degenerate/carried-footer.golden +++ b/internal/record/testdata/degenerate/carried-footer.golden @@ -63,7 +63,7 @@ other.txt NEW 1 3 "confidence": null, "security_summary": null, "tool_version": "VERSION", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "model": null, "author": null, "review_models": [], diff --git a/internal/record/testdata/degenerate/confidence-valid.golden b/internal/record/testdata/degenerate/confidence-valid.golden index 3a67bef34..73e64fb1e 100644 --- a/internal/record/testdata/degenerate/confidence-valid.golden +++ b/internal/record/testdata/degenerate/confidence-valid.golden @@ -61,7 +61,7 @@ other.txt NEW 1 3 "confidence": 4, "security_summary": "nothing alarming", "tool_version": "VERSION", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "model": null, "author": null, "review_models": [], diff --git a/internal/record/testdata/degenerate/fenced-body-section.golden b/internal/record/testdata/degenerate/fenced-body-section.golden index 3fdf53a73..4c3879cf9 100644 --- a/internal/record/testdata/degenerate/fenced-body-section.golden +++ b/internal/record/testdata/degenerate/fenced-body-section.golden @@ -94,7 +94,7 @@ other.txt NEW 1 3 "confidence": null, "security_summary": null, "tool_version": "VERSION", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "model": null, "author": null, "review_models": [], diff --git a/internal/record/testdata/degenerate/missing-marker-ok.golden b/internal/record/testdata/degenerate/missing-marker-ok.golden index 8bb4e87ab..5a5131f1a 100644 --- a/internal/record/testdata/degenerate/missing-marker-ok.golden +++ b/internal/record/testdata/degenerate/missing-marker-ok.golden @@ -59,7 +59,7 @@ other.txt NEW 1 3 "confidence": null, "security_summary": null, "tool_version": "VERSION", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "model": null, "author": null, "review_models": [], diff --git a/internal/record/testdata/degenerate/normalized-fenced.golden b/internal/record/testdata/degenerate/normalized-fenced.golden index a78f361f5..2df53c467 100644 --- a/internal/record/testdata/degenerate/normalized-fenced.golden +++ b/internal/record/testdata/degenerate/normalized-fenced.golden @@ -63,7 +63,7 @@ other.txt NEW 1 3 "confidence": null, "security_summary": null, "tool_version": "VERSION", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "model": null, "author": null, "review_models": [], diff --git a/internal/record/testdata/degenerate/normalized-prose.golden b/internal/record/testdata/degenerate/normalized-prose.golden index 2b4d6ecc6..7fe7d8c73 100644 --- a/internal/record/testdata/degenerate/normalized-prose.golden +++ b/internal/record/testdata/degenerate/normalized-prose.golden @@ -63,7 +63,7 @@ other.txt NEW 1 3 "confidence": null, "security_summary": null, "tool_version": "VERSION", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "model": null, "author": null, "review_models": [], diff --git a/internal/record/testdata/degenerate/normalized-weak-shapes.golden b/internal/record/testdata/degenerate/normalized-weak-shapes.golden index 3fc1468ed..d29563cd7 100644 --- a/internal/record/testdata/degenerate/normalized-weak-shapes.golden +++ b/internal/record/testdata/degenerate/normalized-weak-shapes.golden @@ -112,7 +112,7 @@ other.txt NEW 1 3 "confidence": null, "security_summary": null, "tool_version": "VERSION", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "model": null, "author": null, "review_models": [], diff --git a/internal/record/testdata/incremental/non-touching/rereview.golden b/internal/record/testdata/incremental/non-touching/rereview.golden index 4f932164e..82c3e3f1a 100644 --- a/internal/record/testdata/incremental/non-touching/rereview.golden +++ b/internal/record/testdata/incremental/non-touching/rereview.golden @@ -83,7 +83,7 @@ recorded: .verdict/state/local-kb/findings.json (0 open) + .verdict/state/local- "confidence": null, "security_summary": null, "tool_version": "VERSION", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "model": null, "author": null, "review_models": [], diff --git a/internal/record/testdata/incremental/reopen/rereview.golden b/internal/record/testdata/incremental/reopen/rereview.golden index 4f932164e..82c3e3f1a 100644 --- a/internal/record/testdata/incremental/reopen/rereview.golden +++ b/internal/record/testdata/incremental/reopen/rereview.golden @@ -83,7 +83,7 @@ recorded: .verdict/state/local-kb/findings.json (0 open) + .verdict/state/local- "confidence": null, "security_summary": null, "tool_version": "VERSION", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "model": null, "author": null, "review_models": [], diff --git a/internal/record/testdata/kb/absent.golden b/internal/record/testdata/kb/absent.golden index 52fd1a8e9..c58f428b9 100644 --- a/internal/record/testdata/kb/absent.golden +++ b/internal/record/testdata/kb/absent.golden @@ -60,7 +60,7 @@ other.txt NEW 1 3 "confidence": null, "security_summary": null, "tool_version": "VERSION", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "model": null, "author": null, "review_models": [], diff --git a/internal/record/testdata/kb/bad-id-shape.golden b/internal/record/testdata/kb/bad-id-shape.golden index 9804e1df1..8d6ae60ce 100644 --- a/internal/record/testdata/kb/bad-id-shape.golden +++ b/internal/record/testdata/kb/bad-id-shape.golden @@ -61,7 +61,7 @@ other.txt NEW 1 3 "confidence": null, "security_summary": null, "tool_version": "VERSION", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "model": null, "author": null, "review_models": [], diff --git a/internal/record/testdata/kb/bad-policy-env.golden b/internal/record/testdata/kb/bad-policy-env.golden index de12e196a..c7497e43f 100644 --- a/internal/record/testdata/kb/bad-policy-env.golden +++ b/internal/record/testdata/kb/bad-policy-env.golden @@ -98,7 +98,7 @@ other.txt NEW 1 3 "confidence": null, "security_summary": null, "tool_version": "VERSION", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "model": null, "author": null, "review_models": [], diff --git a/internal/record/testdata/kb/bad-shape.golden b/internal/record/testdata/kb/bad-shape.golden index ad86c0ba1..ccddd3a01 100644 --- a/internal/record/testdata/kb/bad-shape.golden +++ b/internal/record/testdata/kb/bad-shape.golden @@ -62,7 +62,7 @@ other.txt NEW 1 3 "confidence": null, "security_summary": null, "tool_version": "VERSION", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "model": null, "author": null, "review_models": [], diff --git a/internal/record/testdata/kb/broken-store.golden b/internal/record/testdata/kb/broken-store.golden index 7a6bc7ebc..bac4a2184 100644 --- a/internal/record/testdata/kb/broken-store.golden +++ b/internal/record/testdata/kb/broken-store.golden @@ -61,7 +61,7 @@ other.txt NEW 1 3 "confidence": null, "security_summary": null, "tool_version": "VERSION", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "model": null, "author": null, "review_models": [], diff --git a/internal/record/testdata/kb/counter-adds/rereview.golden b/internal/record/testdata/kb/counter-adds/rereview.golden index 12fa04c16..aae9ff0f6 100644 --- a/internal/record/testdata/kb/counter-adds/rereview.golden +++ b/internal/record/testdata/kb/counter-adds/rereview.golden @@ -111,7 +111,7 @@ reverts.jsonl.lock "confidence": null, "security_summary": null, "tool_version": "VERSION", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "model": null, "author": null, "review_models": [], diff --git a/internal/record/testdata/kb/duplicate.golden b/internal/record/testdata/kb/duplicate.golden index 218309311..67b59f9c1 100644 --- a/internal/record/testdata/kb/duplicate.golden +++ b/internal/record/testdata/kb/duplicate.golden @@ -62,7 +62,7 @@ other.txt NEW 1 3 "confidence": null, "security_summary": null, "tool_version": "VERSION", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "model": null, "author": null, "review_models": [], diff --git a/internal/record/testdata/kb/empty.golden b/internal/record/testdata/kb/empty.golden index 52fd1a8e9..c58f428b9 100644 --- a/internal/record/testdata/kb/empty.golden +++ b/internal/record/testdata/kb/empty.golden @@ -60,7 +60,7 @@ other.txt NEW 1 3 "confidence": null, "security_summary": null, "tool_version": "VERSION", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "model": null, "author": null, "review_models": [], diff --git a/internal/record/testdata/kb/false-positive/rereview.golden b/internal/record/testdata/kb/false-positive/rereview.golden index c2754fbed..c3c9097f7 100644 --- a/internal/record/testdata/kb/false-positive/rereview.golden +++ b/internal/record/testdata/kb/false-positive/rereview.golden @@ -113,7 +113,7 @@ reverts.jsonl.lock "confidence": null, "security_summary": null, "tool_version": "VERSION", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "model": null, "author": null, "review_models": [], diff --git a/internal/record/testdata/kb/joins-idempotent/rereview.golden b/internal/record/testdata/kb/joins-idempotent/rereview.golden index 6dc712f8c..d7dc1953e 100644 --- a/internal/record/testdata/kb/joins-idempotent/rereview.golden +++ b/internal/record/testdata/kb/joins-idempotent/rereview.golden @@ -111,7 +111,7 @@ reverts.jsonl.lock "confidence": null, "security_summary": null, "tool_version": "VERSION", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "model": null, "author": null, "review_models": [], diff --git a/internal/record/testdata/kb/no-store.golden b/internal/record/testdata/kb/no-store.golden index 3df4983d9..8073c13af 100644 --- a/internal/record/testdata/kb/no-store.golden +++ b/internal/record/testdata/kb/no-store.golden @@ -61,7 +61,7 @@ other.txt NEW 1 3 "confidence": null, "security_summary": null, "tool_version": "VERSION", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "model": null, "author": null, "review_models": [], diff --git a/internal/record/testdata/kb/null.golden b/internal/record/testdata/kb/null.golden index 5fa49fbe7..430b53293 100644 --- a/internal/record/testdata/kb/null.golden +++ b/internal/record/testdata/kb/null.golden @@ -61,7 +61,7 @@ other.txt NEW 1 3 "confidence": null, "security_summary": null, "tool_version": "VERSION", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "model": null, "author": null, "review_models": [], diff --git a/internal/record/testdata/kb/retired.golden b/internal/record/testdata/kb/retired.golden index 7c397f570..7db82737f 100644 --- a/internal/record/testdata/kb/retired.golden +++ b/internal/record/testdata/kb/retired.golden @@ -61,7 +61,7 @@ other.txt NEW 1 3 "confidence": null, "security_summary": null, "tool_version": "VERSION", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "model": null, "author": null, "review_models": [], diff --git a/internal/record/testdata/kb/string-counters/rereview.golden b/internal/record/testdata/kb/string-counters/rereview.golden index 899ee6081..9cd84be07 100644 --- a/internal/record/testdata/kb/string-counters/rereview.golden +++ b/internal/record/testdata/kb/string-counters/rereview.golden @@ -103,7 +103,7 @@ reverts.jsonl.lock "confidence": null, "security_summary": null, "tool_version": "VERSION", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "model": null, "author": null, "review_models": [], diff --git a/internal/record/testdata/kb/truncated.golden b/internal/record/testdata/kb/truncated.golden index 9106aba8d..96300710d 100644 --- a/internal/record/testdata/kb/truncated.golden +++ b/internal/record/testdata/kb/truncated.golden @@ -68,7 +68,7 @@ other.txt NEW 1 3 "confidence": null, "security_summary": null, "tool_version": "VERSION", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "model": null, "author": null, "review_models": [], diff --git a/internal/record/testdata/kb/unknown.golden b/internal/record/testdata/kb/unknown.golden index 23b16090d..31e28d21a 100644 --- a/internal/record/testdata/kb/unknown.golden +++ b/internal/record/testdata/kb/unknown.golden @@ -61,7 +61,7 @@ other.txt NEW 1 3 "confidence": null, "security_summary": null, "tool_version": "VERSION", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "model": null, "author": null, "review_models": [], diff --git a/internal/record/testdata/kb/valid.golden b/internal/record/testdata/kb/valid.golden index 218309311..67b59f9c1 100644 --- a/internal/record/testdata/kb/valid.golden +++ b/internal/record/testdata/kb/valid.golden @@ -62,7 +62,7 @@ other.txt NEW 1 3 "confidence": null, "security_summary": null, "tool_version": "VERSION", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "model": null, "author": null, "review_models": [], diff --git a/internal/record/testdata/matrix/n10/first.golden b/internal/record/testdata/matrix/n10/first.golden index 234a8d5d8..386b883ea 100644 --- a/internal/record/testdata/matrix/n10/first.golden +++ b/internal/record/testdata/matrix/n10/first.golden @@ -895,7 +895,7 @@ other.txt NEW 1 3 "confidence": null, "security_summary": null, "tool_version": "VERSION", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "model": null, "author": null, "review_models": [], diff --git a/internal/record/testdata/matrix/n10/rereview.golden b/internal/record/testdata/matrix/n10/rereview.golden index 57eee58bd..610ccc5a4 100644 --- a/internal/record/testdata/matrix/n10/rereview.golden +++ b/internal/record/testdata/matrix/n10/rereview.golden @@ -458,7 +458,7 @@ recorded: .verdict/state/local-mx/findings.json (11 open) + .verdict/state/local "confidence": null, "security_summary": null, "tool_version": "VERSION", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "model": null, "author": null, "review_models": [], diff --git a/internal/record/testdata/matrix/n200/first.golden b/internal/record/testdata/matrix/n200/first.golden index 3413cb2b2..9fd12640c 100644 --- a/internal/record/testdata/matrix/n200/first.golden +++ b/internal/record/testdata/matrix/n200/first.golden @@ -2150,7 +2150,7 @@ other.txt NEW 1 3 "confidence": null, "security_summary": null, "tool_version": "VERSION", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "model": null, "author": null, "review_models": [], diff --git a/internal/record/testdata/matrix/n200/rereview.golden b/internal/record/testdata/matrix/n200/rereview.golden index 347718d63..f6d234114 100644 --- a/internal/record/testdata/matrix/n200/rereview.golden +++ b/internal/record/testdata/matrix/n200/rereview.golden @@ -1523,7 +1523,7 @@ recorded: .verdict/state/local-mx/findings.json (202 open) + .verdict/state/loca "confidence": null, "security_summary": null, "tool_version": "VERSION", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "model": null, "author": null, "review_models": [], diff --git a/internal/record/testdata/matrix/n50/first.golden b/internal/record/testdata/matrix/n50/first.golden index d5aec9c2a..9b9de0370 100644 --- a/internal/record/testdata/matrix/n50/first.golden +++ b/internal/record/testdata/matrix/n50/first.golden @@ -2290,7 +2290,7 @@ other.txt NEW 1 3 "confidence": null, "security_summary": null, "tool_version": "VERSION", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "model": null, "author": null, "review_models": [], diff --git a/internal/record/testdata/matrix/n50/rereview.golden b/internal/record/testdata/matrix/n50/rereview.golden index 598c02bb9..0c6d4eb33 100644 --- a/internal/record/testdata/matrix/n50/rereview.golden +++ b/internal/record/testdata/matrix/n50/rereview.golden @@ -1817,7 +1817,7 @@ recorded: .verdict/state/local-mx/findings.json (52 open) + .verdict/state/local "confidence": null, "security_summary": null, "tool_version": "VERSION", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "model": null, "author": null, "review_models": [], diff --git a/internal/record/testdata/overrides/dir-as-fragment.golden b/internal/record/testdata/overrides/dir-as-fragment.golden index 80cbea4ef..fff6a2587 100644 --- a/internal/record/testdata/overrides/dir-as-fragment.golden +++ b/internal/record/testdata/overrides/dir-as-fragment.golden @@ -28,7 +28,7 @@ other.txt NEW 1 3 "confidence": null, "security_summary": null, "tool_version": "VERSION", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "model": null, "author": null, "review_models": [], diff --git a/internal/record/testdata/overrides/eq-threshold.golden b/internal/record/testdata/overrides/eq-threshold.golden index 80cbea4ef..fff6a2587 100644 --- a/internal/record/testdata/overrides/eq-threshold.golden +++ b/internal/record/testdata/overrides/eq-threshold.golden @@ -28,7 +28,7 @@ other.txt NEW 1 3 "confidence": null, "security_summary": null, "tool_version": "VERSION", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "model": null, "author": null, "review_models": [], diff --git a/internal/record/testdata/overrides/valid.golden b/internal/record/testdata/overrides/valid.golden index 80cbea4ef..fff6a2587 100644 --- a/internal/record/testdata/overrides/valid.golden +++ b/internal/record/testdata/overrides/valid.golden @@ -28,7 +28,7 @@ other.txt NEW 1 3 "confidence": null, "security_summary": null, "tool_version": "VERSION", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "model": null, "author": null, "review_models": [], diff --git a/internal/record/testdata/provider/gitlab.golden b/internal/record/testdata/provider/gitlab.golden index 784e09700..909d55b7c 100644 --- a/internal/record/testdata/provider/gitlab.golden +++ b/internal/record/testdata/provider/gitlab.golden @@ -56,7 +56,7 @@ other.txt NEW 1 3 "confidence": null, "security_summary": null, "tool_version": "VERSION", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "model": null, "author": null, "review_models": [], diff --git a/internal/record/testdata/refuse/empty-prior.golden b/internal/record/testdata/refuse/empty-prior.golden index e3a9aa357..404e0c66d 100644 --- a/internal/record/testdata/refuse/empty-prior.golden +++ b/internal/record/testdata/refuse/empty-prior.golden @@ -57,7 +57,7 @@ other.txt NEW 1 3 "confidence": null, "security_summary": null, "tool_version": "VERSION", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "model": null, "author": null, "review_models": [], diff --git a/internal/record/testdata/refuse/false-prior.golden b/internal/record/testdata/refuse/false-prior.golden index e3a9aa357..404e0c66d 100644 --- a/internal/record/testdata/refuse/false-prior.golden +++ b/internal/record/testdata/refuse/false-prior.golden @@ -57,7 +57,7 @@ other.txt NEW 1 3 "confidence": null, "security_summary": null, "tool_version": "VERSION", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "model": null, "author": null, "review_models": [], diff --git a/internal/record/testdata/refuse/invalid-utf8-review.golden b/internal/record/testdata/refuse/invalid-utf8-review.golden index 6ad68ef43..49be19db7 100644 --- a/internal/record/testdata/refuse/invalid-utf8-review.golden +++ b/internal/record/testdata/refuse/invalid-utf8-review.golden @@ -94,7 +94,7 @@ other.txt NEW 1 3 "confidence": null, "security_summary": null, "tool_version": "VERSION", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "model": null, "author": null, "review_models": [], diff --git a/internal/record/testdata/refuse/null-prior.golden b/internal/record/testdata/refuse/null-prior.golden index e3a9aa357..404e0c66d 100644 --- a/internal/record/testdata/refuse/null-prior.golden +++ b/internal/record/testdata/refuse/null-prior.golden @@ -57,7 +57,7 @@ other.txt NEW 1 3 "confidence": null, "security_summary": null, "tool_version": "VERSION", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "model": null, "author": null, "review_models": [], diff --git a/internal/record/testdata/source/dirty-head.golden b/internal/record/testdata/source/dirty-head.golden index a6140ea52..46113cbe6 100644 --- a/internal/record/testdata/source/dirty-head.golden +++ b/internal/record/testdata/source/dirty-head.golden @@ -57,7 +57,7 @@ other.txt NEW 1 3 "confidence": null, "security_summary": null, "tool_version": "VERSION", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "model": null, "author": null, "review_models": [], diff --git a/internal/record/testdata/source/dirty-string.golden b/internal/record/testdata/source/dirty-string.golden index e3a9aa357..404e0c66d 100644 --- a/internal/record/testdata/source/dirty-string.golden +++ b/internal/record/testdata/source/dirty-string.golden @@ -57,7 +57,7 @@ other.txt NEW 1 3 "confidence": null, "security_summary": null, "tool_version": "VERSION", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "model": null, "author": null, "review_models": [], diff --git a/internal/record/testdata/uncite/null-keeps/rereview.golden b/internal/record/testdata/uncite/null-keeps/rereview.golden index 7ed4ebb4c..3e0d0927c 100644 --- a/internal/record/testdata/uncite/null-keeps/rereview.golden +++ b/internal/record/testdata/uncite/null-keeps/rereview.golden @@ -56,7 +56,7 @@ recorded: .verdict/state/local-kb/findings.json (1 open) + .verdict/state/local- "confidence": null, "security_summary": null, "tool_version": "VERSION", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "model": null, "author": null, "review_models": [], diff --git a/internal/record/testdata/verify/contradict-exit/rereview.golden b/internal/record/testdata/verify/contradict-exit/rereview.golden index 8de8c4a48..df23ffc47 100644 --- a/internal/record/testdata/verify/contradict-exit/rereview.golden +++ b/internal/record/testdata/verify/contradict-exit/rereview.golden @@ -113,7 +113,7 @@ reverts.jsonl.lock "confidence": null, "security_summary": null, "tool_version": "VERSION", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "model": null, "author": null, "review_models": [], diff --git a/internal/record/testdata/verify/contradict-timeout/rereview.golden b/internal/record/testdata/verify/contradict-timeout/rereview.golden index 46939d654..19e008af3 100644 --- a/internal/record/testdata/verify/contradict-timeout/rereview.golden +++ b/internal/record/testdata/verify/contradict-timeout/rereview.golden @@ -113,7 +113,7 @@ reverts.jsonl.lock "confidence": null, "security_summary": null, "tool_version": "VERSION", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "model": null, "author": null, "review_models": [], diff --git a/internal/record/testdata/verify/on-addressed/rereview.golden b/internal/record/testdata/verify/on-addressed/rereview.golden index ef5a68113..9dbb7db9f 100644 --- a/internal/record/testdata/verify/on-addressed/rereview.golden +++ b/internal/record/testdata/verify/on-addressed/rereview.golden @@ -120,7 +120,7 @@ reverts.jsonl.lock "confidence": null, "security_summary": null, "tool_version": "VERSION", - "prompts_hash": "0819c05a9f07bebd054279a4a998adfc9077a5cf5a12dc84d588205b917a893d", + "prompts_hash": "57708e26c0828084fa5ffc651af76a5f7b6d8c5dc404408c1806f4046a635cc9", "model": null, "author": null, "review_models": [], diff --git a/skills/verdict/SKILL.md b/skills/verdict/SKILL.md index a29098df4..5388de063 100644 --- a/skills/verdict/SKILL.md +++ b/skills/verdict/SKILL.md @@ -95,10 +95,11 @@ after 3 rounds, stop and report them rather than recording a partial review. PR fetch for posting. Downstream verbs address the bundle as `local-work`. Never call `triage` — propose status changes via `triage[]` in `review.json`. -The operator's own reads between runs: `triage` (status changes), `report` -(ranked read), `threads` (refresh the PR conversation feed), `calibrate` -(predictions vs ground truth), and `fix` (one bounded verify-gated pass over a -local bundle — prints the finding plus land instructions). +The operator's own verbs between runs: `triage` (status changes), `report` +(ranked read), `threads` (refresh the PR conversation feed), `drain` (plan and +post replies to waiting threads), `calibrate` (predictions vs ground truth), and +`fix` (one bounded verify-gated pass over a local bundle — prints the finding +plus land instructions). Delta re-review: `verdict fetch owner/repo 123 --base-sha `, then load `prompts/incremental-review.md` instead of `prompts/review.md`. @@ -107,17 +108,18 @@ and you fall back to the full diff. ## Mode router -| Ask | Load | Terminal write | -| ------------------------------------------ | ------------------------------------------ | -------------------------------------------------------- | -| Review a PR | `prompts/review.md` | one review | -| Review local changes (no PR) | `prompts/review.md` + `source.json` bundle | `record`, then `report` — never `post` | -| New commits landed | `prompts/incremental-review.md` | one review OR no-review note | -| Address review threads | `prompts/address-reviews.md` | commit/push + one reply per thread | -| Fix failing CI | `prompts/fix-ci.md` | commit/push + summary | -| Implement / build | `prompts/build.md` | commit/push + PR link | -| Draft a review report without posting | `prompts/ci.md` | report markdown file, no post | -| Grade closed findings (self-grading probe) | `prompts/grade.md` | grade rows + agent judgments (additive) + agreement rate | -| Anything else | `prompts/system.md` + task text | summary stdout | +| Ask | Load | Terminal write | +| ------------------------------------------ | ------------------------------------------ | --------------------------------------------------------------- | +| Review a PR | `prompts/review.md` | one review | +| Review local changes (no PR) | `prompts/review.md` + `source.json` bundle | `record`, then `report` — never `post` | +| New commits landed | `prompts/incremental-review.md` | one review OR no-review note | +| Address review threads | `prompts/address-reviews.md` | commit/push + one reply per thread; reply-only passes use drain | +| Answer pending review-thread replies | `prompts/address-reviews.md` | `verdict drain owner/repo N --agent --post` | +| Fix failing CI | `prompts/fix-ci.md` | commit/push + summary | +| Implement / build | `prompts/build.md` | commit/push + PR link | +| Draft a review report without posting | `prompts/ci.md` | report markdown file, no post | +| Grade closed findings (self-grading probe) | `prompts/grade.md` | grade rows + agent judgments (additive) + agreement rate | +| Anything else | `prompts/system.md` + task text | summary stdout | `prompts/system.md` loads on every run. `prompts/reviewer-subagent.md` is the contract for lens subagents the Review modes dispatch — the orchestrator reads it From 8787cafc31b77bb3f8b3dcbddb13d049b3c0a022 Mon Sep 17 00:00:00 2001 From: Sutu Sebastian Date: Tue, 17 Nov 2026 15:06:57 +0200 Subject: [PATCH 07/14] fix(drain): omit empty posted entries on append failure and expose pure draft preflight --- internal/core/drain/ledger.go | 6 +-- internal/core/drain/post.go | 87 ++++++++++++++++++++------------ internal/core/drain/post_test.go | 64 +++++++++++++++++++++++ 3 files changed, 120 insertions(+), 37 deletions(-) diff --git a/internal/core/drain/ledger.go b/internal/core/drain/ledger.go index 3ab9cde9e..b52e2c5a1 100644 --- a/internal/core/drain/ledger.go +++ b/internal/core/drain/ledger.go @@ -10,9 +10,7 @@ import ( "github.com/stainless-code/verdict/internal/storelock" ) -// AppendLedger records one successful reply under the store lock. A crash -// after a host write but before this call is the only unrecorded window; once -// the entry lands, the next drain reads it and makes no second host write. +// AppendLedger records one successful reply under the store lock. func AppendLedger(path string, entry *LedgerEntry) error { unlock, err := storelock.Acquire(path, storelock.DefaultWait) if err != nil { @@ -34,8 +32,6 @@ func AppendLedger(path string, entry *LedgerEntry) error { return nil } -// readLedger reads the shared address-reviews ledger. An absent file is an -// empty one; a corrupt file refuses instead of being read as nobody replied. func readLedger(path string) ([]LedgerEntry, error) { raw, err := jq.CappedFile(path, jq.MaxPRBytes) if err != nil { diff --git a/internal/core/drain/post.go b/internal/core/drain/post.go index daf502049..cd4958fc3 100644 --- a/internal/core/drain/post.go +++ b/internal/core/drain/post.go @@ -16,8 +16,7 @@ import ( // plan was made: the agent answered a question that is no longer the last one. const ReasonStaleThread = "stale-thread" -// PostRequest carries one post run. The write callbacks are injected so the -// ordering and the idempotency rules can be tested without a host. +// PostRequest carries one post run. type PostRequest struct { Plan *File Feed *threadscore.File @@ -40,6 +39,34 @@ type PostResult struct { Incomplete bool } +// ValidatePostDrafts runs the local §6 preflight gates without mutating plan: +// missing/invalid/stale drafts, ThreadReply capability, and secret scan. +func ValidatePostDrafts(plan *File, draftsRaw []byte, provider string) (*RepliesFile, *Drafts, []Skip, *core.RefusalError) { + if plan == nil { + return nil, nil, nil, &core.RefusalError{Code: CodeDrainFailed, Message: "drain-failed: no plan to post against"} + } + if len(bytes.TrimSpace(draftsRaw)) == 0 { + return nil, nil, nil, invalid("root", "no drafts; run drain --agent first") + } + summary, noDraftsSkips, ref := CheckDrafts(draftsRaw, plan) + if ref != nil { + return nil, nil, nil, ref + } + caps := core.CapabilitiesFor(provider) + if !caps.ThreadReply { + return nil, nil, nil, &core.RefusalError{Code: "provider-unimplemented", Message: fmt.Sprintf( + "thread replies on %s are not implemented (%s)", provider, caps.ThreadReplyReason())} + } + var doc RepliesFile + if err := json.Unmarshal(draftsRaw, &doc); err != nil { + return nil, nil, nil, invalid("root", err.Error()) + } + if ref := secretGate(doc.Replies); ref != nil { + return nil, nil, nil, ref + } + return &doc, summary, noDraftsSkips, nil +} + // Post runs §6's gates in order, then posts each draft and records one ledger // entry per successful write. A host failure is recorded and the remaining // drafts are still attempted; the caller turns Incomplete into a refusal. @@ -62,33 +89,33 @@ func Post(req *PostRequest) (*PostResult, *core.RefusalError) { return res, nil } -// postDrafts runs §6's first gates: drafts, capability, then secret scan. func postDrafts(req *PostRequest) (*RepliesFile, *core.RefusalError) { if req.Plan == nil || req.Feed == nil { return nil, &core.RefusalError{Code: CodeDrainFailed, Message: "drain-failed: no plan or thread feed to post against"} } - if len(bytes.TrimSpace(req.DraftsRaw)) == 0 { - return nil, invalid("root", "no drafts; run drain --agent first") - } - summary, noDraftsSkips, ref := CheckDrafts(req.DraftsRaw, req.Plan) + doc, summary, noDraftsSkips, ref := ValidatePostDrafts(req.Plan, req.DraftsRaw, req.Provider) if ref != nil { return nil, ref } req.Plan.Drafts = summary - req.Plan.Skipped = append(req.Plan.Skipped, noDraftsSkips...) - caps := core.CapabilitiesFor(req.Provider) - if !caps.ThreadReply { - return nil, &core.RefusalError{Code: "provider-unimplemented", Message: fmt.Sprintf( - "thread replies on %s are not implemented (%s)", req.Provider, caps.ThreadReplyReason())} - } - var doc RepliesFile - if err := json.Unmarshal(req.DraftsRaw, &doc); err != nil { - return nil, invalid("root", err.Error()) - } - if ref := secretGate(doc.Replies); ref != nil { - return nil, ref + req.Plan.Skipped = appendUniqueSkips(req.Plan.Skipped, noDraftsSkips) + return doc, nil +} + +func appendUniqueSkips(existing, extra []Skip) []Skip { + for _, s := range extra { + dup := false + for _, prev := range existing { + if prev.ThreadID == s.ThreadID && prev.Reason == s.Reason { + dup = true + break + } + } + if !dup { + existing = append(existing, s) + } } - return &doc, nil + return existing } func postThreads(feed *threadscore.File) map[string]*threadscore.Thread { @@ -127,36 +154,34 @@ func postOne(req *PostRequest, byID map[string]*threadscore.Thread, reply Reply, res.Failed = append(res.Failed, Failed{ThreadID: reply.ThreadID, Reason: err.Error()}) return } - res.Posted = append(res.Posted, recordPost(req, thread, reply, id, res)) + if posted, ok := recordPost(req, thread, reply, id, res); ok { + res.Posted = append(res.Posted, posted) + } } -// recordPost appends the ledger entry immediately after one successful write, -// then resolves a withdraw and marks the feed. A failure is recorded but never -// rolls back the reply already on the host. -func recordPost(req *PostRequest, thread *threadscore.Thread, reply Reply, id string, res *PostResult) Posted { +func recordPost(req *PostRequest, thread *threadscore.Thread, reply Reply, id string, res *PostResult) (Posted, bool) { entry := LedgerEntry{ Thread: reply.ThreadID, ReplyID: id, At: req.At, InReplyTo: reply.WaitingCommentID, By: ReplyBy, } if err := req.Append(&entry); err != nil { res.Failed = append(res.Failed, Failed{ThreadID: reply.ThreadID, Reason: "could not record reply: " + err.Error()}) - return Posted{} + return Posted{}, false } req.Ledger = append(req.Ledger, entry) posted := Posted{ThreadID: reply.ThreadID, ReplyID: id, Disposition: string(reply.Disposition)} if reply.Disposition != DispositionWithdraw { - return posted + return posted, true } if err := req.Resolve(reply.ThreadID); err != nil { res.Failed = append(res.Failed, Failed{ThreadID: reply.ThreadID, Reason: "could not resolve thread: " + err.Error()}) - return posted + return posted, true } thread.Resolved = true posted.Resolved = true - return posted + return posted, true } -// postSkipReason returns the typed reason a refreshed thread must not post. func postSkipReason(req *PostRequest, reply Reply, thread *threadscore.Thread, last *threadscore.Comment) string { switch { case thread.Resolved: @@ -172,8 +197,6 @@ func postSkipReason(req *PostRequest, reply Reply, thread *threadscore.Thread, l } } -// secretGate scans every outbound body before the first write and names the -// draft site. There is no override on drain: a posted reply cannot be unsent. func secretGate(replies []Reply) *core.RefusalError { for i, reply := range replies { if reply.Disposition == DispositionDefer { diff --git a/internal/core/drain/post_test.go b/internal/core/drain/post_test.go index bc5bbc384..8be9b0642 100644 --- a/internal/core/drain/post_test.go +++ b/internal/core/drain/post_test.go @@ -269,3 +269,67 @@ func TestPostRefusesUnsupportedHost(t *testing.T) { t.Error("unsupported host made a write") } } + +func TestPostAppendFailureRecordsFailedWithoutEmptyPosted(t *testing.T) { + req, calls, _ := postFixture(t, nil) + req.Append = func(entry *LedgerEntry) error { + if entry.Thread == "PRRT_2" { + return errors.New("disk full") + } + return nil + } + res, ref := Post(req) + if ref != nil { + t.Fatalf("Post refused: %+v", ref) + } + if !res.Incomplete || len(res.Posted) != 2 || len(res.Failed) != 1 { + t.Fatalf("result = %+v, want 2 posted, 1 failed, incomplete", res) + } + for _, p := range res.Posted { + if p.ThreadID == "" { + t.Errorf("empty Posted entry recorded on append failure: %+v", res.Posted) + } + } + if res.Failed[0].ThreadID != "PRRT_2" || !strings.Contains(res.Failed[0].Reason, "disk full") { + t.Errorf("failed = %+v, want PRRT_2 disk full", res.Failed) + } + if len(*calls) != 3 { + t.Errorf("calls = %d, want 3", len(*calls)) + } +} + +func TestValidatePostDraftsDoesNotMutatePlanOrDuplicateSkips(t *testing.T) { + req, _, _ := postFixture(t, nil) + raw, err := json.Marshal(RepliesFile{ + SchemaVersion: SchemaVersion, + PlanDigest: req.Plan.PlanDigest, + Replies: []Reply{ + {ThreadID: "PRRT_1", WaitingCommentID: "101", Disposition: DispositionAnswer, Body: "Answer one."}, + }, + }) + if err != nil { + t.Fatal(err) + } + req.DraftsRaw = raw + doc, summary, skips, ref := ValidatePostDrafts(req.Plan, req.DraftsRaw, "github") + if ref != nil || doc == nil || summary.Count != 1 || len(skips) != 2 { + t.Fatalf("ValidatePostDrafts = (%v, %+v, %+v, %+v)", doc, summary, skips, ref) + } + if req.Plan.Drafts != nil || len(req.Plan.Skipped) != 0 { + t.Fatalf("ValidatePostDrafts mutated plan: %+v", req.Plan) + } + req.Plan.Skipped = append(req.Plan.Skipped, skips...) + res, ref := Post(req) + if ref != nil || len(res.Posted) != 1 { + t.Fatalf("Post = (%+v, %+v)", res, ref) + } + noDraftCount := 0 + for _, s := range req.Plan.Skipped { + if s.Reason == ReasonNoDraft { + noDraftCount++ + } + } + if noDraftCount != 2 { + t.Errorf("no-draft skips = %d, want 2 (no duplicates): %+v", noDraftCount, req.Plan.Skipped) + } +} From b27f27dd97319fe22dc91628f82c382d72a8eb15 Mon Sep 17 00:00:00 2001 From: Sutu Sebastian Date: Tue, 17 Nov 2026 15:09:29 +0200 Subject: [PATCH 08/14] fix(drain): compose --agent --post, run local checks before reads, lock post run, and emit single incomplete envelope --- internal/drain/post.go | 69 ++++-- internal/drain/post_test.go | 473 ++++++++++++++++++++++++++++++++++++ internal/drain/verb.go | 108 ++++---- internal/drain/verb_test.go | 121 ++++++++- 4 files changed, 705 insertions(+), 66 deletions(-) create mode 100644 internal/drain/post_test.go diff --git a/internal/drain/post.go b/internal/drain/post.go index 994aafb9f..f22dfdb3d 100644 --- a/internal/drain/post.go +++ b/internal/drain/post.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" "io/fs" + "path/filepath" "github.com/stainless-code/verdict/internal/cli" "github.com/stainless-code/verdict/internal/core" @@ -15,12 +16,15 @@ import ( threadscore "github.com/stainless-code/verdict/internal/core/threads" "github.com/stainless-code/verdict/internal/jq" "github.com/stainless-code/verdict/internal/readcommon" + "github.com/stainless-code/verdict/internal/storelock" ) -// postMode runs §6's gates before a single host write: validate the drafts, -// check the capability, refresh the feed, then hand the write order to the -// pure post service. The plan and the feed it writes are the run's receipt. func postMode(ctx context.Context, r *cli.Runner, req Request, fl *flags) int { + if fl.provider != "" { + if ref := checkThreadReplyCap(fl.provider); ref != nil { + return r.Refuse(ref) + } + } dir, plan, ref := postPlan(req, fl) if ref != nil { return r.Refuse(ref) @@ -29,13 +33,22 @@ func postMode(ctx context.Context, r *cli.Runner, req Request, fl *flags) int { if ref != nil { return r.Refuse(ref) } + if _, _, _, ref := draincore.ValidatePostDrafts(plan, drafts, plan.Provider); ref != nil { + return r.Refuse(ref) + } + unlock, err := storelock.Acquire(filepath.Join(dir, verbDrain), storelock.DefaultWait) + if err != nil { + return r.Refuse(drainFailed(fmt.Sprintf("could not lock %s: %v", dir, err))) + } + defer unlock() + resp, ref := fetchcore.RunThreads(ctx, refreshRequest(r, req, fl)) if ref != nil { return r.Refuse(drainFailed(ref.Message)) } - in, code, done := readInputs(ctx, r, req, fl, resp) - if done { - return code + in, ref := readInputs(ctx, req, resp) + if ref != nil { + return r.Refuse(ref) } result, ref := postWrites(ctx, req, dir, plan, drafts, in) if ref != nil { @@ -44,7 +57,15 @@ func postMode(ctx context.Context, r *cli.Runner, req Request, fl *flags) int { return postFinish(r, req, dir, plan, resp, result) } -// postPlan reads the plan and checks the capability before any host read. +func checkThreadReplyCap(provider string) *core.RefusalError { + caps := core.CapabilitiesFor(provider) + if !caps.ThreadReply { + return &core.RefusalError{Code: "provider-unimplemented", Message: fmt.Sprintf( + "thread replies on %s are not implemented (%s)", provider, caps.ThreadReplyReason())} + } + return nil +} + func postPlan(req Request, fl *flags) (string, *draincore.File, *core.RefusalError) { dir, ref := readcommon.ResolveBundleDir(req.RepoRootPath(), req.Pr) if ref != nil { @@ -57,11 +78,6 @@ func postPlan(req Request, fl *flags) (string, *draincore.File, *core.RefusalErr if ref := planProvider(plan.Provider, fl.provider); ref != nil { return "", nil, ref } - caps := core.CapabilitiesFor(plan.Provider) - if !caps.ThreadReply { - return "", nil, &core.RefusalError{Code: "provider-unimplemented", Message: fmt.Sprintf( - "thread replies on %s are not implemented (%s)", plan.Provider, caps.ThreadReplyReason())} - } return dir, plan, nil } @@ -138,25 +154,40 @@ func saveFeedWriter(dir string) func(*threadscore.File) error { } } +func postSuccessNext(req Request) string { + return "refresh threads with verdict threads " + req.Repo + " " + req.Pr +} + func postFinish(r *cli.Runner, req Request, dir string, plan *draincore.File, resp *fetchcore.ThreadsResponse, result *draincore.PostResult, ) int { - r.Warnings = append(r.Warnings, resp.Warnings...) - nextText := "refresh threads with verdict threads " + req.Repo + " " + req.Pr + r.Warnings = resp.Warnings + nextText := postSuccessNext(req) if result.Incomplete { nextText = "re-run verdict drain " + req.Repo + " " + req.Pr + " --post" } fmt.Fprintf(r.Human, "» %d posted, %d failed -> %s/%s\n", len(result.Posted), len(result.Failed), dir, draincore.KeyPlanJSON) + if result.Incomplete { + ref := &core.RefusalError{Code: draincore.CodeDrainIncomplete, Message: fmt.Sprintf( + "%d thread(s) could not be posted; the ledger makes a re-run idempotent", len(result.Failed))} + if !r.JSONMode { + return r.Refuse(ref) + } + env := core.RenderEnvelope(verbDrain, req.Repo, req.Pr, cli.NowUTC(r.Now()), nextText, + r.Warnings, plan.Wire(), &core.SchemaError{ + Code: ref.Code, + Message: ref.Message + "\n" + cli.HintFor(ref.Code), + }) + fmt.Fprint(r.Out, jq.PrettyOrdered(env)) + r.WriteRentry() + return cli.ExitFor(ref, cli.ExitRefused) + } if r.JSONMode { - env := core.RenderEnvelope(verbDrain, req.Repo, req.Pr, core.NowUTC(r.Now()), nextText, + env := core.RenderEnvelope(verbDrain, req.Repo, req.Pr, cli.NowUTC(r.Now()), nextText, r.Warnings, plan.Wire(), nil) fmt.Fprint(r.Out, jq.PrettyOrdered(env)) } - if result.Incomplete { - return r.Refuse(&core.RefusalError{Code: "drain-incomplete", Message: fmt.Sprintf( - "%d thread(s) could not be posted; the ledger makes a re-run idempotent", len(result.Failed))}) - } return cli.ExitOK } diff --git a/internal/drain/post_test.go b/internal/drain/post_test.go new file mode 100644 index 000000000..1d42706c5 --- /dev/null +++ b/internal/drain/post_test.go @@ -0,0 +1,473 @@ +package drain + +import ( + "bytes" + "context" + "encoding/json" + "io" + "os" + "path/filepath" + "strings" + "sync" + "testing" + "time" + + "github.com/stainless-code/verdict/internal/cli" + "github.com/stainless-code/verdict/internal/core" + draincore "github.com/stainless-code/verdict/internal/core/drain" + threadscore "github.com/stainless-code/verdict/internal/core/threads" +) + +type drainHostStub struct { + mu sync.Mutex + pageJSON string + self string + calls []string + failRootID string + postDelay time.Duration + postedCount map[string]int +} + +func (s *drainHostStub) Run(_ context.Context, cmd *core.Command) (core.Result, error) { + joined := strings.Join(cmd.Argv, " ") + s.mu.Lock() + s.calls = append(s.calls, joined) + delay := s.postDelay + if delay > 0 && len(s.postedCount) == 0 && len(cmd.Argv) >= 4 && cmd.Argv[1] == "--method" && cmd.Argv[2] == "POST" { + s.mu.Unlock() + time.Sleep(delay) + s.mu.Lock() + } + if s.postedCount == nil { + s.postedCount = map[string]int{} + } + s.mu.Unlock() + + if len(cmd.Argv) >= 4 && cmd.Argv[0] == "gh" && cmd.Argv[1] == "api" && cmd.Argv[2] == "user" { + return core.Result{Stdout: s.self + "\n"}, nil + } + if len(cmd.Argv) >= 3 && cmd.Argv[0] == "gh" && cmd.Argv[1] == "api" && cmd.Argv[2] == "graphql" { + if strings.Contains(joined, "resolveReviewThread") { + return core.Result{Stdout: `{"data":{"resolveReviewThread":{"thread":{"id":"PRRT_2","isResolved":true}}}}`}, nil + } + return core.Result{Stdout: s.pageJSON}, nil + } + if len(cmd.Argv) >= 4 && cmd.Argv[0] == "gh" && cmd.Argv[1] == "api" && cmd.Argv[2] == "--method" && cmd.Argv[3] == "POST" { + endpoint := cmd.Argv[4] + if s.failRootID != "" && strings.Contains(endpoint, "/comments/"+s.failRootID+"/replies") { + return core.Result{ExitCode: 1, Stderr: "host rejected reply"}, nil + } + s.mu.Lock() + switch { + case strings.Contains(endpoint, "/comments/101/replies"): + s.postedCount["PRRT_1"]++ + s.mu.Unlock() + return core.Result{Stdout: `{"id":501}`}, nil + case strings.Contains(endpoint, "/comments/201/replies"): + s.postedCount["PRRT_2"]++ + s.mu.Unlock() + return core.Result{Stdout: `{"id":502}`}, nil + } + s.mu.Unlock() + } + return core.Result{ExitCode: 1, Stderr: "unexpected command: " + joined}, nil +} + +func (s *drainHostStub) postCount(threadID string) int { + s.mu.Lock() + defer s.mu.Unlock() + return s.postedCount[threadID] +} + +func (s *drainHostStub) callLog() []string { + s.mu.Lock() + defer s.mu.Unlock() + return append([]string{}, s.calls...) +} + +func setupDrainBundle(t *testing.T) (string, string) { + t.Helper() + root := t.TempDir() + dir := filepath.Join(root, ".verdict", "state", "7") + if err := os.MkdirAll(dir, 0o755); err != nil { + t.Fatal(err) + } + prJSON := `{"state":"OPEN","headRefOid":"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa","baseRefOid":"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb","author":{"login":"teammate"}}` + if err := os.WriteFile(filepath.Join(dir, "PR.json"), []byte(prJSON), 0o600); err != nil { + t.Fatal(err) + } + if err := os.WriteFile(filepath.Join(dir, "full.diff"), []byte("diff sentinel\n"), 0o600); err != nil { + t.Fatal(err) + } + return root, dir +} + +func onePendingPageJSON() string { + return `{"data":{"repository":{"pullRequest":{"reviewThreads":{"pageInfo":{"hasNextPage":false,"endCursor":null},"nodes":[ + {"id":"PRRT_1","isResolved":false,"isOutdated":false,"path":"a.go","line":10,"startLine":null,"diffSide":"RIGHT","comments":{"totalCount":2,"nodes":[ + {"id":"101","databaseId":101,"author":{"__typename":"Bot","login":"verdict-bot"},"body":"finding\n\n","createdAt":"2026-11-01T00:00:00Z","url":"https://example.invalid/101"}, + {"id":"102","databaseId":102,"author":{"__typename":"User","login":"alice"},"body":"why?","createdAt":"2026-11-02T00:00:00Z","url":"https://example.invalid/102"} + ]}} + ]}}}}}` +} + +func twoPendingPageJSON() string { + return `{"data":{"repository":{"pullRequest":{"reviewThreads":{"pageInfo":{"hasNextPage":false,"endCursor":null},"nodes":[ + {"id":"PRRT_1","isResolved":false,"isOutdated":false,"path":"a.go","line":10,"startLine":null,"diffSide":"RIGHT","comments":{"totalCount":2,"nodes":[ + {"id":"101","databaseId":101,"author":{"__typename":"Bot","login":"verdict-bot"},"body":"finding\n\n","createdAt":"2026-11-01T00:00:00Z","url":"https://example.invalid/101"}, + {"id":"102","databaseId":102,"author":{"__typename":"User","login":"alice"},"body":"why?","createdAt":"2026-11-02T00:00:00Z","url":"https://example.invalid/102"} + ]}}, + {"id":"PRRT_2","isResolved":false,"isOutdated":false,"path":"b.go","line":20,"startLine":null,"diffSide":"RIGHT","comments":{"totalCount":2,"nodes":[ + {"id":"201","databaseId":201,"author":{"__typename":"Bot","login":"verdict-bot"},"body":"finding\n\n","createdAt":"2026-11-01T00:00:00Z","url":"https://example.invalid/201"}, + {"id":"202","databaseId":202,"author":{"__typename":"User","login":"bob"},"body":"is this wrong?","createdAt":"2026-11-02T00:00:00Z","url":"https://example.invalid/202"} + ]}} + ]}}}}}` +} + +func writePlanAndDrafts(t *testing.T, dir, provider string, replies []draincore.Reply, overrideDigest string) { + t.Helper() + pending := []draincore.Pending{ + { + ThreadID: "PRRT_1", RootCommentID: "101", WaitingCommentID: "102", + WaitingAuthor: "alice", WaitingAt: "2026-11-02T00:00:00Z", Path: "a.go", + }, + { + ThreadID: "PRRT_2", RootCommentID: "201", WaitingCommentID: "202", + WaitingAuthor: "bob", WaitingAt: "2026-11-02T00:00:00Z", Path: "b.go", + }, + } + digest := draincore.Digest(pending) + plan := &draincore.File{ + SchemaVersion: draincore.SchemaVersion, + Provider: provider, + PR: 7, + HeadSHA: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + PlannedAt: "2026-11-17T11:00:00Z", + Self: "verdict-bot", + PlanDigest: digest, + Pending: pending, + Skipped: []draincore.Skip{}, + Posted: []draincore.Posted{}, + Failed: []draincore.Failed{}, + } + if err := draincore.WritePlan(filepath.Join(dir, draincore.KeyPlanJSON), plan); err != nil { + t.Fatal(err) + } + if replies == nil { + return + } + if overrideDigest != "" { + digest = overrideDigest + } + raw, err := json.Marshal(draincore.RepliesFile{ + SchemaVersion: draincore.SchemaVersion, + PlanDigest: digest, + Replies: replies, + }) + if err != nil { + t.Fatal(err) + } + if err := os.WriteFile(filepath.Join(dir, draincore.KeyDraftsJSON), raw, 0o600); err != nil { + t.Fatal(err) + } +} + +func TestPostLocalRefusalsMakeZeroHostCallsAndKeepThreadsUnchanged(t *testing.T) { + t.Parallel() + goodReplies := []draincore.Reply{ + {ThreadID: "PRRT_1", WaitingCommentID: "102", Disposition: draincore.DispositionAnswer, Body: "Answer one."}, + } + secretReplies := []draincore.Reply{ + {ThreadID: "PRRT_1", WaitingCommentID: "102", Disposition: draincore.DispositionAnswer, Body: "key AKIAIOSFODNN7EXAMPLE"}, + } + + cases := []struct { + name string + args []string + setup func(t *testing.T, dir string) + wantCode string + }{ + { + name: "unsupported provider flag without plan", + args: []string{"--provider", "forgejo", "--post"}, + setup: func(*testing.T, string) {}, + wantCode: "provider-unimplemented", + }, + { + name: "missing plan", + args: []string{"--post"}, + setup: func(*testing.T, string) {}, + wantCode: draincore.CodeDrainFailed, + }, + { + name: "provider flag disagrees with plan", + args: []string{"--provider", "gitlab", "--post"}, + setup: func(t *testing.T, dir string) { + writePlanAndDrafts(t, dir, "github", goodReplies, "") + }, + wantCode: draincore.CodeDrainFailed, + }, + { + name: "missing drafts file", + args: []string{"--post"}, + setup: func(t *testing.T, dir string) { + writePlanAndDrafts(t, dir, "github", nil, "") + }, + wantCode: draincore.CodeDraftsInvalid, + }, + { + name: "invalid drafts file", + args: []string{"--post"}, + setup: func(t *testing.T, dir string) { + writePlanAndDrafts(t, dir, "github", nil, "") + plan, err := draincore.ReadPlan(filepath.Join(dir, draincore.KeyPlanJSON)) + if err != nil { + t.Fatal(err) + } + bad := `{"schema_version":"1","plan_digest":"` + plan.PlanDigest + `","replies":[{"bad":true}]}` + if err := os.WriteFile(filepath.Join(dir, draincore.KeyDraftsJSON), []byte(bad), 0o600); err != nil { + t.Fatal(err) + } + }, + wantCode: draincore.CodeDraftsInvalid, + }, + { + name: "stale drafts file", + args: []string{"--post"}, + setup: func(t *testing.T, dir string) { + writePlanAndDrafts(t, dir, "github", goodReplies, "old-digest") + }, + wantCode: draincore.CodeDraftsStale, + }, + { + name: "unsupported plan provider", + args: []string{"--post"}, + setup: func(t *testing.T, dir string) { + writePlanAndDrafts(t, dir, "forgejo", goodReplies, "") + }, + wantCode: "provider-unimplemented", + }, + { + name: "secret-shaped draft body", + args: []string{"--post"}, + setup: func(t *testing.T, dir string) { + writePlanAndDrafts(t, dir, "github", secretReplies, "") + }, + wantCode: "post-secret-shaped", + }, + } + + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + t.Parallel() + root, dir := setupDrainBundle(t) + sentinel := []byte(`{"sentinel":true}` + "\n") + threadsPath := filepath.Join(dir, threadscore.KeyThreadsJSON) + if err := os.WriteFile(threadsPath, sentinel, 0o600); err != nil { + t.Fatal(err) + } + tc.setup(t, dir) + + cmdr := &drainHostStub{pageJSON: twoPendingPageJSON(), self: "verdict-bot"} + var out, diag bytes.Buffer + r := &cli.Runner{ + Out: &out, Diag: &diag, Human: &diag, + Now: func() time.Time { return time.Date(2026, 11, 17, 12, 0, 0, 0, time.UTC) }, + Cmd: "drain", JSONMode: true, Effective: cli.Defaults(), + } + req := Request{ + Runtime: &core.Runtime{Env: map[string]string{}, Commander: cmdr}, + Repo: "acme/app", + Pr: "7", + RepoRoot: root, + } + code := Run(context.Background(), r, tc.args, req) + if code != cli.ExitRefused { + t.Fatalf("exit = %d, want %d (out=%s diag=%s)", code, cli.ExitRefused, out.String(), diag.String()) + } + if calls := cmdr.callLog(); len(calls) != 0 { + t.Errorf("local refusal made %d host call(s): %v", len(calls), calls) + } + gotThreads, err := os.ReadFile(threadsPath) + if err != nil { + t.Fatal(err) + } + if !bytes.Equal(gotThreads, sentinel) { + t.Errorf("threads.json modified by local refusal: got %q, want %q", gotThreads, sentinel) + } + var env struct { + Error *struct { + Code string `json:"code"` + } `json:"error"` + } + if err := json.Unmarshal(out.Bytes(), &env); err != nil { + t.Fatalf("decode envelope: %v\n%s", err, out.String()) + } + if env.Error == nil || env.Error.Code != tc.wantCode { + t.Errorf("error.code = %+v, want %q", env.Error, tc.wantCode) + } + }) + } +} + +func TestPostCallOrderLocalChecksThenReadsThenWrites(t *testing.T) { + t.Parallel() + root, dir := setupDrainBundle(t) + replies := []draincore.Reply{ + {ThreadID: "PRRT_1", WaitingCommentID: "102", Disposition: draincore.DispositionAnswer, Body: "Answer one."}, + {ThreadID: "PRRT_2", WaitingCommentID: "202", Disposition: draincore.DispositionWithdraw, Body: "Answer two."}, + } + writePlanAndDrafts(t, dir, "github", replies, "") + + cmdr := &drainHostStub{pageJSON: twoPendingPageJSON(), self: "verdict-bot"} + var out, diag bytes.Buffer + r := &cli.Runner{ + Out: &out, Diag: &diag, Human: &diag, + Now: func() time.Time { return time.Date(2026, 11, 17, 12, 0, 0, 0, time.UTC) }, + Cmd: "drain", JSONMode: true, Effective: cli.Defaults(), + } + req := Request{ + Runtime: &core.Runtime{Env: map[string]string{}, Commander: cmdr}, + Repo: "acme/app", + Pr: "7", + RepoRoot: root, + } + if code := Run(context.Background(), r, []string{"--provider", "github", "--post"}, req); code != cli.ExitOK { + t.Fatalf("exit = %d, out=%s diag=%s", code, out.String(), diag.String()) + } + calls := cmdr.callLog() + if len(calls) != 5 { + t.Fatalf("call count = %d, want 5: %v", len(calls), calls) + } + for i, c := range calls { + t.Logf("host call %d: %s", i+1, c) + } + if !strings.Contains(calls[0], "api graphql") || strings.Contains(calls[0], "resolveReviewThread") { + t.Errorf("call[0] = %q, want thread refresh graphql", calls[0]) + } + if !strings.Contains(calls[1], "api user --jq .login") { + t.Errorf("call[1] = %q, want self login", calls[1]) + } + if !strings.Contains(calls[2], "comments/101/replies") { + t.Errorf("call[2] = %q, want reply 101", calls[2]) + } + if !strings.Contains(calls[3], "comments/201/replies") { + t.Errorf("call[3] = %q, want reply 201", calls[3]) + } + if !strings.Contains(calls[4], "resolveReviewThread") { + t.Errorf("call[4] = %q, want resolve PRRT_2", calls[4]) + } +} + +func TestPostIncompleteEmitsSingleJSONEnvelope(t *testing.T) { + t.Parallel() + root, dir := setupDrainBundle(t) + replies := []draincore.Reply{ + {ThreadID: "PRRT_1", WaitingCommentID: "102", Disposition: draincore.DispositionAnswer, Body: "Answer one."}, + {ThreadID: "PRRT_2", WaitingCommentID: "202", Disposition: draincore.DispositionAnswer, Body: "Answer two."}, + } + writePlanAndDrafts(t, dir, "github", replies, "") + + cmdr := &drainHostStub{pageJSON: twoPendingPageJSON(), self: "verdict-bot", failRootID: "201"} + var out, diag bytes.Buffer + r := &cli.Runner{ + Out: &out, Diag: &diag, Human: &diag, + Now: func() time.Time { return time.Date(2026, 11, 17, 12, 0, 0, 0, time.UTC) }, + Cmd: "drain", JSONMode: true, Effective: cli.Defaults(), + } + req := Request{ + Runtime: &core.Runtime{Env: map[string]string{}, Commander: cmdr}, + Repo: "acme/app", + Pr: "7", + RepoRoot: root, + } + code := Run(context.Background(), r, []string{"--post"}, req) + if code != cli.ExitRefused { + t.Fatalf("exit = %d, want %d (out=%s)", code, cli.ExitRefused, out.String()) + } + dec := json.NewDecoder(bytes.NewReader(out.Bytes())) + var env struct { + Verb string `json:"verb"` + Next string `json:"next"` + Data *draincore.File `json:"data"` + Error *struct { + Code string `json:"code"` + Message string `json:"message"` + } `json:"error"` + } + if err := dec.Decode(&env); err != nil { + t.Fatalf("decode first envelope: %v\n%s", err, out.String()) + } + var extra any + if err := dec.Decode(&extra); err != io.EOF { + t.Fatalf("stdout contained more than one JSON value (err=%v, extra=%v):\n%s", err, extra, out.String()) + } + if env.Error == nil || env.Error.Code != draincore.CodeDrainIncomplete { + t.Errorf("error = %+v, want %s", env.Error, draincore.CodeDrainIncomplete) + } + if env.Data == nil || len(env.Data.Posted) != 1 || len(env.Data.Failed) != 1 || env.Data.PostedAt == nil { + t.Errorf("data receipt = %+v, want 1 posted, 1 failed, non-nil posted_at", env.Data) + } + if !strings.Contains(env.Next, "--post") { + t.Errorf("next = %q, want --post re-run", env.Next) + } +} + +func TestPostConcurrentRunsSerialize(t *testing.T) { + t.Parallel() + root, dir := setupDrainBundle(t) + replies := []draincore.Reply{ + {ThreadID: "PRRT_1", WaitingCommentID: "102", Disposition: draincore.DispositionAnswer, Body: "Answer one."}, + {ThreadID: "PRRT_2", WaitingCommentID: "202", Disposition: draincore.DispositionAnswer, Body: "Answer two."}, + } + writePlanAndDrafts(t, dir, "github", replies, "") + + cmdr := &drainHostStub{ + pageJSON: twoPendingPageJSON(), + self: "verdict-bot", + postDelay: 80 * time.Millisecond, + } + start := make(chan struct{}) + var wg sync.WaitGroup + codes := make([]int, 2) + outs := make([]bytes.Buffer, 2) + diags := make([]bytes.Buffer, 2) + + for i := range 2 { + wg.Add(1) + go func(idx int) { + defer wg.Done() + <-start + r := &cli.Runner{ + Out: &outs[idx], Diag: &diags[idx], Human: &diags[idx], + Now: func() time.Time { return time.Date(2026, 11, 17, 12, 0, 0, 0, time.UTC) }, + Cmd: "drain", JSONMode: true, Effective: cli.Defaults(), + } + req := Request{ + Runtime: &core.Runtime{Env: map[string]string{}, Commander: cmdr}, + Repo: "acme/app", + Pr: "7", + RepoRoot: root, + } + codes[idx] = Run(context.Background(), r, []string{"--post"}, req) + }(i) + } + close(start) + wg.Wait() + + for i, code := range codes { + if code != cli.ExitOK { + t.Fatalf("worker %d exit = %d, out=%s, diag=%s", i, code, outs[i].String(), diags[i].String()) + } + } + if got := cmdr.postCount("PRRT_1"); got != 1 { + t.Errorf("PRRT_1 posts = %d, want 1", got) + } + if got := cmdr.postCount("PRRT_2"); got != 1 { + t.Errorf("PRRT_2 posts = %d, want 1", got) + } + entries, err := ReadLedger(filepath.Join(dir, draincore.KeyLedgerJSON)) + if err != nil || len(entries) != 2 { + t.Errorf("ledger = %+v (len %d), err=%v; want 2 entries", entries, len(entries), err) + } +} diff --git a/internal/drain/verb.go b/internal/drain/verb.go index 4dd5ef389..510fcaae0 100644 --- a/internal/drain/verb.go +++ b/internal/drain/verb.go @@ -47,10 +47,11 @@ type flags struct { // Run executes `drain [--provider

] [--max-threads ] // [--agent [--timeout ] [-- ]] [--post] [--json]`. Plan -// and draft modes never write to the host; --post validates the drafts first -// and then follows the ordered write path. +// and draft modes never write to the host; --agent --post plans, drafts, +// validates, and posts in one run; --post alone validates existing drafts +// locally before any host read. func Run(ctx context.Context, r *cli.Runner, args []string, req Request) int { - r.Repo, r.Pr = req.Repo, req.Pr + r.Cmd, r.Repo, r.Pr = verbDrain, req.Repo, req.Pr fl, code, done := parseFlags(r, args) if done { return code @@ -62,51 +63,60 @@ func Run(ctx context.Context, r *cli.Runner, args []string, req Request) int { if ref := preflight(req); ref != nil { return r.Refuse(ref) } - if fl.post { - return postMode(ctx, r, req, fl) + limit, code, done := parseLimit(r, fl.max) + if done { + return code } - resp, ref := fetchcore.RunThreads(ctx, refreshRequest(r, req, fl)) - if ref != nil { - return r.Refuse(drainFailed(ref.Message)) + if fl.post && fl.provider != "" { + if ref := checkThreadReplyCap(fl.provider); ref != nil { + return r.Refuse(ref) + } } - return finish(ctx, r, req, fl, resp) + if fl.agent != "" || !fl.post { + return runPlanAndMaybePost(ctx, r, req, fl, limit) + } + return postMode(ctx, r, req, fl) } -func preflight(req Request) *core.RefusalError { - dir, ref := readcommon.ResolveBundleDir(req.RepoRootPath(), req.Pr) +func runPlanAndMaybePost(ctx context.Context, r *cli.Runner, req Request, fl *flags, limit int) int { + resp, ref := fetchcore.RunThreads(ctx, refreshRequest(r, req, fl)) if ref != nil { - return drainFailed(ref.Message) + return r.Refuse(drainFailed(ref.Message)) } - if !readcommon.IsDir(dir) { - return drainFailed(fmt.Sprintf("missing bundle %s — fetch the PR first", dir)) + r.Warnings = resp.Warnings + if fl.post { + if ref := checkThreadReplyCap(resp.Data.Provider); ref != nil { + return r.Refuse(ref) + } } - return nil -} - -func drainFailed(msg string) *core.RefusalError { - return &core.RefusalError{Code: "drain-failed", Message: msg} -} - -func finish(ctx context.Context, r *cli.Runner, req Request, fl *flags, resp *fetchcore.ThreadsResponse) int { - in, code, done := readInputs(ctx, r, req, fl, resp) - if done { - return code + in, ref := readInputs(ctx, req, resp) + if ref != nil { + return r.Refuse(ref) } plan, _ := draincore.NewPlan(resp.Data.Provider, threadscore.PRNumber(req.Pr), resp.Data.HeadSHA, - req.TimeUTC(), in.self, in.feed, in.ledger, in.limit) + req.TimeUTC(), in.self, in.feed, in.ledger, limit) if err := draincore.WritePlan(in.dir+pathSep+draincore.KeyPlanJSON, plan); err != nil { return r.Refuse(drainFailed(fmt.Sprintf("could not write %s/%s: %v", in.dir, draincore.KeyPlanJSON, err))) } if fl.agent != "" && len(plan.Pending) > 0 { - code, done := draft(ctx, r, req, fl, in.dir, plan) - if done { + if code, done := draft(ctx, r, req, fl, in.dir, plan); done { return code } } - r.Warnings = append(r.Warnings, resp.Warnings...) - fmt.Fprintf(r.Human, "» %d pending, %d skipped -> %s/%s\n", len(plan.Pending), len(plan.Skipped), in.dir, draincore.KeyPlanJSON) + if fl.post && len(plan.Pending) > 0 { + return postMode(ctx, r, req, fl) + } + return finishPlan(r, req, fl, in.dir, plan) +} + +func finishPlan(r *cli.Runner, req Request, fl *flags, dir string, plan *draincore.File) int { + nextText := next(req, fl) + if fl.post { + nextText = postSuccessNext(req) + } + fmt.Fprintf(r.Human, "» %d pending, %d skipped -> %s/%s\n", len(plan.Pending), len(plan.Skipped), dir, draincore.KeyPlanJSON) if r.JSONMode { - env := core.RenderEnvelope(verbDrain, req.Repo, req.Pr, core.NowUTC(r.Now()), next(req, fl), + env := core.RenderEnvelope(verbDrain, req.Repo, req.Pr, core.NowUTC(r.Now()), nextText, r.Warnings, plan.Wire(), nil) fmt.Fprint(r.Out, jq.PrettyOrdered(env)) } @@ -118,34 +128,44 @@ type planInputs struct { feed *threadscore.File self string ledger []draincore.LedgerEntry - limit int } -func readInputs(ctx context.Context, r *cli.Runner, req Request, fl *flags, resp *fetchcore.ThreadsResponse) (*planInputs, int, bool) { +func readInputs(ctx context.Context, req Request, resp *fetchcore.ThreadsResponse) (*planInputs, *core.RefusalError) { dir, ref := readcommon.ResolveBundleDir(req.RepoRootPath(), req.Pr) if ref != nil { - return nil, r.Refuse(drainFailed(ref.Message)), true + return nil, drainFailed(ref.Message) } feed, err := threadscore.ReadFile(dir + pathSep + threadscore.KeyThreadsJSON) if err != nil { - return nil, r.Refuse(drainFailed(fmt.Sprintf("unreadable %s/threads.json: %v", dir, err))), true + return nil, drainFailed(fmt.Sprintf("unreadable %s/threads.json: %v", dir, err)) } if resp.Data.Truncated || feed.Truncated { - return nil, r.Refuse(drainFailed(dir + "/threads.json is truncated — refresh threads before draining")), true + return nil, drainFailed(dir + "/threads.json is truncated — refresh threads before draining") } self, ref := selfLogin(ctx, req, resp.Data.Provider) if ref != nil { - return nil, r.Refuse(ref), true + return nil, ref } ledger, err := ReadLedger(dir + pathSep + draincore.KeyLedgerJSON) if err != nil { - return nil, r.Refuse(drainFailed(err.Error())), true + return nil, drainFailed(err.Error()) } - limit, code, done := parseLimit(r, fl.max) - if done { - return nil, code, true + return &planInputs{dir: dir, feed: feed, self: self, ledger: ledger}, nil +} + +func preflight(req Request) *core.RefusalError { + dir, ref := readcommon.ResolveBundleDir(req.RepoRootPath(), req.Pr) + if ref != nil { + return drainFailed(ref.Message) } - return &planInputs{dir: dir, feed: feed, self: self, ledger: ledger, limit: limit}, 0, false + if !readcommon.IsDir(dir) { + return drainFailed(fmt.Sprintf("missing bundle %s — fetch the PR first", dir)) + } + return nil +} + +func drainFailed(msg string) *core.RefusalError { + return &core.RefusalError{Code: "drain-failed", Message: msg} } func parseLimit(r *cli.Runner, text string) (int, int, bool) { @@ -171,7 +191,7 @@ func selfLogin(ctx context.Context, req Request, provider string) (string, *core func next(req Request, fl *flags) string { if fl.agent != "" { - return "inspect the drafts in " + draincore.KeyDraftsJSON + " in this bundle" + return "post replies with verdict drain " + req.Repo + " " + req.Pr + " --post" } return "draft replies with verdict drain " + req.Repo + " " + req.Pr + " --agent " } @@ -295,7 +315,7 @@ func draft(ctx context.Context, r *cli.Runner, req Request, fl *flags, dir strin if ref != nil { return r.Refuse(ref), true } - r.Warnings = append(r.Warnings, res.Warnings...) + r.Warnings = res.Warnings raw, err := jq.CappedFile(dir+pathSep+draincore.KeyDraftsJSON, jq.MaxPRBytes) if err != nil { return r.Refuse(&core.RefusalError{Code: "no-review-artifact", Message: err.Error()}), true diff --git a/internal/drain/verb_test.go b/internal/drain/verb_test.go index 3aea400f2..0f047bece 100644 --- a/internal/drain/verb_test.go +++ b/internal/drain/verb_test.go @@ -1,7 +1,11 @@ package drain import ( + "bytes" "context" + "encoding/json" + "os" + "path/filepath" "strings" "testing" "time" @@ -17,11 +21,24 @@ func (*stubCommander) Run(context.Context, *core.Command) (core.Result, error) { return core.Result{}, nil } -func TestNextAfterAgentDoesNotRecommendPost(t *testing.T) { +func TestNextAfterAgentRecommendsPost(t *testing.T) { t.Parallel() got := next(Request{Repo: "acme/app", Pr: "7"}, &flags{agent: "claude"}) - if !strings.Contains(got, draincore.KeyDraftsJSON) || strings.Contains(got, "--post") { - t.Errorf("next = %q, want an available step naming %s with no --post", got, draincore.KeyDraftsJSON) + const wantCmd = "verdict drain acme/app 7 --post" + if !strings.Contains(got, wantCmd) { + t.Fatalf("next = %q, want %q", got, wantCmd) + } + _, after, ok := strings.Cut(got, "verdict drain ") + if !ok { + t.Fatalf("next %q did not start command with verdict drain", got) + } + fields := strings.Fields(after) + if len(fields) < 3 || fields[0] != "acme/app" || fields[1] != "7" { + t.Fatalf("recommended args = %v, want repo pr --post", fields) + } + fl, code, done := parseFlags(&cli.Runner{}, fields[2:]) + if done || code != 0 || !fl.post { + t.Fatalf("recommended flags did not parse: fl=%+v code=%d done=%v", fl, code, done) } } @@ -46,3 +63,101 @@ func TestRefreshRequestKeepsInjectedCommander(t *testing.T) { t.Errorf("refresh commander = %T, want the injected commander", got.Commander) } } + +func TestRunAgentAndPostComposesOneRun(t *testing.T) { + root, dir := setupDrainBundle(t) + binDir := t.TempDir() + agentScript := filepath.Join(binDir, "claude") + script := `#!/bin/sh +set -eu +prompt="" +for arg in "$@"; do prompt="$arg"; done +target="${prompt#*Write exactly one file, }" +target="${target%%,*}" +plan_dir="$(dirname "$target")" +digest="$(sed -n 's/.*"plan_digest": *"\([^"]*\)".*/\1/p' "$plan_dir/drain.json" | head -n 1)" +printf '{"schema_version":"1","plan_digest":"%s","replies":[{"thread_id":"PRRT_1","waiting_comment_id":"102","disposition":"answer","body":"Answer one."}]}\n' "$digest" >"$target" +` + if err := os.WriteFile(agentScript, []byte(script), 0o700); err != nil { + t.Fatal(err) + } + t.Setenv("PATH", binDir+string(os.PathListSeparator)+os.Getenv("PATH")) + + cmdr := &drainHostStub{ + pageJSON: onePendingPageJSON(), + self: "verdict-bot", + } + var out, diag bytes.Buffer + r := &cli.Runner{ + Out: &out, Diag: &diag, Human: &diag, + Now: func() time.Time { return time.Date(2026, 11, 17, 12, 0, 0, 0, time.UTC) }, + Cmd: "drain", JSONMode: true, Effective: cli.Defaults(), + } + req := Request{ + Runtime: &core.Runtime{Env: map[string]string{}, Commander: cmdr}, + Repo: "acme/app", + Pr: "7", + RepoRoot: root, + } + code := Run(context.Background(), r, []string{"--agent", "claude", "--post"}, req) + if code != cli.ExitOK { + t.Fatalf("Run exit = %d, out=%s, diag=%s", code, out.String(), diag.String()) + } + var env struct { + Data *draincore.File `json:"data"` + Error *struct { + Code string `json:"code"` + } `json:"error"` + } + if err := json.Unmarshal(out.Bytes(), &env); err != nil { + t.Fatalf("decode envelope: %v\n%s", err, out.String()) + } + if env.Error != nil || env.Data == nil || env.Data.Drafts == nil || env.Data.Drafts.Count != 1 { + t.Fatalf("envelope = %+v", env) + } + if len(env.Data.Posted) != 1 || env.Data.Posted[0].ThreadID != "PRRT_1" || env.Data.Posted[0].ReplyID != "501" { + t.Fatalf("posted = %+v, want 1 posted reply 501", env.Data.Posted) + } + if cmdr.postCount("PRRT_1") != 1 { + t.Errorf("host post calls = %d, want 1 (calls=%v)", cmdr.postCount("PRRT_1"), cmdr.calls) + } + entries, err := ReadLedger(filepath.Join(dir, draincore.KeyLedgerJSON)) + if err != nil || len(entries) != 1 || entries[0].ReplyID != "501" { + t.Errorf("ledger = %+v, err=%v", entries, err) + } +} + +func TestRunAgentAndPostZeroPendingSkipsLaunchAndPost(t *testing.T) { + t.Parallel() + root, _ := setupDrainBundle(t) + cmdr := &drainHostStub{ + pageJSON: `{"data":{"repository":{"pullRequest":{"reviewThreads":{"pageInfo":{"hasNextPage":false,"endCursor":null},"nodes":[]}}}}}`, + self: "verdict-bot", + } + var out, diag bytes.Buffer + r := &cli.Runner{ + Out: &out, Diag: &diag, Human: &diag, + Now: func() time.Time { return time.Date(2026, 11, 17, 12, 0, 0, 0, time.UTC) }, + Cmd: "drain", JSONMode: true, Effective: cli.Defaults(), + } + req := Request{ + Runtime: &core.Runtime{Env: map[string]string{}, Commander: cmdr}, + Repo: "acme/app", + Pr: "7", + RepoRoot: root, + } + code := Run(context.Background(), r, []string{"--agent", "nonexistent-agent", "--post"}, req) + if code != cli.ExitOK { + t.Fatalf("Run exit = %d, out=%s, diag=%s", code, out.String(), diag.String()) + } + var env struct { + Data *draincore.File `json:"data"` + Error any `json:"error"` + } + if err := json.Unmarshal(out.Bytes(), &env); err != nil { + t.Fatalf("decode envelope: %v\n%s", err, out.String()) + } + if env.Error != nil || env.Data == nil || len(env.Data.Pending) != 0 || len(env.Data.Posted) != 0 { + t.Errorf("envelope = %+v, want 0 pending, 0 posted, nil error", env) + } +} From 0294169ee78eb37984034624888c90d1ae8bc79f Mon Sep 17 00:00:00 2001 From: Sutu Sebastian Date: Tue, 17 Nov 2026 15:09:52 +0200 Subject: [PATCH 09/14] chore(drain): drop unexported narration comments flagged in review --- internal/core/hostcaps.go | 3 +-- internal/core/post/host.go | 4 ---- internal/core/post/host_reply.go | 7 ------- internal/core/threads/threads.go | 3 --- 4 files changed, 1 insertion(+), 16 deletions(-) diff --git a/internal/core/hostcaps.go b/internal/core/hostcaps.go index 890199ff3..79a023a82 100644 --- a/internal/core/hostcaps.go +++ b/internal/core/hostcaps.go @@ -71,8 +71,7 @@ const ( // it has no documented resolve endpoint, so resolution stays a manual // host/CLI step there. reasonNoResolveMutation = "no-resolve-mutation" - // reasonNoThreadReply names a posting host with no reply endpoint. - reasonNoThreadReply = "no-thread-reply" + reasonNoThreadReply = "no-thread-reply" ) // CapabilityGap is one absent capability and the code that says why. diff --git a/internal/core/post/host.go b/internal/core/post/host.go index 673c2d059..b324c9aef 100644 --- a/internal/core/post/host.go +++ b/internal/core/post/host.go @@ -39,8 +39,6 @@ type hostResolver interface { repo, pr, threadID string) error } -// hostReplier is the reply half: the one call that answers a waiting comment -// in a thread verdict authored. Only hosts with a reply endpoint get one. type hostReplier interface { replyThread(ctx context.Context, cmdr Commander, env map[string]string, repo, pr, rootID, threadID, body string) (string, error) @@ -64,8 +62,6 @@ func hostFor(provider string) (hostWriter, hostReader, hostResolver) { } } -// replierFor is post mode's only reply-provider switch. A host with no reply -// endpoint gets nil, and the capability gate refuses before a call is built. func replierFor(provider string) hostReplier { switch provider { case providerGitHub: diff --git a/internal/core/post/host_reply.go b/internal/core/post/host_reply.go index 40a3d0629..9d4b6c24a 100644 --- a/internal/core/post/host_reply.go +++ b/internal/core/post/host_reply.go @@ -9,8 +9,6 @@ import ( "github.com/stainless-code/verdict/internal/jq" ) -// replyThread posts one drain reply on GitHub as a direct reply to the root -// comment. The body is one -f field, never part of a shell command. func (githubHost) replyThread(ctx context.Context, cmdr Commander, _ map[string]string, repo, pr, rootID, _, body string, ) (string, error) { @@ -30,9 +28,6 @@ func (githubHost) replyThread(ctx context.Context, cmdr Commander, _ map[string] return replyID(res.Stdout) } -// replyThread posts one drain reply as a GitLab discussion note. Like the -// other GitLab writes, the JSON body arrives on stdin with the content type -// pinned on argv. func (gitlabHost) replyThread(ctx context.Context, cmdr Commander, _ map[string]string, repo, pr, _, threadID, body string, ) (string, error) { @@ -53,8 +48,6 @@ func (gitlabHost) replyThread(ctx context.Context, cmdr Commander, _ map[string] return replyID(res.Stdout) } -// replyID reads the new note id from a host reply. Both hosts accept a number -// or a string; a reply the host did not identify cannot enter the ledger. func replyID(stdout string) (string, error) { doc, err := jq.Decode([]byte(stdout)) if err != nil { diff --git a/internal/core/threads/threads.go b/internal/core/threads/threads.go index 2c19d0ac8..277299b14 100644 --- a/internal/core/threads/threads.go +++ b/internal/core/threads/threads.go @@ -311,11 +311,8 @@ const summaryMarkerFormat = "" // distinct from both finding and review markers. var summaryMarkerRe = regexp.MustCompile(`^$`) -// replyMarkerFormat is the hidden final line drain appends to a posted reply. -// It binds the reply to the thread and the waiting comment it answers. const replyMarkerFormat = "" -// replyMarkerRe reads only a final line whose ids carry no whitespace. var replyMarkerRe = regexp.MustCompile(`^$`) // SummaryMarker renders the hidden final line of a PR-level summary comment. From f1bc11a64c9a7248010c087a6b534805afabd71f Mon Sep 17 00:00:00 2001 From: Sutu Sebastian Date: Tue, 17 Nov 2026 15:10:50 +0200 Subject: [PATCH 10/14] test(evals): cover drain --agent --post one-run path and updated next hint --- evals/cases/drain-plan.sh | 2 +- evals/cases/drain-post.sh | 24 ++++++++++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/evals/cases/drain-plan.sh b/evals/cases/drain-plan.sh index 92f88989c..d68be8262 100755 --- a/evals/cases/drain-plan.sh +++ b/evals/cases/drain-plan.sh @@ -140,7 +140,7 @@ chmod +x "$EVAL_STUBBIN/claude" export DRAIN_AGENT_MODE=good run_review drain acme/app 7 --agent claude --json if [ "$EVAL_STATUS" -eq 0 ] && jq -e '.data.drafts.count == 1 and .data.drafts.dispositions.answer == 1 - and (.next | contains("drain.replies.json")) and (.next | contains("--post") | not)' <"$EVAL_OUT" >/dev/null; then + and (.next | contains("verdict drain acme/app 7 --post"))' <"$EVAL_OUT" >/dev/null; then good "P7 a good stub draft validates and lands in the plan" else bad "P7 draft: exit $EVAL_STATUS $(head -c 500 "$EVAL_ERR") $(head -c 500 "$EVAL_OUT")" diff --git a/evals/cases/drain-post.sh b/evals/cases/drain-post.sh index a4e782cd9..905334068 100644 --- a/evals/cases/drain-post.sh +++ b/evals/cases/drain-post.sh @@ -28,6 +28,7 @@ HUMAN2="$(comment 202 bob User 2026-11-02T00:00:00Z 'is this wrong?')" jq -n --argjson a "$(node PRRT_1 a.go "[$ROOT1,$HUMAN1]")" \ --argjson b "$(node PRRT_2 b.go "[$ROOT2,$HUMAN2]")" \ '{data:{repository:{pullRequest:{reviewThreads:{pageInfo:{hasNextPage:false,endCursor:null},nodes:[$a,$b]}}}}}' >"$EVAL_SANDBOX/page.json" +cp "$EVAL_SANDBOX/page.json" "$EVAL_SANDBOX/page.initial.json" MARK1="" MARK2="" @@ -88,12 +89,18 @@ chmod +x "$EVAL_STUBBIN/gh" cat >"$EVAL_STUBBIN/claude" <<'AGENT' #!/usr/bin/env bash +set -euo pipefail echo "stub-agent $*" >>"$EVAL_STUBLOG" -digest="$(jq -r .plan_digest .verdict/state/7/drain.json)" +prompt="${@: -1}" +target="${prompt#*Write exactly one file, }" +target="${target%%,*}" +[ -n "$target" ] && [ "$target" != "$prompt" ] +plan="$(dirname "$target")/drain.json" +digest="$(jq -r .plan_digest "$plan")" jq -n --arg digest "$digest" '{schema_version:"1",plan_digest:$digest,replies:[ {thread_id:"PRRT_1",waiting_comment_id:"102",disposition:"answer",body:"Answer one."}, {thread_id:"PRRT_2",waiting_comment_id:"202",disposition:"withdraw",body:"Answer two."}]}' \ - >.verdict/state/7/drain.replies.json + >"$target" AGENT chmod +x "$EVAL_STUBBIN/claude" @@ -148,6 +155,19 @@ if [ "$EVAL_STATUS" -eq 0 ] && [ "$(grep -Ec 'POST|threadId=' "$EVAL_STUBLOG" || else bad "P6 rerun: exit $EVAL_STATUS $(head -c 400 "$EVAL_OUT")" fi + +cp "$EVAL_SANDBOX/page.initial.json" "$EVAL_SANDBOX/page.json" +rm -f "$DIR/replies.json" "$DIR/drain.json" "$DIR/drain.replies.json" +run_review drain acme/app 7 --agent claude --post --json +if [ "$EVAL_STATUS" -eq 0 ] && jq -e '.data.drafts.count == 2 and (.data.posted | length == 2) + and (.data.failed | length == 0) and .data.posted_at != null + and ((.data.posted | map(select(.disposition == "withdraw" and .resolved)) | length) == 1)' <"$EVAL_OUT" >/dev/null \ + && jq -e 'length == 2 and (map(.by) | all(. == "drain"))' "$DIR/replies.json" >/dev/null; then + good "P7 --agent --post plans, drafts, validates, and posts in one run" +else + bad "P7 one-run: exit $EVAL_STATUS $(head -c 500 "$EVAL_OUT") $(head -c 300 "$EVAL_ERR")" +fi + if matches 'unhandled gh call' "$EVAL_STUBLOG"; then bad "a later run made an unregistered gh call: $(cat "$EVAL_STUBLOG")" else From e6fbb7e9da29a347c3dfcf09b74a7c0ce375d996 Mon Sep 17 00:00:00 2001 From: Sutu Sebastian Date: Tue, 17 Nov 2026 15:13:50 +0200 Subject: [PATCH 11/14] refactor(drain): align structs and split helpers to satisfy lint rules --- internal/core/drain/post.go | 10 +- internal/core/drain/post_test.go | 37 +-- internal/drain/post.go | 34 ++- internal/drain/post_test.go | 437 ++++++++++++++----------------- internal/drain/verb.go | 67 +++-- internal/drain/verb_test.go | 46 ++-- 6 files changed, 310 insertions(+), 321 deletions(-) diff --git a/internal/core/drain/post.go b/internal/core/drain/post.go index cd4958fc3..ff846ee38 100644 --- a/internal/core/drain/post.go +++ b/internal/core/drain/post.go @@ -4,6 +4,7 @@ import ( "bytes" "encoding/json" "fmt" + "slices" "strings" "github.com/stainless-code/verdict/internal/core" @@ -104,14 +105,7 @@ func postDrafts(req *PostRequest) (*RepliesFile, *core.RefusalError) { func appendUniqueSkips(existing, extra []Skip) []Skip { for _, s := range extra { - dup := false - for _, prev := range existing { - if prev.ThreadID == s.ThreadID && prev.Reason == s.Reason { - dup = true - break - } - } - if !dup { + if !slices.Contains(existing, s) { existing = append(existing, s) } } diff --git a/internal/core/drain/post_test.go b/internal/core/drain/post_test.go index 8be9b0642..b671f7591 100644 --- a/internal/core/drain/post_test.go +++ b/internal/core/drain/post_test.go @@ -279,17 +279,10 @@ func TestPostAppendFailureRecordsFailedWithoutEmptyPosted(t *testing.T) { return nil } res, ref := Post(req) - if ref != nil { - t.Fatalf("Post refused: %+v", ref) - } - if !res.Incomplete || len(res.Posted) != 2 || len(res.Failed) != 1 { - t.Fatalf("result = %+v, want 2 posted, 1 failed, incomplete", res) - } - for _, p := range res.Posted { - if p.ThreadID == "" { - t.Errorf("empty Posted entry recorded on append failure: %+v", res.Posted) - } + if ref != nil || !res.Incomplete || len(res.Posted) != 2 || len(res.Failed) != 1 { + t.Fatalf("Post = (%+v, %+v), want 2 posted, 1 failed, incomplete", res, ref) } + assertNoEmptyPosted(t, res.Posted) if res.Failed[0].ThreadID != "PRRT_2" || !strings.Contains(res.Failed[0].Reason, "disk full") { t.Errorf("failed = %+v, want PRRT_2 disk full", res.Failed) } @@ -298,6 +291,15 @@ func TestPostAppendFailureRecordsFailedWithoutEmptyPosted(t *testing.T) { } } +func assertNoEmptyPosted(t *testing.T, posted []Posted) { + t.Helper() + for _, p := range posted { + if p.ThreadID == "" { + t.Errorf("empty Posted entry recorded on append failure: %+v", posted) + } + } +} + func TestValidatePostDraftsDoesNotMutatePlanOrDuplicateSkips(t *testing.T) { req, _, _ := postFixture(t, nil) raw, err := json.Marshal(RepliesFile{ @@ -323,13 +325,18 @@ func TestValidatePostDraftsDoesNotMutatePlanOrDuplicateSkips(t *testing.T) { if ref != nil || len(res.Posted) != 1 { t.Fatalf("Post = (%+v, %+v)", res, ref) } - noDraftCount := 0 - for _, s := range req.Plan.Skipped { + assertNoDraftCount(t, req.Plan.Skipped, 2) +} + +func assertNoDraftCount(t *testing.T, skipped []Skip, want int) { + t.Helper() + got := 0 + for _, s := range skipped { if s.Reason == ReasonNoDraft { - noDraftCount++ + got++ } } - if noDraftCount != 2 { - t.Errorf("no-draft skips = %d, want 2 (no duplicates): %+v", noDraftCount, req.Plan.Skipped) + if got != want { + t.Errorf("no-draft skips = %d, want %d: %+v", got, want, skipped) } } diff --git a/internal/drain/post.go b/internal/drain/post.go index f22dfdb3d..90c1514ab 100644 --- a/internal/drain/post.go +++ b/internal/drain/post.go @@ -20,22 +20,10 @@ import ( ) func postMode(ctx context.Context, r *cli.Runner, req Request, fl *flags) int { - if fl.provider != "" { - if ref := checkThreadReplyCap(fl.provider); ref != nil { - return r.Refuse(ref) - } - } - dir, plan, ref := postPlan(req, fl) - if ref != nil { - return r.Refuse(ref) - } - drafts, ref := postDraftsFile(dir) + dir, plan, drafts, ref := postPreflight(req, fl) if ref != nil { return r.Refuse(ref) } - if _, _, _, ref := draincore.ValidatePostDrafts(plan, drafts, plan.Provider); ref != nil { - return r.Refuse(ref) - } unlock, err := storelock.Acquire(filepath.Join(dir, verbDrain), storelock.DefaultWait) if err != nil { return r.Refuse(drainFailed(fmt.Sprintf("could not lock %s: %v", dir, err))) @@ -57,6 +45,26 @@ func postMode(ctx context.Context, r *cli.Runner, req Request, fl *flags) int { return postFinish(r, req, dir, plan, resp, result) } +func postPreflight(req Request, fl *flags) (string, *draincore.File, []byte, *core.RefusalError) { + if fl.provider != "" { + if ref := checkThreadReplyCap(fl.provider); ref != nil { + return "", nil, nil, ref + } + } + dir, plan, ref := postPlan(req, fl) + if ref != nil { + return "", nil, nil, ref + } + drafts, ref := postDraftsFile(dir) + if ref != nil { + return "", nil, nil, ref + } + if _, _, _, ref := draincore.ValidatePostDrafts(plan, drafts, plan.Provider); ref != nil { + return "", nil, nil, ref + } + return dir, plan, drafts, nil +} + func checkThreadReplyCap(provider string) *core.RefusalError { caps := core.CapabilitiesFor(provider) if !caps.ThreadReply { diff --git a/internal/drain/post_test.go b/internal/drain/post_test.go index 1d42706c5..cb30766b5 100644 --- a/internal/drain/post_test.go +++ b/internal/drain/post_test.go @@ -19,60 +19,79 @@ import ( ) type drainHostStub struct { - mu sync.Mutex + postedCount map[string]int pageJSON string self string - calls []string failRootID string + calls []string postDelay time.Duration - postedCount map[string]int + mu sync.Mutex } func (s *drainHostStub) Run(_ context.Context, cmd *core.Command) (core.Result, error) { joined := strings.Join(cmd.Argv, " ") + s.recordCall(joined) + if isPostReply(cmd.Argv) { + s.maybeDelay() + return s.handlePostReply(cmd.Argv[4], joined) + } + return s.handleReadOrResolve(cmd.Argv, joined) +} + +func (s *drainHostStub) recordCall(joined string) { s.mu.Lock() + defer s.mu.Unlock() s.calls = append(s.calls, joined) - delay := s.postDelay - if delay > 0 && len(s.postedCount) == 0 && len(cmd.Argv) >= 4 && cmd.Argv[1] == "--method" && cmd.Argv[2] == "POST" { - s.mu.Unlock() - time.Sleep(delay) - s.mu.Lock() - } if s.postedCount == nil { s.postedCount = map[string]int{} } +} + +func (s *drainHostStub) maybeDelay() { + s.mu.Lock() + delay := s.postDelay + first := len(s.postedCount) == 0 s.mu.Unlock() + if delay > 0 && first { + time.Sleep(delay) + } +} - if len(cmd.Argv) >= 4 && cmd.Argv[0] == "gh" && cmd.Argv[1] == "api" && cmd.Argv[2] == "user" { +func (s *drainHostStub) handlePostReply(endpoint, joined string) (core.Result, error) { + if s.failRootID != "" && strings.Contains(endpoint, "/comments/"+s.failRootID+"/replies") { + return core.Result{ExitCode: 1, Stderr: "host rejected reply"}, nil + } + for rootID, info := range map[string]struct{ thread, out string }{ + "/comments/101/replies": {"PRRT_1", `{"id":501}`}, + "/comments/201/replies": {"PRRT_2", `{"id":502}`}, + } { + if strings.Contains(endpoint, rootID) { + s.mu.Lock() + s.postedCount[info.thread]++ + s.mu.Unlock() + return core.Result{Stdout: info.out}, nil + } + } + return core.Result{ExitCode: 1, Stderr: "unexpected command: " + joined}, nil +} + +func (s *drainHostStub) handleReadOrResolve(argv []string, joined string) (core.Result, error) { + if len(argv) >= 4 && argv[0] == "gh" && argv[1] == "api" && argv[2] == "user" { return core.Result{Stdout: s.self + "\n"}, nil } - if len(cmd.Argv) >= 3 && cmd.Argv[0] == "gh" && cmd.Argv[1] == "api" && cmd.Argv[2] == "graphql" { + if len(argv) >= 3 && argv[0] == "gh" && argv[1] == "api" && argv[2] == "graphql" { if strings.Contains(joined, "resolveReviewThread") { return core.Result{Stdout: `{"data":{"resolveReviewThread":{"thread":{"id":"PRRT_2","isResolved":true}}}}`}, nil } return core.Result{Stdout: s.pageJSON}, nil } - if len(cmd.Argv) >= 4 && cmd.Argv[0] == "gh" && cmd.Argv[1] == "api" && cmd.Argv[2] == "--method" && cmd.Argv[3] == "POST" { - endpoint := cmd.Argv[4] - if s.failRootID != "" && strings.Contains(endpoint, "/comments/"+s.failRootID+"/replies") { - return core.Result{ExitCode: 1, Stderr: "host rejected reply"}, nil - } - s.mu.Lock() - switch { - case strings.Contains(endpoint, "/comments/101/replies"): - s.postedCount["PRRT_1"]++ - s.mu.Unlock() - return core.Result{Stdout: `{"id":501}`}, nil - case strings.Contains(endpoint, "/comments/201/replies"): - s.postedCount["PRRT_2"]++ - s.mu.Unlock() - return core.Result{Stdout: `{"id":502}`}, nil - } - s.mu.Unlock() - } return core.Result{ExitCode: 1, Stderr: "unexpected command: " + joined}, nil } +func isPostReply(argv []string) bool { + return len(argv) >= 5 && argv[0] == "gh" && argv[1] == "api" && argv[2] == "--method" && argv[3] == "POST" +} + func (s *drainHostStub) postCount(threadID string) int { s.mu.Lock() defer s.mu.Unlock() @@ -102,6 +121,24 @@ func setupDrainBundle(t *testing.T) (string, string) { return root, dir } +func runDrainTest(t *testing.T, root string, cmdr core.Commander, args []string) (outStr, diagStr string, code int) { + t.Helper() + var out, diag bytes.Buffer + r := &cli.Runner{ + Out: &out, Diag: &diag, Human: &diag, + Now: func() time.Time { return time.Date(2026, 11, 17, 12, 0, 0, 0, time.UTC) }, + Cmd: "drain", JSONMode: true, Effective: cli.Defaults(), + } + req := Request{ + Runtime: &core.Runtime{Env: map[string]string{}, Commander: cmdr}, + Repo: "acme/app", + Pr: "7", + RepoRoot: root, + } + code = Run(context.Background(), r, args, req) + return out.String(), diag.String(), code +} + func onePendingPageJSON() string { return `{"data":{"repository":{"pullRequest":{"reviewThreads":{"pageInfo":{"hasNextPage":false,"endCursor":null},"nodes":[ {"id":"PRRT_1","isResolved":false,"isOutdated":false,"path":"a.go","line":10,"startLine":null,"diffSide":"RIGHT","comments":{"totalCount":2,"nodes":[ @@ -124,7 +161,7 @@ func twoPendingPageJSON() string { ]}}}}}` } -func writePlanAndDrafts(t *testing.T, dir, provider string, replies []draincore.Reply, overrideDigest string) { +func writePlanAndDrafts(t *testing.T, dir, provider string, replies []draincore.Reply, overrideDigest string) string { t.Helper() pending := []draincore.Pending{ { @@ -154,7 +191,7 @@ func writePlanAndDrafts(t *testing.T, dir, provider string, replies []draincore. t.Fatal(err) } if replies == nil { - return + return digest } if overrideDigest != "" { digest = overrideDigest @@ -170,6 +207,17 @@ func writePlanAndDrafts(t *testing.T, dir, provider string, replies []draincore. if err := os.WriteFile(filepath.Join(dir, draincore.KeyDraftsJSON), raw, 0o600); err != nil { t.Fatal(err) } + return plan.PlanDigest +} + +type localRefusalCase struct { + name string + planProvider string + overrideDigest string + wantCode string + args []string + replies []draincore.Reply + rawBadDrafts bool } func TestPostLocalRefusalsMakeZeroHostCallsAndKeepThreadsUnchanged(t *testing.T) { @@ -181,135 +229,88 @@ func TestPostLocalRefusalsMakeZeroHostCallsAndKeepThreadsUnchanged(t *testing.T) {ThreadID: "PRRT_1", WaitingCommentID: "102", Disposition: draincore.DispositionAnswer, Body: "key AKIAIOSFODNN7EXAMPLE"}, } - cases := []struct { - name string - args []string - setup func(t *testing.T, dir string) - wantCode string - }{ - { - name: "unsupported provider flag without plan", - args: []string{"--provider", "forgejo", "--post"}, - setup: func(*testing.T, string) {}, - wantCode: "provider-unimplemented", - }, - { - name: "missing plan", - args: []string{"--post"}, - setup: func(*testing.T, string) {}, - wantCode: draincore.CodeDrainFailed, - }, - { - name: "provider flag disagrees with plan", - args: []string{"--provider", "gitlab", "--post"}, - setup: func(t *testing.T, dir string) { - writePlanAndDrafts(t, dir, "github", goodReplies, "") - }, - wantCode: draincore.CodeDrainFailed, - }, - { - name: "missing drafts file", - args: []string{"--post"}, - setup: func(t *testing.T, dir string) { - writePlanAndDrafts(t, dir, "github", nil, "") - }, - wantCode: draincore.CodeDraftsInvalid, - }, - { - name: "invalid drafts file", - args: []string{"--post"}, - setup: func(t *testing.T, dir string) { - writePlanAndDrafts(t, dir, "github", nil, "") - plan, err := draincore.ReadPlan(filepath.Join(dir, draincore.KeyPlanJSON)) - if err != nil { - t.Fatal(err) - } - bad := `{"schema_version":"1","plan_digest":"` + plan.PlanDigest + `","replies":[{"bad":true}]}` - if err := os.WriteFile(filepath.Join(dir, draincore.KeyDraftsJSON), []byte(bad), 0o600); err != nil { - t.Fatal(err) - } - }, - wantCode: draincore.CodeDraftsInvalid, - }, - { - name: "stale drafts file", - args: []string{"--post"}, - setup: func(t *testing.T, dir string) { - writePlanAndDrafts(t, dir, "github", goodReplies, "old-digest") - }, - wantCode: draincore.CodeDraftsStale, - }, - { - name: "unsupported plan provider", - args: []string{"--post"}, - setup: func(t *testing.T, dir string) { - writePlanAndDrafts(t, dir, "forgejo", goodReplies, "") - }, - wantCode: "provider-unimplemented", - }, - { - name: "secret-shaped draft body", - args: []string{"--post"}, - setup: func(t *testing.T, dir string) { - writePlanAndDrafts(t, dir, "github", secretReplies, "") - }, - wantCode: "post-secret-shaped", - }, + cases := []localRefusalCase{ + {name: "unsupported provider flag without plan", args: []string{"--provider", "forgejo", "--post"}, wantCode: "provider-unimplemented"}, + {name: "missing plan", args: []string{"--post"}, wantCode: draincore.CodeDrainFailed}, + {name: "provider flag disagrees with plan", args: []string{"--provider", "gitlab", "--post"}, planProvider: "github", replies: goodReplies, wantCode: draincore.CodeDrainFailed}, + {name: "missing drafts file", args: []string{"--post"}, planProvider: "github", wantCode: draincore.CodeDraftsInvalid}, + {name: "invalid drafts file", args: []string{"--post"}, planProvider: "github", rawBadDrafts: true, wantCode: draincore.CodeDraftsInvalid}, + {name: "stale drafts file", args: []string{"--post"}, planProvider: "github", replies: goodReplies, overrideDigest: "old-digest", wantCode: draincore.CodeDraftsStale}, + {name: "unsupported plan provider", args: []string{"--post"}, planProvider: "forgejo", replies: goodReplies, wantCode: "provider-unimplemented"}, + {name: "secret-shaped draft body", args: []string{"--post"}, planProvider: "github", replies: secretReplies, wantCode: "post-secret-shaped"}, } - for _, tc := range cases { + for i := range cases { + tc := &cases[i] t.Run(tc.name, func(t *testing.T) { t.Parallel() - root, dir := setupDrainBundle(t) - sentinel := []byte(`{"sentinel":true}` + "\n") - threadsPath := filepath.Join(dir, threadscore.KeyThreadsJSON) - if err := os.WriteFile(threadsPath, sentinel, 0o600); err != nil { - t.Fatal(err) - } - tc.setup(t, dir) - - cmdr := &drainHostStub{pageJSON: twoPendingPageJSON(), self: "verdict-bot"} - var out, diag bytes.Buffer - r := &cli.Runner{ - Out: &out, Diag: &diag, Human: &diag, - Now: func() time.Time { return time.Date(2026, 11, 17, 12, 0, 0, 0, time.UTC) }, - Cmd: "drain", JSONMode: true, Effective: cli.Defaults(), - } - req := Request{ - Runtime: &core.Runtime{Env: map[string]string{}, Commander: cmdr}, - Repo: "acme/app", - Pr: "7", - RepoRoot: root, - } - code := Run(context.Background(), r, tc.args, req) - if code != cli.ExitRefused { - t.Fatalf("exit = %d, want %d (out=%s diag=%s)", code, cli.ExitRefused, out.String(), diag.String()) - } - if calls := cmdr.callLog(); len(calls) != 0 { - t.Errorf("local refusal made %d host call(s): %v", len(calls), calls) - } - gotThreads, err := os.ReadFile(threadsPath) - if err != nil { - t.Fatal(err) - } - if !bytes.Equal(gotThreads, sentinel) { - t.Errorf("threads.json modified by local refusal: got %q, want %q", gotThreads, sentinel) - } - var env struct { - Error *struct { - Code string `json:"code"` - } `json:"error"` - } - if err := json.Unmarshal(out.Bytes(), &env); err != nil { - t.Fatalf("decode envelope: %v\n%s", err, out.String()) - } - if env.Error == nil || env.Error.Code != tc.wantCode { - t.Errorf("error.code = %+v, want %q", env.Error, tc.wantCode) - } + runLocalRefusalCase(t, tc) }) } } +func runLocalRefusalCase(t *testing.T, tc *localRefusalCase) { + t.Helper() + root, dir := setupDrainBundle(t) + sentinel := []byte(`{"sentinel":true}` + "\n") + threadsPath := filepath.Join(dir, threadscore.KeyThreadsJSON) + if err := os.WriteFile(threadsPath, sentinel, 0o600); err != nil { + t.Fatal(err) + } + prepareLocalRefusalFixture(t, dir, tc) + cmdr := &drainHostStub{pageJSON: twoPendingPageJSON(), self: "verdict-bot"} + out, diag, code := runDrainTest(t, root, cmdr, tc.args) + if code != cli.ExitRefused { + t.Fatalf("exit = %d, want %d (out=%s diag=%s)", code, cli.ExitRefused, out, diag) + } + if calls := cmdr.callLog(); len(calls) != 0 { + t.Errorf("local refusal made %d host call(s): %v", len(calls), calls) + } + assertSentinelBytes(t, threadsPath, sentinel) + assertRefusalCode(t, out, tc.wantCode) +} + +func prepareLocalRefusalFixture(t *testing.T, dir string, tc *localRefusalCase) { + t.Helper() + if tc.planProvider == "" { + return + } + digest := writePlanAndDrafts(t, dir, tc.planProvider, tc.replies, tc.overrideDigest) + if !tc.rawBadDrafts { + return + } + bad := `{"schema_version":"1","plan_digest":"` + digest + `","replies":[{"bad":true}]}` + if err := os.WriteFile(filepath.Join(dir, draincore.KeyDraftsJSON), []byte(bad), 0o600); err != nil { + t.Fatal(err) + } +} + +func assertSentinelBytes(t *testing.T, path string, want []byte) { + t.Helper() + got, err := os.ReadFile(path) + if err != nil { + t.Fatal(err) + } + if !bytes.Equal(got, want) { + t.Errorf("threads.json modified by local refusal: got %q, want %q", got, want) + } +} + +func assertRefusalCode(t *testing.T, out, wantCode string) { + t.Helper() + var env struct { + Error *struct { + Code string `json:"code"` + } `json:"error"` + } + if err := json.Unmarshal([]byte(out), &env); err != nil { + t.Fatalf("decode envelope: %v\n%s", err, out) + } + if env.Error == nil || env.Error.Code != wantCode { + t.Errorf("error.code = %+v, want %q", env.Error, wantCode) + } +} + func TestPostCallOrderLocalChecksThenReadsThenWrites(t *testing.T) { t.Parallel() root, dir := setupDrainBundle(t) @@ -318,44 +319,27 @@ func TestPostCallOrderLocalChecksThenReadsThenWrites(t *testing.T) { {ThreadID: "PRRT_2", WaitingCommentID: "202", Disposition: draincore.DispositionWithdraw, Body: "Answer two."}, } writePlanAndDrafts(t, dir, "github", replies, "") - cmdr := &drainHostStub{pageJSON: twoPendingPageJSON(), self: "verdict-bot"} - var out, diag bytes.Buffer - r := &cli.Runner{ - Out: &out, Diag: &diag, Human: &diag, - Now: func() time.Time { return time.Date(2026, 11, 17, 12, 0, 0, 0, time.UTC) }, - Cmd: "drain", JSONMode: true, Effective: cli.Defaults(), - } - req := Request{ - Runtime: &core.Runtime{Env: map[string]string{}, Commander: cmdr}, - Repo: "acme/app", - Pr: "7", - RepoRoot: root, - } - if code := Run(context.Background(), r, []string{"--provider", "github", "--post"}, req); code != cli.ExitOK { - t.Fatalf("exit = %d, out=%s diag=%s", code, out.String(), diag.String()) + out, diag, code := runDrainTest(t, root, cmdr, []string{"--provider", "github", "--post"}) + if code != cli.ExitOK { + t.Fatalf("exit = %d, out=%s diag=%s", code, out, diag) } - calls := cmdr.callLog() + assertHostCallOrder(t, cmdr.callLog()) +} + +func assertHostCallOrder(t *testing.T, calls []string) { + t.Helper() if len(calls) != 5 { t.Fatalf("call count = %d, want 5: %v", len(calls), calls) } for i, c := range calls { t.Logf("host call %d: %s", i+1, c) } - if !strings.Contains(calls[0], "api graphql") || strings.Contains(calls[0], "resolveReviewThread") { - t.Errorf("call[0] = %q, want thread refresh graphql", calls[0]) - } - if !strings.Contains(calls[1], "api user --jq .login") { - t.Errorf("call[1] = %q, want self login", calls[1]) - } - if !strings.Contains(calls[2], "comments/101/replies") { - t.Errorf("call[2] = %q, want reply 101", calls[2]) - } - if !strings.Contains(calls[3], "comments/201/replies") { - t.Errorf("call[3] = %q, want reply 201", calls[3]) - } - if !strings.Contains(calls[4], "resolveReviewThread") { - t.Errorf("call[4] = %q, want resolve PRRT_2", calls[4]) + wants := []string{"api graphql", "api user --jq .login", "comments/101/replies", "comments/201/replies", "resolveReviewThread"} + for i, want := range wants { + if !strings.Contains(calls[i], want) { + t.Errorf("call[%d] = %q, want substring %q", i, calls[i], want) + } } } @@ -367,40 +351,32 @@ func TestPostIncompleteEmitsSingleJSONEnvelope(t *testing.T) { {ThreadID: "PRRT_2", WaitingCommentID: "202", Disposition: draincore.DispositionAnswer, Body: "Answer two."}, } writePlanAndDrafts(t, dir, "github", replies, "") - cmdr := &drainHostStub{pageJSON: twoPendingPageJSON(), self: "verdict-bot", failRootID: "201"} - var out, diag bytes.Buffer - r := &cli.Runner{ - Out: &out, Diag: &diag, Human: &diag, - Now: func() time.Time { return time.Date(2026, 11, 17, 12, 0, 0, 0, time.UTC) }, - Cmd: "drain", JSONMode: true, Effective: cli.Defaults(), - } - req := Request{ - Runtime: &core.Runtime{Env: map[string]string{}, Commander: cmdr}, - Repo: "acme/app", - Pr: "7", - RepoRoot: root, - } - code := Run(context.Background(), r, []string{"--post"}, req) + out, _, code := runDrainTest(t, root, cmdr, []string{"--post"}) if code != cli.ExitRefused { - t.Fatalf("exit = %d, want %d (out=%s)", code, cli.ExitRefused, out.String()) + t.Fatalf("exit = %d, want %d (out=%s)", code, cli.ExitRefused, out) } - dec := json.NewDecoder(bytes.NewReader(out.Bytes())) + assertSingleIncompleteEnvelope(t, out) +} + +func assertSingleIncompleteEnvelope(t *testing.T, out string) { + t.Helper() + dec := json.NewDecoder(strings.NewReader(out)) var env struct { - Verb string `json:"verb"` - Next string `json:"next"` Data *draincore.File `json:"data"` Error *struct { Code string `json:"code"` Message string `json:"message"` } `json:"error"` + Verb string `json:"verb"` + Next string `json:"next"` } if err := dec.Decode(&env); err != nil { - t.Fatalf("decode first envelope: %v\n%s", err, out.String()) + t.Fatalf("decode first envelope: %v\n%s", err, out) } var extra any if err := dec.Decode(&extra); err != io.EOF { - t.Fatalf("stdout contained more than one JSON value (err=%v, extra=%v):\n%s", err, extra, out.String()) + t.Fatalf("stdout contained more than one JSON value (err=%v, extra=%v):\n%s", err, extra, out) } if env.Error == nil || env.Error.Code != draincore.CodeDrainIncomplete { t.Errorf("error = %+v, want %s", env.Error, draincore.CodeDrainIncomplete) @@ -421,53 +397,38 @@ func TestPostConcurrentRunsSerialize(t *testing.T) { {ThreadID: "PRRT_2", WaitingCommentID: "202", Disposition: draincore.DispositionAnswer, Body: "Answer two."}, } writePlanAndDrafts(t, dir, "github", replies, "") - - cmdr := &drainHostStub{ - pageJSON: twoPendingPageJSON(), - self: "verdict-bot", - postDelay: 80 * time.Millisecond, + cmdr := &drainHostStub{pageJSON: twoPendingPageJSON(), self: "verdict-bot", postDelay: 80 * time.Millisecond} + codes, outs, diags := runConcurrentPosts(t, root, cmdr) + for i, code := range codes { + if code != cli.ExitOK { + t.Fatalf("worker %d exit = %d, out=%s, diag=%s", i, code, outs[i], diags[i]) + } } + if cmdr.postCount("PRRT_1") != 1 || cmdr.postCount("PRRT_2") != 1 { + t.Errorf("post counts = (1:%d, 2:%d), want (1, 1)", cmdr.postCount("PRRT_1"), cmdr.postCount("PRRT_2")) + } + entries, err := ReadLedger(filepath.Join(dir, draincore.KeyLedgerJSON)) + if err != nil || len(entries) != 2 { + t.Errorf("ledger = %+v (len %d), err=%v; want 2 entries", entries, len(entries), err) + } +} + +func runConcurrentPosts(t *testing.T, root string, cmdr *drainHostStub) ([]int, []string, []string) { + t.Helper() start := make(chan struct{}) var wg sync.WaitGroup codes := make([]int, 2) - outs := make([]bytes.Buffer, 2) - diags := make([]bytes.Buffer, 2) - + outs := make([]string, 2) + diags := make([]string, 2) for i := range 2 { wg.Add(1) go func(idx int) { defer wg.Done() <-start - r := &cli.Runner{ - Out: &outs[idx], Diag: &diags[idx], Human: &diags[idx], - Now: func() time.Time { return time.Date(2026, 11, 17, 12, 0, 0, 0, time.UTC) }, - Cmd: "drain", JSONMode: true, Effective: cli.Defaults(), - } - req := Request{ - Runtime: &core.Runtime{Env: map[string]string{}, Commander: cmdr}, - Repo: "acme/app", - Pr: "7", - RepoRoot: root, - } - codes[idx] = Run(context.Background(), r, []string{"--post"}, req) + outs[idx], diags[idx], codes[idx] = runDrainTest(t, root, cmdr, []string{"--post"}) }(i) } close(start) wg.Wait() - - for i, code := range codes { - if code != cli.ExitOK { - t.Fatalf("worker %d exit = %d, out=%s, diag=%s", i, code, outs[i].String(), diags[i].String()) - } - } - if got := cmdr.postCount("PRRT_1"); got != 1 { - t.Errorf("PRRT_1 posts = %d, want 1", got) - } - if got := cmdr.postCount("PRRT_2"); got != 1 { - t.Errorf("PRRT_2 posts = %d, want 1", got) - } - entries, err := ReadLedger(filepath.Join(dir, draincore.KeyLedgerJSON)) - if err != nil || len(entries) != 2 { - t.Errorf("ledger = %+v (len %d), err=%v; want 2 entries", entries, len(entries), err) - } + return codes, outs, diags } diff --git a/internal/drain/verb.go b/internal/drain/verb.go index 510fcaae0..2da02080b 100644 --- a/internal/drain/verb.go +++ b/internal/drain/verb.go @@ -52,61 +52,82 @@ type flags struct { // locally before any host read. func Run(ctx context.Context, r *cli.Runner, args []string, req Request) int { r.Cmd, r.Repo, r.Pr = verbDrain, req.Repo, req.Pr - fl, code, done := parseFlags(r, args) + fl, limit, code, done := parseRunArgs(ctx, r, args, req) if done { return code } + if fl.agent != "" || !fl.post { + return runPlanAndMaybePost(ctx, r, req, fl, limit) + } + return postMode(ctx, r, req, fl) +} + +func parseRunArgs(ctx context.Context, r *cli.Runner, args []string, req Request) (*flags, int, int, bool) { + fl, code, done := parseFlags(r, args) + if done { + return nil, 0, code, true + } r.RouteHuman() if code, done := r.Canceled(ctx, verbDrain); done { - return code + return nil, 0, code, true } if ref := preflight(req); ref != nil { - return r.Refuse(ref) + return nil, 0, r.Refuse(ref), true } limit, code, done := parseLimit(r, fl.max) if done { - return code + return nil, 0, code, true + } + if ref := checkPostProviderCap(fl); ref != nil { + return nil, 0, r.Refuse(ref), true } + return fl, limit, 0, false +} + +func checkPostProviderCap(fl *flags) *core.RefusalError { if fl.post && fl.provider != "" { - if ref := checkThreadReplyCap(fl.provider); ref != nil { - return r.Refuse(ref) + return checkThreadReplyCap(fl.provider) + } + return nil +} + +func runPlanAndMaybePost(ctx context.Context, r *cli.Runner, req Request, fl *flags, limit int) int { + dir, plan, code, done := buildPlan(ctx, r, req, fl, limit) + if done { + return code + } + if fl.agent != "" && len(plan.Pending) > 0 { + if code, done := draft(ctx, r, req, fl, dir, plan); done { + return code } } - if fl.agent != "" || !fl.post { - return runPlanAndMaybePost(ctx, r, req, fl, limit) + if fl.post && len(plan.Pending) > 0 { + return postMode(ctx, r, req, fl) } - return postMode(ctx, r, req, fl) + return finishPlan(r, req, fl, dir, plan) } -func runPlanAndMaybePost(ctx context.Context, r *cli.Runner, req Request, fl *flags, limit int) int { +func buildPlan(ctx context.Context, r *cli.Runner, req Request, fl *flags, limit int) (string, *draincore.File, int, bool) { resp, ref := fetchcore.RunThreads(ctx, refreshRequest(r, req, fl)) if ref != nil { - return r.Refuse(drainFailed(ref.Message)) + return "", nil, r.Refuse(drainFailed(ref.Message)), true } r.Warnings = resp.Warnings if fl.post { if ref := checkThreadReplyCap(resp.Data.Provider); ref != nil { - return r.Refuse(ref) + return "", nil, r.Refuse(ref), true } } in, ref := readInputs(ctx, req, resp) if ref != nil { - return r.Refuse(ref) + return "", nil, r.Refuse(ref), true } plan, _ := draincore.NewPlan(resp.Data.Provider, threadscore.PRNumber(req.Pr), resp.Data.HeadSHA, req.TimeUTC(), in.self, in.feed, in.ledger, limit) if err := draincore.WritePlan(in.dir+pathSep+draincore.KeyPlanJSON, plan); err != nil { - return r.Refuse(drainFailed(fmt.Sprintf("could not write %s/%s: %v", in.dir, draincore.KeyPlanJSON, err))) - } - if fl.agent != "" && len(plan.Pending) > 0 { - if code, done := draft(ctx, r, req, fl, in.dir, plan); done { - return code - } - } - if fl.post && len(plan.Pending) > 0 { - return postMode(ctx, r, req, fl) + return "", nil, r.Refuse(drainFailed(fmt.Sprintf("could not write %s/%s: %v", in.dir, draincore.KeyPlanJSON, err))), true } - return finishPlan(r, req, fl, in.dir, plan) + return in.dir, plan, 0, false } func finishPlan(r *cli.Runner, req Request, fl *flags, dir string, plan *draincore.File) int { diff --git a/internal/drain/verb_test.go b/internal/drain/verb_test.go index 0f047bece..7092c573c 100644 --- a/internal/drain/verb_test.go +++ b/internal/drain/verb_test.go @@ -66,8 +66,18 @@ func TestRefreshRequestKeepsInjectedCommander(t *testing.T) { func TestRunAgentAndPostComposesOneRun(t *testing.T) { root, dir := setupDrainBundle(t) + installStubClaude(t) + cmdr := &drainHostStub{pageJSON: onePendingPageJSON(), self: "verdict-bot"} + out, diag, code := runDrainTest(t, root, cmdr, []string{"--agent", "claude", "--post"}) + if code != cli.ExitOK { + t.Fatalf("Run exit = %d, out=%s, diag=%s", code, out, diag) + } + assertOneRunPosted(t, out, dir, cmdr) +} + +func installStubClaude(t *testing.T) { + t.Helper() binDir := t.TempDir() - agentScript := filepath.Join(binDir, "claude") script := `#!/bin/sh set -eu prompt="" @@ -78,39 +88,22 @@ plan_dir="$(dirname "$target")" digest="$(sed -n 's/.*"plan_digest": *"\([^"]*\)".*/\1/p' "$plan_dir/drain.json" | head -n 1)" printf '{"schema_version":"1","plan_digest":"%s","replies":[{"thread_id":"PRRT_1","waiting_comment_id":"102","disposition":"answer","body":"Answer one."}]}\n' "$digest" >"$target" ` - if err := os.WriteFile(agentScript, []byte(script), 0o700); err != nil { + if err := os.WriteFile(filepath.Join(binDir, "claude"), []byte(script), 0o700); err != nil { t.Fatal(err) } t.Setenv("PATH", binDir+string(os.PathListSeparator)+os.Getenv("PATH")) +} - cmdr := &drainHostStub{ - pageJSON: onePendingPageJSON(), - self: "verdict-bot", - } - var out, diag bytes.Buffer - r := &cli.Runner{ - Out: &out, Diag: &diag, Human: &diag, - Now: func() time.Time { return time.Date(2026, 11, 17, 12, 0, 0, 0, time.UTC) }, - Cmd: "drain", JSONMode: true, Effective: cli.Defaults(), - } - req := Request{ - Runtime: &core.Runtime{Env: map[string]string{}, Commander: cmdr}, - Repo: "acme/app", - Pr: "7", - RepoRoot: root, - } - code := Run(context.Background(), r, []string{"--agent", "claude", "--post"}, req) - if code != cli.ExitOK { - t.Fatalf("Run exit = %d, out=%s, diag=%s", code, out.String(), diag.String()) - } +func assertOneRunPosted(t *testing.T, out, dir string, cmdr *drainHostStub) { + t.Helper() var env struct { Data *draincore.File `json:"data"` Error *struct { Code string `json:"code"` } `json:"error"` } - if err := json.Unmarshal(out.Bytes(), &env); err != nil { - t.Fatalf("decode envelope: %v\n%s", err, out.String()) + if err := json.Unmarshal([]byte(out), &env); err != nil { + t.Fatalf("decode envelope: %v\n%s", err, out) } if env.Error != nil || env.Data == nil || env.Data.Drafts == nil || env.Data.Drafts.Count != 1 { t.Fatalf("envelope = %+v", env) @@ -118,6 +111,11 @@ printf '{"schema_version":"1","plan_digest":"%s","replies":[{"thread_id":"PRRT_1 if len(env.Data.Posted) != 1 || env.Data.Posted[0].ThreadID != "PRRT_1" || env.Data.Posted[0].ReplyID != "501" { t.Fatalf("posted = %+v, want 1 posted reply 501", env.Data.Posted) } + assertOneRunLedgerAndCalls(t, dir, cmdr) +} + +func assertOneRunLedgerAndCalls(t *testing.T, dir string, cmdr *drainHostStub) { + t.Helper() if cmdr.postCount("PRRT_1") != 1 { t.Errorf("host post calls = %d, want 1 (calls=%v)", cmdr.postCount("PRRT_1"), cmdr.calls) } From 8efabd0807bb8c01bc16106f43a0d73923e66c58 Mon Sep 17 00:00:00 2001 From: Sutu Sebastian Date: Tue, 17 Nov 2026 15:15:24 +0200 Subject: [PATCH 12/14] chore(size): raise byte ratchet for drain post fixes darwin/amd64: 17537552 -> 17540000 linux/amd64: 17232032 -> 17240000 windows/amd64: 17626112 -> 17630000 --- scripts/size-baseline.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/size-baseline.txt b/scripts/size-baseline.txt index 69a57663e..dd324dc48 100644 --- a/scripts/size-baseline.txt +++ b/scripts/size-baseline.txt @@ -1,7 +1,7 @@ deps 0 -darwin/amd64 17530000 +darwin/amd64 17540000 darwin/arm64 15940000 -linux/amd64 17230000 +linux/amd64 17240000 linux/arm64 15600000 -windows/amd64 17620000 +windows/amd64 17630000 windows/arm64 15720000 From 81832f89b61d9ec29766ad9c99bc37013e14d291 Mon Sep 17 00:00:00 2001 From: Sutu Sebastian Date: Tue, 17 Nov 2026 15:24:56 +0200 Subject: [PATCH 13/14] fix(drain): emit drain-incomplete where the refusal registry scan sees it --- internal/core/drain/plan.go | 4 +--- internal/drain/post.go | 2 +- internal/drain/post_test.go | 4 ++-- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/internal/core/drain/plan.go b/internal/core/drain/plan.go index 2b7847065..212f237de 100644 --- a/internal/core/drain/plan.go +++ b/internal/core/drain/plan.go @@ -27,9 +27,7 @@ const ( CodeDraftsInvalid = "drafts-invalid" // CodeDraftsStale refuses a draft written against another plan. CodeDraftsStale = "drafts-stale" - // CodeDrainIncomplete refuses a post run after some writes failed. - CodeDrainIncomplete = "drain-incomplete" - keyThreadID = "thread_id" + keyThreadID = "thread_id" ) // Dispositions counts the draft verdicts the agent chose. diff --git a/internal/drain/post.go b/internal/drain/post.go index 90c1514ab..e322d63ce 100644 --- a/internal/drain/post.go +++ b/internal/drain/post.go @@ -177,7 +177,7 @@ func postFinish(r *cli.Runner, req Request, dir string, plan *draincore.File, fmt.Fprintf(r.Human, "» %d posted, %d failed -> %s/%s\n", len(result.Posted), len(result.Failed), dir, draincore.KeyPlanJSON) if result.Incomplete { - ref := &core.RefusalError{Code: draincore.CodeDrainIncomplete, Message: fmt.Sprintf( + ref := &core.RefusalError{Code: "drain-incomplete", Message: fmt.Sprintf( "%d thread(s) could not be posted; the ledger makes a re-run idempotent", len(result.Failed))} if !r.JSONMode { return r.Refuse(ref) diff --git a/internal/drain/post_test.go b/internal/drain/post_test.go index cb30766b5..0f1733e79 100644 --- a/internal/drain/post_test.go +++ b/internal/drain/post_test.go @@ -378,8 +378,8 @@ func assertSingleIncompleteEnvelope(t *testing.T, out string) { if err := dec.Decode(&extra); err != io.EOF { t.Fatalf("stdout contained more than one JSON value (err=%v, extra=%v):\n%s", err, extra, out) } - if env.Error == nil || env.Error.Code != draincore.CodeDrainIncomplete { - t.Errorf("error = %+v, want %s", env.Error, draincore.CodeDrainIncomplete) + if env.Error == nil || env.Error.Code != "drain-incomplete" { + t.Errorf("error = %+v, want %s", env.Error, "drain-incomplete") } if env.Data == nil || len(env.Data.Posted) != 1 || len(env.Data.Failed) != 1 || env.Data.PostedAt == nil { t.Errorf("data receipt = %+v, want 1 posted, 1 failed, non-nil posted_at", env.Data) From 32a54a247d2e107758e139b5614d330615e46a7b Mon Sep 17 00:00:00 2001 From: Sutu Sebastian Date: Tue, 17 Nov 2026 15:47:29 +0200 Subject: [PATCH 14/14] test(drain): keep shell agent stubs to unix builds --- internal/drain/post_test.go | 9 ---- internal/drain/verb_test.go | 63 ------------------------ internal/drain/verb_unix_test.go | 83 ++++++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+), 72 deletions(-) create mode 100644 internal/drain/verb_unix_test.go diff --git a/internal/drain/post_test.go b/internal/drain/post_test.go index 0f1733e79..a82915289 100644 --- a/internal/drain/post_test.go +++ b/internal/drain/post_test.go @@ -139,15 +139,6 @@ func runDrainTest(t *testing.T, root string, cmdr core.Commander, args []string) return out.String(), diag.String(), code } -func onePendingPageJSON() string { - return `{"data":{"repository":{"pullRequest":{"reviewThreads":{"pageInfo":{"hasNextPage":false,"endCursor":null},"nodes":[ - {"id":"PRRT_1","isResolved":false,"isOutdated":false,"path":"a.go","line":10,"startLine":null,"diffSide":"RIGHT","comments":{"totalCount":2,"nodes":[ - {"id":"101","databaseId":101,"author":{"__typename":"Bot","login":"verdict-bot"},"body":"finding\n\n","createdAt":"2026-11-01T00:00:00Z","url":"https://example.invalid/101"}, - {"id":"102","databaseId":102,"author":{"__typename":"User","login":"alice"},"body":"why?","createdAt":"2026-11-02T00:00:00Z","url":"https://example.invalid/102"} - ]}} - ]}}}}}` -} - func twoPendingPageJSON() string { return `{"data":{"repository":{"pullRequest":{"reviewThreads":{"pageInfo":{"hasNextPage":false,"endCursor":null},"nodes":[ {"id":"PRRT_1","isResolved":false,"isOutdated":false,"path":"a.go","line":10,"startLine":null,"diffSide":"RIGHT","comments":{"totalCount":2,"nodes":[ diff --git a/internal/drain/verb_test.go b/internal/drain/verb_test.go index 7092c573c..55092387f 100644 --- a/internal/drain/verb_test.go +++ b/internal/drain/verb_test.go @@ -4,8 +4,6 @@ import ( "bytes" "context" "encoding/json" - "os" - "path/filepath" "strings" "testing" "time" @@ -64,67 +62,6 @@ func TestRefreshRequestKeepsInjectedCommander(t *testing.T) { } } -func TestRunAgentAndPostComposesOneRun(t *testing.T) { - root, dir := setupDrainBundle(t) - installStubClaude(t) - cmdr := &drainHostStub{pageJSON: onePendingPageJSON(), self: "verdict-bot"} - out, diag, code := runDrainTest(t, root, cmdr, []string{"--agent", "claude", "--post"}) - if code != cli.ExitOK { - t.Fatalf("Run exit = %d, out=%s, diag=%s", code, out, diag) - } - assertOneRunPosted(t, out, dir, cmdr) -} - -func installStubClaude(t *testing.T) { - t.Helper() - binDir := t.TempDir() - script := `#!/bin/sh -set -eu -prompt="" -for arg in "$@"; do prompt="$arg"; done -target="${prompt#*Write exactly one file, }" -target="${target%%,*}" -plan_dir="$(dirname "$target")" -digest="$(sed -n 's/.*"plan_digest": *"\([^"]*\)".*/\1/p' "$plan_dir/drain.json" | head -n 1)" -printf '{"schema_version":"1","plan_digest":"%s","replies":[{"thread_id":"PRRT_1","waiting_comment_id":"102","disposition":"answer","body":"Answer one."}]}\n' "$digest" >"$target" -` - if err := os.WriteFile(filepath.Join(binDir, "claude"), []byte(script), 0o700); err != nil { - t.Fatal(err) - } - t.Setenv("PATH", binDir+string(os.PathListSeparator)+os.Getenv("PATH")) -} - -func assertOneRunPosted(t *testing.T, out, dir string, cmdr *drainHostStub) { - t.Helper() - var env struct { - Data *draincore.File `json:"data"` - Error *struct { - Code string `json:"code"` - } `json:"error"` - } - if err := json.Unmarshal([]byte(out), &env); err != nil { - t.Fatalf("decode envelope: %v\n%s", err, out) - } - if env.Error != nil || env.Data == nil || env.Data.Drafts == nil || env.Data.Drafts.Count != 1 { - t.Fatalf("envelope = %+v", env) - } - if len(env.Data.Posted) != 1 || env.Data.Posted[0].ThreadID != "PRRT_1" || env.Data.Posted[0].ReplyID != "501" { - t.Fatalf("posted = %+v, want 1 posted reply 501", env.Data.Posted) - } - assertOneRunLedgerAndCalls(t, dir, cmdr) -} - -func assertOneRunLedgerAndCalls(t *testing.T, dir string, cmdr *drainHostStub) { - t.Helper() - if cmdr.postCount("PRRT_1") != 1 { - t.Errorf("host post calls = %d, want 1 (calls=%v)", cmdr.postCount("PRRT_1"), cmdr.calls) - } - entries, err := ReadLedger(filepath.Join(dir, draincore.KeyLedgerJSON)) - if err != nil || len(entries) != 1 || entries[0].ReplyID != "501" { - t.Errorf("ledger = %+v, err=%v", entries, err) - } -} - func TestRunAgentAndPostZeroPendingSkipsLaunchAndPost(t *testing.T) { t.Parallel() root, _ := setupDrainBundle(t) diff --git a/internal/drain/verb_unix_test.go b/internal/drain/verb_unix_test.go new file mode 100644 index 000000000..8326aea44 --- /dev/null +++ b/internal/drain/verb_unix_test.go @@ -0,0 +1,83 @@ +//go:build unix + +package drain + +import ( + "encoding/json" + "os" + "path/filepath" + "testing" + + "github.com/stainless-code/verdict/internal/cli" + draincore "github.com/stainless-code/verdict/internal/core/drain" +) + +func TestRunAgentAndPostComposesOneRun(t *testing.T) { + root, dir := setupDrainBundle(t) + installStubClaude(t) + cmdr := &drainHostStub{pageJSON: onePendingPageJSON(), self: "verdict-bot"} + out, diag, code := runDrainTest(t, root, cmdr, []string{"--agent", "claude", "--post"}) + if code != cli.ExitOK { + t.Fatalf("Run exit = %d, out=%s, diag=%s", code, out, diag) + } + assertOneRunPosted(t, out, dir, cmdr) +} + +func installStubClaude(t *testing.T) { + t.Helper() + binDir := t.TempDir() + script := `#!/bin/sh +set -eu +prompt="" +for arg in "$@"; do prompt="$arg"; done +target="${prompt#*Write exactly one file, }" +target="${target%%,*}" +plan_dir="$(dirname "$target")" +digest="$(sed -n 's/.*"plan_digest": *"\([^"]*\)".*/\1/p' "$plan_dir/drain.json" | head -n 1)" +printf '{"schema_version":"1","plan_digest":"%s","replies":[{"thread_id":"PRRT_1","waiting_comment_id":"102","disposition":"answer","body":"Answer one."}]}\n' "$digest" >"$target" +` + if err := os.WriteFile(filepath.Join(binDir, "claude"), []byte(script), 0o700); err != nil { + t.Fatal(err) + } + t.Setenv("PATH", binDir+string(os.PathListSeparator)+os.Getenv("PATH")) +} + +func assertOneRunPosted(t *testing.T, out, dir string, cmdr *drainHostStub) { + t.Helper() + var env struct { + Data *draincore.File `json:"data"` + Error *struct { + Code string `json:"code"` + } `json:"error"` + } + if err := json.Unmarshal([]byte(out), &env); err != nil { + t.Fatalf("decode envelope: %v\n%s", err, out) + } + if env.Error != nil || env.Data == nil || env.Data.Drafts == nil || env.Data.Drafts.Count != 1 { + t.Fatalf("envelope = %+v", env) + } + if len(env.Data.Posted) != 1 || env.Data.Posted[0].ThreadID != "PRRT_1" || env.Data.Posted[0].ReplyID != "501" { + t.Fatalf("posted = %+v, want 1 posted reply 501", env.Data.Posted) + } + assertOneRunLedgerAndCalls(t, dir, cmdr) +} + +func assertOneRunLedgerAndCalls(t *testing.T, dir string, cmdr *drainHostStub) { + t.Helper() + if cmdr.postCount("PRRT_1") != 1 { + t.Errorf("host post calls = %d, want 1 (calls=%v)", cmdr.postCount("PRRT_1"), cmdr.calls) + } + entries, err := ReadLedger(filepath.Join(dir, draincore.KeyLedgerJSON)) + if err != nil || len(entries) != 1 || entries[0].ReplyID != "501" { + t.Errorf("ledger = %+v, err=%v", entries, err) + } +} + +func onePendingPageJSON() string { + return `{"data":{"repository":{"pullRequest":{"reviewThreads":{"pageInfo":{"hasNextPage":false,"endCursor":null},"nodes":[ + {"id":"PRRT_1","isResolved":false,"isOutdated":false,"path":"a.go","line":10,"startLine":null,"diffSide":"RIGHT","comments":{"totalCount":2,"nodes":[ + {"id":"101","databaseId":101,"author":{"__typename":"Bot","login":"verdict-bot"},"body":"finding\n\n","createdAt":"2026-11-01T00:00:00Z","url":"https://example.invalid/101"}, + {"id":"102","databaseId":102,"author":{"__typename":"User","login":"alice"},"body":"why?","createdAt":"2026-11-02T00:00:00Z","url":"https://example.invalid/102"} + ]}} + ]}}}}}` +}