mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +01:00
fix: address review feedback on execute status, file links, and login flags
This commit is contained in:
1 parent
421387793b
commit
801a4cd112
5 files changed
+81
-13
No files matched your search
@@ -197,7 +197,9 @@ export function ExecuteToolPart({ part, isWaitingPermission, onFileClick }: Exec
|
||||
() => (displayOutput === output ? parseOutput(output) : undefined),
|
||||
[displayOutput, output],
|
||||
)
|
||||
const failed = part.state.status === 'error' || metadata.error === true
|
||||
const failed = part.state.status === 'error'
|
||||
|| metadata.error === true
|
||||
|| (part.state.status === 'completed' && calls.some((call) => call.status === 'error'))
|
||||
const status = part.state.status
|
||||
|
||||
const statusLabel = (() => {
|
||||
|
||||
@@ -20,17 +20,19 @@ export function FileReferenceText({ text, onFileClick }: FileReferenceTextProps)
|
||||
}
|
||||
|
||||
segments.push(
|
||||
<span
|
||||
<button
|
||||
key={`ref-${index}`}
|
||||
type="button"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation()
|
||||
onFileClick?.(ref.filePath)
|
||||
}}
|
||||
className="text-primary hover:text-primary-hover cursor-pointer underline decoration-dotted"
|
||||
className="inline p-0 m-0 bg-transparent border-0 font-[inherit] text-left text-primary hover:text-primary-hover cursor-pointer underline decoration-dotted"
|
||||
title={`Click to open ${ref.filePath}`}
|
||||
aria-label={`Open ${ref.filePath}`}
|
||||
>
|
||||
{ref.fullMatch}
|
||||
</span>,
|
||||
</button>,
|
||||
)
|
||||
|
||||
lastIndex = ref.endIndex
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||
import { act, fireEvent, render, screen, waitFor } from '@testing-library/react'
|
||||
import { act, fireEvent, render, screen, waitFor, within } from '@testing-library/react'
|
||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
||||
import { MemoryRouter } from 'react-router-dom'
|
||||
import type { PermissionRequest, SessionMessageAssistantTool } from '@opencode-manager/shared/opencode'
|
||||
@@ -332,7 +332,10 @@ describe('ToolCallPart execute renderer', () => {
|
||||
|
||||
expect(screen.getByText('cua-driver.list_windows [app=TextEdit]')).toBeInTheDocument()
|
||||
expect(screen.getByText('cua-driver.click [x=10]')).toBeInTheDocument()
|
||||
expect(screen.getByText('✗')).toBeInTheDocument()
|
||||
|
||||
const errorRow = screen.getByRole('button', { name: /cua-driver\.click/ })
|
||||
expect(within(errorRow).getByText('✗')).toBeInTheDocument()
|
||||
expect(screen.getByText(/Failed/)).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders line-numbered code and output sections when expanded', () => {
|
||||
@@ -423,7 +426,9 @@ describe('ToolCallPart execute renderer', () => {
|
||||
renderWithProviders(<ToolCallPart part={part} messageID="msg_1" onFileClick={onFileClick} />)
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: /read \[path=src\/app.ts\]/ }))
|
||||
fireEvent.click(screen.getByTitle('Click to open src/app.ts'))
|
||||
const reference = screen.getByRole('button', { name: 'Open src/app.ts' })
|
||||
expect(reference).toHaveAttribute('title', 'Click to open src/app.ts')
|
||||
fireEvent.click(reference)
|
||||
|
||||
expect(onFileClick).toHaveBeenCalledWith('src/app.ts')
|
||||
})
|
||||
|
||||
+25
-6
@@ -135,15 +135,34 @@ function findRepo(repos: ManagerRepo[], needle: string | number): ManagerRepo |
|
||||
return repos.find((r) => r.name === needle) ?? repos.find((r) => r.name.toLowerCase() === needle.toLowerCase())
|
||||
}
|
||||
|
||||
export async function cmdLogin(args: string[]): Promise<void> {
|
||||
const nameFlag = args.indexOf('--name')
|
||||
const managerName = nameFlag >= 0 ? args[nameFlag + 1] : undefined
|
||||
const positional = nameFlag >= 0 ? [...args.slice(0, nameFlag), ...args.slice(nameFlag + 2)] : args
|
||||
const LOGIN_USAGE = 'usage: ocm login <url> [token] [--name <name>]'
|
||||
|
||||
function parseLoginArgs(args: string[]): { url: string; token?: string; managerName?: string } {
|
||||
const positional: string[] = []
|
||||
const managerNames: string[] = []
|
||||
for (let index = 0; index < args.length; index++) {
|
||||
const arg = args[index]
|
||||
if (arg === '--name') {
|
||||
const value = args[index + 1]
|
||||
if (!value || value.startsWith('-')) die(LOGIN_USAGE)
|
||||
managerNames.push(value)
|
||||
index++
|
||||
continue
|
||||
}
|
||||
if (arg.startsWith('-')) die(LOGIN_USAGE)
|
||||
positional.push(arg)
|
||||
}
|
||||
if (managerNames.length > 1) die(LOGIN_USAGE)
|
||||
const url = positional[0]
|
||||
if (!url || (nameFlag >= 0 && !managerName)) die('usage: ocm login <url> [token] [--name <name>]')
|
||||
if (!url) die(LOGIN_USAGE)
|
||||
return { url, token: positional[1], managerName: managerNames[0] }
|
||||
}
|
||||
|
||||
export async function cmdLogin(args: string[]): Promise<void> {
|
||||
const { url, token: providedToken, managerName } = parseLoginArgs(args)
|
||||
const normalisedUrl = normalizeManagerUrl(url)
|
||||
|
||||
let token = positional[1]
|
||||
let token = providedToken
|
||||
if (!token) {
|
||||
if (process.stdin.isTTY) {
|
||||
process.stderr.write('Paste token (input hidden): ')
|
||||
|
||||
@@ -160,6 +160,46 @@ describe('cli auth commands', () => {
|
||||
restore()
|
||||
})
|
||||
|
||||
const expectLoginUsageError = async (args: string[]) => {
|
||||
const { cli, stderr, setToken, restore } = await loadCli()
|
||||
const exitSpy = vi.spyOn(process, 'exit').mockImplementation(() => {
|
||||
throw new Error('exit')
|
||||
})
|
||||
await expect(cli.cmdLogin(args)).rejects.toThrow('exit')
|
||||
expect(stderr.join('')).toContain('usage: ocm login <url> [token] [--name <name>]')
|
||||
expect(exitSpy).toHaveBeenCalledWith(1)
|
||||
expect(setToken).not.toHaveBeenCalled()
|
||||
restore()
|
||||
}
|
||||
|
||||
it('ocm login rejects a repeated --name flag without saving a token', async () => {
|
||||
await expectLoginUsageError(['https://manager.example.com', '--name', 'prod', '--name', 'staging'])
|
||||
})
|
||||
|
||||
it('ocm login rejects a --name flag without a value', async () => {
|
||||
await expectLoginUsageError(['https://manager.example.com', 'tok_xyz', '--name'])
|
||||
})
|
||||
|
||||
it('ocm login rejects a --name value that looks like a flag', async () => {
|
||||
await expectLoginUsageError(['https://manager.example.com', '--name', '--force'])
|
||||
})
|
||||
|
||||
it('ocm login rejects an unknown flag', async () => {
|
||||
await expectLoginUsageError(['https://manager.example.com', 'tok_xyz', '--force'])
|
||||
})
|
||||
|
||||
it('ocm login accepts the token before or after --name', async () => {
|
||||
const afterName = await loadCli()
|
||||
await afterName.cli.cmdLogin(['https://manager.example.com', 'tok_xyz', '--name', 'prod'])
|
||||
expect(afterName.setToken).toHaveBeenCalledWith('https://manager.example.com', 'tok_xyz')
|
||||
afterName.restore()
|
||||
|
||||
const beforeName = await loadCli()
|
||||
await beforeName.cli.cmdLogin(['https://manager.example.com', '--name', 'prod', 'tok_xyz'])
|
||||
expect(beforeName.setToken).toHaveBeenCalledWith('https://manager.example.com', 'tok_xyz')
|
||||
beforeName.restore()
|
||||
})
|
||||
|
||||
it('ocm logout reports removal', async () => {
|
||||
const { cli, written, restore } = await loadCli({ deleteTokenImpl: () => Promise.resolve(true) })
|
||||
await cli.cmdLogout()
|
||||
|
||||
Reference in new issue
Block a user