fix(eda): type-aware actions classifier, one stable-identifier grammar, loader tests that fail for the named reason

This commit is contained in:
sam committed 2026-09-23 21:48:52 +10:00
1 parent 1b28bba234
commit 60c19f450d
10 files changed
+111 -75

No files matched your search

+21 -35
View File
@@ -280,50 +280,41 @@ func (e *Env) Compile(src string) (*Program, error) {
return &Program{prg: prg, actionIDs: ids, resolvable: resolvable}, nil
}
// actionReferences walks the compiled AST once and classifies every read of
// actionReferences walks the checked AST once and classifies every read of
// the `actions` context root as either a statically-resolvable action id or
// not. The invariant is exhaustive by construction: each read of `actions`
// consumes exactly one `actions` identifier node, so counting identifier
// nodes and counting the reads that match the static access shape (a field
// selection on the `actions` ident) yields
// not. A root read is an identifier the checker typed as the `actions`
// object: matching on type rather than name keeps a comprehension variable
// that happens to be called `actions` out of the count. Each root read
// consumes exactly one such identifier, so
//
// resolvable = (identCount == staticCount)
//
// Any other spelling that mentions `actions` contributes an identifier node
// without a matching static access, so it reports unresolvable rather than
// slipping through as a runtime miss. The returned ids are the sorted,
// de-duplicated ids of the static accesses.
//
// With the per-playbook object type the CEL checker rejects every non-static
// `actions` read at compile time -- a dynamic index, `in`, `size`, or a
// method/field selection that is not a declared id never reaches this walk.
// The one spelling the checker does NOT reject is a bare `actions` value
// read, which compiles as an object value but cannot be pinned to an action
// id at load. This walk is retained solely to reject that spelling; the ids
// return is now informational (the unknown-id check moved to the checker's
// per-playbook object type).
// where staticCount is the root reads that are a field selection. The
// checker already rejects every other non-static read (a dynamic index,
// `in`, `size`, an undeclared id); the spelling it accepts is a bare
// `actions` value, which compiles but cannot be pinned to an action id at
// load. This walk exists to reject that spelling; the ids return is
// informational. The ids are sorted and de-duplicated.
func actionReferences(ast *cel.Ast) ([]string, bool) {
if ast == nil || ast.NativeRep() == nil {
return nil, true
}
checked := ast.NativeRep()
isRoot := func(e celast.Expr) bool {
return e.Kind() == celast.IdentKind && checked.GetType(e.ID()).TypeName() == actionsTypeName
}
var identCount, staticCount int
seen := map[string]struct{}{}
visitor := celast.NewExprVisitor(func(e celast.Expr) {
switch e.Kind() {
case celast.IdentKind:
if e.AsIdent() == "actions" {
identCount++
}
case celast.SelectKind:
sel := e.AsSelect()
if !isActionsIdent(sel.Operand()) {
return
}
switch {
case isRoot(e):
identCount++
case e.Kind() == celast.SelectKind && isRoot(e.AsSelect().Operand()):
staticCount++
seen[sel.FieldName()] = struct{}{}
seen[e.AsSelect().FieldName()] = struct{}{}
}
})
celast.PreOrderVisit(ast.NativeRep().Expr(), visitor)
celast.PreOrderVisit(checked.Expr(), visitor)
ids := make([]string, 0, len(seen))
for id := range seen {
ids = append(ids, id)
@@ -332,11 +323,6 @@ func actionReferences(ast *cel.Ast) ([]string, bool) {
return ids, identCount == staticCount
}
// isActionsIdent reports whether e is the `actions` context-root identifier.
func isActionsIdent(e celast.Expr) bool {
return e.Kind() == celast.IdentKind && e.AsIdent() == "actions"
}
// Program is a compiled, cost-limited playbook expression.
type Program struct {
prg cel.Program