test(desktop): cover commit flow in cdp smoke

This commit is contained in:
DragonnZhang 2026-04-25 12:57:16 +08:00
parent 78dad5d0ab
commit cf400d518b
5 changed files with 209 additions and 31 deletions

View file

@ -63,11 +63,11 @@ async function main() {
await cdp.send('Log.enable');
await cdp.send('Page.bringToFront');
await waitForText('Qwen Code');
await waitForText('Connected');
await assertWorkbenchLandmarks();
await saveScreenshot('initial-workspace.png');
await clickButton('Open Project');
await waitForText('desktop-e2e-workspace');
await clickButtonUntilText('Open Project', 'desktop-e2e-workspace');
await waitForText('README.md');
await waitForText('Accept Hunk');
await clickButton('Accept Hunk');
@ -78,6 +78,13 @@ async function main() {
);
await clickButton('Add Comment');
await waitForText('Review note from E2E');
await clickButton('Accept All');
await waitForText('0 modified · 2 staged · 0 untracked');
await waitForText('ADDED · 1 HUNK');
await setFieldByAriaLabel('Commit message', 'desktop e2e commit');
await clickButton('Commit');
await waitForText('No changes');
await assertWorkspaceCommit('desktop e2e commit');
await waitForSelector('[data-testid="project-list"]');
await clickButton('New Thread');
@ -107,7 +114,7 @@ async function main() {
await setFieldByAriaLabel(
'Terminal command',
'node -e "process.stdin.once(\'data\', d => process.stdout.write(\'stdin:\' + d.toString(), () => process.exit(0)))"',
"node -e \"process.stdin.once('data', d => process.stdout.write('stdin:' + d.toString(), () => process.exit(0)))\"",
);
await clickButton('Run');
await waitForText('[running]');
@ -184,6 +191,31 @@ async function createGitWorkspace() {
return dir;
}
async function assertWorkspaceCommit(expectedMessage) {
const { stdout: latestSubject } = await execFileP('git', [
'-C',
workspaceDir,
'log',
'--format=%s',
'-1',
]);
if (latestSubject.trim() !== expectedMessage) {
throw new Error(
`Unexpected latest commit subject: ${latestSubject.trim()}`,
);
}
const { stdout: status } = await execFileP('git', [
'-C',
workspaceDir,
'status',
'--porcelain=v1',
]);
if (status.trim() !== '') {
throw new Error(`Workspace is not clean after commit:\n${status}`);
}
}
function launchDesktopApp({
cdpPort,
homeDir,
@ -306,6 +338,41 @@ async function clickButton(text) {
}
}
async function clickButtonUntilText(
buttonText,
expectedText,
timeoutMs = 15_000,
) {
const deadline = Date.now() + timeoutMs;
let lastError;
while (Date.now() < deadline) {
if (
await evaluate(
`document.body.innerText.includes(${JSON.stringify(expectedText)})`,
)
) {
return;
}
try {
await clickButton(buttonText);
} catch (error) {
lastError = error;
}
await delay(500);
}
throw new Error(
`Timed out waiting for text ${JSON.stringify(
expectedText,
)} after clicking ${JSON.stringify(buttonText)}${
lastError instanceof Error ? `: ${lastError.message}` : ''
}`,
);
}
async function setFieldByAriaLabel(label, value) {
const changed = await evaluate(`(() => {
const field = document.querySelector('[aria-label="${escapeSelector(