@aigne/doc-smith 0.4.5 → 0.6.0

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 (36) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/agents/batch-translate.yaml +3 -0
  3. package/agents/check-detail-result.mjs +2 -1
  4. package/agents/check-detail.mjs +1 -0
  5. package/agents/check-feedback-refiner.mjs +79 -0
  6. package/agents/check-structure-plan.mjs +16 -0
  7. package/agents/detail-generator-and-translate.yaml +3 -0
  8. package/agents/detail-regenerator.yaml +3 -0
  9. package/agents/docs-generator.yaml +3 -0
  10. package/agents/feedback-refiner.yaml +48 -0
  11. package/agents/find-items-by-paths.mjs +5 -1
  12. package/agents/find-user-preferences-by-path.mjs +37 -0
  13. package/agents/input-generator.mjs +8 -9
  14. package/agents/load-sources.mjs +63 -9
  15. package/agents/manage-prefs.mjs +203 -0
  16. package/agents/publish-docs.mjs +3 -1
  17. package/agents/retranslate.yaml +3 -0
  18. package/agents/structure-planning.yaml +3 -0
  19. package/aigne.yaml +4 -0
  20. package/package.json +10 -9
  21. package/prompts/content-detail-generator.md +13 -1
  22. package/prompts/document/detail-generator.md +1 -0
  23. package/prompts/feedback-refiner.md +84 -0
  24. package/prompts/structure-planning.md +8 -0
  25. package/prompts/translator.md +8 -0
  26. package/tests/{test-all-validation-cases.mjs → all-validation-cases.test.mjs} +60 -137
  27. package/tests/check-detail-result.test.mjs +90 -77
  28. package/tests/load-sources.test.mjs +103 -291
  29. package/tests/preferences-utils.test.mjs +369 -0
  30. package/tests/{test-save-docs.mjs → save-docs.test.mjs} +29 -47
  31. package/tests/save-value-to-config.test.mjs +165 -288
  32. package/utils/auth-utils.mjs +1 -1
  33. package/utils/constants.mjs +22 -10
  34. package/utils/markdown-checker.mjs +89 -9
  35. package/utils/preferences-utils.mjs +175 -0
  36. package/utils/utils.mjs +3 -3
@@ -1,92 +1,105 @@
1
+ import { describe, expect, test } from "bun:test";
1
2
  import checkDetailResult from "../agents/check-detail-result.mjs";
2
3
 
3
- async function runTests() {
4
- function assert(condition, message) {
5
- if (!condition) {
6
- throw new Error(`Assertion failed: ${message}`);
7
- }
8
- }
9
-
10
- async function testApproveValidContent() {
11
- console.log("Testing: should approve valid content");
4
+ describe("checkDetailResult", () => {
5
+ test("should approve valid content", async () => {
12
6
  const structurePlan = [{ path: "/getting-started" }];
13
- const content = "This is a test with a [valid link](/getting-started).";
14
- const result = await checkDetailResult({ structurePlan, content });
15
- assert(result.isApproved === true, "Should be approved");
16
- assert(result.detailFeedback === "", "Feedback should be empty");
17
- console.log("✅ Test passed: should approve valid content");
18
- }
7
+ const reviewContent =
8
+ "This is a test with a [valid link](/getting-started).\n\nThis has proper structure with multiple lines.";
9
+ const result = await checkDetailResult({ structurePlan, reviewContent });
10
+ expect(result.isApproved).toBe(true);
11
+ expect(result.detailFeedback).toBe("");
12
+ });
19
13
 
20
- async function testRejectDeadLink() {
21
- console.log("Testing: should reject content with a dead link");
14
+ test("should reject content with a dead link", async () => {
22
15
  const structurePlan = [{ path: "/getting-started" }];
23
- const content = "This contains a [dead link](/dead-link).";
24
- const result = await checkDetailResult({ structurePlan, content });
25
- assert(result.isApproved === false, "Should not be approved");
26
- assert(result.detailFeedback.includes("Found a dead link"), "Should report dead link");
27
- console.log("✅ Test passed: should reject content with a dead link");
28
- }
16
+ const reviewContent = "This contains a [dead link](/dead-link).";
17
+ const result = await checkDetailResult({ structurePlan, reviewContent });
18
+ expect(result.isApproved).toBe(false);
19
+ expect(result.detailFeedback).toContain("Found a dead link");
20
+ });
29
21
 
30
- async function testRejectIncorrectTableSeparator() {
31
- console.log("Testing: should reject content with incorrect table separator");
22
+ test("should accept valid table format", async () => {
32
23
  const structurePlan = [];
33
- const content = "| Header | Header |\n| - | - |\n| Cell | Cell |";
34
- const result = await checkDetailResult({ structurePlan, content });
35
- assert(result.isApproved === false, "Should not be approved");
36
- assert(
37
- result.detailFeedback.includes("incorrect table separator"),
38
- "Should report incorrect table separator",
39
- );
40
- console.log("✅ Test passed: should reject content with incorrect table separator");
41
- }
24
+ const reviewContent =
25
+ "| Header | Header |\n|--------|--------|\n| Cell | Cell |\n\nThis table is properly formatted.";
26
+ const result = await checkDetailResult({ structurePlan, reviewContent });
27
+ expect(result.isApproved).toBe(true);
28
+ expect(result.detailFeedback).toBe("");
29
+ });
42
30
 
43
- async function testApproveExternalLink() {
44
- console.log("Testing: should approve content with an external link");
31
+ test("should approve content with an external link", async () => {
45
32
  const structurePlan = [];
46
- const content = "This is a [valid external link](https://example.com).";
47
- const result = await checkDetailResult({ structurePlan, content });
48
- assert(result.isApproved === true, "Should be approved");
49
- assert(result.detailFeedback === "", "Feedback should be empty");
50
- console.log("✅ Test passed: should approve content with an external link");
51
- }
33
+ const reviewContent =
34
+ "This is a [valid external link](https://example.com).\n\nThis has proper multi-line structure.";
35
+ const result = await checkDetailResult({ structurePlan, reviewContent });
36
+ expect(result.isApproved).toBe(true);
37
+ expect(result.detailFeedback).toBe("");
38
+ });
52
39
 
53
- async function testRejectMultipleIssues() {
54
- console.log("Testing: should reject content with multiple issues");
40
+ test("should reject content with multiple issues", async () => {
55
41
  const structurePlan = [{ path: "/getting-started" }];
56
- const content = "This has a [dead link](/dead-link) and an incorrect table: | - |.";
57
- const result = await checkDetailResult({ structurePlan, content });
58
- assert(result.isApproved === false, "Should not be approved");
59
- assert(result.detailFeedback.includes("Found a dead link"), "Should report dead link");
60
- assert(
61
- result.detailFeedback.includes("incorrect table separator"),
62
- "Should report incorrect table separator",
63
- );
64
- console.log("✅ Test passed: should reject content with multiple issues");
65
- }
42
+ const reviewContent = "This has a [dead link](/dead-link).";
43
+ const result = await checkDetailResult({ structurePlan, reviewContent });
44
+ expect(result.isApproved).toBe(false);
45
+ expect(result.detailFeedback).toContain("dead link");
46
+ });
66
47
 
67
- async function testApproveImageSyntax() {
68
- console.log("Testing: should approve content with image syntax");
48
+ test("should approve content with external image syntax", async () => {
69
49
  const structurePlan = [];
70
- const content = "This is an image ![MCP Go Logo](/logo.png).";
71
- const result = await checkDetailResult({ structurePlan, content });
72
- assert(result.isApproved === true, "Should be approved");
73
- assert(result.detailFeedback === "", "Feedback should be empty");
74
- console.log("✅ Test passed: should approve content with image syntax");
75
- }
50
+ const reviewContent =
51
+ "This is an image ![MCP Go Logo](https://example.com/logo.png).\n\nThis has proper structure.";
52
+ const result = await checkDetailResult({ structurePlan, reviewContent });
53
+ expect(result.isApproved).toBe(true);
54
+ expect(result.detailFeedback).toBe("");
55
+ });
76
56
 
77
- try {
78
- console.log("🚀 Starting checkDetailResult tests...");
79
- await testApproveValidContent();
80
- await testRejectDeadLink();
81
- await testRejectIncorrectTableSeparator();
82
- await testApproveExternalLink();
83
- await testRejectMultipleIssues();
84
- await testApproveImageSyntax();
85
- console.log("🎉 All tests passed!");
86
- } catch (error) {
87
- console.error("❌ Test failed:", error.message);
88
- process.exit(1);
89
- }
90
- }
57
+ test("should approve content with valid local image path", async () => {
58
+ const structurePlan = [];
59
+ const reviewContent =
60
+ "This is a valid image ![Test Image](./README.md).\n\nThis has proper structure.";
61
+ const docsDir = "/Users/lban/arcblock/code/aigne-doc-smith";
62
+ const result = await checkDetailResult({ structurePlan, reviewContent, docsDir });
63
+ expect(result.isApproved).toBe(true);
64
+ expect(result.detailFeedback).toBe("");
65
+ });
91
66
 
92
- runTests();
67
+ test("should reject content with invalid local image path", async () => {
68
+ const structurePlan = [];
69
+ const reviewContent =
70
+ "This is an invalid image ![Non-existent Image](./nonexistent.png).\n\nThis has proper structure.";
71
+ const docsDir = "/Users/lban/arcblock/code/aigne-doc-smith";
72
+ const result = await checkDetailResult({ structurePlan, reviewContent, docsDir });
73
+ expect(result.isApproved).toBe(false);
74
+ expect(result.detailFeedback).toContain("Found invalid local image");
75
+ expect(result.detailFeedback).toContain("only valid media resources can be used");
76
+ });
77
+
78
+ test("should approve content with absolute image path that exists", async () => {
79
+ const structurePlan = [];
80
+ const reviewContent =
81
+ "This is an absolute image ![Test Image](/Users/lban/arcblock/code/aigne-doc-smith/README.md).\n\nThis has proper structure.";
82
+ const result = await checkDetailResult({ structurePlan, reviewContent });
83
+ expect(result.isApproved).toBe(true);
84
+ expect(result.detailFeedback).toBe("");
85
+ });
86
+
87
+ test("should reject content with absolute image path that doesn't exist", async () => {
88
+ const structurePlan = [];
89
+ const reviewContent =
90
+ "This is an invalid absolute image ![Non-existent Image](/path/to/nonexistent.png).\n\nThis has proper structure.";
91
+ const result = await checkDetailResult({ structurePlan, reviewContent });
92
+ expect(result.isApproved).toBe(false);
93
+ expect(result.detailFeedback).toContain("Found invalid local image");
94
+ expect(result.detailFeedback).toContain("only valid media resources can be used");
95
+ });
96
+
97
+ test("should approve content with external image URL", async () => {
98
+ const structurePlan = [];
99
+ const reviewContent =
100
+ "This is an external image ![External Image](https://example.com/image.png).\n\nThis has proper structure.";
101
+ const result = await checkDetailResult({ structurePlan, reviewContent });
102
+ expect(result.isApproved).toBe(true);
103
+ expect(result.detailFeedback).toBe("");
104
+ });
105
+ });