@aigne/doc-smith 0.8.5 → 0.8.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (126) hide show
  1. package/.aigne/doc-smith/output/structure-plan.json +1 -5
  2. package/CHANGELOG.md +25 -0
  3. package/README.md +3 -3
  4. package/agents/{chat.yaml → chat/index.yaml} +7 -7
  5. package/agents/generate/check-document-structure.yaml +30 -0
  6. package/agents/{check-structure-plan.mjs → generate/check-need-generate-structure.mjs} +21 -21
  7. package/agents/generate/generate-structure.yaml +58 -0
  8. package/agents/{docs-generator.yaml → generate/index.yaml} +15 -16
  9. package/agents/generate/refine-document-structure.yaml +12 -0
  10. package/agents/{input-generator.mjs → init/index.mjs} +34 -27
  11. package/agents/{manage-prefs.mjs → prefs/index.mjs} +16 -16
  12. package/agents/publish/index.yaml +17 -0
  13. package/agents/{publish-docs.mjs → publish/publish-docs.mjs} +15 -16
  14. package/agents/schema/{structure-plan-result.yaml → document-execution-structure.yaml} +3 -3
  15. package/agents/schema/document-structure.yaml +26 -0
  16. package/agents/{language-selector.mjs → translate/choose-language.mjs} +5 -5
  17. package/agents/{retranslate.yaml → translate/index.yaml} +17 -18
  18. package/agents/translate/translate-document.yaml +32 -0
  19. package/agents/{batch-translate.yaml → translate/translate-multilingual.yaml} +5 -5
  20. package/agents/update/batch-generate-document.yaml +19 -0
  21. package/agents/{check-detail.mjs → update/check-document.mjs} +16 -16
  22. package/agents/{detail-generator-and-translate.yaml → update/generate-and-translate-document.yaml} +23 -23
  23. package/agents/update/generate-document.yaml +50 -0
  24. package/agents/{detail-regenerator.yaml → update/index.yaml} +16 -17
  25. package/agents/{action-success.mjs → utils/action-success.mjs} +2 -2
  26. package/agents/{check-detail-result.mjs → utils/check-detail-result.mjs} +3 -3
  27. package/agents/{check-feedback-refiner.mjs → utils/check-feedback-refiner.mjs} +6 -6
  28. package/agents/{find-items-by-paths.mjs → utils/choose-docs.mjs} +25 -10
  29. package/agents/{docs-fs.yaml → utils/docs-fs-actor.yaml} +3 -1
  30. package/agents/utils/feedback-refiner.yaml +50 -0
  31. package/agents/{find-item-by-path.mjs → utils/find-item-by-path.mjs} +17 -7
  32. package/agents/{find-user-preferences-by-path.mjs → utils/find-user-preferences-by-path.mjs} +1 -1
  33. package/agents/utils/format-document-structure.mjs +25 -0
  34. package/agents/{load-sources.mjs → utils/load-sources.mjs} +41 -28
  35. package/agents/{save-docs.mjs → utils/save-docs.mjs} +16 -16
  36. package/agents/{save-single-doc.mjs → utils/save-single-doc.mjs} +2 -2
  37. package/agents/{transform-detail-datasources.mjs → utils/transform-detail-datasources.mjs} +1 -1
  38. package/aigne.yaml +35 -35
  39. package/docs/cli-reference.md +1 -1
  40. package/docs/features-generate-documentation.md +1 -1
  41. package/docs/features-update-and-refine.md +2 -2
  42. package/docs-mcp/analyze-docs-relevance.yaml +10 -10
  43. package/docs-mcp/docs-search.yaml +5 -3
  44. package/package.json +10 -8
  45. package/prompts/{document → detail/custom}/custom-code-block.md +6 -6
  46. package/prompts/detail/custom/custom-components.md +172 -0
  47. package/prompts/{document → detail}/d2-chart/rules.md +95 -1
  48. package/prompts/{document → detail}/detail-example.md +80 -61
  49. package/prompts/{document/detail-generator.md → detail/document-rules.md} +4 -8
  50. package/prompts/{content-detail-generator.md → detail/generate-document.md} +48 -25
  51. package/prompts/{check-structure-planning-result.md → structure/check-document-structure.md} +23 -17
  52. package/prompts/{document/structure-planning.md → structure/document-rules.md} +0 -2
  53. package/prompts/{structure-planning.md → structure/generate-structure.md} +51 -30
  54. package/prompts/{document → structure}/structure-example.md +2 -2
  55. package/prompts/{document → structure}/structure-getting-started.md +2 -2
  56. package/prompts/translate/glossary.md +6 -0
  57. package/prompts/{translator.md → translate/translate-document.md} +29 -10
  58. package/prompts/{feedback-refiner.md → utils/feedback-refiner.md} +8 -8
  59. package/tests/agents/chat/chat.test.mjs +46 -0
  60. package/tests/agents/generate/check-document-structure.test.mjs +51 -0
  61. package/tests/agents/generate/check-need-generate-structure.test.mjs +292 -0
  62. package/tests/agents/generate/generate-structure.test.mjs +51 -0
  63. package/tests/{input-generator.test.mjs → agents/init/init.test.mjs} +19 -17
  64. package/tests/agents/prefs/prefs.test.mjs +431 -0
  65. package/tests/agents/publish/publish-docs.test.mjs +642 -0
  66. package/tests/agents/translate/choose-language.test.mjs +311 -0
  67. package/tests/agents/translate/translate-document.test.mjs +51 -0
  68. package/tests/agents/update/check-document.test.mjs +523 -0
  69. package/tests/agents/update/generate-document.test.mjs +51 -0
  70. package/tests/agents/utils/action-success.test.mjs +54 -0
  71. package/tests/{check-detail-result.test.mjs → agents/utils/check-detail-result.test.mjs} +98 -98
  72. package/tests/agents/utils/check-feedback-refiner.test.mjs +478 -0
  73. package/tests/agents/utils/choose-docs.test.mjs +417 -0
  74. package/tests/agents/utils/exit.test.mjs +70 -0
  75. package/tests/agents/utils/feedback-refiner.test.mjs +51 -0
  76. package/tests/agents/utils/find-item-by-path.test.mjs +526 -0
  77. package/tests/agents/utils/find-user-preferences-by-path.test.mjs +382 -0
  78. package/tests/agents/utils/format-document-structure.test.mjs +264 -0
  79. package/tests/agents/utils/fs.test.mjs +267 -0
  80. package/tests/{load-sources.test.mjs → agents/utils/load-sources.test.mjs} +153 -25
  81. package/tests/{save-docs.test.mjs → agents/utils/save-docs.test.mjs} +11 -5
  82. package/tests/agents/utils/save-output.test.mjs +315 -0
  83. package/tests/agents/utils/save-single-doc.test.mjs +364 -0
  84. package/tests/agents/utils/transform-detail-datasources.test.mjs +363 -0
  85. package/tests/utils/auth-utils.test.mjs +358 -0
  86. package/tests/utils/blocklet.test.mjs +334 -0
  87. package/tests/{conflict-resolution.test.mjs → utils/conflict-detector.test.mjs} +3 -3
  88. package/tests/utils/constants.test.mjs +295 -0
  89. package/tests/utils/d2-utils.test.mjs +423 -0
  90. package/tests/utils/deploy.test.mjs +365 -0
  91. package/tests/utils/docs-finder-utils.test.mjs +625 -0
  92. package/tests/utils/file-utils.test.mjs +213 -0
  93. package/tests/{kroki-utils.test.mjs → utils/kroki-utils.test.mjs} +2 -2
  94. package/tests/utils/load-config.test.mjs +141 -0
  95. package/tests/{mermaid-validation.test.mjs → utils/mermaid-validator.test.mjs} +2 -2
  96. package/tests/utils/mock-chat-model.mjs +12 -0
  97. package/tests/{preferences-utils.test.mjs → utils/preferences-utils.test.mjs} +1 -1
  98. package/tests/{save-value-to-config.test.mjs → utils/save-value-to-config.test.mjs} +61 -4
  99. package/tests/utils/utils.test.mjs +939 -0
  100. package/utils/auth-utils.mjs +1 -1
  101. package/utils/conflict-detector.mjs +1 -1
  102. package/utils/constants.mjs +5 -3
  103. package/utils/d2-utils.mjs +194 -0
  104. package/utils/deploy.mjs +3 -3
  105. package/utils/docs-finder-utils.mjs +26 -26
  106. package/utils/icon-map.mjs +26 -0
  107. package/{agents → utils}/load-config.mjs +2 -18
  108. package/utils/markdown-checker.mjs +5 -5
  109. package/agents/batch-docs-detail-generator.yaml +0 -19
  110. package/agents/check-structure-planning-result.yaml +0 -30
  111. package/agents/content-detail-generator.yaml +0 -50
  112. package/agents/feedback-refiner.yaml +0 -52
  113. package/agents/format-structure-plan.mjs +0 -25
  114. package/agents/reflective-structure-planner.yaml +0 -12
  115. package/agents/schema/structure-plan.yaml +0 -26
  116. package/agents/structure-planning.yaml +0 -58
  117. package/agents/team-publish-docs.yaml +0 -18
  118. package/agents/translate.yaml +0 -31
  119. package/prompts/document/custom-components.md +0 -104
  120. package/tests/README.md +0 -93
  121. package/tests/utils.test.mjs +0 -2067
  122. /package/agents/{exit.mjs → utils/exit.mjs} +0 -0
  123. /package/agents/{fs.mjs → utils/fs.mjs} +0 -0
  124. /package/agents/{save-output.mjs → utils/save-output.mjs} +0 -0
  125. /package/prompts/{document → detail}/d2-chart/official-examples.md +0 -0
  126. /package/prompts/{document → detail}/jsx/rules.md +0 -0
@@ -0,0 +1,423 @@
1
+ import { afterEach, beforeEach, describe, expect, test } from "bun:test";
2
+ import { existsSync, mkdtemp, rmdir } from "node:fs";
3
+ import { mkdir, readdir, readFile, writeFile } from "node:fs/promises";
4
+ import { tmpdir } from "node:os";
5
+ import path from "node:path";
6
+
7
+ import Debug from "debug";
8
+
9
+ import { TMP_ASSETS_DIR } from "../../utils/constants.mjs";
10
+ import {
11
+ beforePublishHook,
12
+ checkContent,
13
+ ensureTmpDir,
14
+ getChart,
15
+ isValidCode,
16
+ saveAssets,
17
+ } from "../../utils/d2-utils.mjs";
18
+
19
+ describe("d2-utils", () => {
20
+ let tempDir;
21
+
22
+ beforeEach(async () => {
23
+ tempDir = await new Promise((resolve, reject) => {
24
+ mkdtemp(path.join(tmpdir(), "d2-test-"), (err, dir) => {
25
+ if (err) reject(err);
26
+ else resolve(dir);
27
+ });
28
+ });
29
+ });
30
+
31
+ afterEach(async () => {
32
+ if (tempDir && existsSync(tempDir)) {
33
+ await new Promise((resolve) => {
34
+ rmdir(tempDir, { recursive: true }, () => resolve());
35
+ });
36
+ }
37
+ });
38
+
39
+ describe("getChart", () => {
40
+ test("should generate chart for valid d2 content", async () => {
41
+ const content = "A -> B";
42
+ const result = await getChart({ content });
43
+ expect(typeof result).toBe("string");
44
+ expect(result).toContain("<svg");
45
+ }, 15000);
46
+
47
+ test("should return null for invalid d2 content with strict=false", async () => {
48
+ const content = "A -> B -> C -> [invalid syntax";
49
+ const result = await getChart({ content, strict: false });
50
+ expect(result).toBe(null);
51
+ }, 15000);
52
+
53
+ test("should throw for invalid d2 content with strict=true", async () => {
54
+ const content = "A -> B -> C -> [invalid syntax";
55
+ await expect(getChart({ content, strict: true })).rejects.toThrow();
56
+ }, 15000);
57
+
58
+ test("should handle empty content", async () => {
59
+ const result = await getChart({ content: "" });
60
+ expect(typeof result).toBe("string");
61
+ expect(result).toContain("<svg");
62
+ }, 10000);
63
+
64
+ test("should add stroke-dash to container shapes", async () => {
65
+ const content = `
66
+ container {
67
+ A -> B
68
+ }
69
+ `;
70
+ const result = await getChart({ content });
71
+ expect(typeof result).toBe("string");
72
+ // d2 will convert `strokeDash: 3` to `stroke-dasharray:6.000000,5.919384;`
73
+ expect(result).toContain("stroke-dasharray:6.000000");
74
+ }, 15000);
75
+
76
+ test("should not add stroke-dash to sequence diagrams", async () => {
77
+ const content = `
78
+ shape: sequence_diagram
79
+ A -> B: Hello
80
+ `;
81
+ const result = await getChart({ content });
82
+ expect(typeof result).toBe("string");
83
+ // d2 will convert `strokeDash: 3` to `stroke-dasharray:6.000000,5.919384;`
84
+ expect(result).not.toContain("stroke-dasharray:6.000000");
85
+ }, 15000);
86
+ });
87
+
88
+ describe("saveAssets", () => {
89
+ test("should process markdown with D2 code blocks", async () => {
90
+ const docsDir = path.join(tempDir, "docs");
91
+ await mkdir(docsDir, { recursive: true });
92
+
93
+ const markdown = `# Test Document
94
+
95
+ This is a test document with D2 diagram:
96
+
97
+ \`\`\`d2
98
+ A -> B: connection
99
+ B -> C: another connection
100
+ \`\`\`
101
+
102
+ Some more content here.
103
+ `;
104
+
105
+ const result = await saveAssets({ markdown, docsDir });
106
+
107
+ expect(typeof result).toBe("string");
108
+ expect(result).toContain("# Test Document");
109
+ expect(result).toContain("Some more content here");
110
+
111
+ // Should replace D2 code block with image reference
112
+ expect(result).not.toContain("```d2");
113
+ expect(result).toContain("![](../assets/d2/");
114
+ expect(result).toContain(".svg)");
115
+ });
116
+
117
+ test("should handle markdown without D2 blocks", async () => {
118
+ const docsDir = path.join(tempDir, "docs");
119
+ await mkdir(docsDir, { recursive: true });
120
+
121
+ const markdown = `# Test Document
122
+
123
+ This document has no D2 diagrams.
124
+
125
+ \`\`\`javascript
126
+ console.log('hello world');
127
+ \`\`\`
128
+ `;
129
+
130
+ const result = await saveAssets({ markdown, docsDir });
131
+
132
+ expect(result).toBe(markdown); // Should remain unchanged
133
+ });
134
+
135
+ test("should handle multiple D2 blocks", async () => {
136
+ const docsDir = path.join(tempDir, "docs");
137
+ await mkdir(docsDir, { recursive: true });
138
+
139
+ const markdown = `# Test
140
+
141
+ \`\`\`d2
142
+ A -> B
143
+ \`\`\`
144
+
145
+ Some text.
146
+
147
+ \`\`\`d2
148
+ C -> D
149
+ E -> F
150
+ \`\`\`
151
+ `;
152
+
153
+ const result = await saveAssets({ markdown, docsDir });
154
+
155
+ expect(typeof result).toBe("string");
156
+ expect(result).not.toContain("```d2");
157
+
158
+ // Should have two image references
159
+ const imageMatches = result.match(/!\[\]\(\.\.\/assets\/d2\/.*\.svg\)/g);
160
+ expect(imageMatches).toBeTruthy();
161
+ expect(imageMatches.length).toBe(2);
162
+ });
163
+
164
+ test("should handle empty markdown", async () => {
165
+ const docsDir = path.join(tempDir, "docs");
166
+ await mkdir(docsDir, { recursive: true });
167
+
168
+ const result = await saveAssets({ markdown: "", docsDir });
169
+ expect(result).toBe("");
170
+ });
171
+
172
+ test("should skip generation if SVG file already exists", async () => {
173
+ const docsDir = path.join(tempDir, "docs");
174
+ await mkdir(docsDir, { recursive: true });
175
+ const markdown = `\`\`\`d2\nA -> B\n\`\`\``;
176
+
177
+ // 1. First run to generate the file
178
+ await saveAssets({ markdown, docsDir });
179
+
180
+ // 2. Second run to check if cache is used
181
+ const debugLogs = [];
182
+ const originalWrite = process.stderr.write;
183
+ process.stderr.write = (chunk) => {
184
+ debugLogs.push(chunk.toString());
185
+ return true;
186
+ };
187
+ Debug.enable("doc-smith");
188
+
189
+ try {
190
+ const result = await saveAssets({ markdown, docsDir });
191
+
192
+ expect(typeof result).toBe("string");
193
+ expect(result).toContain(`![](${path.posix.join("..", TMP_ASSETS_DIR, "d2")}`);
194
+ expect(
195
+ debugLogs.some((log) => log.includes("Found assets cache, skipping generation")),
196
+ ).toBe(true);
197
+ } finally {
198
+ process.stderr.write = originalWrite;
199
+ Debug.disable();
200
+ }
201
+ });
202
+
203
+ test("should handle D2 generation errors gracefully", async () => {
204
+ const docsDir = path.join(tempDir, "docs");
205
+ await mkdir(docsDir, { recursive: true });
206
+
207
+ const markdown = `\`\`\`d2\nA -> B -> [invalid\n\`\`\``;
208
+
209
+ const result = await saveAssets({ markdown, docsDir });
210
+ expect(result).toContain("![](../assets/d2/");
211
+ });
212
+
213
+ test("should write .d2 file when debug is enabled", async () => {
214
+ const docsDir = path.join(tempDir, "docs");
215
+ await mkdir(docsDir, { recursive: true });
216
+
217
+ const markdown = `\`\`\`d2\nA -> B\n\`\`\``;
218
+
219
+ // Enable debug mode
220
+ Debug.enable("doc-smith");
221
+
222
+ try {
223
+ await saveAssets({ markdown, docsDir });
224
+
225
+ const assetDir = path.join(docsDir, "../", TMP_ASSETS_DIR, "d2");
226
+ const files = await readdir(assetDir);
227
+ const d2File = files.find((file) => file.endsWith(".d2"));
228
+ expect(d2File).toBeDefined();
229
+ } finally {
230
+ // Restore debug mode
231
+ Debug.disable();
232
+ }
233
+ });
234
+ });
235
+
236
+ describe("beforePublishHook", () => {
237
+ test("should process all markdown files in directory", async () => {
238
+ const docsDir = path.join(tempDir, "docs");
239
+ await mkdir(docsDir, { recursive: true });
240
+
241
+ // Create test markdown files
242
+ const file1Content = `# Doc 1\n\`\`\`d2\nA -> B\n\`\`\``;
243
+ const file2Content = `# Doc 2\n\`\`\`d2\nC -> D\n\`\`\``;
244
+ const file3Content = `# Doc 3\nNo diagrams here.`;
245
+
246
+ await writeFile(path.join(docsDir, "doc1.md"), file1Content);
247
+ await writeFile(path.join(docsDir, "doc2.md"), file2Content);
248
+ await writeFile(path.join(docsDir, "doc3.md"), file3Content);
249
+
250
+ await beforePublishHook({ docsDir });
251
+
252
+ // Check that files were processed
253
+ const processedFile1 = await readFile(path.join(docsDir, "doc1.md"), "utf8");
254
+ const processedFile2 = await readFile(path.join(docsDir, "doc2.md"), "utf8");
255
+ const processedFile3 = await readFile(path.join(docsDir, "doc3.md"), "utf8");
256
+
257
+ expect(processedFile1).not.toContain("```d2");
258
+ expect(processedFile2).not.toContain("```d2");
259
+ expect(processedFile3).toBe(file3Content); // Unchanged
260
+
261
+ expect(processedFile1).toContain("![](../assets/d2/");
262
+ expect(processedFile2).toContain("![](../assets/d2/");
263
+ });
264
+
265
+ test("should handle nested directories", async () => {
266
+ const docsDir = path.join(tempDir, "docs");
267
+ const subDir = path.join(docsDir, "subdir");
268
+ await mkdir(subDir, { recursive: true });
269
+
270
+ const fileContent = `# Nested Doc\n\`\`\`d2\nA -> B\n\`\`\``;
271
+ await writeFile(path.join(subDir, "nested.md"), fileContent);
272
+
273
+ await beforePublishHook({ docsDir });
274
+
275
+ const processedFile = await readFile(path.join(subDir, "nested.md"), "utf8");
276
+ expect(processedFile).not.toContain("```d2");
277
+ expect(processedFile).toContain("![](../assets/d2/");
278
+ });
279
+
280
+ test("should handle empty docs directory", async () => {
281
+ const docsDir = path.join(tempDir, "empty-docs");
282
+ await mkdir(docsDir, { recursive: true });
283
+
284
+ // Should not throw error
285
+ await expect(beforePublishHook({ docsDir })).resolves.toBeUndefined();
286
+ });
287
+
288
+ test("should handle non-existent directory", async () => {
289
+ const nonExistentDir = path.join(tempDir, "non-existent");
290
+ // glob will just return an empty array, so no error should be thrown.
291
+ await expect(beforePublishHook({ docsDir: nonExistentDir })).resolves.toBeUndefined();
292
+ });
293
+ });
294
+
295
+ describe("checkContent", () => {
296
+ test("should generate and cache D2 SVG", async () => {
297
+ const content = "A -> B: test connection";
298
+ await expect(checkContent({ content })).resolves.toBeUndefined();
299
+ });
300
+
301
+ test("should use cached file when available", async () => {
302
+ const content = "A -> B: cached test";
303
+
304
+ // First call should generate
305
+ await checkContent({ content });
306
+
307
+ // Second call should use cache
308
+ const debugLogs = [];
309
+ const originalWrite = process.stderr.write;
310
+ process.stderr.write = (chunk) => {
311
+ debugLogs.push(chunk.toString());
312
+ return true;
313
+ };
314
+ Debug.enable("doc-smith");
315
+
316
+ try {
317
+ const startTime = Date.now();
318
+ await checkContent({ content });
319
+ const endTime = Date.now();
320
+
321
+ // Cache hit should be very fast (< 100ms)
322
+ expect(endTime - startTime).toBeLessThan(100);
323
+ expect(
324
+ debugLogs.some((log) => log.includes("Found assets cache, skipping generation")),
325
+ ).toBe(true);
326
+ } finally {
327
+ process.stderr.write = originalWrite;
328
+ Debug.disable();
329
+ }
330
+ });
331
+
332
+ test("should handle generation errors in strict mode", async () => {
333
+ const malformedContent = "A -> B -> [invalid";
334
+ await expect(checkContent({ content: malformedContent })).rejects.toThrow();
335
+ });
336
+
337
+ test("should handle empty content", async () => {
338
+ await expect(checkContent({ content: "" })).resolves.toBeUndefined();
339
+ });
340
+
341
+ test("should write .d2 file when debug is enabled", async () => {
342
+ const content = "A -> B: debug test";
343
+
344
+ Debug.enable("doc-smith");
345
+
346
+ try {
347
+ await checkContent({ content });
348
+
349
+ const assetDir = path.join(process.cwd(), ".aigne", "doc-smith", ".tmp", "assets", "d2");
350
+ const files = await readdir(assetDir);
351
+ const d2File = files.find((file) => file.endsWith(".d2"));
352
+ expect(d2File).toBeDefined();
353
+ } finally {
354
+ Debug.disable();
355
+ }
356
+ });
357
+ });
358
+
359
+ describe("ensureTmpDir", () => {
360
+ test("should create tmp directory structure", async () => {
361
+ // Change to temp directory for testing
362
+ const originalCwd = process.cwd();
363
+ process.chdir(tempDir);
364
+
365
+ try {
366
+ await ensureTmpDir();
367
+
368
+ const tmpDir = path.join(tempDir, ".aigne", "doc-smith", ".tmp");
369
+ const gitignorePath = path.join(tmpDir, ".gitignore");
370
+
371
+ expect(existsSync(tmpDir)).toBe(true);
372
+ expect(existsSync(gitignorePath)).toBe(true);
373
+
374
+ const gitignoreContent = await readFile(gitignorePath, "utf8");
375
+ expect(gitignoreContent).toBe("**/*");
376
+ } finally {
377
+ process.chdir(originalCwd);
378
+ }
379
+ });
380
+
381
+ test("should not recreate if already exists", async () => {
382
+ const originalCwd = process.cwd();
383
+ process.chdir(tempDir);
384
+
385
+ try {
386
+ // First call
387
+ await ensureTmpDir();
388
+
389
+ const tmpDir = path.join(tempDir, ".aigne", "doc-smith", ".tmp");
390
+ const gitignorePath = path.join(tmpDir, ".gitignore");
391
+
392
+ // Modify .gitignore to test if it gets overwritten
393
+ await writeFile(gitignorePath, "modified content");
394
+
395
+ // Second call
396
+ await ensureTmpDir();
397
+
398
+ const gitignoreContent = await readFile(gitignorePath, "utf8");
399
+ expect(gitignoreContent).toBe("modified content"); // Should not be overwritten
400
+ } finally {
401
+ process.chdir(originalCwd);
402
+ }
403
+ });
404
+ });
405
+
406
+ describe("isValidCode", () => {
407
+ test("should return true for 'd2'", () => {
408
+ expect(isValidCode("d2")).toBe(true);
409
+ });
410
+
411
+ test("should return true for 'D2'", () => {
412
+ expect(isValidCode("D2")).toBe(true);
413
+ });
414
+
415
+ test("should return false for other languages", () => {
416
+ expect(isValidCode("javascript")).toBe(false);
417
+ expect(isValidCode("python")).toBe(false);
418
+ expect(isValidCode("")).toBe(false);
419
+ expect(isValidCode(null)).toBe(false);
420
+ expect(isValidCode(undefined)).toBe(false);
421
+ });
422
+ });
423
+ });