mirror of
https://github.com/stablyai/orca.git
synced 2026-09-30 00:03:15 +00:00
Drop the platform and absolute-path guards: ownsSocketDirectory is already false on Windows and for inherited directories, and an Orca-derived directory is always absolute. Fold the empty-name and traversal checks into agent-browser's own session-name rule. Stop lstat state leaking between lifecycle tests, and pin the probed socket path so the skip test cannot pass on an unwired mock.
31 lines
1.1 KiB
TypeScript
31 lines
1.1 KiB
TypeScript
import { lstatSync } from 'node:fs'
|
|
import { join } from 'node:path'
|
|
|
|
// agent-browser's own session-name rule; doubles as a traversal fence for the `join` below.
|
|
const SAFE_SESSION_NAME = /^[A-Za-z0-9_-]+$/
|
|
|
|
/**
|
|
* True when no daemon can be holding `sessionName`, so closing it would only start one.
|
|
*
|
|
* Only an Orca-derived socket directory proves that (`ownsSocketDirectory`): it is a
|
|
* private per-profile `/tmp` directory, never an inherited one shared with a second
|
|
* profile, and never Windows, which uses named pipes and leaves no socket to inspect.
|
|
*/
|
|
export function canSkipAgentBrowserSessionReset(options: {
|
|
ownsSocketDirectory: boolean
|
|
socketDirectory: string | undefined
|
|
sessionName: string
|
|
}): boolean {
|
|
const { socketDirectory, sessionName } = options
|
|
if (!options.ownsSocketDirectory || !socketDirectory || !SAFE_SESSION_NAME.test(sessionName)) {
|
|
return false
|
|
}
|
|
try {
|
|
lstatSync(join(socketDirectory, `${sessionName}.sock`))
|
|
return false
|
|
} catch (error) {
|
|
// Only a proven-absent socket is safe to skip; permission and other failures prove nothing.
|
|
return (error as NodeJS.ErrnoException).code === 'ENOENT'
|
|
}
|
|
}
|