fix: include legacy triaged reports in confirmed lists
Some checks failed
Security Gate: Secret Scanning / Scan for Verified Secrets (push) Has been cancelled
Some checks failed
Security Gate: Secret Scanning / Scan for Verified Secrets (push) Has been cancelled
This commit is contained in:
parent
0748b7dd9d
commit
b9cf00ef95
@ -4712,6 +4712,68 @@ describe("packages public queries", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("lists legacy triaged package reports as confirmed", async () => {
|
||||
const result = await listPackageReportsInternalHandler(
|
||||
{
|
||||
db: {
|
||||
get: vi.fn(async (id: string) => {
|
||||
if (id === "users:moderator") return { _id: id, role: "moderator" };
|
||||
if (id === "users:reporter") {
|
||||
return { _id: id, handle: "reporter", displayName: "Reporter" };
|
||||
}
|
||||
if (id === "packages:demo") return makePackageDoc({ name: "@scope/demo" });
|
||||
return null;
|
||||
}),
|
||||
query: vi.fn((table: string) => {
|
||||
if (table !== "packageReports") throw new Error(`Unexpected table ${table}`);
|
||||
return {
|
||||
withIndex: vi.fn(() => ({
|
||||
order: vi.fn(() => ({
|
||||
paginate: vi.fn().mockResolvedValue({
|
||||
page: [
|
||||
{
|
||||
_id: "packageReports:legacy",
|
||||
packageId: "packages:demo",
|
||||
userId: "users:reporter",
|
||||
reason: "legacy triaged",
|
||||
status: "triaged",
|
||||
createdAt: 3,
|
||||
},
|
||||
{
|
||||
_id: "packageReports:confirmed",
|
||||
packageId: "packages:demo",
|
||||
userId: "users:reporter",
|
||||
reason: "confirmed",
|
||||
status: "confirmed",
|
||||
createdAt: 2,
|
||||
},
|
||||
{
|
||||
_id: "packageReports:dismissed",
|
||||
packageId: "packages:demo",
|
||||
userId: "users:reporter",
|
||||
reason: "dismissed",
|
||||
status: "dismissed",
|
||||
createdAt: 1,
|
||||
},
|
||||
],
|
||||
continueCursor: null,
|
||||
isDone: true,
|
||||
}),
|
||||
})),
|
||||
})),
|
||||
};
|
||||
}),
|
||||
},
|
||||
} as never,
|
||||
{ actorUserId: "users:moderator", status: "confirmed", limit: 10 },
|
||||
);
|
||||
|
||||
expect(result.items).toEqual([
|
||||
expect.objectContaining({ reportId: "packageReports:legacy", status: "confirmed" }),
|
||||
expect.objectContaining({ reportId: "packageReports:confirmed", status: "confirmed" }),
|
||||
]);
|
||||
});
|
||||
|
||||
it("triages package reports and decrements open count", async () => {
|
||||
const patch = vi.fn();
|
||||
const insert = vi.fn(async () => "auditLogs:1");
|
||||
|
||||
@ -2844,7 +2844,7 @@ export const listPackageReportsInternal = internalQuery({
|
||||
const limit = Math.max(1, Math.min(Math.round(args.limit ?? 25), 100));
|
||||
const status = args.status ?? "open";
|
||||
const reportQuery =
|
||||
status === "all"
|
||||
status === "all" || status === "confirmed"
|
||||
? ctx.db.query("packageReports").withIndex("by_createdAt", (q) => q)
|
||||
: ctx.db
|
||||
.query("packageReports")
|
||||
@ -2856,6 +2856,9 @@ export const listPackageReportsInternal = internalQuery({
|
||||
|
||||
const items: PackageReportListItem[] = [];
|
||||
for (const report of page.page) {
|
||||
if (status === "confirmed" && readArtifactReportStatus(report.status) !== "confirmed") {
|
||||
continue;
|
||||
}
|
||||
const pkg = await ctx.db.get(report.packageId);
|
||||
if (!pkg || pkg.softDeletedAt || pkg.family === "skill") continue;
|
||||
const reporter = await ctx.db.get(report.userId);
|
||||
|
||||
@ -796,6 +796,71 @@ describe("skill artifact moderation", () => {
|
||||
]);
|
||||
});
|
||||
|
||||
it("lists legacy triaged skill reports as confirmed", async () => {
|
||||
const result = await listSkillReportsInternalHandler(
|
||||
{
|
||||
db: {
|
||||
get: vi.fn(async (id: string) => {
|
||||
if (id === "users:moderator") return { _id: id, role: "moderator" };
|
||||
if (id === "skills:demo") return makeSkill({ _id: id, slug: "demo" });
|
||||
if (id === "users:reporter") return makeOwner("users:reporter", "reporter");
|
||||
return null;
|
||||
}),
|
||||
query: vi.fn((table: string) => {
|
||||
if (table === "skillReports") {
|
||||
return {
|
||||
withIndex: vi.fn(() => ({
|
||||
order: vi.fn(() => ({
|
||||
paginate: vi.fn().mockResolvedValue({
|
||||
page: [
|
||||
{
|
||||
_id: "skillReports:legacy",
|
||||
skillId: "skills:demo",
|
||||
userId: "users:reporter",
|
||||
reason: "legacy triaged",
|
||||
status: "triaged",
|
||||
createdAt: 3,
|
||||
},
|
||||
{
|
||||
_id: "skillReports:confirmed",
|
||||
skillId: "skills:demo",
|
||||
userId: "users:reporter",
|
||||
reason: "confirmed",
|
||||
status: "confirmed",
|
||||
createdAt: 2,
|
||||
},
|
||||
{
|
||||
_id: "skillReports:dismissed",
|
||||
skillId: "skills:demo",
|
||||
userId: "users:reporter",
|
||||
reason: "dismissed",
|
||||
status: "dismissed",
|
||||
createdAt: 1,
|
||||
},
|
||||
],
|
||||
isDone: true,
|
||||
continueCursor: "",
|
||||
}),
|
||||
})),
|
||||
})),
|
||||
};
|
||||
}
|
||||
throw new Error(`Unexpected query table: ${table}`);
|
||||
}),
|
||||
},
|
||||
} as never,
|
||||
{
|
||||
actorUserId: "users:moderator",
|
||||
status: "confirmed",
|
||||
},
|
||||
);
|
||||
|
||||
expect(result.items).toEqual([
|
||||
expect.objectContaining({ reportId: "skillReports:legacy", status: "confirmed" }),
|
||||
expect.objectContaining({ reportId: "skillReports:confirmed", status: "confirmed" }),
|
||||
]);
|
||||
});
|
||||
|
||||
it("can hide a skill while triaging a valid report", async () => {
|
||||
const skill = makeSkill({ reportCount: 1 });
|
||||
const patch = vi.fn();
|
||||
|
||||
@ -3583,7 +3583,7 @@ export const listSkillReportsInternal = internalQuery({
|
||||
const limit = Math.max(1, Math.min(Math.round(args.limit ?? 25), 100));
|
||||
const status = args.status ?? "open";
|
||||
const reportQuery =
|
||||
status === "all" || status === "open"
|
||||
status === "all" || status === "open" || status === "confirmed"
|
||||
? ctx.db.query("skillReports").withIndex("by_createdAt", (q) => q)
|
||||
: ctx.db
|
||||
.query("skillReports")
|
||||
@ -3596,6 +3596,9 @@ export const listSkillReportsInternal = internalQuery({
|
||||
const items: SkillReportListItem[] = [];
|
||||
for (const skillReport of page.page) {
|
||||
if (status === "open" && (skillReport.status ?? "open") !== "open") continue;
|
||||
if (status === "confirmed" && readArtifactReportStatus(skillReport.status) !== "confirmed") {
|
||||
continue;
|
||||
}
|
||||
const skill = await ctx.db.get(skillReport.skillId);
|
||||
if (!skill) continue;
|
||||
const reporter = await ctx.db.get(skillReport.userId);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user