Skip to content

Commit 2041269

Browse files
amankansal-ltclaude
andcommitted
refactor(plugins): split manifest connection and credential checks
Keeps readPluginManifest under the fallow complexity threshold, and types the manifest fixture's version so the typecheck passes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent c44bef8 commit 2041269

2 files changed

Lines changed: 36 additions & 29 deletions

File tree

‎src/plugins/manifest.ts‎

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -73,42 +73,45 @@ export function readPluginManifest(directory: string): PluginManifest {
7373
});
7474
}
7575
resolvePluginEntry(directory, declaration.entry);
76-
if (declaration.connection !== undefined) {
77-
const policy = declaration.connection;
78-
if (
79-
!policy ||
80-
typeof policy !== 'object' ||
81-
policy.leaseKind !== 'direct-device-provider' ||
82-
[
83-
'requiresAppAttachment',
84-
'requiresRemoteDaemon',
85-
'supportsArtifacts',
86-
'supportsDeferredAppSelection',
87-
'supportsDirectPortReverse',
88-
'usesCloudWebDriverLease',
89-
].some((key) => typeof policy[key as keyof ConnectionProviderCapabilities] !== 'boolean') ||
90-
policy.requiresRemoteDaemon
91-
) {
92-
throw new AppError(
93-
'INVALID_ARGS',
94-
'Plugin connection must declare local provider capabilities',
95-
);
96-
}
76+
assertLocalConnectionPolicy(declaration.connection);
77+
assertCredentialVariables(declaration.credentialVariables);
78+
return manifest as PluginManifest;
79+
}
80+
81+
function assertLocalConnectionPolicy(policy: ConnectionProviderCapabilities | undefined): void {
82+
if (policy === undefined) return;
83+
if (
84+
!policy ||
85+
typeof policy !== 'object' ||
86+
policy.leaseKind !== 'direct-device-provider' ||
87+
[
88+
'requiresAppAttachment',
89+
'requiresRemoteDaemon',
90+
'supportsArtifacts',
91+
'supportsDeferredAppSelection',
92+
'supportsDirectPortReverse',
93+
'usesCloudWebDriverLease',
94+
].some((key) => typeof policy[key as keyof ConnectionProviderCapabilities] !== 'boolean') ||
95+
policy.requiresRemoteDaemon
96+
) {
97+
throw new AppError(
98+
'INVALID_ARGS',
99+
'Plugin connection must declare local provider capabilities',
100+
);
97101
}
98-
const credentialVariables: unknown = declaration.credentialVariables;
102+
}
103+
104+
function assertCredentialVariables(variables: unknown): void {
99105
if (
100-
credentialVariables !== undefined &&
101-
(!Array.isArray(credentialVariables) ||
102-
!credentialVariables.every(
103-
(name) => typeof name === 'string' && /^[A-Z_][A-Z0-9_]*$/.test(name),
104-
))
106+
variables !== undefined &&
107+
(!Array.isArray(variables) ||
108+
!variables.every((name) => typeof name === 'string' && /^[A-Z_][A-Z0-9_]*$/.test(name)))
105109
) {
106110
throw new AppError(
107111
'INVALID_ARGS',
108112
'Plugin credentialVariables must list environment variable names',
109113
);
110114
}
111-
return manifest as PluginManifest;
112115
}
113116

114117
export function resolvePluginEntry(directory: string, entry: string): string {

‎src/plugins/plugin.fixtures.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ export function selectPlugin(
4646
/** Installs `manifest` as-is, with an entry file that throws if evaluated. */
4747
export function selectPluginManifest(
4848
home: string,
49-
manifest: { name: string; agentDevicePlugin: Record<string, unknown> & { entry: string } },
49+
manifest: {
50+
name: string;
51+
version: string;
52+
agentDevicePlugin: Record<string, unknown> & { entry: string };
53+
},
5054
) {
5155
const installation = crypto.randomUUID();
5256
const directory = path.join(home, 'plugins', installation, 'node_modules', manifest.name);

0 commit comments

Comments
 (0)