chore(scripts): cleanup-test-chats.py replaces the Rust example
- the session batch path hit HTTP 414 on long Graph skip tokens; the web session client pages through - hides every "Native client test" meeting chat after live call tests Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@@ -1,47 +0,0 @@
1
use serde_json::{Value, json};
2
use session::{DEFAULT_ENDPOINT, Method, Scope, Session};
3
4
const SUBJECT: &str = "Native client test";
5
const GRAPH: &str = "https://graph.microsoft.com/v1.0";
6
7
#[tokio::main]
8
async fn main() {
9
let endpoint = std::env::var("CDP_ENDPOINT").unwrap_or_else(|_| DEFAULT_ENDPOINT.to_owned());
10
let session = Session::connect(&endpoint).await.expect("browser");
11
let scope = Scope::graph("Chat.ReadWrite");
12
let me = session
13
.request(Method::Get, &format!("{GRAPH}/me?$select=id"), &scope, None)
14
.await
15
.expect("me");
16
let organization = session
17
.request(Method::Get, &format!("{GRAPH}/organization?$select=id"), &scope, None)
18
.await
19
.expect("organization");
20
let user = json!({
21
"id": me.body.get("id").and_then(Value::as_str).unwrap_or_default(),
22
"tenantId": organization.body.pointer("/value/0/id").and_then(Value::as_str).unwrap_or_default(),
23
});
24
let mut next = Some(format!(
25
"{GRAPH}/me/chats?$select=id,topic&$filter=topic eq '{SUBJECT}'&$top=50"
26
));
27
let mut hidden = 0;
28
while let Some(url) = next.take() {
29
let page = session.request(Method::Get, &url, &scope, None).await.expect("list");
30
let chats = page.body.get("value").and_then(Value::as_array).cloned().unwrap_or_default();
31
for chat in chats {
32
if chat.get("topic").and_then(Value::as_str) != Some(SUBJECT) {
33
continue;
34
}
35
let id = chat.get("id").and_then(Value::as_str).unwrap_or_default();
36
let hide_url = format!("{GRAPH}/chats/{id}/hideForUser");
37
let answer = session
38
.request(Method::Post, &hide_url, &scope, Some(json!({ "user": user })))
39
.await
40
.expect("hide");
41
println!("# hide test meeting chat: HTTP {}", answer.status);
42
hidden += 1;
43
}
44
next = page.body.get("@odata.nextLink").and_then(Value::as_str).map(str::to_owned);
45
}
46
println!("# hid {hidden} test meeting chat(s)");
47
}
@@ -1,47 +0,0 @@1
use serde_json::{Value, json};2
use session::{DEFAULT_ENDPOINT, Method, Scope, Session};3
4
const SUBJECT: &str = "Native client test";5
const GRAPH: &str = "https://graph.microsoft.com/v1.0";6
7
#[tokio::main]8
async fn main() {9
let endpoint = std::env::var("CDP_ENDPOINT").unwrap_or_else(|_| DEFAULT_ENDPOINT.to_owned());10
let session = Session::connect(&endpoint).await.expect("browser");11
let scope = Scope::graph("Chat.ReadWrite");12
let me = session13
.request(Method::Get, &format!("{GRAPH}/me?$select=id"), &scope, None)14
.await15
.expect("me");16
let organization = session17
.request(Method::Get, &format!("{GRAPH}/organization?$select=id"), &scope, None)18
.await19
.expect("organization");20
let user = json!({21
"id": me.body.get("id").and_then(Value::as_str).unwrap_or_default(),22
"tenantId": organization.body.pointer("/value/0/id").and_then(Value::as_str).unwrap_or_default(),23
});24
let mut next = Some(format!(25
"{GRAPH}/me/chats?$select=id,topic&$filter=topic eq '{SUBJECT}'&$top=50"26
));27
let mut hidden = 0;28
while let Some(url) = next.take() {29
let page = session.request(Method::Get, &url, &scope, None).await.expect("list");30
let chats = page.body.get("value").and_then(Value::as_array).cloned().unwrap_or_default();31
for chat in chats {32
if chat.get("topic").and_then(Value::as_str) != Some(SUBJECT) {33
continue;34
}35
let id = chat.get("id").and_then(Value::as_str).unwrap_or_default();36
let hide_url = format!("{GRAPH}/chats/{id}/hideForUser");37
let answer = session38
.request(Method::Post, &hide_url, &scope, Some(json!({ "user": user })))39
.await40
.expect("hide");41
println!("# hide test meeting chat: HTTP {}", answer.status);42
hidden += 1;43
}44
next = page.body.get("@odata.nextLink").and_then(Value::as_str).map(str::to_owned);45
}46
println!("# hid {hidden} test meeting chat(s)");47
}@@ -0,0 +1,29 @@
1
"""Hide the "Native client test" meeting chats that live call tests leave behind.
2
3
Runs through the signed-in M365 web session (skill running-m365-web-session).
4
"""
5
import os
6
import sys
7
import urllib.parse
8
9
sys.path.insert(0, os.path.expanduser("~/.claude/skills/running-m365-web-session"))
10
from m365web.client import Client
11
12
SUBJECT = "Native client test"
13
GRAPH = "https://graph.microsoft.com/v1.0"
14
SCOPE = "Chat.ReadWrite"
15
16
with Client() as client:
17
me = client.request("GET", f"{GRAPH}/me?$select=id", SCOPE)
18
organization = client.request("GET", f"{GRAPH}/organization?$select=id", SCOPE)
19
user = {"id": me["id"], "tenantId": organization["value"][0]["id"]}
20
url = f"{GRAPH}/me/chats?$select=id,topic&$filter=topic eq '{SUBJECT}'&$top=50"
21
chat_ids = []
22
while url:
23
page = client.request("GET", url, SCOPE)
24
chat_ids += [chat["id"] for chat in page["value"] if chat.get("topic") == SUBJECT]
25
url = page.get("@odata.nextLink")
26
for chat_id in chat_ids:
27
path = urllib.parse.quote(chat_id, safe="")
28
client.request("POST", f"{GRAPH}/chats/{path}/hideForUser", SCOPE, body={"user": user})
29
print(f"hid {len(chat_ids)} test meeting chat(s)")
@@ -0,0 +1,29 @@1
"""Hide the "Native client test" meeting chats that live call tests leave behind.2
3
Runs through the signed-in M365 web session (skill running-m365-web-session).4
"""5
import os6
import sys7
import urllib.parse8
9
sys.path.insert(0, os.path.expanduser("~/.claude/skills/running-m365-web-session"))10
from m365web.client import Client11
12
SUBJECT = "Native client test"13
GRAPH = "https://graph.microsoft.com/v1.0"14
SCOPE = "Chat.ReadWrite"15
16
with Client() as client:17
me = client.request("GET", f"{GRAPH}/me?$select=id", SCOPE)18
organization = client.request("GET", f"{GRAPH}/organization?$select=id", SCOPE)19
user = {"id": me["id"], "tenantId": organization["value"][0]["id"]}20
url = f"{GRAPH}/me/chats?$select=id,topic&$filter=topic eq '{SUBJECT}'&$top=50"21
chat_ids = []22
while url:23
page = client.request("GET", url, SCOPE)24
chat_ids += [chat["id"] for chat in page["value"] if chat.get("topic") == SUBJECT]25
url = page.get("@odata.nextLink")26
for chat_id in chat_ids:27
path = urllib.parse.quote(chat_id, safe="")28
client.request("POST", f"{GRAPH}/chats/{path}/hideForUser", SCOPE, body={"user": user})29
print(f"hid {len(chat_ids)} test meeting chat(s)")