# test.govlab/context/core/stores/algorithm.store.test.ts

> 37 lines of code and 0 definitions.

Tree: Codebase Testing
Language: typescript
Canonical: https://banes-lab.com/anatomy/testing#file-testing-test-govlab-context-core-stores-algorithm-store-test-ts
Source text: https://banes-lab.com/source/testing/test.govlab/context/core/stores/algorithm.store.test.ts.txt

Listed in [test.govlab/context/core/stores](https://banes-lab.com/api/source/testing/test.govlab/context/core/stores.md), before [test.govlab/context/core/stores/architecture.store.test.ts](https://banes-lab.com/source/testing/test.govlab/context/core/stores/architecture.store.test.ts.md).

## Contained in

- [test.govlab/context/core/stores](https://banes-lab.com/anatomy/testing/folder-testing-test-govlab-context-core-stores.md)

## Source

```typescript
import { AlgorithmStore } from "@govlab/context/core/stores/algorithm.store.ts";
import type { ContractRecord } from "@govlab/context/types/algorithm.types.ts";
import assert from "node:assert/strict";
import { test } from "vitest";

const record = (id: string, composes: string[] = []): ContractRecord => ({
    composes,
    flow: [],
    force: ["speed"],
    id,
    intent: "i",
    invariant: "v",
    productions: [],
    title: id,
});

const warnings: string[] = [];

const store = new AlgorithmStore({
    data: [{ category: "planted", records: [record("hub", ["leaf", "ghost"]), record("leaf")], tier: "leaf" }],
    logger: {
        warn: (message) => {
            warnings.push(message);
        },
    },
    symbols: [],
});

test("the algorithm store resolves a closure along composes and warns on an unknown seed", () => {
    const closure = store.resolveClosure(["hub", "missing"]);
    assert.deepEqual(closure.order, ["hub", "leaf"]);
    assert.deepEqual(closure.seed, ["hub"]);
    assert.ok(warnings.some((warning) => warning.includes('"missing"')));
});

test("the algorithm store filters by force, clusters, joins concerns and reports a dangling compose", () => {
    assert.equal(store.byForce("speed").length, 2);
    assert.equal(store.cluster().length, 1);
    assert.equal(store.joinConcerns()[0]?.force, "speed");
    assert.deepEqual(store.symbols(), []);
    assert.deepEqual(store.validateOntology().danglingComposes, [{ from: "hub", target: "ghost" }]);
});
```
