@ihyeon/flow-qa 0.9.11 → 0.9.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/src/cli.js CHANGED
@@ -28,7 +28,8 @@ Usage: flow-qa <command> [arguments] [options]
28
28
  Plan cases before target setup; produce a prompt if no model is configured
29
29
  plan <flow.md> --prompt-only Create a prompt for your current AI tool
30
30
  validate <cases.json> Check case structure and assertions
31
- generate <cases.json> [--out test.ts] Generate e2e test code
31
+ generate <cases.json> [--target <name>] [--out test.ts]
32
+ Generate target-aware e2e code (without --target: target-neutral)
32
33
  run <cases.json> --target <name> Run against a registered target and save a QA report
33
34
  [--case <id> ...] Run only the selected case IDs (repeat --case for more)
34
35
  agent-handoff <cases.json> --target <name> [--case <id> ...] [--out directory]
@@ -58,7 +59,8 @@ Local example: flow-qa ui --demo
58
59
  대상 설정 전에 케이스 설계; 모델 미연결 시 프롬프트 생성
59
60
  plan <flow.md> --prompt-only 현재 사용하는 AI에 전달할 프롬프트 생성
60
61
  validate <cases.json> 케이스 구조와 검증 조건 확인
61
- generate <cases.json> [--out test.ts] e2e 테스트 코드 생성
62
+ generate <cases.json> [--target <name>] [--out test.ts]
63
+ 대상별 e2e 코드 생성 (--target 생략 시 대상 중립)
62
64
  run <cases.json> --target <name> 연결한 대상에서 실행하고 QA 리포트 저장
63
65
  [--case <id> ...] 선택한 케이스만 실행 (--case를 반복해 여러 개 선택)
64
66
  agent-handoff <cases.json> --target <name> [--case <id> ...] [--out directory]
@@ -262,8 +264,15 @@ export async function main(args) {
262
264
  }
263
265
  if (command === 'generate') {
264
266
  const output = resolve(workspace, values.out ?? `generated/${suite.id}.e2e.ts`);
265
- await writeOutput(output, compileSuite(suite));
266
- console.log(localized(locale, `Test script: ${output}`, `실행 스크립트: ${output}`));
267
+ const targetName = values.target;
268
+ const target = targetName === undefined ? undefined : (await readConfig(workspace)).targets[targetName];
269
+ if (targetName !== undefined && !target)
270
+ throw new Error(localized(locale, `Target not found: ${targetName}`, `대상을 찾지 못했습니다: ${targetName}`));
271
+ if (target && (suite.platform ?? 'web') !== (target.kind === 'mobile' ? 'mobile' : 'web')) {
272
+ throw new Error(localized(locale, 'The case platform and selected target do not match.', '케이스 플랫폼과 선택한 대상이 일치하지 않습니다.'));
273
+ }
274
+ await writeOutput(output, compileSuite(suite, target));
275
+ console.log(localized(locale, `Test script (${targetName ? `target: ${targetName}` : 'target-neutral; use --target to match a run'}): ${output}`, `실행 스크립트 (${targetName ? `대상: ${targetName}` : '대상 중립; 실행과 일치시키려면 --target 사용'}): ${output}`));
267
276
  return;
268
277
  }
269
278
  if (command === 'agent-handoff') {
@@ -9,10 +9,10 @@ function locatorCode(locator) {
9
9
  const method = { text: 'getByText', label: 'getByLabel', testId: 'getByTestId' }[locator.by];
10
10
  return `screen.${method}(${literal(locator.value)})`;
11
11
  }
12
- function stepCode(step) {
12
+ function stepCode(step, launchApp) {
13
13
  switch (step.type) {
14
14
  case 'open': return `await app.open(${literal(step.path)});`;
15
- case 'launchApp': return 'await app.open();';
15
+ case 'launchApp': return launchApp;
16
16
  case 'back': return 'await app.back();';
17
17
  case 'swipe': return `await screen.swipe({ direction: ${literal(step.direction)} });`;
18
18
  case 'act': return `await agent.act(${literal(step.instruction)});`;
@@ -38,9 +38,16 @@ export function expectedChecks(testCase) {
38
38
  export function needsAgent(suite) {
39
39
  return suite.cases.some((testCase) => !testCase.questions.length && testCase.steps.some((step) => step.type === 'act' || step.type === 'assertAgent'));
40
40
  }
41
- export function compileSuite(suite) {
41
+ export function compileSuite(suite, target) {
42
42
  const parsed = suiteSchema.parse(suite);
43
43
  const mobile = parsed.platform === 'mobile';
44
+ // Android Settings may keep a system process alive after force-stop. The
45
+ // mobile SDK's app.open() requires that process to disappear, so use its
46
+ // supported foreground launch for this one built-in app.
47
+ const settings = mobile && target?.kind === 'mobile' && target.platform === 'android' && target.bundleId === 'com.android.settings';
48
+ const launchApp = settings
49
+ ? 'await device.home();\n await device.openApp("com.android.settings");\n if ((await device.foregroundApp()).bundleId !== "com.android.settings") throw new Error("Android Settings did not reach the foreground.");'
50
+ : 'await app.open();';
44
51
  const lines = [`import { test } from '${mobile ? '@e2e-dev/mobile' : '@e2e-dev/web'}';`, "import { expect } from 'e2e';", ''];
45
52
  for (const testCase of parsed.cases) {
46
53
  const title = literal(`[${testCase.id}] ${testCase.title}`);
@@ -49,6 +56,8 @@ export function compileSuite(suite) {
49
56
  continue;
50
57
  }
51
58
  const fixtures = ['app'];
59
+ if (settings)
60
+ fixtures.push('device');
52
61
  if (testCase.steps.some((step) => 'locator' in step || step.type === 'swipe'))
53
62
  fixtures.push('screen');
54
63
  if (testCase.steps.some((step) => step.type === 'assertUrl'))
@@ -58,12 +67,12 @@ export function compileSuite(suite) {
58
67
  lines.push(`test(${title}, async ({ ${fixtures.join(', ')} }) => {`);
59
68
  if (mobile) {
60
69
  if (testCase.steps[0]?.type !== 'launchApp')
61
- lines.push(' await app.open();');
70
+ lines.push(` ${launchApp}`);
62
71
  }
63
72
  else if (testCase.steps[0]?.type !== 'open')
64
73
  lines.push(" await app.open('/');");
65
74
  for (const step of testCase.steps)
66
- lines.push(` ${stepCode(step)}`);
75
+ lines.push(` ${stepCode(step, launchApp)}`);
67
76
  lines.push('});');
68
77
  }
69
78
  return `${lines.join('\n')}\n`;
@@ -21,8 +21,8 @@ function agentCase(testCase) {
21
21
  function packageModule(specifier) {
22
22
  return import.meta.resolve(specifier);
23
23
  }
24
- function compiledTest(suite) {
25
- const source = compileSuite(suite);
24
+ function compiledTest(suite, target) {
25
+ const source = compileSuite(suite, target);
26
26
  return source
27
27
  .replace("from '@e2e-dev/web'", `from ${JSON.stringify(packageModule('@e2e-dev/web'))}`)
28
28
  .replace("from '@e2e-dev/mobile'", `from ${JSON.stringify(packageModule('@e2e-dev/mobile'))}`)
@@ -238,7 +238,7 @@ export async function runSuite(options) {
238
238
  const testFile = path.join(runDir, TEST_FILE);
239
239
  const configFile = path.join(runDir, CONFIG_FILE);
240
240
  const agentAvailable = runnable.some(agentCase);
241
- await writeFile(testFile, compiledTest(executable), { mode: 0o600 });
241
+ await writeFile(testFile, compiledTest(executable, selectedTarget), { mode: 0o600 });
242
242
  await writeFile(configFile, generatedConfig(suite, config, options.targetName, agentAvailable, runId, sdkDevice), { mode: 0o600 });
243
243
  if (options.signal?.aborted) {
244
244
  report = failureReport(context(), 'interrupted', 'An interrupt signal arrived before the run started.');
@@ -5,7 +5,7 @@
5
5
  const t = i18n.t;
6
6
  const names = { scenario: 'nav.scenario', library: 'nav.library', history: 'nav.history', settings: 'nav.settings' };
7
7
  const defaultReportFilter = () => ({ search: '', status: 'all', sort: 'recorded', repeatedOnly: false });
8
- const app = { state: null, connected: false, displayTargets: [], draft: null, selectedCaseIds: new Set(), script: '', savedFile: '', savedHash: '', origin: 'none', sourceFlow: '', boundSource: null, stale: false, dirty: false, busy: false, planning: false, planRequest: 0, stopping: false, report: null, reportMarkdown: '', selectedRun: '', reportFilter: defaultReportFilter(), rerunOrigin: null, rerunTargetMismatch: false, navigationVersion: 0, comparison: null, comparisonRequest: 0, comparisonBusy: false, comparisonStatus: 'comparison.selectBoth', comparisonPins: { baseline: null, current: null }, comparisonSelectionGeneration: 0, comparisonValidation: null, history: { runs: [], nextCursor: null, pagesLoaded: 0, loaded: false, loading: false, request: 0, debounce: null, kind: null, error: null, updatesAvailable: false, pendingRecentUpdate: false }, view: 'scenario' };
8
+ const app = { state: null, connected: false, displayTargets: [], draft: null, selectedCaseIds: new Set(), script: '', neutralScript: '', scriptRevision: 0, savedFile: '', savedHash: '', origin: 'none', sourceFlow: '', boundSource: null, stale: false, dirty: false, busy: false, planning: false, planRequest: 0, stopping: false, report: null, reportMarkdown: '', selectedRun: '', reportFilter: defaultReportFilter(), rerunOrigin: null, rerunTargetMismatch: false, navigationVersion: 0, comparison: null, comparisonRequest: 0, comparisonBusy: false, comparisonStatus: 'comparison.selectBoth', comparisonPins: { baseline: null, current: null }, comparisonSelectionGeneration: 0, comparisonValidation: null, history: { runs: [], nextCursor: null, pagesLoaded: 0, loaded: false, loading: false, request: 0, debounce: null, kind: null, error: null, updatesAvailable: false, pendingRecentUpdate: false }, view: 'scenario' };
9
9
 
10
10
  function el(tag, className, value) {
11
11
  const node = document.createElement(tag);
@@ -210,12 +210,12 @@
210
210
  }
211
211
  function setDraft(suite, script, origin, sourceFlow = '', savedFile = '', savedHash = '') {
212
212
  app.rerunOrigin = null; app.rerunTargetMismatch = false; renderRerunHints();
213
- app.draft = suite; app.script = script; app.origin = origin; app.sourceFlow = sourceFlow; app.boundSource = suite.source ? { ...suite.source } : null; app.savedFile = savedFile; app.savedHash = savedHash; app.stale = false; app.dirty = false;
213
+ app.draft = suite; app.script = script; app.neutralScript = script; app.origin = origin; app.sourceFlow = sourceFlow; app.boundSource = suite.source ? { ...suite.source } : null; app.savedFile = savedFile; app.savedHash = savedHash; app.stale = false; app.dirty = false;
214
214
  $('suite-editor').value = JSON.stringify(suite, null, 2);
215
215
  $('scenario-platform').value = suite.platform || 'web';
216
216
  $('review-checkbox').checked = false;
217
217
  app.selectedCaseIds = new Set((suite.cases || []).map((item) => item.id));
218
- summarize(suite); renderCaseSelection(); readiness();
218
+ summarize(suite); renderCaseSelection(); void syncScriptForTarget();
219
219
  }
220
220
  function targetOptions() {
221
221
  const selected = $('target-select').value;
@@ -231,6 +231,26 @@
231
231
  for (const target of app.state?.targets || []) { const row = el('div', 'settings-entry'); row.append(el('strong', '', target.name), document.createTextNode(` · ${targetLabel(target)}${target.description ? ` · ${target.description}` : ''}`)); list.append(row); }
232
232
  }
233
233
  function targetDescription() { const target = selectedTarget(); $('target-description').textContent = target ? `${targetLabel(target)}${target.description ? ` · ${target.description}` : ''}` : t('scenario.targetHint'); readiness(); }
234
+ async function syncScriptForTarget() {
235
+ const revision = ++app.scriptRevision;
236
+ const suite = app.draft;
237
+ const target = selectedTarget();
238
+ const settings = suite?.platform === 'mobile' && target?.platform === 'android' && target.bundleId === 'com.android.settings';
239
+ $('review-checkbox').checked = false;
240
+ app.script = settings ? '' : app.neutralScript;
241
+ readiness();
242
+ if (!settings || !suite || app.dirty || app.stale) return;
243
+ try {
244
+ const result = await api('/api/compile', { suite, targetName: target.name });
245
+ if (revision !== app.scriptRevision || suite !== app.draft || selectedTarget()?.name !== target.name) return;
246
+ app.script = result.script;
247
+ readiness();
248
+ } catch (error) {
249
+ if (revision !== app.scriptRevision) return;
250
+ showError(error);
251
+ readiness();
252
+ }
253
+ }
234
254
  function renderRerunHints() {
235
255
  $('rerun-origin-hint').hidden = !app.rerunOrigin;
236
256
  if (app.rerunOrigin) $('rerun-origin-hint').textContent = t('app.rerunPrepared', app.rerunOrigin);
@@ -656,6 +676,7 @@
656
676
  const target = app.displayTargets.find((item) => item.name === result.targetName);
657
677
  const sameTarget = result.targetMatches === true && target?.targetFingerprint === result.targetFingerprint;
658
678
  $('target-select').value = sameTarget ? target.name : '';
679
+ await syncScriptForTarget();
659
680
  app.rerunTargetMismatch = !sameTarget;
660
681
  app.rerunOrigin = { runId: result.originRunId, count: result.caseIds.length };
661
682
  renderRerunHints(); targetDescription();
@@ -831,7 +852,7 @@
831
852
  async function saveModel(event) { event.preventDefault(); const form = event.currentTarget; await work(async () => { const values = new FormData(form); const body = { role: form.dataset.role, baseURL: String(values.get('baseURL') || '').trim(), model: String(values.get('model') || '').trim() }; const apiKeyEnv = String(values.get('apiKeyEnv') || '').trim(); if (apiKeyEnv) body.apiKeyEnv = apiKeyEnv; await api('/api/models', body); await refresh(true); noticeKey('app.modelSaved'); }); }
832
853
  async function clearModel(role) { await work(async () => { await api('/api/models', { role, clear: true }); await refresh(true); noticeKey('app.modelCleared'); }); }
833
854
  function targetFields() { const mobile = $('target-kind').value !== 'web'; for (const [id, required] of [['target-url-field', !mobile], ['target-bundle-field', mobile], ['target-device-field', mobile]]) { const field = $(id); field.hidden = !required; field.querySelector('input').required = required; } }
834
- async function saveTarget(event) { event.preventDefault(); const form = event.currentTarget; await work(async () => { const values = new FormData(form); const kind = String(values.get('kind') || 'web'); const body = { name: String(values.get('name') || '').trim(), description: String(values.get('description') || '').trim() }; if (kind === 'web') body.url = String(values.get('url') || '').trim(); else { body.kind = 'mobile'; body.platform = kind; body.bundleId = String(values.get('bundleId') || '').trim(); body.device = String(values.get('device') || '').trim(); } await api('/api/targets', body); form.reset(); targetFields(); await refresh(true); noticeKey('app.targetSaved'); }); }
855
+ async function saveTarget(event) { event.preventDefault(); const form = event.currentTarget; await work(async () => { const values = new FormData(form); const kind = String(values.get('kind') || 'web'); const body = { name: String(values.get('name') || '').trim(), description: String(values.get('description') || '').trim() }; if (kind === 'web') body.url = String(values.get('url') || '').trim(); else { body.kind = 'mobile'; body.platform = kind; body.bundleId = String(values.get('bundleId') || '').trim(); body.device = String(values.get('device') || '').trim(); } await api('/api/targets', body); form.reset(); targetFields(); await refresh(true); await syncScriptForTarget(); noticeKey('app.targetSaved'); }); }
835
856
  function renderLanguage() {
836
857
  const editedModels = [...document.querySelectorAll('.model-form')].map((form) => ({ role: form.dataset.role, values: Object.fromEntries([...form.querySelectorAll('input')].map((input) => [input.name, input.value])) }));
837
858
  const focusedModel = document.activeElement?.closest?.('.model-form');
@@ -891,7 +912,7 @@
891
912
  const json = $('suite-editor').value;
892
913
  const unsavedJson = json.trim() && (!app.savedFile || json !== JSON.stringify(app.draft, null, 2));
893
914
  if (unsavedJson && !confirmScenarioReplacement('app.confirmNewDraft')) return;
894
- app.draft = null; app.selectedCaseIds = new Set(); app.script = ''; app.savedFile = ''; app.savedHash = '';
915
+ app.draft = null; app.selectedCaseIds = new Set(); app.script = ''; app.neutralScript = ''; app.scriptRevision += 1; app.savedFile = ''; app.savedHash = '';
895
916
  app.origin = 'none'; app.sourceFlow = ''; app.boundSource = null; app.stale = false; app.dirty = false; app.rerunOrigin = null; app.rerunTargetMismatch = false; renderRerunHints();
896
917
  $('suite-editor').value = ''; $('review-checkbox').checked = false;
897
918
  summarize(null); renderCaseSelection(); readiness();
@@ -900,8 +921,8 @@
900
921
  });
901
922
  $('flow-input').addEventListener('input', () => { if (app.origin === 'imported' ? $('flow-input').value !== editableFlow(app.sourceFlow) : (app.sourceFlow || app.boundSource) && $('flow-input').value.trim() !== editableFlow(app.sourceFlow).trim()) { app.stale = true; app.savedHash = ''; $('review-checkbox').checked = false; } readiness(); });
902
923
  $('scenario-platform').addEventListener('change', () => { app.planRequest += 1; if (app.draft) { app.stale = true; app.savedHash = ''; } $('review-checkbox').checked = false; readiness(); });
903
- $('suite-editor').addEventListener('input', () => { app.dirty = true; app.script = ''; app.savedFile = ''; app.savedHash = ''; if (app.origin === 'none') app.origin = 'manual'; $('review-checkbox').checked = false; summarize(null); readiness(); });
904
- $('review-checkbox').addEventListener('change', readiness); $('target-select').addEventListener('change', () => { $('review-checkbox').checked = false; if ($('target-select').value) { app.rerunTargetMismatch = false; renderRerunHints(); } targetDescription(); });
924
+ $('suite-editor').addEventListener('input', () => { app.dirty = true; app.script = ''; app.neutralScript = ''; app.scriptRevision += 1; app.savedFile = ''; app.savedHash = ''; if (app.origin === 'none') app.origin = 'manual'; $('review-checkbox').checked = false; summarize(null); readiness(); });
925
+ $('review-checkbox').addEventListener('change', readiness); $('target-select').addEventListener('change', () => { $('review-checkbox').checked = false; if ($('target-select').value) { app.rerunTargetMismatch = false; renderRerunHints(); } targetDescription(); void syncScriptForTarget(); });
905
926
  $('case-selection-list').addEventListener('change', (event) => { const input = event.target.closest('input[data-case-id]'); if (!input) return; const next = new Set(app.selectedCaseIds); if (input.checked) next.add(input.dataset.caseId); else next.delete(input.dataset.caseId); changeCaseSelection(next); });
906
927
  $('select-all-cases').addEventListener('click', () => changeCaseSelection((app.draft?.cases || []).map((item) => item.id)));
907
928
  $('clear-case-selection').addEventListener('click', () => changeCaseSelection([]));
@@ -336,14 +336,26 @@ export async function startUIServer(options) {
336
336
  }
337
337
  return flow;
338
338
  }
339
- async function getSuite(file, verify = false) {
339
+ async function compileForTarget(suite, targetName) {
340
+ if (targetName === undefined)
341
+ return compileSuite(suite);
342
+ const name = parse(idSchema, targetName);
343
+ const target = (await config()).targets[name];
344
+ if (!target)
345
+ invalid('The selected target was not found.');
346
+ if ((suite.platform ?? 'web') !== (target.kind === 'mobile' ? 'mobile' : 'web')) {
347
+ throw new HTTPError(409, 'The case platform and selected target do not match. Review them again.');
348
+ }
349
+ return compileSuite(suite, target);
350
+ }
351
+ async function getSuite(file, verify = false, targetName) {
340
352
  safeBasename(file, '.json');
341
353
  const root = await directory(['cases']);
342
354
  if (!root)
343
355
  notFound();
344
356
  const suite = parse(suiteSchema, jsonObject(await readRegular(root, file, MAX_SUITE)));
345
357
  const flow = await readSource(suite, verify);
346
- return { suite, suiteHash: sha256(JSON.stringify(suite)), script: compileSuite(suite), ...(flow === undefined ? {} : { flow }) };
358
+ return { suite, suiteHash: sha256(JSON.stringify(suite)), script: await compileForTarget(suite, targetName), ...(flow === undefined ? {} : { flow }) };
347
359
  }
348
360
  async function suites() {
349
361
  const root = await directory(['cases']);
@@ -528,7 +540,7 @@ export async function startUIServer(options) {
528
540
  const file = url.searchParams.get('file');
529
541
  if (!file)
530
542
  invalid('A case file name is required.');
531
- sendJSON(response, 200, await getSuite(file, true));
543
+ sendJSON(response, 200, await getSuite(file, true, url.searchParams.get('targetName') ?? undefined));
532
544
  return;
533
545
  }
534
546
  if (url.pathname === '/api/report') {
@@ -763,9 +775,9 @@ export async function startUIServer(options) {
763
775
  }
764
776
  if (url.pathname === '/api/compile') {
765
777
  const result = await mutation(async () => {
766
- const { suite } = parse(z.object({ suite: suiteSchema }).strict(), body);
778
+ const { suite, targetName } = parse(z.object({ suite: suiteSchema, targetName: idSchema.optional() }).strict(), body);
767
779
  await readSource(suite, true);
768
- return { suite, script: compileSuite(suite) };
780
+ return { suite, script: await compileForTarget(suite, targetName) };
769
781
  });
770
782
  sendJSON(response, 200, result);
771
783
  return;
package/docs/mobile.md CHANGED
@@ -50,6 +50,10 @@ Flow QA does not download SDKs, create or boot simulators, or install applicatio
50
50
 
51
51
  The compiler launches the configured app at the start of each runnable case unless the first step is already `launchApp`. It does not clear app data or create login state. A launch is not a fresh account/session. The web-only `open` path and `assertUrl` steps are rejected in mobile suites, and native steps are rejected in web suites.
52
52
 
53
+ Android's built-in Settings app (`com.android.settings`) can keep its system process alive after a force-stop. For that app only, Flow QA sends the device home, opens Settings through the mobile engine, and confirms Settings is in the foreground. This resets the visible Settings screen in the tested Android 16 emulator without requiring the system process to exit; it does not clear Settings data or guarantee process restart. Other Android apps and iOS apps continue using the engine's normal `app.open()` restart.
54
+
55
+ To inspect the script that a selected target will run, choose that target in the local UI before reviewing or downloading the script, or use `flow-qa generate cases/my-flow.json --target my-android --workspace ./my-qa`. CLI generation without `--target` is target-neutral and may differ from Settings execution.
56
+
53
57
  Native `testId` locators use iOS accessibility identifiers or Android resource IDs. Accessibility exposure depends on the app framework. Fixed steps need no model; natural-language steps require a compatible tool/image-capable agent. A WebView's exposed native controls may be usable, but this path does not provide a browser DOM session or prove JavaScript bridge behavior.
54
58
 
55
59
  ## Results and proof boundaries
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ihyeon/flow-qa",
3
- "version": "0.9.11",
3
+ "version": "0.9.12",
4
4
  "license": "MIT",
5
5
  "author": "Hyeonse Im",
6
6
  "repository": {