fun_ci 2.4.0 → 2.5.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 (52) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +73 -0
  3. data/README.md +16 -7
  4. data/lib/fun_ci/agent/events.rb +15 -7
  5. data/lib/fun_ci/agent/job_events.rb +12 -5
  6. data/lib/fun_ci/agent/onward.rb +21 -0
  7. data/lib/fun_ci/agent/output.rb +7 -0
  8. data/lib/fun_ci/agent/reports.rb +3 -0
  9. data/lib/fun_ci/agent/snapshots.rb +25 -7
  10. data/lib/fun_ci/agent/status_text.rb +7 -3
  11. data/lib/fun_ci/agent/wait_command.rb +37 -5
  12. data/lib/fun_ci/console/board_data.rb +46 -11
  13. data/lib/fun_ci/console/branch_page.rb +9 -0
  14. data/lib/fun_ci/console/console_state.rb +22 -8
  15. data/lib/fun_ci/console/cursor.rb +22 -0
  16. data/lib/fun_ci/console/cursor_rows.rb +37 -0
  17. data/lib/fun_ci/console/job_message.rb +5 -4
  18. data/lib/fun_ci/console/job_order.rb +5 -3
  19. data/lib/fun_ci/console/job_row.rb +17 -0
  20. data/lib/fun_ci/console/job_rows.rb +14 -3
  21. data/lib/fun_ci/console/key_handler.rb +88 -51
  22. data/lib/fun_ci/console/question.rb +63 -0
  23. data/lib/fun_ci/console/run_message.rb +3 -3
  24. data/lib/fun_ci/console/view.rb +20 -6
  25. data/lib/fun_ci/jobs/job_run.rb +10 -9
  26. data/lib/fun_ci/persistence/active_runs.rb +47 -17
  27. data/lib/fun_ci/persistence/arrival.rb +18 -0
  28. data/lib/fun_ci/persistence/branch_visibility.rb +40 -0
  29. data/lib/fun_ci/persistence/database.rb +28 -2
  30. data/lib/fun_ci/persistence/hidden_row_tables.rb +24 -0
  31. data/lib/fun_ci/persistence/job_runs.rb +17 -7
  32. data/lib/fun_ci/persistence/job_visibility.rb +43 -0
  33. data/lib/fun_ci/persistence/null_recorder.rb +3 -0
  34. data/lib/fun_ci/persistence/pipeline_recorder.rb +22 -3
  35. data/lib/fun_ci/persistence/pipeline_run.rb +15 -4
  36. data/lib/fun_ci/persistence/stage_job.rb +13 -0
  37. data/lib/fun_ci/persistence/trunk_checks.rb +7 -6
  38. data/lib/fun_ci/pipeline/process_runner.rb +8 -7
  39. data/lib/fun_ci/pipeline/run_canceller.rb +1 -3
  40. data/lib/fun_ci/pipeline/slot.rb +12 -0
  41. data/lib/fun_ci/pipeline/slot_run.rb +20 -5
  42. data/lib/fun_ci/pipeline/slow_turns.rb +74 -0
  43. data/lib/fun_ci/pipeline/stale_pipeline_canceller.rb +1 -1
  44. data/lib/fun_ci/pipeline/trigger.rb +9 -1
  45. data/lib/fun_ci/pipeline/trigger_params.rb +7 -3
  46. data/lib/fun_ci/pipeline/turn_queue.rb +65 -0
  47. data/lib/fun_ci/pipeline/waiting_slots.rb +30 -0
  48. data/lib/fun_ci/pipeline/worktree_pool.rb +5 -2
  49. data/lib/fun_ci/pipeline/worktrees.rb +3 -0
  50. data/lib/fun_ci/trunk/check.rb +7 -2
  51. data/lib/fun_ci/version.rb +1 -1
  52. metadata +26 -11
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eb6518d38e67aecd470fe2c65227af6467e70cf60ef26ece496d0bb91301e80f
4
- data.tar.gz: a57fc48c3b2a1799baabf0f4477da9085c01d5406aa2762df8f5af603d49f203
3
+ metadata.gz: 24bb92ffb151c1e34a14ca8ceb306b9f084afd9dde62dad89905ed845af8c9a2
4
+ data.tar.gz: b1b3a83e020cbc3e0fe019ed827f4caed8be00d39341ae09bfb1a25b97c9520c
5
5
  SHA512:
6
- metadata.gz: ae8a1ce41d3fbb54a807509a001c9ffe72020fe586973dc74cd4b643708938920ec1cd920266c4a52c0e62c1a7f6d1e6e2c40e181b50d4b0de6925e94e65810b
7
- data.tar.gz: ebfc96602d16d8c89101e1dc016537366a3055b7d16aca410c9e1a3700126a59cc6015143e39559ea75935e00403f614c71eb11e34738fcc5c72a13e78af3e8c
6
+ metadata.gz: f99d506f53449c4aa359bc69d504b997603796ddcf1ec079d487edc78f367efa0988aecbc00a159ed716c0c55391e6e2c8c41237c539d0212bb6efce6fb5c3cc
7
+ data.tar.gz: 805ef236f3de05549e1fe898a6efcea0cdfd89b19ce2b8997e42d30d684868845591deaf0a85b9ec367b2fe7744d4ab87cb8b80217efd6ec4556d2be5e784592
data/CHANGELOG.md CHANGED
@@ -7,6 +7,79 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [2.5.0] - 2026-11-11
11
+
12
+ ### Added
13
+ - The console can put a branch or a daily or weekly job out of view. `h` on
14
+ a row asks how: `s` snoozes it until its next run, `i` ignores it until you
15
+ bring it back. The footer says how many rows are hidden, `a` shows them,
16
+ and `h` on a hidden one brings it back. This changes only what the console
17
+ shows on your machine: the branch and the job run as before, and `fun-ci
18
+ jobs`, `status` and `why` report them as before.
19
+ - Every line of `fun-ci events` has `at`, the time it happened in UTC: when a
20
+ run started, a stage finished, a run finished or was superseded, a check
21
+ against the trunk was made, and when a job was scheduled, started and
22
+ finished. It is `null` where fun-ci doesn't know: the end of a job whose
23
+ process died, and the scheduling of a job run kept by an earlier version.
24
+
25
+ ### Changed
26
+ - A newer commit no longer cancels a run whose slow suite has started. The
27
+ slow suite finishes, and the newer run's slow suite waits for it, shown as
28
+ `waiting`; a newer commit still cancels one that is waiting, and when
29
+ several wait, the newest commit's goes next. A waiting slow suite keeps no
30
+ other branch's run from getting a worktree. On a branch that takes commits
31
+ faster than its slow suite runs, slow suites were cancelled nearly every
32
+ time, and a `wait --need all --follow-branch` could wait until the commits
33
+ stopped. Now the newest commit's slow suite waits at most for the one
34
+ already running.
35
+ - A `fun-ci wait` without `--follow-branch` whose run a newer commit cancelled
36
+ runs the commit again, once, and waits on that run. Before, a commit landing
37
+ before the wait first looked at the run left the agent with exit 4 and no
38
+ verdict for the commit it asked about. A commit run again, by `wait` or by
39
+ `fun-ci trigger`, cancels no newer commit's run, and the console's row for
40
+ the branch stays with the newest commit.
41
+ - `fun-ci status` says which level a stage is not needed for, as in `(not
42
+ needed for --need fast)`. Plain `(not needed)` read as wrong while a `wait
43
+ --need all` was waiting on that very stage.
44
+
45
+ ### Fixed
46
+ - The console's header rests on the run that finished last, and its lamp
47
+ shows how that run went. Before, it took the first row on the board, which
48
+ is the one that most needs you, so a branch that failed days ago kept the
49
+ hazard sign and a red lamp up after every later pass. A hidden row shown
50
+ with `a` no longer counts either.
51
+ - The console opens with the cursor on the first row. Before, it had none
52
+ until `j` or `k`, so the keys that act on a row were missing at first
53
+ although the block sat on a row.
54
+ - A tall console with many projects left out every passed project, counted
55
+ beside the keys, when only some would not fit, and left the rest of the
56
+ screen empty. It now keeps as many of their lines as fit.
57
+ - On a terminal too short for every job, the job under the cursor stays on
58
+ screen; the rows furthest from it go first. Before, the rows below the
59
+ screen were cut, the cursor's among them.
60
+ - With more than one project on the board, a job's row cuts its project's
61
+ name to fit, down to its first letter, instead of dropping it, so two projects' jobs of the same name can be told apart. The question to
62
+ cancel a job names its project too.
63
+ - A terminal 20 rows high or less, or one whose job section left no room for
64
+ a branch, showed `No runs yet.` although there were runs. The console now
65
+ always sends the renderer at least one run, which fits what it can of it.
66
+ - `q` and Ctrl-C quit the console while the footer asks a question too.
67
+ Before, they were taken as no answer and did nothing.
68
+ - In the console, the cursor stays on its branch or job when the rows
69
+ reorder. Before, it kept its place on screen, so a row that moved left it on
70
+ another one, and an answer to `Cancel ...?` could cancel a run other than the
71
+ one the footer had named. A question now ends once its row leaves the view or
72
+ its run stops running.
73
+ - A job given a later turn to start is recorded as waiting from the moment a
74
+ commit starts it. Before, it was recorded as running for an instant first,
75
+ and anything reading the database just then, the console or `fun-ci
76
+ events`, took it for a job that had started.
77
+ - `fun-ci runs` no longer dies with "comparison of Integer with nil failed"
78
+ when it lists a run where the slow suite's process died and another stage
79
+ failed or ran over its budget. The died stage is now numbered in the order
80
+ the run's stages finished, and stages that 2.4.0 and earlier kept without
81
+ that number get one the next time fun-ci opens its database.
82
+
10
83
  ## [2.4.0] - 2026-10-19
11
84
 
12
85
  ### Added
data/README.md CHANGED
@@ -23,7 +23,7 @@ fun-ci init --everything
23
23
 
24
24
  This detects your project type, writes four stage scripts into `.fun-ci/`, installs a `post-commit` and a `pre-push` git hook, and checks the setup. It also adds a short section to your `AGENTS.md` (or `CLAUDE.md`, if that is the only one) telling coding agents what to do after a commit; run again after an upgrade, it brings that section up to date.
25
25
 
26
- `fun-ci init` has templates for Ruby, Gradle, Maven, Rust, Go, Elixir, Dart, Swift, PHP, .NET, Python, Deno, Bun, Node, Perl, and C or C++ built with CMake or make. [docs/stacks.md](docs/stacks.md) shows how it recognises each one and the commands it writes; `--stack go` picks one by name. In a project it doesn't recognise, such as a new one with no code yet, it writes placeholder scripts that pass, and `fun-ci check` warns about each one until you replace it. Fun-CI works with any project: the stages are shell scripts, so edit them to run whatever your project uses.
26
+ `fun-ci init` has templates for Ruby, Gradle, Maven, Rust, Go, Elixir, Dart, Swift, PHP, .NET, Python, Deno, Bun, Node, Perl, and C and C++ built with CMake or make. [docs/stacks.md](docs/stacks.md) shows how it recognises each one and the commands it writes; `--stack go` picks one by name. In a project it doesn't recognise, such as a new one with no code yet, it writes placeholder scripts that pass, and `fun-ci check` warns about each one until you replace it. Fun-CI works with any project: the stages are shell scripts, so edit them to run whatever your project uses.
27
27
 
28
28
  - `lint.sh`: linter and static analysis
29
29
  - `build.sh`: compile or build
@@ -51,7 +51,7 @@ After each commit, the `post-commit` hook starts the pipeline in the background
51
51
 
52
52
  `install-hooks` leaves a hook another tool wrote alone, and `fun-ci check` warns that no commit is tested until that hook calls fun-ci. Git LFS's own hooks are the exception: fun-ci writes its hooks in their place, and they run git-lfs's after fun-ci's, so LFS objects still reach the remote. After that, `git lfs install` says the hooks exist and exits 2, since it accepts no hook but its own; there is nothing for it to do. `git lfs update --force` would put git-lfs's back, leaving fun-ci out, until you run `fun-ci install-hooks` again.
53
53
 
54
- Each run happens in a git worktree of its own in fun-ci's state directory (`~/.local/state/fun-ci/projects/`, outside `.git/`, which tools such as Vite won't serve files from), checked out at the commit it tests, so you can keep editing while it runs. Ignored files such as `vendor/bundle` or `node_modules` stay in a worktree from one run to the next, which keeps builds quick. A worktree fun-ci has just made has none of them yet, and one nobody used for a day has them as they were then, so in such a run lint and build get the slow suite's five minutes rather than 30 seconds, and `fun-ci status` says so on their lines. A run's build outputs that git ignores stay too, and are only as right as the commit that made them, so a worktree that last tested another branch can hand a run outputs its commit wouldn't make. List those outputs in `.fun-ci/config`, such as `clean: [public/assets, dist]`, and fun-ci removes their ignored files when a worktree moves to a commit that doesn't descend from the one it last tested; that run's lint and build get the longer budget too. Two runs can go at once; set `worktree_slots: 3` in `.fun-ci/config` for more, and `fun-ci prune` removes the worktrees when you want the space back. A newer commit on a branch cancels the older run that is still going, unless an agent is waiting on it without `--follow-branch`.
54
+ Each run happens in a git worktree of its own in fun-ci's state directory (`~/.local/state/fun-ci/projects/`, outside `.git/`, which tools such as Vite won't serve files from), checked out at the commit it tests, so you can keep editing while it runs. Ignored files such as `vendor/bundle` or `node_modules` stay in a worktree from one run to the next, which keeps builds quick. A worktree fun-ci has just made has none of them yet, and one nobody used for a day has them as they were then, so in such a run lint and build get the slow suite's five minutes rather than 30 seconds, and `fun-ci status` says so on their lines. A run's build outputs that git ignores stay too, and are only as right as the commit that made them, so a worktree that last tested another branch can hand a run outputs its commit wouldn't make. List those outputs in `.fun-ci/config`, such as `clean: [public/assets, dist]`, and fun-ci removes their ignored files when a worktree moves to a commit that doesn't descend from the one it last tested; that run's lint and build get the longer budget too. Two runs can go at once; set `worktree_slots: 3` in `.fun-ci/config` for more, and `fun-ci prune` removes the worktrees when you want the space back. A newer commit on a branch cancels the older run that is still going, unless a `fun-ci wait` without `--follow-branch` is watching it or its slow suite has started. A slow suite that started always finishes, and the newer run's slow suite waits for it (`waiting` in `fun-ci status`), so on a branch that takes commits faster than its slow suite runs, slow verdicts keep coming and the commits in between skip theirs. A `fun-ci wait` without `--follow-branch` whose run was cancelled anyway, because the newer commit landed before the wait first looked, starts that commit again and waits for that run. A commit run again cancels nothing, and its branch's row in the console stays with the newest commit.
55
55
 
56
56
  Results are kept in SQLite under `$XDG_STATE_HOME/fun-ci/` (`~/.local/state/fun-ci/` by default), shared by every project on the machine.
57
57
 
@@ -119,12 +119,21 @@ Keys:
119
119
 
120
120
  - `j` and `k`, or the arrow keys, move the cursor down and up
121
121
  - `c` cancels the run under the cursor: one waiting to start at once, a running one once you answer `y` (`n` or `Esc` keeps it running); the footer offers it only while a run is running or waits to start. The cursor moves on past the last branch into the jobs, and `c` cancels a job too: one waiting its turn at once, a running one the same way; a cancelled job runs again on your next commit
122
+ - `h` hides the branch or job under the cursor, once you answer `s` (snooze) or `i` (ignore); `n` or `Esc` leaves it. `a` shows the hidden rows, and `h` on one of them brings it back (see [Hiding a branch or a job](#hiding-a-branch-or-a-job))
122
123
  - `q` quits
123
124
 
124
125
  The console is drawn in 24-bit colour when `COLORTERM` says the terminal has it (`truecolor` or `24bit`), and in 256 colours otherwise. The pictures above are the renderer's output replayed in a terminal emulator, set in Menlo; in your terminal the text is in your terminal's font.
125
126
 
126
127
  The drawing is done by a separate program, `fun-ci-renderer`, written in Rust. The gem for Linux (x86_64, aarch64, musl) and macOS (arm64, x86_64) includes it. On other Unix-like systems you get the plain gem, where every command except `console` works; install the renderer with `cargo install fun-ci-renderer` (Rust 1.88 or newer), or point `FUN_CI_RENDERER` at a copy you built. Windows is not supported, because fun-ci forks its background pipeline, but WSL runs the Linux gem. When something goes wrong between the two, the details are in `.fun-ci/console.log`.
127
128
 
129
+ ### Hiding a branch or a job
130
+
131
+ A branch you gave up on, or a job you already know is failing, can keep the top of the table red for days. Press `h` on its row and say how long it should stay out of view: `s` snoozes it until its next run, so it comes back when there is something new to see, and `i` ignores it until you bring it back. The footer counts the hidden rows. `a` shows them, pale, each saying how it was hidden, and `h` on one brings it back.
132
+
133
+ ![Hiding rows in the console: h on spike/old-cache, a branch that failed three days ago, asks whether to snooze it until its next run or ignore it until shown again; ignored, it leaves the table. h on the failing soak job snoozes it. a then shows both again, pale: spike/old-cache ignored, soak snoozed until its next run](docs/screenshots/hiding.webp)
134
+
135
+ Hiding changes only what your console shows. The branch and the job still run, and `fun-ci jobs`, `status` and `why` report them as before, so an agent waiting on a commit sees everything.
136
+
128
137
  ## Asking: commands for agents and scripts
129
138
 
130
139
  Every commit's output ends with the command that gets its verdict:
@@ -133,7 +142,7 @@ Every commit's output ends with the command that gets its verdict:
133
142
  fun-ci: testing 3f9c2ab. Verdict: fun-ci wait 3f9c2ab --need all --follow-branch
134
143
  ```
135
144
 
136
- The section `fun-ci init` writes into `AGENTS.md` tells an agent to run that command in the background after each commit. Agent harnesses wake the agent when a background command exits, so it hears about a failure without having to remember to ask. With `--follow-branch`, a newer commit on the branch cancels the older run, and the wait moves on to the newer run's verdict.
145
+ The section `fun-ci init` writes into `AGENTS.md` tells an agent to run that command in the background after each commit. Agent harnesses wake the agent when a background command exits, so it hears about a failure without having to remember to ask. With `--follow-branch`, a newer commit on the branch cancels the older run, and the wait moves on to the newer run's verdict. A slow suite that started is never cancelled, and the newest commit's waiting one goes next, so that wait ends within about two slow suites' time, however fast the commits come.
137
146
 
138
147
  `status` says where a commit's run stands and `wait` blocks until it is decided. Both exit with the verdict for the stages you need: `--need build` (lint and build), `fast` (the default) or `all` (the slow suite too).
139
148
 
@@ -143,7 +152,7 @@ The section `fun-ci init` writes into `AGENTS.md` tells an agent to run that com
143
152
  | 1 | A needed stage failed |
144
153
  | 2 | A needed stage ran over budget |
145
154
  | 3 | Still undecided (`wait --within 30s` gives up at your deadline) |
146
- | 4 | Superseded by a newer commit on the branch (`wait --follow-branch` moves on to it) |
155
+ | 4 | Superseded by a newer commit on the branch (`wait --follow-branch` moves on to it; a plain `wait` first runs the commit again, once) |
147
156
  | 5 | No run for the commit |
148
157
  | 6 | Passed, but conflicts with the trunk (only with `--trunk`) |
149
158
  | 64 | Usage error |
@@ -156,7 +165,7 @@ fun-ci: 2330979 "Add shipping to the cart total" on main
156
165
  lint passed 0.6s
157
166
  build passed 0.3s
158
167
  fast FAILED 0.3s
159
- slow passed 0.5s (not needed)
168
+ slow passed 0.5s (not needed for --need fast)
160
169
  fast failed:
161
170
  1) Failure:
162
171
  CartTest#test_total_includes_shipping [test/cart_test.rb:16]:
@@ -189,7 +198,7 @@ The output's last lines, from output-tail:
189
198
  The whole output: fun-ci why 2330979 fast --raw
190
199
  ```
191
200
 
192
- `fun-ci runs` lists recent runs one line each, and `fun-ci events --follow` prints each run's events as JSON lines as they happen, for a supervising agent or a status bar.
201
+ `fun-ci runs` lists recent runs one line each, and `fun-ci events --follow` prints each run's events as JSON lines as they happen, for a supervising agent or a status bar. Each line has `at`, the time it happened, so the gap between two events can be read off the lines.
193
202
 
194
203
  ### Where your commit stands against the trunk
195
204
 
@@ -201,7 +210,7 @@ fun-ci: f473fdb "Add shipping to the cart total" on feat/cart
201
210
  lint passed 0.2s
202
211
  build passed 0.3s
203
212
  fast passed 0.1s
204
- slow passed 0.2s (not needed)
213
+ slow passed 0.2s (not needed for --need fast)
205
214
  trunk conflicts origin/main 0e15acf, fetched just now, 1 ahead, 1 behind
206
215
  lib/cart.rb
207
216
  Conflicts with origin/main in 1 file. When the task is done, integrate: git pull origin main (or git pull --rebase origin main if the branch isn't shared)
@@ -6,11 +6,17 @@ module FunCi
6
6
  # (acceptance-tests.md, AT-9.16), oldest run first: a run started, each
7
7
  # stage that finished in the order it finished, a run that passed or
8
8
  # failed, a run a newer commit superseded, a check of its commit against
9
- # the trunk recorded or made again. The first look is at nothing.
9
+ # the trunk recorded or made again. The first look is at nothing. Each
10
+ # event says when it happened (`at`), as the database kept it.
10
11
  module Events
11
- # finished: [{ stage:, state:, seconds: }, ...] in the order they finished;
12
+ # When a run started, when its status last changed, and when the latest
13
+ # check of its commit against the trunk was made (nil without one):
14
+ # ISO 8601 times.
15
+ RunTimes = Data.define(:started, :changed, :checked)
16
+
17
+ # finished: [{ stage:, state:, seconds:, at: }, ...] in the order they finished;
12
18
  # trunk: the latest check of its commit, as status --json gives it, or nil.
13
- RunState = Data.define(:id, :sha, :branch, :status, :finished, :superseded_by, :trunk)
19
+ RunState = Data.define(:id, :sha, :branch, :status, :finished, :superseded_by, :trunk, :times)
14
20
 
15
21
  class RunState
16
22
  def initialize(trunk: nil, **) = super
@@ -31,7 +37,7 @@ module FunCi
31
37
 
32
38
  def self.of(run, was)
33
39
  about = { commit: run.sha, branch: run.branch }
34
- [*(was ? [] : [{ event: "run_started", **about }]),
40
+ [*(was ? [] : [{ event: "run_started", **about, at: run.times.started }]),
35
41
  *newly_finished(run, was).map { |stage| { event: "stage_finished", **about, **stage } },
36
42
  *checked(run, was, about), *ended(run, was, about)]
37
43
  end
@@ -46,14 +52,16 @@ module FunCi
46
52
  trunk = run.trunk
47
53
  return [] if trunk.nil? || trunk.values_at(:state, :sha) == was&.trunk&.values_at(:state, :sha)
48
54
 
49
- [{ event: "trunk_checked", **about, trunk: trunk }]
55
+ [{ event: "trunk_checked", **about, trunk: trunk, at: run.times.checked }]
50
56
  end
51
57
 
52
58
  def self.ended(run, was, about)
53
59
  return [] if was&.status == run.status
54
- return [{ event: "run_superseded", **about, by_commit: run.superseded_by }] if run.status == "cancelled"
55
60
 
56
- OUTCOMES.key?(run.status) ? [{ event: "run_finished", **about, state: OUTCOMES.fetch(run.status) }] : []
61
+ at = run.times.changed
62
+ return [{ event: "run_superseded", **about, by_commit: run.superseded_by, at: at }] if run.status == "cancelled"
63
+
64
+ OUTCOMES.key?(run.status) ? [{ event: "run_finished", **about, state: OUTCOMES.fetch(run.status), at: at }] : []
57
65
  end
58
66
  private_class_method :of, :newly_finished, :checked, :ended
59
67
  end
@@ -7,11 +7,17 @@ module FunCi
7
7
  # What happened to a project's daily and weekly job runs between two
8
8
  # looks at them (acceptance-tests.md, AT-13.23, AT-13.28), oldest first: a
9
9
  # job run was scheduled to start later (Jobs::Schedule), started, and
10
- # ended with its state and seconds. The first look is at nothing.
10
+ # ended with its state and seconds. The first look is at nothing. Each
11
+ # event says when it happened (`at`), as the database kept it.
11
12
  module JobEvents
13
+ # When a commit claimed the run (nil for a run kept before that was
14
+ # recorded), when it started and when it ended (nil until it has, and
15
+ # for a run whose process died): ISO 8601 times.
16
+ JobTimes = Data.define(:claimed, :started, :ended)
17
+
12
18
  # state: as Jobs::State says it; seconds: how long it ran, once it ended;
13
19
  # starts_at: when a run waiting its turn starts, nil for any other.
14
- JobState = Data.define(:id, :job, :cadence, :sha, :branch, :state, :seconds, :starts_at)
20
+ JobState = Data.define(:id, :job, :cadence, :sha, :branch, :state, :seconds, :starts_at, :times)
15
21
 
16
22
  # The states of a run that has not ended.
17
23
  GOING = %w[running due scheduled].freeze
@@ -31,9 +37,10 @@ module FunCi
31
37
  # A run first seen waiting was scheduled; one that started since the
32
38
  # last look started.
33
39
  def self.begun(run, was, about)
34
- return [{ event: "job_scheduled", **about, starts_at: run.starts_at }] if run.state == "scheduled" && !was
40
+ scheduled = { event: "job_scheduled", **about, starts_at: run.starts_at, at: run.times.claimed }
41
+ return [scheduled] if run.state == "scheduled" && !was
35
42
 
36
- started?(run, was) ? [{ event: "job_started", **about }] : []
43
+ started?(run, was) ? [{ event: "job_started", **about, at: run.times.started }] : []
37
44
  end
38
45
 
39
46
  # First seen past waiting, or past it now after it waited; one
@@ -48,7 +55,7 @@ module FunCi
48
55
  def self.ended(run, was, about)
49
56
  return [] if was&.state == run.state || GOING.include?(run.state)
50
57
 
51
- [{ event: "job_finished", **about, state: run.state, seconds: run.seconds }]
58
+ [{ event: "job_finished", **about, state: run.state, seconds: run.seconds, at: run.times.ended }]
52
59
  end
53
60
  private_class_method :of, :begun, :started?, :ended
54
61
  end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module FunCi
4
+ module Agent
5
+ # What a wait does once the run it waited on is decided
6
+ # (acceptance-tests.md, AT-9.12, AT-9.21): `:follow` the branch to the
7
+ # commit that superseded the run, `:run_again` its own commit, once, or
8
+ # `:stop` with the report.
9
+ module Onward
10
+ # report: the decided report, nil when no run turned up; ran_again:
11
+ # whether this wait has run its commit again already.
12
+ def self.decide(report, follow_branch:, ran_again:)
13
+ return :stop unless report&.superseded_by
14
+ return :follow if follow_branch
15
+ return :run_again if report.verdict == :superseded && !ran_again
16
+
17
+ :stop
18
+ end
19
+ end
20
+ end
21
+ end
@@ -83,6 +83,13 @@ module FunCi
83
83
  @stdout.puts "fun-ci: #{sha[0, 7]} was superseded; following #{report.branch} to #{report.superseded_by[0, 7]}."
84
84
  end
85
85
 
86
+ # Says the wait starts the commit `sha` again, which a newer one superseded; JSON has only the answer.
87
+ def running_again(sha, report)
88
+ return if @json
89
+
90
+ @stdout.puts "fun-ci: #{sha[0, 7]} was superseded by #{report.superseded_by[0, 7]}; running it again."
91
+ end
92
+
86
93
  # entries: [[report, age in words], ...], newest first.
87
94
  def runs(entries)
88
95
  return print_json(entries.map { |report, _| StatusJson.document(report) }) if @json
@@ -26,6 +26,9 @@ module FunCi
26
26
  run && of(run, need)
27
27
  end
28
28
 
29
+ # The id of the commit's newest run, or nil.
30
+ def latest_id(sha) = @runs.latest_of_commit(sha)&.fetch(:id)
31
+
29
32
  # Checks the commit against where the trunk is now, and keeps the check.
30
33
  def recheck_trunk(sha) = @details.recheck_trunk(sha)
31
34
 
@@ -38,7 +38,12 @@ module FunCi
38
38
  JobEvents::JobState.new(id: run[:id], job: run[:job], cadence: run[:cadence], sha: run[:commit_hash],
39
39
  branch: run[:branch], state: Jobs::State.of(run),
40
40
  seconds: Persistence::StageJob.elapsed_duration(run)&.round(1),
41
- starts_at: starts_at(run))
41
+ starts_at: starts_at(run), times: job_times(run))
42
+ end
43
+
44
+ def job_times(run)
45
+ JobEvents::JobTimes.new(claimed: stamp(run[:claimed_at]), started: stamp(run[:started_at]),
46
+ ended: stamp(run[:completed_at]))
42
47
  end
43
48
 
44
49
  # When a run waiting its turn starts, as an ISO time; nil for any other.
@@ -46,23 +51,36 @@ module FunCi
46
51
 
47
52
  def state_of(run)
48
53
  superseded_by = run[:status] == "cancelled" ? @runs.superseded_by(run) : nil
54
+ shown = recorded_check(run)
49
55
  Events::RunState.new(id: run[:id], sha: run[:commit_hash], branch: run[:branch], status: run[:status],
50
- finished: finished(run), superseded_by: superseded_by, trunk: trunk(run))
56
+ finished: finished(run), superseded_by: superseded_by,
57
+ trunk: shown && TrunkJson.document(shown), times: times(run, shown))
51
58
  end
52
59
 
53
- # The latest check recorded; a check still going has none yet.
54
- def trunk(run)
60
+ # The latest check recorded, as shown; nil for a check still going, which has none yet.
61
+ def recorded_check(run)
55
62
  shown = @trunk.for(run)
56
- shown&.check ? TrunkJson.document(shown) : nil
63
+ shown&.check ? shown : nil
64
+ end
65
+
66
+ def times(run, shown)
67
+ checked = shown&.check&.checked_at
68
+ Events::RunTimes.new(started: stamp(run[:created_at]), changed: stamp(run[:updated_at]),
69
+ checked: checked&.utc&.iso8601)
57
70
  end
58
71
 
72
+ # A time the database kept, as events say it: ISO 8601, UTC, to the second.
73
+ def stamp(kept) = kept && Time.parse(kept).utc.iso8601
74
+
59
75
  def finished(run)
60
76
  jobs = Persistence::StageJob.for_run(@db, run[:id]).select { |job| job[:finished_order] }
61
77
  stages = RunReport.stages(jobs).to_h { |stage| [stage.name, stage] }
62
- jobs.sort_by { |job| job[:finished_order] }.map { |job| facts(stages.fetch(job[:stage])) }
78
+ jobs.sort_by { |job| job[:finished_order] }.map { |job| facts(stages.fetch(job[:stage]), job) }
63
79
  end
64
80
 
65
- def facts(stage) = { stage: stage.name, state: stage.state, seconds: stage.seconds }
81
+ def facts(stage, job)
82
+ { stage: stage.name, state: stage.state, seconds: stage.seconds, at: stamp(job[:completed_at]) }
83
+ end
66
84
  end
67
85
  end
68
86
  end
@@ -20,7 +20,8 @@ module FunCi
20
20
  # about the verdict.
21
21
  def self.lines(report, trunk: false, jobs: CommitJobs::NONE)
22
22
  needed = Verdict::LEVELS.fetch(report.need)
23
- [header(report), *report.stages.map { |stage| stage_line(stage, needed) }, *Digest.lines(report.stages, needed),
23
+ [header(report), *report.stages.map { |stage| stage_line(stage, report.need) },
24
+ *Digest.lines(report.stages, needed),
24
25
  *job_lines(jobs), *trunk(report, trunk), *footer(report)]
25
26
  end
26
27
 
@@ -48,9 +49,12 @@ module FunCi
48
49
 
49
50
  def self.header(report) = %(fun-ci: #{report.sha[0, 7]} "#{report.subject}" on #{report.branch})
50
51
 
51
- def self.stage_line(stage, needed)
52
+ # need: the level the verdict is decided at. A stage past it says for
53
+ # which level it is not needed, since a wait may be at another.
54
+ def self.stage_line(stage, need)
52
55
  seconds = stage.seconds ? format("%6.1fs", stage.seconds) : " " * 7
53
- note = (needed.include?(stage.name) ? "" : " (not needed)") + longer(stage)
56
+ beyond = Verdict::LEVELS.fetch(need).include?(stage.name) ? "" : " (not needed for --need #{need})"
57
+ note = beyond + longer(stage)
54
58
  " #{stage.name.ljust(6)} #{WORDS.fetch(stage.state, stage.state).ljust(12)}#{seconds}#{note}".rstrip
55
59
  end
56
60
 
@@ -3,11 +3,12 @@
3
3
  require_relative "command_support"
4
4
  require_relative "output"
5
5
  require_relative "waiting"
6
+ require_relative "onward"
6
7
 
7
8
  module FunCi
8
9
  module Agent
9
10
  # `fun-ci wait [REV] [--need LEVEL] [--within DURATION] [--follow-branch] [--json]`
10
- # (acceptance-tests.md, AT-9.9 to AT-9.12).
11
+ # (acceptance-tests.md, AT-9.9 to AT-9.12, AT-9.21).
11
12
  class WaitCommand
12
13
  include CommandSupport
13
14
 
@@ -16,7 +17,10 @@ module FunCi
16
17
  # post-commit hook's run for a commit just made turns up well within it.
17
18
  GRACE_SECONDS = 5
18
19
  # The answer when no run turned up and the project can't start one.
19
- NOT_SET_UP = Data.define(:verdict).new(verdict: :unknown)
20
+ NOT_SET_UP = Data.define(:verdict, :superseded_by).new(verdict: :unknown, superseded_by: nil)
21
+ # A superseded commit started again: the report on its superseded run,
22
+ # that run's id, and when it was started again.
23
+ Again = Data.define(:report, :run_id, :since)
20
24
 
21
25
  def initialize(context)
22
26
  @context = context
@@ -35,13 +39,32 @@ module FunCi
35
39
 
36
40
  def deadline(options) = options.within && (@context.clock.now + options.within)
37
41
 
38
- # Follows a superseded run on to the commit that superseded it, when asked to.
39
42
  def wait_for(sha, options, deadline, output)
40
43
  report = Waiting.new(@context.clock, deadline: deadline) { poll(sha, options) }.until_decided
41
- return report unless options.follow_branch && report&.superseded_by
44
+ step = Onward.decide(report, follow_branch: options.follow_branch, ran_again: !@again.nil?)
45
+ onward = carry_out(step, sha, report, output)
46
+ onward ? wait_for(onward, options, deadline, output) : report
47
+ end
48
+
49
+ # The commit to wait on next, having done what `step` says (Onward).
50
+ def carry_out(step, sha, report, output)
51
+ case step
52
+ in :follow then follow(sha, report, output)
53
+ in :run_again then run_again(sha, report, output)
54
+ in :stop then nil
55
+ end
56
+ end
42
57
 
58
+ def follow(sha, report, output)
43
59
  output.following(sha, report)
44
- wait_for(report.superseded_by, options, deadline, output)
60
+ report.superseded_by
61
+ end
62
+
63
+ # The commit, once its pipeline is started again; nil when it can't be.
64
+ def run_again(sha, report, output)
65
+ @again = Again.new(report: report, run_id: reports.latest_id(sha), since: @context.clock.now)
66
+ output.running_again(sha, report)
67
+ sha if @context.pipeline.start(sha, report.branch)
45
68
  end
46
69
 
47
70
  def answer(sha, report, output)
@@ -56,9 +79,18 @@ module FunCi
56
79
  def poll(sha, options)
57
80
  @context.pipeline.watch(@context.db)
58
81
  reports.mark_waited(sha, @context.clock.now) unless options.follow_branch
82
+ return run_again_report(sha, options) if @again
83
+
59
84
  report_for(sha, options) || start_after_grace(sha)
60
85
  end
61
86
 
87
+ # The commit's new run once it turns up; the superseded run's report once it hasn't in time.
88
+ def run_again_report(sha, options)
89
+ return report_for(sha, options) if reports.latest_id(sha) != @again.run_id
90
+
91
+ @again.report if @context.clock.now - @again.since >= GRACE_SECONDS
92
+ end
93
+
62
94
  # Nil while waiting for a run; NOT_SET_UP once one can't be started.
63
95
  def start_after_grace(sha)
64
96
  @missing_since ||= @context.clock.now
@@ -9,9 +9,11 @@ require_relative "streak_counter"
9
9
  require_relative "trunk_marks"
10
10
  require_relative "cancelled_folding"
11
11
  require_relative "row_order"
12
+ require_relative "branch_page"
12
13
  require_relative "paging"
13
14
  require_relative "job_rows"
14
15
  require_relative "../persistence/active_jobs"
16
+ require_relative "../persistence/branch_visibility"
15
17
 
16
18
  module FunCi
17
19
  module Console
@@ -36,17 +38,29 @@ module FunCi
36
38
  # Pages by `page_size` from now on, loading at least one such page.
37
39
  def resize(page_size) = @paging.resize(page_size)
38
40
 
39
- # Whether there are branches beyond those `runs` loads.
40
- def more? = heads(@paging.limit + 1).size > @paging.limit
41
-
42
41
  # Records failed each slow suite whose process died (acceptance-tests.md, AT-8.3).
43
42
  def record_dead_slow_suites = @run_canceller.record_dead(@db)
44
43
 
45
- # The job section's rows (JobRows): the jobs of the projects among `runs`.
44
+ # The job section's rows (JobRows): the jobs of the projects among
45
+ # `runs`, those the user hid among them, marked.
46
46
  def jobs(runs)
47
47
  JobRows.new(@db).of(runs.map { |run| run[:project_path] }.uniq.compact, now: @clock.call)
48
48
  end
49
49
 
50
+ # Keeps the job of `row` (a JobRow) out of view from now: `snoozed`, until it runs again, or `ignored`.
51
+ def hide_job(row, kind)
52
+ Persistence::JobVisibility.new(@db).hide(row.project, row.name, kind, at: @clock.call)
53
+ end
54
+
55
+ def show_job(row) = Persistence::JobVisibility.new(@db).show(row.project, row.name)
56
+
57
+ # Keeps the branch of the run `row` out of view from now: `snoozed`, until its next run, or `ignored`.
58
+ def hide_run(row, kind)
59
+ Persistence::BranchVisibility.new(@db).hide(row[:project_path], row[:branch], kind, at: @clock.call)
60
+ end
61
+
62
+ def show_run(row) = Persistence::BranchVisibility.new(@db).show(row[:project_path], row[:branch])
63
+
50
64
  # Records failed each job whose process died (acceptance-tests.md, AT-13.6).
51
65
  def record_dead_jobs = @run_canceller.record_dead_jobs(@db)
52
66
 
@@ -56,9 +70,19 @@ module FunCi
56
70
 
57
71
  # One row per branch, its newest run, for the branches that most need you
58
72
  # and then those run most recently, in RowOrder: a run of cancelled
59
- # runs folded into one, with its stages and the branch's standing against the trunk.
60
- def runs
61
- RowOrder.of(heads(@paging.limit).map { |head| branch_row(head) })
73
+ # runs folded into one, with its stages, the branch's standing against
74
+ # the trunk, and how the user hid the branch (`hidden`, nil while in view).
75
+ # A hidden branch leaves its place to the next one: as many more are read, and the page keeps as many in view.
76
+ def runs = branch_page.runs
77
+
78
+ # The rows `runs` says, and whether there are branches in view beyond
79
+ # them, from one read: the hidden branches among those read, and a page
80
+ # of the others, the first.
81
+ def branch_page
82
+ hidden = Persistence::BranchVisibility.new(@db).hidden
83
+ in_view, out_of_view = heads_read(hidden)
84
+ rows = (out_of_view + in_view.first(@paging.limit)).map { |head| branch_row(head, hidden) }
85
+ BranchPage.new(runs: RowOrder.of(rows), more: in_view.size > @paging.limit)
62
86
  end
63
87
 
64
88
  # The projects among `runs` whose trunk is stale.
@@ -77,12 +101,23 @@ module FunCi
77
101
 
78
102
  private
79
103
 
80
- def heads(limit) = Persistence::PipelineRun.branch_heads(@db, limit: limit, among: RECENT_BRANCHES)
104
+ def heads(limit, more_among: 0)
105
+ Persistence::PipelineRun.branch_heads(@db, limit: limit, among: RECENT_BRANCHES + more_among)
106
+ end
107
+
108
+ # The heads in view and those hidden, of a page and one more in view.
109
+ def heads_read(hidden)
110
+ read = heads(@paging.limit + hidden.size + 1, more_among: hidden.size)
111
+ read.partition { |head| !hidden.key?(branch_of(head)) }
112
+ end
113
+
114
+ def branch_of(head) = head.values_at(:project_path, :branch)
81
115
 
82
- def branch_row(head)
83
- branch_runs = Persistence::PipelineRun.of_branch(@db, head[:project_path], head[:branch], limit: BRANCH_WINDOW)
116
+ def branch_row(head, hidden)
117
+ branch_runs = Persistence::PipelineRun.leading_to(@db, head, limit: BRANCH_WINDOW)
84
118
  row = CancelledFolding.fold(branch_runs).first
85
- enrich_with_stages(row.merge(trunk: TrunkMarks.new(@db).mark(branch_runs).first[:trunk]))
119
+ trunk = TrunkMarks.new(@db).mark(branch_runs).first[:trunk]
120
+ enrich_with_stages(row.merge(trunk: trunk, hidden: hidden[branch_of(head)]))
86
121
  end
87
122
 
88
123
  def enrich_with_stages(run)
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module FunCi
4
+ module Console
5
+ # A page of the board's branch rows (BoardData#runs), and whether there
6
+ # are more branches in view beyond it.
7
+ BranchPage = Data.define(:runs, :more)
8
+ end
9
+ end