Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/core/bazel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
requireLabel,
sanitizeQueryExpression,
simulatorArgs,
testFilterArgs,
runBazel,
runBazelStreaming,
getLastCommand,
Expand Down Expand Up @@ -168,6 +169,29 @@ describe('Bazel argument helpers', () => {
expect(() => configArgs(['bad;config'])).toThrow('Invalid config value');
});

it('testFilterArgs returns single --test_filter for simple string', () => {
expect(testFilterArgs('MyTestSuite')).toEqual(['--test_filter=MyTestSuite']);
});

it('testFilterArgs joins pipe-separated values with commas for rules_apple', () => {
expect(testFilterArgs('SuiteA|SuiteB')).toEqual([
'--test_filter=SuiteA,SuiteB',
]);
});

it('testFilterArgs handles whitespace around pipes', () => {
expect(testFilterArgs(' A | B | C ')).toEqual([
'--test_filter=A,B,C',
]);
});

it('testFilterArgs returns empty array for falsy values', () => {
expect(testFilterArgs(undefined)).toEqual([]);
expect(testFilterArgs('')).toEqual([]);
expect(testFilterArgs(' ')).toEqual([]);
expect(testFilterArgs(null)).toEqual([]);
});

it('builds a simulator build command with stable flag ordering', () => {
expect(
buildCommandArgs({
Expand Down
10 changes: 10 additions & 0 deletions src/core/bazel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,16 @@ export function platformArgs(platform?: BuildPlatform): string[] {
}
}

export function testFilterArgs(testFilter: unknown): string[] {
if (typeof testFilter !== 'string' || !testFilter.trim()) return [];
const trimmed = testFilter.trim();
if (trimmed.includes('|')) {
const joined = trimmed.split('|').map(p => p.trim()).filter(Boolean).join(',');
return [`--test_filter=${joined}`];
}
return [`--test_filter=${trimmed}`];
}

export function configArgs(value: unknown): string[] {
return asStringArray(value, 'configs').map((config) => {
if (!/^[A-Za-z0-9_.-]+$/.test(config)) {
Expand Down
13 changes: 5 additions & 8 deletions src/tools/handlers/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
runBazel,
sanitizeQueryExpression,
simulatorArgs,
testFilterArgs,
} from '../../core/bazel.js';
import {
bootSimulatorIfNeeded,
Expand Down Expand Up @@ -136,7 +137,7 @@ export const definitions: ToolDefinition[] = [
type: 'object',
properties: {
target: { type: 'string', description: 'Bazel test target label.' },
testFilter: { type: 'string', description: 'Optional --test_filter value.' },
testFilter: { type: 'string', description: 'Optional test filter. Supports pipe-separated values (e.g. "SuiteA|SuiteB") to run multiple suites.' },
simulatorName: { type: 'string' },
simulatorVersion: { type: 'string' },
configs: { type: 'array', items: { type: 'string' } },
Expand Down Expand Up @@ -251,7 +252,7 @@ export const definitions: ToolDefinition[] = [
type: 'object',
properties: {
target: { type: 'string', description: 'Bazel test target label.' },
testFilter: { type: 'string', description: 'Optional --test_filter value.' },
testFilter: { type: 'string', description: 'Optional test filter. Supports pipe-separated values (e.g. "SuiteA|SuiteB") to run multiple suites.' },
simulatorName: { type: 'string' },
simulatorVersion: { type: 'string' },
configs: { type: 'array', items: { type: 'string' } },
Expand Down Expand Up @@ -365,10 +366,8 @@ export async function handle(name: string, args: JsonObject): Promise<ToolCallRe
...simulatorArgs(testArgs),
...configArgs(testArgs.configs),
...asStringArray(testArgs.extraArgs, 'extraArgs'),
...testFilterArgs(testArgs.testFilter),
];
if (typeof testArgs.testFilter === 'string' && testArgs.testFilter.trim()) {
bazelArgs.push(`--test_filter=${testArgs.testFilter.trim()}`);
}
bazelArgs.push(target);
const commandResult = await runBazel(
bazelArgs,
Expand Down Expand Up @@ -460,10 +459,8 @@ export async function handle(name: string, args: JsonObject): Promise<ToolCallRe
...simulatorArgs(testArgs),
...configArgs(testArgs.configs),
...asStringArray(testArgs.extraArgs, 'extraArgs'),
...testFilterArgs(testArgs.testFilter),
];
if (typeof testArgs.testFilter === 'string' && testArgs.testFilter.trim()) {
bazelArgs.push(`--test_filter=${testArgs.testFilter.trim()}`);
}
bazelArgs.push(target);
const commandResult = await runBazel(
bazelArgs,
Expand Down
5 changes: 3 additions & 2 deletions src/tools/handlers/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
configArgs,
requireLabel,
runBazel,
testFilterArgs,
} from '../../core/bazel.js';
import {
deviceInfo,
Expand Down Expand Up @@ -125,7 +126,7 @@ export const definitions: ToolDefinition[] = [
type: 'object',
properties: {
target: { type: 'string', description: 'Bazel test target label.' },
testFilter: { type: 'string', description: 'Optional --test_filter value.' },
testFilter: { type: 'string', description: 'Optional test filter. Supports pipe-separated values (e.g. "SuiteA|SuiteB") to run multiple suites.' },
deviceId: { type: 'string', description: 'Device UDID.' },
deviceName: { type: 'string', description: 'Device name.' },
configs: { type: 'array', items: { type: 'string' } },
Expand Down Expand Up @@ -374,7 +375,7 @@ export async function handle(name: string, args: JsonObject): Promise<ToolCallRe
...configArgs(args.configs),
...asStringArray(args.extraArgs, 'extraArgs'),
];
if (args.testFilter) testArgs.push(`--test_filter=${args.testFilter}`);
testArgs.push(...testFilterArgs(args.testFilter));
testArgs.push(`--test_arg=--destination`, `--test_arg=id=${device.udid}`);
testArgs.push(target);
const result = await runBazel(
Expand Down
12 changes: 5 additions & 7 deletions src/tools/handlers/macos.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { JsonObject, ToolCallResult, ToolDefinition, BuildArgs, TestArgs, TargetKind, BuildMode } from '../../types/index.js';
import { stringOrUndefined, numberOrUndefined } from '../helpers.js';
import { buildCommandArgs, configArgs, discoverExpression, modeArgs, requireLabel, runBazel, asStringArray } from '../../core/bazel.js';
import { buildCommandArgs, configArgs, discoverExpression, modeArgs, requireLabel, runBazel, asStringArray, testFilterArgs } from '../../core/bazel.js';
import { findAppBundle, readBundleId } from '../../core/simulators.js';
import { formatCommandResult, structuredCommandResult, toolResult, toolText } from '../../utils/output.js';
import { runCommand } from '../../utils/process.js';
Expand Down Expand Up @@ -49,7 +49,7 @@ export const definitions: ToolDefinition[] = [
type: 'object',
properties: {
target: { type: 'string', description: 'Bazel test target label.' },
testFilter: { type: 'string', description: 'Optional --test_filter value.' },
testFilter: { type: 'string', description: 'Optional test filter. Supports pipe-separated values (e.g. "SuiteA|SuiteB") to run multiple suites.' },
configs: { type: 'array', items: { type: 'string' } },
startupArgs: { type: 'array', items: { type: 'string' } },
extraArgs: { type: 'array', items: { type: 'string' } },
Expand Down Expand Up @@ -79,7 +79,7 @@ export const definitions: ToolDefinition[] = [
type: 'object',
properties: {
target: { type: 'string', description: 'Bazel test target label.' },
testFilter: { type: 'string', description: 'Optional --test_filter value.' },
testFilter: { type: 'string', description: 'Optional test filter. Supports pipe-separated values (e.g. "SuiteA|SuiteB") to run multiple suites.' },
configs: { type: 'array', items: { type: 'string' } },
startupArgs: { type: 'array', items: { type: 'string' } },
extraArgs: { type: 'array', items: { type: 'string' } },
Expand Down Expand Up @@ -236,10 +236,8 @@ export async function handle(name: string, args: JsonObject): Promise<ToolCallRe
'--test_output=errors',
...configArgs(testArgs.configs),
...asStringArray(testArgs.extraArgs, 'extraArgs'),
...testFilterArgs(testArgs.testFilter),
];
if (typeof testArgs.testFilter === 'string' && testArgs.testFilter.trim()) {
bazelArgs.push(`--test_filter=${testArgs.testFilter.trim()}`);
}
bazelArgs.push(target);
const commandResult = await runBazel(
bazelArgs,
Expand Down Expand Up @@ -269,7 +267,7 @@ export async function handle(name: string, args: JsonObject): Promise<ToolCallRe
...configArgs(asStringArray(args.configs, 'configs')),
...asStringArray(args.extraArgs, 'extraArgs'),
];
if (args.testFilter) coverageArgs.push(`--test_filter=${args.testFilter}`);
coverageArgs.push(...testFilterArgs(args.testFilter));
coverageArgs.push(target);
const result = await runBazel(
coverageArgs,
Expand Down
12 changes: 5 additions & 7 deletions src/tools/handlers/multi-platform.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { JsonObject, ToolCallResult, ToolDefinition, BuildArgs, TestArgs, BuildPlatform, BuildMode, TargetKind } from '../../types/index.js';
import { stringOrUndefined, numberOrUndefined } from '../helpers.js';
import { buildCommandArgs, configArgs, discoverExpression, modeArgs, platformArgs, requireLabel, runBazel, asStringArray } from '../../core/bazel.js';
import { buildCommandArgs, configArgs, discoverExpression, modeArgs, platformArgs, requireLabel, runBazel, asStringArray, testFilterArgs } from '../../core/bazel.js';
import { formatCommandResult, structuredCommandResult, toolResult, toolText } from '../../utils/output.js';

export const definitions: ToolDefinition[] = [
Expand Down Expand Up @@ -28,7 +28,7 @@ export const definitions: ToolDefinition[] = [
type: 'object',
properties: {
target: { type: 'string', description: 'Bazel test target label.' },
testFilter: { type: 'string', description: 'Optional --test_filter value.' },
testFilter: { type: 'string', description: 'Optional test filter. Supports pipe-separated values (e.g. "SuiteA|SuiteB") to run multiple suites.' },
configs: { type: 'array', items: { type: 'string' } },
startupArgs: { type: 'array', items: { type: 'string' } },
extraArgs: { type: 'array', items: { type: 'string' } },
Expand Down Expand Up @@ -93,7 +93,7 @@ export const definitions: ToolDefinition[] = [
type: 'object',
properties: {
target: { type: 'string', description: 'Bazel test target label.' },
testFilter: { type: 'string', description: 'Optional --test_filter value.' },
testFilter: { type: 'string', description: 'Optional test filter. Supports pipe-separated values (e.g. "SuiteA|SuiteB") to run multiple suites.' },
configs: { type: 'array', items: { type: 'string' } },
startupArgs: { type: 'array', items: { type: 'string' } },
extraArgs: { type: 'array', items: { type: 'string' } },
Expand Down Expand Up @@ -158,7 +158,7 @@ export const definitions: ToolDefinition[] = [
type: 'object',
properties: {
target: { type: 'string', description: 'Bazel test target label.' },
testFilter: { type: 'string', description: 'Optional --test_filter value.' },
testFilter: { type: 'string', description: 'Optional test filter. Supports pipe-separated values (e.g. "SuiteA|SuiteB") to run multiple suites.' },
configs: { type: 'array', items: { type: 'string' } },
startupArgs: { type: 'array', items: { type: 'string' } },
extraArgs: { type: 'array', items: { type: 'string' } },
Expand Down Expand Up @@ -265,10 +265,8 @@ export async function handle(name: string, args: JsonObject): Promise<ToolCallRe
...platformArgs(plat),
...configArgs(testArgs.configs),
...asStringArray(testArgs.extraArgs, 'extraArgs'),
...testFilterArgs(testArgs.testFilter),
];
if (typeof testArgs.testFilter === 'string' && testArgs.testFilter.trim()) {
bazelArgs.push(`--test_filter=${testArgs.testFilter.trim()}`);
}
bazelArgs.push(target);
const commandResult = await runBazel(
bazelArgs,
Expand Down
21 changes: 6 additions & 15 deletions src/tools/streaming.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
runBazelStreaming,
sanitizeQueryExpression,
simulatorArgs,
testFilterArgs,
} from '../core/bazel.js';
import { bootSimulatorIfNeeded, findAppBundle, installApp, launchApp, readBundleId, resolveSimulator } from '../core/simulators.js';
import { installAppOnDevice, launchAppOnDevice, resolveDevice } from '../core/devices.js';
Expand Down Expand Up @@ -166,10 +167,8 @@ function buildStreamingBazelArgs(name: string, args: JsonObject): string[] {
...simulatorArgs(testArgs),
...configArgs(testArgs.configs),
...asStringArray(testArgs.extraArgs, 'extraArgs'),
...testFilterArgs(testArgs.testFilter),
];
if (typeof testArgs.testFilter === 'string' && testArgs.testFilter.trim()) {
bazelArgs.push(`--test_filter=${testArgs.testFilter.trim()}`);
}
bazelArgs.push(target);
return bazelArgs;
}
Expand Down Expand Up @@ -200,10 +199,8 @@ function buildStreamingBazelArgs(name: string, args: JsonObject): string[] {
'--ios_multi_cpus=arm64',
...configArgs(testArgs.configs),
...asStringArray(testArgs.extraArgs, 'extraArgs'),
...testFilterArgs(testArgs.testFilter),
];
if (typeof testArgs.testFilter === 'string' && testArgs.testFilter.trim()) {
bazelArgs.push(`--test_filter=${testArgs.testFilter.trim()}`);
}
bazelArgs.push(target);
return bazelArgs;
}
Expand All @@ -214,10 +211,8 @@ function buildStreamingBazelArgs(name: string, args: JsonObject): string[] {
'coverage',
...configArgs(testArgs.configs),
...asStringArray(testArgs.extraArgs, 'extraArgs'),
...testFilterArgs(testArgs.testFilter),
];
if (typeof testArgs.testFilter === 'string' && testArgs.testFilter.trim()) {
bazelArgs.push(`--test_filter=${testArgs.testFilter.trim()}`);
}
bazelArgs.push(target);
return bazelArgs;
}
Expand Down Expand Up @@ -248,10 +243,8 @@ function buildStreamingBazelArgs(name: string, args: JsonObject): string[] {
'--test_output=errors',
...configArgs(testArgs.configs),
...asStringArray(testArgs.extraArgs, 'extraArgs'),
...testFilterArgs(testArgs.testFilter),
];
if (typeof testArgs.testFilter === 'string' && testArgs.testFilter.trim()) {
bazelArgs.push(`--test_filter=${testArgs.testFilter.trim()}`);
}
bazelArgs.push(target);
return bazelArgs;
}
Expand Down Expand Up @@ -293,10 +286,8 @@ function buildStreamingBazelArgs(name: string, args: JsonObject): string[] {
...platformArgs(plat),
...configArgs(testArgs.configs),
...asStringArray(testArgs.extraArgs, 'extraArgs'),
...testFilterArgs(testArgs.testFilter),
];
if (typeof testArgs.testFilter === 'string' && testArgs.testFilter.trim()) {
bazelArgs.push(`--test_filter=${testArgs.testFilter.trim()}`);
}
bazelArgs.push(target);
return bazelArgs;
}
Expand Down
Loading