Repository navigation
fix(catalog): stop four false findings in catalog check - #1317
vchamarthi wants to merge 6 commits into
Conversation
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>
Signed-off-by: vchamarthi <123653452+vchamarthi@users.noreply.github.com>
|
🔍 OpenCodeReview found 1 issue(s) in this PR. CI at `120740b`: 1 failing, 20 passing, 4 skipped
By label: 1 should fix
Test notes (2)
Review details
|
|
Codecov Report❌ Patch coverage is
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
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
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
The new negative lookahead only treats-[\\w-]+tokens as “flags” and does not account for flags… · Newjson.loads(text)can be expensive on very large or adversarial.jsoninputs (even if it… · New Including JSON object keys in_json_text()can introduce false positives (keys are metadata, not… · New
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-shelland install detection logic (JSON string extraction, sentence cutting,npx tscexemption whentypescriptis installed). - Refine
bundle-file-unreferencedmessaging 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}?" |
There was a problem hiding this comment.
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.
| try: | ||
| data = json.loads(text) | ||
| except (ValueError, RecursionError): # a file nested deeper than the parser's limit is read as text | ||
| return text |
There was a problem hiding this comment.
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()] |
There was a problem hiding this comment.
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>
|
This is ready for another look: I've pushed 1 commit on Threads and comments:
What I checked on the new commit:
What each test shows
|
…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>
|
This is ready for another look: I've pushed 1 commit on Changes:
Threads and comments:
What I checked on the new commit:
What each test shows
|
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>
|
This is ready for another look: I've pushed 1 commit on Changes:
Threads:
What I checked on the new commit:
What each test shows
|
- --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>
|
This is ready for another look: I've pushed 1 commit on Threads:
What I checked on the new commit:
What each test shows
|
| 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) |
There was a problem hiding this comment.
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


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.jsonfile is read as its strings, each cut at,,.,!or?, so a sentence after an install is not read as packages.PIPE_TO_SHELLdoes not matchcurlorwgetdirectly followed by the pipe.npx tscandnpx tsserverare not counted when the same file installstypescript(pinned or not).dokimi/external/bundle_refs.pyanddocs/external-content.md: the warning says no document names the files, not that they are found only by browsing..is not a cut;--package=tscis not exempt; a line continuation before the pipe is covered by thecurl | shrule.npmoptions beforeinstallare read for thetypescriptcheck;curlwith 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
tscmap is a closed list of two programs. Acurl | shwith no argument is no longer reported.Testing
New tests in
tests/test_catalog_command_checks.pyandtests/test_catalog_bundle_unreferenced.pyfail on the previous commit. I ran those two files,tests/test_catalog_validate.py,tests/test_catalog_command.pyandtests/test_growth_ratchet.py, andruff checkon the changed files.Open questions
See the decisions listed below.
package.jsonscripts and eval strings counted while dropping the trailing sentence. Is that the behaviour you want?tscandtsservertotypescript, 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?curl | shwith nothing betweencurland 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
pytestpassesruff,mypy, and schema checks passAGENTS.mdraise/exit and test names the doc, contract or issue it traces to.github/.licenserc.yaml)Checklist evidence
pytestpasses: 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 hadruff,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 basedokimi/docs/external-content.mdAGENTS.md: nothing left open; mutation of changed lines ranraise/exit and test names the doc, contract or issue it traces to: every new error path and test names a doc, contract or issue.github/.licenserc.yaml): no new source fileFixes #969.