import { join } from "node:path";

import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";

import {
  RULESYNC_OVERVIEW_FILE_NAME,
  RULESYNC_RELATIVE_DIR_PATH,
  RULESYNC_RULES_RELATIVE_DIR_PATH,
} from "../../constants/rulesync-paths.js";
import { setupTestDirectory } from "../../test-utils/test-directories.js";
import { ensureDir, writeFileContent } from "../../utils/file.js";
import { QwencodeRule } from "./qwencode-rule.js";
import { RulesyncRule } from "./rulesync-rule.js";

describe("QwencodeRule", () => {
  let testDir: string;
  let cleanup: () => Promise<void>;

  beforeEach(async () => {
    ({ testDir, cleanup } = await setupTestDirectory());
    vi.spyOn(process, "cwd").mockReturnValue(testDir);
  });

  afterEach(async () => {
    await cleanup();
    vi.restoreAllMocks();
  });

  describe("constructor", () => {
    it("should create instance with default parameters", () => {
      const qwencodeRule = new QwencodeRule({
        relativeDirPath: ".qwen/memories",
        relativeFilePath: "test-rule.md",
        fileContent: "# Test Rule\n\nThis is a test rule.",
      });

      expect(qwencodeRule).toBeInstanceOf(QwencodeRule);
      expect(qwencodeRule.getRelativeDirPath()).toBe(".qwen/memories");
      expect(qwencodeRule.getRelativeFilePath()).toBe("test-rule.md");
      expect(qwencodeRule.getFileContent()).toBe("# Test Rule\n\nThis is a test rule.");
      expect(qwencodeRule.isRoot()).toBe(false);
    });

    it("should create instance with custom outputRoot", () => {
      const qwencodeRule = new QwencodeRule({
        outputRoot: "/custom/path",
        relativeDirPath: ".qwen/memories",
        relativeFilePath: "test-rule.md",
        fileContent: "# Custom Rule",
      });

      expect(qwencodeRule.getFilePath()).toBe("/custom/path/.qwen/memories/test-rule.md");
      expect(qwencodeRule.isRoot()).toBe(false);
    });

    it("should validate content by default", () => {
      expect(() => {
        const _instance = new QwencodeRule({
          relativeDirPath: ".qwen/memories",
          relativeFilePath: "test-rule.md",
          fileContent: "", // empty content should be valid since validate always returns success
        });
      }).not.toThrow();
    });

    it("should skip validation when requested", () => {
      expect(() => {
        const _instance = new QwencodeRule({
          relativeDirPath: ".qwen/memories",
          relativeFilePath: "test-rule.md",
          fileContent: "",
          validate: false,
        });
      }).not.toThrow();
    });

    it("should handle root rule parameter", () => {
      const qwencodeRule = new QwencodeRule({
        relativeDirPath: ".",
        relativeFilePath: "QWEN.md",
        fileContent: "# Root Rule",
        root: true,
      });

      expect(qwencodeRule.isRoot()).toBe(true);
      expect(qwencodeRule.getFileContent()).toBe("# Root Rule");
    });

    it("should handle non-root rule parameter", () => {
      const qwencodeRule = new QwencodeRule({
        relativeDirPath: ".qwen/memories",
        relativeFilePath: "non-root-rule.md",
        fileContent: "# Non-Root Rule",
        root: false,
      });

      expect(qwencodeRule.isRoot()).toBe(false);
      expect(qwencodeRule.getFileContent()).toBe("# Non-Root Rule");
    });
  });

  describe("fromFile", () => {
    it("should create instance from existing non-root file", async () => {
      // Setup test file
      const memoriesDir = join(testDir, ".qwen/memories");
      await ensureDir(memoriesDir);
      const testContent = "# Test Rule from File\n\nContent from file.";
      await writeFileContent(join(memoriesDir, "test.md"), testContent);

      const qwencodeRule = await QwencodeRule.fromFile({
        outputRoot: testDir,
        relativeFilePath: "test.md",
      });

      expect(qwencodeRule.getRelativeDirPath()).toBe(".qwen/memories");
      expect(qwencodeRule.getRelativeFilePath()).toBe("test.md");
      expect(qwencodeRule.getFileContent()).toBe(testContent);
      expect(qwencodeRule.getFilePath()).toBe(join(testDir, ".qwen/memories/test.md"));
      expect(qwencodeRule.isRoot()).toBe(false);
    });

    it("should create instance from existing root file (QWEN.md)", async () => {
      // Setup root test file
      const testContent = "# Root Rule from File\n\nThis is the root QWEN.md file.";
      await writeFileContent(join(testDir, "QWEN.md"), testContent);

      const qwencodeRule = await QwencodeRule.fromFile({
        outputRoot: testDir,
        relativeFilePath: "QWEN.md",
      });

      expect(qwencodeRule.getRelativeDirPath()).toBe(".");
      expect(qwencodeRule.getRelativeFilePath()).toBe("QWEN.md");
      expect(qwencodeRule.getFileContent()).toBe(testContent);
      expect(qwencodeRule.getFilePath()).toBe(join(testDir, "QWEN.md"));
      expect(qwencodeRule.isRoot()).toBe(true);
    });

    it("should use default outputRoot when not provided", async () => {
      // Setup test file in test directory (process.cwd() is mocked to return testDir)
      const memoriesDir = join(testDir, ".qwen/memories");
      await ensureDir(memoriesDir);
      const testContent = "# Default OutputRoot Test";
      const testFilePath = join(memoriesDir, "default-test.md");
      await writeFileContent(testFilePath, testContent);

      const qwencodeRule = await QwencodeRule.fromFile({
        relativeFilePath: "default-test.md",
      });

      expect(qwencodeRule.getRelativeDirPath()).toBe(".qwen/memories");
      expect(qwencodeRule.getRelativeFilePath()).toBe("default-test.md");
      expect(qwencodeRule.getFileContent()).toBe(testContent);
      expect(qwencodeRule.isRoot()).toBe(false);
      expect(qwencodeRule.getFilePath()).toBe(join(testDir, ".qwen/memories/default-test.md"));
    });

    it("should handle root file detection with default outputRoot", async () => {
      // Setup root test file in test directory (process.cwd() is mocked to return testDir)
      const testContent = "# Root Default OutputRoot Test";
      const rootFilePath = join(testDir, "QWEN.md");
      await writeFileContent(rootFilePath, testContent);

      const qwencodeRule = await QwencodeRule.fromFile({
        relativeFilePath: "QWEN.md",
      });

      expect(qwencodeRule.getRelativeDirPath()).toBe(".");
      expect(qwencodeRule.getRelativeFilePath()).toBe("QWEN.md");
      expect(qwencodeRule.getFileContent()).toBe(testContent);
      expect(qwencodeRule.isRoot()).toBe(true);
      expect(qwencodeRule.getFilePath()).toBe(join(testDir, "QWEN.md"));
    });

    it("should handle validation parameter", async () => {
      const memoriesDir = join(testDir, ".qwen/memories");
      await ensureDir(memoriesDir);
      const testContent = "# Validation Test";
      await writeFileContent(join(memoriesDir, "validation-test.md"), testContent);

      const qwencodeRuleWithValidation = await QwencodeRule.fromFile({
        outputRoot: testDir,
        relativeFilePath: "validation-test.md",
        validate: true,
      });

      const qwencodeRuleWithoutValidation = await QwencodeRule.fromFile({
        outputRoot: testDir,
        relativeFilePath: "validation-test.md",
        validate: false,
      });

      expect(qwencodeRuleWithValidation.getFileContent()).toBe(testContent);
      expect(qwencodeRuleWithoutValidation.getFileContent()).toBe(testContent);
    });

    it("should throw error when file does not exist", async () => {
      await expect(
        QwencodeRule.fromFile({
          outputRoot: testDir,
          relativeFilePath: "nonexistent.md",
        }),
      ).rejects.toThrow();
    });

    it("should throw error when root file does not exist", async () => {
      await expect(
        QwencodeRule.fromFile({
          outputRoot: testDir,
          relativeFilePath: "QWEN.md",
        }),
      ).rejects.toThrow();
    });
  });

  describe("fromRulesyncRule", () => {
    it("should create instance from non-root RulesyncRule", () => {
      const rulesyncRule = new RulesyncRule({
        relativeDirPath: RULESYNC_RELATIVE_DIR_PATH,
        relativeFilePath: "test-rule.md",
        frontmatter: {
          root: false,
          targets: ["*"],
          description: "Test rule",
          globs: [],
        },
        body: "# Test RulesyncRule\n\nContent from rulesync.",
      });

      const qwencodeRule = QwencodeRule.fromRulesyncRule({
        rulesyncRule,
      });

      expect(qwencodeRule).toBeInstanceOf(QwencodeRule);
      expect(qwencodeRule.getRelativeDirPath()).toBe(".qwen/memories");
      expect(qwencodeRule.getRelativeFilePath()).toBe("test-rule.md");
      expect(qwencodeRule.getFileContent()).toBe("# Test RulesyncRule\n\nContent from rulesync.");
      expect(qwencodeRule.isRoot()).toBe(false);
    });

    it("should create instance from root RulesyncRule", () => {
      const rulesyncRule = new RulesyncRule({
        relativeDirPath: RULESYNC_RELATIVE_DIR_PATH,
        relativeFilePath: "root-rule.md",
        frontmatter: {
          root: true,
          targets: ["*"],
          description: "Root rule",
          globs: ["**/*"],
        },
        body: "# Root RulesyncRule\n\nContent from root rulesync.",
      });

      const qwencodeRule = QwencodeRule.fromRulesyncRule({
        rulesyncRule,
      });

      expect(qwencodeRule).toBeInstanceOf(QwencodeRule);
      expect(qwencodeRule.getRelativeDirPath()).toBe(".");
      expect(qwencodeRule.getRelativeFilePath()).toBe("QWEN.md");
      expect(qwencodeRule.getFileContent()).toBe(
        "# Root RulesyncRule\n\nContent from root rulesync.",
      );
      expect(qwencodeRule.isRoot()).toBe(true);
    });

    it("should use custom outputRoot", () => {
      const rulesyncRule = new RulesyncRule({
        relativeDirPath: RULESYNC_RELATIVE_DIR_PATH,
        relativeFilePath: "custom-base.md",
        frontmatter: {
          root: false,
          targets: ["*"],
          description: "",
          globs: [],
        },
        body: "# Custom Base Directory",
      });

      const qwencodeRule = QwencodeRule.fromRulesyncRule({
        outputRoot: "/custom/base",
        rulesyncRule,
      });

      expect(qwencodeRule.getFilePath()).toBe("/custom/base/.qwen/memories/custom-base.md");
      expect(qwencodeRule.isRoot()).toBe(false);
    });

    it("should handle validation parameter", () => {
      const rulesyncRule = new RulesyncRule({
        relativeDirPath: RULESYNC_RELATIVE_DIR_PATH,
        relativeFilePath: "validation.md",
        frontmatter: {
          root: false,
          targets: ["*"],
          description: "",
          globs: [],
        },
        body: "# Validation Test",
      });

      const qwencodeRuleWithValidation = QwencodeRule.fromRulesyncRule({
        rulesyncRule,
        validate: true,
      });

      const qwencodeRuleWithoutValidation = QwencodeRule.fromRulesyncRule({
        rulesyncRule,
        validate: false,
      });

      expect(qwencodeRuleWithValidation.getFileContent()).toBe("# Validation Test");
      expect(qwencodeRuleWithoutValidation.getFileContent()).toBe("# Validation Test");
    });

    it("should handle undefined root frontmatter as false", () => {
      const rulesyncRule = new RulesyncRule({
        relativeDirPath: RULESYNC_RELATIVE_DIR_PATH,
        relativeFilePath: "no-root-frontmatter.md",
        frontmatter: {
          targets: ["*"],
          description: "",
          globs: [],
        } as any, // root is undefined
        body: "# No Root Frontmatter",
      });

      const qwencodeRule = QwencodeRule.fromRulesyncRule({
        rulesyncRule,
      });

      expect(qwencodeRule.isRoot()).toBe(false);
      expect(qwencodeRule.getRelativeDirPath()).toBe(".qwen/memories");
    });
  });

  describe("toRulesyncRule", () => {
    it("should convert non-root QwencodeRule to RulesyncRule", () => {
      const qwencodeRule = new QwencodeRule({
        outputRoot: testDir,
        relativeDirPath: ".qwen/memories",
        relativeFilePath: "convert-test.md",
        fileContent: "# Convert Test\n\nThis will be converted.",
      });

      const rulesyncRule = qwencodeRule.toRulesyncRule();

      expect(rulesyncRule).toBeInstanceOf(RulesyncRule);
      expect(rulesyncRule.getRelativeDirPath()).toBe(RULESYNC_RULES_RELATIVE_DIR_PATH);
      expect(rulesyncRule.getRelativeFilePath()).toBe("convert-test.md");
      expect(rulesyncRule.getBody()).toBe("# Convert Test\n\nThis will be converted.");

      const frontmatter = rulesyncRule.getFrontmatter();
      expect(frontmatter.root).toBe(false);
      expect(frontmatter.targets).toEqual(["*"]);
      expect(frontmatter.description).toBeUndefined();
      expect(frontmatter.globs).toEqual([]);
    });

    it("should convert root QwencodeRule to RulesyncRule", () => {
      const qwencodeRule = new QwencodeRule({
        outputRoot: testDir,
        relativeDirPath: ".",
        relativeFilePath: "QWEN.md",
        fileContent: "# Root Convert Test\n\nThis root will be converted.",
        root: true,
      });

      const rulesyncRule = qwencodeRule.toRulesyncRule();

      expect(rulesyncRule).toBeInstanceOf(RulesyncRule);
      expect(rulesyncRule.getRelativeDirPath()).toBe(RULESYNC_RULES_RELATIVE_DIR_PATH);
      expect(rulesyncRule.getRelativeFilePath()).toBe(RULESYNC_OVERVIEW_FILE_NAME);
      expect(rulesyncRule.getBody()).toBe("# Root Convert Test\n\nThis root will be converted.");

      const frontmatter = rulesyncRule.getFrontmatter();
      expect(frontmatter.root).toBe(true);
      expect(frontmatter.targets).toEqual(["*"]);
      expect(frontmatter.description).toBeUndefined();
      expect(frontmatter.globs).toEqual(["**/*"]);
    });

    it("should preserve metadata in conversion", () => {
      const qwencodeRule = new QwencodeRule({
        outputRoot: "/test/path",
        relativeDirPath: ".qwen/memories",
        relativeFilePath: "metadata-test.md",
        fileContent: "# Metadata Test\n\nContent with metadata.",
      });

      const rulesyncRule = qwencodeRule.toRulesyncRule();

      expect(rulesyncRule.getFilePath()).toBe(
        join(testDir, RULESYNC_RULES_RELATIVE_DIR_PATH, "metadata-test.md"),
      );
      expect(rulesyncRule.getBody()).toBe("# Metadata Test\n\nContent with metadata.");
    });
  });

  describe("validate", () => {
    it("should always return success", () => {
      const qwencodeRule = new QwencodeRule({
        relativeDirPath: ".qwen/memories",
        relativeFilePath: "validation-test.md",
        fileContent: "# Any content is valid",
      });

      const result = qwencodeRule.validate();

      expect(result.success).toBe(true);
      expect(result.error).toBeNull();
    });

    it("should return success for empty content", () => {
      const qwencodeRule = new QwencodeRule({
        relativeDirPath: ".qwen/memories",
        relativeFilePath: "empty.md",
        fileContent: "",
      });

      const result = qwencodeRule.validate();

      expect(result.success).toBe(true);
      expect(result.error).toBeNull();
    });

    it("should return success for root content", () => {
      const qwencodeRule = new QwencodeRule({
        relativeDirPath: ".",
        relativeFilePath: "QWEN.md",
        fileContent: "# Root Content\n\nThis is root content.",
        root: true,
      });

      const result = qwencodeRule.validate();

      expect(result.success).toBe(true);
      expect(result.error).toBeNull();
    });

    it("should return success for any content format", () => {
      const contents = [
        "# Markdown content",
        "Plain text content",
        "---\nfrontmatter: true\n---\nContent with frontmatter",
        "/* Code comments */",
        "Invalid markdown ### ###",
      ];

      for (const content of contents) {
        const qwencodeRule = new QwencodeRule({
          relativeDirPath: ".qwen/memories",
          relativeFilePath: "test.md",
          fileContent: content,
        });

        const result = qwencodeRule.validate();
        expect(result.success).toBe(true);
        expect(result.error).toBeNull();
      }
    });
  });

  describe("getSettablePaths", () => {
    it("should return correct paths for root and nonRoot", () => {
      const paths = QwencodeRule.getSettablePaths();

      expect(paths.root).toEqual({
        relativeDirPath: ".",
        relativeFilePath: "QWEN.md",
      });

      expect(paths.nonRoot).toEqual({
        relativeDirPath: ".qwen/memories",
      });
    });

    it("should have consistent paths structure", () => {
      const paths = QwencodeRule.getSettablePaths();

      expect(paths).toHaveProperty("root");
      expect(paths).toHaveProperty("nonRoot");
      expect(paths.root).toHaveProperty("relativeDirPath");
      expect(paths.root).toHaveProperty("relativeFilePath");
      expect(paths.nonRoot).toHaveProperty("relativeDirPath");
    });
  });

  describe("isTargetedByRulesyncRule", () => {
    it("should return true for rules targeting qwencode", () => {
      const rulesyncRule = new RulesyncRule({
        outputRoot: testDir,
        relativeDirPath: ".qwen/memories",
        relativeFilePath: "test.md",
        frontmatter: {
          targets: ["qwencode"],
        },
        body: "Test content",
      });

      expect(QwencodeRule.isTargetedByRulesyncRule(rulesyncRule)).toBe(true);
    });

    it("should return true for rules targeting all tools (*)", () => {
      const rulesyncRule = new RulesyncRule({
        outputRoot: testDir,
        relativeDirPath: ".qwen/memories",
        relativeFilePath: "test.md",
        frontmatter: {
          targets: ["*"],
        },
        body: "Test content",
      });

      expect(QwencodeRule.isTargetedByRulesyncRule(rulesyncRule)).toBe(true);
    });

    it("should return false for rules not targeting qwencode", () => {
      const rulesyncRule = new RulesyncRule({
        outputRoot: testDir,
        relativeDirPath: ".qwen/memories",
        relativeFilePath: "test.md",
        frontmatter: {
          targets: ["cursor", "copilot"],
        },
        body: "Test content",
      });

      expect(QwencodeRule.isTargetedByRulesyncRule(rulesyncRule)).toBe(false);
    });

    it("should return false for empty targets", () => {
      const rulesyncRule = new RulesyncRule({
        outputRoot: testDir,
        relativeDirPath: ".qwen/memories",
        relativeFilePath: "test.md",
        frontmatter: {
          targets: [],
        },
        body: "Test content",
      });

      expect(QwencodeRule.isTargetedByRulesyncRule(rulesyncRule)).toBe(false);
    });

    it("should handle mixed targets including qwencode", () => {
      const rulesyncRule = new RulesyncRule({
        outputRoot: testDir,
        relativeDirPath: ".qwen/memories",
        relativeFilePath: "test.md",
        frontmatter: {
          targets: ["cursor", "qwencode", "copilot"],
        },
        body: "Test content",
      });

      expect(QwencodeRule.isTargetedByRulesyncRule(rulesyncRule)).toBe(true);
    });

    it("should handle undefined targets in frontmatter", () => {
      const rulesyncRule = new RulesyncRule({
        outputRoot: testDir,
        relativeDirPath: ".qwen/memories",
        relativeFilePath: "test.md",
        frontmatter: {},
        body: "Test content",
      });

      expect(QwencodeRule.isTargetedByRulesyncRule(rulesyncRule)).toBe(true);
    });
  });

  describe("integration tests", () => {
    it("should handle complete workflow from non-root file to rulesync rule", async () => {
      // Create original file
      const memoriesDir = join(testDir, ".qwen/memories");
      await ensureDir(memoriesDir);
      const originalContent = "# Integration Test\n\nComplete workflow test.";
      await writeFileContent(join(memoriesDir, "integration.md"), originalContent);

      // Load from file
      const qwencodeRule = await QwencodeRule.fromFile({
        outputRoot: testDir,
        relativeFilePath: "integration.md",
      });

      // Convert to rulesync rule
      const rulesyncRule = qwencodeRule.toRulesyncRule();

      // Verify conversion
      expect(rulesyncRule.getBody()).toBe(originalContent);
      expect(rulesyncRule.getRelativeDirPath()).toBe(RULESYNC_RULES_RELATIVE_DIR_PATH);
      expect(rulesyncRule.getRelativeFilePath()).toBe("integration.md");
    });

    it("should handle complete workflow from root file to rulesync rule", async () => {
      // Create root file
      const originalContent = "# Root Integration Test\n\nComplete root workflow test.";
      await writeFileContent(join(testDir, "QWEN.md"), originalContent);

      // Load from file
      const qwencodeRule = await QwencodeRule.fromFile({
        outputRoot: testDir,
        relativeFilePath: "QWEN.md",
      });

      expect(qwencodeRule.isRoot()).toBe(true);

      // Convert to rulesync rule
      const rulesyncRule = qwencodeRule.toRulesyncRule();

      // Verify conversion
      expect(rulesyncRule.getBody()).toBe(originalContent);
      expect(rulesyncRule.getRelativeDirPath()).toBe(RULESYNC_RULES_RELATIVE_DIR_PATH);
      expect(rulesyncRule.getRelativeFilePath()).toBe(RULESYNC_OVERVIEW_FILE_NAME);
      expect(rulesyncRule.getFrontmatter().root).toBe(true);
    });

    it("should handle roundtrip conversion rulesync -> qwencode -> rulesync", () => {
      const originalBody = "# Roundtrip Test\n\nContent should remain the same.";

      // Start with rulesync rule
      const originalRulesync = new RulesyncRule({
        outputRoot: testDir,
        relativeDirPath: RULESYNC_RELATIVE_DIR_PATH,
        relativeFilePath: "roundtrip.md",
        frontmatter: {
          root: false,
          targets: ["*"],
          description: "",
          globs: [],
        },
        body: originalBody,
      });

      // Convert to qwencode rule
      const qwencodeRule = QwencodeRule.fromRulesyncRule({
        outputRoot: testDir,
        rulesyncRule: originalRulesync,
      });

      // Convert back to rulesync rule
      const finalRulesync = qwencodeRule.toRulesyncRule();

      // Verify content preservation
      expect(finalRulesync.getBody()).toBe(originalBody);
      expect(finalRulesync.getRelativeFilePath()).toBe("roundtrip.md");
    });

    it("should preserve root status through roundtrip conversion", () => {
      const originalBody = "# Root Roundtrip Test";

      // Start with root rulesync rule
      const originalRulesync = new RulesyncRule({
        outputRoot: testDir,
        relativeDirPath: RULESYNC_RELATIVE_DIR_PATH,
        relativeFilePath: "root-roundtrip.md",
        frontmatter: {
          root: true,
          targets: ["*"],
          description: "",
          globs: ["**/*"],
        },
        body: originalBody,
      });

      // Convert to qwencode rule
      const qwencodeRule = QwencodeRule.fromRulesyncRule({
        outputRoot: testDir,
        rulesyncRule: originalRulesync,
      });

      expect(qwencodeRule.isRoot()).toBe(true);

      // Convert back to rulesync rule
      const finalRulesync = qwencodeRule.toRulesyncRule();

      // Verify root status preservation
      expect(finalRulesync.getFrontmatter().root).toBe(true);
      expect(finalRulesync.getFrontmatter().globs).toEqual(["**/*"]);
    });

    it("should handle path determination correctly for root vs non-root files", () => {
      // Test non-root file path determination
      const nonRootRulesync = new RulesyncRule({
        relativeDirPath: RULESYNC_RELATIVE_DIR_PATH,
        relativeFilePath: "non-root.md",
        frontmatter: {
          root: false,
          targets: ["*"],
          description: "",
          globs: [],
        },
        body: "# Non-Root Rule",
      });

      const nonRootQwencode = QwencodeRule.fromRulesyncRule({
        rulesyncRule: nonRootRulesync,
      });

      expect(nonRootQwencode.getRelativeDirPath()).toBe(".qwen/memories");
      expect(nonRootQwencode.getRelativeFilePath()).toBe("non-root.md");
      expect(nonRootQwencode.isRoot()).toBe(false);

      // Test root file path determination
      const rootRulesync = new RulesyncRule({
        relativeDirPath: RULESYNC_RELATIVE_DIR_PATH,
        relativeFilePath: "some-root.md",
        frontmatter: {
          root: true,
          targets: ["*"],
          description: "",
          globs: ["**/*"],
        },
        body: "# Root Rule",
      });

      const rootQwencode = QwencodeRule.fromRulesyncRule({
        rulesyncRule: rootRulesync,
      });

      expect(rootQwencode.getRelativeDirPath()).toBe(".");
      expect(rootQwencode.getRelativeFilePath()).toBe("QWEN.md");
      expect(rootQwencode.isRoot()).toBe(true);
    });
  });
});
