Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 25 additions & 18 deletions playwright/global.setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,32 @@ const fs = require('fs');
const path = require('path');

setup('OAuth', async ({browser}) => {
const agentId = 'AGENT1'; // Configure which agent to set up
const page = await browser.newPage();
await oauthLogin(page, agentId);
const agents = ['AGENT1', 'AGENT2']; // Array of agents to set up

await page.getByRole('textbox').click();
const accessToken = await page.getByRole('textbox').inputValue();
for (const agentId of agents) {
const page = await browser.newPage();
await oauthLogin(page, agentId);

const envPath = path.resolve(__dirname, '../.env');
let envContent = '';
if (fs.existsSync(envPath)) {
envContent = fs.readFileSync(envPath, 'utf8');
// Remove any existing ACCESS_TOKEN line for this agent
const accessTokenPattern = new RegExp(`^PW_${agentId}_ACCESS_TOKEN=.*$`, 'm');
envContent = envContent.replace(accessTokenPattern, '');
// Also remove legacy ACCESS_TOKEN for backward compatibility
envContent = envContent.replace(/^ACCESS_TOKEN=.*$/m, '');
// Ensure trailing newline
if (!envContent.endsWith('\n')) envContent += '\n';
await page.getByRole('textbox').click();
const accessToken = await page.getByRole('textbox').inputValue();

const envPath = path.resolve(__dirname, '../.env');
let envContent = '';
if (fs.existsSync(envPath)) {
envContent = fs.readFileSync(envPath, 'utf8');
// Remove any existing ACCESS_TOKEN line for this agent
const accessTokenPattern = new RegExp(`^PW_${agentId}_ACCESS_TOKEN=.*$`, 'm');
envContent = envContent.replace(accessTokenPattern, '');
// Also remove legacy ACCESS_TOKEN for backward compatibility
if (agentId === 'AGENT1') {
envContent = envContent.replace(/^ACCESS_TOKEN=.*$/m, '');
}
Comment on lines +24 to +26

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need this backward compatible code here?

// Ensure trailing newline
if (!envContent.endsWith('\n')) envContent += '\n';
}
envContent += `PW_${agentId}_ACCESS_TOKEN=${accessToken}\n`;
fs.writeFileSync(envPath, envContent, 'utf8');

await page.close();
}
envContent += `PW_${agentId}_ACCESS_TOKEN=${accessToken}\n`;
fs.writeFileSync(envPath, envContent, 'utf8');
});
Loading