databrickslabs / databrickslabs/ontos

[Bug]: test_semantic_links_manager.py — 2 pre-existing failures on main

Open
#486 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

roadmap/v1.1.0 scope/ontology tech/python tech/testing type/bug
Dominant language
Python
Stars
212
Forks
71
Avg merge
4d 10h
Merged PRs (30d)
43

Description

Summary

Two pre-existing test failures in src/backend/src/tests/unit/test_semantic_links_manager.py reproduce on a clean checkout of `main` (also seen in PR #483 CI, where they are pre-existing). They are blocking nothing because they are isolated to this file, but they hide regressions in `SemanticLinksManager`.

Failing tests

```
FAILED src/tests/unit/test_semantic_links_manager.py::TestSemanticLinksManager::test_to_api_without_label_resolves_name
FAILED src/tests/unit/test_semantic_links_manager.py::TestSemanticLinksManager::test_add_link_success
```

Failure details

1. `test_to_api_without_label_resolves_name`

Test mocks `mock_db.execute().fetchone()` to return a row whose `getitem` yields `"Resolved Name"`, and expects `_to_api` to set `result.label = "Resolved Name"` when the DB row has no label. Actual:

```
AssertionError: assert 'Product' == 'Resolved Name'
```

i.e. `_to_api` is returning the IRI's trailing token (`Product` from `http://example.com/schema/Product\`) rather than running the SQL fallback to resolve the persisted entity name. Likely either:

  • The SQL fallback path changed and is no longer wired, or
  • The test mocks the wrong session method (e.g. `_to_api` now uses `session.scalar(...)` / `session.query(...)` instead of `session.execute(...).fetchone()`).

Either way the test no longer reflects the implementation.

2. `test_add_link_success`

```
AssertionError: Expected 'flush' to have been called once. Called 0 times.
```

`add_link` no longer calls `session.flush()` (either replaced with `commit`, removed because the repo handles persistence, or refactored into a different sequence). Also surfaces noisy collateral errors during fixture setup:

```
Failed to sync taxonomy odcs-ontology.ttl: unsupported operand type(s) for +=: 'int' and 'Mock'
Failed to load triples from database: 'Mock' object is not iterable
```

…suggesting the fixture wiring around `SemanticModelsManager` is also stale — the manager initializer now reads/aggregates data from the DB during construction that the test fixture doesn't stub.

Suggested fix

Audit `SemanticLinksManager._to_api` and `SemanticLinksManager.add_link` against the test expectations. Realistically:

  • Rewrite the two tests to mock against the current session API used by the manager.
  • Tighten the fixture so constructing the manager does not trigger the bundled-taxonomy sync path (either inject a no-op `SemanticModelsManager`, or set a flag that skips graph rebuild during tests).

Why now

These showed up in the term-mapping (#483) CI as pre-existing failures and were noted but explicitly left out of scope. Filing as a separate issue so the test suite goes back to green and changes to `SemanticLinksManager` (which Term Mapping leans on for link writes) get caught by these tests instead of by manual UI testing.

Repro

```bash
cd src/backend
hatch -e dev run pytest src/tests/unit/test_semantic_links_manager.py -x
```

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with src/backend/src/tests/unit/test_semantic_links_manager.py and run cd src/backend && hatch -e dev run pytest src/tests/unit/test_semantic_links_manager.py -x. Compare the two failing tests with SemanticLinksManager._to_api and add_link, then inspect fixture setup around SemanticModelsManager. Done means both tests pass without the taxonomy-sync and database-loading fixture errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend, testing-qa
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.