@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,417 @@
1
+ import { afterEach, beforeEach, describe, expect, mock, spyOn, test } from "bun:test";
2
+ import chooseDocs from "../../../agents/utils/choose-docs.mjs";
3
+ import * as docsFinderUtils from "../../../utils/docs-finder-utils.mjs";
4
+
5
+ describe("chooseDocs utility", () => {
6
+ let getMainLanguageFilesSpy;
7
+ let processSelectedFilesSpy;
8
+ let findItemByPathSpy;
9
+ let getActionTextSpy;
10
+ let addFeedbackToItemsSpy;
11
+ let consoleErrorSpy;
12
+ let consoleWarnSpy;
13
+ let mockOptions;
14
+
15
+ beforeEach(() => {
16
+ // Spy on utility functions
17
+ getMainLanguageFilesSpy = spyOn(docsFinderUtils, "getMainLanguageFiles").mockResolvedValue([
18
+ "/docs/guide.md",
19
+ "/docs/api.md",
20
+ "/docs/tutorial.md",
21
+ ]);
22
+ processSelectedFilesSpy = spyOn(docsFinderUtils, "processSelectedFiles").mockResolvedValue([
23
+ { path: "/docs/guide.md", content: "# Guide", title: "Guide" },
24
+ { path: "/docs/api.md", content: "# API", title: "API" },
25
+ ]);
26
+ findItemByPathSpy = spyOn(docsFinderUtils, "findItemByPath").mockResolvedValue({
27
+ path: "/docs/guide.md",
28
+ content: "# Guide",
29
+ title: "Guide",
30
+ });
31
+ getActionTextSpy = spyOn(docsFinderUtils, "getActionText").mockImplementation(
32
+ (isTranslate, template) => template.replace("{action}", isTranslate ? "translate" : "update"),
33
+ );
34
+ addFeedbackToItemsSpy = spyOn(docsFinderUtils, "addFeedbackToItems").mockImplementation(
35
+ (items, feedback) => items.map((item) => ({ ...item, feedback })),
36
+ );
37
+
38
+ // Spy on console methods
39
+ consoleErrorSpy = spyOn(console, "error").mockImplementation(() => {});
40
+ consoleWarnSpy = spyOn(console, "warn").mockImplementation(() => {});
41
+
42
+ // Mock options with prompts
43
+ mockOptions = {
44
+ prompts: {
45
+ checkbox: mock().mockResolvedValue(["/docs/guide.md", "/docs/api.md"]),
46
+ input: mock().mockResolvedValue("Test feedback"),
47
+ },
48
+ };
49
+ });
50
+
51
+ afterEach(() => {
52
+ // Restore all spies
53
+ getMainLanguageFilesSpy?.mockRestore();
54
+ processSelectedFilesSpy?.mockRestore();
55
+ findItemByPathSpy?.mockRestore();
56
+ getActionTextSpy?.mockRestore();
57
+ addFeedbackToItemsSpy?.mockRestore();
58
+ consoleErrorSpy?.mockRestore();
59
+ consoleWarnSpy?.mockRestore();
60
+ });
61
+
62
+ // DOCS PROVIDED TESTS
63
+ test("should process provided docs array successfully", async () => {
64
+ const input = {
65
+ docs: ["/docs/guide.md", "/docs/api.md"],
66
+ documentExecutionStructure: [{ path: "/docs/guide.md" }],
67
+ boardId: "board-123",
68
+ docsDir: "/project/docs",
69
+ isTranslate: false,
70
+ feedback: "Update these docs",
71
+ locale: "en",
72
+ };
73
+
74
+ const result = await chooseDocs(input, mockOptions);
75
+
76
+ expect(findItemByPathSpy).toHaveBeenCalledTimes(2);
77
+ expect(findItemByPathSpy).toHaveBeenCalledWith(
78
+ input.documentExecutionStructure,
79
+ "/docs/guide.md",
80
+ "board-123",
81
+ "/project/docs",
82
+ "en",
83
+ );
84
+ expect(addFeedbackToItemsSpy).toHaveBeenCalledWith(expect.any(Array), "Update these docs");
85
+ expect(result).toEqual({
86
+ selectedDocs: expect.any(Array),
87
+ feedback: "Update these docs",
88
+ selectedPaths: expect.any(Array),
89
+ });
90
+ });
91
+
92
+ test("should handle docs with some items not found", async () => {
93
+ findItemByPathSpy.mockImplementation((_, path) => {
94
+ if (path === "/docs/missing.md") {
95
+ return null;
96
+ }
97
+ return { path, content: `Content for ${path}`, title: path };
98
+ });
99
+
100
+ const input = {
101
+ docs: ["/docs/guide.md", "/docs/missing.md", "/docs/api.md"],
102
+ documentExecutionStructure: [],
103
+ boardId: "board-123",
104
+ docsDir: "/project/docs",
105
+ isTranslate: false,
106
+ locale: "en",
107
+ };
108
+
109
+ const result = await chooseDocs(input, mockOptions);
110
+
111
+ expect(consoleWarnSpy).toHaveBeenCalledWith(
112
+ '⚠️ Item with path "/docs/missing.md" not found in documentExecutionStructure',
113
+ );
114
+ expect(result.selectedDocs).toHaveLength(2); // Only found items
115
+ });
116
+
117
+ test("should throw error when none of provided docs are found", async () => {
118
+ findItemByPathSpy.mockResolvedValue(null);
119
+
120
+ const input = {
121
+ docs: ["/docs/missing1.md", "/docs/missing2.md"],
122
+ documentExecutionStructure: [],
123
+ boardId: "board-123",
124
+ docsDir: "/project/docs",
125
+ isTranslate: false,
126
+ locale: "en",
127
+ };
128
+
129
+ await expect(chooseDocs(input, mockOptions)).rejects.toThrow(
130
+ "None of the specified document paths were found in documentExecutionStructure",
131
+ );
132
+ });
133
+
134
+ // INTERACTIVE SELECTION TESTS
135
+ test("should handle interactive document selection when docs not provided", async () => {
136
+ const input = {
137
+ docs: [],
138
+ documentExecutionStructure: [{ path: "/docs/guide.md" }],
139
+ docsDir: "/project/docs",
140
+ isTranslate: false,
141
+ locale: "en",
142
+ };
143
+
144
+ const result = await chooseDocs(input, mockOptions);
145
+
146
+ expect(getMainLanguageFilesSpy).toHaveBeenCalledWith(
147
+ "/project/docs",
148
+ "en",
149
+ input.documentExecutionStructure,
150
+ );
151
+ expect(mockOptions.prompts.checkbox).toHaveBeenCalled();
152
+ expect(processSelectedFilesSpy).toHaveBeenCalledWith(
153
+ ["/docs/guide.md", "/docs/api.md"],
154
+ input.documentExecutionStructure,
155
+ "/project/docs",
156
+ );
157
+ expect(result.selectedDocs).toBeDefined();
158
+ });
159
+
160
+ test("should handle interactive selection when docs is null", async () => {
161
+ const input = {
162
+ docs: null,
163
+ documentExecutionStructure: [],
164
+ docsDir: "/project/docs",
165
+ isTranslate: true,
166
+ locale: "zh",
167
+ };
168
+
169
+ await chooseDocs(input, mockOptions);
170
+
171
+ expect(getMainLanguageFilesSpy).toHaveBeenCalled();
172
+ expect(getActionTextSpy).toHaveBeenCalledWith(true, "Select documents to {action}:");
173
+ });
174
+
175
+ test("should throw error when no main language files found", async () => {
176
+ getMainLanguageFilesSpy.mockResolvedValue([]);
177
+
178
+ const input = {
179
+ docs: [],
180
+ documentExecutionStructure: [],
181
+ docsDir: "/empty/docs",
182
+ isTranslate: false,
183
+ locale: "en",
184
+ };
185
+
186
+ await expect(chooseDocs(input, mockOptions)).rejects.toThrow(
187
+ "Please provide a docs parameter to specify which documents to update",
188
+ );
189
+ expect(consoleErrorSpy).toHaveBeenCalledWith(
190
+ new Error("No documents found in the docs directory"),
191
+ );
192
+ });
193
+
194
+ test("should throw error when no documents selected interactively", async () => {
195
+ mockOptions.prompts.checkbox.mockResolvedValue([]);
196
+
197
+ const input = {
198
+ docs: [],
199
+ documentExecutionStructure: [],
200
+ docsDir: "/project/docs",
201
+ isTranslate: false,
202
+ locale: "en",
203
+ };
204
+
205
+ await expect(chooseDocs(input, mockOptions)).rejects.toThrow(
206
+ "Please provide a docs parameter to specify which documents to update",
207
+ );
208
+ });
209
+
210
+ // CHECKBOX VALIDATION TESTS
211
+ test("should validate checkbox selection requires at least one document", async () => {
212
+ const input = {
213
+ docs: [],
214
+ documentExecutionStructure: [],
215
+ docsDir: "/project/docs",
216
+ isTranslate: false,
217
+ locale: "en",
218
+ };
219
+
220
+ await chooseDocs(input, mockOptions);
221
+
222
+ const checkboxCall = mockOptions.prompts.checkbox.mock.calls[0][0];
223
+ expect(checkboxCall.validate([])).toBe("Please select at least one document");
224
+ expect(checkboxCall.validate(["/docs/guide.md"])).toBe(true);
225
+ });
226
+
227
+ test("should filter choices based on search term", async () => {
228
+ const input = {
229
+ docs: [],
230
+ documentExecutionStructure: [],
231
+ docsDir: "/project/docs",
232
+ isTranslate: false,
233
+ locale: "en",
234
+ };
235
+
236
+ await chooseDocs(input, mockOptions);
237
+
238
+ const checkboxCall = mockOptions.prompts.checkbox.mock.calls[0][0];
239
+ const choices = checkboxCall.source();
240
+ expect(choices).toHaveLength(3);
241
+
242
+ const filteredChoices = checkboxCall.source("api");
243
+ expect(filteredChoices).toHaveLength(1);
244
+ expect(filteredChoices[0].value).toBe("/docs/api.md");
245
+ });
246
+
247
+ // FEEDBACK HANDLING TESTS
248
+ test("should prompt for feedback when not provided", async () => {
249
+ const input = {
250
+ docs: ["/docs/guide.md"],
251
+ documentExecutionStructure: [],
252
+ boardId: "board-123",
253
+ docsDir: "/project/docs",
254
+ isTranslate: true,
255
+ locale: "en",
256
+ };
257
+
258
+ const result = await chooseDocs(input, mockOptions);
259
+
260
+ expect(getActionTextSpy).toHaveBeenCalledWith(
261
+ true,
262
+ "How should we improve this {action}? (press Enter to skip):",
263
+ );
264
+ expect(mockOptions.prompts.input).toHaveBeenCalled();
265
+ expect(result.feedback).toBe("Test feedback");
266
+ });
267
+
268
+ test("should use provided feedback without prompting", async () => {
269
+ const input = {
270
+ docs: ["/docs/guide.md"],
271
+ documentExecutionStructure: [],
272
+ boardId: "board-123",
273
+ docsDir: "/project/docs",
274
+ isTranslate: false,
275
+ feedback: "Provided feedback",
276
+ locale: "en",
277
+ };
278
+
279
+ const result = await chooseDocs(input, mockOptions);
280
+
281
+ expect(mockOptions.prompts.input).not.toHaveBeenCalled();
282
+ expect(result.feedback).toBe("Provided feedback");
283
+ });
284
+
285
+ test("should handle empty feedback gracefully", async () => {
286
+ mockOptions.prompts.input.mockResolvedValue("");
287
+
288
+ const input = {
289
+ docs: ["/docs/guide.md"],
290
+ documentExecutionStructure: [],
291
+ boardId: "board-123",
292
+ docsDir: "/project/docs",
293
+ isTranslate: false,
294
+ locale: "en",
295
+ };
296
+
297
+ const result = await chooseDocs(input, mockOptions);
298
+
299
+ expect(result.feedback).toBe("");
300
+ expect(addFeedbackToItemsSpy).toHaveBeenCalledWith(expect.any(Array), "");
301
+ });
302
+
303
+ // RESET FUNCTIONALITY TESTS
304
+ test("should reset content to null when reset is true", async () => {
305
+ const input = {
306
+ docs: ["/docs/guide.md"],
307
+ documentExecutionStructure: [],
308
+ boardId: "board-123",
309
+ docsDir: "/project/docs",
310
+ isTranslate: false,
311
+ feedback: "Reset test",
312
+ locale: "en",
313
+ reset: true,
314
+ };
315
+
316
+ const result = await chooseDocs(input, mockOptions);
317
+
318
+ expect(result.selectedDocs).toEqual(
319
+ expect.arrayContaining([
320
+ expect.objectContaining({
321
+ content: null,
322
+ }),
323
+ ]),
324
+ );
325
+ });
326
+
327
+ test("should preserve content when reset is false", async () => {
328
+ const input = {
329
+ docs: ["/docs/guide.md"],
330
+ documentExecutionStructure: [],
331
+ boardId: "board-123",
332
+ docsDir: "/project/docs",
333
+ isTranslate: false,
334
+ feedback: "No reset test",
335
+ locale: "en",
336
+ reset: false,
337
+ };
338
+
339
+ const result = await chooseDocs(input, mockOptions);
340
+
341
+ expect(result.selectedDocs).toEqual(
342
+ expect.arrayContaining([
343
+ expect.objectContaining({
344
+ content: expect.any(String),
345
+ }),
346
+ ]),
347
+ );
348
+ });
349
+
350
+ // RETURN VALUE STRUCTURE TESTS
351
+ test("should return correct structure with all required fields", async () => {
352
+ const input = {
353
+ docs: ["/docs/guide.md", "/docs/api.md"],
354
+ documentExecutionStructure: [],
355
+ boardId: "board-123",
356
+ docsDir: "/project/docs",
357
+ isTranslate: false,
358
+ feedback: "Structure test",
359
+ locale: "en",
360
+ };
361
+
362
+ const result = await chooseDocs(input, mockOptions);
363
+
364
+ expect(result).toHaveProperty("selectedDocs");
365
+ expect(result).toHaveProperty("feedback");
366
+ expect(result).toHaveProperty("selectedPaths");
367
+ expect(Array.isArray(result.selectedDocs)).toBe(true);
368
+ expect(Array.isArray(result.selectedPaths)).toBe(true);
369
+ expect(typeof result.feedback).toBe("string");
370
+ });
371
+
372
+ test("should map selectedPaths correctly from selectedDocs", async () => {
373
+ findItemByPathSpy.mockImplementation((_, path) => ({
374
+ path,
375
+ content: `Content for ${path}`,
376
+ title: path,
377
+ }));
378
+
379
+ const input = {
380
+ docs: ["/docs/guide.md", "/docs/api.md"],
381
+ documentExecutionStructure: [],
382
+ boardId: "board-123",
383
+ docsDir: "/project/docs",
384
+ isTranslate: false,
385
+ feedback: "Path mapping test",
386
+ locale: "en",
387
+ };
388
+
389
+ const result = await chooseDocs(input, mockOptions);
390
+
391
+ expect(result.selectedPaths).toEqual(["/docs/guide.md", "/docs/api.md"]);
392
+ });
393
+
394
+ // EDGE CASES
395
+ test("should handle special characters in file paths", async () => {
396
+ const specialPaths = ["/docs/中文文档.md", "/docs/file with spaces.md"];
397
+ findItemByPathSpy.mockImplementation((_, path) => ({
398
+ path,
399
+ content: `Content for ${path}`,
400
+ title: path,
401
+ }));
402
+
403
+ const input = {
404
+ docs: specialPaths,
405
+ documentExecutionStructure: [],
406
+ boardId: "board-123",
407
+ docsDir: "/project/docs",
408
+ isTranslate: false,
409
+ feedback: "Special chars test",
410
+ locale: "zh",
411
+ };
412
+
413
+ const result = await chooseDocs(input, mockOptions);
414
+
415
+ expect(result.selectedPaths).toEqual(specialPaths);
416
+ });
417
+ });
@@ -0,0 +1,70 @@
1
+ import { afterEach, beforeEach, describe, expect, spyOn, test } from "bun:test";
2
+ import exit from "../../../agents/utils/exit.mjs";
3
+
4
+ describe("exit", () => {
5
+ let processExitSpy;
6
+ let originalProcessExit;
7
+
8
+ beforeEach(() => {
9
+ // Save the original process.exit
10
+ originalProcessExit = process.exit;
11
+
12
+ // Spy on process.exit to prevent actual process termination
13
+ processExitSpy = spyOn(process, "exit").mockImplementation(() => {
14
+ // Mock implementation that doesn't actually exit
15
+ });
16
+ });
17
+
18
+ afterEach(() => {
19
+ // Restore the original process.exit
20
+ processExitSpy?.mockRestore();
21
+ process.exit = originalProcessExit;
22
+ });
23
+
24
+ // BASIC FUNCTIONALITY TESTS
25
+ test("should call process.exit with code 0", async () => {
26
+ await exit();
27
+
28
+ expect(processExitSpy).toHaveBeenCalledWith(0);
29
+ expect(processExitSpy).toHaveBeenCalledTimes(1);
30
+ });
31
+
32
+ test("should be callable multiple times (in theory)", async () => {
33
+ await exit();
34
+ await exit();
35
+
36
+ expect(processExitSpy).toHaveBeenCalledWith(0);
37
+ expect(processExitSpy).toHaveBeenCalledTimes(2);
38
+ });
39
+
40
+ test("should maintain process.exit behavior characteristics", async () => {
41
+ // Test that our spy captures the essential behavior
42
+ await exit();
43
+
44
+ // Verify the call was made with the expected arguments
45
+ const calls = processExitSpy.mock.calls;
46
+ expect(calls).toHaveLength(1);
47
+ expect(calls[0]).toEqual([0]);
48
+ });
49
+
50
+ // ERROR HANDLING TESTS
51
+ test("should handle spy restoration correctly", async () => {
52
+ await exit();
53
+ expect(processExitSpy).toHaveBeenCalled();
54
+
55
+ // Manually restore and verify
56
+ processExitSpy.mockRestore();
57
+ expect(process.exit).toBe(originalProcessExit);
58
+ });
59
+
60
+ test("should work correctly when process.exit throws (theoretical)", async () => {
61
+ // Reset the spy to throw an error
62
+ processExitSpy.mockImplementation(() => {
63
+ throw new Error("Mock exit error");
64
+ });
65
+
66
+ // The function should still attempt to call process.exit
67
+ await expect(exit()).rejects.toThrow("Mock exit error");
68
+ expect(processExitSpy).toHaveBeenCalledWith(0);
69
+ });
70
+ });
@@ -0,0 +1,51 @@
1
+ import { afterAll, beforeAll, describe, expect, test } from "bun:test";
2
+ import { join } from "node:path";
3
+ import { AIAgent } from "@aigne/core";
4
+ import { loadAgent } from "@aigne/core/loader/index.js";
5
+ import { loadModel } from "../../utils/mock-chat-model.mjs";
6
+
7
+ describe("feedbackRefiner Agent", () => {
8
+ beforeAll(() => {
9
+ process.env.AIGNE_OBSERVABILITY_DISABLED = "true";
10
+ });
11
+
12
+ afterAll(() => {
13
+ delete process.env.AIGNE_OBSERVABILITY_DISABLED;
14
+ });
15
+ test("should load agent correctly with proper configuration", async () => {
16
+ const agent = await loadAgent(
17
+ join(import.meta.dirname, "../../../agents/utils/feedback-refiner.yaml"),
18
+ {
19
+ model: loadModel,
20
+ },
21
+ );
22
+
23
+ expect(agent).toBeDefined();
24
+
25
+ // Verify agent exists and is correct type
26
+ expect(agent).toBeDefined();
27
+ expect(agent).toBeInstanceOf(AIAgent);
28
+ expect(agent.name).toBe("feedbackRefiner");
29
+ });
30
+
31
+ test("should have instructions loaded from file", async () => {
32
+ const agent = await loadAgent(
33
+ join(import.meta.dirname, "../../../agents/utils/feedback-refiner.yaml"),
34
+ {
35
+ model: loadModel,
36
+ },
37
+ );
38
+
39
+ expect(agent).toBeDefined();
40
+
41
+ // Verify instructions are loaded
42
+ expect(agent.instructions).toBeDefined();
43
+ const instructions = await agent.instructions.build({});
44
+ expect(instructions.messages).toBeDefined();
45
+ expect(instructions.messages.length).toBeGreaterThan(0);
46
+
47
+ // The instructions should contain content from the prompt file
48
+ const systemMessage = instructions.messages.find((m) => m.role === "system");
49
+ expect(systemMessage).toBeDefined();
50
+ });
51
+ });