Skip to content

See how your app actually fits together. An interactive, plain-English map of your codebase, drawn by Claude or Codex.

fix(health): recognize FastAPI named guard dependencies

Bl0ck154660ea7e6f191
diff --git a/skills/floorplan/scripts/lib/health.mjs b/skills/floorplan/scripts/lib/health.mjs
index a5cb39e..1742a50 100644
--- a/skills/floorplan/scripts/lib/health.mjs
+++ b/skills/floorplan/scripts/lib/health.mjs
@@ -195,7 +195,7 @@ function findSecrets(src, f, out) {
// ---------- 2. who may call each endpoint ----------
// Decorators / middleware / dependencies whose names say "check who is calling".
-const GUARD_NAME = /(^|_)(login|auth|authenticated|authorized?|jwt|token|permission|permissions|perm|role|roles|staff|admin|superuser|owner|scope|scopes|session|api_?key|signature|signed|hmac|device|member|user)(_|$)|_required$|^requires?_|^ensure_|^verify_|^check_(auth|token|user|session|permission|role|api)|protect|^is_?authenticated|^is_?admin/i;
+const GUARD_NAME = /(^|_)(login|auth|authenticated|authorized?|jwt|token|permission|permissions|perm|role|roles|staff|admin|superuser|owner|scope|scopes|session|api_?key|signature|signed|hmac|device|member|user)(_|$)|_required$|^requires?_|^ensure_|^verify_|^guard(?:_|$)|_guard$|^check_(auth|token|user|session|permission|role|api)|protect|^is_?authenticated|^is_?admin/i;
const NOT_GUARD = /^(route|get|post|put|patch|delete|cached?|limit|limiter|rate_?limit\w*|cross_origin|wraps|staticmethod|classmethod|property|retry|timed|log\w*|swag_from|validate\w*|expects|marshal\w*|doc|json_required|fields?_required|params?_required|body_required|transaction\w*|csrf\w*|exempt)$/i;
const isGuardName = (name) => !!name && !NOT_GUARD.test(name) && GUARD_NAME.test(snake(name));
// FastAPI dependencies that hand over a database session rather than check the caller
diff --git a/tests/fixtures/fastapi-guard-name/app/main.py b/tests/fixtures/fastapi-guard-name/app/main.py
new file mode 100644
index 0000000..2eea55e
--- /dev/null
+++ b/tests/fixtures/fastapi-guard-name/app/main.py
@@ -0,0 +1,17 @@
+from fastapi import FastAPI, Depends
+
+app = FastAPI()
+
+def metrics_guard():
+ return True
+
+def metrics_logger():
+ return True
+
[email protected]("/billing/protected", dependencies=[Depends(metrics_guard)])
+def protected():
+ return {"ok": True}
+
[email protected]("/billing/open", dependencies=[Depends(metrics_logger)])
+def open_route():
+ return {"ok": True}
diff --git a/tests/health.test.mjs b/tests/health.test.mjs
index 83cccb4..a72a15e 100644
--- a/tests/health.test.mjs
+++ b/tests/health.test.mjs
@@ -44,6 +44,11 @@ test('FastAPI: Annotated dependency aliases count as sign-in checks (#4)', () =>
assert.deepEqual(openEndpoints(graph), ['POST /comments', 'POST /feedback']);
});
+test('FastAPI: a named guard dependency is not a public endpoint (#7)', () => {
+ const graph = buildFixture('fastapi-guard-name');
+ assert.deepEqual(openEndpoints(graph), ['POST /billing/open']);
+});
+
test('FastAPI: checks added where a router is included count as sign-in checks', () => {
const graph = buildFixture('fastapi-include-router');
assert.equal(graph.routes.length, 4, `expected the sample's 4 endpoints, found ${graph.routes.length}`);