fix: resolve 3 protocol bugs, improve CLI and snapshot code quality (#487)
## Summary - Fix `allowFileAccess` being silently stripped from launch commands by adding it to the Zod schema in `protocol.ts` (the `--allow-file-access` CLI flag was not reaching the browser) - Fix `trace stop` requiring a path argument despite help text documenting it as optional -- now works with or without a path - Fix `addscript`/`addstyle` silently succeeding when neither `content` nor `url` is provided -- now returns a validation error - Replace hardcoded ANSI escape code with `color::error_indicator()` in `main.rs` to respect `NO_COLOR` - Fix double-parse pattern and add descriptive expect messages in `commands.rs` - Fix incomplete string escaping in `snapshot.ts` `buildSelector` (use `JSON.stringify` instead of manual quote escaping) - Simplify redundant ternary in `snapshot.ts` cursor-interactive role assignment - Sync docs changelog with CHANGELOG.md (v0.8.1 through v0.10.0)
This commit is contained in:
@@ -582,6 +582,22 @@ describe('parseCommand', () => {
|
||||
const result = parseCommand(cmd({ id: '1', action: 'launch', ignoreHTTPSErrors: 'true' }));
|
||||
expect(result.success).toBe(false);
|
||||
});
|
||||
|
||||
it('should parse launch with allowFileAccess true', () => {
|
||||
const result = parseCommand(cmd({ id: '1', action: 'launch', allowFileAccess: true }));
|
||||
expect(result.success).toBe(true);
|
||||
if (result.success) {
|
||||
expect(result.command.allowFileAccess).toBe(true);
|
||||
}
|
||||
});
|
||||
|
||||
it('should parse launch with allowFileAccess false', () => {
|
||||
const result = parseCommand(cmd({ id: '1', action: 'launch', allowFileAccess: false }));
|
||||
expect(result.success).toBe(true);
|
||||
if (result.success) {
|
||||
expect(result.command.allowFileAccess).toBe(false);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('mouse actions', () => {
|
||||
@@ -1108,6 +1124,46 @@ describe('parseCommand', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('addscript and addstyle', () => {
|
||||
it('should parse addscript with content', () => {
|
||||
const result = parseCommand(
|
||||
cmd({ id: '1', action: 'addscript', content: 'console.log("hi")' })
|
||||
);
|
||||
expect(result.success).toBe(true);
|
||||
});
|
||||
|
||||
it('should parse addscript with url', () => {
|
||||
const result = parseCommand(
|
||||
cmd({ id: '1', action: 'addscript', url: 'https://example.com/script.js' })
|
||||
);
|
||||
expect(result.success).toBe(true);
|
||||
});
|
||||
|
||||
it('should reject addscript with neither content nor url', () => {
|
||||
const result = parseCommand(cmd({ id: '1', action: 'addscript' }));
|
||||
expect(result.success).toBe(false);
|
||||
});
|
||||
|
||||
it('should parse addstyle with content', () => {
|
||||
const result = parseCommand(
|
||||
cmd({ id: '1', action: 'addstyle', content: 'body { color: red }' })
|
||||
);
|
||||
expect(result.success).toBe(true);
|
||||
});
|
||||
|
||||
it('should parse addstyle with url', () => {
|
||||
const result = parseCommand(
|
||||
cmd({ id: '1', action: 'addstyle', url: 'https://example.com/style.css' })
|
||||
);
|
||||
expect(result.success).toBe(true);
|
||||
});
|
||||
|
||||
it('should reject addstyle with neither content nor url', () => {
|
||||
const result = parseCommand(cmd({ id: '1', action: 'addstyle' }));
|
||||
expect(result.success).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('invalid commands', () => {
|
||||
it('should reject unknown action', () => {
|
||||
const result = parseCommand(cmd({ id: '1', action: 'unknown' }));
|
||||
|
||||
Reference in New Issue
Block a user