Repository navigation
feat(core): domain model, run states, grouping into lines and config parsing - #2
Conversation
…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
left a comment
There was a problem hiding this comment.
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:
-
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’smaininto another branch, and one run{ headBranch: 'main', headRepository: REPO, pullRequestNumbers: [7] }, the result contains onlybranch:main;pr:7is missing. Verified with a failing throwaway Vitest assertion using the existing fixtures. The earlycontinueprevents even explicit PR associations from being considered. Add the default-branch line while also assigning matching open PRs, so both required lines survive. -
src/core/build-snapshot.ts:204— should-fix — Include superseded active runs in the displayed state. Minimal input: an older SHA with anin_progressrun created at 09:00 and a newer SHA with a successful run created at 10:00. The line returnsstate: 'success', active: true, although the brief requires its aggregated state to read active whenever anything still runs. Verified by a failing throwaway Vitest test (successinstead ofin_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. -
src/core/build-snapshot.ts:223— should-fix — Use activity across the ref for recent-window visibility. Atnow = 2026-11-13T12:00Z, with a 24-hour window, give non-default branchfeaturean 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. -
src/core/inputs.ts:31— should-fix — Preserve branch/tag identity instead of treating every named ref as a branch. With a successfulpushon branchmainat SHA A (09:00), then areleaserun on tagmainat SHA B (10:00), the default-branch line reports B and drops A. Verified with a failing throwaway Vitest test (tag-commitinstead ofbranch-commit). GitHub’s event docs identify release refs as tags. The current input andbranch:<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.
| sameName(run.headRepository, repository.fullName) && run.headBranch !== null; | ||
| if (onOwnBranch && run.headBranch === repository.defaultBranch) { | ||
| add(run, branchGroup(repository.defaultBranch, 'default_branch')); | ||
| continue; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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".
| ...current.sort(compareCurrentRuns).map((run) => toRunView(run, false)), | ||
| ...superseded.sort(compareSupersededRuns).map((run) => toRunView(run, true)), | ||
| ]; | ||
| const summary = summariseRunStates(current.map(stateOf)); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)), |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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).
| /** `conclusion`, kept raw (see `normaliseRunState`). */ | ||
| readonly conclusion: string | null; | ||
| /** `head_branch`: branch (or tag) name; null for a few events. */ | ||
| readonly headBranch: string | null; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
- 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
left a comment
There was a problem hiding this comment.
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 producespr: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-runhead_repositoryand PRhead.reporesponses 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) && |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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 (nowis 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),WorkflowRunInputandPullRequestInput. They carry what GitHub's "List workflow runs" and "List pull requests" return (head_branch,head_sha,head_repository,event, rawstatus/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 arenull, 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 haskind(default_branch/branch/pull_request),label(main,#123),pullRequest(title, author, URL, draft) for PR lines,state(the badge),commitState,countsandfailed(the newest commit's verdict),active,date,updatedAt,commit(sha, first line of the message, author name) andruns.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.in_progressin_progressqueued,requested,pendingqueuedwaiting(environment approval)waitingfailure,startup_failurefailuretimed_out,action_required,cancelled,stale,success,neutral,skippedcompletedwithout a conclusionunknown(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 inRUN_STATE_PRECEDENCE:in_progress>queued>waiting>failure>timed_out>action_required>cancelled>unknown>stale>success>neutral>skippedstatereads as active, because the page is about what is running now. The newest commit's own outcome is not hidden: each line also carriescommitState(the same aggregation over the newest commit's runs only), pluscountsandfailed(failed + timed-out runs) for that commit. The page can therefore show "running, 1 failed", or "running (older commit), latest commit passed".unknownsits above success, so an unrecognised value is never shown as green.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:
pushrun and itspull_requestrun on the same commit as two checks.runs, after the current ones, markedsuperseded: true. They makestateandactiveread active;commitState,countsandfailedremain the verdict on the newest commit.Assigning runs to lines
mainis not the default branch: the head repository tells them apart.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. Apushrun 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.Which lines are shown
recentWindowHours(default 24 h). The window boundary is inclusive.Ordering (deterministic)
date, newest first, then by key.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 likeport: 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.jsonis 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 (withpushed_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
startup_failureis folded intofailure.requested/pendingare folded intoqueued.waitingranks belowqueued: it means paused on an approval, not running.commitStatewas added next tostate(after review), so the badge can be driven bystatealone while the newest commit's verdict stays one field away.failedcounts onlyfailureandtimed_out. Cancellations andaction_requiredare not failures, but they are still visible incountsand in the line state.dateis 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.updatedAtis still provided, and it drives the recent window.resolveWatchListwas 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.repositorywith an HTTP status,rate_limited,other).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
head_branch, which is a branch or tag name, with no reliable ref-kind field, so areleaserun on a tag namedmainwould 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.head_branchis null and that matches no PR is dropped.🤖 Generated with Claude Code