openfused 0.3.23 → 0.4.1
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.
- package/dist/cli.js +12 -24
- package/dist/crypto.d.ts +0 -2
- package/dist/crypto.js +16 -93
- package/dist/store.d.ts +2 -0
- package/dist/store.js +26 -241
- package/dist/wasm-core.d.ts +113 -0
- package/dist/wasm-core.js +179 -0
- package/package.json +6 -4
- package/templates/CHARTER.md +45 -6
- package/templates/CONTEXT.md +10 -0
- package/wasm/.gitkeep +0 -0
- package/wasm/openfuse-core.wasm +0 -0
- package/dist/validity.d.ts +0 -41
- package/dist/validity.js +0 -117
- package/dist/validity.test.d.ts +0 -1
- package/dist/validity.test.js +0 -199
package/dist/validity.test.js
DELETED
|
@@ -1,199 +0,0 @@
|
|
|
1
|
-
// Tests for context validity window module
|
|
2
|
-
// Run: node --import tsx/esm src/validity.test.ts
|
|
3
|
-
// (or after build: node dist/validity.test.js)
|
|
4
|
-
import { describe, it } from "node:test";
|
|
5
|
-
import assert from "node:assert/strict";
|
|
6
|
-
import { parseTtlMs, computeConfidence, parseValiditySections, buildValidityReport, DEFAULT_TTL_TIERS, } from "./validity.js";
|
|
7
|
-
// --- parseTtlMs ---
|
|
8
|
-
describe("parseTtlMs", () => {
|
|
9
|
-
it("parses hours", () => {
|
|
10
|
-
assert.equal(parseTtlMs("6", "h"), 6 * 60 * 60 * 1000);
|
|
11
|
-
});
|
|
12
|
-
it("parses days", () => {
|
|
13
|
-
assert.equal(parseTtlMs("3", "d"), 3 * 24 * 60 * 60 * 1000);
|
|
14
|
-
});
|
|
15
|
-
it("parses 1d", () => {
|
|
16
|
-
assert.equal(parseTtlMs("1", "d"), 24 * 60 * 60 * 1000);
|
|
17
|
-
});
|
|
18
|
-
it("parses 24h", () => {
|
|
19
|
-
assert.equal(parseTtlMs("24", "H"), 24 * 60 * 60 * 1000);
|
|
20
|
-
});
|
|
21
|
-
});
|
|
22
|
-
// --- computeConfidence ---
|
|
23
|
-
describe("computeConfidence", () => {
|
|
24
|
-
const ttl6h = 6 * 60 * 60 * 1000;
|
|
25
|
-
it("returns 1.0 when no addedAt (no timestamp)", () => {
|
|
26
|
-
assert.equal(computeConfidence(undefined, ttl6h), 1.0);
|
|
27
|
-
});
|
|
28
|
-
it("returns 1.0 at write time", () => {
|
|
29
|
-
const now = new Date("2026-03-21T12:00:00Z");
|
|
30
|
-
const addedAt = new Date("2026-03-21T12:00:00Z");
|
|
31
|
-
assert.equal(computeConfidence(addedAt, ttl6h, now), 1.0);
|
|
32
|
-
});
|
|
33
|
-
it("returns 0.5 at TTL boundary", () => {
|
|
34
|
-
const addedAt = new Date("2026-03-21T00:00:00Z");
|
|
35
|
-
const now = new Date("2026-03-21T06:00:00Z"); // exactly 6h later
|
|
36
|
-
const conf = computeConfidence(addedAt, ttl6h, now);
|
|
37
|
-
assert.ok(Math.abs(conf - 0.5) < 0.0001, `expected ~0.5, got ${conf}`);
|
|
38
|
-
});
|
|
39
|
-
it("returns ~0.25 at 2× TTL", () => {
|
|
40
|
-
const addedAt = new Date("2026-03-21T00:00:00Z");
|
|
41
|
-
const now = new Date("2026-03-21T12:00:00Z"); // 12h = 2× TTL
|
|
42
|
-
const conf = computeConfidence(addedAt, ttl6h, now);
|
|
43
|
-
assert.ok(Math.abs(conf - 0.25) < 0.0001, `expected ~0.25, got ${conf}`);
|
|
44
|
-
});
|
|
45
|
-
it("returns < 0.1 at 3.32× TTL (expired threshold)", () => {
|
|
46
|
-
const addedAt = new Date("2026-03-21T00:00:00Z");
|
|
47
|
-
const now = new Date("2026-03-21T20:00:00Z"); // 20h ≈ 3.33× TTL
|
|
48
|
-
const conf = computeConfidence(addedAt, ttl6h, now);
|
|
49
|
-
assert.ok(conf < 0.1, `expected < 0.1, got ${conf}`);
|
|
50
|
-
});
|
|
51
|
-
it("handles future addedAt gracefully (returns 1.0)", () => {
|
|
52
|
-
const addedAt = new Date("2026-03-22T00:00:00Z");
|
|
53
|
-
const now = new Date("2026-03-21T12:00:00Z");
|
|
54
|
-
assert.equal(computeConfidence(addedAt, ttl6h, now), 1.0);
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
// --- parseValiditySections ---
|
|
58
|
-
describe("parseValiditySections", () => {
|
|
59
|
-
it("returns empty array when no validity annotations", () => {
|
|
60
|
-
const content = "# Context\n\nWorking on: auth refactor\n";
|
|
61
|
-
const sections = parseValiditySections(content);
|
|
62
|
-
assert.equal(sections.length, 0);
|
|
63
|
-
});
|
|
64
|
-
it("parses a single validity section with addedAt", () => {
|
|
65
|
-
const addedAt = "2026-03-21T10:00:00Z";
|
|
66
|
-
const now = new Date("2026-03-21T13:00:00Z"); // 3h after write
|
|
67
|
-
const content = [
|
|
68
|
-
"<!-- validity: 6h -->",
|
|
69
|
-
`<!-- openfuse:added: ${addedAt} -->`,
|
|
70
|
-
"Working on: auth refactor",
|
|
71
|
-
"Blocked on: IAM role",
|
|
72
|
-
].join("\n");
|
|
73
|
-
const sections = parseValiditySections(content, now);
|
|
74
|
-
assert.equal(sections.length, 1);
|
|
75
|
-
assert.equal(sections[0].ttlMs, 6 * 60 * 60 * 1000);
|
|
76
|
-
// toISOString() returns .000Z suffix; just check the date round-trips
|
|
77
|
-
assert.ok(sections[0].addedAt instanceof Date);
|
|
78
|
-
assert.equal(sections[0].addedAt.getTime(), new Date(addedAt).getTime());
|
|
79
|
-
assert.ok(sections[0].confidence > 0.5, "should be > 0.5 at 3h of 6h TTL");
|
|
80
|
-
assert.equal(sections[0].expired, false);
|
|
81
|
-
assert.ok(sections[0].sectionText.includes("auth refactor"));
|
|
82
|
-
});
|
|
83
|
-
it("parses a section without addedAt (confidence = 1.0)", () => {
|
|
84
|
-
const content = [
|
|
85
|
-
"<!-- validity: 1d -->",
|
|
86
|
-
"Architecture: JWT with 15-minute expiry",
|
|
87
|
-
].join("\n");
|
|
88
|
-
const sections = parseValiditySections(content);
|
|
89
|
-
assert.equal(sections.length, 1);
|
|
90
|
-
assert.equal(sections[0].addedAt, undefined);
|
|
91
|
-
assert.equal(sections[0].confidence, 1.0);
|
|
92
|
-
assert.equal(sections[0].expired, false);
|
|
93
|
-
});
|
|
94
|
-
it("marks expired sections correctly", () => {
|
|
95
|
-
const addedAt = "2026-03-20T00:00:00Z"; // 48h ago
|
|
96
|
-
const now = new Date("2026-03-22T00:00:00Z");
|
|
97
|
-
const content = [
|
|
98
|
-
"<!-- validity: 6h -->",
|
|
99
|
-
`<!-- openfuse:added: ${addedAt} -->`,
|
|
100
|
-
"Blocked on: IAM role",
|
|
101
|
-
].join("\n");
|
|
102
|
-
const sections = parseValiditySections(content, now);
|
|
103
|
-
assert.equal(sections.length, 1);
|
|
104
|
-
assert.equal(sections[0].expired, true);
|
|
105
|
-
assert.ok(sections[0].confidence < 0.1);
|
|
106
|
-
});
|
|
107
|
-
it("parses multiple validity sections independently", () => {
|
|
108
|
-
const now = new Date("2026-03-22T00:00:00Z");
|
|
109
|
-
const freshAdded = "2026-03-21T23:00:00Z"; // 1h ago — fresh vs 6h TTL
|
|
110
|
-
const staleAdded = "2026-03-18T00:00:00Z"; // 96h ago — expired vs 24h TTL (0.5^4 = 0.0625 < 0.1)
|
|
111
|
-
const content = [
|
|
112
|
-
"# Context",
|
|
113
|
-
"",
|
|
114
|
-
"<!-- validity: 6h -->",
|
|
115
|
-
`<!-- openfuse:added: ${freshAdded} -->`,
|
|
116
|
-
"Working on: auth refactor",
|
|
117
|
-
"",
|
|
118
|
-
"<!-- validity: 1d -->",
|
|
119
|
-
`<!-- openfuse:added: ${staleAdded} -->`,
|
|
120
|
-
"Sprint goal: ship auth by Friday",
|
|
121
|
-
].join("\n");
|
|
122
|
-
const sections = parseValiditySections(content, now);
|
|
123
|
-
assert.equal(sections.length, 2);
|
|
124
|
-
assert.equal(sections[0].expired, false);
|
|
125
|
-
assert.equal(sections[1].expired, true);
|
|
126
|
-
});
|
|
127
|
-
it("parses validity with component annotation", () => {
|
|
128
|
-
const content = [
|
|
129
|
-
"<!-- validity: 6h, component: auth-gateway -->",
|
|
130
|
-
"Working on: JWT refactor",
|
|
131
|
-
].join("\n");
|
|
132
|
-
const sections = parseValiditySections(content);
|
|
133
|
-
assert.equal(sections.length, 1);
|
|
134
|
-
assert.equal(sections[0].ttlMs, 6 * 60 * 60 * 1000);
|
|
135
|
-
});
|
|
136
|
-
it("parses day-based TTL", () => {
|
|
137
|
-
const content = [
|
|
138
|
-
"<!-- validity: 3d -->",
|
|
139
|
-
"Architecture: microservices with shared auth layer",
|
|
140
|
-
].join("\n");
|
|
141
|
-
const sections = parseValiditySections(content);
|
|
142
|
-
assert.equal(sections.length, 1);
|
|
143
|
-
assert.equal(sections[0].ttlMs, 3 * 24 * 60 * 60 * 1000);
|
|
144
|
-
});
|
|
145
|
-
});
|
|
146
|
-
// --- buildValidityReport ---
|
|
147
|
-
describe("buildValidityReport", () => {
|
|
148
|
-
it("returns correct counts for mixed fresh/stale", () => {
|
|
149
|
-
const now = new Date("2026-03-22T00:00:00Z");
|
|
150
|
-
const freshAdded = "2026-03-21T23:00:00Z";
|
|
151
|
-
const staleAdded = "2026-03-20T00:00:00Z";
|
|
152
|
-
const content = [
|
|
153
|
-
"<!-- validity: 6h -->",
|
|
154
|
-
`<!-- openfuse:added: ${freshAdded} -->`,
|
|
155
|
-
"Working on: auth refactor",
|
|
156
|
-
"",
|
|
157
|
-
"<!-- validity: 6h -->",
|
|
158
|
-
`<!-- openfuse:added: ${staleAdded} -->`,
|
|
159
|
-
"Blocked on: IAM role (OLD)",
|
|
160
|
-
].join("\n");
|
|
161
|
-
const sections = parseValiditySections(content, now);
|
|
162
|
-
const report = buildValidityReport(sections);
|
|
163
|
-
assert.equal(report.total, 2);
|
|
164
|
-
assert.equal(report.fresh, 1);
|
|
165
|
-
assert.equal(report.stale, 1);
|
|
166
|
-
});
|
|
167
|
-
it("formats ttlLabel correctly for hours and days", () => {
|
|
168
|
-
const content = [
|
|
169
|
-
"<!-- validity: 6h -->",
|
|
170
|
-
"Task context",
|
|
171
|
-
"",
|
|
172
|
-
"<!-- validity: 1d -->",
|
|
173
|
-
"Sprint context",
|
|
174
|
-
"",
|
|
175
|
-
"<!-- validity: 3d -->",
|
|
176
|
-
"Architecture context",
|
|
177
|
-
].join("\n");
|
|
178
|
-
const sections = parseValiditySections(content);
|
|
179
|
-
const report = buildValidityReport(sections);
|
|
180
|
-
assert.equal(report.entries[0].ttlLabel, "6h");
|
|
181
|
-
assert.equal(report.entries[1].ttlLabel, "1d");
|
|
182
|
-
assert.equal(report.entries[2].ttlLabel, "3d");
|
|
183
|
-
});
|
|
184
|
-
it("truncates long section previews to 80 chars", () => {
|
|
185
|
-
const longLine = "A".repeat(100);
|
|
186
|
-
const content = `<!-- validity: 6h -->\n${longLine}`;
|
|
187
|
-
const sections = parseValiditySections(content);
|
|
188
|
-
const report = buildValidityReport(sections);
|
|
189
|
-
assert.ok(report.entries[0].preview.length <= 80);
|
|
190
|
-
});
|
|
191
|
-
});
|
|
192
|
-
// --- DEFAULT_TTL_TIERS ---
|
|
193
|
-
describe("DEFAULT_TTL_TIERS", () => {
|
|
194
|
-
it("has expected values", () => {
|
|
195
|
-
assert.equal(DEFAULT_TTL_TIERS.task, 6 * 60 * 60 * 1000);
|
|
196
|
-
assert.equal(DEFAULT_TTL_TIERS.sprint, 24 * 60 * 60 * 1000);
|
|
197
|
-
assert.equal(DEFAULT_TTL_TIERS.architecture, 72 * 60 * 60 * 1000);
|
|
198
|
-
});
|
|
199
|
-
});
|