Files
waggle-os/packages/core/tests/embeddings/inprocess-embedder.test.ts
shumeiko.it 0fef37ac53 chore(core): mark the files copied from hive-mind-core as Apache-2.0
The logger, injection scanner, ingress guard, WorkspaceManager, embedders,
recall helpers and execution traces came from @waggle/hive-mind-core
(Apache-2.0); awareness, identity and parts of WaggleDB were adapted from
it. They keep Apache-2.0: an SPDX header with the original copyright line
and the source file, packages/core/LICENSE.md listing them,
LICENSE-APACHE with the full text, and "MIT AND Apache-2.0" in
package.json. A test keeps the list and the headers in step. No code
changes.

Logs UF-069: the hive-mind-core LICENSE is an abridged Apache text.
2026-11-04 10:19:05 +01:00

42 lines
1.7 KiB
TypeScript

// SPDX-License-Identifier: Apache-2.0
// Copyright 2026 Marko Marković · Egzakta Group · waggle-os.ai
// Copied from @waggle/hive-mind-core tests/mind/inprocess-embedder.test.ts and changed for @waggle/core.
/**
* In-process embedder tests: `normalizeDimensions(input, target)` and its
* "no-copy fast path when dims match" contract.
*/
import { describe, it, expect } from 'vitest';
import { normalizeDimensions } from '../../src/embeddings/inprocess-embedder.js';
describe('normalizeDimensions', () => {
it('returns the same vector when lengths already match', () => {
const input = new Float32Array([1, 2, 3, 4]);
const output = normalizeDimensions(input, 4);
// Implementation intentionally returns the same reference when dims match
// — this is a public behavioural contract (no-copy fast path).
expect(output).toBe(input);
expect(Array.from(output)).toEqual([1, 2, 3, 4]);
});
it('zero-pads when the input is shorter than the target', () => {
const input = new Float32Array([1, 2, 3]);
const output = normalizeDimensions(input, 6);
expect(output.length).toBe(6);
expect(Array.from(output)).toEqual([1, 2, 3, 0, 0, 0]);
});
it('truncates when the input is longer than the target', () => {
const input = new Float32Array([1, 2, 3, 4, 5, 6]);
const output = normalizeDimensions(input, 3);
expect(output.length).toBe(3);
expect(Array.from(output)).toEqual([1, 2, 3]);
});
it('handles empty input by producing a zero-filled target vector', () => {
const input = new Float32Array([]);
const output = normalizeDimensions(input, 4);
expect(output.length).toBe(4);
expect(Array.from(output)).toEqual([0, 0, 0, 0]);
});
});