Files
archived-orca/tests/e2e/source-control/source-control-ai-generators.ts
T
Neil a16afc4e67 refactor(e2e): group journeys by feature and repair browser recovery (#43628)
* refactor(e2e): group journeys and fixtures by feature ownership

* refactor(e2e): consolidate remaining Playwright owner imports

* test(ci): stop copying retired route modules into fixtures

* fix(browser): preserve one-shot follow intent across equal snapshots

* refactor(settings): colocate commit message defaults with source control

* test(browser): await page registration and focus the concrete page

* fix(browser): keep viewport recovery progressing during incompatible frames

* fix(browser): wait for stale helper exit before replacement commands
2026-11-17 11:44:44 -08:00

94 lines
3.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import type { Page } from '@stablyai/playwright-test'
import { writeFileSync } from 'node:fs'
async function setCustomGenerator(page: Page, scriptPath: string): Promise<void> {
await page.evaluate(async (scriptPath) => {
const store =
window.__store ??
(() => {
throw new Error('window.__store is not available')
})()
const currentSettings = store.getState().settings
if (!currentSettings) {
throw new Error('Settings were not loaded')
}
await store.getState().updateSettings({
activeRuntimeEnvironmentId: null,
sourceControlAi: {
enabled: true,
agentId: 'custom' as const,
selectedModelByAgent: {},
selectedThinkingByModel: {},
instructionsByOperation: {},
actions: {},
customAgentCommand: `node ${JSON.stringify(scriptPath)}`
}
})
}, scriptPath)
}
// Echo the prompt’s linked issue to test renderer → IPC → metadata → template → agent stdin.
// emitPayload runs with the captured issue and must write the caller’s expected reply.
export function writeLinkedIssueEchoGenerator(scriptPath: string, emitPayload: string[]): void {
writeFileSync(
scriptPath,
[
'const chunks = []',
"process.stdin.on('data', (chunk) => chunks.push(chunk))",
"process.stdin.on('end', () => {",
" const prompt = Buffer.concat(chunks).toString('utf8')",
// Capture the whole line: a zero-digit match would hide an unexpanded {linkedIssue} token as empty.
' const match = prompt.match(/ORCA_E2E_ISSUE=([^\\r\\n]*)/)',
" const issue = match ? match[1] || 'empty' : 'missing'",
...emitPayload,
'})'
].join('\n')
)
}
export async function installDelayedPrGenerator(
page: Page,
generatorScriptPath: string,
callLogPath: string,
base: string
): Promise<void> {
writeFileSync(
generatorScriptPath,
[
"const fs = require('fs')",
`fs.appendFileSync(${JSON.stringify(callLogPath)}, 'start\\n')`,
'setTimeout(() => {',
' console.log(JSON.stringify({',
` base: ${JSON.stringify(base)},`,
" title: 'Generated PR title after switch',",
" body: 'Generated PR body after switch',",
' draft: false',
' }))',
` fs.appendFileSync(${JSON.stringify(callLogPath)}, 'finish\\n')`,
'}, 1500)'
].join('\n')
)
await setCustomGenerator(page, generatorScriptPath)
}
export async function installDelayedCommitMessageGenerator(
page: Page,
generatorScriptPath: string,
callLogPath: string
): Promise<void> {
writeFileSync(
generatorScriptPath,
[
"const fs = require('fs')",
`fs.appendFileSync(${JSON.stringify(callLogPath)}, 'start\\n')`,
'setTimeout(() => {',
" console.log('Generated commit message after switch')",
" console.log('')",
" console.log('Generated from staged e2e-commit-message-generation.txt after switching worktrees')",
` fs.appendFileSync(${JSON.stringify(callLogPath)}, 'finish\\n')`,
'}, 1500)'
].join('\n')
)
await setCustomGenerator(page, generatorScriptPath)
}