Skip to content

Url handler system#6

Merged
bigr merged 2 commits intomainfrom
klinger-url-handler-system
Oct 22, 2025
Merged

Url handler system#6
bigr merged 2 commits intomainfrom
klinger-url-handler-system

Conversation

@bigr
Copy link
Owner

@bigr bigr commented Oct 22, 2025

No description provided.

bigr added 2 commits October 22, 2025 22:22
Add complete URL handler system with commands for generating handler
scripts, installing system handlers, and generating userscripts for
external link interception in PWAs.

## New Commands

- `generate-handler`: Generate URL scheme handler script with browser
  integration, URL decoding, and security validation
- `install-handler`: Register handler with XDG MIME system, create
  desktop file, and update registry
- `generate-userscript`: Generate userscript for intercepting external
  links with configurable in-scope hosts

## Implementation Details

- Handler scripts decode custom URL schemes (e.g., ff://) and launch
  specified browser with decoded URLs
- Security validation ensures only http/https URLs are accepted
- XDG integration for proper system-level handler registration
- Comprehensive installation instructions for userscript setup
- Full support for multiple browsers (firefox, chrome, chromium, edge)
- Registry integration for tracking installed handlers

## Testing

- 19 new unit tests with 85-100% coverage
- Tests cover handler generation, installation, and userscript creation
- Tests verify dry-run mode, error handling, and edge cases
- All pre-commit hooks passing (ruff, mypy, formatting)

## Documentation

- Updated Implementation-specification.md Phase 4 checklist
- All Phase 4 items marked as complete
- Inline help text and examples in CLI commands

Verification:
- `pytest -m \"not playwright\" -q` - 118 tests passed
- `pre-commit run --all-files` - all checks passed
- Test coverage: 82% overall, 100% for userscript.py, 85% for handler.py
Add comprehensive integration tests for handler generation, installation,
and userscript creation workflows.

## Test Coverage

### Handler Generation (2 tests)
- Full handler script generation with executable permissions
- Multiple schemes support (ff, external, custom)

### Handler Installation (2 tests)
- Complete installation workflow with XDG registration
- Multiple handler installation and registry tracking

### Userscript Generation (1 test)
- Userscript creation with in-scope hosts configuration

### Complete Workflow (2 tests)
- End-to-end workflow: generate → install → userscript
- Default paths and auto-detection testing

## Key Test Scenarios

- Handler script creation with proper bash syntax and security
- Desktop file generation with MIME type registration
- Registry integration for handler tracking
- Userscript generation with correct scheme usage
- XDG integration (mocked subprocess calls)
- Default path resolution and auto-detection
- Multiple handler support

## Testing Results

```
✅ 7 new integration tests added
✅ 125 total tests passing (118 unit + 7 integration)
✅ 83% overall code coverage (increased from 82%)
✅ 87% coverage on handler.py (increased from 85%)
✅ 100% coverage on userscript.py (maintained)
✅ All pre-commit hooks passing
```

## Configuration

- Excluded integration tests from pre-commit mypy checks
  (they use test-specific patterns incompatible with strict mode)
- Integration tests still validated via pyproject.toml mypy overrides

The integration tests verify the complete handler workflow as specified
in Phase 4 requirements (Handler generation and registration).
@bigr bigr merged commit bec9018 into main Oct 22, 2025
5 checks passed
bigr added a commit that referenced this pull request Oct 23, 2025
- Add platform-specific locking: fcntl (Unix) and msvcrt (Windows)
- Make add_app() atomic with single-lock read-check-write operation
- Prevent race condition where two simultaneous adds could corrupt registry
- Add type annotations to satisfy mypy strict type checking
- Resolves user testing issues #6 and #7 (registry concurrency and platform locking)
bigr added a commit that referenced this pull request Oct 24, 2025
- Refactor _find_browser_executable() in handler.py to use same robust strategy as add.py
- Add platform-specific path checking and shutil.which() fallback
- Support Snap, Flatpak, and custom browser installations
- Add comprehensive offline installation instructions across all docs
- Update README.md, USAGE.md, TROUBLESHOOTING.md with PYTHONPATH method
- Fix test expectations to match new error messages
- Add test for browser detection via PATH fallback
- Resolves second-round testing issue #9 (handler generation failures)
- Resolves second-round testing issue #6 (offline installation unclear)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant