@dataparade/cli 0.0.13 → 0.0.15
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/dist/package.json +2 -2
- package/dist/src/ai-enrichment/candidate-selector.d.ts +4 -4
- package/dist/src/ai-enrichment/candidate-selector.js +37 -32
- package/dist/src/ai-enrichment/fallbacks.js +130 -3
- package/dist/src/ai-enrichment/merge-rules.d.ts +3 -3
- package/dist/src/ai-enrichment/merge-rules.js +118 -40
- package/dist/src/ai-enrichment/prompts/provider-enrichment-prompts.d.ts +2 -2
- package/dist/src/ai-enrichment/prompts/provider-enrichment-prompts.js +3 -3
- package/dist/src/ai-enrichment/property-priority.d.ts +5 -0
- package/dist/src/ai-enrichment/property-priority.js +23 -0
- package/dist/src/ai-enrichment/provider-prompt.d.ts +5 -5
- package/dist/src/ai-enrichment/provider-prompt.js +24 -19
- package/dist/src/ai-enrichment/red-flags.d.ts +46 -0
- package/dist/src/ai-enrichment/red-flags.js +365 -0
- package/dist/src/ai-enrichment/third-party-evidence.d.ts +3 -3
- package/dist/src/ai-enrichment/third-party-evidence.js +96 -93
- package/dist/src/cli.d.ts +1 -1
- package/dist/src/cli.js +236 -143
- package/dist/src/core/pipeline/orchestrator-result.d.ts +9 -1
- package/dist/src/core/pipeline/orchestrator.d.ts +2 -2
- package/dist/src/core/pipeline/scan-pipeline.d.ts +2 -2
- package/dist/src/core/pipeline/scan-pipeline.js +46 -34
- package/dist/src/core/schema/dataflow-wrapper.schema.d.ts +33 -1
- package/dist/src/core/schema/dataflow-wrapper.schema.js +19 -3
- package/dist/src/output/json.d.ts +18 -3
- package/dist/src/output/json.js +14 -5
- package/dist/src/platform-api/cli-scan-failure-report.d.ts +9 -0
- package/dist/src/platform-api/cli-scan-failure-report.js +23 -0
- package/dist/tests/schema/dataflow-wrapper.schema.spec.js +142 -21
- package/dist/tests/unit/ai-enrichment/candidate-selector.spec.js +80 -49
- package/dist/tests/unit/ai-enrichment/fallbacks.spec.js +78 -0
- package/dist/tests/unit/ai-enrichment/merge-rules.spec.js +510 -264
- package/dist/tests/unit/ai-enrichment/provider-prompt.spec.js +80 -77
- package/dist/tests/unit/ai-enrichment/red-flags.spec.js +227 -0
- package/dist/tests/unit/ai-enrichment/third-party-evidence.spec.js +38 -34
- package/dist/tests/unit/cli/scan-command-e2e-backend-lambda-orphan.spec.d.ts +1 -0
- package/dist/tests/unit/cli/scan-command-e2e-backend-lambda-orphan.spec.js +60 -0
- package/dist/tests/unit/cli/scan-command-e2e-occupied-section-hubs.spec.d.ts +1 -0
- package/dist/tests/unit/cli/scan-command-e2e-occupied-section-hubs.spec.js +58 -0
- package/dist/tests/unit/cli/scan-command-e2e-ruby-basic.spec.d.ts +1 -0
- package/dist/tests/unit/cli/scan-command-e2e-ruby-basic.spec.js +46 -0
- package/dist/tests/unit/cli/scan-quota-flow.spec.js +57 -45
- package/dist/tests/unit/platform-api/cli-scan-failure-report.spec.d.ts +1 -0
- package/dist/tests/unit/platform-api/cli-scan-failure-report.spec.js +25 -0
- package/package.json +2 -2
- package/dist/tests/fixtures/e2e-ts-sample/db-client-import.d.ts +0 -2
- package/dist/tests/fixtures/e2e-ts-sample/db-client-import.js +0 -8
- package/dist/tests/fixtures/e2e-ts-sample/db.d.ts +0 -3
- package/dist/tests/fixtures/e2e-ts-sample/db.js +0 -7
- package/dist/tests/fixtures/e2e-ts-sample/external-api.d.ts +0 -1
- package/dist/tests/fixtures/e2e-ts-sample/external-api.js +0 -18
- package/dist/tests/fixtures/e2e-ts-sample/pg-client.d.ts +0 -3
- package/dist/tests/fixtures/e2e-ts-sample/pg-client.js +0 -7
- package/dist/tests/fixtures/e2e-ts-sample/server.d.ts +0 -14
- package/dist/tests/fixtures/e2e-ts-sample/server.js +0 -4
- package/dist/tests/fixtures/e2e-ts-sentry-route-env/server.js +0 -24
- package/dist/tests/fixtures/ingest-basic/src/index.d.ts +0 -1
- package/dist/tests/fixtures/ingest-basic/src/index.js +0 -6
- package/dist/tests/fixtures/mixed-language-basic/api.d.ts +0 -2
- package/dist/tests/fixtures/mixed-language-basic/api.js +0 -12
- package/dist/tests/fixtures/monorepo-app-plus-terraform/packages/app/app/route.d.ts +0 -1
- package/dist/tests/fixtures/monorepo-app-plus-terraform/packages/app/app/route.js +0 -6
- package/dist/tests/fixtures/monorepo-front-back-sections/backend/app/route.d.ts +0 -1
- package/dist/tests/fixtures/monorepo-front-back-sections/backend/app/route.js +0 -6
- package/dist/tests/fixtures/monorepo-front-back-sections/frontend/app/route.d.ts +0 -1
- package/dist/tests/fixtures/monorepo-front-back-sections/frontend/app/route.js +0 -7
- package/dist/tests/fixtures/typescript-basic/app/route.d.ts +0 -1
- package/dist/tests/fixtures/typescript-basic/app/route.js +0 -7
- package/dist/tests/fixtures/typescript-basic/db-client-import.d.ts +0 -2
- package/dist/tests/fixtures/typescript-basic/db-client-import.js +0 -8
- package/dist/tests/fixtures/typescript-basic/db.d.ts +0 -3
- package/dist/tests/fixtures/typescript-basic/db.js +0 -7
- package/dist/tests/fixtures/typescript-basic/external-api.d.ts +0 -1
- package/dist/tests/fixtures/typescript-basic/external-api.js +0 -18
- package/dist/tests/fixtures/typescript-basic/pg-client.d.ts +0 -3
- package/dist/tests/fixtures/typescript-basic/pg-client.js +0 -7
- package/dist/tests/fixtures/typescript-basic/server.d.ts +0 -14
- package/dist/tests/fixtures/typescript-basic/server.js +0 -4
- package/dist/tests/fixtures/typescript-dependency-manifests-basic/src/index.d.ts +0 -0
- package/dist/tests/fixtures/typescript-dependency-manifests-basic/src/index.js +0 -2
- /package/dist/tests/{fixtures/e2e-ts-sentry-route-env/server.d.ts → unit/ai-enrichment/red-flags.spec.d.ts} +0 -0
|
@@ -4,18 +4,18 @@ const merge_rules_1 = require("../../../src/ai-enrichment/merge-rules");
|
|
|
4
4
|
function makeBaseComponents() {
|
|
5
5
|
return [
|
|
6
6
|
{
|
|
7
|
-
id:
|
|
8
|
-
name:
|
|
9
|
-
type:
|
|
7
|
+
id: 'asset_frontend',
|
|
8
|
+
name: 'Frontend',
|
|
9
|
+
type: 'asset',
|
|
10
10
|
confidence: 0.9,
|
|
11
11
|
detectedFrom: [],
|
|
12
12
|
sourceLocations: [],
|
|
13
13
|
properties: {},
|
|
14
14
|
},
|
|
15
15
|
{
|
|
16
|
-
id:
|
|
17
|
-
name:
|
|
18
|
-
type:
|
|
16
|
+
id: 'asset_backend',
|
|
17
|
+
name: 'Backend',
|
|
18
|
+
type: 'asset',
|
|
19
19
|
confidence: 0.9,
|
|
20
20
|
detectedFrom: [],
|
|
21
21
|
sourceLocations: [],
|
|
@@ -26,26 +26,26 @@ function makeBaseComponents() {
|
|
|
26
26
|
function makeBaseFlows() {
|
|
27
27
|
return [
|
|
28
28
|
{
|
|
29
|
-
id:
|
|
30
|
-
sourceComponentId:
|
|
31
|
-
targetComponentId:
|
|
32
|
-
type:
|
|
29
|
+
id: 'flow_1',
|
|
30
|
+
sourceComponentId: 'asset_frontend',
|
|
31
|
+
targetComponentId: 'asset_backend',
|
|
32
|
+
type: 'api_call',
|
|
33
33
|
confidence: 0.8,
|
|
34
34
|
},
|
|
35
35
|
];
|
|
36
36
|
}
|
|
37
|
-
describe(
|
|
38
|
-
it(
|
|
37
|
+
describe('ai-enrichment merge rules', () => {
|
|
38
|
+
it('remaps provider component target from path alias to canonical component id', () => {
|
|
39
39
|
const components = [
|
|
40
40
|
{
|
|
41
|
-
id:
|
|
42
|
-
name:
|
|
43
|
-
type:
|
|
41
|
+
id: 'cmp_11',
|
|
42
|
+
name: 'auth-helper',
|
|
43
|
+
type: 'asset',
|
|
44
44
|
confidence: 0.9,
|
|
45
45
|
detectedFrom: [],
|
|
46
46
|
sourceLocations: [
|
|
47
47
|
{
|
|
48
|
-
filePath:
|
|
48
|
+
filePath: 'backend/lambdas/auth-helper/index.js',
|
|
49
49
|
startLine: 1,
|
|
50
50
|
endLine: 20,
|
|
51
51
|
},
|
|
@@ -55,120 +55,120 @@ describe("ai-enrichment merge rules", () => {
|
|
|
55
55
|
];
|
|
56
56
|
const proposals = [
|
|
57
57
|
{
|
|
58
|
-
id:
|
|
58
|
+
id: 'provider_1',
|
|
59
59
|
proposal: {
|
|
60
|
-
kind:
|
|
61
|
-
targetComponentId:
|
|
62
|
-
candidateType:
|
|
63
|
-
setProperties: { programming_language: [
|
|
64
|
-
confidence: { score: 0.82, band:
|
|
60
|
+
kind: 'component_patch',
|
|
61
|
+
targetComponentId: 'backend/lambdas/auth-helper',
|
|
62
|
+
candidateType: 'node_property',
|
|
63
|
+
setProperties: { programming_language: ['javascript'] },
|
|
64
|
+
confidence: { score: 0.82, band: 'high' },
|
|
65
65
|
evidence: [
|
|
66
66
|
{
|
|
67
|
-
filePath:
|
|
67
|
+
filePath: 'backend/lambdas/auth-helper/index.js',
|
|
68
68
|
startLine: 1,
|
|
69
69
|
endLine: 10,
|
|
70
|
-
reason:
|
|
70
|
+
reason: 'lambda source file',
|
|
71
71
|
},
|
|
72
72
|
],
|
|
73
|
-
provider:
|
|
74
|
-
model:
|
|
75
|
-
agent:
|
|
73
|
+
provider: 'openai',
|
|
74
|
+
model: 'gpt-4o-mini',
|
|
75
|
+
agent: 'propertyAgent',
|
|
76
76
|
},
|
|
77
77
|
},
|
|
78
78
|
];
|
|
79
79
|
const result = (0, merge_rules_1.mergeAiProposals)(components, [], proposals);
|
|
80
|
-
expect(result.appliedProposalIds).toEqual([
|
|
80
|
+
expect(result.appliedProposalIds).toEqual(['provider_1']);
|
|
81
81
|
expect(result.rejectedProposalIds).toEqual([]);
|
|
82
|
-
expect(result.components[0]?.id).toBe(
|
|
82
|
+
expect(result.components[0]?.id).toBe('cmp_11');
|
|
83
83
|
expect(result.components[0]?.properties.programming_language).toEqual([
|
|
84
|
-
|
|
84
|
+
'javascript',
|
|
85
85
|
]);
|
|
86
86
|
});
|
|
87
|
-
it(
|
|
87
|
+
it('applies only the highest-ranked proposal per target', () => {
|
|
88
88
|
const proposals = [
|
|
89
89
|
{
|
|
90
|
-
id:
|
|
90
|
+
id: 'p_low',
|
|
91
91
|
proposal: {
|
|
92
|
-
kind:
|
|
93
|
-
targetComponentId:
|
|
94
|
-
candidateType:
|
|
92
|
+
kind: 'component_patch',
|
|
93
|
+
targetComponentId: 'asset_backend',
|
|
94
|
+
candidateType: 'node_property',
|
|
95
95
|
setProperties: { pii: false },
|
|
96
|
-
confidence: { score: 0.8, band:
|
|
96
|
+
confidence: { score: 0.8, band: 'medium' },
|
|
97
97
|
evidence: [
|
|
98
98
|
{
|
|
99
|
-
filePath:
|
|
99
|
+
filePath: 'src/backend.ts',
|
|
100
100
|
startLine: 10,
|
|
101
101
|
endLine: 20,
|
|
102
|
-
reason:
|
|
102
|
+
reason: 'no pii path',
|
|
103
103
|
},
|
|
104
104
|
],
|
|
105
|
-
provider:
|
|
106
|
-
model:
|
|
107
|
-
agent:
|
|
105
|
+
provider: 'openai',
|
|
106
|
+
model: 'x',
|
|
107
|
+
agent: 'propertyAgent',
|
|
108
108
|
},
|
|
109
109
|
},
|
|
110
110
|
{
|
|
111
|
-
id:
|
|
111
|
+
id: 'p_high',
|
|
112
112
|
proposal: {
|
|
113
|
-
kind:
|
|
114
|
-
targetComponentId:
|
|
115
|
-
candidateType:
|
|
113
|
+
kind: 'component_patch',
|
|
114
|
+
targetComponentId: 'asset_backend',
|
|
115
|
+
candidateType: 'node_property',
|
|
116
116
|
setProperties: { pii: true },
|
|
117
|
-
confidence: { score: 0.92, band:
|
|
117
|
+
confidence: { score: 0.92, band: 'high' },
|
|
118
118
|
evidence: [
|
|
119
119
|
{
|
|
120
|
-
filePath:
|
|
120
|
+
filePath: 'src/backend.ts',
|
|
121
121
|
startLine: 10,
|
|
122
122
|
endLine: 20,
|
|
123
|
-
reason:
|
|
123
|
+
reason: 'user email persisted',
|
|
124
124
|
},
|
|
125
125
|
{
|
|
126
|
-
filePath:
|
|
126
|
+
filePath: 'src/db.ts',
|
|
127
127
|
startLine: 1,
|
|
128
128
|
endLine: 4,
|
|
129
|
-
reason:
|
|
129
|
+
reason: 'email column present',
|
|
130
130
|
},
|
|
131
131
|
],
|
|
132
|
-
provider:
|
|
133
|
-
model:
|
|
134
|
-
agent:
|
|
132
|
+
provider: 'openai',
|
|
133
|
+
model: 'x',
|
|
134
|
+
agent: 'propertyAgent',
|
|
135
135
|
},
|
|
136
136
|
},
|
|
137
137
|
];
|
|
138
138
|
const result = (0, merge_rules_1.mergeAiProposals)(makeBaseComponents(), makeBaseFlows(), proposals);
|
|
139
|
-
const backend = result.components.find((c) => c.id ===
|
|
139
|
+
const backend = result.components.find((c) => c.id === 'asset_backend');
|
|
140
140
|
expect(backend?.properties.pii).toBe(true);
|
|
141
|
-
expect(result.appliedProposalIds).toEqual([
|
|
141
|
+
expect(result.appliedProposalIds).toEqual(['p_high']);
|
|
142
142
|
expect(result.rejectedProposalIds).toEqual([
|
|
143
143
|
{
|
|
144
|
-
proposalId:
|
|
145
|
-
reason:
|
|
144
|
+
proposalId: 'p_low',
|
|
145
|
+
reason: 'target_already_modified_by_higher_ranked_proposal',
|
|
146
146
|
},
|
|
147
147
|
]);
|
|
148
148
|
});
|
|
149
|
-
it(
|
|
149
|
+
it('rejects flow inserts below insert threshold', () => {
|
|
150
150
|
const proposals = [
|
|
151
151
|
{
|
|
152
|
-
id:
|
|
152
|
+
id: 'insert_low_confidence',
|
|
153
153
|
proposal: {
|
|
154
|
-
kind:
|
|
155
|
-
candidateType:
|
|
154
|
+
kind: 'flow_patch',
|
|
155
|
+
candidateType: 'missing_interaction',
|
|
156
156
|
insertIfMissing: true,
|
|
157
|
-
sourceComponentId:
|
|
158
|
-
targetComponentId:
|
|
159
|
-
setType:
|
|
160
|
-
confidence: { score: 0.8, band:
|
|
157
|
+
sourceComponentId: 'asset_backend',
|
|
158
|
+
targetComponentId: 'asset_frontend',
|
|
159
|
+
setType: 'api_call',
|
|
160
|
+
confidence: { score: 0.8, band: 'medium' },
|
|
161
161
|
evidence: [
|
|
162
162
|
{
|
|
163
|
-
filePath:
|
|
163
|
+
filePath: 'src/api.ts',
|
|
164
164
|
startLine: 3,
|
|
165
165
|
endLine: 5,
|
|
166
|
-
reason:
|
|
166
|
+
reason: 'response mapper reference',
|
|
167
167
|
},
|
|
168
168
|
],
|
|
169
|
-
provider:
|
|
170
|
-
model:
|
|
171
|
-
agent:
|
|
169
|
+
provider: 'openai',
|
|
170
|
+
model: 'x',
|
|
171
|
+
agent: 'interactionAgent',
|
|
172
172
|
},
|
|
173
173
|
},
|
|
174
174
|
];
|
|
@@ -176,35 +176,35 @@ describe("ai-enrichment merge rules", () => {
|
|
|
176
176
|
expect(result.appliedProposalIds).toEqual([]);
|
|
177
177
|
expect(result.rejectedProposalIds).toEqual([
|
|
178
178
|
{
|
|
179
|
-
proposalId:
|
|
180
|
-
reason:
|
|
179
|
+
proposalId: 'insert_low_confidence',
|
|
180
|
+
reason: 'confidence_below_threshold:0.85',
|
|
181
181
|
},
|
|
182
182
|
]);
|
|
183
183
|
expect(result.dataFlows).toHaveLength(1);
|
|
184
184
|
});
|
|
185
|
-
it(
|
|
185
|
+
it('rejects flow_patch when preserving data-flow topology even above insert threshold', () => {
|
|
186
186
|
const proposals = [
|
|
187
187
|
{
|
|
188
|
-
id:
|
|
188
|
+
id: 'insert_high_confidence',
|
|
189
189
|
proposal: {
|
|
190
|
-
kind:
|
|
191
|
-
candidateType:
|
|
190
|
+
kind: 'flow_patch',
|
|
191
|
+
candidateType: 'missing_interaction',
|
|
192
192
|
insertIfMissing: true,
|
|
193
|
-
sourceComponentId:
|
|
194
|
-
targetComponentId:
|
|
195
|
-
setType:
|
|
196
|
-
confidence: { score: 0.95, band:
|
|
193
|
+
sourceComponentId: 'asset_backend',
|
|
194
|
+
targetComponentId: 'asset_frontend',
|
|
195
|
+
setType: 'api_call',
|
|
196
|
+
confidence: { score: 0.95, band: 'high' },
|
|
197
197
|
evidence: [
|
|
198
198
|
{
|
|
199
|
-
filePath:
|
|
199
|
+
filePath: 'src/api.ts',
|
|
200
200
|
startLine: 3,
|
|
201
201
|
endLine: 5,
|
|
202
|
-
reason:
|
|
202
|
+
reason: 'response mapper reference',
|
|
203
203
|
},
|
|
204
204
|
],
|
|
205
|
-
provider:
|
|
206
|
-
model:
|
|
207
|
-
agent:
|
|
205
|
+
provider: 'openai',
|
|
206
|
+
model: 'x',
|
|
207
|
+
agent: 'interactionAgent',
|
|
208
208
|
},
|
|
209
209
|
},
|
|
210
210
|
];
|
|
@@ -212,56 +212,56 @@ describe("ai-enrichment merge rules", () => {
|
|
|
212
212
|
expect(result.appliedProposalIds).toEqual([]);
|
|
213
213
|
expect(result.rejectedProposalIds).toEqual([
|
|
214
214
|
{
|
|
215
|
-
proposalId:
|
|
216
|
-
reason:
|
|
215
|
+
proposalId: 'insert_high_confidence',
|
|
216
|
+
reason: 'data_flow_topology_preserved',
|
|
217
217
|
},
|
|
218
218
|
]);
|
|
219
219
|
expect(result.dataFlows).toHaveLength(1);
|
|
220
|
-
expect(result.dataFlows[0]?.targetComponentId).toBe(
|
|
220
|
+
expect(result.dataFlows[0]?.targetComponentId).toBe('asset_backend');
|
|
221
221
|
});
|
|
222
|
-
it(
|
|
222
|
+
it('rejects flow_patch when intra-section gate is enabled and endpoints are in different sections', () => {
|
|
223
223
|
const components = [
|
|
224
224
|
{
|
|
225
|
-
id:
|
|
226
|
-
name:
|
|
227
|
-
type:
|
|
225
|
+
id: 'asset_frontend',
|
|
226
|
+
name: 'Frontend',
|
|
227
|
+
type: 'asset',
|
|
228
228
|
confidence: 0.9,
|
|
229
229
|
detectedFrom: [],
|
|
230
230
|
sourceLocations: [],
|
|
231
|
-
properties: { section_id:
|
|
231
|
+
properties: { section_id: 'frontend' },
|
|
232
232
|
},
|
|
233
233
|
{
|
|
234
|
-
id:
|
|
235
|
-
name:
|
|
236
|
-
type:
|
|
234
|
+
id: 'asset_backend',
|
|
235
|
+
name: 'Backend',
|
|
236
|
+
type: 'asset',
|
|
237
237
|
confidence: 0.9,
|
|
238
238
|
detectedFrom: [],
|
|
239
239
|
sourceLocations: [],
|
|
240
|
-
properties: { section_id:
|
|
240
|
+
properties: { section_id: 'backend' },
|
|
241
241
|
},
|
|
242
242
|
];
|
|
243
243
|
const proposals = [
|
|
244
244
|
{
|
|
245
|
-
id:
|
|
245
|
+
id: 'insert_cross_section',
|
|
246
246
|
proposal: {
|
|
247
|
-
kind:
|
|
248
|
-
candidateType:
|
|
247
|
+
kind: 'flow_patch',
|
|
248
|
+
candidateType: 'missing_interaction',
|
|
249
249
|
insertIfMissing: true,
|
|
250
|
-
sourceComponentId:
|
|
251
|
-
targetComponentId:
|
|
252
|
-
setType:
|
|
253
|
-
confidence: { score: 0.95, band:
|
|
250
|
+
sourceComponentId: 'asset_frontend',
|
|
251
|
+
targetComponentId: 'asset_backend',
|
|
252
|
+
setType: 'api_call',
|
|
253
|
+
confidence: { score: 0.95, band: 'high' },
|
|
254
254
|
evidence: [
|
|
255
255
|
{
|
|
256
|
-
filePath:
|
|
256
|
+
filePath: 'src/api.ts',
|
|
257
257
|
startLine: 3,
|
|
258
258
|
endLine: 5,
|
|
259
|
-
reason:
|
|
259
|
+
reason: 'request path observed',
|
|
260
260
|
},
|
|
261
261
|
],
|
|
262
|
-
provider:
|
|
263
|
-
model:
|
|
264
|
-
agent:
|
|
262
|
+
provider: 'openai',
|
|
263
|
+
model: 'x',
|
|
264
|
+
agent: 'interactionAgent',
|
|
265
265
|
},
|
|
266
266
|
},
|
|
267
267
|
];
|
|
@@ -271,67 +271,67 @@ describe("ai-enrichment merge rules", () => {
|
|
|
271
271
|
expect(result.appliedProposalIds).toEqual([]);
|
|
272
272
|
expect(result.rejectedProposalIds).toEqual([
|
|
273
273
|
{
|
|
274
|
-
proposalId:
|
|
275
|
-
reason:
|
|
274
|
+
proposalId: 'insert_cross_section',
|
|
275
|
+
reason: 'cross_section_flow_change_blocked',
|
|
276
276
|
},
|
|
277
277
|
]);
|
|
278
278
|
});
|
|
279
|
-
it(
|
|
279
|
+
it('applies flow_patch when intra-section gate is enabled and endpoints share a section', () => {
|
|
280
280
|
const components = [
|
|
281
281
|
{
|
|
282
|
-
id:
|
|
283
|
-
name:
|
|
284
|
-
type:
|
|
282
|
+
id: 'asset_frontend_api',
|
|
283
|
+
name: 'Frontend API',
|
|
284
|
+
type: 'asset',
|
|
285
285
|
confidence: 0.9,
|
|
286
286
|
detectedFrom: [],
|
|
287
287
|
sourceLocations: [],
|
|
288
|
-
properties: { section_id:
|
|
288
|
+
properties: { section_id: 'frontend' },
|
|
289
289
|
},
|
|
290
290
|
{
|
|
291
|
-
id:
|
|
292
|
-
name:
|
|
293
|
-
type:
|
|
291
|
+
id: 'asset_frontend_worker',
|
|
292
|
+
name: 'Frontend Worker',
|
|
293
|
+
type: 'asset',
|
|
294
294
|
confidence: 0.9,
|
|
295
295
|
detectedFrom: [],
|
|
296
296
|
sourceLocations: [],
|
|
297
|
-
properties: { section_id:
|
|
297
|
+
properties: { section_id: 'frontend' },
|
|
298
298
|
},
|
|
299
299
|
];
|
|
300
300
|
const proposals = [
|
|
301
301
|
{
|
|
302
|
-
id:
|
|
302
|
+
id: 'insert_same_section',
|
|
303
303
|
proposal: {
|
|
304
|
-
kind:
|
|
305
|
-
candidateType:
|
|
304
|
+
kind: 'flow_patch',
|
|
305
|
+
candidateType: 'missing_interaction',
|
|
306
306
|
insertIfMissing: true,
|
|
307
|
-
sourceComponentId:
|
|
308
|
-
targetComponentId:
|
|
309
|
-
setType:
|
|
310
|
-
confidence: { score: 0.95, band:
|
|
307
|
+
sourceComponentId: 'asset_frontend_api',
|
|
308
|
+
targetComponentId: 'asset_frontend_worker',
|
|
309
|
+
setType: 'api_call',
|
|
310
|
+
confidence: { score: 0.95, band: 'high' },
|
|
311
311
|
evidence: [
|
|
312
312
|
{
|
|
313
|
-
filePath:
|
|
313
|
+
filePath: 'src/frontend.ts',
|
|
314
314
|
startLine: 12,
|
|
315
315
|
endLine: 20,
|
|
316
|
-
reason:
|
|
316
|
+
reason: 'internal call observed',
|
|
317
317
|
},
|
|
318
318
|
],
|
|
319
|
-
provider:
|
|
320
|
-
model:
|
|
321
|
-
agent:
|
|
319
|
+
provider: 'openai',
|
|
320
|
+
model: 'x',
|
|
321
|
+
agent: 'interactionAgent',
|
|
322
322
|
},
|
|
323
323
|
},
|
|
324
324
|
];
|
|
325
325
|
const result = (0, merge_rules_1.mergeAiProposals)(components, [], proposals, {}, {
|
|
326
326
|
enforceIntraSectionFlowChangesOnly: true,
|
|
327
327
|
});
|
|
328
|
-
expect(result.appliedProposalIds).toEqual([
|
|
328
|
+
expect(result.appliedProposalIds).toEqual(['insert_same_section']);
|
|
329
329
|
expect(result.rejectedProposalIds).toEqual([]);
|
|
330
330
|
expect(result.dataFlows).toHaveLength(1);
|
|
331
|
-
expect(result.dataFlows[0]?.sourceComponentId).toBe(
|
|
332
|
-
expect(result.dataFlows[0]?.targetComponentId).toBe(
|
|
331
|
+
expect(result.dataFlows[0]?.sourceComponentId).toBe('asset_frontend_api');
|
|
332
|
+
expect(result.dataFlows[0]?.targetComponentId).toBe('asset_frontend_worker');
|
|
333
333
|
});
|
|
334
|
-
it(
|
|
334
|
+
it('rejects component patch when all updates are no-op or empty-equivalent', () => {
|
|
335
335
|
const components = makeBaseComponents();
|
|
336
336
|
components[1].properties = {
|
|
337
337
|
inference_status: undefined,
|
|
@@ -341,37 +341,37 @@ describe("ai-enrichment merge rules", () => {
|
|
|
341
341
|
};
|
|
342
342
|
const proposals = [
|
|
343
343
|
{
|
|
344
|
-
id:
|
|
344
|
+
id: 'p_noop',
|
|
345
345
|
proposal: {
|
|
346
|
-
kind:
|
|
347
|
-
targetComponentId:
|
|
348
|
-
candidateType:
|
|
346
|
+
kind: 'component_patch',
|
|
347
|
+
targetComponentId: 'asset_backend',
|
|
348
|
+
candidateType: 'node_property',
|
|
349
349
|
setProperties: {
|
|
350
|
-
inference_status:
|
|
351
|
-
api_versioning_strategy:
|
|
350
|
+
inference_status: 'needs_review',
|
|
351
|
+
api_versioning_strategy: 'none',
|
|
352
352
|
access_controls_for_delivery: null,
|
|
353
353
|
cloud_services_used: null,
|
|
354
354
|
},
|
|
355
|
-
confidence: { score: 0.9, band:
|
|
355
|
+
confidence: { score: 0.9, band: 'high' },
|
|
356
356
|
evidence: [
|
|
357
357
|
{
|
|
358
|
-
filePath:
|
|
358
|
+
filePath: 'src/backend.ts',
|
|
359
359
|
startLine: 1,
|
|
360
360
|
endLine: 2,
|
|
361
|
-
reason:
|
|
361
|
+
reason: 'existing metadata only',
|
|
362
362
|
},
|
|
363
363
|
],
|
|
364
|
-
provider:
|
|
365
|
-
model:
|
|
366
|
-
agent:
|
|
364
|
+
provider: 'openai',
|
|
365
|
+
model: 'x',
|
|
366
|
+
agent: 'propertyAgent',
|
|
367
367
|
},
|
|
368
368
|
},
|
|
369
369
|
];
|
|
370
370
|
const result = (0, merge_rules_1.mergeAiProposals)(components, makeBaseFlows(), proposals);
|
|
371
|
-
const backend = result.components.find((c) => c.id ===
|
|
371
|
+
const backend = result.components.find((c) => c.id === 'asset_backend');
|
|
372
372
|
expect(result.appliedProposalIds).toEqual([]);
|
|
373
373
|
expect(result.rejectedProposalIds).toEqual([
|
|
374
|
-
{ proposalId:
|
|
374
|
+
{ proposalId: 'p_noop', reason: 'no_meaningful_changes' },
|
|
375
375
|
]);
|
|
376
376
|
expect(backend?.properties).toEqual({
|
|
377
377
|
inference_status: undefined,
|
|
@@ -380,7 +380,7 @@ describe("ai-enrichment merge rules", () => {
|
|
|
380
380
|
cloud_services_used: [],
|
|
381
381
|
});
|
|
382
382
|
});
|
|
383
|
-
it(
|
|
383
|
+
it('applies component patch when at least one property meaningfully changes', () => {
|
|
384
384
|
const components = makeBaseComponents();
|
|
385
385
|
components[1].properties = {
|
|
386
386
|
cloud_services_used: [],
|
|
@@ -388,187 +388,187 @@ describe("ai-enrichment merge rules", () => {
|
|
|
388
388
|
};
|
|
389
389
|
const proposals = [
|
|
390
390
|
{
|
|
391
|
-
id:
|
|
391
|
+
id: 'p_meaningful',
|
|
392
392
|
proposal: {
|
|
393
|
-
kind:
|
|
394
|
-
targetComponentId:
|
|
395
|
-
candidateType:
|
|
393
|
+
kind: 'component_patch',
|
|
394
|
+
targetComponentId: 'asset_backend',
|
|
395
|
+
candidateType: 'node_property',
|
|
396
396
|
setProperties: {
|
|
397
|
-
inference_status:
|
|
398
|
-
cloud_services_used: [
|
|
397
|
+
inference_status: 'needs_review',
|
|
398
|
+
cloud_services_used: ['aws'],
|
|
399
399
|
},
|
|
400
|
-
confidence: { score: 0.9, band:
|
|
400
|
+
confidence: { score: 0.9, band: 'high' },
|
|
401
401
|
evidence: [
|
|
402
402
|
{
|
|
403
|
-
filePath:
|
|
403
|
+
filePath: 'src/backend.ts',
|
|
404
404
|
startLine: 1,
|
|
405
405
|
endLine: 2,
|
|
406
|
-
reason:
|
|
406
|
+
reason: 'cloud provider usage',
|
|
407
407
|
},
|
|
408
408
|
],
|
|
409
|
-
provider:
|
|
410
|
-
model:
|
|
411
|
-
agent:
|
|
409
|
+
provider: 'openai',
|
|
410
|
+
model: 'x',
|
|
411
|
+
agent: 'propertyAgent',
|
|
412
412
|
},
|
|
413
413
|
},
|
|
414
414
|
];
|
|
415
415
|
const result = (0, merge_rules_1.mergeAiProposals)(components, makeBaseFlows(), proposals);
|
|
416
|
-
const backend = result.components.find((c) => c.id ===
|
|
417
|
-
expect(result.appliedProposalIds).toEqual([
|
|
416
|
+
const backend = result.components.find((c) => c.id === 'asset_backend');
|
|
417
|
+
expect(result.appliedProposalIds).toEqual(['p_meaningful']);
|
|
418
418
|
expect(result.rejectedProposalIds).toEqual([]);
|
|
419
419
|
expect(backend?.properties.inference_status).toBeUndefined();
|
|
420
|
-
expect(backend?.properties.cloud_services_used).toEqual([
|
|
420
|
+
expect(backend?.properties.cloud_services_used).toEqual(['aws']);
|
|
421
421
|
});
|
|
422
|
-
it(
|
|
422
|
+
it('merges AI data_action verbs into dataActions without removing deterministic assignments', () => {
|
|
423
423
|
const components = makeBaseComponents();
|
|
424
424
|
components[1].properties = {
|
|
425
425
|
dataActions: [
|
|
426
426
|
{
|
|
427
|
-
action:
|
|
428
|
-
source:
|
|
427
|
+
action: 'store',
|
|
428
|
+
source: 'deterministic',
|
|
429
429
|
confidence: 1,
|
|
430
|
-
status:
|
|
430
|
+
status: 'asserted',
|
|
431
431
|
evidence: {
|
|
432
|
-
kind:
|
|
433
|
-
description:
|
|
432
|
+
kind: 'storage_subtype',
|
|
433
|
+
description: 'database subtype',
|
|
434
434
|
},
|
|
435
435
|
},
|
|
436
436
|
{
|
|
437
|
-
action:
|
|
438
|
-
source:
|
|
437
|
+
action: 'disclose',
|
|
438
|
+
source: 'user',
|
|
439
439
|
confidence: 1,
|
|
440
|
-
status:
|
|
440
|
+
status: 'asserted',
|
|
441
441
|
evidence: [
|
|
442
442
|
{
|
|
443
|
-
filePath:
|
|
443
|
+
filePath: 'src/backend.ts',
|
|
444
444
|
startLine: 1,
|
|
445
445
|
endLine: 2,
|
|
446
|
-
reason:
|
|
446
|
+
reason: 'user confirmed outbound share',
|
|
447
447
|
},
|
|
448
448
|
],
|
|
449
449
|
},
|
|
450
450
|
],
|
|
451
|
-
primaryDataAction:
|
|
451
|
+
primaryDataAction: 'store',
|
|
452
452
|
};
|
|
453
453
|
const proposals = [
|
|
454
454
|
{
|
|
455
|
-
id:
|
|
455
|
+
id: 'p_data_actions',
|
|
456
456
|
proposal: {
|
|
457
|
-
kind:
|
|
458
|
-
targetComponentId:
|
|
459
|
-
candidateType:
|
|
457
|
+
kind: 'component_patch',
|
|
458
|
+
targetComponentId: 'asset_backend',
|
|
459
|
+
candidateType: 'node_property',
|
|
460
460
|
setProperties: {
|
|
461
|
-
data_action: [
|
|
461
|
+
data_action: ['log', 'store'],
|
|
462
462
|
},
|
|
463
463
|
propertyEvidence: {
|
|
464
464
|
data_action: [
|
|
465
465
|
{
|
|
466
|
-
filePath:
|
|
466
|
+
filePath: 'src/backend.ts',
|
|
467
467
|
startLine: 40,
|
|
468
468
|
endLine: 42,
|
|
469
|
-
reason:
|
|
469
|
+
reason: 'logger.info email',
|
|
470
470
|
},
|
|
471
471
|
],
|
|
472
472
|
},
|
|
473
|
-
confidence: { score: 0.88, band:
|
|
473
|
+
confidence: { score: 0.88, band: 'high' },
|
|
474
474
|
evidence: [
|
|
475
475
|
{
|
|
476
|
-
filePath:
|
|
476
|
+
filePath: 'src/backend.ts',
|
|
477
477
|
startLine: 40,
|
|
478
478
|
endLine: 42,
|
|
479
|
-
reason:
|
|
479
|
+
reason: 'logger.info email',
|
|
480
480
|
},
|
|
481
481
|
],
|
|
482
|
-
provider:
|
|
483
|
-
model:
|
|
484
|
-
agent:
|
|
482
|
+
provider: 'openai',
|
|
483
|
+
model: 'x',
|
|
484
|
+
agent: 'propertyAgent',
|
|
485
485
|
},
|
|
486
486
|
},
|
|
487
487
|
];
|
|
488
488
|
const result = (0, merge_rules_1.mergeAiProposals)(components, makeBaseFlows(), proposals);
|
|
489
|
-
const backend = result.components.find((c) => c.id ===
|
|
489
|
+
const backend = result.components.find((c) => c.id === 'asset_backend');
|
|
490
490
|
const actions = backend?.properties.dataActions;
|
|
491
|
-
expect(result.appliedProposalIds).toEqual([
|
|
491
|
+
expect(result.appliedProposalIds).toEqual(['p_data_actions']);
|
|
492
492
|
expect(actions?.map((a) => a.action).sort()).toEqual([
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
493
|
+
'disclose',
|
|
494
|
+
'log',
|
|
495
|
+
'store',
|
|
496
496
|
]);
|
|
497
|
-
expect(actions?.find((a) => a.action ===
|
|
498
|
-
expect(actions?.find((a) => a.action ===
|
|
499
|
-
expect(actions?.find((a) => a.action ===
|
|
497
|
+
expect(actions?.find((a) => a.action === 'store')?.source).toBe('deterministic');
|
|
498
|
+
expect(actions?.find((a) => a.action === 'disclose')?.source).toBe('user');
|
|
499
|
+
expect(actions?.find((a) => a.action === 'log')?.source).toBe('ai');
|
|
500
500
|
expect(backend?.properties.data_action).toBeUndefined();
|
|
501
501
|
expect(backend?.properties.primaryDataAction).toBeDefined();
|
|
502
502
|
});
|
|
503
|
-
it(
|
|
503
|
+
it('rejects data_action merge below 0.72 confidence and leaves deterministic verbs intact', () => {
|
|
504
504
|
const components = makeBaseComponents();
|
|
505
505
|
components[1].properties = {
|
|
506
506
|
dataActions: [
|
|
507
507
|
{
|
|
508
|
-
action:
|
|
509
|
-
source:
|
|
508
|
+
action: 'store',
|
|
509
|
+
source: 'deterministic',
|
|
510
510
|
confidence: 1,
|
|
511
|
-
status:
|
|
511
|
+
status: 'asserted',
|
|
512
512
|
evidence: {
|
|
513
|
-
kind:
|
|
514
|
-
description:
|
|
513
|
+
kind: 'storage_subtype',
|
|
514
|
+
description: 'database subtype',
|
|
515
515
|
},
|
|
516
516
|
},
|
|
517
517
|
],
|
|
518
518
|
};
|
|
519
519
|
const proposals = [
|
|
520
520
|
{
|
|
521
|
-
id:
|
|
521
|
+
id: 'p_low_da',
|
|
522
522
|
proposal: {
|
|
523
|
-
kind:
|
|
524
|
-
targetComponentId:
|
|
525
|
-
candidateType:
|
|
523
|
+
kind: 'component_patch',
|
|
524
|
+
targetComponentId: 'asset_backend',
|
|
525
|
+
candidateType: 'node_property',
|
|
526
526
|
setProperties: {
|
|
527
|
-
data_action: [
|
|
527
|
+
data_action: ['log'],
|
|
528
528
|
},
|
|
529
|
-
confidence: { score: 0.71, band:
|
|
529
|
+
confidence: { score: 0.71, band: 'medium' },
|
|
530
530
|
evidence: [
|
|
531
531
|
{
|
|
532
|
-
filePath:
|
|
532
|
+
filePath: 'src/backend.ts',
|
|
533
533
|
startLine: 1,
|
|
534
534
|
endLine: 1,
|
|
535
|
-
reason:
|
|
535
|
+
reason: 'weak log guess',
|
|
536
536
|
},
|
|
537
537
|
],
|
|
538
|
-
provider:
|
|
539
|
-
model:
|
|
540
|
-
agent:
|
|
538
|
+
provider: 'openai',
|
|
539
|
+
model: 'x',
|
|
540
|
+
agent: 'propertyAgent',
|
|
541
541
|
},
|
|
542
542
|
},
|
|
543
543
|
];
|
|
544
544
|
const result = (0, merge_rules_1.mergeAiProposals)(components, makeBaseFlows(), proposals);
|
|
545
|
-
const backend = result.components.find((c) => c.id ===
|
|
545
|
+
const backend = result.components.find((c) => c.id === 'asset_backend');
|
|
546
546
|
expect(result.appliedProposalIds).toEqual([]);
|
|
547
547
|
expect(result.rejectedProposalIds).toEqual([
|
|
548
548
|
{
|
|
549
|
-
proposalId:
|
|
550
|
-
reason:
|
|
549
|
+
proposalId: 'p_low_da',
|
|
550
|
+
reason: 'confidence_below_threshold:0.72',
|
|
551
551
|
},
|
|
552
552
|
]);
|
|
553
553
|
expect(backend?.properties.dataActions).toEqual([
|
|
554
554
|
{
|
|
555
|
-
action:
|
|
556
|
-
source:
|
|
555
|
+
action: 'store',
|
|
556
|
+
source: 'deterministic',
|
|
557
557
|
confidence: 1,
|
|
558
|
-
status:
|
|
558
|
+
status: 'asserted',
|
|
559
559
|
evidence: {
|
|
560
|
-
kind:
|
|
561
|
-
description:
|
|
560
|
+
kind: 'storage_subtype',
|
|
561
|
+
description: 'database subtype',
|
|
562
562
|
},
|
|
563
563
|
},
|
|
564
564
|
]);
|
|
565
565
|
});
|
|
566
|
-
it(
|
|
566
|
+
it('does not write dataActions onto actor nodes', () => {
|
|
567
567
|
const components = [
|
|
568
568
|
{
|
|
569
|
-
id:
|
|
570
|
-
name:
|
|
571
|
-
type:
|
|
569
|
+
id: 'actor_user',
|
|
570
|
+
name: 'End User',
|
|
571
|
+
type: 'actor',
|
|
572
572
|
confidence: 0.9,
|
|
573
573
|
detectedFrom: [],
|
|
574
574
|
sourceLocations: [],
|
|
@@ -577,92 +577,338 @@ describe("ai-enrichment merge rules", () => {
|
|
|
577
577
|
];
|
|
578
578
|
const proposals = [
|
|
579
579
|
{
|
|
580
|
-
id:
|
|
580
|
+
id: 'p_actor_da',
|
|
581
581
|
proposal: {
|
|
582
|
-
kind:
|
|
583
|
-
targetComponentId:
|
|
584
|
-
candidateType:
|
|
582
|
+
kind: 'component_patch',
|
|
583
|
+
targetComponentId: 'actor_user',
|
|
584
|
+
candidateType: 'node_property',
|
|
585
585
|
setProperties: {
|
|
586
|
-
data_action: [
|
|
586
|
+
data_action: ['collect'],
|
|
587
587
|
},
|
|
588
|
-
confidence: { score: 0.9, band:
|
|
588
|
+
confidence: { score: 0.9, band: 'high' },
|
|
589
589
|
evidence: [
|
|
590
590
|
{
|
|
591
|
-
filePath:
|
|
591
|
+
filePath: 'src/ui.ts',
|
|
592
592
|
startLine: 1,
|
|
593
593
|
endLine: 2,
|
|
594
|
-
reason:
|
|
594
|
+
reason: 'form submit',
|
|
595
595
|
},
|
|
596
596
|
],
|
|
597
|
-
provider:
|
|
598
|
-
model:
|
|
599
|
-
agent:
|
|
597
|
+
provider: 'openai',
|
|
598
|
+
model: 'x',
|
|
599
|
+
agent: 'propertyAgent',
|
|
600
600
|
},
|
|
601
601
|
},
|
|
602
602
|
];
|
|
603
603
|
const result = (0, merge_rules_1.mergeAiProposals)(components, [], proposals);
|
|
604
604
|
expect(result.appliedProposalIds).toEqual([]);
|
|
605
605
|
expect(result.rejectedProposalIds).toEqual([
|
|
606
|
-
{ proposalId:
|
|
606
|
+
{ proposalId: 'p_actor_da', reason: 'no_meaningful_changes' },
|
|
607
607
|
]);
|
|
608
608
|
expect(result.components[0]?.properties.dataActions).toBeUndefined();
|
|
609
609
|
});
|
|
610
|
-
it(
|
|
610
|
+
it('promotes a deterministic relay candidate when AI supplies corroboration', () => {
|
|
611
611
|
const components = makeBaseComponents();
|
|
612
612
|
components[0].properties = {
|
|
613
613
|
dataActions: [
|
|
614
614
|
{
|
|
615
|
-
action:
|
|
616
|
-
source:
|
|
615
|
+
action: 'relay',
|
|
616
|
+
source: 'deterministic',
|
|
617
617
|
confidence: 0.6,
|
|
618
|
-
status:
|
|
618
|
+
status: 'candidate',
|
|
619
619
|
evidence: {
|
|
620
|
-
kind:
|
|
621
|
-
description:
|
|
620
|
+
kind: 'relay_topology',
|
|
621
|
+
description: 'in-degree and out-degree without store',
|
|
622
622
|
},
|
|
623
623
|
},
|
|
624
624
|
],
|
|
625
625
|
};
|
|
626
626
|
const proposals = [
|
|
627
627
|
{
|
|
628
|
-
id:
|
|
628
|
+
id: 'p_relay',
|
|
629
629
|
proposal: {
|
|
630
|
-
kind:
|
|
631
|
-
targetComponentId:
|
|
632
|
-
candidateType:
|
|
630
|
+
kind: 'component_patch',
|
|
631
|
+
targetComponentId: 'asset_frontend',
|
|
632
|
+
candidateType: 'node_property',
|
|
633
633
|
setProperties: {
|
|
634
|
-
data_action: [
|
|
634
|
+
data_action: ['relay'],
|
|
635
635
|
},
|
|
636
636
|
propertyEvidence: {
|
|
637
637
|
data_action: [
|
|
638
638
|
{
|
|
639
|
-
filePath:
|
|
639
|
+
filePath: 'src/proxy.ts',
|
|
640
640
|
startLine: 8,
|
|
641
641
|
endLine: 12,
|
|
642
|
-
reason:
|
|
642
|
+
reason: 'express proxy middleware passthrough',
|
|
643
643
|
},
|
|
644
644
|
],
|
|
645
645
|
},
|
|
646
|
-
confidence: { score: 0.9, band:
|
|
646
|
+
confidence: { score: 0.9, band: 'high' },
|
|
647
647
|
evidence: [
|
|
648
648
|
{
|
|
649
|
-
filePath:
|
|
649
|
+
filePath: 'src/proxy.ts',
|
|
650
650
|
startLine: 8,
|
|
651
651
|
endLine: 12,
|
|
652
|
-
reason:
|
|
652
|
+
reason: 'express proxy middleware passthrough',
|
|
653
653
|
},
|
|
654
654
|
],
|
|
655
|
-
provider:
|
|
656
|
-
model:
|
|
657
|
-
agent:
|
|
655
|
+
provider: 'openai',
|
|
656
|
+
model: 'x',
|
|
657
|
+
agent: 'propertyAgent',
|
|
658
658
|
},
|
|
659
659
|
},
|
|
660
660
|
];
|
|
661
661
|
const result = (0, merge_rules_1.mergeAiProposals)(components, makeBaseFlows(), proposals);
|
|
662
|
-
const frontend = result.components.find((c) => c.id ===
|
|
663
|
-
const relay = frontend?.properties.dataActions?.find((a) => a.action ===
|
|
664
|
-
expect(result.appliedProposalIds).toEqual([
|
|
665
|
-
expect(relay?.status).toBe(
|
|
666
|
-
expect(relay?.source).toBe(
|
|
662
|
+
const frontend = result.components.find((c) => c.id === 'asset_frontend');
|
|
663
|
+
const relay = frontend?.properties.dataActions?.find((a) => a.action === 'relay');
|
|
664
|
+
expect(result.appliedProposalIds).toEqual(['p_relay']);
|
|
665
|
+
expect(relay?.status).toBe('asserted');
|
|
666
|
+
expect(relay?.source).toBe('ai');
|
|
667
|
+
});
|
|
668
|
+
it('persists propertyEvidence for non-data-action properties onto the component', () => {
|
|
669
|
+
const components = makeBaseComponents();
|
|
670
|
+
const proposals = [
|
|
671
|
+
{
|
|
672
|
+
id: 'p_cloud',
|
|
673
|
+
proposal: {
|
|
674
|
+
kind: 'component_patch',
|
|
675
|
+
targetComponentId: 'asset_backend',
|
|
676
|
+
candidateType: 'node_property',
|
|
677
|
+
setProperties: {
|
|
678
|
+
cloud_provider: 'aws',
|
|
679
|
+
programming_language: ['typescript'],
|
|
680
|
+
},
|
|
681
|
+
propertyEvidence: {
|
|
682
|
+
cloud_provider: [
|
|
683
|
+
{
|
|
684
|
+
filePath: 'infra/main.tf',
|
|
685
|
+
startLine: 12,
|
|
686
|
+
endLine: 18,
|
|
687
|
+
reason: 'provider aws block',
|
|
688
|
+
},
|
|
689
|
+
],
|
|
690
|
+
programming_language: [
|
|
691
|
+
{
|
|
692
|
+
filePath: 'src/backend.ts',
|
|
693
|
+
startLine: 1,
|
|
694
|
+
endLine: 1,
|
|
695
|
+
reason: 'typescript source file',
|
|
696
|
+
},
|
|
697
|
+
],
|
|
698
|
+
},
|
|
699
|
+
confidence: { score: 0.9, band: 'high' },
|
|
700
|
+
evidence: [
|
|
701
|
+
{
|
|
702
|
+
filePath: 'infra/main.tf',
|
|
703
|
+
startLine: 12,
|
|
704
|
+
endLine: 18,
|
|
705
|
+
reason: 'provider aws block',
|
|
706
|
+
},
|
|
707
|
+
],
|
|
708
|
+
provider: 'openai',
|
|
709
|
+
model: 'x',
|
|
710
|
+
agent: 'propertyAgent',
|
|
711
|
+
},
|
|
712
|
+
},
|
|
713
|
+
];
|
|
714
|
+
const result = (0, merge_rules_1.mergeAiProposals)(components, makeBaseFlows(), proposals);
|
|
715
|
+
const backend = result.components.find((c) => c.id === 'asset_backend');
|
|
716
|
+
const propertyEvidence = backend?.properties.propertyEvidence;
|
|
717
|
+
expect(result.appliedProposalIds).toEqual(['p_cloud']);
|
|
718
|
+
expect(backend?.properties.cloud_provider).toBe('aws');
|
|
719
|
+
expect(backend?.properties.programming_language).toEqual(['typescript']);
|
|
720
|
+
expect(propertyEvidence?.cloud_provider).toEqual([
|
|
721
|
+
{
|
|
722
|
+
filePath: 'infra/main.tf',
|
|
723
|
+
startLine: 12,
|
|
724
|
+
endLine: 18,
|
|
725
|
+
reason: 'provider aws block',
|
|
726
|
+
},
|
|
727
|
+
]);
|
|
728
|
+
expect(propertyEvidence?.programming_language).toEqual([
|
|
729
|
+
{
|
|
730
|
+
filePath: 'src/backend.ts',
|
|
731
|
+
startLine: 1,
|
|
732
|
+
endLine: 1,
|
|
733
|
+
reason: 'typescript source file',
|
|
734
|
+
},
|
|
735
|
+
]);
|
|
736
|
+
});
|
|
737
|
+
it('persists an AI patch with five or more independently cited keys', () => {
|
|
738
|
+
const keys = [
|
|
739
|
+
'cloud_provider',
|
|
740
|
+
'programming_language',
|
|
741
|
+
'hosting_type',
|
|
742
|
+
'api_type',
|
|
743
|
+
'authentication_method',
|
|
744
|
+
'integration_status',
|
|
745
|
+
];
|
|
746
|
+
const setProperties = Object.fromEntries(keys.map((key) => [key, `${key}_value`]));
|
|
747
|
+
const propertyEvidence = Object.fromEntries(keys.map((key, index) => [
|
|
748
|
+
key,
|
|
749
|
+
[
|
|
750
|
+
{
|
|
751
|
+
filePath: 'src/backend.ts',
|
|
752
|
+
startLine: index + 1,
|
|
753
|
+
endLine: index + 1,
|
|
754
|
+
reason: `${key} literal`,
|
|
755
|
+
},
|
|
756
|
+
],
|
|
757
|
+
]));
|
|
758
|
+
const result = (0, merge_rules_1.mergeAiProposals)(makeBaseComponents(), makeBaseFlows(), [
|
|
759
|
+
{
|
|
760
|
+
id: 'p_many_properties',
|
|
761
|
+
proposal: {
|
|
762
|
+
kind: 'component_patch',
|
|
763
|
+
targetComponentId: 'asset_backend',
|
|
764
|
+
candidateType: 'node_property',
|
|
765
|
+
setProperties,
|
|
766
|
+
propertyEvidence,
|
|
767
|
+
confidence: { score: 0.9, band: 'high' },
|
|
768
|
+
evidence: propertyEvidence.cloud_provider,
|
|
769
|
+
provider: 'openai',
|
|
770
|
+
model: 'x',
|
|
771
|
+
agent: 'propertyAgent',
|
|
772
|
+
},
|
|
773
|
+
},
|
|
774
|
+
]);
|
|
775
|
+
const backend = result.components.find((c) => c.id === 'asset_backend');
|
|
776
|
+
for (const key of keys) {
|
|
777
|
+
expect(backend?.properties[key]).toBe(`${key}_value`);
|
|
778
|
+
expect((backend?.properties.propertyEvidence)[key]).toHaveLength(1);
|
|
779
|
+
}
|
|
780
|
+
});
|
|
781
|
+
it('merges propertyEvidence by key without wiping unrelated existing evidence', () => {
|
|
782
|
+
const components = makeBaseComponents();
|
|
783
|
+
components[1].properties = {
|
|
784
|
+
cloud_provider: 'aws',
|
|
785
|
+
propertyEvidence: {
|
|
786
|
+
cloud_provider: [
|
|
787
|
+
{
|
|
788
|
+
filePath: 'infra/main.tf',
|
|
789
|
+
startLine: 1,
|
|
790
|
+
endLine: 2,
|
|
791
|
+
reason: 'existing aws evidence',
|
|
792
|
+
},
|
|
793
|
+
],
|
|
794
|
+
encrypt_at_rest: [
|
|
795
|
+
{
|
|
796
|
+
filePath: 'infra/db.tf',
|
|
797
|
+
startLine: 5,
|
|
798
|
+
endLine: 8,
|
|
799
|
+
reason: 'existing encryption evidence',
|
|
800
|
+
},
|
|
801
|
+
],
|
|
802
|
+
},
|
|
803
|
+
};
|
|
804
|
+
const proposals = [
|
|
805
|
+
{
|
|
806
|
+
id: 'p_lang',
|
|
807
|
+
proposal: {
|
|
808
|
+
kind: 'component_patch',
|
|
809
|
+
targetComponentId: 'asset_backend',
|
|
810
|
+
candidateType: 'node_property',
|
|
811
|
+
setProperties: {
|
|
812
|
+
programming_language: ['typescript'],
|
|
813
|
+
},
|
|
814
|
+
propertyEvidence: {
|
|
815
|
+
programming_language: [
|
|
816
|
+
{
|
|
817
|
+
filePath: 'src/backend.ts',
|
|
818
|
+
startLine: 1,
|
|
819
|
+
endLine: 1,
|
|
820
|
+
reason: 'typescript source',
|
|
821
|
+
},
|
|
822
|
+
],
|
|
823
|
+
},
|
|
824
|
+
confidence: { score: 0.9, band: 'high' },
|
|
825
|
+
evidence: [
|
|
826
|
+
{
|
|
827
|
+
filePath: 'src/backend.ts',
|
|
828
|
+
startLine: 1,
|
|
829
|
+
endLine: 1,
|
|
830
|
+
reason: 'typescript source',
|
|
831
|
+
},
|
|
832
|
+
],
|
|
833
|
+
provider: 'openai',
|
|
834
|
+
model: 'x',
|
|
835
|
+
agent: 'propertyAgent',
|
|
836
|
+
},
|
|
837
|
+
},
|
|
838
|
+
];
|
|
839
|
+
const result = (0, merge_rules_1.mergeAiProposals)(components, makeBaseFlows(), proposals);
|
|
840
|
+
const backend = result.components.find((c) => c.id === 'asset_backend');
|
|
841
|
+
const propertyEvidence = backend?.properties.propertyEvidence;
|
|
842
|
+
expect(result.appliedProposalIds).toEqual(['p_lang']);
|
|
843
|
+
expect(propertyEvidence?.encrypt_at_rest?.[0]?.filePath).toBe('infra/db.tf');
|
|
844
|
+
expect(propertyEvidence?.cloud_provider?.[0]?.filePath).toBe('infra/main.tf');
|
|
845
|
+
expect(propertyEvidence?.programming_language?.[0]?.filePath).toBe('src/backend.ts');
|
|
846
|
+
});
|
|
847
|
+
it('keeps a non-sparse scanner value and its evidence when AI disagrees', () => {
|
|
848
|
+
const components = makeBaseComponents();
|
|
849
|
+
components[1].properties = {
|
|
850
|
+
cloud_provider: 'aws',
|
|
851
|
+
propertyEvidence: {
|
|
852
|
+
cloud_provider: [
|
|
853
|
+
{
|
|
854
|
+
filePath: 'infra/main.tf',
|
|
855
|
+
startLine: 1,
|
|
856
|
+
endLine: 2,
|
|
857
|
+
reason: 'property.patterns.yaml:terraform_provider',
|
|
858
|
+
},
|
|
859
|
+
],
|
|
860
|
+
},
|
|
861
|
+
};
|
|
862
|
+
const result = (0, merge_rules_1.mergeAiProposals)(components, makeBaseFlows(), [
|
|
863
|
+
{
|
|
864
|
+
id: 'p_cloud_disagreement',
|
|
865
|
+
proposal: {
|
|
866
|
+
kind: 'component_patch',
|
|
867
|
+
targetComponentId: 'asset_backend',
|
|
868
|
+
candidateType: 'node_property',
|
|
869
|
+
setProperties: { cloud_provider: 'gcp' },
|
|
870
|
+
propertyEvidence: {
|
|
871
|
+
cloud_provider: [
|
|
872
|
+
{
|
|
873
|
+
filePath: 'src/backend.ts',
|
|
874
|
+
startLine: 1,
|
|
875
|
+
endLine: 1,
|
|
876
|
+
reason: 'AI inferred GCP',
|
|
877
|
+
},
|
|
878
|
+
],
|
|
879
|
+
},
|
|
880
|
+
confidence: { score: 0.9, band: 'high' },
|
|
881
|
+
evidence: [
|
|
882
|
+
{
|
|
883
|
+
filePath: 'src/backend.ts',
|
|
884
|
+
startLine: 1,
|
|
885
|
+
endLine: 1,
|
|
886
|
+
reason: 'AI inferred GCP',
|
|
887
|
+
},
|
|
888
|
+
],
|
|
889
|
+
provider: 'openai',
|
|
890
|
+
model: 'x',
|
|
891
|
+
agent: 'propertyAgent',
|
|
892
|
+
},
|
|
893
|
+
},
|
|
894
|
+
]);
|
|
895
|
+
const backend = result.components.find((c) => c.id === 'asset_backend');
|
|
896
|
+
expect(backend?.properties.cloud_provider).toBe('aws');
|
|
897
|
+
expect(backend?.properties.propertyEvidence).toEqual({
|
|
898
|
+
cloud_provider: [
|
|
899
|
+
{
|
|
900
|
+
filePath: 'infra/main.tf',
|
|
901
|
+
startLine: 1,
|
|
902
|
+
endLine: 2,
|
|
903
|
+
reason: 'property.patterns.yaml:terraform_provider',
|
|
904
|
+
},
|
|
905
|
+
],
|
|
906
|
+
});
|
|
907
|
+
expect(result.rejectedProposalIds).toEqual([
|
|
908
|
+
{
|
|
909
|
+
proposalId: 'p_cloud_disagreement',
|
|
910
|
+
reason: 'no_meaningful_changes',
|
|
911
|
+
},
|
|
912
|
+
]);
|
|
667
913
|
});
|
|
668
914
|
});
|