rtk gain --project mis-scopes project directories whose path contains [, * or ?

Open Beginner friendly
#5,173 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
82/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
rust, sqlite
Domain
cli, databases

Research direction

Start in src/core/tracking.rs at project_filter_params, which builds the <cwd>/* GLOB pattern, and list every query that consumes it (summary, daily/weekly/monthly, recent). Either escape [, ], *, ? before appending /*, or replace the GLOB with a substr(project_path, 1, length(?1) + 1) = ?1 || '/' comparison. Reproduce with the scratch RTK_DB_PATH recipe given, then add a test pairing a bracketed project directory with its unbracketed twin; done means only the bracketed project and its subdirectory are counted.

Written by the indexing model from the issue text.

Description

rtk gain --project builds its subdirectory filter as a SQLite GLOB pattern (project_filter_params in src/core/tracking.rs: <cwd>/*) without escaping the path. A project directory whose name contains a GLOB metacharacter ([, ], *, ?) is therefore scoped wrongly: its own subdirectories are left out, and sibling directories that the pattern happens to match are counted in.

Repro (v1.0.1 and a build of develop 3ab08beca; project_filter_params is byte-identical in v1.0.1, v1.2.0 and develop), with a scratch RTK_DB_PATH:

mkdir -p 'proj[1]/sub' proj1/sub
(cd 'proj[1]' && rtk ls) ; (cd 'proj[1]/sub' && rtk ls) ; (cd proj1/sub && rtk ls)
cd 'proj[1]' && rtk gain --project

Rows recorded: proj[1], proj[1]/sub, proj1/sub. Expected in scope: the first two. Actual: proj[1] and proj1/sub. [1] is read as a character class, so the pattern …/proj[1]/* matches …/proj1/sub and not …/proj[1]/sub.

Every query that goes through project_filter_params is affected (summary, daily/weekly/monthly, recent, and --failures --project once #3227 lands). A fix escapes the three metacharacters ([ → [[], * → [*], ? → [?]) before appending /*, or swaps GLOB for substr(project_path, 1, length(?1) + 1) = ?1 || '/', with a test that has a bracketed project next to its unbracketed twin.

Dominant language
Rust
Stars
86.4k
Forks
5.5k
Avg merge
7d 6h
Merged PRs (30d)
48

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from rtk-ai/rtk

All issues in rtk-ai/rtk

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.