firefly-import-preprocessor/.github/prompts/generate-config-tests.prompt.md
Reindl David (IT-PTR-CEN2-SL10) 170b2d2016 release 1.0
2026-05-02 17:53:19 +02:00

4.3 KiB
Raw Blame History

description argument-hint agent
Generate PHPUnit snapshot tests for a transformation config. Use when you want to add or update integration tests for a config file by providing 12 example input/output pairs per transformation rule. config file path (e.g. config/config-ubs-account.json) agent

Generate Config Integration Tests

You help the user create PHPUnit snapshot (golden-file) tests for a specific transformation config.

Workflow

Step 1 — Identify the config

If the user provided a config path as the argument, use it. Otherwise list all JSON files in config/ (excluding config.example.json) and ask which one to test.

Step 2 — Read and summarise the config

Read the config file with the read_file tool. Then present a compact table like:

# sourceColumn transformations outputColumn
1 Buchungsdatum dateformat (d.m.Y → Y-m-d) date
2 Buchungstext trim → replace → lowercase description

Also note: the metadata.extractionRules (which pre-header lines are extracted and under what names), and csvStructure.headerLine / csvStructure.delimiter.

Step 3 — Collect examples from the user

For each row in the table, ask the user to provide 12 example input cell values and the expected output value after transformation. Present a form like:

Rule 1 — Buchungsdatum → date (dateformat d.m.Y → Y-m-d)
  Example 1 input:  ___    expected output: ___
  Example 2 input:  ___    expected output: ___ (optional)

Rule 2 — Buchungstext → description (trim → replace → lowercase)
  Example 1 input:  ___    expected output: ___
  …

For _constant_ source columns (metadata injections), ask the user for the expected metadata value that should appear in the output (e.g. the IBAN string).

For metadata extraction rules, ask for a representative pre-header line string and the expected extracted value.

If the user skips a rule, use a simple passthrough value (copy source → output unchanged).

Step 4 — Synthesise fixture files

Derive the config name from the filename (e.g. config-ubs-account.jsonconfig-ubs-account).

tests/fixtures/<config-name>/input.csv

Build a minimal CSV that satisfies csvStructure:

  • Pre-header lines (lines 1 … headerLine-1): one synthetic line per metadata extraction rule that matches its regex and returns the example value the user gave. Remaining pre-header lines (if any) can be empty placeholders.
  • Header line (line headerLine): the delimiter-separated source column names needed by the config.
  • Data rows: one row per example set. Where the user provided two examples for the same rule, use two data rows; align all other columns to the first example's values.

tests/fixtures/<config-name>/expected.csv

Header: the output column names in the order they appear after all transformations are applied (new create columns appended after existing ones).
Rows: the expected output values the user specified, aligned to the data rows above.

Step 5 — Generate or update tests/ConfigIntegrationTest.php

If the file does not exist, create it. If it exists, add or replace only the parts that concern this config's fixture. The class must:

  • Use namespace UbsCsvTransformer\Tests
  • Extend PHPUnit\Framework\TestCase
  • Have a public static function fixtureProvider(): array that auto-discovers tests/fixtures/*/ directories, maps each to ['configName' => ..., 'fixtureDir' => ...]
  • Have a @dataProvider fixtureProvider test method testConfigProducesExpectedOutput(string $configName, string $fixtureDir) that:
    1. Resolves config/<configName>.json
    2. Instantiates ConfigurationLoader with that path
    3. Instantiates TransformerEngine with the loader
    4. Calls transform() with $fixtureDir/input.csv into a temp file
    5. Reads the temp file and $fixtureDir/expected.csv and asserts they are identical line-by-line with assertSame
    6. Cleans up the temp file in tearDown

Follow all existing project conventions:

  • German docblocks
  • PSR-12, max line length 150
  • No PHPStan suppressions

Step 6 — Verify

Run composer test and confirm the new test passes. If it fails, show the diff and ask the user to correct their expected values, then update expected.csv.