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 paste preflight source", () => {
  it("rust_family 粘贴链应走 Rust paste preflight，而不是本地 shell row 语义推导", () => {
    const source = fs.readFileSync(SIDEBAR_SOURCE, "utf8");
    const preflightIndex = source.indexOf("preflightFileTreePaste(");
    const rustBranchStart = source.lastIndexOf("if (isRustFamilyTreeRenderer) {", preflightIndex);
    const legacyBranchStart = source.indexOf("const targetDocId = inferPasteTargetDocId", preflightIndex);

    expect(preflightIndex).toBeGreaterThanOrEqual(0);
    expect(rustBranchStart).toBeGreaterThanOrEqual(0);
    expect(legacyBranchStart).toBeGreaterThan(rustBranchStart);
    const rustPasteBranch = source.slice(rustBranchStart, legacyBranchStart);

    expect(rustPasteBranch).toContain("preflightFileTreePaste(");
    expect(rustPasteBranch).toContain("buildFileTreeShellPastePreflightPayload(");
    expect(rustPasteBranch).toContain("pastePlan.docItems");
    expect(rustPasteBranch).toContain("pastePlan.resourceTransferPlan");
    expect(rustPasteBranch).not.toContain("docItemsMap");
    expect(rustPasteBranch).not.toContain("copyableAssetIds");
    expect(source).not.toContain("getOrderedFileTreeShellRows");
  });
});
