Skip to content

armgit / Orkas

Public Imported from GitHub
0

Orkas is an open-source (MIT), local-first AI team for your desktop: a Commander turns your goal into to-dos and coordinates 16 built-in specialist agents plus Claude Code, Codex, OpenCode, OpenClaw and Hermes, with projects, scheduled automations and connectors. Free app for macOS & Windows; built-in models or your own keys.

Fix open-source test expectations

wyt6903e1f0cbf4
diff --git a/test/main/avatar-catalogs.test.ts b/test/main/avatar-catalogs.test.ts
index 989f85bb..8b44a4ee 100644
--- a/test/main/avatar-catalogs.test.ts
+++ b/test/main/avatar-catalogs.test.ts
@@ -5,12 +5,10 @@ import { fileURLToPath } from 'node:url';
import { describe, expect, it } from 'vitest';
const here = path.dirname(fileURLToPath(import.meta.url));
-const repoRoot = path.resolve(here, '../../..');
+const repoRoot = path.resolve(here, '../..');
const catalogs = [
- ['PC', 'PC/src/main/data/avatars.json'],
- ['iOS', 'iOS/webui/data/avatars.json'],
- ['Web', 'Web/res/data/avatars.json'],
+ ['desktop', 'src/main/data/avatars.json'],
] as const;
function stableStringify(value: unknown): string {
@@ -52,7 +50,7 @@ function validateCatalog(label: string, relPath: string, catalog: any): void {
}
describe('avatar catalogs', () => {
- it('keeps PC, iOS, and Web avatar resources consistent', () => {
+ it('keeps the desktop avatar catalog structurally valid', () => {
const rows = catalogs.map(([label, relPath]) => {
const catalog = JSON.parse(fs.readFileSync(path.join(repoRoot, relPath), 'utf8'));
validateCatalog(label, relPath, catalog);
@@ -60,12 +58,6 @@ describe('avatar catalogs', () => {
});
const first = rows[0];
- for (const row of rows.slice(1)) {
- expect(
- row.normalized,
- `${row.label} (${row.relPath}) differs from ${first.label} (${first.relPath})`,
- ).toBe(first.normalized);
- }
expect(first.normalized.length).toBeGreaterThan(0);
});
});
diff --git a/test/main/core-regression.test.ts b/test/main/core-regression.test.ts
index e52fca15..80bb8aad 100644
--- a/test/main/core-regression.test.ts
+++ b/test/main/core-regression.test.ts
@@ -115,7 +115,7 @@ describe('PC core regression unit coverage', () => {
});
let entries = (await auth.listEntries()).entries;
- expect(entries.map((entry) => entry.profileId)).toEqual([primary.profileId, backup.profileId]);
+ expect(entries.map((entry) => entry.profileId)).toEqual([backup.profileId, primary.profileId]);
await auth.reorderEntries([second.entryId, first.entryId]);
entries = (await auth.listEntries()).entries;
expect(entries.map((entry) => entry.entryId)).toEqual([second.entryId, first.entryId]);
@@ -141,7 +141,8 @@ describe('PC core regression unit coverage', () => {
expect((await auth.listEntries()).entries.map((entry) => entry.profileId)).toEqual([backup.profileId]);
const raw = fs.readFileSync(paths.userAuthProfilesFile(TEST_UID), 'utf8');
- expect(raw).toMatch(/^ORKLSEC1:/);
+ const localSecrets = await import('../../src/main/util/local-secret-store');
+ expect(localSecrets.isEncryptedSecret(raw)).toBe(true);
expect(raw).not.toContain('sk-primary-regression-xxxxxxxx');
expect(raw).not.toContain('sk-backup-regression-xxxxxxxx');
expect(raw).not.toContain('tvly-regression-secret');
diff --git a/test/main/features/agents.test.ts b/test/main/features/agents.test.ts
index 66d61207..8ab46ffa 100644
--- a/test/main/features/agents.test.ts
+++ b/test/main/features/agents.test.ts
@@ -1454,32 +1454,24 @@ describe('agents › list cache invalidation', () => {
expect(list[0].name).toBe('V2');
});
- it('updates marketplace agent spec in dev', async () => {
- const prevDevtools = process.env.ORKAS_DEVTOOLS;
- process.env.ORKAS_DEVTOOLS = '1';
- try {
- const dir = path.join(builtinAgentsDir(), 'platform-agent');
- fs.mkdirSync(dir, { recursive: true });
- fs.writeFileSync(path.join(dir, 'agent.json'), JSON.stringify({
- agent_id: 'platform-agent',
- name: 'OldPlatformAgent',
- description: '',
- workflow: '',
- }));
-
- const dev = await import('../../../src/main/features/agents_dev');
- const updated = await dev.updateBuiltinAgentSpec('platform-agent', { name: 'RenamedPlatformAgent' });
-
- expect(updated?.name).toBe('RenamedPlatformAgent');
- expect(JSON.parse(fs.readFileSync(path.join(dir, 'agent.json'), 'utf8')).name)
- .toBe('RenamedPlatformAgent');
- const a = await loadAgents();
- expect((await a.listAgents()).find((x) => x.agent_id === 'platform-agent')?.name)
- .toBe('RenamedPlatformAgent');
- } finally {
- if (prevDevtools === undefined) delete process.env.ORKAS_DEVTOOLS;
- else process.env.ORKAS_DEVTOOLS = prevDevtools;
- }
+ it('keeps marketplace agent specs read-only through the custom edit path', async () => {
+ const dir = path.join(builtinAgentsDir(), 'platform-agent');
+ fs.mkdirSync(dir, { recursive: true });
+ fs.writeFileSync(path.join(dir, 'agent.json'), JSON.stringify({
+ agent_id: 'platform-agent',
+ name: 'OldPlatformAgent',
+ description: '',
+ workflow: '',
+ }));
+
+ const a = await loadAgents();
+ const updated = await a.updateCustomAgent('platform-agent', { name: 'RenamedPlatformAgent' });
+
+ expect(updated).toBeNull();
+ expect(JSON.parse(fs.readFileSync(path.join(dir, 'agent.json'), 'utf8')).name)
+ .toBe('OldPlatformAgent');
+ expect((await a.listAgents()).find((x) => x.agent_id === 'platform-agent')?.name)
+ .toBe('OldPlatformAgent');
});
it('cache-only invalidator picks up marketplace file rewrites', async () => {
diff --git a/test/main/features/auth.test.ts b/test/main/features/auth.test.ts
index 9ea39664..3694f517 100644
--- a/test/main/features/auth.test.ts
+++ b/test/main/features/auth.test.ts
@@ -141,19 +141,21 @@ describe('auth › multi-profile store (addApiKey / removeCredential / renamePro
it('stores auth-profiles with the local-secret facade', async () => {
const a = await import('../../../src/main/features/auth');
const paths = await import('../../../src/main/paths');
+ const localSecrets = await import('../../../src/main/util/local-secret-store');
await a.addApiKey('openai', 'sk-local-secret-xxxxxxxx');
const raw = fs.readFileSync(paths.userAuthProfilesFile(TEST_UID), 'utf8');
- expect(raw).toMatch(/^ORKLSEC1:/);
+ expect(localSecrets.isEncryptedSecret(raw)).toBe(true);
expect(raw).not.toContain('sk-local-secret-xxxxxxxx');
});
- it('uses the account uid, not the local directory id, as the auth-profiles secret owner when logged in', async () => {
+ it('uses account.json user_id as the auth-profiles secret owner when present', async () => {
const accountUid = 'A0653F11-9F05-4A8B-89CE-0026D809EAFC';
- const tokenStore = await import('../../../src/main/features/account/token_store');
- tokenStore.setSession({ user_id: accountUid, session_id: 'session-1' });
+ const paths = await import('../../../src/main/paths');
+ const accountFile = path.join(paths.userLocalConfigDir(TEST_UID), 'account.json');
+ fs.mkdirSync(path.dirname(accountFile), { recursive: true });
+ fs.writeFileSync(accountFile, JSON.stringify({ user_id: accountUid }), 'utf8');
const a = await import('../../../src/main/features/auth');
- const paths = await import('../../../src/main/paths');
const localSecrets = await import('../../../src/main/util/local-secret-store');
await a.addApiKey('openai', 'sk-account-owner-xxxxxxxx');
@@ -171,10 +173,13 @@ describe('auth › multi-profile store (addApiKey / removeCredential / renamePro
expect(json).toContain('sk-account-owner-xxxxxxxx');
});
- it('rewrites local-id-owned auth-profiles to the account uid on read', async () => {
+ it('rewrites local-id-owned auth-profiles to the account.json uid on read', async () => {
const accountUid = 'A0653F11-9F05-4A8B-89CE-0026D809EAFC';
const paths = await import('../../../src/main/paths');
const localSecrets = await import('../../../src/main/util/local-secret-store');
+ const accountFile = path.join(paths.userLocalConfigDir(TEST_UID), 'account.json');
+ fs.mkdirSync(path.dirname(accountFile), { recursive: true });
+ fs.writeFileSync(accountFile, JSON.stringify({ user_id: accountUid }), 'utf8');
const file = paths.userAuthProfilesFile(TEST_UID);
fs.mkdirSync(path.dirname(file), { recursive: true });
fs.writeFileSync(file, localSecrets.encryptLocalSecret({
@@ -198,8 +203,6 @@ describe('auth › multi-profile store (addApiKey / removeCredential / renamePro
imageProfiles: [],
})), 'utf8');
- const tokenStore = await import('../../../src/main/features/account/token_store');
- tokenStore.setSession({ user_id: accountUid, session_id: 'session-1' });
const a = await import('../../../src/main/features/auth');
const { providers } = await a.listProviders();
expect(providers.find((p) => p.id === 'openai')?.profiles[0]?.masked).toBe('sk-l…xxxx');
@@ -239,7 +242,9 @@ describe('auth › multi-profile store (addApiKey / removeCredential / renamePro
const { providers } = await a.listProviders();
expect(providers.find((p) => p.id === 'openai')?.profiles[0]?.masked).toBe('sk-l…xxxx');
const raw = fs.readFileSync(file, 'utf8');
- expect(raw).toMatch(/^ORKLSEC1:/);
+ const localSecrets = await import('../../../src/main/util/local-secret-store');
+ expect(localSecrets.isEncryptedSecret(raw)).toBe(true);
+ expect(() => cryptoVault.decrypt(TEST_UID, raw)).toThrow();
expect(raw).not.toContain('sk-legacy-xxxxxxxx');
});
diff --git a/test/main/features/client_config.test.ts b/test/main/features/client_config.test.ts
index 51141028..9abde03e 100644
--- a/test/main/features/client_config.test.ts
+++ b/test/main/features/client_config.test.ts
@@ -290,7 +290,6 @@ describe('client_config', () => {
const now = 1_234_567;
vi.spyOn(Date, 'now').mockReturnValue(now);
- process.env.ORKAS_API_BASE_URL = 'https://config.example/api/';
let requestedUrl = '';
let requestedInit: RequestInit | undefined;
vi.stubGlobal('fetch', async (input: string | URL | Request, init?: RequestInit) => {
@@ -312,10 +311,10 @@ describe('client_config', () => {
expect(result).toEqual({ updated: true });
const url = new URL(requestedUrl);
- expect(url.origin + url.pathname).toBe('https://config.example/api/config/client');
+ expect(url.origin + url.pathname).toBe('https://orkas.ai/api/config/client');
expect(url.searchParams.get('platform')).toBe(clientConfigPlatform());
expect(url.searchParams.get('version')).toBe('9.8.7');
- expect(url.searchParams.get('channel')).toBe('dev');
+ expect(url.searchParams.get('channel')).toBe('open');
expect(url.searchParams.get('region')).toBe('global');
expect(url.searchParams.get('os')).toBe(process.platform);
expect(url.searchParams.get('arch')).toBe(process.arch);
diff --git a/test/main/features/connectors/oauth-dcr.test.ts b/test/main/features/connectors/oauth-dcr.test.ts
index 475dbff5..0b967168 100644
--- a/test/main/features/connectors/oauth-dcr.test.ts
+++ b/test/main/features/connectors/oauth-dcr.test.ts
@@ -3,18 +3,18 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
const electronMock = vi.hoisted(() => ({
openExternal: vi.fn(async () => undefined),
}));
+const OSS_API_BASE = vi.hoisted(() => 'https://orkas.ai/api');
vi.mock('electron', () => ({
shell: { openExternal: electronMock.openExternal },
}));
-vi.mock('../../../../src/main/features/account/server', () => ({
- accountApiBase: () => 'https://account.example/api',
-}));
-
-vi.mock('../../../../src/main/features/account/token_store', () => ({
- getDeviceId: () => 'device-1',
- authHeaders: () => ({ user_id: 'uid-1', session_id: 'sid-1' }),
+vi.mock('../../../../src/main/features/connectors/_server_bridge', () => ({
+ accountApiBase: () => OSS_API_BASE,
+ tokenStore: {
+ getDeviceId: () => 'device-1',
+ authHeaders: () => ({}),
+ },
}));
vi.mock('../../../../src/main/features/config', () => ({
@@ -70,7 +70,7 @@ describe('features/connectors/oauth-dcr', () => {
}
if (String(url) === 'https://auth.notion.example/register') {
const body = JSON.parse(String(init?.body || '{}'));
- expect(body.redirect_uris).toEqual(['https://account.example/api/connectors/oauth/dcr-callback']);
+ expect(body.redirect_uris).toEqual([`${OSS_API_BASE}/connectors/oauth/dcr-callback`]);
expect(body.grant_types).toContain('authorization_code');
return jsonResponse({ client_id: 'client-1', client_secret: 'secret-1' });
}
@@ -88,7 +88,7 @@ describe('features/connectors/oauth-dcr', () => {
expect(opened.href.startsWith('https://auth.notion.example/authorize?')).toBe(true);
expect(opened.searchParams.get('response_type')).toBe('code');
expect(opened.searchParams.get('client_id')).toBe('client-1');
- expect(opened.searchParams.get('redirect_uri')).toBe('https://account.example/api/connectors/oauth/dcr-callback');
+ expect(opened.searchParams.get('redirect_uri')).toBe(`${OSS_API_BASE}/connectors/oauth/dcr-callback`);
expect(opened.searchParams.get('resource')).toBe('https://mcp.notion.example/mcp');
expect(opened.searchParams.get('code_challenge_method')).toBe('S256');
expect(opened.searchParams.get('code_challenge')).toBeTruthy();
@@ -114,7 +114,7 @@ describe('features/connectors/oauth-dcr', () => {
if (String(url) === 'https://auth.notion.example/register') {
return jsonResponse({ client_id: 'client-1', client_secret: 'secret-1' });
}
- if (String(url) === 'https://account.example/api/connectors/oauth/dcr-exchange') {
+ if (String(url) === `${OSS_API_BASE}/connectors/oauth/dcr-exchange`) {
const body = JSON.parse(String(init?.body || '{}'));
expect(body.exchange_code).toBe('exchange-1');
return jsonResponse({ code: 0, oauth_code: 'provider-code', oauth_state: 'wrong-state' });
@@ -156,7 +156,7 @@ describe('features/connectors/oauth-dcr', () => {
if (String(url) === 'https://auth.notion.example/register') {
return jsonResponse({ client_id: 'client-1', client_secret: 'secret-1' });
}
- if (String(url) === 'https://account.example/api/connectors/oauth/dcr-exchange') {
+ if (String(url) === `${OSS_API_BASE}/connectors/oauth/dcr-exchange`) {
return jsonResponse({ code: 0, oauth_code: 'provider-code', oauth_state: openedState });
}
if (String(url) === 'https://auth.notion.example/token') {
@@ -171,13 +171,13 @@ describe('features/connectors/oauth-dcr', () => {
scope: 'read write',
});
}
- if (String(url) === 'https://account.example/api/connectors/oauth/dcr-store') {
+ if (String(url) === `${OSS_API_BASE}/connectors/oauth/dcr-store`) {
const body = JSON.parse(String(init?.body || '{}'));
expect(body.provider).toBe('notion');
expect(body.refresh_token).toBe('refresh-local');
expect(body.dcr_client.client_id).toBe('client-1');
expect(body.dcr_client.client_secret).toBe('secret-1');
- expect((init?.headers as Record<string, string>).user_id).toBe('uid-1');
+ expect((init?.headers as Record<string, string>).user_id).toBeUndefined();
return jsonResponse({
code: 0,
access_token: 'access-server',
@@ -262,7 +262,7 @@ describe('features/connectors/oauth-dcr', () => {
if (fetchMock.mock.calls.length === 1) {
throw new TypeError('fetch failed');
}
- expect(String(url)).toBe('https://account.example/api/connectors/oauth/refresh');
+ expect(String(url)).toBe(`${OSS_API_BASE}/connectors/oauth/refresh`);
const body = JSON.parse(String(init.body));
expect(body.provider).toBe('notion');
expect(body.grant_id).toBe('grant-1');
diff --git a/test/main/features/connectors/oauth-github-server-managed.test.ts b/test/main/features/connectors/oauth-github-server-managed.test.ts
index 73cdd22b..5cf7ce94 100644
--- a/test/main/features/connectors/oauth-github-server-managed.test.ts
+++ b/test/main/features/connectors/oauth-github-server-managed.test.ts
@@ -17,6 +17,14 @@ vi.mock('../../../../src/main/features/account/token_store', () => ({
authHeaders: () => ({ user_id: 'uid-1', session_id: 'sid-1' }),
}));
+vi.mock('../../../../src/main/features/connectors/_server_bridge', () => ({
+ accountApiBase: () => 'https://orkas.ai/api',
+ tokenStore: {
+ getDeviceId: () => 'dev-1',
+ authHeaders: () => ({}),
+ },
+}));
+
vi.mock('../../../../src/main/features/config', () => ({
getLanguage: () => 'zh',
}));
@@ -118,7 +126,7 @@ describe('connector OAuth GitHub server-managed grants', () => {
expect(body.refresh_token).toBe('ghr-old');
expect(body.access_token).toBe('ghu-old');
expect(body.grant_id).toBeUndefined();
- expect((init.headers as Record<string, string>).user_id).toBe('uid-1');
+ expect((init.headers as Record<string, string>).user_id).toBeUndefined();
});
it('does not call the server when an existing server-managed GitHub token is fresh', async () => {
diff --git a/test/main/features/connectors/oauth.test.ts b/test/main/features/connectors/oauth.test.ts
index 51db2c27..1ce2221b 100644
--- a/test/main/features/connectors/oauth.test.ts
+++ b/test/main/features/connectors/oauth.test.ts
@@ -17,6 +17,13 @@ beforeEach(() => {
getDeviceId: () => 'device-1',
authHeaders: () => ({}),
}));
+ vi.doMock('../../../../src/main/features/connectors/_server_bridge', () => ({
+ accountApiBase: () => 'https://orkas.ai/api',
+ tokenStore: {
+ getDeviceId: () => 'device-1',
+ authHeaders: () => ({}),
+ },
+ }));
vi.doMock('../../../../src/main/features/config', () => ({
getLanguage: () => 'en',
}));
@@ -27,6 +34,7 @@ afterEach(() => {
vi.doUnmock('electron');
vi.doUnmock('../../../../src/main/features/account/server');
vi.doUnmock('../../../../src/main/features/account/token_store');
+ vi.doUnmock('../../../../src/main/features/connectors/_server_bridge');
vi.doUnmock('../../../../src/main/features/config');
});
@@ -109,7 +117,7 @@ describe('features/connectors/oauth', () => {
const pending = oauth.startGoogleSheetsPicker(['sheet-1']);
expect(shell.openExternal).toHaveBeenCalledTimes(1);
const opened = new URL((shell.openExternal as unknown as ReturnType<typeof vi.fn>).mock.calls[0][0]);
- expect(opened.pathname).toBe('/connectors/oauth/google/picker/start');
+ expect(opened.pathname).toBe('/api/connectors/oauth/google/picker/start');
expect(opened.searchParams.get('catalog_id')).toBe('gsheets');
expect(opened.searchParams.get('file_ids')).toBe('sheet-1');
diff --git a/test/main/features/connectors/registry-secret-store.test.ts b/test/main/features/connectors/registry-secret-store.test.ts
index 524afea2..77cb2059 100644
--- a/test/main/features/connectors/registry-secret-store.test.ts
+++ b/test/main/features/connectors/registry-secret-store.test.ts
@@ -57,9 +57,10 @@ describe('connectors registry secret storage', () => {
const raw = fs.readFileSync(paths.userConnectorsConfigFile(TEST_UID), 'utf8');
expect(raw).not.toContain('access-secret');
expect(raw).not.toContain('refresh-secret');
+ const localSecrets = await import('../../../../src/main/util/local-secret-store');
const disk = JSON.parse(raw);
expect(disk.connections.github.oauth_grant).toBeUndefined();
- expect(String(disk.connections.github.secrets_enc)).toMatch(/^ORKLSEC1:/);
+ expect(localSecrets.isEncryptedSecret(String(disk.connections.github.secrets_enc))).toBe(true);
const loaded = registry.load(TEST_UID);
expect(loaded.connections.github.oauth_grant?.access_token).toBe('access-secret');
@@ -89,7 +90,9 @@ describe('connectors registry secret storage', () => {
expect(loaded.connections.github.oauth_grant?.refresh_token).toBe('refresh-secret');
const migrated = JSON.parse(fs.readFileSync(file, 'utf8'));
- expect(String(migrated.connections.github.secrets_enc)).toMatch(/^ORKLSEC1:/);
+ const localSecrets = await import('../../../../src/main/util/local-secret-store');
+ expect(localSecrets.isEncryptedSecret(String(migrated.connections.github.secrets_enc))).toBe(true);
+ expect(() => cryptoVault.decrypt(TEST_UID, String(migrated.connections.github.secrets_enc))).toThrow();
expect(JSON.stringify(migrated)).not.toContain('refresh-secret');
});
});
diff --git a/test/main/features/group_chat/bus.test.ts b/test/main/features/group_chat/bus.test.ts
index dc3de165..b961a54e 100644
--- a/test/main/features/group_chat/bus.test.ts
+++ b/test/main/features/group_chat/bus.test.ts
@@ -293,24 +293,19 @@ describe('group_chat bus › enqueue routing + persistence', () => {
expect(bus._cidStateForTest(TEST_UID, cid)?.producedPaths.has(finalPath)).toBe(true);
});
- it('auto-closes sync conflicts from a structured XML result', async () => {
+ it('ignores structured sync conflict results in the open build', async () => {
const bus = await import('../../../../src/main/features/group_chat/bus');
const paths = await import('../../../../src/main/paths');
const state = await import('../../../../src/main/features/group_chat/state');
- const conflicts = await import('../../../../src/main/features/sync/conflicts');
const cid = 'cid-sync-conflict-xml';
const relPath = 'cloud/memory/CONFLICT.md';
const currentPath = path.join(paths.userCloudRoot(TEST_UID), 'memory', 'CONFLICT.md');
fs.mkdirSync(path.dirname(currentPath), { recursive: true });
fs.writeFileSync(currentPath, 'initial current');
- const entry = await conflicts.archiveConflict(TEST_UID, relPath, 'local', 'cloud', {
- kind: 'binary',
- currentSide: 'local',
- nowMs: Date.UTC(2026, 5, 10, 1, 0, 0),
- });
+ const conflictId = 'conflict-xml-1';
await state.setToolExtraRoots(TEST_UID, cid, [path.dirname(currentPath)]);
await state.setSyncConflictResolution(TEST_UID, cid, [{
- id: entry.id,
+ id: conflictId,
rel_path: relPath,
current_path: currentPath,
}]);
@@ -320,7 +315,7 @@ describe('group_chat bus › enqueue routing + persistence', () => {
cid,
fromActorId: 'user',
text: `SYNC_CONFLICT_XML_RESULT:${Buffer.from(JSON.stringify({
- conflictId: entry.id,
+ conflictId,
relPath,
targetPath: currentPath,
status: 'resolved',
@@ -330,7 +325,8 @@ describe('group_chat bus › enqueue routing + persistence', () => {
await waitForQuiescent(TEST_UID, cid);
expect(fs.readFileSync(currentPath, 'utf8')).toBe('initial current');
- expect(await conflicts.listConflicts(TEST_UID)).toEqual([]);
+ expect((await state.readState(TEST_UID, cid)).sync_conflict_resolution?.conflicts)
+ .toEqual([{ id: conflictId, rel_path: relPath, current_path: currentPath }]);
});
// `isQuiescent` reflects the in-memory queue/running state — exercised
diff --git a/test/main/features/marketplace_defaults.test.ts b/test/main/features/marketplace_defaults.test.ts
index bb429635..9e649e60 100644
--- a/test/main/features/marketplace_defaults.test.ts
+++ b/test/main/features/marketplace_defaults.test.ts
@@ -42,9 +42,22 @@ afterEach(async () => {
else process.env.ORKAS_API_BASE_URL = prevApi;
if (prevProfile === undefined) delete process.env.ORKAS_PROFILE;
else process.env.ORKAS_PROFILE = prevProfile;
+ vi.unstubAllGlobals();
fs.rmSync(tmpDir, { recursive: true, force: true });
});
+function jsonResponse(body: unknown, status = 200): Response {
+ return new Response(JSON.stringify(body), {
+ status,
+ headers: { 'Content-Type': 'application/json' },
+ });
+}
+
+function routeOf(input: string | URL | Request): string {
+ const url = new URL(String(input));
+ return `${url.origin}${url.pathname}`;
+}
+
describe('marketplace default installs', () => {
it('uses bare production API domains so POST requests are not downgraded by www redirects', async () => {
delete process.env.ORKAS_API_BASE_URL;
@@ -57,10 +70,10 @@ describe('marketplace default installs', () => {
process.env.ORKAS_PROFILE = 'cn';
vi.resetModules();
marketplace = await import('../../../src/main/features/marketplace');
- expect(marketplace.apiBase()).toBe('https://orkas.work/api');
+ expect(marketplace.apiBase()).toBe('https://orkas.ai/api');
});
- it('canonicalizes www API env overrides before marketplace POST requests', async () => {
+ it('ignores API env overrides before marketplace POST requests', async () => {
process.env.ORKAS_API_BASE_URL = `https://${'www.'}orkas.ai/api/`;
vi.resetModules();
@@ -87,19 +100,18 @@ describe('marketplace default installs', () => {
});
it('installs legacy marketplace skills when only _meta category advisories are present', async () => {
- process.env.ORKAS_API_BASE_URL = await listen((req, res) => {
- expect(req.method).toBe('POST');
- expect(req.url).toBe('/api/marketplace/skills/bundle');
- res.setHeader('Content-Type', 'application/json');
- res.end(JSON.stringify({
+ vi.stubGlobal('fetch', vi.fn(async (input: string | URL | Request, init?: RequestInit) => {
+ expect(init?.method).toBe('POST');
+ expect(routeOf(input)).toBe('https://orkas.ai/api/marketplace/skills/bundle');
+ return jsonResponse({
code: 0,
bundle_url: 'https://cdn.test/legacy-skill.zip',
version: '1.0.0',
published_at: 10,
create_uid: '0',
status: 'approved',
- }));
- });
+ });
+ }));
const users = await import('../../../src/main/features/users');
users.activateUser('u1');
@@ -133,19 +145,18 @@ describe('marketplace default installs', () => {
});
it('returns only blocking quality findings in marketplace install rejection details', async () => {
- process.env.ORKAS_API_BASE_URL = await listen((req, res) => {
- expect(req.method).toBe('POST');
- expect(req.url).toBe('/api/marketplace/skills/bundle');
- res.setHeader('Content-Type', 'application/json');
- res.end(JSON.stringify({
+ vi.stubGlobal('fetch', vi.fn(async (input: string | URL | Request, init?: RequestInit) => {
+ expect(init?.method).toBe('POST');
+ expect(routeOf(input)).toBe('https://orkas.ai/api/marketplace/skills/bundle');
+ return jsonResponse({
code: 0,
bundle_url: 'https://cdn.test/unsafe-skill.zip',
version: '1.0.0',
published_at: 10,
create_uid: '0',
status: 'approved',
- }));
- });
+ });
+ }));
const users = await import('../../../src/main/features/users');
users.activateUser('u1');
@@ -281,13 +292,12 @@ describe('marketplace default installs', () => {
it('reports transient default seed failures so logged-in startup can retry', async () => {
let calls = 0;
- process.env.ORKAS_API_BASE_URL = await listen((req, res) => {
+ vi.stubGlobal('fetch', vi.fn(async (input: string | URL | Request, init?: RequestInit) => {
calls++;
- expect(req.method).toBe('POST');
- expect(req.url).toBe('/api/marketplace/defaults');
- res.setHeader('Content-Type', 'application/json');
- res.end(JSON.stringify({ code: 1, msg: '系统繁忙,请稍后重试' }));
- });
+ expect(init?.method).toBe('POST');
+ expect(routeOf(input)).toBe('https://orkas.ai/api/marketplace/defaults');
+ return jsonResponse({ code: 1, msg: '系统繁忙,请稍后重试' });
+ }));
const users = await import('../../../src/main/features/users');
users.activateUser('u1');
@@ -303,10 +313,10 @@ describe('marketplace default installs', () => {
});
it('incrementally seeds new defaults while respecting installed rows and uninstall tombstones', async () => {
- process.env.ORKAS_API_BASE_URL = await listen((req, res) => {
- if (req.method === 'POST' && req.url === '/api/marketplace/defaults') {
- res.setHeader('Content-Type', 'application/json');
- res.end(JSON.stringify({
+ vi.stubGlobal('fetch', vi.fn(async (input: string | URL | Request, init?: RequestInit) => {
+ const route = routeOf(input);
+ if (init?.method === 'POST' && route === 'https://orkas.ai/api/marketplace/defaults') {
+ return jsonResponse({
code: 0,
agents: [{
id: 'agent-new',
@@ -368,57 +378,42 @@ describe('marketplace default installs', () => {
status: 'approved',
},
],
- }));
- return;
+ });
}
- if (req.method === 'POST' && req.url === '/api/marketplace/agents/detail') {
- let raw = '';
- req.on('data', (chunk) => { raw += chunk; });
- req.on('end', () => {
- const body = JSON.parse(raw || '{}');
- res.setHeader('Content-Type', 'application/json');
- if (body.id === 'agent-failing') {
- res.end(JSON.stringify({ code: 1, msg: 'temporary detail failure' }));
- return;
- }
- res.end(JSON.stringify({
- code: 0,
- agent_json: {
- name: body.id,
- skill_list: body.id === 'agent-blocked' ? ['skill-deleted'] : ['skill-dep'],
- },
- version: '1.0.0',
- category: 'general',
- published_at: 10,
- agent_json_url: `https://cdn.test/${body.id}.json`,
- create_uid: '0',
- status: 'approved',
- }));
+ if (init?.method === 'POST' && route === 'https://orkas.ai/api/marketplace/agents/detail') {
+ const body = JSON.parse(String(init.body || '{}'));
+ if (body.id === 'agent-failing') {
+ return jsonResponse({ code: 1, msg: 'temporary detail failure' });
+ }
+ return jsonResponse({
+ code: 0,
+ agent_json: {
+ name: body.id,
+ skill_list: body.id === 'agent-blocked' ? ['skill-deleted'] : ['skill-dep'],
+ },
+ version: '1.0.0',
+ category: 'general',
+ published_at: 10,
+ agent_json_url: `https://cdn.test/${body.id}.json`,
+ create_uid: '0',
+ status: 'approved',
});
- return;
}
- if (req.method === 'POST' && req.url === '/api/marketplace/skills/bundle') {
- let raw = '';
- req.on('data', (chunk) => { raw += chunk; });
- req.on('end', () => {
- const body = JSON.parse(raw || '{}');
- res.setHeader('Content-Type', 'application/json');
- res.end(JSON.stringify({
- code: 0,
- bundle_url: `https://cdn.test/${body.id}.zip`,
- version: '1.0.0',
- published_at: 70,
- updated_at: 80,
- create_uid: '0',
- status: 'approved',
- default_install: false,
- }));
+ if (init?.method === 'POST' && route === 'https://orkas.ai/api/marketplace/skills/bundle') {
+ const body = JSON.parse(String(init.body || '{}'));
+ return jsonResponse({
+ code: 0,
+ bundle_url: `https://cdn.test/${body.id}.zip`,
+ version: '1.0.0',
+ published_at: 70,
+ updated_at: 80,
+ create_uid: '0',
+ status: 'approved',
+ default_install: false,
});
- return;
}
- res.statusCode = 404;
- res.end('not found');
- });
+ return jsonResponse({ code: 1, msg: `unexpected route ${route}` }, 404);
+ }));
const users = await import('../../../src/main/features/users');
users.activateUser('u1');
diff --git a/test/main/features/skills.test.ts b/test/main/features/skills.test.ts
index 8e994f92..50dab7bb 100644
--- a/test/main/features/skills.test.ts
+++ b/test/main/features/skills.test.ts
@@ -798,30 +798,20 @@ describe('skills › listSkills', () => {
expect(found?.default_install).toBe(true);
});
- it('updates marketplace skill display name in dev without renaming install dir', async () => {
- const prevDevtools = process.env.ORKAS_DEVTOOLS;
- process.env.ORKAS_DEVTOOLS = '1';
- try {
- const dir = path.join(builtinSkillsDir(), 'platform-excel');
- fs.mkdirSync(dir, { recursive: true });
- fs.writeFileSync(path.join(dir, 'SKILL.md'),
- '---\nname: "Old platform skill"\ndescription: "platform"\n---\n\nUse when editing spreadsheets.\n');
+ it('keeps marketplace skill metadata read-only through the edit path', async () => {
+ const dir = path.join(builtinSkillsDir(), 'platform-excel');
+ fs.mkdirSync(dir, { recursive: true });
+ fs.writeFileSync(path.join(dir, 'SKILL.md'),
+ '---\nname: "Old platform skill"\ndescription: "platform"\n---\n\nUse when editing spreadsheets.\n');
- const s = await loadSkills();
- const result = await s.applySkillMetadataForEdit('platform-excel', { name: 'Excel / XLSX' });
-
- expect(result.ok).toBe(true);
- expect(result.skillId).toBe('platform-excel');
- expect(fs.existsSync(dir)).toBe(true);
- expect(fs.existsSync(path.join(builtinSkillsDir(), 'Excel / XLSX'))).toBe(false);
- const after = fs.readFileSync(path.join(dir, 'SKILL.md'), 'utf8');
- expect(s.parseSkillFrontmatter(after).name).toBe('Excel / XLSX');
- expect((await s.listSkills()).find((x) => x.id === 'platform-excel')?.name)
- .toBe('Excel / XLSX');
- } finally {
- if (prevDevtools === undefined) delete process.env.ORKAS_DEVTOOLS;
- else process.env.ORKAS_DEVTOOLS = prevDevtools;
- }
+ const s = await loadSkills();
+ const result = await s.applySkillMetadataForEdit('platform-excel', { name: 'Excel / XLSX' });
+
+ expect(result.ok).toBe(false);
+ expect(result.reason).toBeUndefined();
+ expect(fs.existsSync(dir)).toBe(true);
+ const after = fs.readFileSync(path.join(dir, 'SKILL.md'), 'utf8');
+ expect(s.parseSkillFrontmatter(after).name).toBe('Old platform skill');
});
it('cache-only invalidator picks up marketplace file rewrites', async () => {
diff --git a/test/main/features/sync-login-guard.test.ts b/test/main/features/sync-login-guard.test.ts
index 6b4c23db..6b2be69c 100644
--- a/test/main/features/sync-login-guard.test.ts
+++ b/test/main/features/sync-login-guard.test.ts
@@ -1,60 +1,11 @@
-import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+import { describe, expect, it } from 'vitest';
import * as fs from 'node:fs';
-import * as os from 'node:os';
import * as path from 'node:path';
-const syncEngineCtor = vi.hoisted(() => vi.fn());
-
-vi.mock('../../../src/main/features/sync/engine', () => ({
- SyncEngine: syncEngineCtor,
-}));
-
-let tmpDir: string;
-let prevWs: string | undefined;
-let prevAuth: string | undefined;
-
-beforeEach(() => {
- tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'orkas-sync-login-guard-'));
- prevWs = process.env.ORKAS_WORKSPACE_ROOT;
- prevAuth = process.env.CORE_AGENT_AUTH_DIR;
- process.env.ORKAS_WORKSPACE_ROOT = tmpDir;
- delete process.env.CORE_AGENT_AUTH_DIR;
- vi.resetModules();
- syncEngineCtor.mockReset();
- syncEngineCtor.mockImplementation(() => ({
- onStatus: vi.fn(() => () => {}),
- onUsage: vi.fn(() => () => {}),
- onDataChanged: vi.fn(() => () => {}),
- syncNow: vi.fn(async () => {}),
- refreshUsage: vi.fn(async () => {}),
- teardown: vi.fn(),
- }));
-});
-
-afterEach(() => {
- if (prevWs === undefined) delete process.env.ORKAS_WORKSPACE_ROOT;
- else process.env.ORKAS_WORKSPACE_ROOT = prevWs;
- if (prevAuth === undefined) delete process.env.CORE_AGENT_AUTH_DIR;
- else process.env.CORE_AGENT_AUTH_DIR = prevAuth;
- fs.rmSync(tmpDir, { recursive: true, force: true });
- vi.resetModules();
-});
-
describe('sync login guard', () => {
- it('does not start an engine when the requested account uid is no longer active', async () => {
- const users = await import('../../../src/main/features/users');
- const tokenStore = await import('../../../src/main/features/account/token_store');
- const localIndex = await import('../../../src/main/features/sync/local_index');
- const sync = await import('../../../src/main/features/sync');
-
- users.activateUser('account-user-1');
- tokenStore.setSession({ user_id: 'account-user-1', session_id: 'sid-secret' });
- localIndex.setStateEnabled('account-user-1', true);
-
- users.switchToAnonymousLocalId();
- await sync.init('account-user-1', 'account-user-1');
-
- expect(syncEngineCtor).not.toHaveBeenCalled();
- expect(sync.isRunning()).toBe(false);
+ it('does not ship the account-backed sync engine in the open build', () => {
+ const root = process.cwd();
+ expect(fs.existsSync(path.join(root, 'src', 'main', 'features', 'sync'))).toBe(false);
+ expect(fs.existsSync(path.join(root, 'src', 'main', 'features', 'account'))).toBe(false);
});
});
diff --git a/test/main/util/log-sanitize.test.ts b/test/main/util/log-sanitize.test.ts
index 0cee7ef4..981eecff 100644
--- a/test/main/util/log-sanitize.test.ts
+++ b/test/main/util/log-sanitize.test.ts
@@ -81,7 +81,7 @@ describe('sanitizeLogTextForUpload › set A (must be masked)', () => {
});
it('masks common provider token prefixes', () => {
- const out = sanitizeLogTextForUpload('key test-openai-key-redacted');
+ const out = sanitizeLogTextForUpload('key sk-testopenaiKeyredacted123');
expect(out).toBe('key ***TOKEN***');
});
diff --git a/test/main/util/migrate-connectors-to-cloud.test.ts b/test/main/util/migrate-connectors-to-cloud.test.ts
index f1e899d6..075e7050 100644
--- a/test/main/util/migrate-connectors-to-cloud.test.ts
+++ b/test/main/util/migrate-connectors-to-cloud.test.ts
@@ -2,12 +2,10 @@ import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
import * as fs from 'node:fs';
import * as os from 'node:os';
import * as path from 'node:path';
-import { createRequire } from 'node:module';
let tmpDir: string;
let prevWs: string | undefined;
const TEST_UID = 'u-connectors-migrate';
-const cjsRequire = createRequire(import.meta.url);
beforeEach(() => {
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'orkas-migrate-connectors-'));
@@ -43,13 +41,8 @@ describe('util/migrate-connectors-to-cloud', () => {
expect(fs.existsSync(stamp)).toBe(false);
});
- it('copies plaintext connector registry to cloud and removes the legacy local file', async () => {
+ it('keeps plaintext connector registry local in the open build', async () => {
const { paths, migration } = await loadMigration();
- const users = cjsRequire('../../../src/main/features/users') as typeof import('../../../src/main/features/users');
- const tokenStore = cjsRequire('../../../src/main/features/account/token_store') as typeof import('../../../src/main/features/account/token_store');
- users.activateUser(TEST_UID);
- tokenStore.setSession({ user_id: 'oauth-user-1', session_id: 'sid' });
-
const oldPath = path.join(paths.userLocalConfigDir(TEST_UID), 'connectors.json');
const newPath = path.join(paths.userCloudConfigDir(TEST_UID), 'connectors.json');
const stamp = path.join(paths.userCloudConfigDir(TEST_UID), '.migrate-connectors-to-cloud.done');
@@ -57,10 +50,10 @@ describe('util/migrate-connectors-to-cloud', () => {
fs.mkdirSync(path.dirname(oldPath), { recursive: true });
fs.writeFileSync(oldPath, body, 'utf8');
- expect(migration.migrateConnectorsToCloud(TEST_UID)).toBe(true);
+ expect(migration.migrateConnectorsToCloud(TEST_UID)).toBe(false);
- expect(fs.existsSync(oldPath)).toBe(false);
- expect(fs.readFileSync(newPath, 'utf8')).toBe(body);
- expect(fs.existsSync(stamp)).toBe(true);
+ expect(fs.readFileSync(oldPath, 'utf8')).toBe(body);
+ expect(fs.existsSync(newPath)).toBe(false);
+ expect(fs.existsSync(stamp)).toBe(false);
});
});
diff --git a/test/renderer/conversation-info.test.ts b/test/renderer/conversation-info.test.ts
index 070b29b9..d1bc14ab 100644
--- a/test/renderer/conversation-info.test.ts
+++ b/test/renderer/conversation-info.test.ts
@@ -227,7 +227,7 @@ describe('ConversationInfo files tab', () => {
expect(result.counts.files).toBe('1');
});
- it('shows a cloud-sync scope note above the file list when sync is enabled', async () => {
+ it('does not render the stripped cloud-sync scope note above the file list', async () => {
const html = await renderFilesHtml({
syncEnabled: true,
history: [],
@@ -248,8 +248,8 @@ describe('ConversationInfo files tab', () => {
},
});
- expect(html).toContain('ci-files-sync-note');
- expect(html).toContain('Cloud sync does not include these files');
+ expect(html).not.toContain('ci-files-sync-note');
+ expect(html).not.toContain('Cloud sync does not include these files');
});
});
diff --git a/test/renderer/ipc-shim.test.ts b/test/renderer/ipc-shim.test.ts
index 2cdee0fb..2c4ce082 100644
--- a/test/renderer/ipc-shim.test.ts
+++ b/test/renderer/ipc-shim.test.ts
@@ -64,6 +64,6 @@ describe('ipc-shim streams', () => {
const reader = res.body.getReader();
await expect(reader.read()).rejects.toThrow('boom');
- expect(monitorError).toHaveBeenCalledWith('ipc_stream', expect.any(Object));
+ expect(monitorError).not.toHaveBeenCalled();
});
});
diff --git a/test/setup-env.ts b/test/setup-env.ts
index d763734c..86ffdfed 100644
--- a/test/setup-env.ts
+++ b/test/setup-env.ts
@@ -29,6 +29,7 @@
import * as fs from 'node:fs';
import * as os from 'node:os';
import * as path from 'node:path';
+import { vi } from 'vitest';
// Register tsx/cjs so that any `require('./group_chat/bus')`-style CJS lookups
// (used inside features/chats.ts to break the bus ↔ chats import cycle without
@@ -42,3 +43,19 @@ if (!process.env.ORKAS_WORKSPACE_ROOT) {
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'orkas-vitest-'));
process.env.ORKAS_WORKSPACE_ROOT = tmp;
}
+
+// `activateUser()` starts session GC as a fire-and-forget startup task. In
+// full-suite Vitest runs, hundreds of isolated module graphs activate users
+// concurrently, and those late dynamic imports can race teardown. The sweep
+// itself is covered by its module contract; unit tests that merely need an
+// active uid should not inherit that background work.
+vi.mock('../src/main/features/sessions_sweep', () => ({
+ sweepSessions: vi.fn(async () => ({
+ scanned: 0,
+ orphan_cid: 0,
+ ephemeral_on_cloud: 0,
+ legacy: 0,
+ local_aged_out: 0,
+ errors: 0,
+ })),
+}));