Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
test: stabilize Fast sync handshake and auth imports
xuzini-xznfeca441ebfe7
diff --git a/apps/desktop/src/main/maker-host/__tests__/claudeAuthAdapterOAuthEnv.test.ts b/apps/desktop/src/main/maker-host/__tests__/claudeAuthAdapterOAuthEnv.test.tsindex a4163538dd..d86087f4d8 100644--- a/apps/desktop/src/main/maker-host/__tests__/claudeAuthAdapterOAuthEnv.test.ts+++ b/apps/desktop/src/main/maker-host/__tests__/claudeAuthAdapterOAuthEnv.test.ts@@ -119,6 +119,9 @@ vi.mock('../anthropic-compat-proxy-host.js', () => ({isAnthropicCompatProxyHandleReady: () => h.proxyReady,}));+// Load the adapter once during collection; keep cold transforms outside auth deadlines.+import * as mod from '../auth-adapters.js';+const CREDENTIAL_KEYS = ['ANTHROPIC_API_KEY','ANTHROPIC_AUTH_TOKEN',@@ -149,14 +152,13 @@ describe('DesktopClaudeAuthAdapter — Claude 订阅只经 CLI 自己的登录',it('keeps the owner-scoped BYOK key readable when Cindy gateway access is disabled', async () => {h.canUseGateway = false;- const { readClaudeApiKey, readOwnerScopedXdGatewayKey } = await import('../auth-adapters.js');+ const { readClaudeApiKey, readOwnerScopedXdGatewayKey } = mod;expect(readClaudeApiKey()).toBeNull();expect(readOwnerScopedXdGatewayKey()).toBe('sk-xd-gateway');});async function makeAdapter() {- const mod = await import('../auth-adapters.js');return new mod.DesktopClaudeAuthAdapter();}@@ -237,7 +239,6 @@ describe('DesktopClaudeAuthAdapter — Claude 订阅只经 CLI 自己的登录',it('未指定来源 + 无网关 key:非 Anthropic 模型不交给订阅,经 proxy 隐式桥(占位 key)', async () => {h.gatewayKey = null;- const mod = await import('../auth-adapters.js');const adapter = new mod.DesktopClaudeAuthAdapter();// 没有 authSource → maker-core 不按订阅会话起 CLI,仍设 proxy BASE_URL。await expect(adapter.getState({ model: 'glm-5' })).resolves.toEqual({ authenticated: true });@@ -289,7 +290,6 @@ describe('DesktopClaudeAuthAdapter — Claude 订阅只经 CLI 自己的登录',it('provider-oauth 模式:无网关 key / 订阅也可用,且只注入占位 key', async () => {h.nativeLogin = false;h.gatewayKey = null;- const mod = await import('../auth-adapters.js');const adapter = new mod.DesktopClaudeAuthAdapter();await expect(adapter.getState({ credentialMode: 'provider-oauth' })).resolves.toMatchObject({@@ -313,7 +313,6 @@ describe('DesktopClaudeAuthAdapter — Claude 订阅只经 CLI 自己的登录',});it('getOneShotAuth:连了订阅时 host 直连请求固定走网关 key,绝不用订阅', async () => {- const mod = await import('../auth-adapters.js');const adapter = new mod.DesktopClaudeAuthAdapter();await expect(adapter.getOneShotAuth()).resolves.toMatchObject({ apiKey: 'sk-xd-gateway' });h.nativeLogin = false;diff --git a/apps/desktop/src/main/maker-host/__tests__/codexAuthBindingClaim.test.ts b/apps/desktop/src/main/maker-host/__tests__/codexAuthBindingClaim.test.tsindex 37742e76be..76ff84510b 100644--- a/apps/desktop/src/main/maker-host/__tests__/codexAuthBindingClaim.test.ts+++ b/apps/desktop/src/main/maker-host/__tests__/codexAuthBindingClaim.test.ts@@ -61,6 +61,9 @@ vi.mock('../../appSessionState.js', async (importOriginal) => {};});+// Load the adapter once during collection; keep cold transforms outside claim deadlines.+import { DesktopCodexAuthAdapter } from '../auth-adapters.js';+function fixture(): {codexHome: string;systemAuth: string;@@ -122,7 +125,6 @@ describe('codex OAuth binding auto-claim on reconcile', () => {const { bindingFile } = fixture();h.dataOwnerId = 'owner-a';writeStableProjectionOwner('owner-a');- const { DesktopCodexAuthAdapter } = await import('../auth-adapters.js');const adapter = new DesktopCodexAuthAdapter();await expect(adapter.getState()).resolves.toMatchObject({@@ -143,7 +145,6 @@ describe('codex OAuth binding auto-claim on reconcile', () => {fs.writeFileSync(bindingFile, JSON.stringify({ legacyClaimOwner: 'owner-a' }));h.dataOwnerId = 'owner-a';writeStableProjectionOwner('owner-a');- const { DesktopCodexAuthAdapter } = await import('../auth-adapters.js');const adapter = new DesktopCodexAuthAdapter();await expect(adapter.getState()).resolves.toMatchObject({@@ -164,7 +165,6 @@ describe('codex OAuth binding auto-claim on reconcile', () => {);h.dataOwnerId = 'owner-b';writeStableProjectionOwner('owner-b');- const { DesktopCodexAuthAdapter } = await import('../auth-adapters.js');const adapter = new DesktopCodexAuthAdapter();await expect(adapter.getState()).resolves.toEqual({@@ -192,7 +192,6 @@ describe('codex OAuth binding auto-claim on reconcile', () => {).toBe(true);h.dataOwnerId = 'owner-a';writeStableProjectionOwner('owner-a');- const { DesktopCodexAuthAdapter } = await import('../auth-adapters.js');const adapter = new DesktopCodexAuthAdapter();await expect(adapter.getState()).resolves.toMatchObject({ authenticated: false });@@ -205,7 +204,6 @@ describe('codex OAuth binding auto-claim on reconcile', () => {const { bindingFile } = fixture();h.dataOwnerId = 'owner-a';writeStableProjectionOwner('owner-a');- const { DesktopCodexAuthAdapter } = await import('../auth-adapters.js');const adapter = new DesktopCodexAuthAdapter();// getState 的同步段捕获 sessionAtStart(owner-a);首个 await 挂起后切到 owner-b。@@ -224,7 +222,6 @@ describe('codex OAuth binding auto-claim on reconcile', () => {const { bindingFile } = fixture();h.dataOwnerId = 'owner-a';writeStableProjectionOwner('owner-a');- const { DesktopCodexAuthAdapter } = await import('../auth-adapters.js');const adapter = new DesktopCodexAuthAdapter();const claimed = vi.fn();adapter.setOnOAuthBindingClaimed(claimed);@@ -246,7 +243,6 @@ describe('codex OAuth binding auto-claim on reconcile', () => {);h.dataOwnerId = 'owner-b';writeStableProjectionOwner('owner-b');- const { DesktopCodexAuthAdapter } = await import('../auth-adapters.js');const adapter = new DesktopCodexAuthAdapter();const claimed = vi.fn();adapter.setOnOAuthBindingClaimed(claimed);@@ -260,7 +256,6 @@ describe('codex OAuth binding auto-claim on reconcile', () => {const { bindingFile } = fixture();h.dataOwnerId = 'owner-a';writeStableProjectionOwner('owner-a');- const { DesktopCodexAuthAdapter } = await import('../auth-adapters.js');const throwing = new DesktopCodexAuthAdapter();throwing.setOnOAuthBindingClaimed(() => {@@ -281,7 +276,6 @@ describe('codex OAuth binding auto-claim on reconcile', () => {it('keeps pre-session behavior without writing any binding when no owner is committed', async () => {const { bindingFile } = fixture();writeStableProjectionOwner(null);- const { DesktopCodexAuthAdapter } = await import('../auth-adapters.js');const adapter = new DesktopCodexAuthAdapter();await expect(adapter.getState()).resolves.toMatchObject({diff --git a/apps/desktop/src/main/maker-host/__tests__/codexAuthIsolatedSandbox.test.ts b/apps/desktop/src/main/maker-host/__tests__/codexAuthIsolatedSandbox.test.tsindex 39094c48e5..c20e5f49d9 100644--- a/apps/desktop/src/main/maker-host/__tests__/codexAuthIsolatedSandbox.test.ts+++ b/apps/desktop/src/main/maker-host/__tests__/codexAuthIsolatedSandbox.test.ts@@ -61,6 +61,9 @@ vi.mock('../../appSessionState.js', async (importOriginal) => {};});+// Load the adapter once during collection; keep cold transforms outside isolation deadlines.+import { DesktopCodexAuthAdapter, readCodexOneShotCreds } from '../auth-adapters.js';+function fixture(): {codexHome: string;systemAuth: string;@@ -142,7 +145,6 @@ describe('dev 沙箱凭证隔离(XDT_ISOLATED_AUTH)', () => {const { localAuth, systemAuth } = fixture();trustIsolatedAuthSandbox();h.dataOwnerId = 'owner-a';- const { DesktopCodexAuthAdapter } = await import('../auth-adapters.js');const adapter = new DesktopCodexAuthAdapter();// getState 内部按需 reconcile;隔离下不得把系统凭证呈现为已登录。await expect(adapter.getState()).resolves.toMatchObject({ authenticated: false });@@ -158,7 +160,6 @@ describe('dev 沙箱凭证隔离(XDT_ISOLATED_AUTH)', () => {expect(fs.statSync(systemAuth).nlink).toBe(2);trustIsolatedAuthSandbox();h.dataOwnerId = 'owner-a';- const { DesktopCodexAuthAdapter } = await import('../auth-adapters.js');const adapter = new DesktopCodexAuthAdapter();await adapter.getState();expect(fs.existsSync(localAuth)).toBe(false);@@ -181,7 +182,6 @@ describe('dev 沙箱凭证隔离(XDT_ISOLATED_AUTH)', () => {trustIsolatedAuthSandbox();h.dataOwnerId = 'owner-a';- const { DesktopCodexAuthAdapter } = await import('../auth-adapters.js');const adapter = new DesktopCodexAuthAdapter();await expect(adapter.getState()).resolves.toMatchObject({ authenticated: false });expect(() => fs.lstatSync(localAuth)).toThrow();@@ -205,7 +205,6 @@ describe('dev 沙箱凭证隔离(XDT_ISOLATED_AUTH)', () => {fs.writeFileSync(localAuth, JSON.stringify({ tokens: { access_token: 'orphan-token' } }));trustIsolatedAuthSandbox();h.dataOwnerId = 'owner-a';- const { DesktopCodexAuthAdapter } = await import('../auth-adapters.js');const adapter = new DesktopCodexAuthAdapter();await adapter.getState();@@ -227,7 +226,6 @@ describe('dev 沙箱凭证隔离(XDT_ISOLATED_AUTH)', () => {it('开关关(默认):reconcile 照常建共享硬链', async () => {const { localAuth, systemAuth } = fixture();h.dataOwnerId = 'owner-a';- const { DesktopCodexAuthAdapter } = await import('../auth-adapters.js');const adapter = new DesktopCodexAuthAdapter();await expect(adapter.getState()).resolves.toMatchObject({ authenticated: true });const sysStat = fs.statSync(systemAuth);@@ -251,7 +249,6 @@ describe('dev 沙箱凭证隔离(XDT_ISOLATED_AUTH)', () => {const releaseStat = fs.statSync(releaseAuth);const releaseBindingBytes = fs.readFileSync(releaseBinding);h.dataOwnerId = 'owner-a';- const { DesktopCodexAuthAdapter, readCodexOneShotCreds } = await import('../auth-adapters.js');const adapter = new DesktopCodexAuthAdapter();// This fixture owns credentials only; asset preparation has separate boundary tests.vi.spyOn(adapter, 'ensureGlobalCodexAssets').mockResolvedValue();@@ -322,7 +319,6 @@ describe('dev 沙箱凭证隔离(XDT_ISOLATED_AUTH)', () => {const releaseBytes = fs.readFileSync(releaseAuth);const systemBytes = fs.readFileSync(systemAuth);h.dataOwnerId = 'owner-a';- const { DesktopCodexAuthAdapter } = await import('../auth-adapters.js');const adapter = new DesktopCodexAuthAdapter();await expect(adapter.getState({ credentialMode: 'oauth-bearer' })).resolves.toMatchObject({@@ -402,7 +398,6 @@ describe('dev 沙箱凭证隔离(XDT_ISOLATED_AUTH)', () => {const releaseStat = fs.statSync(releaseAuth);const releaseBindingBytes = fs.readFileSync(releaseBinding);h.dataOwnerId = 'owner-a';- const { DesktopCodexAuthAdapter } = await import('../auth-adapters.js');const adapter = new DesktopCodexAuthAdapter();await expect(adapter.getState({ credentialMode: 'oauth-bearer' })).resolves.toMatchObject({@@ -431,7 +426,6 @@ describe('dev 沙箱凭证隔离(XDT_ISOLATED_AUTH)', () => {const releaseStat = fs.statSync(releaseAuth);const releaseBinding = path.join(h.userDataDir, 'native-provider-auth.json');h.dataOwnerId = 'owner-a';- const { DesktopCodexAuthAdapter } = await import('../auth-adapters.js');const adapter = new DesktopCodexAuthAdapter();await expect(adapter.getState({ credentialMode: 'oauth-bearer' })).resolves.toMatchObject({@@ -457,7 +451,6 @@ describe('dev 沙箱凭证隔离(XDT_ISOLATED_AUTH)', () => {);bindReleaseOpenAi(releaseAuth, 'owner-other');h.dataOwnerId = 'owner-a';- const { DesktopCodexAuthAdapter } = await import('../auth-adapters.js');const adapter = new DesktopCodexAuthAdapter();await expect(adapter.getState({ credentialMode: 'oauth-bearer' })).resolves.toMatchObject({@@ -493,7 +486,6 @@ describe('dev 沙箱凭证隔离(XDT_ISOLATED_AUTH)', () => {),).toBe(true);h.dataOwnerId = 'owner-a';- const { DesktopCodexAuthAdapter } = await import('../auth-adapters.js');const adapter = new DesktopCodexAuthAdapter();await expect(adapter.getState({ credentialMode: 'oauth-bearer' })).resolves.toMatchObject({@@ -513,7 +505,6 @@ describe('dev 沙箱凭证隔离(XDT_ISOLATED_AUTH)', () => {it('dev 默认只读共享:断开只停用 Cindy,重启不复活,显式本机连接可恢复', async () => {const { codexHome, localAuth, systemAuth } = fixture();h.dataOwnerId = 'owner-a';- const { DesktopCodexAuthAdapter, readCodexOneShotCreds } = await import('../auth-adapters.js');const adapter = new DesktopCodexAuthAdapter();const onLogout = vi.fn();const onInvalidated = vi.fn();@@ -575,7 +566,6 @@ describe('dev 沙箱凭证隔离(XDT_ISOLATED_AUTH)', () => {fs.mkdirSync(codexHome, { recursive: true });fs.linkSync(systemAuth, localAuth);const before = fs.readFileSync(systemAuth);- const { DesktopCodexAuthAdapter } = await import('../auth-adapters.js');const adapter = new DesktopCodexAuthAdapter();await expect(adapter.triggerLogin({ mode: 'local' })).resolves.toMatchObject({ authenticated: true });await adapter.logout();@@ -605,7 +595,6 @@ describe('dev 沙箱凭证隔离(XDT_ISOLATED_AUTH)', () => {fixture();h.isPackaged = true;h.dataOwnerId = 'owner-a';- const { DesktopCodexAuthAdapter } = await import('../auth-adapters.js');const { CodexAgent } = await import('../../../../../../packages/maker-core/src/agents/codex/index.js');const adapter = new DesktopCodexAuthAdapter();await adapter.logout();@@ -646,7 +635,6 @@ describe('dev 沙箱凭证隔离(XDT_ISOLATED_AUTH)', () => {h.isPackaged = true;h.dataOwnerId = 'owner-a';const before = fs.readFileSync(systemAuth);- const { DesktopCodexAuthAdapter } = await import('../auth-adapters.js');const adapter = new DesktopCodexAuthAdapter();let release!: () => void;const gate = new Promise<void>(resolve => { release = resolve; });@@ -701,7 +689,6 @@ describe('dev 沙箱凭证隔离(XDT_ISOLATED_AUTH)', () => {h.dataOwnerId = 'owner-a';fs.mkdirSync(codexHome, { recursive: true });if (existing) fs.writeFileSync(localAuth, JSON.stringify({ tokens: { access_token: 'old-copy' } }));- const { DesktopCodexAuthAdapter } = await import('../auth-adapters.js');const adapter = new DesktopCodexAuthAdapter();await expect(adapter.triggerLogin({ mode: 'local' })).resolves.toMatchObject({ authenticated: true });const renewed = JSON.stringify({ tokens: { access_token: 'renewed-native-token', account_id: 'acct-1' } });@@ -719,7 +706,6 @@ describe('dev 沙箱凭证隔离(XDT_ISOLATED_AUTH)', () => {fs.writeFileSync(releaseAuth, JSON.stringify({ tokens: { access_token: 'release-token', account_id: 'release-account' } }));bindReleaseOpenAi(releaseAuth);const before = fs.readFileSync(releaseAuth);- const { DesktopCodexAuthAdapter } = await import('../auth-adapters.js');const adapter = new DesktopCodexAuthAdapter();await adapter.logout();expect(fs.readFileSync(releaseAuth)).toEqual(before);@@ -732,7 +718,6 @@ describe('dev 沙箱凭证隔离(XDT_ISOLATED_AUTH)', () => {it('keeps a user disconnect durable when read-only invalidation cleanup is already running', async () => {const { systemAuth } = fixture();h.dataOwnerId = 'owner-a';- const { DesktopCodexAuthAdapter } = await import('../auth-adapters.js');const adapter = new DesktopCodexAuthAdapter();await adapter.getState();const before = fs.readFileSync(systemAuth);@@ -753,7 +738,6 @@ describe('dev 沙箱凭证隔离(XDT_ISOLATED_AUTH)', () => {const { systemAuth } = fixture();h.dataOwnerId = 'owner-a';const before = fs.readFileSync(systemAuth);- const { DesktopCodexAuthAdapter } = await import('../auth-adapters.js');const adapter = new DesktopCodexAuthAdapter();await adapter.getState();let release!: () => void;@@ -775,7 +759,6 @@ describe('dev 沙箱凭证隔离(XDT_ISOLATED_AUTH)', () => {it('dev 默认只读的 unproven 失效只保留内存边界', async () => {const { codexHome, localAuth, systemAuth } = fixture();h.dataOwnerId = 'owner-a';- const { DesktopCodexAuthAdapter, readCodexOneShotCreds } = await import('../auth-adapters.js');const adapter = new DesktopCodexAuthAdapter();const onInvalidated = vi.fn();adapter.setOnInvalidatedBroadcast(onInvalidated);@@ -825,7 +808,6 @@ describe('dev 沙箱凭证隔离(XDT_ISOLATED_AUTH)', () => {it('dev 只读失效以内存指纹等待系统凭证换代,不泄漏旧 token 或写共享文件', async () => {const { codexHome, localAuth, systemAuth } = fixture();h.dataOwnerId = 'owner-a';- const { DesktopCodexAuthAdapter, readCodexOneShotCreds } = await import('../auth-adapters.js');const adapter = new DesktopCodexAuthAdapter();await expect(adapter.getState({ credentialMode: 'oauth-bearer' })).resolves.toMatchObject({@@ -899,7 +881,6 @@ describe('dev 沙箱凭证隔离(XDT_ISOLATED_AUTH)', () => {it('dev 只读系统换代先于迟到失效时记录本地旧代并恢复系统新代', async () => {const { codexHome, localAuth, systemAuth } = fixture();h.dataOwnerId = 'owner-a';- const { DesktopCodexAuthAdapter, readCodexOneShotCreds } = await import('../auth-adapters.js');const adapter = new DesktopCodexAuthAdapter();await expect(adapter.getState({ credentialMode: 'oauth-bearer' })).resolves.toMatchObject({@@ -967,7 +948,6 @@ describe('dev 沙箱凭证隔离(XDT_ISOLATED_AUTH)', () => {vi.stubEnv('XDT_ALLOW_DEV_OAUTH_WRITE', '1');h.dataOwnerId = 'owner-a';const chmod = vi.spyOn(fs.promises, 'chmod');- const { DesktopCodexAuthAdapter } = await import('../auth-adapters.js');const adapter = new DesktopCodexAuthAdapter();await expect(adapter.getState()).resolves.toMatchObject({@@ -1000,7 +980,6 @@ describe('dev 沙箱凭证隔离(XDT_ISOLATED_AUTH)', () => {vi.stubEnv('XDT_ALLOW_DEV_OAUTH_WRITE', '1');h.dataOwnerId = 'owner-a';const chmod = vi.spyOn(fs.promises, 'chmod');- const { DesktopCodexAuthAdapter } = await import('../auth-adapters.js');const adapter = new DesktopCodexAuthAdapter();await expect(adapter.getState()).resolves.toMatchObject({@@ -1028,7 +1007,6 @@ describe('dev 沙箱凭证隔离(XDT_ISOLATED_AUTH)', () => {trustIsolatedAuthSandbox();h.dataOwnerId = 'owner-a';const chmod = vi.spyOn(fs.promises, 'chmod');- const { DesktopCodexAuthAdapter } = await import('../auth-adapters.js');const state = await new DesktopCodexAuthAdapter().getState();expect(state).toMatchObject({ authenticated: false });@@ -1050,7 +1028,6 @@ describe('dev 沙箱凭证隔离(XDT_ISOLATED_AUTH)', () => {const systemBytes = fs.readFileSync(systemAuth);trustIsolatedAuthSandbox();h.dataOwnerId = 'owner-a';- const { DesktopCodexAuthAdapter } = await import('../auth-adapters.js');const adapter = new DesktopCodexAuthAdapter();let finishLogout!: () => void;vi.spyOn(adapter, 'ensureGlobalCodexAssets').mockResolvedValue();@@ -1095,7 +1072,6 @@ describe('dev 沙箱凭证隔离(XDT_ISOLATED_AUTH)', () => {fs.writeFileSync(proofPath, `${JSON.stringify(proof)}\n`, { mode: 0o600 });h.dataOwnerId = 'owner-a';const chmod = vi.spyOn(fs.promises, 'chmod');- const { DesktopCodexAuthAdapter } = await import('../auth-adapters.js');await expect(new DesktopCodexAuthAdapter().getState()).resolves.toMatchObject({oauthWritesBlocked: true,diff --git a/apps/desktop/src/main/provider-group/__tests__/fastPolicyRuntime.test.ts b/apps/desktop/src/main/provider-group/__tests__/fastPolicyRuntime.test.tsindex f117db302b..866f79cacc 100644--- a/apps/desktop/src/main/provider-group/__tests__/fastPolicyRuntime.test.ts+++ b/apps/desktop/src/main/provider-group/__tests__/fastPolicyRuntime.test.ts@@ -93,24 +93,45 @@ beforeEach(() => {});afterAll(() => fs.rmSync(temporary, { recursive: true, force: true }));+function blockCapabilitiesRequest() {+ let enter!: () => void;+ let unblock!: () => void;+ const started = new Promise<void>((resolve) => { enter = resolve; });+ const blocked = new Promise<void>((resolve) => { unblock = resolve; });+ state.beforeCaps = () => {+ enter();+ return blocked;+ };+ return {+ started,+ release() {+ state.beforeCaps = undefined;+ unblock();+ },+ };+}+describe('group owner to executor enforcement handshake', () => {it('coalesces repeated sync requests while the same offline revision is in flight', async () => {- let release!: () => void;- state.beforeCaps = () =>- new Promise<void>((resolve) => {- release = resolve;- });+ const caps = blockCapabilitiesRequest();// Only one remote endpoint makes the blocked request count unambiguous.state.config!.members = state.config!.members.slice(0, 1);state.offline.add('one');- const first = runtime.syncGroupFastPolicy('openai');- await expect.poll(() => state.calls.length).toBe(1);- const repeats = Array.from({ length: 5 }, () => runtime.syncGroupFastPolicy('openai'));- state.beforeCaps = undefined;- release();- await Promise.all([first, ...repeats]);- expect(state.calls).toHaveLength(1);- expect(runtime.groupFastPolicyPending('openai')).toBe(true);+ const pending = [runtime.syncGroupFastPolicy('openai')];+ try {+ // The request starts after durable writes and lock release; wait for that+ // event under the test deadline, without a shorter wall-clock poll.+ await Promise.race([caps.started, pending[0]]);+ expect(state.calls).toHaveLength(1);+ pending.push(...Array.from({ length: 5 }, () => runtime.syncGroupFastPolicy('openai')));+ caps.release();+ await Promise.all(pending);+ expect(state.calls).toHaveLength(1);+ expect(runtime.groupFastPolicyPending('openai')).toBe(true);+ } finally {+ caps.release();+ await Promise.all(pending);+ }});it('reports a changed setting as pending before it has been sent to executors', async () => {@@ -121,25 +142,26 @@ describe('group owner to executor enforcement handshake', () => {});it('still applies a newer setting requested while an earlier revision is in flight', async () => {- let release!: () => void;- state.beforeCaps = () =>- new Promise<void>((resolve) => {- release = resolve;- });+ const caps = blockCapabilitiesRequest();state.config!.members = state.config!.members.slice(0, 1);- const first = runtime.syncGroupFastPolicy('openai');- await expect.poll(() => state.calls.length).toBe(1);- state.config!.allowFast = true;- const changed = runtime.syncGroupFastPolicy('openai');- state.beforeCaps = undefined;- release();- await Promise.all([first, changed]);- expect(- state.calls- .filter(({ command }) => command.op === 'fast-policy')- .map(({ command }) => command.allowFast),- ).toEqual([false, true]);- expect(runtime.groupFastPolicyPending('openai')).toBe(false);+ const pending = [runtime.syncGroupFastPolicy('openai')];+ try {+ await Promise.race([caps.started, pending[0]]);+ expect(state.calls).toHaveLength(1);+ state.config!.allowFast = true;+ pending.push(runtime.syncGroupFastPolicy('openai'));+ caps.release();+ await Promise.all(pending);+ expect(+ state.calls+ .filter(({ command }) => command.op === 'fast-policy')+ .map(({ command }) => command.allowFast),+ ).toEqual([false, true]);+ expect(runtime.groupFastPolicyPending('openai')).toBe(false);+ } finally {+ caps.release();+ await Promise.all(pending);+ }});it('intersects a relay source with the executor local group and releases it even without a local member', async () => {