Repository navigation
fix(cli): novelty subcommands exit with a message on unreadable or invalid input #235
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
vchamarthi
wants to merge
25
commits into
intel:main
Choose a base branch
from
vchamarthi:fix/cli-input-novelty
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+884
−45
Open
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
e881dca
fix(novelty): analyze and probe exit with a message on an unreadable …
vchamarthi de1fcab
fix(novelty): items exits with a message on an unreadable --probes file
vchamarthi 5d656ca
fix(novelty): probe and shorten exit with a message on an unreadable …
vchamarthi 6784cac
fix(novelty): view exits 1 with a message on an unreadable or invalid…
vchamarthi b733c2a
fix(novelty): routing exits with a message on an unreadable or non-UT…
vchamarthi ced2598
fix(novelty): shorten exits with a message when --artifact cannot be …
vchamarthi 7591501
chore: changelog fragment and growth baseline
vchamarthi 26a9916
fix(novelty): reject a malformed bundle in --atoms and cover the revi…
vchamarthi 92792f1
fix(novelty): drop the Error prefix from the --atoms read failure mes…
vchamarthi fdc190e
fix(novelty): probe --artifact refuses an unreadable entry point inst…
napetrov d2c81f3
test(novelty): import json at module top instead of __import__
napetrov 3709700
fix(novelty): refuse any unreadable --artifact and a non-object atoms…
vchamarthi 8c7555e
fix(novelty): refuse an atoms bundle with wrong-typed values and deep…
vchamarthi 4813252
fix(novelty): check excluded paths and refuse deeply nested probe and…
vchamarthi ceccf70
test(novelty): pin a boolean --atoms bundle word budget as refused
antonwolfy 495d4d1
fix(novelty): refuse atoms fields of the wrong type and deeply nested…
vchamarthi 37360b3
fix(novelty): refuse wrong-typed span, atom and probe fields and a de…
vchamarthi 422ff9e
test(novelty): pin a null model in a probes file as refused
antonwolfy 08cfdea
fix(novelty): check every atoms field a reader uses
vchamarthi b3dd46c
Merge origin/main into fix/cli-input-novelty
vchamarthi 04d8e81
Exit with the message when novelty analyze raises ValueError
antonwolfy 6f2f4aa
test(novelty): pin the analyze exit when the arms cannot run
xaleryb b352b77
test(novelty): pin the atoms field checks that guard a traceback
xaleryb ae956c7
Merge remote-tracking branch 'intel/main' into sweep1027-235
napetrov a38f971
fix(novelty): refuse bad --arms or --placebo-text before any model call
napetrov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
dokimi/changelog.d/20261025_120000_vchamarthi_cli-input-novelty.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| ### Fixed | ||
|
|
||
| - **`novelty` subcommands** exit with a message on an unreadable or invalid `--placebo-text`, `--probes`, `--atoms`, `--novelty`, `--queries` or `--artifact`, or an `--atoms` file whose `bundle` is not an object, instead of a traceback. | ||
3 changes: 3 additions & 0 deletions
3
dokimi/changelog.d/20261026_000000_vchamarthi_atoms-bundle-values.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| ### Fixed | ||
|
|
||
| - **`novelty probe` and `novelty shorten`** exit with a message on an `--atoms` file whose spans, atoms, `extraction` or `bundle` have a missing or wrong-type field or whose JSON is nested too deeply to parse, and `novelty view` does the same for deep nesting, instead of a traceback. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| # Copyright (C) 2026 Intel Corporation | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| """Reading a file a command was pointed at, with an exit that names it.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from pathlib import Path | ||
|
|
||
|
|
||
| def read_text_or_exit(path: str | None, flag: str) -> str | None: | ||
| """The text of the file `flag` names, None when the flag is unset. | ||
|
|
||
| A file that cannot be read stops the command with a message naming the flag and the | ||
| path, instead of a traceback. | ||
| """ | ||
| if not path: | ||
| return None | ||
| try: | ||
| return Path(path).read_text(encoding="utf-8") | ||
| except (OSError, UnicodeDecodeError) as exc: | ||
| raise SystemExit(f"cannot read {flag} {path}: {exc}") from None | ||
|
|
||
|
|
||
| def placebo_text_for_arms_or_exit(path: str | None, arms: tuple[str, ...]) -> str | None: | ||
| """The ``--placebo-text`` of an analyze run, checked against its arms before any model call. | ||
|
|
||
| A typo in --arms or --placebo-text would otherwise cost the extraction calls that run | ||
| before the measurement checks the same thing. | ||
| """ | ||
| from dokimi.novelty.measure import check_arms | ||
|
|
||
| placebo_text = read_text_or_exit(path, "--placebo-text") | ||
| try: | ||
| check_arms(arms, placebo_text) | ||
| except ValueError as exc: | ||
| raise SystemExit(str(exc)) from None | ||
| return placebo_text |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| # Copyright (C) 2026 Intel Corporation | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| """`novelty view`: read the saved novelty artifact and atoms file, or exit 1 naming the bad one.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import sys | ||
| from pathlib import Path | ||
| from typing import NoReturn | ||
|
|
||
|
|
||
| def _fail(message: str) -> NoReturn: | ||
| print(f"Error: {message}", file=sys.stderr) | ||
| raise SystemExit(1) | ||
|
|
||
|
|
||
| def load_view_inputs(novelty_path: str, atoms_path: str): | ||
| """``(artifact, atoms, spans)`` from the two files; an unreadable or invalid one exits 1.""" | ||
| from dokimi.artifacts import load_artifact | ||
| from dokimi.novelty.atoms import load_atoms | ||
|
|
||
| try: | ||
| artifact = load_artifact("novelty", Path(novelty_path)) | ||
| except OSError as exc: | ||
| _fail(f"cannot read {novelty_path}: {exc}") | ||
| except (ValueError, RecursionError) as exc: # not UTF-8, not JSON, or not a novelty artifact | ||
| _fail(f"{novelty_path} is not a valid novelty artifact: {exc}") | ||
| try: | ||
| atoms, spans = load_atoms(atoms_path) | ||
| except OSError as exc: | ||
| _fail(f"cannot read {atoms_path}: {exc}") | ||
| except (ValueError, RecursionError) as exc: # not UTF-8, not JSON, or not an atoms record | ||
| _fail(f"{atoms_path} is not a valid atoms file: {exc}") | ||
| return artifact, atoms, spans |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.