import { GraphAI } from "../../src/index";
import { graphDataLatestVersion } from "../common";
import { copyAgent } from "../test_agents";
import test from "node:test";
import assert from "node:assert";

const graph_data = {
  version: graphDataLatestVersion,
  nodes: {
    inject1: {},
    inject2: {},
    result: {
      agent: "copyAgent",
      inputs: {
        array: [":inject1", ":inject2"],
      },
      isResult: true,
    },
  },
};

test("test injection static node", async () => {
  const graph = new GraphAI(graph_data, { copyAgent }, {});
  graph.injectValue("inject1", "hello");
  graph.injectValue("inject2", "good morning");

  const result = await graph.run();
  assert.deepStrictEqual(result, {
    result: {
      array: ["hello", "good morning"],
    },
  });
});

test("test injection static node", async () => {
  const graph = new GraphAI(graph_data, { copyAgent }, {});
  await assert.rejects(
    async () => {
      await graph.run();
    },
    { name: "Error", message: "Static node(s) must have value. Set value, injectValue, or set update. Affected nodeIds: inject1, inject2" },
  );
});
