mirror of
https://github.com/alkimake/paperclip.git
synced 2026-06-16 19:00:38 +09:00
Restore feedback trace export fixes
This commit is contained in:
parent
ed95fc1dda
commit
00898e8194
9 changed files with 357 additions and 24 deletions
|
|
@ -1069,6 +1069,73 @@ describe("feedbackService.saveIssueVote", () => {
|
|||
});
|
||||
});
|
||||
|
||||
it("can flush a single shared trace immediately by trace id", async () => {
|
||||
const { companyId, issueId, commentId: firstCommentId } = await seedIssueWithAgentComment();
|
||||
const secondCommentId = randomUUID();
|
||||
const agentId = await db
|
||||
.select({ authorAgentId: issueComments.authorAgentId })
|
||||
.from(issueComments)
|
||||
.where(eq(issueComments.id, firstCommentId))
|
||||
.then((rows) => rows[0]?.authorAgentId ?? null);
|
||||
|
||||
await db.insert(issueComments).values({
|
||||
id: secondCommentId,
|
||||
companyId,
|
||||
issueId,
|
||||
authorAgentId: agentId,
|
||||
body: "Second AI generated update",
|
||||
});
|
||||
|
||||
const uploadTraceBundle = vi.fn().mockResolvedValue({
|
||||
objectKey: `feedback-traces/${companyId}/2026/04/01/test-trace.json`,
|
||||
});
|
||||
const flushingSvc = feedbackService(db, {
|
||||
shareClient: {
|
||||
uploadTraceBundle,
|
||||
},
|
||||
});
|
||||
|
||||
const first = await flushingSvc.saveIssueVote({
|
||||
issueId,
|
||||
targetType: "issue_comment",
|
||||
targetId: firstCommentId,
|
||||
vote: "up",
|
||||
authorUserId: "user-1",
|
||||
allowSharing: true,
|
||||
});
|
||||
await flushingSvc.saveIssueVote({
|
||||
issueId,
|
||||
targetType: "issue_comment",
|
||||
targetId: secondCommentId,
|
||||
vote: "up",
|
||||
authorUserId: "user-1",
|
||||
allowSharing: true,
|
||||
});
|
||||
|
||||
const flushResult = await flushingSvc.flushPendingFeedbackTraces({
|
||||
companyId,
|
||||
traceId: first.traceId ?? undefined,
|
||||
limit: 1,
|
||||
});
|
||||
|
||||
expect(flushResult).toMatchObject({
|
||||
attempted: 1,
|
||||
sent: 1,
|
||||
failed: 0,
|
||||
});
|
||||
expect(uploadTraceBundle).toHaveBeenCalledTimes(1);
|
||||
|
||||
const traces = await flushingSvc.listFeedbackTraces({
|
||||
companyId,
|
||||
issueId,
|
||||
includePayload: true,
|
||||
});
|
||||
const firstTrace = traces.find((trace) => trace.targetId === firstCommentId);
|
||||
const secondTrace = traces.find((trace) => trace.targetId === secondCommentId);
|
||||
expect(firstTrace?.status).toBe("sent");
|
||||
expect(secondTrace?.status).toBe("pending");
|
||||
});
|
||||
|
||||
it("marks pending shared traces as failed when remote export upload fails", async () => {
|
||||
const { companyId, issueId, commentId } = await seedIssueWithAgentComment();
|
||||
const uploadTraceBundle = vi.fn().mockRejectedValue(new Error("telemetry unavailable"));
|
||||
|
|
@ -1106,4 +1173,39 @@ describe("feedbackService.saveIssueVote", () => {
|
|||
expect(traces[0]?.exportedAt).toBeNull();
|
||||
expect(uploadTraceBundle).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it("marks pending shared traces as failed when no feedback export backend is configured", async () => {
|
||||
const { companyId, issueId, commentId } = await seedIssueWithAgentComment();
|
||||
|
||||
const result = await svc.saveIssueVote({
|
||||
issueId,
|
||||
targetType: "issue_comment",
|
||||
targetId: commentId,
|
||||
vote: "up",
|
||||
authorUserId: "user-1",
|
||||
allowSharing: true,
|
||||
});
|
||||
|
||||
const flushResult = await svc.flushPendingFeedbackTraces({
|
||||
companyId,
|
||||
traceId: result.traceId ?? undefined,
|
||||
limit: 1,
|
||||
});
|
||||
|
||||
expect(flushResult).toMatchObject({
|
||||
attempted: 1,
|
||||
sent: 0,
|
||||
failed: 1,
|
||||
});
|
||||
|
||||
const traces = await svc.listFeedbackTraces({
|
||||
companyId,
|
||||
issueId,
|
||||
includePayload: true,
|
||||
});
|
||||
expect(traces[0]?.status).toBe("failed");
|
||||
expect(traces[0]?.attemptCount).toBe(1);
|
||||
expect(traces[0]?.failureReason).toBe("Feedback export backend is not configured");
|
||||
expect(traces[0]?.exportedAt).toBeNull();
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue