Fix owner-scoped file watch reloads (#4682)
Co-authored-by: Orca <help@stably.ai>
This commit is contained in:
@@ -118,6 +118,7 @@ function mockLocalPathStats(entries: Record<string, [number, number]>) {
|
||||
|
||||
function createRuntimeFileCommands(options?: {
|
||||
path?: string
|
||||
openFile?: ReturnType<typeof vi.fn>
|
||||
openDiff?: ReturnType<typeof vi.fn>
|
||||
resolveRuntimeGitTarget?: ReturnType<typeof vi.fn>
|
||||
}) {
|
||||
@@ -134,7 +135,7 @@ function createRuntimeFileCommands(options?: {
|
||||
path
|
||||
})),
|
||||
resolveRuntimeGitTarget: options?.resolveRuntimeGitTarget ?? vi.fn(),
|
||||
openFile: vi.fn(),
|
||||
openFile: options?.openFile ?? vi.fn(),
|
||||
...(options?.openDiff ? { openDiff: options.openDiff } : {})
|
||||
} as never)
|
||||
return { commands, store }
|
||||
@@ -187,7 +188,33 @@ describe('RuntimeFileCommands', () => {
|
||||
|
||||
const result = await commands.openMobileDiff('id:wt-1', 'docs/readme.md', true)
|
||||
|
||||
expect(openDiff).toHaveBeenCalledWith('wt-1', '/repo/docs/readme.md', 'docs/readme.md', true)
|
||||
expect(openDiff).toHaveBeenCalledWith(
|
||||
'wt-1',
|
||||
'/repo/docs/readme.md',
|
||||
'docs/readme.md',
|
||||
true,
|
||||
'runtime-1'
|
||||
)
|
||||
expect(result).toEqual({
|
||||
worktree: 'wt-1',
|
||||
relativePath: 'docs/readme.md',
|
||||
kind: 'markdown',
|
||||
opened: true
|
||||
})
|
||||
})
|
||||
|
||||
it('opens text files through the renderer host with the runtime owner', async () => {
|
||||
const openFile = vi.fn()
|
||||
const { commands } = createRuntimeFileCommands({ openFile })
|
||||
|
||||
const result = await commands.openMobileFile('id:wt-1', 'docs/readme.md')
|
||||
|
||||
expect(openFile).toHaveBeenCalledWith(
|
||||
'wt-1',
|
||||
'/repo/docs/readme.md',
|
||||
'docs/readme.md',
|
||||
'runtime-1'
|
||||
)
|
||||
expect(result).toEqual({
|
||||
worktree: 'wt-1',
|
||||
relativePath: 'docs/readme.md',
|
||||
|
||||
@@ -120,8 +120,19 @@ export type RuntimeFileCommandHost = {
|
||||
resolveRuntimeGitTarget(
|
||||
selector: string
|
||||
): Promise<{ worktree: ResolvedRuntimeFileWorktree; connectionId?: string }>
|
||||
openFile(worktreeId: string, filePath: string, relativePath: string): void
|
||||
openDiff(worktreeId: string, filePath: string, relativePath: string, staged: boolean): void
|
||||
openFile(
|
||||
worktreeId: string,
|
||||
filePath: string,
|
||||
relativePath: string,
|
||||
runtimeEnvironmentId: string
|
||||
): void
|
||||
openDiff(
|
||||
worktreeId: string,
|
||||
filePath: string,
|
||||
relativePath: string,
|
||||
staged: boolean,
|
||||
runtimeEnvironmentId: string
|
||||
): void
|
||||
}
|
||||
|
||||
export class RuntimeFileCommands {
|
||||
@@ -173,7 +184,7 @@ export class RuntimeFileCommands {
|
||||
return { worktree: worktree.id, relativePath, kind, opened: false }
|
||||
}
|
||||
const filePath = joinWorktreeRelativePath(worktree.path, relativePath)
|
||||
this.host.openFile(worktree.id, filePath, relativePath)
|
||||
this.host.openFile(worktree.id, filePath, relativePath, this.host.getRuntimeId())
|
||||
return { worktree: worktree.id, relativePath, kind, opened: true }
|
||||
}
|
||||
|
||||
@@ -192,7 +203,7 @@ export class RuntimeFileCommands {
|
||||
? 'markdown'
|
||||
: 'text'
|
||||
const filePath = joinWorktreeRelativePath(worktree.path, relativePath)
|
||||
this.host.openDiff(worktree.id, filePath, relativePath, staged)
|
||||
this.host.openDiff(worktree.id, filePath, relativePath, staged, this.host.getRuntimeId())
|
||||
return { worktree: worktree.id, relativePath, kind, opened: true }
|
||||
}
|
||||
|
||||
|
||||
@@ -782,8 +782,19 @@ type RuntimeNotifier = {
|
||||
focusEditorTab?(tabId: string, worktreeId: string): void
|
||||
closeSessionTab?(tabId: string, worktreeId: string): void
|
||||
moveSessionTab?(worktreeId: string, move: RuntimeMobileSessionTabMove): void
|
||||
openFile?(worktreeId: string, filePath: string, relativePath: string): void
|
||||
openDiff?(worktreeId: string, filePath: string, relativePath: string, staged: boolean): void
|
||||
openFile?(
|
||||
worktreeId: string,
|
||||
filePath: string,
|
||||
relativePath: string,
|
||||
runtimeEnvironmentId: string
|
||||
): void
|
||||
openDiff?(
|
||||
worktreeId: string,
|
||||
filePath: string,
|
||||
relativePath: string,
|
||||
staged: boolean,
|
||||
runtimeEnvironmentId: string
|
||||
): void
|
||||
readMobileMarkdownTab?(worktreeId: string, tabId: string): Promise<RuntimeMarkdownReadTabResult>
|
||||
saveMobileMarkdownTab?(
|
||||
worktreeId: string,
|
||||
@@ -2697,17 +2708,17 @@ export class OrcaRuntimeService {
|
||||
requireStore: () => this.requireStore(),
|
||||
resolveWorktreeSelector: (selector) => this.resolveWorktreeSelector(selector),
|
||||
resolveRuntimeGitTarget: (selector) => this.resolveRuntimeGitTarget(selector),
|
||||
openFile: (worktreeId, filePath, relativePath) => {
|
||||
openFile: (worktreeId, filePath, relativePath, runtimeEnvironmentId) => {
|
||||
if (!this.notifier?.openFile) {
|
||||
throw new Error('renderer_unavailable')
|
||||
}
|
||||
this.notifier.openFile(worktreeId, filePath, relativePath)
|
||||
this.notifier.openFile(worktreeId, filePath, relativePath, runtimeEnvironmentId)
|
||||
},
|
||||
openDiff: (worktreeId, filePath, relativePath, staged) => {
|
||||
openDiff: (worktreeId, filePath, relativePath, staged, runtimeEnvironmentId) => {
|
||||
if (!this.notifier?.openDiff) {
|
||||
throw new Error('renderer_unavailable')
|
||||
}
|
||||
this.notifier.openDiff(worktreeId, filePath, relativePath, staged)
|
||||
this.notifier.openDiff(worktreeId, filePath, relativePath, staged, runtimeEnvironmentId)
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user