fix(terminal): keep OMP subcommands extension-free (#6612)
Co-authored-by: Wolfgang Schoenberger <221313372+wolfiesch@users.noreply.github.com>
This commit is contained in:
co-authored by
Wolfgang Schoenberger
parent
bcce8e37e2
commit
b86242469c
@@ -210,6 +210,61 @@ exit 0
|
||||
expect(readFileSync(join(sourceDir, 'config.yml'), 'utf8')).toBe('updated-by-omp-config\n')
|
||||
})
|
||||
|
||||
itWithBash.each([
|
||||
'__complete',
|
||||
'bench',
|
||||
'completions',
|
||||
'dry-balance',
|
||||
'gallery',
|
||||
'install',
|
||||
'join',
|
||||
'models',
|
||||
'say',
|
||||
'tiny-models',
|
||||
'token',
|
||||
'ttsr',
|
||||
'usage'
|
||||
])('runs OMP %s subcommands without injecting the status extension', async (subcommand) => {
|
||||
const tempDir = makeTempDir()
|
||||
const binDir = join(tempDir, 'bin')
|
||||
const sourceDir = join(tempDir, 'source-omp-agent')
|
||||
const extensionDir = join(sourceDir, 'extensions')
|
||||
mkdirSync(binDir)
|
||||
mkdirSync(sourceDir, { recursive: true })
|
||||
mkdirSync(extensionDir, { recursive: true })
|
||||
const statusExtension = join(extensionDir, 'orca-agent-status.ts')
|
||||
writeFileSync(statusExtension, 'export default {}')
|
||||
writeFakeOmp(binDir)
|
||||
|
||||
const captureFile = join(tempDir, `${subcommand}-capture`)
|
||||
await runInteractiveBashPty({
|
||||
cwd: tempDir,
|
||||
rcfileContent: getPosixOmpShellWrapper(),
|
||||
env: {
|
||||
...process.env,
|
||||
HOME: tempDir,
|
||||
PATH: `${binDir}:${process.env.PATH ?? ''}`,
|
||||
PI_CODING_AGENT_DIR: '',
|
||||
ORCA_PI_CODING_AGENT_DIR: '',
|
||||
ORCA_OMP_CODING_AGENT_DIR: '',
|
||||
ORCA_OMP_SOURCE_AGENT_DIR: sourceDir,
|
||||
ORCA_OMP_STATUS_EXTENSION: statusExtension,
|
||||
ORCA_FAKE_OMP_DEFAULT_DIR: sourceDir,
|
||||
ORCA_CAPTURE_FILE: captureFile,
|
||||
TERM: process.env.TERM || 'xterm-256color'
|
||||
},
|
||||
input: `omp ${subcommand}
|
||||
exit 0
|
||||
`
|
||||
})
|
||||
|
||||
const capture = readFileSync(captureFile, 'utf8')
|
||||
expect(capture).toContain('PI=\n')
|
||||
expect(capture).toContain(`EFFECTIVE=${sourceDir}`)
|
||||
expect(capture).toContain(`ARG1=${subcommand}`)
|
||||
expect(capture).not.toContain('ARG1=--extension')
|
||||
})
|
||||
|
||||
itWithBash(
|
||||
'lets OMP config subcommands fall back to the default home without a source shadow',
|
||||
async () => {
|
||||
|
||||
@@ -5,25 +5,38 @@
|
||||
// normal source of truth.
|
||||
|
||||
const OMP_SUBCOMMANDS = [
|
||||
'__complete',
|
||||
'acp',
|
||||
'agents',
|
||||
'auth-broker',
|
||||
'auth-gateway',
|
||||
'bench',
|
||||
'commit',
|
||||
'completions',
|
||||
'config',
|
||||
'dry-balance',
|
||||
'gallery',
|
||||
'grep',
|
||||
'grievances',
|
||||
'install',
|
||||
'join',
|
||||
'models',
|
||||
'plugin',
|
||||
'read',
|
||||
'say',
|
||||
'search',
|
||||
'setup',
|
||||
'shell',
|
||||
'read',
|
||||
'ssh',
|
||||
'stats',
|
||||
'tiny-models',
|
||||
'token',
|
||||
'ttsr',
|
||||
'update',
|
||||
'usage',
|
||||
'worktree',
|
||||
'wt',
|
||||
'search',
|
||||
'q'
|
||||
'q',
|
||||
'wt'
|
||||
] as const
|
||||
|
||||
export function getPosixOmpShellWrapper(): string {
|
||||
@@ -31,17 +44,12 @@ export function getPosixOmpShellWrapper(): string {
|
||||
return `# Why: OMP does not auto-load Orca's managed status extension; wrap only
|
||||
# interactive launch invocations so subcommands such as \`omp config\` keep
|
||||
# their normal argv shape.
|
||||
__orca_omp_is_subcommand() {
|
||||
case "\${1:-}" in
|
||||
${subcommands}) return 0 ;;
|
||||
esac
|
||||
return 1
|
||||
}
|
||||
__orca_omp_should_skip_extension() {
|
||||
case "\${1:-}" in
|
||||
help|--help|-h|--version|-v) return 0 ;;
|
||||
${subcommands}) return 0 ;;
|
||||
esac
|
||||
__orca_omp_is_subcommand "\${1:-}"
|
||||
return 1
|
||||
}
|
||||
__orca_omp() {
|
||||
local __orca_use_extension=1
|
||||
@@ -68,15 +76,10 @@ export function getPowerShellOmpShellWrapper(): string {
|
||||
return `# Why: OMP does not auto-load Orca's managed status extension; wrap only
|
||||
# interactive launch invocations so subcommands such as \`omp config\` keep
|
||||
# their normal argv shape.
|
||||
function Global:__OrcaOmpIsSubcommand {
|
||||
param([string]$Name)
|
||||
$subcommands = @(${subcommands})
|
||||
return $subcommands -contains $Name
|
||||
}
|
||||
function Global:__OrcaOmpShouldSkipExtension {
|
||||
param([string]$Name)
|
||||
if (@("help", "--help", "-h", "--version", "-v") -contains $Name) { return $true }
|
||||
return __OrcaOmpIsSubcommand -Name $Name
|
||||
$skip = @("help", "--help", "-h", "--version", "-v") + @(${subcommands})
|
||||
return $skip -contains $Name
|
||||
}
|
||||
if ($env:ORCA_OMP_STATUS_EXTENSION) {
|
||||
function Global:omp {
|
||||
|
||||
Reference in New Issue
Block a user