fix(sync): סנכרון-הסטטוס יכתוב רק על issue-שורש פתוח, לא על sub-task שנסגר (#446)
הג'וב sync-case-status כתב על כל issue מקושר-לתיק שסטטוסו שונה מהיעד — השומר היחיד היה 'issue.status !== targetStatus'. לכן הוא החזיר sub-tasks שנסגרו (done) ל-in_progress, כפי שתועד ב-CMPA-140 / תיק 8125-09-24. בחירת-היעד חולצה ל-src/sync-target.ts: נבחר שורש יחיד (parentId === null) שאינו done/cancelled ואינו in_review/blocked; אפס או יותר-מאחד → לא נכתב דבר, ונרשם לוג עם הסיבה. שני הקבועים מובחנים בכוונה — CLOSED_ISSUE_STATUSES הוא ההגדרה היחידה של 'סגור' (מראה של legal-ai/web/paperclip_client.py:561), ו-NON_WRITABLE_STATUSES הוא 'מצב בבעלות Paperclip/בהמתנה-לאדם': כתיבת in_progress על issue ב-in_review מזמינה auto-block תוך דקה (legal-ai/docs/paperclip-quirks.md §3) וגונבת אותו מתור-הביקורת של היו"ר. הלולאה הכפולה הוחלפה במעבר אחד + קיבוץ למפת case_number→מועמדים; הקיבוץ נדרש כדי לבחור 'השורש היחיד', וכתוצר-לוואי O(NxM)→O(M) קריאות state.get. מבחן-רגרסיה (node --test, ללא תלויות חדשות) משחזר את 11 ה-issues שנמדדו לתיק 8125-09-24 ומוכיח את הדלתא: הכלל הישן היה כותב על CMPA-140, החדש לא. בבעלות ריפו זה בהחלטת פאנל — העברת הלוגיקה ל-legal-ai נפסלה כי היא מוסיפה UPDATE ישיר ל-DB של Paperclip, בהפרת INV-INT4 (GAP-24/25).
This commit is contained in:
134
src/sync-target.test.ts
Normal file
134
src/sync-target.test.ts
Normal file
@@ -0,0 +1,134 @@
|
||||
/// <reference types="node" />
|
||||
|
||||
import assert from "node:assert/strict";
|
||||
import { test } from "node:test";
|
||||
// Excluded from tsc (tsconfig.json) — never bundled/emitted, run natively via
|
||||
// `node --test`, which requires the literal `.ts` extension (Node's ESM
|
||||
// resolver does not remap `.js` specifiers to `.ts` files at runtime).
|
||||
import { pickSyncTargetIssue, type SyncCandidate } from "./sync-target.ts";
|
||||
|
||||
/**
|
||||
* הכלל הישן (worker.ts:894 לפני #446): כל issue מקושר שסטטוסו שונה מהיעד —
|
||||
* נכתב, בלי סינון parentId ובלי סינון-סטטוס.
|
||||
*/
|
||||
function legacyTargets(
|
||||
candidates: readonly SyncCandidate[],
|
||||
targetStatus: string,
|
||||
): string[] {
|
||||
return candidates.filter((c) => c.status !== targetStatus).map((c) => c.id);
|
||||
}
|
||||
|
||||
test("רגרסיית 8125-09-24 / CMPA-140: 11 ה-issues הממשיים של התיק, אף sub-task done לא נבחר", () => {
|
||||
// נמדד ב-DB החי של Paperclip (2026-08-24) — כל ה-issues המקושרים לתיק
|
||||
// 8125-09-24. CMPA-140 (זה שנדרס בפועל, done→in_progress) הוא **ילד** של
|
||||
// CMPA-139, לא שורש. CMPA-139 עצמו אינו ברשימה בכוונה: נמדד שאין לו
|
||||
// רשומת legal-case-number ב-plugin_state, ולכן הוא לא מגיע כמועמד כלל —
|
||||
// לילד יש הורה שאינו מקושר.
|
||||
const candidates: SyncCandidate[] = [
|
||||
{ id: "CMPA-116", status: "cancelled", parentId: null },
|
||||
{ id: "CMPA-84", status: "cancelled", parentId: null },
|
||||
{ id: "CMPA-86", status: "cancelled", parentId: null },
|
||||
{ id: "CMPA-140", status: "done", parentId: "CMPA-139" }, // זה שנדרס בפועל
|
||||
{ id: "CMPA-141", status: "cancelled", parentId: "CMPA-139" },
|
||||
{ id: "CMPA-85", status: "done", parentId: "CMPA-84" },
|
||||
{ id: "CMPA-146", status: "done", parentId: "CMPA-84" },
|
||||
{ id: "CMPA-147", status: "done", parentId: "CMPA-84" },
|
||||
{ id: "CMPA-87", status: "done", parentId: "CMPA-86" },
|
||||
{ id: "CMPA-88", status: "done", parentId: "CMPA-86" },
|
||||
{ id: "CMPA-89", status: "cancelled", parentId: "CMPA-86" },
|
||||
];
|
||||
|
||||
// סטטוס-התיק היה drafted → in_progress (CASE_STATUS_TO_ISSUE_STATUS ב-worker.ts).
|
||||
const targetStatus = "in_progress";
|
||||
|
||||
// הכלל הישן היה כותב על CMPA-140 — זה הבאג שתועד.
|
||||
assert.ok(legacyTargets(candidates, targetStatus).includes("CMPA-140"));
|
||||
|
||||
const result = pickSyncTargetIssue(candidates);
|
||||
|
||||
// הכלל החדש אינו כותב על דבר.
|
||||
assert.equal(result.target, null);
|
||||
assert.equal(result.reason, "no_writable_root");
|
||||
});
|
||||
|
||||
test("sub-task יחיד ב-done ומקושר: sub-task לעולם לא נבחר", () => {
|
||||
const candidates: SyncCandidate[] = [
|
||||
{ id: "sub-1", status: "done", parentId: "some-root" },
|
||||
];
|
||||
|
||||
const result = pickSyncTargetIssue(candidates);
|
||||
|
||||
assert.equal(result.target, null);
|
||||
assert.equal(result.reason, "no_writable_root");
|
||||
});
|
||||
|
||||
test("sub-task יחיד פתוח (in_progress) + שורש cancelled: פתוח אינו מספיק, חייב שורש", () => {
|
||||
const candidates: SyncCandidate[] = [
|
||||
{ id: "root-1", status: "cancelled", parentId: null },
|
||||
{ id: "sub-1", status: "in_progress", parentId: "root-1" },
|
||||
];
|
||||
|
||||
const result = pickSyncTargetIssue(candidates);
|
||||
|
||||
assert.equal(result.target, null);
|
||||
assert.equal(result.reason, "no_writable_root");
|
||||
});
|
||||
|
||||
test("שורש יחיד ב-todo: נבחר", () => {
|
||||
const candidates: SyncCandidate[] = [
|
||||
{ id: "root-1", status: "todo", parentId: null },
|
||||
];
|
||||
|
||||
const result = pickSyncTargetIssue(candidates);
|
||||
|
||||
assert.equal(result.target?.id, "root-1");
|
||||
assert.equal(result.reason, "ok");
|
||||
assert.equal(result.writableRoots, 1);
|
||||
});
|
||||
|
||||
test("שורש יחיד ב-in_review: לא נכתב (הגנת auto-block)", () => {
|
||||
const candidates: SyncCandidate[] = [
|
||||
{ id: "root-1", status: "in_review", parentId: null },
|
||||
];
|
||||
|
||||
const result = pickSyncTargetIssue(candidates);
|
||||
|
||||
assert.equal(result.target, null);
|
||||
assert.equal(result.reason, "no_writable_root");
|
||||
});
|
||||
|
||||
test("שורש יחיד ב-blocked: לא נכתב", () => {
|
||||
const candidates: SyncCandidate[] = [
|
||||
{ id: "root-1", status: "blocked", parentId: null },
|
||||
];
|
||||
|
||||
const result = pickSyncTargetIssue(candidates);
|
||||
|
||||
assert.equal(result.target, null);
|
||||
assert.equal(result.reason, "no_writable_root");
|
||||
});
|
||||
|
||||
test("שני שורשים ברי-כתיבה: ambiguous, לא נכתב", () => {
|
||||
const candidates: SyncCandidate[] = [
|
||||
{ id: "root-1", status: "todo", parentId: null },
|
||||
{ id: "root-2", status: "in_progress", parentId: null },
|
||||
];
|
||||
|
||||
const result = pickSyncTargetIssue(candidates);
|
||||
|
||||
assert.equal(result.target, null);
|
||||
assert.equal(result.reason, "ambiguous_writable_roots");
|
||||
assert.equal(result.writableRoots, 2);
|
||||
});
|
||||
|
||||
test("שורש todo + ילד in_progress: השורש נבחר", () => {
|
||||
const candidates: SyncCandidate[] = [
|
||||
{ id: "root-1", status: "todo", parentId: null },
|
||||
{ id: "child-1", status: "in_progress", parentId: "root-1" },
|
||||
];
|
||||
|
||||
const result = pickSyncTargetIssue(candidates);
|
||||
|
||||
assert.equal(result.target?.id, "root-1");
|
||||
assert.equal(result.reason, "ok");
|
||||
});
|
||||
Reference in New Issue
Block a user