Public: anyone can read this; the crew can change it.
An issue's page folds its history and closed comment threads; the open question stays visible #13063
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/13003-an-issue-s-page-folds-its-history-and-cl → main 11 commits fork 6 threads · 6 unresolved
docs/design/areas/comments.md +1
| @@ -8,3 +8,4 @@ A comment on an issue or pull, and the form that writes one. Both are a `card()` | ||
| 8 | 8 | - `.comment-body` — a comment's rendered markdown, always beside `.prose`: padded inside a `.comment` card, unpadded in a `.comment-row` (written by `commentCard()` in `src/web/comments.ts`); `reviewRows()` in `src/web/diff-view.ts` and `reviewEntry()` in `src/web/studio/change.ts`; styled in `src/web/style/components.ts` (tighter in a timeline event's card). |
| 9 | 9 | - `.comment-form` — the form that writes a comment: a textarea and its `.form-actions`. On a thread (`composer()`, also the reply box on a studio change) it is plain lines under the timeline, no `card`, spaced like the home composer; the floating tell box (`tell_here.ts`) passes `boxed` and so adds `card`. A review reply (`reviewRows()`) and the studio box (`studioApp()`) write their own `card comment-form`. Written by `composer()` and `editForm()` in `src/web/pages/thread.ts`, `reviewRows()` in `src/web/diff-view.ts` (a reply in a review thread) and `studioApp()` in `src/web/studio/app.ts` (the "Tell the crew" box); styled in `src/web/style/components.ts`, with its narrow-screen action line and its review-thread margin in `src/web/style/content.ts`. |
| 10 | 10 | - `.tl-earlier` — the line above a long thread's newest items, `Show N earlier items`, a plain link to `?all=1`. Written by `conversation()` in `src/web/pages/thread.ts`; styled in `src/web/style/components.ts` beside `.tl-item`, indented to the timeline's item column. |
| 11 | - `.tl-fold` — a plain `<details>` (id `history`) holding every timeline item before the newest comment, its summary the counts (`49 earlier comments · 3 events`). Written by `conversation()`; `client.ts` opens it when the URL hash is a `#c-…` inside it. |
docs/design/size-budget.json +10 −10
| @@ -1,30 +1,30 @@ | ||
| 1 | 1 | { |
| 2 | 2 | "/": { |
| 3 | "js": 21504, | |
| 3 | "js": 22016, | |
| 4 | 4 | "css": 44544 |
| 5 | 5 | }, |
| 6 | 6 | "/explore": { |
| 7 | "js": 21248, | |
| 7 | "js": 21760, | |
| 8 | 8 | "css": 44544 |
| 9 | 9 | }, |
| 10 | 10 | "/map": { |
| 11 | "js": 28160, | |
| 11 | "js": 28672, | |
| 12 | 12 | "css": 46080 |
| 13 | 13 | }, |
| 14 | 14 | "/:owner/:name": { |
| 15 | "js": 35072, | |
| 15 | "js": 35328, | |
| 16 | 16 | "css": 44544 |
| 17 | 17 | }, |
| 18 | 18 | "/changelog": { |
| 19 | "js": 26112, | |
| 19 | "js": 26368, | |
| 20 | 20 | "css": 44544 |
| 21 | 21 | }, |
| 22 | 22 | "/:owner/:name/next": { |
| 23 | "js": 23040, | |
| 23 | "js": 23296, | |
| 24 | 24 | "css": 44800 |
| 25 | 25 | }, |
| 26 | 26 | "/:owner/:name/space": { |
| 27 | "js": 29440, | |
| 27 | "js": 29696, | |
| 28 | 28 | "css": 45568 |
| 29 | 29 | }, |
| 30 | 30 | "/:owner/:name/space.json": { |
| @@ -32,15 +32,15 @@ | ||
| 32 | 32 | "css": 0 |
| 33 | 33 | }, |
| 34 | 34 | "/pricing": { |
| 35 | "js": 21248, | |
| 35 | "js": 21760, | |
| 36 | 36 | "css": 44544 |
| 37 | 37 | }, |
| 38 | 38 | "/forges/new": { |
| 39 | "js": 21248, | |
| 39 | "js": 21760, | |
| 40 | 40 | "css": 44544 |
| 41 | 41 | }, |
| 42 | 42 | "/claim": { |
| 43 | "js": 23808, | |
| 43 | "js": 24064, | |
| 44 | 44 | "css": 44544 |
| 45 | 45 | } |
| 46 | 46 | } |
docs/features/README.md +1
| @@ -89,6 +89,7 @@ Read with the guide page [Tell the crew](../guide-tell-the-crew.md). | ||
| 89 | 89 | - [](toolbar-tell.md) |
| 90 | 90 | - [](talk-resume-writes.md) |
| 91 | 91 | - [](act-now.md) |
| 92 | - [](thread-fold.md) | |
| 92 | 93 | - [](crew-roles.md) |
| 93 | 94 | - [](ask-settles.md) |
| 94 | 95 | - [](ask-filters.md) |
docs/features/thread-fold.md added +11
| @@ -0,0 +1,11 @@ | ||
| 1 | # A thread folds its settled history (#13003) | |
| 2 | ||
| 3 | An issue's or a pull's conversation opens on what still needs someone: the opening post, the newest comment and whatever followed it, every question still waiting for its answer, and the composer. The settled history before the newest comment sits in plain `<details class="tl-fold">` folds, each with its counts on the summary ("49 earlier comments · 3 events"). | |
| 4 | ||
| 5 | - What stays out of a fold: the newest comment and everything after it, and any entry marked `open` (`Entry.open`, `src/web/pages/thread.ts`). On a pull that is a request for changes that is its reviewer's newest verdict while the pull is open (`standingRequests`, `src/web/studio/change.ts`). A later plain comment from that reviewer does not withdraw it. An approval does. A standing entry splits the history into one fold before it and one after it. A run of fewer than two settled entries is not folded. | |
| 6 | - Resolved line threads on Files already collapse to one line on their own (`src/web/diff-view.ts`). Issue comments have no thread or resolution state, so for an issue the newest comment is the visible question. | |
| 7 | - Long threads: past the newest 50 comments the page still links `?all=1` ("Show N earlier items"). The fold only covers what is on the page. | |
| 8 | - Deep links: `#c-<id>` to a folded comment opens its fold and scrolls to it (`src/web/fold.ts`, appended to `shellJs`; it reads `location` only on a page that has a fold, and opens again on `hashchange`). | |
| 9 | - Without JavaScript: `.tl-fold:has(:target)::details-content { content-visibility: visible; }` shows a fold's content while the linked comment is inside it. That needs `:has()` and `::details-content`: Chrome/Edge 131+, Safari 18.4+, Firefox 143+. In an older browser with script off, the link lands on the closed fold, and the comment is one click on its summary away. Nobody has checked this rule in a real browser yet. The test only checks that the rule ships. | |
| 10 | - Terminal and MCP: rendering only. The terminal and the API return whole threads, so they have nothing to fold. | |
| 11 | - Tests: `test/thread-window.test.ts`. |
src/web/client.ts +5 −4
| @@ -15,6 +15,7 @@ import { keyDecisionJs } from "./key_decision.ts"; | ||
| 15 | 15 | import { actNowJs } from "./act_now.ts"; |
| 16 | 16 | import { FORM_BUSY_JS } from "./form_busy.ts"; |
| 17 | 17 | import { pickJs } from "./pick.ts"; |
| 18 | import { foldJs } from "./fold.ts"; | |
| 18 | 19 | import { imageViewJs } from "./render/image.ts"; |
| 19 | 20 | import { STAGE_BADGE_JS } from "./stage-row.ts"; |
| 20 | 21 | import { overlayHostJs } from "./overlay_host.ts"; |
| @@ -201,9 +202,9 @@ export const openFoldJs = /* js */ `(function(){function o(){var h=location.hash | ||
| 201 | 202 | /** |
| 202 | 203 | * A run's log, live, painted in the studio's own five words. The page |
| 203 | 204 | * renders every line already written; for a run still going, this appends |
| 204 | * each line from the page's one event stream the moment it is written. \`data-cap\` on \`#run-log\` bounds how many lines a long-running | |
| 205 | * agent can pile into the DOM: past it, the oldest line is dropped as a new | |
| 206 | * one arrives, so an hour-long run never grows without bound. | |
| 205 | * each line from the page's one event stream the moment it is written. \`data-cap\` on \`#run-log\` | |
| 206 | * bounds how many lines a long-running agent can pile into the DOM: past it, the oldest line is | |
| 207 | * dropped as a new one arrives, so an hour-long run never grows without bound. | |
| 207 | 208 | */ |
| 208 | 209 | export const studioRunJs = /* js */ ` |
| 209 | 210 | (function () { |
| @@ -2225,7 +2226,7 @@ const shellCore = /* js */ ` | ||
| 2225 | 2226 | `; |
| 2226 | 2227 | |
| 2227 | 2228 | /** The shell and the one script that makes actions answer at once (`act_now.ts`). */ |
| 2228 | export const shellJs = `${shellCore}\n${actNowJs}\n${pickJs}\n${FORM_BUSY_JS}`; | |
| 2229 | export const shellJs = `${shellCore}\n${actNowJs}\n${pickJs}\n${foldJs}\n${FORM_BUSY_JS}`; | |
| 2229 | 2230 | |
| 2230 | 2231 | /** |
| 2231 | 2232 | * Live regions. A page marks the parts of itself that change while it is |
src/web/fold.ts added +22
| @@ -0,0 +1,22 @@ | ||
| 1 | /** | |
| 2 | * A deep link to a comment inside the thread's history fold opens the fold. | |
| 3 | * Without script the same link still lands: `.tl-fold:has(:target)` shows the | |
| 4 | * fold's content while the target is inside it (see style/components.ts), so | |
| 5 | * the fold is closed only when nothing in it is being asked for. | |
| 6 | * Reads `location` only on a page that has a fold. | |
| 7 | */ | |
| 8 | export const foldJs = /* js */ ` | |
| 9 | (function () { | |
| 10 | if (!document.querySelector('details.tl-fold')) return; | |
| 11 | function openFold() { | |
| 12 | var id; | |
| 13 | try { id = decodeURIComponent(location.hash.slice(1)); } catch (err) { return; } | |
| 14 | if (id.indexOf('c-') !== 0) return; | |
| 15 | var el = document.getElementById(id); | |
| 16 | var fold = el && el.closest ? el.closest('details.tl-fold') : null; | |
| 17 | if (fold && !fold.open) { fold.open = true; el.scrollIntoView(); } | |
| 18 | } | |
| 19 | window.addEventListener('hashchange', openFold); | |
| 20 | openFold(); | |
| 21 | })(); | |
| 22 | `; |
src/web/pages/thread.ts +56 −3
| @@ -148,8 +148,13 @@ export function threadContext( | ||
| 148 | 148 | export interface Entry { |
| 149 | 149 | at: string; |
| 150 | 150 | node: Html; |
| 151 | /** A conversation comment: the window is cut on these (`commentAnchor`, core/issues.ts, counts the same). */ | |
| 151 | /** | |
| 152 | * A conversation comment: the window is cut on these (`commentAnchor`, core/issues.ts, counts the | |
| 153 | * same). | |
| 154 | */ | |
| 152 | 155 | comment?: true; |
| 156 | /** A question still waiting for its answer (a standing request for changes): never folded. */ | |
| 157 | open?: true; | |
| 153 | 158 | } |
| 154 | 159 | |
| 155 | 160 | const EVENT_LOOK: Record<string, { icon: IconName; tone: Tone; verb: string }> = |
| @@ -259,6 +264,16 @@ function stateEvents(ctx: Ctx, repo: Repo, issue: Issue): Entry[] { | ||
| 259 | 264 | * its own line: `interrupted: provider limit, resumes 02:00 UTC`. Not a |
| 260 | 265 | * park and not a comment — a comment on an assigned issue starts a run. |
| 261 | 266 | */ |
| 267 | /** "49 earlier comments · 3 events": what a fold holds, on its summary. */ | |
| 268 | export function foldCounts(entries: readonly Entry[]): string { | |
| 269 | const comments = entries.filter((e) => e.comment).length; | |
| 270 | const other = entries.length - comments; | |
| 271 | const plural = (n: number, w: string): string => `${String(n)} ${w}${n === 1 ? "" : "s"}`; | |
| 272 | return [comments > 0 ? plural(comments, "earlier comment") : "", other > 0 ? plural(other, "event") : ""] | |
| 273 | .filter(Boolean) | |
| 274 | .join(" · "); | |
| 275 | } | |
| 276 | ||
| 262 | 277 | function interruptionEntries(ctx: Ctx, issue: Issue): Entry[] { |
| 263 | 278 | return interruptionsOn(ctx.app.db, issue.id).map((run) => ({ |
| 264 | 279 | at: run.at, |
| @@ -270,7 +285,10 @@ function interruptionEntries(ctx: Ctx, issue: Issue): Entry[] { | ||
| 270 | 285 | })); |
| 271 | 286 | } |
| 272 | 287 | |
| 273 | /** The forge's own line where a vision pull landed without an admin: the direction was kept as it was. */ | |
| 288 | /** | |
| 289 | * The forge's own line where a vision pull landed without an admin: the direction was kept as it | |
| 290 | * was. | |
| 291 | */ | |
| 274 | 292 | function forgeEntries(ctx: Ctx, repo: Repo, issue: Issue): Entry[] { |
| 275 | 293 | if (issue.kind !== "pull") return []; |
| 276 | 294 | return listEvents(ctx.app.db, { repoId: repo.id, kind: "repo.vision_kept", limit: 50 }) |
| @@ -399,6 +417,41 @@ export function conversation( | ||
| 399 | 417 | <a href="${ctx.url.pathname}?${more.toString()}">Show ${String(hidden)} earlier items</a> |
| 400 | 418 | </p>`; |
| 401 | 419 | |
| 420 | // Everything before the newest comment folds, with its counts; the newest | |
| 421 | // comment, whatever followed it, and the composer stay in view, and so does | |
| 422 | // every entry still waiting for an answer (`Entry.open`): the folds are the | |
| 423 | // runs of settled history between those. The items stay in the page (a deep | |
| 424 | // link `#c-…` opens its fold, `fold.ts`), and a fold is plain <details>. | |
| 425 | let newest = -1; | |
| 426 | for (let i = shown.length - 1; i >= 0; i--) { | |
| 427 | if (shown[i]!.comment) { | |
outdated
Principle 1/8 and JS-off: a deep link to a folded comment does nothing without script. Give a no-JS path (see review body). |
||
| 428 | newest = i; | |
| 429 | break; | |
| 430 | } | |
| 431 | } | |
| 432 | const body: Html[] = []; | |
| 433 | let run: Entry[] = []; | |
| 434 | let first = true; | |
| 435 | const flush = (): void => { | |
| 436 | if (run.length < 2) body.push(...run.map((e) => e.node)); | |
| 437 | else { | |
| 438 | body.push(html`<details class="tl-fold"${first ? html` id="history"` : null}> | |
| 439 | <summary class="muted small">${foldCounts(run)}</summary> | |
| 440 | ${run.map((e) => e.node)} | |
| 441 | </details>`); | |
| 442 | first = false; | |
| 443 | } | |
| 444 | run = []; | |
| 445 | }; | |
| 446 | shown.forEach((e, i) => { | |
| 447 | if (i < newest && !e.open) run.push(e); | |
| 448 | else { | |
| 449 | flush(); | |
| 450 | body.push(e.node); | |
| 451 | } | |
| 452 | }); | |
| 453 | flush(); | |
| 454 | ||
| 402 | 455 | const opening = tlComment( |
| 403 | 456 | commentCard({ |
| 404 | 457 | id: "", |
| @@ -417,7 +470,7 @@ export function conversation( | ||
| 417 | 470 | node: html`<div class="timeline" id="conversation"> |
| 418 | 471 | ${opening}${when(options.editAction, (action) => |
| 419 | 472 | editForm(issue, action, ctx.url.searchParams.get("edit") === "1"), |
| 420 | )}${planCard(ctx.app.db, issue)}${earlier}${shown.map((e) => e.node)} | |
| 473 | )}${planCard(ctx.app.db, issue)}${earlier}${body} | |
| 421 | 474 | </div>`, |
| 422 | 475 | lastCommentId: comments.length > 0 ? comments[comments.length - 1]!.id : "", |
| 423 | 476 | }; |
src/web/studio/change.ts +29 −5
| @@ -178,6 +178,29 @@ export function wallCard(wall: Wall, act?: string): Html { | ||
| 178 | 178 | * current position, and a dismissed approval that still looks like an |
| 179 | 179 | * approval is exactly how a review gate becomes decorative. |
| 180 | 180 | */ |
| 181 | /** | |
Non-blocking: same slip. The comment above ("a dismissed approval that still looks like an approval...") documents reviewEntry, but standingRequests now sits between it and reviewEntry. Move standingRequests above that block. |
||
| 182 | * Each review, and whether it is a question still waiting: a request for | |
| 183 | * changes that is its reviewer's newest verdict (a plain comment does not | |
| 184 | * withdraw it) on a pull still open. Those stay | |
| 185 | * out of the conversation's history fold (`Entry.open`). | |
| 186 | */ | |
| 187 | export function standingRequests( | |
| 188 | reviews: readonly Review[], | |
| 189 | pullOpen: boolean, | |
| 190 | ): { review: Review; open: boolean }[] { | |
| 191 | const newest = new Map<string, string>(); | |
| 192 | for (const r of reviews) { | |
| 193 | if (r.state === "commented") continue; | |
| 194 | const seen = newest.get(r.authorId); | |
| 195 | const was = seen === undefined ? undefined : reviews.find((x) => x.id === seen); | |
| 196 | if (was === undefined || was.createdAt <= r.createdAt) newest.set(r.authorId, r.id); | |
| 197 | } | |
| 198 | return reviews.map((review) => ({ | |
| 199 | review, | |
| 200 | open: pullOpen && review.state === "changes_requested" && newest.get(review.authorId) === review.id, | |
| 201 | })); | |
| 202 | } | |
| 203 | ||
| 181 | 204 | function reviewEntry( |
| 182 | 205 | review: Review, |
| 183 | 206 | headOid: string, |
| @@ -340,8 +363,8 @@ function conflictWords(baseBranch: string, files: readonly string[]): string { | ||
| 340 | 363 | } |
| 341 | 364 | |
| 342 | 365 | /** |
| 343 | * GET /:owner/:name/pulls/:number, for every repository and every viewer. An older `?rc=` link (an inline comment form | |
| 344 | * on the diff) is handed on to the Files step, where the diff now lives. | |
| 366 | * GET /:owner/:name/pulls/:number, for every repository and every viewer. An older `?rc=` link (an | |
| 367 | * inline comment form on the diff) is handed on to the Files step, where the diff now lives. | |
| 345 | 368 | */ |
| 346 | 369 | export async function pullPage(ctx: Ctx): Promise<Response> { |
| 347 | 370 | const found = pullContext(ctx); |
| @@ -730,9 +753,10 @@ async function changeConversation( | ||
| 730 | 753 | ); |
| 731 | 754 | const talk = conversation(ctx, repo, pull, { |
| 732 | 755 | openVerb: "opened this", |
| 733 | extra: reviews.map((review) => | |
| 734 | reviewEntry(review, headOid, glyph, reviewerMarks), | |
| 735 | ), | |
| 756 | extra: standingRequests(reviews, pull.state === "open" && pull.mergedAt === null).map(({ review, open }) => ({ | |
| 757 | ...reviewEntry(review, headOid, glyph, reviewerMarks), | |
| 758 | ...(open ? { open: true as const } : {}), | |
| 759 | })), | |
| 736 | 760 | editAction: |
| 737 | 761 | mayEditIssue(ctx.app, repo, pull, ctx.auth.user).ok && !mirrored |
| 738 | 762 | ? `${thread}/edit` |
src/web/style/components.ts +3
| @@ -1024,6 +1024,9 @@ html[data-overlay] { overflow: hidden; } | ||
| 1024 | 1024 | min-height: 32px; |
| 1025 | 1025 | } |
| 1026 | 1026 | .tl-earlier { margin: 0; padding-left: 36px; color: var(--muted-fg); font-size: 13px; } |
| 1027 | .tl-fold { margin: 0 0 8px; } | |
| 1028 | .tl-fold:has(:target)::details-content { content-visibility: visible; } | |
| 1029 | .tl-fold > summary { cursor: pointer; padding: 8px 0 8px 32px; } | |
| 1027 | 1030 | .tl-item[data-kind="comment"] { padding-bottom: 16px; } |
| 1028 | 1031 | .tl-item[data-kind="event"] > .card { flex-basis: 100%; margin: 4px 0 0; color: var(--fg); font-size: 14px; } |
| 1029 | 1032 | .tl-item[data-kind="event"] > .comment-body { flex-basis: 100%; min-width: 0; margin: 4px 0 0; padding: 0; color: var(--fg); font-size: 14px; } |
test/thread-window.test.ts +107 −1
| @@ -6,6 +6,14 @@ import { openPull } from "../src/actions/pulls.ts"; | ||
| 6 | 6 | import { commitToBranch } from "../src/actions/repos.ts"; |
| 7 | 7 | |
| 8 | 8 | import { commentAnchor, getIssue, listComments } from "../src/core/issues.ts"; |
| 9 | import { foldJs } from "../src/web/fold.ts"; | |
| 10 | import { shellJs } from "../src/web/client.ts"; | |
| 11 | import { css } from "../src/web/style.ts"; | |
| 12 | import { conversation, type Entry } from "../src/web/pages/thread.ts"; | |
| 13 | import { standingRequests } from "../src/web/studio/change.ts"; | |
| 14 | import { html } from "../src/web/html.ts"; | |
| 15 | import type { Ctx } from "../src/http/context.ts"; | |
| 16 | import type { Review } from "../src/core/reviews.ts"; | |
| 9 | 17 | import { candidatesFor } from "../src/feed/items.ts"; |
| 10 | 18 | |
| 11 | 19 | let f: SnappyFixture; |
| @@ -81,7 +89,8 @@ test("state lines among the newest comments do not move the edge: the anchor sti | ||
| 81 | 89 | const added = addComment(f.app, f.owner, repo, edge, `edge comment ${i}`); |
| 82 | 90 | if (!added.ok) throw new Error(String(added.error)); |
| 83 | 91 | said.push(added.value.id); |
| 84 | // A close and a reopen after every fifth comment, so state lines sit between and after the edge. | |
| 92 | // A close and a reopen after every fifth comment, so state lines sit between and after the | |
| 93 | // edge. | |
| 85 | 94 | if (i % 5 === 4) { |
| 86 | 95 | setIssueState(f.app, f.owner, repo, edge, "closed"); |
| 87 | 96 | setIssueState(f.app, f.owner, repo, edge, "open"); |
| @@ -126,3 +135,100 @@ test("a pull thread windows too, and the link keeps the page's other query", asy | ||
| 126 | 135 | const all = await (await fetch(`${url}?diff=0&all=1`, { headers: { cookie: f.ownerCookie } })).text(); |
| 127 | 136 | expect(all.match(/class="tl-item" id="c-/g)?.length).toBe(70); |
| 128 | 137 | }); |
| 138 | ||
| 139 | test("everything before the newest comment folds with its counts; the newest stays out of the fold", async () => { | |
| 140 | const html = await get(); | |
| 141 | const fold = html.match(/<details class="tl-fold" id="history">([\s\S]*?)<\/details>/); | |
outdated
This asserts source text, not behaviour; it would pass with a broken opener. Drive the page script with a stub location and assert fold.open. |
||
| 142 | expect(fold).not.toBeNull(); | |
| 143 | expect(fold![1]).toContain("49 earlier comments"); | |
| 144 | expect(fold![1]).toContain("comment number 298"); | |
| 145 | expect(fold![1]).not.toContain("comment number 299"); | |
| 146 | expect(html.indexOf("comment number 299")).toBeGreaterThan(html.indexOf("</details>")); | |
| 147 | }); | |
| 148 | ||
| 149 | /** Run the fold script against a stub page; returns what it did. */ | |
| 150 | function runFold(o: { fold: boolean; hash: string; inside: string[]; outside: string[] }) { | |
| 151 | const log = { hashReads: 0, opened: false, listener: "" }; | |
| 152 | const fold = { open: false }; | |
| 153 | const mk = (inFold: boolean) => ({ | |
| 154 | closest: () => (inFold ? fold : null), | |
| 155 | scrollIntoView: () => {}, | |
| 156 | }); | |
| 157 | const document = { | |
| 158 | querySelector: () => (o.fold ? fold : null), | |
| 159 | getElementById: (id: string) => (o.inside.includes(id) ? mk(true) : o.outside.includes(id) ? mk(false) : null), | |
| 160 | }; | |
| 161 | const location = { | |
| 162 | get hash() { | |
| 163 | log.hashReads++; | |
| 164 | return o.hash; | |
| 165 | }, | |
| 166 | }; | |
| 167 | const window = { addEventListener: (name: string) => (log.listener = name) }; | |
| 168 | new Function("document", "location", "window", foldJs)(document, location, window); | |
| 169 | log.opened = fold.open; | |
| 170 | return log; | |
| 171 | } | |
| 172 | const page = { inside: ["c-in"], outside: ["c-out"] }; | |
| 173 | ||
| 174 | test("the fold script opens the fold for a hash inside it, and only then", () => { | |
| 175 | expect(runFold({ fold: true, hash: "#c-in", ...page }).opened).toBe(true); | |
| 176 | expect(runFold({ fold: true, hash: "#c-out", ...page }).opened).toBe(false); | |
| 177 | expect(runFold({ fold: true, hash: "#other", ...page }).opened).toBe(false); | |
| 178 | expect(runFold({ fold: true, hash: "#c-%E0%A4%A", ...page }).opened).toBe(false); | |
| 179 | expect(runFold({ fold: true, hash: "", ...page }).listener).toBe("hashchange"); | |
| 180 | }); | |
| 181 | ||
| 182 | test("with no fold on the page the script reads no location", () => { | |
| 183 | const log = runFold({ fold: false, hash: "#c-in", ...page }); | |
| 184 | expect(log.hashReads).toBe(0); | |
| 185 | expect(log.opened).toBe(false); | |
| 186 | }); | |
| 187 | ||
| 188 | test("without script the target still shows: the fold's content is visible while it holds the target", () => { | |
| 189 | expect(css).toContain(".tl-fold:has(:target)::details-content { content-visibility: visible; }"); | |
| 190 | expect(shellJs).toContain(foldJs); | |
| 191 | }); | |
| 192 | ||
| 193 | test("an entry still waiting for its answer stays out of the fold, and splits it", () => { | |
| 194 | const repo = f.repos[0]!; | |
| 195 | const opened = openIssue(f.app, f.owner, repo, { title: "Open question", body: "q" }); | |
| 196 | if (!opened.ok) throw new Error(String(opened.error)); | |
| 197 | const made: string[] = []; | |
| 198 | for (let i = 0; i < 6; i++) { | |
| 199 | const added = addComment(f.app, f.owner, repo, opened.value, `split comment ${i}`); | |
| 200 | if (!added.ok) throw new Error(String(added.error)); | |
| 201 | made.push(added.value.createdAt); | |
| 202 | } | |
| 203 | const ctx = { app: f.app, url: new URL(`${f.base}${path}`) } as unknown as Ctx; | |
| 204 | const ask = (open: boolean): Entry => ({ | |
| 205 | at: made[2]!, | |
| 206 | node: html`<div class="tl-item" data-kind="event">STANDING REQUEST</div>`, | |
| 207 | ...(open ? { open: true as const } : {}), | |
| 208 | }); | |
| 209 | const out = String(conversation(ctx, repo, opened.value, { openVerb: "opened this", extra: [ask(true)] }).node); | |
| 210 | const outside = out.replace(/<details class="tl-fold"[\s\S]*?<\/details>/g, ""); | |
| 211 | expect(outside).toContain("STANDING REQUEST"); | |
| 212 | expect(outside).toContain("split comment 5"); | |
| 213 | expect(outside).not.toContain("split comment 0"); | |
| 214 | expect(out.match(/<details class="tl-fold"/g)?.length).toBe(2); | |
| 215 | expect(out.match(/id="history"/g)?.length).toBe(1); | |
| 216 | // The same entry, answered, folds with the rest. | |
| 217 | const settled = String(conversation(ctx, repo, opened.value, { openVerb: "opened this", extra: [ask(false)] }).node); | |
| 218 | expect(settled.replace(/<details class="tl-fold"[\s\S]*?<\/details>/g, "")).not.toContain("STANDING REQUEST"); | |
| 219 | expect(settled.match(/<details class="tl-fold"/g)?.length).toBe(1); | |
| 220 | }); | |
| 221 | ||
| 222 | test("a request for changes stands while it is its reviewer's newest verdict on an open pull", () => { | |
| 223 | const r = (id: string, authorId: string, state: Review["state"], createdAt: string): Review => | |
| 224 | ({ id, authorId, authorName: authorId, originAuthor: null, state, body: "", commitOid: "h", baseOid: "", createdAt }) as Review; | |
| 225 | const reviews = [ | |
| 226 | r("1", "a", "changes_requested", "2026-01-01"), | |
| 227 | r("2", "a", "commented", "2026-01-02"), | |
| 228 | r("3", "b", "changes_requested", "2026-01-01"), | |
| 229 | r("4", "b", "approved", "2026-01-03"), | |
| 230 | ]; | |
| 231 | const open = (pullOpen: boolean) => standingRequests(reviews, pullOpen).filter((x) => x.open).map((x) => x.review.id); | |
| 232 | expect(open(true)).toEqual(["1"]); | |
| 233 | expect(open(false)).toEqual([]); | |
| 234 | }); |
Non-blocking: foldCounts landed between interruptionEntries doc comment (the
interrupted: provider limitblock above) and its function, so that doc now sits on the wrong thing. Move foldCounts above that block.