Skip to content

Five unit test files hold their literal-duplicate cases as parametrize tables - #294

Merged
zlareb1 merged 10 commits into
mainfrom
tests/parametrize-literal-duplicates
Nov 6, 2026
Merged

zlareb1 merged 10 commits into
mainfrom
tests/parametrize-literal-duplicates

Conversation

@zlareb1

@zlareb1 zlareb1 commented Nov 6, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

Changelog entry (one or two sentences a user of Loom can read without the diff; the release pull request collects these into the release notes):

...

Why

A scan of tests/unit for test functions whose bodies are identical once their literals are replaced found 95 groups in 19,096 functions. That is 129 functions that differ from a sibling only in the values they pass. These five files hold the largest groups, 33 of the 129. Each group, with the neighbouring tests of the same shape that differ in a name or a second call, is now a pytest.mark.parametrize table whose name holds for every row, 38 functions fewer. Every case keeps an id that names the behaviour it pins, so a failure still says which case broke. The comment that explained a case moved onto its row.

File Test functions Test cases
test_entity_stable_keys.py 21 → 9 21 → 21
test_lemmatize.py 13 → 5 13 → 19
test_identifier_grounding.py 12 → 4 12 → 12
test_migrate_settings.py 9 → 3 9 → 9
test_injectable_identifiers.py 9 → 5 9 → 10
total 64 → 26 64 → 71

The other 96 duplicate functions are pairs and triples spread over 68 files, many of them in areas other open pull requests are changing. Folding them saves no CI time, since a parametrized case costs what a function did. The CI time comes from running the suites in parallel (#287, #288, #290).

Scope and risk

Five unit test files. No server code. No case is dropped: each removed function's assertion is a row in the table that replaces it. Four functions held two lemmatize assertions each, and each assertion is now its own case. Three cases are new. One is a seven-digit zero-padded id, which only the zero-padded-id shape of _injectable_identifiers catches (the five-digit id already in the file, 05059, is caught by the salient-number path first, so no row pinned the zero-padded shape). The other two are lemmatize rows, its and used, each one character too short for its rule: the old short-word test claimed to pin the length guard, but the matches no rule, so no row pinned a guard against a word one character too short. 64 cases became 71.

Removed test Now pinned by
test_entity_stable_keys.py::test_pr_number_in_value_prefixes_key test_entity_stable_key_prefixes_the_salient_entity[PR number in the value]
…::test_pr_number_no_separator_prefixes_key …[PR number without a separator, from the entities]
…::test_bare_hash_ref_treated_as_pr …[bare hash ref is a PR]
…::test_issue_number_prefixes_with_issue …[issue number prefixes with issue]
…::test_handle_prefixes_key …[handle in the value]
…::test_handle_from_entities_list …[handle from the entities]
…::test_test_keyword_id_prefixes_key …[test keyword and id]
…::test_bare_test_file_convention_prefixes_key …[bare test file convention]
…::test_no_entity_leaves_key_unchanged test_entity_stable_key_leaves_a_key_without_a_salient_entity[no entity leaves the key]
…::test_lone_small_number_is_not_a_pr test_entity_stable_key_leaves_a_key_without_a_salient_entity[lone small number is not a PR]
…::test_concept_suffix_strips_multiple_generic_prefixes test_entity_stable_key_prefixes_the_salient_entity[several generic prefixes stripped]
…::test_all_generic_key_is_not_stripped_to_empty test_entity_stable_key_prefixes_the_salient_entity[all-generic key not emptied]
…::test_priority_pr_beats_handle test_entity_stable_key_prefixes_the_salient_entity[PR beats handle]
…::test_handle_ignores_email_local_part test_entity_stable_key_leaves_a_key_without_a_salient_entity[email local part is not a handle]
test_lemmatize.py::test_plural_to_singular test_lemmatize_strips_the_suffixes_of_each_token[plural to singular], [plural to singular, short stem]
…::test_gerund_to_stem …[gerund to stem]
…::test_past_tense_to_stem …[past tense to stem]
…::test_ies_to_y …[ies to y], [ies to y, long stem]
…::test_ier_to_y …[ier to y]
…::test_case_insensitive …[case insensitive], [case insensitive, all caps]
…::test_punctuation_passes_through_as_spaces …[punctuation passes as spaces]
…::test_irregular_words_pass_through test_lemmatize_leaves_or_drops_a_token_no_rule_applies_to[irregular word passes through]
…::test_short_words_unchanged test_lemmatize_leaves_or_drops_a_token_no_rule_applies_to[no suffix rule matches], [single char dropped]
…::test_double_letters_intentional_imperfection test_lemmatize_strips_the_suffixes_of_each_token[double letter kept]
…::test_empty_input test_empty_input_lemmatizes_to_nothing, with both its assertions
test_identifier_grounding.py::test_pr_number_absent_from_hits_returns_reason test_identifier_grounding_missing_names_the_first_identifier_when_none_is_grounded[PR number absent]
…::test_pr_number_present_in_a_hit_returns_none test_identifier_grounding_missing_is_none_when_an_identifier_is_grounded_or_there_is_none[PR number present]
…::test_hash_and_bare_number_forms_ground_the_same_id test_identifier_grounding_missing_is_none_when_an_identifier_is_grounded_or_there_is_none[hash and bare number]
…::test_handle_absent_returns_reason test_identifier_grounding_missing_names_the_first_identifier_when_none_is_grounded[handle absent]
…::test_handle_present_returns_none test_identifier_grounding_missing_is_none_when_an_identifier_is_grounded_or_there_is_none[handle present]
…::test_no_identifier_query_returns_none test_identifier_grounding_missing_is_none_when_an_identifier_is_grounded_or_there_is_none[no identifier]
…::test_grounding_is_case_insensitive test_identifier_grounding_missing_is_none_when_an_identifier_is_grounded_or_there_is_none[case insensitive]
…::test_multiple_identifiers_one_present_returns_none test_identifier_grounding_missing_is_none_when_an_identifier_is_grounded_or_there_is_none[one of several present]
…::test_multiple_identifiers_all_absent_returns_first test_identifier_grounding_missing_names_the_first_identifier_when_none_is_grounded[all absent names the first]
…::test_empty_hits_with_identifier_returns_reason test_identifier_grounding_missing_names_the_first_identifier_when_none_is_grounded[no hits]
test_migrate_settings.py::test_statistics_statement_gets_statistics_flag test_a_statement_gets_the_flags_its_features_or_table_need[statistics]
…::test_nlp_stem_statement_gets_nlp_flag …[nlp stem]
…::test_vector_similarity_index_gets_vector_flag …[vector similarity index]
…::test_plain_statement_gets_no_flags …[plain]
…::test_statement_using_multiple_features_gets_all_flags …[several features get every flag]
…::test_alter_memory_embeddings_gets_nlp_flag_without_naming_the_func …[memory_embeddings ALTER without the function]
…::test_alter_table_without_nlp_columns_gets_no_nlp_flag …[other table ALTER gets no nlp flag]
test_injectable_identifiers.py::test_catches_pascalcase_handle test_an_identifier_shape_that_semantic_recall_misses_is_injected[PascalCase handle]
…::test_catches_snake_case_setting …[snake_case setting]
…::test_catches_zero_padded_test_id …[five-digit test id]
…::test_catches_stid …[STID]
…::test_catches_file_line …[file and line]

Compatibility, rollout and rollback

  • Wire: none.
  • Operator steps: none.
  • Rollback: revert.

Tests

The five files pass: 71 cases, the 64 before, four split out of two-assertion functions, the seven-digit id and the two length-guard rows.

Coverage: run alone, each file executes the same lines and branches of the module it tests as it did before the change, measured again at the head. I compared the coverage JSON of each file on main and on this branch: pytest --cov=<module> --cov-branch <file>.

Mutation testing used cosmic-ray, locally only and not added to CI. Each module was mutated, and its test file run against each mutant. Mutants on lines the file never executes survive both versions alike, so they were marked skipped for both. The same mutants ran before and after, and no kill was lost. The seven new kills in identifiers.py are in the injection loop and its length and stop-word guard (lines 237-250). Every row runs that loop, but only the seven-digit row's assertion depends on it, since every other row's identifier is also found by another path, before the loop or after it; the four in lemmatize.py are the -ed and -s length guards (lines 23 and 39):

Module (test file) Mutants run Killed before Killed after
server/memory/domain/lemmatize.py (test_lemmatize.py) 173 110 114
server/memory/app/extract/keys.py (test_entity_stable_keys.py) 116 92 92
server/memory/domain/retrieval_calibration.py (test_identifier_grounding.py) 61 41 41
server/memory/app/ask/identifiers.py (test_injectable_identifiers.py) 65 14 21
server/core/schema/migrate.py (test_migrate_settings.py) 169 46 46
cosmic-ray init <session>.toml <session>.sqlite   # module-path and test-command per row above
cosmic-ray exec <session>.toml <session>.sqlite

AI assistance in the code (leave one; writing this description with AI is fine):

  • AI-generated (an agent wrote most of the diff): Claude Code. The author checked the case counts, coverage and mutation scores before and after.

  • I can explain every line of this diff and how it interacts with the rest of Loom.

Checklist

  • make format-check, make lint, make typecheck and make test-unit pass; the integration suite passes if server behaviour changed.
  • Generated files are regenerated in this PR, not by hand.
  • A new migration is additive and numbered after the latest on main; no merged migration is edited.
  • A behaviour change to any file a plugin ships bumps both plugin manifests' version.
  • The frontend builds and its tests pass, if frontend/ changed.
  • Docs under docs/ describe the system as it now is.
  • Repository text has no dates, people, host names, internal namespaces, ticket or decision numbers.
  • Commits are signed off (git commit -s).

🤖 Generated with Claude Code

zlareb1 and others added 10 commits November 6, 2026 14:42
…oken handle keeps its own test, a seven-digit row pins the zero-padded shape

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…ding splits into the named and the none cases

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
… own table, the shape test's name reads as a sentence

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…e -s and -ed length guards

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…able name say what each row pins

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
@zlareb1
zlareb1 merged commit 7894a0c into main Nov 6, 2026
23 of 24 checks passed
@zlareb1
zlareb1 deleted the tests/parametrize-literal-duplicates branch November 6, 2026 17:14
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.

1 participant