plain-forge 1.0.1
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/LICENSE +21 -0
- package/README.md +247 -0
- package/bin/cli.mjs +143 -0
- package/forge/docs/.gitkeep +0 -0
- package/forge/rules/definitions.md +57 -0
- package/forge/rules/exported-concepts.md +39 -0
- package/forge/rules/func-specs.md +72 -0
- package/forge/rules/impl-reqs.md +50 -0
- package/forge/rules/import-modules.md +51 -0
- package/forge/rules/required-concepts.md +45 -0
- package/forge/rules/requires-modules.md +59 -0
- package/forge/rules/test-reqs.md +47 -0
- package/forge/skills/add-acceptance-test/SKILL.md +98 -0
- package/forge/skills/add-concept/SKILL.md +67 -0
- package/forge/skills/add-feature/SKILL.md +136 -0
- package/forge/skills/add-functional-spec/SKILL.md +81 -0
- package/forge/skills/add-functional-specs/SKILL.md +115 -0
- package/forge/skills/add-implementation-requirement/SKILL.md +73 -0
- package/forge/skills/add-resource/SKILL.md +108 -0
- package/forge/skills/add-template/SKILL.md +65 -0
- package/forge/skills/add-test-requirement/SKILL.md +68 -0
- package/forge/skills/analyze-2-func-specs/SKILL.md +102 -0
- package/forge/skills/analyze-func-specs/SKILL.md +124 -0
- package/forge/skills/analyze-if-func-spec-too-complex/SKILL.md +152 -0
- package/forge/skills/break-down-func-spec/SKILL.md +156 -0
- package/forge/skills/check-plain-env/SKILL.md +288 -0
- package/forge/skills/consolidate-concepts/SKILL.md +193 -0
- package/forge/skills/create-import-module/SKILL.md +98 -0
- package/forge/skills/create-requires-module/SKILL.md +104 -0
- package/forge/skills/debug-specs/SKILL.md +189 -0
- package/forge/skills/forge-integration/SKILL.md +443 -0
- package/forge/skills/forge-plain/SKILL.md +333 -0
- package/forge/skills/implement-conformance-testing-script/SKILL.md +247 -0
- package/forge/skills/implement-conformance-testing-script/assets/run_conformance_tests_cypress.ps1 +324 -0
- package/forge/skills/implement-conformance-testing-script/assets/run_conformance_tests_golang.ps1 +100 -0
- package/forge/skills/implement-conformance-testing-script/assets/run_conformance_tests_java.sh +102 -0
- package/forge/skills/implement-conformance-testing-script/assets/run_conformance_tests_python.ps1 +92 -0
- package/forge/skills/implement-conformance-testing-script/assets/run_conformance_tests_python.sh +100 -0
- package/forge/skills/implement-prepare-environment-script/SKILL.md +242 -0
- package/forge/skills/implement-prepare-environment-script/assets/prepare_environment_java.sh +42 -0
- package/forge/skills/implement-prepare-environment-script/assets/prepare_environment_python.sh +81 -0
- package/forge/skills/implement-unit-testing-script/SKILL.md +133 -0
- package/forge/skills/implement-unit-testing-script/assets/run_unittests_flutter.ps1 +82 -0
- package/forge/skills/implement-unit-testing-script/assets/run_unittests_golang.ps1 +68 -0
- package/forge/skills/implement-unit-testing-script/assets/run_unittests_java.sh +45 -0
- package/forge/skills/implement-unit-testing-script/assets/run_unittests_python.ps1 +76 -0
- package/forge/skills/implement-unit-testing-script/assets/run_unittests_python.sh +90 -0
- package/forge/skills/implement-unit-testing-script/assets/run_unittests_react.ps1 +83 -0
- package/forge/skills/init-config-file/SKILL.md +261 -0
- package/forge/skills/init-plain-project/SKILL.md +124 -0
- package/forge/skills/load-plain-reference/SKILL.md +646 -0
- package/forge/skills/plain-healthcheck/SKILL.md +132 -0
- package/forge/skills/refactor-module/SKILL.md +197 -0
- package/forge/skills/resolve-spec-conflict/SKILL.md +88 -0
- package/forge/skills/run-codeplain/SKILL.md +540 -0
- package/package.json +42 -0
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: implement-conformance-testing-script
|
|
3
|
+
description: >-
|
|
4
|
+
Implement a conformance-test runner script (Bash on macOS/Linux, PowerShell on
|
|
5
|
+
Windows) for an arbitrary programming language, in one of two variants:
|
|
6
|
+
install-inline (when no prepare_environment_<lang> script exists) or
|
|
7
|
+
activate-only (when one does). Use when the user wants to add a
|
|
8
|
+
conformance-test runner for a new language (Node.js, Go, Rust, Flutter, etc.)
|
|
9
|
+
to a ***plain project, or wants to regenerate / adapt one of the existing
|
|
10
|
+
runners.
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
# Implement Conformance Testing Script
|
|
14
|
+
|
|
15
|
+
This skill produces a single executable script that runs the **conformance tests** for a generated build folder, following a consistent, language-agnostic pattern.
|
|
16
|
+
|
|
17
|
+
The reference implementations are:
|
|
18
|
+
|
|
19
|
+
- [assets/run_conformance_tests_java.sh](assets/run_conformance_tests_java.sh) — Java, install-inline variant.
|
|
20
|
+
- [assets/run_conformance_tests_python.sh](assets/run_conformance_tests_python.sh) — Python, install-inline variant.
|
|
21
|
+
- [assets/run_conformance_tests_<lang>.ps1](assets/run_conformance_tests_*.ps1) — Windows PowerShell equivalents.
|
|
22
|
+
|
|
23
|
+
Read both before writing anything — every script you produce must be a faithful translation of the same pattern into the target language's tooling **and** the user's shell environment.
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
## How conformance scripts differ from unit-test scripts
|
|
27
|
+
|
|
28
|
+
A conformance script is structurally very close to a unit-test script (see the sibling skill [`implement-unit-testing-script`](../implement-unit-testing-script/SKILL.md)) but with two important differences:
|
|
29
|
+
|
|
30
|
+
1. **Two positional arguments instead of one.** A conformance script takes both the **build folder** (source under test) and a **separate conformance tests folder** (the tests to execute against that build).
|
|
31
|
+
2. **Tests are loaded from outside the working folder.** The build is staged into `.tmp/<lang>_<arg>` and the script `cd`s into it, but the test command is pointed at the *original* `$current_dir/<conformance_tests_folder>`. Tests are never copied into the staging area.
|
|
32
|
+
|
|
33
|
+
Everything else — toolchain check, build staging, dependency isolation, exit codes — is the same.
|
|
34
|
+
|
|
35
|
+
## Variant decision: install-inline vs. activate-only
|
|
36
|
+
|
|
37
|
+
**Before writing anything, decide which variant to emit.** Both variants share toolchain check, arg validation, cwd capture, test execution, and exit-code handling — they differ only in the middle (steps 4–7 of [the pattern](#the-pattern) below).
|
|
38
|
+
|
|
39
|
+
| Look for an existing | Emit |
|
|
40
|
+
|---|---|
|
|
41
|
+
| `prepare_environment_<lang>.sh` / `.ps1` in the project's `test_scripts/` folder (or wherever `config.yaml`'s `prepare-environment-script:` key points) | **Activate-only variant.** Verifies the prepared env, activates it, and runs tests. **Does not** stage the build or install deps — prepare already did. |
|
|
42
|
+
| Nothing — no prepare script | **Install-inline variant.** Stages the build, installs deps, and runs tests in one shot. |
|
|
43
|
+
|
|
44
|
+
### Why this split exists
|
|
45
|
+
|
|
46
|
+
The conformance runner is invoked **once per functional spec** by the renderer. Each functional spec in a module has its own `conformance_tests/<module>/<spec>/` folder, and after the renderer finishes generating code for a new spec, it runs the conformance tests of **every previous spec** in the same module to detect regressions. For a module with N functional specs, this script is called **on the order of N times per render** — not once per render.
|
|
47
|
+
|
|
48
|
+
That per-spec invocation pattern is what makes the install step expensive. A naive runner that does `pip install` / `npm ci` / `mvn install -DskipTests` / `cargo build` on every invocation pays the install cost N times per render. For anything beyond a toy project, that cost dominates wall-clock time.
|
|
49
|
+
|
|
50
|
+
The two variants are a direct response to this:
|
|
51
|
+
|
|
52
|
+
- **Install-inline** is correct only when N is small (a few specs) or dependencies are cheap. It is self-contained: stage, install, run, repeat from scratch every invocation.
|
|
53
|
+
- **Activate-only** is the production answer. [`prepare_environment_<lang>`](../implement-prepare-environment-script/SKILL.md) runs **once per render** and pays the install cost a single time, populating `.tmp/<lang>_<arg>/` with the warmed environment. Each of the N conformance invocations then just **attaches** to that working folder and runs the tests — no install, no compile, just activate-and-go.
|
|
54
|
+
|
|
55
|
+
**Why picking the right variant matters:** if you emit the install-inline variant alongside an existing prepare script, prepare's work is wiped (by the script's `rm -rf .tmp/<lang>_$1`) or duplicated (by re-running install) on every run — defeating prepare's whole purpose. Conversely, emitting activate-only without a prepare script means the "verify prepared environment" check fails on every run because nothing has populated the working folder. See [Anti-Patterns](#anti-patterns).
|
|
56
|
+
|
|
57
|
+
## Pick the Shell First
|
|
58
|
+
|
|
59
|
+
Before writing anything, decide which shell flavor the script must target — it depends on the user's environment, not on the language:
|
|
60
|
+
|
|
61
|
+
- **Bash (`.sh`)** — macOS, Linux, WSL, CI runners on Linux. Default unless the user is on native Windows.
|
|
62
|
+
- **PowerShell (`.ps1`)** — native Windows / PowerShell-only environments.
|
|
63
|
+
|
|
64
|
+
If you can't tell from the project (no obvious OS hints, no existing scripts), ask the user.
|
|
65
|
+
|
|
66
|
+
The same pattern applies to both. Only the syntax changes.
|
|
67
|
+
|
|
68
|
+
## The Pattern
|
|
69
|
+
|
|
70
|
+
Steps **1–3** and **step 8** are identical in both variants. Steps **4–7** differ — pick the subsection below that matches the variant you decided on.
|
|
71
|
+
|
|
72
|
+
### Common steps (both variants)
|
|
73
|
+
|
|
74
|
+
1. **Toolchain check.** Verify that the required language runtime / build tool (and the required version, if any) is installed. If not, print an error and exit with code `69`.
|
|
75
|
+
2. **Argument validation.** Require **two** positional arguments: `<build_folder>` and `<conformance_tests_folder>`. If either is missing, print usage and exit with code `69`.
|
|
76
|
+
3. **Capture original cwd.** Store `pwd` in a variable (`current_dir` / `$PWD`) **before** changing directories — the test command in step 8 needs it to resolve the conformance tests folder.
|
|
77
|
+
|
|
78
|
+
### Steps 4–7 — install-inline variant (no prepare script)
|
|
79
|
+
|
|
80
|
+
4. **Working directory setup.** Define a working folder at `.tmp/<lang>_<arg1>`. Wipe it (`rm -rf` / `Remove-Item -Recurse -Force`) and recreate it. This folder — and **only** this folder — is where every subsequent write must land.
|
|
81
|
+
5. **Copy the build.** Recursively copy everything from `<build_folder>` (`$1`) into the working folder. **Do not** copy the conformance tests — they stay where they are. After this step both `$1` (build folder) and `$2` (conformance tests folder) are treated as **read-only** for the rest of the script.
|
|
82
|
+
6. **Enter the working directory.** `cd` / `Set-Location` into `.tmp/<lang>_<arg1>`. If that fails, exit with code `69`. All remaining steps run from inside the working folder; they must never write back to `$1` or `$2`.
|
|
83
|
+
7. **Install dependencies into an isolated environment inside `.tmp/<lang>_<arg1>`.** Set up a per-working-folder dependency location (a Python venv at `./.venv`, a local `./node_modules`, a project-scoped Maven repo at `./.m2`, etc.) and install/resolve all dependencies into it. **Never** install into the source build folder (`$1`), the conformance tests folder (`$2`), the user's global cache (`~/.m2`, system-wide `pip`, `~/.cargo`, `~/.npm`, ...), or anywhere outside `.tmp/<lang>_<arg1>`. If the install command fails, propagate its exit code immediately and **do not** proceed to step 8. See [Dependency isolation (install-inline)](#dependency-isolation-install-inline).
|
|
84
|
+
|
|
85
|
+
### Steps 4–7 — activate-only variant (prepare script exists)
|
|
86
|
+
|
|
87
|
+
4. **Verify the prepared environment.** Both:
|
|
88
|
+
- Check that the working folder `.tmp/<lang>_<arg1>` exists.
|
|
89
|
+
- Check that the language's isolation location inside it exists (e.g. `.venv/bin/activate` for Python, `.m2/` for Java, `node_modules/` for Node, `.gocache/` for Go, `.cargo/` for Rust).
|
|
90
|
+
|
|
91
|
+
If either check fails, print a helpful error (`"Error: prepared environment missing — did you run prepare_environment_<lang>.<sh|ps1> first?"`) and exit `69`. **Do not silently fall back to creating it inline** — that would mask a real misconfiguration and turn this script into the install-inline variant in disguise. After this step both `$1` and `$2` are treated as **read-only** for the rest of the script.
|
|
92
|
+
5. **Enter the working directory.** `cd` / `Set-Location` into `.tmp/<lang>_<arg1>`. If that fails, exit `69`. All remaining steps run from inside the working folder; they must never write back to `$1` or `$2`.
|
|
93
|
+
6. **Activate the prepared dependency environment.** Per-language:
|
|
94
|
+
- Python: `source .venv/bin/activate` (must succeed; exit `69` on failure).
|
|
95
|
+
- Java: set `MAVEN_LOCAL_REPO="$(pwd)/.m2"` so it can be passed as `-Dmaven.repo.local="$MAVEN_LOCAL_REPO"` to `mvn` in step 8.
|
|
96
|
+
- Node.js / Go / Rust: nothing to activate explicitly — the test command in step 8 just needs to receive the same isolation flag/env var that prepare used (`./node_modules` is found by default; pass `GOMODCACHE` / `CARGO_HOME`).
|
|
97
|
+
|
|
98
|
+
Activation is **always relative to the working folder**, never to `$1` or `$2` — prepare populated `.tmp/<lang>_<arg1>/...`, and that is the only place to attach to.
|
|
99
|
+
7. *(There is no step 7 in this variant — install was prepare's job. Skip straight to step 8.)*
|
|
100
|
+
|
|
101
|
+
### Common step 8 (both variants)
|
|
102
|
+
|
|
103
|
+
8. **Run the conformance tests.** Invoke the language's standard test command, **pointed at `$current_dir/<conformance_tests_folder>`** (the original cwd from step 3 + the second arg). The script's final exit code is whatever the test command returns — except for the "no tests discovered" case below.
|
|
104
|
+
|
|
105
|
+
The test command is **read-only** with respect to `$current_dir/$2`. It loads test files from there, but any artifacts the runner produces (caches, JUnit XML, coverage reports, compiled test classes, etc.) must land inside `.tmp/<lang>_<arg1>`, not next to the test files. If your chosen runner defaults to writing output beside the tests, pass an explicit output-directory flag pointing inside the working folder (e.g. `pytest --basetemp=./.pytest_tmp`, `jest --cacheDirectory=./.jest_cache`, Maven `target/` under `.tmp` via `mvn -f "$current_dir/$2/pom.xml" -Dproject.build.directory="$(pwd)/target" test`).
|
|
106
|
+
|
|
107
|
+
### Read-only inputs — hard rule
|
|
108
|
+
|
|
109
|
+
A conformance script has **two** read-only inputs: the source build folder (`$1`) and the conformance tests folder (`$2`). Neither one may be written to under any circumstances. The script must never:
|
|
110
|
+
|
|
111
|
+
- install dependencies into `$1` or `$2` (no `pip install` inside `$1`/`$2`, no `npm install` inside them, no `mvn install` writing into them, no Cargo build artifacts ending up under them),
|
|
112
|
+
- write a virtualenv / `node_modules` / `.m2` / `.gocache` / `.cargo` directory inside `$1` or `$2`,
|
|
113
|
+
- run the test command with its `cwd` set to `$1` or `$2` (every test command runs from inside `.tmp/<lang>_<arg1>` after the `cd` in step 6 / activate-only step 5),
|
|
114
|
+
- create logs, caches, build outputs, JUnit XML, coverage reports, compiled test classes, or temp files inside `$1` or `$2`.
|
|
115
|
+
|
|
116
|
+
Why each input is read-only:
|
|
117
|
+
|
|
118
|
+
- **`$1` (build folder)** is shared with the renderer (`plain_modules/...` by default) and downstream tooling. Writing into it corrupts the renderer's view of "what was generated" and breaks subsequent renders. The whole point of staging into `.tmp/` is so the source folder stays a clean, reproducible artifact of the render.
|
|
119
|
+
- **`$2` (conformance tests folder)** is the user's authored test source — typically checked into version control. Writing into it pollutes the working tree, churns git status, and (with frameworks that auto-discover) can make subsequent runs pick up generated files as if they were tests.
|
|
120
|
+
|
|
121
|
+
If you find yourself about to issue any command whose `cwd` is `$1` or `$2`, or whose target path starts with `$1/` or `$2/`, **stop**. Either move the operation into `.tmp/<lang>_<arg1>`, or you're doing something the script must not do.
|
|
122
|
+
|
|
123
|
+
### "No tests discovered" detection
|
|
124
|
+
|
|
125
|
+
The Python reference script grep's the test runner output for `"Ran 0 tests in"` and exits `1` if no tests ran. Replicate the equivalent check for the target language wherever that language's test runner silently passes when given an empty test set:
|
|
126
|
+
|
|
127
|
+
- Python `unittest`: `"Ran 0 tests in"`
|
|
128
|
+
- Node.js `jest`: `"No tests found"`
|
|
129
|
+
- Go `go test`: `"no test files"` / `"no tests to run"`
|
|
130
|
+
- Rust `cargo test`: `"running 0 tests"`
|
|
131
|
+
- Java `mvn test`: usually fails loudly already; no extra check needed.
|
|
132
|
+
|
|
133
|
+
A silently-passing zero-test run is the most dangerous failure mode of a conformance runner — always guard against it. **This applies to both variants.**
|
|
134
|
+
|
|
135
|
+
## Conventions
|
|
136
|
+
|
|
137
|
+
Shared across both shell flavors **and** both variants:
|
|
138
|
+
|
|
139
|
+
- **Exit codes:**
|
|
140
|
+
- `69` — unrecoverable invocation error: missing argument, missing toolchain, can't enter working folder, can't create venv (install-inline), or prepared environment missing/broken (activate-only). Matches the reference scripts' `UNRECOVERABLE_ERROR_EXIT_CODE`.
|
|
141
|
+
- `1` — "no tests discovered" guard tripped (see above).
|
|
142
|
+
- Any other non-zero code — propagated from the underlying test command.
|
|
143
|
+
- **Working folder naming:** `.tmp/<lang>_<arg1>` where `<lang>` is a short identifier for the language (`java`, `python`, `node`, `go`, `rust`, ...). Use the *first* argument (the build folder) in the path, never the conformance tests folder. All dependency installs, build outputs, caches, test runner artifacts, and the test invocation itself live inside this folder. Nothing the script does should touch `$1` after step 5 (install-inline) / step 4 (activate-only), or `$2` at any point.
|
|
144
|
+
- **Logging — be as verbose as possible.** The script is the only thing the operator sees between a `codeplain` render and a green/red conformance result; when it fails, the only forensic evidence anyone has is its stdout/stderr. Treat the script like a production runbook, not a quiet helper. Concretely:
|
|
145
|
+
- **Announce every step before doing it**, with the exact value of every variable involved — the resolved build folder, the resolved conformance-tests folder, the captured `current_dir`, the working folder, the language, the toolchain version detected, the isolation root being activated (install-inline) or verified (activate-only), the variant in use, and the test command about to run. "Running tests" alone is useless; "Running `python -m unittest discover -b -s /abs/path/to/tests` from working folder `.tmp/python_build/` with venv activated at `./.venv` (Python 3.11.6)" is triage-ready.
|
|
146
|
+
- **Echo every non-trivial command before executing it.** In Bash, use `set -x` for the body of the script (or `echo "+ <cmd>"` immediately before each call); in PowerShell, set `$VerbosePreference = 'Continue'` and use `Write-Verbose` / `Write-Host` to print each command line with its arguments.
|
|
147
|
+
- **Print clear section banners.** Each pattern step gets a banner like `===== [6/8] Activate prepared environment =====` (activate-only) or `===== [7/8] Install dependencies =====` (install-inline) so a long log can be navigated by eye, **and** the banner names the variant so the operator immediately knows which branch is executing.
|
|
148
|
+
- **Print resolved absolute paths**, not just the relative names. Operators reading the log on a different machine need to know where the venv / `.m2` / `node_modules` / `.gocache` / `.cargo` actually landed, and where `$2` resolved to relative to `current_dir`.
|
|
149
|
+
- **Print the toolchain's own `--version` output** (and the path it resolved from) during step 1, even on success. This is the single most useful piece of forensic data when conformance passes locally but fails in CI.
|
|
150
|
+
- **Surface the install / activation output verbatim** — do not pipe it to `/dev/null`, do not redirect to a log file inside the working folder. The operator must see every dependency-resolver line (install-inline) or every "venv missing" / "\.m2 missing" guard message (activate-only) in the script's own output stream. Drop the `VERBOSE`-gated wrapping from the Python reference — conformance output is where forensic data is most valuable.
|
|
151
|
+
- **Print which variant the script is** (install-inline vs. activate-only) and **why** — e.g. "activate-only variant: detected `.tmp/python_build/.venv/bin/activate` from a prior `prepare_environment_python.sh` run". When the verify step trips, the operator must see both the path that was checked and the expected source ("did you run `prepare_environment_python.sh <build>` first?").
|
|
152
|
+
- **On failure, print what was about to run before exiting** — the exact test command, the working directory, the captured `current_dir`, the resolved `$2`, and the relevant environment variables (`PYTHONPATH`, `NODE_PATH`, `GOMODCACHE`, `CARGO_HOME`, `MAVEN_OPTS`, `PATH`, plus `VIRTUAL_ENV` for Python).
|
|
153
|
+
- **Print a final summary line** that names the variant, the test command, the exit code, the captured `current_dir`, and the working folder so the operator knows exactly what to re-run by hand if needed.
|
|
154
|
+
Verbosity is not noise here — a chatty script that documents itself in its own output is the difference between a 30-second triage and a 30-minute one. Never trade verbosity for terseness.
|
|
155
|
+
- **Capture `current_dir` before `cd`.** This is the single most common bug in hand-written conformance scripts: forgetting that the conformance tests folder argument is relative to the *invocation* directory, not the working folder. The captured value must also appear in the verbose log (per the logging rule above) so misresolutions of `$2` are visible at a glance.
|
|
156
|
+
|
|
157
|
+
### Dependency isolation (install-inline)
|
|
158
|
+
|
|
159
|
+
This section applies to **install-inline scripts only.** For activate-only scripts, the isolation location is set up by prepare; you just need to point the test command at it — see [Activating a prepared environment](#activating-a-prepared-environment-activate-only).
|
|
160
|
+
|
|
161
|
+
The dependency environment must live **inside** `$WORKING_FOLDER` so the test run can't be polluted by — or pollute — the user's global caches. Pick the most idiomatic isolation mechanism for the language:
|
|
162
|
+
|
|
163
|
+
| Language | Isolation mechanism | Install command (run inside `$WORKING_FOLDER`) | Test command (point at `$current_dir/$2`) |
|
|
164
|
+
|---|---|---|---|
|
|
165
|
+
| Python | `venv` at `./.venv` | `python3 -m venv .venv && source .venv/bin/activate && pip install -r requirements.txt` | `python -m unittest discover -b -s "$current_dir/$2"` (or `pytest "$current_dir/$2"`) |
|
|
166
|
+
| Node.js | local `./node_modules` (default) | `npm ci` (preferred) or `npm install` | `npx jest --rootDir "$current_dir/$2"` |
|
|
167
|
+
| Java | project-scoped Maven repo at `./.m2` | `mvn -Dmaven.repo.local=./.m2 install -DskipTests` (build + install artifact so the test pom can resolve it) | `mvn -f "$current_dir/$2/pom.xml" -Dmaven.repo.local="$(pwd)/.m2" test` |
|
|
168
|
+
| Go | module cache at `./.gocache` | `GOMODCACHE="$PWD/.gocache" go mod download` (optional pre-warm) | `GOMODCACHE="$PWD/.gocache" go test "$current_dir/$2/..."` |
|
|
169
|
+
| Rust | cargo home at `./.cargo` | `CARGO_HOME="$PWD/.cargo" cargo fetch` (optional pre-warm) | `CARGO_HOME="$PWD/.cargo" cargo test --manifest-path "$current_dir/$2/Cargo.toml"` |
|
|
170
|
+
|
|
171
|
+
Notes:
|
|
172
|
+
|
|
173
|
+
- **Every path in the install command and test command is relative to `.tmp/<lang>_<arg1>`.** That's why the script `cd`s into the working folder in step 6 — from that point on, `./.venv`, `./node_modules`, `./.m2`, etc. all resolve under `.tmp/<lang>_<arg1>`, never under `$1` or `$2`.
|
|
174
|
+
- **Always pass the isolation flag/env var to both the install command and the test command.** They must agree on where deps live, otherwise the test command will silently fall back to the global cache **or** (worse) write into `$1` / `$2`.
|
|
175
|
+
- **Python is the only ecosystem where the venv is mandatory** to satisfy "into a virtual environment" literally. The others use language-native equivalents that achieve the same isolation.
|
|
176
|
+
- **Propagate the install exit code immediately.** In Bash: `<install cmd> || exit $?`. In PowerShell: check `$LASTEXITCODE` and `exit $LASTEXITCODE` if non-zero.
|
|
177
|
+
- **Time the dependency setup** with `date +%s.%N` (Bash) / `Get-Date` (PowerShell) and print `"Requirements setup completed in X.XX seconds"`. If this number is large, that's the signal to add a `prepare_environment_<lang>` script (and switch this script to the activate-only variant).
|
|
178
|
+
|
|
179
|
+
### Activating a prepared environment (activate-only)
|
|
180
|
+
|
|
181
|
+
This section applies to **activate-only scripts only.** The isolation location was created by prepare; conformance just needs to attach to it and pass the right flags to the test command.
|
|
182
|
+
|
|
183
|
+
| Language | Verify exists in step 4 | Activate in step 6 | Test command in step 8 (point at `$current_dir/$2`) |
|
|
184
|
+
|---|---|---|---|
|
|
185
|
+
| Python | `.tmp/<lang>_$1/.venv/bin/activate` | `source .venv/bin/activate` (after `cd`-ing into the working folder) | `python -m unittest discover -b -s "$current_dir/$2"` |
|
|
186
|
+
| Node.js | `.tmp/<lang>_$1/node_modules/` | (nothing) | `npx jest --rootDir "$current_dir/$2"` |
|
|
187
|
+
| Java | `.tmp/<lang>_$1/.m2/` | `MAVEN_LOCAL_REPO="$(pwd)/.m2"` | `mvn -f "$current_dir/$2/pom.xml" -Dmaven.repo.local="$MAVEN_LOCAL_REPO" test` |
|
|
188
|
+
| Go | `.tmp/<lang>_$1/.gocache/` | `export GOMODCACHE="$(pwd)/.gocache"` | `go test "$current_dir/$2/..."` |
|
|
189
|
+
| Rust | `.tmp/<lang>_$1/.cargo/` | `export CARGO_HOME="$(pwd)/.cargo"` | `cargo test --manifest-path "$current_dir/$2/Cargo.toml"` |
|
|
190
|
+
|
|
191
|
+
Notes:
|
|
192
|
+
|
|
193
|
+
- **Verify, don't recreate.** If `.venv` is missing, exit `69` with a clear "did you run prepare_environment first?" message — do **not** silently fall back to creating it inline. That would silently degrade a misconfigured project into the install-inline path and mask the real problem.
|
|
194
|
+
- **Match prepare's isolation paths exactly.** If prepare puts the venv at `.venv` and you look for it at `venv`, the verify step will always fail. Read [`implement-prepare-environment-script`](../implement-prepare-environment-script/SKILL.md) for the canonical paths.
|
|
195
|
+
- **Don't time anything in this variant.** The slow phase is prepare; conformance just runs the tests. Adding a duration log here is misleading — it makes the script look like it's doing the install when it isn't.
|
|
196
|
+
|
|
197
|
+
### Bash specifics
|
|
198
|
+
|
|
199
|
+
- **Shebang:** `#!/bin/bash`.
|
|
200
|
+
- **File naming:** `run_conformance_tests_<lang>.sh`, placed in `assets/` (skill reference) or `test_scripts/` (target project).
|
|
201
|
+
- **Arguments:** `$1` = build folder, `$2` = conformance tests folder.
|
|
202
|
+
- **Make it executable:** `chmod +x` the produced script.
|
|
203
|
+
- **`cd` failure check:** the reference scripts use the `cd ... 2>/dev/null` + `[ $? -ne 0 ]` pattern. Keep it.
|
|
204
|
+
|
|
205
|
+
### PowerShell specifics
|
|
206
|
+
|
|
207
|
+
- **No shebang.** Use a `param([Parameter(Mandatory=$true)][string]$BuildFolder, [Parameter(Mandatory=$true)][string]$ConformanceTestsFolder)` block at the top instead.
|
|
208
|
+
- **File naming:** `run_conformance_tests_<lang>.ps1`.
|
|
209
|
+
- **Exit codes:** use `exit 69` etc. (PowerShell honors them just like Bash).
|
|
210
|
+
- **Toolchain check:** prefer `Get-Command <tool> -ErrorAction SilentlyContinue` and, where a specific version is needed, parse the tool's `--version` output.
|
|
211
|
+
- **Filesystem:** use `Test-Path`, `Remove-Item -Recurse -Force`, `New-Item -ItemType Directory`, `Copy-Item -Recurse`, `Set-Location`. Quote paths to handle spaces.
|
|
212
|
+
- **Capture original cwd:** `$currentDir = (Get-Location).Path` **before** any `Set-Location` call.
|
|
213
|
+
- **No `chmod` step needed.** If execution policy is likely to block the script, mention `Set-ExecutionPolicy -Scope CurrentUser RemoteSigned` to the user — don't bake it into the script.
|
|
214
|
+
|
|
215
|
+
## Workflow
|
|
216
|
+
|
|
217
|
+
1. **Decide the variant.** Look in the project for `prepare_environment_<lang>.sh` / `.ps1` (check `test_scripts/`, then any `prepare-environment-script:` key in `config.yaml`). If present → emit **activate-only**. If absent → emit **install-inline**. See [Variant decision](#variant-decision-install-inline-vs-activate-only).
|
|
218
|
+
2. Confirm the target **language**, **shell flavor** (Bash or PowerShell), and **dependency manifest** (`pom.xml`, `requirements.txt` / `pyproject.toml`, `package.json`, `go.mod`, `Cargo.toml`, ...). Ask if any is unclear.
|
|
219
|
+
3. Read [assets/run_conformance_tests_java.sh](assets/run_conformance_tests_java.sh) and [assets/run_conformance_tests_python.sh](assets/run_conformance_tests_python.sh) to refresh the exact structure. Both are install-inline references — for activate-only, follow steps 4–7 of [the activate-only variant](#steps-47--activate-only-variant-prepare-script-exists) and the [Activating a prepared environment](#activating-a-prepared-environment-activate-only) table.
|
|
220
|
+
4. Translate each step into the equivalent commands for the target language **and** shell. The toolchain check, dependency install/activate, and test invocation are the language-specific parts; the rest is mechanical translation between Bash and PowerShell syntax.
|
|
221
|
+
5. Pick the right per-language row:
|
|
222
|
+
- **Install-inline:** [Dependency isolation (install-inline)](#dependency-isolation-install-inline) table — use the same flag/env var in steps 7 and 8.
|
|
223
|
+
- **Activate-only:** [Activating a prepared environment](#activating-a-prepared-environment-activate-only) table — use the matching verify, activate, and test-command columns in steps 4, 6, and 8.
|
|
224
|
+
6. Add the language-appropriate "no tests discovered" guard from [No tests discovered detection](#no-tests-discovered-detection).
|
|
225
|
+
7. Save the new script. For Bash, `chmod +x` it.
|
|
226
|
+
8. **Update `config.yaml` to reference the new script.** Add or update the `conformance-tests-script:` key with the path to the newly created script (e.g., `conformance-tests-script: test_scripts/run_conformance_tests_<lang>.sh`). This is mandatory — the `codeplain` renderer needs this reference to invoke the conformance test script after rendering each functional spec.
|
|
227
|
+
9. **Link the script into the base `.plain` files as a linked resource.** Once the script exists on disk, it must be referenced from the project's base `.plain` module(s) — typically the one carrying `***test reqs***` for the conformance-testing strategy — so the renderer sees the script's contents as ground truth for the conformance contract. Use the `add-resource` skill to add a standard markdown link (e.g. `[conformance test runner](test_scripts/run_conformance_tests_<lang>.sh)`) inside the relevant section of the spec, with the path resolved relative to the `.plain` file. The script is a single text file, so it satisfies the linked-resource contract directly — do not link the `test_scripts/` directory, do not paraphrase the script into the spec, and do not duplicate its commands inline. If multiple base `.plain` modules reference the conformance contract (e.g. a host module and an integration module that inherits from it), link the script from each module that needs it; the linked resource lives next to the spec that owns the test req, not at the top of the chain by default. After linking, read the spec back to confirm the link path resolves to the script you just wrote. If this is the activate-only variant, link the matching `prepare_environment_<lang>` script next to it from the same spec — the two halves of the conformance contract belong together.
|
|
228
|
+
10. **For activate-only scripts only**: smoke-test by running `prepare_environment_<lang>.<sh|ps1> <build> && run_conformance_tests_<lang>.<sh|ps1> <build> <tests>`. If the conformance script errors with "prepared environment missing" right after a successful prepare, the two scripts disagree on either the working-folder path or the isolation location — fix that before declaring done.
|
|
229
|
+
|
|
230
|
+
## Anti-Patterns
|
|
231
|
+
|
|
232
|
+
- **(Hard mistake) Don't install into, build into, or otherwise write to the source build folder (`$1`) or the conformance tests folder (`$2`).** Both arguments are read-only input. Every install, cache, build artifact, log, JUnit XML, coverage report, compiled test class, and temp file must land in `.tmp/<lang>_<arg1>`. This includes never running `pip install`, `npm install`, `mvn install`, or `cargo build` with `$1` or `$2` as their `cwd` or target; never letting a venv / `node_modules` / `.m2` / `.gocache` / `.cargo` directory appear inside `$1` or `$2`; and never running the test command from inside either folder. The whole point of staging into `.tmp/` is so the build folder remains a clean artifact of the render and the conformance tests folder remains a clean tree under the user's version control — writing to either one corrupts those guarantees.
|
|
233
|
+
- **Don't emit the install-inline variant when a `prepare_environment_<lang>` script already exists.** The conformance script's `rm -rf .tmp/<lang>_$1` will wipe everything prepare did, and the inline install will redo it from scratch on every run. Always run the [Variant decision](#variant-decision-install-inline-vs-activate-only) check first.
|
|
234
|
+
- **Don't emit the activate-only variant when no prepare script exists.** The "verify prepared environment" check will fail on every run because nothing has populated the working folder.
|
|
235
|
+
- **Don't silently fall back from activate-only to install-inline** when the prepared environment is missing. Exit `69` with a clear error so the misconfiguration is visible. Silent fallback hides the real bug and produces inconsistent behavior between runs.
|
|
236
|
+
- **Don't copy the conformance tests folder into `.tmp/`.** Only the build folder is staged (and only in install-inline). The test folder is read in place from `$current_dir/$2`.
|
|
237
|
+
- **Don't compute the test path after `cd`.** Capture `current_dir` first; otherwise `$2` will be resolved relative to the working folder and silently miss the tests.
|
|
238
|
+
- **Don't skip the "no tests discovered" check.** A conformance suite that finds zero tests and exits `0` is the worst possible failure mode — it looks like success in CI.
|
|
239
|
+
- **Don't skip the toolchain check**, even when "everyone has it installed" — exit code `69` is what the calling system relies on to detect a missing runtime.
|
|
240
|
+
- **Don't reuse the source folder in place** (install-inline). Always copy into `.tmp/<lang>_<arg1>` first; the renderer relies on this isolation.
|
|
241
|
+
- **Don't change the exit-code contract.** Other parts of the system branch on `69` and `1` specifically — and these codes must be identical between the Bash and PowerShell variants.
|
|
242
|
+
- **Don't write a cross-shell hybrid** (e.g. a `.sh` that detects PowerShell, or vice versa). Ship one script per shell, named with the appropriate extension.
|
|
243
|
+
- **Don't install dependencies into the user's global location** (`~/.m2`, system-wide `pip`, `~/.cargo`, etc.) in the install-inline variant. Always isolate inside `$WORKING_FOLDER` so concurrent runs and other projects can't interfere.
|
|
244
|
+
- **Don't run the test command without first verifying the install / activation succeeded.** A failed install (or missing prepared env) followed by a "test" run produces misleading errors that look like test failures.
|
|
245
|
+
- **Don't forget to update `config.yaml`.** After creating the conformance test script, always add or update the `conformance-tests-script:` key in `config.yaml` to reference the new script. Without this entry, the `codeplain` renderer won't know where to find the conformance test script.
|
|
246
|
+
- **Don't forget to link the script as a resource in the base `.plain` files.** A script that is referenced only from `config.yaml` is invisible to the spec contract — the renderer treats `conformance-tests-script:` as a build-system pointer, not as part of the test-req contract the model reads. Use the `add-resource` skill to add a markdown link to the script from the `.plain` module that owns the conformance test reqs (see Workflow step 9). Omitting the linked resource means the model authors and reviews conformance-test code without ever seeing the actual runner it has to satisfy — and for activate-only scripts, the model also loses sight of which isolation paths must already be in place by the time tests run.
|
|
247
|
+
- **Don't write a terse script.** Silent steps, `>/dev/null` redirects on the install / activation output, missing `--version` prints, absent variant banners, an un-logged `current_dir`, and a missing final summary all make the script harder to debug than the tests it is running. Follow the *Logging — be as verbose as possible* rule under [Conventions](#conventions) literally: every step announces itself, every command is echoed, the variant is named in its banner, `current_dir` and the resolved `$2` are printed, every failure prints what was about to run and where, and the final summary names the variant, test command, exit code, and working folder.
|
package/forge/skills/implement-conformance-testing-script/assets/run_conformance_tests_cypress.ps1
ADDED
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
#!/usr/bin/env pwsh
|
|
2
|
+
|
|
3
|
+
$ErrorActionPreference = 'Stop'
|
|
4
|
+
|
|
5
|
+
$UNRECOVERABLE_ERROR_EXIT_CODE = 69
|
|
6
|
+
|
|
7
|
+
$NPM_INSTALL_OUTPUT_FILTER = "up to date in|added [0-9]* packages, removed [0-9]* packages, and changed [0-9]* packages in|removed [0-9]* packages, and changed [0-9]* packages in|added [0-9]* packages in|removed [0-9]* packages in"
|
|
8
|
+
|
|
9
|
+
# Function to check and kill any Node process running on port 3000 (React development server)
|
|
10
|
+
function Check-AndKillNodeServer {
|
|
11
|
+
try {
|
|
12
|
+
$connections = Get-NetTCPConnection -LocalPort 3000 -ErrorAction SilentlyContinue
|
|
13
|
+
if ($connections) {
|
|
14
|
+
foreach ($conn in $connections) {
|
|
15
|
+
$proc = Get-Process -Id $conn.OwningProcess -ErrorAction SilentlyContinue
|
|
16
|
+
if ($proc -and $proc.ProcessName -eq "node") {
|
|
17
|
+
Write-Host "Found Node server running on port 3000. Killing it..."
|
|
18
|
+
Stop-Process -Id $proc.Id -Force -ErrorAction SilentlyContinue
|
|
19
|
+
Start-Sleep -Seconds 1
|
|
20
|
+
if ($env:VERBOSE -eq "1") {
|
|
21
|
+
Write-Host "Node server terminated."
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
} catch {
|
|
27
|
+
# Silently ignore errors (port may not be in use)
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
# Function to get all child processes of a given PID recursively
|
|
32
|
+
function Get-ChildProcesses {
|
|
33
|
+
param([int]$ParentPid)
|
|
34
|
+
|
|
35
|
+
$children = Get-CimInstance Win32_Process -Filter "ParentProcessId = $ParentPid" -ErrorAction SilentlyContinue
|
|
36
|
+
$result = @()
|
|
37
|
+
foreach ($child in $children) {
|
|
38
|
+
$result += $child.ProcessId
|
|
39
|
+
$result += Get-ChildProcesses -ParentPid $child.ProcessId
|
|
40
|
+
}
|
|
41
|
+
return $result
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
# Cleanup function to ensure all processes are terminated
|
|
45
|
+
function Cleanup {
|
|
46
|
+
# Kill any running npm processes started by this script
|
|
47
|
+
if ($script:NPM_PID) {
|
|
48
|
+
Stop-Process -Id $script:NPM_PID -Force -ErrorAction SilentlyContinue
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
# Kill React app and its children if they exist
|
|
52
|
+
if ($script:REACT_APP_PID) {
|
|
53
|
+
$processesToKill = Get-ChildProcesses -ParentPid $script:REACT_APP_PID
|
|
54
|
+
|
|
55
|
+
# Kill the main process
|
|
56
|
+
Stop-Process -Id $script:REACT_APP_PID -Force -ErrorAction SilentlyContinue
|
|
57
|
+
|
|
58
|
+
# Kill all the subprocesses
|
|
59
|
+
foreach ($pid in $processesToKill) {
|
|
60
|
+
Stop-Process -Id $pid -Force -ErrorAction SilentlyContinue
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if ($env:VERBOSE -eq "1") {
|
|
64
|
+
Write-Host "React app is terminated!"
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
# Remove temporary files if they exist
|
|
69
|
+
if ($script:build_output -and (Test-Path $script:build_output)) {
|
|
70
|
+
Remove-Item $script:build_output -Force -ErrorAction SilentlyContinue
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
# Check for and kill any existing Node server from previous runs
|
|
75
|
+
Check-AndKillNodeServer
|
|
76
|
+
|
|
77
|
+
# Check if build folder name is provided
|
|
78
|
+
if (-not $args[0]) {
|
|
79
|
+
Write-Host "Error: No build folder name provided."
|
|
80
|
+
Write-Host "Usage: $($MyInvocation.MyCommand.Name) <build_folder_name> <conformance_tests_folder>"
|
|
81
|
+
exit $UNRECOVERABLE_ERROR_EXIT_CODE
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
# Check if conformance tests folder name is provided
|
|
85
|
+
if (-not $args[1]) {
|
|
86
|
+
Write-Host "Error: No conformance tests folder name provided."
|
|
87
|
+
Write-Host "Usage: $($MyInvocation.MyCommand.Name) <build_folder_name> <conformance_tests_folder>"
|
|
88
|
+
exit $UNRECOVERABLE_ERROR_EXIT_CODE
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
$BuildFolder = $args[0]
|
|
92
|
+
$ConformanceTestsFolder = $args[1]
|
|
93
|
+
|
|
94
|
+
if ($args[2] -eq "-v" -or $args[2] -eq "--verbose") {
|
|
95
|
+
$env:VERBOSE = "1"
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
$current_dir = Get-Location
|
|
99
|
+
|
|
100
|
+
try {
|
|
101
|
+
# Define the path to the subfolder
|
|
102
|
+
$NODE_SUBFOLDER = "node_$BuildFolder"
|
|
103
|
+
|
|
104
|
+
# Running React application
|
|
105
|
+
Write-Host "### Step 1: Starting the React application in folder $NODE_SUBFOLDER..."
|
|
106
|
+
|
|
107
|
+
if ($env:VERBOSE -eq "1") {
|
|
108
|
+
Write-Host "Preparing Node subfolder: $NODE_SUBFOLDER"
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
# Check if the node subfolder exists
|
|
112
|
+
if (Test-Path $NODE_SUBFOLDER) {
|
|
113
|
+
# Delete all files and folders except "node_modules", "plain_modules", and "package-lock.json"
|
|
114
|
+
Get-ChildItem -Path $NODE_SUBFOLDER -Force |
|
|
115
|
+
Where-Object {
|
|
116
|
+
$_.Name -ne "node_modules" -and
|
|
117
|
+
$_.Name -ne "plain_modules" -and
|
|
118
|
+
$_.Name -ne "package-lock.json"
|
|
119
|
+
} | Remove-Item -Recurse -Force
|
|
120
|
+
|
|
121
|
+
if ($env:VERBOSE -eq "1") {
|
|
122
|
+
Write-Host "Cleanup completed, keeping 'node_modules' and 'package-lock.json'."
|
|
123
|
+
}
|
|
124
|
+
} else {
|
|
125
|
+
if ($env:VERBOSE -eq "1") {
|
|
126
|
+
Write-Host "Subfolder does not exist. Creating it..."
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
New-Item -ItemType Directory -Path $NODE_SUBFOLDER -Force | Out-Null
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
Copy-Item -Path "$BuildFolder/*" -Destination $NODE_SUBFOLDER -Recurse -Force
|
|
133
|
+
|
|
134
|
+
# Move to the subfolder
|
|
135
|
+
if (-not (Test-Path $NODE_SUBFOLDER)) {
|
|
136
|
+
Write-Host "Error: Node build folder '$NODE_SUBFOLDER' does not exist."
|
|
137
|
+
exit $UNRECOVERABLE_ERROR_EXIT_CODE
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
Push-Location $NODE_SUBFOLDER
|
|
141
|
+
|
|
142
|
+
# Temporarily allow stderr output without throwing (npm may write warnings to stderr)
|
|
143
|
+
# ForEach-Object converts ErrorRecord objects (from stderr) to plain strings to avoid verbose error formatting
|
|
144
|
+
$ErrorActionPreference = 'Continue'
|
|
145
|
+
$npmInstallOutput = npm install --prefer-offline --no-audit --no-fund --loglevel error 2>&1 | ForEach-Object { if ($_ -is [System.Management.Automation.ErrorRecord]) { $_.Exception.Message } else { $_ } } | Out-String
|
|
146
|
+
$ErrorActionPreference = 'Stop'
|
|
147
|
+
# Filter out noisy npm install lines
|
|
148
|
+
$npmInstallOutput -split "`n" | Where-Object { $_ -notmatch $NPM_INSTALL_OUTPUT_FILTER } | ForEach-Object {
|
|
149
|
+
if ($_.Trim()) { Write-Host $_ }
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if ($LASTEXITCODE -ne 0) {
|
|
153
|
+
Write-Host "Error: Installing Node modules."
|
|
154
|
+
exit 2
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
if ($env:VERBOSE -eq "1") {
|
|
158
|
+
Write-Host "Building the application..."
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
$script:build_output = [System.IO.Path]::GetTempFileName()
|
|
162
|
+
|
|
163
|
+
# Temporarily allow stderr output without throwing (build tools may write to stderr)
|
|
164
|
+
$ErrorActionPreference = 'Continue'
|
|
165
|
+
npm run build > $script:build_output 2>&1
|
|
166
|
+
$ErrorActionPreference = 'Stop'
|
|
167
|
+
|
|
168
|
+
if ($LASTEXITCODE -ne 0) {
|
|
169
|
+
Write-Host "Error: Building application."
|
|
170
|
+
Get-Content $script:build_output
|
|
171
|
+
Remove-Item $script:build_output -Force -ErrorAction SilentlyContinue
|
|
172
|
+
exit 2
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
Remove-Item $script:build_output -Force -ErrorAction SilentlyContinue
|
|
176
|
+
|
|
177
|
+
if ($env:VERBOSE -eq "1") {
|
|
178
|
+
Write-Host "Starting the application..."
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
# Start the React app in the background and redirect output to a log file
|
|
182
|
+
$env:BROWSER = "none"
|
|
183
|
+
$reactProcess = Start-Process -FilePath "npm" -ArgumentList "start", "--", "--no-open" `
|
|
184
|
+
-NoNewWindow -PassThru -RedirectStandardOutput "app.log" -RedirectStandardError "app_err.log"
|
|
185
|
+
|
|
186
|
+
if ($env:VERBOSE -eq "1") {
|
|
187
|
+
Write-Host "Application is starting..."
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
# Capture the process ID
|
|
191
|
+
$script:REACT_APP_PID = $reactProcess.Id
|
|
192
|
+
|
|
193
|
+
# Try to find the child npm process
|
|
194
|
+
Start-Sleep -Milliseconds 500
|
|
195
|
+
$npmChild = Get-CimInstance Win32_Process -Filter "ParentProcessId = $($script:REACT_APP_PID)" -ErrorAction SilentlyContinue |
|
|
196
|
+
Where-Object { $_.Name -match "npm" } | Select-Object -First 1
|
|
197
|
+
if ($npmChild) {
|
|
198
|
+
$script:NPM_PID = $npmChild.ProcessId
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
# Wait for the "compiled successfully!" or Vite ready message in the log file
|
|
202
|
+
while ($true) {
|
|
203
|
+
if (Test-Path "app.log") {
|
|
204
|
+
$logContent = Get-Content "app.log" -Raw -ErrorAction SilentlyContinue
|
|
205
|
+
if ($logContent) {
|
|
206
|
+
if ($logContent -match "(?i)compiled successfully|compiled with warnings") {
|
|
207
|
+
break
|
|
208
|
+
}
|
|
209
|
+
if ($logContent -match "(?i)VITE v[0-9]+\.[0-9]+\.[0-9]+\s+ready in") {
|
|
210
|
+
break
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
# Also check if localhost:3000 responds
|
|
216
|
+
try {
|
|
217
|
+
$response = Invoke-WebRequest -Uri "http://localhost:3000" -UseBasicParsing -TimeoutSec 1 -ErrorAction SilentlyContinue
|
|
218
|
+
if ($response) { break }
|
|
219
|
+
} catch {
|
|
220
|
+
# Not ready yet
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
# Check if the React app process is still running
|
|
224
|
+
$proc = Get-Process -Id $script:REACT_APP_PID -ErrorAction SilentlyContinue
|
|
225
|
+
if (-not $proc -or $proc.HasExited) {
|
|
226
|
+
Write-Host "Error in :ImplementationCode: (React app process (PID: $($script:REACT_APP_PID)) has terminated unexpectedly)."
|
|
227
|
+
if (Test-Path "app.log") { Get-Content "app.log" }
|
|
228
|
+
if (Test-Path "app_err.log") { Get-Content "app_err.log" }
|
|
229
|
+
exit 2
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
Start-Sleep -Milliseconds 100
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
# At this point, the React app is up and running in the background
|
|
236
|
+
if ($env:VERBOSE -eq "1") {
|
|
237
|
+
Write-Host "React app is up and running!"
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
Pop-Location
|
|
241
|
+
|
|
242
|
+
# Execute all Cypress conformance tests in the build folder
|
|
243
|
+
Write-Host "### Step 2: Running Cypress conformance tests $ConformanceTestsFolder..."
|
|
244
|
+
|
|
245
|
+
# Move back to the original directory
|
|
246
|
+
Set-Location $current_dir
|
|
247
|
+
|
|
248
|
+
# Define the path to the conformance tests subfolder
|
|
249
|
+
$NODE_CONFORMANCE_TESTS_SUBFOLDER = "node_$ConformanceTestsFolder"
|
|
250
|
+
|
|
251
|
+
if ($env:VERBOSE -eq "1") {
|
|
252
|
+
Write-Host "Preparing conformance tests Node subfolder: $NODE_CONFORMANCE_TESTS_SUBFOLDER"
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
# Check if the conformance tests node subfolder exists
|
|
256
|
+
if (Test-Path $NODE_CONFORMANCE_TESTS_SUBFOLDER) {
|
|
257
|
+
# Delete all files and folders except "node_modules", "plain_modules", and "package-lock.json"
|
|
258
|
+
Get-ChildItem -Path $NODE_CONFORMANCE_TESTS_SUBFOLDER -Force |
|
|
259
|
+
Where-Object {
|
|
260
|
+
$_.Name -ne "node_modules" -and
|
|
261
|
+
$_.Name -ne "plain_modules" -and
|
|
262
|
+
$_.Name -ne "package-lock.json"
|
|
263
|
+
} | Remove-Item -Recurse -Force
|
|
264
|
+
|
|
265
|
+
if ($env:VERBOSE -eq "1") {
|
|
266
|
+
Write-Host "Cleanup completed, keeping 'node_modules' and 'package-lock.json'."
|
|
267
|
+
}
|
|
268
|
+
} else {
|
|
269
|
+
if ($env:VERBOSE -eq "1") {
|
|
270
|
+
Write-Host "Subfolder does not exist. Creating it..."
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
New-Item -ItemType Directory -Path $NODE_CONFORMANCE_TESTS_SUBFOLDER -Force | Out-Null
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
Copy-Item -Path "$ConformanceTestsFolder/*" -Destination $NODE_CONFORMANCE_TESTS_SUBFOLDER -Recurse -Force
|
|
277
|
+
|
|
278
|
+
# Move to the subfolder with Cypress tests
|
|
279
|
+
if (-not (Test-Path $NODE_CONFORMANCE_TESTS_SUBFOLDER)) {
|
|
280
|
+
Write-Host "Error: conformance tests Node folder '$NODE_CONFORMANCE_TESTS_SUBFOLDER' does not exist."
|
|
281
|
+
exit $UNRECOVERABLE_ERROR_EXIT_CODE
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
Push-Location $NODE_CONFORMANCE_TESTS_SUBFOLDER
|
|
285
|
+
|
|
286
|
+
# Temporarily allow stderr output without throwing (npm may write warnings to stderr)
|
|
287
|
+
# ForEach-Object converts ErrorRecord objects (from stderr) to plain strings to avoid verbose error formatting
|
|
288
|
+
$ErrorActionPreference = 'Continue'
|
|
289
|
+
$npmInstallOutput = npm install cypress --save-dev --prefer-offline --no-audit --no-fund --loglevel error 2>&1 | ForEach-Object { if ($_ -is [System.Management.Automation.ErrorRecord]) { $_.Exception.Message } else { $_ } } | Out-String
|
|
290
|
+
$ErrorActionPreference = 'Stop'
|
|
291
|
+
$npmInstallOutput -split "`n" | Where-Object { $_ -notmatch $NPM_INSTALL_OUTPUT_FILTER } | ForEach-Object {
|
|
292
|
+
if ($_.Trim()) { Write-Host $_ }
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
if ($env:VERBOSE -eq "1") {
|
|
296
|
+
Write-Host "Running Cypress conformance tests..."
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
$ErrorActionPreference = 'Continue'
|
|
300
|
+
$cypress_info_output = npx cypress info 2>&1 | ForEach-Object { if ($_ -is [System.Management.Automation.ErrorRecord]) { $_.Exception.Message } else { $_ } } | Out-String
|
|
301
|
+
$ErrorActionPreference = 'Stop'
|
|
302
|
+
$CYPRESS_BROWSER_FLAG = ""
|
|
303
|
+
if ($cypress_info_output -match "(?i)chrome") {
|
|
304
|
+
$CYPRESS_BROWSER_FLAG = "--browser=chrome"
|
|
305
|
+
}
|
|
306
|
+
Write-Host "CYPRESS_BROWSER_FLAG: $(if ($CYPRESS_BROWSER_FLAG) { $CYPRESS_BROWSER_FLAG } else { 'none' })"
|
|
307
|
+
|
|
308
|
+
$env:BROWSERSLIST_IGNORE_OLD_DATA = "1"
|
|
309
|
+
if ($CYPRESS_BROWSER_FLAG) {
|
|
310
|
+
npx cypress run $CYPRESS_BROWSER_FLAG --config video=false 2>$null
|
|
311
|
+
} else {
|
|
312
|
+
npx cypress run --config video=false 2>$null
|
|
313
|
+
}
|
|
314
|
+
$cypress_run_result = $LASTEXITCODE
|
|
315
|
+
|
|
316
|
+
if ($cypress_run_result -ne 0) {
|
|
317
|
+
if ($env:VERBOSE -eq "1") {
|
|
318
|
+
Write-Host "Error: Cypress conformance tests have failed."
|
|
319
|
+
}
|
|
320
|
+
exit 1
|
|
321
|
+
}
|
|
322
|
+
} finally {
|
|
323
|
+
Cleanup
|
|
324
|
+
}
|