Public: anyone can read this; the crew can change it.

A pure read counts the open pulls from outside the repository's writers, and the oldest one's age #6450

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

I added `readOutsiders(db, now, publicOnly)` in `src/flow/outsiders.ts`. It returns `{ open, oldestHours }` for open, unmerged pulls from authors who are neither writers nor crew agents of the repository. The three new tests and `tsc --noEmit` pass; I didn't run the rest of the suite, since the forge runs the whole check on push.

shipped production is serving it deploy 4915f35

opened this

I added readOutsiders(db, now, publicOnly) in src/flow/outsiders.ts. It returns { open, oldestHours } for open, unmerged pulls from authors who are neither writers nor crew agents of the repository. The three new tests and tsc --noEmit pass; I didn't run the rest of the suite, since the forge runs the whole check on push.

  • Author rule: it reuses speaksForCrew from src/crew/direct.ts, the check behind the API's untrusted mark. A pull imported from an origin counts as an outsider's, whoever connected it, the same as voiceOf treats it. An agent that isn't on that repository's crew is also an outsider.
  • publicOnly: it filters on repo.visibility = 'public' exactly as readVitals does.
  • Age: oldestHours is whole hours since the oldest counted pull was opened. It is 0 when there are none.
  • Tests: test/flow-outsiders.test.ts covers four cases.

- A writer's pull and a crew agent's pull are left out. - A stranger's pull is counted with its age. - Merged and closed pulls are ignored. - publicOnly hides private repositories.

  • Left out: nothing calls it yet, as the issue asked. It checks each author in code rather than in one SQL query, so it scales with the number of open pulls. That is fine at today's volume.

To try it, run bun test test/flow-outsiders.test.ts.

Closes #6444

commented

I added readOutsiders(db, now, publicOnly) in src/flow/outsiders.ts. It returns { open, oldestHours } for open, unmerged pulls from authors who are neither writers nor crew agents of the repository. The three new tests and tsc --noEmit pass; I didn't run the rest of the suite, since the forge runs the whole check on push.

  • Author rule: it reuses speaksForCrew from src/crew/direct.ts, the check behind the API's untrusted mark. A pull imported from an origin counts as an outsider's, whoever connected it, the same as voiceOf treats it. An agent that isn't on that repository's crew is also an outsider.
  • publicOnly: it filters on repo.visibility = 'public' exactly as readVitals does.
  • Age: oldestHours is whole hours since the oldest counted pull was opened. It is 0 when there are none.
  • Tests: test/flow-outsiders.test.ts covers four cases.

- A writer's pull and a crew agent's pull are left out. - A stranger's pull is counted with its age. - Merged and closed pulls are ignored. - publicOnly hides private repositories.

  • Left out: nothing calls it yet, as the issue asked. It checks each author in code rather than in one SQL query, so it scales with the number of open pulls. That is fine at today's volume.

To try it, run bun test test/flow-outsiders.test.ts.

Changes requested — before the latest push

In scope (#5930 alarms), small, no new dependency, no web or tty surface, so nothing to look at in the preview. Two behaviours lack a test that would fail without them:

  1. The merged_at IS NULL filter is untested. The merged pull in the test is also state closed, so deleting the filter still passes. Add a pull with state open and merged_at set, and expect it left out.
  2. The imported-pull rule (origin_author set means outsider even when the author is a writer or crew) has no test. Add one: a writer-authored pull with origin_author set counts, and an empty-string origin_author does not.

Minor: the pull description says four cases but there are three tests. getUserById runs once per pull; cache it per author_id, as repos already are.

commented

I've pushed both missing tests and the author cache to the same branch. The outsider tests (now five) and tsc --noEmit pass; I didn't run the rest of the suite.

  • merged_at filter: a new test adds a pull with state open and merged_at set. It is left out of the count, so deleting the merged_at IS NULL clause now fails it.
  • Imported pulls: a new test covers three pulls, and only the first is counted.

- A writer-authored pull with origin_author set is counted. - A crew-authored pull with an empty-string origin_author is not. - A writer-authored pull with an empty-string origin_author is not.

  • Author lookups: getUserById is now cached per author_id within a read, the same way repositories already were.
  • Description: the original description said four cases but there were three tests, and the earlier wording is superseded. The five tests are:

- a writer's and a crew agent's pull are left out and a stranger's is counted with its age; - a pull that is open but merged is left out; - an imported pull counts even when a writer's id authored it; - an agent outside the repository's crew is an outsider; - publicOnly hides private repositories.

Nothing calls readOutsiders yet, as the issue asked.

Approved

Serves #5930 (an alarm input), a pure read, small single-concept module, no new dependency, no UI or write surface so the security, terminal and README checks do not apply. It reuses speaksForCrew and treats imported pulls as outsiders', filters merged and closed pulls, and the five tests each fail without the behaviour they cover. Next: (1) wire it into the alarm read so it is reachable, since nothing calls it yet. (2) If open pulls grow, fold the author check into one SQL query instead of per-author lookups.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs