This commit is contained in:
Chris Tate
2026-01-11 23:55:29 -06:00
parent 343aa1f723
commit d84a769949
6 changed files with 56 additions and 39 deletions
+7 -1
View File
@@ -449,7 +449,13 @@ async function handleScreenshot(
}
async function handleSnapshot(
command: Command & { action: 'snapshot'; interactive?: boolean; maxDepth?: number; compact?: boolean; selector?: string },
command: Command & {
action: 'snapshot';
interactive?: boolean;
maxDepth?: number;
compact?: boolean;
selector?: string;
},
browser: BrowserManager
): Promise<Response<SnapshotData>> {
// Use enhanced snapshot with refs and optional filtering
+3 -1
View File
@@ -123,7 +123,9 @@ describe('BrowserManager', () => {
it('should set cookie with domain', async () => {
const page = browser.getPage();
const context = page.context();
await context.addCookies([{ name: 'domainCookie', value: 'domainValue', domain: 'example.com', path: '/' }]);
await context.addCookies([
{ name: 'domainCookie', value: 'domainValue', domain: 'example.com', path: '/' },
]);
const cookies = await context.cookies();
const testCookie = cookies.find((c) => c.name === 'domainCookie');
expect(testCookie?.value).toBe('domainValue');
+4 -2
View File
@@ -33,7 +33,7 @@ export function getSession(): string {
function getPortForSession(session: string): number {
let hash = 0;
for (let i = 0; i < session.length; i++) {
hash = ((hash << 5) - hash) + session.charCodeAt(i);
hash = (hash << 5) - hash + session.charCodeAt(i);
hash |= 0;
}
// Port range 49152-65535 (dynamic/private ports)
@@ -90,7 +90,9 @@ export function isDaemonRunning(session?: string): boolean {
* Get connection info for the current session
* Returns { type: 'unix', path: string } or { type: 'tcp', port: number }
*/
export function getConnectionInfo(session?: string): { type: 'unix'; path: string } | { type: 'tcp'; port: number } {
export function getConnectionInfo(
session?: string
): { type: 'unix'; path: string } | { type: 'tcp'; port: number } {
const sess = session ?? currentSession;
if (isWindows) {
return { type: 'tcp', port: getPortForSession(sess) };
+16 -6
View File
@@ -252,7 +252,9 @@ describe('parseCommand', () => {
});
it('should parse storage_get with specific key', () => {
const result = parseCommand(cmd({ id: '1', action: 'storage_get', type: 'local', key: 'mykey' }));
const result = parseCommand(
cmd({ id: '1', action: 'storage_get', type: 'local', key: 'mykey' })
);
expect(result.success).toBe(true);
if (result.success) {
expect(result.command.key).toBe('mykey');
@@ -426,14 +428,16 @@ describe('parseCommand', () => {
});
it('should parse snapshot with all options', () => {
const result = parseCommand(cmd({
const result = parseCommand(
cmd({
id: '1',
action: 'snapshot',
interactive: true,
compact: true,
maxDepth: 5,
selector: '.content',
}));
})
);
expect(result.success).toBe(true);
if (result.success) {
expect(result.command.interactive).toBe(true);
@@ -487,7 +491,9 @@ describe('parseCommand', () => {
describe('scroll', () => {
it('should parse scroll command', () => {
const result = parseCommand(cmd({ id: '1', action: 'scroll', direction: 'down', amount: 300 }));
const result = parseCommand(
cmd({ id: '1', action: 'scroll', direction: 'down', amount: 300 })
);
expect(result.success).toBe(true);
});
@@ -521,7 +527,9 @@ describe('parseCommand', () => {
});
it('should parse geolocation', () => {
const result = parseCommand(cmd({ id: '1', action: 'geolocation', latitude: 37.7749, longitude: -122.4194 }));
const result = parseCommand(
cmd({ id: '1', action: 'geolocation', latitude: 37.7749, longitude: -122.4194 })
);
expect(result.success).toBe(true);
});
@@ -572,7 +580,9 @@ describe('parseCommand', () => {
});
it('should parse dialog accept with prompt text', () => {
const result = parseCommand(cmd({ id: '1', action: 'dialog', response: 'accept', promptText: 'hello' }));
const result = parseCommand(
cmd({ id: '1', action: 'dialog', response: 'accept', promptText: 'hello' })
);
expect(result.success).toBe(true);
if (result.success) {
expect(result.command.promptText).toBe('hello');
+6 -9
View File
@@ -223,11 +223,7 @@ function getIndentLevel(line: string): number {
/**
* Process a single line: add ref if needed, filter if requested
*/
function processLine(
line: string,
refs: RefMap,
options: SnapshotOptions
): string | null {
function processLine(line: string, refs: RefMap, options: SnapshotOptions): string | null {
const depth = getIndentLevel(line);
// Check max depth
@@ -359,16 +355,17 @@ export function parseRef(arg: string): string | null {
/**
* Get snapshot statistics
*/
export function getSnapshotStats(tree: string, refs: RefMap): {
export function getSnapshotStats(
tree: string,
refs: RefMap
): {
lines: number;
chars: number;
tokens: number;
refs: number;
interactive: number;
} {
const interactive = Object.values(refs).filter(r =>
INTERACTIVE_ROLES.has(r.role)
).length;
const interactive = Object.values(refs).filter((r) => INTERACTIVE_ROLES.has(r.role)).length;
return {
lines: tree.split('\n').length,