diff --git a/.changeset/f7-desktop-boundaries.md b/.changeset/f7-desktop-boundaries.md new file mode 100644 index 0000000000..fd81607033 --- /dev/null +++ b/.changeset/f7-desktop-boundaries.md @@ -0,0 +1,7 @@ +--- +'@fluentui-react-native/desktop-driver': patch +'@fluentui-react-native/desktop-test': patch +'@fluentui-react-native/desktop-driver-mcp': patch +--- + +Add a dedicated native helper entry to desktop-driver and enforce the neutral desktop package dependency boundary with standalone consumer contracts. diff --git a/packages/agentic/desktop-driver-mcp/references/connection.md b/packages/agentic/desktop-driver-mcp/references/connection.md index 97c90e0205..343e1a736d 100644 --- a/packages/agentic/desktop-driver-mcp/references/connection.md +++ b/packages/agentic/desktop-driver-mcp/references/connection.md @@ -92,13 +92,15 @@ process lives and reports to stderr. Service drain/expiry is still needed when the adapter cannot confirm deletion. `--help` and `--version` write to stderr so stdout carries only protocol. -The adapter resolves the native helper with source builds disabled. The helper -must already be cached by `desktop-driver resolve-driver` or `build-driver`, or -named by `FURN_DESKTOP_DRIVER_HELPER_PATH` or -`FURN_DESKTOP_DRIVER_INSTALL_ROOT`. The helper verifies that the process -listening at the descriptor's URL is the one the supervisor described, on the -same user and interactive session, before the grant leaves the adapter. The -service then confirms its incarnation. +The adapter imports helper resolution from the driver's `/native` entry and +uses the driver's `/authority`, `/client`, and `/operations` entries rather +than loading its root and WebdriverIO integration. It resolves the native +helper with source builds disabled. The helper must already be cached by +`desktop-driver resolve-driver` or `build-driver`, or named by +`FURN_DESKTOP_DRIVER_HELPER_PATH` or `FURN_DESKTOP_DRIVER_INSTALL_ROOT`. The +helper verifies that the process listening at the descriptor's URL is the one +the supervisor described, on the same user and interactive session, before the +grant leaves the adapter. The service then confirms its incarnation. ## Connecting lazily and reconnecting diff --git a/packages/agentic/desktop-driver-mcp/references/current-status.md b/packages/agentic/desktop-driver-mcp/references/current-status.md index 0e72ce554d..51e71502ae 100644 --- a/packages/agentic/desktop-driver-mcp/references/current-status.md +++ b/packages/agentic/desktop-driver-mcp/references/current-status.md @@ -19,21 +19,21 @@ and the generalized management facet is ## Capability matrix -| Capability | State | Boundary/remaining work | -| ------------------------------------------------------- | ------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| Six tools over shared driver schemas | Done | Session, observe, act, check, capture, story. No separate execution path. | -| Private descriptor and native identity verification | Done | Verifies before sending a grant. No model URL/token/config/executable input. | -| Single-flight connection/session lifetime | Done | Serial acquisition, close, operations and resource reads; late acquisition after dispose is cleaned up. | -| Same-port protected restart/revocation | Done in deterministic contracts | Invalid authority is forgotten; next call re-verifies discovery. No mutation replay. Live endpoint reruns remain required. | -| Same-authority transport retry | Done, bounded semantics | Retain known session cleanup responsibility and rebind only after verification of the same incarnation/principal. This is not cross-MCP-connection resume. | -| Lost create response | Fenced; recovery in progress | `session-uncertain`; no repeated acquisition. Operator must revoke the old grant or replace the service. No session-enumeration shortcut. | -| Failed delete/disconnect | Done with limits | Keep known-session responsibility; bounded dispose wait leaves late cleanup attached. Unreachable-service cleanup cannot be guaranteed; service drain/expiry remains necessary. | -| Launch-mode discovery | Done | Status lists effective launch/attach modes; no predictable attach-first failure against launch-only targets. | -| Progress, cancellation, paged image resources | Done | Progress does not renew idle sessions; artifacts are session-bound and hash-checked. | -| Storybook control | Experimental | Driver selection/marker path exists; channel ingress/reconnect and full exclusive context authority remain incomplete. | -| Per-connection attenuated grants and resumable sessions | Work in progress | Current supervisor publishes one shared agent grant. Labels are not client isolation. | -| Workload/test orchestration tools | Work in progress | Belong to a future harness control/client surface; adapter never becomes the resource owner. | -| General MCP-client qualification | Work in progress | SDK stdio evidence exists; client-specific resource/image/cancellation behavior needs independent runs. | +| Capability | State | Boundary/remaining work | +| ------------------------------------------------------- | ------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| Six tools over shared driver schemas | Done | Session, observe, act, check, capture, story. No separate execution path. | +| Private descriptor and native identity verification | Done | Verifies before sending a grant. Uses the driver's `/native`, `/authority`, and `/client` subpaths, not its WebdriverIO-heavy root; boundary tests guard this dependency. No model URL/token/config/executable input. | +| Single-flight connection/session lifetime | Done | Serial acquisition, close, operations and resource reads; late acquisition after dispose is cleaned up. | +| Same-port protected restart/revocation | Done in deterministic contracts | Invalid authority is forgotten; next call re-verifies discovery. No mutation replay. Live endpoint reruns remain required. | +| Same-authority transport retry | Done, bounded semantics | Retain known session cleanup responsibility and rebind only after verification of the same incarnation/principal. This is not cross-MCP-connection resume. | +| Lost create response | Fenced; recovery in progress | `session-uncertain`; no repeated acquisition. Operator must revoke the old grant or replace the service. No session-enumeration shortcut. | +| Failed delete/disconnect | Done with limits | Keep known-session responsibility; bounded dispose wait leaves late cleanup attached. Unreachable-service cleanup cannot be guaranteed; service drain/expiry remains necessary. | +| Launch-mode discovery | Done | Status lists effective launch/attach modes; no predictable attach-first failure against launch-only targets. | +| Progress, cancellation, paged image resources | Done | Progress does not renew idle sessions; artifacts are session-bound and hash-checked. | +| Storybook control | Experimental | Driver selection/marker path exists; channel ingress/reconnect and full exclusive context authority remain incomplete. | +| Per-connection attenuated grants and resumable sessions | Work in progress | Current supervisor publishes one shared agent grant. Labels are not client isolation. | +| Workload/test orchestration tools | Work in progress | Belong to a future harness control/client surface; adapter never becomes the resource owner. | +| General MCP-client qualification | Work in progress | SDK stdio evidence exists; client-specific resource/image/cancellation behavior needs independent runs. | See [connection](connection.md) and [tools](tools.md) for exact behavior. Native and Storybook limitations are tracked in diff --git a/packages/agentic/desktop-driver-mcp/src/connection.test.ts b/packages/agentic/desktop-driver-mcp/src/connection.test.ts new file mode 100644 index 0000000000..e3aba4b524 --- /dev/null +++ b/packages/agentic/desktop-driver-mcp/src/connection.test.ts @@ -0,0 +1,11 @@ +import { connectWithDescriptor } from './connection'; + +jest.mock('@fluentui-react-native/desktop-driver', () => { + throw new Error('The MCP adapter must not load the desktop-driver root entry.'); +}); + +describe('desktop-driver-mcp connection imports', () => { + test('loads its connection implementation without the desktop-driver root entry', () => { + expect(connectWithDescriptor).toEqual(expect.any(Function)); + }); +}); diff --git a/packages/agentic/desktop-driver-mcp/src/connection.ts b/packages/agentic/desktop-driver-mcp/src/connection.ts index 270634ea2a..4314704813 100644 --- a/packages/agentic/desktop-driver-mcp/src/connection.ts +++ b/packages/agentic/desktop-driver-mcp/src/connection.ts @@ -1,4 +1,4 @@ -import { resolveNativeDesktopDriver } from '@fluentui-react-native/desktop-driver'; +import { resolveNativeDesktopDriver } from '@fluentui-react-native/desktop-driver/native'; import { createMacOSPrivateStorage, createMacOSServiceVerifier, diff --git a/packages/agentic/desktop-driver/README.md b/packages/agentic/desktop-driver/README.md index 35fddb1804..acf2e75ab2 100644 --- a/packages/agentic/desktop-driver/README.md +++ b/packages/agentic/desktop-driver/README.md @@ -146,6 +146,7 @@ The [reference index](references/README.md) describes each package-owned guide. | `/wdio` | WebdriverIO connection, custom commands, assertions, and story-plan runner | | `/client` | Low-level typed W3C client | | `/authority` | Grants, private connection descriptors, and macOS owner-validated storage | +| `/native` | Native-helper build, resolution, and verification without loading the package root | | `/server` | Embeddable remote end, session manager, and target registry | | `/agent` | Bounded JSON-safe inspection, action, and evidence API | | `/operations` | Versioned agent operation catalog, executor, and result types | diff --git a/packages/agentic/desktop-driver/package.json b/packages/agentic/desktop-driver/package.json index 2e0ef2896d..9764867493 100644 --- a/packages/agentic/desktop-driver/package.json +++ b/packages/agentic/desktop-driver/package.json @@ -68,6 +68,11 @@ "import": "./lib/authority/index.js", "default": "./src/authority/index.ts" }, + "./native": { + "types": "./lib/native/nativeDriver.d.ts", + "import": "./lib/native/nativeDriver.js", + "default": "./src/native/nativeDriver.ts" + }, "./operations": { "types": "./lib/operations/index.d.ts", "import": "./lib/operations/index.js", diff --git a/packages/agentic/desktop-driver/references/current-status.md b/packages/agentic/desktop-driver/references/current-status.md index b4d7451557..320faeee3f 100644 --- a/packages/agentic/desktop-driver/references/current-status.md +++ b/packages/agentic/desktop-driver/references/current-status.md @@ -22,7 +22,7 @@ and its sub-issues, which record dependencies and parallel waves. | Capability | State | Boundary or remaining work | | ---------------------------------------------------------- | ------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | W3C service and typed/WDIO clients | Done | Registered targets only; native browser-inapplicable commands explicitly unsupported. | -| Application-neutral driver | Done | No Storybook, React, or React Native dependency. Optional story provider is injected. | +| Application-neutral driver | Done | No Storybook, React, or React Native dependency; package-boundary tests reject forbidden imports/dependencies. Optional story provider is injected. | | Native sessions and command/input queues | Done | One reservation per registered target in one service. Cross-service exact-application claims remain work in progress. | | Verified private discovery and grants | Done | Native identity verified before credential transmission; all protected driver routes authenticate. Does not protect the separate Storybook channel. | | Mutation effects, settlement, quarantine | Done | Native mutations settle before advancing. Uncertain story changes now quarantine instead of assuming a later render is safe. | diff --git a/packages/agentic/desktop-driver/references/native-helpers.md b/packages/agentic/desktop-driver/references/native-helpers.md index 64e0d0554b..ff8943b7a8 100644 --- a/packages/agentic/desktop-driver/references/native-helpers.md +++ b/packages/agentic/desktop-driver/references/native-helpers.md @@ -13,6 +13,12 @@ The package ships checked-in native source and builds one small helper on the target operating system. Native binaries are not published in npm, compiled during installation, or downloaded automatically. +Applications that only need helper build, resolution, or verification can +import those functions from +`@fluentui-react-native/desktop-driver/native`. This entry maps directly to +the helper implementation and avoids loading the package root and its +WebdriverIO integration. + Windows and Win32 share the C++ x64 provider. macOS uses the Swift arm64 provider. Both implement the private [FDR1 framed stdio protocol](../native/PROTOCOL.md) behind the same diff --git a/packages/agentic/desktop-driver/src/native/nativeExport.test.ts b/packages/agentic/desktop-driver/src/native/nativeExport.test.ts new file mode 100644 index 0000000000..8fb78b9750 --- /dev/null +++ b/packages/agentic/desktop-driver/src/native/nativeExport.test.ts @@ -0,0 +1,26 @@ +import { existsSync, readFileSync } from 'node:fs'; +import path from 'node:path'; + +type ExportConditions = { + types?: string; + import?: string; + default?: string; +}; + +describe('desktop-driver native entry', () => { + test('exposes the helper implementation as a dedicated package subpath', () => { + const packageRoot = path.resolve(__dirname, '../..'); + const manifest = JSON.parse(readFileSync(path.join(packageRoot, 'package.json'), 'utf8')) as { + exports: Record; + }; + const nativeEntry = manifest.exports['./native']; + + expect(nativeEntry).toEqual({ + types: './lib/native/nativeDriver.d.ts', + import: './lib/native/nativeDriver.js', + default: './src/native/nativeDriver.ts', + }); + expect(existsSync(path.join(packageRoot, nativeEntry.default ?? ''))).toBe(true); + expect(existsSync(path.join(packageRoot, nativeEntry.types ?? ''))).toBe(true); + }); +}); diff --git a/packages/agentic/desktop-test/fixtures/neutral-boundary/loader.mjs b/packages/agentic/desktop-test/fixtures/neutral-boundary/loader.mjs new file mode 100644 index 0000000000..46493c970f --- /dev/null +++ b/packages/agentic/desktop-test/fixtures/neutral-boundary/loader.mjs @@ -0,0 +1,41 @@ +const workspaceEntryPoints = new Map([ + ['@fluentui-react-native/desktop-driver', new URL('../../../desktop-driver/lib/index.js', import.meta.url).href], + ['@fluentui-react-native/desktop-test', new URL('../../../desktop-test/lib/index.js', import.meta.url).href], + ['@fluentui-react-native/desktop-driver-mcp', new URL('../../../desktop-driver-mcp/lib/index.js', import.meta.url).href], +]); + +const forbiddenPackages = new Set(['react', 'react-dom', 'react-native', 'storybook', '@types/react', '@types/react-native']); + +function packageName(specifier) { + const segments = specifier.split('/'); + return specifier.startsWith('@') ? segments.slice(0, 2).join('/') : segments[0]; +} + +function isForbidden(specifier) { + const name = packageName(specifier); + return ( + forbiddenPackages.has(name) || + name.startsWith('@react-native/') || + name.startsWith('@storybook/') || + name.startsWith('@fluentui-react-native/storybook-') || + name.startsWith('storybook-') + ); +} + +export async function resolve(specifier, context, nextResolve) { + if (isForbidden(specifier)) { + throw new Error(`Neutral package boundary rejected forbidden import: ${specifier}`); + } + + if (specifier === '@fluentui-react-native/desktop-driver' && context.parentURL?.includes('/desktop-driver-mcp/')) { + throw new Error('Neutral package boundary rejected desktop-driver root import from the MCP adapter.'); + } + + const packageName = specifier.split('/').slice(0, 2).join('/'); + const workspaceParentURL = workspaceEntryPoints.get(packageName); + if (workspaceParentURL) { + return nextResolve(specifier, { ...context, parentURL: workspaceParentURL }); + } + + return nextResolve(specifier, context); +} diff --git a/packages/agentic/desktop-test/fixtures/neutral-boundary/negative-dependencies/manifest.json b/packages/agentic/desktop-test/fixtures/neutral-boundary/negative-dependencies/manifest.json new file mode 100644 index 0000000000..05083cad38 --- /dev/null +++ b/packages/agentic/desktop-test/fixtures/neutral-boundary/negative-dependencies/manifest.json @@ -0,0 +1,7 @@ +{ + "dependencies": { + "react": "1.0.0", + "react-native": "1.0.0", + "@storybook/react": "1.0.0" + } +} diff --git a/packages/agentic/desktop-test/fixtures/neutral-boundary/negative-imports/react-native.mjs b/packages/agentic/desktop-test/fixtures/neutral-boundary/negative-imports/react-native.mjs new file mode 100644 index 0000000000..1ab6eba688 --- /dev/null +++ b/packages/agentic/desktop-test/fixtures/neutral-boundary/negative-imports/react-native.mjs @@ -0,0 +1 @@ +import 'react-native'; diff --git a/packages/agentic/desktop-test/fixtures/neutral-boundary/negative-imports/react.mjs b/packages/agentic/desktop-test/fixtures/neutral-boundary/negative-imports/react.mjs new file mode 100644 index 0000000000..83bcf4d108 --- /dev/null +++ b/packages/agentic/desktop-test/fixtures/neutral-boundary/negative-imports/react.mjs @@ -0,0 +1 @@ +import 'react'; diff --git a/packages/agentic/desktop-test/fixtures/neutral-boundary/negative-imports/storybook.mjs b/packages/agentic/desktop-test/fixtures/neutral-boundary/negative-imports/storybook.mjs new file mode 100644 index 0000000000..107c2417cf --- /dev/null +++ b/packages/agentic/desktop-test/fixtures/neutral-boundary/negative-imports/storybook.mjs @@ -0,0 +1 @@ +import '@storybook/react'; diff --git a/packages/agentic/desktop-test/fixtures/neutral-boundary/standalone-consumer.mjs b/packages/agentic/desktop-test/fixtures/neutral-boundary/standalone-consumer.mjs new file mode 100644 index 0000000000..4c210d384d --- /dev/null +++ b/packages/agentic/desktop-test/fixtures/neutral-boundary/standalone-consumer.mjs @@ -0,0 +1,25 @@ +import { createDesktopDriverClient } from '@fluentui-react-native/desktop-driver/client'; +import { DesktopAuthority } from '@fluentui-react-native/desktop-driver/authority'; +import { resolveNativeDesktopDriver, verifyNativeDriverArtifact } from '@fluentui-react-native/desktop-driver/native'; +import { describeOperations } from '@fluentui-react-native/desktop-driver/operations'; +import { connectWithDescriptor } from '@fluentui-react-native/desktop-driver-mcp'; +import { defineDesktopConfig } from '@fluentui-react-native/desktop-test/config'; +import { startDesktopService, startNativeDesktopService } from '@fluentui-react-native/desktop-test/driver-service'; + +const catalog = describeOperations({ accessibilityActions: false, boundedObservation: false }); + +if ( + typeof createDesktopDriverClient !== 'function' || + typeof DesktopAuthority !== 'function' || + typeof resolveNativeDesktopDriver !== 'function' || + typeof verifyNativeDriverArtifact !== 'function' || + catalog.schemaVersion !== 1 || + typeof defineDesktopConfig !== 'function' || + typeof startDesktopService !== 'function' || + typeof startNativeDesktopService !== 'function' || + typeof connectWithDescriptor !== 'function' +) { + throw new Error('Standalone desktop consumer did not load its declared package APIs.'); +} + +console.log('standalone-consumer-ok'); diff --git a/packages/agentic/desktop-test/references/contributing.md b/packages/agentic/desktop-test/references/contributing.md index e663567618..d5f7175b95 100644 --- a/packages/agentic/desktop-test/references/contributing.md +++ b/packages/agentic/desktop-test/references/contributing.md @@ -16,6 +16,10 @@ session wiring is in `src/wdio/`. Add contract coverage for schema, lifecycle, reporting protocol, and failure paths. Do not move Storybook-specific story extraction into this package. +The package-boundary contract exercises the built public entry points with a +loader that rejects React, React Native, and Storybook imports; keep its +standalone consumer and negative fixtures representative of package manifests +and runtime imports. Run `yarn format`, `yarn lint`, `yarn build`, and `yarn test` from the package. Run consumer suites when changing public configuration or lifecycle behavior. diff --git a/packages/agentic/desktop-test/references/current-status.md b/packages/agentic/desktop-test/references/current-status.md index 02fb895fa5..ce464c77fa 100644 --- a/packages/agentic/desktop-test/references/current-status.md +++ b/packages/agentic/desktop-test/references/current-status.md @@ -17,23 +17,23 @@ and its sub-issues. ## Capability matrix -| Capability | State | Limit or next gate | -| -------------------------------------------------------- | ------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------- | -| App/suite configuration and standalone installed-app use | Done | Storybook is optional; executable config is trusted operator code, not a sandbox. | -| Native service and helper composition | Done | Generic supervisor and supervised Storybook child use the same real `driverService` factory, helper policy, authority and settled close. | -| Standalone WDIO/Jasmine execution | Done | WDIO owns its session. Storybook CSF callbacks use a runner-owned session borrowed by a Node worker. | -| Required services, reporting, structured results | Done | One collector; bounded JSON/NDJSON summaries. Service-ready is not app/context-ready. | -| `serve --agent` descriptor publication | Done | Protects driver routes; no automatic build/launch from MCP. Normal WDIO cannot use the agent-served path yet. | -| Cleanup failure fence | Done, conservative | Failed cleanup retains `interactive.lock`; manual exact-owner/resource inspection is required. No automatic reclaim. | -| Complete lifecycle settlement | Work in progress | Guarded abandoned work, late acquisitions, exact resource ledger, and report/workload delegation separation need the shared resource model. | -| Durable quarantine wiring | Done | Both native service paths use owner-only storage and exact-incarnation probes; restart is not recovery proof. Live endpoint qualification remains separate. | -| Supervisor crash containment | Work in progress | Child lifelines, survivor reconciliation, stale-claim protocol, status/stop/recover tooling. | -| Storybook resource contributions | Work in progress | Current integration substitutes its CLI lifecycle; retain the channel/driver child until relocation is justified and qualified. | -| MCP/WDIO handoff | Work in progress | Must await drain/deletion; attached-app handoff is independent of future supervisor-owned launch. | -| Supervisor-owned app lifetime | Work in progress | Current session-owned launch/externally owned attach semantics remain; never silently retain or terminate another owner's app. | -| Cross-service/multi-target claims | Work in progress | Target aliases and input mutexes are not exact-application exclusion; resolve registered-ID collisions before expanding hosts. | -| Bounded persisted run-query/control API | Work in progress | Schemas belong here. Agents may eventually select only declared workload IDs, not commands/paths/environment. | -| Automatic service reuse and per-user daemon | Deferred | Requires exact identity/config matching and evidence of need. Never adopt an unknown port occupant. | +| Capability | State | Limit or next gate | +| -------------------------------------------------------- | ------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| App/suite configuration and standalone installed-app use | Done | Storybook is optional; runtime boundary and standalone-consumer contracts reject React, React Native, and Storybook imports/dependencies. Executable config is trusted operator code, not a sandbox. | +| Native service and helper composition | Done | Generic supervisor and supervised Storybook child use the same real `driverService` factory, helper policy, authority and settled close. | +| Standalone WDIO/Jasmine execution | Done | WDIO owns its session. Storybook CSF callbacks use a runner-owned session borrowed by a Node worker. | +| Required services, reporting, structured results | Done | One collector; bounded JSON/NDJSON summaries. Service-ready is not app/context-ready. | +| `serve --agent` descriptor publication | Done | Protects driver routes; no automatic build/launch from MCP. Normal WDIO cannot use the agent-served path yet. | +| Cleanup failure fence | Done, conservative | Failed cleanup retains `interactive.lock`; manual exact-owner/resource inspection is required. No automatic reclaim. | +| Complete lifecycle settlement | Work in progress | Guarded abandoned work, late acquisitions, exact resource ledger, and report/workload delegation separation need the shared resource model. | +| Durable quarantine wiring | Done | Both native service paths use owner-only storage and exact-incarnation probes; restart is not recovery proof. Live endpoint qualification remains separate. | +| Supervisor crash containment | Work in progress | Child lifelines, survivor reconciliation, stale-claim protocol, status/stop/recover tooling. | +| Storybook resource contributions | Work in progress | Current integration substitutes its CLI lifecycle; retain the channel/driver child until relocation is justified and qualified. | +| MCP/WDIO handoff | Work in progress | Must await drain/deletion; attached-app handoff is independent of future supervisor-owned launch. | +| Supervisor-owned app lifetime | Work in progress | Current session-owned launch/externally owned attach semantics remain; never silently retain or terminate another owner's app. | +| Cross-service/multi-target claims | Work in progress | Target aliases and input mutexes are not exact-application exclusion; resolve registered-ID collisions before expanding hosts. | +| Bounded persisted run-query/control API | Work in progress | Schemas belong here. Agents may eventually select only declared workload IDs, not commands/paths/environment. | +| Automatic service reuse and per-user daemon | Deferred | Requires exact identity/config matching and evidence of need. Never adopt an unknown port occupant. | See [lifecycle](lifecycle.md), [commands](commands.md), and `@fluentui-react-native/desktop-driver/references/current-status.md` for the diff --git a/packages/agentic/desktop-test/src/driverService.ts b/packages/agentic/desktop-test/src/driverService.ts index 6dd4d71c6a..5584b68156 100644 --- a/packages/agentic/desktop-test/src/driverService.ts +++ b/packages/agentic/desktop-test/src/driverService.ts @@ -1,7 +1,8 @@ import { createHash } from 'node:crypto'; -import { NativeDesktopHost, resolveNativeDesktopDriver } from '@fluentui-react-native/desktop-driver'; +import { NativeDesktopHost } from '@fluentui-react-native/desktop-driver'; import type { DesktopHost, DesktopTarget, NativeDesktopHostOptions, NativeDriverArtifact } from '@fluentui-react-native/desktop-driver'; +import { resolveNativeDesktopDriver } from '@fluentui-react-native/desktop-driver/native'; import { createMacOSApplicationProbe, createMacOSPrivateStorage, diff --git a/packages/agentic/desktop-test/src/packageBoundary.test.ts b/packages/agentic/desktop-test/src/packageBoundary.test.ts new file mode 100644 index 0000000000..5f8710dd5d --- /dev/null +++ b/packages/agentic/desktop-test/src/packageBoundary.test.ts @@ -0,0 +1,79 @@ +import { readFileSync } from 'node:fs'; +import { spawnSync } from 'node:child_process'; +import path from 'node:path'; + +const packageRoot = path.resolve(__dirname, '..'); +const repoRoot = path.resolve(packageRoot, '../../..'); +const fixtureRoot = path.join(packageRoot, 'fixtures/neutral-boundary'); +const loaderPath = path.join(fixtureRoot, 'loader.mjs'); +const neutralPackages = ['packages/agentic/desktop-driver', 'packages/agentic/desktop-test', 'packages/agentic/desktop-driver-mcp']; + +type PackageManifest = { + dependencies?: Record; + devDependencies?: Record; + optionalDependencies?: Record; + peerDependencies?: Record; +}; + +const forbiddenPackages = new Set(['react', 'react-dom', 'react-native', 'storybook', '@types/react', '@types/react-native']); + +function packageName(specifier: string): string { + const segments = specifier.split('/'); + return specifier.startsWith('@') ? segments.slice(0, 2).join('/') : segments[0]; +} + +function isForbiddenPackage(specifier: string): boolean { + const name = packageName(specifier); + return ( + forbiddenPackages.has(name) || + name.startsWith('@react-native/') || + name.startsWith('@storybook/') || + name.startsWith('@fluentui-react-native/storybook-') || + name.startsWith('storybook-') + ); +} + +function declaredForbiddenPackages(manifest: PackageManifest): string[] { + return Object.values(manifest) + .flatMap((dependencies) => Object.keys(dependencies ?? {})) + .filter(isForbiddenPackage) + .sort(); +} + +function runNode(entry: string): ReturnType { + return spawnSync(process.execPath, ['--experimental-loader', loaderPath, entry], { + cwd: fixtureRoot, + encoding: 'utf8', + }); +} + +describe('application-neutral desktop package boundaries', () => { + test.each(neutralPackages)('%s declares no React, React Native, or Storybook dependency', (relativePackage) => { + const manifest = JSON.parse(readFileSync(path.join(repoRoot, relativePackage, 'package.json'), 'utf8')) as PackageManifest; + expect(declaredForbiddenPackages(manifest)).toEqual([]); + }); + + test('detects prohibited package dependencies in the negative manifest fixture', () => { + const manifest = JSON.parse(readFileSync(path.join(fixtureRoot, 'negative-dependencies/manifest.json'), 'utf8')) as PackageManifest; + expect(declaredForbiddenPackages(manifest)).toEqual(['@storybook/react', 'react', 'react-native']); + }); + + test.each(['react', 'react-native', 'storybook'])('rejects a real %s import in the negative fixture', (packageName) => { + const entry = path.join(fixtureRoot, `negative-imports/${packageName}.mjs`); + const result = runNode(entry); + + expect(result.status).not.toBe(0); + expect(result.stderr).toContain( + `Neutral package boundary rejected forbidden import: ${packageName === 'storybook' ? '@storybook/react' : packageName}`, + ); + }); + + test('runs a standalone consumer through public entries without Storybook', () => { + const consumer = path.join(fixtureRoot, 'standalone-consumer.mjs'); + const result = runNode(consumer); + + expect(result.status).toBe(0); + expect(result.stdout?.toString().trim()).toBe('standalone-consumer-ok'); + expect(result.stderr?.toString()).not.toContain('Neutral package boundary rejected'); + }); +});