Skip to content

armgit / avibe

Public Imported from GitHub
0

Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.

test(model-hub): typecheck the model-hub test project in CI (#1871)

Maxab35b7c046da
diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml
index f7e44db13..f1f65fe04 100644
--- a/.github/workflows/lint.yml
+++ b/.github/workflows/lint.yml
@@ -52,6 +52,10 @@ jobs:
npm ci
npm run validate:theme
npm run lint
+ # `npm run build` runs `tsc -b`, whose projects exclude every
+ # `*.test.ts(x)`, and vitest strips types without checking them. So no
+ # gate below reads a test file's types; this one does.
+ npm run typecheck:tests
npm test
npm run build
diff --git a/ui/package.json b/ui/package.json
index 4a5810163..3f1920b8a 100644
--- a/ui/package.json
+++ b/ui/package.json
@@ -15,6 +15,7 @@
"lint:baseline": "node scripts/lint-baseline.mjs --update",
"preview": "vite preview",
"test": "vitest run",
+ "typecheck:tests": "tsc -p src/components/settings/models/tsconfig.tests.json --noEmit",
"test:crypto": "vitest run src/lib/vaultCrypto.test.ts",
"e2e": "playwright test",
"e2e:headed": "playwright test --headed",
diff --git a/ui/src/components/settings/models/AgentCard.test.tsx b/ui/src/components/settings/models/AgentCard.test.tsx
index 47cfef294..50e9e4d65 100644
--- a/ui/src/components/settings/models/AgentCard.test.tsx
+++ b/ui/src/components/settings/models/AgentCard.test.tsx
@@ -39,7 +39,7 @@ const localeInstance = (lng: 'en' | 'zh') => {
const source = (id: string, name: string): Source => ({
id, last_discovered_at: null, kind: 'api_key', vendor: 'anthropic', display_name: name,
protocol: 'anthropic', supply_channel: 'hub', billing: 'metered', state: { status: 'active', retry_at: null, detail_key: null },
- models: [{ id: 'claude-opus-4-6', origin: 'discovered', reasoning_efforts: [] }],
+ models: [{ id: 'claude-opus-4-6', origin: 'discovered', reasoning_efforts: [], reasoning_efforts_source: null }],
});
const hubAgent: AgentSupply = {
backend: 'claude', cli_present: true, mode: 'hub', menu_kind: 'fixed', selected_model_id: 'claude-opus-4-6', selected_model_explicit: true,
diff --git a/ui/src/components/settings/models/RouteChainDialog.test.tsx b/ui/src/components/settings/models/RouteChainDialog.test.tsx
index 8dc74b9f2..7d93fda5b 100644
--- a/ui/src/components/settings/models/RouteChainDialog.test.tsx
+++ b/ui/src/components/settings/models/RouteChainDialog.test.tsx
@@ -105,16 +105,16 @@ const stocked = () => ({
{
...sources[0],
models: [
- { id: "claude-opus-5", origin: "discovered", reasoning_efforts: [] },
- { id: "claude-sonnet-5", origin: "discovered", reasoning_efforts: [] },
- { id: "claude-haiku-5", origin: "discovered", reasoning_efforts: [] },
+ { id: "claude-opus-5", origin: "discovered", reasoning_efforts: [], reasoning_efforts_source: null },
+ { id: "claude-sonnet-5", origin: "discovered", reasoning_efforts: [], reasoning_efforts_source: null },
+ { id: "claude-haiku-5", origin: "discovered", reasoning_efforts: [], reasoning_efforts_source: null },
],
},
{
...sources[1],
models: [
- { id: "opus-5", origin: "discovered", reasoning_efforts: [] },
- { id: "sonnet-5", origin: "discovered", reasoning_efforts: [] },
+ { id: "opus-5", origin: "discovered", reasoning_efforts: [], reasoning_efforts_source: null },
+ { id: "sonnet-5", origin: "discovered", reasoning_efforts: [], reasoning_efforts_source: null },
],
},
] satisfies Source[],
diff --git a/ui/src/components/settings/models/SettingsModelsPage.render.test.tsx b/ui/src/components/settings/models/SettingsModelsPage.render.test.tsx
index 0ed9ab3bd..84f22a0fa 100644
--- a/ui/src/components/settings/models/SettingsModelsPage.render.test.tsx
+++ b/ui/src/components/settings/models/SettingsModelsPage.render.test.tsx
@@ -15,7 +15,7 @@ import type { ModelsSurfaceKind } from './modelHubSurfaceState';
import { modelsApi } from './modelsApi';
import { SOURCE_MUTATION_REPORT_PROJECTIONS } from './mutationSettlement';
import { SettingsModelsPage } from './SettingsModelsPage';
-import { CONTRACT_VERSION, type AgentBackend, type AgentChain, type AgentSupply, type BackendModel, type RuntimeDependency, type Source, type UsageSummary } from './types';
+import { CONTRACT_VERSION, type AgentBackend, type AgentChain, type AgentSupply, type BackendModel, type RuntimeDependency, type RuntimeManifest, type Source, type UsageSummary } from './types';
const directAgent = (backend: AgentBackend): AgentSupply => ({
backend,
@@ -24,9 +24,17 @@ const directAgent = (backend: AgentBackend): AgentSupply => ({
menu_kind: backend === 'opencode' ? 'open' : 'fixed',
});
+// Named separately from `runtime` so it keeps the arm of `RuntimeManifest` it
+// was written as. Reached through `runtime.manifest` it is the whole union, and
+// re-resolving a spread of that lands on the `unresolved` arm, which carries no
+// version or source_sha for a resolution that requires both.
+const manifest = {
+ name: 'cliproxyapi', resolution: 'resolved', version: '1', source_sha: 'a'.repeat(40), assets: [],
+} satisfies RuntimeManifest;
+
const runtime: RuntimeDependency = {
contract_version: 8,
- manifest: { name: 'cliproxyapi', resolution: 'resolved', version: '1', source_sha: 'a'.repeat(40), assets: [] },
+ manifest,
status: { installed_version: '1', verified: true, health: 'ok' },
};
@@ -497,7 +505,7 @@ describe('SettingsModelsPage surface branches', () => {
const unsupported = {
...runtime,
enabled: true,
- manifest: { ...runtime.manifest, resolution: 'unsupported' as const },
+ manifest: { ...manifest, resolution: 'unsupported' as const },
status: { ...runtime.status, health: 'not_installed' as const },
};
vi.spyOn(modelsApi, 'listSources').mockResolvedValue([]);
@@ -572,7 +580,7 @@ describe('SettingsModelsPage surface branches', () => {
it('keeps tier-editor Escape local to the provider dialog', async () => {
const editableSource: Source = {
...retainedSource,
- models: [{ id: 'model-a', display_name: null, origin: 'manual', reasoning_efforts: ['high'] }],
+ models: [{ id: 'model-a', display_name: null, origin: 'manual', reasoning_efforts: ['high'], reasoning_efforts_source: 'user' }],
};
renderPage([editableSource]);
const user = userEvent.setup();
@@ -737,7 +745,7 @@ describe('SettingsModelsPage surface branches', () => {
presentation: { expects: 'none' as const },
};
const reauth = vi.spyOn(modelsApi, 'reauthSource').mockResolvedValue(started);
- vi.spyOn(modelsApi, 'getOAuthStatus').mockResolvedValue(started);
+ vi.spyOn(modelsApi, 'getOAuthStatus').mockResolvedValue({ flow: started, created: null, repaired: null });
renderPage([blockedSubscription]);
await userEvent.click(await screen.findByRole('button', { name: /Claude native login/i }));
@@ -763,7 +771,7 @@ describe('SettingsModelsPage surface branches', () => {
presentation: { expects: 'paste_callback_url' as const, auth_url: authUrl },
};
vi.spyOn(modelsApi, 'reauthSource').mockResolvedValue(started);
- vi.spyOn(modelsApi, 'getOAuthStatus').mockResolvedValue(started);
+ vi.spyOn(modelsApi, 'getOAuthStatus').mockResolvedValue({ flow: started, created: null, repaired: null });
const tab = { closed: false, opener: {} as unknown, location: { href: '' } };
const open = vi.spyOn(window, 'open').mockReturnValue(tab as unknown as Window);
renderPage([blockedSubscription]);
@@ -794,7 +802,7 @@ describe('SettingsModelsPage surface branches', () => {
.spyOn(modelsApi, 'reauthSource')
.mockRejectedValueOnce(new Error('start failed'))
.mockResolvedValue(started);
- vi.spyOn(modelsApi, 'getOAuthStatus').mockResolvedValue(started);
+ vi.spyOn(modelsApi, 'getOAuthStatus').mockResolvedValue({ flow: started, created: null, repaired: null });
renderPage([blockedSubscription]);
await userEvent.click(await screen.findByRole('button', { name: /Claude native login/i }));
diff --git a/ui/src/components/settings/models/SourceDetailPanel.test.tsx b/ui/src/components/settings/models/SourceDetailPanel.test.tsx
index 5f39b432b..70fb9ea82 100644
--- a/ui/src/components/settings/models/SourceDetailPanel.test.tsx
+++ b/ui/src/components/settings/models/SourceDetailPanel.test.tsx
@@ -46,7 +46,7 @@ const source: Source = {
billing: 'metered',
credential_ref: 'cred_detail',
state: { status: 'active', retry_at: null, detail_key: null },
- models: [{ id: 'model-a', display_name: null, origin: 'manual', reasoning_efforts: ['high'] }],
+ models: [{ id: 'model-a', display_name: null, origin: 'manual', reasoning_efforts: ['high'], reasoning_efforts_source: 'user' }],
};
const heldHops = [{
@@ -223,7 +223,13 @@ const EchoPanel: React.FC<{
);
};
-const renderEchoPanel = (reconcile = vi.fn(), scheduler?: MutationScheduler) => render(
+// Typed off the prop rather than off `vi.fn()`: the default would otherwise
+// narrow the parameter to a mock and turn away the plain deferred-backed
+// reconcilers the settlement tests hand it.
+const renderEchoPanel = (
+ reconcile: React.ComponentProps<typeof EchoPanel>['reconcile'] = vi.fn(),
+ scheduler?: MutationScheduler,
+) => render(
<ToastProvider>
<I18nextProvider i18n={i18n}>
<EchoPanel reconcile={reconcile} scheduler={scheduler} />
@@ -942,7 +948,7 @@ describe('SourceDetailPanel', () => {
it('applies the refetch Source echo before the collection refresh settles', async () => {
const echoed = {
...source,
- models: [...source.models, { id: 'model-b', display_name: null, origin: 'discovered' as const, reasoning_efforts: [] }],
+ models: [...source.models, { id: 'model-b', display_name: null, origin: 'discovered' as const, reasoning_efforts: [], reasoning_efforts_source: null }],
};
const refresh = vi.spyOn(modelsApi, 'refreshSource').mockResolvedValueOnce({ source: echoed, discovered: echoed.models.length });
const reconcile = vi.fn().mockResolvedValue(undefined);
@@ -960,7 +966,7 @@ describe('SourceDetailPanel', () => {
const update = vi.spyOn(modelsApi, 'updateModelReasoningEfforts').mockReturnValueOnce(tierResponse.promise);
const refreshed = {
...source,
- models: [...source.models, { id: 'model-b', display_name: null, origin: 'discovered' as const, reasoning_efforts: [] }],
+ models: [...source.models, { id: 'model-b', display_name: null, origin: 'discovered' as const, reasoning_efforts: [], reasoning_efforts_source: null }],
};
const refetch = vi.spyOn(modelsApi, 'refreshSource').mockResolvedValueOnce({ source: refreshed, discovered: refreshed.models.length });
renderEchoPanel(vi.fn(), serializedTrack());
@@ -1033,7 +1039,7 @@ describe('SourceDetailPanel', () => {
it('applies the manual-create Source echo without waiting for a collection read', async () => {
const echoed = {
...source,
- models: [...source.models, { id: 'model-b', display_name: null, origin: 'manual' as const, reasoning_efforts: [] }],
+ models: [...source.models, { id: 'model-b', display_name: null, origin: 'manual' as const, reasoning_efforts: [], reasoning_efforts_source: null }],
};
vi.spyOn(modelsApi, 'addCustomModel').mockResolvedValueOnce(echoed);
renderEchoPanel();
@@ -1279,7 +1285,7 @@ describe('SourceDetailPanel', () => {
it('hands the editor to the row that was clicked instead of opening a second one', async () => {
renderProtocol('openai_responses', [
source.models[0],
- { id: 'model-b', display_name: null, origin: 'discovered', reasoning_efforts: [] },
+ { id: 'model-b', display_name: null, origin: 'discovered', reasoning_efforts: [], reasoning_efforts_source: null },
]);
await userEvent.click(screen.getByRole('button', { name: /high/i }));
expect(screen.getAllByPlaceholderText(/Enter to add|回车添加/i)).toHaveLength(1);
@@ -1332,7 +1338,7 @@ describe('SourceDetailPanel', () => {
const update = vi.spyOn(modelsApi, 'updateModelReasoningEfforts').mockRejectedValueOnce(new Error('write failed'));
renderProtocol('openai_responses', [
source.models[0],
- { id: 'model-b', display_name: null, origin: 'discovered', reasoning_efforts: [] },
+ { id: 'model-b', display_name: null, origin: 'discovered', reasoning_efforts: [], reasoning_efforts_source: null },
]);
await userEvent.click(screen.getByRole('button', { name: /high/i }));
await userEvent.type(screen.getByPlaceholderText(/Enter to add|回车添加/i), 'low{Enter}');
@@ -1386,7 +1392,7 @@ describe('SourceDetailPanel', () => {
// for one without — CSS nobody wears is not a hit area.
renderProtocol('openai_responses', [
source.models[0],
- { id: 'model-b', display_name: null, origin: 'discovered', reasoning_efforts: [] },
+ { id: 'model-b', display_name: null, origin: 'discovered', reasoning_efforts: [], reasoning_efforts_source: null },
]);
for (const name of [/high/i, /No tiers set|未设置档位/i]) {
expect(screen.getByRole('button', { name }).className).toContain('model-hub-source-tier-cell');
diff --git a/ui/src/components/settings/models/modelsApiDeadline.test.ts b/ui/src/components/settings/models/modelsApiDeadline.test.ts
index 4d21a9ef7..d63fcc310 100644
--- a/ui/src/components/settings/models/modelsApiDeadline.test.ts
+++ b/ui/src/components/settings/models/modelsApiDeadline.test.ts
@@ -35,8 +35,12 @@ describe('Model Hub request deadlines', () => {
signal?.addEventListener('abort', () => reject(signal.reason), { once: true });
}));
vi.stubGlobal('fetch', fetchMock);
+ // Narrowed to a call the compiler accepts for every member of the method
+ // union: no parameters, and a result assignable to each method's own return.
+ // The test calls each one with nothing — what it asserts is that a request
+ // goes out under a deadline, not what any method resolves to.
const methods = Object.entries(modelsApi).filter(
- (entry): entry is [string, (...args: never[]) => Promise<unknown>] =>
+ (entry): entry is [string, () => Promise<never>] =>
typeof entry[1] === 'function',
);
const issuedSignals: AbortSignal[] = [];
diff --git a/ui/src/components/settings/models/mutationSettlement.test.ts b/ui/src/components/settings/models/mutationSettlement.test.ts
index 831cd6025..2b45c4f07 100644
--- a/ui/src/components/settings/models/mutationSettlement.test.ts
+++ b/ui/src/components/settings/models/mutationSettlement.test.ts
@@ -4,7 +4,7 @@ import { fileURLToPath } from 'node:url';
import { describe, expect, it, vi } from 'vitest';
-import { modelChainKey } from './modelRows';
+import { modelChainKey, type ModelChainIndex } from './modelRows';
import type { SourceCreated } from './modelsApi';
import {
createContinuationSettlement,
@@ -13,10 +13,19 @@ import {
SOURCE_MUTATION_REPORT_PROJECTIONS,
sourceMutationLanding,
sourceMutationReadScope,
+ type SourceMutationLandingReads,
} from './mutationSettlement';
import { failRegionRead, readyRegion, unreadRegion } from './regionRead';
import type { AgentChain, AgentSupply, RuntimeDependency, Source } from './types';
+// Fails exactly one projection, keyed generically so each key carries its own
+// value type into `failRegionRead`. Indexing the reads with a union key hands
+// the compiler four candidate types for one inference site and it picks one.
+const degradeProjection = <K extends keyof SourceMutationLandingReads>(
+ reads: SourceMutationLandingReads,
+ projection: K,
+): SourceMutationLandingReads => ({ ...reads, [projection]: failRegionRead(reads[projection]) });
+
describe('mutation settlement fences', () => {
it('atomically rejects every effect belonging to an invalidated attempt', () => {
const authority = createContinuationSettlement();
@@ -82,22 +91,19 @@ describe('mutation settlement fences', () => {
SOURCE_MUTATION_REPORT_PROJECTIONS,
) as (keyof typeof SOURCE_MUTATION_REPORT_PROJECTIONS)[]) {
expect(
- sourceMutationLanding({
- ...reads,
- [projection]: failRegionRead(reads[projection]),
- }, affectedChains, true).verdict,
+ sourceMutationLanding(degradeProjection(reads, projection), affectedChains, true).verdict,
projection,
).toBe('degraded');
}
for (const request of affectedChains) {
const key = modelChainKey(request.backend, request.modelId);
- const missing = readyRegion({
+ const missing = readyRegion<ModelChainIndex>({
...Object.fromEntries(affectedChains.map(({ backend, modelId }) => [
modelChainKey(backend, modelId),
readyRegion({} as AgentChain),
- ])),
- [key]: unreadRegion(),
+ ] as const)),
+ [key]: unreadRegion<AgentChain>(),
});
expect(sourceMutationLanding({ ...reads, chains: missing }, affectedChains, true).verdict, key)
.toBe('degraded');
diff --git a/ui/src/components/settings/models/oauthFailureClass.test.ts b/ui/src/components/settings/models/oauthFailureClass.test.ts
index 6eb81859d..8a0d637e7 100644
--- a/ui/src/components/settings/models/oauthFailureClass.test.ts
+++ b/ui/src/components/settings/models/oauthFailureClass.test.ts
@@ -32,6 +32,9 @@ function failureConsumers(url: URL): FailureConsumer[] {
&& ts.isIdentifier(node.name)
&& isCallTo(node.initializer, 'apiFailure')
) {
+ // Read out here, where the guard above still holds: a narrowing on
+ // `node.name` does not survive into the nested closure below.
+ const declared = node.name.text;
let scope: ts.Node | undefined = node.parent;
while (scope && !ts.isBlock(scope)) scope = scope.parent;
let classifies = false;
@@ -39,7 +42,7 @@ function failureConsumers(url: URL): FailureConsumer[] {
if (
isCallTo(child, 'classifyOAuthFailure')
&& child.arguments.some(
- (argument) => ts.isIdentifier(argument) && argument.text === node.name.text,
+ (argument) => ts.isIdentifier(argument) && argument.text === declared,
)
) {
classifies = true;
diff --git a/ui/src/components/settings/models/routeChainDraft.test.ts b/ui/src/components/settings/models/routeChainDraft.test.ts
index ebd4e2daa..10310d676 100644
--- a/ui/src/components/settings/models/routeChainDraft.test.ts
+++ b/ui/src/components/settings/models/routeChainDraft.test.ts
@@ -21,6 +21,7 @@ const source = (id: string, models: string[]): Source => ({
id: modelId,
origin: "discovered",
reasoning_efforts: [],
+ reasoning_efforts_source: null,
})),
});
diff --git a/ui/src/components/settings/models/useSourceMutationReport.test.tsx b/ui/src/components/settings/models/useSourceMutationReport.test.tsx
index 242015fcb..3c19ce06b 100644
--- a/ui/src/components/settings/models/useSourceMutationReport.test.tsx
+++ b/ui/src/components/settings/models/useSourceMutationReport.test.tsx
@@ -1,5 +1,4 @@
// @vitest-environment jsdom
-import * as React from 'react';
import { act, cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react';
import { I18nextProvider } from 'react-i18next';
import { afterEach, describe, expect, it, vi } from 'vitest';