@kirrosh/zond 0.14.0 → 0.16.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/README.md +1 -1
  2. package/package.json +4 -3
  3. package/src/cli/commands/ci-init.ts +12 -1
  4. package/src/cli/commands/coverage.ts +21 -1
  5. package/src/cli/commands/db.ts +121 -0
  6. package/src/cli/commands/describe.ts +60 -0
  7. package/src/cli/commands/generate.ts +127 -0
  8. package/src/cli/commands/guide.ts +127 -0
  9. package/src/cli/commands/init.ts +57 -0
  10. package/src/cli/commands/request.ts +57 -0
  11. package/src/cli/commands/run.ts +53 -10
  12. package/src/cli/commands/serve.ts +62 -3
  13. package/src/cli/commands/validate.ts +18 -2
  14. package/src/cli/index.ts +204 -7
  15. package/src/cli/json-envelope.ts +19 -0
  16. package/src/core/diagnostics/db-analysis.ts +351 -0
  17. package/src/core/diagnostics/failure-hints.ts +1 -0
  18. package/src/core/generator/data-factory.ts +19 -8
  19. package/src/core/generator/describe.ts +250 -0
  20. package/src/core/generator/guide-builder.ts +20 -0
  21. package/src/core/generator/suite-generator.ts +133 -20
  22. package/src/core/runner/executor.ts +1 -0
  23. package/src/core/runner/send-request.ts +94 -0
  24. package/src/core/runner/types.ts +1 -0
  25. package/src/db/queries.ts +4 -2
  26. package/src/db/schema.ts +11 -3
  27. package/src/mcp/descriptions.ts +0 -24
  28. package/src/mcp/server.ts +1 -8
  29. package/src/mcp/tools/describe-endpoint.ts +3 -218
  30. package/src/mcp/tools/query-db.ts +6 -222
  31. package/src/mcp/tools/run-tests.ts +1 -0
  32. package/src/mcp/tools/send-request.ts +15 -61
  33. package/src/web/views/suites-tab.ts +1 -1
  34. package/src/mcp/tools/generate-and-save.ts +0 -202
  35. package/src/mcp/tools/save-test-suite.ts +0 -218
  36. package/src/mcp/tools/set-work-dir.ts +0 -35
@@ -1,218 +0,0 @@
1
- import { z } from "zod";
2
- import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
3
- import { validateSuite } from "../../core/parser/schema.ts";
4
- import { join, dirname } from "node:path";
5
- import { existsSync, mkdirSync } from "node:fs";
6
- import YAML from "yaml";
7
- import { TOOL_DESCRIPTIONS } from "../descriptions.js";
8
-
9
- export interface SaveResult {
10
- saved: boolean;
11
- filePath?: string;
12
- suite?: { name: unknown; tests: number; base_url: unknown };
13
- hint?: string;
14
- coverage?: Record<string, unknown>;
15
- error?: string;
16
- detected?: string[];
17
- }
18
-
19
- export async function validateAndSave(
20
- filePath: string,
21
- content: string,
22
- overwrite: boolean | undefined,
23
- dbPath?: string,
24
- ): Promise<{ result: SaveResult; isError: boolean }> {
25
- // Parse YAML
26
- let parsed: unknown;
27
- try {
28
- parsed = YAML.parse(content);
29
- } catch (err) {
30
- return {
31
- result: {
32
- saved: false,
33
- error: `YAML parse error: ${(err as Error).message}`,
34
- hint: "Check YAML syntax — indentation, colons, and quoting",
35
- },
36
- isError: true,
37
- };
38
- }
39
-
40
- // Validate against test suite schema
41
- try {
42
- validateSuite(parsed);
43
- } catch (err) {
44
- const message = (err as Error).message;
45
- let hint = "Check the test suite structure matches the expected format";
46
- if (message.includes("status")) {
47
- hint = "Status codes must be numbers, not strings (e.g. status: 200, not status: \"200\")";
48
- } else if (message.includes("exists")) {
49
- hint = "exists must be boolean true/false, not string \"true\"/\"false\"";
50
- } else if (message.includes("tests")) {
51
- hint = "Suite must have a 'tests' array with at least one test step";
52
- }
53
- return {
54
- result: { saved: false, error: `Validation: ${message}`, hint },
55
- isError: true,
56
- };
57
- }
58
-
59
- // Detect hardcoded credentials — long opaque strings in auth headers
60
- const credentialPattern = /Authorization\s*:\s*["']?(Basic|Bearer)\s+([A-Za-z0-9+/=_\-]{20,})["']?/g;
61
- const credMatches = [...content.matchAll(credentialPattern)];
62
- const suspiciousCredentials = credMatches.filter(m => {
63
- const value = m[2]!;
64
- return !value.startsWith("{{") && !value.endsWith("}}");
65
- });
66
- if (suspiciousCredentials.length > 0) {
67
- return {
68
- result: {
69
- saved: false,
70
- error: "Hardcoded credentials detected in Authorization header(s)",
71
- hint: "Never put literal API keys or tokens in YAML files. Store them in the .env.yaml file in the API directory and reference as {{api_key}} in headers.",
72
- detected: suspiciousCredentials.map(m => `${m[1]} <redacted>`),
73
- },
74
- isError: true,
75
- };
76
- }
77
-
78
- // Resolve path
79
- const resolvedPath = filePath.startsWith("/") || /^[a-zA-Z]:/.test(filePath)
80
- ? filePath
81
- : join(process.cwd(), filePath);
82
-
83
- // Check existing file
84
- if (!overwrite && existsSync(resolvedPath)) {
85
- return {
86
- result: {
87
- saved: false,
88
- error: `File already exists: ${resolvedPath}`,
89
- hint: "Use overwrite: true to replace the existing file",
90
- },
91
- isError: true,
92
- };
93
- }
94
-
95
- // Create directories
96
- const dir = dirname(resolvedPath);
97
- if (!existsSync(dir)) {
98
- mkdirSync(dir, { recursive: true });
99
- }
100
-
101
- // Write original YAML content (preserve formatting/comments)
102
- await Bun.write(resolvedPath, content);
103
-
104
- // Extract summary info
105
- const suite = parsed as Record<string, unknown>;
106
- const tests = (suite.tests as unknown[]) ?? [];
107
-
108
- const result: SaveResult = {
109
- saved: true,
110
- filePath: resolvedPath,
111
- suite: {
112
- name: suite.name,
113
- tests: tests.length,
114
- base_url: suite.base_url ?? null,
115
- },
116
- hint: "After tests are ready, ask the user if they want to set up CI/CD with ci_init to run tests automatically on push.",
117
- };
118
-
119
- // Attempt to compute coverage hint
120
- try {
121
- const testDir = dirname(resolvedPath);
122
- const { findCollectionByTestPath } = await import("../../db/queries.ts");
123
- const { getDb } = await import("../../db/schema.ts");
124
- getDb(dbPath);
125
- const collection = findCollectionByTestPath(testDir);
126
- if (collection?.openapi_spec) {
127
- const { readOpenApiSpec, extractEndpoints } = await import("../../core/generator/openapi-reader.ts");
128
- const { scanCoveredEndpoints, filterUncoveredEndpoints } = await import("../../core/generator/coverage-scanner.ts");
129
-
130
- const doc = await readOpenApiSpec(collection.openapi_spec);
131
- const allEndpoints = extractEndpoints(doc);
132
- const covered = await scanCoveredEndpoints(testDir);
133
- const uncovered = filterUncoveredEndpoints(allEndpoints, covered);
134
-
135
- const total = allEndpoints.length;
136
- const coveredCount = total - uncovered.length;
137
- const percentage = total > 0 ? Math.round((coveredCount / total) * 100) : 0;
138
-
139
- const coverage: Record<string, unknown> = { percentage, covered: coveredCount, total, uncoveredCount: uncovered.length };
140
- if (percentage < 80 && uncovered.length > 0) {
141
- coverage.suggestion = `Use generate_and_save with testsDir to cover ${uncovered.length} remaining endpoint${uncovered.length > 1 ? "s" : ""}`;
142
- }
143
- result.coverage = coverage;
144
- }
145
- } catch { /* silently skip coverage if unavailable */ }
146
-
147
- return { result, isError: false };
148
- }
149
-
150
- export function registerSaveTestSuiteTool(server: McpServer, dbPath?: string) {
151
- server.registerTool("save_test_suite", {
152
- description: TOOL_DESCRIPTIONS.save_test_suite,
153
- inputSchema: {
154
- filePath: z.string().describe("Path for saving the YAML test file (e.g. apis/petstore/tests/pets-crud.yaml)"),
155
- content: z.string().describe("YAML content of the test suite"),
156
- overwrite: z.optional(z.boolean()).describe("Overwrite existing file (default: false)"),
157
- },
158
- }, async ({ filePath, content, overwrite }) => {
159
- try {
160
- const { result, isError } = await validateAndSave(filePath, content, overwrite, dbPath);
161
- return {
162
- content: [{ type: "text" as const, text: JSON.stringify(result, null, 2) }],
163
- ...(isError ? { isError: true } : {}),
164
- };
165
- } catch (err) {
166
- return {
167
- content: [{ type: "text" as const, text: JSON.stringify({
168
- saved: false,
169
- error: (err as Error).message,
170
- }, null, 2) }],
171
- isError: true,
172
- };
173
- }
174
- });
175
- }
176
-
177
- export function registerSaveTestSuitesTool(server: McpServer, dbPath?: string) {
178
- server.registerTool("save_test_suites", {
179
- description: TOOL_DESCRIPTIONS.save_test_suites,
180
- inputSchema: {
181
- files: z.array(z.object({
182
- filePath: z.string().describe("Path for saving the YAML test file"),
183
- content: z.string().describe("YAML content of the test suite"),
184
- })).describe("Array of files to save"),
185
- overwrite: z.optional(z.boolean()).describe("Overwrite existing files (default: false)"),
186
- },
187
- }, async ({ files, overwrite }) => {
188
- try {
189
- const results: Array<SaveResult & { filePath: string; inputPath: string }> = [];
190
- let hasErrors = false;
191
-
192
- for (const file of files) {
193
- const { result, isError } = await validateAndSave(file.filePath, file.content, overwrite, dbPath);
194
- results.push({ ...result, inputPath: file.filePath, filePath: result.filePath ?? file.filePath });
195
- if (isError) hasErrors = true;
196
- }
197
-
198
- const summary = {
199
- total: files.length,
200
- saved: results.filter(r => r.saved).length,
201
- failed: results.filter(r => !r.saved).length,
202
- files: results,
203
- };
204
-
205
- return {
206
- content: [{ type: "text" as const, text: JSON.stringify(summary, null, 2) }],
207
- ...(hasErrors ? { isError: true } : {}),
208
- };
209
- } catch (err) {
210
- return {
211
- content: [{ type: "text" as const, text: JSON.stringify({
212
- error: (err as Error).message,
213
- }, null, 2) }],
214
- isError: true,
215
- };
216
- }
217
- });
218
- }
@@ -1,35 +0,0 @@
1
- import { z } from "zod";
2
- import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
3
- import { resolve, join } from "node:path";
4
- import { existsSync } from "node:fs";
5
- import { resetDb } from "../../db/schema.ts";
6
- import { TOOL_DESCRIPTIONS } from "../descriptions.js";
7
-
8
- export function registerSetWorkDirTool(server: McpServer) {
9
- server.registerTool("set_work_dir", {
10
- description: TOOL_DESCRIPTIONS.set_work_dir,
11
- inputSchema: {
12
- workDir: z.string().describe(
13
- "Absolute path to project root (e.g. /home/user/myproject or C:/Users/user/myproject)"
14
- ),
15
- },
16
- }, async ({ workDir }) => {
17
- const resolved = resolve(workDir);
18
- if (!existsSync(resolved)) {
19
- return {
20
- content: [{ type: "text" as const, text: JSON.stringify({ error: `Directory not found: ${resolved}` }, null, 2) }],
21
- isError: true,
22
- };
23
- }
24
- process.chdir(resolved);
25
- resetDb();
26
- const dbPath = join(resolved, "zond.db");
27
- return {
28
- content: [{ type: "text" as const, text: JSON.stringify({
29
- workDir: resolved,
30
- zond_db: dbPath,
31
- hint: "Working directory set. All relative paths and zond.db will now resolve from this directory.",
32
- }, null, 2) }],
33
- };
34
- });
35
- }