schema stamps: lazy v1 for chats + the graph family, honest refusal
Chat records gain version (CURRENT_CHAT_VERSION), stamped by a single writeChat choke point in the store; absence reads as v1 — existing files migrate on their next write, no mass rewrite. The graph family (four JSONL ledgers, sources.json, render-settings.json) shares one lazy sidecar, graph/format.json; positions stays unstamped (rebuildable) and jobs stay unstamped (transient). Downgrade scenario ruled honest-refusal: records stamped newer than the running build read as absent (chats, logged) or throw (graph family) — a read-modify-write store never rewrites what it doesn't understand. Golden fixtures stay the unstamped legacy shape on purpose (lazy v1 is current-valid by design); the stamped write path is pinned by tests/schema-stamps.test.ts. Reads never write — the golden byte-identical pin holds.
This commit is contained in:
@@ -13,9 +13,11 @@ import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { RENDER_SETTINGS_FILE } from "../../config.ts";
|
||||
import { DEFAULT_RENDER_SETTINGS, sanitizeRenderSettings, type GraphRenderSettings } from "../core/render-settings.ts";
|
||||
import { assertGraphFormat, ensureGraphFormat } from "./graph-format.ts";
|
||||
|
||||
/** The persisted settings, or null when no file exists yet (first boot). */
|
||||
export function readRenderSettings(): GraphRenderSettings | null {
|
||||
assertGraphFormat(); // honest refusal on a newer-stamped data dir
|
||||
let raw: string;
|
||||
try {
|
||||
raw = fs.readFileSync(RENDER_SETTINGS_FILE, "utf-8");
|
||||
@@ -33,6 +35,7 @@ export function readRenderSettings(): GraphRenderSettings | null {
|
||||
export function writeRenderSettings(raw: unknown): GraphRenderSettings {
|
||||
const settings = sanitizeRenderSettings(raw);
|
||||
fs.mkdirSync(path.dirname(RENDER_SETTINGS_FILE), { recursive: true });
|
||||
ensureGraphFormat(); // the lazy format stamp (graph-format.ts)
|
||||
fs.writeFileSync(RENDER_SETTINGS_FILE, JSON.stringify(settings, null, "\t"), "utf-8");
|
||||
return settings;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user