@aigne/doc-smith 0.8.12-beta.8 → 0.8.12-beta.9
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.
- package/CHANGELOG.md +13 -0
- package/agents/publish/index.yaml +4 -0
- package/agents/publish/publish-docs.mjs +77 -5
- package/agents/publish/translate-meta.mjs +103 -0
- package/agents/update/generate-document.yaml +30 -28
- package/agents/update/update-document-detail.yaml +3 -1
- package/agents/utils/update-branding.mjs +69 -0
- package/package.json +16 -2
- package/prompts/common/document/role-and-personality.md +3 -1
- package/prompts/detail/d2-diagram/guide.md +7 -1
- package/prompts/detail/d2-diagram/user-prompt.md +3 -0
- package/prompts/detail/generate/system-prompt.md +6 -7
- package/prompts/detail/generate/user-prompt.md +12 -3
- package/prompts/detail/update/user-prompt.md +0 -2
- package/prompts/structure/update/user-prompt.md +0 -4
- package/utils/file-utils.mjs +69 -24
- package/utils/markdown-checker.mjs +0 -20
- package/utils/request.mjs +7 -0
- package/utils/upload-files.mjs +231 -0
- package/utils/utils.mjs +11 -1
- package/.aigne/doc-smith/config.yaml +0 -77
- package/.aigne/doc-smith/history.yaml +0 -37
- package/.aigne/doc-smith/media-description.yaml +0 -91
- package/.aigne/doc-smith/output/structure-plan.json +0 -162
- package/.aigne/doc-smith/preferences.yml +0 -97
- package/.aigne/doc-smith/upload-cache.yaml +0 -1830
- package/.github/PULL_REQUEST_TEMPLATE.md +0 -28
- package/.github/workflows/ci.yml +0 -54
- package/.github/workflows/create-release-pr.yaml +0 -21
- package/.github/workflows/publish-docs.yml +0 -65
- package/.github/workflows/release.yml +0 -49
- package/.github/workflows/reviewer.yml +0 -54
- package/.release-please-manifest.json +0 -3
- package/RELEASE.md +0 -9
- package/assets/screenshots/doc-complete-setup.png +0 -0
- package/assets/screenshots/doc-generate-docs.png +0 -0
- package/assets/screenshots/doc-generate.png +0 -0
- package/assets/screenshots/doc-generated-successfully.png +0 -0
- package/assets/screenshots/doc-publish.png +0 -0
- package/assets/screenshots/doc-regenerate.png +0 -0
- package/assets/screenshots/doc-translate-langs.png +0 -0
- package/assets/screenshots/doc-translate.png +0 -0
- package/assets/screenshots/doc-update.png +0 -0
- package/biome.json +0 -73
- package/codecov.yml +0 -15
- package/docs/_sidebar.md +0 -15
- package/docs/configuration-initial-setup.ja.md +0 -179
- package/docs/configuration-initial-setup.md +0 -198
- package/docs/configuration-initial-setup.zh-TW.md +0 -179
- package/docs/configuration-initial-setup.zh.md +0 -179
- package/docs/configuration-managing-preferences.ja.md +0 -100
- package/docs/configuration-managing-preferences.md +0 -100
- package/docs/configuration-managing-preferences.zh-TW.md +0 -100
- package/docs/configuration-managing-preferences.zh.md +0 -100
- package/docs/configuration.ja.md +0 -69
- package/docs/configuration.md +0 -69
- package/docs/configuration.zh-TW.md +0 -69
- package/docs/configuration.zh.md +0 -69
- package/docs/getting-started.ja.md +0 -107
- package/docs/getting-started.md +0 -107
- package/docs/getting-started.zh-TW.md +0 -107
- package/docs/getting-started.zh.md +0 -107
- package/docs/guides-cleaning-up.ja.md +0 -51
- package/docs/guides-cleaning-up.md +0 -52
- package/docs/guides-cleaning-up.zh-TW.md +0 -51
- package/docs/guides-cleaning-up.zh.md +0 -51
- package/docs/guides-evaluating-documents.ja.md +0 -66
- package/docs/guides-evaluating-documents.md +0 -107
- package/docs/guides-evaluating-documents.zh-TW.md +0 -66
- package/docs/guides-evaluating-documents.zh.md +0 -66
- package/docs/guides-generating-documentation.ja.md +0 -151
- package/docs/guides-generating-documentation.md +0 -89
- package/docs/guides-generating-documentation.zh-TW.md +0 -151
- package/docs/guides-generating-documentation.zh.md +0 -151
- package/docs/guides-interactive-chat.ja.md +0 -85
- package/docs/guides-interactive-chat.md +0 -93
- package/docs/guides-interactive-chat.zh-TW.md +0 -85
- package/docs/guides-interactive-chat.zh.md +0 -85
- package/docs/guides-managing-history.ja.md +0 -48
- package/docs/guides-managing-history.md +0 -53
- package/docs/guides-managing-history.zh-TW.md +0 -48
- package/docs/guides-managing-history.zh.md +0 -48
- package/docs/guides-publishing-your-docs.ja.md +0 -78
- package/docs/guides-publishing-your-docs.md +0 -83
- package/docs/guides-publishing-your-docs.zh-TW.md +0 -78
- package/docs/guides-publishing-your-docs.zh.md +0 -78
- package/docs/guides-translating-documentation.ja.md +0 -95
- package/docs/guides-translating-documentation.md +0 -100
- package/docs/guides-translating-documentation.zh-TW.md +0 -95
- package/docs/guides-translating-documentation.zh.md +0 -95
- package/docs/guides-updating-documentation.ja.md +0 -77
- package/docs/guides-updating-documentation.md +0 -79
- package/docs/guides-updating-documentation.zh-TW.md +0 -77
- package/docs/guides-updating-documentation.zh.md +0 -77
- package/docs/guides.ja.md +0 -32
- package/docs/guides.md +0 -32
- package/docs/guides.zh-TW.md +0 -32
- package/docs/guides.zh.md +0 -32
- package/docs/overview.ja.md +0 -61
- package/docs/overview.md +0 -61
- package/docs/overview.zh-TW.md +0 -61
- package/docs/overview.zh.md +0 -61
- package/docs/release-notes.ja.md +0 -255
- package/docs/release-notes.md +0 -288
- package/docs/release-notes.zh-TW.md +0 -255
- package/docs/release-notes.zh.md +0 -255
- package/prompts/common/afs/afs-tools-usage.md +0 -5
- package/prompts/common/afs/use-afs-instruction.md +0 -1
- package/release-please-config.json +0 -14
- package/tests/agents/chat/chat.test.mjs +0 -46
- package/tests/agents/clear/choose-contents.test.mjs +0 -284
- package/tests/agents/clear/clear-auth-tokens.test.mjs +0 -268
- package/tests/agents/clear/clear-document-config.test.mjs +0 -167
- package/tests/agents/clear/clear-document-structure.test.mjs +0 -380
- package/tests/agents/clear/clear-generated-docs.test.mjs +0 -222
- package/tests/agents/evaluate/code-snippet.test.mjs +0 -163
- package/tests/agents/evaluate/fixtures/api-services.md +0 -87
- package/tests/agents/evaluate/fixtures/js-sdk.md +0 -94
- package/tests/agents/evaluate/generate-report.test.mjs +0 -312
- package/tests/agents/generate/check-document-structure.test.mjs +0 -45
- package/tests/agents/generate/check-need-generate-structure.test.mjs +0 -279
- package/tests/agents/generate/document-structure-tools/add-document.test.mjs +0 -449
- package/tests/agents/generate/document-structure-tools/delete-document.test.mjs +0 -410
- package/tests/agents/generate/document-structure-tools/generate-sub-structure.test.mjs +0 -277
- package/tests/agents/generate/document-structure-tools/move-document.test.mjs +0 -476
- package/tests/agents/generate/document-structure-tools/update-document.test.mjs +0 -548
- package/tests/agents/generate/generate-structure.test.mjs +0 -45
- package/tests/agents/generate/user-review-document-structure.test.mjs +0 -319
- package/tests/agents/history/view.test.mjs +0 -97
- package/tests/agents/init/init.test.mjs +0 -1657
- package/tests/agents/prefs/prefs.test.mjs +0 -431
- package/tests/agents/publish/publish-docs.test.mjs +0 -787
- package/tests/agents/translate/choose-language.test.mjs +0 -311
- package/tests/agents/translate/translate-document.test.mjs +0 -51
- package/tests/agents/update/check-document.test.mjs +0 -463
- package/tests/agents/update/check-update-is-single.test.mjs +0 -300
- package/tests/agents/update/document-tools/update-document-content.test.mjs +0 -329
- package/tests/agents/update/generate-document.test.mjs +0 -51
- package/tests/agents/update/save-and-translate-document.test.mjs +0 -369
- package/tests/agents/update/user-review-document.test.mjs +0 -582
- package/tests/agents/utils/action-success.test.mjs +0 -54
- package/tests/agents/utils/check-detail-result.test.mjs +0 -743
- package/tests/agents/utils/check-feedback-refiner.test.mjs +0 -478
- package/tests/agents/utils/choose-docs.test.mjs +0 -406
- package/tests/agents/utils/exit.test.mjs +0 -70
- package/tests/agents/utils/feedback-refiner.test.mjs +0 -51
- package/tests/agents/utils/find-item-by-path.test.mjs +0 -517
- package/tests/agents/utils/find-user-preferences-by-path.test.mjs +0 -382
- package/tests/agents/utils/format-document-structure.test.mjs +0 -364
- package/tests/agents/utils/fs.test.mjs +0 -267
- package/tests/agents/utils/load-sources.test.mjs +0 -1470
- package/tests/agents/utils/save-docs.test.mjs +0 -109
- package/tests/agents/utils/save-output.test.mjs +0 -315
- package/tests/agents/utils/save-single-doc.test.mjs +0 -364
- package/tests/agents/utils/transform-detail-datasources.test.mjs +0 -320
- package/tests/utils/auth-utils.test.mjs +0 -596
- package/tests/utils/blocklet.test.mjs +0 -336
- package/tests/utils/conflict-detector.test.mjs +0 -355
- package/tests/utils/constants.test.mjs +0 -295
- package/tests/utils/d2-utils.test.mjs +0 -437
- package/tests/utils/deploy.test.mjs +0 -399
- package/tests/utils/docs-finder-utils.test.mjs +0 -650
- package/tests/utils/file-utils.test.mjs +0 -521
- package/tests/utils/history-utils.test.mjs +0 -206
- package/tests/utils/kroki-utils.test.mjs +0 -646
- package/tests/utils/linter/fixtures/css/keyword-error.css +0 -1
- package/tests/utils/linter/fixtures/css/missing-semicolon.css +0 -1
- package/tests/utils/linter/fixtures/css/syntax-error.css +0 -1
- package/tests/utils/linter/fixtures/css/undeclare-variable.css +0 -1
- package/tests/utils/linter/fixtures/css/unused-variable.css +0 -2
- package/tests/utils/linter/fixtures/css/valid-code.css +0 -1
- package/tests/utils/linter/fixtures/dockerfile/keyword-error.dockerfile +0 -1
- package/tests/utils/linter/fixtures/dockerfile/missing-semicolon.dockerfile +0 -2
- package/tests/utils/linter/fixtures/dockerfile/syntax-error.dockerfile +0 -2
- package/tests/utils/linter/fixtures/dockerfile/undeclare-variable.dockerfile +0 -1
- package/tests/utils/linter/fixtures/dockerfile/unused-variable.dockerfile +0 -1
- package/tests/utils/linter/fixtures/dockerfile/valid-code.dockerfile +0 -2
- package/tests/utils/linter/fixtures/go/keyword-error.go +0 -5
- package/tests/utils/linter/fixtures/go/missing-semicolon.go +0 -5
- package/tests/utils/linter/fixtures/go/syntax-error.go +0 -6
- package/tests/utils/linter/fixtures/go/undeclare-variable.go +0 -5
- package/tests/utils/linter/fixtures/go/unused-variable.go +0 -5
- package/tests/utils/linter/fixtures/go/valid-code.go +0 -7
- package/tests/utils/linter/fixtures/js/keyword-error.js +0 -3
- package/tests/utils/linter/fixtures/js/missing-semicolon.js +0 -6
- package/tests/utils/linter/fixtures/js/syntax-error.js +0 -4
- package/tests/utils/linter/fixtures/js/undeclare-variable.js +0 -3
- package/tests/utils/linter/fixtures/js/unused-variable.js +0 -7
- package/tests/utils/linter/fixtures/js/valid-code.js +0 -15
- package/tests/utils/linter/fixtures/json/keyword-error.json +0 -1
- package/tests/utils/linter/fixtures/json/missing-semicolon.json +0 -1
- package/tests/utils/linter/fixtures/json/syntax-error.json +0 -1
- package/tests/utils/linter/fixtures/json/undeclare-variable.json +0 -1
- package/tests/utils/linter/fixtures/json/unused-variable.json +0 -1
- package/tests/utils/linter/fixtures/json/valid-code.json +0 -1
- package/tests/utils/linter/fixtures/jsx/keyword-error.jsx +0 -5
- package/tests/utils/linter/fixtures/jsx/missing-semicolon.jsx +0 -5
- package/tests/utils/linter/fixtures/jsx/syntax-error.jsx +0 -5
- package/tests/utils/linter/fixtures/jsx/undeclare-variable.jsx +0 -5
- package/tests/utils/linter/fixtures/jsx/unused-variable.jsx +0 -4
- package/tests/utils/linter/fixtures/jsx/valid-code.jsx +0 -5
- package/tests/utils/linter/fixtures/python/keyword-error.py +0 -3
- package/tests/utils/linter/fixtures/python/missing-semicolon.py +0 -2
- package/tests/utils/linter/fixtures/python/syntax-error.py +0 -3
- package/tests/utils/linter/fixtures/python/undeclare-variable.py +0 -3
- package/tests/utils/linter/fixtures/python/unused-variable.py +0 -6
- package/tests/utils/linter/fixtures/python/valid-code.py +0 -12
- package/tests/utils/linter/fixtures/ruby/keyword-error.rb +0 -2
- package/tests/utils/linter/fixtures/ruby/missing-semicolon.rb +0 -1
- package/tests/utils/linter/fixtures/ruby/syntax-error.rb +0 -2
- package/tests/utils/linter/fixtures/ruby/undeclare-variable.rb +0 -1
- package/tests/utils/linter/fixtures/ruby/unused-variable.rb +0 -2
- package/tests/utils/linter/fixtures/ruby/valid-code.rb +0 -1
- package/tests/utils/linter/fixtures/sass/keyword-error.sass +0 -2
- package/tests/utils/linter/fixtures/sass/missing-semicolon.sass +0 -3
- package/tests/utils/linter/fixtures/sass/syntax-error.sass +0 -3
- package/tests/utils/linter/fixtures/sass/undeclare-variable.sass +0 -2
- package/tests/utils/linter/fixtures/sass/unused-variable.sass +0 -4
- package/tests/utils/linter/fixtures/sass/valid-code.sass +0 -2
- package/tests/utils/linter/fixtures/scss/keyword-error.scss +0 -1
- package/tests/utils/linter/fixtures/scss/missing-semicolon.scss +0 -1
- package/tests/utils/linter/fixtures/scss/syntax-error.scss +0 -1
- package/tests/utils/linter/fixtures/scss/undeclare-variable.scss +0 -1
- package/tests/utils/linter/fixtures/scss/unused-variable.scss +0 -2
- package/tests/utils/linter/fixtures/scss/valid-code.scss +0 -1
- package/tests/utils/linter/fixtures/shell/keyword-error.sh +0 -5
- package/tests/utils/linter/fixtures/shell/missing-semicolon.sh +0 -3
- package/tests/utils/linter/fixtures/shell/syntax-error.sh +0 -4
- package/tests/utils/linter/fixtures/shell/undeclare-variable.sh +0 -3
- package/tests/utils/linter/fixtures/shell/unused-variable.sh +0 -4
- package/tests/utils/linter/fixtures/shell/valid-code.sh +0 -3
- package/tests/utils/linter/fixtures/ts/keyword-error.ts +0 -1
- package/tests/utils/linter/fixtures/ts/missing-semicolon.ts +0 -1
- package/tests/utils/linter/fixtures/ts/syntax-error.ts +0 -1
- package/tests/utils/linter/fixtures/ts/undeclare-variable.ts +0 -1
- package/tests/utils/linter/fixtures/ts/unused-variable.ts +0 -3
- package/tests/utils/linter/fixtures/ts/valid-code.ts +0 -3
- package/tests/utils/linter/fixtures/tsx/keyword-error.tsx +0 -5
- package/tests/utils/linter/fixtures/tsx/missing-semicolon.tsx +0 -5
- package/tests/utils/linter/fixtures/tsx/syntax-error.tsx +0 -5
- package/tests/utils/linter/fixtures/tsx/undeclare-variable.tsx +0 -6
- package/tests/utils/linter/fixtures/tsx/unused-variable.tsx +0 -6
- package/tests/utils/linter/fixtures/tsx/valid-code.tsx +0 -5
- package/tests/utils/linter/fixtures/vue/keyword-error.vue +0 -6
- package/tests/utils/linter/fixtures/vue/missing-semicolon.vue +0 -6
- package/tests/utils/linter/fixtures/vue/syntax-error.vue +0 -6
- package/tests/utils/linter/fixtures/vue/undeclare-variable.vue +0 -6
- package/tests/utils/linter/fixtures/vue/unused-variable.vue +0 -7
- package/tests/utils/linter/fixtures/vue/valid-code.vue +0 -6
- package/tests/utils/linter/fixtures/yaml/keyword-error.yml +0 -1
- package/tests/utils/linter/fixtures/yaml/missing-semicolon.yml +0 -2
- package/tests/utils/linter/fixtures/yaml/syntax-error.yml +0 -1
- package/tests/utils/linter/fixtures/yaml/undeclare-variable.yml +0 -1
- package/tests/utils/linter/fixtures/yaml/unused-variable.yml +0 -2
- package/tests/utils/linter/fixtures/yaml/valid-code.yml +0 -3
- package/tests/utils/linter/index.test.mjs +0 -440
- package/tests/utils/linter/scan-results.mjs +0 -42
- package/tests/utils/load-config.test.mjs +0 -141
- package/tests/utils/markdown/index.test.mjs +0 -478
- package/tests/utils/mermaid-validator.test.mjs +0 -541
- package/tests/utils/mock-chat-model.mjs +0 -12
- package/tests/utils/preferences-utils.test.mjs +0 -465
- package/tests/utils/save-value-to-config.test.mjs +0 -483
- package/tests/utils/utils.test.mjs +0 -941
|
@@ -1,410 +0,0 @@
|
|
|
1
|
-
import { afterEach, beforeEach, describe, expect, spyOn, test } from "bun:test";
|
|
2
|
-
import deleteDocument from "../../../../agents/generate/document-structure-tools/delete-document.mjs";
|
|
3
|
-
|
|
4
|
-
describe("delete-document", () => {
|
|
5
|
-
let consoleSpy;
|
|
6
|
-
let baseDocumentStructure;
|
|
7
|
-
|
|
8
|
-
beforeEach(() => {
|
|
9
|
-
consoleSpy = spyOn(console, "log").mockImplementation(() => {});
|
|
10
|
-
baseDocumentStructure = [
|
|
11
|
-
{
|
|
12
|
-
title: "Getting Started",
|
|
13
|
-
description: "Introduction to the project",
|
|
14
|
-
path: "/getting-started",
|
|
15
|
-
parentId: null,
|
|
16
|
-
sourceIds: ["intro.md"],
|
|
17
|
-
},
|
|
18
|
-
{
|
|
19
|
-
title: "API Reference",
|
|
20
|
-
description: "Complete API documentation",
|
|
21
|
-
path: "/api",
|
|
22
|
-
parentId: null,
|
|
23
|
-
sourceIds: ["api.js"],
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
title: "Authentication",
|
|
27
|
-
description: "How to authenticate with the API",
|
|
28
|
-
path: "/api/auth",
|
|
29
|
-
parentId: "/api",
|
|
30
|
-
sourceIds: ["auth.js", "security.md"],
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
title: "Rate Limiting",
|
|
34
|
-
description: "API rate limiting documentation",
|
|
35
|
-
path: "/api/rate-limiting",
|
|
36
|
-
parentId: "/api",
|
|
37
|
-
sourceIds: ["rate-limit.js"],
|
|
38
|
-
},
|
|
39
|
-
{
|
|
40
|
-
title: "OAuth",
|
|
41
|
-
description: "OAuth authentication flow",
|
|
42
|
-
path: "/api/auth/oauth",
|
|
43
|
-
parentId: "/api/auth",
|
|
44
|
-
sourceIds: ["oauth.js"],
|
|
45
|
-
},
|
|
46
|
-
];
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
afterEach(() => {
|
|
50
|
-
consoleSpy?.mockRestore();
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
// SUCCESSFUL DELETION TESTS
|
|
54
|
-
test("should delete a leaf document successfully", async () => {
|
|
55
|
-
const result = await deleteDocument({
|
|
56
|
-
documentStructure: baseDocumentStructure,
|
|
57
|
-
path: "/api/rate-limiting",
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
expect(result.documentStructure).toHaveLength(4);
|
|
61
|
-
expect(result.deletedDocument).toEqual({
|
|
62
|
-
title: "Rate Limiting",
|
|
63
|
-
description: "API rate limiting documentation",
|
|
64
|
-
path: "/api/rate-limiting",
|
|
65
|
-
parentId: "/api",
|
|
66
|
-
sourceIds: ["rate-limit.js"],
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
// Verify the document is actually removed
|
|
70
|
-
expect(
|
|
71
|
-
result.documentStructure.find((doc) => doc.path === "/api/rate-limiting"),
|
|
72
|
-
).toBeUndefined();
|
|
73
|
-
|
|
74
|
-
// Verify other documents remain
|
|
75
|
-
expect(result.documentStructure.find((doc) => doc.path === "/api")).toBeDefined();
|
|
76
|
-
expect(result.documentStructure.find((doc) => doc.path === "/api/auth")).toBeDefined();
|
|
77
|
-
expect(consoleSpy).not.toHaveBeenCalled();
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
test("should delete a deeply nested document successfully", async () => {
|
|
81
|
-
const result = await deleteDocument({
|
|
82
|
-
documentStructure: baseDocumentStructure,
|
|
83
|
-
path: "/api/auth/oauth",
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
expect(result.documentStructure).toHaveLength(4);
|
|
87
|
-
expect(result.deletedDocument).toEqual({
|
|
88
|
-
title: "OAuth",
|
|
89
|
-
description: "OAuth authentication flow",
|
|
90
|
-
path: "/api/auth/oauth",
|
|
91
|
-
parentId: "/api/auth",
|
|
92
|
-
sourceIds: ["oauth.js"],
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
// Verify the parent still exists
|
|
96
|
-
expect(result.documentStructure.find((doc) => doc.path === "/api/auth")).toBeDefined();
|
|
97
|
-
expect(consoleSpy).not.toHaveBeenCalled();
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
test("should delete a top-level document with no children", async () => {
|
|
101
|
-
const result = await deleteDocument({
|
|
102
|
-
documentStructure: baseDocumentStructure,
|
|
103
|
-
path: "/getting-started",
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
expect(result.documentStructure).toHaveLength(4);
|
|
107
|
-
expect(result.deletedDocument).toEqual({
|
|
108
|
-
title: "Getting Started",
|
|
109
|
-
description: "Introduction to the project",
|
|
110
|
-
path: "/getting-started",
|
|
111
|
-
parentId: null,
|
|
112
|
-
sourceIds: ["intro.md"],
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
expect(result.documentStructure.find((doc) => doc.path === "/getting-started")).toBeUndefined();
|
|
116
|
-
expect(consoleSpy).not.toHaveBeenCalled();
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
// VALIDATION ERROR TESTS
|
|
120
|
-
test("should return error when path is missing", async () => {
|
|
121
|
-
const result = await deleteDocument({
|
|
122
|
-
documentStructure: baseDocumentStructure,
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
expect(result.documentStructure).toEqual(baseDocumentStructure);
|
|
126
|
-
expect(result.deletedDocument).toBeUndefined();
|
|
127
|
-
expect(consoleSpy).toHaveBeenCalledWith("⚠️ Cannot delete document: path: Required");
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
test("should return error when path is empty string", async () => {
|
|
131
|
-
const result = await deleteDocument({
|
|
132
|
-
documentStructure: baseDocumentStructure,
|
|
133
|
-
path: "",
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
expect(result.documentStructure).toEqual(baseDocumentStructure);
|
|
137
|
-
expect(result.deletedDocument).toBeUndefined();
|
|
138
|
-
expect(consoleSpy).toHaveBeenCalledWith("⚠️ Cannot delete document: path: Path is required");
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
test("should return error when document does not exist", async () => {
|
|
142
|
-
const result = await deleteDocument({
|
|
143
|
-
documentStructure: baseDocumentStructure,
|
|
144
|
-
path: "/nonexistent-document",
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
expect(result.documentStructure).toEqual(baseDocumentStructure);
|
|
148
|
-
expect(result.deletedDocument).toBeUndefined();
|
|
149
|
-
expect(consoleSpy).toHaveBeenCalledWith(
|
|
150
|
-
"⚠️ Cannot delete document: Document '/nonexistent-document' does not exist. Please choose an existing document to delete.",
|
|
151
|
-
);
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
// CHILD DOCUMENTS VALIDATION TESTS
|
|
155
|
-
test("should return error when trying to delete document with child documents", async () => {
|
|
156
|
-
const result = await deleteDocument({
|
|
157
|
-
documentStructure: baseDocumentStructure,
|
|
158
|
-
path: "/api",
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
expect(result.documentStructure).toEqual(baseDocumentStructure);
|
|
162
|
-
expect(result.deletedDocument).toBeUndefined();
|
|
163
|
-
expect(consoleSpy).toHaveBeenCalledWith(
|
|
164
|
-
"⚠️ Cannot delete document: Document '/api' has 2 child document(s): /api/auth, /api/rate-limiting. Please first move or delete these child documents.",
|
|
165
|
-
);
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
test("should return error when trying to delete document with single child", async () => {
|
|
169
|
-
const result = await deleteDocument({
|
|
170
|
-
documentStructure: baseDocumentStructure,
|
|
171
|
-
path: "/api/auth",
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
expect(result.documentStructure).toEqual(baseDocumentStructure);
|
|
175
|
-
expect(result.deletedDocument).toBeUndefined();
|
|
176
|
-
expect(consoleSpy).toHaveBeenCalledWith(
|
|
177
|
-
"⚠️ Cannot delete document: Document '/api/auth' has 1 child document(s): /api/auth/oauth. Please first move or delete these child documents.",
|
|
178
|
-
);
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
test("should allow deletion after children are removed", async () => {
|
|
182
|
-
// First delete the child
|
|
183
|
-
const firstResult = await deleteDocument({
|
|
184
|
-
documentStructure: baseDocumentStructure,
|
|
185
|
-
path: "/api/auth/oauth",
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
// Then delete the parent
|
|
189
|
-
const secondResult = await deleteDocument({
|
|
190
|
-
documentStructure: firstResult.documentStructure,
|
|
191
|
-
path: "/api/auth",
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
expect(secondResult.documentStructure).toHaveLength(3);
|
|
195
|
-
expect(secondResult.deletedDocument.path).toBe("/api/auth");
|
|
196
|
-
expect(consoleSpy).not.toHaveBeenCalled();
|
|
197
|
-
});
|
|
198
|
-
|
|
199
|
-
// EDGE CASES
|
|
200
|
-
test("should handle empty documentation structure", async () => {
|
|
201
|
-
const result = await deleteDocument({
|
|
202
|
-
documentStructure: [],
|
|
203
|
-
path: "/any-path",
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
expect(result.documentStructure).toEqual([]);
|
|
207
|
-
expect(result.deletedDocument).toBeUndefined();
|
|
208
|
-
expect(consoleSpy).toHaveBeenCalledWith(
|
|
209
|
-
"⚠️ Cannot delete document: Document '/any-path' does not exist. Please choose an existing document to delete.",
|
|
210
|
-
);
|
|
211
|
-
});
|
|
212
|
-
|
|
213
|
-
test("should handle documentation structure with single document", async () => {
|
|
214
|
-
const singleDocStructure = [
|
|
215
|
-
{
|
|
216
|
-
title: "Only Document",
|
|
217
|
-
description: "The only document",
|
|
218
|
-
path: "/only",
|
|
219
|
-
parentId: null,
|
|
220
|
-
sourceIds: ["only.md"],
|
|
221
|
-
},
|
|
222
|
-
];
|
|
223
|
-
|
|
224
|
-
const result = await deleteDocument({
|
|
225
|
-
documentStructure: singleDocStructure,
|
|
226
|
-
path: "/only",
|
|
227
|
-
});
|
|
228
|
-
|
|
229
|
-
expect(result.documentStructure).toEqual([]);
|
|
230
|
-
expect(result.deletedDocument).toEqual(singleDocStructure[0]);
|
|
231
|
-
expect(consoleSpy).not.toHaveBeenCalled();
|
|
232
|
-
});
|
|
233
|
-
|
|
234
|
-
test("should handle complex nested hierarchies", async () => {
|
|
235
|
-
const complexStructure = [
|
|
236
|
-
...baseDocumentStructure,
|
|
237
|
-
{
|
|
238
|
-
title: "OAuth Scopes",
|
|
239
|
-
description: "OAuth scope documentation",
|
|
240
|
-
path: "/api/auth/oauth/scopes",
|
|
241
|
-
parentId: "/api/auth/oauth",
|
|
242
|
-
sourceIds: ["scopes.md"],
|
|
243
|
-
},
|
|
244
|
-
{
|
|
245
|
-
title: "JWT Tokens",
|
|
246
|
-
description: "JWT token handling",
|
|
247
|
-
path: "/api/auth/oauth/jwt",
|
|
248
|
-
parentId: "/api/auth/oauth",
|
|
249
|
-
sourceIds: ["jwt.js"],
|
|
250
|
-
},
|
|
251
|
-
];
|
|
252
|
-
|
|
253
|
-
// Should not be able to delete parent with grandchildren
|
|
254
|
-
const result = await deleteDocument({
|
|
255
|
-
documentStructure: complexStructure,
|
|
256
|
-
path: "/api/auth/oauth",
|
|
257
|
-
});
|
|
258
|
-
|
|
259
|
-
expect(result.documentStructure).toEqual(complexStructure);
|
|
260
|
-
expect(consoleSpy).toHaveBeenCalledWith(
|
|
261
|
-
"⚠️ Cannot delete document: Document '/api/auth/oauth' has 2 child document(s): /api/auth/oauth/scopes, /api/auth/oauth/jwt. Please first move or delete these child documents.",
|
|
262
|
-
);
|
|
263
|
-
});
|
|
264
|
-
|
|
265
|
-
test("should correctly identify all direct children", async () => {
|
|
266
|
-
const structureWithManyChildren = [
|
|
267
|
-
{
|
|
268
|
-
title: "Parent",
|
|
269
|
-
description: "Parent document",
|
|
270
|
-
path: "/parent",
|
|
271
|
-
parentId: null,
|
|
272
|
-
sourceIds: ["parent.md"],
|
|
273
|
-
},
|
|
274
|
-
{
|
|
275
|
-
title: "Child 1",
|
|
276
|
-
description: "First child",
|
|
277
|
-
path: "/parent/child1",
|
|
278
|
-
parentId: "/parent",
|
|
279
|
-
sourceIds: ["child1.md"],
|
|
280
|
-
},
|
|
281
|
-
{
|
|
282
|
-
title: "Child 2",
|
|
283
|
-
description: "Second child",
|
|
284
|
-
path: "/parent/child2",
|
|
285
|
-
parentId: "/parent",
|
|
286
|
-
sourceIds: ["child2.md"],
|
|
287
|
-
},
|
|
288
|
-
{
|
|
289
|
-
title: "Child 3",
|
|
290
|
-
description: "Third child",
|
|
291
|
-
path: "/parent/child3",
|
|
292
|
-
parentId: "/parent",
|
|
293
|
-
sourceIds: ["child3.md"],
|
|
294
|
-
},
|
|
295
|
-
{
|
|
296
|
-
title: "Grandchild",
|
|
297
|
-
description: "Grandchild document",
|
|
298
|
-
path: "/parent/child1/grandchild",
|
|
299
|
-
parentId: "/parent/child1",
|
|
300
|
-
sourceIds: ["grandchild.md"],
|
|
301
|
-
},
|
|
302
|
-
];
|
|
303
|
-
|
|
304
|
-
const result = await deleteDocument({
|
|
305
|
-
documentStructure: structureWithManyChildren,
|
|
306
|
-
path: "/parent",
|
|
307
|
-
});
|
|
308
|
-
|
|
309
|
-
expect(result.documentStructure).toEqual(structureWithManyChildren);
|
|
310
|
-
expect(consoleSpy).toHaveBeenCalledWith(
|
|
311
|
-
"⚠️ Cannot delete document: Document '/parent' has 3 child document(s): /parent/child1, /parent/child2, /parent/child3. Please first move or delete these child documents.",
|
|
312
|
-
);
|
|
313
|
-
});
|
|
314
|
-
|
|
315
|
-
// DATA INTEGRITY TESTS
|
|
316
|
-
test("should not modify original documentation structure", async () => {
|
|
317
|
-
const originalStructure = [...baseDocumentStructure];
|
|
318
|
-
|
|
319
|
-
await deleteDocument({
|
|
320
|
-
documentStructure: baseDocumentStructure,
|
|
321
|
-
path: "/api/rate-limiting",
|
|
322
|
-
});
|
|
323
|
-
|
|
324
|
-
expect(baseDocumentStructure).toEqual(originalStructure);
|
|
325
|
-
});
|
|
326
|
-
|
|
327
|
-
test("should preserve document order after deletion", async () => {
|
|
328
|
-
const result = await deleteDocument({
|
|
329
|
-
documentStructure: baseDocumentStructure,
|
|
330
|
-
path: "/api/auth",
|
|
331
|
-
});
|
|
332
|
-
|
|
333
|
-
// Since /api/auth has children, it should not be deleted
|
|
334
|
-
expect(result.documentStructure).toEqual(baseDocumentStructure);
|
|
335
|
-
|
|
336
|
-
// But if we delete a leaf node, order should be preserved
|
|
337
|
-
const leafResult = await deleteDocument({
|
|
338
|
-
documentStructure: baseDocumentStructure,
|
|
339
|
-
path: "/api/rate-limiting",
|
|
340
|
-
});
|
|
341
|
-
|
|
342
|
-
const expectedStructure = baseDocumentStructure.filter(
|
|
343
|
-
(doc) => doc.path !== "/api/rate-limiting",
|
|
344
|
-
);
|
|
345
|
-
expect(leafResult.documentStructure).toEqual(expectedStructure);
|
|
346
|
-
});
|
|
347
|
-
|
|
348
|
-
test("should handle special characters in paths", async () => {
|
|
349
|
-
const specialStructure = [
|
|
350
|
-
...baseDocumentStructure,
|
|
351
|
-
{
|
|
352
|
-
title: "Special Document",
|
|
353
|
-
description: "Document with special characters",
|
|
354
|
-
path: "/api/special-chars_and.numbers123",
|
|
355
|
-
parentId: "/api",
|
|
356
|
-
sourceIds: ["special.md"],
|
|
357
|
-
},
|
|
358
|
-
];
|
|
359
|
-
|
|
360
|
-
const result = await deleteDocument({
|
|
361
|
-
documentStructure: specialStructure,
|
|
362
|
-
path: "/api/special-chars_and.numbers123",
|
|
363
|
-
});
|
|
364
|
-
|
|
365
|
-
expect(result.documentStructure).toHaveLength(5);
|
|
366
|
-
expect(result.deletedDocument.path).toBe("/api/special-chars_and.numbers123");
|
|
367
|
-
expect(consoleSpy).not.toHaveBeenCalled();
|
|
368
|
-
});
|
|
369
|
-
|
|
370
|
-
// RETURN VALUE TESTS
|
|
371
|
-
test("should return complete deleted document information", async () => {
|
|
372
|
-
const result = await deleteDocument({
|
|
373
|
-
documentStructure: baseDocumentStructure,
|
|
374
|
-
path: "/api/rate-limiting",
|
|
375
|
-
});
|
|
376
|
-
|
|
377
|
-
expect(result.deletedDocument).toEqual({
|
|
378
|
-
title: "Rate Limiting",
|
|
379
|
-
description: "API rate limiting documentation",
|
|
380
|
-
path: "/api/rate-limiting",
|
|
381
|
-
parentId: "/api",
|
|
382
|
-
sourceIds: ["rate-limit.js"],
|
|
383
|
-
});
|
|
384
|
-
|
|
385
|
-
// Verify all properties are present
|
|
386
|
-
expect(result.deletedDocument).toHaveProperty("title");
|
|
387
|
-
expect(result.deletedDocument).toHaveProperty("description");
|
|
388
|
-
expect(result.deletedDocument).toHaveProperty("path");
|
|
389
|
-
expect(result.deletedDocument).toHaveProperty("parentId");
|
|
390
|
-
expect(result.deletedDocument).toHaveProperty("sourceIds");
|
|
391
|
-
});
|
|
392
|
-
|
|
393
|
-
test("should return updated documentation structure without deleted document", async () => {
|
|
394
|
-
const originalLength = baseDocumentStructure.length;
|
|
395
|
-
const result = await deleteDocument({
|
|
396
|
-
documentStructure: baseDocumentStructure,
|
|
397
|
-
path: "/getting-started",
|
|
398
|
-
});
|
|
399
|
-
|
|
400
|
-
expect(result.documentStructure).toHaveLength(originalLength - 1);
|
|
401
|
-
expect(result.documentStructure.every((doc) => doc.path !== "/getting-started")).toBe(true);
|
|
402
|
-
|
|
403
|
-
// Verify all other documents are still present
|
|
404
|
-
const remainingPaths = result.documentStructure.map((doc) => doc.path);
|
|
405
|
-
expect(remainingPaths).toContain("/api");
|
|
406
|
-
expect(remainingPaths).toContain("/api/auth");
|
|
407
|
-
expect(remainingPaths).toContain("/api/rate-limiting");
|
|
408
|
-
expect(remainingPaths).toContain("/api/auth/oauth");
|
|
409
|
-
});
|
|
410
|
-
});
|
|
@@ -1,277 +0,0 @@
|
|
|
1
|
-
import { afterEach, beforeEach, describe, expect, test } from "bun:test";
|
|
2
|
-
import { mkdir, rm, writeFile } from "node:fs/promises";
|
|
3
|
-
import { dirname, join } from "node:path";
|
|
4
|
-
import { fileURLToPath } from "node:url";
|
|
5
|
-
import generateSubStructure from "../../../../agents/generate/document-structure-tools/generate-sub-structure.mjs";
|
|
6
|
-
|
|
7
|
-
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
8
|
-
|
|
9
|
-
describe("generate-sub-structure", () => {
|
|
10
|
-
let testDir;
|
|
11
|
-
|
|
12
|
-
beforeEach(async () => {
|
|
13
|
-
testDir = join(__dirname, "test-generate-sub-structure");
|
|
14
|
-
await mkdir(testDir, { recursive: true });
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
afterEach(async () => {
|
|
18
|
-
try {
|
|
19
|
-
await rm(testDir, { recursive: true, force: true });
|
|
20
|
-
} catch {
|
|
21
|
-
// Ignore cleanup errors
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
describe("generateSubStructure function", () => {
|
|
26
|
-
test("should return empty subStructure when subSourcePaths is empty", async () => {
|
|
27
|
-
const result = await generateSubStructure(
|
|
28
|
-
{
|
|
29
|
-
parentDocument: {
|
|
30
|
-
title: "Test Parent",
|
|
31
|
-
description: "Test Description",
|
|
32
|
-
path: "/test",
|
|
33
|
-
parentId: "parent-1",
|
|
34
|
-
sourceIds: [],
|
|
35
|
-
},
|
|
36
|
-
subSourcePaths: [],
|
|
37
|
-
},
|
|
38
|
-
{},
|
|
39
|
-
);
|
|
40
|
-
|
|
41
|
-
expect(result).toBeDefined();
|
|
42
|
-
expect(result.subStructure).toBeDefined();
|
|
43
|
-
expect(Array.isArray(result.subStructure)).toBe(true);
|
|
44
|
-
expect(result.subStructure.length).toBe(0);
|
|
45
|
-
expect(result.message).toBeUndefined();
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
test("should process single source path with small context", async () => {
|
|
49
|
-
const testFile = join(testDir, "test.js");
|
|
50
|
-
await writeFile(testFile, "// Small test file\nconst x = 1;");
|
|
51
|
-
|
|
52
|
-
const mockContext = {
|
|
53
|
-
agents: {
|
|
54
|
-
generateStructureWithoutTools: "mock-agent-without-tools",
|
|
55
|
-
},
|
|
56
|
-
invoke: async (agent, params) => {
|
|
57
|
-
expect(agent).toBe("mock-agent-without-tools");
|
|
58
|
-
expect(params.isSubStructure).toBe(true);
|
|
59
|
-
expect(params.parentDocument).toBeDefined();
|
|
60
|
-
expect(params.datasources).toBeDefined();
|
|
61
|
-
expect(params.allFilesPaths).toBeDefined();
|
|
62
|
-
expect(params.isLargeContext).toBe(false);
|
|
63
|
-
expect(params.files).toBeDefined();
|
|
64
|
-
expect(params.totalTokens).toBeGreaterThan(0);
|
|
65
|
-
|
|
66
|
-
return {
|
|
67
|
-
documentStructure: [
|
|
68
|
-
{
|
|
69
|
-
title: "Test Document",
|
|
70
|
-
path: "/test-doc",
|
|
71
|
-
description: "Generated from test file",
|
|
72
|
-
},
|
|
73
|
-
],
|
|
74
|
-
};
|
|
75
|
-
},
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
const result = await generateSubStructure(
|
|
79
|
-
{
|
|
80
|
-
parentDocument: {
|
|
81
|
-
title: "Parent",
|
|
82
|
-
path: "/parent",
|
|
83
|
-
description: "Parent doc",
|
|
84
|
-
},
|
|
85
|
-
subSourcePaths: [{ path: testFile, reason: "Test file" }],
|
|
86
|
-
},
|
|
87
|
-
{ context: mockContext },
|
|
88
|
-
);
|
|
89
|
-
|
|
90
|
-
expect(result).toBeDefined();
|
|
91
|
-
expect(result.subStructure).toBeDefined();
|
|
92
|
-
expect(Array.isArray(result.subStructure)).toBe(true);
|
|
93
|
-
expect(result.subStructure.length).toBe(1);
|
|
94
|
-
expect(result.message).toContain("Generated a sub structure");
|
|
95
|
-
expect(result.message).toContain("/parent");
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
test("should process multiple source paths", async () => {
|
|
99
|
-
const testFile1 = join(testDir, "test1.js");
|
|
100
|
-
const testFile2 = join(testDir, "test2.js");
|
|
101
|
-
await writeFile(testFile1, "// Test file 1\nconst a = 1;");
|
|
102
|
-
await writeFile(testFile2, "// Test file 2\nconst b = 2;");
|
|
103
|
-
|
|
104
|
-
const mockContext = {
|
|
105
|
-
agents: {
|
|
106
|
-
generateStructureWithoutTools: "mock-agent-without-tools",
|
|
107
|
-
},
|
|
108
|
-
invoke: async (_agent, params) => {
|
|
109
|
-
expect(params.files.length).toBe(2);
|
|
110
|
-
expect(params.allFilesPaths).toContain("test1.js");
|
|
111
|
-
expect(params.allFilesPaths).toContain("test2.js");
|
|
112
|
-
|
|
113
|
-
return {
|
|
114
|
-
documentStructure: [
|
|
115
|
-
{ title: "Doc 1", path: "/doc1" },
|
|
116
|
-
{ title: "Doc 2", path: "/doc2" },
|
|
117
|
-
],
|
|
118
|
-
};
|
|
119
|
-
},
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
const result = await generateSubStructure(
|
|
123
|
-
{
|
|
124
|
-
parentDocument: { title: "Parent", path: "/parent" },
|
|
125
|
-
subSourcePaths: [
|
|
126
|
-
{ path: testFile1, reason: "First test" },
|
|
127
|
-
{ path: testFile2, reason: "Second test" },
|
|
128
|
-
],
|
|
129
|
-
},
|
|
130
|
-
{ context: mockContext },
|
|
131
|
-
);
|
|
132
|
-
|
|
133
|
-
expect(result.subStructure.length).toBe(2);
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
test("should use generateStructure agent for large context", async () => {
|
|
137
|
-
const largeContent = `// Large file\n${"const x = 1;\n".repeat(150000)}`;
|
|
138
|
-
const testFile = join(testDir, "large.js");
|
|
139
|
-
await writeFile(testFile, largeContent);
|
|
140
|
-
|
|
141
|
-
const mockContext = {
|
|
142
|
-
agents: {
|
|
143
|
-
generateStructure: "mock-agent-with-tools",
|
|
144
|
-
generateStructureWithoutTools: "mock-agent-without-tools",
|
|
145
|
-
},
|
|
146
|
-
invoke: async (agent, params) => {
|
|
147
|
-
expect(agent).toBe("mock-agent-with-tools");
|
|
148
|
-
expect(params.isLargeContext).toBe(true);
|
|
149
|
-
|
|
150
|
-
return {
|
|
151
|
-
documentStructure: [{ title: "Large Doc", path: "/large" }],
|
|
152
|
-
};
|
|
153
|
-
},
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
const result = await generateSubStructure(
|
|
157
|
-
{
|
|
158
|
-
parentDocument: { title: "Parent", path: "/parent" },
|
|
159
|
-
subSourcePaths: [{ path: testFile, reason: "Large file" }],
|
|
160
|
-
},
|
|
161
|
-
{ context: mockContext },
|
|
162
|
-
);
|
|
163
|
-
|
|
164
|
-
expect(result.subStructure).toBeDefined();
|
|
165
|
-
expect(result.subStructure.length).toBe(1);
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
test("should handle custom include and exclude patterns", async () => {
|
|
169
|
-
const srcDir = join(testDir, "src");
|
|
170
|
-
await mkdir(srcDir, { recursive: true });
|
|
171
|
-
await writeFile(join(srcDir, "index.js"), "// index");
|
|
172
|
-
await writeFile(join(srcDir, "test.spec.js"), "// test");
|
|
173
|
-
await writeFile(join(srcDir, "utils.ts"), "// utils");
|
|
174
|
-
|
|
175
|
-
const mockContext = {
|
|
176
|
-
agents: {
|
|
177
|
-
generateStructureWithoutTools: "mock-agent",
|
|
178
|
-
},
|
|
179
|
-
invoke: async (_agent, params) => {
|
|
180
|
-
const hasTestFile = params.files.some((f) => f.includes("test.spec.js"));
|
|
181
|
-
expect(hasTestFile).toBe(false);
|
|
182
|
-
|
|
183
|
-
return { documentStructure: [] };
|
|
184
|
-
},
|
|
185
|
-
};
|
|
186
|
-
|
|
187
|
-
await generateSubStructure(
|
|
188
|
-
{
|
|
189
|
-
parentDocument: { title: "Parent", path: "/parent" },
|
|
190
|
-
subSourcePaths: [{ path: testDir, reason: "Test directory" }],
|
|
191
|
-
includePatterns: ["**/*.js", "**/*.ts"],
|
|
192
|
-
excludePatterns: ["**/*.spec.js"],
|
|
193
|
-
},
|
|
194
|
-
{ context: mockContext },
|
|
195
|
-
);
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
test("should deduplicate files in result", async () => {
|
|
199
|
-
const testFile = join(testDir, "test.js");
|
|
200
|
-
await writeFile(testFile, "// test");
|
|
201
|
-
|
|
202
|
-
const mockContext = {
|
|
203
|
-
agents: {
|
|
204
|
-
generateStructureWithoutTools: "mock-agent",
|
|
205
|
-
},
|
|
206
|
-
invoke: async (_agent, params) => {
|
|
207
|
-
const uniqueFiles = new Set(params.files);
|
|
208
|
-
expect(uniqueFiles.size).toBe(params.files.length);
|
|
209
|
-
|
|
210
|
-
return { documentStructure: [] };
|
|
211
|
-
},
|
|
212
|
-
};
|
|
213
|
-
|
|
214
|
-
await generateSubStructure(
|
|
215
|
-
{
|
|
216
|
-
parentDocument: { title: "Parent", path: "/parent" },
|
|
217
|
-
subSourcePaths: [
|
|
218
|
-
{ path: testFile, reason: "First" },
|
|
219
|
-
{ path: testFile, reason: "Second" },
|
|
220
|
-
],
|
|
221
|
-
},
|
|
222
|
-
{ context: mockContext },
|
|
223
|
-
);
|
|
224
|
-
});
|
|
225
|
-
|
|
226
|
-
test("should pass extra parameters to agent", async () => {
|
|
227
|
-
const testFile = join(testDir, "test.js");
|
|
228
|
-
await writeFile(testFile, "// test");
|
|
229
|
-
|
|
230
|
-
const mockContext = {
|
|
231
|
-
agents: {
|
|
232
|
-
generateStructureWithoutTools: "mock-agent",
|
|
233
|
-
},
|
|
234
|
-
invoke: async (_agent, params) => {
|
|
235
|
-
expect(params.extraParam1).toBe("value1");
|
|
236
|
-
expect(params.extraParam2).toBe("value2");
|
|
237
|
-
|
|
238
|
-
return { documentStructure: [] };
|
|
239
|
-
},
|
|
240
|
-
};
|
|
241
|
-
|
|
242
|
-
await generateSubStructure(
|
|
243
|
-
{
|
|
244
|
-
parentDocument: { title: "Parent", path: "/parent" },
|
|
245
|
-
subSourcePaths: [{ path: testFile, reason: "Test" }],
|
|
246
|
-
extraParam1: "value1",
|
|
247
|
-
extraParam2: "value2",
|
|
248
|
-
},
|
|
249
|
-
{ context: mockContext },
|
|
250
|
-
);
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
test("should handle empty documentStructure from agent", async () => {
|
|
254
|
-
const testFile = join(testDir, "test.js");
|
|
255
|
-
await writeFile(testFile, "// test");
|
|
256
|
-
|
|
257
|
-
const mockContext = {
|
|
258
|
-
agents: {
|
|
259
|
-
generateStructureWithoutTools: "mock-agent",
|
|
260
|
-
},
|
|
261
|
-
invoke: async () => {
|
|
262
|
-
return {};
|
|
263
|
-
},
|
|
264
|
-
};
|
|
265
|
-
|
|
266
|
-
const result = await generateSubStructure(
|
|
267
|
-
{
|
|
268
|
-
parentDocument: { title: "Parent", path: "/parent" },
|
|
269
|
-
subSourcePaths: [{ path: testFile, reason: "Test" }],
|
|
270
|
-
},
|
|
271
|
-
{ context: mockContext },
|
|
272
|
-
);
|
|
273
|
-
|
|
274
|
-
expect(result.subStructure).toEqual([]);
|
|
275
|
-
});
|
|
276
|
-
});
|
|
277
|
-
});
|