Q158: run history and run output come from the database, not the snapshot window
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a075f931d5
commit
9d166e3fc9
18 files changed
+222
-35
No files matched your search
@@ -290,6 +290,20 @@ test("the pinned CEO conversation is the Messages front door", async () => {
|
||||
await expect(start).toBeVisible();
|
||||
await expect(chatLog.getByText("General line 0", { exact: true })).toBeVisible();
|
||||
|
||||
// Runs older than the loaded window page in from the database, down to the first one.
|
||||
await page.getByRole("button", { name: "Runs" }).click();
|
||||
const runRows = page.locator(".pane-scroll .nav-row");
|
||||
await expect(runRows).toHaveCount(200);
|
||||
await page.getByRole("button", { name: "Show older runs" }).click();
|
||||
await expect.poll(async () => runRows.count()).toBeGreaterThan(200);
|
||||
for (let click = 0; click < 10 && await page.getByRole("button", { name: "Show older runs" }).isVisible(); click += 1) {
|
||||
await page.getByRole("button", { name: "Show older runs" }).click();
|
||||
await page.waitForTimeout(300);
|
||||
}
|
||||
await expect(page.getByText("These are all the runs.")).toBeVisible();
|
||||
await page.getByRole("button", { name: "Messages" }).click();
|
||||
await page.locator(".convo-item", { hasText: "general" }).click();
|
||||
|
||||
// The header lists the real members, how each agent replies, and who can read.
|
||||
await page.getByRole("button", { name: /^Members \(/ }).click();
|
||||
const roster = page.getByRole("menu");
|
||||
|
||||
@@ -40,6 +40,9 @@ describe("a run's model calls", () => {
|
||||
});
|
||||
const runId = claimNextQueuedRun(connection)!.id;
|
||||
await expect(execution.executeRun(orgId, runId)).rejects.toThrow();
|
||||
// Each call carries its own output, so the run's detail does not depend on a snapshot window.
|
||||
const turnCall = requestsForRun(connection.db, orgId, runId).find((request) => request.purpose === "agent_turn" && request.state === "succeeded")!;
|
||||
expect([typeof turnCall.responseText, typeof turnCall.inputCharCount, typeof turnCall.outputCharCount]).toEqual(["string", "number", "number"]);
|
||||
expect(requestsForRun(connection.db, orgId, runId).map((request) => [request.purpose, request.state])).toEqual([
|
||||
["model_check", "succeeded"],
|
||||
["agent_turn", "succeeded"],
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
import { randomUUID } from "node:crypto";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { describe, expect, test } from "vitest";
|
||||
import { DatabaseConnection } from "../../src/main/database/connection";
|
||||
import { OrganizationService } from "../../src/main/services/organization-service";
|
||||
import { SnapshotService } from "../../src/main/services/snapshot-service";
|
||||
import { runHistory } from "../../src/main/services/run-history";
|
||||
import { RISK_LEVEL, TASK_PRIORITY, TASK_STATUS } from "../../src/shared/domain";
|
||||
|
||||
describe("run history", () => {
|
||||
test("pages back past the snapshot's recent runs to the very first", () => {
|
||||
const connection = new DatabaseConnection(join(tmpdir(), `ac-run-history-${randomUUID()}.db`));
|
||||
const organization = new OrganizationService(connection.db);
|
||||
let orgId = "";
|
||||
let taskId = "";
|
||||
let agentId = "";
|
||||
connection.transaction(() => {
|
||||
orgId = organization.createOrganization({ organizationName: "Acme", employeeName: "Yang", mission: "m", goal: "g" });
|
||||
agentId = organization.createAgent({ orgId, name: "Ada", role: "Engineer", department: "Engineering", modelProviderId: null, modelId: null, budgetCents: 1000, managerAgentId: null });
|
||||
taskId = organization.createTask({
|
||||
orgId, title: "Work", description: "d", status: TASK_STATUS.BACKLOG, assigneeAgentId: agentId, risk: RISK_LEVEL.LOW,
|
||||
projectId: null, goalId: null, workspaceId: null, priority: TASK_PRIORITY.NORMAL, requiresFilesystem: false,
|
||||
});
|
||||
// Every run shares one instant, so only insertion order can page them correctly.
|
||||
const insert = connection.db.prepare("insert into task_runs(id, org_id, task_id, agent_id, trigger, state, created_at) values (?, ?, ?, ?, 'manual', 'completed', '2026-04-01T00:00:00.000Z')");
|
||||
for (let index = 0; index < 230; index += 1) insert.run(`run_${String(index).padStart(3, "0")}`, orgId, taskId, agentId);
|
||||
});
|
||||
const recent = new SnapshotService(connection.db).load().taskRuns;
|
||||
expect(recent).toHaveLength(200);
|
||||
expect(recent[0].id).toBe("run_030");
|
||||
const older = runHistory(connection.db, orgId, recent[0].id, { limit: 20 });
|
||||
expect(older.runs.map((run) => run.id)).toEqual(Array.from({ length: 20 }, (_, index) => `run_${String(index + 10).padStart(3, "0")}`));
|
||||
expect(older.hasMore).toBe(true);
|
||||
const oldest = runHistory(connection.db, orgId, older.runs[0].id, { limit: 20 });
|
||||
expect(oldest.runs.map((run) => run.id)).toEqual(Array.from({ length: 10 }, (_, index) => `run_${String(index).padStart(3, "0")}`));
|
||||
expect(oldest.hasMore).toBe(false);
|
||||
expect(() => runHistory(connection.db, orgId, "run_missing", { limit: 20 })).toThrow("The oldest loaded run was not found.");
|
||||
// The loaded range refreshes in one query from its oldest run up to the cursor.
|
||||
const range = runHistory(connection.db, orgId, recent[0].id, { from: oldest.oldest! });
|
||||
expect([range.runs.length, range.runs[0].id, range.runs.at(-1)!.id, range.hasMore]).toEqual([30, "run_000", "run_029", false]);
|
||||
// The pinned position holds after its run is deleted, and the range still says whether older runs exist.
|
||||
connection.db.prepare("delete from task_runs where id in ('run_000', 'run_001')").run();
|
||||
expect(runHistory(connection.db, orgId, recent[0].id, { from: older.oldest! })).toMatchObject({ hasMore: true });
|
||||
expect(runHistory(connection.db, orgId, recent[0].id, { from: oldest.oldest! }).runs[0].id).toBe("run_002");
|
||||
// With nothing loaded, the newest runs come first.
|
||||
expect(runHistory(connection.db, orgId, null, { limit: 2 }).runs.map((run) => run.id)).toEqual(["run_228", "run_229"]);
|
||||
connection.close();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user