Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

fix(history): render legacy instruction changes without provenance

Afloate1a844a95125
diff --git a/server/profile-versions.test.ts b/server/profile-versions.test.ts
index 6842f8757c..caf79da7c0 100644
--- a/server/profile-versions.test.ts
+++ b/server/profile-versions.test.ts
@@ -156,6 +156,18 @@ describe("profile history", () => {
});
describe("instruction changes in the Changes list", () => {
+ it("shows legacy instruction changes that have no provenance field", () => {
+ const id = "hist-legacy-soul-changes";
+ withBotFolder(id);
+ writeFileSync(historyFile(id), JSON.stringify({ at: 1, actor: "user", field: "soul", before: "Be brief.", after: "Use metric units." }) + "\n");
+ const history = readHistory(id);
+ const changes = soulChanges(id, history);
+ expect(changes).toHaveLength(1);
+ expect(changes[0]).toMatchObject({ id: history[0]!.id, actor: "person", via: "", canRevert: true, added: 1, removed: 1 });
+ expect(changes[0]!.diff).toContain("+Use metric units.");
+ expect(changes[0]!.diff).toContain("-Be brief.");
+ });
+
it("says who changed them, with a diff, and offers Undo for each", async () => {
const id = "hist-soul-changes";
withBotFolder(id);
diff --git a/server/profile-versions.ts b/server/profile-versions.ts
index f4ccb92af3..b679e9e8a7 100644
--- a/server/profile-versions.ts
+++ b/server/profile-versions.ts
@@ -163,9 +163,10 @@ const CHANGE_ACTOR = { user: "person", bot: "bot", file: "person", import: "impo
export function soulChanges(botId: string, rows: readonly HistoryRow[]) {
return rows.filter((row) => row.field === "soul").map((row) => {
const diff = unifiedDiff(row.before ?? "", row.after ?? "", SOUL_FILE);
+ const via = typeof row.via === "string" ? row.via : "";
return {
id: row.id, at: row.at, botId, path: SOUL_FILE, actor: CHANGE_ACTOR[row.actor] ?? "person",
- via: row.actor === "file" ? "disk" : row.via === "rollback" || row.via.startsWith("undo:") ? "revert" : row.via,
+ via: row.actor === "file" ? "disk" : via === "rollback" || via.startsWith("undo:") ? "revert" : via,
kind: "edited" as const, beforeHash: null, afterHash: null, diff: diff.text, added: diff.added, removed: diff.removed,
canRevert: row.canRestore === true, ...(row.restoreUnavailableReason ? { revertUnavailableReason: row.restoreUnavailableReason } : {}),
};