Skip to content

validate: bundle tests hard-fail in downstream repos that correctly exclude template-bundles.yml #45

@HarryCampion

Description

@HarryCampion

Problem

The tests in .rhiza/tests/bundle_test.go and structure_test.go unconditionally require .rhiza/template-bundles.yml to exist, calling t.Fatalf (not t.Skipf) when the file is absent.

However, template-bundles.yml is a template-repo artefact — downstream projects correctly exclude it from sync via their .rhiza/template.yml:

exclude:
  - .rhiza/template-bundles.yml

When a downstream project runs make validate, all bundle tests (7 tests) and TestRequiredFilesExist/Template_bundle_definitions hard-fail:

--- FAIL: TestTemplateBundlesParses (0.00s)
    bundle_test.go:43: failed to read template-bundles.yml: open .rhiza/template-bundles.yml: no such file or directory
--- FAIL: TestTemplateBundlesVersionMatchesProject (0.00s)
    bundle_test.go:65: failed to read template-bundles.yml: open .rhiza/template-bundles.yml: no such file or directory
--- FAIL: TestCoreBundleIsRequired (0.00s)
    ...
--- FAIL: TestRequiredFilesExist/Template_bundle_definitions (0.00s)
    structure_test.go:33: required file missing: .rhiza/template-bundles.yml (Template bundle definitions)

This blocks make validate on every downstream repo that uses the tests bundle.

A second problem: version coupling

TestTemplateBundlesVersionMatchesProject compares template-bundles.yml's version field to the project VERSION file. In a downstream project the VERSION tracks the project release (e.g. 0.0.1-alpha.1), not the template version (0.2.4). These will never match, making the test permanently fail even if the downstream provides a local copy of template-bundles.yml.

The workaround used in this downstream project was to maintain a local template-bundles.yml with version set to the project's own version, which decouples it from the template version entirely — but this is awkward to keep in sync.

Suggested fixes

Option A — Skip gracefully when file is absent (minimal change)

In loadBundles, call t.Skip instead of t.Fatal when the file does not exist:

func loadBundles(t *testing.T) *bundleConfig {
    t.Helper()
    bundlePath := repoPath(".rhiza/template-bundles.yml")
    data, err := os.ReadFile(bundlePath)
    if err != nil {
        if os.IsNotExist(err) {
            t.Skip("template-bundles.yml not present (downstream repo — skipping bundle tests)")
        }
        t.Fatalf("failed to read template-bundles.yml: %v", err)
    }
    ...
}

Apply the same treatment to the structure_test.go entry.

Option B — Move bundle tests out of the synced tests bundle

Keep bundle_test.go in the template repo only (not synced to downstream projects). The tests are only meaningful in the template repo itself.

Option C — Fix the version coupling

Stop comparing template-bundles.yml version to the project VERSION. The bundle file version tracks the template release, not the downstream project release. Consider removing TestTemplateBundlesVersionMatchesProject entirely, or only running it when the file is present and RHIZA_REPO=template is set.


Relates to #44 (the bumpversion entry for template-bundles.yml also causes issues in downstream repos).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions