Skip to content

Commit

Permalink
Expand upgrade validation testing (#19123)
Browse files Browse the repository at this point in the history
* Remove duplication from tests

* lint

* lint

* Simplify tests

* lint

* add more tests for dependency behaviour

* track new test files

* lint

* add test for failure being only emitted in the module that originates it

* fix stdout capture for rules_daml

* lint

* lint

* Move CannotUpgradeView into own section

* Fix more upgrades gen
  • Loading branch information
dylant-da committed Jul 10, 2024
1 parent 64b1f43 commit 9e0e0fa
Show file tree
Hide file tree
Showing 64 changed files with 787 additions and 92 deletions.
57 changes: 57 additions & 0 deletions sdk/compiler/damlc/tests/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -442,10 +442,67 @@ da_haskell_test(
da_haskell_test(
name = "upgrades",
srcs = ["src/DA/Test/DamlcUpgrades.hs"],
compiler_flags = ["-Wno-unused-local-binds"],
data = [
"//compiler/damlc",
"//daml-script/daml:daml-script.dar",
"//daml-script/runner:daml-script-binary",
"//test-common:upgrades-CannotUpgradeView-files",
"//test-common:upgrades-FailWhenATopLevelEnumChangesChangesTheOrderOfItsVariants-files",
"//test-common:upgrades-FailWhenATopLevelVariantChangesChangesTheOrderOfItsVariants-files",
"//test-common:upgrades-FailsOnlyInModuleNotInReexports-files",
"//test-common:upgrades-FailsWhenATopLevelRecordAddsANonOptionalField-files",
"//test-common:upgrades-FailsWhenATopLevelRecordAddsAnOptionalFieldBeforeTheEnd-files",
"//test-common:upgrades-FailsWhenATopLevelVariantAddsAFieldToAVariantsType-files",
"//test-common:upgrades-FailsWhenATopLevelVariantAddsAVariant-files",
"//test-common:upgrades-FailsWhenATopLevelVariantRemovesAVariant-files",
"//test-common:upgrades-FailsWhenAnInstanceIsDropped-files",
"//test-common:upgrades-FailsWhenAnInterfaceIsDefinedInAnUpgradingPackageWhenItWasAlreadyInThePriorPackage-files",
"//test-common:upgrades-FailsWhenExistingFieldInTemplateChoiceIsChanged-files",
"//test-common:upgrades-FailsWhenExistingFieldInTemplateIsChanged-files",
"//test-common:upgrades-FailsWhenNewFieldIsAddedToTemplateChoiceWithoutOptionalType-files",
"//test-common:upgrades-FailsWhenNewFieldIsAddedToTemplateWithoutOptionalType-files",
"//test-common:upgrades-FailsWhenOldFieldIsDeletedFromTemplate-files",
"//test-common:upgrades-FailsWhenOldFieldIsDeletedFromTemplateChoice-files",
"//test-common:upgrades-FailsWhenTemplateAddsKeyType-files",
"//test-common:upgrades-FailsWhenTemplateChangesKeyType-files",
"//test-common:upgrades-FailsWhenTemplateChoiceChangesItsReturnType-files",
"//test-common:upgrades-FailsWhenTemplateRemovesKeyType-files",
"//test-common:upgrades-FailsWhenTwoDeeplyNestedTypeSynonymsResolveToDifferentDatatypes-files",
"//test-common:upgrades-FailsWithSynonymReturnTypeChange-files",
"//test-common:upgrades-FailsWithSynonymReturnTypeChangeInSeparatePackage-files",
"//test-common:upgrades-MissingChoice-files",
"//test-common:upgrades-MissingDataCon-files",
"//test-common:upgrades-MissingModule-files",
"//test-common:upgrades-MissingTemplate-files",
"//test-common:upgrades-RecordFieldsNewNonOptional-files",
"//test-common:upgrades-SucceedWhenATopLevelEnumAddsAField-files",
"//test-common:upgrades-SucceedsWhenATopLevelEnumChanges-files",
"//test-common:upgrades-SucceedsWhenATopLevelRecordAddsAnOptionalFieldAtTheEnd-files",
"//test-common:upgrades-SucceedsWhenATopLevelTypeSynonymChanges-files",
"//test-common:upgrades-SucceedsWhenATopLevelVariantAddsAVariant-files",
"//test-common:upgrades-SucceedsWhenATopLevelVariantAddsAnOptionalFieldToAVariantsType-files",
"//test-common:upgrades-SucceedsWhenAnInstanceIsAddedSeparateDep-files",
"//test-common:upgrades-SucceedsWhenAnInstanceIsAddedUpgradedPackage-files",
"//test-common:upgrades-SucceedsWhenAnInterfaceIsOnlyDefinedInTheInitialPackage-files",
"//test-common:upgrades-SucceedsWhenNewFieldWithOptionalTypeIsAddedToTemplate-files",
"//test-common:upgrades-SucceedsWhenNewFieldWithOptionalTypeIsAddedToTemplateChoice-files",
"//test-common:upgrades-SucceedsWhenTemplateChoiceInputArgumentHasChanged-files",
"//test-common:upgrades-SucceedsWhenTemplateChoiceReturnsATemplateWhichHasChanged-files",
"//test-common:upgrades-SucceedsWhenTwoDeeplyNestedTypeSynonymsResolveToTheSameDatatypes-files",
"//test-common:upgrades-SucceedsWhenUpgradingADependency-files",
"//test-common:upgrades-TemplateChangedKeyType-files",
"//test-common:upgrades-ValidUpgrade-files",
"//test-common:upgrades-WarnsWhenAnInterfaceAndATemplateAreDefinedInTheSamePackage-files",
"//test-common:upgrades-WarnsWhenAnInterfaceIsDefinedAndThenUsedInAPackageThatUpgradesIt-files",
"//test-common:upgrades-WarnsWhenAnInterfaceIsUsedInThePackageThatItsDefinedIn-files",
"//test-common:upgrades-WarnsWhenControllersOfTemplateChoiceAreChanged-files",
"//test-common:upgrades-WarnsWhenObserversOfTemplateChoiceAreChanged-files",
"//test-common:upgrades-WarnsWhenTemplateChangesEnsure-files",
"//test-common:upgrades-WarnsWhenTemplateChangesKeyExpression-files",
"//test-common:upgrades-WarnsWhenTemplateChangesKeyMaintainers-files",
"//test-common:upgrades-WarnsWhenTemplateChangesObservers-files",
"//test-common:upgrades-WarnsWhenTemplateChangesSignatories-files",
],
hackage_deps = [
"base",
Expand Down
10 changes: 6 additions & 4 deletions sdk/daml-lf/validation/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -216,16 +216,16 @@ da_scala_test_suite(
"//test-common:upgrades-FailsWhenUpgradingV3ThenV2-v3.dar",

# More tests ported from DamlcUpgrades.hs
"//test-common:upgrades-FailsWhenATopLevelEnumChanges-v1.dar",
"//test-common:upgrades-FailsWhenATopLevelEnumChanges-v2.dar",
"//test-common:upgrades-SucceedsWhenATopLevelEnumChanges-v1.dar",
"//test-common:upgrades-SucceedsWhenATopLevelEnumChanges-v2.dar",
"//test-common:upgrades-FailsWhenATopLevelRecordAddsANonOptionalField-v1.dar",
"//test-common:upgrades-FailsWhenATopLevelRecordAddsANonOptionalField-v2.dar",
"//test-common:upgrades-FailsWhenATopLevelRecordAddsAnOptionalFieldBeforeTheEnd-v1.dar",
"//test-common:upgrades-FailsWhenATopLevelRecordAddsAnOptionalFieldBeforeTheEnd-v2.dar",
"//test-common:upgrades-FailsWhenATopLevelVariantAddsAFieldToAVariantsType-v1.dar",
"//test-common:upgrades-FailsWhenATopLevelVariantAddsAFieldToAVariantsType-v2.dar",
"//test-common:upgrades-FailsWhenATopLevelVariantAddsAnOptionalFieldToAVariantsType-v1.dar",
"//test-common:upgrades-FailsWhenATopLevelVariantAddsAnOptionalFieldToAVariantsType-v2.dar",
"//test-common:upgrades-SucceedsWhenATopLevelVariantAddsAnOptionalFieldToAVariantsType-v1.dar",
"//test-common:upgrades-SucceedsWhenATopLevelVariantAddsAnOptionalFieldToAVariantsType-v2.dar",
"//test-common:upgrades-FailsWhenATopLevelVariantAddsAVariant-v1.dar",
"//test-common:upgrades-FailsWhenATopLevelVariantAddsAVariant-v2.dar",
"//test-common:upgrades-FailsWhenATopLevelVariantRemovesAVariant-v1.dar",
Expand Down Expand Up @@ -258,6 +258,8 @@ da_scala_test_suite(
"//test-common:upgrades-SucceedsWhenAnInstanceIsAddedSeparateDep-v2.dar",
"//test-common:upgrades-SucceedsWhenAnInstanceIsAddedUpgradedPackage-v1.dar",
"//test-common:upgrades-SucceedsWhenAnInstanceIsAddedUpgradedPackage-v2.dar",
"//test-common:upgrades-SucceedsWhenATopLevelVariantAddsAVariant-v1.dar",
"//test-common:upgrades-SucceedsWhenATopLevelVariantAddsAVariant-v2.dar",
],
flaky = False,
scala_deps = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,8 +426,8 @@ trait LongTests { this: UpgradesSpec =>

"Succeeds when a top-level variant adds a variant" in {
testPackagePair(
"test-common/upgrades-FailsWhenATopLevelVariantAddsAVariant-v1.dar",
"test-common/upgrades-FailsWhenATopLevelVariantAddsAVariant-v2.dar",
"test-common/upgrades-SucceedsWhenATopLevelVariantAddsAVariant-v1.dar",
"test-common/upgrades-SucceedsWhenATopLevelVariantAddsAVariant-v2.dar",
assertPackageUpgradeCheck(None),
)
}
Expand Down Expand Up @@ -468,16 +468,16 @@ trait LongTests { this: UpgradesSpec =>

"Succeeds when a top-level variant adds an optional field to a variant's type" in {
testPackagePair(
"test-common/upgrades-FailsWhenATopLevelVariantAddsAnOptionalFieldToAVariantsType-v1.dar",
"test-common/upgrades-FailsWhenATopLevelVariantAddsAnOptionalFieldToAVariantsType-v2.dar",
"test-common/upgrades-SucceedsWhenATopLevelVariantAddsAnOptionalFieldToAVariantsType-v1.dar",
"test-common/upgrades-SucceedsWhenATopLevelVariantAddsAnOptionalFieldToAVariantsType-v2.dar",
assertPackageUpgradeCheck(None),
)
}

"Succeeds when a top-level enum changes" in {
testPackagePair(
"test-common/upgrades-FailsWhenATopLevelEnumChanges-v1.dar",
"test-common/upgrades-FailsWhenATopLevelEnumChanges-v2.dar",
"test-common/upgrades-SucceedsWhenATopLevelEnumChanges-v1.dar",
"test-common/upgrades-SucceedsWhenATopLevelEnumChanges-v2.dar",
assertPackageUpgradeCheck(None),
)
}
Expand Down
10 changes: 8 additions & 2 deletions sdk/rules_daml/daml.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,13 @@ def _daml_build_impl(ctx):
damlc = ctx.executable.damlc
input_dars = [file_of_target(k) for k in dar_dict.keys()]
output_dar = ctx.outputs.dar
output_stdout = ctx.outputs.stdout
posix = ctx.toolchains["@rules_sh//sh/posix:toolchain_type"]
ghc_opts = ctx.attr.ghc_options
ctx.actions.run_shell(
tools = [damlc],
inputs = [daml_yaml] + srcs + input_dars,
outputs = [output_dar],
outputs = [output_dar] + ([output_stdout] if output_stdout != None else []),
progress_message = "Building Daml project %s" % name,
command = """
set -eou pipefail
Expand All @@ -131,7 +132,7 @@ def _daml_build_impl(ctx):
{sed} -i 's/daml-script$/daml-script.dar/;s/daml-trigger$/daml-trigger.dar/' $tmpdir/daml.yaml
{cp_srcs}
{cp_dars}
{damlc} build --project-root $tmpdir {ghc_opts} -o $PWD/{output_dar}
{damlc} build --project-root $tmpdir {ghc_opts} -o $PWD/{output_dar} 2>&1 | {output_stdout_command}
""".format(
config = daml_yaml.path,
cp_srcs = "\n".join([
Expand All @@ -152,6 +153,7 @@ def _daml_build_impl(ctx):
sed = posix.commands["sed"],
damlc = damlc.path,
output_dar = output_dar.path,
output_stdout_command = "tee " + output_stdout.path if output_stdout != None else "cat",
sdk_version = sdk_version,
ghc_opts = " ".join(ghc_opts),
),
Expand Down Expand Up @@ -179,6 +181,9 @@ _daml_build = rule(
mandatory = True,
doc = "The generated DAR file.",
),
"stdout": attr.output(
doc = "The standard output of the build command.",
),
"ghc_options": attr.string_list(
doc = "Options passed to GHC.",
default = ["--ghc-option=-Werror", "--log-level=WARNING"],
Expand Down Expand Up @@ -347,6 +352,7 @@ def daml_compile(
dar_dict =
{dar: path_to_dar(dar) for dar in (dependencies + data_dependencies + ([upgrades] if upgrades else []))},
dar = name + ".dar",
stdout = name + ".stdout",
ghc_options =
ghc_options +
(["--enable-scenarios=yes"] if enable_scenarios and (target == None or _supports_scenarios(target)) else []),
Expand Down
Loading

0 comments on commit 9e0e0fa

Please sign in to comment.