mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +01:00
Update tests to use Loop terminology
This commit is contained in:
1 parent
5f7abe3fd8
commit
c87edded70
8 files changed
+126
-126
No files matched your search
@@ -194,7 +194,7 @@ describe('Memory Routes - Loop Status', () => {
|
||||
mockResolveProjectId.mockResolvedValue('test-project-id')
|
||||
mockListKv.mockReturnValue([
|
||||
{
|
||||
key: 'ralph:test-worktree-1',
|
||||
key: 'loop:test-worktree-1',
|
||||
data: {
|
||||
active: true,
|
||||
sessionId: 'session-123',
|
||||
@@ -213,21 +213,21 @@ describe('Memory Routes - Loop Status', () => {
|
||||
expiresAt: Date.now() + 86400000,
|
||||
},
|
||||
{
|
||||
key: 'ralph:test-worktree-2',
|
||||
key: 'loop:test-worktree-2',
|
||||
data: null,
|
||||
createdAt: Date.now(),
|
||||
updatedAt: Date.now(),
|
||||
expiresAt: Date.now() + 86400000,
|
||||
},
|
||||
{
|
||||
key: 'ralph:test-worktree-3',
|
||||
key: 'loop:test-worktree-3',
|
||||
data: 'string-data',
|
||||
createdAt: Date.now(),
|
||||
updatedAt: Date.now(),
|
||||
expiresAt: Date.now() + 86400000,
|
||||
},
|
||||
{
|
||||
key: 'ralph:test-worktree-4',
|
||||
key: 'loop:test-worktree-4',
|
||||
data: { sessionId: 'session-abc' },
|
||||
createdAt: Date.now(),
|
||||
updatedAt: Date.now(),
|
||||
|
||||
@@ -9,7 +9,7 @@ interface LoopState {
|
||||
worktreeName: string
|
||||
worktreeBranch: string
|
||||
worktreeDir: string
|
||||
inPlace: boolean
|
||||
worktree: boolean
|
||||
iteration: number
|
||||
maxIterations: number
|
||||
phase: 'coding' | 'auditing'
|
||||
@@ -244,8 +244,8 @@ describe('CLI Cancel', () => {
|
||||
|
||||
test('partial name matches single loop proceeds with cancel', async () => {
|
||||
const db = createTestKvDb(tempDir)
|
||||
insertLoopState(db, 'test-project', 'ralph-feat-auth', {})
|
||||
insertLoopState(db, 'test-project', 'ralph-fix-bug', {})
|
||||
insertLoopState(db, 'test-project', 'loop-feat-auth', {})
|
||||
insertLoopState(db, 'test-project', 'loop-fix-bug', {})
|
||||
db.close()
|
||||
|
||||
const outputLines: string[] = []
|
||||
@@ -260,7 +260,7 @@ describe('CLI Cancel', () => {
|
||||
})
|
||||
|
||||
const db2 = new Database(join(tempDir, 'memory.db'))
|
||||
const authRow = db2.prepare('SELECT data FROM project_kv WHERE key = ?').get('loop:ralph-feat-auth') as { data: string }
|
||||
const authRow = db2.prepare('SELECT data FROM project_kv WHERE key = ?').get('loop:loop-feat-auth') as { data: string }
|
||||
const authState = JSON.parse(authRow.data) as LoopState
|
||||
db2.close()
|
||||
|
||||
@@ -270,8 +270,8 @@ describe('CLI Cancel', () => {
|
||||
|
||||
test('partial name matches multiple loops lists ambiguous and exits', async () => {
|
||||
const db = createTestKvDb(tempDir)
|
||||
insertLoopState(db, 'test-project', 'ralph-feat-auth', {})
|
||||
insertLoopState(db, 'test-project', 'ralph-auth-fix', {})
|
||||
insertLoopState(db, 'test-project', 'loop-feat-auth', {})
|
||||
insertLoopState(db, 'test-project', 'loop-auth-fix', {})
|
||||
db.close()
|
||||
|
||||
const outputLines: string[] = []
|
||||
@@ -299,7 +299,7 @@ describe('CLI Cancel', () => {
|
||||
expect(exited).toBe(true)
|
||||
const output = outputLines.join('\n')
|
||||
expect(output).toContain("Multiple loops match 'auth':")
|
||||
expect(output).toContain('ralph-feat-auth')
|
||||
expect(output).toContain('ralph-auth-fix')
|
||||
expect(output).toContain('loop-feat-auth')
|
||||
expect(output).toContain('loop-auth-fix')
|
||||
})
|
||||
})
|
||||
@@ -9,7 +9,7 @@ interface LoopState {
|
||||
worktreeName: string
|
||||
worktreeBranch: string
|
||||
worktreeDir: string
|
||||
inPlace: boolean
|
||||
worktree: boolean
|
||||
iteration: number
|
||||
maxIterations: number
|
||||
phase: 'coding' | 'auditing'
|
||||
@@ -274,10 +274,10 @@ describe('CLI Status - partial matching', () => {
|
||||
|
||||
test('partial name matches single active loop', async () => {
|
||||
const db = createTestKvDb(tempDir)
|
||||
insertLoopState(db, 'test-project', 'ralph-feat-auth', {
|
||||
insertLoopState(db, 'test-project', 'loop-feat-auth', {
|
||||
startedAt: new Date(Date.now() - 3600000).toISOString(),
|
||||
})
|
||||
insertLoopState(db, 'test-project', 'ralph-fix-bug', {
|
||||
insertLoopState(db, 'test-project', 'loop-fix-bug', {
|
||||
startedAt: new Date(Date.now() - 1800000).toISOString(),
|
||||
})
|
||||
db.close()
|
||||
@@ -294,17 +294,17 @@ describe('CLI Status - partial matching', () => {
|
||||
})
|
||||
|
||||
const output = outputLines.join('\n')
|
||||
expect(output).toContain('Memory Loop: ralph-feat-auth')
|
||||
expect(output).toContain('Memory Loop: loop-feat-auth')
|
||||
})
|
||||
|
||||
test('partial name matches single recent loop', async () => {
|
||||
const db = createTestKvDb(tempDir)
|
||||
insertLoopState(db, 'test-project', 'ralph-completed-auth', {
|
||||
insertLoopState(db, 'test-project', 'loop-completed-auth', {
|
||||
active: false,
|
||||
completedAt: new Date().toISOString(),
|
||||
terminationReason: 'success',
|
||||
})
|
||||
insertLoopState(db, 'test-project', 'ralph-fix-bug', {
|
||||
insertLoopState(db, 'test-project', 'loop-fix-bug', {
|
||||
active: true,
|
||||
startedAt: new Date(Date.now() - 1800000).toISOString(),
|
||||
})
|
||||
@@ -322,13 +322,13 @@ describe('CLI Status - partial matching', () => {
|
||||
})
|
||||
|
||||
const output = outputLines.join('\n')
|
||||
expect(output).toContain('Memory Loop (Completed): ralph-completed-auth')
|
||||
expect(output).toContain('Memory Loop (Completed): loop-completed-auth')
|
||||
})
|
||||
|
||||
test('partial name matches multiple loops lists ambiguous', async () => {
|
||||
const db = createTestKvDb(tempDir)
|
||||
insertLoopState(db, 'test-project', 'ralph-feat-auth', {})
|
||||
insertLoopState(db, 'test-project', 'ralph-auth-fix', {})
|
||||
insertLoopState(db, 'test-project', 'loop-feat-auth', {})
|
||||
insertLoopState(db, 'test-project', 'loop-auth-fix', {})
|
||||
db.close()
|
||||
|
||||
const outputLines: string[] = []
|
||||
@@ -357,17 +357,17 @@ describe('CLI Status - partial matching', () => {
|
||||
expect(exited).toBe(true)
|
||||
const output = outputLines.join('\n')
|
||||
expect(output).toContain("Multiple loops match 'auth':")
|
||||
expect(output).toContain('ralph-feat-auth')
|
||||
expect(output).toContain('ralph-auth-fix')
|
||||
expect(output).toContain('loop-feat-auth')
|
||||
expect(output).toContain('loop-auth-fix')
|
||||
})
|
||||
|
||||
test('partial name matches via worktreeBranch field', async () => {
|
||||
const db = createTestKvDb(tempDir)
|
||||
insertLoopState(db, 'test-project', 'ralph-feat-auth', {
|
||||
insertLoopState(db, 'test-project', 'loop-feat-auth', {
|
||||
worktreeBranch: 'feat/auth',
|
||||
startedAt: new Date(Date.now() - 3600000).toISOString(),
|
||||
})
|
||||
insertLoopState(db, 'test-project', 'ralph-fix-bug', {
|
||||
insertLoopState(db, 'test-project', 'loop-fix-bug', {
|
||||
worktreeBranch: 'fix/bug',
|
||||
startedAt: new Date(Date.now() - 1800000).toISOString(),
|
||||
})
|
||||
@@ -385,13 +385,13 @@ describe('CLI Status - partial matching', () => {
|
||||
})
|
||||
|
||||
const output = outputLines.join('\n')
|
||||
expect(output).toContain('Memory Loop: ralph-feat-auth')
|
||||
expect(output).toContain('Memory Loop: loop-feat-auth')
|
||||
expect(output).toContain('Branch: feat/auth')
|
||||
})
|
||||
|
||||
test('case-insensitive matching works', async () => {
|
||||
const db = createTestKvDb(tempDir)
|
||||
insertLoopState(db, 'test-project', 'ralph-feat-auth', {
|
||||
insertLoopState(db, 'test-project', 'loop-feat-auth', {
|
||||
startedAt: new Date(Date.now() - 3600000).toISOString(),
|
||||
})
|
||||
db.close()
|
||||
@@ -408,7 +408,7 @@ describe('CLI Status - partial matching', () => {
|
||||
})
|
||||
|
||||
const output = outputLines.join('\n')
|
||||
expect(output).toContain('Memory Loop: ralph-feat-auth')
|
||||
expect(output).toContain('Memory Loop: loop-feat-auth')
|
||||
})
|
||||
|
||||
test('exact match takes priority over partial', async () => {
|
||||
@@ -416,7 +416,7 @@ describe('CLI Status - partial matching', () => {
|
||||
insertLoopState(db, 'test-project', 'auth', {
|
||||
startedAt: new Date(Date.now() - 3600000).toISOString(),
|
||||
})
|
||||
insertLoopState(db, 'test-project', 'ralph-auth', {
|
||||
insertLoopState(db, 'test-project', 'loop-auth', {
|
||||
startedAt: new Date(Date.now() - 1800000).toISOString(),
|
||||
})
|
||||
db.close()
|
||||
@@ -434,14 +434,14 @@ describe('CLI Status - partial matching', () => {
|
||||
|
||||
const output = outputLines.join('\n')
|
||||
expect(output).toContain('Memory Loop: auth')
|
||||
expect(output).not.toContain('Memory Loop: ralph-auth')
|
||||
expect(output).not.toContain('Memory Loop: loop-auth')
|
||||
})
|
||||
|
||||
test('--list-worktrees with filter returns filtered results', async () => {
|
||||
const db = createTestKvDb(tempDir)
|
||||
insertLoopState(db, 'test-project', 'ralph-feat-auth', { worktreeBranch: 'feat/auth' })
|
||||
insertLoopState(db, 'test-project', 'ralph-fix-bug', { worktreeBranch: 'fix/bug' })
|
||||
insertLoopState(db, 'test-project', 'ralph-update-deps', {})
|
||||
insertLoopState(db, 'test-project', 'loop-feat-auth', { worktreeBranch: 'feat/auth' })
|
||||
insertLoopState(db, 'test-project', 'loop-fix-bug', { worktreeBranch: 'fix/bug' })
|
||||
insertLoopState(db, 'test-project', 'loop-update-deps', {})
|
||||
db.close()
|
||||
|
||||
const outputLines: string[] = []
|
||||
@@ -457,15 +457,15 @@ describe('CLI Status - partial matching', () => {
|
||||
})
|
||||
|
||||
const output = outputLines.join('\n')
|
||||
expect(output).toContain('ralph-feat-auth')
|
||||
expect(output).not.toContain('ralph-fix-bug')
|
||||
expect(output).not.toContain('ralph-update-deps')
|
||||
expect(output).toContain('loop-feat-auth')
|
||||
expect(output).not.toContain('loop-fix-bug')
|
||||
expect(output).not.toContain('loop-update-deps')
|
||||
})
|
||||
|
||||
test('--list-worktrees without filter returns all', async () => {
|
||||
const db = createTestKvDb(tempDir)
|
||||
insertLoopState(db, 'test-project', 'ralph-feat-auth', {})
|
||||
insertLoopState(db, 'test-project', 'ralph-fix-bug', {})
|
||||
insertLoopState(db, 'test-project', 'loop-feat-auth', {})
|
||||
insertLoopState(db, 'test-project', 'loop-fix-bug', {})
|
||||
db.close()
|
||||
|
||||
const outputLines: string[] = []
|
||||
@@ -480,7 +480,7 @@ describe('CLI Status - partial matching', () => {
|
||||
})
|
||||
|
||||
const output = outputLines.join('\n')
|
||||
expect(output).toContain('ralph-feat-auth')
|
||||
expect(output).toContain('ralph-fix-bug')
|
||||
expect(output).toContain('loop-feat-auth')
|
||||
expect(output).toContain('loop-fix-bug')
|
||||
})
|
||||
})
|
||||
@@ -1,6 +1,6 @@
|
||||
import { describe, test, expect } from 'bun:test'
|
||||
import { formatTokens, formatSessionOutput, formatAuditResult } from '../src/utils/loop-format'
|
||||
import type { LoopSessionOutput } from '../src/services/ralph'
|
||||
import type { LoopSessionOutput } from '../src/services/loop'
|
||||
|
||||
describe('formatTokens', () => {
|
||||
test('numbers less than 1000 returned as string', () => {
|
||||
|
||||
@@ -4,7 +4,7 @@ import { createKvQuery } from '../src/storage/kv-queries'
|
||||
import { createKvService } from '../src/services/kv'
|
||||
import { createLoopService } from '../src/services/loop'
|
||||
|
||||
const TEST_DIR = '/tmp/opencode-manager-ralph-test-' + Date.now()
|
||||
const TEST_DIR = '/tmp/opencode-manager-loop-test-' + Date.now()
|
||||
|
||||
function createTestDb(): Database {
|
||||
const db = new Database(`${TEST_DIR}-${Math.random().toString(36).slice(2)}.db`)
|
||||
@@ -53,7 +53,7 @@ describe('LoopService', () => {
|
||||
sessionId: 'session-123',
|
||||
worktreeName: 'test-worktree',
|
||||
worktreeDir: '/path/to/worktree',
|
||||
worktreeBranch: 'opencode/ralph-test',
|
||||
worktreeBranch: 'opencode/loop-test',
|
||||
workspaceId: 'wrk-test-worktree',
|
||||
iteration: 1,
|
||||
maxIterations: 5,
|
||||
@@ -85,7 +85,7 @@ describe('LoopService', () => {
|
||||
sessionId: 'session-456',
|
||||
worktreeName: 'test-worktree',
|
||||
worktreeDir: '/path/to/worktree',
|
||||
worktreeBranch: 'opencode/ralph-test',
|
||||
worktreeBranch: 'opencode/loop-test',
|
||||
workspaceId: 'wrk-test-worktree',
|
||||
iteration: 1,
|
||||
maxIterations: 0,
|
||||
@@ -145,7 +145,7 @@ describe('LoopService', () => {
|
||||
sessionId: 'session-789',
|
||||
worktreeName: 'test-worktree',
|
||||
worktreeDir: '/path/to/worktree',
|
||||
worktreeBranch: 'opencode/ralph-test',
|
||||
worktreeBranch: 'opencode/loop-test',
|
||||
workspaceId: 'wrk-test-worktree',
|
||||
iteration: 3,
|
||||
maxIterations: 0,
|
||||
@@ -169,7 +169,7 @@ describe('LoopService', () => {
|
||||
sessionId: 'session-789',
|
||||
worktreeName: 'test-worktree',
|
||||
worktreeDir: '/path/to/worktree',
|
||||
worktreeBranch: 'opencode/ralph-test',
|
||||
worktreeBranch: 'opencode/loop-test',
|
||||
workspaceId: 'wrk-test-worktree',
|
||||
iteration: 1,
|
||||
maxIterations: 0,
|
||||
@@ -192,7 +192,7 @@ describe('LoopService', () => {
|
||||
sessionId: 'session-789',
|
||||
worktreeName: 'test-worktree',
|
||||
worktreeDir: '/path/to/worktree',
|
||||
worktreeBranch: 'opencode/ralph-test',
|
||||
worktreeBranch: 'opencode/loop-test',
|
||||
workspaceId: 'wrk-test-worktree',
|
||||
iteration: 2,
|
||||
maxIterations: 10,
|
||||
@@ -215,7 +215,7 @@ describe('LoopService', () => {
|
||||
sessionId: 'session-789',
|
||||
worktreeName: 'test-worktree',
|
||||
worktreeDir: '/path/to/worktree',
|
||||
worktreeBranch: 'opencode/ralph-test',
|
||||
worktreeBranch: 'opencode/loop-test',
|
||||
workspaceId: 'wrk-test-worktree',
|
||||
iteration: 1,
|
||||
maxIterations: 0,
|
||||
@@ -238,7 +238,7 @@ describe('LoopService', () => {
|
||||
sessionId: 'session-persist',
|
||||
worktreeName: 'test-worktree',
|
||||
worktreeDir: '/path/to/worktree',
|
||||
worktreeBranch: 'opencode/ralph-test',
|
||||
worktreeBranch: 'opencode/loop-test',
|
||||
workspaceId: 'wrk-test-worktree',
|
||||
iteration: 5,
|
||||
maxIterations: 10,
|
||||
@@ -266,7 +266,7 @@ describe('LoopService', () => {
|
||||
sessionId: 'session-audit',
|
||||
worktreeName: 'test-worktree',
|
||||
worktreeDir: '/path/to/worktree',
|
||||
worktreeBranch: 'opencode/ralph-test',
|
||||
worktreeBranch: 'opencode/loop-test',
|
||||
workspaceId: 'wrk-test-worktree',
|
||||
iteration: 1,
|
||||
maxIterations: 0,
|
||||
@@ -292,7 +292,7 @@ describe('LoopService', () => {
|
||||
sessionId: 'session-audit',
|
||||
worktreeName: 'test-worktree',
|
||||
worktreeDir: '/path/to/worktree',
|
||||
worktreeBranch: 'opencode/ralph-test',
|
||||
worktreeBranch: 'opencode/loop-test',
|
||||
workspaceId: 'wrk-test-worktree',
|
||||
iteration: 2,
|
||||
maxIterations: 0,
|
||||
@@ -320,7 +320,7 @@ describe('LoopService', () => {
|
||||
sessionId: 'session-audit',
|
||||
worktreeName: 'test-worktree',
|
||||
worktreeDir: '/path/to/worktree',
|
||||
worktreeBranch: 'opencode/ralph-test',
|
||||
worktreeBranch: 'opencode/loop-test',
|
||||
workspaceId: 'wrk-test-worktree',
|
||||
iteration: 2,
|
||||
maxIterations: 0,
|
||||
@@ -345,7 +345,7 @@ describe('LoopService', () => {
|
||||
sessionId: 'session-audit',
|
||||
worktreeName: 'test-worktree',
|
||||
worktreeDir: '/path/to/worktree',
|
||||
worktreeBranch: 'opencode/ralph-test',
|
||||
worktreeBranch: 'opencode/loop-test',
|
||||
workspaceId: 'wrk-test-worktree',
|
||||
iteration: 2,
|
||||
maxIterations: 0,
|
||||
@@ -370,7 +370,7 @@ describe('LoopService', () => {
|
||||
sessionId: 'active-1',
|
||||
worktreeName: 'worktree-1',
|
||||
worktreeDir: '/path/to/worktree1',
|
||||
worktreeBranch: 'opencode/ralph-worktree-1',
|
||||
worktreeBranch: 'opencode/loop-worktree-1',
|
||||
workspaceId: 'wrk-worktree-1',
|
||||
iteration: 1,
|
||||
maxIterations: 0,
|
||||
@@ -388,8 +388,8 @@ describe('LoopService', () => {
|
||||
sessionId: 'active-2',
|
||||
worktreeName: 'worktree-2',
|
||||
worktreeDir: '/path/to/worktree2',
|
||||
worktreeBranch: 'opencode/ralph-worktree-2',
|
||||
workspaceId: 'ralph-worktree-2',
|
||||
worktreeBranch: 'opencode/loop-worktree-2',
|
||||
workspaceId: 'loop-worktree-2',
|
||||
iteration: 2,
|
||||
maxIterations: 0,
|
||||
completionPromise: null,
|
||||
@@ -406,8 +406,8 @@ describe('LoopService', () => {
|
||||
sessionId: 'inactive-1',
|
||||
worktreeName: 'worktree-3',
|
||||
worktreeDir: '/path/to/worktree3',
|
||||
worktreeBranch: 'opencode/ralph-worktree-3',
|
||||
workspaceId: 'ralph-worktree-3',
|
||||
worktreeBranch: 'opencode/loop-worktree-3',
|
||||
workspaceId: 'loop-worktree-3',
|
||||
iteration: 1,
|
||||
maxIterations: 0,
|
||||
completionPromise: null,
|
||||
@@ -436,7 +436,7 @@ describe('LoopService', () => {
|
||||
sessionId: 'session-1',
|
||||
worktreeName: 'unique-worktree-name',
|
||||
worktreeDir: '/path/to/worktree',
|
||||
worktreeBranch: 'opencode/ralph-unique-worktree-name',
|
||||
worktreeBranch: 'opencode/loop-unique-worktree-name',
|
||||
workspaceId: 'wrk-unique-worktree-name',
|
||||
iteration: 1,
|
||||
maxIterations: 0,
|
||||
@@ -464,7 +464,7 @@ describe('LoopService', () => {
|
||||
sessionId: 'session-err',
|
||||
worktreeName: 'test-worktree',
|
||||
worktreeDir: '/path/to/worktree',
|
||||
worktreeBranch: 'opencode/ralph-test',
|
||||
worktreeBranch: 'opencode/loop-test',
|
||||
workspaceId: 'wrk-test-worktree',
|
||||
iteration: 1,
|
||||
maxIterations: 5,
|
||||
@@ -489,7 +489,7 @@ describe('LoopService', () => {
|
||||
sessionId: 'session-default',
|
||||
worktreeName: 'test-worktree',
|
||||
worktreeDir: '/path/to/worktree',
|
||||
worktreeBranch: 'opencode/ralph-test',
|
||||
worktreeBranch: 'opencode/loop-test',
|
||||
workspaceId: 'wrk-test-worktree',
|
||||
iteration: 1,
|
||||
maxIterations: 0,
|
||||
@@ -654,7 +654,7 @@ describe('Stall Detection', () => {
|
||||
} as any
|
||||
|
||||
const { createLoopEventHandler } = require('../src/hooks/loop')
|
||||
const mockGetConfig = () => ({ ralph: {}, executionModel: undefined, auditorModel: undefined })
|
||||
const mockGetConfig = () => ({ loop: {}, executionModel: undefined, auditorModel: undefined })
|
||||
const handler = createLoopEventHandler(loopService, mockClient, mockV2Client, createMockLogger(), mockGetConfig)
|
||||
|
||||
const info = handler.getStallInfo('test')
|
||||
@@ -691,7 +691,7 @@ describe('Stall Detection', () => {
|
||||
} as any
|
||||
|
||||
const { createLoopEventHandler } = require('../src/hooks/loop')
|
||||
const mockGetConfig = () => ({ ralph: {}, executionModel: undefined, auditorModel: undefined })
|
||||
const mockGetConfig = () => ({ loop: {}, executionModel: undefined, auditorModel: undefined })
|
||||
const handler = createLoopEventHandler(loopService, mockClient, mockV2Client, createMockLogger(), mockGetConfig)
|
||||
|
||||
const sessionId = 'test-session'
|
||||
@@ -753,7 +753,7 @@ describe('Stall Detection', () => {
|
||||
} as any
|
||||
|
||||
const { createLoopEventHandler } = require('../src/hooks/loop')
|
||||
const mockGetConfig = () => ({ ralph: {}, executionModel: undefined, auditorModel: undefined })
|
||||
const mockGetConfig = () => ({ loop: {}, executionModel: undefined, auditorModel: undefined })
|
||||
const handler = createLoopEventHandler(loopService, mockClient, mockV2Client, createMockLogger(), mockGetConfig)
|
||||
|
||||
const parentId = 'parent-session'
|
||||
@@ -828,7 +828,7 @@ describe('Stall Detection', () => {
|
||||
} as any
|
||||
|
||||
const { createLoopEventHandler } = require('../src/hooks/loop')
|
||||
const mockGetConfig = () => ({ ralph: {}, executionModel: undefined, auditorModel: undefined })
|
||||
const mockGetConfig = () => ({ loop: {}, executionModel: undefined, auditorModel: undefined })
|
||||
const handler = createLoopEventHandler(loopService, mockClient, mockV2Client, createMockLogger(), mockGetConfig)
|
||||
|
||||
const sessionId = 'test-session'
|
||||
@@ -900,7 +900,7 @@ describe('Stall Detection', () => {
|
||||
} as any
|
||||
|
||||
const { createLoopEventHandler } = require('../src/hooks/loop')
|
||||
const mockGetConfig = () => ({ ralph: {}, executionModel: undefined, auditorModel: undefined })
|
||||
const mockGetConfig = () => ({ loop: {}, executionModel: undefined, auditorModel: undefined })
|
||||
const handler = createLoopEventHandler(loopService, mockClient, mockV2Client, createMockLogger(), mockGetConfig)
|
||||
|
||||
const sessionId = 'test-session'
|
||||
@@ -986,7 +986,7 @@ describe('session rotation', () => {
|
||||
},
|
||||
} as any
|
||||
|
||||
const mockGetConfig = () => ({ ralph: {}, executionModel: undefined, auditorModel: undefined })
|
||||
const mockGetConfig = () => ({ loop: {}, executionModel: undefined, auditorModel: undefined })
|
||||
const handler = createLoopEventHandler(loopService, mockClient, mockV2Client, createMockLogger(), mockGetConfig)
|
||||
|
||||
const state = {
|
||||
@@ -1071,7 +1071,7 @@ describe('session rotation', () => {
|
||||
},
|
||||
} as any
|
||||
|
||||
const mockGetConfig = () => ({ ralph: {}, executionModel: undefined, auditorModel: undefined })
|
||||
const mockGetConfig = () => ({ loop: {}, executionModel: undefined, auditorModel: undefined })
|
||||
const handler = createLoopEventHandler(loopService, mockClient, mockV2Client, createMockLogger(), mockGetConfig)
|
||||
|
||||
const state = {
|
||||
@@ -1138,7 +1138,7 @@ describe('session rotation', () => {
|
||||
},
|
||||
} as any
|
||||
|
||||
const mockGetConfig = () => ({ ralph: {}, executionModel: undefined, auditorModel: undefined })
|
||||
const mockGetConfig = () => ({ loop: {}, executionModel: undefined, auditorModel: undefined })
|
||||
const handler = createLoopEventHandler(loopService, mockClient, mockV2Client, createMockLogger(), mockGetConfig)
|
||||
|
||||
const state = {
|
||||
@@ -1231,7 +1231,7 @@ describe('Assistant Error Detection', () => {
|
||||
},
|
||||
} as any
|
||||
|
||||
const mockGetConfig = () => ({ ralph: {}, executionModel: undefined, auditorModel: undefined })
|
||||
const mockGetConfig = () => ({ loop: {}, executionModel: undefined, auditorModel: undefined })
|
||||
const handler = createLoopEventHandler(loopService, mockClient, mockV2Client, createMockLogger(), mockGetConfig)
|
||||
|
||||
const state = {
|
||||
@@ -1306,7 +1306,7 @@ describe('Assistant Error Detection', () => {
|
||||
},
|
||||
} as any
|
||||
|
||||
const mockGetConfig = () => ({ ralph: {}, executionModel: undefined, auditorModel: undefined })
|
||||
const mockGetConfig = () => ({ loop: {}, executionModel: undefined, auditorModel: undefined })
|
||||
const handler = createLoopEventHandler(loopService, mockClient, mockV2Client, createMockLogger(), mockGetConfig)
|
||||
|
||||
const state = {
|
||||
@@ -1371,7 +1371,7 @@ describe('Assistant Error Detection', () => {
|
||||
},
|
||||
} as any
|
||||
|
||||
const mockGetConfig = () => ({ ralph: {}, executionModel: undefined, auditorModel: undefined })
|
||||
const mockGetConfig = () => ({ loop: {}, executionModel: undefined, auditorModel: undefined })
|
||||
const handler = createLoopEventHandler(loopService, mockClient, mockV2Client, createMockLogger(), mockGetConfig)
|
||||
|
||||
const state = {
|
||||
@@ -1441,7 +1441,7 @@ describe('Assistant Error Detection', () => {
|
||||
},
|
||||
} as any
|
||||
|
||||
const mockGetConfig = () => ({ ralph: {}, executionModel: undefined, auditorModel: undefined })
|
||||
const mockGetConfig = () => ({ loop: {}, executionModel: undefined, auditorModel: undefined })
|
||||
const handler = createLoopEventHandler(loopService, mockClient, mockV2Client, createMockLogger(), mockGetConfig)
|
||||
|
||||
const state = {
|
||||
@@ -1516,7 +1516,7 @@ describe('Assistant Error Detection', () => {
|
||||
} as any
|
||||
|
||||
const mockGetConfig = () => ({
|
||||
ralph: { model: 'custom/model' },
|
||||
loop: { model: 'custom/model' },
|
||||
executionModel: 'execution/model',
|
||||
auditorModel: undefined,
|
||||
})
|
||||
@@ -1592,7 +1592,7 @@ describe('Assistant Error Detection', () => {
|
||||
},
|
||||
} as any
|
||||
|
||||
const mockGetConfig = () => ({ ralph: {}, executionModel: undefined, auditorModel: undefined })
|
||||
const mockGetConfig = () => ({ loop: {}, executionModel: undefined, auditorModel: undefined })
|
||||
const handler = createLoopEventHandler(loopService, mockClient, mockV2Client, createMockLogger(), mockGetConfig)
|
||||
|
||||
const state = {
|
||||
|
||||
@@ -10,12 +10,12 @@ interface TestItem {
|
||||
describe('findPartialMatch', () => {
|
||||
test('exact match returns single result', () => {
|
||||
const items: TestItem[] = [
|
||||
{ worktreeName: 'ralph-feat-auth', value: 'a' },
|
||||
{ worktreeName: 'ralph-fix-bug', value: 'b' },
|
||||
{ worktreeName: 'ralph-update-deps', value: 'c' },
|
||||
{ worktreeName: 'loop-feat-auth', value: 'a' },
|
||||
{ worktreeName: 'loop-fix-bug', value: 'b' },
|
||||
{ worktreeName: 'loop-update-deps', value: 'c' },
|
||||
]
|
||||
|
||||
const result = findPartialMatch('ralph-feat-auth', items, (i) => [i.worktreeName])
|
||||
const result = findPartialMatch('loop-feat-auth', items, (i) => [i.worktreeName])
|
||||
|
||||
expect(result.match).toBe(items[0])
|
||||
expect(result.candidates).toEqual([])
|
||||
@@ -23,9 +23,9 @@ describe('findPartialMatch', () => {
|
||||
|
||||
test('substring match returns single result', () => {
|
||||
const items: TestItem[] = [
|
||||
{ worktreeName: 'ralph-feat-auth', value: 'a' },
|
||||
{ worktreeName: 'ralph-fix-bug', value: 'b' },
|
||||
{ worktreeName: 'ralph-update-deps', value: 'c' },
|
||||
{ worktreeName: 'loop-feat-auth', value: 'a' },
|
||||
{ worktreeName: 'loop-fix-bug', value: 'b' },
|
||||
{ worktreeName: 'loop-update-deps', value: 'c' },
|
||||
]
|
||||
|
||||
const result = findPartialMatch('auth', items, (i) => [i.worktreeName])
|
||||
@@ -36,8 +36,8 @@ describe('findPartialMatch', () => {
|
||||
|
||||
test('case-insensitive substring match', () => {
|
||||
const items: TestItem[] = [
|
||||
{ worktreeName: 'ralph-feat-auth', value: 'a' },
|
||||
{ worktreeName: 'ralph-fix-bug', value: 'b' },
|
||||
{ worktreeName: 'loop-feat-auth', value: 'a' },
|
||||
{ worktreeName: 'loop-fix-bug', value: 'b' },
|
||||
]
|
||||
|
||||
const result = findPartialMatch('AUTH', items, (i) => [i.worktreeName])
|
||||
@@ -48,9 +48,9 @@ describe('findPartialMatch', () => {
|
||||
|
||||
test('multiple substring matches returns candidates', () => {
|
||||
const items: TestItem[] = [
|
||||
{ worktreeName: 'ralph-feat-auth', value: 'a' },
|
||||
{ worktreeName: 'ralph-auth-fix', value: 'b' },
|
||||
{ worktreeName: 'ralph-update-deps', value: 'c' },
|
||||
{ worktreeName: 'loop-feat-auth', value: 'a' },
|
||||
{ worktreeName: 'loop-auth-fix', value: 'b' },
|
||||
{ worktreeName: 'loop-update-deps', value: 'c' },
|
||||
]
|
||||
|
||||
const result = findPartialMatch('auth', items, (i) => [i.worktreeName])
|
||||
@@ -61,8 +61,8 @@ describe('findPartialMatch', () => {
|
||||
|
||||
test('no matches returns null and empty candidates', () => {
|
||||
const items: TestItem[] = [
|
||||
{ worktreeName: 'ralph-feat-auth', value: 'a' },
|
||||
{ worktreeName: 'ralph-fix-bug', value: 'b' },
|
||||
{ worktreeName: 'loop-feat-auth', value: 'a' },
|
||||
{ worktreeName: 'loop-fix-bug', value: 'b' },
|
||||
]
|
||||
|
||||
const result = findPartialMatch('nonexistent', items, (i) => [i.worktreeName])
|
||||
@@ -74,7 +74,7 @@ describe('findPartialMatch', () => {
|
||||
test('exact match takes priority over multiple substring matches', () => {
|
||||
const items: TestItem[] = [
|
||||
{ worktreeName: 'auth', value: 'a' },
|
||||
{ worktreeName: 'ralph-auth', value: 'b' },
|
||||
{ worktreeName: 'loop-auth', value: 'b' },
|
||||
{ worktreeName: 'auth-fix', value: 'c' },
|
||||
]
|
||||
|
||||
@@ -86,8 +86,8 @@ describe('findPartialMatch', () => {
|
||||
|
||||
test('matches against worktreeBranch field', () => {
|
||||
const items: TestItem[] = [
|
||||
{ worktreeName: 'ralph-feat-auth', worktreeBranch: 'feat/auth', value: 'a' },
|
||||
{ worktreeName: 'ralph-fix-bug', worktreeBranch: 'fix/bug', value: 'b' },
|
||||
{ worktreeName: 'loop-feat-auth', worktreeBranch: 'feat/auth', value: 'a' },
|
||||
{ worktreeName: 'loop-fix-bug', worktreeBranch: 'fix/bug', value: 'b' },
|
||||
]
|
||||
|
||||
const result = findPartialMatch('feat/auth', items, (i) => [i.worktreeName, i.worktreeBranch])
|
||||
@@ -98,8 +98,8 @@ describe('findPartialMatch', () => {
|
||||
|
||||
test('matches against worktreeBranch with partial input', () => {
|
||||
const items: TestItem[] = [
|
||||
{ worktreeName: 'ralph-feat-auth', worktreeBranch: 'feat/auth', value: 'a' },
|
||||
{ worktreeName: 'ralph-fix-bug', worktreeBranch: 'fix/bug', value: 'b' },
|
||||
{ worktreeName: 'loop-feat-auth', worktreeBranch: 'feat/auth', value: 'a' },
|
||||
{ worktreeName: 'loop-fix-bug', worktreeBranch: 'fix/bug', value: 'b' },
|
||||
]
|
||||
|
||||
const result = findPartialMatch('feat', items, (i) => [i.worktreeName, i.worktreeBranch])
|
||||
@@ -112,9 +112,9 @@ describe('findPartialMatch', () => {
|
||||
describe('filterByPartial', () => {
|
||||
test('with filter returns filtered items', () => {
|
||||
const items: TestItem[] = [
|
||||
{ worktreeName: 'ralph-feat-auth', value: 'a' },
|
||||
{ worktreeName: 'ralph-fix-bug', value: 'b' },
|
||||
{ worktreeName: 'ralph-update-deps', value: 'c' },
|
||||
{ worktreeName: 'loop-feat-auth', value: 'a' },
|
||||
{ worktreeName: 'loop-fix-bug', value: 'b' },
|
||||
{ worktreeName: 'loop-update-deps', value: 'c' },
|
||||
]
|
||||
|
||||
const result = filterByPartial('auth', items, (i) => [i.worktreeName])
|
||||
@@ -124,8 +124,8 @@ describe('filterByPartial', () => {
|
||||
|
||||
test('without filter returns all items', () => {
|
||||
const items: TestItem[] = [
|
||||
{ worktreeName: 'ralph-feat-auth', value: 'a' },
|
||||
{ worktreeName: 'ralph-fix-bug', value: 'b' },
|
||||
{ worktreeName: 'loop-feat-auth', value: 'a' },
|
||||
{ worktreeName: 'loop-fix-bug', value: 'b' },
|
||||
]
|
||||
|
||||
const result = filterByPartial(undefined, items, (i) => [i.worktreeName])
|
||||
@@ -135,8 +135,8 @@ describe('filterByPartial', () => {
|
||||
|
||||
test('empty filter returns all items', () => {
|
||||
const items: TestItem[] = [
|
||||
{ worktreeName: 'ralph-feat-auth', value: 'a' },
|
||||
{ worktreeName: 'ralph-fix-bug', value: 'b' },
|
||||
{ worktreeName: 'loop-feat-auth', value: 'a' },
|
||||
{ worktreeName: 'loop-fix-bug', value: 'b' },
|
||||
]
|
||||
|
||||
const result = filterByPartial('', items, (i) => [i.worktreeName])
|
||||
@@ -146,8 +146,8 @@ describe('filterByPartial', () => {
|
||||
|
||||
test('case-insensitive filtering', () => {
|
||||
const items: TestItem[] = [
|
||||
{ worktreeName: 'ralph-feat-auth', value: 'a' },
|
||||
{ worktreeName: 'ralph-fix-bug', value: 'b' },
|
||||
{ worktreeName: 'loop-feat-auth', value: 'a' },
|
||||
{ worktreeName: 'loop-fix-bug', value: 'b' },
|
||||
]
|
||||
|
||||
const result = filterByPartial('AUTH', items, (i) => [i.worktreeName])
|
||||
@@ -157,8 +157,8 @@ describe('filterByPartial', () => {
|
||||
|
||||
test('filters by worktreeBranch field', () => {
|
||||
const items: TestItem[] = [
|
||||
{ worktreeName: 'ralph-feat-auth', worktreeBranch: 'feat/auth', value: 'a' },
|
||||
{ worktreeName: 'ralph-fix-bug', worktreeBranch: 'fix/bug', value: 'b' },
|
||||
{ worktreeName: 'loop-feat-auth', worktreeBranch: 'feat/auth', value: 'a' },
|
||||
{ worktreeName: 'loop-fix-bug', worktreeBranch: 'fix/bug', value: 'b' },
|
||||
]
|
||||
|
||||
const result = filterByPartial('feat', items, (i) => [i.worktreeName, i.worktreeBranch])
|
||||
|
||||
@@ -33,7 +33,7 @@ function createMockLogger(): Logger {
|
||||
|
||||
describe('Plan Approval Tool Interception', () => {
|
||||
let db: Database
|
||||
let ralphService: ReturnType<typeof createLoopService>
|
||||
let loopService: ReturnType<typeof createLoopService>
|
||||
const projectId = 'test-project'
|
||||
const sessionID = 'test-session-123'
|
||||
|
||||
@@ -75,7 +75,7 @@ Do NOT output text without also making this tool call.
|
||||
beforeEach(() => {
|
||||
db = createTestDb()
|
||||
const kvService = createKvService(db)
|
||||
ralphService = createLoopService(kvService, projectId, createMockLogger())
|
||||
loopService = createLoopService(kvService, projectId, createMockLogger())
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
@@ -94,7 +94,7 @@ Do NOT output text without also making this tool call.
|
||||
sessionId: sessionID,
|
||||
worktreeName: 'test-worktree',
|
||||
worktreeDir: '/test/worktree',
|
||||
worktreeBranch: 'opencode/ralph-test',
|
||||
worktreeBranch: 'opencode/loop-test',
|
||||
workspaceId: 'wrk-test-worktree',
|
||||
iteration: 1,
|
||||
maxIterations: 5,
|
||||
@@ -105,9 +105,9 @@ Do NOT output text without also making this tool call.
|
||||
audit: false,
|
||||
errorCount: 0,
|
||||
auditCount: 0,
|
||||
inPlace: false,
|
||||
worktree: true,
|
||||
}
|
||||
ralphService.setState(sessionID, state)
|
||||
loopService.setState(sessionID, state)
|
||||
}
|
||||
|
||||
if (tool === 'question') {
|
||||
@@ -129,16 +129,16 @@ Do NOT output text without also making this tool call.
|
||||
|
||||
if (!sessionActive) return
|
||||
|
||||
const RALPH_BLOCKED_TOOLS: Record<string, string> = {
|
||||
const LOOP_BLOCKED_TOOLS: Record<string, string> = {
|
||||
question: 'The question tool is not available during a memory loop. Do not ask questions — continue working on the task autonomously.',
|
||||
'memory-plan-execute': 'The memory-plan-execute tool is not available during a memory loop. Focus on executing the current plan.',
|
||||
'memory-loop': 'The memory-loop tool is not available during a memory loop. Focus on executing the current plan.',
|
||||
}
|
||||
|
||||
if (!(tool in RALPH_BLOCKED_TOOLS)) return
|
||||
if (!(tool in LOOP_BLOCKED_TOOLS)) return
|
||||
|
||||
output.title = 'Tool blocked'
|
||||
output.output = RALPH_BLOCKED_TOOLS[tool]!
|
||||
output.output = LOOP_BLOCKED_TOOLS[tool]!
|
||||
}
|
||||
|
||||
test('Detects plan approval question and injects "New session" directive', () => {
|
||||
@@ -321,7 +321,7 @@ Do NOT output text without also making this tool call.
|
||||
expect(output.output).toBe(originalOutput)
|
||||
})
|
||||
|
||||
test('Ralph blocking still works for question tool when Ralph is active', () => {
|
||||
test('Loop blocking still works for question tool when loop is active', () => {
|
||||
const output = { title: '', output: 'test', metadata: {} }
|
||||
|
||||
simulateToolExecuteAfter('question', {}, output, true)
|
||||
@@ -330,7 +330,7 @@ Do NOT output text without also making this tool call.
|
||||
expect(output.output).toBe('test')
|
||||
})
|
||||
|
||||
test('Ralph blocking works for memory-plan-execute tool', () => {
|
||||
test('Loop blocking works for memory-plan-execute tool', () => {
|
||||
const output = { title: '', output: 'test', metadata: {} }
|
||||
|
||||
simulateToolExecuteAfter('memory-plan-execute', {}, output, true)
|
||||
@@ -339,7 +339,7 @@ Do NOT output text without also making this tool call.
|
||||
expect(output.output).toContain('memory-plan-execute tool is not available')
|
||||
})
|
||||
|
||||
test('Ralph blocking works for memory-loop tool', () => {
|
||||
test('Loop blocking works for memory-loop tool', () => {
|
||||
const output = { title: '', output: 'test', metadata: {} }
|
||||
|
||||
simulateToolExecuteAfter('memory-loop', {}, output, true)
|
||||
@@ -348,7 +348,7 @@ Do NOT output text without also making this tool call.
|
||||
expect(output.output).toContain('memory-loop tool is not available')
|
||||
})
|
||||
|
||||
test('Ralph blocking does not affect non-blocked tools', () => {
|
||||
test('Loop blocking does not affect non-blocked tools', () => {
|
||||
const output = { title: '', output: 'test', metadata: {} }
|
||||
|
||||
simulateToolExecuteAfter('memory-read', {}, output, true)
|
||||
@@ -357,7 +357,7 @@ Do NOT output text without also making this tool call.
|
||||
expect(output.output).toBe('test')
|
||||
})
|
||||
|
||||
test('Ralph blocking only applies when Ralph is active', () => {
|
||||
test('Loop blocking only applies when loop is active', () => {
|
||||
const output = { title: '', output: 'test', metadata: {} }
|
||||
|
||||
simulateToolExecuteAfter('memory-plan-execute', {}, output, false)
|
||||
|
||||
@@ -47,14 +47,14 @@ describe('Tool Blocking Logic', () => {
|
||||
db.close()
|
||||
})
|
||||
|
||||
describe('Ralph state lookup', () => {
|
||||
test('getActiveState returns active state when Ralph loop is active', () => {
|
||||
describe('Loop state lookup', () => {
|
||||
test('getActiveState returns active state when loop is active', () => {
|
||||
const state = {
|
||||
active: true,
|
||||
sessionId: sessionID,
|
||||
worktreeName: 'test-worktree',
|
||||
worktreeDir: '/test/worktree',
|
||||
worktreeBranch: 'opencode/ralph-test',
|
||||
worktreeBranch: 'opencode/loop-test',
|
||||
workspaceId: 'wrk-test-worktree',
|
||||
iteration: 1,
|
||||
maxIterations: 5,
|
||||
@@ -65,7 +65,7 @@ describe('Tool Blocking Logic', () => {
|
||||
audit: false,
|
||||
errorCount: 0,
|
||||
auditCount: 0,
|
||||
inPlace: false,
|
||||
worktree: true,
|
||||
}
|
||||
loopService.setState(sessionID, state)
|
||||
|
||||
@@ -74,18 +74,18 @@ describe('Tool Blocking Logic', () => {
|
||||
expect(retrieved?.active).toBe(true)
|
||||
})
|
||||
|
||||
test('getActiveState returns null when no Ralph loop exists', () => {
|
||||
test('getActiveState returns null when no loop exists', () => {
|
||||
const retrieved = loopService.getActiveState('non-existent-session')
|
||||
expect(retrieved).toBeNull()
|
||||
})
|
||||
|
||||
test('getActiveState returns null when Ralph loop is inactive', () => {
|
||||
test('getActiveState returns null when loop is inactive', () => {
|
||||
const inactiveState = {
|
||||
active: false,
|
||||
sessionId: sessionID,
|
||||
worktreeName: 'test-worktree',
|
||||
worktreeDir: '/test/worktree',
|
||||
worktreeBranch: 'opencode/ralph-test',
|
||||
worktreeBranch: 'opencode/loop-test',
|
||||
workspaceId: 'wrk-test-worktree',
|
||||
iteration: 1,
|
||||
maxIterations: 5,
|
||||
@@ -96,7 +96,7 @@ describe('Tool Blocking Logic', () => {
|
||||
audit: false,
|
||||
errorCount: 0,
|
||||
auditCount: 0,
|
||||
inPlace: false,
|
||||
worktree: true,
|
||||
}
|
||||
loopService.setState(sessionID, inactiveState)
|
||||
|
||||
|
||||
Reference in new issue
Block a user