@mhingston5/lasso 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +707 -0
- package/docs/agent-wrangling.png +0 -0
- package/package.json +26 -0
- package/src/capabilities/matcher.ts +25 -0
- package/src/capabilities/registry.ts +103 -0
- package/src/capabilities/types.ts +15 -0
- package/src/cir/lower.ts +253 -0
- package/src/cir/optimize.ts +251 -0
- package/src/cir/types.ts +131 -0
- package/src/cir/validate.ts +265 -0
- package/src/compiler/compile.ts +601 -0
- package/src/compiler/feedback.ts +471 -0
- package/src/compiler/runtime-helpers.ts +455 -0
- package/src/composition/chain.ts +58 -0
- package/src/composition/conditional.ts +76 -0
- package/src/composition/parallel.ts +75 -0
- package/src/composition/types.ts +105 -0
- package/src/environment/analyzer.ts +56 -0
- package/src/environment/discovery.ts +179 -0
- package/src/environment/types.ts +68 -0
- package/src/failures/classifiers.ts +134 -0
- package/src/failures/generator.ts +421 -0
- package/src/failures/map-reference-failures.ts +23 -0
- package/src/failures/ontology.ts +210 -0
- package/src/failures/recovery.ts +214 -0
- package/src/failures/types.ts +14 -0
- package/src/index.ts +67 -0
- package/src/memory/advisor.ts +132 -0
- package/src/memory/extractor.ts +166 -0
- package/src/memory/store.ts +107 -0
- package/src/memory/types.ts +53 -0
- package/src/metaharness/engine.ts +256 -0
- package/src/metaharness/predictor.ts +168 -0
- package/src/metaharness/types.ts +40 -0
- package/src/mutation/derive.ts +308 -0
- package/src/mutation/diff.ts +52 -0
- package/src/mutation/engine.ts +256 -0
- package/src/mutation/types.ts +84 -0
- package/src/pi/command-input.ts +209 -0
- package/src/pi/commands.ts +351 -0
- package/src/pi/extension.ts +16 -0
- package/src/planner/synthesize.ts +83 -0
- package/src/planner/template-rules.ts +183 -0
- package/src/planner/types.ts +42 -0
- package/src/reference/catalog.ts +128 -0
- package/src/reference/patch-validation-strategies.ts +170 -0
- package/src/reference/patch-validation.ts +174 -0
- package/src/reference/pr-review-merge.ts +155 -0
- package/src/reference/strategies.ts +126 -0
- package/src/reference/types.ts +33 -0
- package/src/replanner/risk-rules.ts +161 -0
- package/src/replanner/runtime.ts +308 -0
- package/src/replanner/synthesize.ts +619 -0
- package/src/replanner/types.ts +73 -0
- package/src/spec/schema.ts +254 -0
- package/src/spec/types.ts +319 -0
- package/src/spec/validate.ts +296 -0
- package/src/state/snapshots.ts +43 -0
- package/src/state/types.ts +12 -0
- package/src/synthesis/graph-builder.ts +267 -0
- package/src/synthesis/harness-builder.ts +113 -0
- package/src/synthesis/intent-ir.ts +63 -0
- package/src/synthesis/policy-builder.ts +320 -0
- package/src/synthesis/risk-analyzer.ts +182 -0
- package/src/synthesis/skill-parser.ts +441 -0
- package/src/verification/engine.ts +230 -0
- package/src/versioning/file-store.ts +103 -0
- package/src/versioning/history.ts +43 -0
- package/src/versioning/store.ts +16 -0
- package/src/versioning/types.ts +31 -0
- package/test/capabilities/matcher.test.ts +67 -0
- package/test/capabilities/registry.test.ts +136 -0
- package/test/capabilities/synthesis.test.ts +264 -0
- package/test/cir/lower.test.ts +417 -0
- package/test/cir/optimize.test.ts +266 -0
- package/test/cir/validate.test.ts +368 -0
- package/test/compiler/adaptive-runtime.test.ts +157 -0
- package/test/compiler/compile.test.ts +1198 -0
- package/test/compiler/feedback.test.ts +784 -0
- package/test/compiler/guardrails.test.ts +191 -0
- package/test/compiler/trace.test.ts +404 -0
- package/test/composition/chain.test.ts +328 -0
- package/test/composition/conditional.test.ts +241 -0
- package/test/composition/parallel.test.ts +215 -0
- package/test/environment/analyzer.test.ts +204 -0
- package/test/environment/discovery.test.ts +149 -0
- package/test/failures/classifiers.test.ts +287 -0
- package/test/failures/generator.test.ts +203 -0
- package/test/failures/ontology.test.ts +439 -0
- package/test/failures/recovery.test.ts +300 -0
- package/test/helpers/createFixtureRepo.ts +84 -0
- package/test/helpers/createPatchValidationFixture.ts +144 -0
- package/test/helpers/runCompiledWorkflow.ts +208 -0
- package/test/memory/advisor.test.ts +332 -0
- package/test/memory/extractor.test.ts +295 -0
- package/test/memory/store.test.ts +244 -0
- package/test/metaharness/engine.test.ts +575 -0
- package/test/metaharness/predictor.test.ts +436 -0
- package/test/mutation/derive-failure.test.ts +209 -0
- package/test/mutation/engine.test.ts +622 -0
- package/test/package-smoke.test.ts +29 -0
- package/test/pi/command-input.test.ts +153 -0
- package/test/pi/commands.test.ts +623 -0
- package/test/planner/classify-template.test.ts +32 -0
- package/test/planner/synthesize.test.ts +901 -0
- package/test/reference/PatchValidation.failures.test.ts +137 -0
- package/test/reference/PatchValidation.test.ts +326 -0
- package/test/reference/PrReviewMerge.failures.test.ts +121 -0
- package/test/reference/PrReviewMerge.test.ts +55 -0
- package/test/reference/catalog-open.test.ts +70 -0
- package/test/replanner/runtime.test.ts +207 -0
- package/test/replanner/synthesize.test.ts +303 -0
- package/test/spec/validate.test.ts +1056 -0
- package/test/state/snapshots.test.ts +264 -0
- package/test/synthesis/custom-workflow.test.ts +264 -0
- package/test/synthesis/graph-builder.test.ts +370 -0
- package/test/synthesis/harness-builder.test.ts +128 -0
- package/test/synthesis/policy-builder.test.ts +149 -0
- package/test/synthesis/risk-analyzer.test.ts +230 -0
- package/test/synthesis/skill-parser.test.ts +796 -0
- package/test/verification/engine.test.ts +509 -0
- package/test/versioning/history.test.ts +144 -0
- package/test/versioning/store.test.ts +254 -0
- package/vitest.config.ts +9 -0
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { analyzeRisks } from "../../src/synthesis/risk-analyzer.js";
|
|
3
|
+
import type { TaskGraph } from "../../src/synthesis/graph-builder.js";
|
|
4
|
+
|
|
5
|
+
describe("risk-analyzer", () => {
|
|
6
|
+
describe("analyzeRisks", () => {
|
|
7
|
+
describe("candidate source kind detection", () => {
|
|
8
|
+
it("should detect branch candidate source", () => {
|
|
9
|
+
const graph: TaskGraph = {
|
|
10
|
+
family: "patch-validation",
|
|
11
|
+
stages: [],
|
|
12
|
+
inputs: {
|
|
13
|
+
candidateBranch: "fix-branch",
|
|
14
|
+
verificationCommands: ["npm test"]
|
|
15
|
+
},
|
|
16
|
+
goal: "Validate patch"
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const risks = analyzeRisks(graph);
|
|
20
|
+
|
|
21
|
+
expect(risks.candidateSourceKind).toBe("branch");
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("should detect patch file candidate source", () => {
|
|
25
|
+
const graph: TaskGraph = {
|
|
26
|
+
family: "patch-validation",
|
|
27
|
+
stages: [],
|
|
28
|
+
inputs: {
|
|
29
|
+
patchFilePath: "fix.patch",
|
|
30
|
+
verificationCommands: ["npm test"]
|
|
31
|
+
},
|
|
32
|
+
goal: "Validate patch"
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const risks = analyzeRisks(graph);
|
|
36
|
+
|
|
37
|
+
expect(risks.candidateSourceKind).toBe("patchFile");
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("should detect PR candidate source", () => {
|
|
41
|
+
const graph: TaskGraph = {
|
|
42
|
+
family: "pr-review-merge",
|
|
43
|
+
stages: [],
|
|
44
|
+
inputs: {
|
|
45
|
+
sourceBranch: "feature",
|
|
46
|
+
targetBranch: "main",
|
|
47
|
+
verificationCommands: ["npm test"]
|
|
48
|
+
},
|
|
49
|
+
goal: "Review and merge PR"
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const risks = analyzeRisks(graph);
|
|
53
|
+
|
|
54
|
+
expect(risks.candidateSourceKind).toBe("pr");
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
describe("approval requirement detection", () => {
|
|
59
|
+
it("should detect approval requirement from inputs", () => {
|
|
60
|
+
const graph: TaskGraph = {
|
|
61
|
+
family: "patch-validation",
|
|
62
|
+
stages: [],
|
|
63
|
+
inputs: {
|
|
64
|
+
approvalRequired: true,
|
|
65
|
+
candidateBranch: "fix-branch"
|
|
66
|
+
},
|
|
67
|
+
goal: "Validate patch"
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
const risks = analyzeRisks(graph);
|
|
71
|
+
|
|
72
|
+
expect(risks.approvalRequired).toBe(true);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it("should default approval to false when not specified", () => {
|
|
76
|
+
const graph: TaskGraph = {
|
|
77
|
+
family: "patch-validation",
|
|
78
|
+
stages: [],
|
|
79
|
+
inputs: {
|
|
80
|
+
candidateBranch: "fix-branch"
|
|
81
|
+
},
|
|
82
|
+
goal: "Validate patch"
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const risks = analyzeRisks(graph);
|
|
86
|
+
|
|
87
|
+
expect(risks.approvalRequired).toBe(false);
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
describe("verification breadth assessment", () => {
|
|
92
|
+
it("should assess narrow verification breadth with no commands", () => {
|
|
93
|
+
const graph: TaskGraph = {
|
|
94
|
+
family: "patch-validation",
|
|
95
|
+
stages: [],
|
|
96
|
+
inputs: {},
|
|
97
|
+
goal: "Validate patch"
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
const risks = analyzeRisks(graph);
|
|
101
|
+
|
|
102
|
+
expect(risks.verificationBreadth).toBe("narrow");
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it("should assess moderate verification breadth with 1-2 commands", () => {
|
|
106
|
+
const graph: TaskGraph = {
|
|
107
|
+
family: "patch-validation",
|
|
108
|
+
stages: [],
|
|
109
|
+
inputs: {
|
|
110
|
+
verificationCommands: ["npm test"],
|
|
111
|
+
reproduceCommands: ["npm run fail"]
|
|
112
|
+
},
|
|
113
|
+
goal: "Validate patch"
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
const risks = analyzeRisks(graph);
|
|
117
|
+
|
|
118
|
+
expect(risks.verificationBreadth).toBe("moderate");
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it("should assess comprehensive verification breadth with 3+ commands", () => {
|
|
122
|
+
const graph: TaskGraph = {
|
|
123
|
+
family: "patch-validation",
|
|
124
|
+
stages: [],
|
|
125
|
+
inputs: {
|
|
126
|
+
verificationCommands: ["npm test", "npm run lint"],
|
|
127
|
+
reproduceCommands: ["npm run fail"]
|
|
128
|
+
},
|
|
129
|
+
goal: "Validate patch"
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
const risks = analyzeRisks(graph);
|
|
133
|
+
|
|
134
|
+
expect(risks.verificationBreadth).toBe("comprehensive");
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
describe("stage risk analysis", () => {
|
|
139
|
+
it("should analyze stage risks correctly", () => {
|
|
140
|
+
const graph: TaskGraph = {
|
|
141
|
+
family: "patch-validation",
|
|
142
|
+
stages: [
|
|
143
|
+
{
|
|
144
|
+
id: "apply-candidate",
|
|
145
|
+
type: "apply",
|
|
146
|
+
dependencies: [],
|
|
147
|
+
description: "Apply candidate",
|
|
148
|
+
requiredInputs: []
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
id: "verify-fix",
|
|
152
|
+
type: "verify",
|
|
153
|
+
dependencies: [],
|
|
154
|
+
description: "Verify fix",
|
|
155
|
+
requiredInputs: []
|
|
156
|
+
}
|
|
157
|
+
],
|
|
158
|
+
inputs: {
|
|
159
|
+
patchFilePath: "fix.patch",
|
|
160
|
+
verificationCommands: ["npm test"]
|
|
161
|
+
},
|
|
162
|
+
goal: "Validate patch"
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
const risks = analyzeRisks(graph);
|
|
166
|
+
|
|
167
|
+
expect(risks.stageRisks.size).toBeGreaterThan(0);
|
|
168
|
+
const applyRisk = risks.stageRisks.get("apply-candidate");
|
|
169
|
+
expect(applyRisk).toBeDefined();
|
|
170
|
+
expect(applyRisk?.risk).toBe("medium");
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
describe("overall risk calculation", () => {
|
|
175
|
+
it("should calculate overall risk as medium when any stage is medium", () => {
|
|
176
|
+
const graph: TaskGraph = {
|
|
177
|
+
family: "patch-validation",
|
|
178
|
+
stages: [
|
|
179
|
+
{
|
|
180
|
+
id: "apply-candidate",
|
|
181
|
+
type: "apply",
|
|
182
|
+
dependencies: [],
|
|
183
|
+
description: "Apply candidate",
|
|
184
|
+
requiredInputs: []
|
|
185
|
+
}
|
|
186
|
+
],
|
|
187
|
+
inputs: {
|
|
188
|
+
patchFilePath: "fix.patch"
|
|
189
|
+
},
|
|
190
|
+
goal: "Validate patch"
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
const risks = analyzeRisks(graph);
|
|
194
|
+
|
|
195
|
+
expect(risks.overallRisk).toBe("medium");
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
describe("mitigation suggestions", () => {
|
|
200
|
+
it("should suggest mitigations for narrow verification", () => {
|
|
201
|
+
const graph: TaskGraph = {
|
|
202
|
+
family: "patch-validation",
|
|
203
|
+
stages: [],
|
|
204
|
+
inputs: {},
|
|
205
|
+
goal: "Validate patch"
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
const risks = analyzeRisks(graph);
|
|
209
|
+
|
|
210
|
+
expect(risks.mitigations.length).toBeGreaterThan(0);
|
|
211
|
+
expect(risks.mitigations.some(m => m.includes("verification commands"))).toBe(true);
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
it("should suggest mitigations for patch file candidate", () => {
|
|
215
|
+
const graph: TaskGraph = {
|
|
216
|
+
family: "patch-validation",
|
|
217
|
+
stages: [],
|
|
218
|
+
inputs: {
|
|
219
|
+
patchFilePath: "fix.patch"
|
|
220
|
+
},
|
|
221
|
+
goal: "Validate patch"
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
const risks = analyzeRisks(graph);
|
|
225
|
+
|
|
226
|
+
expect(risks.mitigations.some(m => m.includes("Patch application"))).toBe(true);
|
|
227
|
+
});
|
|
228
|
+
});
|
|
229
|
+
});
|
|
230
|
+
});
|