mirror of
https://github.com/stablyai/orca.git
synced 2026-11-14 18:07:45 +00:00
test: remove 321 low-value main and shared tests (#39429)
Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
|
||||
import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { dirname, join } from 'node:path'
|
||||
import { parse as parseToml } from 'smol-toml'
|
||||
@@ -17,9 +17,7 @@ import { JcodeHookService } from './hook-service'
|
||||
import {
|
||||
getJcodeConfigPath,
|
||||
getJcodeManagedCommand,
|
||||
getJcodeManagedScriptFileName,
|
||||
getJcodeManagedScriptPath,
|
||||
JCODE_HOOK_EVENTS
|
||||
getJcodeManagedScriptPath
|
||||
} from './hook-settings'
|
||||
import { tomlQuoteString } from './hook-config'
|
||||
|
||||
@@ -39,36 +37,6 @@ describe('JcodeHookService', () => {
|
||||
rmSync(homeDir, { recursive: true, force: true })
|
||||
})
|
||||
|
||||
it('reports not_installed before any install', () => {
|
||||
const status = new JcodeHookService().getStatus()
|
||||
expect(status).toMatchObject({
|
||||
agent: 'jcode',
|
||||
state: 'not_installed',
|
||||
configPath: getJcodeConfigPath()
|
||||
})
|
||||
})
|
||||
|
||||
it('installs managed hooks into jcode config.toml and posts to /hook/jcode', () => {
|
||||
const status = new JcodeHookService().install()
|
||||
expect(status.state).toBe('installed')
|
||||
expect(status.agent).toBe('jcode')
|
||||
expect(status.configPath).toBe(getJcodeConfigPath())
|
||||
expect(status.managedHooksPresent).toBe(true)
|
||||
|
||||
const config = readFileSync(getJcodeConfigPath(), 'utf8')
|
||||
for (const event of JCODE_HOOK_EVENTS) {
|
||||
// Commands are shell-quoted for jcode, then TOML-quoted for config storage.
|
||||
expect(config).toContain(
|
||||
`${event} = ${tomlQuoteString(getJcodeManagedCommand(getJcodeManagedScriptPath()))}`
|
||||
)
|
||||
}
|
||||
const script = readFileSync(getJcodeManagedScriptPath(), 'utf8')
|
||||
expect(script).toContain('/hook/jcode')
|
||||
expect(script).toContain('payload@-')
|
||||
expect(script).toContain('$JCODE_HOOK_PAYLOAD')
|
||||
expect(script).toContain('payload="$JCODE_HOOK_PAYLOAD"')
|
||||
})
|
||||
|
||||
it('reports a missing managed script and repairs it without changing config', () => {
|
||||
const service = new JcodeHookService()
|
||||
service.install()
|
||||
@@ -86,30 +54,6 @@ describe('JcodeHookService', () => {
|
||||
expect(readFileSync(getJcodeConfigPath(), 'utf8')).toBe(config)
|
||||
})
|
||||
|
||||
it('reports missing scripts alongside incomplete event coverage and user hooks', () => {
|
||||
const service = new JcodeHookService()
|
||||
service.install()
|
||||
writeFileSync(
|
||||
getJcodeConfigPath(),
|
||||
`[hooks]\nsession_start = ${tomlQuoteString(getJcodeManagedCommand(getJcodeManagedScriptPath()))}\nturn_end = "~/bin/my-turn-notify"\n`,
|
||||
'utf8'
|
||||
)
|
||||
rmSync(getJcodeManagedScriptPath())
|
||||
|
||||
const status = service.getStatus()
|
||||
expect(status.state).toBe('partial')
|
||||
expect(status.detail).toContain('Managed hook script missing')
|
||||
expect(status.detail).toContain(
|
||||
'Managed hook missing for events: turn_start, pre_tool, post_tool, session_end'
|
||||
)
|
||||
expect(status.detail).toContain('User-owned hooks kept for events: turn_end')
|
||||
expect(service.install().state).toBe('partial')
|
||||
expect(service.getStatus().detail).not.toContain('script missing')
|
||||
expect(readFileSync(getJcodeConfigPath(), 'utf8')).toContain(
|
||||
'turn_end = "~/bin/my-turn-notify"'
|
||||
)
|
||||
})
|
||||
|
||||
it.each([
|
||||
'/Users/previous/.orca/agent-hooks/jcode-hook.sh',
|
||||
'C:\\Users\\previous\\.orca\\agent-hooks\\jcode-hook.cmd'
|
||||
@@ -133,60 +77,6 @@ describe('JcodeHookService', () => {
|
||||
expect(readFileSync(configPath, 'utf8')).not.toContain('previous')
|
||||
})
|
||||
|
||||
it('does not report stale managed commands as installed beside the current one', () => {
|
||||
const service = new JcodeHookService()
|
||||
service.install()
|
||||
const staleCommand = getJcodeManagedCommand('/Users/previous/.orca/agent-hooks/jcode-hook.sh')
|
||||
writeFileSync(
|
||||
getJcodeConfigPath(),
|
||||
`[hooks]\n${JCODE_HOOK_EVENTS.map((event) => `${event} = [${tomlQuoteString(staleCommand)}, ${tomlQuoteString(getJcodeManagedCommand(getJcodeManagedScriptPath()))}]`).join('\n')}\n`,
|
||||
'utf8'
|
||||
)
|
||||
|
||||
const status = service.getStatus()
|
||||
expect(status.state).toBe('partial')
|
||||
expect(status.managedHooksPresent).toBe(true)
|
||||
expect(status.detail).toBe(
|
||||
`Managed hook command outdated for events: ${JCODE_HOOK_EVENTS.join(', ')}`
|
||||
)
|
||||
expect(service.install().state).toBe('installed')
|
||||
expect(readFileSync(getJcodeConfigPath(), 'utf8')).not.toContain('previous')
|
||||
})
|
||||
|
||||
it('reports legacy unquoted commands as outdated even when the script exists', () => {
|
||||
const service = new JcodeHookService()
|
||||
service.install()
|
||||
writeFileSync(
|
||||
getJcodeConfigPath(),
|
||||
`[hooks]\n${JCODE_HOOK_EVENTS.map((event) => `${event} = ${tomlQuoteString(getJcodeManagedScriptPath())}`).join('\n')}\n`,
|
||||
'utf8'
|
||||
)
|
||||
|
||||
const status = service.getStatus()
|
||||
expect(status.state).toBe('partial')
|
||||
expect(status.detail).toContain('Managed hook command outdated for events:')
|
||||
expect(status.detail).not.toContain('script missing')
|
||||
expect(status.detail).not.toContain('User-owned')
|
||||
expect(service.install().state).toBe('installed')
|
||||
})
|
||||
|
||||
it('does not mistake a user command mentioning the managed script in a comment for Orca ownership', () => {
|
||||
const configPath = getJcodeConfigPath()
|
||||
mkdirSync(dirname(configPath), { recursive: true })
|
||||
writeFileSync(
|
||||
configPath,
|
||||
`[hooks]\nturn_end = "~/bin/my-turn-notify" # replaces agent-hooks/${getJcodeManagedScriptFileName()}\n`,
|
||||
'utf8'
|
||||
)
|
||||
|
||||
const status = new JcodeHookService().getStatus()
|
||||
expect(status.state).toBe('partial')
|
||||
expect(status.managedHooksPresent).toBe(false)
|
||||
expect(status.detail).toContain('User-owned hooks kept for events: turn_end')
|
||||
expect(status.detail).not.toContain('command outdated')
|
||||
expect(status.detail).not.toContain('script missing')
|
||||
})
|
||||
|
||||
it('preserves unrelated config tables when installing hooks', () => {
|
||||
const configPath = getJcodeConfigPath()
|
||||
mkdirSync(dirname(configPath), { recursive: true })
|
||||
@@ -207,15 +97,6 @@ describe('JcodeHookService', () => {
|
||||
expect(readFileSync(configPath, 'utf8')).toContain('turn_end = "~/bin/my-turn-notify"')
|
||||
})
|
||||
|
||||
it('reports error when the [hooks] table holds a non-scalar value', () => {
|
||||
const configPath = getJcodeConfigPath()
|
||||
mkdirSync(dirname(configPath), { recursive: true })
|
||||
writeFileSync(configPath, '[hooks]\nturn_end = """\nmultiline\n"""\n', 'utf8')
|
||||
const status = new JcodeHookService().install()
|
||||
expect(status.state).toBe('error')
|
||||
expect(status.detail).toContain('config.toml')
|
||||
})
|
||||
|
||||
it('appends to user hook arrays and removes only its own element', () => {
|
||||
const configPath = getJcodeConfigPath()
|
||||
const source = `[hooks]\npre_tool = [\n "~/gates/pre-tool.sh", # policy\n "~/gates/memory-gate.sh",\n]\npre_tool_timeout_ms = 5000\n`
|
||||
@@ -244,16 +125,4 @@ describe('JcodeHookService', () => {
|
||||
'pre_tool = [\n "~/gates/pre-tool.sh", # policy\n "~/gates/memory-gate.sh",\n]\n'
|
||||
)
|
||||
})
|
||||
|
||||
it('remove clears only the managed entries', () => {
|
||||
new JcodeHookService().install()
|
||||
const before = readFileSync(getJcodeConfigPath(), 'utf8')
|
||||
expect(before).toContain('turn_end')
|
||||
const status = new JcodeHookService().remove()
|
||||
expect(status.state).toBe('not_installed')
|
||||
expect(status.detail).toBeNull()
|
||||
expect(existsSync(getJcodeManagedScriptPath())).toBe(true)
|
||||
const after = readFileSync(getJcodeConfigPath(), 'utf8')
|
||||
expect(after).not.toContain(getJcodeManagedScriptPath())
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user