@sun-asterisk/sungen 3.2.11 → 3.2.12-beta.10

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.
Files changed (51) hide show
  1. package/dist/capabilities/discover.d.ts.map +1 -1
  2. package/dist/capabilities/discover.js +5 -2
  3. package/dist/capabilities/discover.js.map +1 -1
  4. package/dist/cli/commands/capability.d.ts.map +1 -1
  5. package/dist/cli/commands/capability.js +44 -2
  6. package/dist/cli/commands/capability.js.map +1 -1
  7. package/dist/dashboard/templates/index.html +1 -1
  8. package/dist/exporters/csv-exporter.d.ts.map +1 -1
  9. package/dist/exporters/csv-exporter.js +7 -2
  10. package/dist/exporters/csv-exporter.js.map +1 -1
  11. package/dist/exporters/feature-parser.d.ts.map +1 -1
  12. package/dist/exporters/feature-parser.js +15 -2
  13. package/dist/exporters/feature-parser.js.map +1 -1
  14. package/dist/exporters/json-exporter.d.ts.map +1 -1
  15. package/dist/exporters/json-exporter.js +10 -5
  16. package/dist/exporters/json-exporter.js.map +1 -1
  17. package/dist/exporters/result-variants.d.ts +23 -5
  18. package/dist/exporters/result-variants.d.ts.map +1 -1
  19. package/dist/exporters/result-variants.js +65 -9
  20. package/dist/exporters/result-variants.js.map +1 -1
  21. package/dist/exporters/test-data-resolver.d.ts.map +1 -1
  22. package/dist/exporters/test-data-resolver.js.map +1 -1
  23. package/dist/harness/capability.d.ts +1 -0
  24. package/dist/harness/capability.d.ts.map +1 -1
  25. package/dist/harness/capability.js.map +1 -1
  26. package/dist/harness/catalog/drivers.yaml +2 -1
  27. package/dist/orchestrator/templates/ai-src/commands/create-data-test.md +111 -0
  28. package/dist/orchestrator/templates/ai-src/commands/create-test.md +3 -0
  29. package/dist/orchestrator/templates/ai-src/commands/run-test.md +1 -0
  30. package/dist/orchestrator/templates/ai-src/config/claude.md +3 -1
  31. package/dist/orchestrator/templates/ai-src/config/copilot.md +3 -1
  32. package/dist/orchestrator/templates/ai-src/skills/sungen-data-factory/SKILL.md +213 -0
  33. package/dist/orchestrator/templates/ai-src/skills/sungen-tc-generation/SKILL.md +1 -0
  34. package/package.json +3 -2
  35. package/src/capabilities/discover.ts +5 -2
  36. package/src/cli/commands/capability.ts +40 -2
  37. package/src/dashboard/templates/index.html +1 -1
  38. package/src/exporters/csv-exporter.ts +7 -3
  39. package/src/exporters/feature-parser.ts +15 -2
  40. package/src/exporters/json-exporter.ts +10 -6
  41. package/src/exporters/result-variants.ts +68 -9
  42. package/src/exporters/test-data-resolver.ts +1 -0
  43. package/src/harness/capability.ts +1 -0
  44. package/src/harness/catalog/drivers.yaml +2 -1
  45. package/src/orchestrator/templates/ai-src/commands/create-data-test.md +111 -0
  46. package/src/orchestrator/templates/ai-src/commands/create-test.md +3 -0
  47. package/src/orchestrator/templates/ai-src/commands/run-test.md +1 -0
  48. package/src/orchestrator/templates/ai-src/config/claude.md +3 -1
  49. package/src/orchestrator/templates/ai-src/config/copilot.md +3 -1
  50. package/src/orchestrator/templates/ai-src/skills/sungen-data-factory/SKILL.md +213 -0
  51. package/src/orchestrator/templates/ai-src/skills/sungen-tc-generation/SKILL.md +1 -0
@@ -25,7 +25,7 @@ import {
25
25
  import { ApiCatalogEntry, EnvironmentInfo, PlaywrightResult, ScreenSummary, TestCaseRow } from './types';
26
26
  import { collectSecretValues, formatApiExpected, formatApiRequest, hasApiCalls, redactSecrets } from './api-testcase-formatter';
27
27
  import { SelectorKeyMap, substituteSelectorKeysInStep } from './selector-key-resolver';
28
- import { resolveResultVariants } from './result-variants';
28
+ import { formatVariantRow, resolveResultVariants } from './result-variants';
29
29
 
30
30
  export interface BuildCsvInput {
31
31
  screen: string;
@@ -70,7 +70,7 @@ export function buildTestCaseRows(input: BuildCsvInput): TestCaseRow[] {
70
70
  // Data-driven (@cases): expand to one CSV row per executed dataset input (Playwright titles
71
71
  // "<scenario> — <label>"); plain scenarios resolve their single result. Shared with the
72
72
  // dashboard/JSON exporter via resolveResultVariants so the two can't drift on @cases handling.
73
- const variants = resolveResultVariants(m, input.results);
73
+ const variants = resolveResultVariants(m, input.results, input.testData);
74
74
 
75
75
  for (const variant of variants) {
76
76
  const displayName = `${m.feature.name}${variant.nameSuffix}`;
@@ -132,7 +132,11 @@ export function buildTestCaseRows(input: BuildCsvInput): TestCaseRow[] {
132
132
  // Multi-line bullet format keeps delivery CSV/XLSX in sync with the
133
133
  // dashboard's Test data section. Multi-line CSV cells are valid (quoted
134
134
  // automatically) and render natively as multi-line in XLSX.
135
- const testData = formatTestData(m.feature.referencedVars, input.testData, Infinity, '\n');
135
+ let testData = formatTestData(m.feature.referencedVars, input.testData, Infinity, '\n');
136
+ // @cases: each report line shows ITS OWN dataset row (executed auto rows and manual
137
+ // split rows both carry variant.row) — one line per case, one dataset per line.
138
+ const variantRow = formatVariantRow(variant, '\n');
139
+ if (variantRow) testData = testData ? `${testData}\n${variantRow}` : variantRow;
136
140
 
137
141
  // Status for this (possibly per-input) row — resolved into `variant` above.
138
142
  const result: PlaywrightResult | undefined = variant.result;
@@ -9,7 +9,7 @@ import { FeatureMetadata, OrderedStep, ScenarioMetadata } from './types';
9
9
  /**
10
10
  * Variables referenced in a scenario: find all {{var_name}} in step text.
11
11
  */
12
- function extractReferencedVars(scenario: ParsedScenario): string[] {
12
+ function extractReferencedVars(scenario: ParsedScenario, includeComments = false): string[] {
13
13
  const vars = new Set<string>();
14
14
  for (const step of scenario.steps) {
15
15
  const matches = step.text.matchAll(/\{\{([a-zA-Z_][a-zA-Z0-9_.-]*)\}\}/g);
@@ -28,6 +28,19 @@ function extractReferencedVars(scenario: ParsedScenario): string[] {
28
28
  }
29
29
  }
30
30
  }
31
+ // Manual scenarios carry their real tester procedure in `# Tester verifies:` comment
32
+ // blocks — the {{var}} refs there are the data the tester needs, so include them
33
+ // (issue: manual test cases exported with an empty Test Data cell). Automated
34
+ // scenarios keep step-only scanning: their comments are notes (SPEC-GAP etc.) and
35
+ // would only add noise vars to the delivery report.
36
+ if (includeComments) {
37
+ for (const line of scenario.comments ?? []) {
38
+ const matches = line.matchAll(/\{\{([a-zA-Z_][a-zA-Z0-9_.-]*)\}\}/g);
39
+ for (const match of matches) {
40
+ vars.add(match[1]);
41
+ }
42
+ }
43
+ }
31
44
  return Array.from(vars);
32
45
  }
33
46
 
@@ -85,7 +98,7 @@ export function parseFeatureMetadata(featureFilePath: string): FeatureMetadata {
85
98
  tags: [...parsed.tags, ...sc.tags],
86
99
  stepsName: sc.stepsName,
87
100
  extendsName: sc.extendsName,
88
- referencedVars: extractReferencedVars(sc),
101
+ referencedVars: extractReferencedVars(sc, extractTestcaseType([...parsed.tags, ...sc.tags]) === 'Manual'),
89
102
  rawGivenSteps: given,
90
103
  rawWhenSteps: when,
91
104
  rawThenSteps: then,
@@ -23,7 +23,7 @@ import {
23
23
  } from './playwright-report-parser';
24
24
  import { ApiCatalogEntry, EnvironmentInfo, PlaywrightResult } from './types';
25
25
  import { SelectorKeyMap, substituteSelectorKeysInStep } from './selector-key-resolver';
26
- import { resolveResultVariants } from './result-variants';
26
+ import { formatVariantRow, resolveResultVariants } from './result-variants';
27
27
  import {
28
28
  ScenarioSnapshot,
29
29
  ScreenSnapshot,
@@ -123,13 +123,17 @@ export function buildScreenSnapshot(input: BuildScreenSnapshotInput): ScreenSnap
123
123
  }
124
124
  // Dashboard modal uses whitespace-pre-wrap — pass '\n' to render one
125
125
  // key/value per line instead of the CSV-friendly "; " join.
126
- const testDataStr = formatTestData(m.feature.referencedVars, input.testData, Infinity, '\n');
126
+ const baseTestDataStr = formatTestData(m.feature.referencedVars, input.testData, Infinity, '\n');
127
127
 
128
- // @cases scenarios expand to one snapshot entry per executed dataset row (shared with the CSV
129
- // exporter via resolveResultVariants), so their per-row pass/fail is counted not collapsed
130
- // into one Pending/N/A entry as before.
131
- const variants = resolveResultVariants(m, input.results ?? null);
128
+ // @cases scenarios expand to one snapshot entry per executed dataset row and manual
129
+ // @cases split per DATASET row (shared with the CSV exporter via resolveResultVariants),
130
+ // so their per-row pass/fail is counted — not collapsed into one Pending/N/A entry.
131
+ const variants = resolveResultVariants(m, input.results ?? null, input.testData);
132
132
  for (const variant of variants) {
133
+ // Per-line Test Data: shared vars + THIS variant's dataset row (parity with csv-exporter).
134
+ let testDataStr = baseTestDataStr;
135
+ const variantRow = formatVariantRow(variant, '\n');
136
+ if (variantRow) testDataStr = testDataStr ? `${testDataStr}\n${variantRow}` : variantRow;
133
137
  const displayName = `${m.feature.name}${variant.nameSuffix}`;
134
138
  const { vpId, category1 } = splitVpAndName(displayName);
135
139
  const tcId = generateTcId(input.screen, vpId, fallbackIndex);
@@ -5,12 +5,42 @@
5
5
  */
6
6
  import { MergedScenario } from './scenario-merger';
7
7
  import { PlaywrightResult } from './types';
8
+ import { extractTestcaseType } from './feature-parser';
8
9
 
9
10
  export interface ResultVariant {
10
- /** Appended to the scenario display name: `''` for a plain scenario, ` — <label>` per executed
11
+ /** Appended to the scenario display name: `''` for a plain scenario, ` — <label>` per
11
12
  * @cases dataset row (so each row gets a distinct category1). */
12
13
  nameSuffix: string;
13
14
  result?: PlaywrightResult;
15
+ /** The @cases dataset row backing this variant — lets the exporters render the row's own
16
+ * columns into the Test Data cell (`__`-prefixed bookkeeping keys excluded). Present on
17
+ * executed auto rows (matched by label) and on manual split rows. */
18
+ row?: Record<string, unknown>;
19
+ }
20
+
21
+ /**
22
+ * Read the `@cases:<name>` dataset rows for a scenario from the (flattened) test-data map.
23
+ * `loadTestData()` flattens arrays to JSON strings — accept that shape and raw arrays.
24
+ * Scalar rows normalize to `{ value }`, mirroring the runtime TestDataLoader.cases().
25
+ */
26
+ export function getCasesDatasetRows(
27
+ m: MergedScenario,
28
+ testData: Record<string, string> | null | undefined,
29
+ ): Array<Record<string, unknown>> | null {
30
+ const tag = m.feature.tags.find((t) => t.startsWith('@cases:'));
31
+ if (!tag || !testData) return null;
32
+ let list: unknown = testData[tag.slice('@cases:'.length)];
33
+ if (typeof list === 'string') {
34
+ try { list = JSON.parse(list); } catch { return null; }
35
+ }
36
+ if (!Array.isArray(list) || list.length === 0) return null;
37
+ return list.map((row) =>
38
+ row && typeof row === 'object' && !Array.isArray(row) ? (row as Record<string, unknown>) : { value: row });
39
+ }
40
+
41
+ /** Display label of a dataset row — mirrors the runtime TestDataLoader.cases() rule. */
42
+ function rowLabel(row: Record<string, unknown>, i: number): string {
43
+ return String(row.case ?? row.name ?? row.label ?? `row ${i + 1}`);
14
44
  }
15
45
 
16
46
  /**
@@ -18,9 +48,12 @@ export interface ResultVariant {
18
48
  *
19
49
  * A `@cases:<dataset>` scenario compiles to one `test()` per dataset row, whose Playwright title is
20
50
  * `<scenario> — <label>` — expand into one variant per EXECUTED row by matching that prefix (so an
21
- * already-run row carries its real pass/fail). A plain scenario resolves its single result by the
22
- * spec test title. With no results — or a @cases scenario with no matching result yet — a lone
23
- * variant with no result is returned, so the caller marks it Pending / N/A.
51
+ * already-run row carries its real pass/fail), attaching the backing dataset row by label.
52
+ *
53
+ * A MANUAL `@cases` scenario never executes, so that expansion can never fire — split it from the
54
+ * DATASET instead: one variant per row (` — <label>`, no result → Pending), each carrying its row
55
+ * so the manual tester gets one report line + its own data per case to walk and record. An auto
56
+ * @cases scenario that has not run yet stays a single line (its expansion belongs to execution).
24
57
  *
25
58
  * NOTE: this deliberately does NOT gate on `m.spec`. For @cases the compiled test title carries a
26
59
  * `— ${__row.__label}` suffix, so `findMatchingSpecTest` (base-name match) often leaves `m.spec`
@@ -30,13 +63,26 @@ export interface ResultVariant {
30
63
  export function resolveResultVariants(
31
64
  m: MergedScenario,
32
65
  results: Map<string, PlaywrightResult> | null,
66
+ testData?: Record<string, string> | null,
33
67
  ): ResultVariant[] {
34
68
  const isCases = m.feature.tags.some((t) => t.startsWith('@cases:'));
35
- if (isCases && results) {
36
- const marker = `${m.feature.name} — `;
37
- const rows = [...results.entries()].filter(([t]) => t.includes(marker));
38
- if (rows.length) {
39
- return rows.map(([t, r]) => ({ nameSuffix: ` — ${t.slice(t.indexOf(marker) + marker.length)}`, result: r }));
69
+ if (isCases) {
70
+ const datasetRows = getCasesDatasetRows(m, testData);
71
+ const byLabel = new Map<string, Record<string, unknown>>();
72
+ (datasetRows ?? []).forEach((row, i) => byLabel.set(rowLabel(row, i), row));
73
+
74
+ if (results) {
75
+ const marker = `${m.feature.name} — `;
76
+ const ran = [...results.entries()].filter(([t]) => t.includes(marker));
77
+ if (ran.length) {
78
+ return ran.map(([t, r]) => {
79
+ const label = t.slice(t.indexOf(marker) + marker.length);
80
+ return { nameSuffix: ` — ${label}`, result: r, row: byLabel.get(label) };
81
+ });
82
+ }
83
+ }
84
+ if (datasetRows && extractTestcaseType(m.feature.tags) === 'Manual') {
85
+ return datasetRows.map((row, i) => ({ nameSuffix: ` — ${rowLabel(row, i)}`, row }));
40
86
  }
41
87
  return [{ nameSuffix: '' }];
42
88
  }
@@ -45,3 +91,16 @@ export function resolveResultVariants(
45
91
  }
46
92
  return [{ nameSuffix: '' }];
47
93
  }
94
+
95
+ /**
96
+ * Render a variant's dataset row for the Test Data cell: one `col: value` line per column,
97
+ * `__`-prefixed bookkeeping keys excluded. Returns '' when the variant carries no row.
98
+ */
99
+ export function formatVariantRow(variant: ResultVariant, separator: string = '\n'): string {
100
+ if (!variant.row) return '';
101
+ const useBullet = separator.includes('\n');
102
+ return Object.entries(variant.row)
103
+ .filter(([k]) => !k.startsWith('__'))
104
+ .map(([k, v]) => `${useBullet ? '• ' : ''}${k}: ${v}`)
105
+ .join(separator);
106
+ }
@@ -133,6 +133,7 @@ function truncate(s: string, max: number): string {
133
133
  return s.substring(0, max - 1) + '…';
134
134
  }
135
135
 
136
+
136
137
  /**
137
138
  * Resolve `{{var}}` test-data placeholders in a step / expected-result line to their concrete values,
138
139
  * so the delivery report shows what QA actually verifies (e.g. `text contains {{app_version}}` →
@@ -24,6 +24,7 @@ export interface DriverMeta {
24
24
  package: string;
25
25
  runtime?: string;
26
26
  adapter?: string; // registry adapter name (defaults to id)
27
+ bundled?: boolean; // shipped as a core dependency — present without `capability add`
27
28
  capabilities: string[];
28
29
  unblocks?: string[];
29
30
  }
@@ -51,7 +51,8 @@ drivers:
51
51
  data-factory:
52
52
  kind: capability
53
53
  package: "@sungen/driver-data-factory"
54
- status: planned
54
+ status: shipped
55
+ bundled: true # runtime-free knowledge+codegen — shipped by default (no `capability add` needed)
55
56
  capabilities: ["@dataFactory"]
56
57
  unblocks: [M1]
57
58
  mock:
@@ -0,0 +1,111 @@
1
+ ---
2
+ name: create-data-test
3
+ description: "Generate standardized test-data for a screen/flow from the Data Factory catalog — valid/boundary/invalid values with CHK-* traceability (no free-form guessing)"
4
+ argument-hint: [screen-or-flow-name]
5
+ order: 25
6
+ claude-tools: "Read, Grep, Bash, Glob, Write, Edit, AskUserQuestion, Skill"
7
+ copilot-tools: "[vscode, execute, read, agent, edit, search, todo]"
8
+ codex-trigger: "Run when the user asks to CREATE, generate, or standardize TEST DATA / test values for a screen or flow (valid/boundary/invalid, boundary values, negative data). Uses the Data Factory driver. Not for generating the .feature scenarios themselves (that is create-test)."
9
+ ---
10
+
11
+ **Input**: A screen or flow name (e.g., `/sungen:create-data-test login`), OR **no name** to do every unit (with a confirmation — see ALL mode). Load the `sungen-data-factory` skill for the full method.
12
+
13
+ > **When to use.** `/sungen:create-test` already standardizes field test-data via Data Factory **inline** (its step 5.3), so you normally do **not** need this command as a follow-up. Use it **on demand** to *re-standardize*: after you edit a field-map or the `.overwrite`, for a unit authored before Data Factory existed, to refresh error-code mappings, or to (re)generate across many units at once (ALL mode). It MERGES into existing test-data (never clobbers).
14
+
15
+ ## Role
16
+
17
+ You are a **Senior QA Engineer** producing **test data to a standard**, not by guessing. You do NOT invent values field-by-field. You follow the 4-source method (spec rules → field-type catalog → design technique → DB mapping), driven by the **Data Factory** capability driver. Values come from the catalog (`common/` + the project's `.overwrite`), each tagged with a `CHK-*` id that traces back to the spec. Where the catalog cannot cover a project-specific field, you **ask the QA** — you never fabricate domain data.
18
+
19
+ ## Preconditions
20
+
21
+ 1. **Availability** — Data Factory is **bundled with core** (no `capability add` needed); its CLI (`sungen data …`) is available out of the box. Just continue.
22
+ 2. Determine mode from `$ARGUMENTS`:
23
+ - A **name** given → single-unit mode (that screen/flow only).
24
+ - **No name** → **ALL mode** (see below — always confirm first).
25
+
26
+ ## ALL mode (no name) — confirm before doing everything
27
+
28
+ If no name was given, the user wants **all** screens/flows — but this is wide, and a missing name is often a typo (they meant `create-data-test home`). So:
29
+
30
+ 1. List every unit under `qa/screens/*` and `qa/flows/*`, and classify each as **new** (no `test-data/<name>.yaml` yet) vs **would-overwrite**.
31
+ 2. Show the list and use `AskUserQuestion` to confirm: *"Generate test-data for ALL N units? (X new · Y would overwrite)"* — default to **No**.
32
+ 3. Only proceed when the user confirms. Then run the per-unit flow below for each (the CLI `sungen data gen --all` also enforces this confirm; `--yes` after the user agrees).
33
+
34
+ ## Per-unit flow (single unit, or each unit in ALL mode)
35
+
36
+ Auto-detect: `qa/flows/<name>/` → flow; else `qa/screens/<name>/` → screen. (API units carry their contract in `apis.yaml` — data there is `@cases` in create-test, not this command.)
37
+
38
+ ### 1. Read the sources (Nguồn 1 + 4)
39
+
40
+ Read `qa/<screens|flows>/<name>/requirements/spec.md` and `test-viewpoint.md`. For **each input field / parameter**, extract:
41
+ - data **type** (map to a catalog field-type: email · password · phone · string · number-integer · number-float · currency · postcode · katakana …),
42
+ - `required`, format, **min/max** length or value,
43
+ - the real **error/message code** the spec shows when a rule is violated,
44
+ - any **DB mapping** (unique, cross-entity dependency) noted in the spec.
45
+
46
+ Viewpoint tells you which fields are high-priority → give them the fullest data.
47
+
48
+ **No input fields → nothing to generate.** If the unit is a pure navigation / listing / capture-compare flow (e.g. a home-shopping browse flow) with **no user-input fields or parameters**, Data Factory has nothing to standardize. Report *"`<name>`: no input fields → nothing to generate"* and stop for this unit — do **not** write an empty `qa/data-factory/<name>.fields.yaml`. (Its scenarios are covered by create-test's data, not by field-level test data.)
49
+
50
+ ### 2. Write the field-map — `qa/data-factory/<name>.fields.yaml`
51
+
52
+ This is the input the deterministic generator expands. One entry per field:
53
+
54
+ ```yaml
55
+ screen: <name> # or: flow: <name>
56
+ fields:
57
+ - name: email
58
+ type: email
59
+ required: true
60
+ unique: true # fresh-per-run (register email won't collide)
61
+ constraints: { maxLocal: 64, maxTotal: 254 } # project's real limits
62
+ errorMap: { M13: E1042, M02: E1001 } # catalog placeholder → project's real code
63
+ - name: password
64
+ type: password
65
+ constraints: { minLength: 8, maxLength: 32 }
66
+ ```
67
+
68
+ **`unique: true`** — set it for a field that must be **different every run** (register email/username that can't clash with a record a previous run created). The valid value then gets a runtime `{{$timestamp}}` (email → `user+{{$timestamp}}@…`), so each run is fresh — no cross-run cache, no order-dependent flakiness. Boundary/invalid values stay literal (they test rules, not record creation).
69
+
70
+ Map every placeholder error code you can (`errorMap`) to the spec's real code. Leave a code unmapped only if the spec truly has none — the lint will flag it as an open point to confirm with BA/Dev.
71
+
72
+ **Complex forms — nested & dependent fields.** For a grouped/object field, give it **`fields:`** (sub-fields, expanded recursively; no `type` on the group). For a field whose rule depends on another, add **`dependsOn: { field: <other>, value: <v> }`** — it's recorded as a note so the scenario/`@cases` honor it (the generator doesn't resolve the runtime condition):
73
+ ```yaml
74
+ fields:
75
+ - name: address # group → nested object
76
+ fields:
77
+ - { name: city, type: string, constraints: { maxLength: 50 } }
78
+ - { name: postcode, type: postcode, dependsOn: { field: country, value: JP } }
79
+ ```
80
+
81
+ ### 3. Blind spots — ask, do not invent
82
+
83
+ If a field's type is **not** in the catalog (a business enum, a cross-entity constraint, a project data model), **stop and ask the QA** with `AskUserQuestion` for: (1) the valid set, (2) invalid / non-existent values, (3) the error code when wrong, (4) dependencies on other fields. Record the answer in `qa/data-factory/project/<entity>.yaml` for reuse. Never fabricate domain values.
84
+
85
+ ### 4. Lint the coverage
86
+
87
+ Run (local-first): `[ -x ./bin/sungen.js ] && ./bin/sungen.js data lint --screen <name> || npx sungen data lint --screen <name>`. Fix what it reports: add missing boundary values, resolve `UNRESOLVED` items (supply the constraint), map `OPEN_ERRORREF` codes. The bar is the phuong-phap §6 checklist — every required field has valid + boundary + invalid, one invalid per rule.
88
+
89
+ ### 5. Generate the test-data
90
+
91
+ Run (local-first): `[ -x ./bin/sungen.js ] && ./bin/sungen.js data gen --screen <name> || npx sungen data gen --screen <name>`. If `test-data/<name>.yaml` already exists it **merges** the standardized field data in — it **replaces only the field keys it owns and preserves every other key** (create-test's data, flow-namespaced keys, `@cases` datasets, overrides). It asks before merging (in ALL mode after they confirmed, add `--yes`; `--force` skips the prompt). The output is standardized `valid/boundary/invalid` values with `CHK-*` traceability.
92
+
93
+ ### 5.5 Validate semantic correctness
94
+
95
+ Run (local-first): `[ -x ./bin/sungen.js ] && ./bin/sungen.js data validate --screen <name> || npx sungen data validate --screen <name>`. This is stronger than lint (coverage): it checks every generated value is **semantically** correct — each `valid`/`boundary` value actually satisfies the constraints, and each synthesized `invalid` value actually violates them (a value in the `valid` set that breaks `maxLength`, or a "below min" case that landed inside the range, is a `VALUE_NOT_VALID` error). Fix any `error`; `INVALID_LOOKS_VALID` warns are a prompt to confirm the value is invalid for a non-length reason (charset/format). Each generated value also carries an `expected: valid|invalid` field in the test-data for traceability.
96
+
97
+ ### 5.6 Domain / stateful preconditions (spec + viewpoint only — no DB/API needed)
98
+
99
+ If the spec describes a **stateful precondition** — an entity with relationships or a business state the test needs *before* it runs (e.g. "a paid order of user A", "a valid unused reset token ≤24h", "the session-storage buffer holds the entered values") — **auto-draft it: run `… data state --scaffold <name>`** to generate a recipe skeleton from the spec's precondition sentences (one resource per signal, provenance guessed, entity as `TODO`). Then **fill each `entity`/`desiredState`/`bindings` and confirm the domain specifics with the QA** (`AskUserQuestion`) — never invent domain values. (You can also hand-author the `resources:` graph in `qa/data-factory/recipes.yaml`.) Provenance is **not only api/db** — pick `prior-flow` / `fixture` / `client-storage` / `server-context` / `manual` (use `api`/`db` only when a datasource exists). Then run `data state --recipe <name>`: it validates the graph and renders a standardized **manual precondition** block (`@manual:data-setup` when it can't be auto-provisioned) to weave into the scenario's `Background`. This is the domain/stateful improvement that works with **only spec + viewpoint** — the testcase states the required state precisely instead of a vague note; it auto-provisions later if an api/db datasource is added (no rewrite). For a **journey where the same data flows across screens** (setup → confirmation → complete), declare a `shared: { entity, screens: [...] }` so one dataset is used across all of them (the Cross-artifact Gate then asserts they match).
100
+
101
+ ### 5.7 Cross-artifact check (testcase ↔ data agree)
102
+
103
+ Run (local-first): `… data crosscheck --screen <name>`. It verifies the testcase and its test-data agree: no dangling `{{var}}` (every referenced var has a value), any cross-screen **shared** dataset is identical across the journey, and a declared state-precondition is surfaced in the feature. Fix any `error`. This is the `data-only` harness profile — `data validate` (values correct) + `data crosscheck` (values match the test); together they are the deterministic Data Gate + Cross-artifact Gate.
104
+
105
+ ### 6. Weave into scenarios (if create-test already ran)
106
+
107
+ If the `.feature` exists, turn the generated invalid/boundary sets into data-driven `Scenario Outline` + `Examples` (`@cases`) referencing the values — following `sungen-gherkin-syntax`. Weave any `data state` precondition block into the `Background`. Otherwise leave the standardized `test-data/<name>.yaml` for `/sungen:run-test` to consume.
108
+
109
+ ## After running
110
+
111
+ Use `AskUserQuestion` to offer the next step: review the generated data, run `/sungen:create-test <name>` (if scenarios don't exist yet), or `/sungen:run-test <name>`.
@@ -167,6 +167,8 @@ If the unit is **api-first** (`qa/api/<name>/` or `qa/api/flows/<name>/`), the d
167
167
 
168
168
  **5d. Sequential fallback.** Use the single-context incremental path (Step 2: tier-by-tier `Write`/`Edit` batches) when: only **one** shard applies, **Copilot / no sub-agents**, or a constrained setup. Same output, just no speedup. **For flows**: `[Screen:Element]` namespace refs, test-data namespaced by phase, `@flow` tag.
169
169
 
170
+ 5.3. **Standardize field test-data — Data Factory (when the unit has input fields).** Don't hand-invent per-field values — make them **standard**. For each input field, author the field-map `qa/data-factory/<name>.fields.yaml` (field → catalog `type` + the spec's real `constraints` + `errorMap` placeholder→real code), then run (Bash, local-first) `[ -x ./bin/sungen.js ] && ./bin/sungen.js data lint --screen <name> || npx sungen data lint --screen <name>` and `… data gen --screen <name>`, per the **`sungen-data-factory`** skill. `data gen` **MERGES** into `test-data.yaml` (replaces only its field keys, preserves your scenario/namespaced data), so it is safe to run here. Weave the standardized **boundary/invalid** sets into `@cases` (`Scenario Outline` + `Examples`) with `CHK-*` trace; keep the map's `errorMap`/`constraints` aligned to the spec. Then run `… data validate --screen <name>` (values are semantically correct) and — once the `.feature` exists — `… data crosscheck --screen <name>` (testcase ↔ data agree: no dangling `{{var}}`, shared datasets identical); fix any `error`. If the spec has a **stateful precondition** (an entity/state the test needs first), run `… data state --scaffold <name>` to auto-draft a recipe skeleton from the spec, **fill each `entity`/`desiredState` + confirm domain values with the QA**, then `… data state` and weave its `@manual:data-setup` `Background` block (see the `sungen-data-factory` skill — works with spec+viewpoint only, no DB/API). **This is the same standard as `/sungen:create-data-test`, applied inline — so you do NOT run that command separately afterwards.** A unit with **no input fields** (navigation / list / capture-compare) → **skip this step** (nothing to standardize).
171
+
170
172
  5.4. **Depth self-check (deterministic — run BEFORE the audit).** Run `sungen depth-lint --screen <name>` (Bash). It reuses the audit's businessDepth classifier and splits every shallow business-critical scenario into two actionable buckets — act on them now so the audit/repair loop doesn't burn rounds on depth:
171
173
  - **DEEPEN IN PLACE** — add a real value assertion to each (`User see all [X] contain {{v}}`, `User remember [X] as {{v}}` + `… with {{v}}`). The printed `template` is a **hint** keyed off the theme — apply judgment to the scenario's actual claim; do NOT paste a value assertion that doesn't fit (e.g. a carousel-visibility scenario should assert the product SET, not a price). If a flagged scenario is genuinely visibility/behavior (not data-correctness), that's an over-count — leave it and note it, never fake an assertion.
172
174
  - **CROSS-SCREEN** — route to a flow (`/sungen:add-flow`) or tag `@manual:Mx` + reason; do NOT fake an on-screen data assertion. This removes it from the screen's depth denominator honestly.
@@ -194,6 +196,7 @@ If the unit is **api-first** (`qa/api/<name>/` or `qa/api/flows/<name>/`), the d
194
196
  4. Follow the `sungen-tc-generation` skill for section identification, viewpoint generation, and output format. **For flows**, use the "Flow Test Generation" section in the skill. When requirements exist, use the "Requirements-Driven Generation" strategy. **For Tier 1**, apply the **Lightweight Guard** — verify required fields, validation rules, business rules, security checks, and key state transitions all have TCs after generation. **For Tier 2+**, **MUST** apply the full **Mapping Contract** — walk every `spec.md` section top-to-bottom and produce the indicated TCs per Table 1; handle `test-viewpoint.md` per Table 2. Do not silently skip sections. Present sections as a numbered list and let user pick.
195
197
  5. Generate or update `.feature` + `test-data.yaml` following `sungen-gherkin-syntax` and `sungen-tc-generation` skills. Generate **group-by-group** (one viewpoint group at a time, tier-by-tier `Write`/`Edit` batches) to stay under the output-token cap. **For flows**: use `[Screen:Element]` namespace format, namespace test-data by phase, add `@flow` tag. **If a scenario needs `@query` DB verification**, check the datasource `engine` first — unsupported engine → follow `sungen-gherkin-syntax` § "Unsupported DB engine — fallback" instead of authoring `@query` steps.
196
198
  > **No parallel fan-out here.** Copilot has no sub-agents, so generation is sequential (the Claude Code variant fans out one `sungen-generator` per viewpoint group and merges). Same output, no speedup.
199
+ 5.3. **Standardize field test-data — Data Factory (when the unit has input fields).** For each input field, author the field-map `qa/data-factory/<name>.fields.yaml` (field → catalog `type` + real `constraints` + `errorMap`), then run `sungen data lint --screen ${input:name}` and `sungen data gen --screen ${input:name}` per the **`sungen-data-factory`** skill. `data gen` **MERGES** into `test-data.yaml` (replaces only its field keys, preserves the rest), so it is safe here. Weave the standardized boundary/invalid sets into `@cases` with `CHK-*` trace. Then `… data validate` (values correct) + `… data crosscheck` (testcase↔data agree); for a stateful precondition, `… data state --scaffold <name>` to auto-draft → fill entities + confirm with QA → `… data state`, weave the `@manual:data-setup` `Background` (works spec+viewpoint only). **Same standard as `/sungen:create-data-test`, applied inline — do NOT run that command separately afterwards.** No input fields (navigation/list) → skip.
197
200
  5.4. **Depth self-check (deterministic — BEFORE the audit).** Run `sungen depth-lint --screen ${input:name}`. It splits every shallow business-critical scenario into **DEEPEN IN PLACE** (add a real value assertion — the printed `template` is a theme-keyed hint, apply judgment to the actual claim; never fake one onto a visibility/behavior scenario) and **CROSS-SCREEN** (route to a flow / tag `@manual:Mx` + reason — removes it from the depth denominator honestly). Act on both, re-run until `deepen` is empty (or only honest over-counts remain), THEN gate. Lifts first-pass `businessDepth` mechanically instead of via 2–3 repair rounds.
198
201
  5.5. **Quality gate & repair (harness — always run).** Per `sungen-harness-audit`: run `sungen audit --screen ${input:name}` (structural), THEN do an **independent semantic review inline** using the `sungen-reviewer` criteria (does each scenario's steps PROVE its title/viewpoint? observable Thens? business-critical assertion depth?). Merge both sets of issues; if gate FAILs / findings exist, repair (budget 3) and re-audit — GATE missing theme → generate it (cross-screen → **automate it in the flow** via `/sungen:add-flow`, NOT a full `@manual` screen duplicate — `sungen audit` flags an automatable `@manual` as `MANUAL-AUTOMATABLE`; reserve `@manual:Mx` for true judgment/missing-capability); DEPTH → add data assertions; BALANCE → add business-core first; TRACE → align VP ids. Never fake a pass.
199
202
  5.6. **Record.** `sungen manifest --screen ${input:name}`. Ledger **each phase** (not just repair) — pick one `runId` at the start and pass it so `trace`/`ledger report` show THIS run, not a mix: `sungen ledger record --screen ${input:name} --run <runId> --step <discovery|viewpoint|gherkin|audit|repair:N> --ms <elapsed>`. On re-run, start with `sungen manifest --screen ${input:name} --diff` and only regenerate changed sections.
@@ -127,6 +127,7 @@ If the unit is **api-first**, skip every selector/capture phase (an API test has
127
127
  ## Pre-run (phased — per `sungen-selector-fix` skill)
128
128
 
129
129
  1. Verify `<base>/<name>/` has `.feature` + `test-data.yaml`. **If the feature has `@query` steps**, check the resolved datasource `engine` in `qa/datasources.yaml` — unsupported engine → follow the `sungen-gherkin-syntax` skill § "Unsupported DB engine — fallback" before compiling (do not attempt a direct connect).
130
+ 1.5. **Data Factory pre-check (before running)** — Data Factory is bundled with core, so whenever a field-map exists (`qa/data-factory/<name>.fields.yaml`), confirm the test-data is standardized and covers each field before you run: `[ -x ./bin/sungen.js ] && ./bin/sungen.js data lint --screen <name> || npx sungen data lint --screen <name>`. If it reports coverage gaps (missing boundary/invalid, unresolved values, unmapped error codes) or the field-map is newer than `test-data/<name>.yaml`, refresh via `/sungen:create-data-test <name>` (or `sungen data gen --screen <name>`) — then compile. Blind spots (a `type` not in the catalog) are for the QA to answer, not to invent. No field-map / driver disabled → skip this step.
130
131
  2. **Phase 0 — Selector Pre-gen**: if `selectors.yaml` is missing/empty or doesn't cover the feature file's `[Reference]`s, apply the following decision tree before running Phase 0 from `sungen-selector-fix`:
131
132
 
132
133
  ```
@@ -18,14 +18,16 @@ You generate 3 files for sungen — a Gherkin compiler that produces Playwright
18
18
  | `sungen-delivery` | Export Gherkin + Playwright results → CSV test case deliverable |
19
19
  | `sungen-capture` | Acquire visual/design context — one skill, 4 modes: figma-mcp (Dev Mode MCP), figma-pat (URL → spec_figma.md), live (Playwright MCP scan), local (images in `requirements/ui/`) |
20
20
  | `sungen-locale` | Bootstrap i18n — audit selectors, detect locale switch mechanism, generate test-data overlay |
21
+ | `sungen-data-factory` | Standardized test-data — field-type/security catalog, 4-source method, `.overwrite`, blind-spot prompts |
21
22
 
22
- ## Workflow (7 AI commands)
23
+ ## Workflow (8 AI commands)
23
24
 
24
25
  | Command | What it does |
25
26
  |---|---|
26
27
  | `/sungen:add-screen <name> <path>` | Scaffold `qa/screens/<name>/` directories |
27
28
  | `/sungen:add-flow <name> [--path <url>]` | Scaffold `qa/flows/<name>/` directories for E2E cross-screen testing |
28
29
  | `/sungen:create-test <name>` | Generate `.feature` + `test-data.yaml` (auto-detects screen or flow) |
30
+ | `/sungen:create-data-test <name>` | Generate standardized test-data (valid/boundary/invalid + CHK trace) from the Data Factory catalog; no name = all units (asks to confirm) |
29
31
  | `/sungen:review <name>` | Score syntax, coverage, viewpoint quality (auto-detects screen or flow) |
30
32
  | `/sungen:run-test <name>` | Generate `selectors.yaml`, compile, run, auto-fix (auto-detects screen or flow) |
31
33
  | `/sungen:delivery [name...]` | Export test cases → CSV for QA delivery (all screens if no arg) |
@@ -18,14 +18,16 @@ You generate 3 files for sungen — a Gherkin compiler that produces Playwright
18
18
  | `sungen-delivery` | Export Gherkin + Playwright results → CSV test case deliverable |
19
19
  | `sungen-capture` | Acquire visual/design context — one skill, 4 modes: figma-mcp (Dev Mode MCP), figma-pat (URL → spec_figma.md), live (Playwright MCP scan), local (images in `requirements/ui/`) |
20
20
  | `sungen-locale` | Bootstrap i18n — audit selectors, detect locale switch mechanism, generate test-data overlay |
21
+ | `sungen-data-factory` | Standardized test-data — field-type/security catalog, 4-source method, `.overwrite`, blind-spot prompts |
21
22
 
22
- ## Workflow (7 AI commands)
23
+ ## Workflow (8 AI commands)
23
24
 
24
25
  | Command | What it does |
25
26
  |---|---|
26
27
  | `/sungen-add-screen <name> <path>` | Scaffold `qa/screens/<name>/` directories |
27
28
  | `/sungen-add-flow <name> [--path <url>]` | Scaffold `qa/flows/<name>/` directories for E2E cross-screen testing |
28
29
  | `/sungen-create-test <name>` | Generate `.feature` + `test-data.yaml` (auto-detects screen or flow) |
30
+ | `/sungen-create-data-test <name>` | Generate standardized test-data (valid/boundary/invalid + CHK trace) from the Data Factory catalog; no name = all units (asks to confirm) |
29
31
  | `/sungen-review <name>` | Score syntax, coverage, viewpoint quality (auto-detects screen or flow) |
30
32
  | `/sungen-run-test <name>` | Generate `selectors.yaml`, compile, run, auto-fix (auto-detects screen or flow) |
31
33
  | `/sungen-delivery [name...]` | Export test cases → CSV for QA delivery (all screens if no arg) |