Skip to content

Scripts UI

perfshop-scripts-ui is the web workshop for pedagogical test scripts. It combines a Git file editor wired to Forgejo, a test launcher that runs scripts in perfshop-test-runner through docker exec, and a run history UI with all of their artifacts.

Its role differs from perfshop-jmeter-ui:

  • JMeter UI drives load shots (.jmx → JMeter in another container).
  • Scripts UI drives functional tests (.robot and .py scripts → Robot Framework / pytest in perfshop-test-runner), and additionally manages direct editing of the files versioned in Forgejo.

The architecture is very close to JMeter UI (same Node/Express foundation, same "exec in another container, through the Docker relay" pattern), with two extra specifics: Forgejo integration through its REST API and structured persistence of runs as artifacts.

Source of truth

This page is drawn from the perfshop-scripts-ui block of the compose files, the Dockerfile in scripts-ui/, and the 9 modules in scripts-ui/src/ (server.js, config.js, i18n.js, validation.js, docker.js, security.js, auth.js, forgejo.js, runs.js).

Overall architecture

flowchart TB
  subgraph browser["Browser"]
    UI["Scripts UI<br/>http://localhost:3008"]
  end

  subgraph sui["perfshop-scripts-ui<br/>(Node 20 + Express, port 3008)"]
    direction TB
    SRV["server.js<br/>(orchestration)"]
    AU["auth.js<br/>(8h session + CSRF + rate limit)"]
    FG["forgejo.js<br/>(Forgejo API, tree, CRUD)"]
    RN["runs.js<br/>(launch + artifacts)"]
    DK["docker.js<br/>(Docker API, relay socket)"]
    VA["validation.js<br/>(path sanitization)"]

    SRV --> AU
    SRV --> FG
    SRV --> RN
    RN --> DK
    FG --> VA
  end

  subgraph fg["perfshop-forgejo<br/>(self-hosted Git, port 3009)"]
    REPO["perfshop-tests repository<br/>(Robot Framework tests<br/>+ pytest)"]
  end

  subgraph tr["perfshop-test-runner<br/>(Python 3.11 + RF 7.0 + pytest)"]
    SH["SSH entrypoint"]
    RUNNER["exec robot|pytest"]
  end

  subgraph sel["perfshop-selenium"]
    CHROME["standalone-chrome<br/>:4444"]
  end

  subgraph vols["Docker volumes"]
    FTD[/"forgejo-token-data:/token<br/>(RO - Forgejo token)"/]
    LOGS[/"./test-runner/logs → /rf-logs<br/>(shared persistent runs)"/]
  end

  DOCK[/"perfshop-docker-relay<br/>/run/docker-relay/docker.sock"/]

  UI -->|HTTPS| SRV
  FG -->|REST API v1| fg
  DK -->|talks to the relay| DOCK
  DOCK -.->|docker exec perfshop-test-runner<br/>robot ... / python -m pytest ...| RUNNER
  RUNNER -->|WebDriver| CHROME
  RUNNER -->|writes logs + artifacts| LOGS
  SRV -->|reads /token/forgejo_token| FTD
  SRV -->|reads past runs| LOGS

Three key communication chains:

  1. Scripts UI → Forgejo — through HTTP REST (/api/v1 API) using the token stored in /token/forgejo_token (a volume shared with the Forgejo seed).
  2. Scripts UI → Test Runner — through the equivalent of docker exec, by way of the perfshop-docker-relay relay, to launch robot or python -m pytest commands. Scripts UI does not mount the daemon socket: the relay grants it only the state of perfshop-test-runner and commands in that container (see Docker socket: the relay).
  3. Test Runner → Scripts UI — through the shared bind mount ./test-runner/logs → /rf-logs, which lets the UI read logs and artifacts produced by runs.

Docker Compose configuration

Key Value
Build ./scripts-ui (local Dockerfile)
container_name perfshop-scripts-ui
Exposed port 3008 (host) → 3008 (container), variable SCRIPTS_UI_PORT
Network perfshop-network

Bind mounts

Bind mount Mount point Mode Role
docker-relay-scripts-ui (named volume) /run/docker-relay RO Docker relay socket, for the equivalent of docker exec perfshop-test-runner — and nothing else
forgejo-token-data (named volume) /token RO Forgejo token generated by perfshop-forgejo-seed, shared through a named volume
./test-runner/logs /rf-logs RW Volume shared with perfshop-test-runner — reading logs + writing persistent runs

Token sharing through a named volume

The Forgejo token is created by perfshop-forgejo-seed at first startup and written into /token/forgejo_token inside a Docker named volume (forgejo-token-data). This volume is then mounted read-only into perfshop-scripts-ui. This pattern avoids passing the token through an environment variable (visible in docker inspect). At later startups, the seed reuses the token as long as it opens the perfshop-tests repository; it recreates it if the volume was recreated or if the token was revoked in Forgejo (Scripts UI reads the file again when it changes).

Environment variables

Variable Default Role
PORT 3008 HTTP port of the Express server
PUBLIC_SCRIPTS_URL http://localhost:3008 Exposed public URL
PUBLIC_FORGEJO_URL http://localhost:3009 Forgejo URL exposed in the UI (navigation links)
FORGEJO_INTERNAL_URL http://perfshop-forgejo:3000 Internal URL for server-side API calls
FORGEJO_CI_USER perfshop-ci Name of the Forgejo CI account used for automatic commits
FORGEJO_REPO perfshop-tests Target repository name
FORGEJO_TOKEN_FILE /token/forgejo_token Path of the file holding the token
PERFSHOP_API_INTERNAL http://perfshop-app:8080 Internal PerfShop backend URL (used by some tests)
TEST_RUNNER_CONTAINER perfshop-test-runner Name of the target container for docker exec — the relay grants that name only: changing it means changing docker-relay/src/policy.js too
DOCKER_SOCKET /run/docker-relay/docker.sock (compose files) Docker API socket: the relay's. Without the variable, the code falls back to /var/run/docker.sock, which the service no longer mounts
PERFSHOP_FRONTEND_URL / _INTERNAL — Public and internal frontend URLs (passed to the scripts through their environment)
SELENIUM_REMOTE_URL http://perfshop-selenium:4444/wd/hub Selenium hub URL to use in tests
RUNS_DIR /rf-logs/runs Directory of the runs (one sub-directory per run: reports, screenshots, meta.json, output.txt)
RUNNER_RUNS_DIR value of RUNS_DIR The same directory as seen from perfshop-test-runner (both mount ./test-runner/logs on /rf-logs)
RUNS_RETENTION_DAYS 30 Retention of the runs on disk: a run older than N days is deleted (at startup, then every hour); 0 = never by age (see "Run retention")
RUNS_RETENTION_MAX_MB 2048 Cap of the runs directory, in MB: beyond it, the oldest runs are deleted until it is back under the cap; 0 = no cap
PERFSHOP_TRAINING_DIR — (empty) Folder of the technical accounts volume (training-secret, read-only): the secret and the account list are re-read at every run; empty = no identity handed to the scripts (see "Training identity of a run")
MAX_CONCURRENT_RUNS 3 Maximum number of concurrent runs
TREE_MAX_DEPTH 4 Maximum depth of the displayed Forgejo tree (safety against malformed repos)
SESSION_SECRET perfshop-dev-secret (dev) Cookie signing secret — fail-fast in NODE_ENV=production if left at default
SESSION_COOKIE_SECURE / _SAME_SITE false / lax Cookie policy (HTTP / HTTPS)
PERFSHOP_LANG fr UI language

The 9 modules in src/

Module Lines Role
server.js 81 Express orchestration, session, middlewares, route mounting, window.__CONFIG__ injection
config.js 49 Reads environment variables and exports PUBLIC_CONFIG
i18n.js 51 Loads translation bundles from public/i18n/{fr,en}.json
validation.js 33 Path sanitization (protection against ../ and dangerous characters)
docker.js 123 Low-level Docker API client through the Unix socket
security.js 64 csrfProtection and rateLimit middlewares
auth.js 68 Login/logout/status + requireAuth middleware
forgejo.js 312 Complete wrapper of the Forgejo REST API (tree, file CRUD, commits, sync)
runs.js 384 Run launching, status (report counters), per-run directory and artifacts, read link of the reports, concurrency limit

Key utility — validation.js

The entire security of file operations rests on a single function: the strict validation of relative paths supplied by the client. No write operation is performed without passing through this filter, which rejects:

  • Absolute paths starting with /
  • .. or ../ sequences
  • Control characters and shell special characters
  • Paths deeper than TREE_MAX_DEPTH (4 levels)

This function is called by forgejo.js before any Forgejo API call, and by runs.js before any docker exec command.

Forgejo integration — the forgejo.js module

The forgejo.js module is a complete wrapper of the Forgejo v1 API that exposes to the browser a set of REST routes modeled on usual Git operations. Internally, it translates each call into a Bearer <token> HTTP request toward FORGEJO_INTERNAL_URL/api/v1.

Exposed routes

Method Route Forgejo operation
GET /api/tree GET /repos/{owner}/{repo}/git/trees/main?recursive=true then hierarchical reconstruction
GET /api/file?path=... GET /repos/{owner}/{repo}/contents/{path} (base64 decoding)
GET /api/download?path=... Download of the raw content
PUT /api/file PUT /repos/{owner}/{repo}/contents/{path} (create or update)
POST /api/upload Multipart upload (through multer) then Forgejo PUT
DELETE /api/file (body: path, sha) DELETE /repos/{owner}/{repo}/contents/{path}
POST /api/mkdir Creation of a .gitkeep file in a new folder
POST /api/move Rename or move (= delete + create on the Forgejo side)
GET /api/commits GET /repos/{owner}/{repo}/commits
POST /api/sync git pull on the perfshop-test-runner side through docker exec

Commit author (classroom platform)

Every write goes through the same technical account of Forgejo (its token). Since 2026-10-20, each also sends the account of the session as the commit author (author field of the Forgejo contents API: publish, upload, delete, new folder, and both halves of a move); Forgejo 14 then writes it as author AND committer (measured on 2026-10-20: the technical account no longer appears in the commit, the write still goes through its token). The history (/api/commits, or Forgejo itself) therefore tells who published, moved or deleted each file. A session without a valid e-mail writes as before, under the technical account. This is not a protection: any account with the Scripts right writes anywhere in the repository, another student's folder included — the rule "one folder per student, named with their initials" stays an instruction of the practical works (PO decision, TPS board §2-B no. 40 (e)).

HTTP authentication to Forgejo

The token is read once at startup from /token/forgejo_token. If the file is missing or empty, the module logs a warning but keeps going (Forgejo routes will then return 500 on every call — a deliberate silent degradation so that the UI can still start in a degraded state).

sequenceDiagram
  autonumber
  participant UI as Browser
  participant SRV as scripts-ui (Node)
  participant FGS as perfshop-forgejo-seed
  participant FTD as forgejo-token-data volume
  participant FG as perfshop-forgejo

  Note over FGS,FTD: At first startup (one-shot)
  FGS->>FG: POST /users/admin<br/>(CI account)
  FGS->>FG: POST /users/{ci}/tokens<br/>(API token generation)
  FG-->>FGS: token
  FGS->>FTD: writes /token/forgejo_token

  Note over SRV,FTD: At scripts-ui startup
  SRV->>FTD: fs.readFileSync('/token/forgejo_token')
  FTD-->>SRV: token (in memory, module variable)

  Note over UI,FG: Normal operation
  UI->>SRV: GET /api/tree
  SRV->>FG: GET /api/v1/repos/perfshop-ci/perfshop-tests/git/trees/main<br/>Authorization: Bearer <token>
  FG-->>SRV: JSON tree
  SRV-->>UI: reformatted tree

Running tests — the runs.js module

The runs.js module (and its pure modules src/lib/run-*.js) implements a mini execution engine:

  • a concurrency limit (MAX_CONCURRENT_RUNS = 3) so as not to saturate perfshop-test-runner (HTTP 429 beyond);
  • a unique identifier per run (run-<ms>-<8 random hexadecimal characters>);
  • one directory per run: Robot writes output.xml, log.html, report.html and its screenshots into RUNS_DIR/<runId>/ (pytest: pytest.xml) — two students launching the same script no longer overwrite each other;
  • a status that tells the truth: passed, skipped (the script ended without executing any test: all skipped — yet Robot and pytest exit with 0), failed, error (the infrastructure could not run the test); the passed / failed / skipped counters are read from the report (output.xml or pytest.xml) and shown with the result;
  • live output while running, by polling /api/run/:runId (1.5 s).

Exposed routes

Method Route Role
POST /api/run Launches a script (Robot Framework or pytest) in perfshop-test-runner
GET /api/run/:runId Live state of the run (output, status, counters)
GET /api/runs The last 50 finished runs (directories of RUNS_DIR that have a meta.json)
GET /api/runs/:id Detail of a run: meta.json, output, and a signed read link (viewToken)
GET /api/runs/:id/artifact?name=... One artifact: log.html, report.html, output.xml, pytest.xml or a *.png screenshot (&download=1: download)
GET /api/runs/:id/<name> The same artifact addressed by path (a relative link of a report opened in the tab)
GET /api/runs/:id/view/<token>/<name> Read link of the HTML reports and their screenshots, authorised by the token (see below)
GET /api/runner-status Public — state of the perfshop-test-runner container (UP/DOWN)

Flow of a Robot Framework run launch

sequenceDiagram
  autonumber
  actor S as Student
  participant UI as Browser
  participant SRV as scripts-ui
  participant DK as Docker relay
  participant TR as perfshop-test-runner
  participant FS as RUNS_DIR/{runId}

  S->>UI: Selects CT-011-parcours-metier-ui.robot<br/>clicks "Run"
  UI->>SRV: POST /api/run {filepath}
  SRV->>SRV: Path validation (validation.js), runId
  SRV->>DK: exec robot --outputdir RUNS_DIR/{runId}<br/>--output output.xml --log log.html --report report.html<br/>/scripts/CT-011-parcours-metier-ui.robot
  DK->>TR: exec (PERFSHOP_FRONTEND_URL, SELENIUM_REMOTE_URL…)
  TR->>FS: output.xml, log.html, report.html, *.png screenshots

  loop Polling every 1.5 s
    UI->>SRV: GET /api/run/{runId}
    SRV-->>UI: {status: "running", output: "…"}
  end

  TR-->>DK: exit code
  SRV->>FS: reads the counters of output.xml → passed / skipped / failed / error
  SRV->>FS: writes output.txt and meta.json
  UI->>SRV: GET /api/runs/{runId}
  SRV-->>UI: {status, stats, artifacts, viewToken}
  S->>UI: Clicks "📊 Log"
  UI->>SRV: GET /api/runs/{runId}/view/{token}/log.html
  SRV-->>UI: log.html in a CSP sandbox — its screenshots load under the same link

Directory of a run

RUNS_DIR/                          (default /rf-logs/runs)
└── run-1790709517794-92cdc041/
    ├── meta.json      ← script, startedAt, endedAt, status, rc, stats {pass, fail, skip}, artifacts, trainingUser
    ├── output.txt     ← full output of the run
    ├── output.xml     ← Robot Framework (pytest: pytest.xml)
    ├── log.html
    ├── report.html
    └── T01_homepage.png …   ← screenshots (Capture Page Screenshot)

The runner writes directly into this directory: both containers mount the same ./test-runner/logs on /rf-logs. If the runner sees this directory elsewhere, RUNNER_RUNS_DIR gives its path on the runner side.

Run retention

A run is the trace of a student's work (evidence of a session, a disputed grade): it is kept 30 days, not one week, to cover grading done after the submission date. The disk, however, is bounded: 2 GB for the whole directory. The rule (src/lib/runs-retention.js) is applied when Scripts UI starts, then every hour:

  1. a run older than RUNS_RETENTION_DAYS days (default 30) is deleted;
  2. if the directory still exceeds RUNS_RETENTION_MAX_MB MB (default 2048), the oldest runs are deleted until it is back under the cap;
  3. a run in progress is never deleted; a deleted run also disappears from the Runs tab.

The age of a run is read from its identifier (run-<ms>-<hex>, assigned by Scripts UI), not from the directory date, which a student's code can change. The directory is written by the students' code: it is treated as hostile — only real directories with a run name are candidates, no link is ever followed, and the size is not measured beyond 8 levels of sub-directories. A disk error is logged and never stops the service.

Every purge is logged:

[runs/retention] règle : 30 jours, 2048 Mo (RUNS_RETENTION_DAYS, RUNS_RETENTION_MAX_MB ; 0 = désactivé)
[runs/retention] 29 run(s) supprimé(s), 14.1 Mo, plus ancien du 2026-07-24T07:36:14.474Z — règle : 30 jours, 2048 Mo ; 43 conservé(s)

Export the evidence before the deadline

A run to be kept beyond 30 days (disputed grade, exam file) must be copied out of test-runner/logs/runs/ before the deadline. When upgrading to a version that applies the retention, runs older than 30 days are deleted at the first start: archive the directory first, for example tar -czf runs-before-retention.tar.gz -C test-runner/logs runs.

A Robot Framework report is rendered by inline scripts: the service's security policy (script-src 'self') would block them ("Opening Robot Framework log failed"). It is also partly written by the student's script (Log … html=True). HTML reports are therefore served in a sandbox (Content-Security-Policy: sandbox allow-scripts …, without allow-same-origin): their scripts run in an opaque origin, with no access to the session, to the service's other windows or to the API.

In that sandbox the browser sends no cookie with the images of a report. The "📊 Log" link therefore opens the report through a read link /api/runs/<id>/view/<token>/log.html: the token is signed (HMAC, random per-process secret), is valid for that run only, expires after 2 h and changes on every restart of the service (reopening the run from the Runs tab gives a new one). The screenshots, named relatively in the report, load under that same link.

/rf-logs is mounted read-write in the runner, where students' code runs: Scripts UI only reads and serves regular files there (a planted symbolic link is never followed), writes its own files through an exclusive temporary file then a rename, and only serves known names (log.html, report.html, output.xml, result.xml, pytest.xml) or single-segment *.png screenshots.

Training identity of a run (technical accounts)

A script that logs in to the shop contains no password: it reads its identity from its environment (Robot Framework guide, "Credentials in a script").

Variable given to the script Content
PERFSHOP_TRAINING_USER technical account assigned to this run (ci-1@perfshop.com … ci-3@perfshop.com)
PERFSHOP_TRAINING_PASSWORD shared secret of the technical accounts
PERFSHOP_TRAINING_EMPTY_USER ci-empty@perfshop.com, an account that never orders ("no order" state)
  • One account per simultaneous run: the cart, the order history, the loyalty discount and the double-click protection belong to the logged-in account; two runs on the same account would interfere (one empties the other's cart). Each run gets the first free account (3 accounts for at most 3 simultaneous runs); when none is free, the launch is refused ("Every technical account is taken…"), never shared. The account used is recorded in meta.json (trainingUser).
  • Origin: perfshop-app creates these accounts at every start (complete, valid profile) and generates the secret at its first start (256 bits) in the training-secret volume — files password (mode 600) and accounts.json —, mounted read-only in Scripts UI (PERFSHOP_TRAINING_DIR) and in the runner. The secret is written in no versioned file, no page, no documentation. ci-0@perfshop.com is reserved for the trainer's tools (tools/verif-qa).
  • Masking: like the masked variables of a CI, every occurrence of the secret is replaced by *** in the stored output (output.txt) and in the API responses. Limit: a script that deliberately writes the secret in its report (Log %{PERFSHOP_TRAINING_PASSWORD}) reveals it in its log.html — masking protects against accidents, not against a script written to disclose it (it needs the secret to log in).
  • Rotation: docker exec perfshop-app rm /training/password, then restart perfshop-app: a new secret is generated and every account realigned; Scripts UI re-reads the secret at every run (no restart).
  • Polluted "empty" account: if a script ordered with ci-empty, CT-021c reports it; delete that account in the admin (its orders go with it): it is recreated empty at the next start of perfshop-app.

Security

The four layers are the same as for jmeter-ui:

Layer Details
CSRF Session-signed token, required on POST, PUT, DELETE
Rate limit rateLimit(60_000, 10) on /api/auth/login
Session express-session 8h, httpOnly cookie, secure / sameSite policy conditional
Auth gate Systematic requireAuth on all sensitive routes, except /api/runner-status (public healthcheck) and the read link of the reports (/api/runs/:id/view/…), authorised by a signed token that an authenticated route hands out

On top of that, strict path sanitization by validation.js before any Forgejo call or docker exec — this layer is specific to Scripts UI and is justified by the richness of file operations exposed.

Known limitations and directions

  • No SSE/WebSocket for live streaming — polling every 2 seconds was chosen for simplicity and robustness. A future iteration could switch to SSE for streaming the output.
  • Global retention, not per group — the rule (30 days, 2 GB) applies to the whole runs directory: a very productive session can push out, through the cap, the old runs of another group (a Selenium screenshot weighs about 0.4 MB). Export what must be kept (see "Run retention").
  • No multi-user collaborative editing — two instructors editing the same file in parallel risk a Git conflict (resolved by the last commit). Acceptable for the targeted pedagogical use.
  • No branch management — the UI only works on main. Branches and pull requests are managed directly in Forgejo by advanced instructors.

Going further

  • QA Overview
  • Forgejo — configuration of the self-hosted Git service and of the seed
  • Test Runner — container where scripts are actually executed
  • Selenium — Chrome grid used by web tests
  • Squash TM — for formal test case management (complementary usage)