Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion apps/server/src/agent/review-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,9 @@ function citationEvidenceIssues(documents: Array<{ path: string; content: string
function dedupeIssues(issues: ReviewIssue[]): ReviewIssue[] {
const byKey = new Map<string, ReviewIssue>();
for (const issue of issues) {
const key = issue.title.toLowerCase().replace(/[^a-z0-9]+/g, " ").trim();
const key = issue.title.normalize("NFC").toLowerCase().replace(/[^\p{L}\p{M}\p{N}]+/gu, " ").trim();
// A title without comparable text provides no evidence of duplication.
if (!key) { byKey.set(issue.id, issue); continue; }
const existing = byKey.get(key);
if (!existing) byKey.set(key, issue);
else { existing.evidence.push(...issue.evidence.filter((evidence) => !existing.evidence.some((item) => item.path === evidence.path && item.excerpt === evidence.excerpt))); existing.rationale = `${existing.rationale}\n${issue.rationale}`.trim(); }
Expand Down
23 changes: 23 additions & 0 deletions apps/server/src/app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1232,6 +1232,29 @@ describe("workspace API", () => {
expect((await (await request(`/api/projects/${project.id}/reviews`)).json() as unknown[])).toHaveLength(1);
});

test("preserves distinct multilingual Review findings while merging matching titles", async () => {
const provider: AgentProvider = {
async revise(input) { return { replacement: input.selection.text, rationale: "unused" }; },
async review() {
return { overallAssessment: "Review findings.", recommendation: "borderline", strengths: [], weaknesses: [], nextSteps: [],
issues: ["缺少消融实验", "威胁模型不完整", "缺少消融实验", "Résumé incomplet", "Re\u0301sume\u0301 incomplet!", "⚠️", "❗", "कला", "किला"].map((title, index) => ({
category: "clarity" as const, severity: "major" as const, title, rationale: `Finding ${index}`, impact: "Needs review", suggestion: "Inspect evidence", evidence: [],
})) };
},
};
const request = await testApplication(provider);
const project = await (await request("/api/projects", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ name: "Multilingual Review" }) })).json() as PaperProject;
const response = await request(`/api/projects/${project.id}/reviews`, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ sourceOnly: true }) });
expect(response.status).toBe(201);
const reviewed = await response.json() as { report: { issues: Array<{ title: string; rationale: string }> } };
const titles = reviewed.report.issues.map((issue) => issue.title);
for (const title of ["缺少消融实验", "威胁模型不完整", "Résumé incomplet", "⚠️", "❗", "कला", "किला"]) expect(titles.filter((item) => item === title)).toHaveLength(1);
expect(titles).not.toContain("Re\u0301sume\u0301 incomplet!");
expect(reviewed.report.issues.find((issue) => issue.title === "缺少消融实验")?.rationale).toContain("Finding 2");
const reports = await (await request(`/api/projects/${project.id}/reviews`)).json() as Array<{ issues: Array<{ title: string }> }>;
expect(reports[0]?.issues.map((issue) => issue.title)).toEqual(titles);
});

test("cancels an in-flight Review without persisting a partial report", async () => {
const provider: AgentProvider = {
async revise(input) { return { replacement: input.selection.text, rationale: "unused" }; },
Expand Down
26 changes: 26 additions & 0 deletions apps/server/src/claims/claim-http.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,32 @@ test("HTTP file rename preserves another project's supported workspace evidence"
]);
});

test("HTTP workspace evidence keeps distinct files and anchored passages with idempotent retries", async () => {
const { request, save } = await fixture();
const project = await request<PaperProject>("/projects", "POST", { name: "Independent support" }, 201);
const base = `/projects/${project.id}`;
await save(project.id, "The evaluated result improves accuracy by 10%.");
const [claim] = await request<PaperClaim[]>(`${base}/claim-scans`, "POST", undefined, 201);
const content = "First independent measurement.\nSecond independent measurement.\n";
for (const path of ["evidence.tex", "other.tex"]) await request(`${base}/files`, "POST", { path, content }, 201);
const link = async (path: string, startOffset: number, endOffset: number) => {
const opened = await request<FileContentResponse>(`${base}/file?path=${path}`);
return request<ClaimEvidenceLink>(`${base}/claims/${claim!.id}/links`, "POST", { kind: "workspace", path, anchor: {
path, fileVersion: opened.file.version, startOffset, endOffset, exactText: opened.content.slice(startOffset, endOffset), prefix: "", suffix: "",
} }, 201);
};
const first = await link("evidence.tex", 0, content.indexOf("\n"));
const second = await link("evidence.tex", content.indexOf("\n") + 1, content.length - 1);
const other = await link("other.tex", 0, content.indexOf("\n"));
expect(new Set([first.id, second.id, other.id]).size).toBe(3);
expect((await link("evidence.tex", 0, content.indexOf("\n"))).id).toBe(first.id);
const links = await request<ClaimEvidenceLink[]>(`${base}/claim-links`);
expect(links).toHaveLength(3);
expect(links.map((item) => item.id)).toEqual([first.id, second.id, other.id]);
await request(`${base}/claims/${claim!.id}/links/${second.id}`, "DELETE", undefined, 204);
expect((await request<ClaimEvidenceLink[]>(`${base}/claim-links`)).map((item) => item.id)).toEqual([first.id, other.id]);
});

test("HTTP scan and save keep decimal anchors and current reanchored semantics", async () => {
const { request, save } = await fixture();
const project = await request<PaperProject>("/projects", "POST", { name: "Claim semantics" }, 201);
Expand Down
7 changes: 6 additions & 1 deletion apps/server/src/claims/claim-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,12 @@ export class ClaimService {
return this.database.mutate((state) => {
if (!state.paperClaims.some((claim) => claim.projectId === projectId && claim.id === claimId)) throw new ApiError(404, "claim_not_found", "Claim not found");
if (checked.kind === "literature" && !state.sourceEvidence.some((evidence) => evidence.id === checked.evidenceId && evidence.projectId === projectId)) throw new ApiError(400, "evidence_not_found", "Evidence does not belong to this project");
const duplicate = state.claimEvidenceLinks.find((candidate) => candidate.claimId === claimId && candidate.kind === checked.kind && (candidate.kind !== "literature" || checked.kind !== "literature" || candidate.evidenceId === checked.evidenceId));
const duplicate = state.claimEvidenceLinks.find((candidate) => {
if (candidate.claimId !== claimId || candidate.kind !== checked.kind) return false;
if (candidate.kind === "literature" && checked.kind === "literature") return candidate.evidenceId === checked.evidenceId;
if (candidate.kind === "workspace" && checked.kind === "workspace") return candidate.path === checked.path && candidate.anchor.fileVersion === checked.anchor.fileVersion && candidate.anchor.startOffset === checked.anchor.startOffset && candidate.anchor.endOffset === checked.anchor.endOffset && candidate.anchor.exactText === checked.anchor.exactText;
return true;
});
if (duplicate) return duplicate;
const created = { ...checked, id: `claim_link_${crypto.randomUUID()}`, claimId } as ClaimEvidenceLink;
state.claimEvidenceLinks.push(created);
Expand Down
Loading