Skip to content

Conversation

@jost-s
Copy link
Contributor

@jost-s jost-s commented Feb 2, 2026

This PR adds Rust tests when an entry type or a collection are scaffolded. It also adds unit tests for some of the used functions.

It was a nightmare to fiddle with Rust's idiosyncrasies like ownership that requires clones, strong typing etc. and all that having to always rebuild the whole binary to pick up the changed templates and then run through scaffolding a web-app and entries to see the changes in rendered files. Therefore the unit tests. Which are a bit easier to handle, but the repo structure is still pretty clunky.

Note that I haven't deleted anything Tryorama related yet, to make this PR easier to review.

resolves #533

Summary by CodeRabbit

  • New Features

    • Entry-type scaffolding now includes the integrity zome manifest so generated templates and tests reflect integrity-zome context.
  • Tests

    • Vastly expanded unit/integration test scaffolding and helpers for entry types, collections, and zomes.
    • Test templates now use cargo test and include additional test utilities; added a dev-only assertion helper.
  • Chores

    • Bumped multiple Holochain-related versions to dev releases.
    • Updated dev environment to Node.js 24, adjusted package/workspace scripts, and made test runner invocation more verbose while skipping npm test steps.

@coderabbitai
Copy link

coderabbitai bot commented Feb 2, 2026

Walkthrough

Add SweetTest-based Rust test templates and helpers; inject holochain as a workspace dependency (with default-features = false) via a new workspace helper; bump multiple Holochain-related version constants to dev releases; update dev environment Node version and web-app test scripts; expose an API to add workspace dependencies; pass integrity zome manifests into entry-type templating; and add many template/unit tests and test helpers.

Changes

Cohort / File(s) Summary
Versions & dev env
src/versions.rs, src/cli/custom-template/flake.nix, flake.nix
Bumped HOLOCHAIN/HDK/HDI/HC_* constants to dev-suffixed versions; updated flake devShell Node from nodejs_22nodejs_24.
Workspace Cargo management
src/scaffold/app/cargo.rs, Cargo.toml
Added public add_workspace_dependency() that inserts/updates workspace.dependencies and tests; added pretty_assertions = "1.4" under [dev-dependencies].
Zome scaffolding & deps
src/scaffold/zome.rs, src/scaffold/zome/coordinator.rs
Now injects holochain into workspace dependencies using HOLOCHAIN_VERSION and default-features = false; coordinator zome initial Cargo.toml includes dev/test deps and new unit tests.
Entry-type scaffolding API
src/scaffold/entry_type.rs, src/templates/entry_type.rs
Persist integrity zome manifest and pass it into scaffold_entry_type_templates; added ScaffoldEntryTypeData.integrity_zome_manifest: ZomeManifest field and updated function signatures.
Template behavior & filters
src/templates/collection.rs, src/templates/entry_type.rs
When no_spec is true, template directory filtering also excludes dnas (in addition to tests).
Extensive template tests & helpers
src/templates/entry_type/tests.rs, src/templates/entry_type/tests/common.rs, src/templates/entry_type/tests/entry_type.rs
Large suites of unit tests and helpers added to validate template rendering across many entry-type permutations and collection templates.
SweetTest Rust templates
templates/generic/entry-type/.../tests/*.hbs, templates/generic/collection/.../tests/*.hbs, templates/generic/entry-type/.../tests/common.rs.hbs
Added SweetTest-based Rust test templates and helpers (sample/create helpers) and comprehensive CRUD/propagation/delete test templates for coordinator zomes and collections.
Web app script/templates & CI helper
templates/generic/web-app/package.json.hbs, run_test.sh
Removed tests workspace from package.json.hbs, set test script to cargo test, added scripts.build:zomes; enabled set -x tracing and removed some npm run test steps in run_test.sh.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • feat: Upgrade to 0.6 #512: Modifies the same version constants and flake inputs (src/versions.rs, flake.nix), indicating a direct code-level relation.

Suggested reviewers

  • mattyg
  • ThetaSinner
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 76.54% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title 'Refactor/replace tryorama with sweettest' directly reflects the main change: switching from tryorama to sweettest test framework as a primary objective.
Linked Issues check ✅ Passed The PR substantially addresses #533 requirements: creates Rust sweettest templates (test files, common helpers), updates versions.rs, modifies web-app templates, and removes tryorama/npm references from package.json. Most coding tasks are complete; TypeScript template deletion appears pending.
Out of Scope Changes check ✅ Passed All changes align with #533 scope: version updates, Rust test generation, template refactoring, and dev dependencies. NodeJS and flake.nix updates support the new Rust-based testing infrastructure.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch refactor/replace-tryorama-with-sweettest

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@jost-s jost-s force-pushed the refactor/replace-tryorama-with-sweettest branch from 0740fd7 to b4a2be5 Compare February 3, 2026 14:05
@jost-s jost-s marked this pull request as ready for review February 3, 2026 14:05
@jost-s jost-s force-pushed the refactor/replace-tryorama-with-sweettest branch from b4a2be5 to 3caa96d Compare February 3, 2026 14:06
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Fix all issues with AI agents
In `@src/scaffold/zome/coordinator.rs`:
- Line 43: The Cargo dependency declaration for the holochain crate currently
includes a non-existent feature "transport-iroh"; remove "transport-iroh" from
the features list on the holochain dependency (the line containing holochain =
{{ workspace = true, optional = true, features = ["wasmer_sys",
"transport-iroh", "test_utils"] }}) or, if that transport feature is needed, add
a separate dependency entry for holochain_cli_client and put "transport-iroh" in
its features instead; ensure the holochain features list only contains valid
features such as "wasmer_sys" and "test_utils".

In `@src/templates/entry_type/tests/entry_type.rs`:
- Around line 362-385: The function expected_rendered_create_and_update
currently hardcodes the origin getter name ("get_original_test_post") when
calling expected_create_and_read_test; change this to build the name from the
entry_type_name_snake_case parameter (e.g., using
format!("get_original_{entry_type_name_snake_case}")) so it matches
expected_rendered_create_and_update_and_delete and works for non-"test_post"
types; update the call site in expected_rendered_create_and_update (and ensure
the second argument remains "hash.clone()" and the third stays None) to use the
dynamic name.

In
`@templates/generic/entry-type/dnas/`{{dna_role_name}}/zomes/coordinator/{{coordinator_zome_manifest.name}}/tests/common.rs.hbs:
- Around line 16-25: When cardinality is "vector" and the template emits a
linked_from value for {{field_name}}, it's producing a single hash instead of a
Vec; update the branch in the {{coordinator_zome_manifest.name}} test template
so that when {{`#if` (eq cardinality "vector")}} and the linked_from is not
self-referential you wrap the produced hash in a Vec (e.g. vec![<hash>]) —
preserve the existing distinction between ActionHash (signed_action.hashed.hash)
and entry hash (signed_action.hashed.content.entry_hash()) but wrap either
result in vec![...] so {{field_name}} gets a Vec of hashes rather than a single
hash.
🧹 Nitpick comments (2)
templates/generic/collection/dnas/{{dna_role_name}}/zomes/coordinator/{{coordinator_zome_manifest.name}}/tests/{{kebab_case collection_name}}.rs.hbs (1)

16-21: Verify cell ordering assumption in cells_flattened().

The test assumes cells[0] belongs to the first conductor and cells[1] to the second. While this typically holds for SweetConductorBatch::standard(n) with a single DNA, the ordering relies on internal implementation details. Consider adding a brief comment documenting this assumption for future maintainability.

src/scaffold/app/cargo.rs (1)

235-238: The #[inline] attribute is unnecessary here.

For a trivial function that only returns PathBuf::new().join("Cargo.toml"), the compiler will inline this automatically. The #[inline] attribute is typically only needed for cross-crate inlining of non-trivial functions.

♻️ Suggested simplification
-#[inline]
 fn workspace_cargo_toml_path(_app_file_tree: &FileTree) -> PathBuf {
     PathBuf::new().join("Cargo.toml")
 }

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In
`@templates/generic/entry-type/dnas/`{{dna_role_name}}/zomes/coordinator/{{coordinator_zome_manifest.name}}/tests/common.rs.hbs:
- Around line 20-34: The template calls create_{{snake_case
linked_from.name}}(...).await.signed_action.hashed.content.entry_hash() for
fields that expect an EntryHash but doesn't handle the Option; update those
occurrences (the branches that call entry_hash()) to call
.entry_hash().unwrap().clone() so the value matches the expected EntryHash type
(keep the ActionHash branches unchanged); locate the calls within the
coordinator zome test template around the linked_from cases and replace
.entry_hash() with .entry_hash().unwrap().clone().

@jost-s jost-s requested a review from a team February 3, 2026 20:56
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@src/templates/entry_type/tests/common.rs`:
- Around line 297-460: The generated struct field type doesn't become optional
for self-referential linked_from fields, causing a mismatch with templates that
render None; update FieldDefinition::rust_type() to detect when linked_from is
Some(Referenceable::EntryType(entry_ref)) and entry_ref.entry_type equals the
parent EntryDefinition.name and cardinality is Cardinality::Single, and in that
case return an Option-wrapped type (as if Cardinality::Option) instead of the
raw ActionHash (or other type); ensure this logic references FieldDefinition,
rust_type(), Cardinality::Single, linked_from, and EntryTypeReference so
self-referential single fields are rendered as Option<T> to match the None
placeholder.
🧹 Nitpick comments (1)
src/templates/entry_type/tests/common.rs (1)

462-494: Consider a small helper or table-driven pattern to reduce repetition.
Most tests repeat the same EntryDefinition boilerplate; a simple builder helper would make adding new field types faster.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@src/templates/entry_type/tests/common.rs`:
- Around line 585-606: The test option_linked_from_agent_pub_key sets
linked_from to Referenceable::Agent but keeps field_type as FieldType::String,
causing a mismatch with the template which uses linked_from.hash_type(); update
the FieldDefinition in the EntryDefinition within the
option_linked_from_agent_pub_key test to use field_type: FieldType::AgentPubKey
so the rendered output and test expectation align with the linked_from-derived
type.
🧹 Nitpick comments (1)
templates/generic/entry-type/dnas/{{dna_role_name}}/zomes/coordinator/{{coordinator_zome_manifest.name}}/tests/common.rs.hbs (1)

11-101: Consider extracting deeply nested conditionals into partial templates.

The sample_{{snake_case entry_type.name}} function has 8+ levels of nesting due to the combinatorial logic for linked_from, cardinality, and field_type. While functionally correct, this depth makes the template harder to maintain and debug.

If Handlebars partials are available in your template system, consider extracting logical blocks (e.g., linked_from_vector.hbs, no_linked_from_single.hbs) to improve readability.

veeso
veeso previously approved these changes Feb 4, 2026
mattyg
mattyg previously approved these changes Feb 4, 2026
Copy link
Member

@mattyg mattyg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Monumental. I reviewed the best I could and scaffolded an app. Thanks for adding so many tests.

@jost-s jost-s dismissed stale reviews from mattyg and veeso via 35f7c9a February 4, 2026 18:28
@jost-s jost-s requested a review from mattyg February 4, 2026 18:31
@jost-s jost-s force-pushed the refactor/replace-tryorama-with-sweettest branch from 35f7c9a to 192cd58 Compare February 4, 2026 18:59
@cocogitto-bot
Copy link

cocogitto-bot bot commented Feb 4, 2026

✔️ 192cd58 - Conventional commits check succeeded.

@jost-s jost-s enabled auto-merge (rebase) February 4, 2026 19:01
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@src/templates/entry_type/tests/common.rs`:
- Around line 630-651: The test vector_action_hash_linked_from_self_reference
defines an invalid self-referential linked_from for a Vector cardinality; remove
or update this test so it only covers allowed self-references
(Cardinality::Option) — locate the test function
vector_action_hash_linked_from_self_reference and either delete it or change the
FieldDefinition so cardinality is Cardinality::Option (or remove the
linked_from), keeping the rest of the parameters (EntryDefinition,
FieldType::ActionHash, Referenceable::EntryType / EntryTypeReference) unchanged
to produce a valid scenario.
🧹 Nitpick comments (1)
run_test.sh (1)

2-2: Gate set -x to avoid leaking secrets in logs.
Consider enabling tracing only when explicitly requested.

🔧 Suggested change
-set -xe
+set -e
+[[ -n "${TRACE:-}" ]] && set -x

@jost-s jost-s merged commit 6dacfe1 into main Feb 4, 2026
13 checks passed
@jost-s jost-s deleted the refactor/replace-tryorama-with-sweettest branch February 4, 2026 20:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Switch from tryorama to sweettest

3 participants