import assert from "node:assert/strict";
import { describe, it } from "vitest";
import { FederatedMemoryProvider } from "./federated-memory.js";

describe("FederatedMemoryProvider", () => {
	it("search_returns_locally_stored_records_by_text_summary_and_tags", async () => {
		const provider = new FederatedMemoryProvider();
		await provider.store({
			id: "mem-1",
			text: "Stale runtime projections block autonomous dispatch.",
			tags: ["uok", "diagnostics"],
		});
		await provider.store({
			id: "mem-2",
			summary: "Widget rendering should fail open.",
			tags: ["ui"],
		});

		assert.deepEqual(
			(await provider.search("runtime")).map((entry) => entry.id),
			["mem-1"],
		);
		assert.deepEqual(
			(await provider.search("widget")).map((entry) => entry.id),
			["mem-2"],
		);
		assert.deepEqual(
			(await provider.search("diagnostics")).map((entry) => entry.id),
			["mem-1"],
		);
	});

	it("search_honors_limit_and_empty_query_returns_recent_local_records", async () => {
		const provider = new FederatedMemoryProvider();
		await provider.store({ id: "mem-1", text: "one" });
		await provider.store({ id: "mem-2", text: "two" });

		const results = await provider.search("", { limit: 1 });

		assert.equal(results.length, 1);
		assert.equal(results[0]?.id, "mem-1");
	});
});
