-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinstalled-search-count.e2e.ts
More file actions
237 lines (215 loc) · 6.87 KB
/
Copy pathinstalled-search-count.e2e.ts
File metadata and controls
237 lines (215 loc) · 6.87 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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
import {
mkdirSync,
mkdtempSync,
realpathSync,
rmSync,
writeFileSync,
} from 'node:fs'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import type { Page } from '@playwright/test'
import type { Settings } from '@/shared/settings'
import { test, expect } from '../fixtures/electron-app'
import { readSettingsFile, writeSettingsFile } from '../helpers/settings-file'
const SEARCH_COUNT_SKILLS = [
{ name: 'alpha-count-e2e', source: 'laststance/skills' },
{ name: 'beta-count-e2e', source: 'laststance/skills' },
{ name: 'gamma-count-e2e', source: 'pbakaus/impeccable' },
]
type SearchCountDisplaySetting = Settings['installedSearchCountDisplay']
type IsolatedHomeUse = (home: string) => Promise<void>
/**
* Write one source skill folder that the real scanner will count after app launch.
* @param home - Isolated E2E HOME used by the Electron fixture.
* @param skillName - Folder name and SKILL.md title for the staged skill.
* @returns void after the source skill exists on disk.
* @example
* stageSourceSkill('/tmp/home', 'alpha-count-e2e')
*/
function stageSourceSkill(home: string, skillName: string): void {
const sourcePath = join(home, '.agents', 'skills', skillName)
mkdirSync(sourcePath, { recursive: true })
writeFileSync(
join(sourcePath, 'SKILL.md'),
`---\nname: ${skillName}\ndescription: ${skillName} description\n---\n# ${skillName}\n`,
'utf8',
)
}
/**
* Write the skills CLI lockfile so the real scanner exposes deterministic repo facets.
* @param home - Isolated E2E HOME used by the Electron fixture.
* @returns void after `.skill-lock.json` maps each staged skill to its repo.
* @example
* stageSkillLock('/tmp/home')
*/
function stageSkillLock(home: string): void {
const lockPath = join(home, '.agents', '.skill-lock.json')
const skills = Object.fromEntries(
SEARCH_COUNT_SKILLS.map((skill) => [
skill.name,
{
source: skill.source,
sourceType: 'github',
sourceUrl: `https://github.com/${skill.source}.git`,
},
]),
)
writeFileSync(lockPath, JSON.stringify({ skills }, null, 2), 'utf8')
}
/**
* Stage the complete Installed-count HOME before Electron starts scanning.
* @param home - Isolated E2E HOME used by the Electron fixture.
* @returns void after source skills and repo metadata are on disk.
* @example
* stageInstalledCountHome('/tmp/home')
*/
function stageInstalledCountHome(home: string): void {
mkdirSync(join(home, '.agents', 'skills'), { recursive: true })
for (const skill of SEARCH_COUNT_SKILLS) {
stageSourceSkill(home, skill.name)
}
stageSkillLock(home)
}
/**
* Provide an isolated HOME with only the three Installed-count skills staged.
* @param use - Playwright fixture continuation that launches Electron after setup.
* @param display - Optional persisted count placement to write before launch.
* @returns Promise that resolves after the fixture HOME is cleaned up.
* @example
* await useInstalledCountHome(use, 'inline')
*/
async function useInstalledCountHome(
use: IsolatedHomeUse,
display?: SearchCountDisplaySetting,
): Promise<void> {
const home = realpathSync.native(
mkdtempSync(join(tmpdir(), 'skills-desktop-e2e-search-count-')),
)
try {
stageInstalledCountHome(home)
if (display) {
writeSettingsFile(home, { installedSearchCountDisplay: display })
}
await use(home)
} finally {
rmSync(home, { recursive: true, force: true })
}
}
/**
* Dispatch Installed search and repo filters in one renderer transaction.
* @param page - Electron renderer page under test.
* @param filters - Search query and selected repository ids to apply.
* @returns Promise that resolves once Redux has the requested filter state.
* @example
* await applyInstalledFilters(appWindow, { query: 'missing', sources: [] })
*/
async function applyInstalledFilters(
page: Page,
filters: { query: string; sources: string[] },
): Promise<void> {
await page.evaluate(({ query, sources }) => {
const store = window.__store__
if (!store) throw new Error('window.__store__ is not exposed')
store.dispatch({
type: 'ui/setSearchQuery',
payload: query,
})
store.dispatch({
type: 'ui/setSelectedSources',
payload: sources,
})
}, filters)
}
const installedCountTest = test.extend<{ isolatedHome: string }>({
// eslint-disable-next-line no-empty-pattern
isolatedHome: async ({}, use) => {
await useInstalledCountHome(use)
},
})
const inlineInstalledCountTest = test.extend<{ isolatedHome: string }>({
// eslint-disable-next-line no-empty-pattern
isolatedHome: async ({}, use) => {
await useInstalledCountHome(use, 'inline')
},
})
installedCountTest(
'Installed tab badge tracks the current visible count and Marketplace stays count-free',
async ({ appWindow }) => {
// Arrange / Assert
await expect(
appWindow.getByRole('tab', {
name: /^Installed, 3 skills visible$/,
}),
).toBeVisible()
await expect(
appWindow.getByRole('tab', { name: /^Marketplace$/ }),
).toBeVisible()
// Act
await applyInstalledFilters(appWindow, {
query: 'alpha-count',
sources: [],
})
// Assert
await expect(
appWindow.getByRole('tab', {
name: /^Installed, 1 skill visible$/,
}),
).toBeVisible()
// Act
await applyInstalledFilters(appWindow, {
query: '',
sources: ['pbakaus/impeccable'],
})
// Assert
await expect(
appWindow.getByRole('tab', {
name: /^Installed, 1 skill visible$/,
}),
).toBeVisible()
// Act
await applyInstalledFilters(appWindow, {
query: 'missing-count-e2e',
sources: [],
})
// Assert
await expect(
appWindow.getByRole('tab', {
name: /^Installed, 0 skills visible$/,
}),
).toBeVisible()
await expect(
appWindow.getByRole('tab', { name: /^Marketplace$/ }),
).toBeVisible()
},
)
inlineInstalledCountTest(
'persisted inline mode moves the count into the toolbar and removes the tab badge',
async ({ appWindow, isolatedHome }) => {
// Arrange / Assert
await appWindow.waitForFunction(() => {
const store = window.__store__
if (!store) return false
const state = store.getState() as {
settings?: { installedSearchCountDisplay?: string }
}
return state.settings?.installedSearchCountDisplay === 'inline'
})
await expect(
appWindow.getByRole('tab', { name: /^Installed$/ }),
).toBeVisible()
await expect(
appWindow.getByRole('tab', {
name: /^Installed, 3 skills visible$/,
}),
).toHaveCount(0)
await expect(
appWindow
.locator('[aria-live="polite"]')
.filter({ hasText: /^3 skills$/ }),
).toBeVisible()
const persisted = readSettingsFile(isolatedHome) as {
installedSearchCountDisplay?: string
} | null
expect(persisted?.installedSearchCountDisplay).toBe('inline')
},
)