Skip to content

Commit 5aae479

Browse files
committed
feat(git): name a reported query's category on its started event
- A reported query's `started` event carries `queryCategory`, so a console that stops recording a category can drop the successful queries of it that it kept. A visible command, and a query of no category (an automatic refresh or watcher), carries none. - `execution_policy::query_category()` gives the running request's category, and `reports_queries()` checks it against `consoleQueries`. - `console-queries-v1.json` lists every category in `queryCategories`, which hosts read to check their own names; a test matches the list against the enum, so it fails to compile when a category is added and the list is not.
1 parent 5fc1079 commit 5aae479

4 files changed

Lines changed: 72 additions & 17 deletions

File tree

‎rust/contracts/rust-core-api.md‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,7 +1181,7 @@ Each event has `operationId` and `type`:
11811181
| Type | Additional fields |
11821182
| --- | --- |
11831183
| `requestStarted` | none; cancellation is registered before delivery |
1184-
| `started` | `invocationId`, `workingDirectory`, `arguments`, nullable resolved `executable`, `temporaryConfig` key/value pairs, `displayArguments`, `globalArguments`, `source`, `query` |
1184+
| `started` | `invocationId`, `workingDirectory`, `arguments`, nullable resolved `executable`, `temporaryConfig` key/value pairs, `displayArguments`, `globalArguments`, `source`, `query`, and a query's `queryCategory` when it has one |
11851185
| `output` | `invocationId`, `stream` (`stdout`/`stderr`), `text`, `progress`, `truncated`, optional `progressDetails` (`stage`, nullable `percent`, `completed`, `total`) |
11861186
| `finished` | `invocationId`, nullable `exitCode`, monotonic `durationMilliseconds`, nullable `error`, `expectedExit` |
11871187
| `requestFinished` | nullable `error`, including failures before a child started; `unconfirmedInvocations`, the started records without `finished`; `failureRecord`, true when `error` is set, is not a cancellation, and no record of the request failed or is unconfirmed, so the host shows the error as its own record |
@@ -1261,7 +1261,12 @@ tell apart; otherwise Core derives it from the request command: `diff` for `git.
12611261
`git.comparison` and `git.planDiffBlocks`; `log` for history, reference, tag, commit and
12621262
graph reads; `annotate` for `git.blame` and `git.lineHistory`; `panels` for worktree,
12631263
stash, remote, pull request, untracked directory, repository setup and execution inspection
1264-
reads; and `checks` for every other Git command. Commands outside Git have no category.
1264+
reads; and `checks` for every other Git command. Commands outside Git have no category, and
1265+
neither have the queries of a `background` request that names none. The `queryCategories`
1266+
list of the fixture below names every category; `gitExecution` rejects any other name. A
1267+
reported query's `started` event carries its `queryCategory`, so a host that stops
1268+
recording a category can drop the successful queries of it that it kept; a visible command,
1269+
and a query of no category, carries none.
12651270
A query whose category the console does not record emits no events while it succeeds, so it
12661271
never consumes the console's capacity. If it fails (an error, or a nonzero exit that does not
12671272
answer its question) in a request whose provenance is not `background`, Core sends its

‎rust/crates/git/src/execution_events.rs‎

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ enum Kind<'a> {
4848
/// An internal query reported because the console records its category, as opposed
4949
/// to a command the workflow runs visibly; consoles fold a query's output by default.
5050
query: bool,
51+
/// The category of a query, so a console can drop the queries of a category it stops
52+
/// recording; absent for a visible command and a query of no category.
53+
#[serde(skip_serializing_if = "Option::is_none")]
54+
query_category: Option<super::console::QueryCategory>,
5155
},
5256
Output {
5357
invocation_id: u64,
@@ -224,6 +228,10 @@ impl Invocation {
224228
working_directory: root,
225229
arguments: &arguments,
226230
query: self.query,
231+
query_category: self
232+
.query
233+
.then(super::execution_policy::query_category)
234+
.flatten(),
227235
},
228236
);
229237
}
@@ -633,13 +641,23 @@ mod tests {
633641
let marks: Vec<_> = events
634642
.iter()
635643
.filter(|event| event["type"] == "started")
636-
.map(|event| (event["arguments"][0].clone(), event["query"].clone()))
644+
.map(|event| {
645+
(
646+
event["arguments"][0].clone(),
647+
event["query"].clone(),
648+
event.get("queryCategory").cloned(),
649+
)
650+
})
637651
.collect();
638652
assert_eq!(
639653
marks,
640654
[
641-
(serde_json::json!("log"), serde_json::json!(true)),
642-
(serde_json::json!("commit"), serde_json::json!(false))
655+
(
656+
serde_json::json!("log"),
657+
serde_json::json!(true),
658+
Some(serde_json::json!("log"))
659+
),
660+
(serde_json::json!("commit"), serde_json::json!(false), None)
643661
]
644662
);
645663
}

‎rust/crates/git/src/execution_policy.rs‎

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -100,19 +100,23 @@ pub(super) fn source() -> super::console::Source {
100100
}
101101
}
102102

103-
/// Whether the running request's internal queries are recorded: the category the host named,
104-
/// or else the request command's, is one the console records. A `background` request without
105-
/// a named category is an automatic refresh or watcher, which runs too often to record.
106-
pub(super) fn reports_queries() -> bool {
103+
/// The category of the running request's internal queries: the one the host named, or else
104+
/// the request command's. A `background` request without a named category is an automatic
105+
/// refresh or watcher, whose queries belong to no category.
106+
pub(super) fn query_category() -> Option<QueryCategory> {
107107
let options = current();
108-
options
109-
.query_category
110-
.or_else(|| {
111-
(source() != super::console::Source::Background)
112-
.then_some(options.command_category)
113-
.flatten()
114-
})
115-
.is_some_and(|category| options.console_queries.contains(&category))
108+
options.query_category.or_else(|| {
109+
(source() != super::console::Source::Background)
110+
.then_some(options.command_category)
111+
.flatten()
112+
})
113+
}
114+
115+
/// Whether the running request's internal queries are recorded: their category is one the
116+
/// console records. Queries of no category, those of an automatic refresh or watcher, run too
117+
/// often to record.
118+
pub(super) fn reports_queries() -> bool {
119+
query_category().is_some_and(|category| current().console_queries.contains(&category))
116120
}
117121

118122
/// Whether the running request's unrecorded queries still report a failure: a request that
@@ -298,6 +302,23 @@ mod tests {
298302
"../../../fixtures/git/console-queries-v1.json"
299303
))
300304
.unwrap();
305+
// Hosts read the whole list from the fixture. The match fails to compile when a
306+
// category is added, so the list cannot fall behind the enum.
307+
use super::super::console::QueryCategory::*;
308+
let categories: Vec<super::super::console::QueryCategory> =
309+
serde_json::from_value(fixture["queryCategories"].clone()).unwrap();
310+
let positions = categories.iter().map(|category| match category {
311+
References => 0,
312+
Reload => 1,
313+
DiffRefresh => 2,
314+
Diff => 3,
315+
Log => 4,
316+
LogPathFilter => 5,
317+
Annotate => 6,
318+
Panels => 7,
319+
Checks => 8,
320+
});
321+
assert!(positions.eq(0..9), "{categories:?}");
301322
for (command, category) in fixture["categories"].as_object().unwrap() {
302323
assert_eq!(
303324
serde_json::json!(super::super::console::category::of_command(command)),

‎rust/fixtures/git/console-queries-v1.json‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
{
22
"version": 1,
3+
"queryCategories": [
4+
"references",
5+
"reload",
6+
"diffRefresh",
7+
"diff",
8+
"log",
9+
"logPathFilter",
10+
"annotate",
11+
"panels",
12+
"checks"
13+
],
314
"categories": {
415
"git.diff": "diff",
516
"git.comparison": "diff",

0 commit comments

Comments
 (0)