Repository navigation
feat(staged): make hidden child note chats read-only #1050
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
Draft
matt2e
wants to merge
1
commit into
main
Choose a base branch
from
disably-sending-messages-in-hidden-child-chats
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
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
176 changes: 176 additions & 0 deletions
176
apps/staged/src/lib/features/sessions/SessionChatPane.childNote.component.test.ts
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 |
|---|---|---|
| @@ -0,0 +1,176 @@ | ||
| import { flushSync, mount, tick, unmount } from 'svelte'; | ||
| import { beforeEach, describe, expect, it, vi } from 'vitest'; | ||
| import type { BranchNote, Session } from '../../types'; | ||
|
|
||
| const { branchNote } = vi.hoisted(() => ({ | ||
| /** What `getBranchNoteBySession` answers for the mounted session. */ | ||
| branchNote: { current: null as BranchNote | null, fail: false }, | ||
| })); | ||
|
|
||
| // Heavy leaf components are stubbed out: these tests exercise whether the | ||
| // pane offers a composer at all, not the composer's internals. | ||
| vi.mock('./ChatComposer.svelte', async () => { | ||
| const { default: PromptInputStub } = await import('./testStubs/PromptInputStub.svelte'); | ||
| return { default: PromptInputStub, composerControlClass: '' }; | ||
| }); | ||
| vi.mock('../agents/AcpFixedConfigPicker.svelte', () => import('./testStubs/EmptyStub.svelte')); | ||
| vi.mock('./PlanCard.svelte', () => import('./testStubs/EmptyStub.svelte')); | ||
| vi.mock('./PipelineSteps.svelte', () => import('./testStubs/EmptyStub.svelte')); | ||
| vi.mock('./tool-calls/ToolCallCard.svelte', () => import('./testStubs/EmptyStub.svelte')); | ||
| vi.mock('./tool-calls/ToolCallHeader.svelte', () => import('./testStubs/EmptyStub.svelte')); | ||
| vi.mock('./NoteActivityCard.svelte', () => import('./testStubs/EmptyStub.svelte')); | ||
| vi.mock( | ||
| '../../shared/markdown/DiagramViewerModal.svelte', | ||
| () => import('./testStubs/EmptyStub.svelte') | ||
| ); | ||
| vi.mock('../branches/dragDrop', () => ({ subscribeDragDrop: () => () => {} })); | ||
| vi.mock('../agents/agent.svelte', () => ({ agentState: { providers: [] } })); | ||
| vi.mock('../settings/preferences.svelte', () => ({ setAcpConfigPref: vi.fn() })); | ||
| vi.mock('../../transport', async (importOriginal) => ({ | ||
| ...(await importOriginal<typeof import('../../transport')>()), | ||
| listenToEvent: () => () => {}, | ||
| })); | ||
| vi.mock('../../shared/draftCache', () => ({ | ||
| createDraftWriteScheduler: () => ({ | ||
| scheduleSave: vi.fn(), | ||
| saveNow: vi.fn(async () => {}), | ||
| clearNow: vi.fn(async () => {}), | ||
| flush: vi.fn(async () => {}), | ||
| }), | ||
| loadDraft: async () => null, | ||
| })); | ||
| vi.mock('../../commands', async (importOriginal) => ({ | ||
| ...(await importOriginal<typeof import('../../commands')>()), | ||
| getSession: async (id: string) => | ||
| ({ | ||
| id, | ||
| status: 'completed', | ||
| completionReason: 'interrupted', | ||
| provider: null, | ||
| workingDir: null, | ||
| }) as unknown as Session, | ||
| getLatestSessionMessages: async () => ({ data: [] }), | ||
| getSessionMessages: async () => ({ data: [] }), | ||
| getSessionMessagesSince: async () => [], | ||
| getSessionAcpMetadataMessages: async () => [], | ||
| getSessionAcpMetadataMessagesSince: async () => [], | ||
| listQueuedSessionMessages: async () => [], | ||
| getBranchNoteBySession: async () => { | ||
| if (branchNote.fail) throw new Error('lookup failed'); | ||
| return branchNote.current; | ||
| }, | ||
| })); | ||
|
|
||
| import SessionChatPane from './SessionChatPane.svelte'; | ||
| import { reactiveProps } from './testStubs/reactiveProps.svelte'; | ||
|
|
||
| function note(sessionId: string, parentProjectNoteId: string | null): BranchNote { | ||
| return { | ||
| id: `note-${sessionId}`, | ||
| branchId: 'branch-1', | ||
| sessionId, | ||
| title: 'Note', | ||
| content: 'body', | ||
| createdAt: 1, | ||
| updatedAt: 1, | ||
| completedAt: 1, | ||
| suggestedNextCommitStep: null, | ||
| suggestedNextNoteStep: null, | ||
| parentProjectNoteId, | ||
| subtype: null, | ||
| readAt: null, | ||
| }; | ||
| } | ||
|
|
||
| function mountPane(sessionId: string) { | ||
| const props = reactiveProps({ active: true, sessionId, hashtagItems: [] }); | ||
| const target = document.createElement('div'); | ||
| document.body.appendChild(target); | ||
| const pane = mount(SessionChatPane, { target, props }); | ||
| return { pane, props }; | ||
| } | ||
|
|
||
| /** Let the pane's async session and note loads and effect flushes settle. */ | ||
| async function settle() { | ||
| for (let i = 0; i < 8; i++) { | ||
| await tick(); | ||
| } | ||
| flushSync(); | ||
| } | ||
|
|
||
| const composer = () => document.querySelector('[data-testid="prompt-input"]'); | ||
| const readOnlyNotice = () => document.querySelector('[data-testid="read-only-chat-notice"]'); | ||
| const resumeButton = () => | ||
| Array.from(document.querySelectorAll('button')).find((b) => b.textContent?.trim() === 'Resume'); | ||
|
|
||
| describe('SessionChatPane for a hidden child note', () => { | ||
| beforeEach(() => { | ||
| document.body.innerHTML = ''; | ||
| branchNote.current = null; | ||
| branchNote.fail = false; | ||
| vi.spyOn(console, 'error').mockImplementation(() => {}); | ||
| }); | ||
|
|
||
| it('replaces the composer and Resume with a read-only notice', async () => { | ||
| branchNote.current = note('child', 'project-note-1'); | ||
| const { pane } = mountPane('child'); | ||
| flushSync(); | ||
| await settle(); | ||
|
|
||
| expect(composer()).toBeNull(); | ||
| expect(resumeButton()).toBeUndefined(); | ||
| expect(readOnlyNotice()?.textContent).toContain('read-only'); | ||
| expect(readOnlyNotice()?.textContent).toContain('project note'); | ||
|
|
||
| unmount(pane); | ||
| }); | ||
|
|
||
| it("keeps the composer for a note that is shown in the branch's notes", async () => { | ||
| branchNote.current = note('standalone', null); | ||
| const { pane } = mountPane('standalone'); | ||
| flushSync(); | ||
| await settle(); | ||
|
|
||
| expect(composer()).not.toBeNull(); | ||
| expect(resumeButton()).toBeDefined(); | ||
| expect(readOnlyNotice()).toBeNull(); | ||
|
|
||
| unmount(pane); | ||
| }); | ||
|
|
||
| it('keeps the composer when the note lookup fails or finds no note', async () => { | ||
| branchNote.fail = true; | ||
| const { pane, props } = mountPane('no-note'); | ||
| flushSync(); | ||
| await settle(); | ||
| expect(composer()).not.toBeNull(); | ||
| expect(readOnlyNotice()).toBeNull(); | ||
|
|
||
| // A commit session has no note; the chat is writable. | ||
| branchNote.fail = false; | ||
| props.sessionId = 'commit'; | ||
| flushSync(); | ||
| await settle(); | ||
| expect(composer()).not.toBeNull(); | ||
| expect(readOnlyNotice()).toBeNull(); | ||
|
|
||
| unmount(pane); | ||
| }); | ||
|
|
||
| it('drops the notice when the pane moves on to a writable session', async () => { | ||
| branchNote.current = note('child', 'project-note-1'); | ||
| const { pane, props } = mountPane('child'); | ||
| flushSync(); | ||
| await settle(); | ||
| expect(readOnlyNotice()).not.toBeNull(); | ||
|
|
||
| branchNote.current = note('standalone', null); | ||
| props.sessionId = 'standalone'; | ||
| flushSync(); | ||
| await settle(); | ||
| expect(readOnlyNotice()).toBeNull(); | ||
| expect(composer()).not.toBeNull(); | ||
|
|
||
| unmount(pane); | ||
| }); | ||
| }); |
Oops, something went wrong.
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.
Gate
send_queued_session_message_for_storeand the automatic queue drain as well as this direct-resume wrapper. Existing installations can already contain follow-ups queued for a running child-note session; when that turn finishes,drain_queued_message_for_sessioncalls the ungatedresume_session_for_storedirectly, so the queued prompt starts a new turn despite the chat now being read-only. The publicsend_queued_session_messagecommand has the same bypass for manually selected queued messages.Useful? React with 👍 / 👎.