Skip to content

Commit f7640bd

Browse files
committed
fix: enforce XOR between agent and custom source in online eval config
1 parent 7314305 commit f7640bd

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

src/cli/commands/run/command.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export const registerRun = (program: Command) => {
101101
json?: boolean;
102102
}) => {
103103
const isArnMode = !!(cliOptions.runtimeArn && cliOptions.evaluatorArn);
104-
const isCustomMode = !!cliOptions.customServiceName;
104+
const isCustomMode = !!(cliOptions.customServiceName && cliOptions.customLogGroupName);
105105
const isInputMode = !!cliOptions.inputPath;
106106
if (!isArnMode && !isCustomMode && !isInputMode) {
107107
requireProject();

src/schema/schemas/primitives/__tests__/online-eval-config.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,13 @@ describe('OnlineEvalConfigSchema', () => {
118118
expect(OnlineEvalConfigSchema.safeParse(config).success).toBe(true);
119119
});
120120

121-
it('accepts config with both agent and custom log source fields', () => {
121+
it('rejects config with both agent and custom log source fields', () => {
122122
const config = {
123123
...validConfig,
124124
customLogGroupName: '/custom/log-group',
125125
customServiceName: 'custom-service',
126126
};
127-
expect(OnlineEvalConfigSchema.safeParse(config).success).toBe(true);
127+
expect(OnlineEvalConfigSchema.safeParse(config).success).toBe(false);
128128
});
129129

130130
it('rejects config with neither agent nor custom log source fields', () => {

src/schema/schemas/primitives/online-eval-config.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,24 +50,25 @@ export const OnlineEvalConfigSchema = z
5050
})
5151
.refine(
5252
data => {
53-
const hasAgent = data.agent !== undefined;
54-
const hasCustom = data.customLogGroupName !== undefined && data.customServiceName !== undefined;
55-
return hasAgent || hasCustom;
53+
// Custom fields must be provided together
54+
const hasLogGroup = data.customLogGroupName !== undefined;
55+
const hasServiceName = data.customServiceName !== undefined;
56+
return hasLogGroup === hasServiceName;
5657
},
5758
{
58-
message:
59-
'Either "agent" must be provided (for project agents) or both "customLogGroupName" and "customServiceName" (for external agents)',
59+
message: 'Both "customLogGroupName" and "customServiceName" must be provided together',
6060
}
6161
)
6262
.refine(
6363
data => {
64-
// If one custom field is set, the other must also be set
65-
const hasLogGroup = data.customLogGroupName !== undefined;
66-
const hasServiceName = data.customServiceName !== undefined;
67-
return hasLogGroup === hasServiceName;
64+
const hasAgent = data.agent !== undefined;
65+
const hasCustom = data.customLogGroupName !== undefined && data.customServiceName !== undefined;
66+
// Exactly one source must be specified, not both
67+
return (hasAgent || hasCustom) && !(hasAgent && hasCustom);
6868
},
6969
{
70-
message: 'Both "customLogGroupName" and "customServiceName" must be provided together',
70+
message:
71+
'Specify either "agent" (for project agents) or both "customLogGroupName" and "customServiceName" (for external agents), but not both',
7172
}
7273
);
7374

0 commit comments

Comments
 (0)