File size: 1,599 Bytes
39b3fb5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import assert from "node:assert/strict";
import test from "node:test";
import { KittyRuntime } from "../src/runtime/agent-runtime.js";
import { LocalMeshBus } from "../src/runtime/mesh.js";

test("runtime creates an agent context and queues executable tasks", async () => {
  const runtime = new KittyRuntime(new LocalMeshBus());
  await runtime.start();

  const context = runtime.createContext({ label: "Test Context" });
  const result = await runtime.submitTask({
    contextId: context.id,
    command: "execute_resonance_vm",
    payload: { ok: true },
    dependencies: [],
    failRate: 0,
    latencyMs: 100,
    vmTarget: "apl-wasm",
    ideTarget: "vscode",
  });

  assert.equal(result.status, "queued");
  assert.equal(runtime.snapshot().contexts.length, 1);
  await new Promise((resolve) => setTimeout(resolve, 25));
  assert.equal(runtime.snapshot().results[0]?.status, "succeeded");

  await runtime.stop();
});

test("runtime blocks tasks above entropy threshold before dispatch", async () => {
  const runtime = new KittyRuntime(new LocalMeshBus());
  await runtime.start();
  const context = runtime.createContext();

  const result = await runtime.submitTask({
    contextId: context.id,
    command: "execute_resonance_vm",
    payload: {},
    dependencies: ["a", "b", "c", "d", "e", "f", "g"],
    failRate: 0.8,
    latencyMs: 9_000,
    vmTarget: "docker",
    ideTarget: "none",
  });

  assert.equal(result.status, "blocked");
  assert.equal(runtime.snapshot().results[0]?.status, "blocked");

  await runtime.stop();
});