mirror of
https://github.com/stablyai/orca.git
synced 2026-10-30 00:27:39 +00:00
#14397 split `shared/types.ts` into 46 per-domain modules but kept the path as a re-export barrel so the import sites did not have to change. This removes the barrel: every consumer now imports from the module that actually declares the type, and `src/shared/types.ts` is deleted. Barrels hide where a type lives, make every consumer look like it depends on the whole domain, and let an unrelated edit invalidate a module that ~2,000 files transitively import. 2,323 import declarations across 2,321 files. Rewritten mechanically: each specifier was resolved to an absolute path via the TypeScript AST and recomputed, rather than string-substituted, so alias forms (`@/../../shared/ types`) and per-specifier `type` modifiers survive. Four cases the mechanical pass had to handle, each found by a gate rather than by reading the diff: - Modules inside `src/shared` import the barrel as `./types`, not `shared/types`. A pre-filter on the latter string skipped 176 of them and left imports dangling at a deleted file, which surfaced as confusing `Property 'x' is optional in type 'Repo' but required in Pick<Repo, ...>` errors rather than "module not found". - The barrel RENAMED one type on the way through (`WorkspaceSource as WorkspaceCreateTelemetrySource`), so the original name in the owning module has to be re-aliased at each consumer. - Three test files put `;(globalThis as ...)` on the line after the import. TypeScript parses that `;` as the import statement's terminator, so replacing through `statement.getEnd()` deletes it and breaks ASI. The rewrite now stops at the module specifier. - A file that already imported directly from a module got a SECOND import from it, because the barrel re-exported those same names — which trips `import/no-duplicates` under `--deny-warnings`. A post-pass merges declarations sharing a specifier and type-only-ness; the `import type` plus `import` pair from one module is left alone, since that form is allowed. Splitting one barrel import into several genuinely adds lines, which pushed `terminal-layout-pty-ownership.ts` to 301 counted lines: its 107-character import must wrap, and neither local type collapses onto one line (101 and 116 characters). Rather than contort a type declaration to fit a line budget, `collectLeafIds` and `pruneLeaves` move to `terminal-pane-layout-tree.ts` — they are pure structural operations on the layout tree and independent of PTY ownership. `visible-worktrees.ts` similarly loses its own mini-barrel re-export of `isDefaultBranchWorkspace`, with the four real consumers repointed at the declaring module. No `max-lines` bypass added. Verified: cold `tsc --noEmit` green on node, cli, and web (buildinfo deleted first — these projects are `composite: true` and reuse stale caches); the full `pnpm lint` green, not just bare oxlint — the narrower local check is what let the duplicate imports reach CI; max-lines ratchet OK at 344.
196 lines
6.8 KiB
TypeScript
196 lines
6.8 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import type { PRCheckDetail } from '../../../../src/shared/github/check-types'
|
|
import {
|
|
checkOutcome,
|
|
firstFailingCheckKey,
|
|
getPRReviewerRows,
|
|
prCheckKey,
|
|
prStateBadge,
|
|
sortPRChecks,
|
|
summarizePRChecks
|
|
} from './pr-checks-presentation'
|
|
|
|
function check(over: Partial<PRCheckDetail>): PRCheckDetail {
|
|
return {
|
|
name: 'ci',
|
|
status: 'completed',
|
|
conclusion: 'success',
|
|
url: null,
|
|
...over
|
|
}
|
|
}
|
|
|
|
describe('checkOutcome', () => {
|
|
it('treats a completed null-conclusion check as neutral, not failure', () => {
|
|
expect(checkOutcome(check({ status: 'completed', conclusion: null }))).toBe('neutral')
|
|
})
|
|
it('treats queued/in_progress as pending', () => {
|
|
expect(checkOutcome(check({ status: 'queued', conclusion: null }))).toBe('pending')
|
|
expect(checkOutcome(check({ status: 'in_progress', conclusion: null }))).toBe('pending')
|
|
})
|
|
it('maps failure/cancelled/timed_out to failure', () => {
|
|
expect(checkOutcome(check({ conclusion: 'failure' }))).toBe('failure')
|
|
expect(checkOutcome(check({ conclusion: 'cancelled' }))).toBe('failure')
|
|
expect(checkOutcome(check({ conclusion: 'timed_out' }))).toBe('failure')
|
|
})
|
|
it('maps a merge-blocking action_required gate to failure', () => {
|
|
expect(checkOutcome(check({ conclusion: 'action_required' }))).toBe('failure')
|
|
})
|
|
it('maps skipped to success and neutral to neutral (desktop parity)', () => {
|
|
expect(checkOutcome(check({ conclusion: 'skipped' }))).toBe('success')
|
|
expect(checkOutcome(check({ conclusion: 'neutral' }))).toBe('neutral')
|
|
})
|
|
})
|
|
|
|
describe('sortPRChecks', () => {
|
|
it('orders failures first, then pending, then success', () => {
|
|
const checks = [
|
|
check({ name: 'ok', conclusion: 'success' }),
|
|
check({ name: 'pending', status: 'in_progress', conclusion: null }),
|
|
check({ name: 'broke', conclusion: 'failure' })
|
|
]
|
|
expect(sortPRChecks(checks).map((c) => c.name)).toEqual(['broke', 'pending', 'ok'])
|
|
})
|
|
it('is stable within a bucket', () => {
|
|
const checks = [
|
|
check({ name: 'a', conclusion: 'failure' }),
|
|
check({ name: 'b', conclusion: 'failure' })
|
|
]
|
|
expect(sortPRChecks(checks).map((c) => c.name)).toEqual(['a', 'b'])
|
|
})
|
|
})
|
|
|
|
describe('firstFailingCheckKey', () => {
|
|
it('returns the key of the first failing check in the given order', () => {
|
|
const checks = sortPRChecks([
|
|
check({ name: 'ok', checkRunId: 1, conclusion: 'success' }),
|
|
check({ name: 'broke', checkRunId: 2, conclusion: 'failure' }),
|
|
check({ name: 'also-broke', checkRunId: 3, conclusion: 'cancelled' })
|
|
])
|
|
expect(firstFailingCheckKey(checks)).toBe(prCheckKey(check({ checkRunId: 2 })))
|
|
})
|
|
it('returns null when nothing is failing', () => {
|
|
expect(
|
|
firstFailingCheckKey([
|
|
check({ conclusion: 'success' }),
|
|
check({ status: 'in_progress', conclusion: null })
|
|
])
|
|
).toBeNull()
|
|
})
|
|
})
|
|
|
|
describe('summarizePRChecks', () => {
|
|
it('returns a "No checks" summary for an empty list', () => {
|
|
const summary = summarizePRChecks([])
|
|
expect(summary.total).toBe(0)
|
|
expect(summary.outcome).toBe('none')
|
|
expect(summary.label).toBe('No checks')
|
|
})
|
|
it('counts pass/pending/fail and reports worst-case outcome', () => {
|
|
const summary = summarizePRChecks([
|
|
check({ conclusion: 'success' }),
|
|
check({ status: 'in_progress', conclusion: null }),
|
|
check({ conclusion: 'failure' })
|
|
])
|
|
expect(summary).toMatchObject({
|
|
total: 3,
|
|
passed: 1,
|
|
pending: 1,
|
|
failed: 1,
|
|
outcome: 'failure'
|
|
})
|
|
expect(summary.label).toBe('1 failing · 1 pending · 1 passed')
|
|
})
|
|
it('reports pending when no failures but some pending', () => {
|
|
expect(
|
|
summarizePRChecks([
|
|
check({ conclusion: 'success' }),
|
|
check({ status: 'queued', conclusion: null })
|
|
]).outcome
|
|
).toBe('pending')
|
|
})
|
|
it('reports success when all pass', () => {
|
|
expect(summarizePRChecks([check({ conclusion: 'success' })]).outcome).toBe('success')
|
|
})
|
|
it('reports a neutral-only set as neutral with a labeled count (not empty success)', () => {
|
|
const summary = summarizePRChecks([
|
|
check({ conclusion: 'neutral' }),
|
|
check({ conclusion: 'neutral' })
|
|
])
|
|
expect(summary).toMatchObject({
|
|
total: 2,
|
|
passed: 0,
|
|
pending: 0,
|
|
failed: 0,
|
|
outcome: 'neutral'
|
|
})
|
|
expect(summary.label).toBe('2 neutral')
|
|
})
|
|
it('counts skipped as passed so the sidebar matches desktop and the tasks grid', () => {
|
|
const summary = summarizePRChecks([
|
|
check({ conclusion: 'success' }),
|
|
check({ conclusion: 'success' }),
|
|
check({ conclusion: 'skipped' })
|
|
])
|
|
expect(summary).toMatchObject({ total: 3, passed: 3, outcome: 'success' })
|
|
expect(summary.label).toBe('3 passed')
|
|
})
|
|
})
|
|
|
|
describe('prCheckKey', () => {
|
|
it('prefers checkRunId, then workflowRunId, then name', () => {
|
|
expect(prCheckKey(check({ checkRunId: 5, workflowRunId: 9 }))).toBe('run:5')
|
|
expect(prCheckKey(check({ workflowRunId: 9 }))).toBe('wf:9')
|
|
expect(prCheckKey(check({ name: 'lint' }))).toBe('name:lint')
|
|
})
|
|
})
|
|
|
|
describe('prStateBadge', () => {
|
|
it('maps each PR state to a label + status-color token matching the workspace-list badge', () => {
|
|
expect(prStateBadge('open')).toEqual({ label: 'Open', token: 'statusGreen' })
|
|
expect(prStateBadge('closed')).toEqual({ label: 'Closed', token: 'statusRed' })
|
|
expect(prStateBadge('merged')).toEqual({ label: 'Merged', token: 'statusPurple' })
|
|
expect(prStateBadge('draft')).toEqual({ label: 'Draft', token: 'textSecondary' })
|
|
})
|
|
})
|
|
|
|
describe('getPRReviewerRows', () => {
|
|
it('returns empty for no reviewers', () => {
|
|
expect(getPRReviewerRows({})).toEqual([])
|
|
})
|
|
it('labels requested-only reviewers as Requested', () => {
|
|
const rows = getPRReviewerRows({
|
|
reviewRequests: [{ login: 'alice', name: 'Alice', avatarUrl: 'a' }]
|
|
})
|
|
expect(rows).toEqual([
|
|
{
|
|
login: 'alice',
|
|
name: 'Alice',
|
|
avatarUrl: 'a',
|
|
stateLabel: 'Requested',
|
|
token: 'statusAmber'
|
|
}
|
|
])
|
|
})
|
|
it('maps latest-review states to labels', () => {
|
|
const rows = getPRReviewerRows({
|
|
latestReviews: [
|
|
{ login: 'bob', state: 'APPROVED' },
|
|
{ login: 'carol', state: 'CHANGES_REQUESTED' }
|
|
]
|
|
})
|
|
expect(rows.map((r) => [r.login, r.stateLabel, r.token])).toEqual([
|
|
['bob', 'Approved', 'statusGreen'],
|
|
['carol', 'Changes requested', 'statusRed']
|
|
])
|
|
})
|
|
it('dedupes a reviewer present in both requests and reviews (requested wins)', () => {
|
|
const rows = getPRReviewerRows({
|
|
reviewRequests: [{ login: 'alice', name: null, avatarUrl: '' }],
|
|
latestReviews: [{ login: 'alice', state: 'APPROVED' }]
|
|
})
|
|
expect(rows).toHaveLength(1)
|
|
expect(rows[0].stateLabel).toBe('Requested')
|
|
})
|
|
})
|