Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

test(provider-share): 修复 CI 测试接线并同步直连生成物

yan0037cf3b123c
diff --git a/apps/desktop/src/main/__tests__/deviceLinkDispatch.test.ts b/apps/desktop/src/main/__tests__/deviceLinkDispatch.test.ts
index 6ed0f3e0bd..a06e50da7f 100644
--- a/apps/desktop/src/main/__tests__/deviceLinkDispatch.test.ts
+++ b/apps/desktop/src/main/__tests__/deviceLinkDispatch.test.ts
@@ -15,6 +15,11 @@ vi.mock('electron', () => ({
ipcMain: { handle: vi.fn(), removeHandler: vi.fn() },
app: { getVersion: () => '1.0.0' },
}));
+// Ordinary same-account dispatch has no delegated share lease. Keep the host account
+// boundary isolated; delegated guest admission is exercised in providerShareRuntime.test.ts.
+vi.mock('../device-link/providerShareDelegatedAccess.js', () => ({
+ delegatedProviderShareGuestAccess: () => null,
+}));
// This suite exercises dispatch authorization, not authenticated ICE HTTP setup.
vi.mock('../task-migration/service', () => ({ requestTaskMigration: vi.fn() }));
vi.mock('../remote-desktop/iceConfig', () => ({ loadDesktopIceServers: vi.fn(async () => []) }));
diff --git a/apps/desktop/src/main/__tests__/makerOrcaRoleMarking.test.ts b/apps/desktop/src/main/__tests__/makerOrcaRoleMarking.test.ts
index 26a984a1d0..c5d9c6e28a 100644
--- a/apps/desktop/src/main/__tests__/makerOrcaRoleMarking.test.ts
+++ b/apps/desktop/src/main/__tests__/makerOrcaRoleMarking.test.ts
@@ -46,7 +46,7 @@ describe('maker Orca role marking IPC boundary', () => {
expectOrder(
roleMarkingSource,
'await assertReviewSettingsUnlocked(sessionId);',
- 'await setSessionOrcaRole(sessionId, orcaRole);',
+ 'await setSessionOrcaRole(sessionId, orcaRole, { owner: owner!, assertCurrent });',
);
expectOrder(
collabGuardSource,
diff --git a/apps/desktop/src/main/device-link/__tests__/remoteInvokeSendGuard.test.ts b/apps/desktop/src/main/device-link/__tests__/remoteInvokeSendGuard.test.ts
index 2f008be8c7..cff11c0d6e 100644
--- a/apps/desktop/src/main/device-link/__tests__/remoteInvokeSendGuard.test.ts
+++ b/apps/desktop/src/main/device-link/__tests__/remoteInvokeSendGuard.test.ts
@@ -1,7 +1,7 @@
import { readFileSync } from 'node:fs';
import ts from 'typescript';
import { expect, it, vi } from 'vitest';
-import { DeviceLinkError, FILE_PEER_CHANNEL, type DeviceLinkClient } from '@cindy/device-link';
+import { DeviceLinkError, FILE_PEER_CHANNEL, parseProviderSharePeer, type DeviceLinkClient } from '@cindy/device-link';
import { ensureInvokeLinkReady, invokeWithClosedLinkRecovery } from '../linkRecovery';
// Run the production adapter with only its host dependencies injected, without
@@ -41,6 +41,7 @@ function loadBackgroundInvoke(overrides: Record<string, unknown>) {
compilerOptions: { target: ts.ScriptTarget.ES2022 },
}).outputText;
const dependencies = {
+ parseProviderSharePeer,
resolveRemoteAgentTargetWhenReady: async (id: string) => id,
client: { isLinkReady: () => true },
remoteInvoke: loadRemoteInvoke({}),
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/bootstrapDirectoryGrants.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/bootstrapDirectoryGrants.test.ts
index 19190f6f91..f5f07319a6 100644
--- a/apps/desktop/src/main/maker-ipc/__tests__/bootstrapDirectoryGrants.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/bootstrapDirectoryGrants.test.ts
@@ -255,7 +255,7 @@ describe('bootstrap directory-grant wiring', () => {
expect(bootstrap.indexOf('await prepareDirectoryGrantsForBootstrap')).toBeGreaterThanOrEqual(0);
expect(bootstrap.indexOf('await prepareDirectoryGrantsForBootstrap')).toBeLessThan(
- bootstrap.indexOf('await maker.createSession(o)'),
+ bootstrap.indexOf('await maker.createSession(o, creationSignal)'),
);
expect(bootstrap).toContain('if (existing) await persistSessionFields(sessionId, patch);');
expect(bootstrap).toContain('readPersistedWritableDirs: readSessionWritableDirsFromDb');
diff --git a/apps/desktop/src/main/remote-agent/__tests__/connectionPool.test.ts b/apps/desktop/src/main/remote-agent/__tests__/connectionPool.test.ts
index d2bbd5ef4b..e032871356 100644
--- a/apps/desktop/src/main/remote-agent/__tests__/connectionPool.test.ts
+++ b/apps/desktop/src/main/remote-agent/__tests__/connectionPool.test.ts
@@ -653,7 +653,10 @@ describe('remote connection pool with a real host', () => {
expect(first[0].status).toBe('rejected');
if (first[0].status !== 'rejected') throw new Error('Local cleanup failure must reach the owner');
expect(first[0].reason).toBeInstanceOf(AggregateError);
- expect((first[0].reason as AggregateError).errors).toEqual(failures);
+ const cleanupErrors = (first[0].reason as AggregateError).errors;
+ expect(cleanupErrors).toEqual([failures[0], failures[1], expect.any(AggregateError)]);
+ // Preparation now owns executor and MCP disposal; neither original failure may disappear.
+ expect((cleanupErrors[2] as AggregateError).errors).toEqual([failures[3], failures[2]]);
const repeated = await Promise.allSettled([handle.detach!({ reason: 'account-boundary' })]);
expect(repeated[0].status).toBe('rejected');
if (repeated[0].status === 'rejected') expect(repeated[0].reason).toBe(first[0].reason);
diff --git a/apps/desktop/src/renderer/features/provider-share/__tests__/providerShareInsightsFlow.test.tsx b/apps/desktop/src/renderer/features/provider-share/__tests__/providerShareInsightsFlow.test.tsx
index 34a4a898ba..50dea33bb5 100644
--- a/apps/desktop/src/renderer/features/provider-share/__tests__/providerShareInsightsFlow.test.tsx
+++ b/apps/desktop/src/renderer/features/provider-share/__tests__/providerShareInsightsFlow.test.tsx
@@ -59,6 +59,7 @@ vi.mock('../../../../main/maker-ipc/register.js', () => ({}));
vi.mock('../../../../main/device-link/index.js', () => ({ remoteBackgroundInvoke: vi.fn() }));
vi.mock('../../../../main/device-link/providerShareApi.js', () => ({
providerShareApi: {},
+ providerShareOwnerKey: () => 'isolated-owner',
fetchIdentityCard: vi.fn(),
sha256Hex: (v: string) => v,
}));
@@ -86,6 +87,8 @@ vi.mock('../../../../main/device-link/providerShareHost.js', () => ({
startProviderShareHost: vi.fn(),
stopProviderShareHost: vi.fn(),
providerShareAccessRevision: () => 1,
+ ownedProviderShareGuestAccess: () =>
+ state.active ? { shareId: 'flow', memberId: 'guest', providerId: 'anthropic' } : null,
providerShareGuestAccess: () =>
state.active ? { shareId: 'flow', memberId: 'guest', providerId: 'anthropic' } : null,
ensureProviderSharePeerKnown: async () => {},
diff --git a/packages/device-link/src/directRuntimeSource.ts b/packages/device-link/src/directRuntimeSource.ts
index 2d7e930c2a..35174e0bc1 100644
--- a/packages/device-link/src/directRuntimeSource.ts
+++ b/packages/device-link/src/directRuntimeSource.ts
@@ -1,2 +1,2 @@
// Generated by node scripts/direct-link-runtime.mjs. Do not edit.
-export const DIRECT_LINK_RUNTIME_SOURCE = "\"use strict\";var CindyDirectLink=(()=>{var g=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var N=Object.getOwnPropertyNames;var D=Object.prototype.hasOwnProperty;var x=(i,n)=>{for(var t in n)g(i,t,{get:n[t],enumerable:!0})},w=(i,n,t,r)=>{if(n&&typeof n==\"object\"||typeof n==\"function\")for(let e of N(n))!D.call(i,e)&&e!==t&&g(i,e,{get:()=>n[e],enumerable:!(r=k(n,e))||r.enumerable});return i};var L=i=>w(g({},\"__esModule\",{value:!0}),i);var q={};x(q,{create:()=>H});var m=2*1024*1024,U=4*1024*1024;var Ne=128*1024;var De=4*1024*1024,xe=16*1024*1024;var we=16*1024*1024,Le=8*1024*1024;var Ce=5*6e4;function I(i){let n=0;for(let t=0;t<i.length;t+=1){let r=i.codePointAt(t);r>65535&&(t+=1),n+=r<=127?1:r<=2047?2:r<=65535?3:4}return n}function A(i,n){let t=new Map,r=e=>{let o=t.get(e);t.delete(e),o?.session.close()};return{async command(e){if(!(!e||typeof e.connection!=\"string\"||!/^[a-zA-Z0-9-]{1,64}$/.test(e.connection)||typeof e.id!=\"string\"))try{let o=t.get(e.connection);if(e.action===\"offer\"||e.action===\"accept\"){if(o||t.size>=16)throw new Error;o={session:i.create(e.connection,{open:()=>n({type:\"open\",connection:e.connection}),message:d=>n({type:\"message\",connection:e.connection,text:d}),drained:()=>{let d=t.get(e.connection);d&&n({type:\"buffer\",connection:e.connection,sequence:d.sequence,buffered:d.session.bufferedAmount})},closed:()=>{t.has(e.connection)&&(t.delete(e.connection),n({type:\"closed\",connection:e.connection}))}}),sequence:0},t.set(e.connection,o)}if(e.action===\"close\"){r(e.connection);return}if(!o)throw new Error;let l;if(e.action===\"offer\")l=await o.session.offer();else if(e.action===\"accept\"||e.action===\"answer\"){if(typeof e.sdp!=\"string\"||!e.sdp||e.sdp.length>131072)throw new Error;e.action===\"accept\"?l=await o.session.accept(e.sdp):await o.session.answer(e.sdp)}else if(e.action===\"send\"){if(typeof e.text!=\"string\"||I(e.text)>m||e.sequence!==o.sequence+1)throw new Error;o.session.send(e.text),o.sequence=e.sequence,n({type:\"buffer\",connection:e.connection,sequence:o.sequence,buffered:o.session.bufferedAmount});return}else throw new Error;n({type:\"reply\",id:e.id,ok:!0,...l?{value:l}:{}})}catch{n({type:\"reply\",id:e.id,ok:!1}),r(e.connection),n({type:\"closed\",connection:e.connection})}},dispose(){for(let e of t.keys())r(e)}}}function P(){return{create(i,n){let t=new RTCPeerConnection({iceServers:[]}),r,e=!1,o=0,l=[],h,d,v=new TextEncoder,b=new TextDecoder(\"utf-8\",{fatal:!0}),f=()=>{e||(e=!0,clearTimeout(h),clearTimeout(d),l=[],r?.close(),t.close(),n.closed())},E=()=>{!e&&r&&r.bufferedAmount>0&&!d&&(d=setTimeout(()=>{d=void 0,T()},100))},T=()=>{e||(n.drained(),E())},y=s=>{if(e||r||s.label!==\"device-link-v1\"||!s.ordered||s.maxRetransmits!==null||s.maxPacketLifeTime!==null){s.close();return}r=s,r.binaryType=\"arraybuffer\",r.bufferedAmountLowThreshold=0,r.onopen=()=>{e||n.open()},r.onclose=f,r.onerror=f,r.onbufferedamountlow=()=>{clearTimeout(d),d=void 0,T()},r.onmessage=({data:c})=>{try{if(e||!(c instanceof ArrayBuffer)||c.byteLength<2||c.byteLength>16*1024)throw new Error;let a=new Uint8Array(c);if(a[0]!==0&&a[0]!==1)throw new Error;if(o+=a.length-1,o>m||l.length>=256)throw new Error;if(l.push(a.subarray(1)),clearTimeout(h),a[0]===0){h=setTimeout(f,1e4);return}let p=new Uint8Array(o),u=0;for(let S of l)p.set(S,u),u+=S.length;l=[],o=0,n.message(b.decode(p))}catch{f()}}};t.ondatachannel=({channel:s})=>y(s),t.onconnectionstatechange=()=>{[\"failed\",\"closed\",\"disconnected\"].includes(t.connectionState)&&f()};let _=async s=>{if(await t.setLocalDescription(s),t.iceGatheringState!==\"complete\"&&!e&&await new Promise(c=>{let a=setTimeout(p,3e3);function p(){clearTimeout(a),t.removeEventListener(\"icegatheringstatechange\",u),c()}function u(){(t.iceGatheringState===\"complete\"||e)&&p()}t.addEventListener(\"icegatheringstatechange\",u),u()}),e||!t.localDescription?.sdp)throw new Error(\"DIRECT_CHANNEL_CLOSED\");return t.localDescription.sdp};return{async offer(){return y(t.createDataChannel(\"device-link-v1\",{ordered:!0})),_(await t.createOffer())},async accept(s){return await t.setRemoteDescription({type:\"offer\",sdp:s}),_(await t.createAnswer())},async answer(s){await t.setRemoteDescription({type:\"answer\",sdp:s})},send(s){if(e||r?.readyState!==\"open\")throw new Error(\"DIRECT_CHANNEL_CLOSED\");let c=v.encode(s);if(!c.length||c.length>m||r.bufferedAmount>3*m)throw new Error(\"DIRECT_CHANNEL_BACKPRESSURE\");try{for(let a=0;a<c.length;a+=16*1024-1){let p=Math.min(c.length,a+16384-1),u=new Uint8Array(p-a+1);u[0]=p===c.length?1:0,u.set(c.subarray(a,p),1),r.send(u.buffer)}E()}catch(a){throw f(),a}},get bufferedAmount(){return r?.bufferedAmount??0},close:f}}}}function H(i){return A(P(),i)}return L(q);})();\n";
+export const DIRECT_LINK_RUNTIME_SOURCE = "\"use strict\";var CindyDirectLink=(()=>{var g=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var D=Object.getOwnPropertyNames;var N=Object.prototype.hasOwnProperty;var x=(i,n)=>{for(var t in n)g(i,t,{get:n[t],enumerable:!0})},L=(i,n,t,r)=>{if(n&&typeof n==\"object\"||typeof n==\"function\")for(let e of D(n))!N.call(i,e)&&e!==t&&g(i,e,{get:()=>n[e],enumerable:!(r=k(n,e))||r.enumerable});return i};var w=i=>L(g({},\"__esModule\",{value:!0}),i);var G={};x(G,{create:()=>H});var m=2*1024*1024,U=4*1024*1024;var De=128*1024;var Ne=4*1024*1024,xe=16*1024*1024;var Le=16*1024*1024,we=8*1024*1024;var Ce=5*6e4;function I(i){let n=0;for(let t=0;t<i.length;t+=1){let r=i.codePointAt(t);r>65535&&(t+=1),n+=r<=127?1:r<=2047?2:r<=65535?3:4}return n}function A(i,n){let t=new Map,r=e=>{let o=t.get(e);t.delete(e),o?.session.close()};return{async command(e){if(!(!e||typeof e.connection!=\"string\"||!/^[a-zA-Z0-9-]{1,64}$/.test(e.connection)||typeof e.id!=\"string\"))try{let o=t.get(e.connection);if(e.action===\"offer\"||e.action===\"accept\"){if(o||t.size>=16)throw new Error;o={session:i.create(e.connection,{open:()=>n({type:\"open\",connection:e.connection}),message:d=>n({type:\"message\",connection:e.connection,text:d}),drained:()=>{let d=t.get(e.connection);d&&n({type:\"buffer\",connection:e.connection,sequence:d.sequence,buffered:d.session.bufferedAmount})},closed:()=>{t.has(e.connection)&&(t.delete(e.connection),n({type:\"closed\",connection:e.connection}))}}),sequence:0},t.set(e.connection,o)}if(e.action===\"close\"){r(e.connection);return}if(!o)throw new Error;let l;if(e.action===\"offer\")l=await o.session.offer();else if(e.action===\"accept\"||e.action===\"answer\"){if(typeof e.sdp!=\"string\"||!e.sdp||e.sdp.length>131072)throw new Error;e.action===\"accept\"?l=await o.session.accept(e.sdp):await o.session.answer(e.sdp)}else if(e.action===\"send\"){if(typeof e.text!=\"string\"||I(e.text)>m||e.sequence!==o.sequence+1)throw new Error;o.session.send(e.text),o.sequence=e.sequence,n({type:\"buffer\",connection:e.connection,sequence:o.sequence,buffered:o.session.bufferedAmount});return}else throw new Error;n({type:\"reply\",id:e.id,ok:!0,...l?{value:l}:{}})}catch{n({type:\"reply\",id:e.id,ok:!1}),r(e.connection),n({type:\"closed\",connection:e.connection})}},dispose(){for(let e of t.keys())r(e)}}}function P(){return{create(i,n){let t=new RTCPeerConnection({iceServers:[]}),r,e=!1,o=0,l=[],h,d,v=new TextEncoder,b=new TextDecoder(\"utf-8\",{fatal:!0}),f=()=>{e||(e=!0,clearTimeout(h),clearTimeout(d),l=[],r?.close(),t.close(),n.closed())},E=()=>{!e&&r&&r.bufferedAmount>0&&!d&&(d=setTimeout(()=>{d=void 0,T()},100))},T=()=>{e||(n.drained(),E())},y=s=>{if(e||r||s.label!==\"device-link-v1\"||!s.ordered||s.maxRetransmits!==null||s.maxPacketLifeTime!==null){s.close();return}r=s,r.binaryType=\"arraybuffer\",r.bufferedAmountLowThreshold=0,r.onopen=()=>{e||n.open()},r.onclose=f,r.onerror=f,r.onbufferedamountlow=()=>{clearTimeout(d),d=void 0,T()},r.onmessage=({data:c})=>{try{if(e||!(c instanceof ArrayBuffer)||c.byteLength<2||c.byteLength>16*1024)throw new Error;let a=new Uint8Array(c);if(a[0]!==0&&a[0]!==1)throw new Error;if(o+=a.length-1,o>m||l.length>=256)throw new Error;if(l.push(a.subarray(1)),clearTimeout(h),a[0]===0){h=setTimeout(f,1e4);return}let p=new Uint8Array(o),u=0;for(let S of l)p.set(S,u),u+=S.length;l=[],o=0,n.message(b.decode(p))}catch{f()}}};t.ondatachannel=({channel:s})=>y(s),t.onconnectionstatechange=()=>{[\"failed\",\"closed\",\"disconnected\"].includes(t.connectionState)&&f()};let _=async s=>{if(await t.setLocalDescription(s),t.iceGatheringState!==\"complete\"&&!e&&await new Promise(c=>{let a=setTimeout(p,3e3);function p(){clearTimeout(a),t.removeEventListener(\"icegatheringstatechange\",u),c()}function u(){(t.iceGatheringState===\"complete\"||e)&&p()}t.addEventListener(\"icegatheringstatechange\",u),u()}),e||!t.localDescription?.sdp)throw new Error(\"DIRECT_CHANNEL_CLOSED\");return t.localDescription.sdp};return{async offer(){return y(t.createDataChannel(\"device-link-v1\",{ordered:!0})),_(await t.createOffer())},async accept(s){return await t.setRemoteDescription({type:\"offer\",sdp:s}),_(await t.createAnswer())},async answer(s){await t.setRemoteDescription({type:\"answer\",sdp:s})},send(s){if(e||r?.readyState!==\"open\")throw new Error(\"DIRECT_CHANNEL_CLOSED\");let c=v.encode(s);if(!c.length||c.length>m||r.bufferedAmount>3*m)throw new Error(\"DIRECT_CHANNEL_BACKPRESSURE\");try{for(let a=0;a<c.length;a+=16*1024-1){let p=Math.min(c.length,a+16384-1),u=new Uint8Array(p-a+1);u[0]=p===c.length?1:0,u.set(c.subarray(a,p),1),r.send(u.buffer)}E()}catch(a){throw f(),a}},get bufferedAmount(){return r?.bufferedAmount??0},close:f}}}}function H(i){return A(P(),i)}return w(G);})();\n";