Files
orca/src/shared/plugins/plugin-kill-list.test.ts
T
Neil bb667a33bd test: retire the last private-predicate duplicates in the leaked-internals sweep (#23949)
Sixth and final wave over the modules that export symbols only tests import.
Deletes private-predicate cases whose behavior is already asserted through the
module's real entry point, then makes the symbol private again.

Also removes three distinct junk shapes the earlier detectors missed:
- a self-comparison whose expected empty row was produced by the helper under
  test (`worktree-palette-search`), now a literal;
- expected values computed by a sibling helper rather than asserted
  (`terminal-theme`), now read through the production `getBuiltinTheme`;
- a negative control that cannot fail — `expect('json' in jsonlMonarchLanguage)
  .toBe(false)`, where `IMonarchLanguage` has no such key, so it guarded nothing
  while appearing to guard "does not attach the JSON language service".

Dead production code removed where tests were its only callers:
`refreshWindowsTerminalCapabilities` (a one-line alias for
`loadWindowsTerminalCapabilities({force: true})`), `readSpoolRecords`,
`buildAgentPromptSubmitBytes`, and `getCommitMessageModelCapability`.

About 70% of everything this detector flagged across the whole vein was a false
positive, so most modules were left untouched. Bounds consumed as test input,
`*ForTests` seams, non-hook cores of `useSyncExternalStore` hooks, and
value-position registrations all look identical to a leaked internal from the
outside and are not.
2026-09-29 17:04:42 -07:00

107 lines
2.9 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import {
PLUGIN_KILL_LIST_ENTRY_LIMIT,
PLUGIN_KILL_LIST_FUTURE_SKEW_MS,
findKilledPlugin,
isPluginKillListTooFarInFuture,
pluginKillListSchema,
type PluginKillList
} from './plugin-kill-list'
function entry(pluginKey = 'community.unsafe'): Record<string, unknown> {
return {
pluginKey,
reason: 'Known malicious release',
advisoryUrl: 'https://orca.example/security/unsafe'
}
}
describe('pluginKillListSchema', () => {
it('parses a strict versioned revocation document', () => {
const parsed = pluginKillListSchema.parse({
version: 1,
generatedAt: '2026-07-12T20:00:00Z',
plugins: [entry()]
})
expect(findKilledPlugin(parsed, 'community.unsafe')).toEqual(entry())
})
it.each([
{
version: 1,
generatedAt: '2026-07-12T20:00:00Z',
plugins: [],
unexpected: true
},
{
version: 1,
generatedAt: '2026-07-12T20:00:00Z',
plugins: [{ ...entry(), unexpected: true }]
},
{
version: 1,
generatedAt: 'not-a-date',
plugins: []
},
{
version: 1,
generatedAt: '2026-07-12T20:00:00Z',
plugins: [{ ...entry(), pluginKey: 'unsafe' }]
},
{
version: 1,
generatedAt: '2026-07-12T20:00:00Z',
plugins: [{ ...entry(), advisoryUrl: 'http://orca.example/advisory' }]
}
])('rejects malformed or untrusted fields', (killList) => {
expect(pluginKillListSchema.safeParse(killList).success).toBe(false)
})
it('rejects duplicate killed plugin identities', () => {
const parsed = pluginKillListSchema.safeParse({
version: 1,
generatedAt: '2026-07-12T20:00:00Z',
plugins: [entry(), entry()]
})
expect(parsed.success).toBe(false)
if (!parsed.success) {
expect(parsed.error.issues).toEqual(
expect.arrayContaining([
expect.objectContaining({ message: 'duplicate killed plugin: community.unsafe' })
])
)
}
})
it('caps the revocation document size by entry count', () => {
const plugins = Array.from({ length: PLUGIN_KILL_LIST_ENTRY_LIMIT + 1 }, (_, index) =>
entry(`publisher.plugin-${index}`)
)
expect(
pluginKillListSchema.safeParse({
version: 1,
generatedAt: '2026-07-12T20:00:00Z',
plugins
}).success
).toBe(false)
})
})
describe('isPluginKillListTooFarInFuture', () => {
const list = (generatedAt: string): PluginKillList =>
pluginKillListSchema.parse({ version: 1, generatedAt, plugins: [entry()] })
it('flags a snapshot that would freeze out every later revocation', () => {
expect(isPluginKillListTooFarInFuture(list('9999-12-31T23:59:59Z'))).toBe(true)
})
it('allows a snapshot inside the clock-skew window', () => {
const generatedAt = new Date(
Date.now() + PLUGIN_KILL_LIST_FUTURE_SKEW_MS - 60_000
).toISOString()
expect(isPluginKillListTooFarInFuture(list(generatedAt))).toBe(false)
})
})