@forwardimpact/libutil 0.1.70 → 0.1.73

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,123 +0,0 @@
1
- import { test, describe, beforeEach } from "node:test";
2
- import assert from "node:assert";
3
-
4
- // Module under test
5
- import { Tokenizer, ranks } from "../tokenizer.js";
6
- import { countTokens, createTokenizer } from "../index.js";
7
-
8
- describe("Tokenizer", () => {
9
- describe("constructor", () => {
10
- test("creates instance with ranks parameter", () => {
11
- const tokenizer = new Tokenizer(ranks);
12
- assert.ok(tokenizer instanceof Tokenizer);
13
- });
14
-
15
- test("creates instance without ranks parameter", () => {
16
- const tokenizer = new Tokenizer();
17
- assert.ok(tokenizer instanceof Tokenizer);
18
- });
19
- });
20
-
21
- describe("encode", () => {
22
- let tokenizer;
23
-
24
- beforeEach(() => {
25
- tokenizer = new Tokenizer(ranks);
26
- });
27
-
28
- test("handles empty string", () => {
29
- const result = tokenizer.encode("");
30
- assert.strictEqual(result.length, 0);
31
- });
32
-
33
- test("handles non-string input", () => {
34
- const result = tokenizer.encode(null);
35
- assert.strictEqual(result.length, 0);
36
- });
37
-
38
- test("encodes simple word", () => {
39
- const result = tokenizer.encode("hello");
40
- assert.ok(result.length >= 1);
41
- assert.ok(Array.isArray(result));
42
- });
43
-
44
- test("encodes longer text", () => {
45
- const shortText = "hello";
46
- const longText = "hello world this is a longer piece of text";
47
-
48
- const shortResult = tokenizer.encode(shortText);
49
- const longResult = tokenizer.encode(longText);
50
-
51
- assert.ok(longResult.length > shortResult.length);
52
- });
53
-
54
- test("handles whitespace-only text", () => {
55
- const result = tokenizer.encode(" ");
56
- assert.strictEqual(result.length, 0);
57
- });
58
-
59
- test("handles punctuation", () => {
60
- const result = tokenizer.encode("Hello, world!");
61
- assert.ok(result.length >= 3); // At least hello + comma + world + exclamation
62
- });
63
-
64
- test("handles mixed content", () => {
65
- const result = tokenizer.encode("The year 2024 was great!");
66
- assert.ok(result.length >= 5); // Multiple words and punctuation
67
- });
68
-
69
- test("provides reasonable approximation", () => {
70
- // Test that the approximation is in a reasonable range
71
- const text = "This is a test sentence with about ten words here.";
72
- const result = tokenizer.encode(text);
73
-
74
- // Should be roughly 10-15 tokens for this sentence
75
- assert.ok(result.length >= 8);
76
- assert.ok(result.length <= 20);
77
- });
78
- });
79
-
80
- describe("decode", () => {
81
- test("throws error when called", () => {
82
- const tokenizer = new Tokenizer(ranks);
83
- assert.throws(() => tokenizer.decode([1, 2, 3]), {
84
- message: /decode\(\) not implemented/,
85
- });
86
- });
87
- });
88
- });
89
-
90
- describe("Integration with libutil functions", () => {
91
- describe("tokenizerFactory", () => {
92
- test("creates Tokenizer instance", () => {
93
- const tokenizer = createTokenizer();
94
- assert.ok(tokenizer instanceof Tokenizer);
95
- });
96
- });
97
-
98
- describe("countTokens", () => {
99
- test("returns token count for text", () => {
100
- const count = countTokens("hello world");
101
- assert.ok(typeof count === "number");
102
- assert.ok(count >= 1);
103
- });
104
-
105
- test("handles empty text", () => {
106
- const count = countTokens("");
107
- assert.strictEqual(count, 0);
108
- });
109
-
110
- test("uses provided tokenizer", () => {
111
- const customTokenizer = new Tokenizer(ranks);
112
- const count = countTokens("test", customTokenizer);
113
- assert.ok(typeof count === "number");
114
- assert.ok(count >= 1);
115
- });
116
-
117
- test("uses default tokenizer when none provided", () => {
118
- const count = countTokens("test");
119
- assert.ok(typeof count === "number");
120
- assert.ok(count >= 1);
121
- });
122
- });
123
- });
package/test/wait.test.js DELETED
@@ -1,109 +0,0 @@
1
- import { describe, test } from "node:test";
2
- import assert from "node:assert";
3
-
4
- import { waitFor } from "../wait.js";
5
-
6
- const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
7
-
8
- describe("waitFor", () => {
9
- test("throws if delayFn is missing", async () => {
10
- await assert.rejects(
11
- () => waitFor(() => Promise.resolve(true), {}),
12
- /delayFn is required/,
13
- );
14
- });
15
-
16
- test("resolves immediately when condition is true", async () => {
17
- let callCount = 0;
18
- await waitFor(
19
- () => {
20
- callCount++;
21
- return Promise.resolve(true);
22
- },
23
- {},
24
- delay,
25
- );
26
-
27
- assert.strictEqual(callCount, 1);
28
- });
29
-
30
- test("retries until condition becomes true", async () => {
31
- let callCount = 0;
32
- await waitFor(
33
- () => {
34
- callCount++;
35
- return Promise.resolve(callCount >= 3);
36
- },
37
- { interval: 10, timeout: 5000 },
38
- delay,
39
- );
40
-
41
- assert.strictEqual(callCount, 3);
42
- });
43
-
44
- test("throws error on timeout", async () => {
45
- await assert.rejects(
46
- () =>
47
- waitFor(
48
- () => Promise.resolve(false),
49
- { timeout: 50, interval: 10 },
50
- delay,
51
- ),
52
- { message: "Timeout waiting for condition after 50ms" },
53
- );
54
- });
55
-
56
- test("ignores errors during polling", async () => {
57
- let callCount = 0;
58
- await waitFor(
59
- () => {
60
- callCount++;
61
- if (callCount < 3) {
62
- throw new Error("Service not ready");
63
- }
64
- return Promise.resolve(true);
65
- },
66
- { interval: 10, timeout: 5000 },
67
- delay,
68
- );
69
-
70
- assert.strictEqual(callCount, 3);
71
- });
72
-
73
- test("uses default options when not provided", async () => {
74
- let called = false;
75
- await waitFor(
76
- () => {
77
- called = true;
78
- return Promise.resolve(true);
79
- },
80
- {},
81
- delay,
82
- );
83
-
84
- assert.strictEqual(called, true);
85
- });
86
-
87
- test("increases interval with exponential backoff", async () => {
88
- const intervals = [];
89
- let lastTime = Date.now();
90
- let callCount = 0;
91
-
92
- await waitFor(
93
- () => {
94
- const now = Date.now();
95
- if (callCount > 0) {
96
- intervals.push(now - lastTime);
97
- }
98
- lastTime = now;
99
- callCount++;
100
- return Promise.resolve(callCount >= 4);
101
- },
102
- { interval: 20, maxInterval: 100, timeout: 5000 },
103
- delay,
104
- );
105
-
106
- // Intervals should generally increase (with some tolerance for timing)
107
- assert.ok(intervals.length >= 2);
108
- });
109
- });
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes