@ilya-lesikov/pi-pi 0.1.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.
- package/3p/pi-ask-user/index.ts +1835 -0
- package/3p/pi-ask-user/package.json +50 -0
- package/3p/pi-ask-user/single-select-layout.ts +203 -0
- package/3p/pi-lsp/extensions/lsp/client.ts +542 -0
- package/3p/pi-lsp/extensions/lsp/config.ts +135 -0
- package/3p/pi-lsp/extensions/lsp/effects/command.ts +42 -0
- package/3p/pi-lsp/extensions/lsp/effects/filesystem.ts +50 -0
- package/3p/pi-lsp/extensions/lsp/effects/runtime.ts +21 -0
- package/3p/pi-lsp/extensions/lsp/errors.ts +113 -0
- package/3p/pi-lsp/extensions/lsp/formatting.ts +315 -0
- package/3p/pi-lsp/extensions/lsp/index.ts +231 -0
- package/3p/pi-lsp/extensions/lsp/protocol.ts +209 -0
- package/3p/pi-lsp/extensions/lsp/retry.ts +39 -0
- package/3p/pi-lsp/extensions/lsp/tools/programs.ts +293 -0
- package/3p/pi-lsp/extensions/lsp/tools.ts +89 -0
- package/3p/pi-lsp/extensions/lsp/types.ts +243 -0
- package/3p/pi-lsp/package.json +54 -0
- package/3p/pi-plannotator/AGENTS.md +583 -0
- package/3p/pi-plannotator/apps/pi-extension/README.md +228 -0
- package/3p/pi-plannotator/apps/pi-extension/assistant-message.ts +128 -0
- package/3p/pi-plannotator/apps/pi-extension/config.test.ts +166 -0
- package/3p/pi-plannotator/apps/pi-extension/config.ts +318 -0
- package/3p/pi-plannotator/apps/pi-extension/current-pi-session.ts +147 -0
- package/3p/pi-plannotator/apps/pi-extension/index.ts +1279 -0
- package/3p/pi-plannotator/apps/pi-extension/package.json +56 -0
- package/3p/pi-plannotator/apps/pi-extension/plannotator-browser.test.ts +13 -0
- package/3p/pi-plannotator/apps/pi-extension/plannotator-browser.ts +616 -0
- package/3p/pi-plannotator/apps/pi-extension/plannotator-events.ts +342 -0
- package/3p/pi-plannotator/apps/pi-extension/plannotator.json +12 -0
- package/3p/pi-plannotator/apps/pi-extension/server/agent-jobs.ts +515 -0
- package/3p/pi-plannotator/apps/pi-extension/server/ai-runtime.ts +169 -0
- package/3p/pi-plannotator/apps/pi-extension/server/annotations.ts +85 -0
- package/3p/pi-plannotator/apps/pi-extension/server/external-annotations.ts +189 -0
- package/3p/pi-plannotator/apps/pi-extension/server/handlers.ts +210 -0
- package/3p/pi-plannotator/apps/pi-extension/server/helpers.ts +78 -0
- package/3p/pi-plannotator/apps/pi-extension/server/ide.ts +46 -0
- package/3p/pi-plannotator/apps/pi-extension/server/integrations.ts +195 -0
- package/3p/pi-plannotator/apps/pi-extension/server/network.test.ts +158 -0
- package/3p/pi-plannotator/apps/pi-extension/server/network.ts +268 -0
- package/3p/pi-plannotator/apps/pi-extension/server/pr.ts +126 -0
- package/3p/pi-plannotator/apps/pi-extension/server/project.ts +64 -0
- package/3p/pi-plannotator/apps/pi-extension/server/reference.ts +362 -0
- package/3p/pi-plannotator/apps/pi-extension/server/serverAnnotate.ts +199 -0
- package/3p/pi-plannotator/apps/pi-extension/server/serverPlan.ts +505 -0
- package/3p/pi-plannotator/apps/pi-extension/server/serverReview.ts +1229 -0
- package/3p/pi-plannotator/apps/pi-extension/server/vcs.ts +121 -0
- package/3p/pi-plannotator/apps/pi-extension/server.test.ts +966 -0
- package/3p/pi-plannotator/apps/pi-extension/server.ts +44 -0
- package/3p/pi-plannotator/apps/pi-extension/tool-scope.test.ts +88 -0
- package/3p/pi-plannotator/apps/pi-extension/tool-scope.ts +39 -0
- package/3p/pi-plannotator/apps/pi-extension/tsconfig.json +16 -0
- package/3p/pi-plannotator/apps/pi-extension/vendor.sh +48 -0
- package/3p/pi-plannotator/package.json +53 -0
- package/3p/pi-plannotator/packages/ai/ai.test.ts +1407 -0
- package/3p/pi-plannotator/packages/ai/base-session.ts +94 -0
- package/3p/pi-plannotator/packages/ai/context.ts +250 -0
- package/3p/pi-plannotator/packages/ai/endpoints.ts +326 -0
- package/3p/pi-plannotator/packages/ai/index.ts +105 -0
- package/3p/pi-plannotator/packages/ai/package.json +21 -0
- package/3p/pi-plannotator/packages/ai/provider.ts +103 -0
- package/3p/pi-plannotator/packages/ai/providers/claude-agent-sdk.ts +447 -0
- package/3p/pi-plannotator/packages/ai/providers/codex-sdk.ts +430 -0
- package/3p/pi-plannotator/packages/ai/providers/command-path.ts +115 -0
- package/3p/pi-plannotator/packages/ai/providers/opencode-sdk.ts +546 -0
- package/3p/pi-plannotator/packages/ai/providers/pi-events.ts +110 -0
- package/3p/pi-plannotator/packages/ai/providers/pi-sdk-node.ts +425 -0
- package/3p/pi-plannotator/packages/ai/providers/pi-sdk.ts +469 -0
- package/3p/pi-plannotator/packages/ai/session-manager.ts +195 -0
- package/3p/pi-plannotator/packages/ai/tsconfig.json +15 -0
- package/3p/pi-plannotator/packages/ai/types.ts +379 -0
- package/3p/pi-plannotator/packages/server/agent-jobs.ts +538 -0
- package/3p/pi-plannotator/packages/server/agent-review-message.test.ts +135 -0
- package/3p/pi-plannotator/packages/server/agent-review-message.ts +243 -0
- package/3p/pi-plannotator/packages/server/ai-runtime.ts +108 -0
- package/3p/pi-plannotator/packages/server/annotate.ts +401 -0
- package/3p/pi-plannotator/packages/server/browser.test.ts +87 -0
- package/3p/pi-plannotator/packages/server/browser.ts +245 -0
- package/3p/pi-plannotator/packages/server/claude-review.ts +352 -0
- package/3p/pi-plannotator/packages/server/code-nav.ts +73 -0
- package/3p/pi-plannotator/packages/server/codex-review-schema.json +41 -0
- package/3p/pi-plannotator/packages/server/codex-review.ts +330 -0
- package/3p/pi-plannotator/packages/server/config.ts +8 -0
- package/3p/pi-plannotator/packages/server/draft.ts +1 -0
- package/3p/pi-plannotator/packages/server/editor-annotations.ts +76 -0
- package/3p/pi-plannotator/packages/server/external-annotations.test.ts +18 -0
- package/3p/pi-plannotator/packages/server/external-annotations.ts +207 -0
- package/3p/pi-plannotator/packages/server/git.ts +141 -0
- package/3p/pi-plannotator/packages/server/goal-setup.test.ts +55 -0
- package/3p/pi-plannotator/packages/server/goal-setup.ts +248 -0
- package/3p/pi-plannotator/packages/server/ide.ts +43 -0
- package/3p/pi-plannotator/packages/server/image.test.ts +63 -0
- package/3p/pi-plannotator/packages/server/image.ts +66 -0
- package/3p/pi-plannotator/packages/server/index.ts +648 -0
- package/3p/pi-plannotator/packages/server/integrations.test.ts +172 -0
- package/3p/pi-plannotator/packages/server/integrations.ts +214 -0
- package/3p/pi-plannotator/packages/server/jj.test.ts +69 -0
- package/3p/pi-plannotator/packages/server/jj.ts +86 -0
- package/3p/pi-plannotator/packages/server/p4.ts +417 -0
- package/3p/pi-plannotator/packages/server/package.json +40 -0
- package/3p/pi-plannotator/packages/server/path-utils.ts +18 -0
- package/3p/pi-plannotator/packages/server/pr.ts +146 -0
- package/3p/pi-plannotator/packages/server/project.test.ts +115 -0
- package/3p/pi-plannotator/packages/server/project.ts +45 -0
- package/3p/pi-plannotator/packages/server/reference-handlers.ts +404 -0
- package/3p/pi-plannotator/packages/server/remote.test.ts +150 -0
- package/3p/pi-plannotator/packages/server/remote.ts +74 -0
- package/3p/pi-plannotator/packages/server/repo.ts +80 -0
- package/3p/pi-plannotator/packages/server/resolve-file.test.ts +310 -0
- package/3p/pi-plannotator/packages/server/review-workspace.test.ts +1032 -0
- package/3p/pi-plannotator/packages/server/review-workspace.ts +48 -0
- package/3p/pi-plannotator/packages/server/review.ts +1318 -0
- package/3p/pi-plannotator/packages/server/sessions.ts +111 -0
- package/3p/pi-plannotator/packages/server/share-url.ts +53 -0
- package/3p/pi-plannotator/packages/server/shared-handlers.test.ts +43 -0
- package/3p/pi-plannotator/packages/server/shared-handlers.ts +177 -0
- package/3p/pi-plannotator/packages/server/storage.test.ts +176 -0
- package/3p/pi-plannotator/packages/server/storage.ts +17 -0
- package/3p/pi-plannotator/packages/server/tour/tour-review.test.ts +146 -0
- package/3p/pi-plannotator/packages/server/tour/tour-review.ts +604 -0
- package/3p/pi-plannotator/packages/server/tsconfig.json +15 -0
- package/3p/pi-plannotator/packages/server/vcs.test.ts +48 -0
- package/3p/pi-plannotator/packages/server/vcs.ts +80 -0
- package/3p/pi-plannotator/packages/shared/agent-jobs.ts +132 -0
- package/3p/pi-plannotator/packages/shared/agents.ts +53 -0
- package/3p/pi-plannotator/packages/shared/annotate-args.test.ts +386 -0
- package/3p/pi-plannotator/packages/shared/annotate-args.ts +107 -0
- package/3p/pi-plannotator/packages/shared/at-reference.test.ts +99 -0
- package/3p/pi-plannotator/packages/shared/at-reference.ts +52 -0
- package/3p/pi-plannotator/packages/shared/checklist.ts +52 -0
- package/3p/pi-plannotator/packages/shared/code-file.test.ts +112 -0
- package/3p/pi-plannotator/packages/shared/code-file.ts +41 -0
- package/3p/pi-plannotator/packages/shared/code-nav.test.ts +515 -0
- package/3p/pi-plannotator/packages/shared/code-nav.ts +436 -0
- package/3p/pi-plannotator/packages/shared/compress.ts +51 -0
- package/3p/pi-plannotator/packages/shared/config.ts +262 -0
- package/3p/pi-plannotator/packages/shared/crypto.test.ts +172 -0
- package/3p/pi-plannotator/packages/shared/crypto.ts +97 -0
- package/3p/pi-plannotator/packages/shared/data-dir.ts +42 -0
- package/3p/pi-plannotator/packages/shared/diff-paths.test.ts +30 -0
- package/3p/pi-plannotator/packages/shared/diff-paths.ts +137 -0
- package/3p/pi-plannotator/packages/shared/draft.ts +64 -0
- package/3p/pi-plannotator/packages/shared/external-annotation.ts +397 -0
- package/3p/pi-plannotator/packages/shared/extract-code-paths.test.ts +59 -0
- package/3p/pi-plannotator/packages/shared/extract-code-paths.ts +66 -0
- package/3p/pi-plannotator/packages/shared/favicon.ts +5 -0
- package/3p/pi-plannotator/packages/shared/feedback-templates.test.ts +65 -0
- package/3p/pi-plannotator/packages/shared/feedback-templates.ts +29 -0
- package/3p/pi-plannotator/packages/shared/goal-setup.test.ts +231 -0
- package/3p/pi-plannotator/packages/shared/goal-setup.ts +336 -0
- package/3p/pi-plannotator/packages/shared/html-to-markdown.test.ts +62 -0
- package/3p/pi-plannotator/packages/shared/html-to-markdown.ts +32 -0
- package/3p/pi-plannotator/packages/shared/improvement-hooks.test.ts +135 -0
- package/3p/pi-plannotator/packages/shared/improvement-hooks.ts +115 -0
- package/3p/pi-plannotator/packages/shared/integrations-common.ts +243 -0
- package/3p/pi-plannotator/packages/shared/jj-core.test.ts +236 -0
- package/3p/pi-plannotator/packages/shared/jj-core.ts +433 -0
- package/3p/pi-plannotator/packages/shared/package.json +55 -0
- package/3p/pi-plannotator/packages/shared/pfm-reminder.test.ts +88 -0
- package/3p/pi-plannotator/packages/shared/pfm-reminder.ts +80 -0
- package/3p/pi-plannotator/packages/shared/pr-github.ts +661 -0
- package/3p/pi-plannotator/packages/shared/pr-gitlab.test.ts +202 -0
- package/3p/pi-plannotator/packages/shared/pr-gitlab.ts +620 -0
- package/3p/pi-plannotator/packages/shared/pr-provider.test.ts +266 -0
- package/3p/pi-plannotator/packages/shared/pr-provider.ts +123 -0
- package/3p/pi-plannotator/packages/shared/pr-stack.test.ts +104 -0
- package/3p/pi-plannotator/packages/shared/pr-stack.ts +194 -0
- package/3p/pi-plannotator/packages/shared/pr-types.ts +326 -0
- package/3p/pi-plannotator/packages/shared/project.ts +71 -0
- package/3p/pi-plannotator/packages/shared/prompts-integration.test.ts +421 -0
- package/3p/pi-plannotator/packages/shared/prompts.test.ts +504 -0
- package/3p/pi-plannotator/packages/shared/prompts.ts +247 -0
- package/3p/pi-plannotator/packages/shared/reference-common.ts +87 -0
- package/3p/pi-plannotator/packages/shared/repo.ts +71 -0
- package/3p/pi-plannotator/packages/shared/resolve-file.test.ts +113 -0
- package/3p/pi-plannotator/packages/shared/resolve-file.ts +509 -0
- package/3p/pi-plannotator/packages/shared/review-args.test.ts +64 -0
- package/3p/pi-plannotator/packages/shared/review-args.ts +85 -0
- package/3p/pi-plannotator/packages/shared/review-core.test.ts +286 -0
- package/3p/pi-plannotator/packages/shared/review-core.ts +895 -0
- package/3p/pi-plannotator/packages/shared/review-workspace-node.ts +230 -0
- package/3p/pi-plannotator/packages/shared/review-workspace.ts +436 -0
- package/3p/pi-plannotator/packages/shared/semantic-diff-types.ts +76 -0
- package/3p/pi-plannotator/packages/shared/semantic-diff.test.ts +322 -0
- package/3p/pi-plannotator/packages/shared/semantic-diff.ts +520 -0
- package/3p/pi-plannotator/packages/shared/storage.ts +378 -0
- package/3p/pi-plannotator/packages/shared/tour.ts +61 -0
- package/3p/pi-plannotator/packages/shared/tsconfig.json +15 -0
- package/3p/pi-plannotator/packages/shared/types.ts +29 -0
- package/3p/pi-plannotator/packages/shared/url-to-markdown.test.ts +177 -0
- package/3p/pi-plannotator/packages/shared/url-to-markdown.ts +351 -0
- package/3p/pi-plannotator/packages/shared/vcs-core.test.ts +332 -0
- package/3p/pi-plannotator/packages/shared/vcs-core.ts +482 -0
- package/3p/pi-plannotator/packages/shared/worktree-pool.test.ts +162 -0
- package/3p/pi-plannotator/packages/shared/worktree-pool.ts +103 -0
- package/3p/pi-plannotator/packages/shared/worktree.ts +119 -0
- package/3p/pi-subagents/package.json +50 -0
- package/3p/pi-subagents/src/agent-manager.ts +413 -0
- package/3p/pi-subagents/src/agent-runner.ts +502 -0
- package/3p/pi-subagents/src/agent-types.ts +248 -0
- package/3p/pi-subagents/src/context.ts +58 -0
- package/3p/pi-subagents/src/cross-extension-rpc.ts +135 -0
- package/3p/pi-subagents/src/custom-agents.ts +137 -0
- package/3p/pi-subagents/src/default-agents.ts +144 -0
- package/3p/pi-subagents/src/env.ts +33 -0
- package/3p/pi-subagents/src/group-join.ts +141 -0
- package/3p/pi-subagents/src/index.ts +1811 -0
- package/3p/pi-subagents/src/invocation-config.ts +40 -0
- package/3p/pi-subagents/src/memory.ts +165 -0
- package/3p/pi-subagents/src/model-resolver.ts +81 -0
- package/3p/pi-subagents/src/output-file.ts +77 -0
- package/3p/pi-subagents/src/prompts.ts +85 -0
- package/3p/pi-subagents/src/skill-loader.ts +79 -0
- package/3p/pi-subagents/src/types.ts +111 -0
- package/3p/pi-subagents/src/ui/agent-widget.ts +496 -0
- package/3p/pi-subagents/src/ui/conversation-viewer.ts +250 -0
- package/3p/pi-subagents/src/worktree.ts +162 -0
- package/3p/pi-tasks/package.json +52 -0
- package/3p/pi-tasks/src/auto-clear.ts +91 -0
- package/3p/pi-tasks/src/index.ts +1150 -0
- package/3p/pi-tasks/src/process-tracker.ts +140 -0
- package/3p/pi-tasks/src/reminder-cadence.ts +90 -0
- package/3p/pi-tasks/src/task-store.ts +324 -0
- package/3p/pi-tasks/src/tasks-config.ts +27 -0
- package/3p/pi-tasks/src/types.ts +40 -0
- package/3p/pi-tasks/src/ui/settings-menu.ts +152 -0
- package/3p/pi-tasks/src/ui/task-widget.ts +296 -0
- package/AGENTS.md +28 -0
- package/LICENSE +201 -0
- package/extensions/orchestrator/agents/brainstorm-reviewer.ts +77 -0
- package/extensions/orchestrator/agents/code-reviewer.ts +89 -0
- package/extensions/orchestrator/agents/explore.ts +33 -0
- package/extensions/orchestrator/agents/librarian.ts +43 -0
- package/extensions/orchestrator/agents/plan-reviewer.ts +75 -0
- package/extensions/orchestrator/agents/planner.ts +61 -0
- package/extensions/orchestrator/agents/registry.ts +156 -0
- package/extensions/orchestrator/agents/task.ts +50 -0
- package/extensions/orchestrator/agents/tool-routing.ts +84 -0
- package/extensions/orchestrator/ast-search.ts +85 -0
- package/extensions/orchestrator/cbm.ts +330 -0
- package/extensions/orchestrator/command-handlers.test.ts +163 -0
- package/extensions/orchestrator/command-handlers.ts +116 -0
- package/extensions/orchestrator/commands.test.ts +81 -0
- package/extensions/orchestrator/commands.ts +75 -0
- package/extensions/orchestrator/config.test.ts +221 -0
- package/extensions/orchestrator/config.ts +230 -0
- package/extensions/orchestrator/context.test.ts +293 -0
- package/extensions/orchestrator/context.ts +206 -0
- package/extensions/orchestrator/event-handlers.test.ts +190 -0
- package/extensions/orchestrator/event-handlers.ts +1416 -0
- package/extensions/orchestrator/exa.ts +104 -0
- package/extensions/orchestrator/flant-infra.ts +486 -0
- package/extensions/orchestrator/index.ts +80 -0
- package/extensions/orchestrator/integration.test.ts +1214 -0
- package/extensions/orchestrator/orchestrator.test.ts +252 -0
- package/extensions/orchestrator/orchestrator.ts +538 -0
- package/extensions/orchestrator/phases/brainstorm.test.ts +15 -0
- package/extensions/orchestrator/phases/brainstorm.ts +273 -0
- package/extensions/orchestrator/phases/implementation.ts +40 -0
- package/extensions/orchestrator/phases/machine.test.ts +293 -0
- package/extensions/orchestrator/phases/machine.ts +209 -0
- package/extensions/orchestrator/phases/planning.ts +255 -0
- package/extensions/orchestrator/phases/review.ts +193 -0
- package/extensions/orchestrator/plannotator.ts +56 -0
- package/extensions/orchestrator/pp-menu.ts +866 -0
- package/extensions/orchestrator/state.test.ts +343 -0
- package/extensions/orchestrator/state.ts +237 -0
- package/extensions/orchestrator/validate-artifacts.test.ts +88 -0
- package/extensions/orchestrator/validate-artifacts.ts +272 -0
- package/extensions/orchestrator/vendor.d.ts +26 -0
- package/package.json +73 -0
- package/scripts/postinstall.sh +18 -0
|
@@ -0,0 +1,515 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import {
|
|
3
|
+
buildRgArgs,
|
|
4
|
+
classifyMatch,
|
|
5
|
+
rankLocations,
|
|
6
|
+
parseRgJsonOutput,
|
|
7
|
+
validateCodeNavRequest,
|
|
8
|
+
extractChangedFiles,
|
|
9
|
+
type CodeNavLocation,
|
|
10
|
+
} from "./code-nav";
|
|
11
|
+
|
|
12
|
+
// ---------------------------------------------------------------------------
|
|
13
|
+
// classifyMatch
|
|
14
|
+
// ---------------------------------------------------------------------------
|
|
15
|
+
|
|
16
|
+
describe("classifyMatch", () => {
|
|
17
|
+
describe("TypeScript/JavaScript", () => {
|
|
18
|
+
const lang = "typescript";
|
|
19
|
+
|
|
20
|
+
test("function declaration", () => {
|
|
21
|
+
expect(classifyMatch("function startServer(", "startServer", lang)).toBe("definition");
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test("async function declaration", () => {
|
|
25
|
+
expect(classifyMatch("export async function startServer(", "startServer", lang)).toBe("definition");
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test("export function", () => {
|
|
29
|
+
expect(classifyMatch("export function handleRequest(", "handleRequest", lang)).toBe("definition");
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test("const assignment", () => {
|
|
33
|
+
expect(classifyMatch("const startServer = async () => {", "startServer", lang)).toBe("definition");
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test("let assignment", () => {
|
|
37
|
+
expect(classifyMatch("let counter = 0;", "counter", lang)).toBe("definition");
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test("class declaration", () => {
|
|
41
|
+
expect(classifyMatch("export class ReviewServer {", "ReviewServer", lang)).toBe("definition");
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test("interface declaration", () => {
|
|
45
|
+
expect(classifyMatch("export interface CodeNavRequest {", "CodeNavRequest", lang)).toBe("definition");
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
test("type declaration", () => {
|
|
49
|
+
expect(classifyMatch("type DiffType = 'unified' | 'split';", "DiffType", lang)).toBe("definition");
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test("enum declaration", () => {
|
|
53
|
+
expect(classifyMatch("enum Status {", "Status", lang)).toBe("definition");
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test("method in class/object", () => {
|
|
57
|
+
expect(classifyMatch(" async handleRequest(", "handleRequest", lang)).toBe("definition");
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
test("plain reference (function call)", () => {
|
|
61
|
+
expect(classifyMatch(" const result = startServer(config);", "startServer", lang)).toBe("reference");
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test("bare indented call is not a definition", () => {
|
|
65
|
+
expect(classifyMatch(" startServer(config);", "startServer", lang)).toBe("reference");
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test("indented call in if/return is not a definition", () => {
|
|
69
|
+
expect(classifyMatch(" return startServer(config);", "startServer", lang)).toBe("reference");
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test("plain reference (import)", () => {
|
|
73
|
+
expect(classifyMatch('import { startServer } from "./server";', "startServer", lang)).toBe("reference");
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test("const with type annotation", () => {
|
|
77
|
+
expect(classifyMatch("const runtime: CodeNavRuntime = {", "runtime", lang)).toBe("definition");
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
describe("Python", () => {
|
|
82
|
+
const lang = "python";
|
|
83
|
+
|
|
84
|
+
test("def function", () => {
|
|
85
|
+
expect(classifyMatch("def handle_request(self, req):", "handle_request", lang)).toBe("definition");
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
test("class declaration", () => {
|
|
89
|
+
expect(classifyMatch("class ReviewServer:", "ReviewServer", lang)).toBe("definition");
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
test("top-level assignment", () => {
|
|
93
|
+
expect(classifyMatch("DEFAULT_PORT = 8080", "DEFAULT_PORT", lang)).toBe("definition");
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
test("plain reference", () => {
|
|
97
|
+
expect(classifyMatch(" server = ReviewServer()", "ReviewServer", lang)).toBe("reference");
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
describe("Go", () => {
|
|
102
|
+
const lang = "go";
|
|
103
|
+
|
|
104
|
+
test("func declaration", () => {
|
|
105
|
+
expect(classifyMatch("func StartServer(config Config) error {", "StartServer", lang)).toBe("definition");
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
test("method declaration", () => {
|
|
109
|
+
expect(classifyMatch("func (s *Server) StartServer() error {", "StartServer", lang)).toBe("definition");
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
test("type declaration", () => {
|
|
113
|
+
expect(classifyMatch("type Config struct {", "Config", lang)).toBe("definition");
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
test("plain reference", () => {
|
|
117
|
+
expect(classifyMatch(" err := StartServer(cfg)", "StartServer", lang)).toBe("reference");
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
describe("Rust", () => {
|
|
122
|
+
const lang = "rust";
|
|
123
|
+
|
|
124
|
+
test("fn declaration", () => {
|
|
125
|
+
expect(classifyMatch("fn start_server() -> Result<()> {", "start_server", lang)).toBe("definition");
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
test("pub fn declaration", () => {
|
|
129
|
+
expect(classifyMatch("pub fn start_server(config: Config) {", "start_server", lang)).toBe("definition");
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
test("struct declaration", () => {
|
|
133
|
+
expect(classifyMatch("pub struct Config {", "Config", lang)).toBe("definition");
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
test("enum declaration", () => {
|
|
137
|
+
expect(classifyMatch("pub enum Status {", "Status", lang)).toBe("definition");
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
test("trait declaration", () => {
|
|
141
|
+
expect(classifyMatch("pub trait Handler {", "Handler", lang)).toBe("definition");
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
test("plain reference", () => {
|
|
145
|
+
expect(classifyMatch(" let server = start_server(config);", "start_server", lang)).toBe("reference");
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
describe("generic fallback", () => {
|
|
150
|
+
test("function keyword (unknown language)", () => {
|
|
151
|
+
expect(classifyMatch("function startServer(", "startServer")).toBe("definition");
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
test("class keyword (unknown language)", () => {
|
|
155
|
+
expect(classifyMatch("class MyClass {", "MyClass")).toBe("definition");
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
test("const keyword (unknown language)", () => {
|
|
159
|
+
expect(classifyMatch("const PORT = 8080;", "PORT")).toBe("definition");
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
test("no definition pattern matches", () => {
|
|
163
|
+
expect(classifyMatch(" startServer(config);", "startServer")).toBe("reference");
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
describe("edge cases", () => {
|
|
168
|
+
test("regex metacharacter in symbol ($)", () => {
|
|
169
|
+
expect(classifyMatch("const $el = document.querySelector('div');", "$el", "typescript")).toBe("definition");
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
test("regex metacharacter in symbol (.)", () => {
|
|
173
|
+
expect(classifyMatch(" obj.method();", "obj.method")).toBe("reference");
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
// ---------------------------------------------------------------------------
|
|
179
|
+
// rankLocations
|
|
180
|
+
// ---------------------------------------------------------------------------
|
|
181
|
+
|
|
182
|
+
describe("rankLocations", () => {
|
|
183
|
+
function loc(overrides: Partial<CodeNavLocation>): CodeNavLocation {
|
|
184
|
+
return {
|
|
185
|
+
kind: "reference",
|
|
186
|
+
confidence: "possible",
|
|
187
|
+
filePath: "src/other.ts",
|
|
188
|
+
line: 1,
|
|
189
|
+
column: 0,
|
|
190
|
+
snippet: "some code",
|
|
191
|
+
...overrides,
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
test("same file ranks first", () => {
|
|
196
|
+
const locations = [
|
|
197
|
+
loc({ filePath: "src/other.ts", line: 10 }),
|
|
198
|
+
loc({ filePath: "src/main.ts", line: 5 }),
|
|
199
|
+
];
|
|
200
|
+
const result = rankLocations(locations, {
|
|
201
|
+
sourceFilePath: "src/main.ts",
|
|
202
|
+
changedFiles: [],
|
|
203
|
+
isTestFile: false,
|
|
204
|
+
});
|
|
205
|
+
expect(result.references[0].filePath).toBe("src/main.ts");
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
test("changed files rank above non-changed", () => {
|
|
209
|
+
const locations = [
|
|
210
|
+
loc({ filePath: "lib/utils.ts" }),
|
|
211
|
+
loc({ filePath: "src/changed.ts" }),
|
|
212
|
+
];
|
|
213
|
+
const result = rankLocations(locations, {
|
|
214
|
+
sourceFilePath: "src/main.ts",
|
|
215
|
+
changedFiles: ["src/changed.ts"],
|
|
216
|
+
isTestFile: false,
|
|
217
|
+
});
|
|
218
|
+
expect(result.references[0].filePath).toBe("src/changed.ts");
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
test("definitions rank above references in same tier", () => {
|
|
222
|
+
const locations = [
|
|
223
|
+
loc({ filePath: "src/a.ts", kind: "reference" }),
|
|
224
|
+
loc({ filePath: "src/a.ts", kind: "definition", confidence: "likely" }),
|
|
225
|
+
];
|
|
226
|
+
const result = rankLocations(locations, {
|
|
227
|
+
sourceFilePath: "src/main.ts",
|
|
228
|
+
changedFiles: [],
|
|
229
|
+
isTestFile: false,
|
|
230
|
+
});
|
|
231
|
+
expect(result.definitions).toHaveLength(1);
|
|
232
|
+
expect(result.references).toHaveLength(1);
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
test("test files demoted when source is not a test", () => {
|
|
236
|
+
const locations = [
|
|
237
|
+
loc({ filePath: "src/__tests__/main.test.ts", kind: "reference" }),
|
|
238
|
+
loc({ filePath: "src/utils.ts", kind: "reference" }),
|
|
239
|
+
];
|
|
240
|
+
const result = rankLocations(locations, {
|
|
241
|
+
sourceFilePath: "src/main.ts",
|
|
242
|
+
changedFiles: [],
|
|
243
|
+
isTestFile: false,
|
|
244
|
+
});
|
|
245
|
+
expect(result.references[0].filePath).toBe("src/utils.ts");
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
test("test files NOT demoted when source is a test", () => {
|
|
249
|
+
const locations = [
|
|
250
|
+
loc({ filePath: "src/__tests__/main.test.ts", kind: "reference" }),
|
|
251
|
+
loc({ filePath: "src/utils.ts", kind: "reference" }),
|
|
252
|
+
];
|
|
253
|
+
const result = rankLocations(locations, {
|
|
254
|
+
sourceFilePath: "src/__tests__/other.test.ts",
|
|
255
|
+
changedFiles: [],
|
|
256
|
+
isTestFile: true,
|
|
257
|
+
});
|
|
258
|
+
expect(result.references[0].filePath).toBe("src/__tests__/main.test.ts");
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
test("caps results", () => {
|
|
262
|
+
const locations = Array.from({ length: 100 }, (_, i) =>
|
|
263
|
+
loc({ filePath: `src/file${i}.ts`, line: i }),
|
|
264
|
+
);
|
|
265
|
+
const result = rankLocations(locations, {
|
|
266
|
+
sourceFilePath: "src/main.ts",
|
|
267
|
+
changedFiles: [],
|
|
268
|
+
isTestFile: false,
|
|
269
|
+
}, 10);
|
|
270
|
+
expect(result.references).toHaveLength(10);
|
|
271
|
+
expect(result.capped).toBe(true);
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
test("not capped when under limit", () => {
|
|
275
|
+
const locations = [loc({}), loc({})];
|
|
276
|
+
const result = rankLocations(locations, {
|
|
277
|
+
sourceFilePath: "src/main.ts",
|
|
278
|
+
changedFiles: [],
|
|
279
|
+
isTestFile: false,
|
|
280
|
+
});
|
|
281
|
+
expect(result.capped).toBe(false);
|
|
282
|
+
});
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
// ---------------------------------------------------------------------------
|
|
286
|
+
// buildRgArgs
|
|
287
|
+
// ---------------------------------------------------------------------------
|
|
288
|
+
|
|
289
|
+
describe("buildRgArgs", () => {
|
|
290
|
+
test("includes --json flag", () => {
|
|
291
|
+
const args = buildRgArgs("mySymbol");
|
|
292
|
+
expect(args).toContain("--json");
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
test("includes --word-regexp", () => {
|
|
296
|
+
const args = buildRgArgs("mySymbol");
|
|
297
|
+
expect(args).toContain("--word-regexp");
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
test("includes glob exclusions for node_modules", () => {
|
|
301
|
+
const args = buildRgArgs("mySymbol");
|
|
302
|
+
const nodeModulesIdx = args.indexOf("!node_modules");
|
|
303
|
+
expect(nodeModulesIdx).toBeGreaterThan(-1);
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
test("escapes regex metacharacters", () => {
|
|
307
|
+
const args = buildRgArgs("$scope");
|
|
308
|
+
const patternIdx = args.indexOf("--") + 1;
|
|
309
|
+
expect(args[patternIdx]).toContain("\\$scope");
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
test("includes max-count", () => {
|
|
313
|
+
const args = buildRgArgs("x");
|
|
314
|
+
const idx = args.indexOf("--max-count");
|
|
315
|
+
expect(idx).toBeGreaterThan(-1);
|
|
316
|
+
expect(args[idx + 1]).toBe("50");
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
test("searches from current directory", () => {
|
|
320
|
+
const args = buildRgArgs("x");
|
|
321
|
+
expect(args[args.length - 1]).toBe(".");
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
test("adds --type filter for known language", () => {
|
|
325
|
+
const args = buildRgArgs("x", "typescript");
|
|
326
|
+
const typeIdx = args.indexOf("--type");
|
|
327
|
+
expect(typeIdx).toBeGreaterThan(-1);
|
|
328
|
+
expect(args[typeIdx + 1]).toBe("ts");
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
test("no --type filter for unknown language", () => {
|
|
332
|
+
const args = buildRgArgs("x", "brainfuck");
|
|
333
|
+
expect(args).not.toContain("--type");
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
test("no --type filter when language is undefined", () => {
|
|
337
|
+
const args = buildRgArgs("x");
|
|
338
|
+
expect(args).not.toContain("--type");
|
|
339
|
+
});
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
// ---------------------------------------------------------------------------
|
|
343
|
+
// parseRgJsonOutput
|
|
344
|
+
// ---------------------------------------------------------------------------
|
|
345
|
+
|
|
346
|
+
describe("parseRgJsonOutput", () => {
|
|
347
|
+
test("parses match lines", () => {
|
|
348
|
+
const lines = [
|
|
349
|
+
JSON.stringify({
|
|
350
|
+
type: "match",
|
|
351
|
+
data: {
|
|
352
|
+
path: { text: "src/server.ts" },
|
|
353
|
+
lines: { text: "export function startServer() {\n" },
|
|
354
|
+
line_number: 42,
|
|
355
|
+
submatches: [{ start: 16, end: 27, match: { text: "startServer" } }],
|
|
356
|
+
},
|
|
357
|
+
}),
|
|
358
|
+
JSON.stringify({ type: "summary", data: {} }),
|
|
359
|
+
].join("\n");
|
|
360
|
+
|
|
361
|
+
const result = parseRgJsonOutput(lines, "startServer", "typescript");
|
|
362
|
+
expect(result).toHaveLength(1);
|
|
363
|
+
expect(result[0].filePath).toBe("src/server.ts");
|
|
364
|
+
expect(result[0].line).toBe(42);
|
|
365
|
+
expect(result[0].column).toBe(16);
|
|
366
|
+
expect(result[0].kind).toBe("definition");
|
|
367
|
+
expect(result[0].confidence).toBe("likely");
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
test("classifies references correctly", () => {
|
|
371
|
+
const lines = JSON.stringify({
|
|
372
|
+
type: "match",
|
|
373
|
+
data: {
|
|
374
|
+
path: { text: "src/index.ts" },
|
|
375
|
+
lines: { text: " const s = startServer();\n" },
|
|
376
|
+
line_number: 10,
|
|
377
|
+
submatches: [{ start: 14, end: 25, match: { text: "startServer" } }],
|
|
378
|
+
},
|
|
379
|
+
});
|
|
380
|
+
|
|
381
|
+
const result = parseRgJsonOutput(lines, "startServer", "typescript");
|
|
382
|
+
expect(result[0].kind).toBe("reference");
|
|
383
|
+
expect(result[0].confidence).toBe("possible");
|
|
384
|
+
});
|
|
385
|
+
|
|
386
|
+
test("skips non-JSON lines", () => {
|
|
387
|
+
const result = parseRgJsonOutput("not json\n\n", "x");
|
|
388
|
+
expect(result).toHaveLength(0);
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
test("strips leading ./ from file paths", () => {
|
|
392
|
+
const line = JSON.stringify({
|
|
393
|
+
type: "match",
|
|
394
|
+
data: {
|
|
395
|
+
path: { text: "./src/server.ts" },
|
|
396
|
+
lines: { text: " startServer();\n" },
|
|
397
|
+
line_number: 10,
|
|
398
|
+
submatches: [{ start: 2, end: 13, match: { text: "startServer" } }],
|
|
399
|
+
},
|
|
400
|
+
});
|
|
401
|
+
const result = parseRgJsonOutput(line, "startServer");
|
|
402
|
+
expect(result[0].filePath).toBe("src/server.ts");
|
|
403
|
+
});
|
|
404
|
+
|
|
405
|
+
test("skips non-match type lines", () => {
|
|
406
|
+
const line = JSON.stringify({ type: "begin", data: { path: { text: "a.ts" } } });
|
|
407
|
+
const result = parseRgJsonOutput(line, "x");
|
|
408
|
+
expect(result).toHaveLength(0);
|
|
409
|
+
});
|
|
410
|
+
|
|
411
|
+
test("truncates long snippets", () => {
|
|
412
|
+
const longLine = "x".repeat(300);
|
|
413
|
+
const line = JSON.stringify({
|
|
414
|
+
type: "match",
|
|
415
|
+
data: {
|
|
416
|
+
path: { text: "a.ts" },
|
|
417
|
+
lines: { text: longLine },
|
|
418
|
+
line_number: 1,
|
|
419
|
+
submatches: [{ start: 0, end: 1 }],
|
|
420
|
+
},
|
|
421
|
+
});
|
|
422
|
+
const result = parseRgJsonOutput(line, "x");
|
|
423
|
+
expect(result[0].snippet.length).toBeLessThanOrEqual(201);
|
|
424
|
+
});
|
|
425
|
+
});
|
|
426
|
+
|
|
427
|
+
// ---------------------------------------------------------------------------
|
|
428
|
+
// validateCodeNavRequest
|
|
429
|
+
// ---------------------------------------------------------------------------
|
|
430
|
+
|
|
431
|
+
describe("validateCodeNavRequest", () => {
|
|
432
|
+
const valid = {
|
|
433
|
+
symbol: "startServer",
|
|
434
|
+
filePath: "src/server.ts",
|
|
435
|
+
line: 42,
|
|
436
|
+
charStart: 10,
|
|
437
|
+
side: "new" as const,
|
|
438
|
+
language: "typescript",
|
|
439
|
+
};
|
|
440
|
+
|
|
441
|
+
test("accepts valid request", () => {
|
|
442
|
+
expect(validateCodeNavRequest(valid)).toBeNull();
|
|
443
|
+
});
|
|
444
|
+
|
|
445
|
+
test("rejects null body", () => {
|
|
446
|
+
expect(validateCodeNavRequest(null)).toBe("Invalid request body");
|
|
447
|
+
});
|
|
448
|
+
|
|
449
|
+
test("rejects empty symbol", () => {
|
|
450
|
+
expect(validateCodeNavRequest({ ...valid, symbol: "" })).toBe("Missing or empty symbol");
|
|
451
|
+
});
|
|
452
|
+
|
|
453
|
+
test("rejects missing filePath", () => {
|
|
454
|
+
expect(validateCodeNavRequest({ ...valid, filePath: "" })).toBe("Missing filePath");
|
|
455
|
+
});
|
|
456
|
+
|
|
457
|
+
test("rejects directory traversal", () => {
|
|
458
|
+
expect(validateCodeNavRequest({ ...valid, filePath: "../etc/passwd" })).toBe("Invalid filePath");
|
|
459
|
+
});
|
|
460
|
+
|
|
461
|
+
test("rejects absolute path", () => {
|
|
462
|
+
expect(validateCodeNavRequest({ ...valid, filePath: "/etc/passwd" })).toBe("Invalid filePath");
|
|
463
|
+
});
|
|
464
|
+
|
|
465
|
+
test("rejects invalid side", () => {
|
|
466
|
+
expect(validateCodeNavRequest({ ...valid, side: "both" })).toBe("side must be 'old' or 'new'");
|
|
467
|
+
});
|
|
468
|
+
});
|
|
469
|
+
|
|
470
|
+
// ---------------------------------------------------------------------------
|
|
471
|
+
// extractChangedFiles
|
|
472
|
+
// ---------------------------------------------------------------------------
|
|
473
|
+
|
|
474
|
+
describe("extractChangedFiles", () => {
|
|
475
|
+
test("extracts paths from unified diff", () => {
|
|
476
|
+
const patch = `diff --git a/src/server.ts b/src/server.ts
|
|
477
|
+
--- a/src/server.ts
|
|
478
|
+
+++ b/src/server.ts
|
|
479
|
+
@@ -1,3 +1,3 @@
|
|
480
|
+
diff --git a/src/utils.ts b/src/utils.ts
|
|
481
|
+
--- a/src/utils.ts
|
|
482
|
+
+++ b/src/utils.ts`;
|
|
483
|
+
|
|
484
|
+
const result = extractChangedFiles(patch);
|
|
485
|
+
expect(result).toEqual(["src/server.ts", "src/utils.ts"]);
|
|
486
|
+
});
|
|
487
|
+
|
|
488
|
+
test("extracts both old and new paths for renames", () => {
|
|
489
|
+
const patch = `diff --git a/src/oldName.ts b/src/newName.ts
|
|
490
|
+
similarity index 95%
|
|
491
|
+
rename from src/oldName.ts
|
|
492
|
+
rename to src/newName.ts`;
|
|
493
|
+
|
|
494
|
+
const result = extractChangedFiles(patch);
|
|
495
|
+
expect(result).toContain("src/oldName.ts");
|
|
496
|
+
expect(result).toContain("src/newName.ts");
|
|
497
|
+
});
|
|
498
|
+
|
|
499
|
+
test("deduplicates when paths are the same", () => {
|
|
500
|
+
const patch = `diff --git a/src/server.ts b/src/server.ts
|
|
501
|
+
--- a/src/server.ts
|
|
502
|
+
+++ b/src/server.ts`;
|
|
503
|
+
|
|
504
|
+
const result = extractChangedFiles(patch);
|
|
505
|
+
expect(result).toEqual(["src/server.ts"]);
|
|
506
|
+
});
|
|
507
|
+
|
|
508
|
+
test("returns empty for null patch", () => {
|
|
509
|
+
expect(extractChangedFiles(null)).toEqual([]);
|
|
510
|
+
});
|
|
511
|
+
|
|
512
|
+
test("returns empty for empty string", () => {
|
|
513
|
+
expect(extractChangedFiles("")).toEqual([]);
|
|
514
|
+
});
|
|
515
|
+
});
|