flatten input context

This commit is contained in:
aecsocket
2026-08-02 15:13:13 +01:00
parent ddb45f6aac
commit 5ead1499cd
3 changed files with 27 additions and 11 deletions
@@ -64,7 +64,7 @@
<div v-else class="mt-3 grid gap-3 md:grid-cols-2">
<div class="min-w-0">
<p class="m-0 mb-2 text-xs font-semibold uppercase tracking-wide text-secondary">
Input (<code>input</code>)
Context
</p>
<pre
class="m-0 overflow-x-auto rounded-lg bg-surface-1 p-3 text-xs leading-relaxed text-contrast"
@@ -428,7 +428,7 @@ import type { Component } from 'vue'
import IssueDetailPath from '~/components/ui/moderation/IssueDetailPath.vue'
const DEFAULT_RULE = `input.trace.issue_type == "OBFUSCATED_NAMES"
const DEFAULT_RULE = `trace.issue_type == "OBFUSCATED_NAMES"
? {"severity": "low"}
: null`
const RULE_EDITOR_OPTIONS: Partial<Ace.EditorOptions> = {
@@ -114,7 +114,7 @@ pub struct DelphiRuleSchemaResponse {
pub components: BTreeMap<String, serde_json::Value>,
}
/// Get the schemas for the CEL input and output values.
/// Get the schemas for the CEL context and output values.
#[utoipa::path(
context_path = "/moderation/tech-review",
tag = "moderation",
@@ -800,12 +800,24 @@ async fn insert_materialized_effects(
pub(super) fn evaluate_rule(
program: &cel::Program,
input: impl Serialize,
input: &RuleInput,
) -> Result<Option<DelphiRuleEffect>> {
let mut context = cel::Context::default();
context
.add_variable("input", input)
.wrap_err("failed to build cel input")?;
.add_variable("schema_version", input.schema_version)
.wrap_err("failed to add `schema_version` to cel context")?;
context
.add_variable("trace", &input.trace)
.wrap_err("failed to add `trace` to cel context")?;
context
.add_variable("scan", &input.scan)
.wrap_err("failed to add `scan` to cel context")?;
context
.add_variable("artifact", &input.artifact)
.wrap_err("failed to add `artifact` to cel context")?;
context
.add_variable("scope", &input.scope)
.wrap_err("failed to add `scope` to cel context")?;
let value = program
.execute(&context)