import { describe, expect, it } from "vitest";
import fs from "node:fs";
import path from "node:path";

const SIDEBAR_SOURCE = path.join(process.cwd(), "src/components/sidebar/sidebar.tsx");

describe("sidebar file tree upload target preflight source", () => {
  it("外部上传链应走 Rust upload target preflight，而不是在 Sidebar 解释目标行与工作区", () => {
    const source = fs.readFileSync(SIDEBAR_SOURCE, "utf8");
    const handlerStart = source.indexOf("const handleResourcePaneDropFiles = useCallback");
    const handlerEnd = source.indexOf("const handleResourcePaneInternalDrop = useCallback");

    expect(handlerStart).toBeGreaterThanOrEqual(0);
    expect(handlerEnd).toBeGreaterThan(handlerStart);
    const handlerSource = source.slice(handlerStart, handlerEnd);

    expect(handlerSource).toContain("preflightFileTreeUploadTarget(");
    expect(handlerSource).toContain("buildFileTreeShellUploadTargetPreflightPayload(");
    expect(handlerSource).toContain("uploadTargetPlan.workspaceId");
    expect(handlerSource).toContain("uploadTargetPlan.targetDocumentId");
    expect(handlerSource).toContain("uploadTargetPlan.targetMindmapId");
    expect(handlerSource).not.toContain("resolveFileTreeShellMindmapTargetId");
    expect(handlerSource).not.toContain("inferFileTreeShellTargetDocumentId");
    expect(handlerSource).not.toContain("sidebarData.documents.find");
  });
});
