Create spec for better process management
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
## ADDED Requirements
|
||||
|
||||
### Requirement: Custom shell command execution
|
||||
The system SHALL support executing user-defined shell commands with full control over arguments and environment.
|
||||
|
||||
#### Scenario: Execute custom command with shell
|
||||
- **GIVEN** useCustomCommand setting is true
|
||||
- **AND** customCommand setting contains a shell command string
|
||||
- **WHEN** the server is started
|
||||
- **THEN** the system SHALL spawn the process with shell: true option
|
||||
- **AND** execute the exact command string as provided by the user
|
||||
|
||||
#### Scenario: Custom command with environment variables
|
||||
- **GIVEN** customCommand is "FOO=bar opencode serve --port 14096"
|
||||
- **WHEN** the server is started
|
||||
- **THEN** the system SHALL execute the command with shell: true
|
||||
- **AND** the environment variable FOO SHALL be set to "bar"
|
||||
|
||||
#### Scenario: Custom command with custom arguments
|
||||
- **GIVEN** customCommand is "opencode serve --port 9999 --verbose"
|
||||
- **WHEN** the server is started
|
||||
- **THEN** the system SHALL execute the command with shell: true
|
||||
- **AND** pass exactly "--port 9999 --verbose" as arguments
|
||||
- **AND** NOT append any default arguments (port, hostname, etc.)
|
||||
|
||||
#### Scenario: Custom command with wrapper script
|
||||
- **GIVEN** customCommand is "/path/to/my-wrapper.sh"
|
||||
- **WHEN** the server is started
|
||||
- **THEN** the system SHALL execute the wrapper script via shell
|
||||
- **AND** the wrapper script SHALL have full control of opencode invocation
|
||||
|
||||
### Requirement: No validation for custom commands
|
||||
The system SHALL NOT validate custom commands before execution.
|
||||
|
||||
#### Scenario: Invalid custom command fails naturally
|
||||
- **GIVEN** customCommand is "invalid-command-that-does-not-exist"
|
||||
- **WHEN** the server is started
|
||||
- **THEN** the system SHALL attempt to execute it
|
||||
- **AND** let the spawn fail naturally with ENOENT error
|
||||
- **AND** NOT perform pre-flight validation
|
||||
|
||||
### Requirement: User controls all arguments in custom mode
|
||||
The system SHALL NOT append any default arguments when using custom command mode.
|
||||
|
||||
#### Scenario: User provides complete command
|
||||
- **GIVEN** useCustomCommand is true
|
||||
- **AND** customCommand is "opencode serve"
|
||||
- **WHEN** the server is started
|
||||
- **THEN** the system SHALL execute exactly "opencode serve"
|
||||
- **AND** NOT append --port, --hostname, or --cors arguments
|
||||
@@ -0,0 +1,75 @@
|
||||
## ADDED Requirements
|
||||
|
||||
### Requirement: Cross-platform executable autodetection
|
||||
The system SHALL provide a mechanism to automatically detect the opencode executable location across macOS, Linux, and Windows platforms.
|
||||
|
||||
#### Scenario: Autodetect finds executable in PATH
|
||||
- **GIVEN** the platform PATH contains an executable named "opencode"
|
||||
- **WHEN** autodetection is triggered
|
||||
- **THEN** the system SHALL return the full path to the executable
|
||||
|
||||
#### Scenario: Configured absolute path takes precedence
|
||||
- **GIVEN** opencodePath is set to an absolute path like "/opt/opencode/bin/opencode"
|
||||
- **AND** the file exists at that location
|
||||
- **WHEN** autodetection is triggered
|
||||
- **THEN** the system SHALL return the configured absolute path directly
|
||||
- **AND** skip searching platform-specific locations
|
||||
|
||||
#### Scenario: Autodetect finds executable in platform-specific location
|
||||
- **GIVEN** opencodePath is set to "opencode" (not an absolute path)
|
||||
- **OR** the configured absolute path does not exist
|
||||
- **AND** opencode is installed at a platform-specific common location
|
||||
- Linux: ~/.local/bin/opencode, ~/.opencode/bin/opencode, ~/.bun/bin/opencode, ~/.npm-global/bin/opencode, ~/.nvm/versions/node/*/bin/opencode, /usr/local/bin/opencode, /usr/bin/opencode
|
||||
- macOS: ~/.local/bin/opencode, /opt/homebrew/bin/opencode, /usr/local/bin/opencode
|
||||
- Windows: %LOCALAPPDATA%\opencode\bin\opencode.exe, %USERPROFILE%\.bun\bin\opencode.exe
|
||||
- **WHEN** autodetection is triggered
|
||||
- **THEN** the system SHALL extract the basename from configured path (e.g., "opencode")
|
||||
- **AND** search platform-specific locations for that basename
|
||||
- **AND** return the full path if found
|
||||
|
||||
#### Scenario: Basename extraction for custom executable names
|
||||
- **GIVEN** opencodePath is set to "my-custom-opencode"
|
||||
- **WHEN** autodetection is triggered
|
||||
- **THEN** the system SHALL search for "my-custom-opencode" in platform-specific locations
|
||||
- **AND** return the full path if found
|
||||
|
||||
#### Scenario: Autodetect fails to find executable - fallback to configured path
|
||||
- **GIVEN** opencode is not in PATH or any platform-specific location
|
||||
- **AND** opencodePath is set to "opencode"
|
||||
- **WHEN** autodetection is triggered
|
||||
- **THEN** the system SHALL return the configured path "opencode" as fallback
|
||||
- **AND** display a toast notification to the user: "Could not find opencode. Please check Settings"
|
||||
|
||||
### Requirement: Startup autodetection
|
||||
The system SHALL attempt to autodetect the opencode executable on every plugin startup when the path is not configured.
|
||||
|
||||
#### Scenario: Startup autodetect succeeds
|
||||
- **GIVEN** the plugin loads
|
||||
- **AND** opencodePath setting is empty
|
||||
- **WHEN** the plugin initializes
|
||||
- **THEN** the system SHALL trigger autodetection
|
||||
- **AND** if found, save the path to opencodePath setting
|
||||
- **AND** display a success notification: "OpenCode executable found at <path>"
|
||||
|
||||
#### Scenario: Startup autodetect fails
|
||||
- **GIVEN** the plugin loads
|
||||
- **AND** opencodePath setting is empty
|
||||
- **WHEN** the plugin initializes
|
||||
- **THEN** the system SHALL trigger autodetection
|
||||
- **AND** if not found, display a toast notification: "Could not find opencode. Please check Settings"
|
||||
|
||||
### Requirement: Manual autodetect trigger
|
||||
The system SHALL provide a UI control to manually trigger autodetection at any time.
|
||||
|
||||
#### Scenario: User clicks Autodetect button
|
||||
- **GIVEN** the user is on the Settings page
|
||||
- **AND** Path mode is selected
|
||||
- **WHEN** the user clicks the "Autodetect" button
|
||||
- **THEN** the system SHALL trigger autodetection
|
||||
- **AND** if found, update the opencodePath field with the detected path
|
||||
- **AND** display a success notification
|
||||
|
||||
#### Scenario: Manual autodetect fails
|
||||
- **GIVEN** the user clicks the "Autodetect" button
|
||||
- **WHEN** autodetection fails to find the executable
|
||||
- **THEN** the system SHALL display a toast notification: "Could not find opencode. Please check your installation."
|
||||
@@ -0,0 +1,69 @@
|
||||
## MODIFIED Requirements
|
||||
|
||||
### Requirement: Server Process Spawning (Modified)
|
||||
The plugin SHALL spawn the OpenCode server process using either a configured executable path with default arguments OR a user-defined custom shell command.
|
||||
|
||||
**FROM:**
|
||||
The plugin SHALL spawn the OpenCode server process using the configured executable path, port, and hostname when the user initiates server start.
|
||||
|
||||
**TO:**
|
||||
The plugin SHALL support two execution modes for spawning the OpenCode server process based on the `useCustomCommand` setting.
|
||||
|
||||
#### Scenario: Path mode spawn (Modified)
|
||||
- **GIVEN** useCustomCommand is false
|
||||
- **WHEN** the user starts the server
|
||||
- **THEN** the plugin spawns the executable at `opencodePath` with arguments `["serve", "--port", <port>, "--hostname", <hostname>, "--cors", "app://obsidian.md"]`
|
||||
- **AND** the process runs with the vault directory as the working directory
|
||||
- **AND** the spawn uses `shell: false`
|
||||
|
||||
#### Scenario: Custom command mode spawn (New)
|
||||
- **GIVEN** useCustomCommand is true
|
||||
- **WHEN** the user starts the server
|
||||
- **THEN** the plugin spawns `customCommand` as a shell command
|
||||
- **AND** the spawn uses `shell: true`
|
||||
- **AND** NO additional arguments are appended to the command
|
||||
- **AND** the process runs with the vault directory as the working directory
|
||||
|
||||
## ADDED Requirements
|
||||
|
||||
### Requirement: Command mode selection
|
||||
The system SHALL support toggling between path mode and custom command mode via settings.
|
||||
|
||||
#### Scenario: Path mode configuration
|
||||
- **GIVEN** useCustomCommand is false (default)
|
||||
- **WHEN** the server starts
|
||||
- **THEN** the system uses the configured opencodePath executable
|
||||
- **AND** appends default arguments for port, hostname, and CORS
|
||||
|
||||
#### Scenario: Custom command mode configuration
|
||||
- **GIVEN** useCustomCommand is true
|
||||
- **WHEN** the server starts
|
||||
- **THEN** the system uses the configured customCommand string
|
||||
- **AND** executes it via shell with no argument manipulation
|
||||
|
||||
### Requirement: Executable verification
|
||||
The system SHALL verify the executable exists in path mode before attempting to spawn.
|
||||
|
||||
#### Scenario: Verify path mode executable
|
||||
- **GIVEN** useCustomCommand is false
|
||||
- **AND** opencodePath is set to an absolute path
|
||||
- **WHEN** the server is about to start
|
||||
- **THEN** the system SHALL verify the file exists and is executable
|
||||
- **AND** if verification fails, return an error before spawning
|
||||
|
||||
#### Scenario: Skip verification for custom command
|
||||
- **GIVEN** useCustomCommand is true
|
||||
- **WHEN** the server is about to start
|
||||
- **THEN** the system SHALL NOT verify the command before spawning
|
||||
- **AND** let execution fail naturally if the command is invalid
|
||||
|
||||
### Requirement: Settings backward compatibility
|
||||
The system SHALL maintain backward compatibility with existing opencodePath configurations.
|
||||
|
||||
#### Scenario: Existing path setting works
|
||||
- **GIVEN** a configuration from a previous plugin version
|
||||
- **AND** opencodePath is set to "/usr/local/bin/opencode"
|
||||
- **AND** useCustomCommand is not set (defaults to false)
|
||||
- **WHEN** the plugin loads
|
||||
- **THEN** the system SHALL use the existing opencodePath
|
||||
- **AND** continue working in path mode with default arguments
|
||||
Reference in New Issue
Block a user