fix: 修复 Queue 已读投影和取消传播
This commit is contained in:
@@ -62,6 +62,14 @@ const selfTest: SelfTestCase = async (context) => {
|
||||
const commander = await client.get("/api/v1/queue/commander?queue=dev") as QueueCommanderSnapshot;
|
||||
assert.equal(commander.stats.byState.cancelled, 1);
|
||||
assert.equal(commander.items[0]?.id, created.id);
|
||||
assert.equal(commander.items[0]?.attentionState, "unread");
|
||||
|
||||
const terminalRead = await client.post(`/api/v1/queue/tasks/${created.id}/read`, { readerId: "self-test" }) as QueueReadCursorRecord;
|
||||
assert.equal(terminalRead.taskVersion, cancelled.version);
|
||||
const readCommander = await client.get("/api/v1/queue/commander?queue=dev&readerId=self-test") as QueueCommanderSnapshot;
|
||||
assert.equal(readCommander.readerId, "self-test");
|
||||
assert.equal(readCommander.stats.byState.cancelled, 1);
|
||||
assert.equal(readCommander.items.some((item) => item.id === created.id), false);
|
||||
return { name: "queue-q1", tests: ["queue-q1-rest-memory"] };
|
||||
} finally {
|
||||
await new Promise<void>((resolve) => server.server.close(() => resolve()));
|
||||
|
||||
@@ -93,10 +93,52 @@ console.log(JSON.stringify({ apiVersion: manifest.apiVersion, kind: manifest.kin
|
||||
assert.equal(refreshed.latestAttempt?.state, "completed");
|
||||
assert.equal(refreshed.latestAttempt?.runId, dispatched.run.id);
|
||||
assert.equal(refreshed.latestAttempt?.sessionPath, "/api/v1/sessions/sess_queue_q2_dispatch_selftest");
|
||||
const manifest = JSON.parse(await readFile(createdManifest, "utf8")) as JsonRecord;
|
||||
assert.ok(JSON.stringify(manifest).includes(dispatched.run.id));
|
||||
const dispatchManifest = JSON.parse(await readFile(createdManifest, "utf8")) as JsonRecord;
|
||||
assert.ok(JSON.stringify(dispatchManifest).includes(dispatched.run.id));
|
||||
|
||||
const cancelCreated = await client.post("/api/v1/queue/tasks", {
|
||||
tenantId: "unidesk",
|
||||
projectId: "pikasTech/unidesk",
|
||||
queue: "dev",
|
||||
lane: "q2",
|
||||
title: "Q2 queue cancel task",
|
||||
priority: 21,
|
||||
backendProfile: "codex",
|
||||
providerId: "G14",
|
||||
workspaceRef: { kind: "host-path", path: context.workspace },
|
||||
sessionRef: { sessionId: "sess_queue_q2_cancel_selftest", metadata: { source: "queue-q2-cancel-self-test" } },
|
||||
executionPolicy: {
|
||||
sandbox: "workspace-write",
|
||||
approval: "never",
|
||||
timeoutMs: 15_000,
|
||||
network: "default",
|
||||
secretScope: { allowCredentialEcho: false, providerCredentials: [{ profile: "codex", secretRef: { name: "agentrun-v01-provider-codex", keys: ["auth.json", "config.toml"], mountPath: context.codexHome } }] },
|
||||
},
|
||||
resourceBundleRef: null,
|
||||
payload: { prompt: "queue cancel hello" },
|
||||
references: [{ kind: "issue", url: "https://github.com/pikasTech/agentrun/issues/105" }],
|
||||
metadata: { source: "queue-q2-cancel-self-test" },
|
||||
idempotencyKey: "queue-q2-cancel-self-test",
|
||||
}) as QueueTaskRecord;
|
||||
const cancelDispatched = await client.post(`/api/v1/queue/tasks/${cancelCreated.id}/dispatch`, { attemptId: "attempt_queue_q2_cancel_selftest" }) as QueueDispatchResult;
|
||||
const cancelled = await client.post(`/api/v1/queue/tasks/${cancelCreated.id}/cancel`, { reason: "self-test queue cancel propagation" }) as QueueTaskRecord;
|
||||
assert.equal(cancelled.state, "cancelled");
|
||||
assert.equal(cancelled.latestAttempt?.state, "cancelled");
|
||||
assert.equal(cancelled.latestAttempt?.runId, cancelDispatched.run.id);
|
||||
assert.equal(cancelled.cancelReason, "self-test queue cancel propagation");
|
||||
const cancelledCommand = await client.get(`/api/v1/runs/${cancelDispatched.run.id}/commands/${cancelDispatched.command.id}`) as { state?: string };
|
||||
assert.equal(cancelledCommand.state, "cancelled");
|
||||
const cancelledSession = await client.get("/api/v1/sessions/sess_queue_q2_cancel_selftest") as { executionState?: string; terminalStatus?: string; failureKind?: string; activeRunId?: string | null; activeCommandId?: string | null };
|
||||
assert.equal(cancelledSession.executionState, "terminal");
|
||||
assert.equal(cancelledSession.terminalStatus, "cancelled");
|
||||
assert.equal(cancelledSession.failureKind, "cancelled");
|
||||
assert.equal(cancelledSession.activeRunId, null);
|
||||
assert.equal(cancelledSession.activeCommandId, null);
|
||||
const cancelManifest = JSON.parse(await readFile(createdManifest, "utf8")) as JsonRecord;
|
||||
assert.ok(JSON.stringify(cancelManifest).includes(cancelDispatched.run.id));
|
||||
assertNoSecretLeak(dispatched);
|
||||
return { name: "queue-q2-dispatch", tests: ["queue-dispatch-run-command-runner-job", "queue-refresh-from-core-status", "queue-dispatch-no-repeat"] };
|
||||
assertNoSecretLeak(cancelled);
|
||||
return { name: "queue-q2-dispatch", tests: ["queue-dispatch-run-command-runner-job", "queue-refresh-from-core-status", "queue-dispatch-no-repeat", "queue-cancel-propagates-to-command-session"] };
|
||||
} finally {
|
||||
await new Promise<void>((resolve) => server.server.close(() => resolve()));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user