fileService.test.ts 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153
  1. import {
  2. existsSync,
  3. mkdirSync,
  4. mkdtempSync,
  5. readFileSync,
  6. rmSync,
  7. symlinkSync,
  8. writeFileSync,
  9. } from "node:fs";
  10. import { homedir, tmpdir } from "node:os";
  11. import { join } from "node:path";
  12. import { afterEach, describe, expect, it, vi } from "vitest";
  13. import {
  14. createFileService,
  15. FileExistenceCache,
  16. isSkippableWorkspaceFileListError,
  17. } from "../src/file/fileService.js";
  18. import { setDataBaseDir } from "../src/paths.js";
  19. import { unpackWorkspaceFileEntries } from "@zcode/shared/workspaceFileEntriesCodec";
  20. import type { IFileService } from "../src/file/file.js";
  21. // 分块拉全量(测试语义等价旧单次 listWorkspaceFiles)。
  22. async function readAllPacked(service: IFileService, rootPath: string): Promise<string> {
  23. const total = await service.listWorkspaceFilesLength({ rootPath });
  24. let packed = "";
  25. for (let offset = 0; offset < total; offset += 1000) {
  26. packed += await service.listWorkspaceFilesRange({ rootPath, offset, length: 1000 });
  27. }
  28. return packed;
  29. }
  30. const tempDirs: string[] = [];
  31. function makeTempDir(prefix: string): string {
  32. const dir = mkdtempSync(join(tmpdir(), prefix));
  33. tempDirs.push(dir);
  34. return dir;
  35. }
  36. afterEach(() => {
  37. setDataBaseDir(null);
  38. while (tempDirs.length > 0) {
  39. const dir = tempDirs.pop();
  40. if (dir) {
  41. rmSync(dir, { recursive: true, force: true });
  42. }
  43. }
  44. });
  45. describe("FileExistenceCache", () => {
  46. it("写入新条目前主动删除所有过期条目", () => {
  47. const now = vi.spyOn(Date, "now").mockReturnValue(1_000);
  48. const cache = new FileExistenceCache();
  49. try {
  50. cache.set("expired-a.pdf", true);
  51. cache.set("expired-b.pdf", false);
  52. expect(cache.size).toBe(2);
  53. now.mockReturnValue(61_001);
  54. cache.set("fresh.pdf", true);
  55. expect(cache.size).toBe(1);
  56. expect(cache.get("expired-a.pdf")).toBeUndefined();
  57. expect(cache.get("expired-b.pdf")).toBeUndefined();
  58. expect(cache.get("fresh.pdf")).toBe(true);
  59. } finally {
  60. now.mockRestore();
  61. }
  62. });
  63. it("最多保留 100 条并按 LRU 淘汰", () => {
  64. const cache = new FileExistenceCache();
  65. for (let index = 0; index < 100; index += 1) {
  66. cache.set(`file-${index}.pdf`, false);
  67. }
  68. expect(cache.get("file-0.pdf")).toBe(false);
  69. cache.set("file-100.pdf", true);
  70. expect(cache.size).toBe(100);
  71. expect(cache.get("file-0.pdf")).toBe(false);
  72. expect(cache.get("file-1.pdf")).toBeUndefined();
  73. expect(cache.get("file-100.pdf")).toBe(true);
  74. });
  75. });
  76. describe("fileService", () => {
  77. // ── readdir ──────────────────────────────────────────────────────
  78. describe("readdir", () => {
  79. it("lists directory entries, filters hidden files, sorts directories first then alphabetically", async () => {
  80. const rootPath = makeTempDir("zcode-readdir-");
  81. mkdirSync(join(rootPath, "src"));
  82. mkdirSync(join(rootPath, "assets"));
  83. mkdirSync(join(rootPath, ".hidden-dir"));
  84. writeFileSync(join(rootPath, "readme.md"), "# Hello");
  85. writeFileSync(join(rootPath, "package.json"), "{}");
  86. writeFileSync(join(rootPath, ".gitignore"), "node_modules");
  87. const service = createFileService();
  88. const entries = await service.readdir({ path: rootPath });
  89. expect(entries).toEqual([
  90. {
  91. name: "assets",
  92. path: join(rootPath, "assets"),
  93. type: "directory",
  94. isSymbolicLink: false,
  95. },
  96. {
  97. name: "src",
  98. path: join(rootPath, "src"),
  99. type: "directory",
  100. isSymbolicLink: false,
  101. },
  102. {
  103. name: "package.json",
  104. path: join(rootPath, "package.json"),
  105. type: "file",
  106. isSymbolicLink: false,
  107. },
  108. {
  109. name: "readme.md",
  110. path: join(rootPath, "readme.md"),
  111. type: "file",
  112. isSymbolicLink: false,
  113. },
  114. ]);
  115. });
  116. it("includes hidden files when requested", async () => {
  117. const rootPath = makeTempDir("zcode-readdir-hidden-");
  118. mkdirSync(join(rootPath, ".github"));
  119. mkdirSync(join(rootPath, "src"));
  120. writeFileSync(join(rootPath, ".gitignore"), "node_modules");
  121. writeFileSync(join(rootPath, "readme.md"), "# Hello");
  122. const service = createFileService();
  123. const entries = await service.readdir({ path: rootPath, includeHidden: true });
  124. expect(entries).toEqual([
  125. {
  126. name: ".github",
  127. path: join(rootPath, ".github"),
  128. type: "directory",
  129. isSymbolicLink: false,
  130. },
  131. {
  132. name: "src",
  133. path: join(rootPath, "src"),
  134. type: "directory",
  135. isSymbolicLink: false,
  136. },
  137. {
  138. name: ".gitignore",
  139. path: join(rootPath, ".gitignore"),
  140. type: "file",
  141. isSymbolicLink: false,
  142. },
  143. {
  144. name: "readme.md",
  145. path: join(rootPath, "readme.md"),
  146. type: "file",
  147. isSymbolicLink: false,
  148. },
  149. ]);
  150. });
  151. it("classifies symlinks to directories as directories", async () => {
  152. const rootPath = makeTempDir("zcode-readdir-symlink-dir-");
  153. const targetPath = join(rootPath, "target");
  154. const linkPath = join(rootPath, "linked-dir");
  155. mkdirSync(targetPath);
  156. symlinkSync(targetPath, linkPath, process.platform === "win32" ? "junction" : "dir");
  157. const service = createFileService();
  158. const entries = await service.readdir({ path: rootPath });
  159. expect(entries).toContainEqual({
  160. name: "linked-dir",
  161. path: linkPath,
  162. type: "directory",
  163. isSymbolicLink: true,
  164. });
  165. });
  166. it("returns empty array for an empty directory", async () => {
  167. const rootPath = makeTempDir("zcode-readdir-empty-");
  168. const service = createFileService();
  169. const entries = await service.readdir({ path: rootPath });
  170. expect(entries).toEqual([]);
  171. });
  172. });
  173. // ── stat ─────────────────────────────────────────────────────────
  174. describe("stat", () => {
  175. it("distinguishes files from directories", async () => {
  176. const rootPath = makeTempDir("zcode-stat-");
  177. const filePath = join(rootPath, "readme.md");
  178. writeFileSync(filePath, "# Hello");
  179. const service = createFileService();
  180. await expect(service.stat({ path: rootPath })).resolves.toEqual({
  181. path: rootPath,
  182. type: "directory",
  183. });
  184. await expect(service.stat({ path: filePath })).resolves.toEqual({
  185. path: filePath,
  186. type: "file",
  187. size: 7,
  188. mtimeMs: expect.any(Number),
  189. });
  190. });
  191. });
  192. describe("checkFilesExist", () => {
  193. it("并发返回文件存在性并把目录和缺失路径判为不可预览", async () => {
  194. const rootPath = makeTempDir("zcode-file-exists-");
  195. const filePath = join(rootPath, "report.pdf");
  196. const directoryPath = join(rootPath, "docs");
  197. const missingPath = join(rootPath, "missing.pdf");
  198. writeFileSync(filePath, "pdf");
  199. mkdirSync(directoryPath);
  200. await expect(
  201. createFileService().checkFilesExist({
  202. paths: [filePath, directoryPath, missingPath],
  203. }),
  204. ).resolves.toEqual([
  205. { path: filePath, exists: true },
  206. { path: directoryPath, exists: false },
  207. { path: missingPath, exists: false },
  208. ]);
  209. });
  210. it("正负结果缓存一分钟,过期后重新读取文件状态", async () => {
  211. const now = vi.spyOn(Date, "now").mockReturnValue(1_000);
  212. const rootPath = makeTempDir("zcode-file-exists-cache-");
  213. const filePath = join(rootPath, "later.pdf");
  214. const service = createFileService();
  215. await expect(service.checkFilesExist({ paths: [filePath] })).resolves.toEqual([
  216. { path: filePath, exists: false },
  217. ]);
  218. writeFileSync(filePath, "created");
  219. now.mockReturnValue(60_999);
  220. await expect(service.checkFilesExist({ paths: [filePath] })).resolves.toEqual([
  221. { path: filePath, exists: false },
  222. ]);
  223. now.mockReturnValue(61_001);
  224. await expect(service.checkFilesExist({ paths: [filePath] })).resolves.toEqual([
  225. { path: filePath, exists: true },
  226. ]);
  227. now.mockRestore();
  228. });
  229. it("拒绝超过单批 15 个路径", async () => {
  230. const service = createFileService();
  231. await expect(
  232. service.checkFilesExist({
  233. paths: Array.from({ length: 16 }, (_, index) => `/tmp/file-${index}.pdf`),
  234. }),
  235. ).rejects.toThrow("15");
  236. });
  237. });
  238. // ── ensureConversationWorkspace ──────────────────────────────────
  239. describe("ensureConversationWorkspace", () => {
  240. it("creates the managed conversation workspace under the configured data root", async () => {
  241. const dataBaseDir = makeTempDir("zcode-conversation-workspace-");
  242. setDataBaseDir(dataBaseDir);
  243. const service = createFileService();
  244. const workspacePath = join(dataBaseDir, ".zcode", "workspace", "default");
  245. await expect(service.ensureConversationWorkspace()).resolves.toEqual({
  246. path: workspacePath,
  247. created: true,
  248. workspacePurpose: "conversation",
  249. });
  250. await expect(service.ensureConversationWorkspace()).resolves.toEqual({
  251. path: workspacePath,
  252. created: false,
  253. workspacePurpose: "conversation",
  254. });
  255. await expect(service.stat({ path: workspacePath })).resolves.toEqual({
  256. path: workspacePath,
  257. type: "directory",
  258. });
  259. });
  260. it("rejects a file collision without returning a half-created workspace", async () => {
  261. const dataBaseDir = makeTempDir("zcode-conversation-workspace-file-");
  262. setDataBaseDir(dataBaseDir);
  263. const workspaceRoot = join(dataBaseDir, ".zcode", "workspace");
  264. mkdirSync(workspaceRoot, { recursive: true });
  265. writeFileSync(join(workspaceRoot, "default"), "not a directory");
  266. await expect(createFileService().ensureConversationWorkspace()).rejects.toThrow(
  267. "Workspace path is not a directory",
  268. );
  269. });
  270. });
  271. // ── createScratchWorkspace ───────────────────────────────────────
  272. describe("createScratchWorkspace", () => {
  273. const scratchRoot = join(homedir(), "ZCodeProject");
  274. const testWorkspaceName = `zcode-file-service-test-${Date.now()}`;
  275. const testWorkspacePath = join(scratchRoot, testWorkspaceName);
  276. afterEach(() => {
  277. rmSync(testWorkspacePath, { recursive: true, force: true });
  278. rmSync(`${testWorkspacePath}-file`, { force: true });
  279. });
  280. it("creates a missing scratch workspace directory", async () => {
  281. const service = createFileService();
  282. await expect(service.createScratchWorkspace({ name: testWorkspaceName })).resolves.toEqual({
  283. path: testWorkspacePath,
  284. });
  285. await expect(service.stat({ path: testWorkspacePath })).resolves.toEqual({
  286. path: testWorkspacePath,
  287. type: "directory",
  288. });
  289. await expect(
  290. service.readdir({ path: testWorkspacePath, includeHidden: true }),
  291. ).resolves.toEqual([]);
  292. });
  293. it("succeeds idempotently when the directory already exists", async () => {
  294. mkdirSync(testWorkspacePath, { recursive: true });
  295. const service = createFileService();
  296. await expect(service.createScratchWorkspace({ name: testWorkspaceName })).resolves.toEqual({
  297. path: testWorkspacePath,
  298. });
  299. });
  300. it("throws when the target path conflicts with a file", async () => {
  301. const fileWorkspaceName = `${testWorkspaceName}-file`;
  302. const fileWorkspacePath = `${testWorkspacePath}-file`;
  303. mkdirSync(scratchRoot, { recursive: true });
  304. writeFileSync(fileWorkspacePath, "not a directory");
  305. const service = createFileService();
  306. await expect(service.createScratchWorkspace({ name: fileWorkspaceName })).rejects.toThrow();
  307. });
  308. });
  309. // ── readTextFile ─────────────────────────────────────────────────
  310. describe("readTextFile", () => {
  311. it("reads full content of a small text file", async () => {
  312. const rootPath = makeTempDir("zcode-readtext-");
  313. const filePath = join(rootPath, "hello.txt");
  314. writeFileSync(filePath, "Hello, world!");
  315. const service = createFileService();
  316. const result = await service.readTextFile({ path: filePath });
  317. expect(result.content).toBe("Hello, world!");
  318. expect(result.offset).toBe(0);
  319. expect(result.bytesRead).toBe(13);
  320. expect(result.totalBytes).toBe(13);
  321. expect(result.truncated).toBe(false);
  322. expect(result.isBinary).toBe(false);
  323. });
  324. it("returns empty content when offset exceeds file size", async () => {
  325. const rootPath = makeTempDir("zcode-readtext-offset-");
  326. const filePath = join(rootPath, "small.txt");
  327. writeFileSync(filePath, "abc");
  328. const service = createFileService();
  329. const result = await service.readTextFile({ path: filePath, offset: 100 });
  330. expect(result.content).toBe("");
  331. expect(result.bytesRead).toBe(0);
  332. expect(result.totalBytes).toBe(3);
  333. expect(result.truncated).toBe(false);
  334. expect(result.isBinary).toBe(false);
  335. });
  336. it("reads a slice with offset and length", async () => {
  337. const rootPath = makeTempDir("zcode-readtext-slice-");
  338. const filePath = join(rootPath, "data.txt");
  339. writeFileSync(filePath, "abcdefghij");
  340. const service = createFileService();
  341. const result = await service.readTextFile({ path: filePath, offset: 3, length: 4 });
  342. expect(result.content).toBe("defg");
  343. expect(result.offset).toBe(3);
  344. expect(result.bytesRead).toBe(4);
  345. expect(result.totalBytes).toBe(10);
  346. // 偏移量3 + 读取4字节 = 7,文件总大小10,还有剩余
  347. expect(result.truncated).toBe(true);
  348. });
  349. it("detects binary files and returns empty content", async () => {
  350. const rootPath = makeTempDir("zcode-readtext-binary-");
  351. const filePath = join(rootPath, "image.bin");
  352. // 构造含大量 null 字节的二进制内容
  353. const binaryContent = Buffer.alloc(64, 0);
  354. writeFileSync(filePath, binaryContent);
  355. const service = createFileService();
  356. const result = await service.readTextFile({ path: filePath });
  357. expect(result.content).toBe("");
  358. expect(result.isBinary).toBe(true);
  359. expect(result.totalBytes).toBe(64);
  360. });
  361. it("truncates when file is larger than default read size", async () => {
  362. const rootPath = makeTempDir("zcode-readtext-large-");
  363. const filePath = join(rootPath, "large.txt");
  364. // 默认读取上限 128KB,写入 256KB 的内容
  365. const largeContent = "x".repeat(256 * 1024);
  366. writeFileSync(filePath, largeContent);
  367. const service = createFileService();
  368. const result = await service.readTextFile({ path: filePath });
  369. expect(result.bytesRead).toBe(128 * 1024);
  370. expect(result.totalBytes).toBe(256 * 1024);
  371. expect(result.truncated).toBe(true);
  372. expect(result.isBinary).toBe(false);
  373. });
  374. it("clamps length to MAX_TEXT_READ_BYTES (256KB)", async () => {
  375. const rootPath = makeTempDir("zcode-readtext-clamp-");
  376. const filePath = join(rootPath, "huge.txt");
  377. const content = "y".repeat(512 * 1024);
  378. writeFileSync(filePath, content);
  379. const service = createFileService();
  380. // 请求读取 512KB,应被截断到 256KB
  381. const result = await service.readTextFile({ path: filePath, length: 512 * 1024 });
  382. expect(result.bytesRead).toBe(256 * 1024);
  383. expect(result.truncated).toBe(true);
  384. });
  385. it("throws when path is not a file", async () => {
  386. const rootPath = makeTempDir("zcode-readtext-dir-");
  387. const service = createFileService();
  388. await expect(service.readTextFile({ path: rootPath })).rejects.toThrow(/not a file/);
  389. });
  390. });
  391. // ── readFileRange ────────────────────────────────────────────────
  392. describe("readFileRange", () => {
  393. it("reads raw bytes at the requested offset", async () => {
  394. const rootPath = makeTempDir("zcode-readrange-");
  395. const filePath = join(rootPath, "doc.pdf");
  396. writeFileSync(filePath, Buffer.from([0x25, 0x50, 0x44, 0x46, 0x2d, 0x31, 0x2e, 0x37]));
  397. const service = createFileService();
  398. const result = await service.readFileRange({ path: filePath, offset: 2, length: 4 });
  399. expect(result).toBeInstanceOf(Uint8Array);
  400. expect(Array.from(result)).toEqual([0x44, 0x46, 0x2d, 0x31]);
  401. });
  402. it("returns a short array when the range crosses EOF", async () => {
  403. const rootPath = makeTempDir("zcode-readrange-eof-");
  404. const filePath = join(rootPath, "doc.pdf");
  405. writeFileSync(filePath, Buffer.alloc(10, 7));
  406. const service = createFileService();
  407. const result = await service.readFileRange({ path: filePath, offset: 6, length: 64 });
  408. expect(result.length).toBe(4);
  409. });
  410. it("returns an empty array when offset exceeds file size", async () => {
  411. const rootPath = makeTempDir("zcode-readrange-offset-");
  412. const filePath = join(rootPath, "doc.pdf");
  413. writeFileSync(filePath, Buffer.alloc(3, 1));
  414. const service = createFileService();
  415. const result = await service.readFileRange({ path: filePath, offset: 100, length: 8 });
  416. expect(result.length).toBe(0);
  417. });
  418. it("clamps length to MAX_BINARY_READ_BYTES (1MB)", async () => {
  419. const rootPath = makeTempDir("zcode-readrange-clamp-");
  420. const filePath = join(rootPath, "large.pdf");
  421. writeFileSync(filePath, Buffer.alloc(1536 * 1024, 2));
  422. const service = createFileService();
  423. const result = await service.readFileRange({
  424. path: filePath,
  425. offset: 0,
  426. length: 2 * 1024 * 1024,
  427. });
  428. expect(result.length).toBe(1024 * 1024);
  429. });
  430. it("throws when path is not a file", async () => {
  431. const rootPath = makeTempDir("zcode-readrange-dir-");
  432. const service = createFileService();
  433. await expect(service.readFileRange({ path: rootPath, offset: 0, length: 8 })).rejects.toThrow(
  434. /not a file/,
  435. );
  436. });
  437. });
  438. // ── readMediaPreview ────────────────────────────────────────────
  439. describe("readMediaPreview", () => {
  440. it("reads image files as base64 previews with inferred media type", async () => {
  441. const rootPath = makeTempDir("zcode-readmedia-");
  442. const filePath = join(rootPath, "preview.png");
  443. writeFileSync(filePath, Buffer.from([0x89, 0x50, 0x4e, 0x47]));
  444. const service = createFileService();
  445. const result = await service.readMediaPreview({ path: filePath });
  446. expect(result).toEqual({
  447. path: filePath,
  448. mediaType: "image/png",
  449. dataBase64: Buffer.from([0x89, 0x50, 0x4e, 0x47]).toString("base64"),
  450. totalBytes: 4,
  451. });
  452. });
  453. it("rejects media previews that exceed the configured size limit", async () => {
  454. const rootPath = makeTempDir("zcode-readmedia-large-");
  455. const filePath = join(rootPath, "large.png");
  456. writeFileSync(filePath, Buffer.alloc(32, 1));
  457. const service = createFileService();
  458. await expect(service.readMediaPreview({ path: filePath, maxBytes: 16 })).rejects.toThrow(
  459. /too large/,
  460. );
  461. });
  462. it.each([
  463. ["clip.mp4", "video/mp4"],
  464. ["clip.mov", "video/quicktime"],
  465. ["clip.webm", "video/webm"],
  466. ["clip.m4v", "video/x-m4v"],
  467. ["song.mp3", "audio/mpeg"],
  468. ["song.wav", "audio/wav"],
  469. ["song.m4a", "audio/mp4"],
  470. ["song.ogg", "audio/ogg"],
  471. ["song.opus", "audio/opus"],
  472. ["song.flac", "audio/flac"],
  473. ["song.weba", "audio/webm"],
  474. ])("infers %s as %s", async (filename, mediaType) => {
  475. const rootPath = makeTempDir("zcode-readmedia-format-");
  476. const filePath = join(rootPath, filename);
  477. writeFileSync(filePath, Buffer.from([1, 2, 3]));
  478. const result = await createFileService().readMediaPreview({ path: filePath });
  479. expect(result.mediaType).toBe(mediaType);
  480. });
  481. });
  482. // ── readBinaryPreview ───────────────────────────────────────────
  483. describe("readBinaryPreview", () => {
  484. it("reads bounded binary files as base64 previews", async () => {
  485. const rootPath = makeTempDir("zcode-readbinary-");
  486. const filePath = join(rootPath, "workbook.xlsx");
  487. const content = Buffer.from([0x50, 0x4b, 0x03, 0x04]);
  488. writeFileSync(filePath, content);
  489. const service = createFileService();
  490. const result = await service.readBinaryPreview({ path: filePath });
  491. expect(result).toEqual({
  492. path: filePath,
  493. dataBase64: content.toString("base64"),
  494. totalBytes: content.byteLength,
  495. });
  496. });
  497. it("rejects binary previews before reading files above the configured limit", async () => {
  498. const rootPath = makeTempDir("zcode-readbinary-large-");
  499. const filePath = join(rootPath, "large.docx");
  500. writeFileSync(filePath, Buffer.alloc(32, 1));
  501. const service = createFileService();
  502. await expect(service.readBinaryPreview({ path: filePath, maxBytes: 16 })).rejects.toThrow(
  503. /too large/,
  504. );
  505. });
  506. it("clamps custom binary preview limits to the 25 MB hard limit", async () => {
  507. const rootPath = makeTempDir("zcode-readbinary-hard-limit-");
  508. const filePath = join(rootPath, "oversized.xlsx");
  509. writeFileSync(filePath, Buffer.alloc(25 * 1024 * 1024 + 1, 1));
  510. const service = createFileService();
  511. await expect(
  512. service.readBinaryPreview({
  513. path: filePath,
  514. maxBytes: Number.MAX_SAFE_INTEGER,
  515. }),
  516. ).rejects.toThrow(/too large/);
  517. });
  518. it("rejects directories", async () => {
  519. const rootPath = makeTempDir("zcode-readbinary-dir-");
  520. const service = createFileService();
  521. await expect(service.readBinaryPreview({ path: rootPath })).rejects.toThrow(/not a file/);
  522. });
  523. });
  524. // ── listWorkspaceFiles ───────────────────────────────────────────
  525. describe("listWorkspaceFiles", () => {
  526. it("classifies unreadable or disappearing directories as skippable mention index errors", () => {
  527. for (const code of ["EACCES", "EPERM", "ENOENT"]) {
  528. expect(isSkippableWorkspaceFileListError({ code })).toBe(true);
  529. }
  530. expect(isSkippableWorkspaceFileListError({ code: "EIO" })).toBe(false);
  531. expect(isSkippableWorkspaceFileListError(new Error("boom"))).toBe(false);
  532. });
  533. it("traverses hidden directories while keeping default excluded directories pruned", async () => {
  534. const rootPath = makeTempDir("zcode-file-service-");
  535. mkdirSync(join(rootPath, "src"));
  536. mkdirSync(join(rootPath, "node_modules"));
  537. mkdirSync(join(rootPath, ".git"));
  538. mkdirSync(join(rootPath, ".github", "workflows"), { recursive: true });
  539. writeFileSync(join(rootPath, "package.json"), "{}");
  540. writeFileSync(join(rootPath, ".gitignore"), "dist/\n");
  541. writeFileSync(join(rootPath, ".env"), "SECRET=123");
  542. writeFileSync(join(rootPath, ".env.local"), "SECRET=456");
  543. writeFileSync(join(rootPath, "src", "index.ts"), "export {};");
  544. writeFileSync(join(rootPath, "node_modules", "ignore-me.js"), "");
  545. writeFileSync(join(rootPath, ".git", "HEAD"), "ref: refs/heads/main");
  546. writeFileSync(join(rootPath, ".github", "workflows", "release.yml"), "name: release");
  547. const service = createFileService();
  548. const entries = unpackWorkspaceFileEntries(await readAllPacked(service, rootPath), rootPath);
  549. expect(entries).toEqual([
  550. {
  551. name: "src",
  552. path: join(rootPath, "src"),
  553. relativePath: "src",
  554. type: "directory",
  555. },
  556. {
  557. name: "release.yml",
  558. path: join(rootPath, ".github", "workflows", "release.yml"),
  559. relativePath: ".github/workflows/release.yml",
  560. type: "file",
  561. },
  562. {
  563. name: ".gitignore",
  564. path: join(rootPath, ".gitignore"),
  565. relativePath: ".gitignore",
  566. type: "file",
  567. },
  568. {
  569. name: "package.json",
  570. path: join(rootPath, "package.json"),
  571. relativePath: "package.json",
  572. type: "file",
  573. },
  574. {
  575. name: "index.ts",
  576. path: join(rootPath, "src", "index.ts"),
  577. relativePath: "src/index.ts",
  578. type: "file",
  579. },
  580. ]);
  581. });
  582. it("skips common generated cache and dependency directories across ecosystems", async () => {
  583. const rootPath = makeTempDir("zcode-file-service-generated-dirs-");
  584. const skippedDirectories = [
  585. ["__pycache__", "module.cpython-312.pyc"],
  586. ["coverage", "lcov.info"],
  587. ["htmlcov", "index.html"],
  588. ["lcov-report", "index.html"],
  589. ["bower_components", "dependency.js"],
  590. ["jspm_packages", "dependency.js"],
  591. ["Pods", "Manifest.lock"],
  592. ["CMakeFiles", "compiler_depend.make"],
  593. ["cmake-build-debug", "CMakeCache.txt"],
  594. ["bazel-out", "artifact.o"],
  595. ["DerivedData", "Build.db"],
  596. ["storybook-static", "iframe.html"],
  597. ["playwright-report", "index.html"],
  598. ["test-results", "trace.zip"],
  599. ["allure-results", "result.json"],
  600. ["allure-report", "index.html"],
  601. ["cdk.out", "manifest.json"],
  602. ["eggs", "package.egg"],
  603. ["pip-wheel-metadata", "metadata.json"],
  604. ["wheels", "package.whl"],
  605. ["package.egg-info", "PKG-INFO"],
  606. ["package.dist-info", "METADATA"],
  607. ];
  608. mkdirSync(join(rootPath, "src"));
  609. writeFileSync(join(rootPath, "src", "index.ts"), "export {};");
  610. for (const [directoryName, fileName] of skippedDirectories) {
  611. mkdirSync(join(rootPath, directoryName), { recursive: true });
  612. writeFileSync(join(rootPath, directoryName, fileName), "");
  613. }
  614. const service = createFileService();
  615. const entries = unpackWorkspaceFileEntries(await readAllPacked(service, rootPath), rootPath);
  616. expect(entries).toEqual([
  617. {
  618. name: "src",
  619. path: join(rootPath, "src"),
  620. relativePath: "src",
  621. type: "directory",
  622. },
  623. {
  624. name: "index.ts",
  625. path: join(rootPath, "src", "index.ts"),
  626. relativePath: "src/index.ts",
  627. type: "file",
  628. },
  629. ]);
  630. });
  631. it("skips standalone compiled and cache file artifacts", async () => {
  632. const rootPath = makeTempDir("zcode-file-service-generated-files-");
  633. const skippedFileNames = [
  634. "module.pyc",
  635. "module.pyo",
  636. "Main.class",
  637. "object.o",
  638. "library.obj",
  639. "archive.a",
  640. "library.lib",
  641. "addon.node",
  642. "library.so",
  643. "library.dylib",
  644. "library.dll",
  645. "program.exe",
  646. "program.pdb",
  647. "coverage.gcda",
  648. "coverage.profraw",
  649. "coverage.out",
  650. "lcov.info",
  651. "package.jar",
  652. "package.war",
  653. "package.aar",
  654. "package.nupkg",
  655. "package.gem",
  656. "module.beam",
  657. "module.hi",
  658. "library.rlib",
  659. "tsconfig.tsbuildinfo",
  660. ];
  661. writeFileSync(join(rootPath, "src.ts"), "export {};");
  662. for (const fileName of skippedFileNames) {
  663. writeFileSync(join(rootPath, fileName), "");
  664. }
  665. const service = createFileService();
  666. const entries = unpackWorkspaceFileEntries(await readAllPacked(service, rootPath), rootPath);
  667. expect(entries.map((entry) => entry.relativePath)).toEqual(["src.ts"]);
  668. });
  669. it("keeps user-maintained directories and distributable assets searchable", async () => {
  670. const rootPath = makeTempDir("zcode-file-service-user-maintained-");
  671. const includedDirectories = [
  672. "vendor",
  673. "env",
  674. "dist",
  675. "build",
  676. "out",
  677. "target",
  678. "bin",
  679. "obj",
  680. "classes",
  681. "_build",
  682. "deps",
  683. "dist-newstyle",
  684. "renv",
  685. ];
  686. for (const directoryName of includedDirectories) {
  687. mkdirSync(join(rootPath, directoryName));
  688. writeFileSync(join(rootPath, directoryName, "kept.txt"), "");
  689. }
  690. for (const fileName of ["bundle.js.map", "app.min.js", "style.min.css"]) {
  691. writeFileSync(join(rootPath, fileName), "");
  692. }
  693. const service = createFileService();
  694. const entries = unpackWorkspaceFileEntries(await readAllPacked(service, rootPath), rootPath);
  695. const relativePaths = entries.map((entry) => entry.relativePath);
  696. for (const directoryName of includedDirectories) {
  697. expect(relativePaths).toContain(directoryName);
  698. expect(relativePaths).toContain(`${directoryName}/kept.txt`);
  699. }
  700. expect(relativePaths).toEqual(
  701. expect.arrayContaining(["bundle.js.map", "app.min.js", "style.min.css"]),
  702. );
  703. });
  704. it("classifies directory symlinks before filtering without traversing them", async () => {
  705. const rootPath = makeTempDir("zcode-file-service-symlink-");
  706. const targetPath = makeTempDir("zcode-file-service-symlink-target-");
  707. const linkPath = join(rootPath, "linked-dir");
  708. writeFileSync(join(targetPath, "outside.ts"), "");
  709. symlinkSync(targetPath, linkPath, process.platform === "win32" ? "junction" : "dir");
  710. const evaluatedTypes: string[] = [];
  711. const service = createFileService({
  712. workspaceFileSearchFilter: {
  713. evaluate: (entry) => {
  714. evaluatedTypes.push(entry.type);
  715. return { include: true, traverse: true };
  716. },
  717. },
  718. });
  719. const entries = unpackWorkspaceFileEntries(await readAllPacked(service, rootPath), rootPath);
  720. expect(evaluatedTypes).toEqual(["directory"]);
  721. expect(entries).toEqual([
  722. {
  723. name: "linked-dir",
  724. path: linkPath,
  725. relativePath: "linked-dir",
  726. type: "directory",
  727. },
  728. ]);
  729. });
  730. it("uses an injected filter as a complete replacement for the default filter", async () => {
  731. const rootPath = makeTempDir("zcode-file-service-custom-filter-");
  732. mkdirSync(join(rootPath, "node_modules"));
  733. writeFileSync(join(rootPath, "node_modules", "package.js"), "");
  734. writeFileSync(join(rootPath, ".env"), "SECRET=123");
  735. // 预置空 .zcodeignore 隔离掉 ignore 规则层:本用例专测"注入 filter 完整替换内置过滤"
  736. // 的旧契约;.zcodeignore 剪枝行为由独立用例覆盖。
  737. writeFileSync(join(rootPath, ".zcodeignore"), "\n");
  738. const service = createFileService({
  739. workspaceFileSearchFilter: {
  740. evaluate: (entry) => ({
  741. include: true,
  742. traverse: entry.type === "directory",
  743. }),
  744. },
  745. });
  746. const entries = unpackWorkspaceFileEntries(await readAllPacked(service, rootPath), rootPath);
  747. expect(entries.map((entry) => entry.relativePath)).toEqual([
  748. "node_modules",
  749. ".env",
  750. "node_modules/package.js",
  751. ]);
  752. });
  753. it("allows an injected filter to exclude every entry", async () => {
  754. const rootPath = makeTempDir("zcode-file-service-exclude-filter-");
  755. mkdirSync(join(rootPath, "src"));
  756. writeFileSync(join(rootPath, "src", "index.ts"), "");
  757. const service = createFileService({
  758. workspaceFileSearchFilter: {
  759. evaluate: () => ({ include: false, traverse: false }),
  760. },
  761. });
  762. expect(unpackWorkspaceFileEntries(await readAllPacked(service, rootPath), rootPath)).toEqual(
  763. [],
  764. );
  765. });
  766. it("returns empty array when hidden directory descendants and env files provide no candidates", async () => {
  767. const rootPath = makeTempDir("zcode-file-service-hidden-");
  768. mkdirSync(join(rootPath, ".vscode"));
  769. writeFileSync(join(rootPath, ".env"), "SECRET=123");
  770. const service = createFileService();
  771. const entries = unpackWorkspaceFileEntries(await readAllPacked(service, rootPath), rootPath);
  772. expect(entries).toEqual([]);
  773. });
  774. it("sorts results by relativePath", async () => {
  775. const rootPath = makeTempDir("zcode-file-service-sort-");
  776. mkdirSync(join(rootPath, "b"));
  777. mkdirSync(join(rootPath, "a"));
  778. writeFileSync(join(rootPath, "b", "z.ts"), "");
  779. writeFileSync(join(rootPath, "a", "x.ts"), "");
  780. writeFileSync(join(rootPath, "root.ts"), "");
  781. const service = createFileService();
  782. const entries = unpackWorkspaceFileEntries(await readAllPacked(service, rootPath), rootPath);
  783. const relativePaths = entries.map((e) => e.relativePath);
  784. expect(relativePaths).toEqual(["a", "b", "a/x.ts", "b/z.ts", "root.ts"]);
  785. });
  786. // .zcodeignore 单一真相源(spec 2026-09-15 增补):目录排除的唯一规则来源。
  787. describe(".zcodeignore", () => {
  788. it("prunes gitignored build directories like obj and bin (ZCT-2096811705629528064)", async () => {
  789. const rootPath = makeTempDir("zcode-file-service-dotnet-");
  790. writeFileSync(join(rootPath, ".gitignore"), "obj/\nbin/\n");
  791. mkdirSync(join(rootPath, "obj", "Debug"), { recursive: true });
  792. mkdirSync(join(rootPath, "bin", "Release"), { recursive: true });
  793. mkdirSync(join(rootPath, "src"));
  794. writeFileSync(join(rootPath, "obj", "Debug", "fake.pdb"), "");
  795. writeFileSync(join(rootPath, "obj", "Debug", "marker.cs"), "");
  796. writeFileSync(join(rootPath, "bin", "Release", "app.dll"), "");
  797. writeFileSync(join(rootPath, "src", "Program.cs"), "");
  798. const service = createFileService();
  799. const entries = unpackWorkspaceFileEntries(
  800. await readAllPacked(service, rootPath),
  801. rootPath,
  802. );
  803. // 自动创建暂时停用,内存中的 gitignore + 默认规则仍剪枝 obj/bin。
  804. expect(entries.map((e) => e.relativePath)).toEqual(["src", ".gitignore", "src/Program.cs"]);
  805. // 规则文件自身是工具配置,不进入候选。
  806. expect(existsSync(join(rootPath, ".zcodeignore"))).toBe(false);
  807. });
  808. it("uses .gitignore plus builtin defaults without creating .zcodeignore", async () => {
  809. const rootPath = makeTempDir("zcode-file-service-create-");
  810. writeFileSync(join(rootPath, ".gitignore"), "dist/\n");
  811. mkdirSync(join(rootPath, "node_modules", "pkg"), { recursive: true });
  812. mkdirSync(join(rootPath, "dist"));
  813. writeFileSync(join(rootPath, "node_modules", "pkg", "index.js"), "");
  814. writeFileSync(join(rootPath, "dist", "bundle.js"), "");
  815. const service = createFileService();
  816. const entries = unpackWorkspaceFileEntries(
  817. await readAllPacked(service, rootPath),
  818. rootPath,
  819. );
  820. // .gitignore 未声明 node_modules:内存默认段仍剪枝(行为兼容)。
  821. expect(entries.map((e) => e.relativePath)).toEqual([".gitignore"]);
  822. expect(existsSync(join(rootPath, ".zcodeignore"))).toBe(false);
  823. });
  824. it("dedupes builtin defaults against gitignore rules on creation", async () => {
  825. const rootPath = makeTempDir("zcode-file-service-create-dedupe-");
  826. // .gitignore 声明了 node_modules/(含尾斜杠差异写法各测一条)。
  827. writeFileSync(join(rootPath, ".gitignore"), "node_modules/\ncoverage\n");
  828. mkdirSync(join(rootPath, "node_modules"));
  829. writeFileSync(join(rootPath, "node_modules", "x.js"), "");
  830. writeFileSync(join(rootPath, "keep.ts"), "");
  831. const service = createFileService();
  832. const preview = await service.readWorkspaceFileSearchIgnore({ rootPath });
  833. await service.writeWorkspaceFileSearchIgnore({ rootPath, content: preview.content });
  834. const entries = unpackWorkspaceFileEntries(
  835. await readAllPacked(service, rootPath),
  836. rootPath,
  837. );
  838. // 去重:gitignore 区已有 node_modules/ 与 coverage,默认段不再重复写这两条
  839. // ——文件中每条规则最多一份,删除 gitignore 区那一行即完全放开。
  840. const created = readFileSync(join(rootPath, ".zcodeignore"), "utf8");
  841. expect(created.match(/^node_modules\/$/gm)).toHaveLength(1);
  842. expect(created.match(/^coverage\/?$/gm)).toHaveLength(1);
  843. // 剪枝仍然生效(gitignore 区那条在起作用);.gitignore 自身保持可搜。
  844. expect(entries.map((e) => e.relativePath)).toEqual([".gitignore", "keep.ts"]);
  845. });
  846. it("uses builtin defaults without creating .zcodeignore when no .gitignore exists", async () => {
  847. const rootPath = makeTempDir("zcode-file-service-create-no-gitignore-");
  848. mkdirSync(join(rootPath, "node_modules"));
  849. writeFileSync(join(rootPath, "node_modules", "x.js"), "");
  850. writeFileSync(join(rootPath, "keep.ts"), "");
  851. const service = createFileService();
  852. const entries = unpackWorkspaceFileEntries(
  853. await readAllPacked(service, rootPath),
  854. rootPath,
  855. );
  856. expect(entries.map((e) => e.relativePath)).toEqual(["keep.ts"]);
  857. expect(existsSync(join(rootPath, ".zcodeignore"))).toBe(false);
  858. });
  859. it("honors gitignore semantics: negation, anchored patterns and directory suffix", async () => {
  860. const rootPath = makeTempDir("zcode-file-service-semantics-");
  861. mkdirSync(join(rootPath, "logs"));
  862. mkdirSync(join(rootPath, "sub", "build"), { recursive: true });
  863. mkdirSync(join(rootPath, "build"));
  864. writeFileSync(
  865. join(rootPath, ".zcodeignore"),
  866. ["logs/*", "!logs/keep.log", "/build", "*.tmp"].join("\n"),
  867. );
  868. writeFileSync(join(rootPath, "logs", "keep.log"), "");
  869. writeFileSync(join(rootPath, "logs", "drop.log"), "");
  870. writeFileSync(join(rootPath, "build", "root-only.txt"), "");
  871. writeFileSync(join(rootPath, "sub", "build", "nested.txt"), "");
  872. writeFileSync(join(rootPath, "scratch.tmp"), "");
  873. writeFileSync(join(rootPath, "main.ts"), "");
  874. const service = createFileService();
  875. const entries = unpackWorkspaceFileEntries(
  876. await readAllPacked(service, rootPath),
  877. rootPath,
  878. );
  879. // ! 反选恢复 logs/keep.log;anchored /build 只剪根 build,sub/build 保留;*.tmp 排除文件。
  880. // logs/* 不排除 logs 目录自身(git 语义:只匹配其下内容)。
  881. expect(entries.map((e) => e.relativePath)).toEqual([
  882. "logs",
  883. "sub",
  884. "sub/build",
  885. "logs/keep.log",
  886. "main.ts",
  887. "sub/build/nested.txt",
  888. ]);
  889. });
  890. it("lets users re-include builtin defaults by editing .zcodeignore (single source of truth)", async () => {
  891. const rootPath = makeTempDir("zcode-file-service-reinclude-");
  892. mkdirSync(join(rootPath, "node_modules", "pkg"), { recursive: true });
  893. writeFileSync(join(rootPath, "node_modules", "pkg", "index.js"), "");
  894. // 用户显式反选内置默认排除:node_modules 必须恢复为可搜(无代码级并集)。
  895. writeFileSync(join(rootPath, ".zcodeignore"), "!node_modules/\n");
  896. const service = createFileService();
  897. const entries = unpackWorkspaceFileEntries(
  898. await readAllPacked(service, rootPath),
  899. rootPath,
  900. );
  901. expect(entries.map((e) => e.relativePath)).toEqual([
  902. "node_modules",
  903. "node_modules/pkg",
  904. "node_modules/pkg/index.js",
  905. ]);
  906. });
  907. it("reads and writes the ignore file via service RPC methods", async () => {
  908. const rootPath = makeTempDir("zcode-file-service-rpc-");
  909. writeFileSync(join(rootPath, ".gitignore"), "out/\n");
  910. const service = createFileService();
  911. const initial = await service.readWorkspaceFileSearchIgnore({ rootPath });
  912. // 尚未落盘:预览初始内容(gitignore 拷贝 + 默认段)。
  913. expect(initial.source).toBe("template");
  914. expect(initial.content).toContain("out/");
  915. expect(existsSync(join(rootPath, ".zcodeignore"))).toBe(false);
  916. await service.writeWorkspaceFileSearchIgnore({ rootPath, content: "custom/\n" });
  917. const afterWrite = await service.readWorkspaceFileSearchIgnore({ rootPath });
  918. expect(afterWrite.source).toBe("file");
  919. expect(afterWrite.content).toBe("custom/\n");
  920. mkdirSync(join(rootPath, "custom"));
  921. writeFileSync(join(rootPath, "custom", "x.txt"), "");
  922. writeFileSync(join(rootPath, "ok.txt"), "");
  923. const entries = unpackWorkspaceFileEntries(
  924. await readAllPacked(service, rootPath),
  925. rootPath,
  926. );
  927. // custom/ 被写入的规则剪枝;.gitignore 本身保持可搜(现有行为)。
  928. expect(entries.map((e) => e.relativePath)).toEqual([".gitignore", "ok.txt"]);
  929. });
  930. it("syncs only the gitignore section while keeping defaults and custom rules", async () => {
  931. const rootPath = makeTempDir("zcode-file-service-section-sync-");
  932. writeFileSync(join(rootPath, ".gitignore"), "out/\n");
  933. const service = createFileService();
  934. const initial = await service.readWorkspaceFileSearchIgnore({ rootPath });
  935. await service.writeWorkspaceFileSearchIgnore({ rootPath, content: initial.content });
  936. // 用户在默认段里删掉 node_modules/(放开),并在自定义区追加自己的规则。
  937. const edited = initial.content
  938. .replace("node_modules/\n", "")
  939. .concat("my-private-assets/\n");
  940. await service.writeWorkspaceFileSearchIgnore({ rootPath, content: edited });
  941. // .gitignore 更新后同步:只重写 gitignore 区。
  942. writeFileSync(join(rootPath, ".gitignore"), "out/\nnewdir/\n");
  943. const synced = await service.applyWorkspaceFileSearchIgnoreTransform({
  944. rootPath,
  945. transform: "sync-gitignore",
  946. });
  947. expect(synced.content).toContain("newdir/");
  948. // 默认段的用户修改(node_modules 放开)与自定义规则都必须保留。
  949. expect(synced.content).not.toContain("node_modules/");
  950. expect(synced.content).toContain("my-private-assets/");
  951. });
  952. it("resets only the defaults section while keeping gitignore and custom rules", async () => {
  953. const rootPath = makeTempDir("zcode-file-service-section-reset-");
  954. writeFileSync(join(rootPath, ".gitignore"), "out/\n");
  955. const service = createFileService();
  956. const initial = await service.readWorkspaceFileSearchIgnore({ rootPath });
  957. const edited = initial.content
  958. .replace("node_modules/\n", "")
  959. .concat("my-private-assets/\n");
  960. await service.writeWorkspaceFileSearchIgnore({ rootPath, content: edited });
  961. const reset = await service.applyWorkspaceFileSearchIgnoreTransform({
  962. rootPath,
  963. transform: "reset-defaults",
  964. });
  965. // 默认段恢复出厂(node_modules/ 回来了)。
  966. expect(reset.content).toContain("node_modules/");
  967. // gitignore 区与自定义区原样保留。
  968. expect(reset.content).toContain("out/");
  969. expect(reset.content).toContain("my-private-assets/");
  970. });
  971. it("falls back to full template rebuild when section markers are missing", async () => {
  972. const rootPath = makeTempDir("zcode-file-service-section-fallback-");
  973. writeFileSync(join(rootPath, ".gitignore"), "out/\n");
  974. // 用户删掉了分区标记(旧格式/手动清理),无法结构化定位分区。
  975. writeFileSync(join(rootPath, ".zcodeignore"), "legacy-rules/\n");
  976. const service = createFileService();
  977. const synced = await service.applyWorkspaceFileSearchIgnoreTransform({
  978. rootPath,
  979. transform: "sync-gitignore",
  980. });
  981. // 退化为整体初始内容重建(含新标记),并在 MR/文档中说明标记行不可删。
  982. expect(synced.content).toContain("out/");
  983. expect(synced.content).toContain("node_modules/");
  984. expect(synced.content).not.toContain("legacy-rules/");
  985. });
  986. });
  987. });
  988. });