豆豆友情提示:这是一个非官方 GitHub 代理镜像,主要用于网络测试或访问加速。请勿在此进行登录、注册或处理任何敏感信息。进行这些操作请务必访问官方网站 github.com。 Raw 内容也通过此代理提供。
Skip to content

Commit 632f65a

Browse files
committed
chore: added download of canary to ci
1 parent cfaec9c commit 632f65a

File tree

5 files changed

+75
-17
lines changed

5 files changed

+75
-17
lines changed

.github/workflows/run-tests.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ jobs:
4141
shell: bash
4242
run: npm ci
4343

44+
- name: Install Chrome Canary
45+
shell: bash
46+
run: |
47+
CANARY_PATH=$(npx @puppeteer/browsers install chrome@canary --format "{{path}}")
48+
echo "CANARY_EXECUTABLE_PATH=$CANARY_PATH" >> $GITHUB_ENV
49+
4450
- name: Build
4551
run: npm run bundle
4652
env:

src/McpContext.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,7 @@ export class McpContext implements Context {
940940
}
941941

942942
async triggerExtensionAction(id: string): Promise<void> {
943-
const page = this.getSelectedPage();
943+
const page = this.getSelectedPptrPage();
944944
// @ts-expect-error internal puppeteer api is needed since we don't have a way to get
945945
// a tab id at the moment
946946
const theTarget = page._tabId;

tests/tools/extensions.test.ts

Lines changed: 53 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {afterEach, describe, it} from 'node:test';
1010

1111
import sinon from 'sinon';
1212

13+
import type { ParsedArguments } from '../../src/cli.js';
1314
import type {McpResponse} from '../../src/McpResponse.js';
1415
import {
1516
installExtension,
@@ -18,8 +19,13 @@ import {
1819
reloadExtension,
1920
triggerExtensionAction,
2021
} from '../../src/tools/extensions.js';
22+
import { listPages } from '../../src/tools/pages.js';
2123
import {withMcpContext} from '../utils.js';
2224

25+
const EXTENSION_WITH_SW_PATH = path.join(
26+
import.meta.dirname,
27+
'../../../tests/tools/fixtures/extension-sw',
28+
);
2329
const EXTENSION_PATH = path.join(
2430
import.meta.dirname,
2531
'../../../tests/tools/fixtures/extension',
@@ -129,39 +135,74 @@ describe('extension', () => {
129135
assert.ok(reinstalled, 'Extension should be present after reload');
130136
});
131137
});
132-
133138
it('triggers an extension action', async () => {
134139
await withMcpContext(
135140
async (response, context) => {
136-
const triggerSpy = sinon.spy(context, 'triggerExtensionAction');
137-
138141
await installExtension.handler(
139-
{params: {path: EXTENSION_PATH}},
142+
{params: {path: EXTENSION_WITH_SW_PATH}},
140143
response,
141144
context,
142145
);
143146

144147
const extensionId = extractId(response);
148+
145149
response.resetResponseLineForTesting();
150+
const listPageDef = listPages({
151+
categoryExtensions: true,
152+
} as ParsedArguments);
153+
await listPageDef.handler(
154+
{params: {}, page: context.getSelectedMcpPage()},
155+
response,
156+
context,
157+
);
158+
let result = await response.handle(listPageDef.name, context);
159+
let textContent = result.content.find(c => c.type === 'text') as {
160+
type: 'text';
161+
text: string;
162+
};
163+
assert.ok(
164+
!textContent.text.includes(extensionId),
165+
'Response should not contain extension service worker id',
166+
);
146167

147168
await triggerExtensionAction.handler(
148169
{params: {id: extensionId}},
149170
response,
150171
context,
151172
);
173+
174+
const swTarget = await context.browser.waitForTarget(
175+
t =>
176+
t.type() === 'service_worker' &&
177+
t.url().includes(extensionId),
178+
);
179+
const swUrl = swTarget.url();
152180

153-
assert.ok(
154-
triggerSpy.calledOnceWithExactly(extensionId),
155-
'triggerExtensionAction should be called with correct params',
181+
response.resetResponseLineForTesting();
182+
await listPageDef.handler(
183+
{params: {}, page: context.getSelectedMcpPage()},
184+
response,
185+
context,
156186
);
187+
result = await response.handle(listPageDef.name, context);
188+
textContent = result.content.find(c => c.type === 'text') as {
189+
type: 'text';
190+
text: string;
191+
};
157192
assert.ok(
158-
response.responseLines[0].includes(
159-
`Extension action triggered. Id: ${extensionId}`,
160-
),
161-
'Response should indicate action triggered',
193+
textContent.text.includes(swUrl),
194+
'Response should contain extension service worker url',
162195
);
163196
},
164-
{channel: 'chrome-canary'},
197+
{
198+
channel: process.env.CANARY_EXECUTABLE_PATH
199+
? undefined
200+
: 'chrome-canary',
201+
executablePath: process.env.CANARY_EXECUTABLE_PATH,
202+
},
203+
{
204+
categoryExtensions: true,
205+
} as ParsedArguments
165206
);
166207
});
167208
});
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
console.log('Service worker loaded');
1+
chrome.action.onClicked.addListener((tab) => {
2+
console.log('Action clicked');
3+
});

tests/utils.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,19 @@ let context: McpContext | undefined;
4848

4949
export async function withBrowser(
5050
cb: (browser: Browser, page: Page) => Promise<void>,
51-
options: {debug?: boolean; autoOpenDevTools?: boolean; channel?: string} = {},
51+
options: {
52+
debug?: boolean;
53+
autoOpenDevTools?: boolean;
54+
channel?: string;
55+
executablePath?: string;
56+
} = {},
5257
) {
5358
const launchOptions: LaunchOptions = {
54-
executablePath: process.env.PUPPETEER_EXECUTABLE_PATH,
55-
channel: options.channel as ChromeReleaseChannel,
59+
executablePath:
60+
options.executablePath ?? process.env.PUPPETEER_EXECUTABLE_PATH,
61+
channel: (options.executablePath
62+
? undefined
63+
: options.channel) as ChromeReleaseChannel,
5664
headless: !options.debug,
5765
defaultViewport: null,
5866
devtools: options.autoOpenDevTools ?? false,
@@ -88,6 +96,7 @@ export async function withMcpContext(
8896
autoOpenDevTools?: boolean;
8997
performanceCrux?: boolean;
9098
channel?: string;
99+
executablePath?: string;
91100
} = {},
92101
args: ParsedArguments = {} as ParsedArguments,
93102
) {

0 commit comments

Comments
 (0)