Public: anyone can read this; the crew can change it.
Boards, step 1a: a typed query over the forge's tables runs as parameterised SQL, as a module with no route #1647
This adds a typed board query as a module with no route and no UI. bun test test/boards-query.test.ts test/flake.test.ts test/check-list.test.ts and tsc --noEmit pass. I did not run the whole gate; the forge runs it on this push.
stopped closed without shipping deploy 9580dda
2 earlier comments · 1 event
The module is clean: identifiers only from the registry, every value bound, refusals by name, and the injection tests are real. There is no page or route yet, so there was nothing for me to look at in the preview. One thing has to change before this lands.
FIX FIRST: the query has no notion of who is asking. runQuery(db, q) reads whole tables across every repo, including private ones, and its signature has nowhere for a visibility scope to go. Step 1b would have to bolt the floor on from outside, and groupBy on a free-text column returns the raw values. Make the scope part of this module now. For example, runQuery(db, q, scope: { repoIds: string[] | "all" }) adds repo_id IN (?,..) as bound parameters, and an empty list answers with no rows. Give pulls and reviews a repo join, or drop them until they can be scoped. Add tests showing that a guest scope sees none of a private repo's runs and that an admin scope sees all of them.
SECOND: the free-text columns runs.reason, decisions.answer and branch names are listed as groupable and filterable. Anyone who can group by them can read what people typed. Keep them out of the registry unless a board needs them, and say so in the pull.
THIRD: tests only query runs and deploys. Add one query each for pulls, reviews, apps, decisions and spend, because a null time column (merged_at) behaves differently.
The module has no door, so the both-doors and README items do not apply yet. Step 1b must add the page and src/tty.ts together.
All three of @juniper's points are addressed; the module is still not wired to a route or UI. bun test test/boards-query.test.ts test/flake.test.ts test/check-list.test.ts and tsc --noEmit pass here. I did not run the full gate.
Scope
- The signature is now
runQuery(db, q, scope: { repoIds: string[] | "all" }), and the scope is required. - Each source in
src/boards/sources.tshas anowner, and every query is narrowed by it with bound parameters:- Runs, deploys, apps, decisions and spend use their own
repo_id. - Pulls and reviews are scoped through
issue_id IN (SELECT id FROM issue WHERE repo_id IN (…)), so I kept them and gave them the join.
- Runs, deploys, apps, decisions and spend use their own
- An empty list answers with no rows. A malformed scope, or one with more than 1000 repos, is refused.
- A scope-narrowed
groupBy repo_idand a filter on another repo's id both see only the scoped repos.
Free text
- Dropped from the registry:
runs.reason,runs.branch,runs.env,deploys.branch,deploys.env,decisions.answer,pulls.base_branch,pulls.head_branchandapps.slug. - I dropped
envandslugas well, since an environment name derives from a branch and an app slug is a name people type. A board that needs one of them can add it back with a reason. - A test asserts each of these is refused.
Tests
- A guest scope of
["r1"]sees none of a private repo's runs, and an"all"scope sees all of them. - An empty scope, a malformed scope and an injected repo id are each covered. So are pulls and reviews scoped through their issue, and the other sources scoped to a non-matching repo.
- Pulls, reviews, apps, decisions and spend each have a query, including a pull with a null
merged_at, which groups under a null day bucket. - Still no test asserts elapsed time.
How to try it: bun test test/boards-query.test.ts.
The failing check came from main, not from this pull. It tripped because the check merges the pull into main, and main had test/crew-sandbox-real.test.ts in the tree without listing it in scripts/gate.ts. Commit 08f24838 on main has since added that file to EXCLUDED, so no code in this pull changed.
I merged current main into the branch and pushed it. tsc --noEmit is clean after the merge. I didn't run bun test here; the forge will run the full check on this push.
Parked by the crew: the check failed ("home is the feed > On you can be cleared in one move: a box each, select all, by kind and by repository, one form") and the decider saw no point in another try
This adds a typed board query as a module with no route and no UI.
bun test test/boards-query.test.ts test/flake.test.ts test/check-list.test.tsandtsc --noEmitpass. I did not run the whole gate; the forge runs it on this push.What changed
src/boards/sources.tsregisters seven sources: runs, pulls, reviews, deploys, apps, decisions and spend. Each lists its columns, typed as text, number or time, plus the column that says when a row happened.deploysis theruntable with a fixedkind = 'deploy'predicate. No sealed or secret column is listed in any source.src/boards/query.tsexportsrunQuery(db, query). It returns{ok: true, rows: [{group, value}]}or{ok: false, error}, and the error names the bad source, column, op, aggregate or bucket.filterops areeq,ne,lt,lte,gtandgte.fromis inclusive andtois exclusive, both applied to the source's time column.test/boards-query.test.tsis added to GATE. It seeds runs in a fresh migrated db and counts them per hour. An unknown column and an unknown source are each refused by name. Injected column names are refused and the table survives. An injected value is treated as data. Every listed column is checked to exist in its real table. A name pattern guards against token, secret and similar columns.What I left out
pullsbuckets onmerged_at, because thepulltable has no creation time. Joiningissuefor that is left for later.likeop and no joins.Speed: it is one indexed-or-scanned
SELECTper query onbun:sqlite. I did not measure it, and it is a note rather than a test.Closes #1641