per-session models: every session owns its model + thinking level from birth
The reported bug (2026-09-28): every chat ran glm-5.3-flash regardless of any pick, while composer and settings UIs agreed with each other and lied about the run. Root cause: a fossil default-settings record (settings.json chat section, frozen pre-slots-wave) was stamped verbatim into every new chat at birth by the new-session flow, and resolveConversationSpec prefers the per-chat record over the strong slot forever. Owner redesign — models are per session, always; the strong slot is the new-session default: - POST /api/chats stamps the newborn verbatim from the strong slot (model + thinking level); no client settings PUT on create anymore - the composer control is dual-bound: in-session it reads/writes the session's own record (GET /api/chats/:id, PUT .../settings); on the draft surfaces it binds the strong slot (picking there = changing the default) - thinking levels follow the identical mechanics (confirmed by owner) - the zombie default-settings system dies whole: useDefaultSettings, /api/settings/defaults, src/store/default-settings.ts, the chat section of UserSettings (sanitizer strips fossil copies), the legacy default-settings.json fold, and DEFAULT_SETTINGS_FILE - catalogDefaultsFor collapses to the strong slot alone - thinking display for a legacy unstamped session resolves exactly like the engine (session ?? strong ?? model ladder) Tests: new chat-birth-stamp suite pins the stamp, the unconfigured boot, the unset level, and the copy-not-live-view regression; defaults pins rewritten strong-only; legacy-migration suite deleted.
This commit is contained in:
@@ -1,28 +1,23 @@
|
||||
/**
|
||||
* Tests for the settings STORE (settings-storage wave, 2026-09-19):
|
||||
* src/store/settings.ts — the record's fs adapter + the LAZY MIGRATION
|
||||
* from the legacy default-settings.json — and the record-backed
|
||||
* default-settings facade (src/store/default-settings.ts). Writes the
|
||||
* real repo data/ files (npm test's shared data/, disposable scratch by
|
||||
* doctrine) and cleans up after itself; a pre-existing settings.json is
|
||||
* snapshotted and restored so the wave's own dev state survives the run.
|
||||
* src/store/settings.ts — the record's fs adapter. Writes the real repo
|
||||
* data/ files (npm test's shared data/, disposable scratch by doctrine)
|
||||
* and cleans up after itself; a pre-existing settings.json is snapshotted
|
||||
* and restored so the worktree's own dev state survives the run.
|
||||
*
|
||||
* (The legacy default-settings.json fold and the chat-section facade died
|
||||
* with per-session models, owner 2026-09-28 — sessions own their model
|
||||
* from birth, stamped from the strong slot server-side.)
|
||||
*/
|
||||
|
||||
import assert from "node:assert/strict";
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { after, afterEach, describe, it } from "node:test";
|
||||
import { DEFAULT_SETTINGS_FILE, SETTINGS_FILE } from "../config.ts";
|
||||
import { SETTINGS_FILE } from "../config.ts";
|
||||
import { readSettings, writeSettings } from "../src/store/settings.ts";
|
||||
import { readDefaultSettings, writeDefaultSettings } from "../src/store/default-settings.ts";
|
||||
import type { ChatSettings } from "../src/core";
|
||||
|
||||
const CHAT_FIXTURE: ChatSettings = {
|
||||
model: { provider: "openrouter", id: "z-ai/glm-5.3-flash" },
|
||||
thinkingLevel: "low",
|
||||
};
|
||||
|
||||
// Snapshot any pre-existing files; restore in after() so the worktree's
|
||||
// Snapshot any pre-existing record; restore in after() so the worktree's
|
||||
// own dev state survives a test run.
|
||||
let hadSettings = false;
|
||||
let savedSettings = "";
|
||||
@@ -30,22 +25,11 @@ try {
|
||||
savedSettings = fs.readFileSync(SETTINGS_FILE, "utf-8");
|
||||
hadSettings = true;
|
||||
} catch {
|
||||
/* none */
|
||||
/* first boot — nothing to snapshot */
|
||||
}
|
||||
let hadDefaults = false;
|
||||
let savedDefaults = "";
|
||||
try {
|
||||
savedDefaults = fs.readFileSync(DEFAULT_SETTINGS_FILE, "utf-8");
|
||||
hadDefaults = true;
|
||||
} catch {
|
||||
/* none */
|
||||
}
|
||||
|
||||
after(() => {
|
||||
if (hadSettings) fs.writeFileSync(SETTINGS_FILE, savedSettings, "utf-8");
|
||||
else fs.rmSync(SETTINGS_FILE, { force: true });
|
||||
if (hadDefaults) fs.writeFileSync(DEFAULT_SETTINGS_FILE, savedDefaults, "utf-8");
|
||||
else fs.rmSync(DEFAULT_SETTINGS_FILE, { force: true });
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
@@ -53,9 +37,8 @@ afterEach(() => {
|
||||
});
|
||||
|
||||
describe("the settings store", () => {
|
||||
it("reads null on first boot (no record, no legacy file)", () => {
|
||||
it("reads null on first boot (no record)", () => {
|
||||
fs.rmSync(SETTINGS_FILE, { force: true });
|
||||
fs.rmSync(DEFAULT_SETTINGS_FILE, { force: true });
|
||||
assert.equal(readSettings(), null);
|
||||
});
|
||||
|
||||
@@ -66,56 +49,28 @@ describe("the settings store", () => {
|
||||
assert.deepEqual(out.graph, { enabled: false });
|
||||
});
|
||||
|
||||
it("a chat section on disk is IGNORED — the field died with per-session models (owner, 2026-09-28)", () => {
|
||||
fs.mkdirSync(path.dirname(SETTINGS_FILE), { recursive: true });
|
||||
// A fossil `chat` section (the old default-settings record) must not
|
||||
// resurrect through the sanitizer — the key is simply gone.
|
||||
fs.writeFileSync(
|
||||
SETTINGS_FILE,
|
||||
JSON.stringify({
|
||||
version: 1,
|
||||
chat: { model: { provider: "openrouter", id: "z-ai/glm-5.3-flash" }, thinkingLevel: "low" },
|
||||
graph: { enabled: true },
|
||||
}),
|
||||
"utf-8",
|
||||
);
|
||||
const out = readSettings();
|
||||
assert.ok(out);
|
||||
assert.equal("chat" in out, false, "the chat section never surfaces");
|
||||
assert.deepEqual(out.graph, { enabled: true }); // siblings survive
|
||||
});
|
||||
|
||||
it("corrupt settings.json → null (first-boot semantics), never throws", () => {
|
||||
fs.mkdirSync(path.dirname(SETTINGS_FILE), { recursive: true });
|
||||
fs.writeFileSync(SETTINGS_FILE, "{not json", "utf-8");
|
||||
assert.equal(readSettings(), null);
|
||||
});
|
||||
|
||||
it("LEGACY MIGRATION: default-settings.json folds into the record's chat section on first read", () => {
|
||||
fs.rmSync(SETTINGS_FILE, { force: true });
|
||||
fs.mkdirSync(path.dirname(DEFAULT_SETTINGS_FILE), { recursive: true });
|
||||
fs.writeFileSync(DEFAULT_SETTINGS_FILE, JSON.stringify(CHAT_FIXTURE), "utf-8");
|
||||
const migrated = readSettings();
|
||||
assert.ok(migrated, "the legacy file became a record");
|
||||
assert.equal(migrated.version, 1);
|
||||
assert.deepEqual(migrated.chat, CHAT_FIXTURE);
|
||||
// The record is now persisted — the legacy file is left inert on disk.
|
||||
assert.ok(fs.existsSync(SETTINGS_FILE));
|
||||
assert.deepEqual(readSettings()?.chat, CHAT_FIXTURE);
|
||||
// And the default-settings facade reads the SAME section.
|
||||
assert.deepEqual(readDefaultSettings(), CHAT_FIXTURE);
|
||||
});
|
||||
|
||||
it("LEGACY MIGRATION is one-shot: an unreadable/corrupt legacy file never blocks first boot", () => {
|
||||
fs.rmSync(SETTINGS_FILE, { force: true });
|
||||
fs.mkdirSync(path.dirname(DEFAULT_SETTINGS_FILE), { recursive: true });
|
||||
fs.writeFileSync(DEFAULT_SETTINGS_FILE, "junk", "utf-8");
|
||||
assert.equal(readSettings(), null);
|
||||
});
|
||||
});
|
||||
|
||||
describe("the record-backed default-settings facade", () => {
|
||||
it("writeDefaultSettings lands in the record's chat section WITHOUT touching other sections", () => {
|
||||
writeSettings({ version: 1, graph: { enabled: false }, agent: { tools: { research: false } } });
|
||||
writeDefaultSettings(CHAT_FIXTURE);
|
||||
const out = readSettings();
|
||||
assert.ok(out);
|
||||
assert.deepEqual(out.chat, CHAT_FIXTURE);
|
||||
assert.deepEqual(out.graph, { enabled: false }); // untouched
|
||||
assert.deepEqual(out.agent?.tools, { research: false }); // untouched
|
||||
});
|
||||
|
||||
it("writeDefaultSettings creates the record on first boot", () => {
|
||||
fs.rmSync(SETTINGS_FILE, { force: true });
|
||||
fs.rmSync(DEFAULT_SETTINGS_FILE, { force: true });
|
||||
assert.equal(readSettings(), null);
|
||||
writeDefaultSettings(CHAT_FIXTURE);
|
||||
assert.deepEqual(readDefaultSettings(), CHAT_FIXTURE);
|
||||
});
|
||||
|
||||
it("readDefaultSettings returns null when the record has no chat section", () => {
|
||||
writeSettings({ version: 1, graph: { enabled: true } });
|
||||
assert.equal(readDefaultSettings(), null);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user