@dataparade/cli 0.0.9 → 0.0.11

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 (179) hide show
  1. package/README.md +1 -1
  2. package/dist/package.json +1 -1
  3. package/dist/src/ai-enrichment/lambda-init-error.d.ts +5 -0
  4. package/dist/src/ai-enrichment/lambda-init-error.js +38 -0
  5. package/dist/src/ai-enrichment/providers/platform-proxy-provider.d.ts +5 -0
  6. package/dist/src/ai-enrichment/providers/platform-proxy-provider.js +27 -1
  7. package/dist/src/analyzers/cpp/cpp-detection-config.d.ts +73 -0
  8. package/dist/src/analyzers/cpp/cpp-detection-config.js +137 -0
  9. package/dist/src/analyzers/cpp/dependency-manifests.d.ts +8 -0
  10. package/dist/src/analyzers/cpp/dependency-manifests.js +130 -0
  11. package/dist/src/analyzers/cpp/detector.d.ts +3 -0
  12. package/dist/src/analyzers/cpp/detector.js +21 -0
  13. package/dist/src/analyzers/cpp/index.d.ts +2 -0
  14. package/dist/src/analyzers/cpp/index.js +11 -0
  15. package/dist/src/analyzers/cpp/manifest-parsers.d.ts +13 -0
  16. package/dist/src/analyzers/cpp/manifest-parsers.js +104 -0
  17. package/dist/src/analyzers/cpp/parser.d.ts +35 -0
  18. package/dist/src/analyzers/cpp/parser.js +206 -0
  19. package/dist/src/analyzers/cpp/patterns.d.ts +3 -0
  20. package/dist/src/analyzers/cpp/patterns.js +37 -0
  21. package/dist/src/analyzers/csharp/csharp-detection-config.d.ts +100 -0
  22. package/dist/src/analyzers/csharp/csharp-detection-config.js +160 -0
  23. package/dist/src/analyzers/csharp/dependency-manifests.d.ts +13 -0
  24. package/dist/src/analyzers/csharp/dependency-manifests.js +184 -0
  25. package/dist/src/analyzers/csharp/detector.d.ts +3 -0
  26. package/dist/src/analyzers/csharp/detector.js +21 -0
  27. package/dist/src/analyzers/csharp/index.d.ts +2 -0
  28. package/dist/src/analyzers/csharp/index.js +11 -0
  29. package/dist/src/analyzers/csharp/manifest-parsers.d.ts +34 -0
  30. package/dist/src/analyzers/csharp/manifest-parsers.js +130 -0
  31. package/dist/src/analyzers/csharp/parser.d.ts +48 -0
  32. package/dist/src/analyzers/csharp/parser.js +277 -0
  33. package/dist/src/analyzers/csharp/patterns.d.ts +3 -0
  34. package/dist/src/analyzers/csharp/patterns.js +57 -0
  35. package/dist/src/analyzers/go/dependency-manifests.d.ts +10 -0
  36. package/dist/src/analyzers/go/dependency-manifests.js +117 -0
  37. package/dist/src/analyzers/go/detector.d.ts +3 -0
  38. package/dist/src/analyzers/go/detector.js +21 -0
  39. package/dist/src/analyzers/go/go-detection-config.d.ts +97 -0
  40. package/dist/src/analyzers/go/go-detection-config.js +164 -0
  41. package/dist/src/analyzers/go/index.d.ts +2 -0
  42. package/dist/src/analyzers/go/index.js +11 -0
  43. package/dist/src/analyzers/go/manifest-parsers.d.ts +20 -0
  44. package/dist/src/analyzers/go/manifest-parsers.js +104 -0
  45. package/dist/src/analyzers/go/parser.d.ts +40 -0
  46. package/dist/src/analyzers/go/parser.js +186 -0
  47. package/dist/src/analyzers/go/patterns.d.ts +3 -0
  48. package/dist/src/analyzers/go/patterns.js +50 -0
  49. package/dist/src/analyzers/jvm/dependency-manifests.d.ts +16 -0
  50. package/dist/src/analyzers/jvm/dependency-manifests.js +205 -0
  51. package/dist/src/analyzers/jvm/detector.d.ts +3 -0
  52. package/dist/src/analyzers/jvm/detector.js +21 -0
  53. package/dist/src/analyzers/jvm/index.d.ts +9 -0
  54. package/dist/src/analyzers/jvm/index.js +18 -0
  55. package/dist/src/analyzers/jvm/jvm-detection-config.d.ts +136 -0
  56. package/dist/src/analyzers/jvm/jvm-detection-config.js +195 -0
  57. package/dist/src/analyzers/jvm/manifest-parsers.d.ts +61 -0
  58. package/dist/src/analyzers/jvm/manifest-parsers.js +246 -0
  59. package/dist/src/analyzers/jvm/parser.d.ts +54 -0
  60. package/dist/src/analyzers/jvm/parser.js +419 -0
  61. package/dist/src/analyzers/jvm/patterns.d.ts +3 -0
  62. package/dist/src/analyzers/jvm/patterns.js +64 -0
  63. package/dist/src/analyzers/python/detector.js +1 -1
  64. package/dist/src/analyzers/python/parser.d.ts +1 -0
  65. package/dist/src/analyzers/python/parser.js +7 -0
  66. package/dist/src/analyzers/python/patterns.d.ts +1 -0
  67. package/dist/src/analyzers/python/patterns.js +22 -77
  68. package/dist/src/analyzers/python/python-detection-config.d.ts +18 -0
  69. package/dist/src/analyzers/python/python-detection-config.js +20 -0
  70. package/dist/src/analyzers/registry.js +15 -0
  71. package/dist/src/analyzers/shared/c-family-calls.d.ts +26 -0
  72. package/dist/src/analyzers/shared/c-family-calls.js +118 -0
  73. package/dist/src/analyzers/shared/strip-comments.d.ts +32 -0
  74. package/dist/src/analyzers/shared/strip-comments.js +167 -0
  75. package/dist/src/analyzers/typescript/detector.js +1 -1
  76. package/dist/src/analyzers/typescript/typescript-detection-config.d.ts +37 -0
  77. package/dist/src/analyzers/typescript/typescript-detection-config.js +48 -0
  78. package/dist/src/analyzers/typescript/typescript-detection.d.ts +1 -0
  79. package/dist/src/analyzers/typescript/typescript-detection.js +27 -29
  80. package/dist/src/cli.js +28 -1
  81. package/dist/src/config/file.js +5 -0
  82. package/dist/src/config/resolve.js +5 -0
  83. package/dist/src/core/pipeline/graph-mapping.js +3 -0
  84. package/dist/src/core/pipeline/structural-scan.js +154 -31
  85. package/dist/src/core/schema/scan-config.schema.d.ts +5 -0
  86. package/dist/src/core/schema/scan-config.schema.js +5 -0
  87. package/dist/src/core/schema/scan-result.schema.d.ts +5 -0
  88. package/dist/src/core/schema/scan-result.schema.js +5 -0
  89. package/dist/src/core/sectioning/discover-service-sections.js +27 -1
  90. package/dist/src/core/types/file.d.ts +1 -1
  91. package/dist/src/ingest/file-system.js +27 -0
  92. package/dist/src/patterns/config.d.ts +8 -0
  93. package/dist/src/patterns/config.js +136 -0
  94. package/dist/src/patterns/detectors/cpp.d.ts +8 -0
  95. package/dist/src/patterns/detectors/cpp.js +243 -0
  96. package/dist/src/patterns/detectors/csharp.d.ts +9 -0
  97. package/dist/src/patterns/detectors/csharp.js +385 -0
  98. package/dist/src/patterns/detectors/go.d.ts +9 -0
  99. package/dist/src/patterns/detectors/go.js +298 -0
  100. package/dist/src/patterns/detectors/helpers.d.ts +3 -0
  101. package/dist/src/patterns/detectors/helpers.js +5 -0
  102. package/dist/src/patterns/detectors/jvm.d.ts +15 -0
  103. package/dist/src/patterns/detectors/jvm.js +537 -0
  104. package/dist/src/patterns/detectors/python.d.ts +1 -0
  105. package/dist/src/patterns/detectors/python.js +92 -5
  106. package/dist/src/patterns/detectors/typescript.d.ts +2 -0
  107. package/dist/src/patterns/detectors/typescript.js +156 -4
  108. package/dist/src/patterns/engine.d.ts +18 -0
  109. package/dist/src/patterns/engine.js +30 -0
  110. package/dist/src/patterns/scan-exclusions.js +20 -0
  111. package/dist/src/platform-api/telemetry-client.d.ts +6 -0
  112. package/dist/src/platform-api/telemetry-client.js +65 -0
  113. package/dist/src/platform-api/telemetry.types.d.ts +13 -0
  114. package/dist/src/platform-api/telemetry.types.js +2 -0
  115. package/dist/src/platform-api/upload-client.d.ts +2 -0
  116. package/dist/src/platform-api/upload-client.js +4 -0
  117. package/dist/src/platform-api/upload.types.d.ts +2 -0
  118. package/dist/src/upload/build-preview-url.d.ts +2 -2
  119. package/dist/src/upload/build-preview-url.js +10 -3
  120. package/dist/src/upload/run-upload.js +62 -19
  121. package/dist/src/upload/types.d.ts +2 -0
  122. package/dist/tests/unit/ai-enrichment/lambda-init-error.spec.d.ts +1 -0
  123. package/dist/tests/unit/ai-enrichment/lambda-init-error.spec.js +11 -0
  124. package/dist/tests/unit/ai-enrichment/platform-proxy-provider.spec.js +80 -0
  125. package/dist/tests/unit/analyzers/cpp/dependency-manifests.spec.d.ts +1 -0
  126. package/dist/tests/unit/analyzers/cpp/dependency-manifests.spec.js +66 -0
  127. package/dist/tests/unit/analyzers/cpp/parser.spec.d.ts +1 -0
  128. package/dist/tests/unit/analyzers/cpp/parser.spec.js +80 -0
  129. package/dist/tests/unit/analyzers/cpp/patterns.spec.d.ts +1 -0
  130. package/dist/tests/unit/analyzers/cpp/patterns.spec.js +141 -0
  131. package/dist/tests/unit/analyzers/csharp/dependency-manifests.spec.d.ts +1 -0
  132. package/dist/tests/unit/analyzers/csharp/dependency-manifests.spec.js +75 -0
  133. package/dist/tests/unit/analyzers/csharp/parser.spec.d.ts +1 -0
  134. package/dist/tests/unit/analyzers/csharp/parser.spec.js +118 -0
  135. package/dist/tests/unit/analyzers/csharp/patterns.spec.d.ts +1 -0
  136. package/dist/tests/unit/analyzers/csharp/patterns.spec.js +210 -0
  137. package/dist/tests/unit/analyzers/go/dependency-manifests.spec.d.ts +1 -0
  138. package/dist/tests/unit/analyzers/go/dependency-manifests.spec.js +96 -0
  139. package/dist/tests/unit/analyzers/go/parser.spec.d.ts +1 -0
  140. package/dist/tests/unit/analyzers/go/parser.spec.js +110 -0
  141. package/dist/tests/unit/analyzers/go/patterns.spec.d.ts +1 -0
  142. package/dist/tests/unit/analyzers/go/patterns.spec.js +239 -0
  143. package/dist/tests/unit/analyzers/jvm/dependency-manifests.spec.d.ts +1 -0
  144. package/dist/tests/unit/analyzers/jvm/dependency-manifests.spec.js +179 -0
  145. package/dist/tests/unit/analyzers/jvm/parser.spec.d.ts +1 -0
  146. package/dist/tests/unit/analyzers/jvm/parser.spec.js +195 -0
  147. package/dist/tests/unit/analyzers/jvm/patterns.spec.d.ts +1 -0
  148. package/dist/tests/unit/analyzers/jvm/patterns.spec.js +284 -0
  149. package/dist/tests/unit/analyzers/python/patterns.spec.js +169 -0
  150. package/dist/tests/unit/analyzers/typescript/detector.spec.js +188 -0
  151. package/dist/tests/unit/core/cpp-dotnet-scan.spec.d.ts +1 -0
  152. package/dist/tests/unit/core/cpp-dotnet-scan.spec.js +67 -0
  153. package/dist/tests/unit/core/cpp-dotnet-sections.spec.d.ts +1 -0
  154. package/dist/tests/unit/core/cpp-dotnet-sections.spec.js +46 -0
  155. package/dist/tests/unit/core/go-scan.spec.d.ts +1 -0
  156. package/dist/tests/unit/core/go-scan.spec.js +78 -0
  157. package/dist/tests/unit/core/graph-mapping.spec.js +75 -0
  158. package/dist/tests/unit/core/jvm-scan.spec.d.ts +1 -0
  159. package/dist/tests/unit/core/jvm-scan.spec.js +94 -0
  160. package/dist/tests/unit/ingest/cpp-dotnet-languages.spec.d.ts +1 -0
  161. package/dist/tests/unit/ingest/cpp-dotnet-languages.spec.js +56 -0
  162. package/dist/tests/unit/ingest/jvm-languages.spec.d.ts +1 -0
  163. package/dist/tests/unit/ingest/jvm-languages.spec.js +47 -0
  164. package/dist/tests/unit/platform-api/telemetry-client.spec.d.ts +1 -0
  165. package/dist/tests/unit/platform-api/telemetry-client.spec.js +48 -0
  166. package/dist/tests/unit/upload/build-preview-url.spec.js +10 -0
  167. package/dist/tests/unit/upload/run-upload.spec.js +18 -0
  168. package/package.json +1 -1
  169. package/patterns/cpp.md +176 -0
  170. package/patterns/cpp.patterns.yaml +314 -0
  171. package/patterns/csharp.md +211 -0
  172. package/patterns/csharp.patterns.yaml +375 -0
  173. package/patterns/go.md +211 -0
  174. package/patterns/go.patterns.yaml +429 -0
  175. package/patterns/jvm.md +160 -0
  176. package/patterns/jvm.patterns.yaml +884 -0
  177. package/patterns/python.patterns.yaml +177 -0
  178. package/patterns/third-party.patterns.yaml +5 -0
  179. package/patterns/typescript.patterns.yaml +222 -0
@@ -0,0 +1,210 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const detector_1 = require("../../../../src/analyzers/csharp/detector");
4
+ function makeCSharpFile(content, path = "Program.cs") {
5
+ return {
6
+ path,
7
+ name: path,
8
+ content,
9
+ language: "csharp",
10
+ size: content.length,
11
+ };
12
+ }
13
+ describe("C# analyzer patterns", () => {
14
+ it("detects controller actions and expands the [controller] route token", () => {
15
+ const content = [
16
+ "using Microsoft.AspNetCore.Mvc;",
17
+ "",
18
+ "[ApiController]",
19
+ '[Route("api/[controller]")]',
20
+ "public class UsersController : ControllerBase",
21
+ "{",
22
+ ' [HttpGet("{id}")]',
23
+ " public IActionResult GetUser(int id) => Ok();",
24
+ "",
25
+ " [HttpPost]",
26
+ " public IActionResult CreateUser() => Ok();",
27
+ "}",
28
+ "",
29
+ ].join("\n");
30
+ const findings = (0, detector_1.detectCSharpPatterns)(makeCSharpFile(content, "Controllers/UsersController.cs"));
31
+ const routes = findings.filter((f) => f.pattern === "express_route");
32
+ expect(routes.map((r) => r.name).sort()).toEqual([
33
+ "GET api/Users/{id}",
34
+ "POST api/Users",
35
+ ]);
36
+ expect(routes[0].properties.framework).toBe("aspnet_core_mvc");
37
+ expect(routes[0].properties.controller).toBe("UsersController");
38
+ expect(routes[0].properties.handlerType).toBe("controller_action");
39
+ });
40
+ it("detects minimal API route registrations", () => {
41
+ const content = [
42
+ "var builder = WebApplication.CreateBuilder(args);",
43
+ "var app = builder.Build();",
44
+ "",
45
+ 'app.MapGet("/health", () => Results.Ok());',
46
+ 'app.MapPost("/orders", (Order order) => Results.Created());',
47
+ "",
48
+ "app.Run();",
49
+ "",
50
+ ].join("\n");
51
+ const findings = (0, detector_1.detectCSharpPatterns)(makeCSharpFile(content));
52
+ const routes = findings.filter((f) => f.pattern === "express_route");
53
+ expect(routes.map((r) => r.name).sort()).toEqual([
54
+ "GET /health",
55
+ "POST /orders",
56
+ ]);
57
+ expect(routes[0].properties.handlerType).toBe("minimal_api");
58
+ });
59
+ it("detects EF Core and Npgsql as database_connection findings", () => {
60
+ const content = [
61
+ "using Microsoft.EntityFrameworkCore;",
62
+ "",
63
+ "public class AppDbContext : DbContext",
64
+ "{",
65
+ " protected override void OnConfiguring(DbContextOptionsBuilder options)",
66
+ " {",
67
+ ' options.UseNpgsql("Host=localhost;Database=app");',
68
+ " }",
69
+ "}",
70
+ "",
71
+ ].join("\n");
72
+ const findings = (0, detector_1.detectCSharpPatterns)(makeCSharpFile(content, "Data/AppDbContext.cs"));
73
+ const dbs = findings.filter((f) => f.pattern === "database_connection");
74
+ expect(dbs.map((d) => d.properties.client)).toContain("entity_framework_core");
75
+ });
76
+ it("detects HttpClient calls and resolves the third-party service", () => {
77
+ const content = [
78
+ "using System.Net.Http;",
79
+ "",
80
+ "public class ChargeService",
81
+ "{",
82
+ " private readonly HttpClient _client = new HttpClient();",
83
+ "",
84
+ " public async Task Charge()",
85
+ " {",
86
+ ' await _client.PostAsync("https://api.stripe.com/v1/charges", null);',
87
+ " }",
88
+ "}",
89
+ "",
90
+ ].join("\n");
91
+ const findings = (0, detector_1.detectCSharpPatterns)(makeCSharpFile(content, "Services/ChargeService.cs"));
92
+ const apis = findings.filter((f) => f.pattern === "external_api_call");
93
+ const stripeCall = apis.find((f) => f.properties.url === "https://api.stripe.com/v1/charges");
94
+ expect(stripeCall).toBeDefined();
95
+ expect(stripeCall?.properties.serviceName).toBe("stripe");
96
+ });
97
+ it("detects [Authorize] and JWT bearer configuration as auth_middleware", () => {
98
+ const content = [
99
+ "using Microsoft.AspNetCore.Authentication.JwtBearer;",
100
+ "using Microsoft.AspNetCore.Authorization;",
101
+ "using Microsoft.AspNetCore.Mvc;",
102
+ "",
103
+ "[Authorize]",
104
+ "public class SecureController : ControllerBase",
105
+ "{",
106
+ " public void Configure(IServiceCollection services)",
107
+ " {",
108
+ " services.AddAuthentication().AddJwtBearer();",
109
+ " }",
110
+ "}",
111
+ "",
112
+ ].join("\n");
113
+ const findings = (0, detector_1.detectCSharpPatterns)(makeCSharpFile(content, "Controllers/SecureController.cs"));
114
+ const auth = findings.filter((f) => f.pattern === "auth_middleware");
115
+ const names = auth.map((a) => a.name);
116
+ expect(names).toContain("jwt_bearer");
117
+ expect(names).toContain("authorize_attribute");
118
+ });
119
+ it("detects environment and configuration keys as env_variable findings", () => {
120
+ const content = [
121
+ "using System;",
122
+ "",
123
+ "public class Settings",
124
+ "{",
125
+ ' public string Key = Environment.GetEnvironmentVariable("API_KEY");',
126
+ ' public string Db = builder.Configuration.GetConnectionString("Default");',
127
+ "}",
128
+ "",
129
+ ].join("\n");
130
+ const findings = (0, detector_1.detectCSharpPatterns)(makeCSharpFile(content, "Config/Settings.cs"));
131
+ const envs = findings.filter((f) => f.pattern === "env_variable");
132
+ const keys = envs.map((e) => e.properties.key);
133
+ expect(keys).toContain("API_KEY");
134
+ expect(keys).toContain("Default");
135
+ });
136
+ it("detects Azure Functions handlers as lambda_handler findings", () => {
137
+ const content = [
138
+ "using Microsoft.Azure.Functions.Worker;",
139
+ "",
140
+ "public class OrderFunctions",
141
+ "{",
142
+ ' [Function("ProcessOrder")]',
143
+ " public void Run([QueueTrigger(\"orders\")] string message)",
144
+ " {",
145
+ " }",
146
+ "}",
147
+ "",
148
+ ].join("\n");
149
+ const findings = (0, detector_1.detectCSharpPatterns)(makeCSharpFile(content, "Functions/OrderFunctions.cs"));
150
+ const handlers = findings.filter((f) => f.pattern === "lambda_handler");
151
+ expect(handlers.length).toBe(1);
152
+ expect(handlers[0].properties.functionName).toBe("ProcessOrder");
153
+ expect(handlers[0].properties.framework).toBe("azure_functions");
154
+ });
155
+ it("ignores routes that only appear in comments", () => {
156
+ const content = [
157
+ "using Microsoft.AspNetCore.Mvc;",
158
+ "",
159
+ "var app = builder.Build();",
160
+ '// app.MapGet("/legacy", () => Results.Ok());',
161
+ "",
162
+ ].join("\n");
163
+ const findings = (0, detector_1.detectCSharpPatterns)(makeCSharpFile(content));
164
+ expect(findings.filter((f) => f.pattern === "express_route")).toEqual([]);
165
+ });
166
+ it("detects Microsoft.Identity.Web OAuth2 as auth_middleware", () => {
167
+ const content = [
168
+ "using Microsoft.Identity.Web;",
169
+ "",
170
+ "builder.Services.AddMicrosoftIdentityWebApp(builder.Configuration);",
171
+ "",
172
+ ].join("\n");
173
+ const findings = (0, detector_1.detectCSharpPatterns)(makeCSharpFile(content, "Program.cs"));
174
+ const authFindings = findings.filter((f) => f.pattern === "auth_middleware");
175
+ expect(authFindings.length).toBeGreaterThanOrEqual(1);
176
+ expect(authFindings[0].properties.strategy).toBe("oauth2");
177
+ expect(authFindings[0].name).toBe("microsoft_identity_web");
178
+ });
179
+ it("detects GCP Cloud Functions .NET as lambda_handler", () => {
180
+ // The detector matches typeNames appearing in a method's declaration line
181
+ // (e.g. as a parameter type). IHttpFunction used as a parameter triggers detection.
182
+ const content = [
183
+ "using Google.Cloud.Functions.Framework;",
184
+ "using Microsoft.AspNetCore.Http;",
185
+ "",
186
+ "public class HelloWorld",
187
+ "{",
188
+ " public async Task HandleAsync(IHttpFunction ctx, HttpContext context)",
189
+ " {",
190
+ " await context.Response.WriteAsync(\"Hello World!\");",
191
+ " }",
192
+ "}",
193
+ "",
194
+ ].join("\n");
195
+ const findings = (0, detector_1.detectCSharpPatterns)(makeCSharpFile(content, "HelloWorld.cs"));
196
+ const handlers = findings.filter((f) => f.pattern === "lambda_handler");
197
+ expect(handlers.length).toBeGreaterThanOrEqual(1);
198
+ expect(handlers[0].properties.framework).toBe("gcp_functions_dotnet");
199
+ });
200
+ it("returns no findings for a non-C# file", () => {
201
+ const file = {
202
+ path: "main.cpp",
203
+ name: "main.cpp",
204
+ content: "#include <crow.h>",
205
+ language: "cpp",
206
+ size: 17,
207
+ };
208
+ expect((0, detector_1.detectCSharpPatterns)(file)).toEqual([]);
209
+ });
210
+ });
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const path_1 = __importDefault(require("path"));
7
+ const dependency_manifests_1 = require("../../../../src/analyzers/go/dependency-manifests");
8
+ const manifest_parsers_1 = require("../../../../src/analyzers/go/manifest-parsers");
9
+ const FIXTURE_ROOT = path_1.default.join(__dirname, "..", "..", "..", "fixtures", "go-dependency-manifests-basic");
10
+ describe("Go manifest parsers", () => {
11
+ it("parses the module path and both require forms", () => {
12
+ const content = [
13
+ "module github.com/acme/gateway",
14
+ "",
15
+ "go 1.22",
16
+ "",
17
+ "require (",
18
+ "\tgithub.com/getsentry/sentry-go v0.28.1",
19
+ "\tgithub.com/lib/pq v1.10.9",
20
+ ")",
21
+ "",
22
+ "require github.com/gin-gonic/gin v1.10.0 // indirect",
23
+ "",
24
+ ].join("\n");
25
+ const parsed = (0, manifest_parsers_1.parseGoMod)(content);
26
+ expect(parsed.modulePath).toBe("github.com/acme/gateway");
27
+ expect(parsed.requires.sort()).toEqual([
28
+ "github.com/getsentry/sentry-go",
29
+ "github.com/gin-gonic/gin",
30
+ "github.com/lib/pq",
31
+ ]);
32
+ });
33
+ it("skips replace, exclude, and retract blocks", () => {
34
+ const content = [
35
+ "module github.com/acme/app",
36
+ "",
37
+ "require github.com/real/dep v1.0.0",
38
+ "",
39
+ "replace (",
40
+ "\tgithub.com/replaced/dep => ../local",
41
+ ")",
42
+ "",
43
+ "exclude (",
44
+ "\tgithub.com/excluded/dep v1.2.3",
45
+ ")",
46
+ "",
47
+ ].join("\n");
48
+ expect((0, manifest_parsers_1.parseGoMod)(content).requires).toEqual(["github.com/real/dep"]);
49
+ });
50
+ it("parses go.work workspace members", () => {
51
+ const content = [
52
+ "go 1.22",
53
+ "",
54
+ "use (",
55
+ "\t./services/api",
56
+ "\t./services/worker",
57
+ ")",
58
+ "",
59
+ ].join("\n");
60
+ expect((0, manifest_parsers_1.parseGoWork)(content)).toEqual([
61
+ "services/api",
62
+ "services/worker",
63
+ ]);
64
+ });
65
+ it("returns an empty manifest for content with no requires", () => {
66
+ const parsed = (0, manifest_parsers_1.parseGoMod)("module github.com/acme/tiny\n\ngo 1.22\n");
67
+ expect(parsed.modulePath).toBe("github.com/acme/tiny");
68
+ expect(parsed.requires).toEqual([]);
69
+ });
70
+ });
71
+ describe("Go dependency manifest scanning", () => {
72
+ it("collects required modules from go.mod", async () => {
73
+ const manifests = await (0, dependency_manifests_1.parseGoDependencyManifests)(FIXTURE_ROOT);
74
+ expect(manifests.length).toBe(1);
75
+ expect(manifests[0].manifestRelativePath).toBe("go.mod");
76
+ expect(manifests[0].modulePath).toBe("github.com/acme/gateway");
77
+ expect(manifests[0].packages).toEqual(expect.arrayContaining([
78
+ "github.com/getsentry/sentry-go",
79
+ "github.com/stripe/stripe-go/v76",
80
+ "github.com/aws/aws-sdk-go-v2",
81
+ "github.com/lib/pq",
82
+ "github.com/redis/go-redis/v9",
83
+ ]));
84
+ });
85
+ it("maps module paths to third-party services and databases", async () => {
86
+ const findings = await (0, dependency_manifests_1.detectGoPatternsFromDependencyManifests)(FIXTURE_ROOT);
87
+ const serviceNames = findings
88
+ .filter((f) => f.pattern === "external_api_call")
89
+ .map((f) => f.properties.serviceName);
90
+ expect(serviceNames).toEqual(expect.arrayContaining(["sentry", "stripe", "aws"]));
91
+ const databases = findings
92
+ .filter((f) => f.pattern === "database_connection")
93
+ .map((f) => f.properties.client);
94
+ expect(databases).toEqual(expect.arrayContaining(["lib_pq", "go_redis"]));
95
+ });
96
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,110 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const parser_1 = require("../../../../src/analyzers/go/parser");
4
+ function createGoFile(content, path = "main.go") {
5
+ return {
6
+ path,
7
+ name: path,
8
+ content,
9
+ language: "go",
10
+ size: content.length,
11
+ };
12
+ }
13
+ describe("Go parser - parseGoSourceFile", () => {
14
+ it("indexes package, grouped imports, functions, types, and calls", () => {
15
+ const content = [
16
+ "package main",
17
+ "",
18
+ "import (",
19
+ '\t"database/sql"',
20
+ '\t"net/http"',
21
+ "",
22
+ '\tmux "github.com/gorilla/mux"',
23
+ '\t_ "github.com/lib/pq"',
24
+ ")",
25
+ "",
26
+ "type Server struct {",
27
+ "\tdb *sql.DB",
28
+ "}",
29
+ "",
30
+ "func (s *Server) Handle(w http.ResponseWriter, r *http.Request) {",
31
+ '\tresp, _ := http.Get("https://api.example.com/items")',
32
+ "\tdefer resp.Body.Close()",
33
+ "}",
34
+ "",
35
+ "func NewServer() *Server {",
36
+ "\treturn &Server{}",
37
+ "}",
38
+ "",
39
+ ].join("\n");
40
+ const result = (0, parser_1.parseGoSourceFile)(createGoFile(content));
41
+ expect(result.warnings).toEqual([]);
42
+ expect(result.packageName).toBe("main");
43
+ expect(result.imports.map((i) => i.path)).toEqual([
44
+ "database/sql",
45
+ "net/http",
46
+ "github.com/gorilla/mux",
47
+ "github.com/lib/pq",
48
+ ]);
49
+ const gorilla = result.imports.find((i) => i.path === "github.com/gorilla/mux");
50
+ expect(gorilla?.alias).toBe("mux");
51
+ const pq = result.imports.find((i) => i.path === "github.com/lib/pq");
52
+ expect(pq?.isBlank).toBe(true);
53
+ expect(pq?.alias).toBeUndefined();
54
+ const server = result.types.find((t) => t.name === "Server");
55
+ expect(server?.kind).toBe("struct");
56
+ const handle = result.functions.find((fn) => fn.name === "Handle");
57
+ expect(handle?.receiverType).toBe("Server");
58
+ const newServer = result.functions.find((fn) => fn.name === "NewServer");
59
+ expect(newServer?.receiverType).toBeUndefined();
60
+ const httpGet = result.calls.find((c) => c.callee === "http.Get");
61
+ expect(httpGet).toBeDefined();
62
+ expect(httpGet?.argumentsSnippet).toContain("https://api.example.com/items");
63
+ });
64
+ it("indexes single-line and aliased imports", () => {
65
+ const content = [
66
+ "package api",
67
+ "",
68
+ 'import "fmt"',
69
+ 'import alias "github.com/acme/lib"',
70
+ "",
71
+ ].join("\n");
72
+ const result = (0, parser_1.parseGoSourceFile)(createGoFile(content, "api.go"));
73
+ expect(result.imports.map((i) => i.path)).toEqual([
74
+ "fmt",
75
+ "github.com/acme/lib",
76
+ ]);
77
+ expect(result.imports[1].alias).toBe("alias");
78
+ });
79
+ it("blanks comments while preserving backtick raw strings and layout", () => {
80
+ const content = [
81
+ "package main",
82
+ "",
83
+ '// resp, _ := http.Get("https://old.example.com")',
84
+ "/* block",
85
+ " comment */",
86
+ "const query = `SELECT * FROM users -- not a comment`",
87
+ 'const url = "https://api.example.com/v1" // trailing',
88
+ "",
89
+ ].join("\n");
90
+ const result = (0, parser_1.parseGoSourceFile)(createGoFile(content));
91
+ expect(result.strippedContent).toContain("SELECT * FROM users");
92
+ expect(result.strippedContent).toContain("https://api.example.com/v1");
93
+ expect(result.strippedContent).not.toContain("old.example.com");
94
+ expect(result.strippedContent).not.toContain("trailing");
95
+ expect(result.strippedContent.split("\n").length).toBe(content.split("\n").length);
96
+ });
97
+ it("returns a warning and an empty model for non-Go files", () => {
98
+ const file = {
99
+ path: "main.cpp",
100
+ name: "main.cpp",
101
+ content: "#include <crow.h>",
102
+ language: "cpp",
103
+ size: 17,
104
+ };
105
+ const result = (0, parser_1.parseGoSourceFile)(file);
106
+ expect(result.imports).toEqual([]);
107
+ expect(result.functions).toEqual([]);
108
+ expect(result.warnings.length).toBeGreaterThan(0);
109
+ });
110
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,239 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const detector_1 = require("../../../../src/analyzers/go/detector");
4
+ function makeGoFile(content, path = "main.go") {
5
+ return {
6
+ path,
7
+ name: path,
8
+ content,
9
+ language: "go",
10
+ size: content.length,
11
+ };
12
+ }
13
+ describe("Go analyzer patterns", () => {
14
+ it("detects gin routes with their HTTP method", () => {
15
+ const content = [
16
+ "package main",
17
+ "",
18
+ 'import "github.com/gin-gonic/gin"',
19
+ "",
20
+ "func main() {",
21
+ "\tr := gin.Default()",
22
+ '\tr.GET("/customers", listCustomers)',
23
+ '\tr.POST("/charges", createCharge)',
24
+ '\tr.Run(":8080")',
25
+ "}",
26
+ "",
27
+ ].join("\n");
28
+ const findings = (0, detector_1.detectGoPatterns)(makeGoFile(content, "server.go"));
29
+ const routes = findings.filter((f) => f.pattern === "express_route");
30
+ expect(routes.map((r) => r.name).sort()).toEqual([
31
+ "GET /customers",
32
+ "POST /charges",
33
+ ]);
34
+ expect(routes[0].properties.framework).toBe("gin");
35
+ });
36
+ it("detects Go 1.22 method-prefixed net/http patterns", () => {
37
+ const content = [
38
+ "package main",
39
+ "",
40
+ 'import "net/http"',
41
+ "",
42
+ "func main() {",
43
+ "\tmux := http.NewServeMux()",
44
+ '\tmux.HandleFunc("GET /health", healthHandler)',
45
+ '\tmux.HandleFunc("/legacy", legacyHandler)',
46
+ "}",
47
+ "",
48
+ ].join("\n");
49
+ const findings = (0, detector_1.detectGoPatterns)(makeGoFile(content, "server.go"));
50
+ const routes = findings.filter((f) => f.pattern === "express_route");
51
+ expect(routes.map((r) => r.name).sort()).toEqual([
52
+ "GET /health",
53
+ "NET_HTTP_ROUTE /legacy",
54
+ ]);
55
+ });
56
+ it("attributes a gorilla/mux route to one framework, not two", () => {
57
+ const content = [
58
+ "package main",
59
+ "",
60
+ "import (",
61
+ '\t"net/http"',
62
+ "",
63
+ '\t"github.com/gorilla/mux"',
64
+ ")",
65
+ "",
66
+ "func main() {",
67
+ "\tr := mux.NewRouter()",
68
+ '\tr.HandleFunc("/orders", ordersHandler).Methods("POST")',
69
+ "}",
70
+ "",
71
+ ].join("\n");
72
+ const findings = (0, detector_1.detectGoPatterns)(makeGoFile(content, "server.go"));
73
+ const routes = findings.filter((f) => f.pattern === "express_route");
74
+ // net/http is imported too, but its rule yields lines ending in .Methods().
75
+ expect(routes.length).toBe(1);
76
+ expect(routes[0].name).toBe("POST /orders");
77
+ expect(routes[0].properties.framework).toBe("gorilla_mux");
78
+ });
79
+ it("resolves the engine from the sql.Open driver argument", () => {
80
+ const content = [
81
+ "package main",
82
+ "",
83
+ "import (",
84
+ '\t"database/sql"',
85
+ "",
86
+ '\t_ "github.com/lib/pq"',
87
+ ")",
88
+ "",
89
+ "func open() {",
90
+ '\tdb, _ := sql.Open("postgres", dsn)',
91
+ "\t_ = db",
92
+ "}",
93
+ "",
94
+ ].join("\n");
95
+ const findings = (0, detector_1.detectGoPatterns)(makeGoFile(content, "db.go"));
96
+ const dbs = findings.filter((f) => f.pattern === "database_connection");
97
+ const sqlOpen = dbs.find((d) => d.properties.client === "database_sql");
98
+ expect(sqlOpen).toBeDefined();
99
+ expect(sqlOpen?.properties.driver).toBe("postgres");
100
+ expect(sqlOpen?.properties.databaseType).toBe("postgres");
101
+ // The blank driver import is its own signal.
102
+ expect(dbs.map((d) => d.properties.client)).toContain("lib_pq");
103
+ });
104
+ it("falls back to a generic sql databaseType for unknown drivers", () => {
105
+ const content = [
106
+ "package main",
107
+ "",
108
+ 'import "database/sql"',
109
+ "",
110
+ "func open() {",
111
+ '\tdb, _ := sql.Open("exotic-driver", dsn)',
112
+ "\t_ = db",
113
+ "}",
114
+ "",
115
+ ].join("\n");
116
+ const findings = (0, detector_1.detectGoPatterns)(makeGoFile(content, "db.go"));
117
+ const sqlOpen = findings.find((f) => f.properties.client === "database_sql");
118
+ expect(sqlOpen?.properties.driver).toBe("exotic-driver");
119
+ expect(sqlOpen?.properties.databaseType).toBe("sql");
120
+ });
121
+ it("detects http.Get calls and resolves the third-party service", () => {
122
+ const content = [
123
+ "package main",
124
+ "",
125
+ 'import "net/http"',
126
+ "",
127
+ "func charge() {",
128
+ '\tresp, _ := http.Get("https://api.stripe.com/v1/charges")',
129
+ "\tdefer resp.Body.Close()",
130
+ "}",
131
+ "",
132
+ ].join("\n");
133
+ const findings = (0, detector_1.detectGoPatterns)(makeGoFile(content, "charge.go"));
134
+ const apis = findings.filter((f) => f.pattern === "external_api_call");
135
+ const stripeCall = apis.find((f) => f.properties.url === "https://api.stripe.com/v1/charges");
136
+ expect(stripeCall).toBeDefined();
137
+ expect(stripeCall?.properties.serviceName).toBe("stripe");
138
+ });
139
+ it("does not treat a chi router .Get() as an outbound HTTP call", () => {
140
+ const content = [
141
+ "package main",
142
+ "",
143
+ "import (",
144
+ '\t"net/http"',
145
+ "",
146
+ '\t"github.com/go-chi/chi/v5"',
147
+ ")",
148
+ "",
149
+ "func main() {",
150
+ "\tr := chi.NewRouter()",
151
+ '\tr.Get("/items", itemsHandler)',
152
+ "}",
153
+ "",
154
+ ].join("\n");
155
+ const findings = (0, detector_1.detectGoPatterns)(makeGoFile(content, "server.go"));
156
+ const routes = findings.filter((f) => f.pattern === "express_route");
157
+ expect(routes.map((r) => r.name)).toEqual(["GET /items"]);
158
+ // r.Get is a route registration, not an outbound call.
159
+ expect(findings.filter((f) => f.pattern === "external_api_call")).toEqual([]);
160
+ });
161
+ it("detects os.Getenv keys as env_variable findings", () => {
162
+ const content = [
163
+ "package main",
164
+ "",
165
+ 'import "os"',
166
+ "",
167
+ "func config() {",
168
+ '\turl := os.Getenv("DATABASE_URL")',
169
+ '\tkey, _ := os.LookupEnv("API_KEY")',
170
+ "\t_, _ = url, key",
171
+ "}",
172
+ "",
173
+ ].join("\n");
174
+ const findings = (0, detector_1.detectGoPatterns)(makeGoFile(content, "config.go"));
175
+ const envs = findings.filter((f) => f.pattern === "env_variable");
176
+ expect(envs.map((e) => e.properties.key).sort()).toEqual([
177
+ "API_KEY",
178
+ "DATABASE_URL",
179
+ ]);
180
+ });
181
+ it("detects jwt usage as auth_middleware findings", () => {
182
+ const content = [
183
+ "package auth",
184
+ "",
185
+ 'import "github.com/golang-jwt/jwt/v5"',
186
+ "",
187
+ "func verify(token string) error {",
188
+ "\t_, err := jwt.Parse(token, nil)",
189
+ "\treturn err",
190
+ "}",
191
+ "",
192
+ ].join("\n");
193
+ const findings = (0, detector_1.detectGoPatterns)(makeGoFile(content, "auth.go"));
194
+ const auth = findings.filter((f) => f.pattern === "auth_middleware" && f.name === "golang_jwt");
195
+ expect(auth.length).toBe(1);
196
+ expect(auth[0].properties.strategy).toBe("jwt");
197
+ });
198
+ it("detects AWS Lambda handlers as lambda_handler findings", () => {
199
+ const content = [
200
+ "package main",
201
+ "",
202
+ 'import "github.com/aws/aws-lambda-go/lambda"',
203
+ "",
204
+ "func main() {",
205
+ "\tlambda.Start(handleRequest)",
206
+ "}",
207
+ "",
208
+ ].join("\n");
209
+ const findings = (0, detector_1.detectGoPatterns)(makeGoFile(content, "main.go"));
210
+ const handlers = findings.filter((f) => f.pattern === "lambda_handler");
211
+ expect(handlers.length).toBe(1);
212
+ expect(handlers[0].properties.framework).toBe("aws_lambda_go");
213
+ });
214
+ it("ignores routes that only appear in comments", () => {
215
+ const content = [
216
+ "package main",
217
+ "",
218
+ 'import "github.com/gin-gonic/gin"',
219
+ "",
220
+ "func main() {",
221
+ "\tr := gin.Default()",
222
+ '\t// r.GET("/legacy", legacyHandler)',
223
+ "}",
224
+ "",
225
+ ].join("\n");
226
+ const findings = (0, detector_1.detectGoPatterns)(makeGoFile(content, "server.go"));
227
+ expect(findings.filter((f) => f.pattern === "express_route")).toEqual([]);
228
+ });
229
+ it("returns no findings for a non-Go file", () => {
230
+ const file = {
231
+ path: "app.py",
232
+ name: "app.py",
233
+ content: "import requests",
234
+ language: "python",
235
+ size: 15,
236
+ };
237
+ expect((0, detector_1.detectGoPatterns)(file)).toEqual([]);
238
+ });
239
+ });