Skip to content

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

@larsgeorge-db

Description

@larsgeorge-db

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
```

Metadata

Metadata

Assignees

No one assigned

    Labels

    scope/ontologyOntology related featuretech/pythonPull requests that update python codetech/testingTesting: unit, integration, and UI test infrastructuretype/bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions