mirror of
https://github.com/stablyai/orca.git
synced 2026-09-24 08:02:33 +00:00
* chore(lint): upgrade oxlint to 1.71 and enable 7 new rules Upgrade oxlint 1.67.0 -> 1.71.0 (1.72 was blocked by the repo's 3-day minimum-release-age supply-chain guard; nothing here needs it). The bump is a no-op on the existing config. Enable 3 error rules (backlog autofixed to zero in this commit) and 4 warn rules (surface signal without gating CI): error (autofixed, behavior-preserving): - unicorn/prefer-node-protocol (~1531 sites: bare builtin -> node:) - typescript/no-import-type-side-effects (~36: all-inline-type -> import type) - unicorn/no-array-reverse (19: copy-then-reverse -> toReversed) warn (real signal, current fires are test-only/correct): - unicorn/no-array-fill-with-reference-type (aliasing footgun guard) - typescript/no-unsafe-function-type (bans bare Function type) - unicorn/prefer-array-flat-map (map().flat() -> flatMap()) - unicorn/prefer-regexp-test (.match() in bool ctx -> .test()) mobile/.oxlintrc.json extends root, so it inherits all 7; the autofix ran from root and covered mobile/ too. Verification (all green): oxlint 0 errors (root+mobile+aux configs), oxfmt clean, typecheck (node+cli+web), vitest 22795 passed / 0 failed, builds (electron-vite + web + cli) succeed. node: rewrites confirmed to skip embedded SSH/CLI string payloads (AST-only); all toReversed sites verified to operate on fresh copies or write-once locals. * chore(lint): bump mobile oxlint to 1.71 so inherited rules parse mobile/ is a standalone pnpm project pinning its own oxlint@1.67, which lacks unicorn/no-array-fill-with-reference-type (needs >=1.70). Since mobile/.oxlintrc.json extends the root config, mobile CI's 'cd mobile && oxlint' failed to parse the new rule. Bump mobile to match root (1.71). Verified in mobile/: oxlint 0 errors, oxfmt --check clean, tsc --noEmit pass, vitest 978 passed / 0 failed. Co-authored-by: Orca <help@stably.ai> --------- Co-authored-by: Orca <help@stably.ai>
84 lines
3.6 KiB
TypeScript
84 lines
3.6 KiB
TypeScript
import { existsSync, mkdtempSync, writeFileSync } from 'node:fs'
|
|
import { tmpdir } from 'node:os'
|
|
import { basename, join } from 'node:path'
|
|
import { describe, expect, it } from 'vitest'
|
|
import {
|
|
createRuntimeTransportMetadata,
|
|
RUNTIME_SOCKET_NAME_REGEX,
|
|
sweepOrphanedRuntimeSockets
|
|
} from './runtime-rpc'
|
|
|
|
describe('sweepOrphanedRuntimeSockets', () => {
|
|
// Why: a pid we know is always alive and is never the test runner's own
|
|
// pid — init on POSIX, so process.kill(1, 0) resolves without ESRCH. Using
|
|
// this synthetic pid for ownPid cleanly separates three retention branches
|
|
// (own-pid-skipped / alive-non-own-retained / dead-swept) into distinct
|
|
// observations.
|
|
const SYNTHETIC_OWN_PID = 1
|
|
const KNOWN_DEAD_PID = 99999999
|
|
|
|
it.runIf(process.platform !== 'win32')(
|
|
'sweeps dead-pid sockets while retaining own, alive, and non-matching entries',
|
|
() => {
|
|
const userDataPath = mkdtempSync(join(tmpdir(), 'orca-sweep-'))
|
|
|
|
const ownPidSocket = join(userDataPath, `o-${SYNTHETIC_OWN_PID}-aaaa.sock`)
|
|
const aliveSocket = join(userDataPath, `o-${process.pid}-bbbb.sock`)
|
|
const deadSocket = join(userDataPath, `o-${KNOWN_DEAD_PID}-cccc.sock`)
|
|
const unrelatedFile = join(userDataPath, 'foo.sock')
|
|
|
|
writeFileSync(ownPidSocket, '')
|
|
writeFileSync(aliveSocket, '')
|
|
writeFileSync(deadSocket, '')
|
|
writeFileSync(unrelatedFile, '')
|
|
|
|
sweepOrphanedRuntimeSockets(userDataPath, SYNTHETIC_OWN_PID)
|
|
|
|
// Why: own pid (1) is skipped by the ownPid === pid early-exit.
|
|
expect(existsSync(ownPidSocket)).toBe(true)
|
|
// Why: alive non-own pid — process.kill(pid, 0) succeeds without
|
|
// throwing, so the sweep leaves it alone.
|
|
expect(existsSync(aliveSocket)).toBe(true)
|
|
// Why: dead pid — process.kill throws ESRCH, sweep removes it.
|
|
expect(existsSync(deadSocket)).toBe(false)
|
|
// Why: regex miss — not `o-<digits>-<suffix>.sock` shape, so the
|
|
// sweep never touches it.
|
|
expect(existsSync(unrelatedFile)).toBe(true)
|
|
}
|
|
)
|
|
|
|
it('tolerates a non-existent userData directory', () => {
|
|
const userDataPath = join(tmpdir(), `orca-sweep-missing-${Date.now()}`)
|
|
|
|
expect(() => sweepOrphanedRuntimeSockets(userDataPath, SYNTHETIC_OWN_PID)).not.toThrow()
|
|
})
|
|
|
|
it('regex invariant: matches sockets produced by createRuntimeTransportMetadata', () => {
|
|
// Why: if the socket-name factory ever changes shape (e.g. adds a new
|
|
// separator or allows different characters), the sweep will silently
|
|
// stop matching real sockets. Assert the two stay in lockstep.
|
|
const userDataPath = '/tmp'
|
|
const transport = createRuntimeTransportMetadata(userDataPath, 12345, 'linux', 'rt_abcdef')
|
|
expect(transport.kind).toBe('unix')
|
|
if (transport.kind !== 'unix') {
|
|
throw new Error('expected unix transport')
|
|
}
|
|
const socketName = basename(transport.endpoint)
|
|
expect(RUNTIME_SOCKET_NAME_REGEX.test(socketName)).toBe(true)
|
|
})
|
|
|
|
it('regex invariant: also matches the fallback runtimeId suffix ("rt")', () => {
|
|
// Why: createRuntimeTransportMetadata falls back to the literal 'rt'
|
|
// suffix when the runtimeId contains no allowed characters; the sweep
|
|
// regex must still match that shape.
|
|
const userDataPath = '/tmp'
|
|
const transport = createRuntimeTransportMetadata(userDataPath, 99, 'darwin', '!!!!')
|
|
if (transport.kind !== 'unix') {
|
|
throw new Error('expected unix transport')
|
|
}
|
|
const socketName = basename(transport.endpoint)
|
|
expect(RUNTIME_SOCKET_NAME_REGEX.test(socketName)).toBe(true)
|
|
expect(socketName).toBe('o-99-rt.sock')
|
|
})
|
|
})
|