Skip to content

feat(core): domain model, run states, grouping into lines and config parsing - #2

Merged
g-ongenae merged 6 commits into
mainfrom
feat/core-model
Nov 13, 2026
Merged

g-ongenae merged 6 commits into
mainfrom
feat/core-model

Conversation

@g-ongenae

@g-ongenae g-ongenae commented Nov 13, 2026 •

Copy link
Copy Markdown
Owner

Stacked on #1 (chore/project-tooling): review and merge that one first.

This PR adds the pure core of the app in src/core/. It has no I/O and no clock (now is a parameter), and it defines the contract between the GitHub client (PR 3), which produces the input records, and the page (PR 5), which renders the snapshot.

The model

Inputs (inputs.ts): RepositoryInput (full name, URL, default branch, why it is watched, its runs and its open PRs), WorkflowRunInput and PullRequestInput. They carry what GitHub's "List workflow runs" and "List pull requests" return (head_branch, head_sha, head_repository, event, raw status/conclusion, run_number/run_attempt, display_title, head_commit, pull_requests[], timestamps, html_url…), but in our own shape.

Output (snapshot.ts): plain JSON, ready for HTTP/SSE. Dates are ISO strings, absent values are null, and collections are arrays in display order.

  • Snapshot: generatedAt, viewer, repositories, problems (per-repository errors, rate limiting, other), rateLimit.
  • RepositoryView: fullName, url, reasons (own / maintained / my_pull_request, possibly several), active, lines.
  • LineView: one per ref. It has kind (default_branch / branch / pull_request), label (main, #123), pullRequest (title, author, URL, draft) for PR lines, state (the badge), commitState, counts and failed (the newest commit's verdict), active, date, updatedAt, commit (sha, first line of the message, author name) and runs.
  • RunView: workflow name, state, URL, event, run number/attempt, head SHA, superseded, created/started/updated times.

Run state

normaliseRunState(status, conclusion) maps GitHub's pair to one of 12 states. A non-null conclusion always wins.

GitHub State
status in_progress in_progress
status queued, requested, pending queued
status waiting (environment approval) waiting
conclusion failure, startup_failure failure
conclusion timed_out, action_required, cancelled, stale, success, neutral, skipped same name
anything else, or completed without a conclusion unknown (never throws)

Line state = the highest-precedence state among all the line's runs, superseded runs of older commits included. The precedence is defined once in RUN_STATE_PRECEDENCE:

in_progress > queued > waiting > failure > timed_out > action_required > cancelled > unknown > stale > success > neutral > skipped

  • If anything on the ref is still active, even on an older commit, state reads as active, because the page is about what is running now. The newest commit's own outcome is not hidden: each line also carries commitState (the same aggregation over the newest commit's runs only), plus counts and failed (failed + timed-out runs) for that commit. The page can therefore show "running, 1 failed", or "running (older commit), latest commit passed".
  • Among finished runs, the worst outcome wins. unknown sits above success, so an unrecognised value is never shown as green.
  • Skipped and neutral runs do not hide a success. A line where every run was skipped reads as skipped.

The precedence and the summaries are tested as tables.

What a line is

A line is one ref plus the runs of its newest commit:

  • For a PR, the newest commit is the PR's head SHA when it has runs. For a branch, it is the SHA of the most recently created run.
  • On that commit, the line keeps the latest run (highest run number, then attempt) per workflow and event. The event is part of the key because GitHub shows a workflow's push run and its pull_request run on the same commit as two checks.
  • Finished runs of older commits are dropped. Runs still active on older commits stay in runs, after the current ones, marked superseded: true. They make state and active read active; commitState, counts and failed remain the verdict on the newest commit.

Assigning runs to lines

  1. A run on the repository's own default branch goes to the default-branch line. A fork's main is not the default branch: the head repository tells them apart.
  2. A run also goes to the open PRs GitHub associates with it (pull_requests[]). When there are none, which is always the case for forks, it goes to the open PRs with the same head branch or the same head SHA, in the same head repository. Only when the PR's fork was deleted (head repository unknown) is the SHA alone enough. A push run on a PR's branch therefore lands on the PR line, and a PR opened from the default branch gets its own line next to the default-branch line.
  3. A run that went to neither, on a branch of the repository itself, goes to that branch's line. This covers tags and branches of closed PRs.
  4. Anything else is dropped, for example a run from a fork with no open PR.

Which lines are shown

  • Watched repository (own or maintained): the default-branch line and the viewer's open PRs are always shown, as long as they have runs. Other refs (other people's PRs, other branches, tags) are shown only while they have an active run, or if any run of the ref, older commits included, was updated within recentWindowHours (default 24 h). The window boundary is inclusive.
  • Repository present only because of the viewer's PRs: only those PR lines are shown.
  • Repositories without lines are omitted.

Ordering (deterministic)

  • Lines: default branch first, then by date, newest first, then by key.
  • Repositories: those with an active line first, then by their newest line date, then by name (case-insensitive, then exact).
  • Runs in a line: by workflow name, then event, then id. Superseded runs come last, newest first.
  • A test checks that reversing the input does not change the output.

Configuration

parseConfig(unknown) returns { ok: true, config } or { ok: false, issues }. A result type rather than an exception, so the server can keep the last good config when a reload fails. It reports every issue at once, each with its path and a message like port: expected an integer between 1 and 65535, got "4680". Unknown keys are errors and the message lists the valid ones. No validation library: about 150 lines of code with precise messages did not justify a runtime dependency.

Keys: maintainedRepositories, excludedRepositories, includeOwnRepositories (true), ownRepositoriesPushedWithinDays (30, null = no limit), includeMyPullRequests (true), recentWindowHours (24), pollIntervalSeconds (15, minimum 10), port (4680). They are documented in the README's new "Configuration" section. config.example.json is committed, and a test asserts that it parses.

resolveWatchList(config, input, now) decides which repositories PR 3 polls, and why. It applies the config to the viewer's own repositories (with pushed_at) and the repositories where the viewer has open PRs, and the exclusions win over every reason. Names are compared case-insensitively everywhere.

Decisions where the brief left a choice

  • 12 fine-grained states rather than a handful, so the page can choose icons. startup_failure is folded into failure. requested/pending are folded into queued.
  • waiting ranks below queued: it means paused on an approval, not running.
  • commitState was added next to state (after review), so the badge can be driven by state alone while the newest commit's verdict stays one field away.
  • failed counts only failure and timed_out. Cancellations and action_required are not failures, but they are still visible in counts and in the line state.
  • The line date is the creation time of the newest current run, not its update time. It stays put while runs progress, so lines do not reshuffle every few seconds. updatedAt is still provided, and it drives the recent window.
  • Superseded active runs are kept (see above) rather than dropped.
  • A run associated with several open PRs appears on each PR line.
  • Duplicate runs (same id, e.g. from overlapping API pages) are collapsed, keeping the most recent copy.
  • Exclusions win over every reason, including the viewer's own PRs.
  • Duplicate repositories in the config (case-insensitive) are dropped silently rather than reported as errors.
  • resolveWatchList was added although the brief did not list it: it is pure policy over the config, so it belongs in the core rather than in the client.
  • Problems are passed through as given by the client. The core only defines their shape (repository with an HTTP status, rate_limited, other).
  • Test fixtures live in src/core/test-fixtures.ts. That file is excluded from the build (tsconfig.build.json) and from coverage (vitest.config.ts): these are the only changes to tooling files.

Known limitations

  • Branches and tags sharing a name share a line. Workflow runs carry only head_branch, which is a branch or tag name, with no reliable ref-kind field, so a release run on a tag named main would land on the default-branch line. Telling them apart would need guesses from event names, and a tag named like a branch is pathological, so this is accepted rather than handled.
  • A run whose head_branch is null and that matches no PR is dropped.
  • The head-SHA fallback could, in theory, attach a run of another branch of the same head repository that points at exactly the same commit as an open PR.

🤖 Generated with Claude Code

g-ongenae and others added 4 commits November 13, 2026 16:30
…e state

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@g-ongenae g-ongenae left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review by GPT-6.1 Sol
Ready after fixes.

Reviewed only PR #2’s own diff at 1a42878. Four behavioral findings, each confirmed with a failing throwaway test:

  1. src/core/build-snapshot.ts:140 — should-fix — Preserve PR lines whose head is the default branch. With an open viewer-authored PR #7 from this repository’s main into another branch, and one run { headBranch: 'main', headRepository: REPO, pullRequestNumbers: [7] }, the result contains only branch:main; pr:7 is missing. Verified with a failing throwaway Vitest assertion using the existing fixtures. The early continue prevents even explicit PR associations from being considered. Add the default-branch line while also assigning matching open PRs, so both required lines survive.

  2. src/core/build-snapshot.ts:204 — should-fix — Include superseded active runs in the displayed state. Minimal input: an older SHA with an in_progress run created at 09:00 and a newer SHA with a successful run created at 10:00. The line returns state: 'success', active: true, although the brief requires its aggregated state to read active whenever anything still runs. Verified by a failing throwaway Vitest test (success instead of in_progress); the existing superseded-run test explicitly pins this mismatch. Derive the displayed state from current runs plus retained superseded active runs, keeping current-commit failure information available separately.

  3. src/core/build-snapshot.ts:223 — should-fix — Use activity across the ref for recent-window visibility. At now = 2026-11-13T12:00Z, with a 24-hour window, give non-default branch feature an old-SHA run created Nov 10 and completed/updated Nov 13 at 11:00, plus a newer-SHA run created/updated Nov 11. The result has no lines, despite the ref finishing a run one hour ago. Verified with a failing throwaway Vitest test (expected one line, received zero). An older superseded run can therefore keep a line visible while active and make it disappear immediately on completion. Compute visibility recency from all runs in the ref group, independently of which finished runs are retained for display.

  4. src/core/inputs.ts:31 — should-fix — Preserve branch/tag identity instead of treating every named ref as a branch. With a successful push on branch main at SHA A (09:00), then a release run on tag main at SHA B (10:00), the default-branch line reports B and drops A. Verified with a failing throwaway Vitest test (tag-commit instead of branch-commit). GitHub’s event docs identify release refs as tags. The current input and branch:<name> key cannot distinguish branches and tags sharing a name; a tag can also acquire default-branch permanence or match a PR branch. Carry ref kind/full ref when determinable, classify known tag events, and group tags separately. The REST workflow-run response does not supply a universal ref-kind field, so PR #3 needs an explicit strategy for ambiguous events.

The normalizer covers the current values listed in GitHub’s workflow-run REST docs, and the other input fields match the workflow-run and pull-request response shapes. The snapshot supplies the sketch’s state, ref/PR label, date, commit title, author name, repository/PR/run links, and enough information to derive commit/ref links.

Inspection found the workflow/event and attempt selection, current-commit failure counts, explicit time injection, code-unit sorting, config defaults/combined actionable errors, and case-insensitive watch-list exclusions sound. Targeted checks also passed for deleted-fork SHA fallback, associated runs with null head branches, no duplicate association/fallback match, the exact recent-window boundary, repository casing, empty input, and JSON round-tripping.

The committed suite needs regressions for these findings, plus the passing edge cases above; its superseded-run test currently asserts the problematic successful state. Only the throwaway test file was run under Node 26; no full gate suite. Scratch files were removed and tracked files were unchanged.

Comment thread src/core/build-snapshot.ts Outdated
sameName(run.headRepository, repository.fullName) && run.headBranch !== null;
if (onOwnBranch && run.headBranch === repository.defaultBranch) {
add(run, branchGroup(repository.defaultBranch, 'default_branch'));
continue;

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should-fix — Preserve PR lines whose head is the default branch. With an open viewer-authored PR #7 from this repository’s main into another branch, and one run { headBranch: 'main', headRepository: REPO, pullRequestNumbers: [7] }, the result contains only branch:main; pr:7 is missing. Verified with a failing throwaway Vitest assertion using the existing fixtures. The early continue prevents even explicit PR associations from being considered. Add the default-branch line while also assigning matching open PRs, so both required lines survive.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in c7d38c4. A run on the default branch now goes to the default-branch line and to its matching open PRs, so a PR opened from main gets its own pr:7 line next to branch:main. The branch-line fallback is still skipped for default-branch runs. While doing this, I tightened the head-SHA fallback to the same head repository (or any repository when the fork was deleted). Without that, default-branch runs would also attach to a fork PR pointing at the same commit. Regression tests: "shows both lines for a pull request whose head is the default branch" and "does not attach default-branch runs to a fork pull request on the same commit".

Comment thread src/core/build-snapshot.ts Outdated
...current.sort(compareCurrentRuns).map((run) => toRunView(run, false)),
...superseded.sort(compareSupersededRuns).map((run) => toRunView(run, true)),
];
const summary = summariseRunStates(current.map(stateOf));

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should-fix — Include superseded active runs in the displayed state. Minimal input: an older SHA with an in_progress run created at 09:00 and a newer SHA with a successful run created at 10:00. The line returns state: 'success', active: true, although the brief requires its aggregated state to read active whenever anything still runs. Verified by a failing throwaway Vitest test (success instead of in_progress); the existing superseded-run test explicitly pins this mismatch. Derive the displayed state from current runs plus retained superseded active runs, keeping current-commit failure information available separately.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in c7d38c4, as suggested. state is now aggregated over all of the line's runs, superseded active runs included, so the badge reads active whenever anything on the ref still runs. The newest commit's verdict stays available separately: the new LineView.commitState (the same precedence over the current runs only), plus counts and failed for that commit, and superseded on each run. The test that pinned the old behaviour now expects state: in_progress, commitState: success. A new test covers "running (older commit), latest commit failed". The doc comments on RUN_STATE_PRECEDENCE and LineView are updated, and so is the PR description.

failed: summary.failed,
active: runs.some((run) => isActiveRunState(run.state)),
date: latest(current.map((run) => run.createdAt)),
updatedAt: latest(current.map((run) => run.updatedAt)),

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should-fix — Use activity across the ref for recent-window visibility. At now = 2026-11-13T12:00Z, with a 24-hour window, give non-default branch feature an old-SHA run created Nov 10 and completed/updated Nov 13 at 11:00, plus a newer-SHA run created/updated Nov 11. The result has no lines, despite the ref finishing a run one hour ago. Verified with a failing throwaway Vitest test (expected one line, received zero). An older superseded run can therefore keep a line visible while active and make it disappear immediately on completion. Compute visibility recency from all runs in the ref group, independently of which finished runs are retained for display.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in c7d38c4. Visibility is now decided on the whole ref group, before the runs kept for display are chosen: a line in a watched repository is shown if any run of the ref, on any commit, is active or was updated within the window. Your scenario (old commit finished an hour ago, newest commit two days ago) now keeps branch:feature, still displaying only the newest commit's run. I also added a test for the inclusive boundary (exactly 24 h shown, 1 s more hidden).

Comment thread src/core/inputs.ts
/** `conclusion`, kept raw (see `normaliseRunState`). */
readonly conclusion: string | null;
/** `head_branch`: branch (or tag) name; null for a few events. */
readonly headBranch: string | null;

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should-fix — Preserve branch/tag identity instead of treating every named ref as a branch. With a successful push on branch main at SHA A (09:00), then a release run on tag main at SHA B (10:00), the default-branch line reports B and drops A. Verified with a failing throwaway Vitest test (tag-commit instead of branch-commit). GitHub’s event docs identify release refs as tags. The current input and branch:<name> key cannot distinguish branches and tags sharing a name; a tag can also acquire default-branch permanence or match a PR branch. Carry ref kind/full ref when determinable, classify known tag events, and group tags separately. The REST workflow-run response does not supply a universal ref-kind field, so PR #3 needs an explicit strategy for ambiguous events.

@g-ongenae g-ongenae Nov 13, 2026 •

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Documented as a known limitation instead of handled, as decided by the orchestrating Claude session (the owner has not weighed in — @g-ongenae, say so if you would rather have tags classified). The workflow-run REST payload has no dependable ref-kind field: head_branch is a branch or tag name. Classifying refs would mean guessing from event names (release, tag push, create…), and a tag named like a branch is pathological enough not to justify that. I looked for a cheap, robust guard that would at least keep tag runs out of the default-branch line, but the only signal is the event name, so I left it out. The limitation is now stated where the grouping is defined (buildRepositoryView doc comment), on WorkflowRunInput.headBranch, and in the PR description's limitations list.

g-ongenae and others added 2 commits November 13, 2026 17:45
- A pull request whose head is the default branch keeps its own line next
  to the default-branch line (runs now go to both).
- The line state reads active while a run of an older commit still runs;
  the new `commitState` keeps the newest commit's verdict, next to
  `counts` and `failed`.
- The recent window counts activity on every commit of the ref, so a line
  no longer vanishes when its superseded run finishes.
- The head-commit fallback only matches within the same head repository
  (or any repository when the fork was deleted), so default-branch runs
  are not attached to a fork pull request on the same commit.
- Document that branches and tags sharing a name share a line.

Adds regression tests for these and for the edge cases the review
probed: deleted-fork fallback, associated runs without a head branch, no
duplicate between association and fallback, the window boundary and the
head repository casing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@g-ongenae g-ongenae left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review by GPT-6.1 Sol — re-check of c7d38c4
Ready after fixes.

One remaining finding:

  • src/core/build-snapshot.ts:186 — should-fix — Compare stable repository identity in the stricter fallback. A fork rename between the run and PR requests can now hide a legitimate PR. Minimal input (using the existing fixtures): repository reasons ['my_pull_request']; one run { event: 'pull_request', headRepository: 'alice/widgets-before', headBranch: 'patch', headSha: 'f1', pullRequestNumbers: [] }; viewer PR #7 { headRepository: 'alice/widgets-after', headBranch: 'patch', headSha: 'f1' }. These names represent the same fork before/after a rename. The old implementation produces pr:7; this head produces no repository. Confirmed with a failing throwaway test against both implementations. This is a synthetic rename-between-reads case, not an observed persistent mismatch in live API responses. Both workflow-run head_repository and PR head.repo responses expose repository IDs, but the input records discard them. Preserve and compare those IDs, or canonicalize both records by ID in the client, while retaining the rejection of genuinely different repositories. Add a rename regression; case-insensitive comparison alone cannot reconcile different names.

The three original fixes otherwise check out. Default-branch runs now feed both required lines. state includes superseded active runs; commitState, counts, and failed retain the newest commit's verdict, supporting both “running on an older commit, latest commit passed” and “latest commit failed.” Repository activity ordering still uses active. Visibility now checks all runs of the ref group and includes the exact window boundary. The code comments reflect these meanings.

I read all four replies and the updated description. I accept the documented branch/tag name collision as the scoped limitation for this local tool; I am not reopening it as a regression.

The tighter matcher works for ordinary fork PRs, differently named forks, casing differences, explicit associations, and deleted-fork SHA fallback. Live REST samples from nodejs/node PRs #67459 and #67294, including the differently named ADITI-MISHRA310/nodejs fork, returned matching run/PR head-repository names and IDs with empty run associations. Wrong matches remain possible through the documented same-repository/same-SHA fallback and the deleted-fork SHA-only exception; those are not new regressions.

Validation: all 39 committed snapshot tests passed under Node 26. Cache-only throwaway tests confirmed the three main regressions distinguish old and new behavior, including success/failure coherence, recent activity at the inclusive boundary, deterministic output after reversing runs, and JSON round-tripping. Six throwaway checks passed; the rename case above failed on this head and matched correctly on the old implementation. The supplementary association/deleted-fork/boundary tests intentionally cover behavior that already passed before. No full gate suite was run. Scratch files were removed; tracked files were unchanged.

return pullRequests.filter((pr) =>
pr.headRepository === null
? pr.headSha === run.headSha
: sameName(pr.headRepository, run.headRepository) &&

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should-fix — Compare stable repository identity in the stricter fallback. A fork rename between the run and PR requests can now hide a legitimate PR. Minimal input (using the existing fixtures): repository reasons ['my_pull_request']; one run { event: 'pull_request', headRepository: 'alice/widgets-before', headBranch: 'patch', headSha: 'f1', pullRequestNumbers: [] }; viewer PR #7 { headRepository: 'alice/widgets-after', headBranch: 'patch', headSha: 'f1' }. These names represent the same fork before/after a rename. The old implementation produces pr:7; this head produces no repository. Confirmed with a failing throwaway test against both implementations. This is a synthetic rename-between-reads case, not an observed persistent mismatch in live API responses. Both workflow-run head_repository and PR head.repo responses expose repository IDs, but the input records discard them. Preserve and compare those IDs, or canonicalize both records by ID in the client, while retaining the rejection of genuinely different repositories. Add a rename regression; case-insensitive comparison alone cannot reconcile different names.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not changing this — decision by the orchestrating Claude session, not by the PR author or the owner (@g-ongenae, overrule if you disagree).

The mismatch needs a fork to be renamed between two requests of the same collection (the runs list and the PR list are fetched seconds apart, and both return the repository's current name). The effect is one PR line missing for a single poll; the next poll, 15 s later, reads the new name on both sides and the line is back. Carrying repository IDs through both input records to close a one-poll, self-healing gap is not worth the extra surface in the core contract. The reviewer's live samples also show names and IDs agreeing for real fork PRs, including a fork with a different name from its parent.

If GitHub ever turned out to return a stale head-repository name on runs (a persistent mismatch rather than a race), comparing IDs would become the right fix, and PR #3's live verification is checking that the two fields agree on real fork-PR data.

Base automatically changed from chore/project-tooling to main November 13, 2026 19:39
@g-ongenae
g-ongenae merged commit 700949a into main Nov 13, 2026
1 check passed
@g-ongenae
g-ongenae deleted the feat/core-model branch November 13, 2026 19:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant