fix: no hub scripts under an mcp limit, count role changes once stored

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
hugocasa
2026-12-02 12:49:03 +01:00
co-authored by Claude Opus 5.5
parent a40f821ad7
commit 5b52dec5d4
3 changed files with 26 additions and 8 deletions
+9 -4
View File
@@ -1108,10 +1108,6 @@ pub async fn validate_instance_roles_write(
))
})?;
}
log_mcp_role_changes(next.iter().map(|r| {
let before = current.iter().find(|c| c.name == r.name);
(before.and_then(|c| c.mcp.as_ref()), r.mcp.as_ref())
}));
Ok(())
}
@@ -1140,10 +1136,19 @@ pub fn log_mcp_role_changes<'a>(
/// by billing on every replica, so it is rebuilt here rather than on the notify that drops the
/// role caches.
pub async fn after_instance_roles_write(db: &DB) -> Result<()> {
// What the write replaced: validating it read the cache.
let previous = cached_instance_roles();
invalidate_all_roles_cache();
let mut tx = db.begin().await?;
sync_role_seats(&mut tx, None).await?;
tx.commit().await?;
if let Some(previous) = previous {
let next = instance_roles(db).await?;
log_mcp_role_changes(next.iter().map(|r| {
let before = previous.iter().find(|c| c.name == r.name);
(before.and_then(|c| c.mcp.as_ref()), r.mcp.as_ref())
}));
}
Ok(())
}
+15 -2
View File
@@ -67,8 +67,16 @@ impl McpScopeConfig {
pub fn limited_by(mut self, limit: &McpLimit) -> Self {
self.no_endpoints = true;
self.endpoints.clear();
// Every limit leaves at most deployed runnables to run, which a Hub script is not.
self.hub_apps = None;
match limit {
McpLimit::ReadAndRun => {}
McpLimit::ReadAndRun => {
// `all` reaches any Hub script by name; its `*` selection stays.
if self.all {
self.all = false;
self.granular = true;
}
}
McpLimit::ReadOnly | McpLimit::Off => self.read_only = true,
McpLimit::Runnables { scripts, flows } => {
// Favorites name no path: the listing's favorites join keeps narrowing them.
@@ -86,7 +94,6 @@ impl McpScopeConfig {
}
self.all = false;
self.granular = true;
self.hub_apps = None;
}
}
self
@@ -432,6 +439,12 @@ mod tests {
assert!(!parse(&["mcp:all", "mcp:read_run"]).limited_by(&limit).read_run);
assert!(parse(&["mcp:all", "mcp:read_only"]).limited_by(&limit).read_only);
for scopes in [&["mcp:all"][..], &["mcp:scripts:f/a/*", "mcp:hub:slack"][..]] {
let runs = parse(scopes).limited_by(&McpLimit::ReadAndRun);
assert!(runs.is_allowed("script", "f/a/x") && !runs.read_only);
assert!(!runs.all && runs.hub_apps.is_none(), "{scopes:?}");
}
let favorites = parse(&["mcp:favorites"]).limited_by(&limit);
assert!(favorites.favorites && favorites.granular);
assert!(!favorites.is_allowed("script", "f/b/x"));
+2 -2
View File
@@ -177,13 +177,13 @@ describe("token command", () => {
const created = await backend.runCLICommand(
[
"token", "create", "--label", "cli-scoped-token",
"--scope", "jobs:run", "--scope", "mcp:workspaces:a,b",
"--scope", "mcp:all", "--scope", "mcp:workspaces:a,b",
],
tempDir
);
expect(created.code).toEqual(0);
const token = await scopesOf();
expect(token.scopes).toEqual(["jobs:run", "mcp:workspaces:a,b"]);
expect(token.scopes).toEqual(["mcp:all", "mcp:workspaces:a,b"]);
const narrowed = await backend.runCLICommand(
["token", "update-scopes", token.token_prefix, "--scope", "scripts:read"],