refactor: restructure into herdr/herdr-composer, rename ovis-composer -> herdr-composer, migrate stored data

Co-Authored-By: Ovis Fast (Claude) <[email protected]>
This commit is contained in:
FactorandOvis Fast committed 2026-11-19 12:52:42 +01:00
1 parent 6beecaac83
commit 74c1dfaeb8
27 files changed
+253 -97

No files matched your search

+98 -11
View File
@@ -3,7 +3,7 @@ import assert from "node:assert/strict";
import {
HISTORY_LIMIT, queueKey, loadHistory, saveHistory, loadQueue, saveQueue, loadUsage, saveUsage,
KEYS, draftKey, loadDraft, saveDraft,
} from "../mod/ovis-composer/storage.js";
} from "../herdr/herdr-composer/mods/herdr-composer/storage.js";
const memStore = () => {
const m = new Map();
@@ -23,12 +23,12 @@ test("saveHistory truncates to 500, keeping the newest", () => {
test("history drops invalid entries on load", () => {
const store = memStore();
store.set("ovis-composer.history", [{ id: "a", text: "x", at: 1 }, { id: "b" }, null]);
store.set("herdr-composer.history", [{ id: "a", text: "x", at: 1 }, { id: "b" }, null]);
assert.equal(loadHistory(store).length, 1);
});
test("queueKey is per agent", () => {
assert.equal(queueKey("a1"), "ovis-composer.queue:a1");
assert.equal(queueKey("a1"), "herdr-composer.queue:a1");
});
test("queue roundtrip; keeps sending state as written", () => {
@@ -42,7 +42,7 @@ test("queue roundtrip; keeps sending state as written", () => {
test("saveQueue ignores empty agent", () => {
const store = memStore();
saveQueue(store, "", [{ id: "1", text: "t", state: "queued", createdAt: 1 }]);
assert.equal(store.get("ovis-composer.queue:"), undefined);
assert.equal(store.get("herdr-composer.queue:"), undefined);
});
test("usage keeps only non-negative finite numbers", () => {
@@ -64,8 +64,8 @@ const draft = (over = {}) => ({
});
test("draftKey is per agent", () => {
assert.equal(KEYS.draft, "ovis-composer.draft");
assert.equal(draftKey("t2"), "ovis-composer.draft:t2");
assert.equal(KEYS.draft, "herdr-composer.draft");
assert.equal(draftKey("t2"), "herdr-composer.draft:t2");
});
test("draft roundtrip", () => {
@@ -97,7 +97,7 @@ test("saveDraft ignores rubbish and empty agent", () => {
saveDraft(store, "t2", "x");
saveDraft(store, "", draft());
assert.equal(loadDraft(store, "t2").text, "hello");
assert.equal(store.get("ovis-composer.draft:"), undefined);
assert.equal(store.get("herdr-composer.draft:"), undefined);
});
test("empty draft overwrites the old one", () => {
@@ -133,7 +133,7 @@ test("queue roundtrip keeps a countdown entry (restart turns it into held)", ()
assert.deepEqual(loadQueue(store, "a"), q);
});
import { loadUserMin, saveUserMin } from "../mod/ovis-composer/storage.js";
import { loadUserMin, saveUserMin } from "../herdr/herdr-composer/mods/herdr-composer/storage.js";
test("userMin: the height the person dragged the composer to; 0 is none", () => {
const store = memStore();
@@ -142,10 +142,97 @@ test("userMin: the height the person dragged the composer to; 0 is none", () =>
assert.equal(loadUserMin(store), 300);
saveUserMin(store, 0);
assert.equal(loadUserMin(store), 0);
store.set("ovis-composer.userMin", "x");
store.set("herdr-composer.userMin", "x");
assert.equal(loadUserMin(store), 0);
store.set("ovis-composer.userMin", -5);
store.set("herdr-composer.userMin", -5);
assert.equal(loadUserMin(store), 0);
saveUserMin(store, NaN);
assert.equal(store.get("ovis-composer.userMin"), -5);
assert.equal(store.get("herdr-composer.userMin"), -5);
});
// --- the rename ovis-composer -> herdr-composer: nothing the person kept is lost
import { LEGACY_PREFIX, loadFavorites } from "../herdr/herdr-composer/mods/herdr-composer/storage.js";
const OLD = "ovis-composer.";
const NEW = "herdr-composer.";
test("migration: the legacy prefix", () => {
assert.equal(LEGACY_PREFIX, "ovis-composer.");
assert.equal(KEYS.history, "herdr-composer.history");
assert.equal(queueKey("t2"), "herdr-composer.queue:t2");
assert.equal(draftKey("t2"), "herdr-composer.draft:t2");
});
test("migration: the new key wins over the old one", () => {
const store = memStore();
store.set(OLD + "history", [{ id: "old", text: "old", at: 1 }]);
store.set(NEW + "history", [{ id: "new", text: "new", sentAt: 2 }]);
assert.deepEqual(loadHistory(store).map((e) => e.id), ["new"]);
});
test("migration: history from the old key is read and written under the new one; the old stays", () => {
const store = memStore();
const old = [{ id: "old", text: "old", at: 1 }];
store.set(OLD + "history", old);
assert.deepEqual(loadHistory(store).map((e) => e.id), ["old"]);
assert.deepEqual(store.get(NEW + "history"), old);
assert.deepEqual(store.get(OLD + "history"), old);
});
test("migration: favourites, usage, queue, draft and userMin come across the same way", () => {
const store = memStore();
store.set(OLD + "favorites", [{ id: "f", text: "x", at: 4 }]);
store.set(OLD + "usage", { review: 2 });
store.set(OLD + "queue:t2", [{ id: "1", text: "t", state: "held", createdAt: 5 }]);
store.set(OLD + "draft:t2", { text: "szkic", caret: 2, attachments: [], identity: { created_ms: 9, app: null }, savedAt: 1 });
store.set(OLD + "userMin", 300);
assert.equal(loadFavorites(store)[0].createdAt, 4);
assert.deepEqual(loadUsage(store), { review: 2 });
assert.equal(loadQueue(store, "t2")[0].state, "held");
assert.equal(loadDraft(store, "t2").text, "szkic");
assert.equal(loadUserMin(store), 300);
for (const key of ["favorites", "usage", "queue:t2", "draft:t2", "userMin"]) {
assert.notEqual(store.get(NEW + key), undefined, key);
assert.notEqual(store.get(OLD + key), undefined, key);
}
});
test("migration: neither key -> the defaults, and nothing is written", () => {
const store = memStore();
assert.deepEqual(loadHistory(store), []);
assert.deepEqual(loadFavorites(store), []);
assert.deepEqual(loadUsage(store), {});
assert.deepEqual(loadQueue(store, "t2"), []);
assert.equal(loadDraft(store, "t2"), null);
assert.equal(loadUserMin(store), 0);
assert.equal(store.get(NEW + "history"), undefined);
assert.equal(store.get(NEW + "draft:t2"), undefined);
});
test("migration: rubbish in the old key is ignored as before, and not copied", () => {
const store = memStore();
store.set(OLD + "history", "x");
store.set(OLD + "favorites", [{ nope: 1 }]);
store.set(OLD + "queue:t2", [{ id: "1" }]);
store.set(OLD + "draft:t2", [1, 2]);
store.set(OLD + "usage", { a: -1, b: "x" });
store.set(OLD + "userMin", -3);
assert.deepEqual(loadHistory(store), []);
assert.deepEqual(loadFavorites(store), []);
assert.deepEqual(loadQueue(store, "t2"), []);
assert.equal(loadDraft(store, "t2"), null);
assert.deepEqual(loadUsage(store), {});
assert.equal(loadUserMin(store), 0);
for (const key of ["history", "favorites", "queue:t2", "draft:t2", "usage", "userMin"]) {
assert.equal(store.get(NEW + key), undefined, key);
}
});
test("migration: a store that cannot be written to still reads the old data", () => {
const raw = new Map([[OLD + "history", [{ id: "old", text: "old", at: 1 }]]]);
const store = { get: (k) => raw.get(k), set: () => { throw new Error("read-only"); } };
assert.deepEqual(loadHistory(store).map((e) => e.id), ["old"]);
});