Skip to content

fix(catalog): stop four false findings in catalog check - #1317

Open
vchamarthi wants to merge 6 commits into
intel:mainfrom
vchamarthi:issue-969-catalog-check-misclassifies-descriptions-3
Open

vchamarthi wants to merge 6 commits into
intel:mainfrom
vchamarthi:issue-969-catalog-check-misclassifies-descriptions-3

Conversation

@vchamarthi

Copy link
Copy Markdown
Contributor

Summary

Fixes #969 scenarios 1, 5, 6 and 7; scenarios 2, 3 and 4 were fixed in #1041. Related: #946, #960 and #1090 touch the same code and keep their behaviour.

Changes

  • dokimi/external/command_checks.py: a .json file is read as its strings, each cut at , , . , ! or ? , so a sentence after an install is not read as packages.
  • PIPE_TO_SHELL does not match curl or wget directly followed by the pipe.
  • npx tsc and npx tsserver are not counted when the same file installs typescript (pinned or not).
  • dokimi/external/bundle_refs.py and docs/external-content.md: the warning says no document names the files, not that they are found only by browsing.
  • A changelog fragment.
  • Nested JSON deeper than the parser's limit is read as text; a standalone . is not a cut; --package=tsc is not exempt; a line continuation before the pipe is covered by the curl | sh rule.
  • The sentence cut skips quoted text; an npm alias does not count as the package it is named after; npm options before install are read for the typescript check; curl with only flags before the pipe is not a download.

Risk

Low. A JSON install command that continues past a comma or full stop is now cut there, and the tsc map is a closed list of two programs. A curl | sh with no argument is no longer reported.

Testing

New tests in tests/test_catalog_command_checks.py and tests/test_catalog_bundle_unreferenced.py fail on the previous commit. I ran those two files, tests/test_catalog_validate.py, tests/test_catalog_command.py and tests/test_growth_ratchet.py, and ruff check on the changed files.

Open questions

See the decisions listed below.

  • I chose Read JSON as its decoded strings, cut at sentence punctuation over treating .json as prose and reading only fences and code spans: keeps installs in package.json scripts and eval strings counted while dropping the trailing sentence. Is that the behaviour you want?
  • I chose A closed map of tsc and tsserver to typescript, per file over a general rule for any program of an installed package: smallest change that covers the reported case. Is that the behaviour you want?
  • I chose Ignore curl | sh with nothing between curl and the pipe over requiring a URL: a download with a variable or flags only is still a download, so only the argument-less form is dropped. Is that the behaviour you want?

Revert

Revert the commit; nothing is stored.

Checklist

  • Tests added/updated and pytest passes
  • ruff, mypy, and schema checks pass
  • Docs updated (or N/A) — see the docs-drift checklist in CONTRIBUTING.md
  • Self-reviewed per "Before opening a PR" in AGENTS.md
  • Each new raise/exit and test names the doc, contract or issue it traces to
  • No ad-hoc run artifacts committed
  • New files carry the SPDX license header (or are exempt in .github/.licenserc.yaml)
Checklist evidence
  • Tests added/updated and pytest passes: 2 test file(s) changed; suite: 35727 passed; 1 failing test(s) fail on the base branch too: tests/test_repo_compare_interval.py::test_the_row_p_places_zero_where_large_deltas_round_p_at_zero_apart; 9 of 13 proof(s) fail before the change; 4 pin behaviour the base code already had
  • ruff, mypy, and schema checks pass: passed: ci.yml:static / ruff check, ci.yml:typecheck / mypy, ci.yml:static / schema-check, ci.yml:static / schema_compat vs the PR base
  • Docs updated (or N/A): updated: dokimi/docs/external-content.md
  • Self-reviewed per "Before opening a PR" in AGENTS.md: nothing left open; mutation of changed lines ran
  • Each new raise/exit and test names the doc, contract or issue it traces to: every new error path and test names a doc, contract or issue
  • No ad-hoc run artifacts committed: 1 added file(s), none a run's output
  • New files carry the SPDX license header (or are exempt in .github/.licenserc.yaml): no new source file

Fixes #969.

install-unpinned read the words after `pip install pkg,` in an evals.json
sentence as packages; JSON files are now read as their strings, each cut
at the end of a sentence. pipe-to-shell no longer fires on `curl | sh`
with no argument. `npx tsc` is not counted in a file that installs
`typescript`. The bundle-file-unreferenced message no longer says the
files are found only by browsing.

Fixes intel#969

Signed-off-by: vchamarthi <123653452+vchamarthi@users.noreply.github.com>
@vchamarthi
vchamarthi requested a review from a team as a code owner November 26, 2026 22:40
Signed-off-by: vchamarthi <123653452+vchamarthi@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 26, 2026 22:40
@exai-bot

exai-bot commented Nov 26, 2026 •

Copy link
Copy Markdown

🔍 OpenCodeReview found 1 issue(s) in this PR.

CI at `120740b`: 1 failing, 20 passing, 4 skipped

The only failing check is CodeQL (python), caused by a runner/tool-bundle extraction infrastructure failure rather than this code change. The other 24 checks are passing or skipped; Python CodeQL analysis remains unverified and should be rerun.

Check Status Assessment
CodeQL (python) failing at step Run github/codeql-action/init@33d7b85da1a04171e211befe2c739303b9a4c066 Infrastructure or flaky. CodeQL initialization failed while extracting the external CLI bundle into the runner toolcache, before Python analysis. Both streaming extraction and the downloaded-bundle fallback failed; this change modifies application code, tests and documentation, not the CodeQL workflow or tool installation.

By label: 1 should fix

Label Location Finding
should fix command_checks.py:631 Impact: symbolic targeted installs can produce false warnings or suppress a real unpinned invocation in an unrelated literal directory.
Test notes (2)
  • dokimi/dokimi/external/command_checks.py:358: With raw = words changed to raw = words raise, the tests still pass: dokimi/tests/test_catalog_bundle_unreferenced.py, dokimi/tests/test_catalog_command_checks.py, dokimi/tests/test_catalog_command_checks_directories.py. If this condition matters, a test should pin it.
  • dokimi/dokimi/external/command_checks.py:404: With target = m.group(1) changed to target = m.group(1) raise, the tests still pass: dokimi/tests/test_catalog_bundle_unreferenced.py, dokimi/tests/test_catalog_command_checks.py, dokimi/tests/test_catalog_command_checks_directories.py. If this condition matters, a test should pin it.
Review details
  • Commit reviewed: 120740b against merge base 22aa409
  • Coverage: 2 files in 1 groups
  • Engine: OpenCodeReview v1.13.5-exai.4.8f73eada, us.openai.gpt-6.1-sol
  • Usage: 377k tokens (257k from cache), 2m51s
  • Tool calls: 27 (13 file_read, 4 code_search, 2 ci_status, 2 local_check_results, 2 pr_threads, 1 ci_log_search, 1 code_comment, 1 file_find, 1 file_read_diff)
  • small change set: 2 files

@codecov-commenter

codecov-commenter commented Nov 26, 2026 •

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 95.36424% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 96.19%. Comparing base (9bf1ce7) to head (120740b).
⚠️ Report is 31 commits behind head on main.

Files with missing lines Patch % Lines
dokimi/dokimi/external/command_checks.py 95.36% 7 Missing ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1317      +/-   ##
==========================================
+ Coverage   96.14%   96.19%   +0.04%     
==========================================
  Files         498      499       +1     
  Lines       66028    66806     +778     
  Branches    11461    11624     +163     
==========================================
+ Hits        63482    64262     +780     
+ Misses       1574     1571       -3     
- Partials      972      973       +1     
Files with missing lines Coverage Δ
dokimi/dokimi/external/bundle_refs.py 97.87% <ø> (ø)
dokimi/dokimi/external/command_checks.py 96.65% <95.36%> (-0.65%) ⬇️

... and 60 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI 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.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

3 open issues
What changed in this PR

Reduces false positives in catalog check for install-unpinned, pipe-to-shell, and bundle-file-unreferenced, especially around JSON content parsing and npx tsc/typescript interactions.

Changes:

  • Adjust pipe-to-shell and install detection logic (JSON string extraction, sentence cutting, npx tsc exemption when typescript is installed).
  • Refine bundle-file-unreferenced messaging to avoid implying files are found “only by browsing”.
  • Add regression tests for #969 scenarios and new edge cases.
File Description
dokimi/​dokimi/​external/​command_checks.py Updates detection heuristics for JSON, `curl
dokimi/​dokimi/​external/​bundle_refs.py Updates warning wording for unreferenced bundled files.
dokimi/​docs/​external-content.md Aligns documentation wording with the updated warning behavior.
dokimi/​tests/​test_catalog_command_checks.py Adds regression coverage for JSON sentence cutting, `curl
dokimi/​tests/​test_catalog_bundle_unreferenced.py Adds a regression test for updated bundle warning wording.
dokimi/​changelog.d/​20261126_190000_catalog-command-and-bundle-false-findings.md Changelog entry describing the fixes.

Review effort: Lite

# ``curl`` or ``wget`` with nothing but flags before the pipe (``curl -fsSL | sh``) names no download: a sentence that forbids it.
PIPE_TO_SHELL = re.compile(
r"\b(?:curl|wget)\b(?:[^\n;&|\\'\"]|'[^'\n]*'|\"[^\"\n]*\"|\\\r?\n|\\[^\n]|\|(?!\|)){0,500}?"
r"\b(?:curl|wget)\b(?!(?:(?:[ \t]|\\\r?\n)+-[\w-]+)*(?:[ \t]|\\\r?\n)*\|(?!\|))(?:[^\n;&|\\'\"]|'[^'\n]*'|\"[^\"\n]*\"|\\\r?\n|\\[^\n]|\|(?!\|)){0,500}?"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I couldn't reproduce this: python -c "from dokimi.external.command_checks import _findings_in as f; print(f([('a.md','curl -H "Accept: x" | sh\n')]))" gives [('pipe-to-shell', 'a download is piped into a shell or interpreter in a.md (line 1); ...')]. I don't think it's a defect, because a flag that takes a value (-H 'Accept: x') cannot be told from an operand without knowing every curl and wget option, so such a pipe is still reported; I chose reporting over staying silent, since a missed download-to-shell is worse than a warning on a sentence. The exemption is for bare flags only, as the comment above the pattern says.

Comment on lines +518 to +521
try:
data = json.loads(text)
except (ValueError, RecursionError): # a file nested deeper than the parser's limit is read as text
return text

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is already handled on the latest commit: A scanned file larger than BUNDLED_MAX_BYTES (256 KiB) is not read at all (command_checks.py, the bundled-file walk), so json.loads only sees bounded input, and test_deeply_nested_json_does_not_stop_the_scan covers the nesting limit.

if isinstance(item, str):
lines.append(_cut_sentences(item))
elif isinstance(item, dict):
stack += [*item.values(), *item.keys()]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I couldn't reproduce this: python -c "from dokimi.external.command_checks import _findings_in as f; print(f([('a.json','{\"pip install requests\": 1}')]))" gives [('install-unpinned', '1 install name no version (pip requests); ...')]. I don't think it's a defect, because a key is text the file holds, and before this PR the whole file was scanned as text, so a command written as a key was found; dropping keys would stop reporting it.

Fixes review findings on intel#1317:
- curl -K- and wget -i- (not -qO-) read their download from stdin, so a pipe to
  a shell after them is still reported.
- npm options before install (npm --no-audit install) are read for
  unpinned packages, so such an install is no longer lost.
- an install aimed at another directory (--prefix, --dir, -C,
  --workspace, --filter; not --prefix .) does not provide tsc to a later npx.
- the dots of a relative path (../..) do not end a JSON command.
- separate JSON strings no longer share an open shell quote.
- an install aimed at another directory (--prefix tools) provides tsc to an
  npx run after cd into that directory.

Signed-off-by: vchamarthi <123653452+vchamarthi@users.noreply.github.com>
@vchamarthi

Copy link
Copy Markdown
Contributor Author

This is ready for another look: I've pushed 1 commit on issue-969-catalog-check-misclassifies-descriptions-3 (32b29c0..4b703d7).

Threads and comments:

  • I answered each one in its thread: 6 fixed, 2 not a defect, 1 already settled.

What I checked on the new commit:

  • 5 of 8 new tests fail before the fix and pass after it; the other 3 pass before the fix too, so they guard the change rather than reproduce a bug.
  • The full test suite passes with main merged in (36,267 tests), apart from 1 failure main has too.
What each test shows
  • test_a_download_fed_through_stdin_is_still_a_pipe_to_shell: fails before, passes after.
  • test_an_unpinned_typescript_install_with_options_before_install_is_reported: fails before, passes after.
  • test_an_install_into_another_directory_does_not_provide_tsc: fails before, passes after.
  • test_the_dots_of_a_relative_path_in_a_json_install_do_not_end_the_command: fails before, passes after.
  • test_a_quote_left_open_by_one_json_string_does_not_hide_the_next: fails before, passes after.
  • test_wget_output_to_stdout_without_a_download_is_not_flagged: passes before the fix too.
  • test_an_install_into_the_current_directory_provides_tsc: passes before the fix too.
  • test_an_install_into_another_directory_provides_tsc_after_entering_it: passes before the fix too.

…orted

Fixes: -Kconfig/-iurls count as downloads for pipe-to-shell; a cd out of
the install directory, a subshell cd, --package-lock-only and --dry-run
installs no longer provide tsc; pnpm --dir/-C installs provide tsc after cd.

Also: curl's -i cluster is no flag-with-file (only curl -K and wget -i are); a subshell cd does not move the entered directory.

Also: `cd` is followed with subshell scope, and an absolute install directory matches the same absolute `cd`.
Signed-off-by: vchamarthi <123653452+vchamarthi@users.noreply.github.com>
@vchamarthi

Copy link
Copy Markdown
Contributor Author

This is ready for another look: I've pushed 1 commit on issue-969-catalog-check-misclassifies-descriptions-3 (4b703d7..75d48f6).

Changes:

  • curl -Kconfig | sh and wget -iurls -O- | sh keep their pipe-to-shell warning.
  • cd tools; cd ../other no longer counts as being in tools.
  • --package-lock-only, --lockfile-only and --dry-run installs no longer provide tsc.
  • pnpm --dir/-C installs provide tsc after cd into that directory.
  • curl -isSL | sh is no longer reported; -i is only a file option for wget.
  • A subshell (cd ..) no longer moves the directory followed after cd tools.
  • npx inside (cd tools && npx tsc) finds the install in tools.
  • --prefix /tmp/tools with cd /tmp/tools match.

Threads and comments:

  • I answered each one in its thread: 4 fixed.

What I checked on the new commit:

  • 1 of 3 new tests fail before the fix and pass after it; the other 2 pass before the fix too, so they guard the change rather than reproduce a bug.
  • The full test suite passes with main merged in (36,615 tests), apart from 1 failure main has too.
What each test shows
  • the four new test groups: fails before, passes after.
  • curl -i cluster and subshell cd: passes before the fix too.
  • subshell scope and absolute cd: passes before the fix too.

Fixes review findings on intel#1317:
- --bin-links=false, --no-bin-links and --save-dev with --omit=dev or
  --production leave no tsc for npx, so they do not provide it;
  --save-dev=false does not count as a dev install.
- a quoted "cd tools" is data: only a cd that starts a command moves
  the directory, and a quoted cd target is read to its closing quote.
- an install provides tsc to an npx run in the same directory or below
  it (npx looks up the tree; a child named ..src is a child), so an
  install in one sibling no longer hides npx tsc in another.
- a cd into a variable is followed as that name, so an install and an
  npx after the same cd "$ROOT" still meet.

Signed-off-by: vchamarthi <123653452+vchamarthi@users.noreply.github.com>
@vchamarthi

Copy link
Copy Markdown
Contributor Author

This is ready for another look: I've pushed 1 commit on issue-969-catalog-check-misclassifies-descriptions-3 (75d48f6..22aa409).

Changes:

  • An install with --save-dev --omit=dev, --production, --bin-links=false or --no-bin-links no longer counts as providing tsc.
  • Only a cd that starts a command moves the tracked directory.
  • An ordinary install provides tsc only to an npx run in the same directory.
  • A quoted cd target is read to its closing quote.
  • An npx run in a directory below the install directory finds the install.
  • A cd into a variable is followed as that name.
  • --save-dev=false is not a dev install.
  • Only a .. path component leaves the install directory.

Threads:

  • I answered each one in its thread: 3 fixed.

What I checked on the new commit:

  • 2 of 3 new tests fail before the fix and pass after it; the other passes before the fix too, so it guards the change rather than reproduce a bug.
  • The full test suite passes with main merged in (37,132 tests), apart from 1 failure main has too.
What each test shows
  • new regressions for the three threads: fails before, passes after.
  • quoted cd target and child directory: fails before, passes after.
  • variable cd, save-dev=false, ..src child: passes before the fix too.

- --include dev wins over --omit=dev; --only production as a separate
  word is read like --only=production and is a value option
- a quoted or escaped cd target is one directory
- cd - in a subshell leaves the directory unknown until ) or an
  absolute, ~ or $VAR cd, instead of dropping the install
- $VAR and ~ directories are not under a literal relative install

Signed-off-by: vchamarthi <123653452+vchamarthi@users.noreply.github.com>
@vchamarthi

Copy link
Copy Markdown
Contributor Author

This is ready for another look: I've pushed 1 commit on issue-969-catalog-check-misclassifies-descriptions-3 (22aa409..120740b).

Threads:

  • I answered each one in its thread: 5 fixed.

What I checked on the new commit:

  • 7 of 8 new tests fail before the fix and pass after it; the other passes before the fix too, so it guards the change rather than reproduce a bug.
  • The full test suite passes with main merged in (37,300 tests), apart from 1 failure main has too.
What each test shows
  • the new case: fails before, passes after.
  • the new case: fails before, passes after.
  • the new case: fails before, passes after.
  • the new case: fails before, passes after.
  • the new case: fails before, passes after.
  • the new case: fails before, passes after.
  • a quoted or escaped $ directory is a literal child of the install: passes before the fix too.
  • a --prefix '$X' install is found from cd '$X': fails before, passes after.

continue
base, here = _cwd(code, 0, m.start()), _installs_here(m.group(0), pnpm)
target = None if here else _install_dir(m.group(0))
where = base if here else (_join(base, target) if base and target else None)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

bug · should fix
Impact: symbolic targeted installs can produce false warnings or suppress a real unpinned invocation in an unrelated literal directory.

Trigger: npm install --prefix "$P" typescript@5.9.3; cd "$P"; npx tsc incorrectly reports npx tsc; replacing the cd with cd '$P' incorrectly suppresses it (when P names another project).

Evidence: _install_dir preserves the symbolic $P, but _join('.', '$P') returns ./$P. _cwd records $P for the expanded destination and ./$P for the literal destination, so _within matches the wrong one. Unquoted tilde targets and pnpm --dir/-C share this path. Preserve symbolic targets as roots rather than passing them through the literal-relative join, and add catalog-finding regressions for both destinations alongside the quoted-literal tests.

Workaround: enter the intended directory before installing, or use npx --package=typescript@5.9.3 tsc.

Should fix: A run shows it, and the code before this change fails the same way.

Shown by running: exit 1 (at the head) · exit 1 (at the merge base) · exit 0 (at the head with the fix)

python proof_c1.py

What the proof does: Runs _unpinned_in_readings on a script that installs typescript@5.9.3 with --prefix "$P" and then runs cd "$P"; npx tsc, and asserts npx tsc is not reported.

The problem shows as the output FALSE POSITIVE npx tsc reported.

dokimi/proof_c1.py

import sys
from dokimi.external.command_checks import _unpinned_in_readings

text = 'npm install --prefix "$P" typescript@5.9.3; cd "$P"; npx tsc\n'
res = _unpinned_in_readings(text, False)
print(res)
if any('npx tsc' in r for r in res):
    print('FALSE POSITIVE npx tsc reported')
    sys.exit(1)
['npx tsc']
FALSE POSITIVE npx tsc reported

This branch has not been deployed

No deployments
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.

catalog check misclassifies descriptions, commands and bundled references

4 participants