-
Notifications
You must be signed in to change notification settings - Fork 1
fix: sync meta_json.title in updateSessionTitle so ZCode App shows it #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+67
−15
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -98,47 +98,52 @@ function makeStatement(sql: string) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // SELECT title_overridden FROM tasks WHERE task_id=? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // SELECT title_overridden, meta_json FROM tasks WHERE task_id=? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (/^SELECT title_overridden/i.test(sql)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| get(taskId: string) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for (const r of rows.values()) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (r.task_id === taskId) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return { title_overridden: r.title_overridden } as const; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| title_overridden: r.title_overridden, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| meta_json: r.meta_json, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } as const; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return undefined; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+101
to
116
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Update the mock statement to support the new
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // UPDATE tasks SET title=?, updated_at=?, searchable_text=? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // UPDATE tasks SET title=?, updated_at=?, searchable_text=?, meta_json=? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // WHERE task_id=? AND title_overridden=0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (/^UPDATE tasks SET title/i.test(sql)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| run(title: string, updatedAt: number, searchable: string, taskId: string) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| run(title: string, updatedAt: number, searchable: string, metaJson: string, taskId: string) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let changes = 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for (const r of rows.values()) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (r.task_id === taskId && r.title_overridden === 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| r.title = title; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| r.updated_at = updatedAt; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| r.searchable_text = searchable; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| r.meta_json = metaJson; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| changes++; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return { changes }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // UPDATE tasks SET updated_at=?, searchable_text=? WHERE task_id=? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // UPDATE tasks SET updated_at=?, searchable_text=?, meta_json=? WHERE task_id=? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // (title_overridden=1 branch: keep user title, still refresh searchable_text) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (/^UPDATE tasks SET updated_at=\?, searchable_text/i.test(sql)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| run(updatedAt: number, searchable: string, taskId: string) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| run(updatedAt: number, searchable: string, metaJson: string, taskId: string) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let changes = 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for (const r of rows.values()) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (r.task_id === taskId) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| r.updated_at = updatedAt; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| r.searchable_text = searchable; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| r.meta_json = metaJson; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| changes++; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -250,7 +255,7 @@ describe("tasks-index session sync", () => { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| describe("updateSessionTitle", () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| it("updates title + searchable_text when title_overridden=0", async () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| it("updates title + searchable_text + meta_json when title_overridden=0", async () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await upsertSessionTask({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| workspaceKey: "/ws", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| taskId: "sess_4", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -262,6 +267,8 @@ describe("tasks-index session sync", () => { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(r.title).toBe("new title"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(r.searchable_text).toBe("new title"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(r.title_overridden).toBe(0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // The App reads title from meta_json first — must be in sync. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(JSON.parse(r.meta_json).title).toBe("new title"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| it("uses the full prompt text as searchable_text when provided", async () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -303,7 +310,7 @@ describe("tasks-index session sync", () => { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(r.searchable_text.length).toBe(80); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| it("respects user title override but still refreshes searchable_text", async () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| it("respects user title override but still refreshes searchable_text + meta_json", async () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await upsertSessionTask({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| workspaceKey: "/ws", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| taskId: "sess_6", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -320,12 +327,38 @@ describe("tasks-index session sync", () => { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(r.title).toBe("user kept name"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // But searchable_text is still updated (not user-controlled). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(r.searchable_text).toBe("search body"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // meta_json.title is synced to the auto title for consistency (the App | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // reads meta_json first, but with title_overridden=1 the column wins). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(JSON.parse(r.meta_json).title).toBe("auto title"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| it("returns false when the session row does not exist", async () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const ok = await updateSessionTitle("never_created", "title"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(ok).toBe(false); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(rows.size).toBe(0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| it("regression: meta_json.title is updated so the App shows the new title", async () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // The ZCode App reads title from meta_json first, falling back to the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // title column only when meta_json is unparseable. At session/create the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // meta_json.title is "" (empty). Without patching meta_json on title | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // update, the App keeps showing the empty title even though the column | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // was updated. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await upsertSessionTask({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| workspaceKey: "/ws", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| taskId: "sess_meta", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| title: "", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const before = JSON.parse(rows.get("/ws\u0000sess_meta")!.meta_json); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(before.title).toBe(""); // empty at create time | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await updateSessionTitle("sess_meta", "fix the login bug"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const after = JSON.parse(rows.get("/ws\u0000sess_meta")!.meta_json); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // App reads this → must reflect the new title. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(after.title).toBe("fix the login bug"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Other meta fields must survive the patch. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(after.taskId).toBe("sess_meta"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(after.mode).toBe("build"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the user has already overridden the title (
row.title_overridden === 1), unconditionally settingmeta["title"] = trimmed(the auto-generated title) will overwrite the user's custom title inmeta_json. Since the App reads the title frommeta_jsonfirst, this will cause the App to display the auto-generated title instead of the user's overridden title, breaking the override behavior.To fix this, we should select the
titlecolumn as well, and iftitle_overridden === 1, preserve the existing user-defined title inmeta_json.