Skip to content

Conversation

viksit
Copy link
Collaborator

@viksit viksit commented Jun 4, 2025

this PR implements matchesPattern and matchesSpec with a new compileMatchSpec helper that turns a spec into a fast predicate function, supports wildcards (_, *), full Lua regex, numeric and boolean literals, functions, and OR-style tables.

  • introduces a module-level _matchSpecCache so identical specs compile once and then get reused.
  • refactors addAssignable, removeAssignable, and isAssignable to carry both the raw spec and its compiled predicate, guaranteeing consistent updates and deletions.
  • adds hyper/spec/assignment_spec.lua suite that tests the new pattern engine, tag matching, caching behavior, and assignable bookkeeping.

hyper/src/utils.lua

  • supports exact equality, wildcards ('*'/'_'), full lua regex patterns
  • added function patterns with (value, msg) context
  • added table patterns with OR logic (any sub-pattern matches)
  • enhanced strict field validation (fails on missing expected fields)
  • one-shot compile with compiled predicate cached on spec table (__matcher key)
  • backward compatibility for top-level and body field lookup

hyper/src/assignment.lua

  • added intelligent pattern caching trigger in addAssignable()
  • enhanced isAssignable() to automatically use cached compiled patterns
  • should maintain full api compatibility with existing assignment workflows

hyper/spec/assignment_spec.lua

  • main test file
  • truth-table coverage for equality, wildcard, regex, function, table patterns
  • performance characteristics testing with cached matcher verification
  • strict field validation and complex nested pattern scenarios
  • edge cases, error handling, and backward compatibility validation
viksit@hyperion hyper % busted
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●Error handling message
spec/process_spec.lua:192: Test error
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
231 successes / 0 failures / 0 errors / 0 pending : 0.144643 seconds

@viksit viksit changed the base branch from main to feat/m3 June 4, 2025 07:21
@twilson63
Copy link
Collaborator

Good start,

The core focus of this task is to port the assignments module

https://github.com/permaweb/aos/blob/main/process/assignment.lua

@viksit viksit force-pushed the viksit/m3/assignments branch from 803aa5f to c0c2917 Compare June 6, 2025 09:40
@twilson63
Copy link
Collaborator

To create a unit test to test assignments you want to call the main function passing a base and a req

The base is the state

base = {
  process = {Add Process Message Here}
  results = {}
}
req = {
  slot = 0,
  body = {
     [Add your message here ],
     target = [Not the id of the process]
  }
}

Call main(base, req)
and the message should fail if the message does not match the criteria added for assignments

Then create a test that passes a message that does match the criteria for assignments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants