mirror of
https://github.com/stablyai/orca.git
synced 2026-11-17 19:34:29 +00:00
test(cloud): CR-cmd-quiet wrap cases (1-3 rows, long coloured prompt); the zsh history hook moves to its own PR after #468's rotation
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -24,11 +24,4 @@ if [ -n "${ORCA_WORKSPACE_PATH-}" ] && [ -z "${ORCA_DEFAULT_BRANCH-}" ]; then
|
||||
export ORCA_DEFAULT_BRANCH="${__orca_branch#origin/}" CONDUCTOR_DEFAULT_BRANCH="${__orca_branch#origin/}"
|
||||
fi
|
||||
fi
|
||||
# CR-cmd-quiet: Orca's staged agent launch (` . '/tmp/orca-launch-….sh'`) stays out of zsh history.
|
||||
# zsh records a line before running it, so the hook must exist first; the staged script itself
|
||||
# drops the line from bash's history. eval: bash parses this file too.
|
||||
if [ -n "${ZSH_VERSION-}" ]; then
|
||||
eval '__orca_skip_launch_history() { [[ $1 == *orca-launch-* ]] && return 1; return 0 }
|
||||
(( ${zshaddhistory_functions[(Ie)__orca_skip_launch_history]} )) || zshaddhistory_functions+=(__orca_skip_launch_history)'
|
||||
fi
|
||||
unset __orca_env_file __orca_line __orca_n __orca_names __orca_branch
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
utimesSync,
|
||||
writeFileSync
|
||||
} from 'node:fs'
|
||||
import { execFileSync } from 'node:child_process'
|
||||
import { execFileSync, spawnSync } from 'node:child_process'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { basename, join } from 'node:path'
|
||||
import { afterEach, beforeEach, describe, expect, it } from 'vitest'
|
||||
@@ -142,24 +142,53 @@ describe('CR-cmd-quiet: Orca’s staged agent line leaves no trace on a cloud ho
|
||||
// A 21-column prompt plus the typed line on a 40-column terminal: the rows they took.
|
||||
const prompt = 'user@host:~/project$ '
|
||||
const rows = Math.ceil((prompt.length + staged.command.length) / 40)
|
||||
let stdout = ''
|
||||
let stderr = ''
|
||||
try {
|
||||
execFileSync('bash', ['-c', `PS1='${prompt}'; ${staged.command}`], {
|
||||
env: { ...process.env, COLUMNS: '40' },
|
||||
encoding: 'utf8',
|
||||
stdio: ['ignore', 'pipe', 'pipe']
|
||||
})
|
||||
} catch (error) {
|
||||
const failed = error as { stdout: string; stderr: string }
|
||||
stdout = failed.stdout
|
||||
stderr = failed.stderr
|
||||
}
|
||||
const { stdout, stderr } = spawnSync('bash', ['-c', `PS1='${prompt}'; ${staged.command}`], {
|
||||
env: { ...process.env, COLUMNS: '40' },
|
||||
encoding: 'utf8'
|
||||
})
|
||||
expect(stdout.startsWith(`\r${ESC}[${rows}A${ESC}[J`)).toBe(true)
|
||||
expect(stdout).toContain('AGENT-OUTPUT')
|
||||
expect(stderr).toContain('orca-no-such-dir')
|
||||
})
|
||||
|
||||
function eraseRows(shellPrompt: string, columns: number): number {
|
||||
const staged = quietStage('/bin/bash', 'true')
|
||||
const out = execFileSync(
|
||||
'bash',
|
||||
['-c', `PS1=${JSON.stringify(shellPrompt)}; ${staged.command}`],
|
||||
{
|
||||
env: { ...process.env, COLUMNS: String(columns) },
|
||||
encoding: 'utf8'
|
||||
}
|
||||
)
|
||||
const match = new RegExp(`^\\r${ESC}\\[(\\d+)A${ESC}\\[J`).exec(out)
|
||||
return match ? Number(match[1]) : -1
|
||||
}
|
||||
|
||||
it.each([1, 2, 3])(
|
||||
'erases exactly the %i row(s) the prompt and typed line wrapped across, nothing above the prompt',
|
||||
(rows) => {
|
||||
const prompt = 'ubuntu@ik-card:~/w$ '
|
||||
// The typed line's length depends on the temp dir; size the pane so it wraps across `rows`.
|
||||
const typed = quietStage('/bin/bash', 'true').command.length
|
||||
const columns = Math.ceil((prompt.length + typed) / rows)
|
||||
expect(Math.ceil((prompt.length + typed) / columns)).toBe(rows)
|
||||
expect(eraseRows(prompt, columns)).toBe(rows)
|
||||
}
|
||||
)
|
||||
|
||||
it('counts a long coloured prompt (deep cwd, git branch) by its visible width', () => {
|
||||
const visible =
|
||||
'ubuntu@ik-card:~/orca/workspaces/Hello-World/fix-login-redirect (fix-login-redirect)$ '
|
||||
// Colours and an OSC 133 mark, wrapped in \[ \] the way prompts are written: they take no room.
|
||||
const coloured = String.raw`\[\e]133;A\a\]\[\e[32m\]ubuntu@ik-card\[\e[0m\]:\[\e[34m\]~/orca/workspaces/Hello-World/fix-login-redirect\[\e[0m\] (fix-login-redirect)$ `
|
||||
const staged = quietStage('/bin/bash', 'true')
|
||||
const rows = Math.ceil((visible.length + staged.command.length) / 120)
|
||||
expect(eraseRows(coloured, 120)).toBe(rows)
|
||||
// Only the prompt's last line shares a row with the typed line.
|
||||
expect(eraseRows(String.raw`first line\n` + 'ubuntu@ik-card:~/w$ ', 400)).toBe(1)
|
||||
})
|
||||
|
||||
it('drops the line from bash history', () => {
|
||||
const staged = quietStage('/bin/bash', 'true')
|
||||
const history = execFileSync(
|
||||
|
||||
Reference in New Issue
Block a user