@dataparade/cli 0.0.13 → 0.0.14

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 (74) hide show
  1. package/dist/package.json +2 -2
  2. package/dist/src/ai-enrichment/candidate-selector.d.ts +4 -4
  3. package/dist/src/ai-enrichment/candidate-selector.js +37 -32
  4. package/dist/src/ai-enrichment/fallbacks.js +130 -3
  5. package/dist/src/ai-enrichment/merge-rules.d.ts +3 -3
  6. package/dist/src/ai-enrichment/merge-rules.js +118 -40
  7. package/dist/src/ai-enrichment/prompts/provider-enrichment-prompts.d.ts +2 -2
  8. package/dist/src/ai-enrichment/prompts/provider-enrichment-prompts.js +3 -3
  9. package/dist/src/ai-enrichment/property-priority.d.ts +5 -0
  10. package/dist/src/ai-enrichment/property-priority.js +23 -0
  11. package/dist/src/ai-enrichment/provider-prompt.d.ts +5 -5
  12. package/dist/src/ai-enrichment/provider-prompt.js +24 -19
  13. package/dist/src/ai-enrichment/red-flags.d.ts +46 -0
  14. package/dist/src/ai-enrichment/red-flags.js +365 -0
  15. package/dist/src/ai-enrichment/third-party-evidence.d.ts +3 -3
  16. package/dist/src/ai-enrichment/third-party-evidence.js +96 -93
  17. package/dist/src/cli.d.ts +1 -1
  18. package/dist/src/cli.js +158 -141
  19. package/dist/src/core/pipeline/orchestrator-result.d.ts +9 -1
  20. package/dist/src/core/pipeline/orchestrator.d.ts +2 -2
  21. package/dist/src/core/pipeline/scan-pipeline.d.ts +2 -2
  22. package/dist/src/core/pipeline/scan-pipeline.js +46 -34
  23. package/dist/src/output/json.d.ts +11 -3
  24. package/dist/src/output/json.js +10 -5
  25. package/dist/tests/unit/ai-enrichment/candidate-selector.spec.js +80 -49
  26. package/dist/tests/unit/ai-enrichment/fallbacks.spec.js +78 -0
  27. package/dist/tests/unit/ai-enrichment/merge-rules.spec.js +510 -264
  28. package/dist/tests/unit/ai-enrichment/provider-prompt.spec.js +80 -77
  29. package/dist/tests/unit/ai-enrichment/red-flags.spec.js +227 -0
  30. package/dist/tests/unit/ai-enrichment/third-party-evidence.spec.js +38 -34
  31. package/dist/tests/unit/cli/scan-command-e2e-backend-lambda-orphan.spec.d.ts +1 -0
  32. package/dist/tests/unit/cli/scan-command-e2e-backend-lambda-orphan.spec.js +60 -0
  33. package/dist/tests/unit/cli/scan-command-e2e-occupied-section-hubs.spec.d.ts +1 -0
  34. package/dist/tests/unit/cli/scan-command-e2e-occupied-section-hubs.spec.js +58 -0
  35. package/dist/tests/unit/cli/scan-command-e2e-ruby-basic.spec.d.ts +1 -0
  36. package/dist/tests/unit/cli/scan-command-e2e-ruby-basic.spec.js +46 -0
  37. package/dist/tests/unit/cli/scan-quota-flow.spec.js +8 -0
  38. package/package.json +2 -2
  39. package/dist/tests/fixtures/e2e-ts-sample/db-client-import.d.ts +0 -2
  40. package/dist/tests/fixtures/e2e-ts-sample/db-client-import.js +0 -8
  41. package/dist/tests/fixtures/e2e-ts-sample/db.d.ts +0 -3
  42. package/dist/tests/fixtures/e2e-ts-sample/db.js +0 -7
  43. package/dist/tests/fixtures/e2e-ts-sample/external-api.d.ts +0 -1
  44. package/dist/tests/fixtures/e2e-ts-sample/external-api.js +0 -18
  45. package/dist/tests/fixtures/e2e-ts-sample/pg-client.d.ts +0 -3
  46. package/dist/tests/fixtures/e2e-ts-sample/pg-client.js +0 -7
  47. package/dist/tests/fixtures/e2e-ts-sample/server.d.ts +0 -14
  48. package/dist/tests/fixtures/e2e-ts-sample/server.js +0 -4
  49. package/dist/tests/fixtures/e2e-ts-sentry-route-env/server.js +0 -24
  50. package/dist/tests/fixtures/ingest-basic/src/index.d.ts +0 -1
  51. package/dist/tests/fixtures/ingest-basic/src/index.js +0 -6
  52. package/dist/tests/fixtures/mixed-language-basic/api.d.ts +0 -2
  53. package/dist/tests/fixtures/mixed-language-basic/api.js +0 -12
  54. package/dist/tests/fixtures/monorepo-app-plus-terraform/packages/app/app/route.d.ts +0 -1
  55. package/dist/tests/fixtures/monorepo-app-plus-terraform/packages/app/app/route.js +0 -6
  56. package/dist/tests/fixtures/monorepo-front-back-sections/backend/app/route.d.ts +0 -1
  57. package/dist/tests/fixtures/monorepo-front-back-sections/backend/app/route.js +0 -6
  58. package/dist/tests/fixtures/monorepo-front-back-sections/frontend/app/route.d.ts +0 -1
  59. package/dist/tests/fixtures/monorepo-front-back-sections/frontend/app/route.js +0 -7
  60. package/dist/tests/fixtures/typescript-basic/app/route.d.ts +0 -1
  61. package/dist/tests/fixtures/typescript-basic/app/route.js +0 -7
  62. package/dist/tests/fixtures/typescript-basic/db-client-import.d.ts +0 -2
  63. package/dist/tests/fixtures/typescript-basic/db-client-import.js +0 -8
  64. package/dist/tests/fixtures/typescript-basic/db.d.ts +0 -3
  65. package/dist/tests/fixtures/typescript-basic/db.js +0 -7
  66. package/dist/tests/fixtures/typescript-basic/external-api.d.ts +0 -1
  67. package/dist/tests/fixtures/typescript-basic/external-api.js +0 -18
  68. package/dist/tests/fixtures/typescript-basic/pg-client.d.ts +0 -3
  69. package/dist/tests/fixtures/typescript-basic/pg-client.js +0 -7
  70. package/dist/tests/fixtures/typescript-basic/server.d.ts +0 -14
  71. package/dist/tests/fixtures/typescript-basic/server.js +0 -4
  72. package/dist/tests/fixtures/typescript-dependency-manifests-basic/src/index.d.ts +0 -0
  73. package/dist/tests/fixtures/typescript-dependency-manifests-basic/src/index.js +0 -2
  74. /package/dist/tests/{fixtures/e2e-ts-sentry-route-env/server.d.ts → unit/ai-enrichment/red-flags.spec.d.ts} +0 -0
@@ -1,46 +1,48 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const provider_prompt_1 = require("../../../src/ai-enrichment/provider-prompt");
4
- describe("provider-prompt", () => {
5
- it("slimComponentForLlm keeps detectedFrom paths and splits sparse keys", () => {
4
+ describe('provider-prompt', () => {
5
+ it('slimComponentForLlm keeps detectedFrom paths and splits sparse keys', () => {
6
6
  const c = {
7
- id: "tp_1",
8
- name: "Acme API",
9
- type: "third_party",
7
+ id: 'tp_1',
8
+ name: 'Acme API',
9
+ type: 'third_party',
10
10
  confidence: 0.9,
11
11
  detectedFrom: [
12
12
  {
13
- pattern: "import",
13
+ pattern: 'import',
14
14
  sourceLocation: {
15
- filePath: "src/lib/acme.ts",
15
+ filePath: 'src/lib/acme.ts',
16
16
  startLine: 3,
17
17
  endLine: 3,
18
18
  },
19
19
  },
20
20
  ],
21
21
  sourceLocations: [
22
- { filePath: "src/lib/acme.ts", startLine: 1, endLine: 20 },
22
+ { filePath: 'src/lib/acme.ts', startLine: 1, endLine: 20 },
23
23
  ],
24
24
  properties: {
25
- section_id: "backend",
25
+ section_id: 'backend',
26
26
  vendor: null,
27
27
  integration_method: [],
28
+ encrypt_at_rest: null,
28
29
  inference_status: undefined,
29
30
  },
30
31
  };
31
32
  const slim = (0, provider_prompt_1.slimComponentForLlm)(c);
32
33
  expect(slim.detectedFrom).toHaveLength(1);
33
- expect(slim.detectedFrom[0]?.filePath).toBe("src/lib/acme.ts");
34
- expect(slim.propertiesSet).toEqual({ section_id: "backend" });
35
- expect(slim.sparsePropertyKeys).toContain("vendor");
36
- expect(slim.sparsePropertyKeys).not.toContain("inference_status");
34
+ expect(slim.detectedFrom[0]?.filePath).toBe('src/lib/acme.ts');
35
+ expect(slim.propertiesSet).toEqual({ section_id: 'backend' });
36
+ expect(slim.sparsePropertyKeys).toContain('vendor');
37
+ expect(slim.sparsePropertyKeys).not.toContain('inference_status');
38
+ expect(slim.sparsePropertyKeys[0]).toBe('encrypt_at_rest');
37
39
  });
38
- it("buildProviderPromptPayload includes componentContext for queued componentIds", () => {
40
+ it('buildProviderPromptPayload includes componentContext for queued componentIds', () => {
39
41
  const components = [
40
42
  {
41
- id: "tp_1",
42
- name: "X",
43
- type: "third_party",
43
+ id: 'tp_1',
44
+ name: 'X',
45
+ type: 'third_party',
44
46
  confidence: 0.8,
45
47
  detectedFrom: [],
46
48
  sourceLocations: [],
@@ -48,84 +50,84 @@ describe("provider-prompt", () => {
48
50
  },
49
51
  ];
50
52
  const payload = (0, provider_prompt_1.buildProviderPromptPayload)({
51
- agent: "tpAgent",
53
+ agent: 'tpAgent',
52
54
  queue: [
53
55
  {
54
- id: "c1",
55
- candidateType: "third_party",
56
+ id: 'c1',
57
+ candidateType: 'third_party',
56
58
  priority: 90,
57
- componentId: "tp_1",
59
+ componentId: 'tp_1',
58
60
  missingFields: [],
59
- rationale: "test",
61
+ rationale: 'test',
60
62
  hints: [],
61
63
  },
62
64
  ],
63
65
  components,
64
66
  dataFlows: [],
65
67
  });
66
- expect(payload.agent).toBe("tpAgent");
68
+ expect(payload.agent).toBe('tpAgent');
67
69
  expect(payload.componentContext.tp_1).toBeDefined();
68
- expect(payload.componentContext.tp_1.name).toBe("X");
69
- expect(String(payload.instructions)).toContain("targetComponentId` must be exactly one of canonicalComponentIds");
70
- expect(String(payload.instructions)).toContain("data_action");
71
- expect(String(payload.instructions)).toContain("multiple");
72
- expect(payload.canonicalComponentIds).toEqual(["tp_1"]);
70
+ expect(payload.componentContext.tp_1.name).toBe('X');
71
+ expect(String(payload.instructions)).toContain('targetComponentId` must be exactly one of canonicalComponentIds');
72
+ expect(String(payload.instructions)).toContain('data_action');
73
+ expect(String(payload.instructions)).toContain('multiple');
74
+ expect(payload.canonicalComponentIds).toEqual(['tp_1']);
73
75
  });
74
- it("collectReferencedPathsForQueue includes flow endpoint component paths", () => {
76
+ it('collectReferencedPathsForQueue includes flow endpoint component paths', () => {
75
77
  const components = [
76
78
  {
77
- id: "a",
78
- name: "A",
79
- type: "asset",
79
+ id: 'a',
80
+ name: 'A',
81
+ type: 'asset',
80
82
  confidence: 0.9,
81
83
  detectedFrom: [],
82
- sourceLocations: [{ filePath: "src/a.ts", startLine: 1, endLine: 2 }],
84
+ sourceLocations: [{ filePath: 'src/a.ts', startLine: 1, endLine: 2 }],
83
85
  properties: {},
84
86
  },
85
87
  {
86
- id: "b",
87
- name: "B",
88
- type: "asset",
88
+ id: 'b',
89
+ name: 'B',
90
+ type: 'asset',
89
91
  confidence: 0.9,
90
92
  detectedFrom: [],
91
- sourceLocations: [{ filePath: "src/b.ts", startLine: 1, endLine: 2 }],
93
+ sourceLocations: [{ filePath: 'src/b.ts', startLine: 1, endLine: 2 }],
92
94
  properties: {},
93
95
  },
94
96
  ];
95
97
  const dataFlows = [
96
98
  {
97
- id: "f1",
98
- sourceComponentId: "a",
99
- targetComponentId: "b",
100
- type: "api_call",
99
+ id: 'f1',
100
+ sourceComponentId: 'a',
101
+ targetComponentId: 'b',
102
+ type: 'api_call',
101
103
  confidence: 0.8,
102
104
  },
103
105
  ];
104
106
  const paths = (0, provider_prompt_1.collectReferencedPathsForQueue)([
105
107
  {
106
- id: "c1",
107
- candidateType: "flow_direction",
108
+ id: 'c1',
109
+ candidateType: 'flow_direction',
108
110
  priority: 1,
109
- flowId: "f1",
111
+ flowId: 'f1',
110
112
  missingFields: [],
111
- rationale: "",
113
+ rationale: '',
112
114
  hints: [],
113
115
  },
114
116
  ], components, dataFlows);
115
- expect(paths).toEqual(["src/a.ts", "src/b.ts"]);
117
+ expect(paths).toEqual(['src/a.ts', 'src/b.ts']);
116
118
  });
117
- it("buildFileExcerptsForQueue maps scan files to referenced paths", () => {
119
+ it('buildFileExcerptsForQueue maps scan files to referenced paths', () => {
118
120
  const components = [
119
121
  {
120
- id: "tp_1",
121
- name: "X",
122
- type: "third_party",
122
+ id: 'tp_1',
123
+ name: 'X',
124
+ type: 'third_party',
123
125
  confidence: 0.8,
124
126
  detectedFrom: [
125
127
  {
126
- pattern: "external_api_call",
128
+ pattern: 'external_api_call',
127
129
  sourceLocation: {
128
- filePath: "pkg/handler.ts",
130
+ filePath: 'pkg/handler.ts',
129
131
  startLine: 10,
130
132
  endLine: 12,
131
133
  },
@@ -137,38 +139,38 @@ describe("provider-prompt", () => {
137
139
  ];
138
140
  const files = [
139
141
  {
140
- path: "pkg/handler.ts",
141
- name: "handler.ts",
142
- content: "export const x = 1;\n",
143
- language: "typescript",
142
+ path: 'pkg/handler.ts',
143
+ name: 'handler.ts',
144
+ content: 'export const x = 1;\n',
145
+ language: 'typescript',
144
146
  size: 20,
145
147
  },
146
148
  ];
147
149
  const excerpts = (0, provider_prompt_1.buildFileExcerptsForQueue)(files, [
148
150
  {
149
- id: "c1",
150
- candidateType: "third_party",
151
+ id: 'c1',
152
+ candidateType: 'third_party',
151
153
  priority: 1,
152
- componentId: "tp_1",
154
+ componentId: 'tp_1',
153
155
  missingFields: [],
154
- rationale: "",
156
+ rationale: '',
155
157
  hints: [],
156
158
  },
157
159
  ], components, []);
158
- expect(excerpts["pkg/handler.ts"]).toContain("export const x");
160
+ expect(excerpts['pkg/handler.ts']).toContain('export const x');
159
161
  });
160
- it("buildProviderPromptPayload adds relevantFileContents when files match queue", () => {
162
+ it('buildProviderPromptPayload adds relevantFileContents when files match queue', () => {
161
163
  const components = [
162
164
  {
163
- id: "tp_1",
164
- name: "X",
165
- type: "third_party",
165
+ id: 'tp_1',
166
+ name: 'X',
167
+ type: 'third_party',
166
168
  confidence: 0.8,
167
169
  detectedFrom: [
168
170
  {
169
- pattern: "external_api_call",
171
+ pattern: 'external_api_call',
170
172
  sourceLocation: {
171
- filePath: "lib/x.ts",
173
+ filePath: 'lib/x.ts',
172
174
  startLine: 1,
173
175
  endLine: 1,
174
176
  },
@@ -179,15 +181,15 @@ describe("provider-prompt", () => {
179
181
  },
180
182
  ];
181
183
  const payload = (0, provider_prompt_1.buildProviderPromptPayload)({
182
- agent: "tpAgent",
184
+ agent: 'tpAgent',
183
185
  queue: [
184
186
  {
185
- id: "c1",
186
- candidateType: "third_party",
187
+ id: 'c1',
188
+ candidateType: 'third_party',
187
189
  priority: 1,
188
- componentId: "tp_1",
190
+ componentId: 'tp_1',
189
191
  missingFields: [],
190
- rationale: "",
192
+ rationale: '',
191
193
  hints: [],
192
194
  },
193
195
  ],
@@ -195,14 +197,15 @@ describe("provider-prompt", () => {
195
197
  dataFlows: [],
196
198
  files: [
197
199
  {
198
- path: "lib/x.ts",
199
- name: "x.ts",
200
- content: "void 0;",
201
- language: "typescript",
200
+ path: 'lib/x.ts',
201
+ name: 'x.ts',
202
+ content: 'void 0;',
203
+ language: 'typescript',
202
204
  size: 6,
203
205
  },
204
206
  ],
205
207
  });
206
- expect(payload.relevantFileContents?.["lib/x.ts"]).toBe("void 0;");
208
+ expect(payload
209
+ .relevantFileContents?.['lib/x.ts']).toBe('void 0;');
207
210
  });
208
211
  });
@@ -0,0 +1,227 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const red_flags_1 = require("../../../src/ai-enrichment/red-flags");
4
+ const fallbacks_1 = require("../../../src/ai-enrichment/fallbacks");
5
+ const provider_topology_rules_1 = require("../../../src/ai-enrichment/provider-topology-rules");
6
+ const json_1 = require("../../../src/output/json");
7
+ describe('connectivity red flags', () => {
8
+ beforeEach(() => {
9
+ (0, provider_topology_rules_1.clearProviderTopologyRulesCacheForTest)();
10
+ });
11
+ it('absorbs a serverless handler into Aws Lambda and wires the section hub', () => {
12
+ const components = [
13
+ {
14
+ id: 'hub_backend',
15
+ name: 'backend',
16
+ type: 'asset',
17
+ subType: 'application',
18
+ confidence: 1,
19
+ detectedFrom: [],
20
+ sourceLocations: [],
21
+ properties: {
22
+ section_id: 'backend',
23
+ section_label: 'backend',
24
+ isMainApplication: true,
25
+ },
26
+ },
27
+ {
28
+ id: 'cmp_lambda',
29
+ name: 'Aws Lambda',
30
+ type: 'asset',
31
+ subType: 'compute_service',
32
+ confidence: 0.9,
33
+ detectedFrom: [],
34
+ sourceLocations: [],
35
+ properties: {
36
+ section_id: 'backend',
37
+ section_label: 'backend',
38
+ managed_service_key: 'lambda',
39
+ },
40
+ },
41
+ {
42
+ id: 'handler_lambda',
43
+ name: 'Aws Lambda Handler',
44
+ type: 'asset',
45
+ subType: 'function',
46
+ confidence: 0.9,
47
+ detectedFrom: [{ pattern: 'lambda_handler' }],
48
+ sourceLocations: [
49
+ {
50
+ filePath: 'backend/src/lambda.ts',
51
+ startLine: 72,
52
+ endLine: 72,
53
+ },
54
+ ],
55
+ properties: {
56
+ section_id: 'backend',
57
+ section_label: 'backend',
58
+ handlerType: 'serverless_handler',
59
+ },
60
+ },
61
+ ];
62
+ const collapsed = (0, red_flags_1.collapseServerlessHandlersIntoManagedLambda)(components, []);
63
+ expect(collapsed.components.some((c) => c.id === 'handler_lambda')).toBe(false);
64
+ const lambda = collapsed.components.find((c) => c.id === 'cmp_lambda');
65
+ expect(lambda).toBeDefined();
66
+ expect(lambda?.sourceLocations).toEqual(expect.arrayContaining([
67
+ expect.objectContaining({
68
+ filePath: 'backend/src/lambda.ts',
69
+ startLine: 72,
70
+ }),
71
+ ]));
72
+ expect(collapsed.dataFlows.some((f) => f.sourceComponentId === 'hub_backend' &&
73
+ f.targetComponentId === 'cmp_lambda' &&
74
+ f.enrichmentNotes === 'section_hub_to_managed_lambda')).toBe(true);
75
+ const flags = (0, red_flags_1.collectRedFlags)(collapsed.components, collapsed.dataFlows);
76
+ expect(flags.find((f) => f.code === 'disconnected_handler')).toBeUndefined();
77
+ });
78
+ it('creates Aws Lambda when absorbing a handler with no managed node yet', () => {
79
+ const components = [
80
+ {
81
+ id: 'hub_backend',
82
+ name: 'backend',
83
+ type: 'asset',
84
+ subType: 'application',
85
+ confidence: 1,
86
+ detectedFrom: [],
87
+ sourceLocations: [],
88
+ properties: {
89
+ section_id: 'backend',
90
+ isMainApplication: true,
91
+ },
92
+ },
93
+ {
94
+ id: 'handler_only',
95
+ name: 'orphan handler',
96
+ type: 'asset',
97
+ subType: 'function',
98
+ confidence: 0.9,
99
+ detectedFrom: [{ pattern: 'lambda_handler' }],
100
+ sourceLocations: [
101
+ { filePath: 'backend/handler.ts', startLine: 7, endLine: 7 },
102
+ ],
103
+ properties: {
104
+ section_id: 'backend',
105
+ section_label: 'backend',
106
+ handlerType: 'serverless_handler',
107
+ },
108
+ },
109
+ ];
110
+ const collapsed = (0, red_flags_1.collapseServerlessHandlersIntoManagedLambda)(components, []);
111
+ expect(collapsed.components.some((c) => c.id === 'handler_only')).toBe(false);
112
+ const lambda = collapsed.components.find((c) => c.properties?.managed_service_key === 'lambda');
113
+ expect(lambda).toBeDefined();
114
+ expect(lambda?.name).toBe('Aws Lambda');
115
+ expect(lambda?.sourceLocations?.[0]?.filePath).toBe('backend/handler.ts');
116
+ expect(collapsed.dataFlows.some((f) => f.sourceComponentId === 'hub_backend' &&
117
+ f.targetComponentId === lambda?.id)).toBe(true);
118
+ const flags = (0, red_flags_1.collectRedFlags)(collapsed.components, collapsed.dataFlows);
119
+ expect(flags.some((f) => f.code === 'disconnected_handler')).toBe(false);
120
+ expect((0, red_flags_1.formatRedFlagWarning)({
121
+ code: 'missing_section_hub',
122
+ severity: 'red',
123
+ sectionId: 'x',
124
+ message: 'm',
125
+ })).toMatch(/^red-flag:/);
126
+ });
127
+ it('end-to-end fallbacks + red-flag pass absorb a lone backend handler', () => {
128
+ const components = [
129
+ {
130
+ id: 'handler_lambda',
131
+ name: 'Aws Lambda Handler',
132
+ type: 'asset',
133
+ subType: 'function',
134
+ confidence: 0.9,
135
+ detectedFrom: [{ pattern: 'lambda_handler' }],
136
+ sourceLocations: [
137
+ { filePath: 'backend/handler.ts', startLine: 1, endLine: 1 },
138
+ ],
139
+ properties: {
140
+ section_id: 'backend',
141
+ section_label: 'backend',
142
+ section_role: 'service',
143
+ handlerType: 'serverless_handler',
144
+ },
145
+ },
146
+ ];
147
+ const fallback = (0, fallbacks_1.applyDeterministicInferenceFallbacks)(components, []);
148
+ const pass = (0, red_flags_1.applyConnectivityRedFlagPass)(fallback.components, fallback.dataFlows);
149
+ const hub = pass.components.find((c) => c.properties?.section_id === 'backend' &&
150
+ (c.properties?.isMainApplication === true ||
151
+ c.properties?.isMainApplication === 'true'));
152
+ expect(hub).toBeDefined();
153
+ expect(pass.components.some((c) => c.id === 'handler_lambda')).toBe(false);
154
+ const lambda = pass.components.find((c) => c.properties?.managed_service_key === 'lambda');
155
+ expect(lambda).toBeDefined();
156
+ expect(pass.dataFlows.some((f) => f.sourceComponentId === hub?.id && f.targetComponentId === lambda?.id)).toBe(true);
157
+ expect(pass.redFlags.filter((f) => f.code === 'disconnected_handler' || f.code === 'missing_section_hub')).toHaveLength(0);
158
+ });
159
+ it('flags disconnected non-handler section nodes that remain after repair', () => {
160
+ const components = [
161
+ {
162
+ id: 'hub',
163
+ name: 'backend',
164
+ type: 'asset',
165
+ subType: 'application',
166
+ confidence: 1,
167
+ detectedFrom: [],
168
+ sourceLocations: [],
169
+ properties: {
170
+ section_id: 'backend',
171
+ isMainApplication: true,
172
+ },
173
+ },
174
+ {
175
+ id: 'lonely_db',
176
+ name: 'Orphan Cache',
177
+ type: 'asset',
178
+ subType: 'cache',
179
+ confidence: 1,
180
+ detectedFrom: [],
181
+ sourceLocations: [],
182
+ properties: { section_id: 'backend' },
183
+ },
184
+ ];
185
+ const flows = [];
186
+ const flags = (0, red_flags_1.collectRedFlags)(components, flows);
187
+ expect(flags.some((f) => f.code === 'disconnected_section_node' &&
188
+ f.componentId === 'lonely_db')).toBe(true);
189
+ });
190
+ it('embeds redFlags into dataflow metadata when present', () => {
191
+ const scanResult = {
192
+ components: [],
193
+ dataFlows: [],
194
+ filesScanned: 0,
195
+ filesSkipped: 0,
196
+ totalLines: 0,
197
+ scanDurationMs: 1,
198
+ warnings: [],
199
+ errors: [],
200
+ };
201
+ const graph = {
202
+ nodes: [],
203
+ edges: [],
204
+ };
205
+ const wrapper = (0, json_1.buildDataflowWrapper)(scanResult, graph, {
206
+ projectName: 'test',
207
+ redFlags: [
208
+ {
209
+ code: 'disconnected_handler',
210
+ severity: 'red',
211
+ sectionId: 'backend',
212
+ componentId: 'handler_1',
213
+ message: 'Handler disconnected',
214
+ },
215
+ ],
216
+ });
217
+ expect(wrapper.metadata.redFlags).toEqual([
218
+ {
219
+ code: 'disconnected_handler',
220
+ severity: 'red',
221
+ sectionId: 'backend',
222
+ componentId: 'handler_1',
223
+ message: 'Handler disconnected',
224
+ },
225
+ ]);
226
+ });
227
+ });
@@ -4,35 +4,39 @@ const third_party_evidence_1 = require("../../../src/ai-enrichment/third-party-e
4
4
  function candidate(componentId) {
5
5
  return {
6
6
  id: `cand_${componentId}`,
7
- candidateType: "third_party",
7
+ candidateType: 'third_party',
8
8
  priority: 90,
9
9
  componentId,
10
- missingFields: ["vendor", "api_type", "authentication_method"],
11
- rationale: "fill sparse third-party properties from evidence",
10
+ missingFields: ['vendor', 'api_type', 'authentication_method'],
11
+ rationale: 'fill sparse third-party properties from evidence',
12
12
  hints: [],
13
13
  };
14
14
  }
15
15
  function component() {
16
16
  return {
17
- id: "cmp_tp_1",
18
- name: "Stripe",
19
- type: "third_party",
17
+ id: 'cmp_tp_1',
18
+ name: 'Stripe',
19
+ type: 'third_party',
20
20
  confidence: 0.9,
21
21
  detectedFrom: [
22
22
  {
23
- pattern: "external_api_call",
23
+ pattern: 'external_api_call',
24
24
  sourceLocation: {
25
- filePath: "backend/services/payments/index.ts",
25
+ filePath: 'backend/services/payments/index.ts',
26
26
  startLine: 1,
27
27
  endLine: 1,
28
28
  },
29
29
  },
30
30
  ],
31
31
  sourceLocations: [
32
- { filePath: "backend/services/payments/index.ts", startLine: 1, endLine: 1 },
32
+ {
33
+ filePath: 'backend/services/payments/index.ts',
34
+ startLine: 1,
35
+ endLine: 1,
36
+ },
33
37
  ],
34
38
  properties: {
35
- section_id: "backend/services/payments",
39
+ section_id: 'backend/services/payments',
36
40
  vendor: null,
37
41
  serviceName: null,
38
42
  client: null,
@@ -50,55 +54,55 @@ function component() {
50
54
  function files() {
51
55
  return [
52
56
  {
53
- path: "backend/services/payments/index.ts",
54
- name: "index.ts",
55
- language: "typescript",
57
+ path: 'backend/services/payments/index.ts',
58
+ name: 'index.ts',
59
+ language: 'typescript',
56
60
  size: 200,
57
61
  content: [
58
62
  'import Stripe from "stripe";',
59
- "const client = new Stripe(process.env.STRIPE_API_KEY || \"\", { apiVersion: \"2023-10-16\" });",
60
- "await fetch(\"https://api.stripe.com/v1/customers\", {",
61
- " headers: { Authorization: `Bearer ${process.env.STRIPE_API_KEY}` }",
62
- "});",
63
- ].join("\n"),
63
+ 'const client = new Stripe(process.env.STRIPE_API_KEY || "", { apiVersion: "2023-10-16" });',
64
+ 'await fetch("https://api.stripe.com/v1/customers", {',
65
+ ' headers: { Authorization: `Bearer ${process.env.STRIPE_API_KEY}` }',
66
+ '});',
67
+ ].join('\n'),
64
68
  },
65
69
  {
66
- path: "backend/services/payments/package.json",
67
- name: "package.json",
68
- language: "json",
70
+ path: 'backend/services/payments/package.json',
71
+ name: 'package.json',
72
+ language: 'json',
69
73
  size: 80,
70
74
  content: JSON.stringify({
71
75
  dependencies: {
72
- stripe: "^17.0.0",
76
+ stripe: '^17.0.0',
73
77
  },
74
78
  }),
75
79
  },
76
80
  ];
77
81
  }
78
- describe("third-party evidence enrichment", () => {
79
- it("builds an evidence-backed proposal for sparse third-party fields", () => {
82
+ describe('third-party evidence enrichment', () => {
83
+ it('builds an evidence-backed proposal for sparse third-party fields', () => {
80
84
  const proposal = (0, third_party_evidence_1.buildThirdPartyHeuristicProposal)({
81
- candidate: candidate("cmp_tp_1"),
85
+ candidate: candidate('cmp_tp_1'),
82
86
  component: component(),
83
87
  files: files(),
84
88
  });
85
89
  expect(proposal).toBeDefined();
86
- expect(proposal?.kind).toBe("component_patch");
87
- expect(proposal?.setProperties.vendor).toBe("Stripe");
88
- expect(proposal?.setProperties.authentication_method).toBe("bearer_token");
89
- expect(proposal?.setProperties.api_type).toBe("rest");
90
- expect(proposal?.setProperties.documentation_url).toBe("https://docs.stripe.com");
90
+ expect(proposal?.kind).toBe('component_patch');
91
+ expect(proposal?.setProperties.vendor).toBe('Stripe');
92
+ expect(proposal?.setProperties.authentication_method).toBe('bearer_token');
93
+ expect(proposal?.setProperties.api_type).toBe('rest');
94
+ expect(proposal?.setProperties.documentation_url).toBeUndefined();
91
95
  expect(proposal?.evidence.length).toBeGreaterThan(0);
92
96
  expect((0, third_party_evidence_1.verifyThirdPartyProposal)(proposal)).toEqual({ ok: true });
93
97
  });
94
- it("accepts proposals for additional fields when evidence is present", () => {
98
+ it('accepts proposals for additional fields when evidence is present', () => {
95
99
  const proposal = (0, third_party_evidence_1.buildThirdPartyHeuristicProposal)({
96
- candidate: candidate("cmp_tp_1"),
100
+ candidate: candidate('cmp_tp_1'),
97
101
  component: {
98
102
  ...component(),
99
103
  properties: {
100
104
  ...component().properties,
101
- vendor: "Stripe",
105
+ vendor: 'Stripe',
102
106
  vendor_soc2_iso27001: [],
103
107
  },
104
108
  },
@@ -107,7 +111,7 @@ describe("third-party evidence enrichment", () => {
107
111
  expect(proposal).toBeDefined();
108
112
  if (!proposal)
109
113
  return;
110
- proposal.setProperties.vendor_soc2_iso27001 = ["soc2"];
114
+ proposal.setProperties.vendor_soc2_iso27001 = ['soc2'];
111
115
  proposal.propertyEvidence = {
112
116
  ...(proposal.propertyEvidence ?? {}),
113
117
  vendor_soc2_iso27001: proposal.evidence.slice(0, 1),