From 3612230fec112f770752f95f832e12ef7e160559 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Sat, 21 Nov 2026 09:10:08 +0100 Subject: [PATCH 1/3] refactor(install)!: remove the GitHub Actions artifact install source install-from-source --github-actions-artifact, the installSource config key, and the github-actions-artifact client source kind only worked with a remote daemon that held its own GitHub credentials. No local daemon or provider runtime resolves them; each one failed with "require a compatible remote daemon". A GitHub artifact already has a signed download URL that needs no credentials. Pass that URL to install-from-source . The help and docs show how to get it. --- .../client/src/__tests__/index-apps.test.ts | 28 ---- .../src/flag-definitions-target.ts | 17 --- .../command-surface/src/management/install.ts | 41 +---- .../command-surface/src/schema/cli-config.ts | 6 - .../src/schema/option-schema.test.ts | 2 - .../src/schema/option-schema.ts | 1 - packages/contracts/src/cli-flags.ts | 3 - .../daemon-client/src/__tests__/index.test.ts | 31 ---- .../http-server-rpc-validation.test.ts | 15 -- .../src/server/http/http-rpc-methods.ts | 79 +--------- .../http-server-provider-scenarios.test.ts | 29 ---- .../install-source-resolution.test.ts | 6 +- .../src/sessions/install-source-resolution.ts | 21 +-- packages/kernel/src/contracts.ts | 21 +-- .../platform-android/src/install-artifact.ts | 4 +- .../src/core/install-artifact.ts | 6 +- packages/provision-kit/package.json | 4 - .../src/install-source-config.test.ts | 141 ------------------ .../src/install-source-config.ts | 111 -------------- packages/provision-kit/src/install-source.ts | 6 +- .../proxy/src/install-source-admission.ts | 2 +- scripts/integration-progress-model.ts | 1 - scripts/layering/package-boundaries.test.ts | 1 - src/__tests__/cli-client-commands.test.ts | 121 +-------------- src/__tests__/cli-config.test.ts | 40 ----- .../__tests__/args-parse-session.test.ts | 17 --- .../schema/cli-help-command-usage.test.ts | 4 +- src/commands/schema/cli-help-overview.test.ts | 2 +- src/commands/schema/cli-help-topics.test.ts | 8 +- src/commands/schema/cli-help.ts | 2 +- src/commands/schema/usage.test.ts | 3 +- src/commands/schema/usage.ts | 2 +- src/sdk/install-source.ts | 2 +- website/docs/docs/client-api.md | 16 +- website/docs/docs/commands.md | 20 ++- website/docs/docs/configuration.md | 17 +-- 36 files changed, 58 insertions(+), 772 deletions(-) delete mode 100644 packages/provision-kit/src/install-source-config.test.ts delete mode 100644 packages/provision-kit/src/install-source-config.ts diff --git a/packages/client/src/__tests__/index-apps.test.ts b/packages/client/src/__tests__/index-apps.test.ts index a1e947a3b8..b47f207a19 100644 --- a/packages/client/src/__tests__/index-apps.test.ts +++ b/packages/client/src/__tests__/index-apps.test.ts @@ -434,31 +434,3 @@ test('apps.installFromSource derives Android launchTarget from packageName when }, }); }); - -test('apps.installFromSource forwards GitHub Actions artifact sources unchanged', async () => { - const setup = createClientTransport(async () => ({ - ok: true, - data: { - packageName: 'com.example.ci', - }, - })); - const client = createAgentDeviceClient(setup.config, { transport: setup.transport }); - - await client.apps.installFromSource({ - platform: 'android', - source: { - kind: 'github-actions-artifact', - owner: 'acme', - repo: 'mobile', - artifactId: 1234567890, - }, - }); - - assert.equal(setup.calls.length, 1); - assert.deepEqual(setup.calls[0]?.meta?.installSource, { - kind: 'github-actions-artifact', - owner: 'acme', - repo: 'mobile', - artifactId: 1234567890, - }); -}); diff --git a/packages/command-registry/src/flag-definitions-target.ts b/packages/command-registry/src/flag-definitions-target.ts index 0f774ed963..f957565304 100644 --- a/packages/command-registry/src/flag-definitions-target.ts +++ b/packages/command-registry/src/flag-definitions-target.ts @@ -460,23 +460,6 @@ export const TARGET_FLAG_DEFINITIONS: readonly FlagDefinition[] = [ projectConfig: false, recorded: false, }, - { - key: 'githubActionsArtifact', - names: ['--github-actions-artifact'], - type: 'string', - usageLabel: '--github-actions-artifact ', - usageDescription: 'install-from-source: GitHub Actions artifact resolved by a remote daemon', - projectConfig: false, - recorded: false, - }, - { - key: 'installSource', - // Config-only virtual option; parsed explicitly from JSON before generic string options. - names: [], - type: 'string', - projectConfig: false, - recorded: false, - }, { key: 'session', names: ['--session'], diff --git a/packages/command-surface/src/management/install.ts b/packages/command-surface/src/management/install.ts index d0f2cf3b67..75fd8f09c0 100644 --- a/packages/command-surface/src/management/install.ts +++ b/packages/command-surface/src/management/install.ts @@ -4,7 +4,6 @@ import type { CliFlags } from '@agent-device/contracts/command'; import type { CommandSchemaOverride } from '@agent-device/command-registry/command-schema'; import { LEASE_DEVICE_SPEC_FLAGS } from '@agent-device/command-registry/flag-groups'; import { AppError } from '@agent-device/kernel/errors'; -import { parseGitHubActionsArtifactInstallSourceSpec } from '@agent-device/provision-kit/install-source-config'; import { booleanField, jsonSchemaField, @@ -57,7 +56,7 @@ const uninstallCommandMetadata = defineFieldCommandMetadata( const installFromSourceCommandMetadata = defineFieldCommandMetadata( 'install-from-source', - 'Install app builds from URLs, remote source specs, or CI artifacts resolved by a remote daemon. The command allows 600s, including up to 120s for the download; local Android and iOS install steps time out after 120s.', + 'Install app builds from URLs, including signed CI artifact download URLs. The command allows 600s, including up to 120s for the download; local Android and iOS install steps time out after 120s.', { source: requiredField( jsonSchemaField(looseObjectSchema('Install source object.')), @@ -85,12 +84,11 @@ const uninstallCliSchema = { } as const satisfies CommandSchemaOverride; const installFromSourceCliSchema = { - usageOverride: - 'install-from-source | install-from-source --github-actions-artifact ', + usageOverride: 'install-from-source ', usageFlags: [], listUsageOverride: 'install-from-source', positionalArgs: ['url?'], - allowedFlags: ['header', 'githubActionsArtifact', 'installSource', 'retainPaths', 'retentionMs'], + allowedFlags: ['header', 'retainPaths', 'retentionMs'], } as const satisfies CommandSchemaOverride; const installCliReader: CliReader = (positionals, flags) => installInputFromCli(positionals, flags); @@ -179,7 +177,7 @@ const installFromSourceCommandFacet = defineCommandFacet({ name: 'install-from-source', effect: 'destructive', text: { - summary: 'Install app builds from URLs or CI artifacts', + summary: 'Install app builds from URLs', searchHint: 'fetch link hosted', }, metadata: installFromSourceCommandMetadata, @@ -228,42 +226,19 @@ function requiredPair(first: unknown, second: unknown): string[] { ]; } -// fallow-ignore-next-line complexity function resolveInstallSource(positionals: string[], flags: CliFlags) { const url = positionals[0]?.trim(); - if (positionals.length > 1) { - throw new AppError( - 'INVALID_ARGS', - 'install-from-source accepts either one positional or --github-actions-artifact', - ); + if (!url || positionals.length > 1) { + throw new AppError('INVALID_ARGS', 'install-from-source requires exactly one '); } - const githubArtifactSource = flags.githubActionsArtifact - ? parseGitHubActionsArtifactInstallSourceSpec(flags.githubActionsArtifact) - : undefined; - const configuredSource = flags.installSource; - const sourceCount = (url ? 1 : 0) + (githubArtifactSource ? 1 : 0) + (configuredSource ? 1 : 0); - if (sourceCount !== 1) { - throw new AppError( - 'INVALID_ARGS', - 'install-from-source requires exactly one source: , --github-actions-artifact, or config installSource', - ); - } - if (!url && flags.header && flags.header.length > 0) { - throw new AppError( - 'INVALID_ARGS', - 'install-from-source --header is only supported for URL sources', - ); - } - if (githubArtifactSource) return githubArtifactSource; - if (configuredSource) return configuredSource; - if (!isHttpUrl(url!)) { + if (!isHttpUrl(url)) { throw new AppError('INVALID_ARGS', `install-from-source must be an http(s) URL: ${url}`, { hint: 'Install a local build with install .', }); } return { kind: 'url' as const, - url: url!, + url, headers: parseInstallSourceHeaders(flags.header), }; } diff --git a/packages/command-surface/src/schema/cli-config.ts b/packages/command-surface/src/schema/cli-config.ts index 437f658b42..c8d3abaa3b 100644 --- a/packages/command-surface/src/schema/cli-config.ts +++ b/packages/command-surface/src/schema/cli-config.ts @@ -13,7 +13,6 @@ import { getOptionSpec, parseOptionValueFromSource, } from './option-schema.ts'; -import { parseInstallSourceConfig } from '@agent-device/provision-kit/install-source-config'; import { RETIRED_SCREENSHOT_MAX_SIZE } from '@agent-device/contracts/capture'; import { type EnvMap } from '@agent-device/kernel/source-value'; import type { DaemonLockPolicy } from '@agent-device/kernel/contracts'; @@ -169,10 +168,6 @@ function parseConfigObject( `Config key "${rawKey}" is not allowed in ${origin.label}. Move it to ~/.agent-device/config.json, pass it with --config or AGENT_DEVICE_CONFIG, or provide it through CLI flags/environment variables.`, ); } - if (key === 'installSource') { - flags.installSource = parseInstallSourceConfig(rawValue, origin.label); - continue; - } (flags as Record)[key] = parseOptionValueFromSource( spec, rawValue, @@ -214,7 +209,6 @@ function readEnvFlagDefaults(env: EnvMap, command: string | null): Partial = {}; for (const spec of getConfigurableOptionSpecs(command)) { - if (spec.key === 'installSource') continue; const envValue = spec.env.names .map((name) => ({ name, value: env[name] })) .find((entry) => typeof entry.value === 'string' && entry.value.trim().length > 0); diff --git a/packages/command-surface/src/schema/option-schema.test.ts b/packages/command-surface/src/schema/option-schema.test.ts index b7a0c4d2ee..0f23a39e99 100644 --- a/packages/command-surface/src/schema/option-schema.test.ts +++ b/packages/command-surface/src/schema/option-schema.test.ts @@ -94,8 +94,6 @@ test('configurable option specs are filtered by command support', () => { getConfigurableOptionSpecs('install-from-source').map((spec) => spec.key), ); assert.equal(installFromSourceSpecs.has('header'), true); - assert.equal(installFromSourceSpecs.has('installSource'), true); - assert.equal(installFromSourceSpecs.has('githubActionsArtifact'), false); }); test('isFlagSupportedForCommand consults option schema support map', () => { diff --git a/packages/command-surface/src/schema/option-schema.ts b/packages/command-surface/src/schema/option-schema.ts index c80540f98b..d152410fcc 100644 --- a/packages/command-surface/src/schema/option-schema.ts +++ b/packages/command-surface/src/schema/option-schema.ts @@ -21,7 +21,6 @@ const CONFIG_EXCLUDED_FLAG_KEYS = new Set([ 'help', 'version', 'batchSteps', - 'githubActionsArtifact', // A default must never switch a fill to waiting on stdin. 'textStdin', ]); diff --git a/packages/contracts/src/cli-flags.ts b/packages/contracts/src/cli-flags.ts index bab8ee1662..c0bd29453f 100644 --- a/packages/contracts/src/cli-flags.ts +++ b/packages/contracts/src/cli-flags.ts @@ -6,7 +6,6 @@ import type { SwipePattern } from './scroll-gesture.ts'; import type { BootPickPolicy, DeviceTarget, PlatformSelector } from '@agent-device/kernel/device'; import type { SnapshotPreferredBackend } from '@agent-device/kernel/snapshot'; import type { - DaemonInstallSource, DaemonServerMode, DaemonTransportPreference, LeaseBackend, @@ -137,8 +136,6 @@ export type CliFlags = CloudProviderProfileFields & launchConsole?: string; launchArgs?: string[]; header?: string[]; - githubActionsArtifact?: string; - installSource?: DaemonInstallSource; saveScript?: boolean | string; shutdown?: boolean; relaunch?: boolean; diff --git a/packages/daemon-client/src/__tests__/index.test.ts b/packages/daemon-client/src/__tests__/index.test.ts index 3b643d4cd3..8db9769cf6 100644 --- a/packages/daemon-client/src/__tests__/index.test.ts +++ b/packages/daemon-client/src/__tests__/index.test.ts @@ -1037,37 +1037,6 @@ test('sendToDaemon preserves install_source payload metadata for remote HTTP RPC }); assert.equal((rpcRequest as any)?.params?.meta?.retainMaterializedPaths, true); assert.equal((rpcRequest as any)?.params?.meta?.materializedPathRetentionMs, 60_000); - - seenPaths.length = 0; - rpcRequest = null; - - const githubArtifactResponse = await sendToDaemon({ - session: 'default', - command: 'install_source', - positionals: [], - flags: { platform: 'android' }, - meta: { - requestId: 'req-install-source-gh', - installSource: { - kind: 'github-actions-artifact', - owner: 'acme', - repo: 'mobile', - runId: 1234567890, - artifactName: 'app-debug', - }, - }, - }); - - assert.equal(githubArtifactResponse.ok, true); - assert.deepEqual(seenPaths, ['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/agent-device/health', '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/agent-device/rpc']); - assert.deepEqual((rpcRequest as any)?.params?.meta?.installSource, { - kind: 'github-actions-artifact', - owner: 'acme', - repo: 'mobile', - runId: 1234567890, - artifactName: 'app-debug', - }); - assert.equal((rpcRequest as any)?.params?.meta?.uploadedArtifactId, undefined); }); } finally { restoreHttpRequest(); diff --git a/packages/daemon/src/server/__tests__/http-server-rpc-validation.test.ts b/packages/daemon/src/server/__tests__/http-server-rpc-validation.test.ts index f8ef230be4..3cf669aff4 100644 --- a/packages/daemon/src/server/__tests__/http-server-rpc-validation.test.ts +++ b/packages/daemon/src/server/__tests__/http-server-rpc-validation.test.ts @@ -222,21 +222,6 @@ test('install_from_source still admits url sources', async (t) => { }, t); }); -test('install_from_source still admits github-actions-artifact sources', async (t) => { - await withInstallFromSourceRpcServer(async (post) => { - const { status, dispatched } = await post({ - kind: 'github-actions-artifact', - owner: 'callstack', - repo: 'agent-device', - artifactId: 42, - }); - - assert.equal(status, 200); - assert.equal(dispatched.length, 1); - assert.equal(dispatched[0]?.meta?.installSource?.kind, 'github-actions-artifact'); - }, t); -}); - test('remote HTTP rejects host path install sources in the command RPC used by the CLI', async (t) => { if (await skipWhenLoopbackUnavailable(t)) return; diff --git a/packages/daemon/src/server/http/http-rpc-methods.ts b/packages/daemon/src/server/http/http-rpc-methods.ts index 948de61a0f..4240ef4ff1 100644 --- a/packages/daemon/src/server/http/http-rpc-methods.ts +++ b/packages/daemon/src/server/http/http-rpc-methods.ts @@ -79,75 +79,6 @@ function readBooleanParam(params: Record, key: string): boolean return typeof value === 'boolean' ? value : undefined; } -function readRequiredGitHubArtifactText( - record: Record, - key: 'owner' | 'repo' | 'artifactName', -): string { - const value = typeof record[key] === 'string' ? record[key].trim() : ''; - if (!value) { - throw new AppError( - 'INVALID_ARGS', - `Invalid params: source.${key} is required for github-actions-artifact sources`, - ); - } - return value; -} - -function readGitHubArtifactInteger(record: Record, key: 'artifactId' | 'runId') { - const value = record[key]; - const parsed = - typeof value === 'number' ? value : typeof value === 'string' ? Number(value) : Number.NaN; - if (!Number.isInteger(parsed)) { - throw new AppError('INVALID_ARGS', `Invalid params: source.${key} must be an integer`); - } - return parsed; -} - -function parseGitHubActionsArtifactSource(record: Record): HttpInstallSource { - const owner = readRequiredGitHubArtifactText(record, 'owner'); - const repo = readRequiredGitHubArtifactText(record, 'repo'); - const hasArtifactId = record.artifactId !== undefined; - const hasRunId = record.runId !== undefined; - const hasArtifactName = record.artifactName !== undefined; - if (hasArtifactId && (hasRunId || hasArtifactName)) { - throw new AppError( - 'INVALID_ARGS', - 'Invalid params: source must specify either artifactId or artifactName, not both', - ); - } - if (!hasArtifactId && hasRunId && !hasArtifactName) { - throw new AppError( - 'INVALID_ARGS', - 'Invalid params: source.artifactName is required when source.runId is specified', - ); - } - if (!hasArtifactId && !hasArtifactName) { - throw new AppError( - 'INVALID_ARGS', - 'Invalid params: source must specify artifactId or artifactName', - ); - } - if (hasArtifactId) { - return { - kind: 'github-actions-artifact', - owner, - repo, - artifactId: readGitHubArtifactInteger(record, 'artifactId'), - }; - } - let runId: number | undefined; - if (hasRunId) { - runId = readGitHubArtifactInteger(record, 'runId'); - } - return { - kind: 'github-actions-artifact', - owner, - repo, - ...(hasRunId ? { runId } : {}), - artifactName: readRequiredGitHubArtifactText(record, 'artifactName'), - }; -} - function toLeaseDaemonRequest( command: 'lease_allocate' | 'lease_heartbeat' | 'lease_release', params: Record, @@ -212,16 +143,10 @@ function parseInstallSource(params: Record): HttpInstallSource throw new AppError( 'INVALID_ARGS', 'Invalid params: source.kind "path" names a file on the daemon host and is not accepted over HTTP', - { hint: 'Use a "url" or "github-actions-artifact" source.' }, + { hint: 'Use a "url" source.' }, ); } - if (record.kind === 'github-actions-artifact') { - return parseGitHubActionsArtifactSource(record); - } - throw new AppError( - 'INVALID_ARGS', - 'Invalid params: source.kind must be "url" or "github-actions-artifact"', - ); + throw new AppError('INVALID_ARGS', 'Invalid params: source.kind must be "url"'); } function toInstallFromSourceDaemonRequest( diff --git a/packages/daemon/src/server/http/http-server-provider-scenarios.test.ts b/packages/daemon/src/server/http/http-server-provider-scenarios.test.ts index 4f144231cf..460dccf9c3 100644 --- a/packages/daemon/src/server/http/http-server-provider-scenarios.test.ts +++ b/packages/daemon/src/server/http/http-server-provider-scenarios.test.ts @@ -148,24 +148,6 @@ test('Provider-backed integration daemon HTTP server maps RPC methods, auth, and }); assert.equal(installFromUrl.status, 200); - const installFromGitHub = await callRpc(port, { - jsonrpc: '2.0', - id: 'rpc-install-github', - method: 'agent_device.install_from_source', - params: { - session: 'bootstrap', - platform: 'ios', - source: { - kind: 'github-actions-artifact', - owner: 'acme', - repo: 'mobile', - runId: '1234567890', - artifactName: 'ios-debug', - }, - }, - }); - assert.equal(installFromGitHub.status, 200); - const lease = await callRpc(port, { jsonrpc: '2.0', id: 'rpc-lease', @@ -230,17 +212,6 @@ test('Provider-backed integration daemon HTTP server maps RPC methods, auth, and headers: { authorization: 'Bearer signed-token' }, }); - const githubRequest = observedRequests.find( - (req) => req.command === 'install_source' && req.flags?.platform === 'ios', - ); - assert.deepEqual(githubRequest?.meta?.installSource, { - kind: 'github-actions-artifact', - owner: 'acme', - repo: 'mobile', - runId: 1234567890, - artifactName: 'ios-debug', - }); - const leaseRequest = observedRequests.find((req) => req.command === 'lease_allocate'); assert.equal(leaseRequest?.meta?.tenantId, 'Tenant A'); assert.equal(leaseRequest?.meta?.leaseTtlMs, 60000); diff --git a/packages/daemon/src/sessions/__tests__/install-source-resolution.test.ts b/packages/daemon/src/sessions/__tests__/install-source-resolution.test.ts index 08d4641af7..d169711752 100644 --- a/packages/daemon/src/sessions/__tests__/install-source-resolution.test.ts +++ b/packages/daemon/src/sessions/__tests__/install-source-resolution.test.ts @@ -62,7 +62,7 @@ test('resolveInstallSource leaves URL sources unchanged even when upload metadat resolved.cleanup(); }); -test('resolveInstallSource rejects GitHub Actions artifact sources on the local daemon', () => { +test('resolveInstallSource rejects a source kind it cannot materialize', () => { expect(() => resolveInstallSource( makeRequest({ @@ -71,10 +71,10 @@ test('resolveInstallSource rejects GitHub Actions artifact sources on the local owner: 'acme', repo: 'mobile', artifactId: 1234567890, - }, + } as never, }), ), - ).toThrow(/compatible remote daemon/i); + ).toThrow(/must be "url" or "path"/); }); test('resolveInstallSource refuses an unknown upload id rather than reading the wire path', () => { diff --git a/packages/daemon/src/sessions/install-source-resolution.ts b/packages/daemon/src/sessions/install-source-resolution.ts index 86652c9dfd..b040b3ce0e 100644 --- a/packages/daemon/src/sessions/install-source-resolution.ts +++ b/packages/daemon/src/sessions/install-source-resolution.ts @@ -1,19 +1,12 @@ import { AppError } from '@agent-device/kernel/errors'; -import type { DaemonInstallSource, LocalInstallSource } from '@agent-device/kernel/contracts'; +import type { DaemonInstallSource } from '@agent-device/kernel/contracts'; import { cleanupUploadedArtifact, prepareUploadedArtifact, } from '../resources/artifact-tracking.ts'; import type { DaemonRequest } from '../core/daemon-request.ts'; -function assertUnsupportedInstallSource(source: never): never { - throw new AppError( - 'UNSUPPORTED_OPERATION', - `install_from_source ${String((source as DaemonInstallSource).kind)} sources require a compatible remote daemon`, - ); -} - -function requireInstallSource(req: DaemonRequest): LocalInstallSource { +function requireInstallSource(req: DaemonRequest): DaemonInstallSource { const source = req.meta?.installSource; if (!source) { throw new AppError('INVALID_ARGS', 'install_from_source requires a source payload'); @@ -35,18 +28,16 @@ function requireInstallSource(req: DaemonRequest): LocalInstallSource { ); } return source; - case 'github-actions-artifact': + default: throw new AppError( - 'UNSUPPORTED_OPERATION', - 'install_from_source github-actions-artifact sources require a compatible remote daemon', + 'INVALID_ARGS', + `install_from_source source kind must be "url" or "path": ${String((source as { kind?: unknown }).kind)}`, ); - default: - assertUnsupportedInstallSource(source); } } export function resolveInstallSource(req: DaemonRequest): { - source: LocalInstallSource; + source: DaemonInstallSource; cleanup: () => void; } { const source = requireInstallSource(req); diff --git a/packages/kernel/src/contracts.ts b/packages/kernel/src/contracts.ts index ed2e191a43..ec28d5ae5f 100644 --- a/packages/kernel/src/contracts.ts +++ b/packages/kernel/src/contracts.ts @@ -28,26 +28,7 @@ export type DaemonInstallSource = | { kind: 'path'; path: string; - } - | ({ - kind: 'github-actions-artifact'; - owner: string; - repo: string; - } & ( - | { - artifactId: number; - } - | { - runId: number; - artifactName: string; - } - | { - artifactName: string; - } - )); - -/** Install sources that can be materialized by a local daemon. */ -export type LocalInstallSource = Extract; + }; const DAEMON_LOCK_POLICIES = ['reject', 'strip'] as const; export type DaemonLockPolicy = (typeof DAEMON_LOCK_POLICIES)[number]; diff --git a/packages/platform-android/src/install-artifact.ts b/packages/platform-android/src/install-artifact.ts index dc9fb1ce6e..34c306fec8 100644 --- a/packages/platform-android/src/install-artifact.ts +++ b/packages/platform-android/src/install-artifact.ts @@ -1,5 +1,5 @@ import path from 'node:path'; -import type { LocalInstallSource } from '@agent-device/kernel/contracts'; +import type { DaemonInstallSource } from '@agent-device/kernel/contracts'; import { materializeInstallablePath } from '@agent-device/provision-kit/install-source'; import * as manifest from './manifest.ts'; @@ -11,7 +11,7 @@ export type PreparedAndroidInstallArtifact = { }; export async function prepareAndroidInstallArtifact( - source: LocalInstallSource, + source: DaemonInstallSource, options: { signal?: AbortSignal; resolveIdentity?: boolean; diff --git a/packages/platform-apple/src/core/install-artifact.ts b/packages/platform-apple/src/core/install-artifact.ts index f350f2b39c..675ebf0558 100644 --- a/packages/platform-apple/src/core/install-artifact.ts +++ b/packages/platform-apple/src/core/install-artifact.ts @@ -1,5 +1,5 @@ import path from 'node:path'; -import type { LocalInstallSource } from '@agent-device/kernel/contracts'; +import type { DaemonInstallSource } from '@agent-device/kernel/contracts'; import { readIosBundleInfo } from './bundle-info.ts'; import { AppError } from '@agent-device/kernel/errors'; import { @@ -47,7 +47,7 @@ export type PreparedIosInstallArtifact = { }; export async function prepareIosInstallArtifact( - source: LocalInstallSource, + source: DaemonInstallSource, options: InstallIosArtifactOptions, ): Promise { return await withInstallArtifactArchiveScope( @@ -56,7 +56,7 @@ export async function prepareIosInstallArtifact( } async function prepareIosInstallArtifactInScope( - source: LocalInstallSource, + source: DaemonInstallSource, options: InstallIosArtifactOptions, ): Promise { const materialized = await materializeInstallablePath({ diff --git a/packages/provision-kit/package.json b/packages/provision-kit/package.json index b2cb443c23..effccf51f1 100644 --- a/packages/provision-kit/package.json +++ b/packages/provision-kit/package.json @@ -26,10 +26,6 @@ "types": "./src/install-source.ts", "default": "./src/install-source.ts" }, - "./install-source-config": { - "types": "./src/install-source-config.ts", - "default": "./src/install-source-config.ts" - }, "./install-source-network": { "types": "./src/install-source-network.ts", "default": "./src/install-source-network.ts" diff --git a/packages/provision-kit/src/install-source-config.test.ts b/packages/provision-kit/src/install-source-config.test.ts deleted file mode 100644 index 60c99519e3..0000000000 --- a/packages/provision-kit/src/install-source-config.test.ts +++ /dev/null @@ -1,141 +0,0 @@ -import assert from 'node:assert/strict'; -import { test } from 'vitest'; -import { AppError } from '@agent-device/kernel/errors'; -import { - parseGitHubActionsArtifactInstallSourceSpec, - parseInstallSourceConfig, -} from './install-source-config.ts'; - -function assertInvalidArgs(action: () => unknown, message: string): void { - assert.throws(action, (error: unknown) => { - if (!(error instanceof AppError)) return false; - assert.equal(error.code, 'INVALID_ARGS'); - assert.equal(error.message, message); - assert.equal(error.details, undefined); - assert.equal(error.cause, undefined); - return true; - }); -} - -test('parses artifact IDs and names into the exact install-source shapes', () => { - assert.deepEqual( - parseGitHubActionsArtifactInstallSourceSpec(' callstack / agent-device : 6635342232 '), - { - kind: 'github-actions-artifact', - owner: 'callstack', - repo: 'agent-device', - artifactId: 6635342232, - }, - ); - assert.deepEqual( - parseGitHubActionsArtifactInstallSourceSpec( - 'thymikee/RNCLI83: rn-android-emulator-debug-pr-19', - ), - { - kind: 'github-actions-artifact', - owner: 'thymikee', - repo: 'RNCLI83', - artifactName: 'rn-android-emulator-debug-pr-19', - }, - ); -}); - -test('rejects empty or malformed owner/repo:artifact specs with typed errors', () => { - for (const spec of ['', ' ', ':artifact', 'owner/repo:', 'owner:artifact']) { - assertInvalidArgs( - () => parseGitHubActionsArtifactInstallSourceSpec(spec), - spec === 'owner:artifact' - ? '--github-actions-artifact must use owner/repo.' - : '--github-actions-artifact must use owner/repo:artifact, for example thymikee/RNCLI83:6635342232', - ); - } - - for (const spec of ['/repo:artifact', 'owner/:artifact', 'owner/repo/other:artifact']) { - assertInvalidArgs( - () => parseGitHubActionsArtifactInstallSourceSpec(spec), - '--github-actions-artifact must use owner/repo.', - ); - } -}); - -test('parses config fields with whitespace and preserves artifact field names', () => { - const sourceLabel = 'user config file /tmp/agent-device.json'; - assert.deepEqual( - parseInstallSourceConfig( - { - type: ' github-actions-artifact ', - repo: ' thymikee / RNCLI83 ', - artifact: ' 6635342232 ', - }, - sourceLabel, - ), - { - kind: 'github-actions-artifact', - owner: 'thymikee', - repo: 'RNCLI83', - artifactId: 6635342232, - }, - ); - assert.deepEqual( - parseInstallSourceConfig( - { - type: 'github-actions-artifact', - repo: 'callstack/agent-device', - artifact: 'nightly-release', - }, - sourceLabel, - ), - { - kind: 'github-actions-artifact', - owner: 'callstack', - repo: 'agent-device', - artifactName: 'nightly-release', - }, - ); -}); - -test('rejects empty and malformed config fields with typed errors and no cause', () => { - const sourceLabel = 'project config file /tmp/agent-device.json'; - assertInvalidArgs( - () => parseInstallSourceConfig(undefined, sourceLabel), - `${sourceLabel} installSource must be an object.`, - ); - assertInvalidArgs( - () => parseInstallSourceConfig([], sourceLabel), - `${sourceLabel} installSource must be an object.`, - ); - assertInvalidArgs( - () => - parseInstallSourceConfig({ type: ' ', repo: 'owner/repo', artifact: 'build' }, sourceLabel), - `${sourceLabel} installSource.type must be a non-empty string.`, - ); - assertInvalidArgs( - () => - parseInstallSourceConfig({ type: 'url', repo: 'owner/repo', artifact: 'build' }, sourceLabel), - `${sourceLabel} installSource.type must be "github-actions-artifact".`, - ); - assertInvalidArgs( - () => - parseInstallSourceConfig( - { type: 'github-actions-artifact', repo: 'owner/repo/other', artifact: 'build' }, - sourceLabel, - ), - `${sourceLabel} installSource.repo must use owner/repo.`, - ); - assertInvalidArgs( - () => - parseInstallSourceConfig( - { type: 'github-actions-artifact', repo: 'owner/repo', artifact: ' ' }, - sourceLabel, - ), - `${sourceLabel} installSource.artifact must be a non-empty string.`, - ); - assertInvalidArgs( - () => - parseInstallSourceConfig( - { type: 'github-actions-artifact', repo: 'owner/repo', artifact: 1.5 }, - sourceLabel, - ), - `${sourceLabel} installSource.artifact must be an integer.`, - ); -}); diff --git a/packages/provision-kit/src/install-source-config.ts b/packages/provision-kit/src/install-source-config.ts deleted file mode 100644 index 67e17437b9..0000000000 --- a/packages/provision-kit/src/install-source-config.ts +++ /dev/null @@ -1,111 +0,0 @@ -import type { DaemonInstallSource } from '@agent-device/kernel/contracts'; -import { AppError } from '@agent-device/kernel/errors'; - -export function parseGitHubActionsArtifactInstallSourceSpec( - spec: string, - sourceLabel: string = '--github-actions-artifact', -): DaemonInstallSource { - const separator = spec.indexOf(':'); - if (separator <= 0 || separator === spec.length - 1) { - throw new AppError( - 'INVALID_ARGS', - `${sourceLabel} must use owner/repo:artifact, for example thymikee/RNCLI83:6635342232`, - ); - } - const { owner, repo } = parseRepositorySlug(spec.slice(0, separator), sourceLabel); - return buildGitHubActionsArtifactInstallSource( - owner, - repo, - spec.slice(separator + 1), - `${sourceLabel} artifact`, - ); -} - -export function parseInstallSourceConfig(value: unknown, sourceLabel: string): DaemonInstallSource { - if (!value || typeof value !== 'object' || Array.isArray(value)) { - throw new AppError('INVALID_ARGS', `${sourceLabel} installSource must be an object.`); - } - const record = value as Record; - const type = readRequiredText(record.type, `${sourceLabel} installSource.type`); - if (type !== 'github-actions-artifact') { - throw new AppError( - 'INVALID_ARGS', - `${sourceLabel} installSource.type must be "github-actions-artifact".`, - ); - } - const { owner, repo } = parseRepositorySlug( - readRequiredText(record.repo, `${sourceLabel} installSource.repo`), - `${sourceLabel} installSource.repo`, - ); - return buildGitHubActionsArtifactInstallSource( - owner, - repo, - record.artifact, - `${sourceLabel} installSource.artifact`, - ); -} - -function buildGitHubActionsArtifactInstallSource( - owner: string, - repo: string, - artifact: unknown, - artifactField: string, -): DaemonInstallSource { - if (typeof artifact === 'number' || isIntegerString(artifact)) { - return { - kind: 'github-actions-artifact', - owner, - repo, - artifactId: readInteger(artifact, artifactField), - }; - } - const artifactName = readRequiredText(artifact, artifactField); - return { - kind: 'github-actions-artifact', - owner, - repo, - artifactName, - }; -} - -function parseRepositorySlug(value: string, sourceLabel: string): { owner: string; repo: string } { - const separator = value.indexOf('/'); - if ( - separator <= 0 || - separator === value.length - 1 || - value.indexOf('/', separator + 1) !== -1 - ) { - throw new AppError('INVALID_ARGS', `${sourceLabel} must use owner/repo.`); - } - const result = { - owner: value.slice(0, separator).trim(), - repo: value.slice(separator + 1).trim(), - }; - if (!result.owner || !result.repo) { - throw new AppError('INVALID_ARGS', `${sourceLabel} must use owner/repo.`); - } - return result; -} - -function readText(value: unknown): string | undefined { - return typeof value === 'string' && value.trim().length > 0 ? value.trim() : undefined; -} - -function readRequiredText(value: unknown, field: string): string { - const text = readText(value); - if (!text) throw new AppError('INVALID_ARGS', `${field} must be a non-empty string.`); - return text; -} - -function readInteger(value: unknown, field: string): number { - const parsed = - typeof value === 'number' ? value : typeof value === 'string' ? Number(value) : Number.NaN; - if (!Number.isInteger(parsed)) { - throw new AppError('INVALID_ARGS', `${field} must be an integer.`); - } - return parsed; -} - -function isIntegerString(value: unknown): value is string { - return typeof value === 'string' && /^\d+$/.test(value.trim()); -} diff --git a/packages/provision-kit/src/install-source.ts b/packages/provision-kit/src/install-source.ts index 2bbd6f2fd5..a112e2955a 100644 --- a/packages/provision-kit/src/install-source.ts +++ b/packages/provision-kit/src/install-source.ts @@ -1,7 +1,7 @@ import { promises as fs } from 'node:fs'; import os from 'node:os'; import path from 'node:path'; -import type { LocalInstallSource } from '@agent-device/kernel/contracts'; +import type { DaemonInstallSource } from '@agent-device/kernel/contracts'; import { AppError, createRequestCanceledError } from '@agent-device/kernel/errors'; import { ArchiveBudget } from '@agent-device/host-kit/archive'; import { expandUserHomePath } from '@agent-device/host-kit/file'; @@ -15,7 +15,7 @@ import { approveDownloadSourceUrl } from './install-source-network.ts'; import { downloadInstallSource, invalidSourceUrlError } from './install-source-download.ts'; export type MaterializeInstallableOptions = { - source: LocalInstallSource; + source: DaemonInstallSource; isInstallablePath: ( candidatePath: string, stat: { isFile(): boolean; isDirectory(): boolean }, @@ -183,7 +183,7 @@ function expandSourcePath(inputPath: string, env: NodeJS.ProcessEnv): string { } async function materializeLocalSource( - source: LocalInstallSource, + source: DaemonInstallSource, options: { signal: AbortSignal; environment: NodeJS.ProcessEnv; diff --git a/packages/proxy/src/install-source-admission.ts b/packages/proxy/src/install-source-admission.ts index 405ade94f9..73f01547c2 100644 --- a/packages/proxy/src/install-source-admission.ts +++ b/packages/proxy/src/install-source-admission.ts @@ -12,7 +12,7 @@ export function hostPathInstallSourceRefusedResponse(rpcId: unknown): Response { const error = new AppError( 'INVALID_ARGS', 'Invalid params: an install source of kind "path" names a file on the daemon host and is not accepted through the proxy', - { hint: 'Upload the artifact, or use a "url" or "github-actions-artifact" source.' }, + { hint: 'Upload the artifact, or use a "url" source.' }, ); return Response.json( { diff --git a/scripts/integration-progress-model.ts b/scripts/integration-progress-model.ts index 4da9e70571..50f0d38c8c 100644 --- a/scripts/integration-progress-model.ts +++ b/scripts/integration-progress-model.ts @@ -343,7 +343,6 @@ function summarizeProviderScenarioFlagExclusions() { keys: [ 'artifact', 'dsym', - 'githubActionsArtifact', 'snapshotDiff', 'snapshotForceFull', 'baseline', diff --git a/scripts/layering/package-boundaries.test.ts b/scripts/layering/package-boundaries.test.ts index 3a398d6a25..a42e05effa 100644 --- a/scripts/layering/package-boundaries.test.ts +++ b/scripts/layering/package-boundaries.test.ts @@ -578,7 +578,6 @@ test('the real tree parses, declares, and passes R11', () => { '@agent-device/provision-kit/boot-diagnostics', '@agent-device/provision-kit/install-artifact-archive-context', '@agent-device/provision-kit/install-source', - '@agent-device/provision-kit/install-source-config', '@agent-device/provision-kit/install-source-network', '@agent-device/provision-kit/install-source-network-transport', '@agent-device/provision-kit/provider-lease-table', diff --git a/src/__tests__/cli-client-commands.test.ts b/src/__tests__/cli-client-commands.test.ts index e6a9fe4d00..4ab0fd8cc3 100644 --- a/src/__tests__/cli-client-commands.test.ts +++ b/src/__tests__/cli-client-commands.test.ts @@ -72,115 +72,6 @@ test('install-from-source forwards URL and repeated headers to client.apps.insta }); }); -test('install-from-source forwards GitHub Actions artifact flag to client.apps.installFromSource', async () => { - let observed: AppInstallFromSourceOptions | undefined; - const client = createStubClient({ - installFromSource: async (options) => { - observed = options; - return { - launchTarget: 'com.example.demo', - packageName: 'com.example.demo', - identifiers: { appId: 'com.example.demo', package: 'com.example.demo' }, - }; - }, - }); - - const handled = await tryRunClientBackedCommand({ - command: 'install-from-source', - positionals: [], - flags: { - json: false, - help: false, - version: false, - platform: 'android', - githubActionsArtifact: 'thymikee/RNCLI83:6635342232', - }, - client, - }); - - assert.equal(handled, true); - assert.equal(observed?.platform, 'android'); - assert.deepEqual(observed?.source, { - kind: 'github-actions-artifact', - owner: 'thymikee', - repo: 'RNCLI83', - artifactId: 6635342232, - }); -}); - -test('install-from-source preserves colons in GitHub Actions artifact names', async () => { - let observed: AppInstallFromSourceOptions | undefined; - const client = createStubClient({ - installFromSource: async (options) => { - observed = options; - return { - launchTarget: 'com.example.demo', - packageName: 'com.example.demo', - identifiers: { appId: 'com.example.demo', package: 'com.example.demo' }, - }; - }, - }); - - await tryRunClientBackedCommand({ - command: 'install-from-source', - positionals: [], - flags: { - json: false, - help: false, - version: false, - githubActionsArtifact: 'thymikee/RNCLI83:app:debug:pr-19', - }, - client, - }); - - assert.deepEqual(observed?.source, { - kind: 'github-actions-artifact', - owner: 'thymikee', - repo: 'RNCLI83', - artifactName: 'app:debug:pr-19', - }); -}); - -test('install-from-source forwards configured GitHub Actions artifact name to client.apps.installFromSource', async () => { - let observed: AppInstallFromSourceOptions | undefined; - const client = createStubClient({ - installFromSource: async (options) => { - observed = options; - return { - launchTarget: 'com.example.demo', - packageName: 'com.example.demo', - identifiers: { appId: 'com.example.demo', package: 'com.example.demo' }, - }; - }, - }); - - const handled = await tryRunClientBackedCommand({ - command: 'install-from-source', - positionals: [], - flags: { - json: false, - help: false, - version: false, - platform: 'android', - installSource: { - kind: 'github-actions-artifact', - owner: 'thymikee', - repo: 'RNCLI83', - artifactName: 'rn-android-emulator-debug-pr-19', - }, - }, - client, - }); - - assert.equal(handled, true); - assert.deepEqual(observed?.source, { - kind: 'github-actions-artifact', - owner: 'thymikee', - repo: 'RNCLI83', - artifactName: 'rn-android-emulator-debug-pr-19', - }); -}); - test('install-from-source rejects malformed header syntax', async () => { const client = createStubClient({ installFromSource: async () => { @@ -208,7 +99,7 @@ test('install-from-source rejects malformed header syntax', async () => { ); }); -test('install-from-source rejects headers with GitHub Actions artifact sources', async () => { +test('install-from-source requires a URL', async () => { const client = createStubClient({ installFromSource: async () => { throw new Error('unexpected call'); @@ -220,19 +111,13 @@ test('install-from-source rejects headers with GitHub Actions artifact sources', tryRunClientBackedCommand({ command: 'install-from-source', positionals: [], - flags: { - json: false, - help: false, - version: false, - githubActionsArtifact: 'thymikee/RNCLI83:6635342232', - header: ['authorization: Bearer token'], - }, + flags: { json: false, help: false, version: false }, client, }), (error) => error instanceof AppError && error.code === 'INVALID_ARGS' && - error.message.includes('--header is only supported for URL sources'), + error.message.includes('requires exactly one '), ); }); diff --git a/src/__tests__/cli-config.test.ts b/src/__tests__/cli-config.test.ts index 7ad546e16f..cd3a009c15 100644 --- a/src/__tests__/cli-config.test.ts +++ b/src/__tests__/cli-config.test.ts @@ -139,46 +139,6 @@ test('config can set appsFilter through canonical enum values', async () => { fs.rmSync(root, { recursive: true, force: true }); }); -test('user config can provide install-from-source GitHub Actions artifact source', async () => { - const { root, home, project } = makeTempWorkspace(); - fs.mkdirSync(path.join(home, '.agent-device'), { recursive: true }); - fs.writeFileSync( - path.join(home, '.agent-device', 'config.json'), - JSON.stringify({ - platform: 'android', - installSource: { - type: 'github-actions-artifact', - repo: 'thymikee/RNCLI83', - artifact: 'rn-android-emulator-debug-pr-19', - }, - }), - 'utf8', - ); - - const result = await runCliCapture(['install-from-source', '--json'], { - cwd: project, - env: { HOME: home }, - sendToDaemon: async () => ({ - ok: true, - data: { - packageName: 'com.example.demo', - }, - }), - }); - - assert.equal(result.code, null); - assert.equal(result.calls.length, 1); - assert.equal(result.calls[0]?.flags?.platform, 'android'); - assert.deepEqual(result.calls[0]?.meta?.installSource, { - kind: 'github-actions-artifact', - owner: 'thymikee', - repo: 'RNCLI83', - artifactName: 'rn-android-emulator-debug-pr-19', - }); - - fs.rmSync(root, { recursive: true, force: true }); -}); - test('command-specific config defaults are ignored for commands that do not support them', async () => { const { root, home, project } = makeTempWorkspace(); fs.mkdirSync(path.join(home, '.agent-device'), { recursive: true }); diff --git a/src/cli/parser/__tests__/args-parse-session.test.ts b/src/cli/parser/__tests__/args-parse-session.test.ts index d53d63fdcf..16f3cd0314 100644 --- a/src/cli/parser/__tests__/args-parse-session.test.ts +++ b/src/cli/parser/__tests__/args-parse-session.test.ts @@ -472,23 +472,6 @@ test('parseArgs accepts open --launch-args with double-dash-prefixed values', () assert.deepEqual(parsed.flags.launchArgs, ['--es', 'EXTRA_CONFIG', '{"mode":"debug"}']); }); -test('parseArgs accepts install-from-source GitHub Actions artifact flag', () => { - const parsed = parseArgs( - [ - 'install-from-source', - '--github-actions-artifact', - 'thymikee/RNCLI83:6635342232', - '--platform', - 'android', - ], - { strictFlags: true }, - ); - assert.equal(parsed.command, 'install-from-source'); - assert.deepEqual(parsed.positionals, []); - assert.equal(parsed.flags.githubActionsArtifact, 'thymikee/RNCLI83:6635342232'); - assert.equal(parsed.flags.platform, 'android'); -}); - test('parseArgs accepts metro prepare arguments', () => { const parsed = parseArgs( [ diff --git a/src/commands/schema/cli-help-command-usage.test.ts b/src/commands/schema/cli-help-command-usage.test.ts index a05380a5f1..14c3f82391 100644 --- a/src/commands/schema/cli-help-command-usage.test.ts +++ b/src/commands/schema/cli-help-command-usage.test.ts @@ -208,10 +208,10 @@ test('connect command help lists lease id in usage and flags', async () => { assert.doesNotMatch(help, /--launch-url /); }); -test('install-from-source command help describes all source types', async () => { +test('install-from-source command help names signed CI artifact URLs', async () => { const help = await usageForCommand('install-from-source'); if (help === null) throw new Error('Expected command help text'); - assert.match(help, /Install app builds from URLs, remote source specs, or CI artifacts/); + assert.match(help, /Install app builds from URLs, including signed CI artifact download URLs/); }); test('session command help includes daemon state directory discovery', async () => { diff --git a/src/commands/schema/cli-help-overview.test.ts b/src/commands/schema/cli-help-overview.test.ts index 105680e982..b9eb8c53be 100644 --- a/src/commands/schema/cli-help-overview.test.ts +++ b/src/commands/schema/cli-help-overview.test.ts @@ -46,7 +46,7 @@ test('help commands preserves the complete reference displaced from root help', assert.match(help, /^agent-device \S+ — commands/); assert.match(help, /^Commands:/m); - assert.match(help, /install-from-source\s{2,}Install app builds from URLs or CI artifacts/); + assert.match(help, /install-from-source\s{2,}Install app builds from URLs$/m); assert.match(help, /^Global Flags:/m); assert.match(help, /^Configuration:/m); assert.match(help, /^Environment:/m); diff --git a/src/commands/schema/cli-help-topics.test.ts b/src/commands/schema/cli-help-topics.test.ts index 76ec9883a2..1e44638207 100644 --- a/src/commands/schema/cli-help-topics.test.ts +++ b/src/commands/schema/cli-help-topics.test.ts @@ -5,7 +5,7 @@ import { usage, usageForCommand } from '../../cli/parser/args.ts'; test('commands topic includes concise command catalog entries', async () => { const usageText = await usageForCommand('commands'); if (usageText === null) throw new Error('Expected commands help text'); - assert.match(usageText, /install-from-source\s{2,}Install app builds from URLs or CI artifacts/); + assert.match(usageText, /install-from-source\s{2,}Install app builds from URLs$/m); assert.match(usageText, /prepare\s{2,}Pre-warm platform helpers before automation/); assert.match(usageText, /metro\s{2,}Prepare the dev server or reload apps/); assert.match(usageText, /batch --steps \| --steps-file /); @@ -17,10 +17,6 @@ test('commands topic includes concise command catalog entries', async () => { usageText, /gesture \.\.\./, ); - assert.doesNotMatch( - usageText, - /install-from-source \| install-from-source --github-actions-artifact/, - ); assert.doesNotMatch(usageText, /prepare ios-runner --platform ios\|macos/); assert.doesNotMatch(usageText, /metro prepare --public-base-url /); assert.doesNotMatch(usageText, /^ {2}network dump/m); @@ -477,7 +473,7 @@ test('usageForCommand resolves remote help topic', async () => { assert.match(help, /local\/proxy iOS reports that the runner is already owned/); assert.match(help, /same --remote-config to every operational command/); assert.match(help, /Do not use --config as a remote profile flag/); - assert.match(help, /install-from-source --github-actions-artifact org\/repo:artifact/); + assert.match(help, /GitHub Actions artifact, pass its signed download URL/); }); test('usageForCommand resolves physical-device help topic', async () => { diff --git a/src/commands/schema/cli-help.ts b/src/commands/schema/cli-help.ts index 847b6988e2..c0c80d96f6 100644 --- a/src/commands/schema/cli-help.ts +++ b/src/commands/schema/cli-help.ts @@ -619,7 +619,7 @@ Rules: If local/proxy iOS reports that the runner is already owned by another agent-device daemon after lease admission, retry after the owning session closes or after lease expiry. If the conflict repeats, clean stale daemon state on the machine with simulator access. Do not use --config as a remote profile flag. --config loads CLI defaults; --remote-config selects remote daemon/profile settings. For self-contained scripts, pass the same --remote-config to every operational command, including disconnect; a preceding connect is optional but not required. - For remote artifact installs, use install-from-source or install-from-source --github-actions-artifact org/repo:artifact; do not download CI artifacts locally first. + For remote artifact installs, use install-from-source ; do not download CI artifacts locally first. For a GitHub Actions artifact, pass its signed download URL: the Location header of GET https://api.github.com/repos///actions/artifacts//zip. The URL expires after about one minute. After connect, let the active remote connection supply runtime hints. For connected phone/tablet setup and iOS signing prerequisites, read agent-device help physical-device. Use --debug when remote connection or transport errors need diagnostic ids and remote log hints.`, diff --git a/src/commands/schema/usage.test.ts b/src/commands/schema/usage.test.ts index b3ef1fde4c..7dfee97ed3 100644 --- a/src/commands/schema/usage.test.ts +++ b/src/commands/schema/usage.test.ts @@ -41,9 +41,8 @@ test('synopsis names each tailed option with its declared label, aliases include ); }); -test('synopsis omits a hidden option and an option with no CLI token', () => { +test('synopsis omits a hidden option', () => { assert.equal(synopsisFor({ allowedFlags: ['snapshotDiff', 'record'] }), 'sample [--diff]'); - assert.equal(synopsisFor({ allowedFlags: ['snapshotDiff', 'installSource'] }), 'sample [--diff]'); }); test('synopsis renders positionals before the flag tail', () => { diff --git a/src/commands/schema/usage.ts b/src/commands/schema/usage.ts index c33135da9e..6c22c3bf90 100644 --- a/src/commands/schema/usage.ts +++ b/src/commands/schema/usage.ts @@ -14,7 +14,7 @@ function flagDefinitionsForKey(key: FlagKey): FlagDefinition[] { /** * An option's synopsis token is its `usageLabel`, else its first CLI name: nothing for a - * `usageHidden` option, or one with no CLI name at all (a config-only virtual option). + * `usageHidden` option. */ function usageToken(definition: FlagDefinition): string | undefined { if (definition.usageHidden) return undefined; diff --git a/src/sdk/install-source.ts b/src/sdk/install-source.ts index ee5e00f476..9e278b0200 100644 --- a/src/sdk/install-source.ts +++ b/src/sdk/install-source.ts @@ -4,4 +4,4 @@ export { validateDownloadSourceUrl, } from '@agent-device/provision-kit/install-source'; -export type { LocalInstallSource as MaterializeInstallSource } from '@agent-device/kernel/contracts'; +export type { DaemonInstallSource as MaterializeInstallSource } from '@agent-device/kernel/contracts'; diff --git a/website/docs/docs/client-api.md b/website/docs/docs/client-api.md index de25f1fe57..7f8a9fbfe0 100644 --- a/website/docs/docs/client-api.md +++ b/website/docs/docs/client-api.md @@ -471,20 +471,6 @@ If the daemon cannot determine the installed app's identity, the request fails i - URL sources from any public host may point directly to an installable, including a bare iOS `.ipa`, or to a `.zip`, `.tar`, `.tar.gz`, or `.tgz` archive containing exactly one. - For existing reachable artifact URLs, use `source: { kind: 'url', url: ... }`. - For local artifacts, use `source: { kind: 'path', path: ... }` or the CLI `install`/`reinstall` commands. -- When a remote daemon resolves CI artifacts server-side, pass a GitHub Actions artifact source: - -```ts -await client.apps.installFromSource({ - platform: 'android', - source: { - kind: 'github-actions-artifact', - owner: 'acme', - repo: 'mobile', - artifactId: 1234567890, - }, -}); -``` - -Remote daemons may also support `{ kind: 'github-actions-artifact', owner, repo, artifactName }` or `{ kind: 'github-actions-artifact', owner, repo, runId, artifactName }`. The local client passes these payloads through unchanged; it does not authenticate with GitHub or download the artifact. +- For a GitHub Actions artifact, pass its signed download URL as a `url` source. See [Install a GitHub Actions artifact](/docs/commands#install-a-github-actions-artifact). Android `.apk` and `.aab` URL sources resolve package identity from the downloaded install artifact. Archive URLs may contain one installable `.apk`, `.aab`, `.ipa`, or iOS `.app`, including inside nested archives. diff --git a/website/docs/docs/commands.md b/website/docs/docs/commands.md index e0fa89a950..545ad4f3dd 100644 --- a/website/docs/docs/commands.md +++ b/website/docs/docs/commands.md @@ -1683,16 +1683,15 @@ agent-device uninstall com.example.app --platform android -Install app builds from URLs or CI artifacts. +Install app builds from URLs. ```bash -agent-device install-from-source | install-from-source --github-actions-artifact +agent-device install-from-source ``` | Option | What it does | | --- | --- | | `--header ` | install-from-source: repeatable HTTP header for URL downloads | -| `--github-actions-artifact ` | install-from-source: GitHub Actions artifact resolved by a remote daemon | | `--retain-paths` | install-from-source: keep materialized artifact paths after install | | `--retention-ms ` | install-from-source: retain files for 1-2147483647 ms | @@ -1705,17 +1704,28 @@ Exact behavior: `agent-device help install-from-source`. ```bash agent-device install-from-source https://example.com/builds/app.apk --platform android agent-device install-from-source https://example.com/builds/app.aab --platform android -agent-device install-from-source --github-actions-artifact thymikee/RNCLI83:6635342232 --platform android ``` - `install-from-source ` installs an artifact the daemon can reach at a URL; use `install` or `reinstall` for local files. Device coverage matches `install`. - `install-from-source` allows 600 seconds overall, including up to 120 seconds for the download. The local Android and iOS install limits match `install`. - A URL may point to an Android `.apk` or `.aab`, or, from any public host, to an archive containing one `.apk`, `.aab`, `.ipa`, or iOS `.app`. -- `--github-actions-artifact ` lets a compatible remote daemon fetch a GitHub Actions artifact with its own credentials. A numeric artifact is treated as an id, anything else as a name. - Repeat `--header ` for authenticated or signed downloads. Sensitive headers are not forwarded to other origins. - `--retain-paths` keeps the downloaded and extracted files for 15 minutes. Use `--retention-ms ` to set an integer duration from 1 to 2,147,483,647 milliseconds. - Limits: at most five redirects, no HTTPS-to-HTTP downgrade, 2 GiB download, 4 GiB extracted, 100,000 entries, and three nested archive layers. Links and special archive entries are rejected. `HTTP_PROXY`, `HTTPS_PROXY`, and `NO_PROXY` are honored. These match the Node.js client's `installFromSource()` checks. +### Install a GitHub Actions artifact + +GitHub gives each artifact a signed download URL. The URL needs no credentials, so the device or remote daemon can fetch the build directly. The URL expires after about one minute, so get it right before the install: + +```bash +url=$(curl -fsS -o /dev/null -w '%{redirect_url}' \ + -H "Authorization: Bearer $(gh auth token)" \ + https://api.github.com/repos///actions/artifacts//zip) +agent-device install-from-source "$url" --platform android +``` + +In a GitHub Actions job, use `${{ secrets.GITHUB_TOKEN }}` instead of `gh auth token`. The token stays on the machine that runs the command. + ## Push notification simulation diff --git a/website/docs/docs/configuration.md b/website/docs/docs/configuration.md index 191ec224f0..dee2a0035d 100644 --- a/website/docs/docs/configuration.md +++ b/website/docs/docs/configuration.md @@ -90,28 +90,13 @@ explicit config: - `leaseBackend` - provider/cloud fields (`provider*`, `aws*`) - Metro endpoint/token fields (`metro*`, `bundleUrl`) -- request headers and structured install sources +- request headers - local code and write destinations (`reporter`, `reportJunit`, `saveScript`, `launchConsole`) - `postGestureStabilization: false`, which skips the directional scroll `movement` check and the wait that keeps the first read after a scroll or swipe from a tree still in motion, and the first-screen wait after `open` on a local iOS simulator; see [Scroll](/docs/commands#scroll) Project config can also set `snapshotDepth`, `snapshotScope`, `screenshotScale`, `activity`, `relaunch`, `shutdown`, `fps`, and `quality`. Local paths and executable modules, such as `stepsFile` and `reporter`, are allowed only in user or explicit config. The `record` config key and `AGENT_DEVICE_RECORD` were removed. `--record` is per-invocation only: pass it on the command, or set `record: true` in an SDK/MCP call, to keep a corrective read in a healed script. -`install-from-source` can read a GitHub Actions artifact source from user or explicit config when the remote daemon supports resolving CI artifacts. Repository config rejects this key: - -```json -{ - "platform": "android", - "installSource": { - "type": "github-actions-artifact", - "repo": "thymikee/RNCLI83", - "artifact": "rn-android-emulator-debug-pr-19" - } -} -``` - -Use a numeric `artifact` value for an artifact ID. Use a string `artifact` value for an artifact name. - Project config can set a default lock mode for named sessions with `sessionLock` (`AGENT_DEVICE_SESSION_LOCK`). See [Lock a named session to a device](/docs/sessions#lock-a-named-session-to-a-device). From 7f93f66fc65ef235b47f33c8d0cccb29d19a1e31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Sat, 21 Nov 2026 11:33:00 +0100 Subject: [PATCH 2/3] fix(install): acknowledge the install-source wire change and name the removed config key The wire ledger records the narrower DaemonInstallSource as a compatible change: a released client that still sends the removed kind gets a normal INVALID_ARGS error. The fuzz waiver for the removed config-only option goes, and flag definitions now require at least one CLI name, so the guards for nameless options go too. A config file with installSource now says that the key was removed and what replaces it. --- packages/command-registry/src/flag-types.ts | 2 +- .../command-surface/src/schema/cli-config.ts | 6 +++++ packages/contracts/src/screenshot.ts | 2 +- scripts/fuzz/validation-arbitraries-cli.ts | 9 +++---- src/__tests__/cli-config.test.ts | 24 +++++++++++++++++++ src/cli/parser/command-suggestions.ts | 3 +-- test/wire-compat/ledger.json | 9 +++++-- 7 files changed, 43 insertions(+), 12 deletions(-) diff --git a/packages/command-registry/src/flag-types.ts b/packages/command-registry/src/flag-types.ts index 993d180ca5..555bda55b6 100644 --- a/packages/command-registry/src/flag-types.ts +++ b/packages/command-registry/src/flag-types.ts @@ -14,7 +14,7 @@ export type NonRecordableFlagKey = Exclude; export type RecordableFlagKey = Extract; type FlagDefinitionBody = { - names: readonly string[]; + names: readonly [string, ...string[]]; type: FlagType; multiple?: boolean; enumValues?: readonly string[]; diff --git a/packages/command-surface/src/schema/cli-config.ts b/packages/command-surface/src/schema/cli-config.ts index c8d3abaa3b..94c814548d 100644 --- a/packages/command-surface/src/schema/cli-config.ts +++ b/packages/command-surface/src/schema/cli-config.ts @@ -154,6 +154,12 @@ function parseConfigObject( `Config key "${rawKey}" in ${origin.label} was removed; use "screenshotScale" (0.01-1) to downscale screenshots. Recordings capture at native resolution.`, ); } + if (rawKey === 'installSource') { + throw new AppError( + 'INVALID_ARGS', + `Config key "${rawKey}" in ${origin.label} was removed; pass a download URL to install-from-source . For a GitHub Actions artifact, see agent-device help remote.`, + ); + } throw new AppError('INVALID_ARGS', `Unknown config key "${rawKey}" in ${origin.label}.`); } if (!spec.configurable) { diff --git a/packages/contracts/src/screenshot.ts b/packages/contracts/src/screenshot.ts index 7b06ba3c6b..e7dfe85710 100644 --- a/packages/contracts/src/screenshot.ts +++ b/packages/contracts/src/screenshot.ts @@ -121,7 +121,7 @@ type ScreenshotSpecificFlagKey = (typeof SCREENSHOT_ACTION_FLAG_KEYS)[number]; type ScreenshotSpecificFlagDefinition = { key: ScreenshotSpecificFlagKey; - names: readonly string[]; + names: readonly [string, ...string[]]; type: 'boolean' | 'int' | 'number' | 'string' | 'enum'; enumValues?: readonly string[]; min?: number; diff --git a/scripts/fuzz/validation-arbitraries-cli.ts b/scripts/fuzz/validation-arbitraries-cli.ts index 05d4a6a57c..3da53204f2 100644 --- a/scripts/fuzz/validation-arbitraries-cli.ts +++ b/scripts/fuzz/validation-arbitraries-cli.ts @@ -42,7 +42,6 @@ export const UNGENERATED_FLAG_KEYS: Readonly> = { snapshotDiff: 'rewrites the command to `diff`, so the case no longer asserts what it planted', steps: 'belongs to the pinned batch step-source seeds', stepsFile: 'belongs to the pinned batch step-source seeds', - installSource: 'carries no CLI token at all (`names: []`) — reachable only through config', batchOnError: 'supported only on `batch`, which is waived above, so no case can carry it', batchMaxSteps: 'supported only on `batch`, which is waived above, so no case can carry it', }; @@ -69,16 +68,14 @@ export function validationSurfaceBuildCount(): number { return surfaceBuilds; } -/** Every definition that can be written as a token at all, minus the waived keys. */ +/** Every definition, minus the waived keys. */ const safeFlagPool = memoize(() => - getFlagDefinitions().filter( - (definition) => !(definition.key in UNGENERATED_FLAG_KEYS) && definition.names.length > 0, - ), + getFlagDefinitions().filter((definition) => !(definition.key in UNGENERATED_FLAG_KEYS)), ); /** Long token when there is one; short-only definitions (`-i`) are part of the surface too. */ function flagToken(definition: FlagDefinition): string { - return definition.names.find((name) => name.startsWith('--')) ?? definition.names[0]!; + return definition.names.find((name) => name.startsWith('--')) ?? definition.names[0]; } /** diff --git a/src/__tests__/cli-config.test.ts b/src/__tests__/cli-config.test.ts index cd3a009c15..28d81e1fb6 100644 --- a/src/__tests__/cli-config.test.ts +++ b/src/__tests__/cli-config.test.ts @@ -1240,3 +1240,27 @@ test('invalid config key returns parse error before daemon dispatch', async () = fs.rmSync(root, { recursive: true, force: true }); }); + +test('config names the removal of installSource and the URL replacement', async () => { + const { root, home, project } = makeTempWorkspace(); + fs.mkdirSync(path.join(home, '.agent-device'), { recursive: true }); + fs.writeFileSync( + path.join(home, '.agent-device', 'config.json'), + JSON.stringify({ + installSource: { type: 'github-actions-artifact', repo: 'acme/mobile', artifact: 1 }, + }), + 'utf8', + ); + + const result = await runCliCapture(['install-from-source', 'https://example.com/app.apk'], { + cwd: project, + env: { HOME: home }, + sendToDaemon: async () => ({ ok: true, data: {} }), + }); + + assert.equal(result.code, 1); + assert.equal(result.calls.length, 0); + assert.match(result.stderr, /Config key "installSource" .* was removed; pass a download URL/); + + fs.rmSync(root, { recursive: true, force: true }); +}); diff --git a/src/cli/parser/command-suggestions.ts b/src/cli/parser/command-suggestions.ts index 388f32072a..5e1f0bb7ae 100644 --- a/src/cli/parser/command-suggestions.ts +++ b/src/cli/parser/command-suggestions.ts @@ -231,8 +231,7 @@ function listSupportedFlagNames(command: string | null): string[] { const names = new Set(); for (const definition of getFlagDefinitions()) { if (!isFlagSupportedForCommand(definition.key, command)) continue; - const primary = definition.names[0]; - if (primary) names.add(primary); + names.add(definition.names[0]); } return [...names]; } diff --git a/test/wire-compat/ledger.json b/test/wire-compat/ledger.json index 622c899f54..60bf8c6c8f 100644 --- a/test/wire-compat/ledger.json +++ b/test/wire-compat/ledger.json @@ -20,7 +20,7 @@ "packages/kernel/src/contracts.ts#DaemonArtifactKnownType": "sha256:4a55e654d15d4719a579df4aa1929dda1d52a4acf4c71e9ff78814ad09d6d233", "packages/kernel/src/contracts.ts#ScriptDeliveryFailure": "sha256:186881f8b2e6a0227a6d1a2c802d8f7356fee39d4137800a0c9fa65401aa2765", "packages/kernel/src/contracts.ts#DaemonArtifactType": "sha256:5e5017276fefe880b8ab32001888011d2e02a8670f0978afdb9b56a77ab37f09", - "packages/kernel/src/contracts.ts#DaemonInstallSource": "sha256:fe26e202e62d997cdd3855fd96002511783a6c26a9ce27210d7c6cc084c66e4e", + "packages/kernel/src/contracts.ts#DaemonInstallSource": "sha256:adfde90c81de72009bf0e092b95fcb41cece2ecd44e936dcb1f6beb220287f02", "packages/kernel/src/contracts.ts#DaemonLockPolicy": "sha256:f33d0ce7200a7d97c11e91bd2889b5d9bc7f35935a5370a29930118d091468f4", "packages/kernel/src/contracts.ts#DaemonRequest": "sha256:911d93245b8dc557db897c4cac051030db673711bf3af51baa8b82248d509c57", "packages/kernel/src/contracts.ts#DaemonRequestMeta": "sha256:c2b14225388041f3a6e708c898c512f91b9b20e51a2656a1fa0d5bfa5989fa30", @@ -305,7 +305,7 @@ { "declaration": "packages/daemon/src/server/http/http-authorization.ts#authorizeAuxiliaryHttpRequest", "digest": "sha256:be2f3a9965bb6fe456ab8b1f0a696cf80ffcc8016262a4aee28dee25d18650d0", - "rationale": "#2198 context: adds one optional field to the value this DAEMON-INTERNAL gate hands its own route handlers — sessionNamespace, the caller's tenant plus whether the daemon partitioned that caller's session names. Nothing about it is serialized: no request header is read that was not read before, no response field is added, and a refusal keeps the same 401 {ok:false,error,code} REST body sendRestJsonError already sent. What it enables is a refusal DROPPED, never one added — an unattested (client-declared) tenant no longer has the : prefix rule applied to it, because scopeRequestSession never applied that prefix to its sessions either. A released peer that now gets 200 where it got 401 is getting the ndjson record it asked for and already parses. The route also passes its ingress signal to the authorizer, so a held auth hook stops at the same deadline or disconnect; the request, response and status framing are unchanged. An auth-hook or tenant-trust refusal answered after the hook now goes through the request owner's commit gate, so a deadline that passed first answers with its own typed expiry; refusal status and body shapes are unchanged." + "rationale": "#2198 context: adds one optional field to the value this DAEMON-INTERNAL gate hands its own route handlers \u2014 sessionNamespace, the caller's tenant plus whether the daemon partitioned that caller's session names. Nothing about it is serialized: no request header is read that was not read before, no response field is added, and a refusal keeps the same 401 {ok:false,error,code} REST body sendRestJsonError already sent. What it enables is a refusal DROPPED, never one added \u2014 an unattested (client-declared) tenant no longer has the : prefix rule applied to it, because scopeRequestSession never applied that prefix to its sessions either. A released peer that now gets 200 where it got 401 is getting the ndjson record it asked for and already parses. The route also passes its ingress signal to the authorizer, so a held auth hook stops at the same deadline or disconnect; the request, response and status framing are unchanged. An auth-hook or tenant-trust refusal answered after the hook now goes through the request owner's commit gate, so a deadline that passed first answers with its own typed expiry; refusal status and body shapes are unchanged." }, { "declaration": "packages/daemon/src/server/request-diagnostics-http.ts#RequestDiagnosticsHttpAuthorizer", @@ -646,6 +646,11 @@ "declaration": "packages/remote/src/daemon-artifacts.ts#downloadResponseArtifacts", "digest": "sha256:aa3ea996bdd1329d88570ba87c03026946dd33f34172c0eccd5a6ac3d38e9884", "rationale": "#4518 client-side only. Remote record stop downloads to a current request destination or reports a local cwd fallback after publishing. Released daemons supply the same artifact fields, and chunk downloads use the existing artifact order. The request, headers, and response framing are unchanged." + }, + { + "declaration": "packages/kernel/src/contracts.ts#DaemonInstallSource", + "digest": "sha256:adfde90c81de72009bf0e092b95fcb41cece2ecd44e936dcb1f6beb220287f02", + "rationale": "Removes the github-actions-artifact variant. A new client never sends it. A released client that sends it to a new daemon gets a normal INVALID_ARGS error (source.kind must be \"url\"), not a misread payload. No local daemon ever materialized it: it always failed with UNSUPPORTED_OPERATION. The url and path variants are unchanged." } ] } From d4709b3004fde1bc563ee659354559d8b16e2ee2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Sat, 21 Nov 2026 11:36:42 +0100 Subject: [PATCH 3/3] refactor(install): split install-source header parsing and list retired config keys in one table Keeps parseInstallSource and parseConfigObject under the complexity threshold. --- .../command-surface/src/schema/cli-config.ts | 28 ++++++++-------- .../src/server/http/http-rpc-methods.ts | 32 +++++++++---------- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/packages/command-surface/src/schema/cli-config.ts b/packages/command-surface/src/schema/cli-config.ts index 94c814548d..00ad6c01d1 100644 --- a/packages/command-surface/src/schema/cli-config.ts +++ b/packages/command-surface/src/schema/cli-config.ts @@ -130,6 +130,15 @@ const RETIRED_RECORD_CONFIG_KEY = { '--record is per-invocation only: pass --record on the command, or record: true in the SDK/MCP call, to keep a corrective read in a healed script', } as const; +// Removed config keys, each with the guidance that replaces it. +const RETIRED_CONFIG_KEY_MIGRATIONS: Readonly> = { + [RETIRED_RECORD_CONFIG_KEY.flagKey]: `${RETIRED_RECORD_CONFIG_KEY.migration}.`, + [RETIRED_SCREENSHOT_MAX_SIZE.flagKey]: + 'use "screenshotScale" (0.01-1) to downscale screenshots. Recordings capture at native resolution.', + installSource: + 'pass a download URL to install-from-source . For a GitHub Actions artifact, see agent-device help remote.', +}; + function parseConfigObject( source: Record, origin: { source: ConfigFileSource; label: string }, @@ -139,27 +148,18 @@ function parseConfigObject( ([key]) => key !== 'plugins' || origin.source !== 'user', ); for (const [rawKey, rawValue] of entries) { - if (rawKey === RETIRED_RECORD_CONFIG_KEY.flagKey) { + const migration = Object.hasOwn(RETIRED_CONFIG_KEY_MIGRATIONS, rawKey) + ? RETIRED_CONFIG_KEY_MIGRATIONS[rawKey] + : undefined; + if (migration) { throw new AppError( 'INVALID_ARGS', - `Config key "${rawKey}" in ${origin.label} was removed; ${RETIRED_RECORD_CONFIG_KEY.migration}.`, + `Config key "${rawKey}" in ${origin.label} was removed; ${migration}`, ); } const key = rawKey as FlagKey; const spec = getOptionSpec(key); if (!spec) { - if (rawKey === RETIRED_SCREENSHOT_MAX_SIZE.flagKey) { - throw new AppError( - 'INVALID_ARGS', - `Config key "${rawKey}" in ${origin.label} was removed; use "screenshotScale" (0.01-1) to downscale screenshots. Recordings capture at native resolution.`, - ); - } - if (rawKey === 'installSource') { - throw new AppError( - 'INVALID_ARGS', - `Config key "${rawKey}" in ${origin.label} was removed; pass a download URL to install-from-source . For a GitHub Actions artifact, see agent-device help remote.`, - ); - } throw new AppError('INVALID_ARGS', `Unknown config key "${rawKey}" in ${origin.label}.`); } if (!spec.configurable) { diff --git a/packages/daemon/src/server/http/http-rpc-methods.ts b/packages/daemon/src/server/http/http-rpc-methods.ts index 4240ef4ff1..84646aa9c5 100644 --- a/packages/daemon/src/server/http/http-rpc-methods.ts +++ b/packages/daemon/src/server/http/http-rpc-methods.ts @@ -110,6 +110,21 @@ function toLeaseDaemonRequest( }; } +function parseUrlSourceHeaders(rawHeaders: unknown): Record { + const headers: Record = {}; + if (rawHeaders === undefined) return headers; + if (!rawHeaders || typeof rawHeaders !== 'object' || Array.isArray(rawHeaders)) { + throw new AppError('INVALID_ARGS', 'Invalid params: source.headers must be a string map'); + } + for (const [key, value] of Object.entries(rawHeaders as Record)) { + if (typeof value !== 'string') { + throw new AppError('INVALID_ARGS', 'Invalid params: source.headers values must be strings'); + } + headers[key] = value; + } + return headers; +} + function parseInstallSource(params: Record): HttpInstallSource { const source = params.source; if (!source || typeof source !== 'object') { @@ -121,22 +136,7 @@ function parseInstallSource(params: Record): HttpInstallSource if (!url) { throw new AppError('INVALID_ARGS', 'Invalid params: source.url is required for url sources'); } - const rawHeaders = record.headers; - const headers: Record = {}; - if (rawHeaders !== undefined) { - if (!rawHeaders || typeof rawHeaders !== 'object' || Array.isArray(rawHeaders)) { - throw new AppError('INVALID_ARGS', 'Invalid params: source.headers must be a string map'); - } - for (const [key, value] of Object.entries(rawHeaders as Record)) { - if (typeof value !== 'string') { - throw new AppError( - 'INVALID_ARGS', - 'Invalid params: source.headers values must be strings', - ); - } - headers[key] = value; - } - } + const headers = parseUrlSourceHeaders(record.headers); return Object.keys(headers).length > 0 ? { kind: 'url', url, headers } : { kind: 'url', url }; } if (record.kind === 'path') {