@ihyeon/flow-qa 0.10.12 → 0.10.14

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
@@ -250,7 +250,11 @@ export async function main(args) {
250
250
  throw error;
251
251
  }
252
252
  const suite = await planFlow(flow, config.planner, { platform });
253
- suite.source = { file: arg, sha256: sha256(flow) };
253
+ const sourceDirectory = dirname(flowPath);
254
+ const inWorkspaceFlows = sourceDirectory === join(workspace, 'flows')
255
+ || sourceDirectory === join(await realpath(workspace), 'flows');
256
+ const sourceFile = inWorkspaceFlows ? `flows/${basename(flowPath)}` : arg;
257
+ suite.source = { file: sourceFile, sha256: sha256(flow) };
254
258
  await writeJSON(output, suite, true);
255
259
  console.log(localized(locale, `Cases created: ${output}\n${suite.cases.filter((c) => c.questions.length).length} of ${suite.cases.length} cases have open questions.`, `케이스 생성: ${output}\n${suite.cases.length}개 중 확인 질문이 있는 케이스 ${suite.cases.filter((c) => c.questions.length).length}개`));
256
260
  return;
@@ -7,7 +7,8 @@ import { localized, localizeProductMessage } from "./i18n.js";
7
7
  import { idSchema } from "./schema.js";
8
8
  import { targetLabel } from "./targets.js";
9
9
  export const RUN_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
10
- export const MAX_SAVED_REPORT_BYTES = 2 * 1024 * 1024;
10
+ // Saved reports include step results for each attempt in addition to the suite's checks.
11
+ export const MAX_SAVED_REPORT_BYTES = 16 * 1024 * 1024;
11
12
  const archiveEnvelopeSchema = z.object({
12
13
  schemaVersion: z.literal('flow-qa/report-1'), runId: z.string().regex(RUN_ID), suiteId: idSchema,
13
14
  parentRunId: z.string().regex(RUN_ID).optional(),
@@ -34,9 +34,10 @@ async function start(args, locale) {
34
34
  throw new StartupError(localized(locale, 'Port must be an integer from 0 to 65535. Example: flow-qa ui --port 4311', '포트는 0~65535 사이 정수여야 합니다. 예: flow-qa ui --port 4311'));
35
35
  if (values.demo && values.workspace)
36
36
  throw new StartupError(localized(locale, '--demo and --workspace cannot be used together.', '--demo와 --workspace는 함께 사용할 수 없습니다.'));
37
+ const requestedWorkspace = resolve(values.workspace ?? '.');
37
38
  let workspace;
38
39
  try {
39
- workspace = await realpath(resolve(values.workspace ?? '.'));
40
+ workspace = await realpath(requestedWorkspace);
40
41
  }
41
42
  catch {
42
43
  throw new StartupError(localized(locale, 'Workspace directory not found. Run flow-qa init /path/to/my-qa first, then pass --workspace.', '작업 공간 디렉터리를 찾을 수 없습니다. 먼저 flow-qa init /path/to/my-qa로 준비한 뒤 --workspace로 지정하세요.'));
@@ -69,7 +70,7 @@ async function start(args, locale) {
69
70
  throw error;
70
71
  }
71
72
  }
72
- ui = await startUIServer({ workspace, port });
73
+ ui = await startUIServer({ workspace, port, ...(values.demo ? {} : { workspaceAlias: requestedWorkspace }) });
73
74
  console.log(localized(locale, `Flow QA: ${ui.url}\nWorkspace: ${workspace}`, `Flow QA: ${ui.url}\n작업 공간: ${workspace}`));
74
75
  if (demo)
75
76
  console.log(localized(locale, `Local demo app: ${demo.url}\nOpen the example in the case library, review it, then run it in a real browser. No model call is made.`, `로컬 데모 앱: ${demo.url}\n케이스 보관함에서 예제를 열고 검토한 뒤 실제 브라우저로 실행하세요. 모델 호출은 없습니다.`));
@@ -107,6 +107,13 @@
107
107
  return Boolean(app.draft && app.script && app.savedFile && app.savedHash && !app.dirty && !app.stale && !app.busy && !hasUnsavedScenario());
108
108
  }
109
109
  function canDownloadSourceMarkdown() { return canDownloadSavedCases() && Boolean(app.draft.source); }
110
+ function sourceFileName(source) { return source.file.split(/[\\/]/).at(-1); }
111
+ function downloadSavedCases() {
112
+ if (!canDownloadSavedCases()) return;
113
+ const { source } = app.draft;
114
+ const suite = source ? { ...app.draft, source: { ...source, file: `flows/${sourceFileName(source)}` } } : app.draft;
115
+ download(app.savedFile, `${JSON.stringify(suite, null, 2)}\n`, 'application/json');
116
+ }
110
117
  function readiness() {
111
118
  const active = app.state?.active;
112
119
  const ready = !!app.draft && !!app.script && !app.stale && !app.dirty;
@@ -229,10 +236,10 @@
229
236
  $('target-select').firstChild.value = '';
230
237
  for (const target of app.state?.targets || []) { const option = el('option', '', targetDisplay(target)); option.value = target.name; $('target-select').append(option); }
231
238
  if ((app.state?.targets || []).some((x) => x.name === selected)) $('target-select').value = selected;
232
- if (previousFingerprint !== app.displayTargets.find((item) => item.name === selected)?.targetFingerprint) $('review-checkbox').checked = false;
233
239
  targetDescription();
234
240
  const list = $('target-list'); replace(list);
235
241
  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); }
242
+ return previousFingerprint !== selectedTarget()?.targetFingerprint;
236
243
  }
237
244
  function targetDescription() { const target = selectedTarget(); $('target-description').textContent = target ? `${targetLabel(target)}${target.description ? ` · ${target.description}` : ''}` : t('scenario.targetHint'); readiness(); }
238
245
  async function syncScriptForTarget() {
@@ -652,7 +659,11 @@
652
659
  // A newer poll can satisfy the pending settings refresh.
653
660
  const refreshSettings = pendingSettingsRefresh !== 0 && request >= pendingSettingsRefresh;
654
661
  if (refreshSettings) pendingSettingsRefresh = 0;
655
- if (refreshSettings || initialize) { targetOptions(); modelForms(); }
662
+ if (refreshSettings || initialize) {
663
+ const targetChanged = targetOptions();
664
+ modelForms();
665
+ if (targetChanged) void syncScriptForTarget();
666
+ }
656
667
  if (previousActive?.kind === 'run' && !state.active) { if (state.lastError) notice(state.lastError, true); else noticeKey('app.runEnded'); }
657
668
  if (state.lastError && state.lastError !== app.lastError) { app.lastError = state.lastError; notice(state.lastError, true); }
658
669
  await validateComparisonSelection(state);
@@ -700,7 +711,10 @@
700
711
  if (jsonFiles[0].size > 1024 * 1024 || (markdownFiles[0] && markdownFiles[0].size > 128 * 1024)) throw localizedError('app.importTooLarge');
701
712
  let suite;
702
713
  try { suite = JSON.parse(await jsonFiles[0].text()); } catch { throw localizedError('app.invalidJson'); }
703
- const flow = markdownFiles[0] ? await markdownFiles[0].text() : undefined;
714
+ // Keep an initial UTF-8 BOM in the text used to verify the source hash.
715
+ const flow = markdownFiles[0]
716
+ ? new TextDecoder('utf-8', { ignoreBOM: true }).decode(await markdownFiles[0].arrayBuffer())
717
+ : undefined;
704
718
  const body = { suite, ...(flow === undefined ? {} : { flow }) };
705
719
  if (new TextEncoder().encode(JSON.stringify(body)).byteLength > 256 * 1024) throw localizedError('app.importTooLarge');
706
720
  const result = await api('/api/import', body);
@@ -991,7 +1005,7 @@
991
1005
  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'); }); }
992
1006
  async function clearModel(role) { await work(async () => { await api('/api/models', { role, clear: true }); await refresh(true); noticeKey('app.modelCleared'); }); }
993
1007
  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; } }
994
- 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'); }); }
1008
+ 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'); }); }
995
1009
  function renderLanguage() {
996
1010
  const editedModels = [...document.querySelectorAll('.model-form')].map((form) => ({ role: form.dataset.role, values: Object.fromEntries([...form.querySelectorAll('input')].map((input) => [input.name, input.value])) }));
997
1011
  const focusedModel = document.activeElement?.closest?.('.model-form');
@@ -1069,8 +1083,8 @@
1069
1083
  $('import-btn').addEventListener('click', importFiles);
1070
1084
  $('global-stop-btn').addEventListener('click', stop);
1071
1085
  $('reconnect-btn').addEventListener('click', () => refresh(true).catch(showError));
1072
- $('suite-download').addEventListener('click', () => { if (canDownloadSavedCases()) download(app.savedFile, `${JSON.stringify(app.draft, null, 2)}\n`, 'application/json'); });
1073
- $('flow-download').addEventListener('click', () => { if (canDownloadSourceMarkdown()) download(app.draft.source.file.split('/').pop(), app.sourceFlow, 'text/markdown'); });
1086
+ $('suite-download').addEventListener('click', downloadSavedCases);
1087
+ $('flow-download').addEventListener('click', () => { if (canDownloadSourceMarkdown()) download(sourceFileName(app.draft.source), app.sourceFlow, 'text/markdown'); });
1074
1088
  $('script-download').addEventListener('click', () => { if (app.draft && !app.dirty && !app.stale) download(`${app.draft.id || 'flow-qa'}.test.mjs`, app.script, 'text/javascript'); });
1075
1089
  $('report-md').addEventListener('click', downloadReportMarkdown);
1076
1090
  $('report-json').addEventListener('click', () => { if (app.report) download(`${app.selectedRun}.json`, JSON.stringify(app.report, null, 2), 'application/json'); });
@@ -180,13 +180,17 @@ function safeBasename(value, extension) {
180
180
  invalid('Invalid file name.');
181
181
  return value;
182
182
  }
183
- function sourceName(suite) {
183
+ function sourceName(suite, workspaceFlowRoots = []) {
184
184
  if (!suite.source)
185
185
  return undefined;
186
- const match = /^flows\/([^/\\]+)$/.exec(suite.source.file);
187
- if (!match)
188
- invalid('Invalid source flow path.');
189
- return safeBasename(match[1], '.md');
186
+ const file = suite.source.file;
187
+ const match = /^(?:\.\/)?flows\/([^/\\]+)$/.exec(file);
188
+ if (match)
189
+ return safeBasename(match[1], '.md');
190
+ if (path.isAbsolute(file) && workspaceFlowRoots.includes(path.dirname(file))) {
191
+ return safeBasename(path.basename(file), '.md');
192
+ }
193
+ return invalid('Invalid source flow path.');
190
194
  }
191
195
  function headers(response) {
192
196
  response.setHeader('Cache-Control', 'no-store');
@@ -224,6 +228,7 @@ export async function startUIServer(options) {
224
228
  const workspace = await realpath(options.workspace);
225
229
  if (!(await lstat(workspace)).isDirectory())
226
230
  throw new Error('Flow QA workspace does not exist.');
231
+ const workspaceFlowRoots = [path.join(workspace, 'flows'), path.resolve(options.workspaceAlias ?? options.workspace, 'flows')];
227
232
  const port = options.port ?? 4310;
228
233
  if (!Number.isInteger(port) || port < 0 || port > 65535)
229
234
  throw new Error('Invalid UI port.');
@@ -338,7 +343,7 @@ export async function startUIServer(options) {
338
343
  }
339
344
  }
340
345
  async function readSource(suite, verify) {
341
- const name = sourceName(suite);
346
+ const name = sourceName(suite, workspaceFlowRoots);
342
347
  if (!name)
343
348
  return undefined;
344
349
  const root = await directory(['flows']);
@@ -380,7 +385,7 @@ export async function startUIServer(options) {
380
385
  for (const file of files) {
381
386
  try {
382
387
  const suite = parse(suiteSchema, jsonObject(await readRegular(root, file, MAX_SUITE)));
383
- sourceName(suite);
388
+ sourceName(suite, workspaceFlowRoots);
384
389
  summaries.push({ file, id: suite.id, title: suite.title, caseCount: suite.cases.length,
385
390
  questionCount: suite.cases.reduce((count, testCase) => count + testCase.questions.length, 0) });
386
391
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ihyeon/flow-qa",
3
- "version": "0.10.12",
3
+ "version": "0.10.14",
4
4
  "license": "MIT",
5
5
  "author": "Hyeonse Im",
6
6
  "repository": {