mirror of
https://github.com/stablyai/orca.git
synced 2026-09-25 08:02:31 +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>
99 lines
3.5 KiB
TypeScript
99 lines
3.5 KiB
TypeScript
import { mkdtempSync, rmSync } from 'node:fs'
|
|
import { tmpdir } from 'node:os'
|
|
import { join } from 'node:path'
|
|
import { afterEach, beforeEach, describe, expect, it } from 'vitest'
|
|
import { encodePairingOffer } from './pairing'
|
|
import {
|
|
RuntimeEnvironmentStoreError,
|
|
addEnvironmentFromPairingCode,
|
|
listEnvironments,
|
|
markEnvironmentUsed
|
|
} from './runtime-environment-store'
|
|
|
|
function pairingCode(endpoint = 'ws://127.0.0.1:6768'): string {
|
|
return encodePairingOffer({
|
|
v: 2,
|
|
endpoint,
|
|
deviceToken: 'device-token',
|
|
publicKeyB64: Buffer.from(new Uint8Array(32).fill(1)).toString('base64')
|
|
})
|
|
}
|
|
|
|
describe('runtime environment store', () => {
|
|
const tempDirs: string[] = []
|
|
const originalPlatform = Object.getOwnPropertyDescriptor(process, 'platform')
|
|
|
|
beforeEach(() => {
|
|
// Why: this suite tests store timestamps, while secure-file tests cover Windows ACLs.
|
|
Object.defineProperty(process, 'platform', { configurable: true, value: 'linux' })
|
|
})
|
|
|
|
afterEach(() => {
|
|
if (originalPlatform) {
|
|
Object.defineProperty(process, 'platform', originalPlatform)
|
|
}
|
|
for (const dir of tempDirs.splice(0)) {
|
|
rmSync(dir, { recursive: true, force: true })
|
|
}
|
|
})
|
|
|
|
it('rejects duplicate server names instead of silently replacing the saved server', () => {
|
|
const userDataPath = mkdtempSync(join(tmpdir(), 'orca-runtime-env-store-'))
|
|
tempDirs.push(userDataPath)
|
|
|
|
const first = addEnvironmentFromPairingCode(userDataPath, {
|
|
name: 'dev box',
|
|
pairingCode: pairingCode('ws://127.0.0.1:6768')
|
|
})
|
|
|
|
expect(() =>
|
|
addEnvironmentFromPairingCode(userDataPath, {
|
|
name: 'dev box',
|
|
pairingCode: pairingCode('ws://192.0.2.10:6768')
|
|
})
|
|
).toThrow(RuntimeEnvironmentStoreError)
|
|
expect(listEnvironments(userDataPath)).toEqual([first])
|
|
})
|
|
|
|
it('throttles lastUsedAt writes so it does not rewrite the store on every runtime call', () => {
|
|
const userDataPath = mkdtempSync(join(tmpdir(), 'orca-runtime-env-store-'))
|
|
tempDirs.push(userDataPath)
|
|
const env = addEnvironmentFromPairingCode(userDataPath, {
|
|
name: 'dev box',
|
|
pairingCode: pairingCode()
|
|
})
|
|
|
|
// First use persists (lastUsedAt started null).
|
|
markEnvironmentUsed(userDataPath, env.id, { runtimeId: 'runtime-1', now: 1_000 })
|
|
expect(listEnvironments(userDataPath)[0]).toMatchObject({
|
|
lastUsedAt: 1_000,
|
|
runtimeId: 'runtime-1'
|
|
})
|
|
|
|
// A second use shortly after, same runtime, is skipped — lastUsedAt stays put.
|
|
markEnvironmentUsed(userDataPath, env.id, { runtimeId: 'runtime-1', now: 5_000 })
|
|
expect(listEnvironments(userDataPath)[0]!.lastUsedAt).toBe(1_000)
|
|
|
|
// Once the throttle window elapses, it persists again.
|
|
markEnvironmentUsed(userDataPath, env.id, { runtimeId: 'runtime-1', now: 61_000 })
|
|
expect(listEnvironments(userDataPath)[0]!.lastUsedAt).toBe(61_000)
|
|
})
|
|
|
|
it('persists immediately when the runtimeId changes within the throttle window', () => {
|
|
const userDataPath = mkdtempSync(join(tmpdir(), 'orca-runtime-env-store-'))
|
|
tempDirs.push(userDataPath)
|
|
const env = addEnvironmentFromPairingCode(userDataPath, {
|
|
name: 'dev box',
|
|
pairingCode: pairingCode()
|
|
})
|
|
|
|
markEnvironmentUsed(userDataPath, env.id, { runtimeId: 'runtime-1', now: 1_000 })
|
|
// A different runtimeId inside the window must not be dropped.
|
|
markEnvironmentUsed(userDataPath, env.id, { runtimeId: 'runtime-2', now: 2_000 })
|
|
expect(listEnvironments(userDataPath)[0]).toMatchObject({
|
|
lastUsedAt: 2_000,
|
|
runtimeId: 'runtime-2'
|
|
})
|
|
})
|
|
})
|