Build scripts

From marcellourbani/vscode_abap_remote_fs · View interactive version

Build scripts is an AI agent skill from the GitHub repository marcellourbani/vscode_abap_remote_fs. Standalone Phase 6 of SAP UI testing. Rediscovers the configured test folder, program, approved cases, and primary system from disk; validates upstream inputs; then writes one tests/<PROGRAM>/test-scripts/TC-XXX.spec.ts per case using @sap-testing/runtime. Use when the user asks to write, generate,

How to use this skill

Skill file

Build Scripts — Phase 6 (of 7)

If the scenario crosses SAP connections, load multi-system-workflows alongside this

skill. Keep one system per script and implement only the documented explicit JSON handoff

between linked stage cases.

Phase order: analyze-and-plan (1) → explore-ui (2) → design-cases (3) → define-data (4) → prepare-data (5) → build-scripts (6) → run-scripts (7).

For bounded, self-contained support work, use sap-task-helper with explicit inputs, allowed writes, and an output contract. Never delegate the whole phase (e.g. "write specs for all 30 cases") to sap-task-helper — it is a bounded per-file helper and will reject phase-scale work. Convert cases yourself, or delegate at most a small, explicitly-listed batch of disjoint files with a per-file write boundary.

Tool availability (read this if a tool seems missing)

Naming: when these docs say call X, X is a tool (you invoke it and get a result); delegate to / invoke X is an agent (a subagent you launch); load / follow X is a skill (a procedure you read). A name without a verb: see the overview's "Skills, tools, and agents" list.

The editor may hide tools until searched for. Before Step 0, ensure abapfs_get_test_folder, abapfs_get_connected_systems, and abapfs_verify_test_data_usage are available; if any is missing, search your available tools for it by name. If one cannot be found, tell the user.

Non-negotiable execution gate

Every required step and artifact below is recorded as a Phase 6 prerequisite. The abapfs_run_playwright_tests tool verifies script generation and validation and will reject every affected case if anything was skipped, deferred, incomplete, stale, or unverified. A .spec.ts file existing by itself cannot bypass the tool's validation.

Why

The test case says what to verify; the spec is the ONLY thing SAP will actually be asked. If the spec drifts from the case — skips a control, ignores a default, uses a hardcoded value instead of the resolved data — the automation reports GREEN while the real bug lives on. Every deviation from the case's state table is a hole in coverage. Every hardcoded material or plant makes the spec unrunnable in the next system. Fidelity here is what turns a plan into protection.

Goal: 1:1 .md → .spec.ts conversion using only the helper API, with runtime data resolution.

Process

Step 0 — Standalone bootstrap and input gate (mandatory)

Say before acting: "Starting Step 0: standalone bootstrap and upstream input gate."

Run these actions in this exact order in every chat:

  1. Call abapfs_get_test_folder before reading or writing any artifact. Treat the returned absolute path as <TEST_FOLDER>; never infer it from the workspace or a prior chat.
  2. If unset, STOP and ask the user to run "ABAP FS: Enable SAP UI Testing Features". If the folder is not open in the workspace, STOP and ask the user to add it via File > Add Folder to Workspace.
  3. Resolve <PROGRAM> and selected TC-IDs from the current request. If omitted, inspect <TEST_FOLDER>/tests/*/test-cases/_index.md. Auto-select only when exactly one candidate exists; otherwise ask. Use _index.md approval, runnability, and Data required? state, not prior-chat memory.
  4. Enforce the upstream input gate for the selected program: _index.md, _screens.md, and every selected TC-XXX.md must exist. If _index.md/TC-XXX.md is missing or inconsistent, STOP and follow design-cases; if _screens.md is missing, STOP and follow explore-ui. Read a matching TC-XXX.data.md only when the index says Data required? = yes (authored in define-data); no means no sidecar may exist.
  5. Call abapfs_get_connected_systems and confirm the primary connectionId. Ask only if ambiguous. The spec remains system-agnostic; this identity is used to check readiness and verify source facts.
  6. If a selected case has Data required? = yes, inspect <TEST_FOLDER>/tests/<PROGRAM>/test-results/<connectionId>/<TC-ID>/data.json or run the available readiness check. Missing prepared data does not prevent writing a structurally valid spec, but it must be reported in the handoff as a Phase 5 (prepare-data) blocker before execution.
  7. Confirm ABAP tools are available if source verification is needed. Every ABAP-tool call passes explicit connectionId.

Do not continue to Step 1 until <TEST_FOLDER>, <PROGRAM>, selected TC-IDs, required upstream artifacts, and primary connectionId are known.

Say before continuing: "Step 0 completed. Evidence: test folder, program, selected cases, required planning artifacts, and primary connection confirmed. Next: Step 1 — read source artifacts."

Step 1 — Read the test case, screens map, and helpers

Say before acting: "Starting Step 1: read every source artifact required for script generation."

MANDATORY reads (parallel):

The SapSession/SapArtifacts implementation is not present in the test folder or workspace. Use the method reference in Step 2 and the exposed @sap-testing/runtime type declarations as the authoritative API. Load helpers-reference before generating sap.se16n() proof, and also use it whenever another capability seems missing — you cannot add runtime methods from the test workspace.

WRITE to: tests/<PROGRAM>/test-scripts/<TC-XXX>.spec.ts (create test-scripts/ if it doesn't exist)

Be restart-safe — never blindly overwrite an existing spec. This phase can resume in a fresh chat or after a context compaction, so do not rely on memory of what you've written. Before writing <TC-XXX>.spec.ts, check whether it already exists:

Rules:

Say before continuing: "Step 1 completed. Evidence: selected test cases, data specs, _screens.md, and _index.md were read. Next: Step 2 — confirm the runtime API."

Step 2 — Method reference

Say before acting: "Starting Step 2: confirm every required interaction and assertion exists in the runtime API."

Load the sap-webgui skill before choosing locators or helper scopes. Follow its guidance for iframes, accessible names, generated IDs, dialogs, ALV, toolbars, uploads, themes, recording interpretation, and known reliability. In this phase, translate the approved case into runtime calls.

Interaction (via SapSession):

Assertions (via SapSession):

Runtime-safety mechanisms (automatic, no explicit call needed unless noted):

Load helpers-reference for sap.se16n() usage and the auto-mechanism table; load sap-webgui for the popup allow-list and dump-signature list.

Background artifacts (via SapArtifacts) — only these two methods exist. For anything about job status, IDoc counts, or table rows, use the TC's ## Post-test verification section instead (see design-cases and run-scripts) — that covers all DB-backed state now. These two remain because a filesystem path and rendered spool output have no SQL equivalent:

Data (top-level): resolveTestData(tcId, testInfo) → returns { [key]: string } from the .data.md + cache. ALWAYS pass testInfo (available as the test function's second argument) — it scopes the lookup to THIS program, preventing a same-numbered TC-ID in another program from being resolved by mistake.

Say before continuing: "Step 2 completed. Evidence: required runtime methods and any genuine capability gaps were identified. Next: Step 3 — select the spec template."

Step 3 — Spec template — follow exactly

Say before acting: "Starting Step 3: select and apply the correct spec template."

Two variants depending on whether the case needs test data. Read the case's _index.md row first:

Never infer this by rereading the TC body. abapfs_build_test_index already verifies that dataRequired and .data.md existence agree.

Variant A — case WITH `.data.md`
/**
 * TC-001 <title>
 * Source: tests/<PROGRAM>/test-cases/TC-001.md
 * Data:   tests/<PROGRAM>/test-cases/TC-001.data.md
 */
import { test } from "@playwright/test";
import {
  SapSession,
  SapArtifacts,
  resolveTestData,
} from "@sap-testing/runtime";

test("TC-001 <title>", async ({ page }, testInfo) => {
  const sap = new SapSession(
    page,
    { tcId: "TC-001", title: "<title>" },
    testInfo,
  );
  try {
    // Pass testInfo so resolveTestData scopes its search to THIS spec's program —
    // without it, a TC-ID that also exists in another program's test-cases/ could
    // silently resolve the wrong one's data.
    const data = await resolveTestData("TC-001", testInfo);

    await sap.openTx("SE38");
    await sap.setField("Program", "Z_YOUR_REPORT_NAME");
    await sap.pressKey("F8", "Run report");

    // From TC-001.md steps — `{ group: ... }` is emitted ONLY when
    // _screens.md records a real ARIA group. Plain ITS selection screens
    // don't expose one, so most cases just pass the label:
    await sap.setField("Material", data.sample_material);
    await sap.setField("Plant", data.sample_plant);
    await sap.execute();

    // From TC-001.md expected:
    await sap.expectAlert(/completed/i);
    await sap.expectGridHasRow(data.sample_material);

    // SQL still runs later in run-scripts. For verification: sql|mixed, also add
    // sap.se16n() here after the business action to prove the resulting state is
    // visible to business users and capture criteria/output screenshots.

    await sap.finish("pass");
  } catch (err) {
    await sap.finish("fail", (err as Error).message);
    throw err;
  }
});

Mandatory SE16N proof for SQL/mixed cases

Before generating any SE16N block, load the helpers-reference skill and follow its

sap.se16n() contract, especially the outputFields and expect decision rules. The

short examples here show translation patterns; helpers-reference is the authoritative

usage reference for parameters, operators, result fields, screenshot behavior, and

cardinality assertions.

If TC frontmatter says verification: sql or verification: mixed, read its mandatory

se16nTables list and write a meaningful sap.se16n() assertion for EVERY listed table

after the business action, using the same resolved keys. Do not optimize for merely

passing the gate. If a purchase-order case declares [EKKO, EKPO], show the created

header in EKKO and its expected item rows in EKPO. This is supporting screenshot proof:

keep every declared Phase 7 SQL/manual check.

Run abapfs_verify_test_data_usage after writing the spec. It compares literal table values in

the calls against se16nTables; comments and unrelated calls do not count. The run tool

enforces the same coverage. For complex joins/deltas, each listed table's SE16N assertion

shows its meaningful business-visible state while SQL proves the full technical condition.

Example for a created purchase order:

await sap.se16n({
  table: "EKKO",
  outputFields: ["EBELN", "BUKRS", "LIFNR", "BSTYP"],
  where: [{ field: "EBELN", low: data.purchase_order }],
  expect: { exactRows: 1 }
})
await sap.se16n({
  table: "EKPO",
  outputFields: ["EBELN", "EBELP", "MATNR", "WERKS", "MENGE"],
  where: [{ field: "EBELN", low: data.purchase_order }],
  expect: { minRows: 1 }
})

In this example, replace EKPO's minRows: 1 with exactRows: <expected item count> when

the TC knows how many items it created. Likewise, keep outputFields narrowly focused on

the keys and business values the screenshot must prove; never substitute "*" to avoid

identifying technical fields.

Variant B — case WITHOUT `.data.md` (no dynamic test data needed)

Use this for cases that only test validation errors, static defaults, mandatory-field messages, or anything that doesn't require live SAP data.

/**
 * TC-002 <title>
 * Source: tests/<PROGRAM>/test-cases/TC-002.md
 * No .data.md — this case needs no dynamic test data.
 */
import { test } from "@playwright/test";
import { SapSession } from "@sap-testing/runtime";

test("TC-002 <title>", async ({ page }, testInfo) => {
  const sap = new SapSession(
    page,
    { tcId: "TC-002", title: "<title>" },
    testInfo,
  );
  try {
    await sap.openTx("Z_MY_TCODE");
    await sap.selectRadio("Some Mode");
    await sap.execute();
    await sap.expectAlert(/required/i);
    await sap.finish("pass");
  } catch (err) {
    await sap.finish("fail", (err as Error).message);
    throw err;
  }
});

Say before continuing: "Step 3 completed. Evidence: the correct with-data or no-data template was selected for each case. Next: Step 4 — translate the case."

Step 4 — Rules for translating steps

Say before acting: "Starting Step 4: translate every case state, action, and expected result into runtime calls."

Step 4a — Selection screen state table — translate first

Say before acting: "Starting Step 4a: translate every selection-screen state row."

Read the ## Selection screen state at Execute table in the .md. For every row, emit ONE helper call according to Vs default:

| Vs default value | Emit |

| --------------------------------------- | ---------------------------------------------------------------------------- |

| changed from empty / changed from X | The action to set the new value (setField / check / selectRadio) |

| RESET from default X | An explicit clear/uncheck/select-other action — do NOT omit |

| at default | Nothing (no action) — unless the row also says confirm (see below) |

| at default (confirm) | An ASSERTION verifying the control is at the expected default before Execute |

Cross-check every row against _screens.md — the initial: value in the map must match Vs default. On mismatch, STOP and follow explore-ui to re-explore.

Two common mistranslations — do NOT make them:

Examples:

| State-table row | Emit |

| ----------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- |

| Article \| Article Selection \| <data-key: sample_article> \| changed from empty | await sap.setField("Article", data.sample_article, { group: "Article Selection" }) |

| Article Type \| Article Selection \| (leave empty) \| RESET from default \FERT\` | await sap.setField("Article Type", "", { group: "Article Selection" })` |

| Include archived \| Article Selection \| unchecked \| RESET from default CHECKED | await sap.check("Include archived", { group: "Article Selection", value: false }) |

| ALV Output \| Output Mode \| selected \| at default | (no action) |

| Excel Download \| Output Mode \| not selected \| at default (confirm) | Use a runtime assertion when available; otherwise flag the helper gap and use one narrow expect(sap.raw().frameLocator("iframe#ITSFRAME1").getByRole(...)) assertion |

Say before continuing: "Step 4a completed. Evidence: every state-table row maps to an action, assertion, or documented default. Next: Step 4b — translate the Steps section."

Step 4b — Translate the Steps section

Say before acting: "Starting Step 4b: translate navigation, actions, and expected results."

Once state-table actions are emitted, Steps become mostly nav + Execute + follow-ups.

| .md sentence | helper call |

| ---------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- |

| "Open transaction X" | sap.openTx("X") |

| "Start program X" | sap.runReport("X") OR sap.openTx("SE38") + sap.setField("Program", "X") + sap.pressKey("F8") |

| "Set field F in section S to <data-key: k>" | sap.setField("F", data.k, { group: "S" }) |

| "Set field F to a literal constant" | sap.setField("F", "LITERAL") — literal is OK for static values like radio labels, not transactional data |

| "Set field F (duplicate label; ABAP field N) to V" | sap.setField("F", V, { technicalName: "N" }) — last resort; _screens.md must record the duplicate and the verified technicalName |

| "CLEAR field F in section S" | sap.setField("F", "", { group: "S" }) |

| "Range F from A to B" | sap.setRange("F", data.a, data.b, { group: "S" }) |

| "Check C in section S" | sap.check("C", { group: "S" }) |

| "UNCHECK C in section S" | sap.check("C", { group: "S", value: false }) |

| "Select radio R in section S" | sap.selectRadio("R", { group: "S" }) |

| "Switch to tab T" / "On the T tab, …" | sap.clickTab("T") — tab labels are case- and punctuation-sensitive; match _screens.md exactly |

| "Set column C in row R of the item overview to V" | sap.setGridCell("C", R, V) — R is 1-based; use for editable ALV cells (ME21N items, MIGO items, VF01 items). Do NOT use setField on grid cells |

| "Set column C in row R to <data-key: k>" | sap.setGridCell("C", R, data.k) |

| "Click Execute" | sap.execute() |

| "Click button B in dialog D" | sap.clickButton("B", { dialog: "D" }) |

| "On Exit Document dialog, discard changes" / "Leave without saving" | sap.clickButton("No", { dialog: "Exit Document" }) — NOT auto-dismissed; must be explicit |

| "On Exit Document dialog, save changes" | sap.clickButton("Yes", { dialog: "Exit Document" }) |

| "Press F4 and pick V" | sap.pickFromValueHelp("F", "V", { group }) |

| "Upload file P" | Native <input type="file"> → sap.uploadFile(...); SAP path textbox → sap.setField(...), as verified in _screens.md |

| "Download Excel" | const p = await sap.captureDownload(() => sap.clickButton("Export")) |

| "Expected: message M appears" | sap.expectAlert("M") |

| "Expected: title Y" | sap.expectTitle("Y") |

| "Expected: job J finishes" / "IDoc of type T created" / "row in table T where K=V" | Keep the authoritative SQL in ## Post-test verification; for verification: sql|mixed, also add a meaningful sap.se16n() business-visible proof in the spec |

| "Expected: file P on app server" | await artifacts.verifyAL11FilePresent("P") |

| "Expected: message M is NOT shown" | sap.expectNoAlert(/M/) — pass the pattern so it asserts THAT message is absent. The bare sap.expectNoAlert() fails on ANY status text (e.g. a leftover message from the prior round-trip) → false negatives; use it only for "status bar completely clear". |

| "Expected: exactly N rows in the grid" | Do NOT use expectGridHasRow for a count — it is an unanchored substring match (see anti-patterns). Assert on a business-unique value, or add the count as a by: sql ## Post-test verification check |

When _screens.md cites a recording, use it only to clarify validated interaction order and control behavior. Apply the recording classification from sap-webgui; never copy a raw generated locator. Map recorded business literals to declared data.<key> values, remove recorder noise such as a redundant click before fill, preserve intentional Enter/server-roundtrip behavior through helpers, and author assertions from the TC because codegen records actions only. If a required interaction still has no stable semantic contract, STOP, load the sap-webgui-recording skill, and request focused exploration; do not manufacture a locator.

Say before continuing: "Step 4b completed. Evidence: every case step and expected result maps to an allowed runtime operation or post-test verification check. Next: finish Step 4."

Say before continuing: "Step 4 completed. Evidence: each selected case was translated without omitted controls or invented helpers. Next: Step 5 — validate data keys."

Step 5 — Data-key naming

Say before acting: "Starting Step 5: validate every data.<key> reference against its data specification."

Data keys in data.k MUST match keys in .data.md. If .md references a data key that isn't in .data.md, STOP and follow define-data to update .data.md first.

Don't just eyeball this — run the deterministic check after writing the spec (see Step 7).

Say before continuing: "Step 5 completed. Evidence: every referenced data key exists in the matching .data.md. Next: Step 6 — anti-pattern review."

Step 6 — Anti-pattern review

Say before acting: "Starting Step 6: review generated scripts for prohibited patterns."

Say before continuing: "Step 6 completed. Evidence: generated scripts contain no prohibited selectors, waits, screenshots, hardcoded business data, or omitted state rows. Next: Step 7 — verify written specs."

Step 7 — After writing

Say before acting: "Starting Step 7: run deterministic verification for every written spec."

Call abapfs_verify_test_data_usage before handing off — mandatory, not optional.

This fails loudly if the spec references a data.<key> that <TC-XXX>.data.md never declared (the exact mistake that lets resolveTestData throw at run time), and warns about any declared key the spec never ended up using.

Then tell the user it is ready to run with abapfs_run_playwright_tests (headed: true is recommended the first time). Do not execute it during Phase 6; execution follows the run-scripts workflow in Phase 7.

Say before continuing: "Step 7 completed. Evidence: abapfs_verify_test_data_usage results recorded for every new or changed spec. Next: Step 8 — write the handoff."

Step 8 — Write the next-chat handoff

Say before acting: "Starting Step 8: write the Phase 6 handoff."

Before ending Phase 6, make the disk state sufficient for a brand-new run-scripts chat:

Your final message MUST tell the user the exact next step: "Next: Phase 7 — start a new chat, load the run-scripts skill, and say: Run <PROGRAM> on <connectionId> using the specs on disk." Naming the skill matters — without it the next chat tends to skip loading run-scripts and improvise.

Say after the handoff is complete: "Step 8 completed. Evidence: built cases, verification results, and readiness blockers were handed off. Next phase: Phase 7 — in a new chat, load the run-scripts skill and follow it."

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.