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
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,70 @@ test('canonical selector projection preserves recursive tree relations', () => {
containsDescendants: [{ text: 'Save', childOf: { id: 'body' } }],
});
});

test('canonicalizes repeat conditions from agent and upstream command shapes', () => {
const program = parseMaestroProgram(
[
'---',
'- repeat:',
' while:',
' platform: Android',
' notVisible: Ready',
' commands: []',
'- repeat:',
' times: 4',
' while:',
' true: "${output.counter < 3}"',
' commands: []',
'- repeat:',
' times: 2',
' while:',
' true: true',
' commands: []',
].join('\n'),
);

expect(canonicalizeAgentCommands(program)).toEqual([
{ kind: 'repeat', while: { platform: 'android', notVisible: { text: 'Ready' } } },
{ kind: 'repeat', times: 4, while: { true: '${output.counter < 3}' } },
{ kind: 'repeat', times: 2, while: { true: 'true' } },
]);
expect(
canonicalizeUpstreamFlow([
{
type: 'RepeatCommand',
fields: {
times: null,
condition: {
platform: 'Android',
visible: null,
notVisible: { textRegex: 'Ready' },
scriptCondition: null,
},
},
},
{
type: 'RepeatCommand',
fields: {
times: '4',
condition: {
visible: null,
notVisible: null,
scriptCondition: '${output.counter < 3}',
},
},
},
{
type: 'RepeatCommand',
fields: {
times: '2',
condition: { visible: null, notVisible: null, scriptCondition: 'true' },
},
},
]),
).toEqual([
{ kind: 'repeat', while: { platform: 'android', notVisible: { text: 'Ready' } } },
{ kind: 'repeat', times: 4, while: { true: '${output.counter < 3}' } },
{ kind: 'repeat', times: 2, while: { true: 'true' } },
]);
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, test } from 'vitest';
import { isMaestroConditionTruthy } from '../engine-truthiness.ts';
import { isMaestroConditionTruthy, isMaestroScriptResultTruthy } from '../engine-truthiness.ts';

// assertTrue phase 1 (#1295): pin the string-value truthiness table explicitly
// rather than relying on native JS coercion (which would treat every non-empty
Expand Down Expand Up @@ -47,3 +47,22 @@ describe('isMaestroConditionTruthy', () => {
expect(isMaestroConditionTruthy(123)).toBe(true);
});
});

describe('isMaestroScriptResultTruthy', () => {
test.each([
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
['', false],
['false', false],
['0', false],
[false, false],
[0, false],
[0n, false],
[null, false],
[undefined, false],
['true', true],
[1, true],
[1n, true],
[{}, true],
])('%o is %s', (value, expected) => {
expect(isMaestroScriptResultTruthy(value)).toBe(expected);
});
});
21 changes: 1 addition & 20 deletions packages/maestro/src/internal/__tests__/engine.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ import type {
MaestroObservation,
MaestroRuntimePort,
MaestroRuntimeRequest,
MaestroRuntimeResult,
} from '../engine-types.ts';
import { executeMaestroProgram } from './runtime-port-fixtures.ts';
import { executeMaestroProgram, makePort } from './runtime-port-fixtures.ts';

describe('executeMaestroProgram', () => {
test('preserves authored percentage swipe intent without observing', async () => {
Expand Down Expand Up @@ -857,21 +856,3 @@ describe('executeMaestroProgram', () => {
expect(execute.mock.calls[0]?.[0].signal).toBe(controller.signal);
});
});

function makePort(overrides: Partial<MaestroRuntimePort> = {}): MaestroRuntimePort {
return {
execute: vi.fn(async (request): Promise<MaestroRuntimeResult> => {
const { command } = request;
if (
command.kind !== 'takeScreenshot' &&
command.kind !== 'runScript' &&
command.kind !== 'waitForAnimationToEnd'
) {
request.invalidateObservation();
}
return command.kind === 'takeScreenshot' ? { artifactPaths: [command.path] } : {};
}),
observe: vi.fn(async ({ generation }) => ({ generation, matched: true })),
...overrides,
};
}
58 changes: 58 additions & 0 deletions packages/maestro/src/internal/__tests__/program-ir-parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,64 @@ describe('parseMaestroProgram', () => {
assert.equal(retry.commands[0]?.source.line, 27);
});

test('parses repeat while conditions with an optional times limit', () => {
const program = parseMaestroProgram(
[
'---',
'- repeat:',
' while:',
' platform: Android',
' notVisible: ValueX',
' commands:',
' - tapOn: Button',
'- repeat:',
' times: 4',
' while:',
' true: "${output.counter < 3}"',
' commands:',
' - evalScript: ${output.counter++}',
].join('\n'),
);

assert.deepEqual(program.commands[0], {
kind: 'repeat',
source: { line: 2 },
while: { platform: 'android', notVisible: { text: 'ValueX' } },
commands: [
{
kind: 'tapOn',
source: { line: 7 },
target: { space: 'target', selector: { text: 'Button' } },
},
],
});
assert.deepEqual(program.commands[1], {
kind: 'repeat',
source: { line: 8 },
times: 4,
while: { true: '${output.counter < 3}' },
commands: [{ kind: 'evalScript', source: { line: 13 }, script: '${output.counter++}' }],
});
});

test('requires repeat times or a non-empty while condition', () => {
assert.throws(
() => parseMaestroProgram('---\n- repeat:\n commands: []\n'),
/repeat requires times or while.*line 2/i,
);
assert.throws(
() => parseMaestroProgram('---\n- repeat:\n while: {}\n commands: []\n'),
/repeat\.while cannot be empty.*line 3/i,
);
assert.throws(
() =>
parseMaestroProgram(
'---\n- repeat:\n while:\n unsupported: Android\n commands: []\n',
),
/repeat\.while field "unsupported" is not supported.*line 4/i,
);
});

test('parses flow tags as typed metadata and validates each tag', () => {
const program = parseMaestroProgram(
['name: Pager', 'tags: [smoke, pager]', '---', '- launchApp'].join('\n'),
Expand Down
Loading
Loading