webui.Server declared Cfg *config.Holder with eight read sites, none of
which ran in the UI process: composition leaves it nil there. The field
survived because the daemon kept a webui.Server it never served, using it
to render the published ConfigView snapshot and to hold the readiness
probes (archie-core-ml30).
Split at the producer. LocalConfigView becomes webui.BuildConfigView, a
pure function over a ConfigViewInput the configuration owner assembles;
the DTO and its schema stay where the UI renders them. The daemon builds
that input from its own state (boot.configViewInput) and publishes the
result. Readiness reads the daemon's Holder, channel manager and chat
contract, and the registry it produces is a daemon field, not a field on
a server with no listener. Boot now owns one Holder instead of seeding a
second and replacing it in buildDaemon; operator retry caps read it too,
so they follow a reload rather than a boot-time snapshot.
Server loses Cfg, ConfigProvenance, LastReload, ConfigOverrides and
SetProvenance. The nil-guarded branches they fed went with them, each
checked first against what the UI process actually serves:
- chat.show_tool_calls and the /api/setup checklist were degraded, not
dead. ConfigView gains a chat section carrying show_tool_calls, the
operator name and whether a channel is configured, and both surfaces
read the projection. The end-to-end suite asserts the checklist renders
from the published snapshot.
- /api/logs takes its path as a process-local option. The history is on
the daemon's disk, so a dashboard elsewhere cannot read it by learning
the path; that route still needs a contract.
- handleChannels drops its config-derived fallback, superseded by the
status manager, which already carries the descriptions and detail.
- trustForwardedHeaders keeps only the process's own setting, which the
UI process already sets.
- resolveForge keeps the published-projection path it already had.
ConfigView.Editable moves to handleConfig, decided by whether this
process holds UpdateConfig. It describes the writer, not the document, so
the write contract (archie-core-j28m) makes the page editable by wiring
one field. The write handlers and their seams stay for it.
overlay.Store gains Keys: Snapshot nests dotted keys for decoding, so the
overridden-key list was publishing section names ("budgets") where the
dashboard marks and resets rows by stored key ("budgets.max_steps").
Multi-identity forge links move to archie-core-pv6t: forgeConfigForTask
resolved a task's forge from config.Config, had no reachable caller once
the holder was gone, and belongs in the projection rather than the
rendering package.
129 lines
4.4 KiB
Go
129 lines
4.4 KiB
Go
package archied
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"log/slog"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"path/filepath"
|
|
"strconv"
|
|
"testing"
|
|
|
|
"github.com/samcharles93/archie-core/internal/config"
|
|
"github.com/samcharles93/archie-core/internal/domain/workflow"
|
|
"github.com/samcharles93/archie-core/internal/gateway"
|
|
"github.com/samcharles93/archie-core/internal/store"
|
|
"github.com/samcharles93/archie-core/internal/webui"
|
|
)
|
|
|
|
// The dashboard and chat both let an operator approve or decline a task, and
|
|
// they had drifted: declining from the dashboard left the task
|
|
// closed_wont_do, cancelling the same task from chat left it rejected. Two
|
|
// operators looking at one queue saw different states for the same decision,
|
|
// and "rejected" -- which reconcilePRs uses for a pull request closed without
|
|
// merging -- no longer meant one thing.
|
|
//
|
|
// This drives both real surfaces against one store and asserts they agree.
|
|
// It lives in cmd/archied because that is the only place both are wired.
|
|
func TestDashboardAndChatAgreeOnTerminalStates(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
// viaChat runs the action through the chat router; otherwise it
|
|
// goes through the dashboard's HTTP handler.
|
|
viaChat bool
|
|
action string
|
|
want string
|
|
}{
|
|
{name: "dashboard reject", action: "reject", want: workflow.StatusClosedWontDo},
|
|
{name: "chat cancel", viaChat: true, action: "cancel", want: workflow.StatusClosedWontDo},
|
|
{name: "dashboard approve", action: "approve", want: workflow.StatusQueued},
|
|
{name: "chat approve", viaChat: true, action: "approve", want: workflow.StatusQueued},
|
|
}
|
|
|
|
for _, tc := range tests {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
ctx := context.Background()
|
|
st, err := store.Open(ctx, filepath.Join(t.TempDir(), "tasks.db"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
t.Cleanup(func() { _ = st.Close() })
|
|
|
|
task, err := st.EnqueueChatTask(ctx, "acme", "widget", "decide on me", "", "", "reviewer")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := st.Transition(ctx, task.ID, workflow.StatusQueued, workflow.StatusWaitingHuman, "await"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if tc.viaChat {
|
|
runChatAction(t, ctx, st, tc.action, task.ID)
|
|
} else {
|
|
runDashboardAction(t, ctx, st, tc.action, task.ID)
|
|
}
|
|
|
|
got, err := st.TaskByID(ctx, task.ID)
|
|
if err != nil || got == nil {
|
|
t.Fatalf("TaskByID = (%+v, %v)", got, err)
|
|
}
|
|
if got.Status != tc.want {
|
|
t.Errorf("status = %q, want %q: the two surfaces disagree about "+
|
|
"what this action means", got.Status, tc.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
// runChatAction performs the approve/cancel action through the chat
|
|
// controller path and fails the test on error.
|
|
func runChatAction(t *testing.T, ctx context.Context, st store.TaskStore, action string, taskID int64) {
|
|
t.Helper()
|
|
controller := gateway.NewStoreTaskController(chatTaskControllerAdapter{
|
|
taskByID: st.TaskByID,
|
|
requeue: st.Requeue,
|
|
transition: st.Transition,
|
|
})
|
|
var err error
|
|
if action == "approve" {
|
|
err = controller.Approve(ctx, taskID, "reviewer")
|
|
} else {
|
|
err = controller.Cancel(ctx, taskID, "reviewer")
|
|
}
|
|
if err != nil {
|
|
t.Fatalf("chat %s: %v", action, err)
|
|
}
|
|
}
|
|
|
|
// runDashboardAction performs the approve/cancel action through the
|
|
// dashboard's HTTP handler and fails the test when the request is
|
|
// rejected.
|
|
func runDashboardAction(t *testing.T, ctx context.Context, st store.TaskStore, action string, taskID int64) {
|
|
t.Helper()
|
|
// The dashboard reaches task actions through the Gateway contract, which
|
|
// in production carries them back to this daemon's own service. Wiring
|
|
// that service behind a local adapter keeps both surfaces in this test
|
|
// driving the one implementation, which is the whole point of it.
|
|
actor := testTaskActor{&boot{
|
|
st: st, stateStore: st,
|
|
cfg: config.Config{MaxRetries: 3},
|
|
cfgHolder: config.NewHolder(config.Config{MaxRetries: 3}),
|
|
log: slog.New(slog.DiscardHandler),
|
|
}}
|
|
srv := &webui.Server{
|
|
Store: st,
|
|
Chat: &webui.ChatService{Contract: &gateway.LocalChatAdapter{TaskActor: actor}},
|
|
}
|
|
req := httptest.NewRequestWithContext(ctx, http.MethodPost,
|
|
"/api/tasks/"+strconv.FormatInt(taskID, 10)+"/action",
|
|
bytes.NewBufferString(`{"action":"`+action+`"}`))
|
|
req.Header.Set("Content-Type", "application/json")
|
|
req.Header.Set("X-Archie-CSRF", "1")
|
|
w := httptest.NewRecorder()
|
|
srv.Handler().ServeHTTP(w, req)
|
|
if w.Code != http.StatusOK {
|
|
t.Fatalf("dashboard %s: status %d, body %s", action, w.Code, w.Body)
|
|
}
|
|
}
|