Repository navigation
Tests for determine_project_for_conversation #87
Description
Problem
determine_project_for_conversation is the highest schema-drift-risk function in cppa-cursor-browser. Located in services/workspace_resolver.py (line 227), it takes 9 parameters and implements a multi-stage fallback chain: definitive per-workspace mapping → projectLayouts path matching → newlyCreatedFiles URI matching → codeBlockData file-path matching → bubble relevantFiles / attachedFileCodeChunksUris / context.fileSelections matching → last-resort path-segment substring matching. When Cursor changes its internal SQLite schema — and it has already migrated from workspace-specific to global storage — a renamed key silently returns None rather than raising an error, and the fallback chain silently degrades through progressively less reliable resolution stages with no diagnostic signal. The codebase has 34 test files with 344 test cases and CI running pytest, mypy, and gitleaks, but determine_project_for_conversation has only 1 direct test (tests/test_workspace_assignment_fallback.py — testing the invalid-workspace-alias bypass path). None of the 6 fallback stages (projectLayouts, newlyCreatedFiles, codeBlockData, bubble headers, path-segment matching, or the None terminal) have dedicated coverage, meaning schema drift in any stage is undetectable until it surfaces as silent misassignment in production.
Acceptance Criteria
- Direct unit tests covering all 6 fallback stages individually
- Property-based tests (Hypothesis, already in use) for edge cases
- Covers: all 9 parameter combinations, None handling, schema drift scenarios
- At least 15 test cases covering the multi-stage resolution
- Tests pass in CI
Implementation Notes
- Function is in
services/workspace_resolver.py(post-PR refactor(api): split api/workspaces.py 1,407 → 142 LOC into services/ (closes #25) #31 split) - 1 direct test already exists in
tests/test_workspace_assignment_fallback.py— extend from there - Use the Hypothesis approach already established in PR Add Hypothesis property tests for blob/bubble parsing (#71) #81
- Key scenarios: missing keys, empty values, conflicting signals, new schema fields, all-stages-fail-to-None
- Brad already has deep familiarity from Week 22's monolith extraction
References
services/workspace_resolver.py:227— function definition (9 params, ~145 LOC)tests/test_workspace_assignment_fallback.py— existing 1-test coverage
Activity
test: cover determine_project_for_conversation fallback chain (closes #…