-
Notifications
You must be signed in to change notification settings - Fork 853
Expand file tree
/
Copy pathFileContextState.test.ts
More file actions
198 lines (163 loc) · 6.62 KB
/
Copy pathFileContextState.test.ts
File metadata and controls
198 lines (163 loc) · 6.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
import { FileContextState } from '@/features/chat/ui/file-context/state/FileContextState';
describe('FileContextState', () => {
let state: FileContextState;
beforeEach(() => {
state = new FileContextState();
});
describe('initial state', () => {
it('should start with no attached files', () => {
expect(state.getAttachedFiles().size).toBe(0);
});
it('should start with session not started', () => {
expect(state.isSessionStarted()).toBe(false);
});
it('should start with current note not sent', () => {
expect(state.hasSentCurrentNote()).toBe(false);
});
it('should start with no MCP mentions', () => {
expect(state.getMentionedMcpServers().size).toBe(0);
});
});
describe('session lifecycle', () => {
it('should mark session as started', () => {
state.startSession();
expect(state.isSessionStarted()).toBe(true);
});
it('should mark current note as sent', () => {
state.markCurrentNoteSent();
expect(state.hasSentCurrentNote()).toBe(true);
});
});
describe('resetForNewConversation', () => {
it('should reset all state', () => {
state.startSession();
state.markCurrentNoteSent();
state.attachFile('file1.md');
state.addMentionedMcpServer('server1');
state.resetForNewConversation();
expect(state.isSessionStarted()).toBe(false);
expect(state.hasSentCurrentNote()).toBe(false);
expect(state.getAttachedFiles().size).toBe(0);
expect(state.getMentionedMcpServers().size).toBe(0);
});
});
describe('resetForLoadedConversation', () => {
it('should set state based on whether conversation has messages', () => {
state.attachFile('file1.md');
state.addMentionedMcpServer('server1');
state.resetForLoadedConversation(true);
expect(state.isSessionStarted()).toBe(true);
expect(state.hasSentCurrentNote()).toBe(true);
expect(state.getAttachedFiles().size).toBe(0);
expect(state.getMentionedMcpServers().size).toBe(0);
});
it('should not mark as started when no messages', () => {
state.resetForLoadedConversation(false);
expect(state.isSessionStarted()).toBe(false);
expect(state.hasSentCurrentNote()).toBe(false);
});
});
describe('file attachments', () => {
it('should attach a file', () => {
state.attachFile('test.md');
expect(state.getAttachedFiles().has('test.md')).toBe(true);
});
it('should return a copy of attached files (not the internal set)', () => {
state.attachFile('test.md');
const files = state.getAttachedFiles();
files.add('other.md');
expect(state.getAttachedFiles().has('other.md')).toBe(false);
});
it('should detach a file', () => {
state.attachFile('test.md');
state.detachFile('test.md');
expect(state.getAttachedFiles().has('test.md')).toBe(false);
});
it('should set attached files replacing existing', () => {
state.attachFile('old.md');
state.setAttachedFiles(['new1.md', 'new2.md']);
const files = state.getAttachedFiles();
expect(files.has('old.md')).toBe(false);
expect(files.has('new1.md')).toBe(true);
expect(files.has('new2.md')).toBe(true);
});
it('should clear all attachments', () => {
state.attachFile('a.md');
state.clearAttachments();
expect(state.getAttachedFiles().size).toBe(0);
});
});
describe('MCP server mentions', () => {
it('should add a mentioned MCP server', () => {
state.addMentionedMcpServer('server1');
expect(state.getMentionedMcpServers().has('server1')).toBe(true);
});
it('should return a copy of mentioned servers', () => {
state.addMentionedMcpServer('server1');
const servers = state.getMentionedMcpServers();
servers.add('server2');
expect(state.getMentionedMcpServers().has('server2')).toBe(false);
});
it('should clear MCP mentions', () => {
state.addMentionedMcpServer('server1');
state.clearMcpMentions();
expect(state.getMentionedMcpServers().size).toBe(0);
});
it('should set mentioned MCP servers and return true when changed', () => {
const changed = state.setMentionedMcpServers(new Set(['a', 'b']));
expect(changed).toBe(true);
expect(state.getMentionedMcpServers()).toEqual(new Set(['a', 'b']));
});
it('should return false when setting same servers', () => {
state.setMentionedMcpServers(new Set(['a', 'b']));
const changed = state.setMentionedMcpServers(new Set(['a', 'b']));
expect(changed).toBe(false);
});
it('should return true when sizes differ', () => {
state.setMentionedMcpServers(new Set(['a']));
const changed = state.setMentionedMcpServers(new Set(['a', 'b']));
expect(changed).toBe(true);
});
it('should return true when same size but different contents', () => {
state.setMentionedMcpServers(new Set(['a', 'b']));
const changed = state.setMentionedMcpServers(new Set(['a', 'c']));
expect(changed).toBe(true);
});
});
describe('line-range mentions', () => {
it('starts with empty line range map', () => {
expect(state.getLineRangeMentions().size).toBe(0);
});
it('stores a line range mention', () => {
state.attachLineRangeMention('CLAUDE.md', 9, 15);
const map = state.getLineRangeMentions();
expect(map.get('CLAUDE.md')).toEqual({ startLine: 9, endLine: 15 });
});
it('overwrites an existing entry for the same file', () => {
state.attachLineRangeMention('CLAUDE.md', 1, 5);
state.attachLineRangeMention('CLAUDE.md', 9, 15);
expect(state.getLineRangeMentions().get('CLAUDE.md')).toEqual({ startLine: 9, endLine: 15 });
});
it('removes a line range mention', () => {
state.attachLineRangeMention('CLAUDE.md', 9, 15);
state.removeLineRangeMention('CLAUDE.md');
expect(state.getLineRangeMentions().size).toBe(0);
});
it('clears line range mentions on resetForNewConversation', () => {
state.attachLineRangeMention('CLAUDE.md', 9, 15);
state.resetForNewConversation();
expect(state.getLineRangeMentions().size).toBe(0);
});
it('clears line range mentions on resetForLoadedConversation', () => {
state.attachLineRangeMention('CLAUDE.md', 9, 15);
state.resetForLoadedConversation(true);
expect(state.getLineRangeMentions().size).toBe(0);
});
it('returns a copy so external mutations do not affect internal state', () => {
state.attachLineRangeMention('CLAUDE.md', 9, 15);
const map = state.getLineRangeMentions();
map.clear();
expect(state.getLineRangeMentions().size).toBe(1);
});
});
});