Skip to content

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

Merged
wpak-ai merged 4 commits into
masterfrom
feat/tests-for-determin-project
Jun 3, 2026
Merged

test: cover determine_project_for_conversation fallback chain (closes #87)#89
wpak-ai merged 4 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 covering precedence and stage ordering.
    • Added coverage for resolution via definitive mappings, project-layouts, file-paths, conversation/bubble context, and last-resort path-segment/basename matching.
    • Included property-based (fuzz) tests to ensure the resolver never raises on arbitrary inputs.
    • Added cases for malformed, missing, or schema-drifted data and confirmed terminal no-match behavior.

@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: 5d53db4f-cace-4e21-9dc3-7cf01603eac0

📥 Commits

Reviewing files that changed from the base of the PR and between 0c914e4 and 40cd512.

📒 Files selected for processing (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, _resolve wrapper, and _EMPTY_COMPOSER test constant.
Primary mapping tests
tests/test_workspace_assignment_fallback.py
Definitive composer→workspace mapping precedence, invalid mapping handling, and None when no fallback exists.
Stage ordering (newlyCreatedFiles vs codeBlockData)
tests/test_workspace_assignment_fallback.py
Asserts newlyCreatedFiles takes precedence over conflicting codeBlockData.
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; allow later file-path stages when layout roots are unmapped.
File-path based resolution
tests/test_workspace_assignment_fallback.py
Resolve from newlyCreatedFiles paths 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/path-segment 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, schema fields set to None, or malformed newlyCreatedFiles 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; includes a test ensuring invalid definitive mappings do not leak through.

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 accurately describes the main change: adding comprehensive test coverage for the determine_project_for_conversation fallback chain, directly tied to issue #87.
Linked Issues check ✅ Passed The pull request addresses all coding requirements from issue #87: covers all 6 fallback stages individually, includes Hypothesis property tests, handles 9-parameter combinations and None scenarios, delivers 21 test cases (exceeding 15 minimum), and demonstrates local test passage.
Out of Scope Changes check ✅ Passed All changes are scoped to test coverage in tests/test_workspace_assignment_fallback.py. The PR adds comprehensive test suites, fixtures, and helpers exclusively for testing determine_project_for_conversation, 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.

@clean6378-max-it
Copy link
Copy Markdown
Collaborator

@CodeRabbit, I checked myself if my findings are addressed.

What do you think? good to merge?

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 3, 2026

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Read the current test file on the PR branch
cat tests/test_workspace_assignment_fallback.py

Length of output: 19139



@clean6378-max-it — yes, all your findings have been addressed. Here's a quick checklist:

Finding Status Where
[Required] Conflicting-signals test (newlyCreatedFiles → A, codeBlockData → B) ✅ Added TestDetermineProjectStageOrdering.test_newly_created_files_wins_over_conflicting_code_block_data
[Required] Rename misleading test_missing_project_layouts_key_falls_through ✅ Renamed Now test_newly_created_files_resolves_without_project_layouts_entry in TestDetermineProjectLayoutsStage
[Nice-to-have] Path-segment case driven by bubble fields outside workspace roots ✅ Added TestDetermineProjectPathSegmentStage.test_path_segment_matching_from_bubble_relevant_files
[Nice-to-have] Hypothesis: invalid definitive mapping never leaks without fallback ✅ Added TestDetermineProjectFuzz.test_invalid_definitive_mapping_never_returned_without_fallback
[Nice-to-have] project_layouts_map with unresolvable roots falls through to file-path stages ✅ Added TestDetermineProjectLayoutsStage.test_unresolvable_project_layouts_falls_through_to_file_paths

All five items — both required and all three nice-to-haves — are implemented. The suite now has 21 tests with solid coverage across every resolution stage and the three Hypothesis properties. This looks good to merge. 🐇

@clean6378-max-it clean6378-max-it requested a review from wpak-ai June 3, 2026 20:00
@wpak-ai wpak-ai merged commit 2839571 into master Jun 3, 2026
16 checks passed
@wpak-ai wpak-ai deleted the feat/tests-for-determin-project branch June 3, 2026 20:09
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

3 participants