Skip to content

Commit 21f853d

Browse files
committed
test(ai): add integration tests for AIChatHistory backup and restore
47 tests covering session metadata storage, chat history file round-trips, deletion, visual state restoration of all message bubble types (user, assistant, tool, tool_edit, error, question, edit_summary), and end-to-end save-load-render flows. Test data is stored as JSON fixtures in ai-history-test-files/.
1 parent c830834 commit 21f853d

File tree

9 files changed

+871
-0
lines changed

9 files changed

+871
-0
lines changed

src/brackets.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ define(function (require, exports, module) {
298298
SidebarView: require("project/SidebarView"),
299299
WorkingSetView: require("project/WorkingSetView"),
300300
AISnapshotStore: require("core-ai/AISnapshotStore"),
301+
AIChatHistory: require("core-ai/AIChatHistory"),
301302
doneLoading: false
302303
};
303304

test/UnitTestSuite.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ define(function (require, exports, module) {
6363
require("spec/LanguageManager-test");
6464
require("spec/LanguageManager-integ-test");
6565
require("spec/ai-snapshot-test");
66+
require("spec/ai-history-test");
6667
require("spec/LowLevelFileIO-test");
6768
require("spec/Metrics-test");
6869
require("spec/MultiRangeInlineEditor-test");
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"id": "multi-tool-sess",
3+
"title": "Refactor the utils module",
4+
"timestamp": 1700000000000,
5+
"messages": [
6+
{ "type": "user", "text": "Refactor the utils module" },
7+
{ "type": "assistant", "markdown": "I'll analyze the code first.", "isFirst": true },
8+
{ "type": "tool", "toolName": "Glob", "summary": "Finding utils files", "icon": "fa-solid fa-magnifying-glass", "color": "#6b9eff", "elapsed": 0.2 },
9+
{ "type": "tool", "toolName": "Read", "summary": "Reading utils/index.js", "icon": "fa-solid fa-file-lines", "color": "#6bc76b", "elapsed": 0.4 },
10+
{ "type": "tool", "toolName": "Read", "summary": "Reading utils/helpers.js", "icon": "fa-solid fa-file-lines", "color": "#6bc76b", "elapsed": 0.3 },
11+
{ "type": "assistant", "markdown": "I see several opportunities for improvement." },
12+
{ "type": "tool", "toolName": "Edit", "summary": "Editing utils/index.js", "icon": "fa-solid fa-pen", "color": "#e8a838", "elapsed": 1.1 },
13+
{ "type": "tool_edit", "file": "/src/utils/index.js", "linesAdded": 15, "linesRemoved": 8 },
14+
{ "type": "tool", "toolName": "Edit", "summary": "Editing utils/helpers.js", "icon": "fa-solid fa-pen", "color": "#e8a838", "elapsed": 0.9 },
15+
{ "type": "tool_edit", "file": "/src/utils/helpers.js", "linesAdded": 7, "linesRemoved": 12 },
16+
{ "type": "assistant", "markdown": "Refactoring complete! I've:\n- Extracted shared logic\n- Removed duplicate code\n- Added proper types" },
17+
{
18+
"type": "edit_summary",
19+
"files": [
20+
{ "file": "/src/utils/index.js", "added": 15, "removed": 8 },
21+
{ "file": "/src/utils/helpers.js", "added": 7, "removed": 12 }
22+
]
23+
},
24+
{ "type": "complete" }
25+
]
26+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"id": "err-sess",
3+
"title": "Run the tests",
4+
"timestamp": 1700000000000,
5+
"messages": [
6+
{ "type": "user", "text": "Run the tests" },
7+
{ "type": "assistant", "markdown": "I'll run the test suite.", "isFirst": true },
8+
{ "type": "tool", "toolName": "Bash", "summary": "Running npm test", "icon": "fa-solid fa-terminal", "color": "#c084fc", "elapsed": 5.2 },
9+
{ "type": "error", "text": "Process exited with code 1: Tests failed" },
10+
{ "type": "assistant", "markdown": "The tests failed. Let me investigate." },
11+
{ "type": "tool", "toolName": "Read", "summary": "Reading test output", "icon": "fa-solid fa-file-lines", "color": "#6bc76b", "elapsed": 0.3 },
12+
{ "type": "complete" }
13+
]
14+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"id": "img-sess",
3+
"title": "Check this screenshot",
4+
"timestamp": 1700000000000,
5+
"messages": [
6+
{
7+
"type": "user",
8+
"text": "Check this screenshot",
9+
"images": [
10+
{ "dataUrl": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUg==", "mediaType": "image/png" },
11+
{ "dataUrl": "data:image/jpeg;base64,/9j/4AAQSkZJRg==", "mediaType": "image/jpeg" }
12+
]
13+
},
14+
{ "type": "assistant", "markdown": "I can see two images in your screenshot.", "isFirst": true },
15+
{ "type": "complete" }
16+
]
17+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"id": "other-ans-sess",
3+
"title": "Configure the build",
4+
"timestamp": 1700000000000,
5+
"messages": [
6+
{ "type": "user", "text": "Configure the build" },
7+
{
8+
"type": "question",
9+
"questions": [
10+
{
11+
"question": "Which bundler?",
12+
"options": [
13+
{ "label": "Webpack", "description": "Established bundler" },
14+
{ "label": "Vite", "description": "Fast dev server" }
15+
]
16+
}
17+
],
18+
"answers": {
19+
"Which bundler?": "Rollup with custom plugins"
20+
}
21+
},
22+
{ "type": "complete" }
23+
]
24+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"id": "q-sess",
3+
"title": "Set up authentication",
4+
"timestamp": 1700000000000,
5+
"messages": [
6+
{ "type": "user", "text": "Set up authentication" },
7+
{ "type": "assistant", "markdown": "I have a few questions before I start.", "isFirst": true },
8+
{
9+
"type": "question",
10+
"questions": [
11+
{
12+
"question": "Which auth method do you prefer?",
13+
"options": [
14+
{ "label": "JWT", "description": "Stateless token-based auth" },
15+
{ "label": "Session", "description": "Server-side session storage" },
16+
{ "label": "OAuth", "description": "Third-party provider auth" }
17+
]
18+
},
19+
{
20+
"question": "Which database?",
21+
"options": [
22+
{ "label": "PostgreSQL", "description": "Relational database" },
23+
{ "label": "MongoDB", "description": "Document database" }
24+
]
25+
}
26+
],
27+
"answers": {
28+
"Which auth method do you prefer?": "JWT",
29+
"Which database?": "PostgreSQL"
30+
}
31+
},
32+
{ "type": "assistant", "markdown": "Great, I'll set up JWT auth with PostgreSQL." },
33+
{ "type": "tool", "toolName": "Write", "summary": "Writing auth/jwt.js", "icon": "fa-solid fa-file-pen", "color": "#e8a838", "elapsed": 0.8 },
34+
{ "type": "tool_edit", "file": "/src/auth/jwt.js", "linesAdded": 45, "linesRemoved": 0 },
35+
{ "type": "complete" }
36+
]
37+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"id": "simple-sess",
3+
"title": "What is 2+2?",
4+
"timestamp": 1700000000000,
5+
"messages": [
6+
{ "type": "user", "text": "What is 2+2?" },
7+
{ "type": "assistant", "markdown": "The answer is **4**.", "isFirst": true },
8+
{ "type": "complete" }
9+
]
10+
}

0 commit comments

Comments
 (0)