@mhingston5/lasso 0.1.0 → 0.2.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.
@@ -3,11 +3,13 @@ import {
3
3
  prepareInitialAdaptiveInput,
4
4
  unwrapAdaptiveInput,
5
5
  prepareRuntimeReplan,
6
+ prepareRuntimeReplanWithTraceSynthesis,
6
7
  MAX_ADAPTIVE_VERSIONS,
7
8
  } from "../../src/replanner/runtime.js";
8
9
  import type { ReferenceWorkflowRequest } from "../../src/reference/catalog.js";
9
10
  import type { HarnessSpec } from "../../src/spec/types.js";
10
11
  import type { CompiledHarnessResult } from "../../src/compiler/compile.js";
12
+ import type { EnvironmentModel } from "../../src/environment/types.js";
11
13
  import { createInitialVersion } from "../../src/versioning/history.js";
12
14
 
13
15
  describe("replanner/runtime", () => {
@@ -204,4 +206,136 @@ describe("replanner/runtime", () => {
204
206
  }
205
207
  });
206
208
  });
209
+
210
+ describe("prepareRuntimeReplanWithTraceSynthesis", () => {
211
+ const mockResult: CompiledHarnessResult = {
212
+ status: "completed",
213
+ terminalNodeId: "validated-fix",
214
+ result: { output: "test" },
215
+ outputs: { start: { stdout: "test" } },
216
+ trace: [],
217
+ harnessState: {
218
+ inputs: {},
219
+ outputs: { start: { stdout: "test" } },
220
+ nodeResults: { start: { stdout: "test" } },
221
+ failures: [],
222
+ metrics: { retries: 0, durationMs: 100 },
223
+ },
224
+ };
225
+
226
+ const mockEnv: EnvironmentModel = {
227
+ tools: [
228
+ { name: "bash", version: "5.0", available: true },
229
+ { name: "git", version: "2.39", available: true },
230
+ ],
231
+ resources: [],
232
+ constraints: [],
233
+ authState: [],
234
+ externalSystems: [],
235
+ discoveredAt: Date.now(),
236
+ };
237
+
238
+ it("should return trace_synthesis decision for successful execution", async () => {
239
+ const wrapped = prepareInitialAdaptiveInput(mockRequest, mockSpec, {});
240
+ const adaptive = unwrapAdaptiveInput(wrapped).metadata!;
241
+
242
+ const decision = await prepareRuntimeReplanWithTraceSynthesis({
243
+ adaptive,
244
+ runtimeInput: {},
245
+ result: mockResult,
246
+ environment: mockEnv,
247
+ });
248
+
249
+ expect(decision.decision).toBe("trace_synthesis");
250
+ if (decision.decision === "trace_synthesis") {
251
+ expect(decision.synthesisResult).toBeDefined();
252
+ expect(decision.synthesisResult.decision).toBe("continue");
253
+ expect(decision.lineageEntry).toBeDefined();
254
+ }
255
+ });
256
+
257
+ it("should stop when max version limit reached", async () => {
258
+ const wrapped = prepareInitialAdaptiveInput(mockRequest, mockSpec, {});
259
+ const adaptive = unwrapAdaptiveInput(wrapped).metadata!;
260
+ adaptive.currentVersion.version = MAX_ADAPTIVE_VERSIONS;
261
+
262
+ const decision = await prepareRuntimeReplanWithTraceSynthesis({
263
+ adaptive,
264
+ runtimeInput: {},
265
+ result: mockResult,
266
+ environment: mockEnv,
267
+ });
268
+
269
+ expect(decision.decision).toBe("stop");
270
+ });
271
+
272
+ it("should build execution trace from harness state failures", async () => {
273
+ const resultWithFailures: CompiledHarnessResult = {
274
+ ...mockResult,
275
+ harnessState: {
276
+ ...mockResult.harnessState,
277
+ nodeResults: { start: { stdout: "test" }, "other-node": { stdout: "done" } },
278
+ failures: [
279
+ {
280
+ domainType: "lasso",
281
+ rootCause: "tool_missing",
282
+ nodeId: "start",
283
+ message: "bash: command not found",
284
+ },
285
+ ],
286
+ },
287
+ };
288
+
289
+ const wrapped = prepareInitialAdaptiveInput(mockRequest, mockSpec, {});
290
+ const adaptive = unwrapAdaptiveInput(wrapped).metadata!;
291
+
292
+ const decision = await prepareRuntimeReplanWithTraceSynthesis({
293
+ adaptive,
294
+ runtimeInput: {},
295
+ result: resultWithFailures,
296
+ environment: mockEnv,
297
+ });
298
+
299
+ expect(decision.decision).toBe("trace_synthesis");
300
+ if (decision.decision === "trace_synthesis") {
301
+ expect(decision.synthesisResult.mutations.length).toBeGreaterThan(0);
302
+ expect(decision.synthesisResult.rationale.length).toBeGreaterThan(0);
303
+ }
304
+ });
305
+
306
+ it("should propagate synthesis mutations into next version spec", async () => {
307
+ const resultWithFailures: CompiledHarnessResult = {
308
+ ...mockResult,
309
+ harnessState: {
310
+ ...mockResult.harnessState,
311
+ nodeResults: { start: { stdout: "test" }, "other-node": { stdout: "done" } },
312
+ failures: [
313
+ {
314
+ domainType: "lasso",
315
+ rootCause: "tool_missing",
316
+ nodeId: "start",
317
+ message: "bash: command not found",
318
+ },
319
+ ],
320
+ },
321
+ };
322
+
323
+ const wrapped = prepareInitialAdaptiveInput(mockRequest, mockSpec, {});
324
+ const adaptive = unwrapAdaptiveInput(wrapped).metadata!;
325
+
326
+ const decision = await prepareRuntimeReplanWithTraceSynthesis({
327
+ adaptive,
328
+ runtimeInput: {},
329
+ result: resultWithFailures,
330
+ environment: mockEnv,
331
+ });
332
+
333
+ if (decision.decision === "trace_synthesis" && decision.nextVersion) {
334
+ expect(decision.nextVersion.spec).toBeDefined();
335
+ expect(decision.nextVersion.spec.graph.nodes.length).toBeGreaterThanOrEqual(
336
+ mockSpec.graph.nodes.length,
337
+ );
338
+ }
339
+ });
340
+ });
207
341
  });