mirror of
https://github.com/tiennm99/ccs.git
synced 2026-09-04 16:16:46 +00:00
fix(kiro): parse Builder ID selector dynamically
This commit is contained in:
@@ -191,6 +191,21 @@ export function validateManualCallbackUrl(callbackUrl: string, authUrl: string):
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getKiroBuilderIdSelectionInput(output: string): string | null {
|
||||||
|
const promptMatch = /Select login method/i.exec(output);
|
||||||
|
if (!promptMatch || promptMatch.index === undefined) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const promptWindow = output.slice(promptMatch.index, promptMatch.index + 600);
|
||||||
|
const optionMatch = /(?:^|\n)\s*(\d+)\s*[\).:-]?\s*(?:AWS\s+)?Builder ID\b/im.exec(promptWindow);
|
||||||
|
if (!optionMatch) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return `${optionMatch[1]}\n`;
|
||||||
|
}
|
||||||
|
|
||||||
async function promptManualCallbackUrl(
|
async function promptManualCallbackUrl(
|
||||||
displayName: string,
|
displayName: string,
|
||||||
state: ProcessState,
|
state: ProcessState,
|
||||||
@@ -318,8 +333,16 @@ async function handleStdout(
|
|||||||
state.accumulatedOutput.includes('Select login method')
|
state.accumulatedOutput.includes('Select login method')
|
||||||
) {
|
) {
|
||||||
state.kiroMethodSelectionHandled = true;
|
state.kiroMethodSelectionHandled = true;
|
||||||
authProcess.stdin?.write('1\n');
|
const builderIdSelection = getKiroBuilderIdSelectionInput(state.accumulatedOutput);
|
||||||
log('Auto-selected Kiro Builder ID flow');
|
if (!builderIdSelection) {
|
||||||
|
console.log(fail('Unable to auto-select Kiro Builder ID from the upstream login menu.'));
|
||||||
|
console.log(' The upstream Kiro prompt format may have changed.');
|
||||||
|
killWithEscalation(authProcess);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
authProcess.stdin?.write(builderIdSelection);
|
||||||
|
log(`Auto-selected Kiro Builder ID flow (${builderIdSelection.trim()})`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse project list when available
|
// Parse project list when available
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { describe, expect, it } from 'bun:test';
|
|||||||
import {
|
import {
|
||||||
extractLikelyAuthFailureFromStderr,
|
extractLikelyAuthFailureFromStderr,
|
||||||
getExpectedLocalCallback,
|
getExpectedLocalCallback,
|
||||||
|
getKiroBuilderIdSelectionInput,
|
||||||
validateManualCallbackUrl,
|
validateManualCallbackUrl,
|
||||||
} from '../../../src/cliproxy/auth/oauth-process';
|
} from '../../../src/cliproxy/auth/oauth-process';
|
||||||
|
|
||||||
@@ -84,3 +85,35 @@ describe('oauth-process manual callback validation', () => {
|
|||||||
).toContain('state does not match');
|
).toContain('state does not match');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('oauth-process Kiro Builder ID menu parsing', () => {
|
||||||
|
it('selects Builder ID when it is the first option', () => {
|
||||||
|
const output = `
|
||||||
|
Select login method
|
||||||
|
1. Builder ID
|
||||||
|
2. IAM Identity Center
|
||||||
|
`;
|
||||||
|
|
||||||
|
expect(getKiroBuilderIdSelectionInput(output)).toBe('1\n');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('selects the Builder ID option even when upstream reorders the menu', () => {
|
||||||
|
const output = `
|
||||||
|
Select login method
|
||||||
|
1. IAM Identity Center
|
||||||
|
2. AWS Builder ID
|
||||||
|
`;
|
||||||
|
|
||||||
|
expect(getKiroBuilderIdSelectionInput(output)).toBe('2\n');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns null when the Builder ID option is not present in the prompt window', () => {
|
||||||
|
const output = `
|
||||||
|
Select login method
|
||||||
|
1. IAM Identity Center
|
||||||
|
2. Google
|
||||||
|
`;
|
||||||
|
|
||||||
|
expect(getKiroBuilderIdSelectionInput(output)).toBeNull();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user