fix(store,gateway): taskstate constants and mobile jump-to search

Follow-up pieces of the task-controls work: store.InsertEvent factors out
an execer-generic insertEvent so SQLite gets the same zero-time defaulting
ArchiveTask's audit path relies on; gateway tests assert against
taskstate constants instead of magic status strings; the navigation
command bar gets an accessible mobile search toggle.

Refs #53
This commit is contained in:
sam committed 2026-08-09 01:26:40 +10:00
1 parent a27d430215
commit 92280f4039
3 files changed
+52 -5

No files matched your search

+8 -2
View File
@@ -265,7 +265,7 @@ func TestStoreTaskControllerRejectsCallerIdentityForLegacyTask(t *testing.T) {
}
func TestStoreTaskControllerCancelActiveStates(t *testing.T) {
for _, status := range []string{"queued", "waiting_human", "pr_open"} {
for _, status := range []string{taskstate.Queued, taskstate.WaitingHuman, taskstate.Parked} {
store := &fakeChatTaskStore{statuses: map[int64]ChatTaskStatus{1: {Status: status}}}
c := NewStoreTaskController(store)
if err := c.Cancel(context.Background(), 1, ""); err != nil {
@@ -372,7 +372,13 @@ func TestStoreTaskControllerStopRunningWithoutRuntime(t *testing.T) {
}
func TestStoreTaskControllerCancelRejectsTerminalStates(t *testing.T) {
for _, status := range []string{"merged", "parked", "rejected", "dead", "closed_wont_do"} {
for _, status := range []string{
taskstate.PROpen,
taskstate.Merged,
taskstate.Rejected,
taskstate.Dead,
taskstate.Declined,
} {
store := &fakeChatTaskStore{statuses: map[int64]ChatTaskStatus{1: {Status: status}}}
c := NewStoreTaskController(store)
err := c.Cancel(context.Background(), 1, "")
+12 -1
View File
@@ -30,11 +30,22 @@ CREATE INDEX IF NOT EXISTS idx_events_kind ON events(kind, id);
// InsertEvent appends an event to the log and returns its row id.
func (s *Store) InsertEvent(ctx context.Context, e events.Event) (int64, error) {
return insertEvent(ctx, s.db, e)
}
type eventExecer interface {
ExecContext(context.Context, string, ...any) (sql.Result, error)
}
func insertEvent(ctx context.Context, execer eventExecer, e events.Event) (int64, error) {
if e.At.IsZero() {
e.At = time.Now().UTC()
}
data, err := json.Marshal(e.Data)
if err != nil {
data = fmt.Appendf(nil, `{"marshal_error":%q}`, err.Error())
}
res, err := s.db.ExecContext(ctx, `
res, err := execer.ExecContext(ctx, `
INSERT INTO events (at, kind, task_id, repo, issue, workflow, stage, detail, data)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`,
e.At.UTC().Format(time.RFC3339Nano), e.Kind, e.TaskID, e.Repo, e.Issue,
+32 -2
View File
@@ -42,7 +42,6 @@ function currentTheme() {
return localStorage.getItem(THEME_KEY) || "dark";
}
function commandBar(onNavigate) {
const items = new Map();
@@ -85,11 +84,35 @@ function commandBar(onNavigate) {
// Search jumps between sections. It is deliberately not a data search: the
// sections own their own filtering, and a second search that means something
// different in each place is worse than none.
let searchWrap;
const closeMobileSearch = () => {
searchWrap?.classList.remove("is-open");
searchToggle.setAttribute("aria-expanded", "false");
};
const searchToggle = el(
"button.icon-btn.mobile-search-toggle",
{
type: "button",
"aria-label": "Open Jump to navigation",
"aria-expanded": "false",
onclick: () => {
searchWrap.classList.add("is-open");
searchToggle.setAttribute("aria-expanded", "true");
search.focus();
},
},
icon("search", { size: 15 }),
);
const search = el("input", {
type: "search",
placeholder: "Jump to\u2026",
"aria-label": "Jump to a section",
onkeydown: (e) => {
if (e.key === "Escape") {
closeMobileSearch();
e.target.blur();
return;
}
if (e.key !== "Enter") return;
const q = e.target.value.trim().toLowerCase();
const hit = routes.find((r) => !r.soon && r.label.toLowerCase().startsWith(q));
@@ -97,9 +120,16 @@ function commandBar(onNavigate) {
onNavigate(hit.path);
e.target.value = "";
e.target.blur();
closeMobileSearch();
}
},
});
searchWrap = el(
"div.topbar-search",
el("span.topbar-search-icon", { "aria-hidden": "true" }, icon("search", { size: 15 })),
searchToggle,
search,
);
return {
node: el(
@@ -108,7 +138,7 @@ function commandBar(onNavigate) {
nav,
el(
"div.topbar-end",
el("div.topbar-search", icon("search", { size: 15 }), search),
searchWrap,
el("button.icon-btn", { title: "Documentation", "aria-label": "Documentation" }, icon("help")),
themeBtn,
el("div.avatar", { title: "Signed in locally" }, "A"),