-
Notifications
You must be signed in to change notification settings - Fork 0
feat: complete agent self-upgrade closure #97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
7a9487b
docs: add agent self-upgrade closure design spec
ZingerLittleBee 1a72eee
docs: revise agent self-upgrade spec per review feedback
ZingerLittleBee f8455e8
docs: clarify upgrade store setJobs semantics and fix stale Capabilit…
ZingerLittleBee 33321a4
docs: add agent self-upgrade closure implementation plan
ZingerLittleBee 44d5366
feat(common): add upgrade lifecycle protocol
ZingerLittleBee 6cfe08b
feat(server): add upgrade job tracker
ZingerLittleBee 425990a
feat(server): add upgrade release lookup
ZingerLittleBee 5a3856c
feat(agent): add upgrade execution pipeline
ZingerLittleBee fcdd2ca
feat(web): add upgrade jobs store and hooks
ZingerLittleBee 559b815
docs: add agent upgrade documentation and QA checklist
ZingerLittleBee 9eeff92
refactor(server): remove incomplete upgrade state wiring
ZingerLittleBee daa01f8
refactor(agent): simplify self-upgrade execution
ZingerLittleBee 5ebafe8
refactor(web): remove upgrade job hydration
ZingerLittleBee 3e7c1d5
refactor(common): remove upgrade lifecycle protocol
ZingerLittleBee b8ba14e
test(web): fix frontend test mocks
ZingerLittleBee a2f4fdb
fix(upgrade): restore end-to-end upgrade state flow
ZingerLittleBee 7080233
fix(ci): resolve frontend typecheck and clippy errors
ZingerLittleBee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
288 changes: 288 additions & 0 deletions
288
apps/web/src/components/server/agent-version-section.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,288 @@ | ||
| import { fireEvent, render, screen } from '@testing-library/react' | ||
| import { beforeEach, describe, expect, it, vi } from 'vitest' | ||
| import { AgentVersionSection } from './agent-version-section' | ||
|
|
||
| vi.mock('react-i18next', () => ({ | ||
| useTranslation: () => ({ | ||
| t: (key: string) => key | ||
| }) | ||
| })) | ||
|
|
||
| const mockTriggerUpgrade = vi.fn() | ||
| const mockUseUpgradeJob = vi.fn() | ||
| vi.mock('@/hooks/use-upgrade-job', () => ({ | ||
| useUpgradeJob: (serverId: string) => mockUseUpgradeJob(serverId) | ||
| })) | ||
|
|
||
| const mockUseAuth = vi.fn() | ||
| vi.mock('@/hooks/use-auth', () => ({ | ||
| useAuth: () => mockUseAuth() | ||
| })) | ||
|
|
||
| const mockGetEffectiveCapabilityEnabled = vi.fn() | ||
| vi.mock('@/lib/capabilities', () => ({ | ||
| CAP_UPGRADE: 4, | ||
| getEffectiveCapabilityEnabled: (...args: unknown[]) => mockGetEffectiveCapabilityEnabled(...args) | ||
| })) | ||
| const UPGRADE_LATEST_PATTERN = /upgrade_latest_version/ | ||
| const UPGRADE_ERROR_WITH_BACKUP_PATTERN = /upgrade_error_with_backup/ | ||
| const UPGRADE_BACKUP_PATH_PATTERN = /upgrade_backup_path/ | ||
|
|
||
| describe('AgentVersionSection', () => { | ||
| beforeEach(() => { | ||
| vi.clearAllMocks() | ||
| mockUseAuth.mockReturnValue({ user: { role: 'admin' } }) | ||
| mockUseUpgradeJob.mockReturnValue({ | ||
| job: null, | ||
| triggerUpgrade: mockTriggerUpgrade, | ||
| isLoading: false | ||
| }) | ||
| mockGetEffectiveCapabilityEnabled.mockReturnValue(true) | ||
| }) | ||
|
|
||
| it('renders current agent version', () => { | ||
| render( | ||
| <AgentVersionSection | ||
| agentVersion="1.2.3" | ||
| configuredCapabilities={255} | ||
| effectiveCapabilities={255} | ||
| latestVersion="1.2.3" | ||
| serverId="srv-1" | ||
| /> | ||
| ) | ||
| expect(screen.getByText('v1.2.3')).toBeDefined() | ||
| }) | ||
|
|
||
| it('shows unknown version when agentVersion is null', () => { | ||
| render( | ||
| <AgentVersionSection | ||
| agentVersion={null} | ||
| configuredCapabilities={255} | ||
| effectiveCapabilities={255} | ||
| latestVersion="1.2.3" | ||
| serverId="srv-1" | ||
| /> | ||
| ) | ||
| expect(screen.getByText('vunknown')).toBeDefined() | ||
| }) | ||
|
|
||
| it('shows update available badge when versions differ', () => { | ||
| render( | ||
| <AgentVersionSection | ||
| agentVersion="1.2.3" | ||
| configuredCapabilities={255} | ||
| effectiveCapabilities={255} | ||
| latestVersion="1.3.0" | ||
| serverId="srv-1" | ||
| /> | ||
| ) | ||
| expect(screen.getByText(UPGRADE_LATEST_PATTERN)).toBeDefined() | ||
| }) | ||
|
|
||
| it('shows upgrade button for admin when update available and capability enabled', () => { | ||
| render( | ||
| <AgentVersionSection | ||
| agentVersion="1.2.3" | ||
| configuredCapabilities={255} | ||
| effectiveCapabilities={255} | ||
| latestVersion="1.3.0" | ||
| serverId="srv-1" | ||
| /> | ||
| ) | ||
| expect(screen.getByText('upgrade_start')).toBeDefined() | ||
| }) | ||
|
|
||
| it('does not show upgrade button for non-admin users', () => { | ||
| mockUseAuth.mockReturnValue({ user: { role: 'member' } }) | ||
| render( | ||
| <AgentVersionSection | ||
| agentVersion="1.2.3" | ||
| configuredCapabilities={255} | ||
| effectiveCapabilities={255} | ||
| latestVersion="1.3.0" | ||
| serverId="srv-1" | ||
| /> | ||
| ) | ||
| expect(screen.queryByText('upgrade_start')).toBeNull() | ||
| }) | ||
|
|
||
| it('does not show upgrade button when capability is disabled', () => { | ||
| mockGetEffectiveCapabilityEnabled.mockReturnValue(false) | ||
| render( | ||
| <AgentVersionSection | ||
| agentVersion="1.2.3" | ||
| configuredCapabilities={0} | ||
| effectiveCapabilities={0} | ||
| latestVersion="1.3.0" | ||
| serverId="srv-1" | ||
| /> | ||
| ) | ||
| expect(screen.queryByText('upgrade_start')).toBeNull() | ||
| }) | ||
|
|
||
| it('shows disabled message for admin when capability is disabled', () => { | ||
| mockGetEffectiveCapabilityEnabled.mockReturnValue(false) | ||
| render( | ||
| <AgentVersionSection | ||
| agentVersion="1.2.3" | ||
| configuredCapabilities={0} | ||
| effectiveCapabilities={0} | ||
| latestVersion="1.3.0" | ||
| serverId="srv-1" | ||
| /> | ||
| ) | ||
| expect(screen.getByText('cap_disabled')).toBeDefined() | ||
| }) | ||
|
|
||
| it('triggers upgrade when button clicked', () => { | ||
| render( | ||
| <AgentVersionSection | ||
| agentVersion="1.2.3" | ||
| configuredCapabilities={255} | ||
| effectiveCapabilities={255} | ||
| latestVersion="1.3.0" | ||
| serverId="srv-1" | ||
| /> | ||
| ) | ||
| const button = screen.getByText('upgrade_start') | ||
| fireEvent.click(button) | ||
| expect(mockTriggerUpgrade).toHaveBeenCalledWith('1.3.0') | ||
| }) | ||
|
|
||
| it('shows stepper when upgrade is running', () => { | ||
| mockUseUpgradeJob.mockReturnValue({ | ||
| job: { | ||
| backup_path: null, | ||
| error: null, | ||
| finished_at: null, | ||
| job_id: 'job-1', | ||
| server_id: 'srv-1', | ||
| stage: 'downloading', | ||
| started_at: new Date().toISOString(), | ||
| status: 'running', | ||
| target_version: '1.3.0' | ||
| }, | ||
| triggerUpgrade: mockTriggerUpgrade, | ||
| isLoading: false | ||
| }) | ||
| render( | ||
| <AgentVersionSection | ||
| agentVersion="1.2.3" | ||
| configuredCapabilities={255} | ||
| effectiveCapabilities={255} | ||
| latestVersion="1.3.0" | ||
| serverId="srv-1" | ||
| /> | ||
| ) | ||
| expect(screen.getByText('upgrade_in_progress')).toBeDefined() | ||
| // The stage name appears in both the badge and stepper, so check for multiple occurrences | ||
| const stageElements = screen.getAllByText('upgrade_stage_downloading') | ||
| expect(stageElements.length).toBeGreaterThanOrEqual(1) | ||
| }) | ||
|
|
||
| it('shows success state when upgrade succeeded', () => { | ||
| mockUseUpgradeJob.mockReturnValue({ | ||
| job: { | ||
| backup_path: null, | ||
| error: null, | ||
| finished_at: new Date().toISOString(), | ||
| job_id: 'job-1', | ||
| server_id: 'srv-1', | ||
| stage: 'restarting', | ||
| started_at: new Date().toISOString(), | ||
| status: 'succeeded', | ||
| target_version: '1.3.0' | ||
| }, | ||
| triggerUpgrade: mockTriggerUpgrade, | ||
| isLoading: false | ||
| }) | ||
| render( | ||
| <AgentVersionSection | ||
| agentVersion="1.3.0" | ||
| configuredCapabilities={255} | ||
| effectiveCapabilities={255} | ||
| latestVersion="1.3.0" | ||
| serverId="srv-1" | ||
| /> | ||
| ) | ||
| expect(screen.getByText('upgrade_status_succeeded')).toBeDefined() | ||
| }) | ||
|
|
||
| it('shows failed state with error message', () => { | ||
| mockUseUpgradeJob.mockReturnValue({ | ||
| job: { | ||
| backup_path: '/tmp/backup', | ||
| error: 'Download failed: connection timeout', | ||
| finished_at: new Date().toISOString(), | ||
| job_id: 'job-1', | ||
| server_id: 'srv-1', | ||
| stage: 'downloading', | ||
| started_at: new Date().toISOString(), | ||
| status: 'failed', | ||
| target_version: '1.3.0' | ||
| }, | ||
| triggerUpgrade: mockTriggerUpgrade, | ||
| isLoading: false | ||
| }) | ||
| render( | ||
| <AgentVersionSection | ||
| agentVersion="1.2.3" | ||
| configuredCapabilities={255} | ||
| effectiveCapabilities={255} | ||
| latestVersion="1.3.0" | ||
| serverId="srv-1" | ||
| /> | ||
| ) | ||
| expect(screen.getByText('upgrade_status_failed')).toBeDefined() | ||
| expect(screen.getByText('Download failed: connection timeout')).toBeDefined() | ||
| expect(screen.getByText(UPGRADE_ERROR_WITH_BACKUP_PATTERN)).toBeDefined() | ||
| }) | ||
|
|
||
| it('shows timeout state with backup path', () => { | ||
| mockUseUpgradeJob.mockReturnValue({ | ||
| job: { | ||
| backup_path: '/opt/serverbee/backups/agent.bak', | ||
| error: null, | ||
| finished_at: new Date().toISOString(), | ||
| job_id: 'job-1', | ||
| server_id: 'srv-1', | ||
| stage: 'installing', | ||
| started_at: new Date().toISOString(), | ||
| status: 'timeout', | ||
| target_version: '1.3.0' | ||
| }, | ||
| triggerUpgrade: mockTriggerUpgrade, | ||
| isLoading: false | ||
| }) | ||
| render( | ||
| <AgentVersionSection | ||
| agentVersion="1.2.3" | ||
| configuredCapabilities={255} | ||
| effectiveCapabilities={255} | ||
| latestVersion="1.3.0" | ||
| serverId="srv-1" | ||
| /> | ||
| ) | ||
| expect(screen.getByText('upgrade_status_timeout')).toBeDefined() | ||
| expect(screen.getByText(UPGRADE_BACKUP_PATH_PATTERN)).toBeDefined() | ||
| }) | ||
|
|
||
| it('disables upgrade button while loading', () => { | ||
| mockUseUpgradeJob.mockReturnValue({ | ||
| job: null, | ||
| triggerUpgrade: mockTriggerUpgrade, | ||
| isLoading: true | ||
| }) | ||
| render( | ||
| <AgentVersionSection | ||
| agentVersion="1.2.3" | ||
| configuredCapabilities={255} | ||
| effectiveCapabilities={255} | ||
| latestVersion="1.3.0" | ||
| serverId="srv-1" | ||
| /> | ||
| ) | ||
| const button = screen.getByRole('button') | ||
| expect(button).toBeDisabled() | ||
| }) | ||
| }) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: ZingerLittleBee/ServerBee
Length of output: 96
🌐 Web query:
For the@base-ui/react/checkboxversion used by this repository, what are the exact types and semantics for Checkbox.RootcheckedandonCheckedChange?💡 Result:
For
@base-ui/react/checkboxCheckbox.Root: checked: boolean | undefined (controlled checked state; use defaultChecked for uncontrolled) onCheckedChange: ((checked: boolean, eventDetails: CheckboxRootChangeEventDetails) => void) | undefined Where CheckboxRootChangeEventDetails = BaseUIChangeEventDetails with reason: 'none'. Note: The query mentions "version used by this repository" but no specific repo provided; types from@base-ui/react@1.1.0 and current docs match. Base UI (MUI) follows similar patterns to Radix but uses boolean (not 'indeterminate') for checked prop.Citations:
🏁 Script executed:
Repository: ZingerLittleBee/ServerBee
Length of output: 3601
🏁 Script executed:
Repository: ZingerLittleBee/ServerBee
Length of output: 207
🏁 Script executed:
Repository: ZingerLittleBee/ServerBee
Length of output: 108
🏁 Script executed:
Repository: ZingerLittleBee/ServerBee
Length of output: 108
🏁 Script executed:
Repository: ZingerLittleBee/ServerBee
Length of output: 1577
Fix the checkbox mock to align with actual input state transitions.
On Line 85, using
!checkedto toggle can diverge from the real HTML input's state. Useevent.currentTarget.checkedto ensure the mock's behavior matches the actual Checkbox component semantics.Proposed fix
<input checked={checked} data-testid="checkbox" - onChange={() => onCheckedChange?.(!checked)} + onChange={(event) => onCheckedChange?.(event.currentTarget.checked)} type="checkbox" {...props} />📝 Committable suggestion
🤖 Prompt for AI Agents