feat: add --dry-run support to events helper commands#455
feat: add --dry-run support to events helper commands#455joeVenner wants to merge 1 commit intogoogleworkspace:mainfrom
Conversation
🦋 Changeset detectedLatest commit: 3515881 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces a Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a --dry-run mode for the events +renew and events +subscribe helper commands. The implementation is a good start, but there are a couple of issues with the dry-run logic. In renew.rs, the dry-run output is missing for single-subscription renewals, making it inconsistent. More critically, in subscribe.rs, the dry-run mode doesn't work when using an existing subscription, leading to unexpected live API calls. My review includes suggestions to fix these issues to ensure the --dry-run feature behaves as expected across all scenarios.
| let pubsub_token = if dry_run { | ||
| None | ||
| } else { | ||
| Some( | ||
| auth::get_token(&[PUBSUB_SCOPE]) | ||
| .await | ||
| .map_err(|e| GwsError::Auth(format!("Failed to get Pub/Sub token: {e}")))?, | ||
| ) | ||
| }; |
There was a problem hiding this comment.
The --dry-run implementation is incomplete and leads to unexpected API calls. When using an existing subscription (--subscription), the code proceeds to the pull_loop, which attempts to fetch a real token and pull messages from Pub/Sub. This defeats the purpose of a dry run.
This happens because there's no dry-run check for the existing subscription path. The pull_loop is called unconditionally, and it uses pubsub_token_provider which is not aware of the dry-run mode.
A possible fix is to handle the dry-run case for existing subscriptions early in the function and return before pull_loop is called, similar to how it's done for new subscriptions. For example, you could add a check after parsing arguments:
if dry_run && config.subscription.is_some() {
// Print dry-run JSON for existing subscription and return Ok(())
}| if !dry_run { | ||
| let token = ws_token.as_ref().expect("Token should be present in non-dry-run mode"); | ||
| let resp = client | ||
| .post(format!( | ||
| "https://workspaceevents.googleapis.com/v1/{name}:reactivate" | ||
| )) | ||
| .bearer_auth(token) | ||
| .header("Content-Type", "application/json") | ||
| .body("{}") | ||
| .send() | ||
| .await | ||
| .context("Failed to reactivate subscription")?; | ||
|
|
||
| let body: Value = resp.json().await.context("Failed to parse response")?; | ||
|
|
||
| println!( | ||
| "{}", | ||
| serde_json::to_string_pretty(&body).unwrap_or_default() | ||
| ); | ||
| } |
There was a problem hiding this comment.
Inconsistent dry-run behavior. When --dry-run is used with a specific subscription name (--name), the command doesn't produce any JSON output indicating what would have happened. This is inconsistent with the behavior when --all is used. An else block should be added to provide a descriptive JSON output for the single-subscription dry-run case.
if !dry_run {
let token = ws_token.as_ref().expect("Token should be present in non-dry-run mode");
let resp = client
.post(format!(
"https://workspaceevents.googleapis.com/v1/{name}:reactivate"
))
.bearer_auth(token)
.header("Content-Type", "application/json")
.body("{}")
.send()
.await
.context("Failed to reactivate subscription")?;
let body: Value = resp.json().await.context("Failed to parse response")?;
println!(
"{}",
serde_json::to_string_pretty(&body).unwrap_or_default()
);
} else {
let result = json!({
"dry_run": true,
"action": "Would reactivate subscription",
"name": name,
"note": "Run without --dry-run to actually reactivate the subscription"
});
println!(
"{}",
serde_json::to_string_pretty(&result).unwrap_or_default()
);
}Add dry-run mode to gws events +renew and gws events +subscribe commands. When --dry-run is specified, the commands print what actions would be taken without making any API calls. This allows agents to simulate requests and learn without reaching the server.
e907467 to
3515881
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a --dry-run mode for the events +renew and events +subscribe helper commands. The implementation is mostly correct, but there are a couple of issues where the dry-run logic is incomplete, causing inconsistencies or leading to unintended API calls. I've left specific comments with suggestions to address these issues. Once fixed, this will be a great enhancement for simulating requests.
| if !dry_run { | ||
| let token = ws_token.as_ref().expect("Token should be present in non-dry-run mode"); | ||
| let resp = client | ||
| .post(format!( | ||
| "https://workspaceevents.googleapis.com/v1/{name}:reactivate" | ||
| )) | ||
| .bearer_auth(token) | ||
| .header("Content-Type", "application/json") | ||
| .body("{}") | ||
| .send() | ||
| .await | ||
| .context("Failed to reactivate subscription")?; | ||
|
|
||
| let body: Value = resp.json().await.context("Failed to parse response")?; | ||
|
|
||
| println!( | ||
| "{}", | ||
| serde_json::to_string_pretty(&body).unwrap_or_default() | ||
| ); | ||
| } |
There was a problem hiding this comment.
The dry-run mode for reactivating a specific subscription is incomplete. It prints a message to stderr but doesn't produce the JSON output describing the action, which is inconsistent with the behavior for renewing multiple subscriptions. To ensure consistent behavior and fully implement the dry-run feature, you should add an else block to output a JSON summary for this case.
if !dry_run {
let token = ws_token.as_ref().expect("Token should be present in non-dry-run mode");
let resp = client
.post(format!(
"https://workspaceevents.googleapis.com/v1/{name}:reactivate"
))
.bearer_auth(token)
.header("Content-Type", "application/json")
.body("{}")
.send()
.await
.context("Failed to reactivate subscription")?;
let body: Value = resp.json().await.context("Failed to parse response")?;
println!(
"{}",
serde_json::to_string_pretty(&body).unwrap_or_default()
);
} else {
let result = json!({
"dry_run": true,
"action": "Would reactivate subscription",
"name": name,
"note": "Run without --dry-run to actually reactivate this subscription"
});
println!(
"{}",
serde_json::to_string_pretty(&result).unwrap_or_default()
);
}| let dry_run = matches.get_flag("dry-run"); | ||
|
|
||
| if dry_run { | ||
| eprintln!("🏃 DRY RUN — no changes will be made\n"); | ||
| } |
There was a problem hiding this comment.
The dry-run implementation is incomplete for existing subscriptions. When the --subscription flag is used in dry-run mode, the command proceeds to call pull_loop, which makes real API calls to Pub/Sub. This defeats the purpose of a dry run.
A check should be added to handle this scenario. When dry_run is true and an existing subscription is provided, the command should print what it would do and exit, rather than entering the pull_loop.
Add dry-run mode to gws events +renew and gws events +subscribe commands. When --dry-run is specified, the commands print what actions would be taken without making any API calls. This allows agents to simulate requests and learn without reaching the server.
Description
Please include a summary of the change and which issue is fixed. If adding a new feature or command, please include the output of running it with
--dry-runto prove the JSON request body matches the Discovery Document schema.Dry Run Output:
// Paste --dry-run output here if applicableChecklist:
AGENTS.mdguidelines (no generatedgoogle-*crates).cargo fmt --allto format the code perfectly.cargo clippy -- -D warningsand resolved all warnings.pnpx changeset) to document my changes.