Skip to content

Commit d0596b2

Browse files
Fix mock decision context to flatten user attributes
The test context in DecisionFunctionModal nested attributes under an "attributes" key, but the real proxy flattens them as top-level fields on ctx.session.user. This caused runtime errors (e.g. "Cannot read properties of undefined") when testing decision functions that access custom attributes like ctx.session.user.departments. Added cross-reference comments in both context.rs and the modal to prevent future drift between the real and mock context shapes.
1 parent 5b48a09 commit d0596b2

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

admin-ui/src/components/DecisionFunctionModal.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,10 @@ export function DecisionFunctionModal({
348348
}
349349
}
350350
}
351+
// This mock must mirror the shape built by proxy/src/decision/context.rs
352+
// (build_session_context / build_query_context). Keep in sync when the
353+
// real context changes — user attributes are flattened onto the user
354+
// object, NOT nested under an "attributes" key.
351355
setTestContextStr(
352356
JSON.stringify(
353357
{
@@ -357,7 +361,7 @@ export function DecisionFunctionModal({
357361
username: currentUser?.username ?? 'testuser',
358362
tenant: currentUser?.tenant ?? 'default',
359363
roles: ['analyst'],
360-
attributes: testAttrs,
364+
...testAttrs, // flattened — matches build_user_object() in context.rs
361365
},
362366
time: { hour: 14, day_of_week: 'Monday' },
363367
datasource: { name: 'my_ds', access_mode: 'policy_required' },

proxy/src/decision/context.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ pub struct QueryMetadata {
4848
/// - `admin-ui/src/pages/UserEditPage.tsx` — attributes section hint text
4949
/// - `docs/permission-system.md` — Decision Functions → Context modes
5050
/// - `proxy/src/admin/dto.rs` — `EXTRA_RESERVED_USER_KEYS` if adding a virtual field
51+
/// - `admin-ui/src/components/DecisionFunctionModal.tsx` — mock test context
52+
/// (search for "context.rs" — the mock must mirror this shape exactly)
5153
/// - Any CodeMirror editor in `admin-ui/` that references `ctx.session.user.*` in
5254
/// autocomplete, placeholders, hints, or templates
5355
fn build_user_object(session: &SessionInfo) -> serde_json::Value {

0 commit comments

Comments
 (0)