apiVersion: argoproj.io/v1alpha1
kind: WorkflowTemplate
metadata:
  name: run-shell-tests
  labels:
    dagweave.io/catalog-item: run-shell-tests
  annotations:
    # The catalog semver this manifest was authored at. The dagweave app records
    # (catalog-item-id, semver) -> content-hash -> base-vN when it mints the tenant
    # cluster name via ResolveOrMint. Keep in sync with metadata.yaml `version`.
    dagweave.io/catalog-version: "1.0.2"
    dagweave.io/catalog-category: "CI/CD"
spec:
  entrypoint: test
  templates:
    - name: test
      inputs:
        parameters:
          # Directory to run the test command in (the checked-out repo root).
          - name: work-dir
            default: "."
          # The test command to run, e.g. "npm ci && npm test". Runs on Node 24
          # (node:24-alpine); swap the image for a different toolchain if needed.
          - name: test-command
      container:
        # Pinned by digest per the catalog convention: an image rebuild can never
        # silently change the behaviour of an already-released item version.
        # node:26-alpine — a generic toolchain image; the item stays language-agnostic
        # by taking the test command verbatim.
        image: node@sha256:c6ad9e9c1d80f6eb607c26b4b0a132ff7a2344fad1c78ea3baa2a7d4c8de6d94
        command: [sh, -c]
        # The work-dir and test-command are passed as env vars (below), never
        # interpolated from Argo into the shell, so they carry no injection risk. The
        # test command is *meant* to be executed as a shell command — that is the point
        # of this item — so it is run via `sh -c "$TEST_COMMAND"` after cd'ing in.
        args:
          - |
            set -eu
            cd "$WORK_DIR"
            sh -c "$TEST_COMMAND"
        env:
          - name: WORK_DIR
            value: "{{inputs.parameters.work-dir}}"
          - name: TEST_COMMAND
            value: "{{inputs.parameters.test-command}}"
