git.delta.rocks / jrsonnet / refs/heads / master

difftreelog

source

tests/golden/super_assert.jsonnet1.3 KiBsourcehistory
1// From rustanka:23// Minimal reproduction of infinite recursion bug with super + assertions4// This pattern is from loki's compactor-worker.libsonnet + arm.libsonnet5//6// The issue: when using super in field definition AND having an assertion7// that accesses that same field via $, jrsonnet detects infinite recursion8// but go-jsonnet handles it correctly.910local base = {11  deployment: { spec: { replicas: 1 } },12};1314local autoscaling = {15  _config+:: {16    autoscaling: {17      enabled: false,18      // This assertion accesses $.deployment, which triggers the recursion19      assert (20        if self.enabled21        then std.get($.deployment.spec, 'replicas') == null22        else $.deployment.spec.replicas == 123      ) : 'replicas check failed',24    },25  },2627  // This field uses super AND the condition depends on _config which has the assertion28  deployment: std.mergePatch(29    super.deployment,30    if $._config.autoscaling.enabled then { spec+: { replicas: null } } else {},31  ),32};3334local arm = {35  // This function mimics overrideSuperIfExists from arm.libsonnet36  local overrideSuperIfExists(name, override) =37    if !( name in super) || super[name] == null || super[name] == {}38    then null39    else super[name] + override,4041  deployment: overrideSuperIfExists('deployment', {}),42};4344// The combination triggers the bug45base + autoscaling + arm