mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +01:00
Merge branch 'main' into feat/docker-self-upgrade
Resolve conflicts against the restart-coordinator rewrite and renumber the manager-upgrade-jobs migration from 16 to 19 to avoid colliding with main's 016-018 migrations. Includes review fixes: background the docker pull, add a staleness guard for stuck recreating jobs, move manager-upgrade types to @opencode-manager/shared, wire the active-session pre-check dialog into the Upgrade Manager button, and surface upgrade errors via FetchError-aware messaging.
This commit is contained in:
commit
9effe53bdc
125 files changed
+3899
-975
No files matched your search
@@ -0,0 +1,53 @@
|
||||
import { Database } from 'bun:sqlite'
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import { migrate, type Migration } from '../../src/db/migration-runner'
|
||||
import { logger } from '../../src/utils/logger'
|
||||
|
||||
function makeMigration(version: number, name: string, up: () => void): Migration {
|
||||
return { version, name, up, down: () => {} }
|
||||
}
|
||||
|
||||
describe('migrate - version/name mismatch guard', () => {
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks()
|
||||
})
|
||||
|
||||
it('warns and skips when an applied version was recorded under a different name', () => {
|
||||
const db = new Database(':memory:')
|
||||
db.run('CREATE TABLE schema_migrations (version INTEGER PRIMARY KEY, name TEXT NOT NULL, applied_at INTEGER NOT NULL)')
|
||||
db.run("INSERT INTO schema_migrations (version, name, applied_at) VALUES (15, 'repos-add-name', 0)")
|
||||
|
||||
const warnSpy = vi.spyOn(logger, 'warn').mockImplementation(() => {})
|
||||
const up = vi.fn()
|
||||
|
||||
migrate(db, [makeMigration(15, 'schedule-worktree-isolation', up)])
|
||||
|
||||
expect(up).not.toHaveBeenCalled()
|
||||
expect(warnSpy).toHaveBeenCalledWith(
|
||||
expect.stringContaining('Migration version 15 is recorded as "repos-add-name" but the code defines "schedule-worktree-isolation"'),
|
||||
)
|
||||
})
|
||||
|
||||
it('does not warn when recorded names match', () => {
|
||||
const db = new Database(':memory:')
|
||||
db.run('CREATE TABLE schema_migrations (version INTEGER PRIMARY KEY, name TEXT NOT NULL, applied_at INTEGER NOT NULL)')
|
||||
db.run("INSERT INTO schema_migrations (version, name, applied_at) VALUES (15, 'schedule-worktree-isolation', 0)")
|
||||
|
||||
const warnSpy = vi.spyOn(logger, 'warn').mockImplementation(() => {})
|
||||
|
||||
migrate(db, [makeMigration(15, 'schedule-worktree-isolation', vi.fn())])
|
||||
|
||||
expect(warnSpy).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('applies pending migrations and records them', () => {
|
||||
const db = new Database(':memory:')
|
||||
const up = vi.fn()
|
||||
|
||||
migrate(db, [makeMigration(1, 'base', up)])
|
||||
|
||||
expect(up).toHaveBeenCalledTimes(1)
|
||||
const row = db.prepare('SELECT version, name FROM schema_migrations WHERE version = 1').get() as { version: number; name: string }
|
||||
expect(row).toEqual({ version: 1, name: 'base' })
|
||||
})
|
||||
})
|
||||
@@ -1,6 +1,5 @@
|
||||
import { describe, it, expect, beforeEach, vi } from 'vitest'
|
||||
import * as db from '../../src/db/queries'
|
||||
import * as schema from '../../src/db/schema'
|
||||
|
||||
const mockDb = {
|
||||
prepare: vi.fn(),
|
||||
@@ -289,17 +288,4 @@ describe('Database Queries', () => {
|
||||
expect(mockDb.prepare).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
|
||||
describe('Database Schema', () => {
|
||||
it('should have schema module available', () => {
|
||||
expect(schema.initializeDatabase).toBeDefined()
|
||||
expect(typeof schema.initializeDatabase).toBe('function')
|
||||
})
|
||||
})
|
||||
|
||||
describe('Transaction Support', () => {
|
||||
it('should support transaction existence', () => {
|
||||
expect(typeof mockDb.transaction).toBe('function')
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,107 @@
|
||||
import { describe, expect, it, beforeEach } from 'vitest'
|
||||
import { Database } from 'bun:sqlite'
|
||||
import { migrate } from '../../src/db/migration-runner'
|
||||
import { allMigrations } from '../../src/db/migrations'
|
||||
import { createScheduleJob, getScheduleJobById, updateScheduleJob } from '../../src/db/schedules'
|
||||
import type { ScheduleJobPersistenceInput } from '../../src/services/schedule-config'
|
||||
|
||||
describe('schedule permission config persistence', () => {
|
||||
let db: Database
|
||||
|
||||
beforeEach(() => {
|
||||
db = new Database(':memory:')
|
||||
db.exec('PRAGMA foreign_keys = OFF')
|
||||
migrate(db, allMigrations)
|
||||
|
||||
const now = Date.now()
|
||||
db.exec(
|
||||
`INSERT INTO repos (id, repo_url, local_path, branch, default_branch, clone_status, cloned_at)
|
||||
VALUES (1, 'https://github.com/test/repo', 'repos/test', 'main', 'main', 'ready', ${now})`,
|
||||
)
|
||||
})
|
||||
|
||||
const baseInput = (overrides: Partial<ScheduleJobPersistenceInput> = {}): ScheduleJobPersistenceInput => ({
|
||||
name: 'Permission test job',
|
||||
description: null,
|
||||
enabled: true,
|
||||
scheduleMode: 'interval',
|
||||
intervalMinutes: 60,
|
||||
cronExpression: null,
|
||||
timezone: null,
|
||||
agentSlug: null,
|
||||
prompt: 'Run a permission test',
|
||||
model: null,
|
||||
skillMetadata: null,
|
||||
permissionConfig: null,
|
||||
branch: null,
|
||||
nextRunAt: Date.now() + 3600000,
|
||||
...overrides,
|
||||
})
|
||||
|
||||
it('round-trips permissionConfig when set on create', () => {
|
||||
const config = {
|
||||
allowExternalDirectory: true,
|
||||
bashDenyPatterns: ['rm -rf /'],
|
||||
}
|
||||
const created = createScheduleJob(db, 1, baseInput({ permissionConfig: config }))
|
||||
|
||||
expect(created.permissionConfig).toEqual(config)
|
||||
|
||||
const fetched = getScheduleJobById(db, 1, created.id)
|
||||
expect(fetched).not.toBeNull()
|
||||
expect(fetched!.permissionConfig).toEqual(config)
|
||||
})
|
||||
|
||||
it('returns null permissionConfig when not provided on create', () => {
|
||||
const created = createScheduleJob(db, 1, baseInput())
|
||||
|
||||
expect(created.permissionConfig).toBeNull()
|
||||
|
||||
const fetched = getScheduleJobById(db, 1, created.id)
|
||||
expect(fetched).not.toBeNull()
|
||||
expect(fetched!.permissionConfig).toBeNull()
|
||||
})
|
||||
|
||||
it('updates permissionConfig independently of other fields', () => {
|
||||
const created = createScheduleJob(db, 1, baseInput())
|
||||
expect(created.permissionConfig).toBeNull()
|
||||
|
||||
const config = {
|
||||
allowExternalDirectory: false,
|
||||
bashDenyPatterns: ['sudo rm -rf *'],
|
||||
}
|
||||
const updated = updateScheduleJob(db, 1, created.id, baseInput({ permissionConfig: config }))
|
||||
expect(updated).not.toBeNull()
|
||||
expect(updated!.permissionConfig).toEqual(config)
|
||||
|
||||
// Verify other fields are unchanged
|
||||
expect(updated!.name).toBe('Permission test job')
|
||||
expect(updated!.prompt).toBe('Run a permission test')
|
||||
})
|
||||
|
||||
it('clears permissionConfig when set to null on update', () => {
|
||||
const config = { allowExternalDirectory: true, bashDenyPatterns: [] }
|
||||
const created = createScheduleJob(db, 1, baseInput({ permissionConfig: config }))
|
||||
expect(created.permissionConfig).toEqual(config)
|
||||
|
||||
const updated = updateScheduleJob(db, 1, created.id, baseInput({ permissionConfig: null }))
|
||||
expect(updated).not.toBeNull()
|
||||
expect(updated!.permissionConfig).toBeNull()
|
||||
})
|
||||
|
||||
it('preserves permissionConfig when updating other fields', () => {
|
||||
const config = { allowExternalDirectory: false, bashDenyPatterns: ['rm -rf *'] }
|
||||
const created = createScheduleJob(db, 1, baseInput({ permissionConfig: config }))
|
||||
expect(created.permissionConfig).toEqual(config)
|
||||
|
||||
const updated = updateScheduleJob(db, 1, created.id, {
|
||||
...baseInput({ permissionConfig: config }),
|
||||
name: 'Updated name',
|
||||
prompt: 'Updated prompt',
|
||||
})
|
||||
expect(updated).not.toBeNull()
|
||||
expect(updated!.name).toBe('Updated name')
|
||||
expect(updated!.prompt).toBe('Updated prompt')
|
||||
expect(updated!.permissionConfig).toEqual(config)
|
||||
})
|
||||
})
|
||||
@@ -20,6 +20,7 @@ function makeJobRow(overrides: Record<string, unknown> = {}) {
|
||||
prompt: 'Generate a weekly summary.',
|
||||
model: 'openai/gpt-5-mini',
|
||||
skill_metadata: JSON.stringify({ skillSlugs: ['planning'], notes: 'Optional notes' }),
|
||||
permission_config: null,
|
||||
branch: null,
|
||||
created_at: Date.UTC(2026, 2, 8, 12, 0, 0),
|
||||
updated_at: Date.UTC(2026, 2, 9, 12, 0, 0),
|
||||
@@ -47,6 +48,7 @@ function makeRunRow(overrides: Record<string, unknown> = {}) {
|
||||
run_branch: null,
|
||||
commit_hash: null,
|
||||
worktree_path: null,
|
||||
workspace_id: null,
|
||||
...overrides,
|
||||
}
|
||||
}
|
||||
@@ -111,6 +113,7 @@ describe('schedule database queries', () => {
|
||||
prompt: 'Generate a weekly summary.',
|
||||
model: 'openai/gpt-5-mini',
|
||||
skillMetadata: { skillSlugs: ['planning'], notes: 'Optional notes' },
|
||||
permissionConfig: null,
|
||||
branch: null,
|
||||
nextRunAt: Date.UTC(2026, 2, 9, 13, 0, 0),
|
||||
})
|
||||
@@ -129,6 +132,7 @@ describe('schedule database queries', () => {
|
||||
'openai/gpt-5-mini',
|
||||
JSON.stringify({ skillSlugs: ['planning'], notes: 'Optional notes' }),
|
||||
null,
|
||||
null,
|
||||
expect.any(Number),
|
||||
expect.any(Number),
|
||||
null,
|
||||
@@ -165,6 +169,7 @@ describe('schedule database queries', () => {
|
||||
prompt: 'Run a new summary.',
|
||||
model: null,
|
||||
skillMetadata: null,
|
||||
permissionConfig: null,
|
||||
branch: null,
|
||||
nextRunAt: null,
|
||||
})
|
||||
@@ -182,6 +187,7 @@ describe('schedule database queries', () => {
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
expect.any(Number),
|
||||
null,
|
||||
42,
|
||||
@@ -300,6 +306,7 @@ describe('schedule database queries', () => {
|
||||
'/worktrees/feature-branch',
|
||||
'feature-x',
|
||||
null,
|
||||
null,
|
||||
42,
|
||||
7,
|
||||
5,
|
||||
@@ -602,8 +609,8 @@ describe('schedule database queries', () => {
|
||||
it('listScheduleRunArtifactsByJob maps run branch/worktree rows', () => {
|
||||
const stmt = {
|
||||
all: vi.fn().mockReturnValue([
|
||||
{ id: 3, status: 'completed', run_branch: 'schedule/7/run-3', worktree_path: null },
|
||||
{ id: 2, status: 'running', run_branch: 'schedule/7/run-2', worktree_path: '/wt/2' },
|
||||
{ id: 3, status: 'completed', run_branch: 'schedule/7/run-3', worktree_path: null, workspace_id: null },
|
||||
{ id: 2, status: 'running', run_branch: 'schedule/7/run-2', worktree_path: '/wt/2', workspace_id: null },
|
||||
]),
|
||||
}
|
||||
mockDb.prepare.mockReturnValue(stmt)
|
||||
@@ -612,8 +619,8 @@ describe('schedule database queries', () => {
|
||||
|
||||
expect(stmt.all).toHaveBeenCalledWith(42, 7)
|
||||
expect(artifacts).toEqual([
|
||||
{ id: 3, status: 'completed', runBranch: 'schedule/7/run-3', worktreePath: null },
|
||||
{ id: 2, status: 'running', runBranch: 'schedule/7/run-2', worktreePath: '/wt/2' },
|
||||
{ id: 3, status: 'completed', runBranch: 'schedule/7/run-3', worktreePath: null, workspaceId: null },
|
||||
{ id: 2, status: 'running', runBranch: 'schedule/7/run-2', worktreePath: '/wt/2', workspaceId: null },
|
||||
])
|
||||
})
|
||||
|
||||
|
||||
Reference in new issue
Block a user