feat(frontend): bind sessions to chart profiles

This commit is contained in:
Jesse_Chen
2026-08-30 15:55:45 +08:00
parent 5c1d095f69
commit f5e6d51646
6 changed files with 120 additions and 5 deletions
+20
View File
@@ -26,6 +26,19 @@ test("create schema keeps the client-generated session id after transcript limit
assert.equal(parsed.messages[0]?.text, "你好");
});
test("chat session schema accepts chart profile snapshots and keeps legacy writes valid", () => {
const parsed = chatSessionWriteSchema.parse({
...values,
chart_profile_id: "other-profile-id",
chart_profile_name: "张三",
chart_profile_role: "other",
});
assert.equal(parsed.chart_profile_id, "other-profile-id");
assert.equal(parsed.chart_profile_name, "张三");
assert.equal(parsed.chart_profile_role, "other");
assert.equal(chatSessionWriteSchema.parse(values).chart_profile_id, undefined);
});
test("chat session schema preserves the safe agent execution receipt", () => {
const receipt = {
runId: "run-1",
@@ -136,6 +149,7 @@ test("session API owns create and update while answer UI keeps sync failures out
const collectionRoute = readFileSync(new URL("../src/app/api/sessions/route.ts", import.meta.url), "utf8");
const itemRoute = readFileSync(new URL("../src/app/api/sessions/[id]/route.ts", import.meta.url), "utf8");
const contract = readFileSync(new URL("../src/lib/chat-session-write-contract.ts", import.meta.url), "utf8");
const migration = readFileSync(new URL("../supabase/migrations/20260830010000_chat_session_chart_profile_binding.sql", import.meta.url), "utf8");
assert.match(page, /thinkingText: message\.thinkingText/);
assert.match(page, /thinkingSections: message\.thinkingSections/);
@@ -151,6 +165,12 @@ test("session API owns create and update while answer UI keeps sync failures out
assert.match(collectionRoute, /const \{ id, \.\.\.values \} = parsed\.data/);
assert.match(contract, /function limitTranscriptSize<Output extends \{ messages: Array<\{ text: string; thinkingText\?: string; thinkingSections\?: unknown \}> \}>/);
assert.match(contract, /\): z\.ZodType<Output> \{/);
assert.match(page, /chartSnapshotForSession/);
assert.match(page, /chart_profile_name: session\.chartProfileName/);
assert.match(page, /分析对象:/);
assert.match(migration, /add column if not exists chart_profile_id text/);
assert.match(migration, /grant insert \(chart_profile_id, chart_profile_name, chart_profile_role\)/);
assert.match(migration, /grant update \(chart_profile_id, chart_profile_name, chart_profile_role\)/);
});