Skip to content

test: cover determine_project_for_conversation fallback chain (closes #87)#89

Open
bradjin8 wants to merge 3 commits into
masterfrom
feat/tests-for-determin-project
Open

test: cover determine_project_for_conversation fallback chain (closes #87)#89
bradjin8 wants to merge 3 commits into
masterfrom
feat/tests-for-determin-project

Conversation

@bradjin8
Copy link
Copy Markdown
Collaborator

@bradjin8 bradjin8 commented Jun 2, 2026

Summary

Closes #87

  • Extends tests/test_workspace_assignment_fallback.py from 1 test to 21 (19 unit + 2 Hypothesis) for determine_project_for_conversation in services/workspace_resolver.py.
  • Adds dedicated coverage for all six resolution stages: definitive per-workspace mapping, projectLayouts, newlyCreatedFiles, codeBlockData, bubble header paths (relevantFiles, attachedFileCodeChunksUris, context.fileSelections), path-segment last resort, and terminal None.
  • Adds Hypothesis property tests (never raises on adversarial inputs; valid definitive mapping wins over conflicting layout signals) and temp-dir fixtures for file-path stages.

Test plan

  • python -m pytest tests/test_workspace_assignment_fallback.py -v
  • All 21 tests pass locally
  • CI (pytest, mypy, gitleaks) green on PR

Summary by CodeRabbit

  • Tests
    • Expanded unit suite for multi-stage workspace-to-project resolution with precedence rules.
    • Added coverage for resolution via composer mappings, project-layouts, file-paths, and conversation/bubble context.
    • Included property-based (fuzz) tests to ensure the resolver never raises on arbitrary inputs.
    • Added cases for malformed or missing data and verified behavior returns no match when all stages fail.

@bradjin8 bradjin8 self-assigned this Jun 2, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 2, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: bf1b2d49-c172-45ba-8a99-4de64fefbea8

📥 Commits

Reviewing files that changed from the base of the PR and between 5a22d46 and 0c914e4.

📒 Files selected for processing (1)
  • tests/test_workspace_assignment_fallback.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/test_workspace_assignment_fallback.py

📝 Walkthrough

Walkthrough

Adds a comprehensive unittest + Hypothesis suite exercising all stages of determine_project_for_conversation: helpers and setup, definitive mapping, project-layouts, file-path stages, bubble-context stages, path-segment fallback, terminal/malformed cases, and property-based fuzz tests.

Changes

Workspace Resolver Test Suite

Layer / File(s) Summary
Test infrastructure and helper utilities
tests/test_workspace_assignment_fallback.py
Module docstring, imports, repository-root path config, _write_workspace_json, and _resolve wrapper for consistent test inputs.
Primary mapping tests
tests/test_workspace_assignment_fallback.py
Definitive composer→workspace mapping precedence, invalid mapping handling, and None when no fallback exists.
Project layouts resolution
tests/test_workspace_assignment_fallback.py
Resolve workspace ids via project_layouts_map using workspace_path_to_id and project-name fallback plus missing-key fallthrough.
File-path based resolution
tests/test_workspace_assignment_fallback.py
Resolve from newlyCreatedFiles and from codeBlockData file URIs.
Bubble-context resolution
tests/test_workspace_assignment_fallback.py
Resolve via relevantFiles, attachedFileCodeChunksUris, and context.fileSelections; skip malformed/non-dict bubble headers.
Path-segment last-resort matching
tests/test_workspace_assignment_fallback.py
Last-resort basename matching outside workspace roots with tie-break preferring longer folder-name overlap.
Terminal None and malformed inputs
tests/test_workspace_assignment_fallback.py
Asserts None when all stages fail, empty composer data, empty/None schema values, or malformed newly-created entries.
Hypothesis strategies and property tests
tests/test_workspace_assignment_fallback.py
Hypothesis strategies for arbitrary composer/bubble inputs and fuzz tests ensuring no raises and definitive mapping wins.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related issues

Poem

🐰
Tests hop through mapping, path, and bubble,
Each stage checked so failures won't double,
Hypothesis fuzzes the wild unknown,
Clear fallbacks find where projects are sown,
A rabbit cheers the resolver well-grown.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% 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 title clearly and specifically describes the main change: expanding test coverage for determine_project_for_conversation's fallback chain, directly matching the PR's primary objective.
Linked Issues check ✅ Passed All PR changes directly address #87 requirements: 21 tests cover all 6 fallback stages, include Hypothesis property tests, handle None cases, and validate schema-drift scenarios as specified.
Out of Scope Changes check ✅ Passed All changes are scoped to tests/test_workspace_assignment_fallback.py, directly targeting the function and scenarios defined in #87 with no unrelated modifications.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/tests-for-determin-project

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

Copy link
Copy Markdown

@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.

🧹 Nitpick comments (1)
tests/test_workspace_assignment_fallback.py (1)

20-25: 💤 Low value

sys.path insertion runs after the import it's meant to enable.

from services.workspace_resolver import ... (Line 20) executes before REPO_ROOT is inserted into sys.path (Lines 23-25). If the repo root weren't already importable, the import on Line 20 would fail first, so the path manipulation is effectively dead code. Move the sys.path setup above the project imports to make it meaningful.

♻️ Proposed reordering
 import unittest

 from hypothesis import given, settings
 from hypothesis import strategies as st

-from services.workspace_resolver import determine_project_for_conversation
-from utils.path_helpers import normalize_file_path
-
 REPO_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
 if REPO_ROOT not in sys.path:
     sys.path.insert(0, REPO_ROOT)
+
+from services.workspace_resolver import determine_project_for_conversation
+from utils.path_helpers import normalize_file_path
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/test_workspace_assignment_fallback.py` around lines 20 - 25, The
sys.path insertion (REPO_ROOT and sys.path.insert(0, REPO_ROOT)) currently comes
after the imports and is therefore ineffective; move the REPO_ROOT computation
and the sys.path insertion so they occur before any project imports (e.g.,
before the lines importing determine_project_for_conversation and
normalize_file_path) so that the module import of services.workspace_resolver
will succeed when the repo root is not already on sys.path.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@tests/test_workspace_assignment_fallback.py`:
- Around line 20-25: The sys.path insertion (REPO_ROOT and sys.path.insert(0,
REPO_ROOT)) currently comes after the imports and is therefore ineffective; move
the REPO_ROOT computation and the sys.path insertion so they occur before any
project imports (e.g., before the lines importing
determine_project_for_conversation and normalize_file_path) so that the module
import of services.workspace_resolver will succeed when the repo root is not
already on sys.path.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 6625dfb6-be45-43aa-a90d-3189c2576dec

📥 Commits

Reviewing files that changed from the base of the PR and between 3bd7ce0 and 9447fa5.

📒 Files selected for processing (1)
  • tests/test_workspace_assignment_fallback.py

@bradjin8 bradjin8 requested a review from clean6378-max-it June 2, 2026 21:44
@clean6378-max-it
Copy link
Copy Markdown
Collaborator

Should fix

tests/test_workspace_assignment_fallback.py (new test) — Add a conflicting-signals case where two non-definitive stages disagree (e.g. newlyCreatedFiles → workspace A, codeBlockData → workspace B) and assert which workspace wins.

Issue #87 calls out “conflicting signals” explicitly; today only definitive-vs-layout conflict is covered (test_definitive_mapping_wins_over_conflicting_layouts). Stage order is the core contract of this function; a single ordering test would guard against accidental reordering during refactors.

tests/test_workspace_assignment_fallback.py:136 — Rename or split test_missing_project_layouts_key_falls_through.

The name implies the projectLayouts stage; the case actually exercises newlyCreatedFiles + workspace_entries with no project_layouts_map entry. Behavior is correct; the name misleads future maintainers.

Nice to have

tests/test_workspace_assignment_fallback.py — Add a path-segment case driven only by bubble fields (relevantFiles / attachments) on a path outside workspace roots (today path-segment coverage uses newlyCreatedFiles only).

tests/test_workspace_assignment_fallback.py — Hypothesis property: when composer_id_to_workspace_id maps to an ID in invalid_workspace_ids and no other stage can match, result is never that invalid ID.

tests/test_workspace_assignment_fallback.py — Explicit project_layouts_map entry with unresolvable roots (missing from workspace_path_to_id / project_name_to_workspace_id) to document fall-through to file-path stages.

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.

Tests for determine_project_for_conversation

2 participants