new task brief

This commit is contained in:
2026-11-10 19:58:06 -05:00
parent 1f7126dca5
commit bcb3da0f18

109
sources/task-brief.md Normal file
View File

@@ -0,0 +1,109 @@
### 1. Task Description
Expand NearBeach's search tests from HTTP-status checks into deterministic, data-driven tests that verify actual search results. Candidate 4 identifies explicit TODOs in `NearBeach/tests/tests_views/tests_search/test_search.py` for customer, organisation, and main search; address those gaps and extend coverage across main, customer, organisation, group, user, sprint, tag, notification, and permission-set searches.
Add at least 20 new test methods covering matching semantics, result counts, pagination, permissions, and closed/include_closed behaviour wherever those features exist in the supplied version. This is a test-engineering task, not a search redesign: preserve existing endpoint contracts and do not implement Candidate 2's unified search or facets.
---
### 2. How to Judge Completion
From the NearBeach repository root, create a virtual environment and install the project requirements plus coverage:
```bash
python3 -m venv .venv
. .venv/bin/activate
python3 -m pip install -r requirements.txt
python3 -m pip install coverage
```
Use the supplied repository's documented Django settings and database configuration. Run the existing search suite before making changes and record the baseline; Django's test runner should create and migrate its test database, so a running development server or manually created superuser is not required.
```bash
python3 manage.py test NearBeach.tests.tests_views.tests_search -v 2
```
After implementation, rerun that command. All existing search tests and at least 20 additional test methods should pass, with assertions on returned object identities, counts, or pagination metadata rather than only HTTP 200 responses. Inspect the tests to confirm that each of the nine search categories above has meaningful result assertions and that permission cases use ordinary users, not only superusers.
Run the coverage check:
```bash
coverage run --source=NearBeach.views.search_views,NearBeach.views.search \
manage.py test NearBeach.tests.tests_views.tests_search
coverage report -m
```
Both `NearBeach/views/search_views.py` and `NearBeach/views/search/search_objects.py` should individually reach at least 80% statement coverage. Record the actual percentages and uncovered lines; do not omit difficult branches or alter coverage exclusions merely to meet the target.
Finally, run the complete existing suite:
```bash
python3 manage.py test
```
There should be no new failures. If the supplied environment has pre-existing failures or unavailable dependencies, document the exact commands, failures, and comparison with the baseline rather than reporting an unverified pass.
---
### 3. Other Notes for Reviewer
NearBeach is an open-source Django/Vue project management application used to track projects, tasks, requirements, and related team activity. Search is a navigation mechanism across multiple business objects and administrative records, so a successful HTTP response alone does not show that users can find the right records or that restricted records stay hidden.
The candidate brief reports gaps explicitly documented as TODOs in the existing search tests. Deterministic fixtures and result-level assertions will make filtering and permission regressions visible, providing a safety net for future search maintenance without changing the user interface or adding a new search API. Permission tests are especially important because a search can return plausible results while silently including objects outside a user's authorised groups.
Endpoint capabilities and permission rules must be confirmed against the supplied repository before encoding expectations. Not every search type necessarily supports pagination, closed-state filtering, or the same ObjectAssignment-based visibility rules; tests should exercise the actual contract for each type rather than invent uniform behaviour. This document describes planned acceptance criteria, not evidence that the code has already been inspected, changed, or tested.
---
### Implementation Essentials (for Model)
**Scope and Starting Points:**
- Start with `NearBeach/tests/tests_views/tests_search/test_search.py`, its TODOs, and neighbouring search tests.
- Read `NearBeach/views/search_views.py`, `NearBeach/views/search/search_objects.py`, URL routing, and the forms used by the endpoints before designing requests.
- Confirm request methods, parameter names, response shapes, pagination behaviour, and permission requirements from the supplied code.
- Reuse existing test conventions, fixture helpers, and authentication setup where appropriate.
- Keep changes in tests and test data by default. If a test reveals a production defect, explain it and agree on a separate fix rather than silently changing search behaviour or weakening the assertion.
**Deterministic Test Data:**
- Prefer class-level `setUpTestData()` with Django `TestCase` where compatible with the existing suite; use transactional tests only when required.
- Create small, explicit datasets with known descriptions, names, statuses, dates, users, groups, and object assignments.
- Include matching records, deliberate near-matches, unrelated records, and restricted records so incorrect filtering cannot pass accidentally.
- Use synthetic usernames and addresses, not personal information.
- Create enough records to cross real pagination boundaries without relying on unrelated fixtures.
- Use fixed or controlled timestamps when dates or ordering affect assertions.
- If reusable fixtures are preferable, place them alongside existing fixture conventions and document the records on which assertions depend.
**Coverage Matrix:**
| Area | Required assertions |
|------|---------------------|
| Exact and partial matching | Expected IDs are returned; unrelated and near-matching records are excluded according to the endpoint's actual matching rules. |
| Case insensitivity | Case variants return the same matching records where searches use case-insensitive matching. |
| Multi-term queries | Where terms are space-split and ANDed, only records matching every term are returned; records matching just one term are excluded. |
| Empty and no-match queries | Assert the endpoint's defined result shape and counts, including a genuinely empty result set. |
| Pagination | Check first page, second page, final boundary, and beyond-last-page behaviour on endpoints that paginate. Verify no overlap or missing expected records across valid pages. |
| Permissions | Ordinary users see permitted records and cannot see restricted records; include users with no relevant access and overlapping group assignments. |
| Closed/include_closed | Closed records are excluded or included as specified by the actual supported toggle, without changing visibility permissions. |
| Counts | Returned totals or per-type counts agree with the accessible matching records, not the unfiltered dataset. |
| Search categories | Main, customer, organisation, group, user, sprint, tag, notification, and permission-set searches each receive result-level assertions. |
**Permissions:**
- Build explicit authorised and unauthorised users/groups using the existing permission model.
- Exercise ObjectAssignment-based filtering where it applies; verify administrative and user-specific endpoints against their own rules.
- For notifications, verify recipient isolation if supported by the endpoint contract.
- Include an object assigned through multiple accessible groups to check that joins do not duplicate results or inflate counts.
- Keep superuser behaviour in a separate case so it cannot mask missing permission setup.
**Assertions and Organisation:**
- Use descriptive test names and `subTest()` for closely related input variants, while still adding at least 20 new test methods.
- Compare exact sets of IDs when order is unspecified; assert ordered sequences only when ordering is part of the contract.
- Check both inclusion and exclusion, and validate totals or metadata when exposed.
- Prefer client requests and real database records over mocking the search/filtering logic being tested.
- Replace TODO comments only when their intended result-level coverage is implemented.
- Do not introduce facet tests unless facets already exist in the supplied repository; Candidate 2 is not a prerequisite.
**Verification Evidence:**
- Record baseline and final search-suite results, including test counts and failures.
- Record the coverage command and individual coverage percentages for both target modules.
- Summarise the full-suite result and distinguish pre-existing/environment failures from regressions.
- List changed test/fixture files and any endpoint limitations discovered during implementation.