Files
kubevela/pkg
Jerrin FrancisandGitHub a6c7a56602 Fix: auto-detect "strings" import for StringParam MinLen/MaxLen in defkit (#7098)
* fix(defkit): auto-detect "strings" import for StringParam MinLen/MaxLen

  StringParam with MinLen or MaxLen generates CUE constraints using
  strings.MinRunes() and strings.MaxRunes(), but the CUE generator only
  scanned template elements for required imports — never the parameter
  list itself. This caused generated definitions to fail validation with
  `reference "strings" not found`.

  - Implement ImportRequirer on StringParam, returning ["strings"] when
    MinLen or MaxLen is set.
  - Extend detectRequiredImports to scan component parameters in addition
    to template helpers and resources.

Signed-off-by: Jerrin Francis <jerrinfrancis7@gmail.com>

* Adding testcases

Signed-off-by: Jerrin Francis <jerrinfrancis7@gmail.com>

* test(defkit): match multi-line CUE import block in auto-import tests

  The generated CUE emits imports as a block:

      import (
          "strings"
      )

  The assertions were checking for the single-line form `import "strings"`,
  which never matched. Replace with MatchRegexp(`import\s+\(\s+"strings"\s+\)`)
  so the regex matches any whitespace (incl. newlines) between `import`, `(`,
  `"strings"`, and `)`. Also count `"strings"` (not `import "strings"`) when
  asserting the import is not duplicated.

Signed-off-by: Jerrin Francis <jerrinfrancis7@gmail.com>

* ci: retrigger checks

Signed-off-by: Jerrin Francis <jerrinfrancis7@gmail.com>

---------

Signed-off-by: Jerrin Francis <jerrinfrancis7@gmail.com>
2026-04-23 06:56:28 -07:00
..
2026-03-18 21:11:22 -07:00