forgedock 1.60.0 → 1.61.0

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.
Files changed (78) hide show
  1. package/bin/config-schema.mjs +44 -1
  2. package/bin/engine/runlog.mjs +52 -0
  3. package/bin/engine-cli.mjs +9 -4
  4. package/bin/env/bench.mjs +38 -0
  5. package/bin/env/cli.mjs +134 -0
  6. package/bin/env/env.mjs +339 -0
  7. package/bin/forgedock.mjs +32 -3
  8. package/bin/help-text.mjs +2 -0
  9. package/bin/lean/ci-budget.mjs +3 -1
  10. package/bin/lean/ci-classify.mjs +74 -0
  11. package/bin/lean/ci-classify.test.mjs +147 -0
  12. package/bin/lean/ci-emit.mjs +175 -0
  13. package/bin/lean/ci-emit.test.mjs +177 -0
  14. package/bin/lean/ci-preflight.mjs +183 -0
  15. package/bin/lean/ci-preflight.test.mjs +122 -0
  16. package/bin/lean/ci-runner-health.mjs +213 -0
  17. package/bin/lean/ci-runner-health.test.mjs +113 -0
  18. package/bin/lean/ci-watch.mjs +79 -0
  19. package/bin/lean/ci-watch.test.mjs +80 -0
  20. package/bin/lean/conformance.mjs +7 -1
  21. package/bin/lean/conformance.test.mjs +7 -1
  22. package/bin/lean/depcache.mjs +38 -8
  23. package/bin/lean/deploy-stages.mjs +514 -0
  24. package/bin/lean/deploy-stages.test.mjs +580 -0
  25. package/bin/lean/effects.mjs +50 -0
  26. package/bin/lean/execution.mjs +8 -1
  27. package/bin/lean/lean.mjs +61 -12
  28. package/bin/lean/lean.test.mjs +87 -0
  29. package/bin/lean/preflight.mjs +62 -1
  30. package/bin/lean/preflight.test.mjs +30 -1
  31. package/bin/lean/release-deploy.mjs +12 -6
  32. package/bin/lean/release-flakes.mjs +16 -0
  33. package/bin/lean/release-flakes.test.mjs +15 -0
  34. package/bin/lean/release-gates.mjs +24 -1
  35. package/bin/lean/release-ledger.mjs +21 -0
  36. package/bin/lean/release-minutes-timing.test.mjs +57 -0
  37. package/bin/lean/release-minutes.mjs +98 -0
  38. package/bin/lean/release-promote.mjs +444 -0
  39. package/bin/lean/release-promote.test.mjs +470 -0
  40. package/bin/lean/release-rollback.mjs +14 -6
  41. package/bin/lean/release.mjs +31 -2
  42. package/bin/lean/sandbox-remote.mjs +11 -3
  43. package/bin/lean/testengine-recall.mjs +82 -0
  44. package/bin/lean/testengine-recall.test.mjs +103 -0
  45. package/bin/lean/testengine-shard.mjs +150 -0
  46. package/bin/lean/testengine-shard.test.mjs +111 -0
  47. package/bin/lean/testengine.mjs +486 -0
  48. package/bin/lean/testengine.test.mjs +303 -0
  49. package/bin/lean/validate-catalog.mjs +16 -0
  50. package/bin/lean/validate-catalog.test.mjs +14 -1
  51. package/bin/lean/verify-settle.test.mjs +156 -0
  52. package/bin/lean/verify.mjs +98 -3
  53. package/bin/pool/agent.mjs +65 -6
  54. package/bin/pool/ci-events.mjs +183 -0
  55. package/bin/pool/ci-events.test.mjs +143 -0
  56. package/bin/pool/docker.mjs +7 -0
  57. package/bin/pool/lane-tools.mjs +32 -0
  58. package/bin/pool/router.mjs +21 -1
  59. package/bin/pool/warm.mjs +14 -3
  60. package/bin/stats/ci-awareness.mjs +66 -0
  61. package/bin/stats/index.mjs +44 -3
  62. package/bin/stats/release-ledger.test.mjs +226 -0
  63. package/bin/stats/release.mjs +365 -1
  64. package/bin/stats/stats.test.mjs +36 -0
  65. package/docs/CI.md +31 -0
  66. package/docs/CONFIG.md +235 -2
  67. package/docs/ENV-LIBRARY.md +172 -0
  68. package/docs/STATS.md +43 -0
  69. package/docs/ci-events.md +88 -0
  70. package/docs/test-engine.md +98 -0
  71. package/package.json +1 -1
  72. package/pool/README.md +1 -0
  73. package/pool/image/entrypoint.sh +15 -3
  74. package/pool/services/docker-compose.yml +53 -0
  75. package/pool/services/git-mirror.sh +22 -0
  76. package/scripts/acceptance-red-green.sh +5 -2
  77. package/scripts/acceptance-red-green.test.sh +11 -0
  78. package/templates/github-actions/forge-env/action.yml +65 -0
package/docs/STATS.md CHANGED
@@ -260,6 +260,49 @@ telemetry comment in the window get their full comment list re-read (6 in parall
260
260
  low). A run with no `--since` and no cache still walks the whole history once. Telemetry comments are edited in place, which
261
261
  the comment window catches; if a cached item still looks stale, run with `--refresh`.
262
262
 
263
+ ## Release ledger (`--release-ledger`, forge#5718)
264
+
265
+ ```bash
266
+ npx forgedock stats --release-ledger [--repo <owner/repo>] [--since <date|21d>] [--json]
267
+ npx forgedock stats --release-ledger --baseline save # freeze today's numbers
268
+ npx forgedock stats --release-ledger --baseline compare # before/after, measured the same way
269
+ ```
270
+
271
+ One table of what a release costs today against the targets, read from the GitHub Actions runs, jobs and steps API plus
272
+ release state. Nothing is estimated: a metric without a sample prints `n/a`. The window defaults to the last 21 days.
273
+
274
+ | Row | How it is measured |
275
+ |-----|--------------------|
276
+ | Mechanical failure surfaced | Failed CI runs whose first failed step is a checkout, toolchain, dependency or lint step: run start to run end (when the failure is visible today), p50 |
277
+ | Job setup (self-hosted, hosted) | Per job, seconds in checkout, toolchain and dependency-install steps (classified by step name, any ecosystem); the p50 of each class, summed |
278
+ | CI wall time per round | A round is every CI run of one head sha of a release PR: first run created to last run finished (first attempt), p50; cancelled rounds are left out |
279
+ | Pushes per release PR | Distinct head shas with CI runs per release PR, p50 (and max) |
280
+ | Deploy pre-gate | Live deploys: run start to the start of the deploy job, p50 |
281
+ | Image build | Per job, minutes in image-build steps, p50 |
282
+ | Deploy job (rollout) | Live deploys: the deploy job's minutes, p50; the report lists its ten longest steps |
283
+ | Release PR opened -> live | PR creation to the end of the first deploy that reached live for its merge commit: median and p90; `clean` = live on the first deploy attempt |
284
+ | Queue time | Job created to job started, p90 |
285
+ | CI minutes in failed / cancelled jobs | Share of job time by job conclusion |
286
+ | CI rounds that fail | Share of judged rounds with a failed run |
287
+ | Deploy attempts that reached live | Deploy runs in which a job ran, and the share whose deploy job succeeded |
288
+
289
+ The report also prints the critical-path jobs (the job that ends last in a round, with its p50 and failure rate).
290
+
291
+ What counts as a release PR, CI run and deploy is generic and can be pinned in forge.yaml (`stats.ledger_*`, see
292
+ [CONFIG.md](CONFIG.md#stats-optional)): a release PR is a PR into the default branch (from `branches.staging` when set); its
293
+ CI runs are the pull-request runs that name it (push runs of the head branch when the repo has none); the deploy workflow is
294
+ the push/dispatch workflow on the default branch whose name says deploy, publish or release with the most runs.
295
+ `--deploy-workflow <name|file>` and `--release-head <branch|any>` override per call. With `release.managed: true` the
296
+ managed ledger's deploy attempt counts are merged in.
297
+
298
+ Cost: one runs query per branch and event (the runs API takes seconds per page), then one jobs call per run, 4 at a time.
299
+ Jobs of completed runs are cached in `~/.forge/stats-cache/<owner>_<repo>/actions-jobs.json`, so a weekly re-read only
300
+ fetches new runs (`--no-cache` skips it). Every read is paginated and retried on transient GitHub errors.
301
+
302
+ `--baseline save` writes the metrics to `release-ledger-baseline.json` next to that cache (`--baseline-file <path>` for a
303
+ file you commit). `--baseline compare` prints each metric before and after with a verdict `improved|regressed|flat|n/a`
304
+ (flat is within 5%, or 2 points for a share) and exits 2 when there is no baseline.
305
+
263
306
  ## Per-release regression rule (`--by version`, forge#4628)
264
307
 
265
308
  ```bash
@@ -0,0 +1,88 @@
1
+ # CI events and the pre-flight fast lane
2
+
3
+ ## `forgedock ci preflight` (#5691)
4
+
5
+ Cheap deterministic checks that fail in seconds, before the 20–36 min suites start. No LLM, no network. Exit 1 only when a check fails; a check whose tool or config is absent is skipped with a reason.
6
+
7
+ | Check | Fails when | Skipped when |
8
+ |---|---|---|
9
+ | `workflow-lint` | `actionlint` reports an error; without it, a syntax scan of `.github/workflows/*.yml` (tab indent, unterminated quote, unbalanced flow bracket) | no workflow files |
10
+ | `lockfile:<pnpm\|npm\|uv\|poetry>` | `pnpm install --frozen-lockfile --lockfile-only`, `npm ci --dry-run`, `uv lock --check` or `poetry check --lock` exits non-zero | no lockfile, or the tool is not on PATH |
11
+ | `generated` | a generator command fails, or `git diff --exit-code` on its declared paths shows a change | `ci.preflight.generated` not set |
12
+ | `env-drift` | a workflow `env:` key set from `secrets.*`/`vars.*` is missing from `.env.example` | no `.env.example` or no such keys |
13
+ | `tools` | a tool in `ci.preflight.tools` is not on PATH | `ci.preflight.tools` not set |
14
+
15
+ The total budget is 60 s (`ci.preflight.timeout_s`); a check starting after it is skipped. `--json` prints `{ok, budgetMs, elapsedMs, checks[]}`.
16
+
17
+ ### forge.yaml
18
+
19
+ ```yaml
20
+ ci:
21
+ preflight:
22
+ timeout_s: 60
23
+ tools:
24
+ - actionlint
25
+ generated:
26
+ - pnpm run gen:sdk :: packages/sdk/src
27
+ ```
28
+
29
+ A `generated` entry is `<command> :: <path> [<path>...]`. The one-level forge.yaml parser flattens `ci.preflight.*` under `ci`, so `ci.generated`, `ci.tools` and `ci.timeout_s` are the keys read. Without them only the auto-detected checks run.
30
+
31
+ ### Job 0 workflow snippet
32
+
33
+ ```yaml
34
+ jobs:
35
+ preflight:
36
+ runs-on: ubuntu-latest
37
+ steps:
38
+ - uses: actions/checkout@v4
39
+ - run: npx forgedock ci preflight
40
+ env:
41
+ FORGE_CI_EVENTS_URL: ${{ vars.FORGE_CI_EVENTS_URL }} # optional
42
+ tests:
43
+ needs: preflight
44
+ ```
45
+
46
+ ### Events
47
+
48
+ With `FORGE_CI_EVENTS_URL` set (the router's `POST /ci/events`, #5688), each failed check is POSTed as a best-effort `step_failed` event `{type, step: "preflight:<check>", class: "deterministic-setup", reason, repo, sha}`. A delivery error never changes the exit code. The GitHub check status stays the source of truth for merge gating.
49
+
50
+ ## Runner-side emitter (#5689)
51
+
52
+ `forgedock ci-step` and `forgedock ci-hook` stream step and test failures to the router while a job runs, so a failure is visible in seconds instead of after the log zip is downloaded. Delivery is best effort: the CI result stays the source of truth.
53
+
54
+ | Env var | Meaning |
55
+ |---|---|
56
+ | `FORGEDOCK_CI_EVENTS_URL` | the router's `POST /ci/events` URL (`FORGE_CI_EVENTS_URL` is read as a fallback). Unset: nothing is posted. |
57
+ | `FORGEDOCK_CI_TOKEN` | bearer token (a router `ci_tokens[]` entry), sent as `Authorization: Bearer`. |
58
+
59
+ The events take `repo`, `sha`, `run_id`, `job` and the PR number (from `refs/pull/<n>/merge`) from `GITHUB_REPOSITORY`, `GITHUB_SHA`, `GITHUB_RUN_ID`, `GITHUB_JOB` and `GITHUB_REF`.
60
+
61
+ ### Wrapping a step
62
+
63
+ ```yaml
64
+ - run: npx forgedock ci-step --name unit -- pnpm test
65
+ env:
66
+ FORGEDOCK_CI_EVENTS_URL: ${{ vars.FORGEDOCK_CI_EVENTS_URL }}
67
+ FORGEDOCK_CI_TOKEN: ${{ secrets.FORGEDOCK_CI_TOKEN }}
68
+ ```
69
+
70
+ `ci-step --name <step> -- <cmd...>` runs the command with its stdout, stderr and exit code passed through unchanged (a signal exits `128+signal`). It posts `step_started`, then on a non-zero exit `step_failed` with `exit_code` and up to 40 lines: the first 40 matching error/fail/Traceback/assert, else the last 40. While the command runs, pytest (`FAILED path::id - msg` plus `path:line: AssertionError`) and vitest/jest (`FAIL path > name` plus `❯ file:line`) output yields one `test_failed` per failing test `{id, file, line, message}`, posted as the line appears. A failed post prints one warning, stops further posts and adds under 2 s.
71
+
72
+ ### Self-hosted runner hooks
73
+
74
+ Set `ACTIONS_RUNNER_HOOK_JOB_STARTED="npx forgedock ci-hook job-started"` and `ACTIONS_RUNNER_HOOK_JOB_COMPLETED="npx forgedock ci-hook job-completed"` in the runner's environment (or `.env`), together with the two variables above. They post `job_started` and `job_finished`, and always exit 0; with the URL unset they do nothing.
75
+
76
+ ## Runner health (#5693)
77
+
78
+ `forgedock ci runner-health` checks the self-hosted runner services on this host and posts a `runner_unhealthy` event (`class: infra`, `step` = `stuck-run`, `service-down`, `orphan-container`, `low-disk` or `low-memory`, the reason in `lines`) per finding, using the same `FORGEDOCK_CI_EVENTS_URL` / `FORGEDOCK_CI_TOKEN` as the emitter. It exits 1 on any finding.
79
+
80
+ | forge.yaml `ci` key | Meaning |
81
+ |---|---|
82
+ | `repo` | repo whose runners to check (else `--repo`, else `GITHUB_REPOSITORY`; without one the stuck-run check is skipped) |
83
+ | `services[]` | systemd units of the runners, e.g. `actions.runner.<owner>-<repo>.<name>.service` |
84
+ | `min_disk_gb` | free-disk floor, default 10 |
85
+ | `recover` | the timer unit passes `--recover` |
86
+ | `job_timeout_min` | container age that counts as orphaned, default 360 |
87
+
88
+ `--recover` restarts only the affected runner's service and removes only orphaned containers; without it the plan is printed and nothing is changed. A service is restarted at most once per 10 minutes. `forgedock ci runner-health --print-units` prints a oneshot service and a timer that runs it every 2 minutes; install them with `systemctl enable --now`.
@@ -0,0 +1,98 @@
1
+ # Test engine (`forgedock tests`, forge#5710)
2
+
3
+ Runs fewer tests per change without weakening the gate, and splits what does run evenly across runners. Everything is
4
+ off until `ci.tests.selection` is set, and nothing is skipped until a recorded shadow period proves the selection.
5
+
6
+ | Command | What it does |
7
+ |---|---|
8
+ | `forgedock tests select` | changed files -> the test files they can affect, with a reason per test |
9
+ | `forgedock tests shard` | test files -> N shards balanced by recorded durations; CI matrix JSON |
10
+ | `forgedock tests recall record` | after the run: were all failing tests inside the selection? one ledger line |
11
+ | `forgedock tests recall [status]`, `recall check` | graduation state and quarantined flaky tests; `check` exits 1 until graduated |
12
+
13
+ ## Selection
14
+
15
+ `tests select [--base <ref> | --changed <file>... | --changed-from <file|->] [--full] [--json] [--out <file>]`.
16
+ Without `--changed*` the diff is `git diff <base>...HEAD` (`--base`, else `origin/$GITHUB_BASE_REF`).
17
+
18
+ A changed file selects, in this order:
19
+
20
+ 1. nothing, when it matches `ci.tests.ignore`;
21
+ 2. **everything**, when it matches a run-everything glob: dependency manifests and lockfiles (npm, pnpm, yarn, bun, poetry, uv, pip, pipenv, go, cargo), toolchain and test-runner config (`tsconfig*.json`, `jest.config.*`, `vitest.config.*`, `pytest.ini`, `tox.ini`, ...), CI files (`.github/**`, `forge.yaml`, `.forge/**`), `Dockerfile*`, compose files, `Makefile`, `.env*`, plus `ci.tests.run_all`;
22
+ 3. the targets of every `ci.tests.suites` rule whose glob matches it;
23
+ 4. itself, when it is a test file;
24
+ 5. every test file that depends on it, directly or through other files:
25
+ - JS/TS: `import`, `export ... from`, `require`, literal `import()`, `jest.mock` / `vi.mock`, `new URL(rel, import.meta.url)`; relative paths, workspace package names (`package.json` `name`) and `tsconfig`/`jsconfig` `baseUrl` + `paths` are resolved against the repo's files;
26
+ - Python: `import a.b`, `from a.b import c`, relative imports, `importlib.import_module("...")`, `mock.patch("...")` targets, `pytest_plugins`; module roots are the repo root, `src/`, every directory with a `pyproject.toml` / `setup.py` / `setup.cfg` / `requirements*.txt`, and the importing file's own directories; every `conftest.py` above a test is a dependency of it;
27
+ - both: a quoted repo path (`"docs/guide.md"`, `"fixtures/order.json"`) is a dependency, so a test that reads a file by path is selected when that file changes;
28
+ 6. **everything**, when none of 3 to 5 produced a test (a file nothing imports, an unknown file type, a deleted source file). An empty diff also selects everything.
29
+
30
+ The graph is a cheap static scan (regular expressions, no parser, no package installed); it over-approximates on purpose. It cannot follow a computed import (`import(name)`), a dependency reached only at run time, or another language. The shadow recall ledger measures exactly that gap, and `ci.tests.suites` is the declared fix for it:
31
+
32
+ ```yaml
33
+ ci:
34
+ tests:
35
+ selection: shadow
36
+ suites:
37
+ - "migrations/** db/*.sql => tests/integration/**" # path globs => test-file globs
38
+ - "deploy/** => @smoke" # a named suite the runner understands
39
+ - "proto/** => *" # everything
40
+ ignore: ["**/*.md"]
41
+ ```
42
+
43
+ A glob without `/` matches the basename in any directory; `**/` also matches no directory. Test files are `*.test.*`, `*.spec.*`, `__tests__/**` (JS/TS) and `test_*.py`, `*_test.py`, unless `ci.tests.test_globs` replaces the convention.
44
+
45
+ `--json` / `--out` print `{plan, config, selection, run_tests, run_suites, quarantined, graduation}`. `plan.run` is `all` or `selection`; `run_tests` is the list to hand to the runner (every test file unless `plan.run` is `selection`). When `plan.run` is `selection` and `run_tests` is empty (for example only ignored files changed), skip the test step: most runners run everything when given no file.
46
+
47
+ ## Modes and graduation
48
+
49
+ | `ci.tests.selection` | Effect |
50
+ |---|---|
51
+ | `off` (default) | nothing is computed; `tests select` says run everything; `recall record` records nothing |
52
+ | `shadow` | the selection is computed and recorded; the full suite runs |
53
+ | `enforce` | the runner gets only the selection, **after graduation**. Before it, enforce is refused: the effective mode stays `shadow` and the output says why |
54
+
55
+ Graduation: the last `graduate_after` (50) full-suite runs under the current selection config all had 100% failure recall (every failing test file was inside the selection), and at least `graduate_min_failing` (1) of them was a subset selection that contained a real failure. A miss, a failure no test file could be named for, or a change to `suites` / `run_all` / `ignore` / `test_globs` restarts the count, also after graduation, which sends `enforce` back to shadow.
56
+
57
+ The full suite always runs on a scheduled run (`GITHUB_EVENT_NAME=schedule`), on a `ci.tests.full_branches` branch as head or PR base (default `main`, `master`, `release/**`) and with `--full`. Keep measuring after graduation: on the nightly run pass `--base <previous nightly sha>` so the day's diff has a real selection to check against the full result.
58
+
59
+ `tests recall record --selection <file from select --out> [--report <file>]... [--failed <test>]...` reads the failing tests from JUnit XML or TAP reports (or `--failed`), and appends one line to the ledger. It always exits 0: the suite's own result is the gate. The ledger is a JSONL file at `ci.tests.recall_ledger`, else `$FORGEDOCK_TESTS_LEDGER`, else `~/.forge/tests/<owner>__<repo>/recall.jsonl` (`FORGEDOCK_TESTS_DIR`): outside the checkout, so a change under test cannot edit its own record. On ephemeral runners, restore and save that file with the CI cache or point it at a persistent volume.
60
+
61
+ ## Sharding
62
+
63
+ `tests shard [--shards <n> | --target-seconds <s>] [--max-shards <n>] [--report <file>]... [--from <selection.json>] [--ecosystem js|python] [--json | --matrix]`.
64
+
65
+ Durations come from earlier reports: JUnit XML (pytest, jest, vitest: per-file seconds are the sum of the cases), TAP, or a `{"<file>": seconds}` JSON map. Files are placed longest first onto the least-loaded shard (greedy LPT). A file without a recorded duration gets the median; with no history at all the split is by file count. `--target-seconds` derives the shard count (`ceil(total / target)`) and lists every file that alone exceeds the target: no file split can shorten those, they need to be broken up or moved off the critical path.
66
+
67
+ `--matrix` prints `{"include":[{"shard":1,"total":4,"files":"a b c"}, ...]}` for a GitHub Actions matrix (`fromJSON`). Paths with spaces need `--json` and their own quoting.
68
+
69
+ Limit: `node --test` on Node 22 writes a file location only for failing tests (TAP) and none in its JUnit reporter, so its reports attribute failures but not durations; use a `{file: seconds}` map for it.
70
+
71
+ ## Flaky quarantine
72
+
73
+ A test file that failed and later passed on the same commit is a flip (`release-flakes.mjs` `detectSameShaFlip`). One that flipped `quarantine_after` (3) times inside `quarantine_window_days` (14) is listed as quarantined by `tests select` and `tests recall`. It is still run. `ci.tests.quarantine`: `report` (default) keeps it blocking; `non-blocking` is the repo's opt-in to let the runner treat its failure as a warning, never for an unskippable class (`migration`, `security`, `rollback`, `backup-restore`, `secrets` as a path segment); `off` lists nothing.
74
+
75
+ ## Workflow sketch
76
+
77
+ ```yaml
78
+ jobs:
79
+ plan:
80
+ runs-on: ubuntu-latest
81
+ outputs: { matrix: "${{ steps.shard.outputs.matrix }}" }
82
+ steps:
83
+ - uses: actions/checkout@v4
84
+ with: { fetch-depth: 0 }
85
+ - run: npx forgedock tests select --out selection.json
86
+ - id: shard
87
+ run: echo "matrix=$(npx forgedock tests shard --from selection.json --target-seconds 240 --max-shards 8 --report durations.json --matrix)" >> "$GITHUB_OUTPUT"
88
+ test:
89
+ needs: plan
90
+ strategy: { matrix: "${{ fromJSON(needs.plan.outputs.matrix) }}", fail-fast: false }
91
+ steps:
92
+ - run: <test runner> ${{ matrix.files }} # writes junit-${{ matrix.shard }}.xml
93
+ recall:
94
+ needs: test
95
+ if: always()
96
+ steps:
97
+ - run: npx forgedock tests recall record --selection selection.json --report junit-1.xml --report junit-2.xml
98
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "forgedock",
3
- "version": "1.60.0",
3
+ "version": "1.61.0",
4
4
  "description": "An AI engineering team that ships to production",
5
5
  "bin": {
6
6
  "forgedock": "bin/forgedock.mjs"
package/pool/README.md CHANGED
@@ -6,6 +6,7 @@ ForgeDock's built-in remote compute pool (imported from computeshare; AGPL-3.0-o
6
6
  - `pool/image/` lane image recipe (Dockerfile, shims, entrypoint, `cs-cred` credential relay, `cs-relay` read-only capability relay: allowlisted commands executed on the dispatching host, #4778).
7
7
  - `pool/install/` agent installers (Windows/WSL, native Linux, router).
8
8
  Native Linux agent (root, systemd): `pool/install/install-agent-linux.sh --router URL --token CODE [--name N --cpus N --mem GB --dry-run]`.
9
+ - `pool/services/` opt-in caching proxies (npm, PyPI, apt) and a read-only git mirror (`docker-compose.yml`); nothing starts them. See `docs/ENV-LIBRARY.md`.
9
10
  - Tests: `bin/tests/computeshare.test.mjs`.
10
11
 
11
12
  The module boundary is the ForgeDock HTTP sandbox protocol: the router speaks it to the dispatcher and relays to agents over HTTP. Sandboxes receive only short-lived GitHub and Claude access tokens; refresh tokens stay on the router host.
@@ -5,6 +5,14 @@
5
5
  # All output goes to /csout/lane.log, which the agent streams back to ForgeDock.
6
6
  set -euo pipefail
7
7
  mkdir -p /csout /result /cache
8
+ if [ -n "${CS_WORK_DIR:-}" ]; then
9
+ # #5696: one mount for worktree and caches. The real path is used for cd so a private dockerd that mounts the same
10
+ # volume resolves compose bind mounts identically.
11
+ cd /
12
+ mkdir -p "$CS_WORK_DIR"
13
+ rm -rf /work
14
+ ln -s "$CS_WORK_DIR" /work
15
+ fi
8
16
  exec > >(tee -a /csout/lane.log) 2>&1
9
17
 
10
18
  export HOME=/root
@@ -12,11 +20,15 @@ export UV_CACHE_DIR=/cache/uv npm_config_cache=/cache/npm POETRY_CACHE_DIR=/cach
12
20
  export TMPDIR=/tmp
13
21
  # ForgeDock's dependency cache (its pnpm store and snapshots) and pnpm's own store live in the persistent per-repo
14
22
  # cache volume, so a lane installs from a warm store instead of downloading every package (a cold monorepo install
15
- # took ~15 min and hit ForgeDock's install timeout). /cache and /work are different volumes, so pnpm imports by copy.
23
+ # took ~15 min and hit ForgeDock's install timeout). The lane worktree lives in the same volume (/cache/work/<id>, /work is a symlink to it), so installs hardlink from the stores instead of copying across mounts (EXDEV).
16
24
  export FORGE_DEPCACHE_ROOT=/cache/forge-depcache npm_config_store_dir=/cache/pnpm-store
17
25
  # Testcontainers' Ryuk reaper never logs "Started" on the sandbox's private dockerd, so every DB test setup failed.
18
26
  # The sandbox and its dockerd are discarded after the lane, so the reaper has nothing to add.
19
27
  export TESTCONTAINERS_RYUK_DISABLED=true
28
+ # env.proxies.apt (opt-in): route apt through the caching proxy. Unset: apt is untouched.
29
+ if [ -n "${FORGE_APT_PROXY:-}" ]; then
30
+ printf 'Acquire::http::Proxy "%s";\n' "$FORGE_APT_PROXY" > /etc/apt/apt.conf.d/01forge-proxy 2>/dev/null || true
31
+ fi
20
32
 
21
33
  echo "[computeshare] sandbox ${CS_SANDBOX_ID:-?} repo ${CS_REPO_SLUG:-?} ref ${CS_REPO_REF:-default} on $(hostname)"
22
34
 
@@ -40,7 +52,7 @@ checkout_repo() {
40
52
  fi
41
53
  rm -rf /work/repo
42
54
  git clone --quiet --reference "$mirror" ${CS_REPO_REF:+--branch "$CS_REPO_REF"} "$CS_REPO_URL" /work/repo
43
- cd /work/repo
55
+ cd "$(readlink -f /work/repo)"
44
56
  fi
45
57
  }
46
58
 
@@ -85,7 +97,7 @@ if [ -z "${warm_claimed:-}" ]; then
85
97
  checkout_repo
86
98
  else
87
99
  (cd /work/repo && /usr/local/bin/cs-warm-refresh "${CS_CLAIM_REF:-}")
88
- cd /work/repo
100
+ cd "$(readlink -f /work/repo)"
89
101
  fi
90
102
 
91
103
  if [ -n "${CS_FORGE_YAML_B64:-}" ]; then
@@ -0,0 +1,53 @@
1
+ # SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
2
+ # SPDX-License-Identifier: AGPL-3.0-or-later
3
+ #
4
+ # Opt-in caching proxies for lanes and CI runners: npm, PyPI, apt, and a read-only git mirror.
5
+ # Nothing uses them until a repo sets forge.yaml `env.proxies` (docs/ENV-LIBRARY.md). Start on one host that the pool
6
+ # hosts and runners can reach:
7
+ # FORGE_PROXY_BIND=<private address> docker compose -f pool/services/docker-compose.yml up -d
8
+ # The default bind is loopback. These services have no authentication: bind them to a private interface only
9
+ # (VPN or internal network), never a public one. Private packages and private repos are not served: the npm and
10
+ # PyPI proxies cache public registries, and the git mirror fetches only the public URLs listed in GIT_MIRROR_REPOS.
11
+ name: forge-proxies
12
+ services:
13
+ npm:
14
+ image: verdaccio/verdaccio:6
15
+ restart: unless-stopped
16
+ ports: ["${FORGE_PROXY_BIND:-127.0.0.1}:4873:4873"]
17
+ volumes: ["npm-cache:/verdaccio/storage"]
18
+ pypi:
19
+ image: epicwink/proxpi:latest
20
+ restart: unless-stopped
21
+ environment:
22
+ PROXPI_INDEX_URL: https://pypi.org/simple/
23
+ PROXPI_CACHE_SIZE: "${FORGE_PYPI_CACHE_BYTES:-21474836480}"
24
+ PROXPI_CACHE_DIR: /cache
25
+ ports: ["${FORGE_PROXY_BIND:-127.0.0.1}:3141:5000"]
26
+ volumes: ["pypi-cache:/cache"]
27
+ apt:
28
+ image: sameersbn/apt-cacher-ng:latest
29
+ restart: unless-stopped
30
+ ports: ["${FORGE_PROXY_BIND:-127.0.0.1}:3142:3142"]
31
+ volumes: ["apt-cache:/var/cache/apt-cacher-ng"]
32
+ git-mirror:
33
+ # Bare mirrors of GIT_MIRROR_REPOS (space-separated https URLs), refreshed every GIT_MIRROR_INTERVAL seconds and
34
+ # served read-only over git:// at git://<host>:9418/<owner>/<name>.git
35
+ image: alpine:3.20
36
+ restart: unless-stopped
37
+ environment:
38
+ GIT_MIRROR_REPOS: "${GIT_MIRROR_REPOS:-}"
39
+ GIT_MIRROR_INTERVAL: "${GIT_MIRROR_INTERVAL:-60}"
40
+ entrypoint: ["/bin/sh", "/mirror.sh"]
41
+ configs:
42
+ - source: mirror_sh
43
+ target: /mirror.sh
44
+ ports: ["${FORGE_PROXY_BIND:-127.0.0.1}:9418:9418"]
45
+ volumes: ["git-mirror:/srv/git"]
46
+ configs:
47
+ mirror_sh:
48
+ file: ./git-mirror.sh
49
+ volumes:
50
+ npm-cache:
51
+ pypi-cache:
52
+ apt-cache:
53
+ git-mirror:
@@ -0,0 +1,22 @@
1
+ #!/bin/sh
2
+ # SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
3
+ # SPDX-License-Identifier: AGPL-3.0-or-later
4
+ # Read-only git mirror (pool/services/docker-compose.yml): keeps a bare mirror of every URL in GIT_MIRROR_REPOS
5
+ # (space-separated https URLs of public repos) under /srv/git/<owner>/<name>.git and serves them over git://.
6
+ set -u
7
+ # git-daemon is a separate package on Alpine.
8
+ apk add --no-cache git git-daemon >/dev/null 2>&1 || echo "apk add git git-daemon failed (already present?)"
9
+ git daemon --reuseaddr --export-all --base-path=/srv/git --listen=0.0.0.0 --port=9418 /srv/git &
10
+ while true; do
11
+ for url in ${GIT_MIRROR_REPOS:-}; do
12
+ rel="$(printf '%s' "$url" | sed -e 's#^https\{0,1\}://[^/]*/##' -e 's#\.git$##').git"
13
+ case "$rel" in *..*|/*) echo "skipped: $url"; continue ;; esac
14
+ if [ -d "/srv/git/$rel" ]; then
15
+ git -C "/srv/git/$rel" remote update --prune >/dev/null 2>&1 || echo "refresh failed: $rel"
16
+ else
17
+ mkdir -p "$(dirname "/srv/git/$rel")"
18
+ git clone --mirror --quiet "$url" "/srv/git/$rel" || echo "clone failed: $url"
19
+ fi
20
+ done
21
+ sleep "${GIT_MIRROR_INTERVAL:-60}"
22
+ done
@@ -101,9 +101,12 @@ while IFS= read -r f; do
101
101
  mkdir -p "$BASE_WT/$(dirname "$f")" && cp -p "$REPO/$f" "$BASE_WT/$f" 2>/dev/null && [ -f "$BASE_WT/$f" ] || OVERLAY_OK=false
102
102
  done <<< "$CHANGED"
103
103
  # Untracked dependency trees (never in git): link head's so a missing install is not mistaken for a red run (#4334):
104
- # every node_modules next to a tracked package.json (workspace packages too, e.g. apps/web/node_modules) and a root .venv.
104
+ # every node_modules next to a tracked package.json (workspace packages too, e.g. apps/web/node_modules), and every .venv
105
+ # next to a tracked Python manifest (root or a monorepo service, e.g. services/api/.venv).
105
106
  DEPS=$( { git -C "$REPO" ls-files -- package.json '*/package.json' 2>/dev/null | while IFS= read -r p; do
106
- d=$(dirname "$p"); [ "$d" = "." ] && echo node_modules || echo "$d/node_modules"; done; echo .venv; } | sort -u )
107
+ d=$(dirname "$p"); [ "$d" = "." ] && echo node_modules || echo "$d/node_modules"; done
108
+ git -C "$REPO" ls-files -- pyproject.toml '*/pyproject.toml' poetry.lock '*/poetry.lock' uv.lock '*/uv.lock' 'requirements*.txt' '*/requirements*.txt' 2>/dev/null | while IFS= read -r p; do
109
+ d=$(dirname "$p"); [ "$d" = "." ] && echo .venv || echo "$d/.venv"; done; echo .venv; } | sort -u )
107
110
  while IFS= read -r t; do
108
111
  [ -n "$t" ] || continue
109
112
  case "$t" in */node_modules/*) continue ;; esac # a package.json inside an installed tree
@@ -87,6 +87,17 @@ check "workspace node_modules and .venv linked into base; new nested test overla
87
87
  [ -d "$R5/apps/web/node_modules/dep" ] && [ -d "$R5/.venv/bin" ] && ok "head dependency trees survive base cleanup" || bad "head dependency trees removed by cleanup"
88
88
 
89
89
 
90
+ # 11b. Python service venv (AlterLab 40652): a test under services/api runs with services/api/.venv (next to its tracked
91
+ # pyproject.toml), not the root .venv; base gets that tree linked, so it fails on the defect instead of UNRUNNABLE
92
+ R6="$TMP/r6"; make_repo "$R6"
93
+ mkdir -p "$R6/services/api"; printf '[project]\nname="api"\n' > "$R6/services/api/pyproject.toml"
94
+ printf '.venv/\n' > "$R6/.gitignore"; git -C "$R6" add -A; git -C "$R6" commit -qm svc; git -C "$R6" update-ref refs/remotes/origin/main HEAD
95
+ fix_head "$R6"
96
+ mkdir -p "$R6/services/api/.venv/bin" "$R6/services/api/tests"; printf 'echo venv\n' > "$R6/services/api/.venv/bin/python"
97
+ printf 'bash .venv/bin/python >/dev/null 2>&1 || exit 127\ntest "$(bash ../../app.sh)" = good && echo "1 passed"\n' > "$R6/services/api/tests/t.sh"
98
+ git -C "$R6" add -A; git -C "$R6" commit -qm test
99
+ check "service .venv next to a tracked pyproject.toml is linked into base" "BASE=FAILED HEAD=RAN" "$R6" "cd services/api && bash tests/t.sh"
100
+
90
101
  # 12. #5544 test-only fix: the base's own version of the test fails, head's passes, source unchanged
91
102
  R5="$TMP/r5"; make_repo "$R5"; mkdir -p "$R5/tests"; printf 'test "$(bash app.sh)" = good && echo "1 passed"\n' > "$R5/tests/t.sh"
92
103
  git -C "$R5" add -A; git -C "$R5" commit -qm "bad test"; git -C "$R5" update-ref refs/remotes/origin/main HEAD
@@ -0,0 +1,65 @@
1
+ # SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
2
+ # SPDX-License-Identifier: AGPL-3.0-or-later
3
+ #
4
+ # forge-env: use a ForgeDock environment snapshot in a GitHub Actions job (docs/ENV-LIBRARY.md).
5
+ # Copy this directory to .github/actions/forge-env/ in your repo.
6
+ #
7
+ # The job runs in the snapshot image for the checkout's key (`container: <env.snapshots.image>:<key>`). The image holds
8
+ # the frozen installs at /work/env. This action checks that the image's key equals the checkout's key and then either
9
+ # mode: prefix (default) copies the checkout over /work/env and reports it as `workdir`; run your steps there
10
+ # mode: link symlinks each dependency tree into the workspace (single-package repos without workspace links)
11
+ # When the keys differ or the job is not in a snapshot image, `hit` is false and nothing is changed: run your normal
12
+ # install step under `if: steps.<id>.outputs.hit != 'true'`. The set of checks a job runs never changes.
13
+ name: forge-env
14
+ description: Use a ForgeDock environment snapshot (dependencies installed once, keyed by lockfiles + toolchain)
15
+ inputs:
16
+ key:
17
+ description: The checkout's environment key (`forgedock env key --store oci`)
18
+ required: true
19
+ mode:
20
+ description: prefix | link
21
+ default: prefix
22
+ prefix:
23
+ description: Where the snapshot image holds the trees
24
+ default: /work/env
25
+ outputs:
26
+ hit:
27
+ description: "'true' when the snapshot matched and is in place"
28
+ value: ${{ steps.use.outputs.hit }}
29
+ workdir:
30
+ description: The directory to run steps in (the prefix on a hit in prefix mode, else the workspace)
31
+ value: ${{ steps.use.outputs.workdir }}
32
+ runs:
33
+ using: composite
34
+ steps:
35
+ - id: use
36
+ shell: bash
37
+ env:
38
+ WANT: ${{ inputs.key }}
39
+ MODE: ${{ inputs.mode }}
40
+ PREFIX: ${{ inputs.prefix }}
41
+ run: |
42
+ set -euo pipefail
43
+ man="$PREFIX/.forge-env.json"
44
+ have=""
45
+ if [ -f "$man" ]; then have=$(sed -n 's/.*"key":"\([0-9a-f]\{16\}\)".*/\1/p' "$man" | head -1); fi
46
+ if [ -z "$have" ] || [ "$have" != "$WANT" ]; then
47
+ echo "forge-env: no snapshot for key $WANT here (image has: ${have:-none}); use the normal install"
48
+ { echo "hit=false"; echo "workdir=$GITHUB_WORKSPACE"; } >> "$GITHUB_OUTPUT"
49
+ exit 0
50
+ fi
51
+ if [ "$MODE" = "link" ]; then
52
+ sed -n 's/.*"trees":\[\([^]]*\)\].*/\1/p' "$man" | tr ',' '\n' | tr -d '"' | while read -r t; do
53
+ [ -n "$t" ] || continue
54
+ if [ -e "$GITHUB_WORKSPACE/$t" ]; then continue; fi
55
+ mkdir -p "$(dirname "$GITHUB_WORKSPACE/$t")"
56
+ ln -s "$PREFIX/$t" "$GITHUB_WORKSPACE/$t"
57
+ done
58
+ echo "workdir=$GITHUB_WORKSPACE" >> "$GITHUB_OUTPUT"
59
+ else
60
+ cp -a "$GITHUB_WORKSPACE/." "$PREFIX/"
61
+ git config --global --add safe.directory "$PREFIX" || true
62
+ echo "workdir=$PREFIX" >> "$GITHUB_OUTPUT"
63
+ fi
64
+ echo "hit=true" >> "$GITHUB_OUTPUT"
65
+ echo "forge-env: snapshot $WANT in place ($MODE)"