Show a re-asked Publish as ready; check task ids only in preview hosts
Ruling R19: any go-ahead or Publish open in front of the person makes the job card ready (D5), a Publish asked again after going live failed too; after Not now the failed go-live reads stopped once the Assistant's turn ends. Ruling R20: the leak check parses link URLs and lets the task id through only as the preview host's first label (eq-<task>, tmp-<task>), never in a path, a query or another label.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
4 files changed,
+116
−54
.rastrillo/budgets.txt+1 −1internal/equipo/chat/jobs.go+12 −14internal/thintest/assistant_job_contract_test.go+13 −6internal/thintest/assistant_outcome_contract_test.go+90 −33
Intent
diff --git a/.rastrillo/budgets.txt b/.rastrillo/budgets.txt| index 0f90a9c7..83d36c4f 100644 |
| --- a/.rastrillo/budgets.txt |
| +++ b/.rastrillo/budgets.txt |
| @@ -71,7 +71,7 @@ perf GET /tasks/{id}/files/{file} skip Research kept images: the bytes of one im |
| perf GET /api/v1/runners skip Mac runners person API: bearer-only JSON for devices; the browser shows runners in the Team section. |
| time cmd/equipo-runner 60s TestReleaseRunnerHasNoFakeWorker builds the release runner and the thin package under testbuild (about 12s locally). |
| size internal/headless - 10368 End-to-end scenarios through a real runner and instance, browser drives and the Assistant's job threads included. Measured 10368 test lines. |
| -size internal/thintest - 26589 Contract and browser tests share one instance harness. Adds the job thread, card lane, page, title, job note and job card contracts. Measured 26589 test lines. |
| +size internal/thintest - 26653 Contract and browser tests share one instance harness. Adds the job thread, card lane, page, title, job note and job card contracts. Measured 26653 test lines. |
| perf GET /api/v1/projects/{id}/merge-policy skip Merge authority person API: bearer-only JSON for devices; the browser reads the policy on /projects/{id}. |
| perf GET /api/v1/usage skip Thin v1 person API: bearer-only JSON for devices; the browser reads usage through /usage. |
| perf GET /api/v1/advice skip Thin v1 person API: bearer-only JSON for devices; the browser reads advice through /usage and /conversation. |
diff --git a/internal/equipo/chat/jobs.go b/internal/equipo/chat/jobs.go| index c65fcfb9..00c8004d 100644 |
| --- a/internal/equipo/chat/jobs.go |
| +++ b/internal/equipo/chat/jobs.go |
| @@ -226,24 +226,22 @@ func (t *txn) jobState(h handoffRecord) (state, key string, first *wire.CardLink |
| if err != nil { |
| return "", "", nil, err |
| } |
| - _, cause, ended, err := t.jobStop(h, settled) |
| + _, _, ended, err := t.jobStop(h, settled) |
| if err != nil { |
| return "", "", nil, err |
| } |
| - // A Publish asked again because going live failed is not ready, as |
| - // the Assistant is told (jobNote): the job stopped. |
| - if cause != causeGoingLive { |
| - src, ready, err := t.readyCard(h) |
| - if err != nil { |
| - return "", "", nil, err |
| - } |
| - if ready { |
| - preview, err := t.taskPreview(src.TaskID) |
| - if err != nil || preview == "" { |
| - return wire.JobReady, "", nil, err |
| - } |
| - return wire.JobReady, "", &wire.CardLink{Label: t.copy("assistant.outcome.preview"), URL: preview}, nil |
| + // Any go-ahead or Publish open in front of the person is ready, a |
| + // Publish asked again because going live failed too (ruling R19). |
| + src, ready, err := t.readyCard(h) |
| + if err != nil { |
| + return "", "", nil, err |
| + } |
| + if ready { |
| + preview, err := t.taskPreview(src.TaskID) |
| + if err != nil || preview == "" { |
| + return wire.JobReady, "", nil, err |
| } |
| + return wire.JobReady, "", &wire.CardLink{Label: t.copy("assistant.outcome.preview"), URL: preview}, nil |
| } |
| if ended { |
| site, err := t.jobSite(h) |
diff --git a/internal/thintest/assistant_job_contract_test.go b/internal/thintest/assistant_job_contract_test.go| index c88560b4..1a5f00b0 100644 |
| --- a/internal/thintest/assistant_job_contract_test.go |
| +++ b/internal/thintest/assistant_job_contract_test.go |
| @@ -658,9 +658,10 @@ func TestContractTeamJobLeaksNoMachinery(t *testing.T) { |
| } |
| } |
| -// TestContractTeamJobGoingLiveFailed: a Publish asked again because going |
| -// live failed is not ready to try, as the Assistant is told: the job |
| -// works on until the Assistant's turn about it ends, then is stopped. |
| +// TestContractTeamJobGoingLiveFailed (ruling R19): a Publish asked |
| +// again because going live failed is ready to try (D5), as any open |
| +// Publish is. Once the person says Not now to it, the failed go-live |
| +// reads stopped, after the Assistant's turn about it ends. |
| func TestContractTeamJobGoingLiveFailed(t *testing.T) { |
| o := newTeamRig(t) |
| id, _, _, _ := o.mergedWebsite("jf", true) |
| @@ -682,13 +683,19 @@ func TestContractTeamJobGoingLiveFailed(t *testing.T) { |
| cards := o.coordinatorCards(wire.CardPublish, id) |
| return len(cards) == 2 && cards[1].State == wire.CardOpen |
| }) |
| - o.assistantCard("the Publish asked again", func(c wire.AssistantCard) bool { |
| + o.noteFor("the publish failure's note", blockedOn("going live failed, and they need to try it again")) |
| + again := o.assistantCard("the Publish asked again", func(c wire.AssistantCard) bool { |
| return isPublishOutcome(c) && c.ID != card.ID && c.State == wire.CardOpen |
| }) |
| - o.noteFor("the publish failure's note", blockedOn("going live failed, and they need to try it again")) |
| + if now := o.jobOf(request, "ready after going live failed", func(c wire.AssistantCard) bool { return c.State == wire.JobReady }); now.Result != equipo.RunnerCopy("assistant.job.ready") { |
| + t.Fatalf("after going live failed %+v", now) |
| + } |
| + if _, err := o.a.Answer(o.ctx, again.ID, wire.ChoiceNotNow, again.Revision); err != nil { |
| + t.Fatal(err) |
| + } |
| time.Sleep(20 * time.Millisecond) |
| if now := o.jobOf(request, "the job card", nil); now.State != wire.JobWorking { |
| - t.Fatalf("after going live failed %+v", now) |
| + t.Fatalf("after Not now, while the Assistant's turn waits %+v", now) |
| } |
| o.reply(o.turn) |
| u := o.message(wire.LaneAssistant) |
diff --git a/internal/thintest/assistant_outcome_contract_test.go b/internal/thintest/assistant_outcome_contract_test.go| index 9902ff8b..c3066f8d 100644 |
| --- a/internal/thintest/assistant_outcome_contract_test.go |
| +++ b/internal/thintest/assistant_outcome_contract_test.go |
| @@ -6,6 +6,7 @@ import ( |
| "encoding/json" |
| "fmt" |
| "net/http" |
| + "net/url" |
| "regexp" |
| "slices" |
| "strings" |
| @@ -805,50 +806,106 @@ func TestContractAssistantLaneLeaksNoMachinery(t *testing.T) { |
| } |
| } |
| -// noMachinery checks a decoded value from the Assistant lane for the |
| -// team's machinery: no forbidden text, no 40-hex SHA, no task id and |
| -// none of the team's keys. A card link's url may be a preview, whose |
| -// host is the devbox app Equipo names for the task (eq-<task>, |
| -// tmp-<task>; ruling R9): only there the task id is not refused; every |
| -// other rule holds for it too. |
| +// noMachinery fails t on the first piece of the team's machinery a |
| +// decoded value from the Assistant lane carries (machineryIn). |
| func noMachinery(t *testing.T, task string, forbidden []string) func(what string, v any, link bool) { |
| - hex := regexp.MustCompile(`[0-9a-f]{40}`) |
| - keys := []string{"task_id", "project_id", "preview_url", "site", "runner"} |
| - var check func(what string, v any, link bool) |
| - check = func(what string, v any, link bool) { |
| + return func(what string, v any, link bool) { |
| t.Helper() |
| - switch x := v.(type) { |
| - case string: |
| - for _, bad := range forbidden { |
| - if strings.Contains(x, bad) { |
| - t.Fatalf("%s says %q: %q", what, bad, x) |
| - } |
| + if bad := machineryIn(task, forbidden, v, link); bad != "" { |
| + t.Fatalf("%s %s", what, bad) |
| + } |
| + } |
| +} |
| + |
| +var sha40 = regexp.MustCompile(`[0-9a-f]{40}`) |
| + |
| +// machineryIn is the first piece of the team's machinery a decoded value |
| +// from the Assistant lane carries, said plainly ("" for none): forbidden |
| +// text, a 40-hex SHA, the task id or one of the team's keys. A card |
| +// link's url may be a preview, whose host is the devbox app Equipo |
| +// names for the task (eq-<task>, tmp-<task>; ruling R9): only there the |
| +// task id is not refused; every other rule holds for it too. |
| +func machineryIn(task string, forbidden []string, v any, link bool) string { |
| + keys := []string{"task_id", "project_id", "preview_url", "site", "runner"} |
| + switch x := v.(type) { |
| + case string: |
| + for _, bad := range forbidden { |
| + if strings.Contains(x, bad) { |
| + return fmt.Sprintf("says %q: %q", bad, x) |
| } |
| - if hex.MatchString(x) || !link && strings.Contains(x, task) { |
| - t.Fatalf("%s says the task or a SHA: %q", what, x) |
| + } |
| + rest := x |
| + if link { |
| + rest = previewHostless(x, task) |
| + } |
| + if sha40.MatchString(x) || strings.Contains(rest, task) { |
| + return fmt.Sprintf("says the task or a SHA: %q", x) |
| + } |
| + case []any: |
| + for _, e := range x { |
| + if bad := machineryIn(task, forbidden, e, false); bad != "" { |
| + return bad |
| } |
| - case []any: |
| - for _, e := range x { |
| - check(what, e, false) |
| + } |
| + case map[string]any: |
| + for key, e := range x { |
| + if slices.Contains(keys, key) { |
| + return fmt.Sprintf("has the key %q", key) |
| } |
| - case map[string]any: |
| - for key, e := range x { |
| - if slices.Contains(keys, key) { |
| - t.Fatalf("%s has the key %q", what, key) |
| - } |
| - if links, ok := e.([]any); ok && key == "links" { |
| - for _, l := range links { |
| - for lk, lv := range l.(map[string]any) { |
| - check(what, lv, lk == "url") |
| + if links, ok := e.([]any); ok && key == "links" { |
| + for _, l := range links { |
| + for lk, lv := range l.(map[string]any) { |
| + if bad := machineryIn(task, forbidden, lv, lk == "url"); bad != "" { |
| + return bad |
| } |
| } |
| - continue |
| } |
| - check(what, e, false) |
| + continue |
| + } |
| + if bad := machineryIn(task, forbidden, e, false); bad != "" { |
| + return bad |
| } |
| } |
| } |
| - return check |
| + return "" |
| +} |
| + |
| +// previewHostless is a link's url without its host's first label when |
| +// that label is the devbox app named for the task (eq-<task>, |
| +// tmp-<task>): the one place the task id may be (R9). Any other url, or |
| +// one that does not parse as an absolute url, is as it is. |
| +func previewHostless(raw, task string) string { |
| + u, err := url.Parse(raw) |
| + if err != nil || u.Host == "" { |
| + return raw |
| + } |
| + label, after, _ := strings.Cut(u.Host, ".") |
| + if label != "eq-"+task && label != "tmp-"+task { |
| + return raw |
| + } |
| + u.Host = "." + after |
| + return u.String() |
| +} |
| + |
| +// TestContractAssistantLeakCheckLinks (ruling R20): the leak check lets |
| +// the task id through only as a preview host's first label (eq-<task>, |
| +// tmp-<task>); in a link's path or query, another host label, or the |
| +// Equipo job link, it is machinery. |
| +func TestContractAssistantLeakCheckLinks(t *testing.T) { |
| + task := "k_7c4qhxw2" |
| + link := func(url string) any { |
| + return map[string]any{"links": []any{map[string]any{"label": "Try it", "url": url}}} |
| + } |
| + for _, ok := range []string{"https://eq-" + task + ".docs-t1.example.ts.net/", "https://tmp-" + task + ".docs-t1.example.ts.net/", "https://site.bds.oncarlos.com/", "http://127.0.0.1:1/jobs/h_abc"} { |
| + if bad := machineryIn(task, nil, link(ok), false); bad != "" { |
| + t.Errorf("%s refused: %s", ok, bad) |
| + } |
| + } |
| + for _, leak := range []string{"https://eq-" + task + ".docs-t1.example.ts.net/" + task, "https://eq-" + task + ".docs-t1.example.ts.net/?t=" + task, "https://site.example.com/" + task, "https://x." + "eq-" + task + ".example.com/", "https://" + task + ".example.com/", "http://127.0.0.1:1/jobs/" + task, "https://eq-" + task + "x.example.com/", "not a url " + task} { |
| + if bad := machineryIn(task, nil, link(leak), false); bad == "" { |
| + t.Errorf("%s let through", leak) |
| + } |
| + } |
| } |
| // cardKeys checks a decoded Assistant card has exactly its keys: the |