#
# Unresolved variables end up in reports and files prommises
#

body common control
{
      bundlesequence => { run, dmi, etc_nologin };
}

bundle agent run
{
  classes:
      "dim_found" expression => regcmp("^[1-9][0-9]*$", $(dim));

  vars:
      "data" string => "PURPLE_DINOSAUR: Ubuntu";
      "dim" int => parsestringarray(
                                     "lsb",
                                     $(data),
                                     "\s*#[^\n]*",
                                     "\s*:\s+",
                                     "15",
                                     "4095"
      );

    dim_found::
      "PURPLE_DINOSAUR" string => canonify("$(lsb[PURPLE_DINOSAUR][1])");

  files:
      "$(PURPLE_DINOSAUR)" create => "true";
      "$(sys.workdir)/state/anotherfile" create => $(PURPLE_DINOSAUR);

  reports:
    dim_found::
      "$(this.bundle): value = $(PURPLE_DINOSAUR)";
}

# inventory DMI decoder, simplified for this test
bundle agent dmi
{
  vars:
      "dmivars" slist => { "PURPLE_DINOSAUR" };
    secondpass::
      "dmi[$(dmivars)]" string => execresult("echo Not A Dinosaur", "useshell");

  classes:
      "secondpass" expression => "any";

  reports:
      "$(this.bundle): Obtained qualified '$(dmi.dmi[$(dmivars)])'"; # fails
      "$(this.bundle): Obtained unqualified '$(dmi[$(dmivars)])'"; # fails
}

# the System::nologin sketch, simplified for this test
bundle agent etc_nologin()
{
  vars:
    secondpass::
      "PURPLE_DINOSAUR" string => "$(sys.workdir)/state", policy => "free";

  classes:
      "secondpass" expression => "any";

  vars:
      "etc_nologin" string => "$(PURPLE_DINOSAUR)/etc/nologin";

  files:
      "$(etc_nologin)" create => "true";

  reports:
      "$(etc_nologin)";
}
# THIS LAST BUNDLE IS FAILING!
# TODO implement skipping of promises that have unresolved variables; ways:
#   a. scan for dollar-paren and skip if found
#      -- this will make it impossible to have any dollar-paren strings
#   b. check if the dollar-paren variable is in any vars promise ...
