Add attachments, usage limits and automation editing
Attachments upload like the web composer's (signed URL, then bytes) and ride on the next message or a draft's first message; pending names show above the composer and removal deletes the unsent upload. Settings shows provider limit windows, banked reset credits and the last 30 days' usage summary, with a status-line note near a limit and a confirmed reset-credit command. Automations can be created and edited in $EDITOR from a template parsed back against the web form's rules, and deleted behind a confirm. Asks for the diagnostics:read and providers:manage scopes the new RPCs need.
This commit is contained in:
1 parent
43347d1d58
commit
2b31804f8e
15 files changed
+1049
-23
No files matched your search
@@ -0,0 +1,93 @@
|
||||
import { describe, expect, test } from "bun:test";
|
||||
import { ScheduledTaskUpsertInput, type OrchestrationProjectShell, type ScheduledTask } from "@t3tools/contracts";
|
||||
import * as Schema from "effect/Schema";
|
||||
|
||||
import { automationTemplate, newAutomationTemplate, parseAutomation } from "../src/model/automations.ts";
|
||||
|
||||
const projects = [
|
||||
{ id: "p1", title: "tasknotes", workspaceRoot: "/repo/tasknotes" },
|
||||
{ id: "p2", title: "tui3", workspaceRoot: "/repo/tui3" },
|
||||
] as unknown as OrchestrationProjectShell[];
|
||||
|
||||
const task = (extra: Record<string, unknown> = {}) =>
|
||||
({
|
||||
id: "task-1",
|
||||
title: "Nightly tidy",
|
||||
prompt: "Tidy the notes.\nThen summarise.",
|
||||
enabled: true,
|
||||
schedule: { type: "fixed_time", timeOfDay: "09:00", weekdays: [1, 2, 3, 4, 5] },
|
||||
projectId: "p1",
|
||||
threadId: "t1",
|
||||
workspaceStrategy: { type: "worktree", baseRef: "main", startFromOrigin: true },
|
||||
modelSelection: { instanceId: "codex", model: "gpt-5", options: [{ id: "effort", value: "high" }] },
|
||||
runtimeMode: "full-access",
|
||||
interactionMode: "default",
|
||||
...extra,
|
||||
}) as unknown as ScheduledTask;
|
||||
|
||||
const isUpsert = Schema.is(ScheduledTaskUpsertInput);
|
||||
|
||||
describe("automation templates", () => {
|
||||
test("an edited task round-trips, keeping its model options", () => {
|
||||
const parsed = parseAutomation(automationTemplate(task(), projects), projects, task());
|
||||
expect(parsed.ok).toBe(true);
|
||||
if (!parsed.ok) return;
|
||||
expect(isUpsert(parsed.input)).toBe(true);
|
||||
expect(parsed.input).toMatchObject({
|
||||
id: "task-1",
|
||||
requireExisting: true,
|
||||
title: "Nightly tidy",
|
||||
prompt: "Tidy the notes.\nThen summarise.",
|
||||
schedule: { type: "fixed_time", timeOfDay: "09:00", weekdays: [1, 2, 3, 4, 5] },
|
||||
projectId: "p1",
|
||||
threadId: "t1",
|
||||
workspaceStrategy: { type: "worktree", baseRef: "main", startFromOrigin: true },
|
||||
modelSelection: { instanceId: "codex", model: "gpt-5", options: [{ id: "effort", value: "high" }] },
|
||||
});
|
||||
});
|
||||
|
||||
test("a new task takes the edited title, interval and prompt", () => {
|
||||
const text = newAutomationTemplate(projects, { projectId: "p2", threadId: "", modelSelection: { instanceId: "claude" as never, model: "opus" }, runtimeMode: "auto" })
|
||||
.replace("Title: ", "Title: Sweep")
|
||||
.replace("Schedule: fixed 09:00 Mon,Tue,Wed,Thu,Fri", "Schedule: interval 2h")
|
||||
.replace("Prompt:\n", "Prompt:\nSweep the inbox.\n");
|
||||
const parsed = parseAutomation(text, projects);
|
||||
expect(parsed.ok).toBe(true);
|
||||
if (!parsed.ok) return;
|
||||
expect(isUpsert(parsed.input)).toBe(true);
|
||||
expect(parsed.input).toMatchObject({ title: "Sweep", schedule: { type: "interval", everyMs: 7_200_000 }, projectId: "p2", threadId: null, runtimeMode: "auto" });
|
||||
expect(parsed.input).not.toHaveProperty("id");
|
||||
});
|
||||
|
||||
test("the web form's checks apply: complete, a minute or more, a checkout path", () => {
|
||||
const blank = newAutomationTemplate(projects, { projectId: "p1", threadId: "", modelSelection: { instanceId: "codex" as never, model: "gpt-5" }, runtimeMode: "full-access" });
|
||||
expect(parseAutomation(blank, projects)).toEqual({ ok: false, error: "Scheduled task is incomplete: add a title, prompt, project, and model." });
|
||||
const filled = blank.replace("Title: ", "Title: X").replace("Prompt:\n", "Prompt:\nDo it.\n");
|
||||
expect(parseAutomation(filled.replace("Schedule: fixed 09:00 Mon,Tue,Wed,Thu,Fri", "Schedule: interval 0m"), projects).ok).toBe(false);
|
||||
expect(parseAutomation(filled.replace("Workspace: worktree", "Workspace: existing_worktree"), projects)).toMatchObject({ ok: false, error: expect.stringContaining("Checkout path is required") });
|
||||
expect(parseAutomation(filled.replace("Project: tasknotes", "Project: nope"), projects).ok).toBe(false);
|
||||
expect(parseAutomation(filled.replace("Schedule: fixed 09:00 Mon,Tue,Wed,Thu,Fri", "Schedule: whenever"), projects).ok).toBe(false);
|
||||
});
|
||||
|
||||
test("editing a webhook task keeps its signature and dedupe, and leaves filters stored", () => {
|
||||
const hook = task({
|
||||
schedule: {
|
||||
type: "webhook",
|
||||
signature: { header: "x-hub-signature-256", encoding: "hex", prefix: "sha256=" },
|
||||
maxDeliveryAgeMinutes: 60,
|
||||
dedupe: { replayKey: "{{headers.x-id}}" },
|
||||
filters: [{ path: "body.action", op: "equals", value: "open" }],
|
||||
},
|
||||
});
|
||||
const parsed = parseAutomation(automationTemplate(hook, projects), projects, hook);
|
||||
expect(parsed.ok).toBe(true);
|
||||
if (!parsed.ok) return;
|
||||
expect(isUpsert(parsed.input)).toBe(true);
|
||||
expect(parsed.input.schedule).toEqual({
|
||||
type: "webhook",
|
||||
signature: { header: "x-hub-signature-256", encoding: "hex", prefix: "sha256=" },
|
||||
maxDeliveryAgeMinutes: 60,
|
||||
dedupe: { replayKey: "{{headers.x-id}}" },
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user