Skip to content

fix(search_file): return workspace-relative paths (T0-6) - #181

Merged
mindfn merged 3 commits into
mainfrom
codex/t0-6-search-file-relative-path
Mar 4, 2026
Merged

fix(search_file): return workspace-relative paths (T0-6)#181
mindfn merged 3 commits into
mainfrom
codex/t0-6-search-file-relative-path

Conversation

@mindfn

@mindfn mindfn commented Mar 4, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • fix search_file to return workspace-relative paths instead of absolute filesystem paths
  • align tool description/output schema text with the actual contract

Why

  • tests/unit/test_v4_file_tools.py::test_search_file_finds_matching_paths expects relative paths
  • absolute paths make outputs machine/temp-dir dependent and break deterministic contract

Verification

  • .venv/bin/pytest -q tests/unit/test_v4_file_tools.py::test_search_file_finds_matching_paths => passed
  • .venv/bin/pytest -q tests/unit/test_v4_file_tools.py => 16 passed

Align search_file output with existing path contract tests by returning workspace-relative matches instead of absolute filesystem paths.\n\nChanges:\n- Emit relative paths for both file and directory search branches in SearchFileTool.\n- Update tool description and output schema text to document workspace-relative output semantics.\n\nWhy:\n- Current behavior returned absolute paths while test and TODO baseline require relative paths.\n- Relative paths keep outputs deterministic across machines and CI temp directories.\n\nVerification:\n- .venv/bin/pytest -q tests/unit/test_v4_file_tools.py::test_search_file_finds_matching_paths => passed\n- .venv/bin/pytest -q tests/unit/test_v4_file_tools.py => 16 passed

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5bc4e0d3a8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

if not _match_pattern(pattern, rel_path):
continue
matches.append(str(abs_path).replace("\\", "/"))
matches.append(rel_path)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve root context in returned search_file paths

Appending rel_path here drops which workspace root a match came from, which breaks multi-root setups introduced by this change from absolute paths. If search_file is run against a non-primary root (for example by passing an absolute path in the second workspace root), the returned relative name is later resolved by read_file via resolve_path against roots[0], so the same path can resolve to the wrong file or fail with FILE_NOT_FOUND even though search_file reported it as a match.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in ce9f26b by preserving root context in search outputs and teaching path resolution to consume it.

What changed:

  • search_file now prefixes non-primary workspace roots as @root[n]/... (primary root remains unchanged).
  • resolve_path now parses @root[n]/... and resolves against the selected workspace root.
  • Added regression tests for both behaviors:
    • test_search_file_prefixes_secondary_root_paths
    • test_read_file_accepts_secondary_root_prefixed_path

Verification:

  • .venv/bin/pytest -q tests/unit/test_v4_file_tools.py::test_search_file_prefixes_secondary_root_paths tests/unit/test_v4_file_tools.py::test_read_file_accepts_secondary_root_prefixed_path
  • .venv/bin/pytest -q tests/unit/test_v4_file_tools.py

Problem:\n- search_file switched to pure workspace-relative output, which dropped root identity in multi-root runs\n- read_file resolves relative paths against workspace_roots[0], so matches from secondary roots could resolve to wrong files or fail\n\nChanges:\n- add @root[n]/<relative-path> support in resolve_path for deterministic root-targeted resolution\n- emit @root[n]/ prefix from search_file when a match belongs to a non-primary workspace root\n- update search_file description/output schema to document the root-prefixed contract\n- add regression tests covering secondary-root search_file output and read_file consumption of prefixed paths\n\nWhy this shape:\n- keeps existing single-root behavior unchanged\n- preserves deterministic relative outputs while restoring root context needed for follow-up file tools

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ce9f26b459

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines 161 to 162
rel_path = _normalized_relative_path(abs_path, root, roots)
if not _match_pattern(pattern, rel_path):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Match globs before adding root prefix

Here rel_path is already rewritten as @root[n]/... for secondary roots, so directory-aware patterns like pkg/*.py or src/**/*.ts no longer match even when files exist under the searched secondary root. I confirmed this by exercising SearchFileTool with two workspace roots: searching the secondary root with pattern pkg/*.py returns zero results because matching is done against the prefixed display path instead of the root-relative path. This is a regression introduced by the prefixing change and causes false negatives for multi-root searches.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 2bf92d2 by separating match-path semantics from display-path formatting.

What changed:

  • search_file now performs glob matching against the root-relative path (for example pkg/c.py).
  • After a match is found, output formatting is applied (@root[n]/... for non-primary roots).
  • Added regression coverage for this case:
    • test_search_file_matches_directory_glob_in_secondary_root

Verification:

  • .venv/bin/pytest -q tests/unit/test_v4_file_tools.py::test_search_file_prefixes_secondary_root_paths tests/unit/test_v4_file_tools.py::test_search_file_matches_directory_glob_in_secondary_root tests/unit/test_v4_file_tools.py::test_read_file_accepts_secondary_root_prefixed_path
  • .venv/bin/pytest -q tests/unit/test_v4_file_tools.py

Problem:\n- secondary-root matches are displayed as @root[n]/...\n- pattern matching was performed against that display string, which breaks directory-aware globs like pkg/*.py\n\nChanges:\n- split search_file path handling into two stages:\n  1) compute root-relative path for matching\n  2) format matched path for output with optional @root[n]/ prefix\n- keep prefixed output contract for non-primary roots, while restoring correct glob behavior\n- add regression test covering directory glob matching in a secondary workspace root\n\nVerification:\n- .venv/bin/pytest -q tests/unit/test_v4_file_tools.py::test_search_file_prefixes_secondary_root_paths tests/unit/test_v4_file_tools.py::test_search_file_matches_directory_glob_in_secondary_root tests/unit/test_v4_file_tools.py::test_read_file_accepts_secondary_root_prefixed_path\n- .venv/bin/pytest -q tests/unit/test_v4_file_tools.py
@mindfn

mindfn commented Mar 4, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@mindfn
mindfn merged commit 018f236 into main Mar 4, 2026
10 checks passed
@mindfn
mindfn deleted the codex/t0-6-search-file-relative-path branch March 4, 2026 10:52
mindfn added a commit that referenced this pull request Mar 11, 2026
Update the project-level TODO ledger after T0-6 was already merged via PR #181.

This marks claim AG10 and task T0-6 as done, replaces the stale pending evidence with merged-code verification, and removes the resolved search_file regression from the current issue cluster so the board matches implementation reality.
mindfn added a commit that referenced this pull request Mar 11, 2026
docs(todos): sync T0-6 status after merged PR #181
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.

1 participant